Files
deepseek-harness/docs/event-producer-consumer.md
Tianyi Cui b59d245c7c feat: Code Mode — the registry's mode config, the SDK codegen, and the run_code bridge
The dsh-tools half of the Code Mode RFC (its fourth, final change): the
registry gains its first config — mode: native | code | both — and OWNS how
its tools reach the model. 'code' contributes exactly one wire tool,
run_code, plus a lazy tools:sdk prompt section declaring every other tool
as a generated TypeScript API (jsonSchemaToTs: total over the defineTool
subset, unknown degradation, lexicographic byte-identical rendering);
'both' ships both representations; 'native' is byte-for-byte the old
behavior. Non-native modes fail every assembly loudly without a
typescript-language ctx.codeRuntime.

run_code's dispatch bridge: JSON-normalizes each binding argument before
dispatch (what dispatches is what the tool/code-dispatch event logs — the
append can never fail on payload shape; BigInt/circulars reject that one
call), serializes all program tool calls through a per-run queue (even
Promise.all — no concurrency-safety metadata yet), routes every sub-call
through tools/pre-execute → tools/post-execute (a deny rejects the
program-side promise), drops sub-call additionalContext (no safe outlet
mid-run; pinned), owns a run-scoped abort that follows the outer signal in
and fires on settlement (in-flight sub-dispatch aborted, queued abandoned,
queue drained before returning), and converts a failed run into
CodeRunFailedError → a structured isError carrying kind + captured logs.
tool/code-dispatch joins SessionEventMap by declaration merging (log-only;
deriveMessages ignores it).

The composed surface: the tools config forwards through agent-core and
both app packages; examples/code-agent + demo:code run the worker runtime
under mode code (keyless boot smoke + a with-key e2e proving the collapsed
[run_code] header, the dispatch events, and the file the program wrote);
two new snapshot scenarios (code-mode-turn, both-mode-turn) record the SDK
section, collapsed header, dispatch events, and result card — each its own
header-pinning class (the harness gains per-scenario config overlays and
per-class pins). Catalogs, graphs, cookbook, hooks-bridge notes, and the
RFC (moved to implemented/, restructured to decision-era headings) updated
in the same change.
2026-07-08 12:58:23 +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:264 agent (emit) stdio-agent
agent/disposed emit packages/core/agent/src/types.ts:271 agent (emit) stdio-agent
agent/error emit packages/core/agent/src/types.ts:420 agent-loop (emit) -
agent/pre-step serial packages/core/agent/src/types.ts:349 agent-loop (serial) compact-basic
agent/prompt-submit waterfall packages/core/agent/src/types.ts:362 agent-loop (waterfall) hooks-claude, hooks-codex
agent/queued emit packages/core/agent/src/types.ts:289 agent-loop (emit) -
agent/request waterfall packages/core/agent/src/types.ts:385 agent-loop (waterfall) -
agent/session-start emit packages/core/agent/src/types.ts:304 agent-loop (emit) hooks-claude, hooks-codex
agent/status emit packages/core/agent/src/types.ts:280 agent-loop (emit) acp, invariants, stdio-agent
agent/step-result waterfall packages/core/agent/src/types.ts:395 agent-loop (waterfall) -
agent/turn-continuation waterfall packages/core/agent/src/types.ts:408 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:111 tools (emit) -
tools/post-execute waterfall packages/core/tools/src/index.ts:106 tools (waterfall) hooks-claude, hooks-codex
tools/pre-execute waterfall packages/core/tools/src/index.ts:90 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.