@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
@@ -527,7 +527,7 @@ function resultResponse(result, leaf) {
527
527
  }
528
528
  if (!isRecord(wireResult))
529
529
  throw outputInvalid('result');
530
- const invalid = validateDeclaredResult(leaf.output, wireResult);
530
+ const invalid = validateDeclaredResult(leaf.output, wireResult, true);
531
531
  if (invalid !== null)
532
532
  throw outputInvalid(invalid.field, invalid.receivedType);
533
533
  for (const key of Object.keys(wireResult)) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/plugin",
3
- "version": "0.3.694",
3
+ "version": "0.3.695",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
28
28
  },
29
29
  "dependencies": {
30
- "@north-light/api": "0.3.694",
31
- "@north-light/identity": "0.3.694"
30
+ "@north-light/api": "0.3.695",
31
+ "@north-light/identity": "0.3.695"
32
32
  },
33
33
  "license": "UNLICENSED",
34
34
  "publishConfig": {
package/runtime.lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.694",
3
+ "version": "0.3.695",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.694",
9
+ "version": "0.3.695",
10
10
  "hasInstallScript": true,
11
11
  "license": "UNLICENSED",
12
12
  "workspaces": [
@@ -28,8 +28,8 @@
28
28
  "@milkdown/preset-gfm": "^7.22.3",
29
29
  "@milkdown/prose": "^7.22.3",
30
30
  "@milkdown/utils": "^7.22.3",
31
- "@north-light/identity": "0.3.694",
32
- "@north-light/plugin": "0.3.694",
31
+ "@north-light/identity": "0.3.695",
32
+ "@north-light/plugin": "0.3.695",
33
33
  "cron-parser": "^5.6.0",
34
34
  "esbuild": "0.28.2",
35
35
  "jose": "^6.2.12",
@@ -10667,17 +10667,17 @@
10667
10667
  },
10668
10668
  "packages/crouter-api": {
10669
10669
  "name": "@north-light/api",
10670
- "version": "0.3.694",
10670
+ "version": "0.3.695",
10671
10671
  "license": "UNLICENSED"
10672
10672
  },
10673
10673
  "packages/crouter-env-docker": {
10674
10674
  "name": "@north-light/env-docker",
10675
- "version": "0.3.694",
10675
+ "version": "0.3.695",
10676
10676
  "license": "UNLICENSED"
10677
10677
  },
10678
10678
  "packages/crouter-identity": {
10679
10679
  "name": "@north-light/identity",
10680
- "version": "0.3.694",
10680
+ "version": "0.3.695",
10681
10681
  "license": "UNLICENSED",
10682
10682
  "dependencies": {
10683
10683
  "jose": "^6.2.1"
@@ -10685,21 +10685,21 @@
10685
10685
  },
10686
10686
  "packages/crouter-plugin": {
10687
10687
  "name": "@north-light/plugin",
10688
- "version": "0.3.694",
10688
+ "version": "0.3.695",
10689
10689
  "license": "UNLICENSED",
10690
10690
  "dependencies": {
10691
- "@north-light/api": "0.3.694",
10692
- "@north-light/identity": "0.3.694"
10691
+ "@north-light/api": "0.3.695",
10692
+ "@north-light/identity": "0.3.695"
10693
10693
  }
10694
10694
  },
10695
10695
  "packages/crouter-sdk": {
10696
10696
  "name": "@north-light/sdk",
10697
- "version": "0.3.694",
10697
+ "version": "0.3.695",
10698
10698
  "license": "UNLICENSED",
10699
10699
  "dependencies": {
10700
- "@north-light/api": "0.3.694",
10701
- "@north-light/identity": "0.3.694",
10702
- "@north-light/plugin": "0.3.694",
10700
+ "@north-light/api": "0.3.695",
10701
+ "@north-light/identity": "0.3.695",
10702
+ "@north-light/plugin": "0.3.695",
10703
10703
  "jose": "^6.2.1"
10704
10704
  },
10705
10705
  "bin": {
@@ -1,40 +0,0 @@
1
- ---
2
- kind: knowledge
3
- when-and-why-to-read: When you need Bash, this knowledge should be read because
4
- Execute bounded shell commands through the daemon.
5
- ---
6
-
7
- # `client.bash`
8
-
9
- `client.bash.run` executes one bounded `bash -c` command through the daemon.
10
-
11
- ```ts
12
- const result = await client.bash.run({
13
- command: 'printf "%s\\n" "$MESSAGE"',
14
- cwd: '/absolute/path/to/project',
15
- env: { MESSAGE: 'hello' },
16
- timeout_s: 30,
17
- profile: 'my-app',
18
- });
19
-
20
- if (result.exit_code !== 0) console.error(result.stderr);
21
- ```
22
-
23
- `run(params, options?)` returns `Promise<BashRunDTO>`. Its final `options` object is the normal request-options object: `headers`, `signal`, `timeout`, and `maxRetries`.
24
-
25
- | Result field | Type | Meaning |
26
- |---|---|---|
27
- | `exit_code` | `number \| null` | Process exit code, or `null` after a timeout. A non-zero code is returned, not thrown. |
28
- | `signal` | `string \| null` | Signal that ended the process, when one did. |
29
- | `stdout` / `stderr` | `string` | Captured output prefix. |
30
- | `stdout_truncated` / `stderr_truncated` | `boolean` | Whether that output stream exceeded its 256 KiB capture limit. |
31
- | `timed_out` | `boolean` | `true` after the daemon terminates the process group for a timeout. |
32
- | `duration_ms` | `number` | Command duration in milliseconds. |
33
-
34
- `cwd` is required, absolute, and must name an existing directory. The daemon never uses its own working directory as a fallback. `timeout_s` defaults to 60, must be greater than 0, and cannot exceed 600. The SDK keeps the HTTP request open for the command timeout plus 15 seconds, unless its configured request timeout is already longer.
35
-
36
- Pass dynamic values through `env` and reference them from the command as `"$NAME"`, rather than interpolating them into shell source. The command receives the daemon's default-deny operational environment, selected profile environment, then your `env` values.
37
-
38
- ## Authority
39
-
40
- The token is the owner credential. Anyone holding it can already create an agent with a bash tool, so this command runs with the daemon user's authority and does not provide a restricted command area.
@@ -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.