@north-light/cli 0.3.694 → 0.3.695

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 (178) hide show
  1. package/README.md +4 -7
  2. package/dist/api/command-manifest/result.d.ts +5 -5
  3. package/dist/api/command-manifest/result.js +1 -1
  4. package/dist/api/contract.d.ts +1 -1
  5. package/dist/api/contract.js +1 -1
  6. package/dist/api/dto/run-events.d.ts +1 -0
  7. package/dist/api/dto/run-events.js +1 -0
  8. package/dist/api/dto/worktree.d.ts +0 -4
  9. package/dist/builtin-memory/crouter-concepts/lifecycle-and-wakes.md +1 -1
  10. package/dist/builtin-memory/crouter-concepts/nodes-and-the-canvas.md +2 -2
  11. package/dist/builtin-memory/crouter-concepts/profiles-kinds-and-modes.md +1 -1
  12. package/dist/builtin-memory/crouter-concepts/scopes-and-trust.md +1 -1
  13. package/dist/builtin-memory/crouter-concepts/why-a-daemon.md +1 -1
  14. package/dist/builtin-memory/crouter-sdk/INDEX.md +3 -3
  15. package/dist/builtin-memory/crouter-sdk/README.md +14 -42
  16. package/dist/builtin-memory/crouter-sdk/client.md +5 -7
  17. package/dist/builtin-memory/crouter-sdk/docker.md +1 -1
  18. package/dist/builtin-memory/crouter-sdk/errors.md +4 -44
  19. package/dist/builtin-memory/crouter-sdk/getting-started.md +11 -83
  20. package/dist/builtin-memory/crouter-sdk/release-notes.md +10 -0
  21. package/dist/builtin-memory/crouter-sdk/resources.md +11 -44
  22. package/dist/builtin-memory/northlight-apps/guides/stream-a-run.md +6 -7
  23. package/dist/clients/attach/session/connection.d.ts +11 -2
  24. package/dist/clients/attach/session/connection.js +1 -1
  25. package/dist/clients/attach/session/keys.d.ts +2 -0
  26. package/dist/clients/attach/session/keys.js +1 -1
  27. package/dist/clients/attach/session/pane-tag.d.ts +3 -3
  28. package/dist/clients/attach/session/reconnect.js +1 -1
  29. package/dist/clients/attach/viewer.js +538 -537
  30. package/dist/commands/node-worktree.js +1 -1
  31. package/dist/commands/surface/node/placement.d.ts +2 -2
  32. package/dist/commands/surface/node/placement.js +1 -1
  33. package/dist/commands/surface.js +1 -1
  34. package/dist/core/broker-client/client.d.ts +6 -9
  35. package/dist/core/broker-client/client.js +1 -1
  36. package/dist/core/canvas/canvas.js +5 -5
  37. package/dist/core/canvas/types.d.ts +0 -2
  38. package/dist/core/conversation-store/row-store.js +10 -10
  39. package/dist/core/graph/names.js +9 -9
  40. package/dist/core/keybindings/attach-control.d.ts +3 -0
  41. package/dist/core/keybindings/attach-control.js +1 -1
  42. package/dist/core/keybindings/catalog.js +1 -1
  43. package/dist/core/ledger/chunks.d.ts +3 -1
  44. package/dist/core/ledger/chunks.js +2 -2
  45. package/dist/core/ledger/index.d.ts +1 -1
  46. package/dist/core/ledger/index.js +1 -1
  47. package/dist/core/ledger/read.d.ts +4 -0
  48. package/dist/core/ledger/read.js +2 -2
  49. package/dist/core/llm/run.js +2 -2
  50. package/dist/core/logged-step-timings.d.ts +7 -0
  51. package/dist/core/logged-step-timings.js +1 -0
  52. package/dist/core/permissions/evaluator.d.ts +2 -1
  53. package/dist/core/permissions/evaluator.js +2 -2
  54. package/dist/core/providers/receipts.js +1 -1
  55. package/dist/core/runs/operations.js +8 -8
  56. package/dist/core/runtime/broker/model-adapter.js +3 -3
  57. package/dist/core/runtime/broker.js +1 -1
  58. package/dist/core/runtime/nodes.d.ts +1 -1
  59. package/dist/core/runtime/nodes.js +1 -1
  60. package/dist/core/runtime/placement-tmux.d.ts +1 -1
  61. package/dist/core/runtime/placement-tmux.js +1 -1
  62. package/dist/core/runtime/revive.js +2 -2
  63. package/dist/core/runtime/runner/machine/ops.d.ts +2 -7
  64. package/dist/core/runtime/runner/machine/ops.js +1 -1
  65. package/dist/core/runtime/runner/machine/runner.d.ts +0 -2
  66. package/dist/core/runtime/runner/machine/runner.js +1 -1
  67. package/dist/core/runtime/tmux-bindings.js +3 -3
  68. package/dist/core/runtime/tmux-driver.d.ts +0 -10
  69. package/dist/core/runtime/tmux-driver.js +6 -6
  70. package/dist/core/step-timings.d.ts +7 -1
  71. package/dist/core/step-timings.js +1 -1
  72. package/dist/core/worktree-close.js +4 -6
  73. package/dist/core/worktree-landing.d.ts +0 -38
  74. package/dist/core/worktree-landing.js +2 -3
  75. package/dist/core/worktree-sweep.d.ts +0 -1
  76. package/dist/core/worktree-sweep.js +4 -6
  77. package/dist/core/worktree.d.ts +0 -4
  78. package/dist/core/worktree.js +13 -15
  79. package/dist/daemon/api/app-listener.d.ts +1 -0
  80. package/dist/daemon/api/app-listener.js +10 -10
  81. package/dist/daemon/api/bridge.js +4 -4
  82. package/dist/daemon/api/handlers/attach.js +1 -1
  83. package/dist/daemon/api/handlers/conversations.js +3 -3
  84. package/dist/daemon/api/server.d.ts +1 -1
  85. package/dist/daemon/api/server.js +1 -1
  86. package/dist/daemon/cron/armed-context.js +1 -1
  87. package/dist/daemon/crtrd.js +20 -18
  88. package/dist/daemon/machine-link/client.d.ts +5 -1
  89. package/dist/daemon/machine-link/client.js +1 -1
  90. package/dist/daemon/machine-link/forward.js +1 -1
  91. package/dist/daemon/machine-link/holder.js +3 -3
  92. package/dist/daemon/pidfile.js +2 -1
  93. package/dist/daemon/reconcilers/managed-worktree-sweep.js +1 -1
  94. package/dist/daemon/reconcilers/node-lifecycle/freeze-lane.js +1 -1
  95. package/dist/daemon/runs/append-section.js +2 -2
  96. package/dist/daemon/runs/observer.js +3 -3
  97. package/docs/apps/guides/stream-a-run.md +6 -7
  98. package/docs/concepts/lifecycle-and-wakes.md +1 -1
  99. package/docs/concepts/nodes-and-the-canvas.md +2 -2
  100. package/docs/concepts/profiles-kinds-and-modes.md +1 -1
  101. package/docs/concepts/scopes-and-trust.md +1 -1
  102. package/docs/concepts/why-a-daemon.md +1 -1
  103. package/docs/sdk/README.md +13 -41
  104. package/docs/sdk/client.md +5 -7
  105. package/docs/sdk/docker.md +1 -1
  106. package/docs/sdk/errors.md +3 -43
  107. package/docs/sdk/getting-started.md +11 -83
  108. package/docs/sdk/release-notes.md +10 -0
  109. package/docs/sdk/resources.md +11 -44
  110. package/package.json +3 -3
  111. package/packages/crouter-api/dist/api/command-manifest/result.js +15 -15
  112. package/packages/crouter-api/dist/api/contract.js +1 -1
  113. package/packages/crouter-api/dist/api/dto/run-events.js +1 -1
  114. package/packages/crouter-api/dist/clients/attach/session/connection.js +36 -1
  115. package/packages/crouter-api/dist/clients/attach/session/keys.js +1 -0
  116. package/packages/crouter-api/dist/clients/attach/session/reconnect.js +11 -15
  117. package/packages/crouter-api/dist/clients/attach/viewer.js +42 -5
  118. package/packages/crouter-api/dist/commands/node-worktree.js +1 -5
  119. package/packages/crouter-api/dist/commands/surface/node/placement.js +2 -2
  120. package/packages/crouter-api/dist/commands/surface.js +2 -3
  121. package/packages/crouter-api/dist/core/broker-client/client.js +5 -17
  122. package/packages/crouter-api/dist/core/canvas/canvas.js +2 -3
  123. package/packages/crouter-api/dist/core/conversation-store/row-store.js +7 -4
  124. package/packages/crouter-api/dist/core/graph/names.js +7 -20
  125. package/packages/crouter-api/dist/core/keybindings/attach-control.js +1 -0
  126. package/packages/crouter-api/dist/core/keybindings/catalog.js +2 -1
  127. package/packages/crouter-api/dist/core/ledger/chunks.js +7 -3
  128. package/packages/crouter-api/dist/core/ledger/index.js +1 -1
  129. package/packages/crouter-api/dist/core/ledger/read.js +18 -1
  130. package/packages/crouter-api/dist/core/llm/run.js +1 -1
  131. package/packages/crouter-api/dist/core/logged-step-timings.js +52 -0
  132. package/packages/crouter-api/dist/core/permissions/evaluator.js +15 -1
  133. package/packages/crouter-api/dist/core/providers/receipts.js +1 -12
  134. package/packages/crouter-api/dist/core/runs/operations.js +5 -4
  135. package/packages/crouter-api/dist/core/runtime/broker/model-adapter.js +14 -3
  136. package/packages/crouter-api/dist/core/runtime/nodes.js +2 -2
  137. package/packages/crouter-api/dist/core/runtime/placement-tmux.js +1 -1
  138. package/packages/crouter-api/dist/core/runtime/revive.js +5 -5
  139. package/packages/crouter-api/dist/core/runtime/runner/machine/ops.js +2 -7
  140. package/packages/crouter-api/dist/core/runtime/runner/machine/runner.js +4 -24
  141. package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +1 -1
  142. package/packages/crouter-api/dist/core/runtime/tmux-driver.js +0 -18
  143. package/packages/crouter-api/dist/core/step-timings.js +7 -2
  144. package/packages/crouter-api/dist/core/worktree-close.js +5 -51
  145. package/packages/crouter-api/dist/core/worktree-landing.js +0 -48
  146. package/packages/crouter-api/dist/core/worktree.js +9 -74
  147. package/packages/crouter-api/dist/daemon/cron/armed-context.js +3 -3
  148. package/packages/crouter-api/dist/daemon/machine-link/forward.js +13 -2
  149. package/packages/crouter-api/dist/daemon/machine-link/holder.js +2 -0
  150. package/packages/crouter-api/dist/daemon/pidfile.js +1 -1
  151. package/packages/crouter-api/dist/daemon/runs/append-section.js +2 -8
  152. package/packages/crouter-api/dist/daemon/runs/observer.js +3 -4
  153. package/packages/crouter-api/package.json +1 -1
  154. package/packages/crouter-identity/package.json +1 -1
  155. package/packages/crouter-plugin/dist/serve.js +1 -1
  156. package/packages/crouter-plugin/package.json +3 -3
  157. package/runtime.lock.json +14 -14
  158. package/dist/builtin-memory/crouter-sdk/bash.md +0 -40
  159. package/dist/builtin-memory/crouter-sdk/files.md +0 -50
  160. package/dist/builtin-memory/crouter-sdk/guides/README.md +0 -18
  161. package/dist/builtin-memory/crouter-sdk/guides/event-driven-assistant.md +0 -91
  162. package/dist/builtin-memory/crouter-sdk/guides/fan-out-pipeline.md +0 -57
  163. package/dist/builtin-memory/crouter-sdk/guides/human-approval.md +0 -79
  164. package/dist/builtin-memory/crouter-sdk/guides/typed-extraction.md +0 -55
  165. package/dist/builtin-memory/crouter-sdk/nodes.md +0 -195
  166. package/dist/builtin-memory/crouter-sdk/streaming.md +0 -151
  167. package/dist/commands/surface-reload.d.ts +0 -7
  168. package/dist/commands/surface-reload.js +0 -1
  169. package/docs/sdk/bash.md +0 -39
  170. package/docs/sdk/files.md +0 -49
  171. package/docs/sdk/guides/README.md +0 -17
  172. package/docs/sdk/guides/event-driven-assistant.md +0 -24
  173. package/docs/sdk/guides/fan-out-pipeline.md +0 -24
  174. package/docs/sdk/guides/human-approval.md +0 -24
  175. package/docs/sdk/guides/typed-extraction.md +0 -24
  176. package/docs/sdk/nodes.md +0 -194
  177. package/docs/sdk/streaming.md +0 -149
  178. package/packages/crouter-api/dist/commands/surface-reload.js +0 -129
package/docs/sdk/nodes.md DELETED
@@ -1,194 +0,0 @@
1
- ---
2
- title: Nodes
3
- description: Create agent runs, wait for outcomes, and parse structured results.
4
- ---
5
-
6
- # `client.nodes`
7
-
8
- Shipped, except where a row says otherwise.
9
-
10
- A node is one agent run on the crouter canvas. It is asynchronous by construction: `create` returns as soon as the daemon has spawned it, and the run keeps working after your call returns.
11
-
12
- There is one name for it — `client.nodes`. There is no `client.responses` alias. A node has a canvas identity, a kind, a working directory, a profile, a deadline, reports, subscriptions, children, and a lifecycle; naming it `responses` would promise `previous_response_id`, `output_text`, `tools`, and `store` semantics that do not exist here.
13
-
14
- ## Methods
15
-
16
- | Method | Route | Phase | Notes |
17
- |---|---|---|---|
18
- | `nodes.create(params)` | `POST /v1/nodes` | 1 | Returns immediately with the node; it is already running. |
19
- | `nodes.retrieve(id)` | `GET /v1/nodes/{id}` | 1 | |
20
- | `nodes.list(query?)` | `GET /v1/nodes` | 1 | Returns an array, as the daemon does. |
21
- | `nodes.outcome(id, { wait })` | `GET /v1/nodes/{id}/outcome?wait=` | 1 | One long poll, `wait` 0–25 s. Returns the wire envelope with `state: 'pending' | 'settled'`. |
22
- | `nodes.waitForOutcome(id, opts?)` | repeats the above | 1 | Loops until settled. Honours `signal`; no implicit time bound. |
23
- | `nodes.createAndWait(params, opts?)` | create + wait | 1 | |
24
- | `nodes.parse(params, opts?)` | create + wait + typed result | 1 | [See below](#parse-and-structured-output). |
25
- | `nodes.message(id, body)` | `POST /v1/nodes/{id}/messages` | 1 | Send a follow-up to a running or dormant node. |
26
- | `nodes.interrupt(id)` | `POST /v1/nodes/{id}/interrupt` | 1 | Stop the current turn, keep the node. |
27
- | `nodes.cancel(id, body?)` | `POST /v1/nodes/{id}/close` | 1 | Tears the node and its exclusive subtree down. `cancel` is the method name; `close` is the route. |
28
- | `nodes.update(id, patch)` | `PATCH /v1/nodes/{id}/config` | Shipped | |
29
- | `nodes.fork(id)` | `POST /v1/nodes/{id}/fork` | Shipped | |
30
- | `nodes.revive(id, body?)` | `POST /v1/nodes/{id}/revive` | Shipped | |
31
- | `nodes.promote(id, body?)` / `nodes.demote(id)` | matching routes | Shipped | Move a node between base and orchestrator mode. |
32
- | `nodes.recycle(id)` | `POST /v1/nodes/{id}/recycle` | Shipped | |
33
- | `nodes.yield(id, body?)` | `POST /v1/nodes/{id}/yield` | Shipped | |
34
- | `nodes.wait(id, body)` | `POST /v1/nodes/{id}/wait` | Shipped | |
35
- | `nodes.relaunchRoot(id)` | matching route | Shipped | |
36
- | `nodes.reviveAll()` | `POST /v1/nodes/revive-all` | Shipped | |
37
- | `nodes.stream(params, options?)` | create + `GET /…/events` | Shipped | [Streaming](./streaming.md). |
38
- | `nodes.events(id, options?)` | `GET /v1/nodes/{id}/events` | Shipped | [Streaming](./streaming.md). |
39
-
40
- Action methods keep the product's literal name (`fork`, `revive`, `promote`, `yield`) rather than being renamed into a generic verb.
41
-
42
- Every method in the table accepts `RequestOptions` as its final argument: `{ headers?, signal?, timeout?, maxRetries? }`. `nodes.stream(params, options?)` uses those options for create and stream opening, except that its stream has no wall-clock `timeout`; `nodes.events(id, options?)` takes `NodeEventsOptions`, which adds `after` and excludes `timeout`.
43
-
44
- ## Create parameters
45
-
46
- Wire fields are `snake_case`. Every `NodeCreateParams` property is optional; `parse()` additionally requires `output_schema`. `NodeCreateParams` is the daemon's `CreateNodeRequest`, except `output_schema` also accepts an object. When neither `parent` nor `root` is supplied, the SDK sends `root: true`; otherwise fields pass through without camelizing.
47
-
48
- | Field | Type | Meaning |
49
- |---|---|---|
50
- | `prompt` | `string` | The run's entire brief. |
51
- | `kind` | `string` | Persona. Omit for the profile's default. |
52
- | `model` | `string` | Durable model override. |
53
- | `profile` | `string` | The profile the run uses: its project purview, environment and profile-owned documents. An application passes **its own** profile here. |
54
- | `cwd` | `string` | Where the request came from. |
55
- | `pin_cwd` | `string` | Pin the node to this directory regardless of `cwd`. |
56
- | `situational_context` | `string` | Ambient context kept out of the visible prompt. |
57
- | `deadline` | `string` (`1h30m`) | Wall clock from spawn. Expiry cancels the node and records `deadline_exceeded`. |
58
- | `output_schema` | `string \| JsonSchema \| { toJSONSchema(): JsonSchema }` | Widened from the wire's JSON string; the SDK serializes. A zod v4 object satisfies the third form. |
59
- | `root` | `boolean` | No parent, no subscription. An application's run is a root. |
60
- | `root_lifecycle` | `'terminal' \| 'resident'` | `terminal` for a bounded run; `resident` for one a person will open and keep. |
61
- | `mode` | `'base' \| 'orchestrator'` | Whether the node works hands-on or fans out to children. |
62
- | `name` | `string` | Display label. |
63
- | `description` | `string` | Display description. |
64
- | `parent` | node id | Graph placement. An external caller leaves this unset. |
65
- | `creator` | node id | Graph placement. An external caller leaves this unset. |
66
- | `scopes` | `string[]` | Per-run allow-list. Omit it to inherit every scope, or under a scoped token to receive that token's ceiling; a list outside the ceiling answers `403 scope_denied` with the offending scopes in `details.scopes`. Scopes are prefixed (`crtr:llm`, `crtr:act`, `crtr:schedule`, `crtr:memory:…`, `crtr:files:…`); `crtr:act` requires `crtr:llm`, and the list must stay inside what the creator's grant holds. Provider-group scopes (`device:messages_send`) are enforced on the broker route; on an unsandboxed host a same-UID process can bypass the list by calling the daemon socket directly, so it guards against a mistaken call, not a hostile node. Keep the list short: it travels in a request header on every device call. See [scoped tokens](./getting-started.md#a-token-that-holds-less-than-the-owner). |
67
- | `worktree` | `string \| boolean` | Create a managed git worktree for the run. |
68
- | `fork_from` | `string` | Start from an existing conversation. |
69
- | `no_kickoff` | `boolean` | Create the node without sending the first message. |
70
- | `node_id` | `string` | Spawn at an exact id. A collision answers `409 node_id_exists`. |
71
- | `prefer_warm` | `boolean` | Serve from the warm pool when the launch tuple matches. |
72
- | `outcome_delivery` | `{ action, payload? }` | Arm outcome delivery at birth. |
73
-
74
- `node_id` is how you make a create safely retryable. Retry with the same id and a duplicate fails loudly with `409 node_id_exists` instead of quietly spawning a second agent — which is why the client never retries a `POST` for you. See [Errors](./errors.md).
75
-
76
- ## Outcomes
77
-
78
- `waitForOutcome`, `createAndWait`, and `parse` return the settled `NodeOutcome` — the same union the API defines, not a translation of it.
79
-
80
- | Wire | Narrow on | Carries |
81
- |---|---|---|
82
- | `kind: 'result'` | `outcome.kind === 'result'` | `structured_result`, `final_report_path`, and on `parse` a typed `output_parsed` |
83
- | `kind: 'failure'`, `reason: 'declined'` | `outcome.reason === 'declined'` | `declined: { reason, code, retryable } \| null` — the agent honestly refused the schema |
84
- | `kind: 'failure'`, any other `reason` | anything else | `detail: NodeOutcomeDetailV1 \| null` — `deadline_exceeded`, a provider fault, a wedge |
85
-
86
- **Agent-side outcomes are returned, never thrown.** A decline carries a typed reason, a code the agent chose, and a `retryable` flag; routing that through an exception would discard the payload and make the happy path lie about what happened. Only transport faults, daemon errors, and your own abort throw.
87
-
88
- ```ts
89
- const outcome = await client.nodes.waitForOutcome(node.node_id, { signal });
90
-
91
- switch (true) {
92
- case outcome.kind === 'result':
93
- console.log(outcome.structured_result, outcome.final_report_path);
94
- break;
95
- case outcome.reason === 'declined':
96
- console.warn(outcome.declined?.reason, outcome.declined?.retryable);
97
- break;
98
- default:
99
- console.error(outcome.reason, outcome.detail);
100
- }
101
- ```
102
-
103
- ### `outcome()` versus `waitForOutcome()`
104
-
105
- `nodes.outcome(id, { wait })` is one long poll: the daemon holds the request open for up to `wait` seconds (0–25) and answers `{ node_id, state: 'pending' | 'settled', outcome, node_status, deadline_at }`. `outcome` is `null` while `state` is `'pending'`. Use it when your own loop owns the timing — a job runner that wants to do other work between polls, or a UI that shows a heartbeat.
106
-
107
- `nodes.waitForOutcome(id, opts?)` repeats that poll until the node settles. It applies **no implicit time bound**: an agent that runs for an hour is polled for an hour. Bound it from either side — pass a `deadline` to `create` so the daemon cancels the run, or pass a `signal` so your client stops waiting.
108
-
109
- ```ts
110
- for (;;) {
111
- const poll = await client.nodes.outcome(node.node_id, { wait: 25 });
112
- if (poll.state === 'settled' && poll.outcome !== null) {
113
- console.log(poll.outcome);
114
- break;
115
- }
116
- // update your UI or job heartbeat here
117
- }
118
- ```
119
-
120
- ## `parse()` and structured output
121
-
122
- ```ts
123
- import { z } from 'zod';
124
-
125
- const run = await client.nodes.parse({
126
- prompt: 'Summarize the failing tests in this repo.',
127
- cwd: '/path/to/repo',
128
- output_schema: z.object({ failures: z.array(z.string()), root_cause: z.string() }),
129
- });
130
-
131
- if (run.kind === 'result') console.log(run.output_parsed.root_cause);
132
- else if (run.reason === 'declined') console.warn(run.declined?.reason);
133
- ```
134
-
135
- `ParsedOutcome<T>` is `NodeOutcome & { output_parsed: T | null }`, discriminated so `output_parsed` is non-null exactly when `kind === 'result'`.
136
-
137
- `output_parsed` is `structured_result` typed to the schema you passed. A Zod schema uses its inferred output type; a Standard Schema uses `~standard.types.output`. A JSON-Schema literal and any other object with `toJSONSchema()` are accepted and serialized, but their `output_parsed` type is `unknown`. The SDK does not re-validate the result — the daemon already enforces the schema when the agent submits it, so a second validation pass would only produce a second set of error messages for the same rejection. There is no helper equivalent to OpenAI's `zodTextFormat`.
138
-
139
- A candidate from Basis's real structured SDK result:
140
-
141
- ```json
142
- {
143
- "tmp": "k1",
144
- "type": "claim",
145
- "slug": "config-memories-in-project",
146
- "text": "All applet configuration memories belong in project memories.",
147
- "quote": "All configuration memories should be in the project memories. We know that.",
148
- "speaker": "Me",
149
- "confidence": "green"
150
- }
151
- ```
152
-
153
- ## Sending a follow-up
154
-
155
- `nodes.message(id, body)` appends to a node's inbox. A dormant node wakes to read it; a running node picks it up at its next turn boundary.
156
-
157
- ```ts
158
- await client.nodes.message(node.node_id, { body: 'Also check the integration lane.' });
159
- ```
160
-
161
- ## Stopping a run
162
-
163
- | Call | Effect |
164
- |---|---|
165
- | `nodes.interrupt(id)` | Stops the current turn. The node stays on the canvas and can be messaged or revived. |
166
- | `nodes.cancel(id, body?)` | Tears the node down along with the subtree it exclusively owns. Terminal. |
167
-
168
- Aborting a `signal` you passed to `waitForOutcome` stops **your client waiting**. It does not stop the node. Call `cancel` for that.
169
-
170
- ## Nested resources
171
-
172
- Nested routes become nested properties.
173
-
174
- | Property | Methods | Phase |
175
- |---|---|---|
176
- | `nodes.reports` | `list` | Shipped |
177
- | `nodes.jobs` | `list`, `cancel` | Shipped |
178
- | `nodes.worktree` | `close`, `abandon` | Shipped |
179
- | `nodes.result` | `submit` | Shipped — only an agent inside a run calls this |
180
-
181
- `nodes.reports.list(id)` returns the agent's pushed progress reports, newest first. Use it when reports are the progress view your application needs; use [streaming](./streaming.md) for live output and tool-call events.
182
-
183
- ```ts
184
- const reports = await client.nodes.reports.list(node.node_id, { limit: 10 });
185
- for (const report of reports) console.log(report.tier, report.body);
186
- ```
187
-
188
- ## Pagination
189
-
190
- List routes return what the daemon returns. `nodes.list`, `nodes.reports.list`, and `nodes.jobs.list` return plain arrays — there is no page object, no `hasNextPage()`, and no `after` cursor on them, because the daemon has no paging substrate behind those routes and an envelope there would promise a continuation that can never happen.
191
-
192
- ## Identifier validation
193
-
194
- Methods that take a node id validate it before the request: core node methods, lifecycle methods, `nodes.reports`, `nodes.jobs`, `nodes.worktree`, and `nodes.result`. An invalid id throws `TypeError` locally and sends no request. `nodes.outcome(id, { wait })` also throws `RangeError` locally when `wait` is not an integer from 0 through 25.
@@ -1,149 +0,0 @@
1
- ---
2
- title: Streaming
3
- description: Follow assistant text, tool activity, reports, and outcomes as an agent runs.
4
- ---
5
-
6
- # Streaming
7
-
8
- Watch a run as it works: assistant text as it is produced, tool calls as they start and finish, reports as they are pushed, and the settled outcome.
9
-
10
- Streaming a run of an app (forwarding it to a browser, following the reply to one message, `event: idle`, typed run events) is on the SDK docs site: [Stream a run](https://sdk.docs.northlight.ai/docs/guides/stream-a-run).
11
-
12
- ## The SDK surface
13
-
14
- ```ts
15
- const stream = client.nodes.stream({ prompt: 'Fix the failing test', cwd }, { headers: { 'x-trace': 'run-9' } });
16
-
17
- stream.on('node.output_text.delta', (event) => process.stdout.write(event.delta));
18
-
19
- for await (const event of stream) {
20
- // the same events, typed by `type`
21
- }
22
-
23
- const outcome = await stream.finalOutcome(); // resolves on node.settled
24
- stream.abort(); // ends the HTTP response; the node keeps running
25
- ```
26
-
27
- | Member | Behaviour |
28
- |---|---|
29
- | `client.nodes.stream(params, options?)` | Creates the node, then opens its event stream. Returns **synchronously**; `stream.node` is a `Promise<NodeDetailDTO>` for the created node. The request options apply to creation and to opening the stream, except `timeout`, because a stream has no wall-clock timeout. |
30
- | `client.nodes.events(id, options?)` | Validates and retrieves an existing node, then streams it. `options` is `NodeEventsOptions`: `after` plus request `headers`, `signal`, and `maxRetries`; it deliberately has no `timeout`. |
31
- | `.on(type, listener)` / `.off(type, listener)` | Typed event emitter; each returns the `NodeStream`. |
32
- | `[Symbol.asyncIterator]()` | Yields the same `NodeEventDTO` union. |
33
- | `.finalOutcome()` | Returns `Promise<NodeOutcomeDTO>`, resolving on `node.settled` and rejecting on a terminal `error` event or a connection failure. |
34
- | `.abort()` | Aborts the underlying `fetch`. An in-flight iterator and `finalOutcome()` reject with `APIUserAbortError`. Passing your own `signal` in the options aborts the stream the same way; `NodeStream` exposes no `signal` property. |
35
-
36
- The method is called `events`, not `subscribe`: a subscription is already a push-delivery edge between two nodes on the canvas, and one word must not mean two things.
37
-
38
- **A stream is an observer, never a lifecycle hold.** Disconnecting drops your subscriber and leaves the node running. Opening a stream never revives a dormant node — call `client.nodes.revive(id)` first if that is what you want.
39
-
40
- ## Activity helper
41
-
42
- `followActivity(stream, { describe? })` turns streamed tool-call events into immutable `ActivityStep[]` snapshots for a plain activity feed. `describeToolDefault(tool, summary)` names the common tools; pass `describe` to use labels for your application or return `null` to hide a tool call. Tool summaries describe the argument shape, never argument values or raw arguments.
43
-
44
- ```ts
45
- import { followActivity } from '@north-light/sdk';
46
-
47
- for await (const steps of followActivity(stream)) {
48
- render(steps);
49
- }
50
- ```
51
-
52
- A step starts as `running`; a `node.tool_call.completed` event changes it to `done` when `status` is `ok` or `failed` when `status` is `error`.
53
-
54
- ## Events
55
-
56
- Every event except `error` carries `node_id` and `sequence_number` in addition to the fields listed. `error` carries only its error object.
57
-
58
- | Event | `data` |
59
- |---|---|
60
- | `node.output_text.delta` | `{ node_id, sequence_number, delta }` |
61
- | `node.output_text.done` | `{ node_id, sequence_number, text }` |
62
- | `node.tool_call.started` | `{ node_id, sequence_number, tool_call_id, tool, summary }` |
63
- | `node.tool_call.completed` | `{ node_id, sequence_number, tool_call_id, tool, status: 'ok' \| 'error', summary }` |
64
- | `node.turn.started` | `{ node_id, sequence_number }` |
65
- | `node.turn.completed` | `{ node_id, sequence_number }` |
66
- | `node.report.pushed` | `{ node_id, sequence_number, report }` |
67
- | `node.status.changed` | `{ node_id, sequence_number, status }`, where `status` can also be stream-only `'dormant'` |
68
- | `node.settled` | `{ node_id, sequence_number, outcome }` — terminal; the daemon ends the response after it |
69
- | `error` | `{ error: { code: 'stream_gap' \| 'stream_dropped' \| 'stream_error', message, details?: { earliest_sequence?: number } } }` — `stream_gap` is recoverable; the other codes terminate the response |
70
-
71
- A turn can emit more than one `node.turn.started`. A `run.message` sent while the turn is running steers by default, so the agent reads it at its next step and the stream emits another `node.turn.started` whose `input.message_ids` holds the joined message; the turn ends with one `node.turn.completed` whose `message_ids` lists every message that joined it. A reply to one message therefore ends at the turn's completion, not at the next `node.turn.started`; the SDK's `RunReply` stops yielding text once a later message joins. Send `{ steer: false }` to start a separate turn after the current one ends.
72
-
73
- `summary` on a tool-call event states whether arguments are null, an array and its item count, an object and its field count, or a primitive type. It never includes argument values or tool output.
74
-
75
- **Deliberately not carried:** thinking deltas, the model's tool-call construction deltas, raw tool output, and the system prompt. Those belong to the owner's viewer, not to an application's run stream.
76
-
77
- ## The route
78
-
79
- ```
80
- GET /v1/nodes/{id}/events Accept: text/event-stream
81
- ?after=<sequence_number> resume from a cursor (optional)
82
- ```
83
-
84
- Server-sent events: one record per event as `event: <type>`, `data: <JSON>`, blank line, plus `: keepalive` comment lines every 15 s. Authentication is the daemon's existing rule — filesystem permission on the unix socket, bearer token over TCP.
85
-
86
- ### What you get depending on the node's state
87
-
88
- | Node state when you call | What the stream does |
89
- |---|---|
90
- | Already settled | Writes retained events when available, ending in `node.settled`; otherwise writes `node.settled` with the outcome and ends. Nothing is revived. |
91
- | Running | Streams live, seeded as described below. |
92
- | Dormant and not settled | Writes `node.status.changed { status: 'dormant' }` and holds the response open with keepalives. It starts streaming if and when the daemon brings a broker up for that node. |
93
-
94
- A node can settle between your `create` and your `events` call, so both branches are ordinary. Either way the terminal event is `node.settled`, read from the same outcome row `nodes.outcome` reads — a client that joins after settlement and a client that was live at settlement see the same outcome.
95
-
96
- ## Sequence, resume, and failure
97
-
98
- `sequence_number` is monotonic per node while that node's in-memory stream hub exists. The daemon keeps one in-memory ring per streamed node holding the last 512 events or 256 KiB, whichever binds first.
99
-
100
- | Situation | Behaviour |
101
- |---|---|
102
- | You join a run already in progress | First replays already-pushed reports oldest first, then seeds from the broker's snapshot: one `node.output_text.done` per completed assistant message, then one `node.output_text.delta` carrying the accumulated partial, then live. No content is lost — only delta granularity. |
103
- | A second subscriber joins | Seeded from the ring, so both subscribers see the same sequence numbers. |
104
- | `after=N` within the retained range | Replays events after `N`. |
105
- | `after=N` outside the retained range, including a future cursor | An `error` event with code **`stream_gap`** carries the earliest available sequence, then the stream continues from that point. It never silently skips. |
106
- | One event exceeds the 256 KiB replay budget | Live subscribers receive it, but the daemon clears the resume ring. A cursor before that event gets `stream_gap`; a cursor on it resumes at the next retained event. |
107
- | Your HTTP reader is too slow | The daemon ends the response with an `error` event whose code is **`stream_dropped`**. One slow reader cannot stall the engine. |
108
- | The node's broker is replaced or its observer socket closes | The daemon reconnects and emits `node.status.changed`. Sequence continues while the stream hub remains in memory. |
109
- | The daemon restarts | The ring is gone. A resuming client gets `stream_gap` with `earliest_sequence: 1`. There is no durable event log. |
110
- | You disconnect | Your subscriber is dropped. The node keeps running. |
111
-
112
- ### Resuming
113
-
114
- ```ts
115
- import { APIError } from '@north-light/sdk';
116
-
117
- let cursor: number | undefined;
118
-
119
- for (;;) {
120
- const stream = client.nodes.events(id, { after: cursor });
121
- try {
122
- for await (const event of stream) {
123
- if (event.type === 'error') {
124
- if (event.error.code === 'stream_gap') {
125
- console.warn('missed events before', event.error.details?.earliest_sequence);
126
- continue; // the stream continues from the floor
127
- }
128
- throw new APIError(0, event.error.code, event.error.message, event.error.details);
129
- }
130
- cursor = event.sequence_number;
131
- handle(event);
132
- }
133
- return; // ended on node.settled
134
- } catch (error) {
135
- if (error instanceof APIError && error.code === 'stream_dropped') continue;
136
- throw error;
137
- }
138
- }
139
- ```
140
-
141
- `stream_gap` is recoverable and the stream continues after it. `stream_dropped` is terminal for that HTTP response — reconnect with the cursor you last saw.
142
-
143
- ## Identifier validation
144
-
145
- `nodes.events(id, options?)` validates `id` before it requests the node or opens SSE. Because it returns a `NodeStream` synchronously, an invalid node identifier rejects `stream.node`, `stream.finalOutcome()`, and an iteration with `TypeError`; no request is sent. See [Errors](./errors.md#identifier-validation).
146
-
147
- ## Event shapes depend on the pinned pi version
148
-
149
- The delta and tool-call shapes come from the installed `@earendil-works/pi-agent-core` and `pi-ai` packages, not from crouter. The daemon's translator is the one place that depends on them. A pi version bump must be checked against it.
@@ -1,129 +0,0 @@
1
- // `crtr surface reload` — hot-reload a viewer pane in place.
2
- //
3
- // A viewer process loads its runtime generation at startup and never reloads
4
- // it, so after a runtime roll an already-open pane keeps running the old
5
- // generation against the new crtrd. Respawning the pane with the viewer's own
6
- // `crtr surface attach to <id>` command line means the fresh process picks up
7
- // the currently selected generation while the pane and broker are untouched.
8
- import { defineLeaf } from '../core/command.js';
9
- import { InputError } from '../core/io.js';
10
- import { listProcessTable } from '../core/canvas/pid.js';
11
- import { displayMessage } from '../core/runtime/tmux-chrome.js';
12
- import { nodeInPane, paneCurrentPath, panePid, paneStartCommand, respawnPaneInPlace, respawnPaneSync, viewerSplitEnv, } from './surface/node/placement.js';
13
- /** True when `rootPid` (the pane's `#{pane_pid}`) or any descendant of it is a
14
- * live `crtr surface attach to <nodeId>` viewer process. This is how a
15
- * shell-hosted viewer is recognized: older panes were opened as a login shell
16
- * that then ran the viewer, so their `#{pane_start_command}` is `zsh -l` and
17
- * only the live process tree reveals the viewer. One process-table snapshot, walked
18
- * from the pane's root pid. */
19
- function paneTreeHasViewer(rootPid, nodeId) {
20
- const table = listProcessTable();
21
- if (table === null)
22
- return false;
23
- const childrenOf = new Map();
24
- const commandOf = new Map();
25
- for (const { pid, ppid, command } of table) {
26
- commandOf.set(pid, command);
27
- const siblings = childrenOf.get(ppid) ?? [];
28
- siblings.push(pid);
29
- childrenOf.set(ppid, siblings);
30
- }
31
- // Node ids are [a-z0-9-] so splicing one into a regex is safe. The viewer
32
- // shows up as e.g. `node /opt/homebrew/bin/crtr surface attach to <id>`.
33
- const viewer = new RegExp(`(?:^|\\s)surface attach to ${nodeId}(?:\\s|$)`);
34
- const queue = [rootPid];
35
- while (queue.length > 0) {
36
- const pid = queue.pop();
37
- const command = commandOf.get(pid);
38
- if (command !== undefined && viewer.test(command))
39
- return true;
40
- const kids = childrenOf.get(pid);
41
- if (kids !== undefined)
42
- queue.push(...kids);
43
- }
44
- return false;
45
- }
46
- /** The node a `crtr surface attach to <id>` command line targets. Panes opened
47
- * by a respawn path (the Markdown file-open bridge, the review companion) carry
48
- * a shell-quoted id, so the raw command line is not comparable to the canonical
49
- * one — the target node is. */
50
- export function attachTargetNode(command) {
51
- const match = /(?:^|\s)surface attach to\s+(?:'([^']*)'|"([^"]*)"|(\S+))/.exec(command);
52
- return match?.[1] ?? match?.[2] ?? match?.[3];
53
- }
54
- export const surfaceReloadLeaf = defineLeaf({
55
- name: 'reload',
56
- description: 'respawn a viewer pane in place onto the current runtime generation',
57
- whenToUse: 'a viewer pane predates a runtime roll and should be refreshed onto the selected generation without losing the pane or the node it views',
58
- help: {
59
- name: 'surface reload',
60
- summary: 'kill and re-run a viewer pane’s `crtr surface attach to <node>` command line in place, so the fresh viewer picks up the currently selected runtime generation',
61
- params: [
62
- { kind: 'flag', name: 'pane', type: 'string', required: false, constraint: 'tmux pane id hosting the viewer to reload. Defaults to $TMUX_PANE / your current pane. The Alt+C menu passes this for you.' },
63
- ],
64
- output: [
65
- { name: 'pane', type: 'string', required: true, constraint: 'The respawned tmux pane.' },
66
- { name: 'node_id', type: 'string', required: true, constraint: 'The node whose viewer was reloaded.' },
67
- ],
68
- outputKind: 'object',
69
- effects: ['Kills the pane’s viewer process and re-runs the viewer command line in the same pane; the node’s broker engine keeps running untouched.'],
70
- },
71
- run: async (input) => {
72
- const pane = input['pane'] ?? process.env['TMUX_PANE'];
73
- if (pane === undefined || pane === '') {
74
- throw new InputError({ error: 'not_in_tmux', message: 'viewer reload is tmux-only — no tmux pane to target', next: 'Run it inside tmux, or pass --pane <pane-id> of a tmux viewer pane.' });
75
- }
76
- // Only respawn a pane that actually hosts a viewer FOR THE TAGGED NODE. The
77
- // node tag alone is not enough — workspace shell panes carry `@crtr_node`
78
- // too, and respawning one would kill a live shell the user is working in.
79
- // Two shapes qualify:
80
- // 1. The pane's start command IS the viewer (tmux launched `crtr surface
81
- // attach to <id>` as the pane command) → a bare `respawn-pane -k`
82
- // replays that exact line.
83
- // 2. The pane was started as a shell (`zsh -l`) that is now RUNNING the
84
- // viewer as a live child process → respawn with an explicit
85
- // `crtr surface attach to <node>` command, because replaying the
86
- // shell line would leave a bare shell instead of a viewer.
87
- // A tagged pane sitting at a shell prompt with no live viewer matches
88
- // neither and is refused — killing it would lose the user's shell.
89
- const nodeId = nodeInPane(pane);
90
- if (nodeId === undefined) {
91
- displayMessage('crtr: no viewer in pane', pane);
92
- throw new InputError({ error: 'no_viewer', message: 'this pane does not host an attach viewer', next: 'Pass --pane <pane-id> for a pane running `crtr surface attach to <node>`.' });
93
- }
94
- const viewerCommand = `crtr surface attach to ${nodeId}`;
95
- // tmux wraps #{pane_start_command} in literal double quotes.
96
- const startCommand = paneStartCommand(pane)?.replace(/^"|"$/g, '');
97
- if (startCommand !== undefined && startCommand.startsWith('crtr surface attach ')) {
98
- // The start command must target the TAGGED node — a mismatch means the
99
- // tag is stale or the viewer belongs to another node; don't touch it.
100
- if (attachTargetNode(startCommand) !== nodeId) {
101
- displayMessage('crtr: viewer/node mismatch in pane', pane);
102
- throw new InputError({ error: 'no_viewer', message: `this pane's viewer command (${startCommand}) does not match its node tag (${nodeId})`, next: 'Pass --pane <pane-id> for a pane running `crtr surface attach to <node>`.' });
103
- }
104
- if (!respawnPaneInPlace(pane)) {
105
- displayMessage('crtr: viewer reload failed', pane);
106
- throw new InputError({ error: 'respawn_failed', message: `tmux could not respawn pane ${pane}`, next: 'Check the tmux server is reachable, then retry.' });
107
- }
108
- displayMessage('crtr: viewer reloaded', pane);
109
- return { pane, node_id: nodeId };
110
- }
111
- const rootPid = panePid(pane);
112
- if (rootPid === undefined || !paneTreeHasViewer(rootPid, nodeId)) {
113
- displayMessage('crtr: no viewer in pane', pane);
114
- throw new InputError({ error: 'no_viewer', message: 'this pane does not host an attach viewer', next: 'Pass --pane <pane-id> for a pane running `crtr surface attach to <node>`.' });
115
- }
116
- // Shell-hosted viewer: respawn onto the viewer command directly. The pane
117
- // deliberately converges on the viewer-as-pane-command shape every other
118
- // crtr surface uses today, so its start command becomes truthful and the
119
- // next reload takes the replay path.
120
- const cwd = paneCurrentPath(pane) ?? process.cwd();
121
- if (!respawnPaneSync({ pane, cwd, env: viewerSplitEnv(), command: viewerCommand })) {
122
- displayMessage('crtr: viewer reload failed', pane);
123
- throw new InputError({ error: 'respawn_failed', message: `tmux could not respawn pane ${pane}`, next: 'Check the tmux server is reachable, then retry.' });
124
- }
125
- displayMessage('crtr: viewer reloaded', pane);
126
- return { pane, node_id: nodeId };
127
- },
128
- render: (r) => `Reloaded viewer for ${r['node_id']} in pane ${r['pane']}.`,
129
- });