@north-light/cli 0.3.691 → 0.3.693

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 (50) hide show
  1. package/dist/api/client.d.ts +3 -1
  2. package/dist/api/client.js +2 -2
  3. package/dist/api/contract.d.ts +1 -1
  4. package/dist/api/contract.js +1 -1
  5. package/dist/api/dto/canvas.d.ts +6 -0
  6. package/dist/api/routes.d.ts +1 -0
  7. package/dist/api/routes.js +1 -1
  8. package/dist/clients/attach/chrome/canvas-panels.d.ts +2 -1
  9. package/dist/clients/attach/chrome/canvas-panels.js +1 -1
  10. package/dist/clients/attach/chrome/inbox-strip.d.ts +2 -1
  11. package/dist/clients/attach/chrome/inbox-strip.js +1 -1
  12. package/dist/clients/attach/chrome/roster.d.ts +2 -1
  13. package/dist/clients/attach/chrome/roster.js +5 -5
  14. package/dist/clients/attach/session/chrome-refresh.d.ts +2 -1
  15. package/dist/clients/attach/session/chrome-refresh.js +1 -1
  16. package/dist/clients/attach/viewer.js +348 -348
  17. package/dist/commands/api-client.d.ts +2 -1
  18. package/dist/commands/api-client.js +2 -2
  19. package/dist/core/canvas/canvas.d.ts +2 -2
  20. package/dist/core/canvas/canvas.js +2 -2
  21. package/dist/core/canvas/deliveries.js +8 -8
  22. package/dist/core/canvas/source.d.ts +4 -2
  23. package/dist/core/canvas/waits.d.ts +2 -2
  24. package/dist/core/canvas/waits.js +7 -7
  25. package/dist/daemon/api/handlers/canvas.js +16 -6
  26. package/dist/daemon/api/operations.js +1 -1
  27. package/dist/daemon/api/router.d.ts +2 -0
  28. package/dist/daemon/api/router.js +1 -1
  29. package/dist/daemon/reconcilers/node-lifecycle/remote-wake.d.ts +2 -2
  30. package/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +2 -2
  31. package/package.json +3 -3
  32. package/packages/crouter-api/dist/api/client.js +4 -0
  33. package/packages/crouter-api/dist/api/contract.js +1 -1
  34. package/packages/crouter-api/dist/api/routes.js +1 -0
  35. package/packages/crouter-api/dist/clients/attach/chrome/canvas-panels.js +2 -2
  36. package/packages/crouter-api/dist/clients/attach/chrome/inbox-strip.js +11 -9
  37. package/packages/crouter-api/dist/clients/attach/chrome/roster.js +2 -2
  38. package/packages/crouter-api/dist/clients/attach/session/chrome-refresh.js +22 -10
  39. package/packages/crouter-api/dist/clients/attach/viewer.js +3 -3
  40. package/packages/crouter-api/dist/commands/api-client.js +3 -0
  41. package/packages/crouter-api/dist/core/canvas/canvas.js +4 -4
  42. package/packages/crouter-api/dist/core/canvas/deliveries.js +1 -1
  43. package/packages/crouter-api/dist/core/canvas/waits.js +4 -4
  44. package/packages/crouter-api/dist/daemon/api/operations.js +1 -0
  45. package/packages/crouter-api/dist/daemon/api/router.js +11 -0
  46. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +16 -3
  47. package/packages/crouter-api/package.json +1 -1
  48. package/packages/crouter-identity/package.json +1 -1
  49. package/packages/crouter-plugin/package.json +3 -3
  50. package/runtime.lock.json +14 -14
@@ -53,6 +53,12 @@ export function createChromeRefresh(ctx, hooks) {
53
53
  .slice(0, 120);
54
54
  hooks.setNotice(detail === '' ? `${label} delayed` : `${label} delayed — ${detail}`);
55
55
  };
56
+ const setAsks = (counts) => {
57
+ if (JSON.stringify(counts) === JSON.stringify(asksMap))
58
+ return;
59
+ asksMap = counts;
60
+ hooks.renderFooter(); // the closed-inbox footer total tracks asksMap
61
+ };
56
62
  // Refresh all canvas chrome (panels + overlay if open) from the active canvas source.
57
63
  let chromeRefreshInFlight = false;
58
64
  let chromeRefreshQueued = false;
@@ -67,7 +73,11 @@ export function createChromeRefresh(ctx, hooks) {
67
73
  chromeRefreshQueued = false;
68
74
  const seqBefore = failureSeq;
69
75
  try {
70
- await hooks.refreshRoster();
76
+ // One read of this node's tree feeds the panels, the inbox strip and the ask counts.
77
+ const view = await canvasSource.panelView?.(nodeId);
78
+ if (view !== undefined)
79
+ setAsks(view.counts);
80
+ await hooks.refreshRoster(view);
71
81
  if (failureSeq === seqBefore)
72
82
  markHealthy();
73
83
  }
@@ -107,15 +117,17 @@ export function createChromeRefresh(ctx, hooks) {
107
117
  // cadence is what brings its backgrounding hint on screen.
108
118
  hooks.refreshInFlightTools();
109
119
  hooks.renderFooter();
110
- void (async () => {
111
- const root = await climbRootFromSource(nodeId);
112
- const counts = await canvasSource.ticketCountsForView(root);
113
- if (JSON.stringify(counts) !== JSON.stringify(asksMap)) {
114
- asksMap = counts;
115
- refresh();
116
- hooks.renderFooter(); // the closed-inbox footer total tracks asksMap
117
- }
118
- })().catch((err) => reportFailure('canvas attention refresh', err));
120
+ // A remote canvas has no tree read: it climbs and counts node by node.
121
+ if (canvasSource.panelView === undefined)
122
+ void (async () => {
123
+ const root = await climbRootFromSource(nodeId);
124
+ const counts = await canvasSource.ticketCountsForView(root);
125
+ if (JSON.stringify(counts) !== JSON.stringify(asksMap)) {
126
+ asksMap = counts;
127
+ refresh();
128
+ hooks.renderFooter();
129
+ }
130
+ })().catch((err) => reportFailure('canvas attention refresh', err));
119
131
  };
120
132
  const nextDelay = () => stalledPasses === 0 ? ASKS_POLL_MS : Math.min(ASKS_POLL_MS * 2 ** stalledPasses, ASKS_POLL_MAX_MS);
121
133
  // A self-rescheduling timer rather than an interval, so the wait can grow
@@ -439,9 +439,9 @@ onConnected) {
439
439
  const chromeRefresh = createChromeRefresh(ctx, {
440
440
  isTornDown: () => lifecycle.isTornDown(),
441
441
  setNotice,
442
- refreshRoster: async () => {
443
- await roster.refresh();
444
- await strip.refresh();
442
+ refreshRoster: async (view) => {
443
+ await roster.refresh(view);
444
+ await strip.refresh(view);
445
445
  },
446
446
  refreshGraph: () => graphOverlay.refresh(),
447
447
  refreshIdentity: () => identity.refresh(),
@@ -352,6 +352,9 @@ export class ApiCanvasSource {
352
352
  this.rosterCache = { at: Date.now(), index };
353
353
  return snapshot.nodes.map((node) => withRowFault(node));
354
354
  }
355
+ async panelView(nodeId) {
356
+ return await this.client.canvasView(nodeId);
357
+ }
355
358
  async panelRoster() {
356
359
  const index = await this.roster();
357
360
  if (index.snapshot !== undefined)
@@ -839,13 +839,13 @@ export async function childrenOf(id) {
839
839
  return (await (await openDb()).prepare('SELECT node_id FROM nodes WHERE parent = ? ORDER BY created')
840
840
  .all(id)).map((r) => r.node_id);
841
841
  }
842
- /** Every node's lean roster row, oldest first — a single scan indexed by
842
+ /** Every node's lean roster row (only those in `ids` when given), oldest first — a single scan indexed by
843
843
  * `idx_nodes_created`, with no per-row hydration or N+1 query. */
844
- export async function rosterNodes() {
844
+ export async function rosterNodes(ids) {
845
845
  return (await (await openDb())
846
846
  .prepareUncached(`SELECT node_id, name, kind, mode, lifecycle, status, cwd, host_kind, parent, created, description
847
- FROM node_rows WHERE ${NOT_A_SPARE} ORDER BY created`)
848
- .all()).map((r) => ({
847
+ FROM node_rows WHERE ${NOT_A_SPARE}${ids === undefined ? '' : ' AND node_id = ANY(?::text[])'} ORDER BY created`)
848
+ .all(...(ids === undefined ? [] : [[...ids]]))).map((r) => ({
849
849
  node_id: r['node_id'],
850
850
  name: r['name'],
851
851
  kind: r['kind'],
@@ -29,7 +29,7 @@ export function deliveryFrom(row) {
29
29
  }
30
30
  async function executionIsLive(db, nodeId, executionId, rejectRefresh) {
31
31
  const row = await db.prepare(`SELECT 1 FROM nodes n JOIN executions e ON e.node_id = n.node_id
32
- WHERE n.node_id = ? AND e.execution_id = ? AND e.state != 'exited'${rejectRefresh ? " AND n.intent IS DISTINCT FROM 'refresh'" : ''}`).get(nodeId, executionId);
32
+ WHERE n.node_id = ? AND e.execution_id = ? AND e.state != 'exited' AND e.stop_reason IS DISTINCT FROM 'release'${rejectRefresh ? " AND n.intent IS DISTINCT FROM 'refresh'" : ''}`).get(nodeId, executionId);
33
33
  return row !== undefined;
34
34
  }
35
35
  async function nodeMailRows(db, nodeId, executionId, wake, freshIds, deferredRun = false) {
@@ -91,15 +91,15 @@ export async function settleObjectWaits(db, objectId, nodeId = null, now = Date.
91
91
  export async function settleNodeObjectWaits(db, nodeId, now = Date.now()) {
92
92
  return Number((await db.prepare("UPDATE waits SET satisfied_at = ? WHERE kind = 'object' AND node_id = ? AND satisfied_at IS NULL").run(now, nodeId)).changes);
93
93
  }
94
- /** Every node's live object waits with the watched object's kind and name, for the roster. A deleted object
94
+ /** Every node's live object waits (only `nodeIds`' when given) with the watched object's kind and name, for the roster. A deleted object
95
95
  * settles its waits on publish, so none should dangle; a wait whose object row is gone is skipped rather than shown nameless. */
96
- export async function liveObjectWaitsNamed(db) {
96
+ export async function liveObjectWaitsNamed(db, nodeIds) {
97
97
  db ??= await openDb();
98
98
  return (await db.prepare(`SELECT w.wait_id, w.node_id, w.target_id, w.created_at, o.type AS object_type, o.name AS object_name
99
99
  FROM waits w JOIN objects o ON o.id = w.target_id
100
- WHERE w.kind = 'object' AND w.satisfied_at IS NULL AND o.deleted_at IS NULL
100
+ WHERE w.kind = 'object' AND w.satisfied_at IS NULL AND o.deleted_at IS NULL${nodeIds === undefined ? '' : ' AND w.node_id = ANY(?::text[])'}
101
101
  ORDER BY w.node_id, w.created_at, w.seq`)
102
- .all())
102
+ .all(...(nodeIds === undefined ? [] : [[...nodeIds]])))
103
103
  .map((row) => ({ waitId: row.wait_id, nodeId: row.node_id, objectId: row.target_id, createdAt: row.created_at, objectType: row.object_type, objectName: row.object_name }));
104
104
  }
105
105
  export async function hasLiveObjectWait(nodeId) {
@@ -219,6 +219,7 @@ export const OPERATIONS = [
219
219
  { name: 'canvas.post.128', method: 'POST', path: '/v1/canvas/history/stats', classes: ['person', 'broker', 'forwarded'], resource: 'canvas-read' },
220
220
  { name: 'canvas.get.129', method: 'GET', path: '/v1/canvas/snapshot', classes: ['person', 'broker', 'forwarded'], resource: 'canvas-read' },
221
221
  { name: 'canvas.get.130', method: 'GET', path: '/v1/canvas/roster', classes: ['person', 'broker'], resource: 'canvas-read' },
222
+ { name: 'canvas.get.view', method: 'GET', path: '/v1/canvas/view/:id', classes: ['person', 'broker'], resource: 'canvas-read' },
222
223
  { name: 'canvas.get.live-roots', method: 'GET', path: '/v1/canvas/live-roots', classes: ['person'], resource: 'canvas-read' },
223
224
  { name: 'canvas.get.browse', method: 'GET', path: '/v1/canvas/browse', classes: ['person', 'broker'], resource: 'canvas-read' },
224
225
  { name: 'canvas.get.analytics', method: 'GET', path: '/v1/canvas/analytics', classes: ['person', 'broker'], resource: 'canvas-read' },
@@ -139,6 +139,17 @@ export async function readableNodeIds(principal) {
139
139
  const rows = await db.prepareUncached(`SELECT o.id FROM objects o WHERE o.type = 'node' AND o.deleted_at IS NULL AND ${may.sql}`).all(...may.params);
140
140
  return new Set(rows.map((r) => r.id));
141
141
  }
142
+ /** Which of `ids` the caller may read: the condition `readableNodeIds()` builds, applied to only those ids. */
143
+ export async function readableAmong(principal, ids) {
144
+ if (actsAsPerson(principal))
145
+ return new Set(ids);
146
+ if (principal.class === 'anonymous' || principal.class === 'machine' || principal.class === 'import' || ids.length === 0)
147
+ return new Set();
148
+ const db = await openDb();
149
+ const may = await permits(db, await readerFor(db, { principal }), 'read');
150
+ const rows = await db.prepareUncached(`SELECT o.id FROM objects o WHERE o.type = 'node' AND o.deleted_at IS NULL AND o.id = ANY(?::text[]) AND ${may.sql}`).all([...ids], ...may.params);
151
+ return new Set(rows.map((r) => r.id));
152
+ }
142
153
  /** The inbox tickets in `ticketIds` whose requester node the caller may read, decided in one query per chunk with the evaluator's condition.
143
154
  * Same answer per ticket as `getRequestByInboxTicket` → `getNode` → `mayOnNode(read)`: a ticket with no requester node, or whose node row or object is missing, is not readable. */
144
155
  export async function readableTicketIds(principal, ticketIds) {
@@ -67,11 +67,24 @@ export async function imageForWake(environmentId) {
67
67
  return await resolveEnvironmentImage(environmentId);
68
68
  }
69
69
  /** Step 3: a `running` Blaxel execution is a resident broker, possibly frozen. On the accepted release it is woken and nothing else
70
- * is written. On another release it is asked to stop for the release first, so the thawed broker exits and the next claim starts
71
- * a new attempt on the accepted one. `lost` means no broker answered: the execution is ended and the caller starts a new attempt. */
70
+ * is written. On another release it is stopped and ended without being woken, so the next tick starts a new attempt on the
71
+ * accepted one. `lost` means no broker answered: the execution is ended and the caller starts a new attempt. */
72
72
  export async function wakeResident(execution) {
73
- if (execution.release !== acceptedRelease())
73
+ if (execution.release !== acceptedRelease()) {
74
+ // The outdated broker is never woken: its stop is recorded, the runner stops it, and only a confirmed stop ends the execution.
75
+ // Until then the wake mail is unclaimable by it (`claimNodeMail` refuses an execution whose stop reason is `release`), and the next tick asks again.
74
76
  await requestExecutionStop(execution.nodeId, { afterTurn: false, reason: 'release' });
77
+ // A stop already tried and unconfirmed is retried by `enactRequestedStops`, not on every tick.
78
+ if (execution.stopRequestedAt !== null)
79
+ return 'lost';
80
+ const stopped = await runnerForExecution(execution.runner).stop(execution, { reason: 'release' });
81
+ if (!stopped.confirmed) {
82
+ emitEvent({ level: 'error', event: 'broker.teardown.unconfirmed', node_id: execution.nodeId, error: stopped.error });
83
+ return 'lost';
84
+ }
85
+ await endExecution(execution.executionId, { reason: 'release' });
86
+ return 'lost';
87
+ }
75
88
  if (await runnerForExecution(execution.runner).wake(execution) === 'no_broker') {
76
89
  await endExecution(execution.executionId, { reason: 'lost' });
77
90
  return 'lost';
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.691",
3
+ "version": "0.3.693",
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.691",
3
+ "version": "0.3.693",
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.691",
3
+ "version": "0.3.693",
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.691",
31
- "@north-light/identity": "0.3.691"
30
+ "@north-light/api": "0.3.693",
31
+ "@north-light/identity": "0.3.693"
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.691",
3
+ "version": "0.3.693",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.691",
9
+ "version": "0.3.693",
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.691",
32
- "@north-light/plugin": "0.3.691",
31
+ "@north-light/identity": "0.3.693",
32
+ "@north-light/plugin": "0.3.693",
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.691",
10670
+ "version": "0.3.693",
10671
10671
  "license": "UNLICENSED"
10672
10672
  },
10673
10673
  "packages/crouter-env-docker": {
10674
10674
  "name": "@north-light/env-docker",
10675
- "version": "0.3.691",
10675
+ "version": "0.3.693",
10676
10676
  "license": "UNLICENSED"
10677
10677
  },
10678
10678
  "packages/crouter-identity": {
10679
10679
  "name": "@north-light/identity",
10680
- "version": "0.3.691",
10680
+ "version": "0.3.693",
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.691",
10688
+ "version": "0.3.693",
10689
10689
  "license": "UNLICENSED",
10690
10690
  "dependencies": {
10691
- "@north-light/api": "0.3.691",
10692
- "@north-light/identity": "0.3.691"
10691
+ "@north-light/api": "0.3.693",
10692
+ "@north-light/identity": "0.3.693"
10693
10693
  }
10694
10694
  },
10695
10695
  "packages/crouter-sdk": {
10696
10696
  "name": "@north-light/sdk",
10697
- "version": "0.3.691",
10697
+ "version": "0.3.693",
10698
10698
  "license": "UNLICENSED",
10699
10699
  "dependencies": {
10700
- "@north-light/api": "0.3.691",
10701
- "@north-light/identity": "0.3.691",
10702
- "@north-light/plugin": "0.3.691",
10700
+ "@north-light/api": "0.3.693",
10701
+ "@north-light/identity": "0.3.693",
10702
+ "@north-light/plugin": "0.3.693",
10703
10703
  "jose": "^6.2.1"
10704
10704
  },
10705
10705
  "bin": {