@north-light/cli 0.3.652 → 0.3.654
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/dist/build-root.js +1 -1
- package/dist/builtin-memory/crouter-sdk/client.md +1 -1
- package/dist/builtin-memory/internal/INDEX.md +2 -2
- package/dist/builtin-memory/internal/memory-loading.md +1 -1
- package/dist/builtin-memory/internal/nodes-and-canvas.md +13 -2
- package/dist/builtin-memory/internal/storage-tiers.md +43 -23
- package/dist/builtin-memory/northlight-apps/concepts/connections.md +2 -2
- package/dist/builtin-memory/northlight-apps/errors.md +1 -1
- package/dist/builtin-memory/northlight-apps/how-it-fits.md +2 -2
- package/dist/clients/attach/viewer.js +502 -502
- package/dist/core/canvas/managed-worktree-sweep-candidates.d.ts +2 -1
- package/dist/core/canvas/managed-worktree-sweep-candidates.js +1 -1
- package/dist/core/canvas/paths.d.ts +7 -9
- package/dist/core/canvas/schema-pg/017-machine-worktree-ops.sql +7 -0
- package/dist/core/canvas/schema-version.d.ts +1 -1
- package/dist/core/canvas/schema-version.js +1 -1
- package/dist/core/command-plugins/compose.d.ts +5 -1
- package/dist/core/command-plugins/compose.js +1 -1
- package/dist/core/runtime/runner/machine/call.d.ts +2 -1
- package/dist/core/runtime/runner/machine/call.js +2 -2
- package/dist/core/runtime/runner/machine/executor.d.ts +1 -1
- package/dist/core/runtime/runner/machine/ops.d.ts +59 -1
- package/dist/core/runtime/runner/machine/ops.js +1 -1
- package/dist/core/runtime/spawn.js +2 -2
- package/dist/core/worktree-close.d.ts +27 -0
- package/dist/core/worktree-close.js +6 -6
- package/dist/core/worktree-machine.d.ts +27 -0
- package/dist/core/worktree-machine.js +1 -0
- package/dist/core/worktree-mutation-async.d.ts +31 -0
- package/dist/core/worktree-mutation-async.js +7 -7
- package/dist/daemon/api/handlers/human-requests.js +1 -1
- package/dist/daemon/api/handlers/nodes.js +1 -1
- package/dist/daemon/api/handlers/reports.js +5 -5
- package/dist/daemon/api/handlers/worktree.js +1 -1
- package/dist/daemon/machine-daemon.js +1 -1
- package/docs/apps/concepts/connections.md +2 -2
- package/docs/apps/errors.md +1 -1
- package/docs/apps/how-it-fits.md +2 -2
- package/docs/cli/join-northlight.md +3 -2
- package/docs/sdk/client.md +1 -1
- package/package.json +2 -2
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +13 -13
package/dist/build-root.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var J=Object.defineProperty;var n=(e,t)=>J(e,"name",{value:t,configurable:!0});import{defineBranch as W,defineRoot as S,GLOBAL_TOKENS as E}from"./core/command.js";import{createCoreHookCatalog as P}from"./core/command-hooks/catalog.js";import{composeCoreHooks as N}from"./core/command-hooks/compose.js";import{mark as h}from"./core/timing.js";import{ApiError as $}from"./api/errors.js";import{CrtrError as K}from"./core/errors.js";import{envNodeId as X,envScopes as Y,isSandboxedNode as B,providerProjectionOverBrokerRelay as Q,scopeAllowed as V}from"./shared/env.js";const b="crtr: agentic runtime.",C=[{name:"--json",desc:"stdout as the leaf's declared outputs in raw JSON instead of prose \u2014 for scripts (a cron's bash, external tooling) that must branch on canvas state; prose stays the contract for what you read yourself."}],O=Object.assign(Object.create(null),{doc:n(async()=>(await import("./commands/doc.js")).registerDoc(),"doc"),"custom-object":n(async()=>(await import("./commands/custom-object.js")).registerCustomObject(),"custom-object"),profile:n(async()=>(await import("./commands/profile.js")).registerProfile(),"profile"),pkg:n(async()=>(await import("./commands/pkg.js")).registerPkg(),"pkg"),human:n(async()=>(await import("./commands/human.js")).registerHuman(),"human"),sys:n(async()=>(await import("./commands/sys.js")).registerSys(),"sys"),node:n(async()=>(await import("./commands/node.js")).registerNode(),"node"),push:n(async()=>(await import("./commands/push.js")).registerPush(),"push"),cron:n(async()=>(await import("./commands/cron.js")).registerCron(),"cron"),canvas:n(async()=>(await import("./commands/canvas.js")).registerCanvas(),"canvas"),surface:n(async()=>(await import("./commands/surface.js")).registerSurface(),"surface")}),m=Object.freeze(Object.keys(O)),Z={human:["crtr:act"],cron:["crtr:schedule"],doc:["crtr:memory:read:user","crtr:memory:rw:user"]};function L(e){const t=Y();return t===null?e:e.filter(r=>{const o=Z[r.name];return o===void 0||o.some(s=>V(t,s))||r.name==="doc"&&process.env.CRTR_GRANTEE?.startsWith("app:")===!0})}n(L,"allowedSubtrees");const M=new Map;function T(e){let t=M.get(e);return t===void 0&&(t=O[e](),M.set(e,t)),t}n(T,"loadSubtree");function k(e){return Promise.all(m.filter(t=>e.has(t)).map(T))}n(k,"loadCoreSubtreesNamed");function x(){return k(new Set(m))}n(x,"loadCoreSubtrees");function R(e){const t=new Set;for(const r of e){const o=r.split(" ")[0];m.includes(o)&&t.add(o)}return t}n(R,"subtreesNamedBy");let A;function he(){return h("cli.hooks.catalog"),A??=x().then(P),A}n(he,"coreHookCatalog");function _(){let e;return()=>(e??=(async()=>{const{compileHookRegistry:t,declaredCommandHookTargets:r,effectiveHookPlugins:o}=await import("./core/command-hooks/discovery.js"),s=o(),a=B()&&X()!==void 0?await(await import("./core/command-hooks/transport/plan.js")).remoteHookPlan(process.cwd()):[];if(h("cli.hooks.effective_plugins",{count:s.length+a.length}),s.length===0&&a.length===0)return h("cli.hooks.empty_registry"),t(P([]),[]);const u=B()?s.filter(l=>l.scope==="project"):s,i=R([...r(u),...a.map(l=>l.target)]);return h("cli.hooks.catalog",{subtrees:[...i].join(",")}),t(P(await k(i)),u,a)})(),e)}n(_,"hookRegistryLoader");function y(e){const t=new Set,r=n((o,s)=>{if(!(o.kind==="branch"&&o.passthrough!==void 0)&&(t.add(s),o.kind==="branch"))for(const a of o.children)r(a,`${s} ${a.name}`)},"visit");for(const o of e)r(o,o.name);return t}n(y,"commandPathsFor");async function we(){return y(await x())}n(we,"coreCommandPaths");async function ye(e){return y(await k(R(e)))}n(ye,"coreCommandPathsCovering");function ee(e){const t=[],r=n((o,s)=>{o.extensible===!0&&t.push(s);for(const a of o.children)a.kind==="branch"&&r(a,[...s,a.name])},"visit");for(const o of e)r(o,[o.name]);return t}n(ee,"extensibleBranchPaths");const te=Object.freeze(["human","sys tutorial"]);async function I(){return new Set(te)}n(I,"extensibleCoreBranches");async function ve(){return new Set(ee(await x()).map(e=>e.join(" ")))}n(ve,"declaredExtensibleCoreBranches");function ne(e,t){const{listing:r,...o}=e.help;return W({name:e.name,description:e.description,whenToUse:e.whenToUse,tier:e.tier,help:o,rootEntry:e.rootEntry,extensible:e.extensible,plugin:e.plugin,slash:e.slash,passthrough:e.passthrough,children:t})}n(ne,"rebuildBranch");async function H(e,t,r){if(t.size===0)return e;const[{buildExternalCommandSnapshot:o},{composeCoreBranchMounts:s}]=await Promise.all([import("./core/command-plugins/discovery.js"),import("./core/command-plugins/compose.js")]),a=o(new Set(m),void 0,void 0,r,t),u=n((i,l)=>{let f=!1;const g=i.children.map(p=>{if(p.kind!=="branch")return p;const d=u(p,[...l,p.name]);return d!==p&&(f=!0),d}),w=i.extensible===!0?s(a.coreMounts,l):[];return f||w.length>0?ne(i,[...g,...w]):i},"composeBranch");return e.map(i=>u(i,[i.name]))}n(H,"composeCorePluginMounts");async function oe(e,t){const{validateEffectiveCommandPlugins:r}=await import("./core/command-plugins/discovery.js"),s=r(new Set(m),void 0,void 0,void 0,t).flatMap(u=>u.manifest===void 0?[]:[u.manifest]).filter(u=>u.coreMounts.some(i=>i.parent[0]===e));if(s.length===0)return null;const a=R(s.flatMap(u=>[...u.coreMounts.map(i=>i.parent.join(" ")),...Object.keys(u.helpAddenda??{})]));return a.add(e),y(await k(a))}n(oe,"dispatchCommandPaths");function v(e,t){const r=e.slice(2).filter(o=>!E.has(o));return r[0]==="sys"&&r[1]===t}n(v,"isSysInvocation");const re=[["surface"],["sys"],["pkg"],["profile","default"],["canvas","chord"],["canvas","config"],["canvas","use"],["canvas","browse"],["canvas","issue"]],se=[["sys","feedback"],["pkg","plugin"],["pkg","market"]];function D(e,t){return t.every((r,o)=>e[o]===r)}n(D,"startsWithPath");function Se(e){const t=e.slice(2).filter(o=>!E.has(o));if(se.some(o=>D(t,o)))return null;const r=re.find(o=>D(t,o));return r===void 0?null:r.join(" ")}n(Se,"personOnlyInvocation");function be(e){return v(e,"daemon")}n(be,"isDaemonControlInvocation");function Ce(e){const t=e.slice(2).filter(r=>!E.has(r));return t[0]==="pkg"&&(t[1]==="plugin"||t[1]==="market")}n(Ce,"isPkgInstallInvocation");function ke(e){return v(e,"signin")||v(e,"signout")}n(ke,"isSignInInvocation");function xe(e){return v(e,"join")}n(xe,"isJoinInvocation");function Ee(e){return v(e,"migrate")}n(Ee,"isLayoutMigrationInvocation");async function Pe(){const{registerDaemonControlSys:e}=await import("./commands/sys/daemon.js");return S({tagline:b,globals:C,subtrees:[e()]})}n(Pe,"resolveDaemonControlRoot");async function Be(){const[{defineSysBranch:e},{sysMigrateLeaf:t}]=await Promise.all([import("./commands/sys/branch.js"),import("./commands/sys/migrate.js")]);return S({tagline:b,globals:C,subtrees:[e([t])]})}n(Be,"resolveLayoutMigrationRoot");async function Oe(e){return(e!==void 0?await ae(e):null)??ie()}n(Oe,"resolveRoot");async function ae(e){if(O[e]===void 0)return null;const t=await T(e),r=await I(),o=[...r].some(a=>a.split(" ")[0]===e)?await oe(e,r):null,s=L(o===null?[t]:await H([t],r,o));return s.length>0?S({tagline:b,globals:C,subtrees:N(s,_())}):null}n(ae,"resolveCoreRoot");async function ie(){const e=await x(),[{buildExternalCommandSnapshot:t},{composeExternalSubtrees:r,composeSandboxProviderSubtrees:o},{qualifiedTopLevelCommandName:s}]=await Promise.all([import("./core/command-plugins/discovery.js"),import("./core/command-plugins/compose.js"),import("./core/command-manifests/registry.js")]),a=await I(),u=await H(e,a,y(e)),i=t(new Set(m),void 0,void 0,y(e),a);let l=r(i);const f=(await import("./daemon/machine-link/config.js")).readMachineConfig()!==void 0;let g;if(B()||Q()||f){const{cliClient:p}=await import("./commands/api-client.js");h("cli.providers.request");let d=[];try{d=(await p().request("GET","/v1/providers/tools")).providers}catch(c){if(!f||!(c instanceof $||c instanceof K))throw c;g=c}h("cli.providers.fetched",{providers:d.length});const j=o(d,new Set(m)),G=new Set(j.map(c=>c.name)),U=new Map(d.map(c=>[c.provider,new Set(c.groups.flatMap(z=>z.leaves.map(F=>F.tool)))])),q=n(async c=>U.get(c)??new Set,"fromCatalog");l=[...j,...r({...i,contributions:i.contributions.map(c=>G.has(c.node.name)?{...c,node:{...c.node,name:s(c.contributor,c.node.name)}}:c)},g===void 0?q:void 0)]}if(!f){const{previewBranches:p}=await import("./core/northlight/previews.js");l=[...l,...p(process.platform,new Set(l.map(d=>d.name)))]}const w=S({tagline:b,globals:C,subtrees:[...N(L(u),_()),...l]});return g===void 0?w:{...w,providerCatalogFailure:g}}n(ie,"buildRoot");export{te as EXTENSIBLE_CORE_BRANCHES,m as SUBTREE_NAMES,ie as buildRoot,we as coreCommandPaths,ye as coreCommandPathsCovering,he as coreHookCatalog,ve as declaredExtensibleCoreBranches,I as extensibleCoreBranches,be as isDaemonControlInvocation,xe as isJoinInvocation,Ee as isLayoutMigrationInvocation,Ce as isPkgInstallInvocation,ke as isSignInInvocation,Se as personOnlyInvocation,ae as resolveCoreRoot,Pe as resolveDaemonControlRoot,Be as resolveLayoutMigrationRoot,Oe as resolveRoot};
|
|
@@ -26,7 +26,7 @@ An app that signs people in with Northlight uses `OAuth2Client` and `oauth.clien
|
|
|
26
26
|
| Option | Type | Default | Meaning |
|
|
27
27
|
|---|---|---|---|
|
|
28
28
|
| `baseURL` | `string` | `CRTR_BASE_URL`, else unset | `http(s)://host:port` of a daemon TCP listener. |
|
|
29
|
-
| `socketPath` | `string` | `CRTR_SOCKET`, else `${CRTR_HOME}/
|
|
29
|
+
| `socketPath` | `string` | `CRTR_SOCKET`, else `CRTR_API_SOCKET`, else `api.sock` in the runtime root (`${CRTR_HOME:-~/.crouter}/runtime/api.sock` on macOS, `/run/crtr/api.sock` on Linux) | Unix socket. Node only; throws in a browser. |
|
|
30
30
|
| `token` | `string` | `CRTRD_TOKEN` | Sent as `Authorization: Bearer <token>`. The owner token or a scoped token from `crtr sys connect`; a scoped token's ceiling is enforced per request (see [[crouter-sdk/getting-started]]). Ignored by a unix-socket daemon, which authenticates by filesystem permission. |
|
|
31
31
|
| `timeout` | `number` (ms) | `30_000` | Per-request wall clock. Does not apply to a stream. |
|
|
32
32
|
| `maxRetries` | `number` | `2` | Transient-failure retries. Never applied to `POST` or `PATCH` — see [[crouter-sdk/errors]]. |
|
|
@@ -13,7 +13,7 @@ This directory is the runtime's **self- and developer-documentation**: operation
|
|
|
13
13
|
|
|
14
14
|
## The object model, in one page
|
|
15
15
|
|
|
16
|
-
crtr keeps one graph of **objects** in one
|
|
16
|
+
crtr keeps one graph of **objects** in one Postgres database — a cluster crtrd supervises on a Mac, or the shared cloud database behind Northlight's control plane. Documents, nodes, bash jobs, owners (person, app, repo, profile) and custom objects are all objects: each has an id, a name, an owner and a privacy level, and **the same verbs work on all of them** — `crtr canvas read`, `list`, `search`, `watch`, `unwatch`, `edges`. What differs is the object's *type*, which decides what events it can emit and how it renders. There are no memory stores, tiers or scopes: a thing an agent writes is a document, and who sees it is decided by its owner, its privacy and its delivery rules.
|
|
17
17
|
|
|
18
18
|
- **Documents** are the one object type for written knowledge: what used to be called memories, reports and context documents. Write them with `crtr doc write|edit|move|history|delete|lint`; read them with `crtr canvas read`. Each has a required one-line **preview** ("When …, read this because …"), a body, optional summary, privacy (`public` default, or `private`: readable by you and the people you share it with, and by an app only with a private-read scope; share with `crtr canvas share`), delivery **rules**, and revisions — an edit is made from the revision you last read and is refused if the document moved on. A document's `kind` is `knowledge` (consulted) or `preference` (directs behavior); `report` documents are created only by `crtr push`. `crtr doc write -h` is the writing guide.
|
|
19
19
|
- **Owners** are objects too: a node, the person (`user`), a profile, an app, or a repo. The owner decides who may read and change a document, where it syncs, and what deletes it. The default owner is the writing node (the document goes away with the node unless a kept document links to it); `--owner user|profile|app|repo` makes it outlive the node. A repo owns only public documents and syncs them to collaborators over the git ref `refs/crtr/docs`. An installed plugin is an app (`app:<plugin>`); crtr's own documents belong to the app `crtr`. Which owner to pick: [[internal/agent-shaping]].
|
|
@@ -27,7 +27,7 @@ crtr keeps one graph of **objects** in one SQLite database (`canvas.db`). Docume
|
|
|
27
27
|
## Contents
|
|
28
28
|
|
|
29
29
|
- **nodes-and-canvas** — the agent-runtime model: nodes as objects on the canvas graph, spawn/delegate, the push/feed spine and watches, lifecycle (mode + lifecycle axes), jobs and custom objects, and revive (manual + daemon auto-revive).
|
|
30
|
-
- **storage-tiers** — where state lives
|
|
30
|
+
- **storage-tiers** — where state lives: the Postgres database (objects, document bodies, settings, conversations), the blob store, the layout root's `runtime/`, `apps/` and `user/` directories, the project scope `.crouter/`, and what git carries for repo documents.
|
|
31
31
|
- **memory-loading** — how documents load into a node: the delivery events, `deliver` levels, `if` conditions, listings, boot-render ordering and the reader's view — read when diagnosing why a document did or didn't load.
|
|
32
32
|
- **agent-shaping** — the when-to-use-which layer over the four dials that shape a node: kinds (the builtin roster, sub-kinds, custom personas), modes (base vs orchestrator), profiles, and document owners (node/profile/repo/user).
|
|
33
33
|
- **plugins** — authoring a crtr plugin: the plugin.json manifest, directory layout, the package-file format of its `memory/` documents, scopes, install mechanics, versioning, command-capable plugins and bare binaries on every node's PATH.
|
|
@@ -45,7 +45,7 @@ A rule's `if` is the eligibility predicate over the receiving node — kind, mod
|
|
|
45
45
|
|
|
46
46
|
A full-body delivery is a read: `crtr canvas read <name>` and every content delivery expose, once per loaded context, the listing of each prefix of the document's name — one preview per document, one bare name per prefix that has names under it — then fire matching `document-read` rules. A document named `x` and documents named `x/…` coexist; reading `x` prints its body alone to stdout and delivers one listing of the names under it and the documents its body links to after command output in the node's tool result — previews only, not reads, never recursing. Content-delivered companions are read in turn until nothing new is delivered. `unlisted: true` suppresses a document from every listing. An owner's top level is never auto-listed — `crtr canvas list --type document` is the deliberate browse. Every content delivery, like every read, records a watch, so later edits reach the reader as pushes.
|
|
47
47
|
|
|
48
|
-
Every delivery registers the document or listing and its level in the loaded context's exposure ledger, kept in canvas.
|
|
48
|
+
Every delivery registers the document or listing and its level in the loaded context's exposure ledger, kept in the canvas database. System and transcript ranks max-fold, so a higher level pierces a lower one while a content delivery silences later lower-level deliveries and duplicate read attachments. A strict resume preserves that ledger and the byte-stable preference snapshot; yield or another new-session boundary clears it and replaces them with exactly the new system and first-message snapshots.
|
|
49
49
|
|
|
50
50
|
## The reader's view
|
|
51
51
|
|
|
@@ -13,7 +13,18 @@ Every agent is a **node**, one kind of **object** on the **canvas** — the sing
|
|
|
13
13
|
|
|
14
14
|
The node-to-node **spine** is the subscription edge: a subscriber receives its publisher's pushes (`node subscription add|remove`, stored as a watch the subscriber holds on the publisher), and that edge decides who-wakes-whom. It sits beside the general watch mechanism below, which lets any object's events reach any node.
|
|
15
15
|
|
|
16
|
-
The **daemon** (`crtrd`) is the sole owner of canvas persistent state: it is the only process that opens
|
|
16
|
+
The **daemon** (`crtrd`) is the sole owner of canvas persistent state: it is the only process that opens the canvas database, launches brokers, and writes runtime/model-auth, all behind the `/v1` HTTP+WS API (dockerd model). Every `crtr` command and viewer is a pure client of that API — they never open the store. A local interactive viewer still streams a node's broker socket (`view.sock`) directly, because that is broker IPC, not canvas state.
|
|
17
|
+
|
|
18
|
+
crtrd runs in one of four roles:
|
|
19
|
+
|
|
20
|
+
| Role | Where | What it does |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| none (default) | a Mac that has not been imported | everything in one process: API on a unix socket, reconcilers, and node processes on this machine; supervises its own Postgres |
|
|
23
|
+
| `--role api` | the cloud control plane | serves `/v1` for many people from the shared database; runs no reconcilers |
|
|
24
|
+
| `--role reconcile` | the cloud control plane | runs the reconcilers and boot sweeps; serves only a health check |
|
|
25
|
+
| `--role machine` | a Mac imported into an account (`runtime/machine.json` present) | opens no database and serves no API; holds an outbound link to the cloud and runs the processes of nodes whose environment is this machine |
|
|
26
|
+
|
|
27
|
+
A node runs in an **environment**. A `blaxel` environment runs its broker, shell and files in a Blaxel sandbox the cloud roles start and wake. A `machine` environment runs them on a Mac: directly under that Mac's own crtrd when it is not imported, or through the machine link when the cloud roles own it. `crtr sys import` moves a Mac or a hosted runtime into an account; `crtr sys machine rotate` replaces an imported Mac's machine credential.
|
|
17
28
|
|
|
18
29
|
## Spawn & delegate
|
|
19
30
|
|
|
@@ -61,4 +72,4 @@ Tear-down: `node lifecycle close` cascade-cancels a node + its exclusive subtree
|
|
|
61
72
|
|
|
62
73
|
Use `node lifecycle revive <id>` to reopen one dormant or terminal node. It resumes an existing saved conversation by default; `--fresh` starts a new cycle on its existing session file, or a truly fresh session if no file exists. A finalized node requires `--reopen` before it can take a new mandate. Mass-reconnecting every eligible disconnected node after a reboot or outage is `canvas revive --all` instead. `reviveNode()` is the **only** sanctioned launcher of a node's broker engine — it builds the pi invocation, sets `CRTR_NODE_ID` + canvas extensions, runs `transition('revive')`, and starts the headless broker host, keeping the db row and broker process in lockstep. Never spawn `pi --session` raw, and never open a node by spawning pi directly — UIs go through `surface node focus` / `node lifecycle revive`.
|
|
63
74
|
|
|
64
|
-
The daemon (`crtrd`, managed via `sys daemon start/stop/status`) supervises live broker exits. It releases an unattended broker after 15 minutes: residents with no live obligation become `done` and pruning-eligible, while terminal nodes and residents awaiting a live child, controller, human, deadline, or structured output become `idle` and remain wakeable. It applies a bounded respawn policy to interrupted nonterminal nodes: an interrupted saved turn resumes in the same conversation with a continuation, whether the broker persisted a clean abort or died abruptly. A pending refresh or pending cycle still starts a fresh cycle from the saved session. Repeated short-lived exits and boot failures terminalize the node as `dead`; no automatic recovery occurs after terminalization, so use an explicit lifecycle revive or an inbox wake. It does not host agents or open viewers. When activating source changes, build, run `npm run install-runtime`, then restart the daemon because new daemon/brokers select the atomically switched, immutable generation while live brokers retain their own. Restarting is safe: it never signals running nodes.
|
|
75
|
+
The daemon (`crtrd`, managed on a Mac via `sys daemon start/stop/status`) supervises live broker exits. It releases an unattended broker after 15 minutes: residents with no live obligation become `done` and pruning-eligible, while terminal nodes and residents awaiting a live child, controller, human, deadline, or structured output become `idle` and remain wakeable. It applies a bounded respawn policy to interrupted nonterminal nodes: an interrupted saved turn resumes in the same conversation with a continuation, whether the broker persisted a clean abort or died abruptly. A pending refresh or pending cycle still starts a fresh cycle from the saved session. Repeated short-lived exits and boot failures terminalize the node as `dead`; no automatic recovery occurs after terminalization, so use an explicit lifecycle revive or an inbox wake. It does not host agents or open viewers. When activating source changes, build, run `npm run install-runtime`, then restart the daemon because new daemon/brokers select the atomically switched, immutable generation while live brokers retain their own. Restarting is safe: it never signals running nodes. The cloud roles are never restarted this way; their orchestrator replaces them on release.
|
|
@@ -2,50 +2,70 @@
|
|
|
2
2
|
name: internal/storage-tiers
|
|
3
3
|
kind: knowledge
|
|
4
4
|
description: Where crouter state belongs
|
|
5
|
-
when-and-why-to-read: When locating crtr state on disk or deciding where a new file belongs, this reference should be read so files are found or placed in the right root — and so you do not look for documents on disk, since they are
|
|
6
|
-
short-form: Where crtr state lives
|
|
5
|
+
when-and-why-to-read: When locating crtr state on disk or deciding where a new file belongs, this reference should be read so files are found or placed in the right root — and so you do not look for documents, settings or conversations on disk, since they are rows in the canvas database, not files.
|
|
6
|
+
short-form: Where crtr state lives — the Postgres canvas database (every object, document body, setting, conversation index), the blob store, the layout root's runtime/user/apps directories, the project scope `.crouter/`, and the git ref that carries repo documents.
|
|
7
7
|
surfaces:
|
|
8
8
|
- on: boot
|
|
9
9
|
at: name
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
# Where everything lives
|
|
12
|
+
# Where everything lives
|
|
13
13
|
|
|
14
|
-
Everything on the canvas — documents, nodes, jobs, owners, custom objects — is an **object** in one
|
|
14
|
+
Everything on the canvas — documents, nodes, jobs, owners, custom objects — is an **object** in one **Postgres database**; see [[internal]] for the object model. Large payloads go to a **blob store**. Files on disk are what is a file by nature: a node's context directory, its runtime files, diagnostics, and project configuration. Precise resolver behavior lives in `src/core/layout.ts`, `src/core/canvas/paths.ts` and `src/core/scope.ts`.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
## 1. Where the database and blobs are
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
- **On a Mac**, crtrd supervises its own Postgres 18 cluster under `<runtime>/pg/`; `CRTR_DATABASE_URL` points it at any other Postgres instead. Blobs are files under `<runtime>/blobs/`.
|
|
19
|
+
- **In the cloud**, the `api` and `reconcile` crtrd roles share one RDS Postgres with the directory (crouter's tables are in schema `crtr`), and blobs are in R2 (`CRTR_R2_BUCKET` plus the other `CRTR_R2_*` variables). The API processes share no disk, so anything they must both see is a row or a blob.
|
|
20
|
+
- **An imported Mac** runs crtrd as the `machine` role: it opens no database and serves no API. It holds an outbound link to the cloud and runs that account's processes for nodes whose environment is this machine.
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
The database holds every object and its edges, watches, events, delivery rules, revisions, the exposure ledger, the inbox and delivery queue, human-request state, the person's settings (profiles, profile defaults, user- and profile-scope `config.json` content, plugin and marketplace installs) and the conversation index. A document's text is a row in the `bodies` table keyed by the revision's `body_hash`; a package document (crtr's own or a plugin's) is the same, and its `source_path` only records where it shipped from and marks it read-only. Who may read a document comes from its privacy, the app's schema and its relation facts (`crtr doc write --owner -h`), not from a directory. Do not look for documents on disk and do not write one as a file: use `crtr doc write`, and read with `crtr canvas read`.
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
Blob keys: `conversations/<node>/<conversation>/<seq>.jsonl` (immutable conversation parts; the live tail is rows), `events/<node>/…` (run-event chunks), `jobs/<node>/<job>/output`, `attachments/<node>/<sha256>`, `requests/<id>/…` (human-request pages on a cloud role), and release artifacts.
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
## 2. The layout root
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
The layout root is `~/.crouter` on macOS and `/` on Linux (a container or sandbox); `CRTR_HOME` overrides it. It holds three directories.
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
### `runtime/` — the canvas home
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
`<layout>/runtime` is the runtime root, returned by `crtrHome()`. It is crtrd's own and is never mounted into an app sandbox.
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
- `pg/` (supervised Postgres), `blobs/`, `secrets/` (sealed env vars; the machine credential on an imported Mac), `machine.json` (an imported Mac's link: API URL, environment id, import run id, directory URL, account).
|
|
35
|
+
- `nodes/<node_id>/job/` — `log.jsonl` (the broker's event stream), `broker.log` (raw stdout/stderr), `telemetry.json` and `fault` (current state, not history). `nodes/<node_id>/messages/` holds inbox bodies too long to inline, written for the broker to read.
|
|
36
|
+
- The node's run folder — `nodes/<node_id>/run/` on macOS, `/run/crtr/nodes/<node_id>/` on Linux — holds `view.sock`, `cli.sock`, `broker-launch.json`, `scopes.json`, `situational-context.md` and per-run `job/` state. It is rebuilt each launch.
|
|
37
|
+
- `requests/<id>/` — a human request's page revisions (`revisions/<rev>/page.json`, `page.tsx`, `page.js`) and `action.json`, the action binding frozen at creation; `reviews/<id>/` — document review results. A cloud role keeps the same files under the blob prefix `requests/<id>`. A request is not owned by a node: settlement, outcome and the delivery schedule are database rows.
|
|
38
|
+
- `plugins/` and `marketplaces/` — user-scope plugin and marketplace checkouts. `repo-sync/<repo>/` — the bare git mirror of a repo object's `refs/crtr/docs`. `bin-shims/<address>/` — symlink shims for bare-binary contributions, prepended to every broker child's PATH and re-derived on demand.
|
|
39
|
+
- `scope/` — the user scope root (`userScopeRoot()`): local files with no database home, such as `feedback/`, `support/<reference>/` (prepared support bundles, zero-egress until submitted), `prompt-reviews/`, viewer pins and completion history. A `config.json` there is legacy: user-scope settings are database rows, read and written through `crtr sys config` and `crtr profile`.
|
|
40
|
+
- `crtrd.log` (the daemon's event stream), `crtrd.err` (raw residue), `generations/` and `selected` (sealed install generations — install machinery, not storage).
|
|
41
|
+
- The API socket `api.sock` is here on macOS and in `/run/crtr` on Linux.
|
|
33
42
|
|
|
34
|
-
|
|
43
|
+
Leftovers from older layouts may remain and are never read in normal operation: `canvas.db.imported*` (the one-time SQLite import into Postgres), `bodies/` (body files copied once into the `bodies` table), and per-node `meta.json`, `inbox.jsonl` and `transcript.jsonl`.
|
|
44
|
+
|
|
45
|
+
### `apps/<app>/` — what an app's processes may touch
|
|
46
|
+
|
|
47
|
+
Each app (the terminal, a plugin, a Northlight app) gets `apps/<app>/{profiles,conversations,nodes,files,home,cache}`. A node's agent folder is `apps/<app>/nodes/<node_id>/` with `context/` — the node's `$CRTR_CONTEXT_DIR`, for scripts, data, logs and page modules; files only, never the way to share writing — plus `reports/`, `attachments/`, `worktree/`, and `home/` for a node of an isolated run. `conversations/<node_id>/` is the path a broker reads its conversation at; the durable copy is rows and blobs.
|
|
48
|
+
|
|
49
|
+
### `user/` — the person's files
|
|
35
50
|
|
|
36
|
-
|
|
51
|
+
`user/files` is the person's files root on Linux. On a Mac it is the parent of `~/.crouter` (the person's home) unless `paths.user_files` says otherwise.
|
|
37
52
|
|
|
38
|
-
|
|
53
|
+
## 3. Project scope
|
|
39
54
|
|
|
40
|
-
|
|
41
|
-
- `<crtrHome>/crtrd.log` is the root daemon's canonical event stream. It contains daemon-owned events, including node-scoped data carried as `node_id` fields.
|
|
55
|
+
`<project>/.crouter/` is the project scope, found by walking up from the cwd. Its `config.json` and `state.json` stay files, with `operations.db` beside them; every crtr process auto-creates them in a project that has none. A project's plugins and marketplaces live in its `plugins/` and `marketplaces/`. The scope root does not decide document ownership.
|
|
42
56
|
|
|
43
|
-
|
|
57
|
+
**Legacy memory directories.** Older runtimes kept documents as markdown in `.crouter/memory/` folders under a repo, profile or user root. `crtr sys migrate` imported those once into documents; the files are left on disk and never read again.
|
|
58
|
+
|
|
59
|
+
## 4. What git carries
|
|
60
|
+
|
|
61
|
+
A repo-owned document travels on the repo's git ref `refs/crtr/docs` (one JSON file per document), which is how collaborators receive it; the checkout's working tree never holds it. crtr's own documents (`src/builtin-memory/` in the crouter repo, owner app `crtr`) and a plugin's `memory/` folder stay markdown files in their package, and the daemon reconciles them into public, read-only document objects; see [[internal/plugins]].
|
|
62
|
+
|
|
63
|
+
A specification, plan or report is a document its node owns, named `<node-id>/<name>` and shared by `[[pointer]]`. It is deleted with that node unless a kept document links to it or it is given another owner (`crtr doc move --owner`).
|
|
44
64
|
|
|
45
|
-
|
|
65
|
+
## Event streams and raw residue
|
|
46
66
|
|
|
47
|
-
|
|
67
|
+
Canonical diagnostics are bounded NDJSON `EventEnvelope` streams. The writer keeps one active file plus `.1` and `.2` generations at 5 MiB each, and each record is at most 64 KiB including its newline. Each long-lived process binds one fixed source and writes only that file: a broker writes `nodes/<node_id>/job/log.jsonl`, and crtrd writes `<runtime>/crtrd.log` (node-scoped daemon events carry a `node_id` field there). `crtrd.err` and `job/broker.log` are raw process output — last-resort evidence, never parsed as events.
|
|
48
68
|
|
|
49
|
-
|
|
69
|
+
## Where a new file belongs
|
|
50
70
|
|
|
51
|
-
|
|
71
|
+
Persistent state another process or role must see → a database row, or a blob when it is large. Configuration that belongs to a project → `<project>/.crouter/`. Per-node runtime files, diagnostics and crtrd's own local caches → `runtime/`. Anything an app's agent writes → its app space, usually the node's `context/`.
|
|
@@ -102,7 +102,7 @@ It refreshes every connection last saved before the cutoff, through the store's
|
|
|
102
102
|
|
|
103
103
|
## Acting without a sign-in
|
|
104
104
|
|
|
105
|
-
A server that acts for a person on their
|
|
105
|
+
A server that acts for a person on their Northlight runtime, for example to publish events to the objects they watch, uses `oauth.appClient(userId)` instead of `oauth.client(userId)`. It stores no connection and refreshes nothing: the SDK signs a `client_credentials` request with your app's key for `sub=user:<id>`, and the directory answers a token and the person's `runtimeUrl`.
|
|
106
106
|
|
|
107
107
|
```ts
|
|
108
108
|
const runtime = await oauth.appClient('user:o1');
|
|
@@ -113,7 +113,7 @@ It needs the app registered with the `app_token_for_user` operation, and an acti
|
|
|
113
113
|
|
|
114
114
|
| Error | Code | Means |
|
|
115
115
|
|---|---|---|
|
|
116
|
-
| `NoHostedRuntimeError` | `no_hosted_runtime` (409) | The person has no
|
|
116
|
+
| `NoHostedRuntimeError` | `no_hosted_runtime` (409) | The person's account has no runtime to act on. Not retryable. |
|
|
117
117
|
| `NotGrantedError` | `not_granted` (409) | The person has no active grant for your app, so they have not signed in to it. Not retryable. |
|
|
118
118
|
| any error with `retryable: true` | `runtime_provisioning` (503), a directory 5xx or a 429 | Try again later. |
|
|
119
119
|
|
|
@@ -22,7 +22,7 @@ Codes the SDK raises itself are listed in `sdkErrorCodes`, and `CrouterError.cod
|
|
|
22
22
|
| `oauth_nonce_missing` | `exchangeIdentity` was called without the `nonce` from `authorizeUrl`. | Save the nonce in the visitor's session and pass it back. |
|
|
23
23
|
| `oauth_state_mismatch` | The callback's `state` was missing or differed from the saved one. | Refuse the callback. |
|
|
24
24
|
| `not_connected` | `oauth.client(userId)` or a refresh found no stored connection for that person. | Show "sign in again". |
|
|
25
|
-
| `no_hosted_runtime` (409, `NoHostedRuntimeError`) | `oauth.appClient(userId)`: the person has no
|
|
25
|
+
| `no_hosted_runtime` (409, `NoHostedRuntimeError`) | `oauth.appClient(userId)`: the person's account has no runtime to act on. Not retryable. | Skip them. |
|
|
26
26
|
| `not_granted` (409, `NotGrantedError`) | `oauth.appClient(userId)`: the person has no active grant for your app. Not retryable. | Send them through sign-in ([[northlight-apps/concepts/connections]]). |
|
|
27
27
|
| `refusal_handler_reentry` | An `onRefusal` handler called `oauth.client` (or a refresh) for the person whose connection it is handling. | Don't call the runtime for `refusal.userId` inside the handler. |
|
|
28
28
|
| `unauthorized` (401, `AuthenticationError`) | The directory refused your app's client assertion (`invalid_client`) on `exchangeCode`, a refresh or `revoke`, including a refresh inside a client from `oauth.client(userId)`. The message names the key id (`kid`) you signed with and asks whether that key's public JWK is registered. `details` is `{oauth_error: 'invalid_client', kid}`, or `key_thumbprint` instead of `kid` for a key with no `kid`. | Check that the key's public JWK is on the app's **Sign-in** tab ([[northlight-apps/guides/manage-your-app]]). |
|
|
@@ -14,9 +14,9 @@ Your app runs on a server you choose. Northlight hosts two other things: the dir
|
|
|
14
14
|
|---|---|---|
|
|
15
15
|
| **Your server** | Anywhere you choose. Your laptop while you develop. | Your pages and logic. It holds the app's private signing key and a stored connection for each person. |
|
|
16
16
|
| **The directory** | `https://account.northlight.ai`, hosted by Northlight | Accounts, app registration (the console at `/console`), consent, tokens and the marketplace. |
|
|
17
|
-
| **The person's runtime** |
|
|
17
|
+
| **The person's runtime** | Northlight's cloud. One shared control plane serves everyone; each of the person's agents runs in its own sandbox. | Their agents, runs, files, documents and providers (sms, search and others), using their own AI subscription. |
|
|
18
18
|
|
|
19
|
-
"Build on Northlight" therefore means three things. Your app's agent work runs on the person's Northlight
|
|
19
|
+
"Build on Northlight" therefore means three things. Your app's agent work runs on the person's Northlight runtime, in Northlight's cloud. People sign in to your app with their Northlight account. And your app can be listed in the Northlight marketplace.
|
|
20
20
|
|
|
21
21
|
```mermaid
|
|
22
22
|
sequenceDiagram
|