@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.
- package/README.md +4 -7
- package/dist/api/command-manifest/result.d.ts +5 -5
- package/dist/api/command-manifest/result.js +1 -1
- package/dist/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/api/dto/run-events.d.ts +1 -0
- package/dist/api/dto/run-events.js +1 -0
- package/dist/api/dto/worktree.d.ts +0 -4
- package/dist/builtin-memory/crouter-concepts/lifecycle-and-wakes.md +1 -1
- package/dist/builtin-memory/crouter-concepts/nodes-and-the-canvas.md +2 -2
- package/dist/builtin-memory/crouter-concepts/profiles-kinds-and-modes.md +1 -1
- package/dist/builtin-memory/crouter-concepts/scopes-and-trust.md +1 -1
- package/dist/builtin-memory/crouter-concepts/why-a-daemon.md +1 -1
- package/dist/builtin-memory/crouter-sdk/INDEX.md +3 -3
- package/dist/builtin-memory/crouter-sdk/README.md +14 -42
- package/dist/builtin-memory/crouter-sdk/client.md +5 -7
- package/dist/builtin-memory/crouter-sdk/docker.md +1 -1
- package/dist/builtin-memory/crouter-sdk/errors.md +4 -44
- package/dist/builtin-memory/crouter-sdk/getting-started.md +11 -83
- package/dist/builtin-memory/crouter-sdk/release-notes.md +10 -0
- package/dist/builtin-memory/crouter-sdk/resources.md +11 -44
- package/dist/builtin-memory/northlight-apps/guides/stream-a-run.md +6 -7
- package/dist/clients/attach/session/connection.d.ts +11 -2
- package/dist/clients/attach/session/connection.js +1 -1
- package/dist/clients/attach/session/keys.d.ts +2 -0
- package/dist/clients/attach/session/keys.js +1 -1
- package/dist/clients/attach/session/pane-tag.d.ts +3 -3
- package/dist/clients/attach/session/reconnect.js +1 -1
- package/dist/clients/attach/viewer.js +538 -537
- package/dist/commands/node-worktree.js +1 -1
- package/dist/commands/surface/node/placement.d.ts +2 -2
- package/dist/commands/surface/node/placement.js +1 -1
- package/dist/commands/surface.js +1 -1
- package/dist/core/broker-client/client.d.ts +6 -9
- package/dist/core/broker-client/client.js +1 -1
- package/dist/core/canvas/canvas.js +5 -5
- package/dist/core/canvas/types.d.ts +0 -2
- package/dist/core/conversation-store/row-store.js +10 -10
- package/dist/core/graph/names.js +9 -9
- package/dist/core/keybindings/attach-control.d.ts +3 -0
- package/dist/core/keybindings/attach-control.js +1 -1
- package/dist/core/keybindings/catalog.js +1 -1
- package/dist/core/ledger/chunks.d.ts +3 -1
- package/dist/core/ledger/chunks.js +2 -2
- package/dist/core/ledger/index.d.ts +1 -1
- package/dist/core/ledger/index.js +1 -1
- package/dist/core/ledger/read.d.ts +4 -0
- package/dist/core/ledger/read.js +2 -2
- package/dist/core/llm/run.js +2 -2
- package/dist/core/logged-step-timings.d.ts +7 -0
- package/dist/core/logged-step-timings.js +1 -0
- package/dist/core/permissions/evaluator.d.ts +2 -1
- package/dist/core/permissions/evaluator.js +2 -2
- package/dist/core/providers/receipts.js +1 -1
- package/dist/core/runs/operations.js +8 -8
- package/dist/core/runtime/broker/model-adapter.js +3 -3
- package/dist/core/runtime/broker.js +1 -1
- package/dist/core/runtime/nodes.d.ts +1 -1
- package/dist/core/runtime/nodes.js +1 -1
- package/dist/core/runtime/placement-tmux.d.ts +1 -1
- package/dist/core/runtime/placement-tmux.js +1 -1
- package/dist/core/runtime/revive.js +2 -2
- package/dist/core/runtime/runner/machine/ops.d.ts +2 -7
- package/dist/core/runtime/runner/machine/ops.js +1 -1
- package/dist/core/runtime/runner/machine/runner.d.ts +0 -2
- package/dist/core/runtime/runner/machine/runner.js +1 -1
- package/dist/core/runtime/tmux-bindings.js +3 -3
- package/dist/core/runtime/tmux-driver.d.ts +0 -10
- package/dist/core/runtime/tmux-driver.js +6 -6
- package/dist/core/step-timings.d.ts +7 -1
- package/dist/core/step-timings.js +1 -1
- package/dist/core/worktree-close.js +4 -6
- package/dist/core/worktree-landing.d.ts +0 -38
- package/dist/core/worktree-landing.js +2 -3
- package/dist/core/worktree-sweep.d.ts +0 -1
- package/dist/core/worktree-sweep.js +4 -6
- package/dist/core/worktree.d.ts +0 -4
- package/dist/core/worktree.js +13 -15
- package/dist/daemon/api/app-listener.d.ts +1 -0
- package/dist/daemon/api/app-listener.js +10 -10
- package/dist/daemon/api/bridge.js +4 -4
- package/dist/daemon/api/handlers/attach.js +1 -1
- package/dist/daemon/api/handlers/conversations.js +3 -3
- package/dist/daemon/api/server.d.ts +1 -1
- package/dist/daemon/api/server.js +1 -1
- package/dist/daemon/cron/armed-context.js +1 -1
- package/dist/daemon/crtrd.js +20 -18
- package/dist/daemon/machine-link/client.d.ts +5 -1
- package/dist/daemon/machine-link/client.js +1 -1
- package/dist/daemon/machine-link/forward.js +1 -1
- package/dist/daemon/machine-link/holder.js +3 -3
- package/dist/daemon/pidfile.js +2 -1
- package/dist/daemon/reconcilers/managed-worktree-sweep.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/freeze-lane.js +1 -1
- package/dist/daemon/runs/append-section.js +2 -2
- package/dist/daemon/runs/observer.js +3 -3
- package/docs/apps/guides/stream-a-run.md +6 -7
- package/docs/concepts/lifecycle-and-wakes.md +1 -1
- package/docs/concepts/nodes-and-the-canvas.md +2 -2
- package/docs/concepts/profiles-kinds-and-modes.md +1 -1
- package/docs/concepts/scopes-and-trust.md +1 -1
- package/docs/concepts/why-a-daemon.md +1 -1
- package/docs/sdk/README.md +13 -41
- package/docs/sdk/client.md +5 -7
- package/docs/sdk/docker.md +1 -1
- package/docs/sdk/errors.md +3 -43
- package/docs/sdk/getting-started.md +11 -83
- package/docs/sdk/release-notes.md +10 -0
- package/docs/sdk/resources.md +11 -44
- package/package.json +3 -3
- package/packages/crouter-api/dist/api/command-manifest/result.js +15 -15
- package/packages/crouter-api/dist/api/contract.js +1 -1
- package/packages/crouter-api/dist/api/dto/run-events.js +1 -1
- package/packages/crouter-api/dist/clients/attach/session/connection.js +36 -1
- package/packages/crouter-api/dist/clients/attach/session/keys.js +1 -0
- package/packages/crouter-api/dist/clients/attach/session/reconnect.js +11 -15
- package/packages/crouter-api/dist/clients/attach/viewer.js +42 -5
- package/packages/crouter-api/dist/commands/node-worktree.js +1 -5
- package/packages/crouter-api/dist/commands/surface/node/placement.js +2 -2
- package/packages/crouter-api/dist/commands/surface.js +2 -3
- package/packages/crouter-api/dist/core/broker-client/client.js +5 -17
- package/packages/crouter-api/dist/core/canvas/canvas.js +2 -3
- package/packages/crouter-api/dist/core/conversation-store/row-store.js +7 -4
- package/packages/crouter-api/dist/core/graph/names.js +7 -20
- package/packages/crouter-api/dist/core/keybindings/attach-control.js +1 -0
- package/packages/crouter-api/dist/core/keybindings/catalog.js +2 -1
- package/packages/crouter-api/dist/core/ledger/chunks.js +7 -3
- package/packages/crouter-api/dist/core/ledger/index.js +1 -1
- package/packages/crouter-api/dist/core/ledger/read.js +18 -1
- package/packages/crouter-api/dist/core/llm/run.js +1 -1
- package/packages/crouter-api/dist/core/logged-step-timings.js +52 -0
- package/packages/crouter-api/dist/core/permissions/evaluator.js +15 -1
- package/packages/crouter-api/dist/core/providers/receipts.js +1 -12
- package/packages/crouter-api/dist/core/runs/operations.js +5 -4
- package/packages/crouter-api/dist/core/runtime/broker/model-adapter.js +14 -3
- package/packages/crouter-api/dist/core/runtime/nodes.js +2 -2
- package/packages/crouter-api/dist/core/runtime/placement-tmux.js +1 -1
- package/packages/crouter-api/dist/core/runtime/revive.js +5 -5
- package/packages/crouter-api/dist/core/runtime/runner/machine/ops.js +2 -7
- package/packages/crouter-api/dist/core/runtime/runner/machine/runner.js +4 -24
- package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +1 -1
- package/packages/crouter-api/dist/core/runtime/tmux-driver.js +0 -18
- package/packages/crouter-api/dist/core/step-timings.js +7 -2
- package/packages/crouter-api/dist/core/worktree-close.js +5 -51
- package/packages/crouter-api/dist/core/worktree-landing.js +0 -48
- package/packages/crouter-api/dist/core/worktree.js +9 -74
- package/packages/crouter-api/dist/daemon/cron/armed-context.js +3 -3
- package/packages/crouter-api/dist/daemon/machine-link/forward.js +13 -2
- package/packages/crouter-api/dist/daemon/machine-link/holder.js +2 -0
- package/packages/crouter-api/dist/daemon/pidfile.js +1 -1
- package/packages/crouter-api/dist/daemon/runs/append-section.js +2 -8
- package/packages/crouter-api/dist/daemon/runs/observer.js +3 -4
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/dist/serve.js +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
- package/dist/builtin-memory/crouter-sdk/bash.md +0 -40
- package/dist/builtin-memory/crouter-sdk/files.md +0 -50
- package/dist/builtin-memory/crouter-sdk/guides/README.md +0 -18
- package/dist/builtin-memory/crouter-sdk/guides/event-driven-assistant.md +0 -91
- package/dist/builtin-memory/crouter-sdk/guides/fan-out-pipeline.md +0 -57
- package/dist/builtin-memory/crouter-sdk/guides/human-approval.md +0 -79
- package/dist/builtin-memory/crouter-sdk/guides/typed-extraction.md +0 -55
- package/dist/builtin-memory/crouter-sdk/nodes.md +0 -195
- package/dist/builtin-memory/crouter-sdk/streaming.md +0 -151
- package/dist/commands/surface-reload.d.ts +0 -7
- package/dist/commands/surface-reload.js +0 -1
- package/docs/sdk/bash.md +0 -39
- package/docs/sdk/files.md +0 -49
- package/docs/sdk/guides/README.md +0 -17
- package/docs/sdk/guides/event-driven-assistant.md +0 -24
- package/docs/sdk/guides/fan-out-pipeline.md +0 -24
- package/docs/sdk/guides/human-approval.md +0 -24
- package/docs/sdk/guides/typed-extraction.md +0 -24
- package/docs/sdk/nodes.md +0 -194
- package/docs/sdk/streaming.md +0 -149
- package/packages/crouter-api/dist/commands/surface-reload.js +0 -129
|
@@ -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.
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
kind: knowledge
|
|
3
|
-
when-and-why-to-read: When you need Streaming, this knowledge should be read
|
|
4
|
-
because Follow assistant text, tool activity, reports, and outcomes as an
|
|
5
|
-
agent runs.
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Streaming
|
|
9
|
-
|
|
10
|
-
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.
|
|
11
|
-
|
|
12
|
-
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).
|
|
13
|
-
|
|
14
|
-
## The SDK surface
|
|
15
|
-
|
|
16
|
-
```ts
|
|
17
|
-
const stream = client.nodes.stream({ prompt: 'Fix the failing test', cwd }, { headers: { 'x-trace': 'run-9' } });
|
|
18
|
-
|
|
19
|
-
stream.on('node.output_text.delta', (event) => process.stdout.write(event.delta));
|
|
20
|
-
|
|
21
|
-
for await (const event of stream) {
|
|
22
|
-
// the same events, typed by `type`
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const outcome = await stream.finalOutcome(); // resolves on node.settled
|
|
26
|
-
stream.abort(); // ends the HTTP response; the node keeps running
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
| Member | Behaviour |
|
|
30
|
-
|---|---|
|
|
31
|
-
| `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. |
|
|
32
|
-
| `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`. |
|
|
33
|
-
| `.on(type, listener)` / `.off(type, listener)` | Typed event emitter; each returns the `NodeStream`. |
|
|
34
|
-
| `[Symbol.asyncIterator]()` | Yields the same `NodeEventDTO` union. |
|
|
35
|
-
| `.finalOutcome()` | Returns `Promise<NodeOutcomeDTO>`, resolving on `node.settled` and rejecting on a terminal `error` event or a connection failure. |
|
|
36
|
-
| `.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. |
|
|
37
|
-
|
|
38
|
-
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.
|
|
39
|
-
|
|
40
|
-
**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.
|
|
41
|
-
|
|
42
|
-
## Activity helper
|
|
43
|
-
|
|
44
|
-
`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.
|
|
45
|
-
|
|
46
|
-
```ts
|
|
47
|
-
import { followActivity } from '@north-light/sdk';
|
|
48
|
-
|
|
49
|
-
for await (const steps of followActivity(stream)) {
|
|
50
|
-
render(steps);
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
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`.
|
|
55
|
-
|
|
56
|
-
## Events
|
|
57
|
-
|
|
58
|
-
Every event except `error` carries `node_id` and `sequence_number` in addition to the fields listed. `error` carries only its error object.
|
|
59
|
-
|
|
60
|
-
| Event | `data` |
|
|
61
|
-
|---|---|
|
|
62
|
-
| `node.output_text.delta` | `{ node_id, sequence_number, delta }` |
|
|
63
|
-
| `node.output_text.done` | `{ node_id, sequence_number, text }` |
|
|
64
|
-
| `node.tool_call.started` | `{ node_id, sequence_number, tool_call_id, tool, summary }` |
|
|
65
|
-
| `node.tool_call.completed` | `{ node_id, sequence_number, tool_call_id, tool, status: 'ok' \| 'error', summary }` |
|
|
66
|
-
| `node.turn.started` | `{ node_id, sequence_number }` |
|
|
67
|
-
| `node.turn.completed` | `{ node_id, sequence_number }` |
|
|
68
|
-
| `node.report.pushed` | `{ node_id, sequence_number, report }` |
|
|
69
|
-
| `node.status.changed` | `{ node_id, sequence_number, status }`, where `status` can also be stream-only `'dormant'` |
|
|
70
|
-
| `node.settled` | `{ node_id, sequence_number, outcome }` — terminal; the daemon ends the response after it |
|
|
71
|
-
| `error` | `{ error: { code: 'stream_gap' \| 'stream_dropped' \| 'stream_error', message, details?: { earliest_sequence?: number } } }` — `stream_gap` is recoverable; the other codes terminate the response |
|
|
72
|
-
|
|
73
|
-
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.
|
|
74
|
-
|
|
75
|
-
`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.
|
|
76
|
-
|
|
77
|
-
**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.
|
|
78
|
-
|
|
79
|
-
## The route
|
|
80
|
-
|
|
81
|
-
```
|
|
82
|
-
GET /v1/nodes/{id}/events Accept: text/event-stream
|
|
83
|
-
?after=<sequence_number> resume from a cursor (optional)
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
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.
|
|
87
|
-
|
|
88
|
-
### What you get depending on the node's state
|
|
89
|
-
|
|
90
|
-
| Node state when you call | What the stream does |
|
|
91
|
-
|---|---|
|
|
92
|
-
| Already settled | Writes retained events when available, ending in `node.settled`; otherwise writes `node.settled` with the outcome and ends. Nothing is revived. |
|
|
93
|
-
| Running | Streams live, seeded as described below. |
|
|
94
|
-
| 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. |
|
|
95
|
-
|
|
96
|
-
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.
|
|
97
|
-
|
|
98
|
-
## Sequence, resume, and failure
|
|
99
|
-
|
|
100
|
-
`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.
|
|
101
|
-
|
|
102
|
-
| Situation | Behaviour |
|
|
103
|
-
|---|---|
|
|
104
|
-
| 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. |
|
|
105
|
-
| A second subscriber joins | Seeded from the ring, so both subscribers see the same sequence numbers. |
|
|
106
|
-
| `after=N` within the retained range | Replays events after `N`. |
|
|
107
|
-
| `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. |
|
|
108
|
-
| 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. |
|
|
109
|
-
| 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. |
|
|
110
|
-
| 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. |
|
|
111
|
-
| The daemon restarts | The ring is gone. A resuming client gets `stream_gap` with `earliest_sequence: 1`. There is no durable event log. |
|
|
112
|
-
| You disconnect | Your subscriber is dropped. The node keeps running. |
|
|
113
|
-
|
|
114
|
-
### Resuming
|
|
115
|
-
|
|
116
|
-
```ts
|
|
117
|
-
import { APIError } from '@north-light/sdk';
|
|
118
|
-
|
|
119
|
-
let cursor: number | undefined;
|
|
120
|
-
|
|
121
|
-
for (;;) {
|
|
122
|
-
const stream = client.nodes.events(id, { after: cursor });
|
|
123
|
-
try {
|
|
124
|
-
for await (const event of stream) {
|
|
125
|
-
if (event.type === 'error') {
|
|
126
|
-
if (event.error.code === 'stream_gap') {
|
|
127
|
-
console.warn('missed events before', event.error.details?.earliest_sequence);
|
|
128
|
-
continue; // the stream continues from the floor
|
|
129
|
-
}
|
|
130
|
-
throw new APIError(0, event.error.code, event.error.message, event.error.details);
|
|
131
|
-
}
|
|
132
|
-
cursor = event.sequence_number;
|
|
133
|
-
handle(event);
|
|
134
|
-
}
|
|
135
|
-
return; // ended on node.settled
|
|
136
|
-
} catch (error) {
|
|
137
|
-
if (error instanceof APIError && error.code === 'stream_dropped') continue;
|
|
138
|
-
throw error;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
`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.
|
|
144
|
-
|
|
145
|
-
## Identifier validation
|
|
146
|
-
|
|
147
|
-
`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 [[crouter-sdk/errors]].
|
|
148
|
-
|
|
149
|
-
## Event shapes depend on the pinned pi version
|
|
150
|
-
|
|
151
|
-
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,7 +0,0 @@
|
|
|
1
|
-
import type { LeafDef } from '../core/command.js';
|
|
2
|
-
/** The node a `crtr surface attach to <id>` command line targets. Panes opened
|
|
3
|
-
* by a respawn path (the Markdown file-open bridge, the review companion) carry
|
|
4
|
-
* a shell-quoted id, so the raw command line is not comparable to the canonical
|
|
5
|
-
* one — the target node is. */
|
|
6
|
-
export declare function attachTargetNode(command: string): string | undefined;
|
|
7
|
-
export declare const surfaceReloadLeaf: LeafDef;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var f=Object.defineProperty;var p=(n,e)=>f(n,"name",{value:e,configurable:!0});import{defineLeaf as w}from"../core/command.js";import{InputError as o}from"../core/io.js";import{listProcessTable as l}from"../core/canvas/pid.js";import{displayMessage as a}from"../core/runtime/tmux-chrome.js";import{nodeInPane as v,paneCurrentPath as g,panePid as x,paneStartCommand as y,respawnPaneInPlace as P,respawnPaneSync as _,viewerSplitEnv as $}from"./surface/node/placement.js";function T(n,e){const r=l();if(r===null)return!1;const s=new Map,t=new Map;for(const{pid:d,ppid:c,command:h}of r){t.set(d,h);const m=s.get(c)??[];m.push(d),s.set(c,m)}const u=new RegExp(`(?:^|\\s)surface attach to ${e}(?:\\s|$)`),i=[n];for(;i.length>0;){const d=i.pop(),c=t.get(d);if(c!==void 0&&u.test(c))return!0;const h=s.get(d);h!==void 0&&i.push(...h)}return!1}p(T,"paneTreeHasViewer");function b(n){const e=/(?:^|\s)surface attach to\s+(?:'([^']*)'|"([^"]*)"|(\S+))/.exec(n);return e?.[1]??e?.[2]??e?.[3]}p(b,"attachTargetNode");const R=w({name:"reload",description:"respawn a viewer pane in place onto the current runtime generation",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",help:{name:"surface reload",summary:"kill and re-run a viewer pane\u2019s `crtr surface attach to <node>` command line in place, so the fresh viewer picks up the currently selected runtime generation",params:[{kind:"flag",name:"pane",type:"string",required:!1,constraint:"tmux pane id hosting the viewer to reload. Defaults to $TMUX_PANE / your current pane. The Alt+C menu passes this for you."}],output:[{name:"pane",type:"string",required:!0,constraint:"The respawned tmux pane."},{name:"node_id",type:"string",required:!0,constraint:"The node whose viewer was reloaded."}],outputKind:"object",effects:["Kills the pane\u2019s viewer process and re-runs the viewer command line in the same pane; the node\u2019s broker engine keeps running untouched."]},run:p(async n=>{const e=n.pane??process.env.TMUX_PANE;if(e===void 0||e==="")throw new o({error:"not_in_tmux",message:"viewer reload is tmux-only \u2014 no tmux pane to target",next:"Run it inside tmux, or pass --pane <pane-id> of a tmux viewer pane."});const r=v(e);if(r===void 0)throw a("crtr: no viewer in pane",e),new o({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>`."});const s=`crtr surface attach to ${r}`,t=y(e)?.replace(/^"|"$/g,"");if(t!==void 0&&t.startsWith("crtr surface attach ")){if(b(t)!==r)throw a("crtr: viewer/node mismatch in pane",e),new o({error:"no_viewer",message:`this pane's viewer command (${t}) does not match its node tag (${r})`,next:"Pass --pane <pane-id> for a pane running `crtr surface attach to <node>`."});if(!P(e))throw a("crtr: viewer reload failed",e),new o({error:"respawn_failed",message:`tmux could not respawn pane ${e}`,next:"Check the tmux server is reachable, then retry."});return a("crtr: viewer reloaded",e),{pane:e,node_id:r}}const u=x(e);if(u===void 0||!T(u,r))throw a("crtr: no viewer in pane",e),new o({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>`."});const i=g(e)??process.cwd();if(!_({pane:e,cwd:i,env:$(),command:s}))throw a("crtr: viewer reload failed",e),new o({error:"respawn_failed",message:`tmux could not respawn pane ${e}`,next:"Check the tmux server is reachable, then retry."});return a("crtr: viewer reloaded",e),{pane:e,node_id:r}},"run"),render:p(n=>`Reloaded viewer for ${n.node_id} in pane ${n.pane}.`,"render")});export{b as attachTargetNode,R as surfaceReloadLeaf};
|
package/docs/sdk/bash.md
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Bash
|
|
3
|
-
description: Execute bounded shell commands through the daemon.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# `client.bash`
|
|
7
|
-
|
|
8
|
-
`client.bash.run` executes one bounded `bash -c` command through the daemon.
|
|
9
|
-
|
|
10
|
-
```ts
|
|
11
|
-
const result = await client.bash.run({
|
|
12
|
-
command: 'printf "%s\\n" "$MESSAGE"',
|
|
13
|
-
cwd: '/absolute/path/to/project',
|
|
14
|
-
env: { MESSAGE: 'hello' },
|
|
15
|
-
timeout_s: 30,
|
|
16
|
-
profile: 'my-app',
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
if (result.exit_code !== 0) console.error(result.stderr);
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
`run(params, options?)` returns `Promise<BashRunDTO>`. Its final `options` object is the normal request-options object: `headers`, `signal`, `timeout`, and `maxRetries`.
|
|
23
|
-
|
|
24
|
-
| Result field | Type | Meaning |
|
|
25
|
-
|---|---|---|
|
|
26
|
-
| `exit_code` | `number \| null` | Process exit code, or `null` after a timeout. A non-zero code is returned, not thrown. |
|
|
27
|
-
| `signal` | `string \| null` | Signal that ended the process, when one did. |
|
|
28
|
-
| `stdout` / `stderr` | `string` | Captured output prefix. |
|
|
29
|
-
| `stdout_truncated` / `stderr_truncated` | `boolean` | Whether that output stream exceeded its 256 KiB capture limit. |
|
|
30
|
-
| `timed_out` | `boolean` | `true` after the daemon terminates the process group for a timeout. |
|
|
31
|
-
| `duration_ms` | `number` | Command duration in milliseconds. |
|
|
32
|
-
|
|
33
|
-
`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.
|
|
34
|
-
|
|
35
|
-
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.
|
|
36
|
-
|
|
37
|
-
## Authority
|
|
38
|
-
|
|
39
|
-
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.
|
package/docs/sdk/files.md
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Files
|
|
3
|
-
description: Read, write, and list host files through the daemon.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# `client.files`
|
|
7
|
-
|
|
8
|
-
`client.files` reads, writes, and lists host files through the daemon.
|
|
9
|
-
|
|
10
|
-
```ts
|
|
11
|
-
const source = await client.files.read('/absolute/path/to/input.txt');
|
|
12
|
-
const written = await client.files.write('/absolute/path/to/output.txt', source.content);
|
|
13
|
-
const directory = await client.files.list('/absolute/path/to');
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
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.
|
|
17
|
-
|
|
18
|
-
Every method accepts ordinary request options in its final object: `headers`, `signal`, `timeout`, and `maxRetries`. `read` and `write` add `encoding`; `list` adds `limit`.
|
|
19
|
-
|
|
20
|
-
## Read
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
await client.files.read(path, { encoding: 'utf8', timeout: 5_000 });
|
|
24
|
-
await client.files.read(path, { encoding: 'base64' });
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
`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.
|
|
28
|
-
|
|
29
|
-
## Write
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
const result = await client.files.write(path, content, { encoding: 'utf8' });
|
|
33
|
-
// result is { path, bytes_written }
|
|
34
|
-
await client.files.write(path, bytes.toString('base64'), { encoding: 'base64' });
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
`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.
|
|
38
|
-
|
|
39
|
-
## List
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
const result = await client.files.list(path, { limit: 100 });
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
`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.
|
|
46
|
-
|
|
47
|
-
## Authority
|
|
48
|
-
|
|
49
|
-
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,17 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: SDK recipes
|
|
3
|
-
description: When composing crouter SDK namespaces into an application, read this because it helps you choose a complete runnable starting point.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# SDK recipes
|
|
7
|
-
|
|
8
|
-
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.
|
|
9
|
-
|
|
10
|
-
| Recipe | Use it when | It ends with |
|
|
11
|
-
|---|---|---|
|
|
12
|
-
| [Typed extraction](./typed-extraction.md) | You need one structured answer and no follow-up. | A typed object or an explicit failure. |
|
|
13
|
-
| [Event-driven assistant](./event-driven-assistant.md) | Events arrive over time from a webhook, queue, or watcher. | A resident node that wakes for each event. |
|
|
14
|
-
| [Fan-out pipeline](./fan-out-pipeline.md) | One task needs independent research before a synthesis. | An orchestrator's final report. |
|
|
15
|
-
| [Human approval](./human-approval.md) | A person must decide before work continues. | A node resumed by an inbox answer. |
|
|
16
|
-
|
|
17
|
-
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,24 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Event-driven assistant
|
|
3
|
-
description: When an assistant must react to later webhook, queue, or file-watcher events, read this because a resident node sleeps until nodes.message delivers the next event.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Event-driven assistant
|
|
7
|
-
|
|
8
|
-
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.
|
|
9
|
-
|
|
10
|
-
<include lang="ts">../../../examples/guides/event-driven-assistant.ts</include>
|
|
11
|
-
|
|
12
|
-
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.
|
|
13
|
-
|
|
14
|
-
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.
|
|
15
|
-
|
|
16
|
-
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.`:
|
|
17
|
-
|
|
18
|
-
```text
|
|
19
|
-
assistant node: 3zl47w7d-mud5amcx-67978c9b
|
|
20
|
-
Type an event and press Enter. Press Ctrl-C to stop the assistant.
|
|
21
|
-
The build completed, but **lint and unit tests failed**. Inspect the two failing check logs first to identify the errors.
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Use a resident node only when future events belong to the same ongoing assistant. For bounded work, use [typed extraction](./typed-extraction.md). See [lifecycle and wakes](../../concepts/lifecycle-and-wakes.md) for why waiting is free and [why a daemon](../../concepts/why-a-daemon.md) for why the process can outlive the terminal that started it.
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Fan-out pipeline
|
|
3
|
-
description: When independent parts of one job need separate agent work before one synthesis, read this because an orchestrator can spawn children, wait for reports, and publish a final result while the SDK streams progress.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Fan-out pipeline
|
|
7
|
-
|
|
8
|
-
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.
|
|
9
|
-
|
|
10
|
-
<include lang="ts">../../../examples/guides/fan-out-pipeline.ts</include>
|
|
11
|
-
|
|
12
|
-
`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.
|
|
13
|
-
|
|
14
|
-
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.
|
|
15
|
-
|
|
16
|
-
A local run created `j6amiqxs-mud4drnk-330da196`; after its two children reported, `waitForOutcome()` returned:
|
|
17
|
-
|
|
18
|
-
```text
|
|
19
|
-
{ "kind": "result", "reason": "finalized" }
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
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.
|
|
23
|
-
|
|
24
|
-
See [nodes and the canvas](../../concepts/nodes-and-the-canvas.md) for reports and durable identities, and [profiles, kinds, and modes](../../concepts/profiles-kinds-and-modes.md) for the base-versus-orchestrator decision.
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Human approval
|
|
3
|
-
description: When a person must approve or reject work before an agent continues, read this because the SDK can create an inbox request whose answer wakes the requesting node.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Human approval
|
|
7
|
-
|
|
8
|
-
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.
|
|
9
|
-
|
|
10
|
-
<include lang="ts">../../../examples/guides/human-approval.ts</include>
|
|
11
|
-
|
|
12
|
-
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.
|
|
13
|
-
|
|
14
|
-
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.
|
|
15
|
-
|
|
16
|
-
Observed against the local daemon after an approve response:
|
|
17
|
-
|
|
18
|
-
```text
|
|
19
|
-
approval ticket: a643479ca7a79758bf86f32d24bd8c9b22e16509cd60996c5e4fe0bc5f097d45
|
|
20
|
-
Answer it in the crtr human inbox. The worker will wake with the response.
|
|
21
|
-
worker outcome: result
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
See [lifecycle and wakes](../../concepts/lifecycle-and-wakes.md) for the wake model and [scopes and trust](../../concepts/scopes-and-trust.md) for why the daemon, rather than the application, owns delivery of the answer.
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Typed extraction
|
|
3
|
-
description: When an application needs one bounded structured answer with no follow-up, read this because nodes.parse returns a typed outcome union instead of hiding agent failures.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Typed extraction
|
|
7
|
-
|
|
8
|
-
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.
|
|
9
|
-
|
|
10
|
-
<include lang="ts">../../../examples/guides/typed-extraction.ts</include>
|
|
11
|
-
|
|
12
|
-
`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.
|
|
13
|
-
|
|
14
|
-
Observed against the local daemon in this checkout:
|
|
15
|
-
|
|
16
|
-
```text
|
|
17
|
-
package @north-light/cli@0.3.332
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
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.
|
|
21
|
-
|
|
22
|
-
**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).
|
|
23
|
-
|
|
24
|
-
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 [nodes and the canvas](../../concepts/nodes-and-the-canvas.md) for why an SDK node has durable identity, and [lifecycle and wakes](../../concepts/lifecycle-and-wakes.md) for the terminal-versus-resident decision.
|