@north-light/crouter 0.3.281 → 0.3.283

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 (188) hide show
  1. package/dist/api/client.d.ts +19 -3
  2. package/dist/api/client.js +34 -0
  3. package/dist/api/dto/broker-ops.d.ts +11 -0
  4. package/dist/api/dto/broker.d.ts +3 -8
  5. package/dist/api/dto/common.d.ts +1 -1
  6. package/dist/api/dto/messages.d.ts +2 -2
  7. package/dist/api/dto/node-outcomes.d.ts +80 -0
  8. package/dist/api/dto/node-outcomes.js +2 -0
  9. package/dist/api/dto/nodes.d.ts +9 -0
  10. package/dist/api/dto/profiles.d.ts +5 -0
  11. package/dist/api/dto/reports.d.ts +45 -0
  12. package/dist/api/index.d.ts +1 -0
  13. package/dist/api/index.js +1 -0
  14. package/dist/api/plugin-manifest-schema.d.ts +208 -0
  15. package/dist/api/plugin-manifest-schema.js +23 -0
  16. package/dist/api/routes.d.ts +7 -0
  17. package/dist/api/routes.js +7 -0
  18. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/provider-rotation.js +24 -3
  19. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/provider-rotation.ts +31 -4
  20. package/dist/cli.js +8 -2
  21. package/dist/clients/attach/overlays/graph.d.ts +5 -0
  22. package/dist/clients/attach/overlays/graph.js +65 -47
  23. package/dist/clients/attach/overlays/pickers.js +8 -9
  24. package/dist/clients/attach/render/card-presentation.js +1 -1
  25. package/dist/clients/attach/viewer.js +1286 -1260
  26. package/dist/commands/api-client.js +22 -23
  27. package/dist/commands/node/create.js +38 -3
  28. package/dist/commands/node/inspect.js +3 -7
  29. package/dist/commands/node/message.js +3 -3
  30. package/dist/commands/node/outcome.d.ts +2 -0
  31. package/dist/commands/node/outcome.js +134 -0
  32. package/dist/commands/node.js +2 -1
  33. package/dist/commands/pkg/browse/catalog.js +1 -1
  34. package/dist/commands/pkg/plugin-manage.d.ts +46 -1
  35. package/dist/commands/pkg/plugin-manage.js +170 -20
  36. package/dist/commands/profile/pause.js +17 -14
  37. package/dist/commands/push.js +102 -1
  38. package/dist/commands/sys/__tests__/setup-core.test.js +4 -1
  39. package/dist/commands/sys/panels/broker-limits-panel.js +7 -1
  40. package/dist/commands/sys/panels/models-panel.js +2 -2
  41. package/dist/commands/sys/settings-shell.d.ts +1 -1
  42. package/dist/commands/sys/settings-shell.js +6 -0
  43. package/dist/commands/sys/settings.js +3 -3
  44. package/dist/core/__tests__/fixtures/fake-engine.d.ts +2 -0
  45. package/dist/core/__tests__/fixtures/fake-engine.js +42 -4
  46. package/dist/core/__tests__/helpers/harness.d.ts +1 -0
  47. package/dist/core/__tests__/helpers/harness.js +9 -0
  48. package/dist/core/__tests__/integration/plugin-revalidate.test.d.ts +1 -0
  49. package/dist/core/__tests__/integration/plugin-revalidate.test.js +355 -0
  50. package/dist/core/__tests__/integration/profile-pause.test.d.ts +1 -0
  51. package/dist/core/__tests__/integration/profile-pause.test.js +115 -0
  52. package/dist/core/__tests__/node-outcome.test.d.ts +1 -0
  53. package/dist/core/__tests__/node-outcome.test.js +184 -0
  54. package/dist/core/__tests__/revive-parked-fresh.test.js +13 -20
  55. package/dist/core/__tests__/seam/broker-provider-retry.test.js +6 -2
  56. package/dist/core/__tests__/seam/dormancy-release.test.js +3 -3
  57. package/dist/core/__tests__/seam/node-outcome-delivery.test.d.ts +1 -0
  58. package/dist/core/__tests__/seam/node-outcome-delivery.test.js +153 -0
  59. package/dist/core/bash-jobs.d.ts +6 -0
  60. package/dist/core/bash-jobs.js +22 -0
  61. package/dist/core/canvas/canvas.d.ts +41 -3
  62. package/dist/core/canvas/canvas.js +153 -39
  63. package/dist/core/canvas/crons.js +2 -1
  64. package/dist/core/canvas/index.d.ts +1 -0
  65. package/dist/core/canvas/index.js +1 -0
  66. package/dist/core/canvas/migrations.js +47 -0
  67. package/dist/core/canvas/node-outcome-deliveries.d.ts +80 -0
  68. package/dist/core/canvas/node-outcome-deliveries.js +163 -0
  69. package/dist/core/canvas/pid.d.ts +7 -0
  70. package/dist/core/canvas/pid.js +17 -0
  71. package/dist/core/canvas/render-source.js +2 -2
  72. package/dist/core/canvas/types.d.ts +42 -1
  73. package/dist/core/canvas/types.js +2 -1
  74. package/dist/core/command-manifests/registry.d.ts +3 -1
  75. package/dist/core/command-manifests/schema.d.ts +2 -75
  76. package/dist/core/command-manifests/schema.js +5 -0
  77. package/dist/core/command-plugins/compose.js +1 -1
  78. package/dist/core/command-plugins/revalidate.d.ts +18 -0
  79. package/dist/core/command-plugins/revalidate.js +152 -0
  80. package/dist/core/command-plugins/transport/http-fetch.d.ts +29 -4
  81. package/dist/core/command-plugins/transport/http-fetch.js +18 -8
  82. package/dist/core/command-plugins/transport/http-invoke.js +7 -0
  83. package/dist/core/command.d.ts +8 -0
  84. package/dist/core/command.js +19 -3
  85. package/dist/core/config.d.ts +4 -1
  86. package/dist/core/config.js +25 -1
  87. package/dist/core/exclusive-lock.d.ts +12 -0
  88. package/dist/core/exclusive-lock.js +29 -0
  89. package/dist/core/feed/feed.d.ts +8 -0
  90. package/dist/core/feed/feed.js +25 -4
  91. package/dist/core/feed/inbox.d.ts +5 -0
  92. package/dist/core/feed/inbox.js +13 -0
  93. package/dist/core/installed-plugins.js +31 -0
  94. package/dist/core/keybindings/catalog.d.ts +1 -1
  95. package/dist/core/keybindings/catalog.js +3 -0
  96. package/dist/core/manifest-recovery.d.ts +15 -0
  97. package/dist/core/manifest-recovery.js +72 -0
  98. package/dist/core/manifest-stale.d.ts +18 -0
  99. package/dist/core/manifest-stale.js +39 -0
  100. package/dist/core/plugin-swap-lock.d.ts +9 -0
  101. package/dist/core/plugin-swap-lock.js +31 -0
  102. package/dist/core/profiles/manifest.d.ts +3 -1
  103. package/dist/core/profiles/manifest.js +6 -1
  104. package/dist/core/runtime/broker/daemon-ops.d.ts +3 -1
  105. package/dist/core/runtime/broker/daemon-ops.js +6 -0
  106. package/dist/core/runtime/broker/engine-drive.d.ts +2 -3
  107. package/dist/core/runtime/broker/engine-drive.js +74 -27
  108. package/dist/core/runtime/broker/frame-dispatch.js +1 -0
  109. package/dist/core/runtime/broker/read-ops.js +14 -0
  110. package/dist/core/runtime/broker/rebind.js +0 -7
  111. package/dist/core/runtime/broker-protocol.d.ts +1 -6
  112. package/dist/core/runtime/fleet.d.ts +7 -0
  113. package/dist/core/runtime/headless-pi.d.ts +13 -0
  114. package/dist/core/runtime/headless-pi.js +10 -2
  115. package/dist/core/runtime/lifecycle.d.ts +6 -1
  116. package/dist/core/runtime/lifecycle.js +50 -1
  117. package/dist/core/runtime/nodes.d.ts +5 -1
  118. package/dist/core/runtime/nodes.js +2 -1
  119. package/dist/core/runtime/outcome-document.d.ts +70 -0
  120. package/dist/core/runtime/outcome-document.js +97 -0
  121. package/dist/core/runtime/revive.js +16 -21
  122. package/dist/core/runtime/spawn.d.ts +5 -1
  123. package/dist/core/runtime/spawn.js +18 -7
  124. package/dist/core/runtime/stamp/channel.d.ts +3 -5
  125. package/dist/core/runtime/stamp/channel.js +3 -10
  126. package/dist/core/runtime/stop-guard.js +2 -2
  127. package/dist/core/runtime/structured-output.d.ts +24 -3
  128. package/dist/core/runtime/structured-output.js +42 -3
  129. package/dist/core/runtime/tmux-bindings.js +4 -0
  130. package/dist/core/runtime/warm-pool.d.ts +5 -2
  131. package/dist/core/runtime/warm-pool.js +5 -5
  132. package/dist/core/subscription-state.js +7 -5
  133. package/dist/core/substrate/render.js +10 -10
  134. package/dist/core/user-settings.d.ts +18 -1
  135. package/dist/core/user-settings.js +37 -0
  136. package/dist/daemon/__tests__/node-deadline-lane.test.d.ts +1 -0
  137. package/dist/daemon/__tests__/node-deadline-lane.test.js +76 -0
  138. package/dist/daemon/__tests__/node-outcome-birth-invariants.test.d.ts +1 -0
  139. package/dist/daemon/__tests__/node-outcome-birth-invariants.test.js +122 -0
  140. package/dist/daemon/__tests__/node-outcome-delivery.test.d.ts +1 -0
  141. package/dist/daemon/__tests__/node-outcome-delivery.test.js +86 -0
  142. package/dist/daemon/api/__tests__/broker-settle-park.test.js +86 -18
  143. package/dist/daemon/api/__tests__/profile-launch-gates.test.js +10 -1
  144. package/dist/daemon/api/__tests__/seam/node-outcome-api.test.d.ts +1 -0
  145. package/dist/daemon/api/__tests__/seam/node-outcome-api.test.js +159 -0
  146. package/dist/daemon/api/__tests__/submit-result.test.d.ts +1 -0
  147. package/dist/daemon/api/__tests__/submit-result.test.js +214 -0
  148. package/dist/daemon/api/handlers/broker-ops.js +53 -24
  149. package/dist/daemon/api/handlers/canvas.js +2 -2
  150. package/dist/daemon/api/handlers/messages.js +12 -2
  151. package/dist/daemon/api/handlers/node-outcomes.d.ts +2 -0
  152. package/dist/daemon/api/handlers/node-outcomes.js +136 -0
  153. package/dist/daemon/api/handlers/nodes.js +67 -1
  154. package/dist/daemon/api/handlers/profiles.js +53 -1
  155. package/dist/daemon/api/handlers/reports.js +197 -33
  156. package/dist/daemon/api/map.d.ts +7 -2
  157. package/dist/daemon/api/map.js +78 -4
  158. package/dist/daemon/api/server.js +2 -0
  159. package/dist/daemon/crtrd.js +12 -0
  160. package/dist/daemon/fleet.d.ts +4 -8
  161. package/dist/daemon/fleet.js +48 -9
  162. package/dist/daemon/messaging/node-message.js +2 -1
  163. package/dist/daemon/node-outcome/deliver-outcome.d.ts +14 -0
  164. package/dist/daemon/node-outcome/deliver-outcome.js +155 -0
  165. package/dist/daemon/park-activity.d.ts +9 -0
  166. package/dist/daemon/park-activity.js +30 -0
  167. package/dist/daemon/park-pending.d.ts +10 -5
  168. package/dist/daemon/park-pending.js +18 -8
  169. package/dist/daemon/reconcilers/bash-deadline.js +6 -0
  170. package/dist/daemon/reconcilers/broker-supervision.d.ts +3 -7
  171. package/dist/daemon/reconcilers/broker-supervision.js +29 -33
  172. package/dist/daemon/reconcilers/node-deadline.d.ts +5 -0
  173. package/dist/daemon/reconcilers/node-deadline.js +82 -0
  174. package/dist/daemon/reconcilers/node-lifecycle/freeze-lane.js +9 -1
  175. package/dist/daemon/reconcilers/node-lifecycle/tick.js +12 -3
  176. package/dist/daemon/reconcilers/node-outcome-delivery-lane.d.ts +10 -0
  177. package/dist/daemon/reconcilers/node-outcome-delivery-lane.js +41 -0
  178. package/dist/pi-extensions/__tests__/canvas-structured-output.test.js +66 -66
  179. package/dist/pi-extensions/canvas-structured-output.d.ts +9 -5
  180. package/dist/pi-extensions/canvas-structured-output.js +23 -297
  181. package/dist/shared/env.d.ts +3 -0
  182. package/dist/shared/env.js +6 -0
  183. package/dist/shared/generated-context.d.ts +3 -9
  184. package/dist/shared/generated-context.js +8 -16
  185. package/dist/types.d.ts +19 -0
  186. package/dist/types.js +1 -0
  187. package/package.json +9 -8
  188. package/runtime.lock.json +227 -383
@@ -137,18 +137,8 @@ export function cliClient(opts) {
137
137
  // NodeSummaryDTO now carries every NodeRow field and NodeDetailDTO extends it,
138
138
  // so the viewer adapter returns the daemon's typed projections directly. It
139
139
  // performs no lossy legacy reconstruction or invented local-presence values.
140
- // The attach viewer's recurring subtree walk (chrome/canvas-panels.ts + overlays/graph.ts
141
- // computeActivity/visitActivity) calls subscriptionsOf/subscribersOf once per
142
- // visited node on every poll tick, and a `GET /v1/nodes/:id` per call just to
143
- // read the edge list off the detail DTO costs one round trip per visited node.
144
- // This short-TTL cache backs those two methods with the lean roster
145
- // (`GET /v1/canvas/roster`) instead — one shared fetch per TTL window covers
146
- // every topology walk in that window, comfortably under the attach viewer's 5s
147
- // poll cadence. Scoped to subscriptionsOf/subscribersOf only: listNodes/getRow
148
- // stay on the full per-id/list HTTP path because the roster does not carry the
149
- // runtime fields (intent/waiting_for/pi_pid/etc) those two already populate for
150
- // real from the full DTO — backing them with the roster would silently null out
151
- // live display fields, not just the already-lossy tmux-presence ones.
140
+ // Index the short-lived lean roster once so repeated topology lookups stay O(1).
141
+ // listNodes/getRow still use full DTO endpoints for fields the roster omits.
152
142
  const ROSTER_CACHE_TTL_MS = 2000;
153
143
  export class ApiCanvasSource {
154
144
  client;
@@ -160,15 +150,30 @@ export class ApiCanvasSource {
160
150
  async roster() {
161
151
  const now = Date.now();
162
152
  if (this.rosterCache !== null && now - this.rosterCache.at < ROSTER_CACHE_TTL_MS) {
163
- return this.rosterCache.roster;
153
+ return this.rosterCache.index;
164
154
  }
165
155
  if (this.rosterInFlight !== null)
166
156
  return this.rosterInFlight;
167
157
  this.rosterInFlight = this.client
168
158
  .canvasRoster()
169
159
  .then((roster) => {
170
- this.rosterCache = { at: Date.now(), roster };
171
- return roster;
160
+ const index = { subscriptions: new Map(), subscribers: new Map() };
161
+ for (const edge of roster.edges) {
162
+ const subscription = { node_id: edge.to_id, active: edge.active, created: edge.created };
163
+ const subscriber = { node_id: edge.from_id, active: edge.active, created: edge.created };
164
+ const subscriptions = index.subscriptions.get(edge.from_id);
165
+ if (subscriptions === undefined)
166
+ index.subscriptions.set(edge.from_id, [subscription]);
167
+ else
168
+ subscriptions.push(subscription);
169
+ const subscribers = index.subscribers.get(edge.to_id);
170
+ if (subscribers === undefined)
171
+ index.subscribers.set(edge.to_id, [subscriber]);
172
+ else
173
+ subscribers.push(subscriber);
174
+ }
175
+ this.rosterCache = { at: Date.now(), index };
176
+ return index;
172
177
  })
173
178
  .finally(() => {
174
179
  this.rosterInFlight = null;
@@ -212,16 +217,10 @@ export class ApiCanvasSource {
212
217
  return rows;
213
218
  }
214
219
  async subscriptionsOf(subscriber) {
215
- const roster = await this.roster();
216
- return roster.edges
217
- .filter((e) => e.from_id === subscriber)
218
- .map((e) => ({ node_id: e.to_id, active: e.active, created: e.created }));
220
+ return this.roster().then((index) => index.subscriptions.get(subscriber) ?? []);
219
221
  }
220
222
  async subscribersOf(publisher) {
221
- const roster = await this.roster();
222
- return roster.edges
223
- .filter((e) => e.to_id === publisher)
224
- .map((e) => ({ node_id: e.from_id, active: e.active, created: e.created }));
223
+ return this.roster().then((index) => index.subscribers.get(publisher) ?? []);
225
224
  }
226
225
  /** BFS over the active `subscribes_to` edges from `root` (its transitive view),
227
226
  * excluding `root` itself — the same traversal shape as
@@ -6,6 +6,7 @@ import { mark } from '../../core/timing.js';
6
6
  import { OUTPUT_SCHEMA_CONSTRAINTS, OUTPUT_SCHEMA_TRANSPORT, parseOutputSchemaValue } from '../../core/runtime/structured-output.js';
7
7
  import { MODEL_SPEC_FORMS, MODEL_SPEC_NEXT } from '../../core/runtime/model-selection.js';
8
8
  import { readMergedLaunchConfig } from '../../core/config.js';
9
+ import { parseDurationMs } from '../../core/wake.js';
9
10
  import { profilesStateBlock } from '../../core/profiles/state-block.js';
10
11
  import { resolveProfileOperand } from '../../core/profiles/manifest.js';
11
12
  import { stateBlock } from '../../core/help.js';
@@ -14,7 +15,7 @@ import { inTmux } from '../../core/runtime/placement-tmux.js';
14
15
  import { openSpawnViewer } from '../surface/node/placement.js';
15
16
  import { resolve } from 'node:path';
16
17
  const YIELD_NUDGE_THRESHOLD = 100_000;
17
- const NODE_NEW_OUTPUT_SCHEMA_EFFECT = '--output-schema writes the accepted result to the node’s context/result.json and pushes it as the node’s final report.';
18
+ const NODE_NEW_OUTPUT_SCHEMA_EFFECT = '--output-schema writes the accepted result to the node’s context/result.json and pushes it as the node’s final report; a node that cannot honestly satisfy the schema declines with `crtr push result --decline "<reason>" --code <token>`, which finishes it with a failure outcome (reason `declined`) whose `declined` field carries { reason, code, retryable } and no result. Name the code tokens you accept in the prompt; crouter carries the code verbatim and you validate it.';
18
19
  const STD_CHILD_FOLLOW_UP = "Do not wait, poll, or duplicate this child's assignment in your own context — there is no result to await, stopping will not strand you, and duplicated work wastes the delegated context. You're auto-subscribed, so its finish wakes you on its own. Two moves only: do other independent work right now, or stop and end your turn — the wake brings you back.";
19
20
  /** Decision road sign for a managed (non-root) child. Normally STD_CHILD_FOLLOW_UP,
20
21
  * but when the SPAWNER is an orchestrator whose context has already grown past
@@ -121,6 +122,9 @@ function nodeNewParams() {
121
122
  // this flag at exactly the moment it is needed. Advertising it would tax
122
123
  // every spawn with a capability almost no caller wants.
123
124
  { kind: 'flag', name: 'no-kickoff', type: 'bool', required: false, hidden: true, constraint: 'With --root, start the broker and session idle without a first message or model turn. Mutually exclusive with a prompt and --mode orchestrator.' },
125
+ { kind: 'flag', name: 'deadline', type: 'string', required: false, constraint: 'Positive, representable wall-clock duration from spawn. Grammar: one or more positive integer-unit parts; units: s, m, h, d; adjacent parts are summed. Omit for no deadline.' },
126
+ { kind: 'flag', name: 'outcome-action', type: 'string', required: false, constraint: 'Declared human-action name that receives the node outcome. Grammar: 1–128 ASCII letters, digits, dots, underscores, or hyphens; starts with a letter or digit. Omit when no external delivery target is needed.' },
127
+ { kind: 'flag', name: 'outcome-payload', type: 'string', required: false, constraint: 'JSON value, serialized at most 64 KiB, frozen and echoed to --outcome-action. Requires --outcome-action.' },
124
128
  {
125
129
  kind: 'flag',
126
130
  name: 'output-schema',
@@ -131,10 +135,10 @@ function nodeNewParams() {
131
135
  whenToUse: 'Use only when the node’s consumer needs a machine-checkable final object with fixed fields. Omit it for ordinary delegation or when a prose report is enough; structured output replaces the completion protocol, and an over-constrained schema can force retries.',
132
136
  value: `Pass the JSON Schema the result must satisfy. ${OUTPUT_SCHEMA_TRANSPORT} ${OUTPUT_SCHEMA_CONSTRAINTS}`,
133
137
  effects: [
134
- 'The node receives a terminal submit tool and cannot finish until submit accepts a result; it must not call `crtr push final` itself.',
138
+ 'The node must answer with `crtr push result` and cannot finish until the result is accepted; a plain `crtr push final` is blocked while the request is pending.',
135
139
  NODE_NEW_OUTPUT_SCHEMA_EFFECT,
136
140
  'The managed parent wakes through its existing subscription when the final report arrives; an independent root has no subscriber to wake.',
137
- 'Successful submit removes the request and terminates the node.',
141
+ 'An accepted result, or a decline, removes the request and terminates the node.',
138
142
  ],
139
143
  },
140
144
  },
@@ -164,6 +168,8 @@ function nodeNewEffects() {
164
168
  'A managed child creates an active parent subscription; its pushes wake the parent. --root creates an independent node with spawned_by provenance and no parent subscription.',
165
169
  '--worktree creates a managed worktree at ~/.crouter/canvas/worktrees/<node-id>/ on a new crtr/<node-id> branch.',
166
170
  NODE_NEW_OUTPUT_SCHEMA_EFFECT,
171
+ '--deadline persists a wall-clock deadline from spawn; expiry cancels the node and records a failure outcome with reason deadline_exceeded.',
172
+ '--outcome-action registers one resolved local human-action target. When the node settles, crouter retries delivery of its outcome document until the target accepts it or permanently rejects it; --outcome-payload is frozen and echoed in that document.',
167
173
  ...(inTmux() ? ['--root opens a viewer for the new node in the current tmux session.'] : []),
168
174
  ];
169
175
  }
@@ -203,6 +209,28 @@ async function runNodeCreation(input) {
203
209
  const situationalContext = situationalContextRaw !== undefined && situationalContextRaw !== '' ? situationalContextRaw : undefined;
204
210
  const outputSchemaParsed = parseOutputSchemaValue(input['outputSchema']);
205
211
  const outputSchema = outputSchemaParsed !== null ? JSON.stringify(outputSchemaParsed) : null;
212
+ const deadline = input['deadline'];
213
+ if (deadline !== undefined) {
214
+ const durationMs = parseDurationMs(deadline);
215
+ const deadlineAt = durationMs === null ? Number.NaN : new Date(Date.now() + durationMs).getTime();
216
+ if (durationMs === null || !Number.isFinite(durationMs) || durationMs <= 0 || !Number.isFinite(deadlineAt)) {
217
+ throw new InputError({ error: 'invalid_deadline', message: '--deadline must be a positive representable duration', field: 'deadline', next: 'Pass positive integer-unit parts using s, m, h, or d.' });
218
+ }
219
+ }
220
+ const outcomeAction = input['outcomeAction'];
221
+ const outcomePayloadRaw = input['outcomePayload'];
222
+ if (outcomePayloadRaw !== undefined && outcomeAction === undefined) {
223
+ throw new InputError({ error: 'outcome_payload_requires_action', message: '--outcome-payload requires --outcome-action', field: 'outcome-payload', next: 'Pass the declared delivery action with --outcome-action.' });
224
+ }
225
+ let outcomePayload;
226
+ if (outcomePayloadRaw !== undefined) {
227
+ try {
228
+ outcomePayload = JSON.parse(outcomePayloadRaw);
229
+ }
230
+ catch {
231
+ throw new InputError({ error: 'invalid_outcome_payload', message: '--outcome-payload must be valid JSON', field: 'outcome-payload', next: 'Pass one valid JSON value.' });
232
+ }
233
+ }
206
234
  const nodeId = input['nodeId']?.trim();
207
235
  if (root && worktreeBase !== undefined) {
208
236
  throw new InputError({ error: 'worktree_root_conflict', message: '--worktree is mutually exclusive with --root', field: 'worktree', next: 'Drop either --root or --worktree.' });
@@ -236,6 +264,13 @@ async function runNodeCreation(input) {
236
264
  ...(situationalContext !== undefined ? { situational_context: situationalContext } : {}),
237
265
  ...(noKickoff ? { no_kickoff: true } : {}),
238
266
  ...(outputSchema !== null ? { output_schema: outputSchema } : {}),
267
+ ...(deadline !== undefined ? { deadline } : {}),
268
+ ...(outcomeAction !== undefined ? {
269
+ outcome_delivery: {
270
+ action: outcomeAction,
271
+ ...(outcomePayload === undefined ? {} : { payload: outcomePayload }),
272
+ },
273
+ } : {}),
239
274
  ...(nodeId !== undefined && nodeId !== '' ? { node_id: nodeId } : {}),
240
275
  // A bare `--root --no-kickoff` create is exactly what the warm pool holds
241
276
  // ready; every other shape is rejected server-side and cold-spawns.
@@ -82,13 +82,9 @@ const nodeList = defineLeaf({
82
82
  return false;
83
83
  return true;
84
84
  });
85
- const nodes = [];
86
- for (const row of rows) {
87
- const detail = await canvasSource.getNode(row.node_id).catch(rethrowAsCliError);
88
- const named = { ...row, name: fullName(detail ?? row) };
89
- if (name === undefined || name === '' || fuzzyMatch(name, named.name))
90
- nodes.push(named);
91
- }
85
+ const nodes = rows
86
+ .map((row) => ({ ...row, name: fullName(row) }))
87
+ .filter((row) => name === undefined || name === '' || fuzzyMatch(name, row.name));
92
88
  return { nodes };
93
89
  },
94
90
  });
@@ -57,7 +57,7 @@ function messageRequestParams() {
57
57
  { kind: 'flag', name: 'to', type: 'string', required: false, constraint: 'Target an existing node by id. Exactly one of --to or --self is required.' },
58
58
  { kind: 'flag', name: 'self', type: 'bool', required: false, constraint: 'Target the calling node. Exactly one of --to or --self is required.' },
59
59
  { kind: 'flag', name: 'tier', type: 'enum', choices: ['critical', 'urgent', 'normal'], required: false, default: 'normal', constraint: 'Delivery urgency. Every accepted tier may revive a dormant target, because the request must be answered; deferred is rejected for that reason.' },
60
- { kind: 'flag', name: 'output-schema', type: 'string', required: true, constraint: `JSON Schema the result must satisfy. ${OUTPUT_SCHEMA_TRANSPORT} The target answers through a constrained submit tool, then keeps working. ${OUTPUT_SCHEMA_CONSTRAINTS}` },
60
+ { kind: 'flag', name: 'output-schema', type: 'string', required: true, constraint: `JSON Schema the result must satisfy. ${OUTPUT_SCHEMA_TRANSPORT} The target answers with \`crtr push result\` (or declines with \`crtr push result --decline "<reason>" --code <token>\`), then keeps working. ${OUTPUT_SCHEMA_CONSTRAINTS}` },
61
61
  { kind: 'flag', name: 'situational-context', type: 'string', required: false, constraint: 'Non-empty hidden ambient context delivered beside the message, or alone.' },
62
62
  { kind: 'flag', name: 'reopen', type: 'bool', required: false, hidden: true, constraint: 'Clear a finalized target latch before delivery or fresh revive.' },
63
63
  ];
@@ -129,7 +129,7 @@ const nodeMessageRequest = defineLeaf({
129
129
  params: messageRequestParams(),
130
130
  output: messageOutput(),
131
131
  outputKind: 'object',
132
- effects: ['Installs the one-off submit schema before appending the request.'],
132
+ effects: ['Installs the one-off output schema before appending the request.'],
133
133
  },
134
134
  run: (input) => {
135
135
  requireNonBlankDiscriminant(input, 'outputSchema');
@@ -144,7 +144,7 @@ export const nodeMessage = defineBranch({
144
144
  help: {
145
145
  name: 'node message',
146
146
  summary: 'deliver one immediate inbox entry to an existing node',
147
- model: 'Both children append one inbox entry to a node that already exists, targeted by id or --self, and may revive it if it is dormant. They differ in what the delivery obligates. An ordinary message obligates nothing: the target reads it and acts however it judges best. A request installs a one-off submit schema and holds the target awake and owing until it answers; the answer is validated against the schema, written to the target’s result file, and pushed as an update report to the TARGET’S subscribers, so subscribe to it first if the answer has to reach you. Neither child creates that standing relationship — a durable delivery edge is `node subscription`, and work that needs a fresh agent is `node new`.',
147
+ model: 'Both children append one inbox entry to a node that already exists, targeted by id or --self, and may revive it if it is dormant. They differ in what the delivery obligates. An ordinary message obligates nothing: the target reads it and acts however it judges best. A request installs a one-off output schema and holds the target awake and owing until it answers; the answer is validated against the schema, written to the target’s result file, and pushed as an update report to the TARGET’S subscribers, so subscribe to it first if the answer has to reach you. Neither child creates that standing relationship — a durable delivery edge is `node subscription`, and work that needs a fresh agent is `node new`.',
148
148
  },
149
149
  children: [nodeMessageSend, nodeMessageRequest],
150
150
  });
@@ -0,0 +1,2 @@
1
+ export declare const nodeOutcomeDelivery: import("../../core/command.js").LeafDef;
2
+ export declare const nodeOutcome: import("../../core/command.js").BranchDef;
@@ -0,0 +1,134 @@
1
+ // `crtr node outcome` — read a durable terminal outcome through crtrd only.
2
+ import { isSafeNodeId } from '../../api/index.js';
3
+ import { defineBranch, defineLeaf } from '../../core/command.js';
4
+ import { InputError } from '../../core/io.js';
5
+ import { cliClient, rethrowAsCliError } from '../api-client.js';
6
+ function nodeId(input) {
7
+ const id = typeof input['node'] === 'string' ? input['node'].trim() : '';
8
+ if (!isSafeNodeId(id)) {
9
+ throw new InputError({
10
+ error: 'invalid_node',
11
+ message: `invalid node id: ${id === '' ? '(empty)' : id}`,
12
+ field: 'node',
13
+ next: 'Pass the exact node id returned when the node was created.',
14
+ });
15
+ }
16
+ return id;
17
+ }
18
+ function renderedJson(value) {
19
+ return value === null || value === undefined ? 'none' : JSON.stringify(value);
20
+ }
21
+ const nodeOutcomeRead = defineLeaf({
22
+ name: 'read',
23
+ description: 'read or briefly await a node’s durable terminal outcome',
24
+ whenToUse: 'an external caller needs the durable result or failure reason for one node, optionally blocking for its terminal outcome without consuming or claiming it',
25
+ help: {
26
+ name: 'node outcome read',
27
+ summary: 'read a node’s durable outcome, optionally awaiting it for up to 25 seconds',
28
+ params: [
29
+ { kind: 'positional', name: 'node', required: true, constraint: 'Node id whose durable outcome to read.' },
30
+ { kind: 'flag', name: 'wait', type: 'int', required: false, default: 0, constraint: 'Whole seconds to await settlement: 0–25. Omit or use 0 to return the current pending/settled state immediately.' },
31
+ ],
32
+ output: [
33
+ { name: 'node_id', type: 'string', required: true, constraint: 'The requested node id.' },
34
+ { name: 'state', type: 'string', required: true, constraint: '`pending` while the node has no terminal outcome, otherwise `settled`.' },
35
+ { name: 'outcome', type: 'object', required: true, constraint: 'The durable result/failure record when settled — kind/reason, revision, settled time, report basename/path, structured result, failure detail, and `declined` ({ reason, code, retryable } for a failure with reason `declined`, else null) — otherwise null.' },
36
+ { name: 'node_status', type: 'string', required: true, constraint: 'The node status observed with the outcome.' },
37
+ { name: 'deadline_at', type: 'string', required: true, constraint: 'The absolute spawn deadline, or null when unbounded.' },
38
+ ],
39
+ outputKind: 'object',
40
+ effects: ['Read-only: calls the daemon’s replay-safe GET outcome route. With --wait, the daemon polls the durable row for no more than 25 seconds.'],
41
+ },
42
+ run: async (input) => {
43
+ const id = nodeId(input);
44
+ const wait = input['wait'];
45
+ if (typeof wait !== 'number' || !Number.isInteger(wait) || wait < 0 || wait > 25) {
46
+ throw new InputError({
47
+ error: 'invalid_wait',
48
+ message: '--wait must be an integer between 0 and 25 seconds',
49
+ field: 'wait',
50
+ received: wait,
51
+ next: 'Pass a whole number from 0 through 25, or omit --wait to poll immediately.',
52
+ });
53
+ }
54
+ return { ...await cliClient().getNodeOutcome(id, { waitSeconds: wait }).catch(rethrowAsCliError) };
55
+ },
56
+ render: (result) => {
57
+ const outcome = result['outcome'];
58
+ if (outcome === null) {
59
+ return [
60
+ `<outcome state="pending" node_id="${result['node_id']}">`,
61
+ `- node status: ${result['node_status']}`,
62
+ `- deadline: ${result['deadline_at'] ?? 'none'}`,
63
+ '</outcome>',
64
+ ].join('\n');
65
+ }
66
+ return [
67
+ `<outcome kind="${outcome['kind']}" reason="${outcome['reason']}" state="settled" node_id="${result['node_id']}" revision="${outcome['revision']}">`,
68
+ `- final report: ${outcome['final_report'] ?? 'none'}`,
69
+ `- report path: ${outcome['final_report_path'] ?? 'none'}`,
70
+ `- structured result: ${renderedJson(outcome['structured_result'])}`,
71
+ `- declined: ${renderedJson(outcome['declined'])}`,
72
+ `- failure detail: ${renderedJson(outcome['detail'])}`,
73
+ `- settled at: ${outcome['settled_at']}`,
74
+ `- node status: ${result['node_status']}`,
75
+ `- deadline: ${result['deadline_at'] ?? 'none'}`,
76
+ '</outcome>',
77
+ ].join('\n');
78
+ },
79
+ });
80
+ export const nodeOutcomeDelivery = defineLeaf({
81
+ name: 'delivery',
82
+ description: 'inspect a node outcome-delivery registration',
83
+ whenToUse: 'you need the durable state of the local action target registered to receive a node’s outcome',
84
+ help: {
85
+ name: 'node outcome delivery',
86
+ summary: 'inspect the registered outcome-delivery target for one node',
87
+ params: [
88
+ { kind: 'positional', name: 'node', required: true, constraint: 'Node id whose outcome-delivery registration to inspect.' },
89
+ ],
90
+ output: [
91
+ { name: 'node_id', type: 'string', required: true, constraint: 'The node whose outcome is delivered.' },
92
+ { name: 'state', type: 'string', required: true, constraint: '`armed`, `pending`, `running`, `accepted`, or `permanent_failed`.' },
93
+ { name: 'action', type: 'string', required: true, constraint: 'The resolved configured action name.' },
94
+ { name: 'attempt', type: 'number', required: true, constraint: 'How many delivery attempts have been claimed.' },
95
+ { name: 'next_attempt_at', type: 'string', required: true, constraint: 'ISO-8601 time of the next retry, or null before a retry is scheduled (including while armed).' },
96
+ { name: 'accepted_at', type: 'string', required: true, constraint: 'When the target accepted the document, or null.' },
97
+ { name: 'permanent_failed_at', type: 'string', required: true, constraint: 'When the target permanently rejected the document, or null.' },
98
+ { name: 'last_failure', type: 'object', required: true, constraint: 'The most recent retryable or permanent delivery failure, or null.' },
99
+ { name: 'created_at', type: 'string', required: true, constraint: 'When this delivery registration was created.' },
100
+ { name: 'updated_at', type: 'string', required: true, constraint: 'When this delivery registration was last updated.' },
101
+ ],
102
+ outputKind: 'object',
103
+ effects: ['Read-only: calls the daemon outcome-delivery inspection route.'],
104
+ },
105
+ run: async (input) => {
106
+ const id = nodeId(input);
107
+ return { ...await cliClient().getOutcomeDelivery(id).catch(rethrowAsCliError) };
108
+ },
109
+ render: (result) => {
110
+ return [
111
+ `<outcome-delivery state="${result['state']}" node_id="${result['node_id']}">`,
112
+ `- attempt: ${result['attempt']}`,
113
+ `- next retry: ${result['next_attempt_at'] ?? 'none'}`,
114
+ `- last failure: ${renderedJson(result['last_failure'])}`,
115
+ `- action: ${result['action']}`,
116
+ `- accepted at: ${result['accepted_at'] ?? 'none'}`,
117
+ `- permanently failed at: ${result['permanent_failed_at'] ?? 'none'}`,
118
+ `- registered at: ${result['created_at']}`,
119
+ `- updated at: ${result['updated_at']}`,
120
+ '</outcome-delivery>',
121
+ ].join('\n');
122
+ },
123
+ });
124
+ export const nodeOutcome = defineBranch({
125
+ name: 'outcome',
126
+ description: 'read a node’s terminal outcome or its delivery state',
127
+ whenToUse: 'you need the durable terminal result/failure of one node, or the state of its registered outcome-delivery target',
128
+ help: {
129
+ name: 'node outcome',
130
+ summary: 'read one node’s durable terminal outcome or its delivery registration',
131
+ model: 'Outcome reads never consume the terminal record. Read returns the durable result or failure and can wait briefly for settlement; delivery inspects the separate action-registration attempt state.',
132
+ },
133
+ children: [nodeOutcomeRead, nodeOutcomeDelivery],
134
+ });
@@ -9,6 +9,7 @@ import { nodeSubscription } from './node/subscription.js';
9
9
  import { nodeBash } from './node/bash.js';
10
10
  import { pyramidSlash } from './node/pyramid.js';
11
11
  import { nodeWorktreeBranch } from './node-worktree.js';
12
+ import { nodeOutcome } from './node/outcome.js';
12
13
  export function registerNode() {
13
14
  return defineBranch({
14
15
  name: 'node',
@@ -23,6 +24,6 @@ export function registerNode() {
23
24
  summary: 'create, inspect, message, and change canvas nodes',
24
25
  model: 'A node is one agent on the canvas. Immediate actions, durable waits, subscriptions, lifecycle changes, and scheduled crons are separate intent families; choose the family by when the effect happens and what persistent state it changes.',
25
26
  },
26
- children: [nodeNew, nodeFork, nodeMessage, nodeWaitBranch, nodeSubscription, nodeInspect, nodeLifecycle, nodeWorktreeBranch, nodeConfig, nodePromote, nodeYield, nodeBash],
27
+ children: [nodeNew, nodeFork, nodeMessage, nodeWaitBranch, nodeSubscription, nodeOutcome, nodeInspect, nodeLifecycle, nodeWorktreeBranch, nodeConfig, nodePromote, nodeYield, nodeBash],
27
28
  });
28
29
  }
@@ -337,7 +337,7 @@ function commandNode(node, parent = []) {
337
337
  children: [],
338
338
  params: node.params,
339
339
  output: node.output,
340
- effects: node.effects,
340
+ effects: [...node.effects],
341
341
  ...("rest" in node ? { rest: { method: node.rest.method, path: node.rest.path, streaming: node.rest.streaming === true } } : {}),
342
342
  };
343
343
  }
@@ -1,5 +1,14 @@
1
+ import { type CommandDiscoveryIssue } from '../../core/command-plugins/discovery.js';
1
2
  import { type HookPluginCandidate } from '../../core/command-hooks/discovery.js';
2
- import { type PluginManifest, type Scope } from '../../types.js';
3
+ import { type HookReport } from '../../core/command-hooks/report.js';
4
+ import { type PluginBundle, type PluginManifest, type Scope } from '../../types.js';
5
+ /** Static command-manifest report attached to install/update results. Runs
6
+ * the Phase-1 validator (no execution) so a caller sees exactly which
7
+ * top-level commands the plugin now contributes and why any were rejected. */
8
+ interface CommandReport {
9
+ mounts: string[];
10
+ issues: CommandDiscoveryIssue[];
11
+ }
3
12
  interface MarketplaceRef {
4
13
  marketplace: string;
5
14
  plugin: string;
@@ -10,6 +19,21 @@ interface InstallResult {
10
19
  path: string;
11
20
  memory?: PluginMemoryReport;
12
21
  }
22
+ interface BundleReplaceResult extends Record<string, unknown> {
23
+ name: string;
24
+ scope: Scope;
25
+ path: string;
26
+ transport: 'http';
27
+ version: string;
28
+ docs: number;
29
+ /** Count of kind-registry entries the bundle declared (0 when none). */
30
+ kinds: number;
31
+ /** Count of page-component registrations the bundle declared (0 when none). */
32
+ pageComponents: number;
33
+ commands: CommandReport;
34
+ hooks?: HookReport;
35
+ memory?: PluginMemoryReport;
36
+ }
13
37
  /** Who owns the physical memory corpus a candidate gate converges. A `package`
14
38
  * corpus is bytes this command owns — staged, or installed under the scope's
15
39
  * plugins dir — so a failed activation still rolls the package back. A `linked`
@@ -27,6 +51,27 @@ interface PluginMemoryReport extends Record<string, unknown> {
27
51
  /** Validate a package candidate before it gains an active plugin path. The
28
52
  * candidate namespace shadows any installed declaration of the same name. */
29
53
  export declare function assertPluginCandidateValid(manifest: PluginManifest, root: string, scope: Scope, scopeRootPath: string, where: string, candidates?: readonly HookPluginCandidate[], ownership?: PluginMemoryOwnership): Promise<PluginMemoryReport | undefined>;
54
+ /**
55
+ * Re-check an installed bundle plugin against its endpoint. A `conditional`
56
+ * check sends the validator stored for the package currently on disk, so an
57
+ * unchanged package is answered 304 and left untouched; an unconditional one
58
+ * asks for the archive outright, which is how recovery from a `manifest_stale`
59
+ * answer gets past a validator that is itself out of date.
60
+ *
61
+ * Returns the swap's report, or `undefined` when the package on disk is already
62
+ * the generation the server serves — whether the server said so with a 304 or
63
+ * we proved it by hashing bytes it re-sent.
64
+ *
65
+ * Every outcome, including a failure, records that the check happened, so an
66
+ * unreachable endpoint costs one timed-out probe per TTL rather than one per
67
+ * command. Failures throw; the caller decides whether a stale-but-present
68
+ * package is still good enough to run on.
69
+ */
70
+ export declare function revalidateBundlePlugin(name: string, bundleSource: PluginBundle, scope: Scope, options: {
71
+ enable: boolean;
72
+ conditional: boolean;
73
+ timeoutMs?: number;
74
+ }): Promise<BundleReplaceResult | undefined>;
30
75
  export declare function isMarketplaceRelativeSource(source: string): boolean;
31
76
  /** Install one marketplace plugin into a scope. Exported so `sys setup` can
32
77
  * install the default plugin set through the same path `pkg plugin install`