dsh-plugin-dev-kb 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -0
  3. package/cordis.patch.yml +12 -0
  4. package/kb/INDEX.md +210 -0
  5. package/kb/README.md +69 -0
  6. package/kb/extra/AGENTS.md +75 -0
  7. package/kb/extra/api-gateway.md +164 -0
  8. package/kb/extra/api-gateway.zh.md +164 -0
  9. package/kb/extra/cookbook/adding-a-vendored-package.md +59 -0
  10. package/kb/extra/cookbook/adding-a-vendored-package.zh.md +59 -0
  11. package/kb/extra/cookbook/maintaining-dsh-code-review.md +64 -0
  12. package/kb/extra/cookbook/maintaining-dsh-code-review.zh.md +64 -0
  13. package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.md +32 -0
  14. package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.zh.md +32 -0
  15. package/kb/extra/defensive-patterns.md +33 -0
  16. package/kb/extra/defensive-patterns.zh.md +33 -0
  17. package/kb/extra/development.md +171 -0
  18. package/kb/extra/development.zh.md +171 -0
  19. package/kb/extra/event-producer-consumer.md +76 -0
  20. package/kb/extra/event-producer-consumer.zh.md +78 -0
  21. package/kb/extra/glossary.md +45 -0
  22. package/kb/extra/glossary.zh.md +45 -0
  23. package/kb/extra/graph-atlas.md +24 -0
  24. package/kb/extra/graph-atlas.zh.md +26 -0
  25. package/kb/extra/i18n/README.md +60 -0
  26. package/kb/extra/i18n/README.zh.md +60 -0
  27. package/kb/extra/i18n/style-samples.md +87 -0
  28. package/kb/extra/i18n/terminology.md +214 -0
  29. package/kb/extra/i18n/translation-prompt.md +263 -0
  30. package/kb/extra/i18n/translation-rules.md +69 -0
  31. package/kb/extra/i18n/translation-rules.zh.md +69 -0
  32. package/kb/extra/module-graph.md +1641 -0
  33. package/kb/extra/module-graph.zh.md +1643 -0
  34. package/kb/extra/postmortem/0001-acp-default-export-drops-inject.md +113 -0
  35. package/kb/extra/postmortem/0001-acp-default-export-drops-inject.zh.md +113 -0
  36. package/kb/extra/postmortem/0002-js-expression-disabled-filesystem-tools.md +47 -0
  37. package/kb/extra/postmortem/0002-js-expression-disabled-filesystem-tools.zh.md +47 -0
  38. package/kb/extra/postmortem/0003-web-agent-gui-feedback-loop.md +53 -0
  39. package/kb/extra/postmortem/0003-web-agent-gui-feedback-loop.zh.md +53 -0
  40. package/kb/extra/postmortem/0004-landlock-partial-notice-misclassified-child-failures.md +55 -0
  41. package/kb/extra/postmortem/0004-landlock-partial-notice-misclassified-child-failures.zh.md +55 -0
  42. package/kb/extra/postmortem/README.md +18 -0
  43. package/kb/extra/postmortem/README.zh.md +18 -0
  44. package/kb/extra/rescope.md +53 -0
  45. package/kb/extra/rescope.zh.md +53 -0
  46. package/kb/extra/subsystems/attachment.md +125 -0
  47. package/kb/extra/subsystems/attachment.zh.md +125 -0
  48. package/kb/extra/subsystems/extensions.md +364 -0
  49. package/kb/extra/subsystems/extensions.zh.md +364 -0
  50. package/kb/extra/subsystems/feedback.md +266 -0
  51. package/kb/extra/subsystems/feedback.zh.md +266 -0
  52. package/kb/extra/testing.md +49 -0
  53. package/kb/extra/testing.zh.md +49 -0
  54. package/kb/extra/web-styling.md +25 -0
  55. package/kb/extra/web-styling.zh.md +25 -0
  56. package/kb/meta/search-index.json +1328 -0
  57. package/kb/meta/site-pages.txt +168 -0
  58. package/kb/meta/source.json +13 -0
  59. package/kb/meta/topics.md +75 -0
  60. package/kb/site/develop/basic/config.md +108 -0
  61. package/kb/site/develop/basic/index.md +146 -0
  62. package/kb/site/develop/basic/publish.md +185 -0
  63. package/kb/site/develop/basic/tool.md +54 -0
  64. package/kb/site/develop/cordis-tutorial/01-first-plugin.md +95 -0
  65. package/kb/site/develop/cordis-tutorial/02-lifecycle-and-effects.md +98 -0
  66. package/kb/site/develop/cordis-tutorial/03-services.md +98 -0
  67. package/kb/site/develop/cordis-tutorial/04-events.md +144 -0
  68. package/kb/site/develop/cordis-tutorial/05-config.md +84 -0
  69. package/kb/site/develop/cordis-tutorial/06-composition-and-hmr.md +113 -0
  70. package/kb/site/develop/cordis-tutorial/07-into-the-harness.md +107 -0
  71. package/kb/site/develop/cordis-tutorial/index.md +62 -0
  72. package/kb/site/develop/framework/events.md +145 -0
  73. package/kb/site/develop/framework/index.md +139 -0
  74. package/kb/site/develop/framework/service.md +152 -0
  75. package/kb/site/develop/practice/index.md +157 -0
  76. package/kb/site/develop/practice/llm-adapter.md +190 -0
  77. package/kb/site/en/develop/basic/config.md +108 -0
  78. package/kb/site/en/develop/basic/index.md +146 -0
  79. package/kb/site/en/develop/basic/publish.md +185 -0
  80. package/kb/site/en/develop/basic/tool.md +54 -0
  81. package/kb/site/en/develop/cordis-tutorial/01-first-plugin.md +95 -0
  82. package/kb/site/en/develop/cordis-tutorial/02-lifecycle-and-effects.md +98 -0
  83. package/kb/site/en/develop/cordis-tutorial/03-services.md +98 -0
  84. package/kb/site/en/develop/cordis-tutorial/04-events.md +144 -0
  85. package/kb/site/en/develop/cordis-tutorial/05-config.md +84 -0
  86. package/kb/site/en/develop/cordis-tutorial/06-composition-and-hmr.md +113 -0
  87. package/kb/site/en/develop/cordis-tutorial/07-into-the-harness.md +107 -0
  88. package/kb/site/en/develop/cordis-tutorial/index.md +60 -0
  89. package/kb/site/en/develop/framework/events.md +145 -0
  90. package/kb/site/en/develop/framework/index.md +139 -0
  91. package/kb/site/en/develop/framework/service.md +150 -0
  92. package/kb/site/en/develop/practice/index.md +157 -0
  93. package/kb/site/en/develop/practice/llm-adapter.md +190 -0
  94. package/kb/site/en/guide/providers-custom-form.png +0 -0
  95. package/kb/site/en/guide/providers-models-page.png +0 -0
  96. package/kb/site/en/guide/providers.md +100 -0
  97. package/kb/site/en/guide/python-sdk.md +106 -0
  98. package/kb/site/en/guide/quickstart.md +32 -0
  99. package/kb/site/en/index.md +8 -0
  100. package/kb/site/en/reference/agent-lifecycle.md +86 -0
  101. package/kb/site/en/reference/capability-seams.md +475 -0
  102. package/kb/site/en/reference/config-catalog.md +3155 -0
  103. package/kb/site/en/reference/cookbook/adding-a-conversation-node.md +235 -0
  104. package/kb/site/en/reference/cookbook/adding-a-package.md +120 -0
  105. package/kb/site/en/reference/cookbook/adding-a-settings-card.md +102 -0
  106. package/kb/site/en/reference/cookbook/adding-a-tool.md +96 -0
  107. package/kb/site/en/reference/cookbook/adding-an-llm-adapter.md +45 -0
  108. package/kb/site/en/reference/cookbook/extension-cookbook.md +131 -0
  109. package/kb/site/en/reference/cordis-api/context.md +368 -0
  110. package/kb/site/en/reference/cordis-api/events.md +211 -0
  111. package/kb/site/en/reference/cordis-api/fiber.md +379 -0
  112. package/kb/site/en/reference/cordis-api/inherited.md +43 -0
  113. package/kb/site/en/reference/cordis-api/registry.md +156 -0
  114. package/kb/site/en/reference/cordis-api/service.md +106 -0
  115. package/kb/site/en/reference/cordis-primer.md +46 -0
  116. package/kb/site/en/reference/index.md +131 -0
  117. package/kb/site/en/reference/persistence-catalog.md +949 -0
  118. package/kb/site/en/reference/subsystems/approval.md +173 -0
  119. package/kb/site/en/reference/subsystems/client-modules.md +121 -0
  120. package/kb/site/en/reference/subsystems/code-runtime.md +194 -0
  121. package/kb/site/en/reference/subsystems/commands.md +190 -0
  122. package/kb/site/en/reference/subsystems/compaction.md +241 -0
  123. package/kb/site/en/reference/subsystems/core.md +1073 -0
  124. package/kb/site/en/reference/subsystems/credentials.md +136 -0
  125. package/kb/site/en/reference/subsystems/filesystem.md +498 -0
  126. package/kb/site/en/reference/subsystems/goal.md +280 -0
  127. package/kb/site/en/reference/subsystems/index.md +58 -0
  128. package/kb/site/en/reference/subsystems/invariants.md +91 -0
  129. package/kb/site/en/reference/subsystems/jobs.md +293 -0
  130. package/kb/site/en/reference/subsystems/llm-streaming.md +920 -0
  131. package/kb/site/en/reference/subsystems/lsp.md +205 -0
  132. package/kb/site/en/reference/subsystems/permission-presets.md +134 -0
  133. package/kb/site/en/reference/subsystems/persistence.md +388 -0
  134. package/kb/site/en/reference/subsystems/plan.md +90 -0
  135. package/kb/site/en/reference/subsystems/sandbox.md +221 -0
  136. package/kb/site/en/reference/subsystems/schedule.md +189 -0
  137. package/kb/site/en/reference/subsystems/scope.md +62 -0
  138. package/kb/site/en/reference/subsystems/session-projection.md +265 -0
  139. package/kb/site/en/reference/subsystems/session-query.md +498 -0
  140. package/kb/site/en/reference/subsystems/session-reference.md +111 -0
  141. package/kb/site/en/reference/subsystems/session-telemetry.md +197 -0
  142. package/kb/site/en/reference/subsystems/session-title.md +207 -0
  143. package/kb/site/en/reference/subsystems/session.md +852 -0
  144. package/kb/site/en/reference/subsystems/settings.md +313 -0
  145. package/kb/site/en/reference/subsystems/shell.md +306 -0
  146. package/kb/site/en/reference/subsystems/skills.md +334 -0
  147. package/kb/site/en/reference/subsystems/spill.md +120 -0
  148. package/kb/site/en/reference/subsystems/storage.md +232 -0
  149. package/kb/site/en/reference/subsystems/subagent.md +737 -0
  150. package/kb/site/en/reference/subsystems/subprocess.md +327 -0
  151. package/kb/site/en/reference/subsystems/system-prompt.md +210 -0
  152. package/kb/site/en/reference/subsystems/terminal.md +187 -0
  153. package/kb/site/en/reference/subsystems/token-meter.md +93 -0
  154. package/kb/site/en/reference/subsystems/tools.md +723 -0
  155. package/kb/site/en/reference/subsystems/typert.md +339 -0
  156. package/kb/site/en/reference/subsystems/user-questions.md +181 -0
  157. package/kb/site/en/reference/subsystems/web-server.md +111 -0
  158. package/kb/site/en/reference/subsystems/web.md +202 -0
  159. package/kb/site/en/reference/subsystems/workflow.md +281 -0
  160. package/kb/site/en/reference/subsystems/workspace.md +231 -0
  161. package/kb/site/en/reference/tool-catalog.md +1877 -0
  162. package/kb/site/en/reference/tool-execution-pipeline.md +66 -0
  163. package/kb/site/guide/providers-custom-form.zh.png +0 -0
  164. package/kb/site/guide/providers-models-page.zh.png +0 -0
  165. package/kb/site/guide/providers.md +100 -0
  166. package/kb/site/guide/python-sdk.md +106 -0
  167. package/kb/site/guide/quickstart.md +32 -0
  168. package/kb/site/index.md +8 -0
  169. package/kb/site/reference/agent-lifecycle.md +86 -0
  170. package/kb/site/reference/capability-seams.md +475 -0
  171. package/kb/site/reference/config-catalog.md +3154 -0
  172. package/kb/site/reference/cookbook/adding-a-conversation-node.md +235 -0
  173. package/kb/site/reference/cookbook/adding-a-package.md +120 -0
  174. package/kb/site/reference/cookbook/adding-a-settings-card.md +102 -0
  175. package/kb/site/reference/cookbook/adding-a-tool.md +98 -0
  176. package/kb/site/reference/cookbook/adding-an-llm-adapter.md +45 -0
  177. package/kb/site/reference/cookbook/extension-cookbook.md +133 -0
  178. package/kb/site/reference/cordis-api/context.md +368 -0
  179. package/kb/site/reference/cordis-api/events.md +211 -0
  180. package/kb/site/reference/cordis-api/fiber.md +379 -0
  181. package/kb/site/reference/cordis-api/inherited.md +43 -0
  182. package/kb/site/reference/cordis-api/registry.md +156 -0
  183. package/kb/site/reference/cordis-api/service.md +106 -0
  184. package/kb/site/reference/cordis-primer.md +52 -0
  185. package/kb/site/reference/index.md +135 -0
  186. package/kb/site/reference/persistence-catalog.md +949 -0
  187. package/kb/site/reference/subsystems/approval.md +173 -0
  188. package/kb/site/reference/subsystems/client-modules.md +121 -0
  189. package/kb/site/reference/subsystems/code-runtime.md +194 -0
  190. package/kb/site/reference/subsystems/commands.md +190 -0
  191. package/kb/site/reference/subsystems/compaction.md +241 -0
  192. package/kb/site/reference/subsystems/core.md +1081 -0
  193. package/kb/site/reference/subsystems/credentials.md +136 -0
  194. package/kb/site/reference/subsystems/filesystem.md +498 -0
  195. package/kb/site/reference/subsystems/goal.md +280 -0
  196. package/kb/site/reference/subsystems/index.md +58 -0
  197. package/kb/site/reference/subsystems/invariants.md +91 -0
  198. package/kb/site/reference/subsystems/jobs.md +293 -0
  199. package/kb/site/reference/subsystems/llm-streaming.md +926 -0
  200. package/kb/site/reference/subsystems/lsp.md +205 -0
  201. package/kb/site/reference/subsystems/permission-presets.md +134 -0
  202. package/kb/site/reference/subsystems/persistence.md +388 -0
  203. package/kb/site/reference/subsystems/plan.md +90 -0
  204. package/kb/site/reference/subsystems/sandbox.md +221 -0
  205. package/kb/site/reference/subsystems/schedule.md +189 -0
  206. package/kb/site/reference/subsystems/scope.md +62 -0
  207. package/kb/site/reference/subsystems/session-projection.md +265 -0
  208. package/kb/site/reference/subsystems/session-query.md +498 -0
  209. package/kb/site/reference/subsystems/session-reference.md +111 -0
  210. package/kb/site/reference/subsystems/session-telemetry.md +197 -0
  211. package/kb/site/reference/subsystems/session-title.md +207 -0
  212. package/kb/site/reference/subsystems/session.md +854 -0
  213. package/kb/site/reference/subsystems/settings.md +313 -0
  214. package/kb/site/reference/subsystems/shell.md +306 -0
  215. package/kb/site/reference/subsystems/skills.md +334 -0
  216. package/kb/site/reference/subsystems/spill.md +120 -0
  217. package/kb/site/reference/subsystems/storage.md +232 -0
  218. package/kb/site/reference/subsystems/subagent.md +739 -0
  219. package/kb/site/reference/subsystems/subprocess.md +327 -0
  220. package/kb/site/reference/subsystems/system-prompt.md +210 -0
  221. package/kb/site/reference/subsystems/terminal.md +187 -0
  222. package/kb/site/reference/subsystems/token-meter.md +93 -0
  223. package/kb/site/reference/subsystems/tools.md +723 -0
  224. package/kb/site/reference/subsystems/typert.md +339 -0
  225. package/kb/site/reference/subsystems/user-questions.md +181 -0
  226. package/kb/site/reference/subsystems/web-server.md +111 -0
  227. package/kb/site/reference/subsystems/web.md +202 -0
  228. package/kb/site/reference/subsystems/workflow.md +281 -0
  229. package/kb/site/reference/subsystems/workspace.md +231 -0
  230. package/kb/site/reference/tool-catalog.md +1880 -0
  231. package/kb/site/reference/tool-execution-pipeline.md +66 -0
  232. package/package.json +40 -0
  233. package/scripts/rebuild-index.mjs +88 -0
  234. package/skills/dsh-plugin-dev-kb.md +66 -0
@@ -0,0 +1,1073 @@
1
+ ---
2
+ editSource: "docs/subsystems/core.md"
3
+ outline: [2,3]
4
+ ---
5
+
6
+ # Core
7
+
8
+ The **core** subsystem is [`packages/core`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/README.md) — the packages every composition boots: the event-sourced session log, system-prompt assembly, the tool registry, the agent types, and the concrete loop that drives them. This page explains what the `agent`/`agent-loop` pair declares — how an agent is created and owned, and the `Agent` handle's delivery, cancellation, and interception contracts — plus the two type patterns every subsystem follows. The group's dedicated pages and the rest of the folder are indexed in the [subsystems README](./index.md).
9
+
10
+ ## The spine, package by package
11
+
12
+ A turn flows through the six packages in one loop: the driver in [`agent-loop`](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/core/agent-loop) claims a queued prompt, opens a turn on the [session log](./session.md) (`ctx.sessions`), assembles the request prefix through [system-prompt](./system-prompt.md) (`ctx.systemPrompt`) and derives history from the log, streams the model response through the [LLM seam](./llm-streaming.md), dispatches tool calls through the [tool registry](./tools.md) (`ctx.tools`), and appends every model-visible fact back onto the log before the next step derives from it. The conversation vocabulary the loop moves — `Message`, `ContentBlock`, `StreamChunk`, the model request — is declared by [`packages/llm`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/llm/README.md) and documented on [llm-streaming.md](./llm-streaming.md).
13
+
14
+ | Package | Owns | Page |
15
+ |---|---|---|
16
+ | `session/` | The append-only `SessionEvent` log and in-memory store — the single source of truth (`ctx.sessions`) | [session.md](./session.md) |
17
+ | `system-prompt/` | Prompt-section and tool-schema assembly (`ctx.systemPrompt`) | [system-prompt.md](./system-prompt.md) |
18
+ | `tools/` | The scoped tool registry and guarded execution pipeline (`ctx.tools`) | [tools.md](./tools.md) |
19
+ | `agent/` | The `Agent` interface, live registry, initiator scope, and `agent/*` event vocabulary (`ctx.agents`) | this page |
20
+ | `agent-loop/` | The concrete driver implementing the public `Agent` contract (`ctx.agentLoop`) | this page |
21
+ | `scope/` | The scoped-registration primitive the registries and loop build per-agent scoping on | [scope.md](./scope.md) |
22
+
23
+ `scope/` is the one non-service package: a dependency-free library (`createScope`/`scopeOf`/`scopeTarget`) that sits below `session/` and `system-prompt/` in the module graph precisely so they can consume it without a cycle. `agent-loop` is the one concrete implementation of the public `Agent` contract and lives here because it is the harness's default product loop; it runs each driver inside `ctx.agents.withInitiator()`. Extension plugins depend on `agent` — including when they need the initiating Agent — and never on `agent-loop` directly, so the loop stays swappable. The default composition that wires this spine into a runnable agent is [`examples/agent-spine-demo`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/examples/agent-spine-demo/README.md).
24
+
25
+ ## Creation and ownership
26
+
27
+ Consumers create agents through `ctx.agents` — `create()` builds a fresh session and agent under one caller-supplied `SessionId`, `resume()` loads a persisted session first — or declaratively through the loop's config entries. Programmatic creation returns the owner's handle:
28
+
29
+ Source: [`packages/core/agent/src/index.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/index.ts)
30
+
31
+ ```ts type-equiv
32
+ /**
33
+ * An owned agent plus its disposer, returned by {@link AgentRegistry.create} /
34
+ * {@link AgentRegistry.resume}. The disposer is a CAPABILITY: among consumers,
35
+ * only the holder can tear this agent down. The registered factory provider is
36
+ * also a structural owner because the scoped agent depends on that provider's
37
+ * service API; provider unload stops and drains every live handle it made.
38
+ * `dispose()` stops the loop, awaits its exit, unregisters the agent, removes
39
+ * its session from the store, and finally unwinds its scoped world.
40
+ *
41
+ * `ctx.agents.get(id)` still returns a bare {@link Agent} — the handle is
42
+ * exposed only to the consumer owner that created it; the structural provider
43
+ * reaches the same teardown internally. Config-created agents (the loop's own
44
+ * startup) are owned by the loop fiber and never need a handle.
45
+ */
46
+ interface AgentHandle {
47
+ agent: Agent
48
+ dispose(): Promise<void>
49
+ }
50
+ ```
51
+
52
+ `CreateAgentOptions` carries the shared identity and everything a fresh agent needs before publication: session metadata (`meta` — validated `cwd`, fork lineage, seed boundary, origin classification, delegation depth), an optional `seed` replay prefix for forks, per-agent `AgentOptions`, a creation-only cancellation `signal`, and `setup`. `ResumeAgentOptions` is the persisted-identity counterpart: `resumeSessionId`, `agentOptions`, `signal`, and `setup`. The `setup` callback (`AgentSetup`) composes the agent's scoped world while both ids are still unpublished — everything registered through `agentCtx` exists before `agent/created` and the first prompt assembly — and may return a synchronous commit invoked immediately before publication; a setup rejection, commit throw, or owner disposal rolls the transaction back without publishing either id.
53
+
54
+ `AgentFactory` is the creation interface behind the registry: the loop registers its factory via `ctx.agents.setFactory()`, so consumers use `ctx.agents` without depending on the concrete loop package. The exact `create`/`resume` signatures and rollback contracts are in the [generated section](#ctxagents--agentregistry) below.
55
+
56
+ ## The agent handle
57
+
58
+ `Agent` is the surface every plugin (UI, hooks, orchestrators) programs against; `ctx.agents.get(id)` returns it, and the [initiator scope](#initiating-agent) carries it. The concrete implementation is package-internal to dsh-agent-loop; nothing outside the loop depends on it. The unified `send` method exposes target and wakeup routing directly; `followup`, `steer`, and `inject` are fixed-preset aliases.
59
+
60
+ Source: [`packages/core/agent/src/types.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/types.ts)
61
+
62
+ ```ts type-equiv
63
+ /** Public live-agent handle. */
64
+ interface Agent {
65
+ /** The single identity shared with {@link session}. */
66
+ readonly id: SessionId
67
+ /** The provider route and model this agent's requests use. */
68
+ readonly options: AgentOptions
69
+ /** The live session this agent drives; its log is the durable source of truth. */
70
+ readonly session: Session
71
+ /** The agent-owned projection of durable pending work. */
72
+ readonly inbox: Inbox
73
+ /** The current lifecycle state, mirrored on every `agent/status` transition. */
74
+ readonly status: AgentStatus
75
+ /** Agent-scoped context; its contributions are agent-local, unwind on disposal, and reject registration afterward. */
76
+ readonly ctx: Context
77
+
78
+ /**
79
+ * Clear queued and steering work — unless `keepInbox` — and abort the active
80
+ * turn or between-turn task. The first cause wins for that activity. With no
81
+ * active activity, cancellation is a no-op and does not arm later work.
82
+ * @param cause - the stable caller intent carried by the active operation signal.
83
+ * @param options - cancellation options; `keepInbox` preserves pending work.
84
+ */
85
+ cancel(cause: AgentCancelCause, options?: CancelOptions): void
86
+
87
+ /**
88
+ * Resolve after the current whole-agent activity reaches quiescence. This
89
+ * follows replacement work started before the observed driver retires,
90
+ * but does not identify the settlement of any particular message.
91
+ * @returns fulfillment after no active driver or maintenance task remains.
92
+ */
93
+ whenIdle(): Promise<void>
94
+
95
+ /**
96
+ * Run one non-turn maintenance task from the true idle phase. The task starts
97
+ * synchronously after claiming that phase; later waking input remains in the
98
+ * inbox until the task settles, while public status stays `idle`.
99
+ * `whenIdle()` follows both the task and any waking work released behind it.
100
+ * @param task - operation whose fulfillment or rejection is preserved, with a signal aborted by {@link cancel}.
101
+ * @throws synchronously when turn-driving or another maintenance task already owns the agent.
102
+ * @returns the task promise.
103
+ */
104
+ runMaintenance<T>(task: (signal: AbortSignal) => Promise<T>): Promise<T>
105
+
106
+ /**
107
+ * Route identified input to an inbox boundary and optionally wake the driver.
108
+ * Waking input submitted after active cancellation is queued for the next
109
+ * turn and runs when the aborted activity converges to idle; a `disposed`
110
+ * cancel leaves it parked. A wake submitted while already idle always opens
111
+ * its turn boundary, even when its message is cleared before the driver
112
+ * claims ([cancel-convergence wake latch](../../../../.agents/notes/implemented/bug-fix/2026-08-07-cancel-convergence-wake-latch.md)).
113
+ * @param message - identified content and the source that supplied it.
114
+ * @param target - the preferred next-turn or next-step inbox boundary.
115
+ * @param wakeup - whether delivery may wake the driver.
116
+ */
117
+ send(message: UserMessage, target: InboxTarget, wakeup: boolean): void
118
+
119
+ /**
120
+ * Queue an ordinary follow-up turn and wake the driver. The item becomes the
121
+ * sole ordinary message of its own turn.
122
+ * @param message - identified prompt content and the source that supplied it.
123
+ */
124
+ followup(message: UserMessage): void
125
+
126
+ /**
127
+ * Submit steering for the nearest step. An idle driver starts a turn;
128
+ * a running driver consumes it at its next step boundary.
129
+ * A rejected step leaves steering parked in the inbox until the next
130
+ * wake; cancellation or disposal may discard pending steering.
131
+ * @param message - identified steering content and the source that supplied it.
132
+ */
133
+ steer(message: UserMessage): void
134
+
135
+ /**
136
+ * Queue model-facing context for the next pre-step without waking the
137
+ * driver. A running driver claims it at the nearest later step boundary;
138
+ * idle drivers leave it pending until follow-up or steering
139
+ * wakes them. It may miss a request whose pre-step already claimed its
140
+ * batch. Cancellation or disposal may discard pending context.
141
+ * @param message - identified injected context and the source that supplied it.
142
+ */
143
+ inject(message: UserMessage): void
144
+ }
145
+ ```
146
+
147
+ ```ts type-equiv
148
+ /**
149
+ * An agent's lifecycle state, emitted on every transition as `agent/status`:
150
+ * `idle` means no driver is active; `running` begins when waking input starts
151
+ * cancellable pre-step processing and lasts while the driver drains,
152
+ * closes, or checkpoints turns. Disposal removes the agent from its registry;
153
+ * it is not a third observable status.
154
+ */
155
+ type AgentStatus = 'idle' | 'running'
156
+ ```
157
+
158
+ `running` describes the driver-wide drain interval and may span consecutive queued turns; it does not prove a turn is still open. Disposal removes the agent from the registry and emits `agent/disposed`; it is not a terminal status value. `followup()` returns no handle: its `MessageId` identifies durable inbox insertion, claim, and discard facts, not a later assistant output or turn ending. `whenIdle()` observes the whole agent, so callers may call a receipt-to-idle interval a run only when they explicitly own that interval ([decision](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-07-30-followup-enqueue-and-owned-runs.md)).
159
+
160
+ ```ts type-equiv
161
+ /** Merge-extensible agent creation options. Persona belongs to system-prompt sections. */
162
+ interface AgentOptions {
163
+ /** Provider route (must have a registered adapter at call time). */
164
+ provider?: string
165
+ /** Model id interpreted by the selected provider adapter. */
166
+ model?: string
167
+ /** Maximum output tokens for each conversation-model request. */
168
+ maxTokens?: number
169
+ }
170
+ ```
171
+
172
+ Dispatch requires `provider` and `model` after `agent/request`. When present, `maxTokens` must be a positive safe integer and caps every conversation-model request; omission allows the exact-model adapter default to materialize before the request header, or otherwise leaves provider behavior unchanged. An agent-scoped `deployment:persona` prompt section may shadow the global default persona.
173
+
174
+ The inbox is the delivery vocabulary — two ordered pending-message lists the agent owns as a durable projection:
175
+
176
+ ```ts type-equiv
177
+ /** One of the two ordered pending-message lists owned by an agent. */
178
+ type InboxTarget = 'next-turn' | 'next-step'
179
+ ```
180
+
181
+ Every pending occurrence is its `UserMessage`; `MessageId` is the sole identity. `Inbox.append`, `prepend`, `replace`, `remove`, `clear`, `splice`, and `claim` record normalized durable `agent/inbox/spliced` mutations and reject duplicate pending ids. `replace(messageId, newMessage)` and `remove(messageId)` locate the pending message across both lists; replacement may change identity and emits the old message as discarded followed by the new message as inserted. Ordinary removals and `clear()` are cancellations. `claim(target)` removes the proposed step batch — all `next-step` input plus, at a turn boundary, one `next-turn` message — through pure deletion splices without emitting discarded notifications, and the loop separately emits per-message claimed notifications. Whole-queue consumers such as UI projections reconstruct `nextTurn` and `nextStep` from the durable splices, while consumers following one message use the exact `agent/inbox/inserted`, `claimed`, and `discarded` notifications.
182
+
183
+ Cancellation:
184
+
185
+ ```ts type-equiv
186
+ /** Options for {@link Agent.cancel}. */
187
+ interface CancelOptions {
188
+ /**
189
+ * Preserve queued and steering inbox items instead of discarding them. The
190
+ * active turn is still aborted, but un-started and pending work survives for a
191
+ * later turn and no canceled inbox splice is logged.
192
+ */
193
+ keepInbox?: boolean | undefined
194
+ }
195
+ ```
196
+
197
+ ```ts type-equiv
198
+ /** Why an active agent driver was cancelled. */
199
+ type AgentCancelCause =
200
+ | { readonly kind: 'user' }
201
+ | { readonly kind: 'parent' }
202
+ | { readonly kind: 'hook'; readonly reason: string }
203
+ | { readonly kind: 'disposed' }
204
+ ```
205
+
206
+ The cause is a TypeScript-enforced same-process input. An active cancellation holder copies it into the runtime-only `AbortSignal.reason`; a signal grants cooperating listeners no classification authority. Durable `turn/end` retains the coarse `{ kind: 'aborted' }` outcome; recording who requested cancellation would require a separate durable event rather than overloading the terminal result.
207
+
208
+ The [event taxonomy](../index.md#events) owns the `agent/*` lifecycle, checkpoint, and waterfall contracts. Turn and step boundaries are durable session events rather than agent emits.
209
+
210
+ ## Initiating Agent
211
+
212
+ The process-local initiator carried by `ctx.agents` is the exact `Agent` above, not a separate frame or copied identity. Ambient presence is neither liveness proof nor authorization; the [initiator-scope decision](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-07-15-agent-initiator-scope.md) defines its lifetime and scope rules.
213
+
214
+ ## Interception decisions
215
+
216
+ Pre-step decisions use the same identified `UserMessage` type as durable user-role input. The entered batch is authoritative and preserves every message's `id` and `source`. Hook bridges map their native decision fields onto this typed result.
217
+
218
+ Source: [`packages/core/agent/src/types.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/types.ts)
219
+
220
+ `agent/pre-step` receives one payload carrying the exclusive claimed batch (`messages`), the proposed step's coordinates (`turn`, `step`), and the current turn's cancellation `signal`. The initial proposal runs inside an open turn before any step; a tool continuation may submit an empty claimed batch between steps:
221
+
222
+ It returns a `PreStepDecision`. Reject opens no step. Enter supplies the complete message batch appended after `step/start`; claimed messages omitted by the final decision remain removed, while input inserted after the claim stays pending:
223
+
224
+ ```ts type-equiv
225
+ /** Whether and with which messages the loop enters a proposed step. */
226
+ type PreStepDecision =
227
+ | { kind: 'reject' }
228
+ | { kind: 'enter'; messages: UserMessage[] }
229
+ ```
230
+
231
+ `agent/request-error` runs after a failed model step closes and before its turn closes. Listeners can repair durable state or await policy work while the failed turn's signal is still live. A handling listener returns `{ kind: 'retry' }` without calling `next()`; the default `undefined` leaves the failure terminal.
232
+
233
+ ```ts type-equiv
234
+ /** Action returned by a listener that owns model-request recovery. */
235
+ type RequestErrorAction = { kind: 'retry' } | undefined
236
+ ```
237
+
238
+ `agent/pre-step` is the only serial listener chain before request derivation. `agent/turn-stopping` runs when a turn has no tool or steering continuation, before one final steering drain.
239
+
240
+ `agent/session-start` carries a `SessionStartSource` (why the session lifecycle began; a bridge keys its SessionStart matcher on it):
241
+
242
+ ```ts type-equiv
243
+ /** Why a session lifecycle began; seeded creates are `startup`, while persisted loads are `resume`. */
244
+ type SessionStartSource = 'startup' | 'resume' | 'clear' | 'compact'
245
+ ```
246
+
247
+ ## Sessions
248
+
249
+ A `Session` is an **append-only log** of typed `SessionEvent`s — the single source of truth. The LLM message history is *derived* from the log (`deriveMessages()`), not stored separately. Every entry carries a monotonic `seq`, a `time`, and a `type`-discriminated `data` payload; surface variants may also list cited earlier events in `sourceEventSeqs` and carry a `surfaceOp`.
250
+
251
+ The `SessionEvent` envelope's exact conditional fields, the twelve event variants (`turn/start`, `turn/end`, `step/start`, `step/end`, `user/message`, `assistant/chunk`, `assistant/message`, `tool/call`, `tool/result`, `steering/message`, `todo/write`, `request/header`), the `deriveMessages()` projection rules, the `TurnTrigger`/`TurnEndReason` reasons, and the execution-enclosure and standalone-event rules are on **[session.md](./session.md)**. How the log is made durable — the `SessionPersistence` interface, JSONL/SQLite backends, the `session/flush` checkpoint, crash recovery, and `SessionHeader` — is on **[persistence.md](./persistence.md)**.
252
+
253
+ ## `ToolDefinition`
254
+
255
+ The one pipeline-authoring type that is core: what every registered tool *is* — a model-facing `ToolSchema` plus an `execute` function and optional final-content and UI callbacks. A tool author rarely constructs it by hand (the `defineTool` DSL builds it with typed arguments), but it is the contract the registry holds and the loop dispatches through.
256
+
257
+ Its full fields, the `defineTool`/`ValueSchemaSpec`/`ParameterSchemaSpec` typed schema DSL, the `ToolExecution`/`ToolExecutionResult` waterfall types, and the tool-presentation UI types are on **[tools.md](./tools.md)**.
258
+
259
+ ## Repo-wide type patterns
260
+
261
+ Two patterns recur across every subsystem and are documented once, here.
262
+
263
+ <a id="the-map--derived-union-pattern"></a>
264
+
265
+ ### The `…Map → derived-union` pattern
266
+
267
+ Almost every extensible sum type in the harness follows one pattern: an interface keyed by a discriminant tag (the `…Map`), from which the union is derived with `keyof`. Plugins add variants by **declaration merging** — no edit to the owning package.
268
+
269
+ ```ts ignore-check
270
+ // The pattern, schematically:
271
+ interface ThingMap {
272
+ 'a': { kind: 'a'; /* … */ }
273
+ 'b': { kind: 'b'; /* … */ }
274
+ }
275
+ type ThingKind = keyof ThingMap // 'a' | 'b'
276
+ type Thing = ThingMap[keyof ThingMap] // the discriminated union
277
+
278
+ // A plugin extends it without touching the source package:
279
+ declare module '@deepseek-ai/dsh-llm' {
280
+ interface ThingMap {
281
+ 'c': { kind: 'c'; /* … */ }
282
+ }
283
+ }
284
+ ```
285
+
286
+ Six canonical maps use this pattern; a plugin author extends these:
287
+
288
+ | Map | Package | Derives | Catalog |
289
+ |---|---|---|---|
290
+ | `ContentBlockMap` | dsh-llm | `ContentBlock` | [llm-streaming.md](./llm-streaming.md#content-blocks-and-messages) |
291
+ | `MessageSourceMap` | dsh-llm | `MessageSource` | [llm-streaming.md](./llm-streaming.md#content-blocks-and-messages) |
292
+ | `FinishReasonMap` | dsh-llm | `FinishReason` | [llm-streaming.md](./llm-streaming.md#the-model-request-and-result) |
293
+ | `TurnTriggerMap` | dsh-session | `TurnTrigger` | [session.md](./session.md) |
294
+ | `TurnEndReasonMap` | dsh-session | `TurnEndReason` | [session.md](./session.md) |
295
+ | `SessionEventMap` | dsh-session | `SessionEvent` | [session.md](./session.md) |
296
+
297
+ Two large discriminated unions are the ones consumers `switch` over most: **`StreamChunk`** (the streaming protocol) and **`SessionEvent`** (the log entry). Per the repo convention, `switch` on the tag — don't chain `if`s — so each arm narrows and a typo'd tag fails to compile.
298
+
299
+ ### Branded IDs
300
+
301
+ IDs passed between packages are **branded** — structurally strings, but non-interchangeable at the type level (a `SessionId` cannot be passed where a `CallId` is expected). Construction goes through a per-type factory; comparison, logging, and JSON behave as ordinary strings.
302
+
303
+ The `Branded<B>` primitive lives in its own type-only package, [dsh-brand](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/util/brand) (no runtime code, no harness-package dependency), so any package can brand the ids it owns without depending on an unrelated capability package.
304
+
305
+ Source: [`packages/util/brand/src/index.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/util/brand/src/index.ts)
306
+
307
+ ```ts type-equiv
308
+ /** A string carrying a compile-time-only brand `B`. */
309
+ type Branded<B extends string> = string & { readonly [BRAND]: B }
310
+ ```
311
+
312
+ The two core IDs are `CallId` (correlates a tool call with its result; dsh-llm) and `SessionId` (the shared live agent and durable session identity; dsh-session). Capability packages brand their own ids too, such as `JobId` in [jobs.md](./jobs.md).
313
+
314
+ <!-- BEGIN GENERATED cordis-surface (gen-cordis-catalog.ts) — do not edit between markers -->
315
+
316
+ <a id="cordis-surface"></a>
317
+
318
+ ## Cordis API
319
+
320
+ Generated from source by `scripts/gen-cordis-catalog.ts` (verified fresh by `pnpm run verify-cordis-catalog` in doc-sync; regenerate with `pnpm run gen-cordis-catalog`) — this section is byte-identical in both language sides of the page. Signature blocks use a `ts cordis-catalog` fence and keep the original source JSDoc; dispatch modes are defined in the [primer](../cordis-primer.md#dispatch-modes), and the framework-inherited `ctx` API lives in [cordis-api/inherited.md](../cordis-api/inherited.md).
321
+
322
+ <a id="ctxagentdefaultmodel--agentdefaultmodelconfig"></a>
323
+
324
+ ### `ctx.agentDefaultModel` — `AgentDefaultModelConfig`
325
+
326
+ Owns the default model selection independently of any Host or transport. The composition entry remains usable without a settings provider; when one is mounted, its user layer is read live.
327
+
328
+ ```ts cordis-catalog
329
+ /**
330
+ * Read the current default model selection.
331
+ * @returns a detached provider, model, and optional reasoning selection.
332
+ */
333
+ currentSelection(): ModelSelection
334
+
335
+ /**
336
+ * Save the complete default model selection. A deployment without a settings
337
+ * provider keeps its composition entry.
338
+ * @param next - resolved selection accepted by an entry point.
339
+ * @returns fulfillment after the optional settings write settles.
340
+ */
341
+ async saveSelection(next: ModelSelection): Promise<void>
342
+ ```
343
+
344
+ Source: [`packages/core/agent-default-model/src/index.ts:64`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent-default-model/src/index.ts)
345
+
346
+ <a id="ctxagentloop--agentloop"></a>
347
+
348
+ ### `ctx.agentLoop` — `AgentLoop`
349
+
350
+ Concrete agent factory and driver service.
351
+
352
+ ```ts cordis-catalog
353
+ /**
354
+ * Create an agent and session under one caller-supplied identity, owned by
355
+ * the accessing fiber. Constructor-driven config calls mint a fresh combined
356
+ * id before entering this boundary.
357
+ * @param id - shared agent/session identity.
358
+ * @param options - concrete loop options.
359
+ * @param meta - optional fresh-session workspace metadata.
360
+ * @returns the published running agent.
361
+ */
362
+ create(id: SessionId, options: AgentOptions = {}, meta: Pick<SessionHeader, 'cwd'> = {}): Agent
363
+
364
+ /**
365
+ * Create an owned agent on a caller-supplied session id.
366
+ * @param ownerCtx - caller context that structurally owns the lifecycle.
367
+ * @param options - identities, session seed/metadata, loop options, setup, and cancellation.
368
+ * @returns the published handle.
369
+ */
370
+ async createAgent(ownerCtx: Context, options: CreateAgentOptions): Promise<AgentHandle>
371
+
372
+ /**
373
+ * Resume an owned agent from the configured persistence service.
374
+ * @param ownerCtx - caller context that owns load, setup, and the live lifecycle.
375
+ * @param options - persisted identity, loop options, setup, and cancellation.
376
+ * @returns the published handle.
377
+ */
378
+ async resume(ownerCtx: Context, options: ResumeAgentOptions): Promise<AgentHandle>
379
+ ```
380
+
381
+ Types: [SessionHeader](./persistence.md)
382
+
383
+ Source: [`packages/core/agent-loop/src/index.ts:296`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent-loop/src/index.ts)
384
+
385
+ <a id="ctxagentpresets--agentpresets"></a>
386
+
387
+ ### `ctx.agentPresets` — `AgentPresets`
388
+
389
+ Registry over the deployment's agent presets.
390
+
391
+ Discovery is unmemoized: `list()` and `resolve()` re-read the roots on every call so a preset authored while the process runs is visible immediately, and a preset deleted underneath a picker disappears from the next read.
392
+
393
+ ```ts cordis-catalog
394
+ /**
395
+ * Every preset the configured roots currently supply.
396
+ * @returns the presets, first-root-wins per id.
397
+ */
398
+ async list(): Promise<AgentPreset[]>
399
+
400
+ /**
401
+ * Resolve one preset by id.
402
+ *
403
+ * A broken preset resolves — deleting one, reading one, and reporting one
404
+ * all need the row — and the mounting paths refuse it AFTER resolution
405
+ * through {@link resolveMountable}.
406
+ * @param id - the preset id, or `undefined` for {@link defaultId}.
407
+ * @returns the resolved preset.
408
+ * @throws when no configured root supplies that id.
409
+ */
410
+ async resolve(id?: string): Promise<AgentPreset>
411
+
412
+ /**
413
+ * Compose one agent from a preset: ensure the preset's standing mount, then
414
+ * parent the agent's scope key to it so the mount's registrations and
415
+ * listeners cover this agent.
416
+ *
417
+ * Call from the agent factory's `setup(agentCtx)`; a rejection there rolls
418
+ * the agent creation back, so a broken preset never yields a half-composed
419
+ * session.
420
+ * @param agentCtx - the agent's scope context.
421
+ * @param id - the preset id, or `undefined` for {@link defaultId}.
422
+ * @returns the preset that was composed, for the caller to record.
423
+ * @throws when the preset is unknown or its composition is unusable.
424
+ */
425
+ async mount(agentCtx: Context, id?: string): Promise<AgentPreset>
426
+
427
+ /**
428
+ * Join one agent to the SAME standing composition another already runs on.
429
+ *
430
+ * This is how a child agent inherits its parent's capabilities. It is a bind,
431
+ * not a mount: the parent's generation is already composed, so the child gets
432
+ * that exact instance — the same plugin objects, the same tool registrations,
433
+ * the same prompt sections. Re-resolving the parent's preset by id instead
434
+ * would re-read the roster, and a composition file edited since the parent
435
+ * started would hand the child a DIFFERENT generation than the one its
436
+ * parent's history was produced under (and a preset deleted since would fail
437
+ * the child outright while its parent keeps running).
438
+ *
439
+ * Synchronous, and with no composition failure mode of its own — it reads no
440
+ * roster, mounts nothing, and touches no file — which is what lets a child
441
+ * creation window use it: the two in-process subagent drivers compose their
442
+ * children inside a synchronous `setup`. It still rejects a caller error, as
443
+ * the `@throws` below record.
444
+ *
445
+ * A parent that joined no preset — a rosterless deployment — yields no join
446
+ * and no error: there, the model-facing rows sit in the host composition and
447
+ * the child already sees them through the global layer.
448
+ * @param agentCtx - the joining agent's scope context.
449
+ * @param parentCtx - the scope context of the agent whose composition to join.
450
+ * @returns the preset id joined, or undefined when the parent joined none.
451
+ * @throws when `agentCtx` carries no scope, or has already joined a preset.
452
+ */
453
+ composeFrom(agentCtx: Context, parentCtx: Context): string | undefined
454
+
455
+ /**
456
+ * The preset one live agent runs on.
457
+ *
458
+ * Read from the live scope chain rather than from the session, so it answers
459
+ * for an agent whose session has not recorded a preset yet — a child agent
460
+ * whose durable header is being built from its parent's composition.
461
+ * @param agentCtx - the agent's scope context.
462
+ * @returns the preset id, or undefined when the agent joined none.
463
+ */
464
+ composedPreset(agentCtx: Context): string | undefined
465
+
466
+ /**
467
+ * Read one preset's composition text.
468
+ * @param id - the preset id.
469
+ * @returns the composition exactly as stored.
470
+ * @throws when no configured root supplies that id.
471
+ */
472
+ async read(id: string): Promise<string>
473
+
474
+ /**
475
+ * Create a locally authored preset by copying an existing one whole.
476
+ *
477
+ * Copy is the only authoring write. Composition text never crosses this
478
+ * seam: the source is named by id and its directory is copied as it stands,
479
+ * so the copy is exactly as loadable as its source and authoring grants no
480
+ * capability the roster did not already carry. The copy is NOT mounted to
481
+ * validate — a source that mounts today yields a copy that mounts today.
482
+ * @param from - the preset the copy starts from; shipped presets are the
483
+ * primary source, so any trust is accepted.
484
+ * @param id - the new preset's id, which becomes its directory name.
485
+ * @param name - display name for the copy; absent falls back to the id.
486
+ * @throws when the source is unknown, the id is unusable or already taken,
487
+ * or the deployment configures no writable root.
488
+ */
489
+ async copy(from: string, id: string, name?: string): Promise<void>
490
+
491
+ /**
492
+ * Delete a locally authored preset.
493
+ * @param id - the preset id.
494
+ * @throws when the preset is unknown or ships with the deployment.
495
+ */
496
+ async remove(id: string): Promise<void>
497
+
498
+ /**
499
+ * One agent's instance of a service its preset mounted.
500
+ *
501
+ * A preset publishes services behind `isolate` realms, which are invisible
502
+ * outside the group that declares them — including to the host. This is how a
503
+ * caller holding the agent reads one anyway: a request that is ABOUT a
504
+ * session but arrives from outside it, which is every browser RPC.
505
+ *
506
+ * Read addressing only. A host row that `inject`s a service cannot use this,
507
+ * because injection resolves before any session exists and has no agent to
508
+ * key by; such a service belongs on the host plane instead.
509
+ * @param agent - the agent whose composition to look inside.
510
+ * @param name - the service name as the preset's rows resolve it.
511
+ * @returns the agent's instance, or undefined when its preset mounts none.
512
+ */
513
+ serviceFor<K extends string & keyof Context>(agent: { ctx: Context }, name: K): Context[K] | undefined
514
+
515
+ /**
516
+ * Re-link one agent to a different preset's standing composition.
517
+ *
518
+ * Only valid while the agent has produced nothing: swapping tools mid
519
+ * conversation would leave logged tool calls the new composition cannot
520
+ * make. The CALLER owns that check — this method does not read session
521
+ * history.
522
+ *
523
+ * The swap is a parent re-link, not an unmount: standing mounts are shared
524
+ * and permanent, so the old composition stays for its other agents and the
525
+ * new one is ensured BEFORE the link moves. An unknown or unusable preset
526
+ * therefore throws with the agent exactly as it was — there is no torn-down
527
+ * state to restore. The re-link runs through the binding this roster kept
528
+ * from the agent's mount — dsh-scope's only re-link authority. An agent
529
+ * that never composed one has nothing to re-link: the switch is then the
530
+ * agent's first bind, exactly a mount.
531
+ * @param agentCtx - the agent's scope context.
532
+ * @param id - the preset to compose the agent from instead.
533
+ * @returns the preset now installed.
534
+ * @throws when the preset is unknown or its composition is unusable.
535
+ */
536
+ async recompose(agentCtx: Context, id: string): Promise<AgentPreset>
537
+
538
+ /**
539
+ * The standing scope key of one preset, for a host reader with no agent.
540
+ *
541
+ * A cold transcript read resolves tool presenters against the composition
542
+ * the session recorded, and the standing mount makes that possible without
543
+ * resuming anything: ensuring the mount composes plugins but starts no
544
+ * agent, no session, and no turn.
545
+ * @param id - the preset id, or `undefined` for {@link defaultId}.
546
+ * @returns the standing scope key readers pass as a registry view scope.
547
+ * @throws when the preset is unknown or its composition is unusable.
548
+ */
549
+ async standingKeyFor(id?: string): Promise<ScopeKey>
550
+ ```
551
+
552
+ Types: [ScopeKey](./scope.md)
553
+
554
+ Source: [`packages/preset/agent-presets/src/index.ts:82`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/preset/agent-presets/src/index.ts)
555
+
556
+ <a id="ctxagents--agentregistry"></a>
557
+
558
+ ### `ctx.agents` — `AgentRegistry`
559
+
560
+ Agent service (`ctx.agents`): tracks live agents and carries the initiating Agent through one process-local asynchronous driver chain. Agent *creation* is provided by whichever plugin implements the AgentFactory (`@deepseek-ai/dsh-agent-loop`), registered via setFactory.
561
+
562
+ Initiator methods provide same-process causal attribution only. Ambient presence is neither liveness proof nor authorization; subjects and owners remain explicit, as does identity at worker, process, persistence, and wire boundaries. Returned Promise boundaries drain during teardown, except a nested lineage that starts an owning-fiber unload is excluded from its own drain.
563
+
564
+ ```ts cordis-catalog
565
+ /**
566
+ * Read the Agent that initiated the inherited asynchronous driver chain.
567
+ * Use this optional form for logging, tracing, metrics, or host attribution
568
+ * that also supports agentless calls. When a parent creates a child, setup
569
+ * reports the causal parent while `agentCtx.agent` identifies the child.
570
+ * @returns the inherited Agent, or `undefined` outside an initiator boundary
571
+ * and inside an explicit clearing boundary.
572
+ * @throws when this service instance has been disposed.
573
+ */
574
+ currentInitiator(): Agent | undefined
575
+
576
+ /**
577
+ * Read the initiating Agent and fail when no initiator boundary is active.
578
+ * Use this for private helpers contractually below a driver, or for a
579
+ * deployment-owned outbound request whose contract forbids agentless calls.
580
+ * Generic or direct-call paths use optional lookup or explicit request fields.
581
+ * @returns the inherited Agent.
582
+ * @throws when no initiator is active or this service instance has been disposed.
583
+ */
584
+ requireInitiator(): Agent
585
+
586
+ /**
587
+ * Run an operation with one exact Agent as its process-local initiator. The
588
+ * exact synchronous value or Promise returned by the operation is preserved.
589
+ * Custom drivers and test harnesses wrap their complete returned foreground
590
+ * lifetime.
591
+ * A queue or wire receiver may establish this boundary only after validating
592
+ * explicit identity and resolving the exact live Agent; this method does neither.
593
+ * Detached work remains owned by the subsystem that starts it.
594
+ * @param agent - initiating Agent to inherit; presence is neither liveness proof nor authorization.
595
+ * @param operation - synchronous or asynchronous operation to invoke.
596
+ * @returns the exact value returned by `operation`.
597
+ * @throws when the initiator scope is closing/disposed, or when `operation` throws.
598
+ */
599
+ withInitiator<T>(agent: Agent, operation: () => T): T
600
+
601
+ /**
602
+ * Run an operation inside a boundary that hides any inherited initiating
603
+ * Agent. The exact synchronous value or Promise is preserved.
604
+ * Use this while creating lazy shared timers, queue pumps, pool maintenance,
605
+ * watchers, or exporters so they do not inherit the first Agent that happens
606
+ * to initialize them. It clears only initiator attribution, not explicit
607
+ * fields, and does not own or drain detached resources.
608
+ * @param operation - synchronous or asynchronous operation to invoke without an initiator.
609
+ * @returns the exact value returned by `operation`.
610
+ * @throws when the initiator scope is closing/disposed, or when `operation` throws.
611
+ */
612
+ withoutInitiator<T>(operation: () => T): T
613
+
614
+ /**
615
+ * Register the agent-creation factory (the loop calls this on construction,
616
+ * effect-scoped). A traced Cordis service is canonicalized to its concrete
617
+ * target; each create/resume call is then traced through that caller's
618
+ * context so ownership follows the caller without stacking proxy layers.
619
+ * Throws if a factory is already registered. Returns the disposer; on
620
+ * dispose the factory slot is cleared.
621
+ * @param factory - the loop-owned factory {@link create}/{@link resume} delegate to.
622
+ * @returns the disposer that clears the factory slot. The exact
623
+ * Cordis effect disposer (single-shot): composite (generator) effects may
624
+ * yield it directly — exact identity nests the teardown in order.
625
+ */
626
+ setFactory(factory: AgentFactory): () => void
627
+
628
+ /**
629
+ * Create and publish a new agent through the registered factory.
630
+ * Distinct from {@link register} (which records an already-constructed
631
+ * agent): this constructs the agent and its session. Rejects if no factory is
632
+ * registered or creation/setup fails. The resolved {@link AgentHandle} lets
633
+ * the owner tear down exactly this agent.
634
+ * @param options - shared identity, session seed/metadata, and agent options.
635
+ * @returns the handle after setup, rollback-covered publication, and loop start complete.
636
+ */
637
+ async create(options: CreateAgentOptions): Promise<AgentHandle>
638
+
639
+ /**
640
+ * Load a persisted session and resume an agent on it through the registered
641
+ * factory. Rejects if no factory is registered; the factory rejects if
642
+ * session persistence is not configured or persistence/setup fails.
643
+ * @param options - persisted identity, configuration, and optional setup.
644
+ * @returns the handle after setup, rollback-covered publication, and loop start complete.
645
+ */
646
+ async resume(options: ResumeAgentOptions): Promise<AgentHandle>
647
+
648
+ /**
649
+ * Register a live agent. Throws if an agent with the same id is already
650
+ * registered. Emits `agent/created` on registration and `agent/disposed`
651
+ * when the calling fiber is disposed — both with the agent's scope carrier
652
+ * (`scopeTarget(agent, agent)`): the subject is the agent in hand, so the
653
+ * emits are scope-filtered regardless of which context invoked `register`
654
+ * (calling through `agent.ctx` scopes EFFECTS; dispatch scoping always
655
+ * requires passing the carrier). Returns the disposer.
656
+ * @param agent - the already-constructed agent to record in the store.
657
+ * @returns the EXACT Cordis effect disposer (single-shot; a repeat call
658
+ * returns undefined without awaiting an in-flight teardown). Exact
659
+ * identity is load-bearing: a composite (generator) effect that owns a
660
+ * teardown ORDER — the agent factory's lifecycle chain — must yield THIS
661
+ * function so Cordis nests the unregistration at that yield position;
662
+ * yielding a wrapper would leave it disposing as a concurrent sibling on
663
+ * owner unload, unregistering the agent (and emitting `agent/disposed`)
664
+ * while its final turn is still draining.
665
+ */
666
+ register(agent: Agent): () => void
667
+
668
+ /**
669
+ * Insert an already-constructed agent without announcing it. This is the
670
+ * advanced ordered-lifecycle primitive used by the async agent factory: it
671
+ * first completes setup while the agent is unpublished, then assigns the
672
+ * returned detach closure into its pre-installed composite teardown before
673
+ * calling {@link announce}. Ordinary callers use {@link register}.
674
+ * @param agent - the prepared, unpublished agent.
675
+ * @param owner - live agent whose scoped context created this agent, or
676
+ * undefined for a top-level runtime root. This is runtime ownership, not
677
+ * the resumed session's durable parent lineage.
678
+ * @returns an idempotent closure that removes this exact entry and emits
679
+ * `agent/disposed` with listener failures contained. When called from a
680
+ * synchronous `agent/created` listener, removal and disposal wait until
681
+ * that creation dispatch unwinds.
682
+ */
683
+ enter(agent: Agent, owner: Agent | undefined): () => void
684
+
685
+ /**
686
+ * Announce an agent previously inserted with {@link enter}.
687
+ * @param agent - the live inserted agent to announce.
688
+ * @throws if `agent` is not the exact live registry entry for its id, or its
689
+ * creation announcement already began (including a reentrant call from a
690
+ * creation listener).
691
+ */
692
+ announce(agent: Agent): void
693
+
694
+ /**
695
+ * Look up a live agent.
696
+ * @param id - the shared agent/session id to look up.
697
+ * @returns the agent, or undefined when no live agent has that id.
698
+ */
699
+ get(id: SessionId): Agent | undefined
700
+
701
+ /**
702
+ * Test whether a live agent was created through one exact parent agent's
703
+ * scoped context. Runtime ownership is independent of durable session
704
+ * lineage and remains unambiguous when unrelated providers reuse an id.
705
+ * @param id - the candidate child agent's shared agent/session id.
706
+ * @param owner - the expected runtime creator agent.
707
+ * @returns true only while the exact child entry is live under that owner.
708
+ */
709
+ isOwnedBy(id: SessionId, owner: Agent): boolean
710
+
711
+ /**
712
+ * All live agents, in registration order.
713
+ * @returns a fresh array; mutating it does not affect the registry.
714
+ */
715
+ list(): Agent[]
716
+
717
+ /**
718
+ * All live top-level agents in registration order. A top-level agent was
719
+ * created without an owning agent context; durable session lineage does not
720
+ * affect this runtime relation, so a resumed fork may still be a root.
721
+ * @returns a fresh array; mutating it does not affect the registry.
722
+ */
723
+ roots(): Agent[]
724
+ ```
725
+
726
+ Source: [`packages/core/agent/src/index.ts:256`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/index.ts)
727
+
728
+ <a id="agent-events"></a>
729
+
730
+ ### `agent/*` events
731
+
732
+ <a id="agentcreated--emit"></a>
733
+
734
+ #### `agent/created` — emit
735
+
736
+ A fully configured agent and live session were published. Setup is composition-only; `agent/session-start` is the first startup-driving extension point. Synchronous listener failure vetoes publication, while returned-promise rejection is reported. Detach requested during dispatch waits until every creation listener has observed the stable entry.
737
+
738
+ ```ts cordis-catalog
739
+ /**
740
+ * A fully configured agent and live session were published. Setup is
741
+ * composition-only; `agent/session-start` is the first startup-driving extension point.
742
+ * Synchronous listener failure vetoes publication, while returned-promise
743
+ * rejection is reported. Detach requested during dispatch waits until every
744
+ * creation listener has observed the stable entry.
745
+ * @param payload.agent - the newly registered agent with its live session and completed setup.
746
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
747
+ * @mode emit
748
+ */
749
+ 'agent/created'(this: Scoped<Agent>, payload: { agent: Agent }): void
750
+ ```
751
+
752
+ Types: [Scoped](./scope.md)
753
+
754
+ Source: [`packages/core/agent/src/runtime-types.ts:159`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
755
+
756
+ <a id="agentdisposed--emit"></a>
757
+
758
+ #### `agent/disposed` — emit
759
+
760
+ An agent left the registry; AgentLoop emits this after driver quiescence and scoped-registration unwind, but before session detachment. Custom registry users own their driver-ordering contract.
761
+
762
+ ```ts cordis-catalog
763
+ /**
764
+ * An agent left the registry; AgentLoop emits this after driver quiescence
765
+ * and scoped-registration unwind, but before session detachment. Custom
766
+ * registry users own their driver-ordering contract.
767
+ * @param payload.agent - the exact agent removed from the registry.
768
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
769
+ * @mode emit
770
+ */
771
+ 'agent/disposed'(this: Scoped<Agent>, payload: { agent: Agent }): void
772
+ ```
773
+
774
+ Types: [Scoped](./scope.md)
775
+
776
+ Source: [`packages/core/agent/src/runtime-types.ts:168`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
777
+
778
+ <a id="agenterror--emit"></a>
779
+
780
+ #### `agent/error` — emit
781
+
782
+ A step or turn errored. The machine reports a failure here even when the error has no in-turn position for a durable record.
783
+
784
+ ```ts cordis-catalog
785
+ /**
786
+ * A step or turn errored. The machine reports a failure here even when
787
+ * the error has no in-turn position for a durable record.
788
+ * @param payload.agent - the agent whose turn errored.
789
+ * @param payload.turn - the turn in which the failure surfaced.
790
+ * @param payload.step - the step at which the failure surfaced.
791
+ * @param payload.error - the failure, verbatim.
792
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
793
+ * @mode emit
794
+ */
795
+ 'agent/error'(this: Scoped<Agent>, payload: { agent: Agent; turn: number; step: number; error: unknown }): void
796
+ ```
797
+
798
+ Types: [Scoped](./scope.md)
799
+
800
+ Source: [`packages/core/agent/src/runtime-types.ts:290`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
801
+
802
+ <a id="agentinboxclaimed--emit"></a>
803
+
804
+ #### `agent/inbox/claimed` — emit
805
+
806
+ One message left the inbox inside its open turn. If the proposed step is rejected, the claimed message ends here: it is neither discarded nor re-emitted as a user/message, and the turn closes without a step.
807
+
808
+ ```ts cordis-catalog
809
+ /**
810
+ * One message left the inbox inside its open turn. If the proposed step
811
+ * is rejected, the claimed message ends here: it is neither discarded nor
812
+ * re-emitted as a user/message, and the turn closes without a step.
813
+ * @param payload.agent - the agent whose inbox changed.
814
+ * @param payload.message - the claimed message.
815
+ * @param payload.turn - the owning turn.
816
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
817
+ * @mode emit
818
+ */
819
+ 'agent/inbox/claimed'(this: Scoped<Agent>, payload: { agent: Agent; message: UserMessage; turn: number }): void
820
+ ```
821
+
822
+ Types: [Scoped](./scope.md) · [UserMessage](./session.md)
823
+
824
+ Source: [`packages/core/agent/src/runtime-types.ts:197`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
825
+
826
+ <a id="agentinboxdiscarded--emit"></a>
827
+
828
+ #### `agent/inbox/discarded` — emit
829
+
830
+ One message was discarded from the live inbox.
831
+
832
+ ```ts cordis-catalog
833
+ /**
834
+ * One message was discarded from the live inbox.
835
+ * @param payload.agent - the agent whose inbox changed.
836
+ * @param payload.message - the discarded message.
837
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
838
+ * @mode emit
839
+ */
840
+ 'agent/inbox/discarded'(this: Scoped<Agent>, payload: { agent: Agent; message: UserMessage }): void
841
+ ```
842
+
843
+ Types: [Scoped](./scope.md) · [UserMessage](./session.md)
844
+
845
+ Source: [`packages/core/agent/src/runtime-types.ts:205`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
846
+
847
+ <a id="agentinboxinserted--emit"></a>
848
+
849
+ #### `agent/inbox/inserted` — emit
850
+
851
+ One message entered the live inbox.
852
+
853
+ ```ts cordis-catalog
854
+ /**
855
+ * One message entered the live inbox.
856
+ * @param payload.agent - the agent whose inbox changed.
857
+ * @param payload.message - the inserted message.
858
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
859
+ * @mode emit
860
+ */
861
+ 'agent/inbox/inserted'(this: Scoped<Agent>, payload: { agent: Agent; message: UserMessage }): void
862
+ ```
863
+
864
+ Types: [Scoped](./scope.md) · [UserMessage](./session.md)
865
+
866
+ Source: [`packages/core/agent/src/runtime-types.ts:186`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
867
+
868
+ <a id="agentpre-step--waterfall"></a>
869
+
870
+ #### `agent/pre-step` — waterfall
871
+
872
+ Reject a proposed step or replace the messages that enter it. Calling `next()` preserves the current messages.
873
+
874
+ ```ts cordis-catalog
875
+ /**
876
+ * Reject a proposed step or replace the messages that enter it. Calling
877
+ * `next()` preserves the current messages.
878
+ * @param payload.agent - the agent proposing the step.
879
+ * @param payload.messages - messages removed from the inbox for this step.
880
+ * @param payload.turn - the turn that will own the step.
881
+ * @param payload.step - the step proposed by the loop.
882
+ * @param payload.signal - the current turn's cancellation signal.
883
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
884
+ * @mode waterfall
885
+ */
886
+ 'agent/pre-step'(this: Scoped<Agent>, payload: { agent: Agent; messages: UserMessage[]; turn: number; step: number; signal: AbortSignal }, next: () => Promise<PreStepDecision>): Promise<PreStepDecision>
887
+ ```
888
+
889
+ Types: [Scoped](./scope.md) · [UserMessage](./session.md)
890
+
891
+ Source: [`packages/core/agent/src/runtime-types.ts:231`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
892
+
893
+ <a id="agentrequest--waterfall"></a>
894
+
895
+ #### `agent/request` — waterfall
896
+
897
+ Replace the frozen call configuration. `await next()` yields the config the machine would use (agent options on the first request, the logged header afterwards); return a replacement to switch. Model-visible content must use logged channels; this waterfall cannot mutate messages.
898
+
899
+ ```ts cordis-catalog
900
+ /**
901
+ * Replace the frozen call configuration. `await next()` yields the config
902
+ * the machine would use (agent options on the first request, the logged
903
+ * header afterwards); return a replacement to switch. Model-visible
904
+ * content must use logged channels; this waterfall cannot mutate messages.
905
+ * @param payload.agent - the agent making the model call.
906
+ * @param payload.turn - the open turn number.
907
+ * @param payload.step - the step whose request this is.
908
+ * @param payload.signal - the current turn's explicit abort signal.
909
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
910
+ * @mode waterfall
911
+ */
912
+ 'agent/request'(this: Scoped<Agent>, payload: { agent: Agent; turn: number; step: number; signal: AbortSignal }, next: () => Promise<LlmCallConfig>): Promise<LlmCallConfig>
913
+ ```
914
+
915
+ Types: [LlmCallConfig](./llm-streaming.md) · [Scoped](./scope.md)
916
+
917
+ Source: [`packages/core/agent/src/runtime-types.ts:244`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
918
+
919
+ <a id="agentrequest-error--waterfall"></a>
920
+
921
+ #### `agent/request-error` — waterfall
922
+
923
+ Handle one failed model-request attempt before the loop retries or closes its step. A listener returns `{ kind: 'retry' }` without calling `next()` when it owns recovery, or calls `next()` to delegate. The default `undefined` leaves the failure terminal.
924
+
925
+ ```ts cordis-catalog
926
+ /**
927
+ * Handle one failed model-request attempt before the loop retries or closes
928
+ * its step. A listener returns `{ kind: 'retry' }` without calling `next()`
929
+ * when it owns recovery, or calls `next()` to delegate. The default
930
+ * `undefined` leaves the failure terminal.
931
+ * @param payload.agent - the agent whose request failed.
932
+ * @param payload.turn - the turn containing the failed request.
933
+ * @param payload.step - the step containing the failed request attempt.
934
+ * @param payload.provider - the provider selected for the failed request.
935
+ * @param payload.failure - serializable facts normalized at the final adapter boundary.
936
+ * @param payload.retryPolicy - the policy of the adapter registration that served the failed request.
937
+ * @param payload.signal - the turn abort signal.
938
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
939
+ * @mode waterfall
940
+ */
941
+ 'agent/request-error'(this: Scoped<Agent>, payload: { agent: Agent; turn: number; step: number; provider: string; failure: LlmFailure; retryPolicy: ResolvedRetryPolicy | undefined; signal: AbortSignal }, next: () => Promise<RequestErrorAction>): Promise<RequestErrorAction>
942
+ ```
943
+
944
+ Types: [LlmFailure](./llm-streaming.md) · [ResolvedRetryPolicy](./llm-streaming.md) · [Scoped](./scope.md)
945
+
946
+ Source: [`packages/core/agent/src/runtime-types.ts:260`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
947
+
948
+ <a id="agentsession-start--emit"></a>
949
+
950
+ #### `agent/session-start` — emit
951
+
952
+ The session lifecycle began, once before the first turn. Use `agent.inject()` to seed model-facing context. This is a notification, not a veto; disposal requested by a lifecycle owner is rechecked before the driver starts.
953
+
954
+ ```ts cordis-catalog
955
+ /**
956
+ * The session lifecycle began, once before the first turn. Use
957
+ * `agent.inject()` to seed model-facing context. This is a notification, not
958
+ * a veto; disposal requested by a lifecycle owner is rechecked before the
959
+ * driver starts.
960
+ * @param payload.agent - the agent whose session lifecycle began.
961
+ * @param payload.source - why the session started (fresh startup, resume, …).
962
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
963
+ * @mode emit
964
+ */
965
+ 'agent/session-start'(this: Scoped<Agent>, payload: { agent: Agent; source: SessionStartSource }): void
966
+ ```
967
+
968
+ Types: [Scoped](./scope.md)
969
+
970
+ Source: [`packages/core/agent/src/runtime-types.ts:217`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
971
+
972
+ <a id="agentstatus--emit"></a>
973
+
974
+ #### `agent/status` — emit
975
+
976
+ Agent status changed (`idle` ⇄ `running`). A waking delivery enters `running` synchronously after reserving cancellation; `idle` means no driver remains scheduled or active.
977
+
978
+ ```ts cordis-catalog
979
+ /**
980
+ * Agent status changed (`idle` ⇄ `running`). A waking delivery enters
981
+ * `running` synchronously after reserving cancellation; `idle` means no
982
+ * driver remains scheduled or active.
983
+ * @param payload.agent - the agent whose status flipped.
984
+ * @param payload.status - the status just entered (the transition's destination).
985
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
986
+ * @mode emit
987
+ */
988
+ 'agent/status'(this: Scoped<Agent>, payload: { agent: Agent; status: AgentStatus }): void
989
+ ```
990
+
991
+ Types: [Scoped](./scope.md)
992
+
993
+ Source: [`packages/core/agent/src/runtime-types.ts:178`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
994
+
995
+ <a id="agentturn-stopping--serial"></a>
996
+
997
+ #### `agent/turn-stopping` — serial
998
+
999
+ The turn is about to close: the model owes no response (no live tool calls, no fresh steering). Awaited before the boundary commits — a listener that objects steers (`agent.steer(...)`) and the machine re-reads its inbox: fresh steering runs another step, none closes the turn. Data decides, so listener order cannot change the outcome. The inverse control (stop a tool loop early) is data too: a tool result carrying `concludesTurn` ends the turn at its step. The conclusion never short-circuits already-submitted next-step work: same-step `additionalContexts` or racing steering still runs, and the turn closes only when that inbox drains.
1000
+
1001
+ ```ts cordis-catalog
1002
+ /**
1003
+ * The turn is about to close: the model owes no response (no live tool
1004
+ * calls, no fresh steering). Awaited before the boundary commits — a
1005
+ * listener that objects steers (`agent.steer(...)`) and the machine
1006
+ * re-reads its inbox: fresh steering runs another step, none closes the
1007
+ * turn. Data decides, so listener order cannot change the outcome. The
1008
+ * inverse control (stop a tool loop early) is data too: a tool result
1009
+ * carrying `concludesTurn` ends the turn at its step. The conclusion
1010
+ * never short-circuits already-submitted next-step work: same-step
1011
+ * `additionalContexts` or racing steering still runs, and the turn
1012
+ * closes only when that inbox drains.
1013
+ * @param payload.agent - the agent whose turn is at its stop boundary.
1014
+ * @param payload.turn - the turn about to close.
1015
+ * @param payload.signal - the current turn's explicit abort signal.
1016
+ * Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners receive only that agent.
1017
+ * @mode serial
1018
+ */
1019
+ 'agent/turn-stopping'(this: Scoped<Agent>, payload: { agent: Agent; turn: number; signal: AbortSignal }): Promise<void> | void
1020
+ ```
1021
+
1022
+ Types: [Scoped](./scope.md)
1023
+
1024
+ Source: [`packages/core/agent/src/runtime-types.ts:278`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent/src/runtime-types.ts)
1025
+
1026
+ <a id="agent-loop-events"></a>
1027
+
1028
+ ### `agent-loop/*` events
1029
+
1030
+ <a id="agent-loopconfig-start-failed--emit"></a>
1031
+
1032
+ #### `agent-loop/config-start-failed` — emit
1033
+
1034
+ A declarative agent entry failed before it could publish a live agent. Consumers that buffer work for the configured identity use this transient signal to reject that work instead of waiting forever. Normal factory teardown suppresses failures from the cancelled startup attempt.
1035
+
1036
+ ```ts cordis-catalog
1037
+ /**
1038
+ * A declarative agent entry failed before it could publish a live agent.
1039
+ * Consumers that buffer work for the configured identity use this
1040
+ * transient signal to reject that work instead of waiting forever. Normal
1041
+ * factory teardown suppresses failures from the cancelled startup attempt.
1042
+ * @param payload.sessionId - exact shared agent/session identity that failed startup.
1043
+ * @param payload.error - persistence, setup, or publication failure.
1044
+ * @mode emit
1045
+ */
1046
+ 'agent-loop/config-start-failed'(payload: { sessionId: SessionId; error: unknown }): void
1047
+ ```
1048
+
1049
+ Source: [`packages/core/agent-loop/src/index.ts:183`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/agent-loop/src/index.ts)
1050
+
1051
+ <a id="agent-preset-events"></a>
1052
+
1053
+ ### `agent-preset/*` events
1054
+
1055
+ <a id="agent-presetselected--emit"></a>
1056
+
1057
+ #### `agent-preset/selected` — emit
1058
+
1059
+ One session committed a different agent preset to its durable log. Consumers invalidate only state derived from that session's composition.
1060
+
1061
+ ```ts cordis-catalog
1062
+ /**
1063
+ * One session committed a different agent preset to its durable log.
1064
+ * Consumers invalidate only state derived from that session's composition.
1065
+ * @mode emit
1066
+ * @param sessionId - the session whose composition changed.
1067
+ * @param agentPreset - the preset recorded by the committed selection.
1068
+ */
1069
+ 'agent-preset/selected'(sessionId: SessionId, agentPreset: string): void
1070
+ ```
1071
+
1072
+ Source: [`packages/preset/agent-presets/src/types.ts:13`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/preset/agent-presets/src/types.ts)
1073
+ <!-- END GENERATED cordis-surface -->