Skip to content

feat: /dewey-distill — compile/curate/promote pipeline via the running MCP server with server-side OpenAI-compatible synthesis #133

Closed

Description

@jflowers

Summary

Add /dewey-distill — a slash command that runs the knowledge pipeline (lint → compile → curate → promote) through the running MCP server, with synthesis executed server-side by a new configurable OpenAI-compatible synthesizer. Includes the server changes that make it possible: synthesizer wiring for the compile/curate tool handlers, mutex unification for compile, and a batch parameter for promote.

Chosen provider instance (user decision): the enmaas provider — OpenAI-compatible API at https://api.enmaas.devshift.net/v1, model rits/zai-org/glm-5-3. The API key must come from environment (DEWEY_SYNTHESIS_API_KEY) or synthesis.api_key in config.yaml — never committed, never logged.

Outcome (the goal — implementation may adapt)

An agent or human can, while the MCP server is running:

  1. See current knowledge state (lint findings, learning inventory, compiled articles).
  2. Turn draft learnings into compiled articles and curated knowledge-store content — synthesis performed by the configured provider inside the server, no CLI round-trip, no server restart.
  3. Review drafts at a human gate (promotion is human validation per the trust-tier model), then promote validated knowledge (learnings and/or compiled articles) to validated tier in one batched call.

With graceful fallback: when synthesis is unconfigured or unavailable, behavior is byte-compatible with today's prompt-mode flows (the calling agent synthesizes per cluster and calls store_compiled). If a better design than the one below achieves these outcomes, use it.

Background — verified facts

  • The running server owns the store. Exclusive Flock(LOCK_EX|LOCK_NB) on .uf/dewey/dewey.lock held for server lifetime (store/store.go:105-120) → dewey compile/curate/lint/promote/doctor/status/index CLI commands all fail beside it ("another Dewey process is using this database"). The pipeline therefore must go through MCP tools.
  • MCP compile/curate currently pass nil synthesizers (server.go:130, server.go:136) and return prompt-mode payloads (status: "prompts_ready" / "prompt_ready") expecting the calling agent to synthesize. The status fields already distinguish modes — a synthesizer-injected path returning "compiled" / "complete" is backward compatible.
  • The server already knows how to build a synthesizer: backgroundCuration (main.go:797-861, esp. 823-838) does ReadSynthesisConfig → NewSynthesizerFromConfig → Available() check → graceful skip. Reuse the pattern at startup.
  • compile has a private mutex (tools/compile.go:58) that is not the shared index mutex — curate correctly shares cfg.indexMutex (tools/curate.go:76-79). Once compile writes synthesized output this becomes a real concurrency gap; unify.
  • promote takes a single page and only maps draft → validated (tools/promote.go:35-76). Promoting compiled/{tag} pages currently fails at page lookup — tracked in bug: dewey_promote MCP tool fails with 'Page not found' for compiled articles #91 (umbrella bug: MCP tools cannot access internal store pages (learnings, compiled articles) #90). This issue's batch-promote work must sequence with (or subsume) that fix.
  • Synthesizer surface (llm/): interface Synthesize(ctx, prompt) (string, error), Available() bool, ModelID() string; existing implementations OllamaSynthesizer, VertexSynthesizer (429 retry/backoff), NoopSynthesizer (test double); factory NewSynthesizerFromConfig.
  • Prior synthesizer regressions to learn from: bug: curation fails with 'unexpected end of JSON input' — VertexSynthesizer MaxTokens hardcoded at 4096 #76 (hardcoded MaxTokens 4096 truncated curation output), bug: VertexSynthesizer HTTP timeout (120s) too short for large curation prompts #77 (120s timeout too short for large prompts). The new provider needs configurable/adequate output limits and timeouts.
  • CLI parity note: when the server is NOT running, dewey compile/dewey curate CLI still build their own synthesizer from config (cli.go:2132-2135, cli.go:2267-2272) — don't break that.

Current implementation direction (adaptable)

llm/ — OpenAI-compatible synthesizer

New Synthesizer implementation speaking an OpenAI-compatible chat-completions API: endpoint, model, api key (env/config), timeouts and retry consistent with Vertex's 429 handling. NewSynthesizerFromConfig gains the branch — exact synthesis.provider naming is the implementer's choice (e.g. openai-compatible with endpoint/model/api_key); document in README and AGENTS.md. dewey doctor's synthesis section validates the new provider's config.

Server wiring

Build the synthesizer at startup (backgroundCuration pattern); pass to compile and curate handlers when configured and Available(), else nil → prompt-mode. Join compile onto the shared index mutex (parity with curate).

promote batch

Add optional pages []string (keep page for single-shot compatibility — DE-005: avoid N-call agent loops). Batch failures fail closed with per-page errors. Coordinate with #91 so compiled/{tag} pages resolve (either fix here or explicitly sequence after it).

/dewey-distill command (.opencode/commands/dewey-distill.md, added to slash_commands.go)

  1. MCP lint → present findings (stale decisions, uncompiled learnings)
  2. Inventory via MCP list_pages (namespaces learning/, compiled/)
  3. GATE: what to compile, which stores to curate
  4. MCP compile / curate — server-side synthesis when configured; if prompt-mode returns, the agent synthesizes per cluster and calls store_compiled
  5. GATE (human): review draft articles + stale decisions — promotion is human validation per the trust-tier model
  6. MCP promote (batch)
  7. Report + suggest /dewey-publish (companion issue) to preserve the results

Acceptance criteria

  • With synthesis configured + available: MCP compile returns status: "compiled" and writes .uf/dewey/compiled/{tag}.md; MCP curate returns status: "complete" — no CLI process, no server restart.
  • Without synthesis: responses byte-compatible with today's prompt-mode (backward compat).
  • promote accepts a batch; learning/{identity} pages promote draft→validated; compiled/{tag} promotes (with bug: dewey_promote MCP tool fails with 'Page not found' for compiled articles #91 resolved or explicitly sequenced).
  • compile and curate race-safe against concurrent index (shared mutex; demonstrated under -race).
  • API key never appears in logs, errors, or committed files; gitleaks-clean.
  • All 37 inherited graphthulhu MCP tools behave identically (regression suite green).
  • DE-007 seam tasks in tasks.md: registration surfaces (server.go tool registration, llm factory, slash_commands.go), documented output shapes (compiled vs prompts_ready), round-trips (compile→promote→tier check; curate→knowledge source indexed).
  • CI parity per AGENTS.md; review-council APPROVE before PR; README/AGENTS.md/GoDoc updated; website-sync issue filed per AGENTS.md (gh issue create --repo unbound-force/website).

Constraints

  • Packaging decision: single OpenSpec change together with the /dewey-publish issue (filed separately) and feat: /dewey-configure slash command to configure sources.yaml #122 — adaptable.
  • No CGO; pure-Go HTTP only. Cloud providers remain opt-in via config (consistent with the Vertex precedent); local-only default preserved.
  • Do not change the Synthesizer interface contract for existing implementations.

Out of scope

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfeature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions