Skip to content

feat(repl): add /deep-seek web-research command - #137

Merged
1011-a merged 3 commits into
mainfrom
feat/deep-seek-research
Jun 4, 2026
Merged

feat(repl): add /deep-seek web-research command#137
1011-a merged 3 commits into
mainfrom
feat/deep-seek-research

Conversation

@1011-a

@1011-a 1011-a commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Adds a new REPL command /deep-seek <question> (aliases /deepseek, /research) that runs a bounded, agentic web-research pass and returns a cited answer.

What it does

Given a question, the pass:

  1. Decomposes it into sub-questions.
  2. Uses WebSearch to find sources and WebFetch to read the promising ones in full (not just snippets).
  3. Cross-checks each key claim across independent sources.
  4. Synthesizes a single report: a direct answer up top, key findings as bullets with inline source URLs, a "Confidence & gaps" note, and a "Sources" list.

If no search backend is configured, it degrades gracefully — falling back to WebFetch against search-engine result pages and flagging anything it can't verify.

How it's built (reuses existing machinery)

  • Factored the import/dream consolidation helper into a general run_bounded_pass(prompt, max_turns, allowed_tools) that scopes both max_turns and a tool allowlist, restoring both afterward. run_memory_consolidation now delegates to it (behavior unchanged).
  • The research pass is restricted to read-only research toolsWebSearch, WebFetch, Agent, MemorySearch, Read, Grep, Glob. No shell, file writes, or settings/cron/provider mutation. The allowlist is enforced at dispatch (is_tool_permitted), not merely advertised — so a pass whose answer pulls in untrusted web content can't be prompt-injected into running a shell.
  • Bounded at 24 turns (DEEP_SEEK_MAX_TURNS) so a research fan-out can't loop indefinitely and the user keeps an interrupt point.
  • Registered in command dispatch, the tab-completion/help source, and a new "Research" help category. Empty input prints usage (notes the BRAVE_SEARCH_API_KEY / SERPER_API_KEY requirement and that question + fetched page content is sent to the model).

Testing

  • Unit/integration: usage-on-empty; status line + synthesized answer; and a security test proving a non-allowlisted tool (Bash) is rejected by the gate mid-pass (the rejection lands as a tool result in the conversation, confirming the allowlist is enforced).
  • Manually verified end-to-end against the real DeepSeek backend: a live question (2025 Nobel Prize in Physics) decomposed → searched → fetched NobelPrize.org / Wikipedia / Physics World → cross-checked → produced a correct cited answer, including the no-search-key WebFetch fallback path.

Gates: cargo fmt --all -- --check ✓ · cargo clippy --all-targets --all-features -- -D warnings ✓ (0 warnings) · full suite 1281 passed / 0 failed.

1011-a added 3 commits June 3, 2026 22:54
`/deep-seek <question>` (aliases /deepseek, /research) runs a bounded
web-research pass: decompose the question, WebSearch + WebFetch sources,
cross-check across sources, and synthesize a cited answer with a confidence/gaps
note and a sources list.

- Reuses the bounded agent-pass machinery: factor the import/dream consolidation
  helper into a general `run_bounded_pass(prompt, max_turns, allowed_tools)` that
  scopes max_turns AND a tool allowlist, restoring both afterward.
  `run_memory_consolidation` now delegates to it (unchanged behavior).
- The pass is restricted to read-only research tools (WebSearch, WebFetch, Agent,
  MemorySearch, Read, Grep, Glob) — no shell, file writes, or config — so it is
  safe to point at questions whose answers pull in untrusted web content. The
  allowlist is enforced at dispatch (is_tool_permitted), not just advertised.
- Bounded at 24 turns (DEEP_SEEK_MAX_TURNS) so a research fan-out can't loop
  indefinitely; the user keeps an interrupt point.
- Registered in dispatch, the tab-completion/help source, and a new "Research"
  help category. Empty input prints usage (notes the BRAVE_SEARCH_API_KEY /
  SERPER_API_KEY requirement and the data-egress).

Tests: usage-on-empty; status-line + synthesized answer; and a security test
proving a non-allowlisted tool (Bash) is rejected by the gate mid-pass.

Gates: cargo fmt --check, clippy --all-targets -- -D warnings, 1281 tests green.
Refines /deep-seek so it no longer depends on a search backend by default:

- URL-first: the prompt now has the model propose likely official/canonical
  URLs from its own knowledge and verify them with WebFetch; an optional
  WebSearch backend (BRAVE_SEARCH_API_KEY / SERPER_API_KEY) only improves
  source discovery. Keeps the open-source default path key-free.
- Evidence labels: every source is tagged [verified] (fetched this pass),
  [known] (model-prior, not fetched), or [unverified]. The prompt forbids
  presenting an unfetched URL as [verified], reducing hallucinated citations.
- Tighter sandbox: the research pass is now restricted to web-only tools
  (WebSearch, WebFetch) — local file reads (Read/Grep/Glob), sub-agents
  (Agent), and memory access (MemorySearch) are dropped, so the pass cannot
  touch the local filesystem.
- run_bounded_pass now intersects with any user-set restrictions instead of
  replacing them, via new AgentLoop::set_tool_restrictions_intersecting — so
  a tool the user disallowed before /deep-seek stays disallowed.

Tests: local-read isolation, sub-agent isolation, user-disallow preservation,
and an evidence-label prompt contract.
…ormat

Two follow-ups to the URL-first deep-seek change:

- Restore the directly-fetchable search-results URLs (DuckDuckGo / Google,
  with the query URL-encoded into `q=`) in the WebSearch "no backend" error,
  and add them to the "backend failed" branch too — so without a search key
  the model still has a concrete source-discovery path via WebFetch, not just
  whatever URLs it can recall. Restores encode_query_component for this.
- Fix a clippy `useless_format` error (the no-backend message lost its only
  interpolation when the fallback URLs were removed), which would have failed
  CI's `clippy -D warnings` gate.

Re-adds the DuckDuckGo/Google URL assertions to the WebSearch missing-key test.
Gates: fmt, clippy --all-targets -- -D warnings, 1285 tests green.
@1011-a
1011-a merged commit bef50ca into main Jun 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant