@north-light/cli 0.3.669 → 0.3.671

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 (86) hide show
  1. package/dist/api/client.js +1 -1
  2. package/dist/api/contract.d.ts +1 -1
  3. package/dist/api/contract.js +1 -1
  4. package/dist/api/dto/bash-jobs.d.ts +2 -0
  5. package/dist/api/dto/execution-start.d.ts +7 -0
  6. package/dist/clients/attach/viewer.js +1 -1
  7. package/dist/commands/node/bash.js +3 -3
  8. package/dist/core/bash-job-supervisor.js +3 -3
  9. package/dist/core/canvas/canvas.d.ts +10 -1
  10. package/dist/core/canvas/canvas.js +18 -18
  11. package/dist/core/canvas/schema-pg/022-create-request-lease.sql +5 -0
  12. package/dist/core/canvas/schema-pg/023-machine-calls-job-stop.sql +7 -0
  13. package/dist/core/canvas/schema-version.d.ts +1 -1
  14. package/dist/core/canvas/schema-version.js +1 -1
  15. package/dist/core/grants/sync.js +1 -1
  16. package/dist/core/runtime/broker/bash-job-launch.d.ts +4 -0
  17. package/dist/core/runtime/broker/bash-job-launch.js +1 -1
  18. package/dist/core/runtime/broker/boot-state.d.ts +8 -0
  19. package/dist/core/runtime/broker/boot-state.js +1 -1
  20. package/dist/core/runtime/broker/cycle-start.d.ts +8 -1
  21. package/dist/core/runtime/broker/cycle-start.js +2 -2
  22. package/dist/core/runtime/broker/turn-admission.d.ts +4 -1
  23. package/dist/core/runtime/broker/turn-admission.js +1 -1
  24. package/dist/core/runtime/broker.js +1 -1
  25. package/dist/core/runtime/runner/blaxel/runner.js +2 -2
  26. package/dist/core/runtime/runner/machine/call.js +2 -2
  27. package/dist/core/runtime/runner/machine/executor.d.ts +3 -3
  28. package/dist/core/runtime/runner/machine/executor.js +1 -1
  29. package/dist/core/runtime/runner/machine/ops.d.ts +18 -1
  30. package/dist/core/runtime/runner/machine/ops.js +1 -1
  31. package/dist/core/runtime/runner/types.d.ts +2 -1
  32. package/dist/daemon/api/handlers/bash-jobs.js +3 -3
  33. package/dist/daemon/api/handlers/delivery.js +1 -1
  34. package/dist/daemon/api/handlers/messages.js +2 -2
  35. package/dist/daemon/api/handlers/nodes.js +1 -1
  36. package/dist/daemon/cron/machine-fire.d.ts +3 -0
  37. package/dist/daemon/cron/machine-fire.js +1 -1
  38. package/dist/daemon/crtrd.js +16 -16
  39. package/dist/daemon/due-sources.d.ts +1 -1
  40. package/dist/daemon/due-sources.js +1 -1
  41. package/dist/daemon/due.js +7 -7
  42. package/dist/daemon/machine-daemon.js +1 -1
  43. package/dist/daemon/machine-link/job-sweep.d.ts +7 -0
  44. package/dist/daemon/machine-link/job-sweep.js +1 -1
  45. package/dist/daemon/reconcilers/bash-deadline.js +1 -1
  46. package/dist/daemon/reconcilers/machine-offline.d.ts +6 -0
  47. package/dist/daemon/reconcilers/machine-offline.js +7 -0
  48. package/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +2 -1
  49. package/dist/daemon/reconcilers/node-lifecycle/tick.js +1 -1
  50. package/dist/pi-extensions/canvas-inbox-watcher.js +2 -2
  51. package/dist/pi-extensions/canvas-stophook.js +1 -1
  52. package/dist/pi-extensions/canvas-tool-guide.d.ts +3 -1
  53. package/dist/pi-extensions/canvas-tool-guide.js +4 -4
  54. package/package.json +3 -3
  55. package/packages/crouter-api/dist/api/client.js +1 -1
  56. package/packages/crouter-api/dist/api/contract.js +1 -1
  57. package/packages/crouter-api/dist/api/dto/execution-start.js +0 -1
  58. package/packages/crouter-api/dist/commands/node/bash.js +7 -4
  59. package/packages/crouter-api/dist/core/bash-job-supervisor.js +15 -2
  60. package/packages/crouter-api/dist/core/canvas/canvas.js +23 -2
  61. package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
  62. package/packages/crouter-api/dist/core/grants/sync.js +3 -0
  63. package/packages/crouter-api/dist/core/runtime/broker/bash-job-launch.js +4 -5
  64. package/packages/crouter-api/dist/core/runtime/revive-all.js +108 -0
  65. package/packages/crouter-api/dist/core/runtime/runner/machine/call.js +1 -1
  66. package/packages/crouter-api/dist/core/runtime/runner/machine/ops.js +1 -1
  67. package/packages/crouter-api/dist/daemon/api/handlers/bash-jobs.js +13 -2
  68. package/packages/crouter-api/dist/daemon/cron/armed-context.js +140 -0
  69. package/packages/crouter-api/dist/daemon/cron/capture.js +50 -0
  70. package/packages/crouter-api/dist/daemon/cron/closed.js +108 -0
  71. package/packages/crouter-api/dist/daemon/cron/disposition.js +63 -0
  72. package/packages/crouter-api/dist/daemon/cron/ended.js +80 -0
  73. package/packages/crouter-api/dist/daemon/cron/escalation.js +136 -0
  74. package/packages/crouter-api/dist/daemon/cron/held.js +20 -0
  75. package/packages/crouter-api/dist/daemon/cron/machine-fire.js +177 -0
  76. package/packages/crouter-api/dist/daemon/cron/narrowed.js +34 -0
  77. package/packages/crouter-api/dist/daemon/cron/recurrence.js +38 -0
  78. package/packages/crouter-api/dist/daemon/cron/run-token.js +37 -0
  79. package/packages/crouter-api/dist/daemon/cron/settle.js +78 -0
  80. package/packages/crouter-api/dist/daemon/cron/sinks.js +70 -0
  81. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +1 -1
  82. package/packages/crouter-api/package.json +1 -1
  83. package/packages/crouter-identity/package.json +1 -1
  84. package/packages/crouter-plugin/package.json +3 -3
  85. package/runtime.lock.json +14 -14
  86. package/scripts/sandbox-bootstrap.sh +4 -0
@@ -0,0 +1,78 @@
1
+ import { consumeCron, recordCronRunLocked, releaseCronRunLease, setCronState, } from '../../core/canvas/crons.js';
2
+ import { withCanvasWrite } from '../../core/canvas/db.js';
3
+ import { enqueueDaemonAction } from '../../core/canvas/daemon-actions.js';
4
+ import { enqueueNodeMail } from '../../core/feed/messages.js';
5
+ import { emitEvent } from '../../core/events/emit.js';
6
+ import { narrowedNotice } from './narrowed.js';
7
+ import { disposeSettledRun } from './disposition.js';
8
+ function occurrenceStaysOwed(lease) {
9
+ return typeof lease === 'object' && (lease.kind === 'park' || lease.kind === 'redue');
10
+ }
11
+ export async function settleRun(c, input) {
12
+ const { outOfBand, outcome, record, lease } = input;
13
+ let delivered;
14
+ let paused;
15
+ let obligation;
16
+ if (outcome.kind === 'disposed') {
17
+ const disposition = await disposeSettledRun(c, outcome.ctx, outOfBand, outcome.selfCanceled ?? false);
18
+ delivered = disposition.delivered;
19
+ paused = disposition.paused;
20
+ obligation = disposition.obligation;
21
+ }
22
+ else if (outcome.kind === 'refused') {
23
+ delivered = `refused: ${outcome.reason}`;
24
+ // A narrowed scope never comes back on its own, so a recurring cron is paused too. Whatever pauses a cron, its armer is told.
25
+ const narrowed = !outOfBand && outcome.reason === 'scope_narrowed';
26
+ paused = !outOfBand && (c.recur == null || narrowed);
27
+ if (paused)
28
+ await setCronState(c.cron_id, 'paused');
29
+ if (paused)
30
+ obligation = await narrowedNotice(c, outcome.message);
31
+ emitEvent({
32
+ level: 'warn',
33
+ event: 'cron.fire.refused',
34
+ fields: { cron_id: c.cron_id, execution_id: record.runId, grant_id: c.grant_id, reason: outcome.reason, out_of_band: outOfBand },
35
+ });
36
+ }
37
+ else {
38
+ delivered = outcome.delivered;
39
+ paused = outcome.paused ?? false;
40
+ }
41
+ const written = await withCanvasWrite(async (db) => {
42
+ if (obligation !== undefined) {
43
+ if (obligation.kind === 'node') {
44
+ const enqueued = await enqueueNodeMail(obligation.destinationNodeId, {
45
+ kind: 'message', label: obligation.label, senderNodeId: obligation.senderNodeId,
46
+ bodyJson: { body: obligation.stdout }, urgency: obligation.urgency, wake: 1,
47
+ idempotencyKey: record.runId,
48
+ });
49
+ if (outcome.kind !== 'refused')
50
+ delivered = `delivered: ${enqueued.deliveryId}`;
51
+ }
52
+ else if (obligation.kind === 'action') {
53
+ const actionId = await enqueueDaemonAction({ adapter: obligation.adapter, bodyJson: obligation.bodyJson, idempotencyKey: record.runId });
54
+ if (outcome.kind !== 'refused')
55
+ delivered = `delivered: ${actionId}`;
56
+ }
57
+ }
58
+ const entry = {
59
+ run_id: record.runId,
60
+ cron_id: c.cron_id,
61
+ started: record.startedAtIso,
62
+ finished: new Date(record.finishedAtMs).toISOString(),
63
+ duration_ms: record.durationMs,
64
+ exit_code: record.exitCode,
65
+ stdout_head: record.stdoutHead,
66
+ stderr_head: record.stderrHead,
67
+ delivered,
68
+ };
69
+ await recordCronRunLocked(db, entry);
70
+ return entry;
71
+ });
72
+ if (lease !== 'none')
73
+ await releaseCronRunLease(c.cron_id, record.runId, lease === 'release' ? undefined : lease);
74
+ // Retain out-of-band, paused, and held rows; their occurrence is not spent.
75
+ if (!outOfBand && c.recur == null && !paused && !occurrenceStaysOwed(lease))
76
+ await consumeCron(c.cron_id);
77
+ return written;
78
+ }
@@ -0,0 +1,70 @@
1
+ import { newNodeId } from '../../core/runtime/nodes.js';
2
+ import { nodeAgentDir } from '../../core/canvas/node-agent-paths.js';
3
+ import { getNode } from '../../core/canvas/canvas.js';
4
+ import { parseCronSink } from '../../core/canvas/crons.js';
5
+ import { hasNoNaturalCycle } from '../../core/runtime/revive-all.js';
6
+ import { isParked } from '../../core/runtime/lifecycle.js';
7
+ import { cronWakeOrigin } from '../../core/runtime/bearings.js';
8
+ import { emitEvent } from '../../core/events/emit.js';
9
+ import { cronBirthPrincipalOf, resolveLiveProfile, resolveLiveProfileName } from './armed-context.js';
10
+ import { checkCronBirth } from './authority.js';
11
+ /** Resolve a completed run into a durable obligation. No sink effect happens here. */
12
+ export async function resolveCronSink(c, runId, stdout) {
13
+ const sink = parseCronSink(c.sink);
14
+ if (sink === null)
15
+ return { kind: 'none', delivered: 'no sink armed — nothing delivered' };
16
+ if (sink.kind === 'node') {
17
+ const meta = await getNode(sink.node);
18
+ if (meta === null)
19
+ throw new Error(`node sink ${sink.node} is gone`);
20
+ if (hasNoNaturalCycle(meta) && !isParked(meta)) {
21
+ throw new Error(`node sink ${sink.node} has no natural cycle ahead (done or finalized)`);
22
+ }
23
+ return {
24
+ kind: 'node',
25
+ destinationNodeId: sink.node,
26
+ senderNodeId: c.created_by !== null && await getNode(c.created_by) !== null ? c.created_by : null,
27
+ label: `⏰ cron ${c.name}`,
28
+ stdout,
29
+ urgency: c.tier,
30
+ };
31
+ }
32
+ if (sink.kind === 'spawn') {
33
+ // The birth is checked now so a refused one settles this run `refused` (no escalation), and
34
+ // again when the action is delivered.
35
+ const stored = cronBirthPrincipalOf(c);
36
+ const authority = await checkCronBirth(stored, { kind: sink.spawn, cwd: c.cwd, profile: resolveLiveProfile(c) });
37
+ if (!authority.allowed) {
38
+ emitEvent({ level: 'warn', event: 'cron.birth.refused', fields: { cron_id: c.cron_id, grant_id: c.grant_id, reason: authority.reason, stage: 'enqueue' } });
39
+ return { kind: 'none', delivered: `refused: ${authority.reason}`, refused: true };
40
+ }
41
+ const principal = { ...stored, scopes: authority.scopes };
42
+ const nodeId = await newNodeId();
43
+ const prompt = [
44
+ `Scheduled cron "${c.name}" (${c.cron_id}) fired and delivered its output to you as your kickoff.`,
45
+ '',
46
+ '## Command output',
47
+ '',
48
+ stdout,
49
+ ].join('\n');
50
+ return {
51
+ kind: 'action',
52
+ adapter: {
53
+ adapter: 'cron_spawn', cronId: c.cron_id, nodeId, kind: sink.spawn,
54
+ cwd: c.isolated ? await nodeAgentDir(nodeId, c.grantee) : c.cwd, isolated: c.isolated,
55
+ principal,
56
+ profile: resolveLiveProfile(c), wakeOrigin: await cronWakeOrigin(c, 'node_birth'), prompt,
57
+ },
58
+ bodyJson: { runId, stdout },
59
+ };
60
+ }
61
+ return {
62
+ kind: 'action',
63
+ adapter: {
64
+ adapter: 'cron_human', cronId: c.cron_id, requestId: await newNodeId(), title: `⏰ cron ${c.name}`,
65
+ summary: `Scheduled cron "${c.name}" delivered output for your attention.`, sessionName: `cron ${c.name} (${c.cron_id})`,
66
+ profileName: resolveLiveProfileName(c) ?? null,
67
+ },
68
+ bodyJson: { runId, stdout },
69
+ };
70
+ }
@@ -121,7 +121,7 @@ export async function recoverLaunching(nodeId, now) {
121
121
  if (!await endLaunchingExecution(execution.executionId, { reason: 'launch_failed' }))
122
122
  return false;
123
123
  const message = `the sandbox start script failed: ${status.reason}`;
124
- await recordLaunchFailure(execution.executionId, new Error(message));
124
+ await recordLaunchFailure(execution.executionId, new Error(status.output === undefined ? message : `${message}\n${status.output}`));
125
125
  // The same bounded sequence a local broker that keeps dying runs (`recordRespawnPolicy`): each failed launch is a consecutive
126
126
  // failure and the backoff holds the next launch. The last one ends the node dead `crash_looped`.
127
127
  const row = await getRow(nodeId);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.669",
3
+ "version": "0.3.671",
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.669",
3
+ "version": "0.3.671",
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.669",
3
+ "version": "0.3.671",
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.669",
31
- "@north-light/identity": "0.3.669"
30
+ "@north-light/api": "0.3.671",
31
+ "@north-light/identity": "0.3.671"
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.669",
3
+ "version": "0.3.671",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.669",
9
+ "version": "0.3.671",
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.669",
32
- "@north-light/plugin": "0.3.669",
31
+ "@north-light/identity": "0.3.671",
32
+ "@north-light/plugin": "0.3.671",
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.669",
10670
+ "version": "0.3.671",
10671
10671
  "license": "UNLICENSED"
10672
10672
  },
10673
10673
  "packages/crouter-env-docker": {
10674
10674
  "name": "@north-light/env-docker",
10675
- "version": "0.3.669",
10675
+ "version": "0.3.671",
10676
10676
  "license": "UNLICENSED"
10677
10677
  },
10678
10678
  "packages/crouter-identity": {
10679
10679
  "name": "@north-light/identity",
10680
- "version": "0.3.669",
10680
+ "version": "0.3.671",
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.669",
10688
+ "version": "0.3.671",
10689
10689
  "license": "UNLICENSED",
10690
10690
  "dependencies": {
10691
- "@north-light/api": "0.3.669",
10692
- "@north-light/identity": "0.3.669"
10691
+ "@north-light/api": "0.3.671",
10692
+ "@north-light/identity": "0.3.671"
10693
10693
  }
10694
10694
  },
10695
10695
  "packages/crouter-sdk": {
10696
10696
  "name": "@north-light/sdk",
10697
- "version": "0.3.669",
10697
+ "version": "0.3.671",
10698
10698
  "license": "UNLICENSED",
10699
10699
  "dependencies": {
10700
- "@north-light/api": "0.3.669",
10701
- "@north-light/identity": "0.3.669",
10702
- "@north-light/plugin": "0.3.669",
10700
+ "@north-light/api": "0.3.671",
10701
+ "@north-light/identity": "0.3.671",
10702
+ "@north-light/plugin": "0.3.671",
10703
10703
  "jose": "^6.2.1"
10704
10704
  },
10705
10705
  "bin": {
@@ -41,6 +41,10 @@ if ! id "$RUN_USER" >/dev/null 2>&1; then
41
41
  fi
42
42
  mkdir -p /run/crtr /var/lib/crtr /work "$RELEASES"
43
43
  chown "$RUN_USER" /run/crtr /var/lib/crtr /work
44
+ # Blaxel unpacks an image into a read-only layer that does not keep file ownership: everything the release image chowned to `crtr` at build
45
+ # (`/work/.crtr`, the home) is root-owned in the sandbox, and the start script, running as `crtr`, could not write `/work/.crtr/plugins-revision`.
46
+ # These are the small trees the image creates; they are handed over here on every boot.
47
+ for dir in /work/.crtr "/home/$RUN_USER"; do [ ! -e "$dir" ] || chown -R "$RUN_USER" "$dir"; done
44
48
  # pi's grep tool wants ripgrep; the release image has it, and installing it once per sandbox avoids a GitHub download at the first grep.
45
49
  rg=present
46
50
  if ! command -v rg >/dev/null 2>&1; then