subharness 0.0.7 → 0.0.10

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 (297) hide show
  1. package/README.md +40 -9
  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 +6 -1
  74. package/dist/cli/args.js +63 -5
  75. package/dist/cli/args.js.map +1 -1
  76. package/dist/cli/catalog-worker.js +3 -2
  77. package/dist/cli/catalog-worker.js.map +1 -1
  78. package/dist/cli/dashboard-client.d.ts +1 -0
  79. package/dist/cli/dashboard-client.js +13 -1
  80. package/dist/cli/dashboard-client.js.map +1 -1
  81. package/dist/cli/dashboard-controller.js +6 -7
  82. package/dist/cli/dashboard-controller.js.map +1 -1
  83. package/dist/cli/dashboard-detail-view.d.ts +14 -8
  84. package/dist/cli/dashboard-detail-view.js +15 -44
  85. package/dist/cli/dashboard-detail-view.js.map +1 -1
  86. package/dist/cli/dashboard-history-view.d.ts +3 -12
  87. package/dist/cli/dashboard-history-view.js +18 -82
  88. package/dist/cli/dashboard-history-view.js.map +1 -1
  89. package/dist/cli/dashboard-live.d.ts +32 -0
  90. package/dist/cli/dashboard-live.js +177 -0
  91. package/dist/cli/dashboard-live.js.map +1 -0
  92. package/dist/cli/dashboard-renderer.d.ts +21 -1
  93. package/dist/cli/dashboard-renderer.js +85 -21
  94. package/dist/cli/dashboard-renderer.js.map +1 -1
  95. package/dist/cli/dashboard-steps.d.ts +53 -0
  96. package/dist/cli/dashboard-steps.js +157 -0
  97. package/dist/cli/dashboard-steps.js.map +1 -0
  98. package/dist/cli/dashboard-task-format.d.ts +15 -0
  99. package/dist/cli/dashboard-task-format.js +119 -0
  100. package/dist/cli/dashboard-task-format.js.map +1 -0
  101. package/dist/cli/dashboard-task-view.d.ts +66 -0
  102. package/dist/cli/dashboard-task-view.js +325 -0
  103. package/dist/cli/dashboard-task-view.js.map +1 -0
  104. package/dist/cli/dashboard.d.ts +2 -0
  105. package/dist/cli/dashboard.js +71 -6
  106. package/dist/cli/dashboard.js.map +1 -1
  107. package/dist/cli/extensions-client.d.ts +23 -0
  108. package/dist/cli/extensions-client.js +147 -0
  109. package/dist/cli/extensions-client.js.map +1 -0
  110. package/dist/cli/extensions.d.ts +15 -0
  111. package/dist/cli/extensions.js +187 -0
  112. package/dist/cli/extensions.js.map +1 -0
  113. package/dist/cli/help.d.ts +1 -0
  114. package/dist/cli/help.js +34 -6
  115. package/dist/cli/help.js.map +1 -1
  116. package/dist/cli/main.js +100 -10
  117. package/dist/cli/main.js.map +1 -1
  118. package/dist/cli/output.js +5 -1
  119. package/dist/cli/output.js.map +1 -1
  120. package/dist/config/access.d.ts +2 -1
  121. package/dist/config/access.js +18 -7
  122. package/dist/config/access.js.map +1 -1
  123. package/dist/config/loader.d.ts +2 -0
  124. package/dist/config/loader.js +20 -6
  125. package/dist/config/loader.js.map +1 -1
  126. package/dist/config/project-context.d.ts +9 -0
  127. package/dist/config/project-context.js +41 -0
  128. package/dist/config/project-context.js.map +1 -0
  129. package/dist/config/resolve-access.d.ts +2 -1
  130. package/dist/config/resolve-access.js +5 -2
  131. package/dist/config/resolve-access.js.map +1 -1
  132. package/dist/events/content.d.ts +43 -0
  133. package/dist/events/content.js +249 -0
  134. package/dist/events/content.js.map +1 -0
  135. package/dist/events/queue.d.ts +59 -0
  136. package/dist/events/queue.js +144 -0
  137. package/dist/events/queue.js.map +1 -0
  138. package/dist/events/validate.d.ts +22 -0
  139. package/dist/events/validate.js +542 -0
  140. package/dist/events/validate.js.map +1 -0
  141. package/dist/extensions/catalog.d.ts +34 -0
  142. package/dist/extensions/catalog.js +103 -0
  143. package/dist/extensions/catalog.js.map +1 -0
  144. package/dist/extensions/child-protocol.d.ts +38 -0
  145. package/dist/extensions/child-protocol.js +2 -0
  146. package/dist/extensions/child-protocol.js.map +1 -0
  147. package/dist/extensions/child.d.ts +1 -0
  148. package/dist/extensions/child.js +125 -0
  149. package/dist/extensions/child.js.map +1 -0
  150. package/dist/extensions/consent.d.ts +13 -0
  151. package/dist/extensions/consent.js +204 -0
  152. package/dist/extensions/consent.js.map +1 -0
  153. package/dist/extensions/environment.d.ts +1 -0
  154. package/dist/extensions/environment.js +12 -0
  155. package/dist/extensions/environment.js.map +1 -0
  156. package/dist/extensions/identity.d.ts +9 -0
  157. package/dist/extensions/identity.js +28 -0
  158. package/dist/extensions/identity.js.map +1 -0
  159. package/dist/extensions/log.d.ts +5 -0
  160. package/dist/extensions/log.js +80 -0
  161. package/dist/extensions/log.js.map +1 -0
  162. package/dist/extensions/manifest.d.ts +7 -0
  163. package/dist/extensions/manifest.js +213 -0
  164. package/dist/extensions/manifest.js.map +1 -0
  165. package/dist/extensions/types.d.ts +24 -0
  166. package/dist/extensions/types.js +2 -0
  167. package/dist/extensions/types.js.map +1 -0
  168. package/dist/extensions.d.ts +5 -0
  169. package/dist/extensions.js +2 -0
  170. package/dist/extensions.js.map +1 -0
  171. package/dist/index.d.ts +1 -0
  172. package/dist/index.js.map +1 -1
  173. package/dist/runtime/approval-registry.d.ts +6 -2
  174. package/dist/runtime/approval-registry.js +31 -3
  175. package/dist/runtime/approval-registry.js.map +1 -1
  176. package/dist/runtime/capture.d.ts +4 -4
  177. package/dist/runtime/capture.js +59 -15
  178. package/dist/runtime/capture.js.map +1 -1
  179. package/dist/runtime/catalog.d.ts +6 -1
  180. package/dist/runtime/catalog.js +1 -1
  181. package/dist/runtime/catalog.js.map +1 -1
  182. package/dist/runtime/coordinator.d.ts +9 -4
  183. package/dist/runtime/coordinator.js +130 -27
  184. package/dist/runtime/coordinator.js.map +1 -1
  185. package/dist/runtime/daemon.js +9 -1
  186. package/dist/runtime/daemon.js.map +1 -1
  187. package/dist/runtime/dashboard.d.ts +4 -0
  188. package/dist/runtime/dashboard.js +8 -0
  189. package/dist/runtime/dashboard.js.map +1 -1
  190. package/dist/runtime/definition.d.ts +1 -1
  191. package/dist/runtime/definition.js +2 -2
  192. package/dist/runtime/definition.js.map +1 -1
  193. package/dist/runtime/event-operation.d.ts +41 -0
  194. package/dist/runtime/event-operation.js +290 -0
  195. package/dist/runtime/event-operation.js.map +1 -0
  196. package/dist/runtime/event-owner.d.ts +94 -0
  197. package/dist/runtime/event-owner.js +429 -0
  198. package/dist/runtime/event-owner.js.map +1 -0
  199. package/dist/runtime/event-source.d.ts +39 -0
  200. package/dist/runtime/event-source.js +344 -0
  201. package/dist/runtime/event-source.js.map +1 -0
  202. package/dist/runtime/extension-instance.d.ts +61 -0
  203. package/dist/runtime/extension-instance.js +356 -0
  204. package/dist/runtime/extension-instance.js.map +1 -0
  205. package/dist/runtime/extension-protocol.d.ts +47 -0
  206. package/dist/runtime/extension-protocol.js +33 -0
  207. package/dist/runtime/extension-protocol.js.map +1 -0
  208. package/dist/runtime/extension-service.d.ts +10 -0
  209. package/dist/runtime/extension-service.js +35 -0
  210. package/dist/runtime/extension-service.js.map +1 -0
  211. package/dist/runtime/extension-supervisor.d.ts +33 -0
  212. package/dist/runtime/extension-supervisor.js +254 -0
  213. package/dist/runtime/extension-supervisor.js.map +1 -0
  214. package/dist/runtime/select-native.d.ts +3 -1
  215. package/dist/runtime/select-native.js +32 -5
  216. package/dist/runtime/select-native.js.map +1 -1
  217. package/dist/runtime/service.d.ts +5 -0
  218. package/dist/runtime/service.js +113 -15
  219. package/dist/runtime/service.js.map +1 -1
  220. package/dist/runtime/session-event-wire.d.ts +29 -0
  221. package/dist/runtime/session-event-wire.js +2 -0
  222. package/dist/runtime/session-event-wire.js.map +1 -0
  223. package/dist/runtime/session-events-service.d.ts +8 -0
  224. package/dist/runtime/session-events-service.js +124 -0
  225. package/dist/runtime/session-events-service.js.map +1 -0
  226. package/dist/runtime/session-events-transport.d.ts +8 -0
  227. package/dist/runtime/session-events-transport.js +142 -0
  228. package/dist/runtime/session-events-transport.js.map +1 -0
  229. package/dist/runtime/startup-lock.d.ts +2 -0
  230. package/dist/runtime/startup-lock.js +49 -5
  231. package/dist/runtime/startup-lock.js.map +1 -1
  232. package/dist/runtime/state.d.ts +2 -1
  233. package/dist/runtime/state.js +4 -0
  234. package/dist/runtime/state.js.map +1 -1
  235. package/dist/runtime/transport.d.ts +1 -0
  236. package/dist/runtime/transport.js +2 -0
  237. package/dist/runtime/transport.js.map +1 -1
  238. package/dist/runtime/types.d.ts +24 -0
  239. package/dist/runtime/types.js.map +1 -1
  240. package/dist/runtime/worker-client.js +42 -13
  241. package/dist/runtime/worker-client.js.map +1 -1
  242. package/dist/runtime/worker-event-channel.d.ts +30 -0
  243. package/dist/runtime/worker-event-channel.js +141 -0
  244. package/dist/runtime/worker-event-channel.js.map +1 -0
  245. package/dist/runtime/worker-event-protocol.d.ts +88 -0
  246. package/dist/runtime/worker-event-protocol.js +114 -0
  247. package/dist/runtime/worker-event-protocol.js.map +1 -0
  248. package/dist/runtime/worker-events.d.ts +73 -0
  249. package/dist/runtime/worker-events.js +704 -0
  250. package/dist/runtime/worker-events.js.map +1 -0
  251. package/dist/runtime/worker-server.d.ts +3 -1
  252. package/dist/runtime/worker-server.js +64 -9
  253. package/dist/runtime/worker-server.js.map +1 -1
  254. package/dist/sdk/connected-events.d.ts +3 -0
  255. package/dist/sdk/connected-events.js +259 -0
  256. package/dist/sdk/connected-events.js.map +1 -0
  257. package/dist/sdk/connected-types.d.ts +2 -0
  258. package/dist/sdk/connected-types.js.map +1 -1
  259. package/dist/sdk/connected.js +3 -0
  260. package/dist/sdk/connected.js.map +1 -1
  261. package/dist/sdk/event-types.d.ts +182 -0
  262. package/dist/sdk/event-types.js +2 -0
  263. package/dist/sdk/event-types.js.map +1 -0
  264. package/dist/sdk/execution-driver.js +1 -1
  265. package/dist/sdk/execution-driver.js.map +1 -1
  266. package/dist/sdk/execution-types.d.ts +2 -0
  267. package/dist/sdk/execution-types.js.map +1 -1
  268. package/dist/sdk/runner.js +2 -0
  269. package/dist/sdk/runner.js.map +1 -1
  270. package/package.json +5 -1
  271. package/sdk/access-config.md +9 -7
  272. package/sdk/adapter-contract.md +25 -3
  273. package/sdk/agent-skill.md +8 -5
  274. package/sdk/cli/dashboard-design.md +37 -9
  275. package/sdk/cli/dashboard-inspection.md +14 -6
  276. package/sdk/cli/extensions.md +44 -0
  277. package/sdk/cli/index.md +53 -14
  278. package/sdk/cli/output.md +14 -2
  279. package/sdk/completion-notifications.md +2 -2
  280. package/sdk/config.md +65 -11
  281. package/sdk/copilot.md +1 -1
  282. package/sdk/cursor.md +2 -2
  283. package/sdk/diagnostics.md +68 -0
  284. package/sdk/distribution.md +13 -3
  285. package/sdk/events.md +339 -0
  286. package/sdk/execution.md +32 -10
  287. package/sdk/extensions.md +189 -0
  288. package/sdk/fx.md +4 -2
  289. package/sdk/harnesses.md +1 -1
  290. package/sdk/index.md +4 -0
  291. package/sdk/message-delivery.md +2 -0
  292. package/sdk/opencode.md +1 -1
  293. package/sdk/plugins/sub-agents.md +3 -1
  294. package/sdk/project-root.md +97 -0
  295. package/sdk/project-team.md +10 -4
  296. package/sdk/sessions.md +4 -0
  297. package/sdk/v1-runtime.md +22 -8
@@ -0,0 +1,189 @@
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 logical project root for a repository extension and is absent for a global extension. By default this is the Git worktree root, or the execution directory outside Git. With [CLI `--root`](project-root.md), it is the selected root, even when a session executes elsewhere; native session workspace metadata still describes its real execution directory and Git worktree. `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 project root. 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 project roots are independent; enabling one affects only that root's instance. Parent, sibling-app, and linked-worktree app roots do not share repository consent.
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 with their canonical project root. CLI `--root` selects that scope independently of execution cwd; public connected SDK creation retains default cwd-based discovery. 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>-<root-hash>.log`, where `<root-hash>` is the first 12 hex characters of the SHA-256 of the canonical project-root 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, logical project root 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
+ - `<project-root>/.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. Without `--root`, repository scope uses the nearest canonical Git worktree root, or the command's directory outside Git. With `--root`, discovery uses only that root's `.subharness/extensions/`. Enclosing project installations are not merged. Linked-worktree app roots 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 project root and never stored in repository files. Existing checkout keys remain valid; app-root keys require their own consent with no store migration. Enabled repository code is that project'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 default 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
+ For an app installation, place the artifact in `apps/my-app/.subharness/extensions/tool-result-logger/` and select the same root for consent and execution:
182
+
183
+ ```sh
184
+ subharness extensions enable repo:tool-result-logger --root ./apps/my-app
185
+ subharness extensions list --root ./apps/my-app
186
+ subharness run --root ./apps/my-app codex --prompt "Review this app."
187
+ ```
188
+
189
+ 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,8 @@ 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.
20
+ - [Logical project roots](project-root.md): app-specific agents, access and extensions, execution directories, and shared worktree access.
17
21
  - [Agent discovery](config.md): repository and global definitions, naming, and personal worktree settings.
18
22
  - [Agent skill](agent-skill.md): the installable skill that teaches a coding agent to delegate with the CLI.
19
23
 
@@ -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
 
@@ -37,7 +37,7 @@ Codex receives the same declared-child instructions and private launcher, but th
37
37
 
38
38
  For every harness, the native execution environment must allow the CLI to read its private launcher and contact the coordinator over loopback HTTP. A native sandbox that blocks local networking also blocks CLI delegation. The library does not relax that policy automatically; the caller supplies explicit native permission options, native settings, or an external execution environment. A lead can instead own independent review outside a managed agent's native delegation flow when the environment cannot grant these prerequisites.
39
39
 
40
- The command has the same arguments as an ordinary CLI invocation:
40
+ Managed runs use the ordinary prompt and execution options, with a declared `subagent:` target:
41
41
 
42
42
  ```sh
43
43
  # Execute through the host's background-command controls when available.
@@ -47,6 +47,8 @@ subharness run subagent:reviewer --cwd /repo/worktree \
47
47
 
48
48
  The suffix is the local map key. It resolves only against the current parent's direct declarations, with no ancestor/global/repository fallback. Missing parent context or an undeclared name is an error. Parent context is passed privately by the integration; no public parent-token flag is required.
49
49
 
50
+ An explicitly selected [logical project root](../project-root.md#sessions-and-managed-children) and its access root are inherited transitively. Managed `list`, `run`, and `check` cannot supply `--root`, even to repeat the inherited value. Child `--cwd` selects execution independently of inherited access and extension scope; when omitted, it uses the invoking managed command's directory. Parents without an explicit root retain default cwd-based discovery. Each native session still reads settings and credential sources at startup; inheritance does not copy a parent's resolved credentials.
51
+
50
52
  Each invocation creates a child session and task. The same `send`, `wait`, `status`, `queue`, `cancel`, and `resume` commands apply. A caller can instead coordinate independently discovered agents directly; that does not implicitly create a nested pipeline.
51
53
 
52
54
  ## Context and results
@@ -0,0 +1,97 @@
1
+ # Logical project roots
2
+
3
+ `--root <directory>` selects a Subharness project independently of the Git repository root. An application inside a monorepo can own its agents, personal access settings, and extensions. The selected directory must already exist. Subharness does not create a repository, worktree, directory, sandbox, or native permission boundary.
4
+
5
+ ```sh
6
+ subharness list --root ./apps/my-app
7
+ subharness check --root ./apps/my-app repo:reviewer
8
+ subharness run --root ./apps/my-app repo:reviewer --prompt "Review this app."
9
+ subharness extensions list --root ./apps/my-app
10
+ subharness extensions enable repo:tool-result-logger --root ./apps/my-app
11
+ subharness extensions disable repo:tool-result-logger --root ./apps/my-app
12
+ ```
13
+
14
+ The option is supported by `list`, `check`, `run`, and extension `list`, `enable`, and `disable`. Options can precede or follow a run/check target or an extension enable/disable reference. Existing prompt sources, direct-harness options, and output formats remain unchanged. Other commands do not accept `--root`; session identifiers already identify the retained execution context. Extension commands remain text-only and do not accept `--cwd`. Help retains its existing no-execution behavior and option-combination restrictions.
15
+
16
+ ## Selection and execution
17
+
18
+ Relative `--root` paths resolve from the invoking command's directory and are canonicalized. Absolute paths are accepted. A missing value, blank value, or repeated flag is `INVALID_ARGUMENT`. An inaccessible or non-directory root is `INVALID_CONFIG` with a safely quoted path. Root argument and directory-validation failures exit `2`, including extension commands. No parent directory search or automatic app discovery occurs.
19
+
20
+ Without `--root`, all existing discovery, access, execution, and extension rules remain unchanged. With `--root`, let `root` mean the canonical selected directory and `accessRoot` mean its personal-access counterpart defined below.
21
+
22
+ | Resource or argument | Explicit-root behavior |
23
+ | --- | --- |
24
+ | Repository agents | Discover only `root/.subharness/agents/`, retaining recursive `.ts` discovery and validation. |
25
+ | Global agents | Continue discovering `~/.subharness/agents/`. Qualified references and bare-name ambiguity rules are unchanged. |
26
+ | Execution directory | For a top-level invocation, an omitted `--cwd` defaults to `root`; managed children retain their invoking directory as described below. An explicit relative `--cwd` resolves from the invoking directory, independently of `--root`, and may be outside the selected project. |
27
+ | Personal settings | Load only `accessRoot/.subharness/agents.local.json`. |
28
+ | Credential and project references | Resolve relative `envFile` and `project` values, including OIDC's default project `.`, from `accessRoot`. Absolute references retain their supplied locations. |
29
+ | Repository extensions | Discover only `root/.subharness/extensions/`; use the selected root for repository consent and instance identity. |
30
+ | Global extensions | Retain their existing consent and applicability across projects. |
31
+ | Explicit definition file | Resolve relative to the invoking directory, independently of both flags. Load only the selected definition and its imports; the selected root still determines access and extensions. |
32
+
33
+ Repository catalogs, settings, and extensions are not merged with the enclosing Git repository or another app. A missing agent catalog contains no repository agents. The personal settings file remains optional: absence uses the existing documented per-harness defaults at that selected location, without reading the enclosing repository's settings. Invalid settings fail normally. Omitted harness entries, empty connection arrays, and ordered explicitly configured alternatives retain their existing access semantics.
34
+
35
+ All target forms use the selected project: repository/global specialists, unambiguous names, direct harnesses, and explicit definition files. An explicit file does not register itself in the project's catalog. A definition's module-relative imports and the native harness's own instruction discovery retain their existing rules.
36
+
37
+ ```sh
38
+ subharness run --root ./apps/my-app --cwd ./scratch \
39
+ ./shared-agents/reviewer.ts --prompt "Review the scratch directory."
40
+ ```
41
+
42
+ This command uses the app's access and enabled extensions, evaluates the selected definition in `scratch`, and runs the native harness there. Root selection does not expand native filesystem or tool permissions.
43
+
44
+ ## Personal access and worktrees
45
+
46
+ For a selected root inside Git, find its containing worktree root and main checkout independently of execution `--cwd`. The access root is the main checkout followed by the selected root's path relative to its worktree root. Outside Git, the selected root is also the access root. Nested independent Git repositories use their own worktree relationship.
47
+
48
+ ```text
49
+ Selected root: /worktrees/feature/apps/my-app
50
+ Worktree root: /worktrees/feature
51
+ Main checkout: /checkouts/repo
52
+ Access root: /checkouts/repo/apps/my-app
53
+ ```
54
+
55
+ Definitions and extensions come from the selected worktree's app. Personal settings and relative credential/project paths come from the corresponding app in the main checkout. Changing execution `--cwd` does not change either root. No personal settings or credentials are copied into a worktree.
56
+
57
+ The counterpart must be an accessible directory at the corresponding canonical path inside the main checkout. A missing counterpart or a symlink redirect to a different location fails access startup with `INVALID_CONFIG`; it never selects the parent project's settings or worktree-local credentials instead. A missing optional settings file within an accessible counterpart retains the documented absence behavior. An app that exists only in a feature worktree therefore needs its corresponding personal-access directory in the main checkout before access startup. Listing agents or managing extensions does not require access startup.
58
+
59
+ An app-local access file can use the existing schema without repeating its monorepo path:
60
+
61
+ ```json
62
+ {
63
+ "access": {
64
+ "codex": [{ "type": "vercel-oidc", "envFile": ".env.local", "project": "." }]
65
+ }
66
+ }
67
+ ```
68
+
69
+ The personal-file Git policy applies to the actual selected settings path. A tracked settings file is rejected before modifying local excludes. An untracked app settings file is excluded by its exact repository-relative path, with Git pattern characters escaped; the enclosing app and other files are not ignored. Git inspection and exclude updates use the owning repository, unaffected by inherited Git environment overrides. Existing errors remain explicit; Subharness does not untrack files or modify a committed `.gitignore`.
70
+
71
+ A repository-relative settings path containing a line feed or carriage return cannot be represented safely in Git's line-based exclude file. Loading an existing personal settings file at such a path fails with `INVALID_CONFIG` and a safely quoted path before changing local excludes. This restriction does not affect catalog listing, extension management, or settings outside Git.
72
+
73
+ The standalone OIDC renewal helper keeps its existing interface and prerequisites. For a root-selected session, resolve its absolute credential-file and project arguments from the selected connection and `accessRoot`. A subsequent top-level readiness check repeats `--root`; renewal does not change the selected account/project/billing route, refresh an already running native process, or replay work.
74
+
75
+ ## Sessions and managed children
76
+
77
+ An explicitly selected project is retained as coordinator-owned session context. Follow-ups keep that selection. Declared children inherit the selected root and access root transitively. Their execution `--cwd` can differ, but does not change inherited access or extension scope. An omitted child `--cwd` retains the invoking managed command's directory; inheritance does not reset an explicitly different parent execution directory to the project root.
78
+
79
+ Managed `list` still lists only declared children. Managed `run` and `check` still require a declared `subagent:` target and the active parent context before loading definitions or settings. Managed `list`, `run`, and `check` cannot supply `--root`, even when it names the inherited root: after validating parent authority, such an override fails with `INVALID_ARGUMENT` at the CLI/coordinator boundary. Malformed command syntax retains normal argument validation. Parents with no explicit root retain their existing cwd-based child discovery rules. Extension management independently selects its installation scope from its own `--root` or invoking directory; it does not replace any running session's retained project selection.
80
+
81
+ The selection identifies locations, not a snapshot of JSON or credentials. Each native session reads its settings and credential sources at startup under the existing access contract; follow-ups retain their already selected native connection. Root inheritance does not copy a parent's resolved token or replace the child's captured environment. Definition closures retain their existing graph-owner cwd and environment. Session close, cancellation, detach, and reconnect retain their current lifecycle behavior.
82
+
83
+ Public connected and embedded SDK creation signatures are unchanged. Connected clients can inspect or continue CLI-created root-selected sessions, but their own creation and check operations retain the existing defaults. Embedded callers continue supplying definition objects and explicit runner access/environment.
84
+
85
+ ## Extension scope and execution identity
86
+
87
+ Repository extension consent, instance identity, failure/re-enable state, status, and log hashing use the canonical selected project root. The existing consent file's `repositories` keys can represent app roots; no consent-store migration is needed. Existing checkout keys continue to apply to no-flag invocations and explicit roots equal to those checkouts. Parent, sibling-app, and linked-worktree app roots do not share repository consent. Global consent is unchanged.
88
+
89
+ `ExtensionContext.workspace` identifies the extension's logical project scope. With `--root`, it is the selected root. Enabled repository extensions receive sessions admitted to that root, even when their execution directory is elsewhere. Native session workspace metadata and dashboard Git grouping continue to describe the real execution directory and Git worktree; they are not rewritten to the logical project root.
90
+
91
+ Extension enablement retains its existing explicit consent requirement. Root selection alone does not enable an extension. Admission-time selection, retained delivery, process ownership, failure isolation, and per-instance limits remain unchanged.
92
+
93
+ ## Coordinator compatibility
94
+
95
+ An explicit-root run requires the coordinator's `cli-root-v1` capability before admission. Managed `list`, `check`, and `run` invocations that supply `--root` also require this capability before submitting a parent operation. A reachable older coordinator returns `COORDINATOR_OUTDATED` with restart guidance; the client does not submit a request that could silently ignore the root, restart the coordinator automatically, fall back to a Git-root agent/access route, or replay a task. This compatibility check precedes coordinator-side parent authorization; a capable coordinator still validates parent authority before rejecting a root override. No-root invocations retain existing compatibility. Standalone top-level `list` and `check` remain coordinator-free. Extension management does not require `cli-root-v1`; its existing status-query and enable-notification compatibility behavior remains unchanged. Managed root inheritance and validation are owned by the coordinator, not by a caller-supplied environment variable.
96
+
97
+ The CLI resolves relative roots before submission; private coordinator admission requires an absolute project-root path and rejects a relative one with `INVALID_ARGUMENT`. Readiness execution requires the retained root and access root together. An incomplete private execution context fails with `INVALID_ARGUMENT` before native startup rather than reverting to cwd-based access, and releases its captured definition resources.
@@ -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.