@north-light/cli 0.3.693 → 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 (208) 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/api/errors.js +1 -1
  10. package/dist/builtin-memory/crouter-concepts/lifecycle-and-wakes.md +1 -1
  11. package/dist/builtin-memory/crouter-concepts/nodes-and-the-canvas.md +2 -2
  12. package/dist/builtin-memory/crouter-concepts/profiles-kinds-and-modes.md +1 -1
  13. package/dist/builtin-memory/crouter-concepts/scopes-and-trust.md +1 -1
  14. package/dist/builtin-memory/crouter-concepts/why-a-daemon.md +1 -1
  15. package/dist/builtin-memory/crouter-sdk/INDEX.md +3 -3
  16. package/dist/builtin-memory/crouter-sdk/README.md +14 -42
  17. package/dist/builtin-memory/crouter-sdk/client.md +5 -7
  18. package/dist/builtin-memory/crouter-sdk/docker.md +1 -1
  19. package/dist/builtin-memory/crouter-sdk/errors.md +4 -44
  20. package/dist/builtin-memory/crouter-sdk/getting-started.md +11 -83
  21. package/dist/builtin-memory/crouter-sdk/release-notes.md +10 -0
  22. package/dist/builtin-memory/crouter-sdk/resources.md +11 -44
  23. package/dist/builtin-memory/northlight-apps/guides/stream-a-run.md +6 -7
  24. package/dist/cli.js +6 -6
  25. package/dist/clients/attach/session/connection.d.ts +11 -2
  26. package/dist/clients/attach/session/connection.js +1 -1
  27. package/dist/clients/attach/session/keys.d.ts +2 -0
  28. package/dist/clients/attach/session/keys.js +1 -1
  29. package/dist/clients/attach/session/pane-tag.d.ts +3 -3
  30. package/dist/clients/attach/session/reconnect.js +1 -1
  31. package/dist/clients/attach/viewer.js +538 -537
  32. package/dist/commands/node/inspect.js +9 -9
  33. package/dist/commands/node-worktree.js +1 -1
  34. package/dist/commands/pkg/market-manage.js +1 -1
  35. package/dist/commands/pkg/plugin-manage.js +1 -1
  36. package/dist/commands/surface/node/placement.d.ts +2 -2
  37. package/dist/commands/surface/node/placement.js +1 -1
  38. package/dist/commands/surface.js +1 -1
  39. package/dist/commands/sys/update.js +1 -1
  40. package/dist/core/broker-client/client.d.ts +6 -9
  41. package/dist/core/broker-client/client.js +1 -1
  42. package/dist/core/canvas/canvas.js +7 -7
  43. package/dist/core/canvas/types.d.ts +0 -2
  44. package/dist/core/config.js +1 -1
  45. package/dist/core/conversation-store/row-store.js +10 -10
  46. package/dist/core/graph/exposures.js +1 -1
  47. package/dist/core/graph/names.js +9 -9
  48. package/dist/core/graph/watches.js +1 -1
  49. package/dist/core/installed-plugins.js +1 -1
  50. package/dist/core/keybindings/attach-control.d.ts +3 -0
  51. package/dist/core/keybindings/attach-control.js +1 -1
  52. package/dist/core/keybindings/catalog.js +1 -1
  53. package/dist/core/ledger/chunks.d.ts +3 -1
  54. package/dist/core/ledger/chunks.js +2 -2
  55. package/dist/core/ledger/index.d.ts +1 -1
  56. package/dist/core/ledger/index.js +1 -1
  57. package/dist/core/ledger/read.d.ts +4 -0
  58. package/dist/core/ledger/read.js +2 -2
  59. package/dist/core/llm/run.js +2 -2
  60. package/dist/core/logged-step-timings.d.ts +7 -0
  61. package/dist/core/logged-step-timings.js +1 -0
  62. package/dist/core/permissions/evaluator.d.ts +2 -1
  63. package/dist/core/permissions/evaluator.js +2 -2
  64. package/dist/core/providers/receipts.js +1 -1
  65. package/dist/core/runs/operations.js +8 -8
  66. package/dist/core/runtime/broker/model-adapter.js +3 -3
  67. package/dist/core/runtime/broker.js +1 -1
  68. package/dist/core/runtime/nodes.d.ts +1 -1
  69. package/dist/core/runtime/nodes.js +1 -1
  70. package/dist/core/runtime/placement-tmux.d.ts +1 -1
  71. package/dist/core/runtime/placement-tmux.js +1 -1
  72. package/dist/core/runtime/revive.js +2 -2
  73. package/dist/core/runtime/runner/machine/ops.d.ts +2 -7
  74. package/dist/core/runtime/runner/machine/ops.js +1 -1
  75. package/dist/core/runtime/runner/machine/runner.d.ts +0 -2
  76. package/dist/core/runtime/runner/machine/runner.js +1 -1
  77. package/dist/core/runtime/tmux-bindings.js +3 -3
  78. package/dist/core/runtime/tmux-driver.d.ts +0 -10
  79. package/dist/core/runtime/tmux-driver.js +6 -6
  80. package/dist/core/scoped-state/imported-mac-installs.d.ts +12 -0
  81. package/dist/core/scoped-state/imported-mac-installs.js +2 -0
  82. package/dist/core/spaces/stop.js +1 -1
  83. package/dist/core/step-timings.d.ts +7 -1
  84. package/dist/core/step-timings.js +1 -1
  85. package/dist/core/worktree-close.js +4 -6
  86. package/dist/core/worktree-landing.d.ts +0 -38
  87. package/dist/core/worktree-landing.js +2 -3
  88. package/dist/core/worktree-sweep.d.ts +0 -1
  89. package/dist/core/worktree-sweep.js +4 -6
  90. package/dist/core/worktree.d.ts +0 -4
  91. package/dist/core/worktree.js +13 -15
  92. package/dist/daemon/api/app-listener.d.ts +1 -0
  93. package/dist/daemon/api/app-listener.js +10 -10
  94. package/dist/daemon/api/bridge.js +4 -4
  95. package/dist/daemon/api/handlers/attach.js +1 -1
  96. package/dist/daemon/api/handlers/conversations.js +3 -3
  97. package/dist/daemon/api/server.d.ts +1 -1
  98. package/dist/daemon/api/server.js +1 -1
  99. package/dist/daemon/cron/armed-context.js +1 -1
  100. package/dist/daemon/crtrd.js +20 -18
  101. package/dist/daemon/machine-link/client.d.ts +5 -1
  102. package/dist/daemon/machine-link/client.js +1 -1
  103. package/dist/daemon/machine-link/forward.js +1 -1
  104. package/dist/daemon/machine-link/holder.js +3 -3
  105. package/dist/daemon/pidfile.js +2 -1
  106. package/dist/daemon/reconcilers/managed-worktree-sweep.js +1 -1
  107. package/dist/daemon/reconcilers/node-lifecycle/freeze-lane.js +1 -1
  108. package/dist/daemon/runs/append-section.js +2 -2
  109. package/dist/daemon/runs/observer.js +3 -3
  110. package/dist/shared/env.d.ts +8 -3
  111. package/dist/shared/env.js +2 -2
  112. package/dist/types.d.ts +1 -1
  113. package/dist/types.js +1 -1
  114. package/docs/apps/guides/stream-a-run.md +6 -7
  115. package/docs/concepts/lifecycle-and-wakes.md +1 -1
  116. package/docs/concepts/nodes-and-the-canvas.md +2 -2
  117. package/docs/concepts/profiles-kinds-and-modes.md +1 -1
  118. package/docs/concepts/scopes-and-trust.md +1 -1
  119. package/docs/concepts/why-a-daemon.md +1 -1
  120. package/docs/sdk/README.md +13 -41
  121. package/docs/sdk/client.md +5 -7
  122. package/docs/sdk/docker.md +1 -1
  123. package/docs/sdk/errors.md +3 -43
  124. package/docs/sdk/getting-started.md +11 -83
  125. package/docs/sdk/release-notes.md +10 -0
  126. package/docs/sdk/resources.md +11 -44
  127. package/package.json +3 -3
  128. package/packages/crouter-api/dist/api/command-manifest/result.js +15 -15
  129. package/packages/crouter-api/dist/api/contract.js +1 -1
  130. package/packages/crouter-api/dist/api/dto/run-events.js +1 -1
  131. package/packages/crouter-api/dist/api/errors.js +1 -1
  132. package/packages/crouter-api/dist/clients/attach/session/connection.js +36 -1
  133. package/packages/crouter-api/dist/clients/attach/session/keys.js +1 -0
  134. package/packages/crouter-api/dist/clients/attach/session/reconnect.js +11 -15
  135. package/packages/crouter-api/dist/clients/attach/viewer.js +42 -5
  136. package/packages/crouter-api/dist/commands/node/inspect.js +16 -2
  137. package/packages/crouter-api/dist/commands/node-worktree.js +1 -5
  138. package/packages/crouter-api/dist/commands/pkg/market-manage.js +22 -19
  139. package/packages/crouter-api/dist/commands/pkg/plugin-manage.js +2 -1
  140. package/packages/crouter-api/dist/commands/surface/node/placement.js +2 -2
  141. package/packages/crouter-api/dist/commands/surface.js +2 -3
  142. package/packages/crouter-api/dist/commands/sys/update.js +5 -3
  143. package/packages/crouter-api/dist/core/broker-client/client.js +5 -17
  144. package/packages/crouter-api/dist/core/canvas/canvas.js +6 -11
  145. package/packages/crouter-api/dist/core/config.js +10 -3
  146. package/packages/crouter-api/dist/core/conversation-store/row-store.js +7 -4
  147. package/packages/crouter-api/dist/core/graph/exposures.js +1 -1
  148. package/packages/crouter-api/dist/core/graph/names.js +7 -20
  149. package/packages/crouter-api/dist/core/graph/watches.js +1 -1
  150. package/packages/crouter-api/dist/core/installed-plugins.js +3 -2
  151. package/packages/crouter-api/dist/core/keybindings/attach-control.js +1 -0
  152. package/packages/crouter-api/dist/core/keybindings/catalog.js +2 -1
  153. package/packages/crouter-api/dist/core/ledger/chunks.js +7 -3
  154. package/packages/crouter-api/dist/core/ledger/index.js +1 -1
  155. package/packages/crouter-api/dist/core/ledger/read.js +18 -1
  156. package/packages/crouter-api/dist/core/llm/run.js +1 -1
  157. package/packages/crouter-api/dist/core/logged-step-timings.js +52 -0
  158. package/packages/crouter-api/dist/core/permissions/evaluator.js +15 -1
  159. package/packages/crouter-api/dist/core/providers/receipts.js +1 -12
  160. package/packages/crouter-api/dist/core/runs/operations.js +5 -4
  161. package/packages/crouter-api/dist/core/runtime/broker/model-adapter.js +14 -3
  162. package/packages/crouter-api/dist/core/runtime/nodes.js +2 -2
  163. package/packages/crouter-api/dist/core/runtime/placement-tmux.js +1 -1
  164. package/packages/crouter-api/dist/core/runtime/revive.js +5 -5
  165. package/packages/crouter-api/dist/core/runtime/runner/machine/ops.js +2 -7
  166. package/packages/crouter-api/dist/core/runtime/runner/machine/runner.js +4 -24
  167. package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +1 -1
  168. package/packages/crouter-api/dist/core/runtime/tmux-driver.js +0 -18
  169. package/packages/crouter-api/dist/core/scoped-state/imported-mac-installs.js +94 -0
  170. package/packages/crouter-api/dist/core/spaces/stop.js +2 -2
  171. package/packages/crouter-api/dist/core/step-timings.js +7 -2
  172. package/packages/crouter-api/dist/core/worktree-close.js +5 -51
  173. package/packages/crouter-api/dist/core/worktree-landing.js +0 -48
  174. package/packages/crouter-api/dist/core/worktree.js +9 -74
  175. package/packages/crouter-api/dist/daemon/cron/armed-context.js +3 -3
  176. package/packages/crouter-api/dist/daemon/machine-link/forward.js +13 -2
  177. package/packages/crouter-api/dist/daemon/machine-link/holder.js +2 -0
  178. package/packages/crouter-api/dist/daemon/pidfile.js +1 -1
  179. package/packages/crouter-api/dist/daemon/runs/append-section.js +2 -8
  180. package/packages/crouter-api/dist/daemon/runs/observer.js +3 -4
  181. package/packages/crouter-api/dist/shared/env.js +15 -4
  182. package/packages/crouter-api/dist/types.js +1 -1
  183. package/packages/crouter-api/package.json +1 -1
  184. package/packages/crouter-identity/package.json +1 -1
  185. package/packages/crouter-plugin/dist/serve.js +1 -1
  186. package/packages/crouter-plugin/package.json +3 -3
  187. package/runtime.lock.json +14 -14
  188. package/dist/builtin-memory/crouter-sdk/bash.md +0 -40
  189. package/dist/builtin-memory/crouter-sdk/files.md +0 -50
  190. package/dist/builtin-memory/crouter-sdk/guides/README.md +0 -18
  191. package/dist/builtin-memory/crouter-sdk/guides/event-driven-assistant.md +0 -91
  192. package/dist/builtin-memory/crouter-sdk/guides/fan-out-pipeline.md +0 -57
  193. package/dist/builtin-memory/crouter-sdk/guides/human-approval.md +0 -79
  194. package/dist/builtin-memory/crouter-sdk/guides/typed-extraction.md +0 -55
  195. package/dist/builtin-memory/crouter-sdk/nodes.md +0 -195
  196. package/dist/builtin-memory/crouter-sdk/streaming.md +0 -151
  197. package/dist/commands/surface-reload.d.ts +0 -7
  198. package/dist/commands/surface-reload.js +0 -1
  199. package/docs/sdk/bash.md +0 -39
  200. package/docs/sdk/files.md +0 -49
  201. package/docs/sdk/guides/README.md +0 -17
  202. package/docs/sdk/guides/event-driven-assistant.md +0 -24
  203. package/docs/sdk/guides/fan-out-pipeline.md +0 -24
  204. package/docs/sdk/guides/human-approval.md +0 -24
  205. package/docs/sdk/guides/typed-extraction.md +0 -24
  206. package/docs/sdk/nodes.md +0 -194
  207. package/docs/sdk/streaming.md +0 -149
  208. package/packages/crouter-api/dist/commands/surface-reload.js +0 -129
@@ -1,50 +0,0 @@
1
- ---
2
- kind: knowledge
3
- when-and-why-to-read: When you need Files, this knowledge should be read because
4
- Read, write, and list host files through the daemon.
5
- ---
6
-
7
- # `client.files`
8
-
9
- `client.files` reads, writes, and lists host files through the daemon.
10
-
11
- ```ts
12
- const source = await client.files.read('/absolute/path/to/input.txt');
13
- const written = await client.files.write('/absolute/path/to/output.txt', source.content);
14
- const directory = await client.files.list('/absolute/path/to');
15
- ```
16
-
17
- Every `path` is absolute. Relative paths and `~` are not expanded. File paths are sent to the daemon unchanged; the daemon checks that they are absolute and returns a mapped API error when they are not.
18
-
19
- Every method accepts ordinary request options in its final object: `headers`, `signal`, `timeout`, and `maxRetries`. `read` and `write` add `encoding`; `list` adds `limit`.
20
-
21
- ## Read
22
-
23
- ```ts
24
- await client.files.read(path, { encoding: 'utf8', timeout: 5_000 });
25
- await client.files.read(path, { encoding: 'base64' });
26
- ```
27
-
28
- `read(path, options?)` returns `Promise<FilePeekDTO>`, `{ path, content, truncated }`, through `GET /v1/files/peek`. It captures at most 512 KiB of file bytes. `truncated: true` means `content` is only the prefix. Request `base64` for binary content.
29
-
30
- ## Write
31
-
32
- ```ts
33
- const result = await client.files.write(path, content, { encoding: 'utf8' });
34
- // result is { path, bytes_written }
35
- await client.files.write(path, bytes.toString('base64'), { encoding: 'base64' });
36
- ```
37
-
38
- `write(path, content, options?)` returns `Promise<FileWriteDTO>`, `{ path, bytes_written }`. Writes create parent directories and atomically replace the target. If `path` is an existing symlink, the daemon resolves it and atomically replaces its destination; the symlink remains. Decoded content above 1 MiB is refused with `UnprocessableEntityError` carrying `status: 413` and `code: 'file_too_large'`; it is never truncated or partially written.
39
-
40
- ## List
41
-
42
- ```ts
43
- const result = await client.files.list(path, { limit: 100 });
44
- ```
45
-
46
- `list(path, options?)` returns `Promise<FileListDTO>`, `{ path, entries, truncated }`, for one directory level. Each entry has `name`, `type: 'file' | 'dir' | 'other'`, `size`, and ISO-8601 `modified`. `limit` must be a positive integer; the default is 1000. `truncated: true` means the directory had more entries than the requested limit.
47
-
48
- ## Authority
49
-
50
- The token is the owner credential. Anyone holding it can already create an agent with a bash tool, so these methods run with the daemon user's authority and do not provide a restricted file area.
@@ -1,18 +0,0 @@
1
- ---
2
- kind: knowledge
3
- when-and-why-to-read: When composing crouter SDK namespaces into an application,
4
- read this because it helps you choose a complete runnable starting point.
5
- ---
6
-
7
- # SDK recipes
8
-
9
- These recipes turn the SDK namespaces into complete applications: a bounded extraction, an assistant that waits for events, a research pipeline, and a human approval step.
10
-
11
- | Recipe | Use it when | It ends with |
12
- |---|---|---|
13
- | [[crouter-sdk/guides/typed-extraction]] | You need one structured answer and no follow-up. | A typed object or an explicit failure. |
14
- | [[crouter-sdk/guides/event-driven-assistant]] | Events arrive over time from a webhook, queue, or watcher. | A resident node that wakes for each event. |
15
- | [[crouter-sdk/guides/fan-out-pipeline]] | One task needs independent research before a synthesis. | An orchestrator's final report. |
16
- | [[crouter-sdk/guides/human-approval]] | A person must decide before work continues. | A node resumed by an inbox answer. |
17
-
18
- Start with typed extraction for a request/response job. Use a resident node when the same assistant should react again later. Use an orchestrator only when child work can proceed independently; otherwise keep the composition in your application.
@@ -1,91 +0,0 @@
1
- ---
2
- kind: knowledge
3
- when-and-why-to-read: When an assistant must react to later webhook, queue, or
4
- file-watcher events, read this because a resident node sleeps until
5
- nodes.message delivers the next event.
6
- ---
7
-
8
- # Event-driven assistant
9
-
10
- Use this recipe for an assistant that reacts to an event source instead of ending after one request. Run `npx tsx examples/guides/event-driven-assistant.ts /path/to/repo`, then type events into standard input to stand in for a webhook handler or file watcher.
11
-
12
- ```ts
13
- import Crouter from '@north-light/sdk';
14
- import { resolve } from 'node:path';
15
- import { createInterface } from 'node:readline';
16
-
17
- const client = new Crouter();
18
- const cwd = resolve(process.argv[2] ?? process.cwd());
19
-
20
- const assistant = await client.nodes.create({
21
- name: 'event assistant',
22
- cwd,
23
- model: process.env.GUIDE_MODEL,
24
- root: true,
25
- root_lifecycle: 'resident',
26
- no_kickoff: true,
27
- situational_context: `You are a standing assistant. Each inbox message is an event from an external source. For each event, briefly state what happened and one useful next action, then push that response as an update report with crtr push update. Do not push final. End the turn and go dormant after reporting. Do not poll or schedule a timer: another event will arrive as a message.`,
28
- });
29
-
30
- console.log(`assistant node: ${assistant.node_id}`);
31
- console.log('Type an event and press Enter. Press Ctrl-C to stop the assistant.');
32
-
33
- const input = createInterface({ input: process.stdin, crlfDelay: Infinity });
34
- let stopping: Promise<void> | undefined;
35
-
36
- function stop(): Promise<void> {
37
- if (stopping !== undefined) return stopping;
38
- input.close();
39
- stopping = client.nodes.cancel(assistant.node_id).then(() => undefined);
40
- return stopping;
41
- }
42
-
43
- process.once('SIGINT', () => {
44
- void stop().catch((error: unknown) => {
45
- console.error(error);
46
- process.exitCode = 1;
47
- });
48
- });
49
-
50
- for await (const line of input) {
51
- if (stopping !== undefined) break;
52
- if (line.trim() === '') continue;
53
- try {
54
- const previous = (await client.nodes.reports.list(assistant.node_id, { limit: 1 }))[0]?.id;
55
- if (stopping !== undefined) break;
56
- await client.nodes.message(assistant.node_id, { body: line });
57
- while (stopping === undefined) {
58
- const report = (await client.nodes.reports.list(assistant.node_id, { limit: 1 }))[0];
59
- if (stopping !== undefined) break;
60
- if (report !== undefined && report.id !== previous) {
61
- console.log(report.body);
62
- break;
63
- }
64
- const state = await client.nodes.retrieve(assistant.node_id);
65
- if (stopping !== undefined) break;
66
- if (state.fault?.retry.disposition === 'fatal' || state.status === 'dead' || state.status === 'canceled') {
67
- throw new Error(`assistant stopped without reporting: ${state.fault?.message ?? state.status}`);
68
- }
69
- await new Promise((resolve) => setTimeout(resolve, 1000));
70
- }
71
- } catch (error) {
72
- if (stopping === undefined) throw error;
73
- }
74
- }
75
-
76
- await stop();
77
- ```
78
-
79
- The external source owns detection. When it receives an event, it calls `nodes.message(nodeId, { body })`. `no_kickoff` leaves the resident node waiting for the first event, while `situational_context` tells it how to handle every event. A dormant resident node wakes for the message; a running node reads it at its next turn boundary. Keep the returned node id with the application so each later event reaches the same context and memory. The agent pushes one update report per event, which the application reads through `nodes.reports.list` and prints. The application checks for a fatal node fault rather than waiting forever for a report that cannot arrive.
80
-
81
- The agent does not poll or schedule a timer: the daemon wakes it on each message, and it goes dormant after reporting. This console program polls for the report associated with the event it just sent; an application with its own event loop can also consume the node's event stream. Ctrl-C calls `nodes.cancel()` only because this interactive example needs an explicit way to stop.
82
-
83
- Observed against the local daemon with `GUIDE_MODEL=openai-codex/gpt-6-sol:high` after sending `Build completed with 2 failing checks: lint and unit tests.`:
84
-
85
- ```text
86
- assistant node: 3zl47w7d-mud5amcx-67978c9b
87
- Type an event and press Enter. Press Ctrl-C to stop the assistant.
88
- The build completed, but **lint and unit tests failed**. Inspect the two failing check logs first to identify the errors.
89
- ```
90
-
91
- Use a resident node only when future events belong to the same ongoing assistant. For bounded work, use [[crouter-sdk/guides/typed-extraction]]. See [[crouter-concepts/lifecycle-and-wakes]] for why waiting is free and [[crouter-concepts/why-a-daemon]] for why the process can outlive the terminal that started it.
@@ -1,57 +0,0 @@
1
- ---
2
- kind: knowledge
3
- when-and-why-to-read: When independent parts of one job need separate agent work
4
- before one synthesis, read this because an orchestrator can spawn children,
5
- wait for reports, and publish a final result while the SDK streams progress.
6
- ---
7
-
8
- # Fan-out pipeline
9
-
10
- Use this recipe when one result needs independent investigation first. Run `npx tsx examples/guides/fan-out-pipeline.ts /path/to/repo`; it asks an orchestrator to inspect a package through two children, prints live text and pushed reports, then prints the final reports retained on the node.
11
-
12
- ```ts
13
- import Crouter from '@north-light/sdk';
14
- import { resolve } from 'node:path';
15
-
16
- const client = new Crouter();
17
- const cwd = resolve(process.argv[2] ?? process.cwd());
18
-
19
- const stream = client.nodes.stream({
20
- name: 'research pipeline',
21
- cwd,
22
- root: true,
23
- root_lifecycle: 'terminal',
24
- mode: 'orchestrator',
25
- deadline: '10m',
26
- prompt: `Research the package in this directory. Spawn two focused children: one should inspect package.json and one should inspect the README. Wait for their reports, reconcile them, then push a final report with the package name, purpose, and one risk or unknown.`,
27
- });
28
-
29
- const node = await stream.node;
30
- console.log(`orchestrator node: ${node.node_id}`);
31
-
32
- for await (const event of stream) {
33
- if (event.type === 'node.output_text.delta') process.stdout.write(event.delta);
34
- if (event.type === 'node.report.pushed') console.log(`\nreport: ${event.report.body}`);
35
- }
36
-
37
- const outcome = await stream.finalOutcome();
38
- const reports = await client.nodes.reports.list(node.node_id, { limit: 10 });
39
- console.log(`\nfinal outcome: ${outcome.kind}`);
40
- for (const report of reports) console.log(`[${report.tier}] ${report.body}`);
41
-
42
- if (outcome.kind !== 'result') process.exitCode = 1;
43
- ```
44
-
45
- `nodes.stream()` creates the orchestrator and observes it. It does not run the orchestration in your process: the node owns its children, waits for their pushed reports, and produces the synthesis. The stream gives your application live output and reports; `nodes.reports.list()` gives it the durable report view after settlement.
46
-
47
- Keep orchestration inside the canvas when children need the canvas's report delivery, durable waits, and a parent that can be inspected or resumed. Keep it in your application when tasks are simple independent calls and the application already owns their scheduling and aggregation. Do not use an orchestrator merely because a task is long; it earns the extra structure only when child work can run independently.
48
-
49
- A local run created `j6amiqxs-mud4drnk-330da196`; after its two children reported, `waitForOutcome()` returned:
50
-
51
- ```text
52
- { "kind": "result", "reason": "finalized" }
53
- ```
54
-
55
- The same run's `nodes.stream()` observer ended during a dormant gap before it could print this outcome. A separate daemon fix is correcting that observer behavior; the example remains the intended streamed shape, but its streamed path has not yet been observed end to end.
56
-
57
- See [[crouter-concepts/nodes-and-the-canvas]] for reports and durable identities, and [[crouter-concepts/profiles-kinds-and-modes]] for the base-versus-orchestrator decision.
@@ -1,79 +0,0 @@
1
- ---
2
- kind: knowledge
3
- when-and-why-to-read: When a person must approve or reject work before an agent
4
- continues, read this because the SDK can create an inbox request whose answer
5
- wakes the requesting node.
6
- ---
7
-
8
- # Human approval
9
-
10
- Use this recipe when a decision belongs to a person, not a timeout or an agent guess. Run `npx tsx examples/guides/human-approval.ts /path/to/repo`; it prints an inbox ticket id. Answer the page in the crtr human inbox and the worker wakes with that answer before it reports its result.
11
-
12
- ```ts
13
- import Crouter from '@north-light/sdk';
14
- import { resolve } from 'node:path';
15
-
16
- const client = new Crouter();
17
- const cwd = resolve(process.argv[2] ?? process.cwd());
18
-
19
- const worker = await client.nodes.create({
20
- name: 'approval worker',
21
- cwd,
22
- root: true,
23
- root_lifecycle: 'terminal',
24
- no_kickoff: true,
25
- });
26
-
27
- const request = await client.human.requests.create({
28
- creator_cwd: cwd,
29
- requester_node_id: worker.node_id,
30
- delivery: { placement: 'panel', inbox: true, reply: true },
31
- page: {
32
- dialect: 'jsx',
33
- source: `export default function Approval() {
34
- return (
35
- <Page title="Approve the release?" subtitle="The worker will continue with your choice.">
36
- <UserQuestion
37
- id="approval"
38
- label="Release action"
39
- body="Approve to continue the release, or reject to stop it."
40
- mode="single"
41
- options={[
42
- { id: 'approve', label: 'Approve', recommended: true },
43
- { id: 'reject', label: 'Reject' },
44
- ]}
45
- />
46
- </Page>
47
- );
48
- }`,
49
- },
50
- });
51
-
52
- const ticket = await client.human.requests.retrieve(request.request_id);
53
- if (ticket.inbox_ticket_id === null) throw new Error('the approval request was not added to the inbox');
54
-
55
- await client.nodes.message(worker.node_id, {
56
- body: `A human approval request is open. Wait for its reply. When it arrives, state whether the release was approved or rejected, then push a final report.`,
57
- });
58
-
59
- console.log(`approval ticket: ${ticket.inbox_ticket_id}`);
60
- console.log('Answer it in the crtr human inbox. The worker will wake with the response.');
61
-
62
- const outcome = await client.nodes.waitForOutcome(worker.node_id);
63
- console.log(`worker outcome: ${outcome.kind}`);
64
- if (outcome.kind !== 'result') process.exitCode = 1;
65
- ```
66
-
67
- The application creates the page through `client.human.requests.create()` and names the worker as `requester_node_id`. `delivery.reply: true` makes the settled answer travel back to that node. The page's `UserQuestion` supplies a known response shape, so the person sees an explicit approve or reject decision instead of an unstructured prompt.
68
-
69
- The worker is terminal because this is a bounded approval run: it waits after setup, wakes when the person answers, then publishes its final result. The pending human request keeps that wait durable. The application does not poll the node or invent a fallback deadline; the human reply is a canvas event. `client.human.inbox` can list, inspect, and answer inbox tickets when your application provides its own human interface.
70
-
71
- Observed against the local daemon after an approve response:
72
-
73
- ```text
74
- approval ticket: a643479ca7a79758bf86f32d24bd8c9b22e16509cd60996c5e4fe0bc5f097d45
75
- Answer it in the crtr human inbox. The worker will wake with the response.
76
- worker outcome: result
77
- ```
78
-
79
- See [[crouter-concepts/lifecycle-and-wakes]] for the wake model and [[crouter-concepts/scopes-and-trust]] for why the daemon, rather than the application, owns delivery of the answer.
@@ -1,55 +0,0 @@
1
- ---
2
- kind: knowledge
3
- when-and-why-to-read: When an application needs one bounded structured answer
4
- with no follow-up, read this because nodes.parse returns a typed outcome union
5
- instead of hiding agent failures.
6
- ---
7
-
8
- # Typed extraction
9
-
10
- Use this recipe to extract a small fact set from files in one working directory. Run it with `npx tsx examples/guides/typed-extraction.ts /path/to/repo`; it prints a package name and version or exits with an explicit agent outcome.
11
-
12
- ```ts
13
- import Crouter from '@north-light/sdk';
14
- import { resolve } from 'node:path';
15
- import { z } from 'zod';
16
-
17
- const client = new Crouter();
18
- const cwd = resolve(process.argv[2] ?? process.cwd());
19
-
20
- const extraction = await client.nodes.parse({
21
- prompt: 'Read package.json in this directory. Return its name and version.',
22
- cwd,
23
- root: true,
24
- root_lifecycle: 'terminal',
25
- deadline: '5m',
26
- output_schema: z.object({
27
- name: z.string(),
28
- version: z.string(),
29
- }),
30
- });
31
-
32
- if (extraction.kind === 'result') {
33
- console.log(`package ${extraction.output_parsed.name}@${extraction.output_parsed.version}`);
34
- } else if (extraction.reason === 'declined') {
35
- console.error(`agent declined: ${extraction.declined?.reason ?? 'no reason supplied'}`);
36
- process.exitCode = 2;
37
- } else {
38
- console.error(`agent failed: ${extraction.reason}`, extraction.detail);
39
- process.exitCode = 1;
40
- }
41
- ```
42
-
43
- `nodes.parse()` creates a terminal root, waits for it, and returns the structured result typed from the Zod schema. The schema belongs at the boundary where your application consumes the answer, not in a second parser after the run.
44
-
45
- Observed against the local daemon in this checkout:
46
-
47
- ```text
48
- package @north-light/cli@0.3.332
49
- ```
50
-
51
- Handle every outcome arm. A result contains `output_parsed`; a decline says the agent could not honestly meet the schema; another failure carries its reason and detail. Transport and daemon failures still throw, so let those reach your normal application error handling.
52
-
53
- **From an app.** An app holding a person's connection does the same thing with `runs.parse({prompt, output_schema})`, which returns the run outcome union (`finalized` with `output_parsed` typed from the schema, `declined` with `details`, `canceled`, `deadline_exceeded`, `runtime_error`). It also covers `run_idle` and questions. See [Typed results](https://sdk.docs.northlight.ai/docs/guides/typed-results).
54
-
55
- This is the right shape for bounded work: one prompt, one answer, and no future message. If a user or external event must return to the same agent later, use a resident node instead. See [[crouter-concepts/nodes-and-the-canvas]] for why an SDK node has durable identity, and [[crouter-concepts/lifecycle-and-wakes]] for the terminal-versus-resident decision.
@@ -1,195 +0,0 @@
1
- ---
2
- kind: knowledge
3
- when-and-why-to-read: When you need Nodes, this knowledge should be read because
4
- Create agent runs, wait for outcomes, and parse structured results.
5
- ---
6
-
7
- # `client.nodes`
8
-
9
- Shipped, except where a row says otherwise.
10
-
11
- 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.
12
-
13
- 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.
14
-
15
- ## Methods
16
-
17
- | Method | Route | Phase | Notes |
18
- |---|---|---|---|
19
- | `nodes.create(params)` | `POST /v1/nodes` | 1 | Returns immediately with the node; it is already running. |
20
- | `nodes.retrieve(id)` | `GET /v1/nodes/{id}` | 1 | |
21
- | `nodes.list(query?)` | `GET /v1/nodes` | 1 | Returns an array, as the daemon does. |
22
- | `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'`. |
23
- | `nodes.waitForOutcome(id, opts?)` | repeats the above | 1 | Loops until settled. Honours `signal`; no implicit time bound. |
24
- | `nodes.createAndWait(params, opts?)` | create + wait | 1 | |
25
- | `nodes.parse(params, opts?)` | create + wait + typed result | 1 | [See below](#parse-and-structured-output). |
26
- | `nodes.message(id, body)` | `POST /v1/nodes/{id}/messages` | 1 | Send a follow-up to a running or dormant node. |
27
- | `nodes.interrupt(id)` | `POST /v1/nodes/{id}/interrupt` | 1 | Stop the current turn, keep the node. |
28
- | `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. |
29
- | `nodes.update(id, patch)` | `PATCH /v1/nodes/{id}/config` | Shipped | |
30
- | `nodes.fork(id)` | `POST /v1/nodes/{id}/fork` | Shipped | |
31
- | `nodes.revive(id, body?)` | `POST /v1/nodes/{id}/revive` | Shipped | |
32
- | `nodes.promote(id, body?)` / `nodes.demote(id)` | matching routes | Shipped | Move a node between base and orchestrator mode. |
33
- | `nodes.recycle(id)` | `POST /v1/nodes/{id}/recycle` | Shipped | |
34
- | `nodes.yield(id, body?)` | `POST /v1/nodes/{id}/yield` | Shipped | |
35
- | `nodes.wait(id, body)` | `POST /v1/nodes/{id}/wait` | Shipped | |
36
- | `nodes.relaunchRoot(id)` | matching route | Shipped | |
37
- | `nodes.reviveAll()` | `POST /v1/nodes/revive-all` | Shipped | |
38
- | `nodes.stream(params, options?)` | create + `GET /…/events` | Shipped | [[crouter-sdk/streaming]]. |
39
- | `nodes.events(id, options?)` | `GET /v1/nodes/{id}/events` | Shipped | [[crouter-sdk/streaming]]. |
40
-
41
- Action methods keep the product's literal name (`fork`, `revive`, `promote`, `yield`) rather than being renamed into a generic verb.
42
-
43
- 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`.
44
-
45
- ## Create parameters
46
-
47
- 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.
48
-
49
- | Field | Type | Meaning |
50
- |---|---|---|
51
- | `prompt` | `string` | The run's entire brief. |
52
- | `kind` | `string` | Persona. Omit for the profile's default. |
53
- | `model` | `string` | Durable model override. |
54
- | `profile` | `string` | The profile the run uses: its project purview, environment and profile-owned documents. An application passes **its own** profile here. |
55
- | `cwd` | `string` | Where the request came from. |
56
- | `pin_cwd` | `string` | Pin the node to this directory regardless of `cwd`. |
57
- | `situational_context` | `string` | Ambient context kept out of the visible prompt. |
58
- | `deadline` | `string` (`1h30m`) | Wall clock from spawn. Expiry cancels the node and records `deadline_exceeded`. |
59
- | `output_schema` | `string \| JsonSchema \| { toJSONSchema(): JsonSchema }` | Widened from the wire's JSON string; the SDK serializes. A zod v4 object satisfies the third form. |
60
- | `root` | `boolean` | No parent, no subscription. An application's run is a root. |
61
- | `root_lifecycle` | `'terminal' \| 'resident'` | `terminal` for a bounded run; `resident` for one a person will open and keep. |
62
- | `mode` | `'base' \| 'orchestrator'` | Whether the node works hands-on or fans out to children. |
63
- | `name` | `string` | Display label. |
64
- | `description` | `string` | Display description. |
65
- | `parent` | node id | Graph placement. An external caller leaves this unset. |
66
- | `creator` | node id | Graph placement. An external caller leaves this unset. |
67
- | `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 [[crouter-sdk/getting-started]]. |
68
- | `worktree` | `string \| boolean` | Create a managed git worktree for the run. |
69
- | `fork_from` | `string` | Start from an existing conversation. |
70
- | `no_kickoff` | `boolean` | Create the node without sending the first message. |
71
- | `node_id` | `string` | Spawn at an exact id. A collision answers `409 node_id_exists`. |
72
- | `prefer_warm` | `boolean` | Serve from the warm pool when the launch tuple matches. |
73
- | `outcome_delivery` | `{ action, payload? }` | Arm outcome delivery at birth. |
74
-
75
- `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 [[crouter-sdk/errors]].
76
-
77
- ## Outcomes
78
-
79
- `waitForOutcome`, `createAndWait`, and `parse` return the settled `NodeOutcome` — the same union the API defines, not a translation of it.
80
-
81
- | Wire | Narrow on | Carries |
82
- |---|---|---|
83
- | `kind: 'result'` | `outcome.kind === 'result'` | `structured_result`, `final_report_path`, and on `parse` a typed `output_parsed` |
84
- | `kind: 'failure'`, `reason: 'declined'` | `outcome.reason === 'declined'` | `declined: { reason, code, retryable } \| null` — the agent honestly refused the schema |
85
- | `kind: 'failure'`, any other `reason` | anything else | `detail: NodeOutcomeDetailV1 \| null` — `deadline_exceeded`, a provider fault, a wedge |
86
-
87
- **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.
88
-
89
- ```ts
90
- const outcome = await client.nodes.waitForOutcome(node.node_id, { signal });
91
-
92
- switch (true) {
93
- case outcome.kind === 'result':
94
- console.log(outcome.structured_result, outcome.final_report_path);
95
- break;
96
- case outcome.reason === 'declined':
97
- console.warn(outcome.declined?.reason, outcome.declined?.retryable);
98
- break;
99
- default:
100
- console.error(outcome.reason, outcome.detail);
101
- }
102
- ```
103
-
104
- ### `outcome()` versus `waitForOutcome()`
105
-
106
- `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.
107
-
108
- `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.
109
-
110
- ```ts
111
- for (;;) {
112
- const poll = await client.nodes.outcome(node.node_id, { wait: 25 });
113
- if (poll.state === 'settled' && poll.outcome !== null) {
114
- console.log(poll.outcome);
115
- break;
116
- }
117
- // update your UI or job heartbeat here
118
- }
119
- ```
120
-
121
- ## `parse()` and structured output
122
-
123
- ```ts
124
- import { z } from 'zod';
125
-
126
- const run = await client.nodes.parse({
127
- prompt: 'Summarize the failing tests in this repo.',
128
- cwd: '/path/to/repo',
129
- output_schema: z.object({ failures: z.array(z.string()), root_cause: z.string() }),
130
- });
131
-
132
- if (run.kind === 'result') console.log(run.output_parsed.root_cause);
133
- else if (run.reason === 'declined') console.warn(run.declined?.reason);
134
- ```
135
-
136
- `ParsedOutcome<T>` is `NodeOutcome & { output_parsed: T | null }`, discriminated so `output_parsed` is non-null exactly when `kind === 'result'`.
137
-
138
- `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`.
139
-
140
- A candidate from Basis's real structured SDK result:
141
-
142
- ```json
143
- {
144
- "tmp": "k1",
145
- "type": "claim",
146
- "slug": "config-memories-in-project",
147
- "text": "All applet configuration memories belong in project memories.",
148
- "quote": "All configuration memories should be in the project memories. We know that.",
149
- "speaker": "Me",
150
- "confidence": "green"
151
- }
152
- ```
153
-
154
- ## Sending a follow-up
155
-
156
- `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.
157
-
158
- ```ts
159
- await client.nodes.message(node.node_id, { body: 'Also check the integration lane.' });
160
- ```
161
-
162
- ## Stopping a run
163
-
164
- | Call | Effect |
165
- |---|---|
166
- | `nodes.interrupt(id)` | Stops the current turn. The node stays on the canvas and can be messaged or revived. |
167
- | `nodes.cancel(id, body?)` | Tears the node down along with the subtree it exclusively owns. Terminal. |
168
-
169
- Aborting a `signal` you passed to `waitForOutcome` stops **your client waiting**. It does not stop the node. Call `cancel` for that.
170
-
171
- ## Nested resources
172
-
173
- Nested routes become nested properties.
174
-
175
- | Property | Methods | Phase |
176
- |---|---|---|
177
- | `nodes.reports` | `list` | Shipped |
178
- | `nodes.jobs` | `list`, `cancel` | Shipped |
179
- | `nodes.worktree` | `close`, `abandon` | Shipped |
180
- | `nodes.result` | `submit` | Shipped — only an agent inside a run calls this |
181
-
182
- `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 [[crouter-sdk/streaming]] for live output and tool-call events.
183
-
184
- ```ts
185
- const reports = await client.nodes.reports.list(node.node_id, { limit: 10 });
186
- for (const report of reports) console.log(report.tier, report.body);
187
- ```
188
-
189
- ## Pagination
190
-
191
- 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.
192
-
193
- ## Identifier validation
194
-
195
- 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.