@north-light/cli 0.3.674 → 0.3.676

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/clients/attach/session/connection.d.ts +2 -1
  2. package/dist/clients/attach/session/connection.js +1 -1
  3. package/dist/clients/attach/viewer.d.ts +11 -1
  4. package/dist/clients/attach/viewer.js +524 -524
  5. package/dist/commands/person-settings.d.ts +5 -0
  6. package/dist/commands/person-settings.js +1 -1
  7. package/dist/core/graph/reader.d.ts +2 -1
  8. package/dist/core/graph/reader.js +3 -3
  9. package/dist/core/graph/repo-sync/repos.d.ts +24 -3
  10. package/dist/core/graph/repo-sync/repos.js +4 -4
  11. package/dist/core/profiles/select.d.ts +3 -1
  12. package/dist/core/profiles/select.js +25 -25
  13. package/dist/core/runtime/bearings.d.ts +3 -3
  14. package/dist/core/runtime/bearings.js +6 -6
  15. package/dist/core/runtime/boot-root.d.ts +3 -3
  16. package/dist/core/runtime/boot-root.js +6 -4
  17. package/dist/core/runtime/deliver-live.js +1 -1
  18. package/dist/core/runtime/front-door.js +1 -1
  19. package/dist/core/runtime/runner/blaxel/image-build.js +6 -6
  20. package/dist/core/runtime/starting-screen.d.ts +12 -0
  21. package/dist/core/runtime/starting-screen.js +9 -0
  22. package/dist/core/substrate/delivery/deliver.d.ts +1 -1
  23. package/dist/core/substrate/delivery/deliver.js +3 -3
  24. package/dist/core/substrate/subject.d.ts +3 -1
  25. package/dist/core/substrate/subject.js +1 -1
  26. package/dist/daemon/api/handlers/broker-ops.js +1 -1
  27. package/dist/daemon/api/handlers/delivery.js +1 -1
  28. package/package.json +3 -3
  29. package/packages/crouter-api/dist/clients/attach/session/connection.js +3 -2
  30. package/packages/crouter-api/dist/clients/attach/viewer.js +16 -7
  31. package/packages/crouter-api/dist/commands/person-settings.js +10 -3
  32. package/packages/crouter-api/dist/core/graph/reader.js +9 -4
  33. package/packages/crouter-api/dist/core/graph/repo-sync/repos.js +56 -13
  34. package/packages/crouter-api/dist/core/profiles/select.js +17 -7
  35. package/packages/crouter-api/dist/core/runtime/bearings.js +11 -12
  36. package/packages/crouter-api/dist/core/runtime/deliver-live.js +1 -1
  37. package/packages/crouter-api/dist/core/runtime/runner/blaxel/image-build.js +13 -5
  38. package/packages/crouter-api/dist/core/substrate/delivery/deliver.js +3 -3
  39. package/packages/crouter-api/dist/core/substrate/subject.js +4 -4
  40. package/packages/crouter-api/dist/daemon/api/handlers/broker-ops.js +6 -4
  41. package/packages/crouter-api/package.json +1 -1
  42. package/packages/crouter-identity/package.json +1 -1
  43. package/packages/crouter-plugin/package.json +3 -3
  44. package/runtime.lock.json +14 -14
@@ -29,8 +29,8 @@ export { buildProjectContextBlock, contextDirNote, orchestratorContextNote };
29
29
  * `assembleNodeSubject`'s profile resolution). This absolute-path disclosure
30
30
  * is intentional (spec-approved): the agent must know its full purview, not a
31
31
  * redacted count. */
32
- export async function profileNote(nodeId) {
33
- const meta = await getNode(nodeId);
32
+ export async function profileNote(nodeId, known) {
33
+ const meta = known !== undefined ? known : await getNode(nodeId);
34
34
  if (meta === null)
35
35
  return '';
36
36
  return profileNoteShared(meta.cwd, meta.profile_id);
@@ -41,10 +41,10 @@ export async function profileNote(nodeId) {
41
41
  // Not the full subtree — just the load-bearing spine up and one level down.
42
42
  /** Ancestry trunk from the root DOWN to (but excluding) `nodeId`, climbing the
43
43
  * spine `parent` edge. Cycle-guarded. Root first. */
44
- async function ancestorTrunk(nodeId) {
44
+ async function ancestorTrunk(nodeId, own) {
45
45
  const trunk = [];
46
46
  const seen = new Set([nodeId]);
47
- let cur = (await getNode(nodeId))?.parent ?? null;
47
+ let cur = own.parent ?? null;
48
48
  while (cur !== null && cur !== '' && !seen.has(cur)) {
49
49
  seen.add(cur);
50
50
  const m = await getNode(cur);
@@ -67,18 +67,17 @@ async function childNodes(nodeId) {
67
67
  /** The graph mini-map: the ancestry trunk (root first), then this node marked
68
68
  * `● you`, then its immediate children. Returns '' for a lone root with no
69
69
  * children (nothing to map). Exported for testing. */
70
- export async function buildGraphMap(nodeId) {
71
- const meta = await getNode(nodeId);
70
+ export async function buildGraphMap(nodeId, known) {
71
+ const meta = known !== undefined ? known : await getNode(nodeId);
72
72
  if (meta === null)
73
73
  return '';
74
- const trunk = await ancestorTrunk(nodeId);
74
+ const trunk = await ancestorTrunk(nodeId, meta);
75
75
  const children = await childNodes(nodeId);
76
76
  return renderGraphMap(nodeId, meta.kind, meta.mode, trunk, children);
77
77
  }
78
78
  /** The identity assertion injected at session start. A fork names its source
79
79
  * while treating the copied first-person narrative as reference. */
80
- async function buildIdentityAssertion(nodeId) {
81
- const meta = await getNode(nodeId);
80
+ async function buildIdentityAssertion(nodeId, meta) {
82
81
  const forkFrom = meta?.fork_from;
83
82
  // A known node id carries its human label. Paths and session ids remain
84
83
  // opaque provenance rather than being passed to the node-id lookup.
@@ -163,13 +162,13 @@ function managedWorktreeNote(node) {
163
162
  * documents owned by the directory's repo (its `<repo>/index` is the workspace front door). */
164
163
  async function bearingsShell(nodeId, knowledge, workspaceContext) {
165
164
  const node = await getNode(nodeId);
166
- const bearings = ['<crtr-bearings>', await buildIdentityAssertion(nodeId)];
167
- const map = await buildGraphMap(nodeId);
165
+ const bearings = ['<crtr-bearings>', await buildIdentityAssertion(nodeId, node)];
166
+ const map = await buildGraphMap(nodeId, node);
168
167
  if (map !== '')
169
168
  bearings.push('', '## Your place in the canvas', map);
170
169
  bearings.push('', '## Your documents and context directory', contextDirNote(nodeId, node?.grantee));
171
170
  // Profile purview — omitted entirely when there is no project purview (see profileNote).
172
- const profileSection = await profileNote(nodeId);
171
+ const profileSection = await profileNote(nodeId, node);
173
172
  if (profileSection !== '')
174
173
  bearings.push('', profileSection);
175
174
  const worktree = managedWorktreeNote(node);
@@ -75,7 +75,7 @@ export async function deliverBearingsLive(nodeId) {
75
75
  // The boot delivery clears and rewrites the ledger and freezes preferences in
76
76
  // one transaction before Pi receives the bearings.
77
77
  await warmNodeRepos(await openDb(), nodeId);
78
- const { content } = await withCanvasWrite(async (db) => await deliver(db, await readerForNode(db, nodeId, async (cwd, person) => await checkoutsForCwd(db, cwd, person)), { activity: 'boot' }));
78
+ const { content } = await withCanvasWrite(async (db) => await deliver(db, await readerForNode(db, nodeId, async (cwd, person, access) => await checkoutsForCwd(db, cwd, person, access)), { activity: 'boot' }));
79
79
  await deliverCustomMessageLive(nodeId, {
80
80
  customType: CONTEXT_INTRO_CUSTOM_TYPE,
81
81
  content: formatCard('bearings', {}, content),
@@ -57,9 +57,14 @@ export function recipeDockerfile(recipe, revision, packagesToken = false) {
57
57
  out.push(guarded('setup script', `bash /tmp/${SETUP_SCRIPT_FILE}`));
58
58
  out.push(guarded('finalize', `echo ${Math.trunc(revision)} > /work/.crtr/recipe-revision && chown -R ${RUN_USER} /work /home/${RUN_USER} /var/lib/crtr`));
59
59
  out.push('', ...base);
60
- for (const dir of ['/work', `/home/${RUN_USER}`, '/usr/local', '/var/lib/crtr', '/usr', '/etc', '/lib'])
60
+ // COPY --from keeps file modes but not owners: without --chown every tree would end up root-owned and the sandbox start (as RUN_USER) would hit git's dubious-ownership refusal.
61
+ for (const dir of ['/work', `/home/${RUN_USER}`, '/var/lib/crtr'])
62
+ out.push(`COPY --from=build --chown=${RUN_USER}:${RUN_USER} ${dir} ${dir}`);
63
+ for (const dir of ['/usr/local', '/usr', '/etc', '/lib'])
61
64
  out.push(`COPY --from=build ${dir} ${dir}`);
62
65
  out.push('COPY --from=build /var/lib/postgresql /var/lib/postgresql');
66
+ // The copied /etc/passwd now names the postgres user (when the setup script installed postgres); its data directory must belong to it or the server refuses to start.
67
+ out.push('RUN if getent passwd postgres >/dev/null; then chown -R postgres:postgres /var/lib/postgresql; fi');
63
68
  if (packagesToken)
64
69
  out.push(`RUN rm -f /work/.npmrc /home/${RUN_USER}/.npmrc`);
65
70
  out.push('WORKDIR /work', 'ENTRYPOINT ["/usr/local/bin/sandbox-api"]', '');
@@ -194,7 +199,9 @@ export async function buildImage(config, name, dir, options = {}) {
194
199
  const started = now();
195
200
  const existing = await getImage(config, name);
196
201
  const before = new Set((existing?.spec?.tags ?? []).map((t) => t.name));
197
- const eventsBefore = existing?.metadata?.events?.length ?? 0;
202
+ // Blaxel keeps only the last 20 events, so the count stops growing on a long-lived image: a build's events are told apart by time, after the newest one already recorded.
203
+ const eventTimes = (doc) => (doc?.metadata?.events ?? []).map((e) => Date.parse(e.time ?? '')).filter((t) => !Number.isNaN(t));
204
+ const lastEventBefore = Math.max(-Infinity, ...eventTimes(existing));
198
205
  const created = await api(config, 'POST', '/images', { resourceType: 'sandbox', name });
199
206
  const uploadUrl = created.headers.get('x-blaxel-upload-url');
200
207
  if (uploadUrl === null)
@@ -208,15 +215,16 @@ export async function buildImage(config, name, dir, options = {}) {
208
215
  const image = await getImage(config, name);
209
216
  const status = image?.metadata?.status;
210
217
  // A rebuild of an existing image still reads BUILT until Blaxel records the new build: it adds an "initiated" and then a "succeeded" event.
211
- if (status === 'BUILT' && (image?.metadata?.events?.length ?? 0) >= eventsBefore + 2) {
218
+ const newEvents = eventTimes(image).filter((t) => t > lastEventBefore).sort((a, b) => a - b);
219
+ if (status === 'BUILT' && newEvents.length >= 2) {
212
220
  // A tag is derived from the build inputs and is immutable; the revision in the Dockerfile makes every revision's tag new. Identical inputs reuse the existing tag.
213
221
  // Blaxel writes the tag after it marks the image BUILT (observed 236 ms later). A tag belongs to this build when its name is new, or when it was
214
222
  // created or updated after this build's first new event (a reused tag touched by the build). A tag that is neither is the previous build's, or a reused
215
223
  // tag Blaxel did not touch; it is taken only once the grace period after BUILT has passed without a tag of this build appearing.
216
224
  builtAt ??= now();
217
225
  const all = (image?.spec?.tags ?? []).filter((t) => t.name !== undefined);
218
- const initiatedAt = (image?.metadata?.events ?? []).slice(eventsBefore).map((e) => e.time ?? '').filter((time) => time !== '').sort()[0];
219
- const touchedSince = (time) => initiatedAt !== undefined && Date.parse(time ?? '') >= Date.parse(initiatedAt);
226
+ const initiatedAt = newEvents[0];
227
+ const touchedSince = (time) => Date.parse(time ?? '') >= initiatedAt;
220
228
  const fresh = all.filter((t) => !before.has(t.name) || touchedSince(t.createdAt) || touchedSince(t.updatedAt));
221
229
  const graceOver = now() - builtAt >= (options.tagGraceMs ?? 60_000);
222
230
  const tags = fresh.length > 0 ? fresh : graceOver ? all : [];
@@ -252,14 +252,14 @@ async function readDocument(db, reader, raw) {
252
252
  * inside its boot, and a document read goes through the read route. */
253
253
  export const DRY_RUN_ONLY = ['workspace-open', 'document-read'];
254
254
  /** One delivery for a live node. Call inside `withCanvasWrite`. */
255
- export async function deliver(db, reader, req) {
255
+ export async function deliver(db, reader, req, subject) {
256
256
  if (DRY_RUN_ONLY.includes(req.activity))
257
257
  throw new ApiError(400, 'usage', `delivery activity ${req.activity} is available to a dry run only`);
258
258
  const node = nodeOf(reader).node;
259
259
  if (req.activity === 'boot' && req.inherited !== true)
260
260
  await clearLedger(db, node.id);
261
261
  const ledger = await loadLedger(db, node.id);
262
- const ctx = { db, reader, subject: await nodeSubject(db, reader), ledger, channel: 'transcript' };
262
+ const ctx = { db, reader, subject: subject ?? await nodeSubject(db, reader), ledger, channel: 'transcript' };
263
263
  const { result, delivered } = await render(ctx, req);
264
264
  await recordContentDelivery(db, reader, delivered);
265
265
  await saveLedger(db, ledger);
@@ -304,7 +304,7 @@ function resolveProfileId(raw, cwd) {
304
304
  export async function hypotheticalReader(db, h) {
305
305
  const app = await ownerForGrantee(db, h.grantee ?? 'app:terminal');
306
306
  const profileId = resolveProfileId(h.profile, h.cwd);
307
- const view = await viewRepos(db, h.cwd, profileId, async (cwd, person) => await checkoutsForCwd(db, cwd, person), liveLookups(db));
307
+ const view = await viewRepos(db, h.cwd, profileId, async (cwd, person, access) => await checkoutsForCwd(db, cwd, person, access), liveLookups(db));
308
308
  const { repos } = view;
309
309
  const mode = h.mode ?? 'base';
310
310
  const node = {
@@ -15,7 +15,7 @@ export { effectiveScopes, scopeForCwd, profileNameFor } from './subject-fields.j
15
15
  * walking the `parent` chain (canvas-db rows) until a row with no parent (the
16
16
  * root). The root is depth 0. Cycle-guarded (parents must not cycle, but never
17
17
  * loop forever) — mirrors `rootOfSpine` in runtime/placement.ts. */
18
- export async function spineDepth(nodeId) {
18
+ export async function spineDepth(nodeId, own) {
19
19
  let cur = nodeId;
20
20
  const seen = new Set();
21
21
  let hops = 0;
@@ -23,7 +23,7 @@ export async function spineDepth(nodeId) {
23
23
  if (seen.has(cur))
24
24
  break;
25
25
  seen.add(cur);
26
- const row = await getRow(cur);
26
+ const row = cur === nodeId && own !== undefined ? own : await getRow(cur);
27
27
  if (row === null || row.parent == null)
28
28
  break;
29
29
  cur = row.parent;
@@ -34,7 +34,7 @@ export async function spineDepth(nodeId) {
34
34
  /** The repos eligible for the node's rules: those enclosing its cwd, then the repos of its profile's project paths. */
35
35
  async function eligibleRepos(cwd, profileId) {
36
36
  const db = await openDb();
37
- const view = await viewRepos(db, cwd, profileId, async (dir, person) => await checkoutsForCwd(db, dir, person), liveLookups(db));
37
+ const view = await viewRepos(db, cwd, profileId, async (dir, person, access) => await checkoutsForCwd(db, dir, person, access), liveLookups(db));
38
38
  return [...view.repos, ...view.projectRepos];
39
39
  }
40
40
  /** Assemble the node-config subject for `nodeId` from its `NodeMeta` + the
@@ -51,7 +51,7 @@ export async function assembleNodeSubject(nodeId, repos) {
51
51
  hasManager: (meta.parent ?? null) !== null,
52
52
  cwd: meta.cwd,
53
53
  scope: scopeForCwd(meta.cwd),
54
- orchestration: { depth: await spineDepth(nodeId) },
54
+ orchestration: { depth: await spineDepth(nodeId, meta) },
55
55
  profile: profileNameFor(meta.profile_id),
56
56
  app: meta.grantee ?? await appForNode(nodeId),
57
57
  scopes: effectiveScopes(meta.scopes),
@@ -33,6 +33,7 @@ import { runAttachments } from './node-records.js';
33
33
  import { readerForNode, warmNodeRepos } from '../../../core/graph/reader.js';
34
34
  import { checkoutsForCwd } from '../../../core/graph/repo-sync/repos.js';
35
35
  import { deliver } from '../../../core/substrate/delivery/deliver.js';
36
+ import { nodeSubject } from '../../../core/substrate/delivery/corpus.js';
36
37
  import { ensureRunObserver } from '../../runs/observer.js';
37
38
  import { parseNodeTelemetryRecord, writeNodeTelemetryRecord } from './telemetry-record.js';
38
39
  import { mapAsync } from '../../../core/async-array.js';
@@ -300,10 +301,11 @@ async function startupDelivery(nodeId, state, bearings, namesOnly, warmed = fals
300
301
  if (!warmed)
301
302
  await warmNodeRepos(await openDb(), nodeId);
302
303
  return await withCanvasWrite(async (db) => {
303
- const reader = await readerForNode(db, nodeId, async (cwd, person) => await checkoutsForCwd(db, cwd, person));
304
- const names = await deliver(db, reader, { activity: 'names' });
305
- const boot = bootOwed ? await deliver(db, reader, { activity: 'boot', ...(bearings === 'inherited' ? { inherited: true } : {}) }) : undefined;
306
- const system = warm ? undefined : await deliver(db, reader, { activity: 'system-prompt' });
304
+ const reader = await readerForNode(db, nodeId, async (cwd, person, access) => await checkoutsForCwd(db, cwd, person, access));
305
+ const subject = await nodeSubject(db, reader);
306
+ const names = await deliver(db, reader, { activity: 'names' }, subject);
307
+ const boot = bootOwed ? await deliver(db, reader, { activity: 'boot', ...(bearings === 'inherited' ? { inherited: true } : {}) }, subject) : undefined;
308
+ const system = warm ? undefined : await deliver(db, reader, { activity: 'system-prompt' }, subject);
307
309
  return {
308
310
  names: { refs: names.refs, names: names.names },
309
311
  ...(boot === undefined ? {} : { boot: { content: boot.content, ...(boot.inherited === true ? { inherited: true } : {}) } }),
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.674",
3
+ "version": "0.3.676",
4
4
  "description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/api/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/identity",
3
- "version": "0.3.674",
3
+ "version": "0.3.676",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/plugin",
3
- "version": "0.3.674",
3
+ "version": "0.3.676",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
28
28
  },
29
29
  "dependencies": {
30
- "@north-light/api": "0.3.674",
31
- "@north-light/identity": "0.3.674"
30
+ "@north-light/api": "0.3.676",
31
+ "@north-light/identity": "0.3.676"
32
32
  },
33
33
  "license": "UNLICENSED",
34
34
  "publishConfig": {
package/runtime.lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.674",
3
+ "version": "0.3.676",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.674",
9
+ "version": "0.3.676",
10
10
  "hasInstallScript": true,
11
11
  "license": "UNLICENSED",
12
12
  "workspaces": [
@@ -28,8 +28,8 @@
28
28
  "@milkdown/preset-gfm": "^7.22.3",
29
29
  "@milkdown/prose": "^7.22.3",
30
30
  "@milkdown/utils": "^7.22.3",
31
- "@north-light/identity": "0.3.674",
32
- "@north-light/plugin": "0.3.674",
31
+ "@north-light/identity": "0.3.676",
32
+ "@north-light/plugin": "0.3.676",
33
33
  "cron-parser": "^5.6.0",
34
34
  "esbuild": "0.28.2",
35
35
  "jose": "^6.2.12",
@@ -10667,17 +10667,17 @@
10667
10667
  },
10668
10668
  "packages/crouter-api": {
10669
10669
  "name": "@north-light/api",
10670
- "version": "0.3.674",
10670
+ "version": "0.3.676",
10671
10671
  "license": "UNLICENSED"
10672
10672
  },
10673
10673
  "packages/crouter-env-docker": {
10674
10674
  "name": "@north-light/env-docker",
10675
- "version": "0.3.674",
10675
+ "version": "0.3.676",
10676
10676
  "license": "UNLICENSED"
10677
10677
  },
10678
10678
  "packages/crouter-identity": {
10679
10679
  "name": "@north-light/identity",
10680
- "version": "0.3.674",
10680
+ "version": "0.3.676",
10681
10681
  "license": "UNLICENSED",
10682
10682
  "dependencies": {
10683
10683
  "jose": "^6.2.1"
@@ -10685,21 +10685,21 @@
10685
10685
  },
10686
10686
  "packages/crouter-plugin": {
10687
10687
  "name": "@north-light/plugin",
10688
- "version": "0.3.674",
10688
+ "version": "0.3.676",
10689
10689
  "license": "UNLICENSED",
10690
10690
  "dependencies": {
10691
- "@north-light/api": "0.3.674",
10692
- "@north-light/identity": "0.3.674"
10691
+ "@north-light/api": "0.3.676",
10692
+ "@north-light/identity": "0.3.676"
10693
10693
  }
10694
10694
  },
10695
10695
  "packages/crouter-sdk": {
10696
10696
  "name": "@north-light/sdk",
10697
- "version": "0.3.674",
10697
+ "version": "0.3.676",
10698
10698
  "license": "UNLICENSED",
10699
10699
  "dependencies": {
10700
- "@north-light/api": "0.3.674",
10701
- "@north-light/identity": "0.3.674",
10702
- "@north-light/plugin": "0.3.674",
10700
+ "@north-light/api": "0.3.676",
10701
+ "@north-light/identity": "0.3.676",
10702
+ "@north-light/plugin": "0.3.676",
10703
10703
  "jose": "^6.2.1"
10704
10704
  },
10705
10705
  "bin": {