@crouton-kit/crouter 0.3.40 → 0.3.42

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 (195) hide show
  1. package/dist/build-root.js +1 -0
  2. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/__tests__/provider-rotation.test.ts +472 -9
  3. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/provider-rotation.ts +284 -76
  4. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/strip-skills-docs.ts +31 -24
  5. package/dist/builtin-pi-packages/pi-crtr-extensions/lib/subscription-state.ts +52 -15
  6. package/dist/clients/attach/attach-cmd.js +720 -747
  7. package/dist/clients/attach/chat-view.js +11 -0
  8. package/dist/clients/attach/view-socket.d.ts +8 -1
  9. package/dist/clients/attach/view-socket.js +15 -1
  10. package/dist/clients/web/server.js +5 -28
  11. package/dist/clients/web/web-cmd.js +1 -1
  12. package/dist/commands/__tests__/revive-now-gate.test.js +60 -0
  13. package/dist/commands/canvas-rebuild-index.js +5 -5
  14. package/dist/commands/memory/shared.d.ts +7 -3
  15. package/dist/commands/memory/shared.js +35 -5
  16. package/dist/commands/memory/write.js +5 -3
  17. package/dist/commands/node-snapshot.js +9 -1
  18. package/dist/commands/node.js +37 -17
  19. package/dist/commands/push.js +8 -0
  20. package/dist/commands/revive.d.ts +10 -0
  21. package/dist/commands/revive.js +28 -10
  22. package/dist/commands/sys/__tests__/setup-core.test.js +19 -0
  23. package/dist/commands/sys/doctor.js +1 -1
  24. package/dist/commands/sys/setup-core.js +3 -2
  25. package/dist/commands/sys/setup.js +1 -1
  26. package/dist/commands/worktree.d.ts +2 -0
  27. package/dist/commands/worktree.js +94 -0
  28. package/dist/core/__tests__/boot.test.js +4 -4
  29. package/dist/core/__tests__/canvas.test.js +19 -7
  30. package/dist/core/__tests__/child-followup.test.js +15 -5
  31. package/dist/core/__tests__/daemon-boot.test.js +6 -1
  32. package/dist/core/__tests__/daemon-wedge.test.js +18 -1
  33. package/dist/core/__tests__/fault-classifier.test.js +30 -0
  34. package/dist/core/__tests__/fixtures/fake-engine.d.ts +13 -0
  35. package/dist/core/__tests__/fixtures/fake-engine.js +20 -0
  36. package/dist/core/__tests__/full/spike-harness.test.js +8 -5
  37. package/dist/core/__tests__/grace-clock.test.js +18 -2
  38. package/dist/core/__tests__/host-teardown-process-group.test.js +465 -0
  39. package/dist/core/__tests__/prune-to-limit.test.js +14 -0
  40. package/dist/core/__tests__/review-model-floor.test.js +32 -0
  41. package/dist/core/__tests__/revive.test.js +18 -4
  42. package/dist/core/__tests__/session-cycles.test.js +77 -0
  43. package/dist/core/__tests__/worktree.test.js +85 -0
  44. package/dist/core/canvas/boot.js +12 -7
  45. package/dist/core/canvas/canvas.d.ts +27 -8
  46. package/dist/core/canvas/canvas.js +54 -26
  47. package/dist/core/canvas/db.js +14 -0
  48. package/dist/core/canvas/history.js +1 -0
  49. package/dist/core/canvas/paths.d.ts +10 -9
  50. package/dist/core/canvas/paths.js +10 -9
  51. package/dist/core/canvas/pid.d.ts +155 -1
  52. package/dist/core/canvas/pid.js +306 -1
  53. package/dist/core/canvas/status-glyph.d.ts +7 -0
  54. package/dist/core/canvas/status-glyph.js +10 -1
  55. package/dist/core/canvas/types.d.ts +34 -0
  56. package/dist/core/fault-classifier.js +5 -1
  57. package/dist/core/profiles/select.d.ts +4 -2
  58. package/dist/core/profiles/select.js +30 -4
  59. package/dist/core/runtime/bearings.js +4 -0
  60. package/dist/core/runtime/branded-host.d.ts +7 -0
  61. package/dist/core/runtime/branded-host.js +44 -17
  62. package/dist/core/runtime/broker-sdk.js +28 -68
  63. package/dist/core/runtime/broker.js +35 -4
  64. package/dist/core/runtime/host.d.ts +3 -3
  65. package/dist/core/runtime/host.js +148 -33
  66. package/dist/core/runtime/launch.d.ts +15 -15
  67. package/dist/core/runtime/launch.js +58 -4
  68. package/dist/core/runtime/naming.js +3 -2
  69. package/dist/core/runtime/nodes.d.ts +3 -1
  70. package/dist/core/runtime/nodes.js +1 -0
  71. package/dist/core/runtime/pi-cli.d.ts +2 -0
  72. package/dist/core/runtime/pi-cli.js +51 -0
  73. package/dist/core/runtime/placement.d.ts +1 -1
  74. package/dist/core/runtime/placement.js +5 -2
  75. package/dist/core/runtime/recap.js +2 -1
  76. package/dist/core/runtime/revive.d.ts +21 -15
  77. package/dist/core/runtime/revive.js +87 -52
  78. package/dist/core/runtime/session-cycles.d.ts +30 -0
  79. package/dist/core/runtime/session-cycles.js +77 -0
  80. package/dist/core/runtime/spawn.d.ts +4 -0
  81. package/dist/core/runtime/spawn.js +152 -100
  82. package/dist/core/runtime/tmux.d.ts +7 -10
  83. package/dist/core/runtime/tmux.js +9 -11
  84. package/dist/core/worktree.d.ts +35 -0
  85. package/dist/core/worktree.js +158 -0
  86. package/dist/daemon/crtrd.d.ts +17 -8
  87. package/dist/daemon/crtrd.js +191 -40
  88. package/dist/index.d.ts +3 -0
  89. package/dist/index.js +7 -0
  90. package/dist/pi-extensions/canvas-context-intro.d.ts +1 -0
  91. package/dist/pi-extensions/canvas-context-intro.js +34 -23
  92. package/dist/pi-extensions/canvas-stophook.js +11 -5
  93. package/dist/web-client/assets/{index-CbO8L0mN.js → index-B00YpRQ1.js} +20 -20
  94. package/dist/web-client/assets/index-DrkcvANq.css +2 -0
  95. package/dist/web-client/index.html +2 -2
  96. package/docs/compat/hearth-crtr-v1.md +191 -0
  97. package/docs/public-api.md +75 -0
  98. package/package.json +3 -4
  99. package/dist/core/__tests__/hearth-bootstrap.test.js +0 -136
  100. package/dist/core/hearth/__tests__/model-auth-guest.test.js +0 -151
  101. package/dist/core/hearth/config.d.ts +0 -3
  102. package/dist/core/hearth/config.js +0 -108
  103. package/dist/core/hearth/guest-env.d.ts +0 -9
  104. package/dist/core/hearth/guest-env.js +0 -27
  105. package/dist/core/hearth/index.d.ts +0 -4
  106. package/dist/core/hearth/index.js +0 -4
  107. package/dist/core/hearth/model-auth-guest.d.ts +0 -8
  108. package/dist/core/hearth/model-auth-guest.js +0 -430
  109. package/dist/core/hearth/provider.d.ts +0 -36
  110. package/dist/core/hearth/provider.js +0 -10
  111. package/dist/core/hearth/providers/__tests__/sweep-and-release.test.js +0 -362
  112. package/dist/core/hearth/providers/blaxel-bootstrap.d.ts +0 -12
  113. package/dist/core/hearth/providers/blaxel-bootstrap.js +0 -147
  114. package/dist/core/hearth/providers/blaxel-home.d.ts +0 -60
  115. package/dist/core/hearth/providers/blaxel-home.js +0 -405
  116. package/dist/core/hearth/providers/blaxel.d.ts +0 -36
  117. package/dist/core/hearth/providers/blaxel.js +0 -364
  118. package/dist/core/hearth/providers/types.d.ts +0 -93
  119. package/dist/core/hearth/types.d.ts +0 -155
  120. package/dist/hearth/control-plane/__tests__/error-serialization.test.js +0 -29
  121. package/dist/hearth/control-plane/__tests__/node-message.test.js +0 -60
  122. package/dist/hearth/control-plane/__tests__/oauth-serving-marker.test.d.ts +0 -1
  123. package/dist/hearth/control-plane/__tests__/oauth-serving-marker.test.js +0 -44
  124. package/dist/hearth/control-plane/__tests__/rate-limit-recurrence.test.d.ts +0 -1
  125. package/dist/hearth/control-plane/__tests__/rate-limit-recurrence.test.js +0 -49
  126. package/dist/hearth/control-plane/__tests__/relay-security.test.d.ts +0 -1
  127. package/dist/hearth/control-plane/__tests__/relay-security.test.js +0 -314
  128. package/dist/hearth/control-plane/__tests__/scheduler-scan-loop.test.d.ts +0 -1
  129. package/dist/hearth/control-plane/__tests__/scheduler-scan-loop.test.js +0 -133
  130. package/dist/hearth/control-plane/__tests__/trigger-delivery.test.d.ts +0 -1
  131. package/dist/hearth/control-plane/__tests__/trigger-delivery.test.js +0 -170
  132. package/dist/hearth/control-plane/__tests__/wake-roll.test.d.ts +0 -1
  133. package/dist/hearth/control-plane/__tests__/wake-roll.test.js +0 -230
  134. package/dist/hearth/control-plane/__tests__/webhook-ingress.test.d.ts +0 -1
  135. package/dist/hearth/control-plane/__tests__/webhook-ingress.test.js +0 -167
  136. package/dist/hearth/control-plane/config.d.ts +0 -21
  137. package/dist/hearth/control-plane/config.js +0 -77
  138. package/dist/hearth/control-plane/db.d.ts +0 -30
  139. package/dist/hearth/control-plane/db.js +0 -561
  140. package/dist/hearth/control-plane/hearth-target.d.ts +0 -23
  141. package/dist/hearth/control-plane/hearth-target.js +0 -68
  142. package/dist/hearth/control-plane/ingress/rate-limit.d.ts +0 -24
  143. package/dist/hearth/control-plane/ingress/rate-limit.js +0 -100
  144. package/dist/hearth/control-plane/ingress/route-store.d.ts +0 -31
  145. package/dist/hearth/control-plane/ingress/route-store.js +0 -61
  146. package/dist/hearth/control-plane/ingress/webhook-delivery-store.d.ts +0 -41
  147. package/dist/hearth/control-plane/ingress/webhook-delivery-store.js +0 -69
  148. package/dist/hearth/control-plane/ingress/webhook-route.d.ts +0 -55
  149. package/dist/hearth/control-plane/ingress/webhook-route.js +0 -285
  150. package/dist/hearth/control-plane/main.d.ts +0 -1
  151. package/dist/hearth/control-plane/main.js +0 -88
  152. package/dist/hearth/control-plane/node-message.d.ts +0 -31
  153. package/dist/hearth/control-plane/node-message.js +0 -98
  154. package/dist/hearth/control-plane/register.d.ts +0 -15
  155. package/dist/hearth/control-plane/register.js +0 -34
  156. package/dist/hearth/control-plane/registry.d.ts +0 -22
  157. package/dist/hearth/control-plane/registry.js +0 -168
  158. package/dist/hearth/control-plane/relay.d.ts +0 -44
  159. package/dist/hearth/control-plane/relay.js +0 -711
  160. package/dist/hearth/control-plane/scheduler/fire-store.d.ts +0 -36
  161. package/dist/hearth/control-plane/scheduler/fire-store.js +0 -73
  162. package/dist/hearth/control-plane/scheduler/recurrence.d.ts +0 -7
  163. package/dist/hearth/control-plane/scheduler/recurrence.js +0 -58
  164. package/dist/hearth/control-plane/scheduler/scan-loop.d.ts +0 -38
  165. package/dist/hearth/control-plane/scheduler/scan-loop.js +0 -138
  166. package/dist/hearth/control-plane/scheduler/schedule-store.d.ts +0 -32
  167. package/dist/hearth/control-plane/scheduler/schedule-store.js +0 -66
  168. package/dist/hearth/control-plane/secrets.d.ts +0 -31
  169. package/dist/hearth/control-plane/secrets.js +0 -134
  170. package/dist/hearth/control-plane/server.d.ts +0 -27
  171. package/dist/hearth/control-plane/server.js +0 -482
  172. package/dist/hearth/control-plane/serving.d.ts +0 -15
  173. package/dist/hearth/control-plane/serving.js +0 -106
  174. package/dist/hearth/control-plane/session.d.ts +0 -68
  175. package/dist/hearth/control-plane/session.js +0 -273
  176. package/dist/hearth/control-plane/triggers/acl.d.ts +0 -14
  177. package/dist/hearth/control-plane/triggers/acl.js +0 -52
  178. package/dist/hearth/control-plane/triggers/audit-store.d.ts +0 -38
  179. package/dist/hearth/control-plane/triggers/audit-store.js +0 -79
  180. package/dist/hearth/control-plane/triggers/deliver.d.ts +0 -43
  181. package/dist/hearth/control-plane/triggers/deliver.js +0 -76
  182. package/dist/hearth/control-plane/triggers/envelope.d.ts +0 -29
  183. package/dist/hearth/control-plane/triggers/envelope.js +0 -38
  184. package/dist/hearth/control-plane/types.d.ts +0 -86
  185. package/dist/hearth/control-plane/types.js +0 -1
  186. package/dist/hearth/control-plane/wake.d.ts +0 -86
  187. package/dist/hearth/control-plane/wake.js +0 -550
  188. package/dist/web-client/assets/index-DwO46Cs5.css +0 -2
  189. /package/dist/{core/__tests__/hearth-bootstrap.test.d.ts → commands/__tests__/revive-now-gate.test.d.ts} +0 -0
  190. /package/dist/{core/hearth/__tests__/model-auth-guest.test.d.ts → commands/sys/__tests__/setup-core.test.d.ts} +0 -0
  191. /package/dist/core/{hearth/providers/__tests__/sweep-and-release.test.d.ts → __tests__/fault-classifier.test.d.ts} +0 -0
  192. /package/dist/core/{hearth/providers/types.js → __tests__/host-teardown-process-group.test.d.ts} +0 -0
  193. /package/dist/core/{hearth/types.js → __tests__/review-model-floor.test.d.ts} +0 -0
  194. /package/dist/{hearth/control-plane/__tests__/error-serialization.test.d.ts → core/__tests__/session-cycles.test.d.ts} +0 -0
  195. /package/dist/{hearth/control-plane/__tests__/node-message.test.d.ts → core/__tests__/worktree.test.d.ts} +0 -0
@@ -24,18 +24,23 @@
24
24
  // thing a terminal worker's bearings drop). The prose lives in
25
25
  // core/runtime/bearings.ts (shared with the promotion guidance dump).
26
26
  //
27
- // IDEMPOTENT across resumes, but FORK-AWARE: a `--session` relaunch restores OUR
28
- // conversation (whose bearings name OUR node id), so the session_start handler
29
- // sees it via `sessionManager.getEntries()` and skips it never accumulates. A
30
- // `--fork-from` boot, by contrast, COPIES the source node's whole conversation
31
- // (whose bearings name the SOURCE's node id), so the handler must NOT treat that
32
- // inherited block as ours; it only skips when a bearings block belonging to OUR
33
- // node is already present (exact `details.nodeId` stamp, content-match
34
- // fallback), otherwise it injects ours whose identity assertion (leading the
35
- // <crtr-bearings> block) reasserts the fork's identity over the inherited persona. This is ONE of two reinforcing
36
- // channels: spawn.ts ALSO prepends the same identity assertion to a fork's
37
- // kickoff prompt (the turn-triggering message), so the override does not rest on
38
- // a single trailing custom_message.
27
+ // IDEMPOTENT across resumes, but FORK-AWARE and BRANCH-AWARE: the idempotency
28
+ // scan walks only the ACTIVE BRANCH (root-first from the current leaf), not
29
+ // every entry in the file. A `--session` relaunch that is a true resume keeps
30
+ // the same branch, so the scan finds OUR prior bearings (named by OUR node id)
31
+ // and skips it never accumulates. A post-yield CYCLE roots a fresh branch (the
32
+ // `crtr-cycle` marker), so the scan correctly finds nothing on that fresh branch
33
+ // and injects a new intro, even though an OLDER cycle's intro still sits
34
+ // elsewhere in the same `.jsonl`. A `--fork-from` boot COPIES the source node's
35
+ // whole conversation onto ITS OWN branch (bearings naming the SOURCE's node id,
36
+ // not ours), so the handler must NOT treat that inherited block as ours; it only
37
+ // skips when a bearings block belonging to OUR node is already present on the
38
+ // active branch (exact `details.nodeId` stamp, content-match fallback),
39
+ // otherwise it injects ours — whose identity assertion (leading the
40
+ // <crtr-bearings> block) reasserts the fork's identity over the inherited
41
+ // persona. This is ONE of two reinforcing channels: spawn.ts ALSO prepends the
42
+ // same identity assertion to a fork's kickoff prompt (the turn-triggering
43
+ // message), so the override does not rest on a single trailing custom_message.
39
44
  //
40
45
  // COLLAPSED BY DEFAULT: a `registerMessageRenderer` keyed to our customType
41
46
  // renders the block as a single one-line stub; the full body only appears when
@@ -166,22 +171,28 @@ export function registerCanvasContextIntro(pi) {
166
171
  const nodeId = process.env['CRTR_NODE_ID'];
167
172
  if (nodeId === undefined || nodeId.trim() === '')
168
173
  return; // not a canvas node
169
- // Idempotent on RESUME, but NOT fooled by a FORK. A `--session` relaunch
170
- // restores OUR conversation, whose bearings name OUR node id skip then,
171
- // so the block never accumulates. A `--fork-from` boot instead copies the
172
- // SOURCE node's whole conversation (its bearings name ITS node id, not
173
- // ours), so a naive "any crtr-context present?" check would suppress our
174
- // own intro and let the fork inherit and impersonate — the source. So we
175
- // only skip when a bearings block belonging to OUR node is already present.
176
- // Primary discriminator: the EXACT `details.nodeId` stamp (machine-
174
+ // Branch-aware idempotency: scan only the ACTIVE branch (root-first from
175
+ // the current leaf), not every entry in the file. A post-yield cycle roots a
176
+ // FRESH branch (the crtr-cycle marker), so scanning the whole file would
177
+ // find a PRIOR cycle's intro and wrongly skip injecting this cycle's own
178
+ // the node's first turn would lack its crtr-context bearings entirely.
179
+ // Falls back to a whole-file scan only if the engine doesn't expose
180
+ // getBranch (older/degraded engine). Not fooled by a FORK either way: a
181
+ // `--fork-from` boot copies the source's whole conversation onto ITS OWN
182
+ // branch (bearings naming the SOURCE's node id, not ours), so a naive
183
+ // "any crtr-context present?" check would suppress our own intro and let
184
+ // the fork inherit — and impersonate — the source. So we only skip when a
185
+ // bearings block belonging to OUR node is already present on the scanned
186
+ // branch. Primary discriminator: the EXACT `details.nodeId` stamp (machine-
177
187
  // readable, copied on fork, never sent to the LLM). Fallback: a substring
178
188
  // match on the block text (our id appears in the identity line AND the
179
189
  // context-dir path `…/nodes/<nodeId>/context`) — covers legacy blocks
180
190
  // persisted before the stamp existed. Either match ⇒ this is our own
181
191
  // resume, not an inherited fork block, so skip.
182
- const ours = ctx.sessionManager
183
- .getEntries()
184
- .some((e) => e.type === 'custom_message' &&
192
+ const scan = typeof ctx.sessionManager.getBranch === 'function'
193
+ ? ctx.sessionManager.getBranch()
194
+ : ctx.sessionManager.getEntries();
195
+ const ours = scan.some((e) => e.type === 'custom_message' &&
185
196
  e.customType === CONTEXT_INTRO_CUSTOM_TYPE &&
186
197
  (e.details?.nodeId === nodeId || entryText(e).includes(nodeId)));
187
198
  if (ours)
@@ -314,16 +314,22 @@ export function registerCanvasStophook(pi) {
314
314
  }
315
315
  // Boot / startup / resume / reload / fork → (re)bind this process to its
316
316
  // session id, record our OS pid (the daemon's broker-liveness signal), and
317
- // CONFIRM any pending refresh-yield. Reaching session_start proves a fresh
318
- // engine actually booted, so it is now safe to clear intent='refresh' — a
319
- // refresh shuts the broker down and the daemon relaunches it FRESH, which
320
- // leaves intent='refresh' set until this boot clears it (the only proof the
321
- // relaunch worked; otherwise a failed relaunch would look like a success).
317
+ // CONFIRM any pending refresh-yield / pending cycle. Reaching session_start
318
+ // proves a fresh engine actually booted, so it is now safe to clear
319
+ // intent='refresh' — a refresh shuts the broker down and the daemon
320
+ // relaunches it FRESH, which leaves intent='refresh' set until this boot
321
+ // clears it (the only proof the relaunch worked; otherwise a failed relaunch
322
+ // would look like a success). Clearing `cycle_pending` here is the same
323
+ // proof for reviveNode's cycling-attempt marker (revive.ts) — it is always
324
+ // safe to clear on ANY confirmed boot (cycling, resuming, or fresh), since a
325
+ // pre-session_start crash-retry (crtrd.ts) only needs the flag while boot is
326
+ // still unconfirmed.
322
327
  const existing = getNode(nodeId);
323
328
  // Identity (session id/file) → meta; runtime (pid, intent) → atomic row setters.
324
329
  updateNode(nodeId, {
325
330
  pi_session_id: id,
326
331
  pi_session_file: sessionFile,
332
+ cycle_pending: false,
327
333
  });
328
334
  recordPid(nodeId, process.pid);
329
335
  if (existing?.intent === 'refresh')