Files
deepseek-harness/docs/event-producer-consumer.md
T
Tianyi Cui 74502fa8c2 Structured output on the subagent seam: schema subset, capture runtime, spawn/fork support
Carved out of #170 per review feedback — the foundation the workflow tool
builds on, now standing alone on master:

- dsh-tools: the structured-output JSON Schema subset (StructuredOutputSchema,
  assertSupportedOutputSchema, validateStructuredValue) — rejects loud outside
  the enforced subset, listing every violation
- dsh-subagent: SubagentStartRequest.outputSchema / SubagentResult.structured
  become a real capability; the service rejects a schema'd request whose
  provider lacks it
- dsh-subagent-inprocess: the shared structured runtime — one global
  structured_output capture tool, a prepend final-assembly listener that
  strips the placeholder for plain agents and swaps in the run's own schema
  (plus the calling instruction as a trailing section) for structured
  children, an agent/turn-continuation veto once captured, and the
  capture/nudge loop in the run driver (structuredNudgeRetries, cancellation
  honored mid-nudge); lifetime refcounted by backends and live runs
- subagent-spawn / subagent-fork flip outputSchema: true

One deliberate divergence from the #170 revision: the backends do NOT add
'tools' to their plugin inject. Doing so deferred their apply past the todo
plugin, and the delegation tool mirrors provider lifecycle — so the
model-visible tool order of every existing prompt changed, invalidating every
recorded snapshot fixture. The runtime now gates its capture-tool registration
on tools availability itself (sync when live, a scoped inject fiber when the
Loader starts the backend first), keeping this PR byte-invisible to existing
transcripts: all 35 snapshot scenarios pass against master's fixtures
unchanged.
2026-07-06 23:29:08 +08:00

6.8 KiB

Event Producer And Consumer Matrix

This matrix shows which packages dispatch each harness-owned event and which packages listen to it. It is intentionally a table rather than one large graph: events are many-to-many, and dense relation data is easier to review in rows. Dynamic dispatch overrides cover sites that deliberately bypass ctx.emit, such as subagent lifecycle containment.

Event Mode Declared in Dispatchers Listeners
agent/created emit packages/core/agent/src/types.ts:248 agent (emit) stdio-agent
agent/disposed emit packages/core/agent/src/types.ts:255 agent (emit) stdio-agent
agent/error emit packages/core/agent/src/types.ts:404 agent-loop (emit) -
agent/pre-step serial packages/core/agent/src/types.ts:333 agent-loop (serial) compact-basic
agent/prompt-submit waterfall packages/core/agent/src/types.ts:346 agent-loop (waterfall) hooks-claude, hooks-codex
agent/queued emit packages/core/agent/src/types.ts:273 agent-loop (emit) -
agent/request waterfall packages/core/agent/src/types.ts:369 agent-loop (waterfall) -
agent/session-start emit packages/core/agent/src/types.ts:288 agent-loop (emit) hooks-claude, hooks-codex
agent/status emit packages/core/agent/src/types.ts:264 agent-loop (emit) acp, invariants, stdio-agent
agent/step-result waterfall packages/core/agent/src/types.ts:379 agent-loop (waterfall) -
agent/turn-continuation waterfall packages/core/agent/src/types.ts:392 agent-loop (waterfall) hooks-claude, hooks-codex
fs/edit-intent waterfall packages/fs/fs/src/index.ts:123 tool-fs (waterfall) fs-policy
fs/observed emit packages/fs/fs/src/index.ts:138 tool-fs (emit) fs-policy
fs/write-intent waterfall packages/fs/fs/src/index.ts:109 tool-fs (waterfall) fs-policy
llm/stream waterfall packages/llm/llm/src/index.ts:39 llm (waterfall) invariants, llm-replay
session/created emit packages/core/session/src/index.ts:39 session (emit) invariants, session-persistence
session/event emit packages/core/session/src/index.ts:47 session (emit) acp, invariants, session-persistence, stdio-agent
session/flush parallel packages/core/session/src/index.ts:57 agent-loop (parallel) session-persistence
subagent/end emit packages/subagent/subagent/src/index.ts:98 subagent (events.dispatch) hooks-claude
subagent/provider-added emit packages/subagent/subagent/src/index.ts:72 subagent (emit) tool-subagent
subagent/provider-removed emit packages/subagent/subagent/src/index.ts:83 - tool-subagent
subagent/start emit packages/subagent/subagent/src/index.ts:91 subagent (events.dispatch) hooks-claude
system-prompt/assemble waterfall packages/core/system-prompt/src/index.ts:38 system-prompt (waterfall) -
system-prompt/change emit packages/core/system-prompt/src/index.ts:44 system-prompt (emit) -
tools/change emit packages/core/tools/src/index.ts:97 tools (emit) -
tools/post-execute waterfall packages/core/tools/src/index.ts:92 tools (waterfall) hooks-claude, hooks-codex
tools/pre-execute waterfall packages/core/tools/src/index.ts:76 tools (waterfall) hooks-claude, hooks-codex

Maintenance mode: hybrid generated: Cordis event declarations and most producer/listener edges are AST-scanned; dynamic dispatch sites are classified in scripts/gen-doc-graphs.ts.