subharness 0.0.7 → 0.0.9

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 (273) hide show
  1. package/README.md +18 -6
  2. package/dist/adapters/claude-events.d.ts +71 -0
  3. package/dist/adapters/claude-events.js +860 -0
  4. package/dist/adapters/claude-events.js.map +1 -0
  5. package/dist/adapters/claude-worker-client.d.ts +11 -0
  6. package/dist/adapters/claude-worker-client.js +219 -5
  7. package/dist/adapters/claude-worker-client.js.map +1 -1
  8. package/dist/adapters/claude-worker-protocol.d.ts +58 -0
  9. package/dist/adapters/claude-worker-protocol.js.map +1 -1
  10. package/dist/adapters/claude-worker.js +48 -3
  11. package/dist/adapters/claude-worker.js.map +1 -1
  12. package/dist/adapters/claude.d.ts +5 -1
  13. package/dist/adapters/claude.js +14 -2
  14. package/dist/adapters/claude.js.map +1 -1
  15. package/dist/adapters/codex-events.d.ts +52 -0
  16. package/dist/adapters/codex-events.js +672 -0
  17. package/dist/adapters/codex-events.js.map +1 -0
  18. package/dist/adapters/codex-turn-failure.d.ts +2 -0
  19. package/dist/adapters/codex-turn-failure.js +116 -0
  20. package/dist/adapters/codex-turn-failure.js.map +1 -0
  21. package/dist/adapters/codex.js +44 -7
  22. package/dist/adapters/codex.js.map +1 -1
  23. package/dist/adapters/copilot-events.d.ts +68 -0
  24. package/dist/adapters/copilot-events.js +650 -0
  25. package/dist/adapters/copilot-events.js.map +1 -0
  26. package/dist/adapters/copilot.js +24 -4
  27. package/dist/adapters/copilot.js.map +1 -1
  28. package/dist/adapters/cursor-acp-events.d.ts +36 -0
  29. package/dist/adapters/cursor-acp-events.js +251 -0
  30. package/dist/adapters/cursor-acp-events.js.map +1 -0
  31. package/dist/adapters/cursor-cli-session.d.ts +1 -0
  32. package/dist/adapters/cursor-cli-session.js +26 -5
  33. package/dist/adapters/cursor-cli-session.js.map +1 -1
  34. package/dist/adapters/cursor-cli.js +5 -0
  35. package/dist/adapters/cursor-cli.js.map +1 -1
  36. package/dist/adapters/cursor-sdk-events.d.ts +30 -0
  37. package/dist/adapters/cursor-sdk-events.js +233 -0
  38. package/dist/adapters/cursor-sdk-events.js.map +1 -0
  39. package/dist/adapters/cursor-session.js +56 -7
  40. package/dist/adapters/cursor-session.js.map +1 -1
  41. package/dist/adapters/cursor-startup.js +8 -2
  42. package/dist/adapters/cursor-startup.js.map +1 -1
  43. package/dist/adapters/event-normalizer.d.ts +57 -0
  44. package/dist/adapters/event-normalizer.js +143 -0
  45. package/dist/adapters/event-normalizer.js.map +1 -0
  46. package/dist/adapters/event-secrets.d.ts +17 -0
  47. package/dist/adapters/event-secrets.js +28 -0
  48. package/dist/adapters/event-secrets.js.map +1 -0
  49. package/dist/adapters/event-types.d.ts +58 -0
  50. package/dist/adapters/event-types.js +2 -0
  51. package/dist/adapters/event-types.js.map +1 -0
  52. package/dist/adapters/fx-events.d.ts +37 -0
  53. package/dist/adapters/fx-events.js +393 -0
  54. package/dist/adapters/fx-events.js.map +1 -0
  55. package/dist/adapters/fx-rpc.d.ts +2 -0
  56. package/dist/adapters/fx-rpc.js +11 -5
  57. package/dist/adapters/fx-rpc.js.map +1 -1
  58. package/dist/adapters/fx.js +73 -8
  59. package/dist/adapters/fx.js.map +1 -1
  60. package/dist/adapters/opencode-events.d.ts +58 -0
  61. package/dist/adapters/opencode-events.js +653 -0
  62. package/dist/adapters/opencode-events.js.map +1 -0
  63. package/dist/adapters/opencode-http.d.ts +1 -0
  64. package/dist/adapters/opencode-http.js +8 -7
  65. package/dist/adapters/opencode-http.js.map +1 -1
  66. package/dist/adapters/opencode.js +50 -9
  67. package/dist/adapters/opencode.js.map +1 -1
  68. package/dist/adapters/rpc.d.ts +2 -0
  69. package/dist/adapters/rpc.js +11 -5
  70. package/dist/adapters/rpc.js.map +1 -1
  71. package/dist/adapters/types.d.ts +2 -0
  72. package/dist/adapters/types.js.map +1 -1
  73. package/dist/cli/args.d.ts +3 -1
  74. package/dist/cli/args.js +25 -1
  75. package/dist/cli/args.js.map +1 -1
  76. package/dist/cli/dashboard-client.d.ts +1 -0
  77. package/dist/cli/dashboard-client.js +13 -1
  78. package/dist/cli/dashboard-client.js.map +1 -1
  79. package/dist/cli/dashboard-controller.js +6 -7
  80. package/dist/cli/dashboard-controller.js.map +1 -1
  81. package/dist/cli/dashboard-detail-view.d.ts +14 -8
  82. package/dist/cli/dashboard-detail-view.js +15 -44
  83. package/dist/cli/dashboard-detail-view.js.map +1 -1
  84. package/dist/cli/dashboard-history-view.d.ts +3 -12
  85. package/dist/cli/dashboard-history-view.js +18 -82
  86. package/dist/cli/dashboard-history-view.js.map +1 -1
  87. package/dist/cli/dashboard-live.d.ts +32 -0
  88. package/dist/cli/dashboard-live.js +177 -0
  89. package/dist/cli/dashboard-live.js.map +1 -0
  90. package/dist/cli/dashboard-renderer.d.ts +21 -1
  91. package/dist/cli/dashboard-renderer.js +85 -21
  92. package/dist/cli/dashboard-renderer.js.map +1 -1
  93. package/dist/cli/dashboard-steps.d.ts +53 -0
  94. package/dist/cli/dashboard-steps.js +157 -0
  95. package/dist/cli/dashboard-steps.js.map +1 -0
  96. package/dist/cli/dashboard-task-format.d.ts +15 -0
  97. package/dist/cli/dashboard-task-format.js +119 -0
  98. package/dist/cli/dashboard-task-format.js.map +1 -0
  99. package/dist/cli/dashboard-task-view.d.ts +66 -0
  100. package/dist/cli/dashboard-task-view.js +325 -0
  101. package/dist/cli/dashboard-task-view.js.map +1 -0
  102. package/dist/cli/dashboard.d.ts +2 -0
  103. package/dist/cli/dashboard.js +71 -6
  104. package/dist/cli/dashboard.js.map +1 -1
  105. package/dist/cli/extensions-client.d.ts +23 -0
  106. package/dist/cli/extensions-client.js +147 -0
  107. package/dist/cli/extensions-client.js.map +1 -0
  108. package/dist/cli/extensions.d.ts +14 -0
  109. package/dist/cli/extensions.js +181 -0
  110. package/dist/cli/extensions.js.map +1 -0
  111. package/dist/cli/help.d.ts +1 -0
  112. package/dist/cli/help.js +21 -0
  113. package/dist/cli/help.js.map +1 -1
  114. package/dist/cli/main.js +54 -2
  115. package/dist/cli/main.js.map +1 -1
  116. package/dist/cli/output.js +1 -0
  117. package/dist/cli/output.js.map +1 -1
  118. package/dist/events/content.d.ts +43 -0
  119. package/dist/events/content.js +249 -0
  120. package/dist/events/content.js.map +1 -0
  121. package/dist/events/queue.d.ts +59 -0
  122. package/dist/events/queue.js +144 -0
  123. package/dist/events/queue.js.map +1 -0
  124. package/dist/events/validate.d.ts +22 -0
  125. package/dist/events/validate.js +542 -0
  126. package/dist/events/validate.js.map +1 -0
  127. package/dist/extensions/catalog.d.ts +33 -0
  128. package/dist/extensions/catalog.js +101 -0
  129. package/dist/extensions/catalog.js.map +1 -0
  130. package/dist/extensions/child-protocol.d.ts +38 -0
  131. package/dist/extensions/child-protocol.js +2 -0
  132. package/dist/extensions/child-protocol.js.map +1 -0
  133. package/dist/extensions/child.d.ts +1 -0
  134. package/dist/extensions/child.js +125 -0
  135. package/dist/extensions/child.js.map +1 -0
  136. package/dist/extensions/consent.d.ts +13 -0
  137. package/dist/extensions/consent.js +204 -0
  138. package/dist/extensions/consent.js.map +1 -0
  139. package/dist/extensions/environment.d.ts +1 -0
  140. package/dist/extensions/environment.js +12 -0
  141. package/dist/extensions/environment.js.map +1 -0
  142. package/dist/extensions/identity.d.ts +9 -0
  143. package/dist/extensions/identity.js +28 -0
  144. package/dist/extensions/identity.js.map +1 -0
  145. package/dist/extensions/log.d.ts +5 -0
  146. package/dist/extensions/log.js +80 -0
  147. package/dist/extensions/log.js.map +1 -0
  148. package/dist/extensions/manifest.d.ts +7 -0
  149. package/dist/extensions/manifest.js +213 -0
  150. package/dist/extensions/manifest.js.map +1 -0
  151. package/dist/extensions/types.d.ts +24 -0
  152. package/dist/extensions/types.js +2 -0
  153. package/dist/extensions/types.js.map +1 -0
  154. package/dist/extensions.d.ts +5 -0
  155. package/dist/extensions.js +2 -0
  156. package/dist/extensions.js.map +1 -0
  157. package/dist/index.d.ts +1 -0
  158. package/dist/index.js.map +1 -1
  159. package/dist/runtime/approval-registry.d.ts +6 -2
  160. package/dist/runtime/approval-registry.js +31 -3
  161. package/dist/runtime/approval-registry.js.map +1 -1
  162. package/dist/runtime/capture.js +45 -13
  163. package/dist/runtime/capture.js.map +1 -1
  164. package/dist/runtime/coordinator.d.ts +8 -4
  165. package/dist/runtime/coordinator.js +128 -26
  166. package/dist/runtime/coordinator.js.map +1 -1
  167. package/dist/runtime/daemon.js +9 -1
  168. package/dist/runtime/daemon.js.map +1 -1
  169. package/dist/runtime/dashboard.d.ts +4 -0
  170. package/dist/runtime/dashboard.js +8 -0
  171. package/dist/runtime/dashboard.js.map +1 -1
  172. package/dist/runtime/event-operation.d.ts +41 -0
  173. package/dist/runtime/event-operation.js +290 -0
  174. package/dist/runtime/event-operation.js.map +1 -0
  175. package/dist/runtime/event-owner.d.ts +94 -0
  176. package/dist/runtime/event-owner.js +429 -0
  177. package/dist/runtime/event-owner.js.map +1 -0
  178. package/dist/runtime/event-source.d.ts +39 -0
  179. package/dist/runtime/event-source.js +344 -0
  180. package/dist/runtime/event-source.js.map +1 -0
  181. package/dist/runtime/extension-instance.d.ts +61 -0
  182. package/dist/runtime/extension-instance.js +356 -0
  183. package/dist/runtime/extension-instance.js.map +1 -0
  184. package/dist/runtime/extension-protocol.d.ts +47 -0
  185. package/dist/runtime/extension-protocol.js +33 -0
  186. package/dist/runtime/extension-protocol.js.map +1 -0
  187. package/dist/runtime/extension-service.d.ts +10 -0
  188. package/dist/runtime/extension-service.js +35 -0
  189. package/dist/runtime/extension-service.js.map +1 -0
  190. package/dist/runtime/extension-supervisor.d.ts +33 -0
  191. package/dist/runtime/extension-supervisor.js +251 -0
  192. package/dist/runtime/extension-supervisor.js.map +1 -0
  193. package/dist/runtime/select-native.d.ts +2 -1
  194. package/dist/runtime/select-native.js +26 -2
  195. package/dist/runtime/select-native.js.map +1 -1
  196. package/dist/runtime/service.d.ts +5 -0
  197. package/dist/runtime/service.js +83 -9
  198. package/dist/runtime/service.js.map +1 -1
  199. package/dist/runtime/session-event-wire.d.ts +29 -0
  200. package/dist/runtime/session-event-wire.js +2 -0
  201. package/dist/runtime/session-event-wire.js.map +1 -0
  202. package/dist/runtime/session-events-service.d.ts +8 -0
  203. package/dist/runtime/session-events-service.js +124 -0
  204. package/dist/runtime/session-events-service.js.map +1 -0
  205. package/dist/runtime/session-events-transport.d.ts +8 -0
  206. package/dist/runtime/session-events-transport.js +142 -0
  207. package/dist/runtime/session-events-transport.js.map +1 -0
  208. package/dist/runtime/startup-lock.d.ts +2 -0
  209. package/dist/runtime/startup-lock.js +49 -5
  210. package/dist/runtime/startup-lock.js.map +1 -1
  211. package/dist/runtime/state.d.ts +2 -1
  212. package/dist/runtime/state.js +4 -0
  213. package/dist/runtime/state.js.map +1 -1
  214. package/dist/runtime/transport.d.ts +1 -0
  215. package/dist/runtime/transport.js +2 -0
  216. package/dist/runtime/transport.js.map +1 -1
  217. package/dist/runtime/types.d.ts +22 -0
  218. package/dist/runtime/types.js.map +1 -1
  219. package/dist/runtime/worker-client.js +42 -13
  220. package/dist/runtime/worker-client.js.map +1 -1
  221. package/dist/runtime/worker-event-channel.d.ts +30 -0
  222. package/dist/runtime/worker-event-channel.js +141 -0
  223. package/dist/runtime/worker-event-channel.js.map +1 -0
  224. package/dist/runtime/worker-event-protocol.d.ts +88 -0
  225. package/dist/runtime/worker-event-protocol.js +114 -0
  226. package/dist/runtime/worker-event-protocol.js.map +1 -0
  227. package/dist/runtime/worker-events.d.ts +73 -0
  228. package/dist/runtime/worker-events.js +704 -0
  229. package/dist/runtime/worker-events.js.map +1 -0
  230. package/dist/runtime/worker-server.d.ts +3 -1
  231. package/dist/runtime/worker-server.js +63 -8
  232. package/dist/runtime/worker-server.js.map +1 -1
  233. package/dist/sdk/connected-events.d.ts +3 -0
  234. package/dist/sdk/connected-events.js +259 -0
  235. package/dist/sdk/connected-events.js.map +1 -0
  236. package/dist/sdk/connected-types.d.ts +2 -0
  237. package/dist/sdk/connected-types.js.map +1 -1
  238. package/dist/sdk/connected.js +3 -0
  239. package/dist/sdk/connected.js.map +1 -1
  240. package/dist/sdk/event-types.d.ts +182 -0
  241. package/dist/sdk/event-types.js +2 -0
  242. package/dist/sdk/event-types.js.map +1 -0
  243. package/dist/sdk/execution-driver.js +1 -1
  244. package/dist/sdk/execution-driver.js.map +1 -1
  245. package/dist/sdk/execution-types.d.ts +2 -0
  246. package/dist/sdk/execution-types.js.map +1 -1
  247. package/dist/sdk/runner.js +2 -0
  248. package/dist/sdk/runner.js.map +1 -1
  249. package/package.json +5 -1
  250. package/sdk/adapter-contract.md +25 -3
  251. package/sdk/agent-skill.md +3 -2
  252. package/sdk/cli/dashboard-design.md +37 -9
  253. package/sdk/cli/dashboard-inspection.md +14 -6
  254. package/sdk/cli/extensions.md +44 -0
  255. package/sdk/cli/index.md +27 -4
  256. package/sdk/cli/output.md +13 -1
  257. package/sdk/completion-notifications.md +2 -2
  258. package/sdk/config.md +31 -2
  259. package/sdk/copilot.md +1 -1
  260. package/sdk/cursor.md +2 -2
  261. package/sdk/diagnostics.md +68 -0
  262. package/sdk/distribution.md +13 -3
  263. package/sdk/events.md +339 -0
  264. package/sdk/execution.md +26 -7
  265. package/sdk/extensions.md +181 -0
  266. package/sdk/fx.md +4 -2
  267. package/sdk/harnesses.md +1 -1
  268. package/sdk/index.md +3 -0
  269. package/sdk/message-delivery.md +2 -0
  270. package/sdk/opencode.md +1 -1
  271. package/sdk/project-team.md +10 -4
  272. package/sdk/sessions.md +4 -0
  273. package/sdk/v1-runtime.md +14 -4
@@ -0,0 +1,181 @@
1
+ # User extensions
2
+
3
+ Extensions are user-developed functionality that observes [live session events](events.md). The coordinator supervises a separate child process for each enabled extension instance. The CLI dashboard and embedded runners do not load extension modules. SDK applications implement their own behavior by consuming `runner.events.open` or `client.events.open` directly.
4
+
5
+ Extensions have no UI, terminal renderer, dashboard access or execution-control hooks. They cannot block, modify or approve native operations through this API. They may use their own code and services to handle delivered events, including explicitly storing data in a location selected by the user.
6
+
7
+ ## Definition API
8
+
9
+ The `subharness/extensions` subpath supplies authoring types. A module default-exports a plain object conforming to `ExtensionDefinition`; its Subharness imports are type-only and disappear from compiled JavaScript.
10
+
11
+ ```ts
12
+ import type { SessionEvent } from "subharness/extensions";
13
+
14
+ export interface ExtensionContext {
15
+ readonly extensionId: string;
16
+ readonly reference: string;
17
+ readonly workspace?: string;
18
+ readonly signal: AbortSignal;
19
+ }
20
+ export interface ExtensionInstance {
21
+ onEvent(event: SessionEvent): void | Promise<void>;
22
+ dispose?(): void | Promise<void>;
23
+ }
24
+ export interface ExtensionDefinition {
25
+ readonly id: string;
26
+ readonly apiVersion: 1;
27
+ setup(context: ExtensionContext): ExtensionInstance | Promise<ExtensionInstance>;
28
+ }
29
+ export interface ExtensionManifest {
30
+ readonly manifestVersion: 1;
31
+ readonly id: string;
32
+ readonly version: string;
33
+ readonly apiVersion: 1;
34
+ readonly eventVersion: 1;
35
+ readonly entry: string;
36
+ }
37
+ ```
38
+
39
+ `id` matches `[a-zA-Z][a-zA-Z0-9_-]{0,63}` and agrees with the manifest and installation directory. `context.extensionId` is that ID. `context.reference` is its qualified `"global:id"` or `"repo:id"` reference. `context.workspace` is the canonical checkout for a repository extension and is absent for a global extension. `signal` represents the extension instance's lifetime; aborting it does not cancel an agent. The context contains no CLI/dashboard handle, native session, execution controls, credentials or tool registry. Every authoring type, including `SessionEvent` and the types it references, is importable from `subharness/extensions`, without requiring a runtime import by the extension. Every event, subscription and capability type is exported from `subharness` and re-exported as a type from `subharness/extensions`.
40
+
41
+ `setup` allocates the instance's resources. `onEvent` receives `SessionEvent` objects directly, narrowed by their `type` discriminator. Calls are serial in delivery order within one instance, and the host awaits each returned promise before calling that instance again. Return values do not modify execution or consume events away from other subscribers. Separate processes have independent queues and handlers. `dispose` releases the instance's resources. These are the only extension hooks.
42
+
43
+ ## Coordinator ownership and delivery
44
+
45
+ Within a coordinator, an extension instance is identified by its qualified reference and, for a repository extension, its canonical checkout. Global instances have no checkout component. Failure state, admission eligibility and re-enablement are tracked separately for each instance identity. Repository instances with the same `repo:id` in different checkouts are independent; enabling in one checkout affects only that checkout's instance.
46
+
47
+ Enablement is resolved when a coordinator session is admitted, for both CLI and connected SDK creation. Every enabled global extension receives that session's events; enabled repository extensions receive only sessions admitted in their canonical checkout. Sessions keep that admission-time selection. Enabling an extension does not attach it to already admitted sessions, and disabling stops its eligibility for newly admitted sessions. It does not cancel agents or withdraw delivery for sessions already assigned to the running instance.
48
+
49
+ Extension admission is fail-open. Extension discovery or consent-read failures never block session admission or change the agent's task outcome. The session is admitted without extension delivery, and the coordinator retains a safe admission diagnostic for `subharness extensions list`. Admission diagnostics are separate from instance diagnostics because these failures may occur before an extension identity is known.
50
+
51
+ An extension process starts when its first matching session is admitted. Subscription registration is part of session admission, before that session's initial events are accepted; subsequent matching sessions are delivered to the applicable running instance. No agent waits for an extension handler. Startup/setup queues obey the same delivery bounds, so slow initialization cannot delay native execution. The instance remains owned by the coordinator until coordinator close, unless failure disables it. It does not stop merely because a dashboard exits, an SDK client disconnects, or one session finishes. Embedded runners never discover or start user extensions.
52
+
53
+ A failed instance stays disabled for the rest of its coordinator's lifetime and is never automatically restarted. Running `subharness extensions enable <global:id|repo:id>` again saves consent and notifies a running coordinator to make a replacement for that instance identity eligible for newly admitted sessions; a new process starts at its first matching admission. With no running coordinator, saving consent is sufficient. If notification fails, consent remains saved, the command warns that the failure state clears on coordinator restart, and exits `0`; it does not claim the running coordinator accepted the reset. Sessions assigned to the failed instance are not reassigned. The failed instance's diagnostic remains visible through `subharness extensions list` for that coordinator's lifetime. Restarting the coordinator resets runtime failure state.
54
+
55
+ The coordinator supervises the child and forwards only normalized, redacted events for its assigned sessions over a private, bounded IPC channel. Execution workers do not import extension code. Crashes, synchronous hangs, rejected handlers, timeouts and backpressure are isolated to the affected child; they do not block agents, coordinator control operations or other extensions. Extension code is trusted user-privileged Node.js code, not a security sandbox. Process supervision isolates delivery/execution lifetimes but does not grant protection from arbitrary filesystem or network side effects of explicitly enabled code.
56
+
57
+ The child runs with the extension directory as its working directory and a minimal environment containing only `PATH`, `HOME`, `TMPDIR` and locale variables. `NODE_OPTIONS`, the coordinator token, all `AGENT_*` variables, provider credentials, Gateway or OIDC tokens, and dotenv values are excluded. Its stdin is closed. Stdout and stderr go to an owner-private log for that instance. The coordinator compacts the log after it exceeds 1.5 MiB, trimming it back to the most recent 1 MiB. Global instances use `<stateDirectory>/extensions/global-<id>.log`. Repository instances use `<stateDirectory>/extensions/repo-<id>-<checkout-hash>.log`, where `<checkout-hash>` is the first 12 hex characters of the SHA-256 of the canonical checkout path. These filenames contain no colons. The selected coordinator's state directory follows the existing [selection rule](execution.md#ownership-and-transport-boundaries): explicit `ConnectOptions.stateDirectory`, then `AGENT_STATE_DIR`, then `~/.subharness/state/shared`. CLI commands use the environment/default selection rule. `subharness extensions list` shows the actual log path for each instance. Log contents never enter execution output, safe diagnostics or the dashboard. Failure to open, write or close this log never stops the extension instance. Unwritable output is discarded, and the instance reports the informational `EXTENSION_LOG_UNAVAILABLE` diagnostic.
58
+
59
+ ## Bounds, shutdown and diagnostics
60
+
61
+ Setup and each handler have a five-second deadline. At most 128 events or 1 MiB of serialized event data may wait for an instance, whichever bound is reached first. Exceeding the delivery bound disables that instance with `EXTENSION_BACKPRESSURE`. A throw/rejection uses `EXTENSION_HANDLER_FAILED`; an asynchronous or synchronous deadline failure uses `EXTENSION_TIMEOUT`. The supervisor can stop a blocked child without waiting for its JavaScript event loop.
62
+
63
+ On shutdown or disablement caused by failure, delivery stops and pending undelivered events are released. The child lifetime signal aborts and `dispose` is called once when the process can cooperate, with a one-second budget. The coordinator terminates an unresponsive child; a crash or forced termination cannot guarantee disposal or completion of a file write. Side effects already performed are not rolled back, and delivery is not an exactly-once transaction. A successful shutdown confirms the supervised process has stopped; cleanup failures are explicit.
64
+
65
+ Manifest/module/export/dependency failures use `EXTENSION_LOAD_FAILED`, and API/event-version mismatches use `EXTENSION_INCOMPATIBLE`. Disposal failures use `EXTENSION_DISPOSE_FAILED`. An unexpected extension-process exit uses `EXTENSION_EXITED` and disables the instance under the same failed-instance lifetime and re-enablement rules as other failures. Messages identify the qualified reference, repository checkout when applicable, and failure phase, contain at most 1 KiB of safe text, and omit event content, raw exception messages/stacks, credentials and raw stdout/stderr. The CLI displays `EXTENSION_*` codes with their safe messages only through `subharness extensions list`. These failures also remain available through the coordinator's existing safe diagnostics. The dashboard neither loads nor hosts extensions and does not display extension diagnostics. Extension output never enters execution-command output, these diagnostics or the dashboard. Runtime failures remain visible through `subharness extensions list` for the owning coordinator's lifetime; they disable that runtime instance without changing stored consent and are not task failures. Runtime status reports each instance as `running`, `idle` or `disabled` and retains at most its eight most recent diagnostics. Each diagnostic records whether it disabled the instance and when it occurred.
66
+
67
+ `subharness extensions list` and the coordinator's extension-status operation each report at most 256 instances. When more instances exist, each reports the exact number omitted. The status operation also retains at most the 16 most recent admission diagnostics, separately from instance diagnostics. An admission diagnostic includes a workspace when one was resolved safely.
68
+
69
+ ## Manifest, discovery and consent
70
+
71
+ Install a compiled extension in one of these directories:
72
+
73
+ - `~/.subharness/extensions/<id>/` for a global installation.
74
+ - `<worktree>/.subharness/extensions/<id>/` for a repository installation.
75
+
76
+ Each directory contains `extension.json`, a compiled ESM entry and any packaged dependencies. A compiled extension is self-contained: it must not require a runtime import of Subharness. A `.mjs` entry can use Node's ESM loading directly; a `.js` entry requires suitable ESM package metadata. There is no TypeScript evaluation or build during discovery or activation.
77
+
78
+ Discovery reads static manifests only, without importing agent or extension modules. Repository scope uses the nearest canonical Git worktree root; outside Git, it uses the command's directory. Linked worktrees are separate repository scopes. Discovery does not traverse symlink directories or search parent repositories. Each `extension.json` is at most 16 KiB, and any `package.json` read from an extension directory is at most 64 KiB. Unknown fields, invalid IDs/versions, unsupported schema versions, missing entries and entry paths escaping the installation directory fail validation. `version` is the extension artifact's semantic version. Manifest/API/event versions are independent of the core package's npm version. `eventVersion` names the `SessionEvent` schema version and must equal `EventBase.version`. `apiVersion` gates the `ExtensionDefinition` contract. A mismatch of either version uses `EXTENSION_INCOMPATIBLE`.
79
+
80
+ Nothing executes merely because a repository contains extension files. The current user explicitly enables an installation with `subharness extensions enable <global:id|repo:id>`. Consent is stored in `~/.subharness/extensions.json` with owner-only permissions, using the [extension consent schema](config.md#extension-consent-and-logs). Repository enablement is keyed by canonical checkout and never stored in repository files. Enabled repository code is the checkout's current code when the supervised process loads it. Consent persists after edits; a running process does not hot-reload its module. Installation sources do not silently replace one another: global and repository references remain qualified and independently enabled.
81
+
82
+ The consent file is at most 256 KiB, with at most 1,024 repository entries and 256 IDs per scope: 256 global IDs and 256 IDs for each repository entry. Every extensions command rejects an existing consent file that is not owner-only, exits `1`, and directs the user to restrict its permissions with `chmod 600 ~/.subharness/extensions.json`. No command repairs its permissions.
83
+
84
+ The coordinator validates compatibility before starting the child, and the child validates the default export before setup. Node.js 22.18 or newer is required. Missing dependencies and invalid modules fail safely; no automatic installation is performed. Discovery/enablement can report static compatibility, but cannot prove module initialization will succeed without executing it. [Extension commands](cli/extensions.md) define management output and failure reporting.
85
+
86
+ ## Complete tool-result logger
87
+
88
+ This extension records completed tool-call observations as JSONL. Set `outputDirectory` to an absolute directory chosen by the user before compiling. The code uses only Node built-ins at runtime. The log contains the bounded, redacted previews supplied by events, not unrestricted native payloads. The extension owns this persistence and its file lifecycle.
89
+
90
+ Save this TypeScript module as `index.mts` in the extension's source project and compile it to `dist/index.mjs`:
91
+
92
+ ```ts
93
+ import type { ExtensionDefinition } from "subharness/extensions";
94
+ import { mkdir, open } from "node:fs/promises";
95
+ import { isAbsolute, join } from "node:path";
96
+
97
+ // Choose this path when preparing the extension, independently of process cwd.
98
+ const outputDirectory = "/absolute/path/chosen/by/the/user";
99
+
100
+ const extension = {
101
+ id: "tool-result-logger",
102
+ apiVersion: 1,
103
+ async setup({ extensionId, reference, workspace, signal }) {
104
+ if (!isAbsolute(outputDirectory)) throw new Error("An absolute output directory is required");
105
+ await mkdir(outputDirectory, { recursive: true, mode: 0o700 });
106
+ // A separate file per process prevents independent instances sharing a writer.
107
+ const filename = join(outputDirectory, `${extensionId}-${process.pid}.jsonl`);
108
+ const file = await open(filename, "a", 0o600);
109
+ return {
110
+ async onEvent(event) {
111
+ if (signal.aborted || event.type !== "item.completed" || event.item.kind !== "tool") return;
112
+ const item = event.item;
113
+ await file.appendFile(JSON.stringify({
114
+ version: 1,
115
+ reference,
116
+ workspace,
117
+ eventId: event.eventId,
118
+ ownerId: event.ownerId,
119
+ sequence: event.sequence,
120
+ observedAt: event.observedAt,
121
+ sessionId: event.sessionId,
122
+ taskId: event.taskId,
123
+ turnId: event.turnId,
124
+ itemId: item.itemId,
125
+ name: item.name,
126
+ state: item.state,
127
+ completion: event.completion,
128
+ input: item.input,
129
+ output: item.output,
130
+ exitCode: item.exitCode,
131
+ durationMs: item.durationMs,
132
+ }) + "\n", "utf8");
133
+ },
134
+ async dispose() {
135
+ await file.close();
136
+ },
137
+ };
138
+ },
139
+ } satisfies ExtensionDefinition;
140
+
141
+ export default extension;
142
+ ```
143
+
144
+ Use this `extension.json` beside the `dist/` directory:
145
+
146
+ ```json
147
+ {
148
+ "manifestVersion": 1,
149
+ "id": "tool-result-logger",
150
+ "version": "1.0.0",
151
+ "apiVersion": 1,
152
+ "eventVersion": 1,
153
+ "entry": "./dist/index.mjs"
154
+ }
155
+ ```
156
+
157
+ TypeScript and Subharness types are development dependencies of the source project. For example, with a compatible local TypeScript compiler, Node types and Subharness declarations installed, compile using:
158
+
159
+ ```sh
160
+ npx --no-install tsc index.mts --outDir dist --target ES2022 --module NodeNext --moduleResolution NodeNext --strict --skipLibCheck
161
+ ```
162
+
163
+ The installed artifact needs only `extension.json` and `dist/index.mjs` for this example; its type-only import is erased. Copy that prepared artifact into an absent destination, then enable it:
164
+
165
+ ```sh
166
+ mkdir -p ~/.subharness/extensions
167
+ cp -R /path/to/compiled-tool-result-logger ~/.subharness/extensions/tool-result-logger
168
+ subharness extensions enable global:tool-result-logger
169
+ subharness extensions list
170
+ ```
171
+
172
+ For repository scope, run from the worktree root:
173
+
174
+ ```sh
175
+ mkdir -p .subharness/extensions
176
+ cp -R /path/to/compiled-tool-result-logger .subharness/extensions/tool-result-logger
177
+ subharness extensions enable repo:tool-result-logger
178
+ subharness extensions list
179
+ ```
180
+
181
+ Enable only the installation(s) whose logging behavior is wanted. The first newly admitted matching coordinator session starts the extension. Its `item.completed` observations include succeeded, failed, cancelled or unknown tool outcomes without inferring success. Logs can contain source code and paths; the user owns their storage, permissions, retention and deletion. Directory/file mode arguments apply when this example creates them and do not tighten permissions on an existing path. A handler failure or slow storage disables the extension instance with a safe list diagnostic, without delaying the agent. An abrupt child exit can leave a partial final line; consumers must tolerate that outcome.
package/sdk/fx.md CHANGED
@@ -108,10 +108,12 @@ Native permissions remain authoritative. fx ACP does not expose scoped allow rul
108
108
 
109
109
  ## Session lifecycle
110
110
 
111
- Each library session owns one native ACP conversation. Successful follow-ups reuse its session identifier. The adapter returns text from the last native message identifier in the completed prompt and excludes thinking, earlier progress messages, tool traffic, and protocol diagnostics. Native ACP uses the same message type for assistant responses and operational notices, so the last message can be a native notice. Responses retain the library's size limit. Only `end_turn` is successful; native errors and other stop reasons reject the task instead of returning a successful empty response.
111
+ Each library session owns one native ACP conversation. Successful follow-ups reuse its session identifier. The complete-response result selects text from the last native message identifier in the completed prompt, excluding thinking, earlier progress messages, tool traffic and protocol diagnostics from that result. Separate [live session events](events.md#effective-route-capabilities) expose bounded assistant and tool previews; native reasoning emission remains unverified. Live observation does not change final-response selection. Native ACP uses the same message type for assistant responses and operational notices, so the last message can be a native notice. Responses retain the library's size limit. Only `end_turn` is successful; native errors and other stop reasons reject the task instead of returning a successful empty response.
112
+
113
+ Malformed optional live-event data emits at most one nonfatal adapter capture error per turn with code `CAPTURE_FAILED`. The capture error does not change the task's execution outcome.
112
114
 
113
115
  Native auxiliary calls, such as title generation or permission classification, can use models selected by fx and consume Gateway usage. They do not change the requested task model and are not library fallback. The adapter preserves native preferences for those operations.
114
116
 
115
- The coordinator owns FIFO task queuing. This adapter reports native steering as unsupported before changing execution; the coordinator applies the existing `steer`-to-`interrupt` behavior. Interruption sends native cancellation and waits for the active prompt and admitted tool callbacks to stop. Unconfirmed cancellation fails explicitly and keeps queued dispatch paused. Prompt-free recovery returns `RECOVERY_UNSUPPORTED`; no task is silently replayed.
117
+ The coordinator owns FIFO task queuing. This adapter reports native steering as unsupported before changing execution; the coordinator applies the existing `steer`-to-`interrupt` behavior. Interruption sends native cancellation and waits for the active prompt and admitted tool callbacks to stop. If a transport failure has started native process retirement, the adapter waits at most six seconds for that retirement to confirm the stop, covering the five-second graceful termination window plus confirmation margin. Unconfirmed cancellation fails explicitly and keeps queued dispatch paused. Prompt-free recovery returns `RECOVERY_UNSUPPORTED`; no task is silently replayed.
116
118
 
117
119
  Closing a session stops the native process and its local tool endpoint. Native diagnostic output is not forwarded because it can contain credentials. Errors identify the affected operation without exposing credentials or raw provider responses.
package/sdk/harnesses.md CHANGED
@@ -10,7 +10,7 @@ An agent declares one harness configuration or a nonempty ordered array through
10
10
 
11
11
  Before submitting work, known unavailability, such as a missing executable or missing eligible login, permits trying the next enabled connection or alternative. Invalid configuration, unsupported explicit options, and uncertain failures are errors. API keys or Gateway tokens present in the environment are not implicitly enabled.
12
12
 
13
- Automatic fallback ends at task submission. Execution failure, allowance exhaustion, or an uncertain submission outcome never automatically replays work or migrates a conversation. Partial file and tool effects remain in the execution environment. The caller can inspect progress and explicitly create other work.
13
+ Automatic fallback ends at task submission. Execution failure, allowance exhaustion, or an uncertain submission outcome never automatically replays work or migrates a conversation. Partial file and tool effects remain in the execution environment. The caller can inspect progress and explicitly create other work. Codex terminal turn failures use the safe category mapping in [Error diagnostics](diagnostics.md), including `CONTEXT_WINDOW_EXCEEDED` for reported context-window exhaustion; this classification does not change queue or recovery behavior.
14
14
 
15
15
  `subharness check` applies the same selection and fallback rules while opening and closing a temporary native session without submitting work. A successful result means startup checks passed for the selected target at that moment. It is not a quota probe or a guarantee that a later task, shell command, declared child launch, or provider request will succeed.
16
16
 
package/sdk/index.md CHANGED
@@ -5,6 +5,8 @@ This index is the entry point to the authoritative subharness contracts. The Typ
5
5
  ## SDK API
6
6
 
7
7
  - [Connected and embedded execution](execution.md): client and runner ownership, sessions, tasks, complete responses, approvals, and hosted delegation.
8
+ - [Live session events](events.md): normalized content, route capabilities, live scopes, flow control and redaction.
9
+ - [User extensions](extensions.md): plain-object definitions, supervised coordinator processes, per-user consent and a tool-result logger.
8
10
  - [Agent definitions](agent.md): package exports, fields, harness options, and definition examples.
9
11
  - [Custom tools](tools.md): validated application functions exposed through native harness integrations.
10
12
  - [Subagents](plugins/sub-agents.md): nested delegation, lineage, context, and result-delivery boundaries.
@@ -14,6 +16,7 @@ This index is the entry point to the authoritative subharness contracts. The Typ
14
16
  - [CLI](cli/index.md): commands, input, admission, waiting, follow-ups, control, and native permission responses.
15
17
  - [CLI output](cli/output.md): compact text, typed JSONL records, states, and exit codes.
16
18
  - [Dashboard presentation](cli/dashboard-design.md): the read-only live terminal hierarchy and interaction contract.
19
+ - [Extension commands](cli/extensions.md): manifest discovery, directory installation and explicit per-user enablement.
17
20
  - [Agent discovery](config.md): repository and global definitions, naming, and personal worktree settings.
18
21
  - [Agent skill](agent-skill.md): the installable skill that teaches a coding agent to delegate with the CLI.
19
22
 
@@ -38,6 +38,8 @@ Cancellation applies recursively to recorded delegation relationships. Pending d
38
38
 
39
39
  `cancel` returns after affected work has stopped. Repeated cancellation of already-settled work returns its state. An unconfirmed stop reports a cancellation error and keeps dispatch paused; it does not authorize starting replacement or queued work. Invalid replacement input is rejected before existing work is cancelled.
40
40
 
41
+ For cancellation and interrupt, "stopped" means that the active native turn, recorded descendant work, and admitted callbacks have reached their confirmed stop boundary. It does not retire the native session. A harness can keep its own background tool processes alive across turns, so those processes can continue after cancellation or task completion. Close the session with `subharness close` or `session.close()` to invoke the harness's tracked-process cleanup. Processes deliberately detached outside native harness tracking are not owned by either the harness or Subharness and can survive session close.
42
+
41
43
  ## Resume after an execution error
42
44
 
43
45
  `subharness resume <session-id>` addresses the existing failed task and requires no new prompt. It does not replay the original task, migrate to another harness, or skip the failure to release the queue. An unavailable native recovery operation returns `RECOVERY_UNSUPPORTED`. A session without failed work returns an error.
package/sdk/opencode.md CHANGED
@@ -50,7 +50,7 @@ Native permissions are configured to ask. Active native permission requests use
50
50
 
51
51
  ## Lifecycle
52
52
 
53
- Each Subharness session owns one native conversation and one native server. Follow-up tasks retain that conversation. Every prompt pins the requested provider/model; detectable changes are errors without replay. A task returns the final assistant text only after successful native completion. Native errors, unfinished responses, and malformed terminal data cannot count as success. The final text limit is 1 MiB.
53
+ Each Subharness session owns one native conversation and one native server. Follow-up tasks retain that conversation. Every prompt pins the requested provider/model; detectable changes are errors without replay. The complete-response result returns final assistant text only after successful native completion. [Live session events](events.md#effective-route-capabilities) separately expose bounded live text, reasoning and tool previews; they do not establish task completion and are delivered only to current subscribers. Native errors, unfinished responses, and malformed terminal data cannot count as success. The final text limit is 1 MiB.
54
54
 
55
55
  Interruption requests native abort and confirms the active work stopped; an accepted HTTP abort request alone is insufficient. It also drains admitted tools and retires outstanding approvals, including when native work ended before interruption began. Native stop confirmation is bounded; that deadline does not limit already-admitted host callbacks, which must settle before interruption completes. Failure to confirm native termination produces `CANCELLATION_FAILED`, and no replacement prompt is admitted to still-running work. Steering uses the shared interrupt behavior; prompt-free recovery is unsupported.
56
56
 
@@ -1,6 +1,6 @@
1
1
  # Repository Agent Team
2
2
 
3
- This repository keeps nine reusable agents in `.subharness/agents/`. An agent defines a stable responsibility, model, and tool access. A skill supplies task-specific instructions that the agent reads when relevant. Adding a technique or library does not require another agent definition.
3
+ This repository keeps ten reusable agents in `.subharness/agents/`. An agent defines a stable responsibility, model, and tool access. A skill supplies task-specific instructions that the agent reads when relevant. Adding a technique or library does not require another agent definition.
4
4
 
5
5
  ## Roles
6
6
 
@@ -9,9 +9,10 @@ This repository keeps nine reusable agents in `.subharness/agents/`. An agent de
9
9
  | `architect` | Codex, `gpt-6-astra`, high effort | Evaluate architecture and API decisions; develop requested design concepts and assets; perform independent visual review when assigned. |
10
10
  | `developer` | Codex, `gpt-5.6-sol`, high effort | Implement documented behavior and application structure with focused TDD and independent review. |
11
11
  | `visual-engineer` | fx, `anthropic/claude-fable-5.1`, native default effort | Implement approved interface styling and native vgpu/WGSL effects using the relevant skill. |
12
- | `api-researcher` | Codex, `gpt-5.6-luna`, low effort | Collect primary-source API evidence: signatures, defaults, events, errors, and lifecycle rules. |
12
+ | `api-researcher` | Codex, `gpt-5.6-luna`, medium effort | Collect primary-source API evidence: signatures, defaults, events, errors, and lifecycle rules. |
13
13
  | `systems-researcher` | Codex, `gpt-5.6-luna`, low effort | Collect evidence from related systems, including job queues, process runners, event streams, actors, and UI state synchronization. |
14
14
  | `planner` | Codex, `gpt-6-astra`, high effort | Turn settled contracts into bounded implementation assignments and verification criteria in ignored scratch files. |
15
+ | `get-context` | fx, `anthropic/claude-sonnet-5.5`, native default effort | Perform one quick orientation pass when the lead receives a new request whose affected repository areas it has not explored, and report relevant files and observed facts. |
15
16
  | `researcher` | fx, `google/gemini-3.8-flash`, native default effort | Answer a bounded technical or design question with primary-source evidence. |
16
17
  | `reviewer` | Claude Code, `claude-opus-5[1m]`, high effort | Independently review correctness, lifecycle, credential routing, and contract compliance without editing files. |
17
18
  | `integrator` | Codex, `gpt-5.6-sol`, high effort | Merge only the exact PRs and reviewed heads explicitly authorized by the lead for the current assignment, following [PR integration](pr-integration.md). |
@@ -28,13 +29,15 @@ Implementation roles return unstaged working-tree changes and verification evide
28
29
 
29
30
  ## Assigning work by complexity
30
31
 
31
- Use `api-researcher` for bounded source searches and API inventories. Use `systems-researcher` for related problems outside agent orchestration. Both use the explicitly selected Codex model, read `.agents/skills/source-research/SKILL.md`, and write only the caller-named files under `.context/research/`. Their output records source URLs or paths, retrieval dates, revisions, observed behavior, and uncertainty. They distinguish facts from inference, do not rank architectural alternatives or settle contracts, and return missing evidence to the lead. The existing fx `researcher` remains available for general technical and visual evidence tasks. The two research roles have different standing evidence responsibilities: `api-researcher` inventories caller-visible interfaces, while `systems-researcher` investigates ownership, failure handling, delivery, and retention across related domains. Keeping those lenses explicit helps a design survey cover both interface conventions and operational behavior. Individual libraries and technologies remain task inputs, not additional permanent roles.
32
+ Use `get-context` only for the initial orientation pass: when the lead receives a new request whose affected repository areas it has not explored. Another role can call it only when that role declares it as a subagent; no current role does. It maps relevant documentation, source files, tests, and observed facts quickly and writes a Markdown report to the caller-named file under `.context/research/`, or to `.context/research/get-context-<short-topic>.md` when the caller names none. The report keeps observed facts separate from any explicitly labeled unverified inferences about possible approaches. Apart from that report, it does not edit files. This is an instruction: the fx roles' `permissionMode: "auto"` leaves native write and shell tools available. It does not choose approaches, settle contracts, or delegate. Follow-up questions, targeted lookups, and evidence research use the lead's own tools or the research roles instead of repeated orientation passes.
33
+
34
+ Use `api-researcher` for bounded source searches and API inventories. Use `systems-researcher` for related problems outside agent orchestration. Both use the explicitly selected Codex model, read `.agents/skills/source-research/SKILL.md`, and write only the caller-named files under `.context/research/`. Their output records source URLs or paths, retrieval dates, revisions, observed behavior, and uncertainty. `api-researcher` separates native capabilities from current adapter usage, inspects complete exported type and event inventories, may use probes that cannot start a model turn, and records the sources searched before reporting that something does not exist. It reads external repositories from shallow clones under `.context/research/sources/` without installing or running them. They distinguish facts from inference, do not rank architectural alternatives or settle contracts, and return missing evidence to the lead. The existing fx `researcher` remains available for general technical and visual evidence tasks. The two research roles have different standing evidence responsibilities: `api-researcher` inventories caller-visible interfaces, while `systems-researcher` investigates ownership, failure handling, delivery, and retention across related domains. Keeping those lenses explicit helps a design survey cover both interface conventions and operational behavior. Individual libraries and technologies remain task inputs, not additional permanent roles.
32
35
 
33
36
  Use `architect` for reasoning across that evidence, including API alternatives with concrete signatures and usage examples, lifecycle ownership, cancellation, errors, compatibility, and misuse cases. Recommendations do not authorize implementation. The lead settles clear choices under `AGENTS.md` and asks the human only for unresolved product tradeoffs or signatures outside delegated authority.
34
37
 
35
38
  Use `planner` only after the relevant decisions are settled in repository documentation. It reads the actual affected implementation and writes only the caller-named files under `.context/research/`. Its assignments identify the governing contracts, owned files, dependencies, behavior-focused failing tests, validation commands, and acceptance criteria. It reports missing decisions instead of choosing public behavior. Plans and progress records are scratch artifacts; they never replace repository contracts, authorize implementation, or become public documentation. The lead validates the assignments and owns task boundaries and implementation authorization.
36
39
 
37
- Use `developer` for implementation and bounded review fixes, and `reviewer` for independent review. Documentation work uses the existing developer or architect with an explicit file scope; it does not need another permanent role. Graphics-specific research uses the existing researcher with the graphics skill when relevant. The `api-researcher`, `systems-researcher`, and `planner` return results to the lead without delegation. The lead supplies bounded questions, sources or search angles, output paths, and stopping criteria so economical evidence collection does not turn into unbounded design work.
40
+ Use `developer` for implementation and bounded review fixes, and `reviewer` for independent review. Documentation work uses the existing developer or architect with an explicit file scope; it does not need another permanent role. Graphics-specific research uses the existing researcher with the graphics skill when relevant. The `get-context`, `api-researcher`, `systems-researcher`, and `planner` return results to the lead without delegation. The lead supplies bounded questions, sources or search angles, output paths, and stopping criteria so economical evidence collection does not turn into unbounded design work.
38
41
 
39
42
  These assignments express task complexity, not a guaranteed price or model benchmark. Models are fixed in definitions; there is no automatic routing based on a guessed task difficulty, silent fallback, or credential change. When the selected model or capability is unavailable, report that limitation to the lead. A follow-up can narrow an unanswered research question in the same session; a new independent angle gets a separate session.
40
43
 
@@ -46,12 +49,15 @@ These files are ordinary instructions consumed through the native harness. Each
46
49
 
47
50
  The caller provides one bounded deliverable, governing contracts, input artifacts, working directory, and relevant skill paths. Each child receives its own task and instructions; it does not inherit the parent's transcript or previously loaded skills. A handoff therefore names required skills again.
48
51
 
52
+ The inline prompts below are short literal examples. A real handoff that generates a long or multiline prompt supplies it through `--prompt-file <path>` using a temporary file accessible only by its owner, or through `--prompt-file -` when the host owns standard input. On POSIX systems, the file uses mode `0600` inside a mode-`0700` temporary directory. A `started` or `accepted` record, or command exit, confirms that the CLI has read the file and it can be removed.
53
+
49
54
  ```sh
50
55
  subharness list
51
56
  subharness run repo:architect --prompt "Read website/design.md and .agents/skills/design-exploration/SKILL.md. Evaluate the supplied hero reference and report a composition recommendation."
52
57
  subharness run repo:visual-engineer --prompt "Use .agents/skills/web-interface/SKILL.md. Implement the hero layout documented in website/design.md. Limit changes to the hero styles."
53
58
  subharness run repo:developer --prompt "Use .agents/skills/web-interface/SKILL.md. Read website/design.md. Check the hero's semantic HTML and keyboard behavior without changing styles."
54
59
  subharness run repo:developer --prompt "Use .agents/skills/webgpu-graphics/SKILL.md. Read website/graphics.md. Verify the mascot camera's documented framing with focused tests."
60
+ subharness run repo:get-context --prompt "New request: add task filtering to the CLI dashboard. Map the relevant files and write the report to .context/research/get-context-dashboard-filtering.md."
55
61
  subharness run repo:api-researcher --prompt "Use .agents/skills/source-research/SKILL.md. Read sdk/sessions.md. Record official SDK cancellation signatures in .context/research/sdk-cancellation.md."
56
62
  subharness run repo:systems-researcher --prompt "Use .agents/skills/source-research/SKILL.md. Read sdk/message-delivery.md. Record queue and observer lifecycle evidence in .context/research/queue-lifecycle.md."
57
63
  subharness run repo:planner --prompt "Read sdk/sessions.md and sdk/message-delivery.md. Inspect src/runtime/coordinator.ts. Write bounded verification assignments for those settled contracts to .context/research/session-verification-plan.md."
package/sdk/sessions.md CHANGED
@@ -25,6 +25,8 @@ Every complete response receives a response identifier and returns control to it
25
25
 
26
26
  `wait` observes the first retained response without creating another task. `wait --after <response-id>` observes later responses from an explicit cursor. `status` reports current state independently of earlier response snapshots. Completing a task does not delete its conversation. Returning a command does not cancel the task or descendants. `--detach` on a task-creating command ends only that command's observation after admission; it is not stored on the session and does not alter later `send`, `wait`, or `status` behavior.
27
27
 
28
+ Cancellation and interrupt stop the agent's active native turn. A native harness can retain a tool process as session-owned background work across turns, so such a process can continue after cancellation or task completion. Closing the session with `subharness close` or `session.close()`, or shutting down the coordinator, closes native resources and lets the harness terminate the tool processes it tracks. A process deliberately detached outside the harness's tracking is outside both Subharness and harness ownership and can survive.
29
+
28
30
  ## Lifetime and recovery
29
31
 
30
32
  The on-demand coordinator retains task records and native session workers beyond individual command exits. Task IDs resolve from other working directories using that coordinator. Task records remain available for its lifetime; they are not silently evicted. Settled permission-request records have a separate bounded retention policy defined in [Responding to Native Permission Requests](approvals.md).
@@ -34,3 +36,5 @@ Restarting the coordinator does not restore queues or automatically replay tasks
34
36
  Cancellation, interrupt propagation, and queue behavior are defined in [Message Delivery](message-delivery.md). The detailed ownership and bounds are defined in the [runtime contract](v1-runtime.md).
35
37
 
36
38
  Supported native permission requests follow [Responding to Native Permission Requests](approvals.md). Observing an approval returns control without completing or restarting the task.
39
+
40
+ `subharness close <session-id>` and SDK `session.close()` share the same close path. Close stops new admission, cancels active and queued tasks and their recorded descendants with confirmed-stop semantics, and then closes native resources. Closed sessions remain inspectable, and repeated successful close is idempotent. Cleanup failure leaves admission closed and retains ownership for a later retry.
package/sdk/v1-runtime.md CHANGED
@@ -4,7 +4,7 @@ The first usable version supplies a TypeScript definition and execution SDK and
4
4
 
5
5
  ## Package and definitions
6
6
 
7
- The package is `subharness`, with the primary executable `subharness` and identical `agent` compatibility alias. Node.js 22.18 or newer is required. ESM exports include `agent`, `tool`, `toolResult`, `codex`, `claudeCode`, `fx`, `opencode`, `copilot`, `cursor`, and their definition/configuration types. The public SDK defines reusable specialists; direct CLI harness targets also execute without a definition. Execution uses either the CLI or the connected or embedded [execution SDK](execution.md). The SDK additionally exports the client, runner, handle, result, access, approval, and error types defined there. The daemon, worker, catalog, and launcher rules below describe CLI execution; an embedded runner owns its coordinator and inline tool closures in the host process, while a connected client shares the CLI coordinator. Definition objects have readonly configuration fields and no execution methods. They contain functions and schemas and are not a serialization format.
7
+ The package is `subharness`, with the primary executable `subharness` and identical `agent` compatibility alias. Node.js 22.18 or newer is required. ESM exports include `agent`, `tool`, `toolResult`, `codex`, `claudeCode`, `fx`, `opencode`, `copilot`, `cursor`, and their definition/configuration types. The public SDK defines reusable specialists; direct CLI harness targets also execute without a definition. Execution uses either the CLI or the connected or embedded [execution SDK](execution.md). The SDK additionally exports the client, runner, handle, result, access, approval and error types defined there, and the normalized types and subscriptions in [Session events](events.md). The `subharness/extensions` subpath supplies the authoring types for [User extensions](extensions.md); compiled extension modules require no runtime import of Subharness. The daemon, worker, catalog, and launcher rules below describe CLI execution; an embedded runner owns its coordinator and inline tool closures in the host process, while a connected client shares the CLI coordinator. Definition objects have readonly configuration fields and no execution methods. They contain functions and schemas and are not a serialization format.
8
8
 
9
9
  ```ts
10
10
  import { agent, codex, claudeCode, tool } from "subharness";
@@ -34,11 +34,11 @@ Readiness means only that the selected target's startup checks passed at that mo
34
34
 
35
35
  The coordinator accepts local connections only. Its endpoint, instance identifier, and access token are stored with owner-only permissions under `~/.subharness/state/`. Task and session identifiers resolve through this coordinator from any working directory. Child invocation context is supplied privately by a session launcher that restores the coordinator location and parent context even when native shells change the inherited environment. Launchers use owner-only permissions, contain no provider credentials, and are removed when the session worker closes. Users do not supply parent identifiers or tokens in command flags. A context is accepted only while its parent task allows delegation.
36
36
 
37
- Closing a response-reading command does not cancel work. The coordinator retains responses and session records for its lifetime. A coordinator restart does not replay tasks or reconstruct queues; unavailable identifiers return an explicit error. Native harness history may still exist, but this version does not promise recovery of library sessions after coordinator or environment exit. Responses are not consumed by readers; each reader supplies its own position. Records are not silently evicted while the coordinator is running.
37
+ Closing a response-reading command does not cancel work. The coordinator retains responses and session records for its lifetime. A coordinator restart does not replay tasks or reconstruct queues; unavailable identifiers return an explicit error. This version does not recover library sessions after coordinator or environment exit. Responses are not consumed by readers; each reader supplies its own position. Task/session metadata and complete-response records are not silently evicted while the coordinator is running. Live event delivery is separate and does not retain content for later subscribers.
38
38
 
39
39
  ## Task states and responses
40
40
 
41
- The coordinator supplies the terminal dashboard with a read-only snapshot of current session work followed by retained finished tasks, including failed active tasks that pause a queue. Each task appears at most once, and retained history is available to newly opened dashboards for the coordinator’s lifetime. The private snapshot includes an explicit finished-history and grouped-context capability markers so the CLI can reject older incompatible coordinators. It carries only session/task identity, selected harness, bounded prompt title, task state, canonical checkout/repository paths, and timestamps needed by the display; it excludes environment variables, credentials, definitions, transcripts, and native diagnostics. Reading it does not acknowledge responses or change task execution. Workers report the actual selected harness to the coordinator after native startup succeeds. Task timing records the first dispatch, latest failure, and terminal completion or confirmed-stop time without resetting on native continuations. Finished rows retain a fixed elapsed duration; recovery clears terminal timing for the resumed task. Snapshot observation adds no public SDK execution method or persistent history. The inspector uses a separate authenticated, read-only session-history projection for retained work requests, stable admission ordinals, queue state and direct child sessions. Full prompt/response content is fetched only for the expanded request through the task-detail projection. It omits already-cached prompt and response text on refresh and never acknowledges delegated outcomes or changes execution. The private transport is defined in [Dashboard inspection](cli/dashboard-inspection.md); presentation is defined in [CLI](cli/index.md#live-dashboard).
41
+ The coordinator supplies the terminal dashboard with a read-only snapshot of current session work followed by retained finished tasks, including failed active tasks that pause a queue. Each task appears at most once, and retained history is available to newly opened dashboards for the coordinator’s lifetime. The private snapshot includes `history: true` for finished history, `grouping: true` for grouped context, and `taskDetails: true` for the expanded task-detail fields. Missing `history` or `grouping` ends the dashboard with `COORDINATOR_OUTDATED` and exit `1`. Missing `taskDetails` keeps the dashboard running; opening a task screen shows `COORDINATOR_OUTDATED` with restart guidance instead of task details. It carries only session/task identity, selected harness, bounded prompt title, task state, canonical checkout/repository paths, and timestamps needed by the display; it excludes environment variables, credentials, definitions, transcripts, and native diagnostics. Reading it does not acknowledge responses or change task execution. Workers report the actual selected harness to the coordinator after native startup succeeds. Task timing records the first dispatch, latest failure, and terminal completion or confirmed-stop time without resetting on native continuations. Finished rows retain a fixed elapsed duration; recovery clears terminal timing for the resumed task. Snapshot observation adds no public SDK execution method or persistent history. The inspector uses a separate authenticated, read-only session-history projection for retained work requests, stable admission ordinals, queue state and direct child sessions. Full prompt/response content and summarized agent/model identity are fetched only for the open task screen through the task-detail projection. It omits already-cached prompt and response text on refresh and never acknowledges delegated outcomes or changes execution. The core task screen renders steps from a task-scoped live subscription; those events are absent from private dashboard projections. The private transport is defined in [Dashboard inspection](cli/dashboard-inspection.md); presentation is defined in [CLI](cli/index.md#live-dashboard).
42
42
 
43
43
  Task states are `queued`, `running`, `waiting`, `awaiting_approval`, `completed`, `failed`, `cancelled`, and `interrupted`. `waiting` means the library task remains active between native turns while delegated work or child-result processing is pending. A native permission request is not a completed response. Terminal outcomes are `completed`, `failed`, `cancelled`, and `interrupted`.
44
44
 
@@ -50,7 +50,9 @@ Each session admits task-creating requests in the order the coordinator receives
50
50
 
51
51
  Steering an actively generating native turn uses native steering when available; otherwise it follows the interrupt contract: cancel the active task and its descendants, then create a replacement task with the supplied message while preserving independently queued work. The output reports the effective delivery mode. Steering a `waiting` task starts a native continuation of that same task with the new input, leaving descendants running. With no active task, steering fails; callers can submit a queued task. Acceptance means the native integration accepted the input, not that the model has acted on it.
52
52
 
53
- Cancellation closes admission of new descendants, removes queued descendants, and requests native interruption for running descendants. `cancel` returns after affected executions have stopped. Repeating cancellation of a terminal task is a harmless status read. Interruption uses the same boundary before the replacement starts; independently queued tasks keep their order. A failed cancellation leaves dispatch paused and returns an error rather than claiming execution stopped. Concurrent interrupts are serialized in admission order.
53
+ Cancellation closes admission of new descendants, removes queued descendants, and requests native interruption for running descendants. `cancel` returns after affected native turns have stopped. Repeating cancellation of a terminal task is a harmless status read. Interruption uses the same boundary before the replacement starts; independently queued tasks keep their order. A failed cancellation leaves dispatch paused and returns an error rather than claiming execution stopped. Concurrent interrupts are serialized in admission order.
54
+
55
+ A native harness can retain a tracked tool process as session-owned background work across turns. Such a process can remain alive after cancellation or task completion even though the native turn has stopped. Closing the session through the CLI or SDK, or shutting down the coordinator, closes native resources and lets the harness terminate the tool processes it tracks. A process deliberately detached outside native harness tracking remains outside both Subharness and harness ownership and can survive session close.
54
56
 
55
57
  On parent execution failure, affected descendants are cancelled before reporting the settled failure. A failed or cancelled child is delivered to its parent as an outcome the parent can interpret; it does not automatically fail the parent. Parent continuation uses the existing native session and original task. Child results received while the parent is busy are retained until they can be delivered without interrupting its turn. Results available together may be delivered in one continuation, once each.
56
58
 
@@ -78,3 +80,11 @@ Coordinators leave endpoint records in place during shutdown. Legacy pathname lo
78
80
  A successful detached task-creation request ends its service observation explicitly after the admission record while the coordinator continues to own the task.
79
81
 
80
82
  Catalog discovery evaluates TypeScript in a short-lived process with the selected execution directory as its working directory. Module stdout and stderr are not mixed into CLI output. Session workers retain their loaded instructions, tools, and harness configuration. New sessions, including delegated child sessions, load the current definition source; the library does not serialize or freeze arbitrary TypeScript closures across sessions.
83
+
84
+ ## Live events and user extensions
85
+
86
+ The public [live event API](events.md) forwards normalized session events only to currently matching subscribers. With no subscriber, adapters skip event normalization and event IPC. Native startup options needed for partial output are enabled for every session so later subscribers receive supported deltas. Opening registers before its promise resolves, and only events accepted after that registration point are delivered. Adapters keep no extra observation content. Earlier content appears only when the native route later supplies it in a snapshot; for mid-item joins on chunk-only `fx-acp` and `cursor-acp`, turn-boundary snapshots cover only content normalized since registration and use state `"incomplete"`. Pending delivery is limited to 128 events or 1 MiB per subscriber; falling behind rejects observation with `EVENT_BACKPRESSURE` without delaying execution. Content limits and redaction apply before transfer.
87
+
88
+ Static extension manifests live in global and repository directories. Explicit per-user consent is stored in the owner-only `~/.subharness/extensions.json` file under the [extension consent schema](config.md#extension-consent-and-logs), with repository consent per canonical checkout. At every newly admitted coordinator session, including connected SDK creation, the coordinator selects all enabled global extensions and enabled repository extensions for that checkout. Instance identity is the qualified reference plus the canonical checkout for repository extensions; global instances have no checkout component. Failure state, admission eligibility and re-enablement are scoped to that identity. Enabling in one checkout affects only that checkout's repository instance. Each applicable extension runs in a separately supervised child process from its first matching session until coordinator close, unless failure disables it. Execution workers, CLI dashboards and embedded runners do not load extension modules. Disabling removes eligibility for newly admitted sessions while existing assignments continue. A failed instance remains disabled and visible through `subharness extensions list` for the coordinator's lifetime, without automatic restart or failure of agents or other extensions. Explicitly enabling the selected instance identity again saves consent and notifies a running coordinator to permit a new process at the first newly admitted matching session; sessions assigned to the failed instance are not reassigned. If notification fails, consent stays saved and enable warns that the failure state clears on coordinator restart, exiting `0`. No notification is needed when no coordinator is running. Restarting the coordinator resets runtime failure state.
89
+
90
+ The CLI task screen itself opens the public task-scoped live subscription and renders incoming turns, assistant text, reasoning, tool and approval steps, and inline session-error notices. Approval and session-error rows count toward the display bound. Its original request, task error and latest complete response come from ordinary inspection. The open screen displays at most 500 steps, dropping the oldest with a visible omission notice; this bound belongs only to dashboard display state. Leaving closes the subscription and discards that state. Reopening does not retrieve past events. Earlier content appears only when the native route itself supplies it in a later snapshot; chunk-only mid-item views remain incomplete. The screen consumes events independently of rendering. After `EVENT_BACKPRESSURE`, it shows a missed-steps notice and follows the [dashboard retry bounds](cli/dashboard-design.md#refresh-and-compatibility): at most one reopen every 2 seconds, stopping after 3 consecutive failures within 60 seconds, counting failed reopens. It then shows “Live steps paused; reopen the task to retry.” SDK applications implement custom event handling through direct subscriptions. [User extensions](extensions.md) defines the plain-object module API, supervised lifetime, manifest, diagnostics and complete logger example.