@north-light/cli 0.3.693 → 0.3.695
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/api/errors.js +1 -1
- 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/cli.js +6 -6
- 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/inspect.js +9 -9
- package/dist/commands/node-worktree.js +1 -1
- package/dist/commands/pkg/market-manage.js +1 -1
- package/dist/commands/pkg/plugin-manage.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/commands/sys/update.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 +7 -7
- package/dist/core/canvas/types.d.ts +0 -2
- package/dist/core/config.js +1 -1
- package/dist/core/conversation-store/row-store.js +10 -10
- package/dist/core/graph/exposures.js +1 -1
- package/dist/core/graph/names.js +9 -9
- package/dist/core/graph/watches.js +1 -1
- package/dist/core/installed-plugins.js +1 -1
- 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/scoped-state/imported-mac-installs.d.ts +12 -0
- package/dist/core/scoped-state/imported-mac-installs.js +2 -0
- package/dist/core/spaces/stop.js +1 -1
- 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/dist/shared/env.d.ts +8 -3
- package/dist/shared/env.js +2 -2
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- 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/api/errors.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/inspect.js +16 -2
- package/packages/crouter-api/dist/commands/node-worktree.js +1 -5
- package/packages/crouter-api/dist/commands/pkg/market-manage.js +22 -19
- package/packages/crouter-api/dist/commands/pkg/plugin-manage.js +2 -1
- 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/commands/sys/update.js +5 -3
- package/packages/crouter-api/dist/core/broker-client/client.js +5 -17
- package/packages/crouter-api/dist/core/canvas/canvas.js +6 -11
- package/packages/crouter-api/dist/core/config.js +10 -3
- package/packages/crouter-api/dist/core/conversation-store/row-store.js +7 -4
- package/packages/crouter-api/dist/core/graph/exposures.js +1 -1
- package/packages/crouter-api/dist/core/graph/names.js +7 -20
- package/packages/crouter-api/dist/core/graph/watches.js +1 -1
- package/packages/crouter-api/dist/core/installed-plugins.js +3 -2
- 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/scoped-state/imported-mac-installs.js +94 -0
- package/packages/crouter-api/dist/core/spaces/stop.js +2 -2
- 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/dist/shared/env.js +15 -4
- package/packages/crouter-api/dist/types.js +1 -1
- 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
package/README.md
CHANGED
|
@@ -113,17 +113,14 @@ import { z } from 'zod';
|
|
|
113
113
|
|
|
114
114
|
const client = new Crouter(); // local daemon; started on first request if it is not running
|
|
115
115
|
|
|
116
|
-
const run = await client.
|
|
117
|
-
prompt: '
|
|
118
|
-
cwd: '/absolute/path/to/project',
|
|
116
|
+
const run = await client.runs.parse({
|
|
117
|
+
prompt: 'Report the name and version of the package in your files folder.',
|
|
119
118
|
output_schema: z.object({ name: z.string(), version: z.string() }),
|
|
120
119
|
});
|
|
121
|
-
|
|
122
|
-
if (run.kind === 'result') console.log(run.output_parsed.name, run.output_parsed.version);
|
|
123
|
-
else console.error(run.reason, run.detail);
|
|
120
|
+
console.log(run);
|
|
124
121
|
```
|
|
125
122
|
|
|
126
|
-
`
|
|
123
|
+
`runs.parse` returns a typed result instead of text you have to parse. A program that drives its owner's own daemon (nodes, bash, crons, the human inbox) uses `CrtrClient` from `@north-light/api` or the `crtr` CLI. See the [SDK docs](https://crouter.docs.northlight.ai/docs/sdk).
|
|
127
124
|
|
|
128
125
|
## Run it in a container
|
|
129
126
|
|
|
@@ -3,7 +3,7 @@ export interface DeclaredOutputShape {
|
|
|
3
3
|
constraint: string;
|
|
4
4
|
/** Named members of an `object` value. Declaring them closes the object. */
|
|
5
5
|
children?: DeclaredOutputField[];
|
|
6
|
-
/** Shape of every member `children` does not declare. Absent
|
|
6
|
+
/** Shape of every member `children` does not declare. Absent closes the object when validated with `closed`. */
|
|
7
7
|
extra?: DeclaredOutputShape;
|
|
8
8
|
/** Shape of each contained value of an `array` or `map` value. */
|
|
9
9
|
items?: DeclaredOutputShape;
|
|
@@ -25,8 +25,8 @@ export interface ValueMismatch {
|
|
|
25
25
|
}
|
|
26
26
|
/** Validates a result object against declared output field descriptors.
|
|
27
27
|
* Returns null if valid; otherwise returns a { field, receivedType } error
|
|
28
|
-
* where `field` is the full path of the first mismatch. */
|
|
29
|
-
export declare function validateDeclaredResult(output: DeclaredOutputField[], result: Record<string, unknown
|
|
28
|
+
* where `field` is the full path of the first mismatch. A client ignores object members it does not know; `closed` makes them a mismatch. */
|
|
29
|
+
export declare function validateDeclaredResult(output: DeclaredOutputField[], result: Record<string, unknown>, closed?: boolean): {
|
|
30
30
|
field: string;
|
|
31
31
|
receivedType?: string;
|
|
32
32
|
expected?: string;
|
|
@@ -34,6 +34,6 @@ export declare function validateDeclaredResult(output: DeclaredOutputField[], re
|
|
|
34
34
|
/** Checks one JSON value against one shape, recursively: object members, array
|
|
35
35
|
* items, map values, union variants, enum values and nullability. An object that
|
|
36
36
|
* declares `children` is closed unless it carries `extra`: an undeclared
|
|
37
|
-
* member is a mismatch at any depth, or must fit `extra`. Returns null, or the first mismatch with its full path from `path`.
|
|
37
|
+
* member is a mismatch at any depth (ignored when `closed` is false), or must fit `extra`. Returns null, or the first mismatch with its full path from `path`.
|
|
38
38
|
* A declared type that is not recognized is accepted. */
|
|
39
|
-
export declare function validateValue(shape: DeclaredOutputShape, value: unknown, path: string): ValueMismatch | null;
|
|
39
|
+
export declare function validateValue(shape: DeclaredOutputShape, value: unknown, path: string, closed?: boolean): ValueMismatch | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var $=Object.defineProperty;var a=(l,n)=>$(l,"name",{value:n,configurable:!0});import{isRecord as m}from"../../shared/predicates.js";function x(l,n,e=!1){for(const u of l){const c=n[u.name];if(!(Object.prototype.hasOwnProperty.call(n,u.name)&&c!==void 0)){if(u.required)return{field:u.name};continue}const t=s(u,c,u.name,e);if(t!==null)return{field:t.path,receivedType:t.receivedType,expected:t.expected}}return null}a(x,"validateDeclaredResult");function s(l,n,e,u=!0){const c=l.type.split("|").map(t=>t.trim()).filter(Boolean),r=c.filter(t=>t.toLowerCase()!=="null");if(n===null&&r.length<c.length||r.length===1&&!b(r[0])||!c.every(t=>b(t)||/^[a-z][a-z0-9_-]*$/.test(t)))return null;if(r.length===1)return g(r[0],l,n,e,u);for(const t of r)if(g(t,l,n,e,u)===null)return null;return y(e,l.type,n)}a(s,"validateValue");function y(l,n,e){const u=e===null?"null":Array.isArray(e)?"array":typeof e;return{path:l,expected:n,receivedType:u}}a(y,"mismatch");function b(l){const n=l.toLowerCase();return n==="null"||n==="string"||n==="path"||n==="markdown"||n==="int"||n==="integer"||n==="number"||n==="float"||n==="bool"||n==="boolean"||n==="array"||n.endsWith("[]")||n==="object"||n==="map"||n==="union"||n==="unknown"||n==="enum"||n==="file"}a(b,"knownType");function g(l,n,e,u,c){const r=l.toLowerCase(),t=a(f=>y(u,f,e),"fail");if(r==="null")return e===null?null:t("null");if(r==="unknown")return null;if(r==="enum")return n.values===void 0||typeof e=="string"&&n.values.includes(e)?null:t(`one of ${(n.values??[]).join(", ")}`);if(r==="file")return m(e)||typeof e=="string"?null:t("file");if(r==="string"||r==="path"||r==="markdown")return typeof e=="string"?null:t(r);if(r==="int"||r==="integer")return typeof e=="number"&&Number.isInteger(e)?null:t("int");if(r==="number"||r==="float")return typeof e=="number"?null:t("number");if(r==="bool"||r==="boolean")return typeof e=="boolean"?null:t("bool");if(r==="array"){if(!Array.isArray(e))return t("array");if(n.items===void 0)return null;for(let f=0;f<e.length;f++){const i=s(n.items,e[f],`${u}[${f}]`,c);if(i!==null)return i}return null}if(r.endsWith("[]"))return Array.isArray(e)?null:t("array");if(r==="map"){if(!m(e))return t("map");if(n.items===void 0)return null;for(const[f,i]of Object.entries(e)){const o=s(n.items,i,`${u}[${JSON.stringify(f)}]`,c);if(o!==null)return o}return null}if(r==="object"){if(!m(e))return t("object");if(n.children===void 0)return null;for(const i of n.children){const o=e[i.name];if(!(Object.prototype.hasOwnProperty.call(e,i.name)&&o!==void 0)){if(i.required)return{path:`${u}.${i.name}`,expected:`${i.type} (required)`,receivedType:"undefined"};continue}const p=s(i,o,`${u}.${i.name}`,c);if(p!==null)return p}const f=new Set(n.children.map(i=>i.name));for(const i of Object.keys(e)){if(f.has(i))continue;if(n.extra===void 0&&c)return y(`${u}.${i}`,"no such member (the object is closed)",e[i]);if(n.extra===void 0||e[i]===void 0)continue;const o=s(n.extra,e[i],`${u}.${i}`,c);if(o!==null)return o}return null}if(r==="union"){const f=[];for(const o of n.variants??[]){const d=s(o,e,u,c);if(d===null)return null;f.push(d)}const i=f[0];return i!==void 0&&i.path!==u&&f.every(o=>o.path===i.path)?{path:i.path,expected:[...new Set(f.map(o=>o.expected))].join(" | "),receivedType:i.receivedType}:t((n.variants??[]).map(o=>o.type).join(" | "))}return typeof e=="string"&&e===l?null:t(l)}a(g,"atomMismatch");export{x as validateDeclaredResult,s as validateValue};
|
package/dist/api/contract.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The contract level this build serves and requires. Written by `scripts/contract.mjs release`; never edit by hand. */
|
|
2
|
-
export declare const CONTRACT_LEVEL = "1.
|
|
2
|
+
export declare const CONTRACT_LEVEL = "1.65";
|
|
3
3
|
/** Request header naming the one contract level the caller needs, e.g. `1.3`. Optional: absent means no check. */
|
|
4
4
|
export declare const REQUIRED_CONTRACT_HEADER = "Crouter-Required-Contract";
|
|
5
5
|
/** Response header listing the contract levels the server serves, comma-separated, one per major, e.g. `1.3`. */
|
package/dist/api/contract.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var c=Object.defineProperty;var e=(r,t)=>c(r,"name",{value:t,configurable:!0});const f="1.
|
|
1
|
+
var c=Object.defineProperty;var e=(r,t)=>c(r,"name",{value:t,configurable:!0});const f="1.65",i="Crouter-Required-Contract",p="Crouter-Contract";function l(r){const t=/^(\d+)\.(\d+)$/.exec(r.trim());return t===null?null:{major:Number(t[1]),minor:Number(t[2])}}e(l,"parseContractLevel");function a(r){return r==null?[]:r.split(",").map(t=>l(t)).filter(t=>t!==null)}e(a,"parseServedContracts");function s(r,t){const n=l(r);return n===null?!1:(typeof t=="string"||t===null||t===void 0?a(t):t).some(u=>u.major===n.major&&u.minor>=n.minor)}e(s,"contractSatisfies");function C(r,t,n={}){if(r===void 0)return null;if(l(r)===null)return{status:400,code:"invalid_request",param:i,message:`${i} must be a contract level like 1.0.`};if(s(r,t))return null;const o=r.trim();return{status:426,code:"runtime_version_unsupported",message:t===null||a(t).length===0?`The runtime did not name its contract level; the caller requires contract ${o} or later. Roll the runtime forward.`:`The runtime serves contract ${t}; the caller requires contract ${o} or later within the same major. Roll the runtime forward, or pin an SDK whose crouterContract the runtime serves.`,details:{sdk_version:(n.legacyMinimum??"").trim(),runtime_version:n.runtimeVersion??null,required_contract:o,runtime_contract:t}}}e(C,"contractRefusal");export{p as CONTRACT_HEADER,f as CONTRACT_LEVEL,i as REQUIRED_CONTRACT_HEADER,C as contractRefusal,s as contractSatisfies,l as parseContractLevel,a as parseServedContracts};
|
|
@@ -9,6 +9,7 @@ export interface RunUsageDTO {
|
|
|
9
9
|
cache_write_tokens: number;
|
|
10
10
|
cost_usd: number;
|
|
11
11
|
}
|
|
12
|
+
export declare const ZERO_RUN_USAGE: Readonly<RunUsageDTO>;
|
|
12
13
|
/** `run.get` status. */
|
|
13
14
|
export type RunStatusDTO = 'running' | 'waiting_on_user' | 'idle' | 'settled';
|
|
14
15
|
/** `run.get` `activity`: what the run's root node is doing now; null unless the run is `running`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t={input_tokens:0,output_tokens:0,cache_read_tokens:0,cache_write_tokens:0,cost_usd:0};export{t as ZERO_RUN_USAGE};
|
|
@@ -14,10 +14,6 @@ export interface CloseWorktreeResultDTO {
|
|
|
14
14
|
/** False while the local branch remains checked out by the deferred cleanup. */
|
|
15
15
|
branch_deleted: boolean;
|
|
16
16
|
branch_delete_error?: string;
|
|
17
|
-
/** Present ONLY when landing had to stash local changes in the base checkout
|
|
18
|
-
* and re-applying them conflicted: names the preserved stash and how to
|
|
19
|
-
* re-apply it. Its absence means nothing local was left over. */
|
|
20
|
-
base_checkout_stash?: string;
|
|
21
17
|
}
|
|
22
18
|
export interface AbandonWorktreeRequest {
|
|
23
19
|
by: string;
|
package/dist/api/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var u=Object.defineProperty;var r=(t,s)=>u(t,"name",{value:s,configurable:!0});class n extends Error{static{r(this,"APIError")}status;code;details;headers;type;param;origin;retryable;retryAfterS;resetAt;requestId;runId;questionId;scope;userAction;constructor(s,i,a,o,
|
|
1
|
+
var u=Object.defineProperty;var r=(t,s)=>u(t,"name",{value:s,configurable:!0});class n extends Error{static{r(this,"APIError")}status;code;details;headers;type;param;origin;retryable;retryAfterS;resetAt;requestId;runId;questionId;scope;userAction;constructor(s,i,a,d,o,e){super(a),this.name="APIError",this.status=s,this.code=i,this.headers=new Headers(o),d!==void 0&&(this.details=d),this.type=e?.type,this.param=e?.param,this.origin=e?.origin,this.retryable=e?.retryable,this.retryAfterS=e?.retry_after_s,this.resetAt=e?.reset_at,this.requestId=e?.request_id??this.headers.get("Request-Id")??void 0,this.runId=e?.run_id,this.questionId=e?.question_id,this.scope=e?.scope,this.userAction=e?.user_action}}function h(t){return t instanceof n?t.status===503&&(t.code==="daemon_unavailable"||t.code==="transport_error"||t.code==="daemon_request_interrupted"||t.code==="runtime_starting"||t.code==="northlight_unreachable")||t.status===504&&(t.code==="request_timeout"||t.code==="deadline_exceeded")||t.status>=500&&t.code==="daemon_health_unavailable":!1}r(h,"isDaemonTransportApiError");function f(t){return t instanceof n&&t.status===401}r(f,"isTokenRevokedApiError");function _(t){if(typeof t!="object"||t===null)return!1;const s=t.error;if(typeof s!="object"||s===null)return!1;const{code:i,message:a}=s;return typeof i=="string"&&typeof a=="string"}r(_,"isErrorBody");export{n as APIError,n as ApiError,h as isDaemonTransportApiError,_ as isErrorBody,f as isTokenRevokedApiError};
|
|
@@ -25,4 +25,4 @@ A node wakes when work actually arrives: a subscribed child pushes a report, ano
|
|
|
25
25
|
|
|
26
26
|
Do not keep a node active to poll a child, a person, or a message. Creation automatically subscribes a parent to its child, and the runtime delivers the child’s outcome. Waiting for something the canvas can push is free: end the turn and let the node become dormant. Schedule a cron only for recurring work or an external condition that nothing can push into the canvas, such as checking a CI run. A timer added “just in case” a child does not report duplicates a runtime guarantee and hides a runtime defect.
|
|
27
27
|
|
|
28
|
-
A broker crash does not erase the node. The daemon retains the durable node row, conversation, waits, and outstanding inbox entries, then applies its recovery policy. This is what makes a resident event-driven assistant practical: it can wait for a webhook, be dormant for hours, and resume its saved work only when the webhook produces a message. Use
|
|
28
|
+
A broker crash does not erase the node. The daemon retains the durable node row, conversation, waits, and outstanding inbox entries, then applies its recovery policy. This is what makes a resident event-driven assistant practical: it can wait for a webhook, be dormant for hours, and resume its saved work only when the webhook produces a message. Use `crtr node message` (or `CrtrClient` from `@north-light/api`) to deliver that external event, and run `crtr canvas read internal/nodes-and-canvas` for lifecycle operations.
|
|
@@ -9,7 +9,7 @@ when-and-why-to-read: When deciding whether an agent task should outlive one
|
|
|
9
9
|
|
|
10
10
|
Use a node when the work may need a follow-up, a report, a child, or time without a caller holding a request open. A node is a durable unit of agent work: it has an identity, a goal, graph relationships, the documents it writes for other readers, a context directory for its scripts and data, and a broker that hosts its agent engine. It is not an HTTP request with an LLM response attached.
|
|
11
11
|
|
|
12
|
-
The canvas is a durable graph of **objects**, not only nodes. Documents, nodes, bash jobs, owners (a person, an app, a repo, a profile) and custom objects registered by outside services are all objects with an id and a name, and the same verbs work on every one of them: `crtr canvas read`, `list`, `search`, `watch`, `unwatch` and `edges`. Edges record what an object links to, who acted on it and who watches it. Reading an object, writing a document, messaging a node or spawning one makes you a watcher, so its later events reach your inbox. See [[crouter-concepts/documents]] for the document object. The canvas makes an agent's work and its relationship to other work visible after the process that created it has returned. This is why
|
|
12
|
+
The canvas is a durable graph of **objects**, not only nodes. Documents, nodes, bash jobs, owners (a person, an app, a repo, a profile) and custom objects registered by outside services are all objects with an id and a name, and the same verbs work on every one of them: `crtr canvas read`, `list`, `search`, `watch`, `unwatch` and `edges`. Edges record what an object links to, who acted on it and who watches it. Reading an object, writing a document, messaging a node or spawning one makes you a watcher, so its later events reach your inbox. See [[crouter-concepts/documents]] for the document object. The canvas makes an agent's work and its relationship to other work visible after the process that created it has returned. This is why `crtr node new` (and `CrtrClient` from `@north-light/api`) returns a node you can retrieve, message, stream, or wait on instead of only returning generated text. A program can create a root node, show its progress, and later message it when a person or an external event has more work for it.
|
|
13
13
|
|
|
14
14
|
```mermaid
|
|
15
15
|
flowchart TD
|
|
@@ -28,4 +28,4 @@ The one way work reports upward is a **push**. A push writes a report, which is
|
|
|
28
28
|
|
|
29
29
|
A node owns an outcome, not merely a deliverable. It may write documents, files and reports while working, but its terminal result is credible only when it has evidence that the requested goal was met. The canvas supports that responsibility: it preserves the goal, the node's documents and reports, and relationships across fresh contexts and broker replacement. A node's context directory holds only what is not a document — scripts, data, logs; writing meant for another reader is a document shared by `[[name]]`.
|
|
30
30
|
|
|
31
|
-
Use a one-shot SDK call such as
|
|
31
|
+
Use a one-shot SDK call such as `runs.parse` when work is bounded and its only useful output is a typed result. Create a node with `crtr node new` or `CrtrClient` when the application needs a continuing conversation or must observe work while it runs. For the operational graph and report model, run `crtr canvas read internal/nodes-and-canvas`.
|
|
@@ -30,4 +30,4 @@ A kind is a recurring role, not a decorative name. It carries a role-specific po
|
|
|
30
30
|
|
|
31
31
|
Base mode is the normal choice: the node owns and performs the work, using a child only for a separable part. Promote to orchestrator only when independent parts can proceed in parallel and the benefits outweigh coordination and integration. A terminal orchestrator still finishes normally; residency is separate and belongs to a person-facing ongoing conversation.
|
|
32
32
|
|
|
33
|
-
These choices keep the application prompt focused. Identity belongs in a profile, standing role in a kind, task-specific intent in the prompt, coordination in mode, and reusable knowledge in the narrowest document owner. For the full selection rules, run `crtr canvas read internal/agent-shaping`;
|
|
33
|
+
These choices keep the application prompt focused. Identity belongs in a profile, standing role in a kind, task-specific intent in the prompt, coordination in mode, and reusable knowledge in the narrowest document owner. For the full selection rules, run `crtr canvas read internal/agent-shaping`; `crtr node new -h` documents the profile, kind, and mode fields a caller passes.
|
|
@@ -25,7 +25,7 @@ Scope strings are prefixed with `crtr:`. These are the ones the daemon and CLI c
|
|
|
25
25
|
|
|
26
26
|
The `memory` in `crtr:memory:*` is the scope family's name for access to **documents** (see [[crouter-concepts/documents]]); there is no separate memory store. The older short names (`ask`, `act`, `schedule`, `memory:read`, `memory:write`, `llm`) are not accepted by `crtr sys connect --scopes`. A node's own documents, and an app's documents for its own nodes, need no `crtr:memory` scope.
|
|
27
27
|
|
|
28
|
-
This is an allow-list, not a claim that code will behave. The daemon checks the scope at the route that performs the action and rejects an unavailable one. The
|
|
28
|
+
This is an allow-list, not a claim that code will behave. The daemon checks the scope at the route that performs the action and rejects an unavailable one. The node-create route's `scopes` field narrows a run: a run's list must stay inside what its creator and grant hold, and `crtr:act` requires `crtr:llm`. `client.memory` is not scope-gated: it lists and reads the person's `knowledge` and `preference` documents, and the answer is filtered by privacy, which is `public` or `private`. An app's ceiling is `public` documents; a grant holding `crtr:memory:read_private:user` or `crtr:memory:manage:user` widens it to `private` ones. Within that ceiling, the app's registered schema and the relation facts it writes decide who may read a document, not a per-call scope. The exception is a run started with a `scopes` list: it reads its own app's documents (including automatic delivery of them at boot) only with `crtr:memory:read:app:<id>` and writes or edits them only with `crtr:memory:rw:app:<id>`; a refused write answers `scope_missing` naming the scope. Such a run still publishes its own reports with `crtr push` and its promoted node still gets a roadmap, but cannot edit any other document through that path, and a child never regains a scope its parent's list dropped.
|
|
29
29
|
|
|
30
30
|
```mermaid
|
|
31
31
|
flowchart LR
|
|
@@ -22,7 +22,7 @@ flowchart LR
|
|
|
22
22
|
|
|
23
23
|
The broker has one job: host a node’s agent session. The daemon has the broader job: preserve the node graph, state transitions, waits, reports, and broker lifecycle. A viewer may stream a broker’s live session, but it does not become the authority that decides whether that node is active, dormant, or revived. Closing a viewer closes a view, not the node’s durable identity.
|
|
24
24
|
|
|
25
|
-
This is why a process crash is recoverable rather than an automatic loss of work. The daemon retains the node row, session information, context directory, documents, waits, and inbox state, then applies recovery to the broker execution. A later wake or explicit revival can continue the node’s saved conversation. The application should create nodes through
|
|
25
|
+
This is why a process crash is recoverable rather than an automatic loss of work. The daemon retains the node row, session information, context directory, documents, waits, and inbox state, then applies recovery to the broker execution. A later wake or explicit revival can continue the node’s saved conversation. The application should create nodes through the daemon (`crtr node new` or `CrtrClient` from `@north-light/api`), not start an LLM process itself, because the daemon is the component that keeps the engine and durable canvas state coordinated.
|
|
26
26
|
|
|
27
27
|
The costs are real. A daemon must be running, and canvas state has one home instead of being scattered across terminals and application processes. Local clients use its owner-only Unix socket. Remote clients use its configured TCP listener and bearer token. A network interruption can therefore fail a mutation loudly rather than encouraging a client to replay it and risk doing the action twice.
|
|
28
28
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
kind: knowledge
|
|
3
|
-
description:
|
|
4
|
-
when-and-why-to-read: When you are writing or reviewing application code that
|
|
5
|
-
short-form: The ESM-only application-facing client for a crtrd daemon. Construction and transports, `client.
|
|
3
|
+
description: Calling a person's crtr runtime from an application with @north-light/sdk
|
|
4
|
+
when-and-why-to-read: When you are writing or reviewing application code that calls a person's crtr runtime — installing @north-light/sdk, constructing a client, running a typed one-shot run, or reaching the daemon from code — this reference should be read because the SDK no longer wraps the owner's node, bash, cron, human-inbox or system routes; a program driving its owner's own daemon uses `CrtrClient` from @north-light/api instead.
|
|
5
|
+
short-form: The ESM-only application-facing client for a crtrd daemon. Construction and transports, `client.runs`, the app-facing resources, error classes, and the pointer to `CrtrClient` for daemon owners.
|
|
6
6
|
surfaces:
|
|
7
7
|
- on: boot
|
|
8
8
|
at: name
|
|
@@ -1,67 +1,39 @@
|
|
|
1
1
|
---
|
|
2
2
|
kind: knowledge
|
|
3
3
|
when-and-why-to-read: When you need SDK overview, this knowledge should be read
|
|
4
|
-
because
|
|
5
|
-
|
|
4
|
+
because What the typed SDK covers on a daemon you run yourself, and where
|
|
5
|
+
daemon owners go for nodes, bash, crons and the human inbox.
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# `@north-light/sdk`
|
|
9
9
|
|
|
10
|
-
The ESM-only client an application installs to
|
|
10
|
+
The ESM-only client an application installs to start runs on a person's runtime, read their results, and manage what the app owns there. Apps that sign people in with Northlight are documented on the SDK docs site, which starts at [Quick setup](https://sdk.docs.northlight.ai/docs/quickstart).
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
`new Crouter()` in Node talks to the owner's unix socket. `new Crouter({ baseURL, token })` in a browser or a remote process talks to the daemon's TCP listener with a bearer token. On either, the client offers the app routes (`runs`, `uploads`, `docs`, `memory`, …) plus the few owner calls an app setup needs: `models.credentials.install`, `spendLimits` and `customObjects`. crtrd stays the sole owner of canvas state.
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
import Crouter from '@north-light/sdk';
|
|
16
|
-
import { z } from 'zod';
|
|
14
|
+
## Driving nodes, bash, crons or the human inbox
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
The SDK does not wrap the owner's node, bash, cron, human-inbox, canvas-view, file and system routes. A program that drives the owner's own daemon uses `CrtrClient` from `@north-light/api`, the typed client the `crtr` CLI itself uses, or the `crtr` CLI. `client.request(method, path, body?, options?)` still reaches any `/v1` route with the SDK's authentication, retries and error mapping.
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
output_schema: z.object({ failures: z.array(z.string()), root_cause: z.string() }),
|
|
24
|
-
});
|
|
18
|
+
```ts
|
|
19
|
+
import { CrtrClient } from '@north-light/api';
|
|
20
|
+
import { socketFetch, defaultSocketPath } from '@north-light/api/node';
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
const crtr = new CrtrClient({ baseUrl: 'http://localhost', fetch: socketFetch(defaultSocketPath()) });
|
|
23
|
+
const node = await crtr.createNode({ prompt: 'List the top-level directories here.', cwd: process.cwd(), root: true });
|
|
27
24
|
```
|
|
28
25
|
|
|
29
|
-
## Building an app for other people
|
|
30
|
-
|
|
31
|
-
An app that signs people in with Northlight and runs agents on their runtimes is documented on the SDK docs site, which starts at [Quick setup](https://sdk.docs.northlight.ai/docs/quickstart). This section and the pages below cover driving a crouter daemon you run yourself.
|
|
32
|
-
|
|
33
26
|
## Pages
|
|
34
27
|
|
|
35
28
|
| Page | Covers |
|
|
36
29
|
|---|---|
|
|
37
|
-
| [[crouter-sdk/getting-started]] | Install, `new Crouter()` on the owner's socket, `
|
|
30
|
+
| [[crouter-sdk/getting-started]] | Install, `new Crouter()` on the owner's socket, `crtr sys connect` for a browser or remote app, Chrome's local-network prompt |
|
|
38
31
|
| [[crouter-sdk/client]] | Every constructor option and its environment-variable fallback; per-request options |
|
|
39
|
-
| [[crouter-sdk/
|
|
40
|
-
| [[crouter-sdk/
|
|
41
|
-
| [[crouter-sdk/files]] | Absolute-path reads, writes, and one-level lists |
|
|
42
|
-
| [[crouter-sdk/bash]] | One bounded command and its output result |
|
|
43
|
-
| [[crouter-sdk/resources]] | Every namespace (including `customObjects`, `runs`, `memory`, `shares`, `providers`) with its routes, what is deliberately excluded, and the `client.request()` escape hatch |
|
|
44
|
-
| [[crouter-sdk/errors]] | The daemon's scoped-token and wire errors, identifier validation, and node retries |
|
|
32
|
+
| [[crouter-sdk/resources]] | Every namespace with its routes, and the `client.request()` escape hatch |
|
|
33
|
+
| [[crouter-sdk/errors]] | The daemon's scoped-token and wire errors, and identifier validation |
|
|
45
34
|
| [[crouter-sdk/docker]] | `start()`, `attach()`, `connection()` from `@north-light/env-docker` |
|
|
46
35
|
| [Release notes](https://sdk.docs.northlight.ai/docs/release-notes) | Behavior changes an existing app must act on, newest first |
|
|
47
36
|
|
|
48
|
-
## Phases
|
|
49
|
-
|
|
50
|
-
The surface ships in three cuts.
|
|
51
|
-
|
|
52
|
-
| Phase | What lands | State |
|
|
53
|
-
|---|---|---|
|
|
54
|
-
| **Phase 1** | Client construction and transports; `client.auth.status()`; `client.nodes.create`, `retrieve`, `list`, `outcome`, `waitForOutcome`, `createAndWait`, `parse`, `message`, `cancel`, and `interrupt`; `nodes.reports.list`; `profiles.ensure` and `retrieve`; `system.status` and `health`; the error hierarchy; per-request options; `crtr sys connect`; and `env-docker.connection()` | Shipped |
|
|
55
|
-
| **Phase 2 namespaces** | Node lifecycle, job, worktree, and result; canvas and canvas history; crons; human requests and inbox; models; `client.files.read` through `/v1/files/peek`, `write`, and `list`; and `client.bash.run` | Shipped |
|
|
56
|
-
| **Phase 2 streaming** | `GET /v1/nodes/{id}/events`, `nodes.stream(params, options?)`, `nodes.events(id, options?)`, `NodeStream`, and the activity helper | Shipped |
|
|
57
|
-
| **Phase 3** | The review, comment, and chat-inventory namespaces | Not shipped |
|
|
58
|
-
|
|
59
|
-
The per-run `scopes` create field ships in phase 1. `nodes.update` scope support remains phase 2 and is not in the shipped client or wire declarations.
|
|
60
|
-
|
|
61
|
-
## Verification status
|
|
62
|
-
|
|
63
|
-
The SDK declarations and streaming examples are verified.
|
|
64
|
-
|
|
65
37
|
## Where the agents read this
|
|
66
38
|
|
|
67
39
|
The same content routed for agents lives in the built-in document `crouter-sdk`, which ships with the `crtr` binary. An agent working in an application's repository reaches it with `crtr canvas read crouter-sdk` and does not need this repository checked out.
|
|
@@ -65,10 +65,9 @@ Autostart is Node-only and applies only to the socket transport. A `baseURL` cli
|
|
|
65
65
|
Every request-capable method accepts an options object as its last argument, after any path, body, or query arguments. Each field overrides the client-level default for that one request.
|
|
66
66
|
|
|
67
67
|
```ts
|
|
68
|
-
const id = 'example-node';
|
|
69
68
|
const signal = new AbortController().signal;
|
|
70
69
|
|
|
71
|
-
await client.
|
|
70
|
+
await client.runs.get('run-1', {
|
|
72
71
|
signal, // AbortSignal — real cancellation, passed straight to fetch
|
|
73
72
|
timeout: 5_000, // ms, this request only
|
|
74
73
|
maxRetries: 0, // this request only
|
|
@@ -85,7 +84,7 @@ await client.nodes.retrieve(id, {
|
|
|
85
84
|
| `deadlineAt` | `number` (epoch ms) | The same deadline as an absolute instant, for passing one deadline to several calls. With `budgetMs` too, the earlier wins. |
|
|
86
85
|
| `headers` | `Record<string, string>` | Merged over `defaultHeaders`, client `headers`, and the token-generated header; a matching name, including `Authorization`, wins. |
|
|
87
86
|
|
|
88
|
-
`signal` is real cancellation. The long-polling helpers (`
|
|
87
|
+
`signal` is real cancellation. The long-polling helpers (`runs.wait`, `runs.parse`) honour it between polls and during the in-flight request, and aborting them stops the client — it does not cancel the run. To stop the run itself, call `client.runs.cancel(id)` or `client.runs.interrupt(id)`.
|
|
89
88
|
|
|
90
89
|
### One deadline per call
|
|
91
90
|
|
|
@@ -95,9 +94,8 @@ Without `budgetMs`/`deadlineAt` a call has one `timeout` per attempt, so a keyed
|
|
|
95
94
|
await client.runs.message(runId, text, { budgetMs: 20_000 });
|
|
96
95
|
```
|
|
97
96
|
|
|
98
|
-
- The deadline is fixed once, when the call starts, and every attempt, every backoff, every `retry_after_s`/`Retry-After` wait, the token fetch and the refresh after a 401 share it. The call rejects at the deadline (plus the scheduling of one timer) whether the time goes to the headers, the body, a retry wait or the token hook, even when your `fetch` ignores its `AbortSignal`. The compound helpers (`runs.wait`, `runs.parse
|
|
97
|
+
- The deadline is fixed once, when the call starts, and every attempt, every backoff, every `retry_after_s`/`Retry-After` wait, the token fetch and the refresh after a 401 share it. The call rejects at the deadline (plus the scheduling of one timer) whether the time goes to the headers, the body, a retry wait or the token hook, even when your `fetch` ignores its `AbortSignal`. The compound helpers (`runs.wait`, `runs.parse`) fix one deadline for the whole helper, not one per poll.
|
|
99
98
|
- A retry wait that would reach the deadline is not slept: the call rejects at once with `DeadlineExceededError` (`code: 'deadline_exceeded'`, status 504). `reason` is `'retry_after'` when the server asked for a wait longer than the time left (`retryAfterRequestS` is that request), and `'elapsed'` when time simply ran out; `deadlineAt` is the instant, and `cause` is the last refusal.
|
|
100
|
-
- A stream (`nodes.stream`, `nodes.events`): `budgetMs` / `deadlineAt` bound opening it (the create or retrieve, the token hook and the connection); once open it lives until it ends or its `signal` aborts.
|
|
101
99
|
- `budgetMs` and `deadlineAt` must fit a timer: at most 2,147,483,647 ms (about 24.8 days) from now, or the call throws `RangeError`.
|
|
102
100
|
- **Holding a lease while you call.** An app that takes a lease or lock for an SDK call sets `budgetMs` and keeps the lease longer than it, with margin, so the call has ended or been abandoned before the lease can be taken over: `LEASE_MS >= BUDGET_MS + MARGIN_MS`. State that inequality next to the constants (or assert it at module load) rather than renewing the lease while a call is unbounded.
|
|
103
101
|
- `OAuth2Client` gives each directory operation (discovery, a code exchange or refresh, a revocation, the JWKS read behind `verifyIdToken`) the same kind of deadline, `OAuth2Options.timeoutMs` (default 10 s). A refresh runs under the user's store lock, so the lock is held no longer than `timeoutMs` plus the store's own time.
|
|
@@ -108,10 +106,10 @@ await client.runs.message(runId, text, { budgetMs: 20_000 });
|
|
|
108
106
|
|---|---|
|
|
109
107
|
| `.withResponse()` / `.asResponse()` | They exist to hand back the raw `Response` and an `x-request-id`. The daemon emits no request id, and a caller who needs raw bytes uses `client.request()`. |
|
|
110
108
|
| `apiKey` | The daemon's credential is a token (`CRTRD_TOKEN`) everywhere in the product. `apiKey` would be a second name for one thing. |
|
|
111
|
-
| Resource-prefixed ids |
|
|
109
|
+
| Resource-prefixed ids | Run ids have their own format. The SDK validates unsafe path identifiers locally with `TypeError`, and the daemon validates the request too; nothing is re-prefixed. |
|
|
112
110
|
|
|
113
111
|
## Wire naming
|
|
114
112
|
|
|
115
|
-
Wire fields are `snake_case` — `
|
|
113
|
+
Wire fields are `snake_case` — `run_id`, `output_schema`, `expires_at`. The SDK does not camelize them. Namespaces and method names are camelCase (`client.customObjects`, `client.runs.listAll`).
|
|
116
114
|
|
|
117
115
|
Timestamps are ISO-8601 strings (`created`, `settled_at`, `finalized_at`, `deadline_at`), not Unix seconds.
|
|
@@ -24,7 +24,7 @@ import Crouter from '@north-light/sdk';
|
|
|
24
24
|
const env = await start({ volume: 'my-agent-home' });
|
|
25
25
|
const client = new Crouter(env.connection());
|
|
26
26
|
|
|
27
|
-
await client.
|
|
27
|
+
await client.runs.start({ prompt: 'Do the thing.' });
|
|
28
28
|
|
|
29
29
|
await env.stop();
|
|
30
30
|
```
|
|
@@ -1,45 +1,23 @@
|
|
|
1
1
|
---
|
|
2
2
|
kind: knowledge
|
|
3
3
|
when-and-why-to-read: When you need Errors, this knowledge should be read
|
|
4
|
-
because What the crouter daemon refuses, how scoped tokens are limited,
|
|
5
|
-
socket wire body
|
|
4
|
+
because What the crouter daemon refuses, how scoped tokens are limited, and
|
|
5
|
+
the socket wire body.
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Errors
|
|
9
9
|
|
|
10
10
|
The error classes, the settled-outcome rule, retries and the app-facing error envelope are the same for every use of `@north-light/sdk`, and they are documented for app builders on the SDK docs site: [Errors](https://sdk.docs.northlight.ai/docs/errors). This page covers what is specific to driving a crouter daemon with `new Crouter()`.
|
|
11
11
|
|
|
12
|
-
**An agent's own outcome is returned, never thrown.** A node that declined the schema, hit its deadline, or crashed comes back as a settled `NodeOutcome` from `waitForOutcome`, `createAndWait`, or `parse`. Narrow on it — see [[crouter-sdk/nodes]].
|
|
13
|
-
|
|
14
|
-
## Daemon error codes
|
|
15
|
-
|
|
16
|
-
A terminal SSE `error` event other than `stream_gap` rejects `NodeStream.finalOutcome()` and the iterator with `APIError` carrying that event's code, message, and details. `stream_gap` is delivered as an event and the stream continues. See [[crouter-sdk/streaming]].
|
|
17
|
-
|
|
18
|
-
```ts
|
|
19
|
-
import { ConflictError, NotFoundError, APIConnectionError } from '@north-light/sdk';
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
await client.nodes.create({ prompt, node_id: 'my-run-42' });
|
|
23
|
-
} catch (error) {
|
|
24
|
-
if (error instanceof ConflictError && error.code === 'node_id_exists') {
|
|
25
|
-
// the run already exists — attach to it instead of spawning a second one
|
|
26
|
-
return client.nodes.waitForOutcome('my-run-42');
|
|
27
|
-
}
|
|
28
|
-
if (error instanceof NotFoundError) throw new Error('no such node');
|
|
29
|
-
if (error instanceof APIConnectionError) throw new Error('the daemon is not reachable');
|
|
30
|
-
throw error;
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
12
|
## Identifier validation
|
|
35
13
|
|
|
36
|
-
The SDK validates path-segment identifiers
|
|
14
|
+
The SDK validates path-segment identifiers (provider names, file ids, share and question ids) before it makes a request. An empty value, `.` or `..`, or one holding `/`, `\`, whitespace, `?`, `#` or `%` throws `TypeError` locally and sends no request.
|
|
37
15
|
|
|
38
16
|
## Scoped tokens
|
|
39
17
|
|
|
40
18
|
| Condition | Class, status, and code |
|
|
41
19
|
|---|---|
|
|
42
|
-
| The bearer token's ceiling lacks the scope a route needs, or
|
|
20
|
+
| The bearer token's ceiling lacks the scope a route needs, or a run asks for `scopes` outside it (`details.scopes` lists them) | `PermissionDeniedError`, 403 `scope_denied` |
|
|
43
21
|
| A scoped token reaches an owner-only route (daemon restart, attach, broker internals, canvas prune, profile pause/resume/delete, model credential install) | `PermissionDeniedError`, 403 `owner_only` |
|
|
44
22
|
|
|
45
23
|
## The wire body
|
|
@@ -52,24 +30,6 @@ The daemon answers an error with:
|
|
|
52
30
|
|
|
53
31
|
`code` is the stable, machine-readable identity — `node_id_exists`, `daemon_unavailable`, `request_timeout`, `node_dormant`. Branch on it. There is no separate `type` field and no `param` field. Northlight's app-facing endpoints answer with a fuller body; see the [error envelope](https://sdk.docs.northlight.ai/docs/errors#the-error-envelope).
|
|
54
32
|
|
|
55
|
-
## Creating a node that survives a retry
|
|
56
|
-
|
|
57
|
-
`nodes.create` is a `POST` and is not retried automatically, because replaying it would spawn a second agent. Pass `node_id` so a duplicate fails loudly with `409 node_id_exists` instead of quietly running twice:
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
const runId = `invoice-${invoice.id}`;
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
await client.nodes.create({ prompt, node_id: runId, root: true });
|
|
64
|
-
} catch (error) {
|
|
65
|
-
if (!(error instanceof ConflictError && error.code === 'node_id_exists')) throw error;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const outcome = await client.nodes.waitForOutcome(runId);
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Which calls the SDK retries, and `runs.start` / `runs.message` idempotency keys, are in [Retries](https://sdk.docs.northlight.ai/docs/errors#retries).
|
|
72
|
-
|
|
73
33
|
## In-repo callers
|
|
74
34
|
|
|
75
35
|
`ApiError` from `@north-light/api` is an alias of `APIError`, so existing crouter code and its transport checks keep working unchanged. Daemon handlers keep throwing `{ status, code, message }` and never name an SDK class — the hierarchy is one `status → constructor` table on the client side and nothing else depends on it.
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
kind: knowledge
|
|
3
3
|
when-and-why-to-read: When you need Getting started, this knowledge should be
|
|
4
|
-
read because Connect to a local or remote daemon and
|
|
4
|
+
read because Connect to a local or remote daemon and start your first run with
|
|
5
5
|
the SDK.
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Getting started
|
|
9
9
|
|
|
10
|
-
Phase 1.
|
|
11
|
-
|
|
12
10
|
An agent run needs a crouter daemon (`crtrd`) to run it. The SDK is a client for that daemon — it never runs an agent itself. There are two ways to reach one: the unix socket on the machine you are running on, or a TCP listener with a bearer token.
|
|
13
11
|
|
|
14
12
|
## 1. Install the runtime
|
|
@@ -37,19 +35,10 @@ Pass nothing. The client resolves the same socket path the `crtr` CLI does, and
|
|
|
37
35
|
import Crouter from '@north-light/sdk';
|
|
38
36
|
|
|
39
37
|
const client = new Crouter();
|
|
40
|
-
|
|
41
|
-
const node = await client.nodes.create({
|
|
42
|
-
prompt: 'List the top-level directories here and say what each one is for.',
|
|
43
|
-
cwd: process.cwd(),
|
|
44
|
-
root: true,
|
|
45
|
-
root_lifecycle: 'terminal',
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const outcome = await client.nodes.waitForOutcome(node.node_id);
|
|
49
|
-
if (outcome.kind === 'result') console.log(outcome.final_report_path);
|
|
38
|
+
const { profiles } = await client.profiles.list();
|
|
50
39
|
```
|
|
51
40
|
|
|
52
|
-
|
|
41
|
+
The SDK covers the app routes (`runs`, `uploads`, `docs`, `memory`, …). To create nodes, run bash, arm crons or answer the human inbox on your own daemon, use `CrtrClient` from `@north-light/api` (see the [[crouter-sdk/README]]).
|
|
53
42
|
|
|
54
43
|
## 4. A browser or a remote application
|
|
55
44
|
|
|
@@ -80,59 +69,23 @@ crtr sys connect --app my-app --scopes crtr:llm,crtr:act,crtr:memory:read:user
|
|
|
80
69
|
|
|
81
70
|
`--scopes` requires `--app` (the app id, without the `app:` prefix) and accepts only `crtr:llm`, `crtr:act`, `crtr:schedule`, `crtr:memory:read:user`, `crtr:memory:read:app`, `crtr:memory:rw:app`, `crtr:files:read:user:.` and `crtr:files:rw:user:.`. This mints a new token for that app whose scope list is a ceiling, appends it to the same secrets store, prints it in place of the owner token, and always hands the daemon over (it reads tokens once, at boot). The ceiling is checked on every request that carries the token:
|
|
82
71
|
|
|
83
|
-
- A scope-gated operation the ceiling lacks answers `403 scope_denied`.
|
|
84
|
-
-
|
|
72
|
+
- A scope-gated operation the ceiling lacks answers `403 scope_denied`. Starting or messaging a run, and creating, reviving, forking, messaging, or yielding a node, needs `crtr:act`, as do `bash`, `files`, and creating a human request or review (there is no separate scope for human requests); arming or running a cron needs `crtr:schedule`; `/v1/llm` needs `crtr:llm`. `client.memory` has no scope of its own: it reads the person's documents filtered by privacy, and a grant holding `crtr:memory:read_private:user` also sees `private` documents, and one holding `crtr:memory:manage:user` sees every level.
|
|
73
|
+
- A run started with `scopes` outside the ceiling answers `403 scope_denied`; `details.scopes` lists the offending scopes. Omit `scopes` and the run gets the ceiling.
|
|
85
74
|
- Owner-only operations — daemon restart, the attach viewer, broker internals, canvas prune, profile pause/resume/delete, model credential install — answer `403 owner_only` to any scoped token.
|
|
86
75
|
|
|
87
76
|
What a scope does **not** do on a developer's machine: there is no OS sandbox. Scopes gate the daemon and the CLI; a run's own bash tool is ungated, and the daemon identifies a calling node by a field the caller declares, so a scope check bounds a well-behaved agent, not a hostile one. A scope the daemon does not check at any route is recorded on the run but not enforced; `sys connect` mints only the scopes listed above. There is no list or revoke verb yet; to retire a scoped token, remove it from the 0600 user secrets store and restart the daemon.
|
|
88
77
|
|
|
89
|
-
###
|
|
78
|
+
### Connect with the saved values
|
|
90
79
|
|
|
91
|
-
Construct the client from the
|
|
80
|
+
Construct the client from the base URL and token the user pasted from `crtr sys connect`:
|
|
92
81
|
|
|
93
82
|
```ts
|
|
94
83
|
import Crouter from '@north-light/sdk';
|
|
95
84
|
|
|
96
|
-
const
|
|
97
|
-
const client = new Crouter(saved ?? {});
|
|
98
|
-
const status = await client.auth.status({ profile: 'my-app', cwd: '/path/to/repo' });
|
|
99
|
-
|
|
100
|
-
if (status.next_step !== null) {
|
|
101
|
-
showSetupPanel({ step: status.next_step, instructions: status.instructions! });
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const run = await client.nodes.createAndWait({
|
|
106
|
-
prompt: 'What changed in this repo today?',
|
|
107
|
-
cwd: '/path/to/repo',
|
|
108
|
-
profile: 'my-app',
|
|
109
|
-
root: true,
|
|
110
|
-
});
|
|
85
|
+
const client = new Crouter({ baseURL: saved.baseURL, token: saved.token });
|
|
111
86
|
```
|
|
112
87
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
An isolated auth-status probe returned:
|
|
116
|
-
|
|
117
|
-
```json
|
|
118
|
-
{
|
|
119
|
-
"no_request": {
|
|
120
|
-
"next_step": "connect",
|
|
121
|
-
"requests": 0
|
|
122
|
-
},
|
|
123
|
-
"missing": {
|
|
124
|
-
"provider": "anthropic",
|
|
125
|
-
"credential": "missing",
|
|
126
|
-
"next_step": "login",
|
|
127
|
-
"instructions": "Run `crtr sys connect --cwd /private/tmp/crouter-sdk-auth-proof.P3fSWg/empty --model anthropic/claude-opus-5` to log in to anthropic."
|
|
128
|
-
},
|
|
129
|
-
"ready": {
|
|
130
|
-
"provider": "anthropic",
|
|
131
|
-
"credential": "ready",
|
|
132
|
-
"next_step": null
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
```
|
|
88
|
+
A rejected token raises `AuthenticationError` and an unreachable listener raises `APIConnectionError`; in both cases ask the user to run `crtr sys connect` again and paste what it prints.
|
|
136
89
|
|
|
137
90
|
The root entry of the SDK is browser-safe: it imports nothing from `node:*`. The unix-socket code is reached only through a dynamic import taken when `socketPath` is set, so a browser bundle never resolves it.
|
|
138
91
|
|
|
@@ -150,29 +103,7 @@ Tell your users what the prompt is for. A prompt that appears with no explanatio
|
|
|
150
103
|
|
|
151
104
|
## 5. A typed result
|
|
152
105
|
|
|
153
|
-
`parse()`
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
import { z } from 'zod';
|
|
157
|
-
|
|
158
|
-
const run = await client.nodes.parse({
|
|
159
|
-
prompt: 'Read package.json here and report its name and version.',
|
|
160
|
-
cwd: '/path/to/repo',
|
|
161
|
-
output_schema: z.object({ name: z.string(), version: z.string() }),
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
if (run.kind === 'result') {
|
|
165
|
-
console.log(run.output_parsed.name, run.output_parsed.version);
|
|
166
|
-
} else if (run.reason === 'declined') {
|
|
167
|
-
console.warn('the agent refused the schema:', run.declined?.reason);
|
|
168
|
-
} else {
|
|
169
|
-
console.error('the run failed:', run.reason, run.detail);
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
`output_parsed` is non-null on a result. A Zod schema supplies its inferred output type; a Standard Schema supplies `~standard.types.output`. A JSON-Schema literal or any other `{ toJSONSchema() }` object is accepted but makes `output_parsed` `unknown`.
|
|
174
|
-
|
|
175
|
-
An outcome is returned, never thrown — including a decline and a failure. Only transport faults, daemon errors, and your own abort throw. See [[crouter-sdk/errors]].
|
|
106
|
+
`client.runs.parse()` starts a run, waits for it to end, and types its structured result against the schema you gave it. See [Typed results](https://sdk.docs.northlight.ai/docs/guides/typed-results) on the SDK docs site.
|
|
176
107
|
|
|
177
108
|
## Build an app for other people
|
|
178
109
|
|
|
@@ -180,9 +111,6 @@ Registering an app, its key pair, the env file and going live are covered for ap
|
|
|
180
111
|
|
|
181
112
|
## Where to go next
|
|
182
113
|
|
|
183
|
-
- A complete local page that demonstrates streaming, structured output, and a plugin: localhost SDK demo (`examples/localhost-demo` in the crouter repository)
|
|
184
114
|
- Every constructor option and environment-variable fallback: [[crouter-sdk/client]]
|
|
185
|
-
-
|
|
186
|
-
- The full create-parameter table and the outcome union: [[crouter-sdk/nodes]]
|
|
187
|
-
- Watching a run as it works: [[crouter-sdk/streaming]]
|
|
115
|
+
- Every namespace and its routes: [[crouter-sdk/resources]]
|
|
188
116
|
- Running the daemon in a container instead: [[crouter-sdk/docker]]
|