create-principles-disciple 1.155.3 → 1.156.0

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 (247) hide show
  1. package/_release/product-identity.json +2 -2
  2. package/codex-adapter/dist/ingestion/pain-receipt-fallback.d.ts +28 -1
  3. package/codex-adapter/dist/ingestion/pain-receipt-fallback.js +53 -17
  4. package/codex-adapter/dist/worker/workspace-worker.js +86 -66
  5. package/codex-adapter/package.json +1 -1
  6. package/console/dist/server/index.d.ts +11 -1
  7. package/console/dist/server/index.js +84 -19
  8. package/console/dist/server/release-handover.d.ts +256 -0
  9. package/console/dist/server/release-handover.js +402 -0
  10. package/console/dist/server/routes/onboarding.js +1 -0
  11. package/console/dist/server/routes/update-transaction.js +37 -3
  12. package/console/dist/server/routes/update.js +21 -1
  13. package/console/dist/server/successor.d.ts +46 -0
  14. package/console/dist/server/successor.js +128 -0
  15. package/console/dist/web/assets/app.css +18 -0
  16. package/console/dist/web/assets/app.js +32 -31
  17. package/console/package.json +1 -1
  18. package/core/dist/runtime/candidate-intake-service.d.ts +1 -1
  19. package/core/dist/runtime/candidate-intake-service.d.ts.map +1 -1
  20. package/core/dist/runtime/candidate-intake-service.js +89 -12
  21. package/core/dist/runtime/candidate-intake-service.js.map +1 -1
  22. package/core/dist/runtime/context-payload.d.ts +11 -0
  23. package/core/dist/runtime/context-payload.d.ts.map +1 -1
  24. package/core/dist/runtime/context-payload.js +27 -0
  25. package/core/dist/runtime/context-payload.js.map +1 -1
  26. package/core/dist/runtime/host-submission-context.d.ts +13 -6
  27. package/core/dist/runtime/host-submission-context.d.ts.map +1 -1
  28. package/core/dist/runtime/host-submission-context.js +77 -8
  29. package/core/dist/runtime/host-submission-context.js.map +1 -1
  30. package/core/dist/runtime/index.d.ts +2 -1
  31. package/core/dist/runtime/index.d.ts.map +1 -1
  32. package/core/dist/runtime/index.js +8 -0
  33. package/core/dist/runtime/index.js.map +1 -1
  34. package/core/dist/runtime/pain-ingress.d.ts +8 -0
  35. package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
  36. package/core/dist/runtime/pain-ingress.js +8 -1
  37. package/core/dist/runtime/pain-ingress.js.map +1 -1
  38. package/core/dist/runtime/pain-recall-read-model.d.ts +72 -0
  39. package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
  40. package/core/dist/runtime/pain-recall-read-model.js +46 -21
  41. package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
  42. package/core/dist/runtime/pain-receipt-recovery.d.ts +4 -1
  43. package/core/dist/runtime/pain-receipt-recovery.d.ts.map +1 -1
  44. package/core/dist/runtime/pain-receipt-recovery.js +28 -10
  45. package/core/dist/runtime/pain-receipt-recovery.js.map +1 -1
  46. package/core/dist/runtime/pain-signal-bridge.d.ts +38 -23
  47. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  48. package/core/dist/runtime/pain-signal-bridge.js +533 -182
  49. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  50. package/core/dist/runtime/pain-signal-runtime-factory.d.ts +8 -1
  51. package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
  52. package/core/dist/runtime/pain-signal-runtime-factory.js +196 -25
  53. package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
  54. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts +78 -4
  55. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts.map +1 -1
  56. package/core/dist/runtime/pain-target-evidence-reconcile.js +229 -18
  57. package/core/dist/runtime/pain-target-evidence-reconcile.js.map +1 -1
  58. package/core/dist/runtime/pain-to-principle-service.d.ts +26 -5
  59. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  60. package/core/dist/runtime/pain-to-principle-service.js +63 -52
  61. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  62. package/core/dist/runtime/store/candidate/admission-document.d.ts +43 -0
  63. package/core/dist/runtime/store/candidate/admission-document.d.ts.map +1 -1
  64. package/core/dist/runtime/store/candidate/admission-document.js +130 -0
  65. package/core/dist/runtime/store/candidate/admission-document.js.map +1 -1
  66. package/core/dist/runtime/store/candidate/candidate-store.d.ts +3 -1
  67. package/core/dist/runtime/store/candidate/candidate-store.d.ts.map +1 -1
  68. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts +2 -1
  69. package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts.map +1 -1
  70. package/core/dist/runtime/store/candidate/memory-candidate-store.js +27 -1
  71. package/core/dist/runtime/store/candidate/memory-candidate-store.js.map +1 -1
  72. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts +2 -1
  73. package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts.map +1 -1
  74. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js +59 -2
  75. package/core/dist/runtime/store/candidate/sqlite-candidate-store.js.map +1 -1
  76. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  77. package/core/dist/runtime/store/context/sqlite-context-assembler.js +18 -3
  78. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  79. package/core/dist/runtime/store/runtime-state-manager.d.ts +2 -1
  80. package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
  81. package/core/dist/runtime/store/runtime-state-manager.js +4 -0
  82. package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
  83. package/core/dist/telemetry-event.d.ts +2 -2
  84. package/core/dist/telemetry-event.d.ts.map +1 -1
  85. package/core/dist/telemetry-event.js +5 -0
  86. package/core/dist/telemetry-event.js.map +1 -1
  87. package/core/package.json +1 -1
  88. package/dist/i18n.d.ts.map +1 -1
  89. package/dist/i18n.js +72 -0
  90. package/dist/i18n.js.map +1 -1
  91. package/dist/index.d.ts +15 -0
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +145 -35
  94. package/dist/index.js.map +1 -1
  95. package/dist/installer.d.ts +149 -9
  96. package/dist/installer.d.ts.map +1 -1
  97. package/dist/installer.js +542 -31
  98. package/dist/installer.js.map +1 -1
  99. package/dist/installers/codex-host-installer.js +1 -1
  100. package/dist/installers/codex-host-installer.js.map +1 -1
  101. package/dist/installers/index.d.ts +10 -0
  102. package/dist/installers/index.d.ts.map +1 -1
  103. package/dist/installers/index.js +4 -0
  104. package/dist/installers/index.js.map +1 -1
  105. package/dist/mvp-config.js +1 -1
  106. package/dist/mvp-config.js.map +1 -1
  107. package/dist/prompts.d.ts +36 -12
  108. package/dist/prompts.d.ts.map +1 -1
  109. package/dist/prompts.js +102 -30
  110. package/dist/prompts.js.map +1 -1
  111. package/dist/service-host-bridge.d.ts +71 -12
  112. package/dist/service-host-bridge.d.ts.map +1 -1
  113. package/dist/service-host-bridge.js +228 -48
  114. package/dist/service-host-bridge.js.map +1 -1
  115. package/dist/service-host-provisioning.d.ts +102 -0
  116. package/dist/service-host-provisioning.d.ts.map +1 -0
  117. package/dist/service-host-provisioning.js +595 -0
  118. package/dist/service-host-provisioning.js.map +1 -0
  119. package/dist/uninstaller.js +1 -1
  120. package/dist/uninstaller.js.map +1 -1
  121. package/dist/update/apply-payload.d.ts +9 -0
  122. package/dist/update/apply-payload.d.ts.map +1 -1
  123. package/dist/update/apply-payload.js +44 -2
  124. package/dist/update/apply-payload.js.map +1 -1
  125. package/dist/update/console-surface.d.ts +2 -1
  126. package/dist/update/console-surface.d.ts.map +1 -1
  127. package/dist/update/console-surface.js +6 -1
  128. package/dist/update/console-surface.js.map +1 -1
  129. package/dist/update/install-layout.d.ts +12 -0
  130. package/dist/update/install-layout.d.ts.map +1 -1
  131. package/dist/update/install-layout.js +49 -7
  132. package/dist/update/install-layout.js.map +1 -1
  133. package/dist/update/release-manager-authority.d.ts +16 -0
  134. package/dist/update/release-manager-authority.d.ts.map +1 -1
  135. package/dist/update/release-manager-authority.js +45 -3
  136. package/dist/update/release-manager-authority.js.map +1 -1
  137. package/dist/update/release-manager.d.ts +8 -3
  138. package/dist/update/release-manager.d.ts.map +1 -1
  139. package/dist/update/release-manager.js +29 -1
  140. package/dist/update/release-manager.js.map +1 -1
  141. package/dist/update/transaction-progress.d.ts +63 -0
  142. package/dist/update/transaction-progress.d.ts.map +1 -0
  143. package/dist/update/transaction-progress.js +207 -0
  144. package/dist/update/transaction-progress.js.map +1 -0
  145. package/dist/utils/env.d.ts +16 -1
  146. package/dist/utils/env.d.ts.map +1 -1
  147. package/dist/utils/env.js +55 -43
  148. package/dist/utils/env.js.map +1 -1
  149. package/host-runtime/dist/diagnostician-auto-run.js +37 -31
  150. package/host-runtime/dist/governance-observation-store.d.ts +38 -0
  151. package/host-runtime/dist/governance-observation-store.js +41 -0
  152. package/host-runtime/dist/governance-trajectory-turn-reader.js +26 -33
  153. package/host-runtime/package.json +1 -1
  154. package/install-layout/dist/background-execution-transition.d.ts +11 -1
  155. package/install-layout/dist/background-execution-transition.js +45 -1
  156. package/install-layout/dist/index.d.ts +3 -3
  157. package/install-layout/dist/index.js +10 -4
  158. package/install-layout/dist/pd-home.d.ts +12 -0
  159. package/install-layout/dist/pd-home.js +6 -1
  160. package/install-layout/package.json +1 -1
  161. package/package.json +7 -7
  162. package/pd-cli/dist/commands/candidate.d.ts +15 -0
  163. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  164. package/pd-cli/dist/commands/candidate.js +449 -93
  165. package/pd-cli/dist/commands/candidate.js.map +1 -1
  166. package/pd-cli/dist/commands/console.d.ts.map +1 -1
  167. package/pd-cli/dist/commands/console.js +10 -0
  168. package/pd-cli/dist/commands/console.js.map +1 -1
  169. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  170. package/pd-cli/dist/commands/diagnose.js +254 -160
  171. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  172. package/pd-cli/dist/commands/intake-outcome-guidance.d.ts +57 -0
  173. package/pd-cli/dist/commands/intake-outcome-guidance.d.ts.map +1 -0
  174. package/pd-cli/dist/commands/intake-outcome-guidance.js +206 -0
  175. package/pd-cli/dist/commands/intake-outcome-guidance.js.map +1 -0
  176. package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -1
  177. package/pd-cli/dist/commands/mcp-probe.js +1 -0
  178. package/pd-cli/dist/commands/mcp-probe.js.map +1 -1
  179. package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
  180. package/pd-cli/dist/commands/pain-record.js +18 -4
  181. package/pd-cli/dist/commands/pain-record.js.map +1 -1
  182. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  183. package/pd-cli/dist/commands/pain-retry.js +91 -21
  184. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  185. package/pd-cli/dist/commands/runtime-uat.d.ts.map +1 -1
  186. package/pd-cli/dist/commands/runtime-uat.js +1 -0
  187. package/pd-cli/dist/commands/runtime-uat.js.map +1 -1
  188. package/pd-cli/dist/commands/service-lifecycle.js +1 -1
  189. package/pd-cli/dist/commands/service-lifecycle.js.map +1 -1
  190. package/pd-cli/dist/commands/service-run-once.d.ts +1 -1
  191. package/pd-cli/dist/commands/service-run-once.d.ts.map +1 -1
  192. package/pd-cli/dist/commands/service-run-once.js +9 -5
  193. package/pd-cli/dist/commands/service-run-once.js.map +1 -1
  194. package/pd-cli/dist/program.d.ts.map +1 -1
  195. package/pd-cli/dist/program.js +14 -3
  196. package/pd-cli/dist/program.js.map +1 -1
  197. package/pd-cli/dist/services/admission-write-gate.d.ts +4 -0
  198. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
  199. package/pd-cli/dist/services/admission-write-gate.js +50 -48
  200. package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
  201. package/pd-cli/dist/services/console-launcher.js +3 -3
  202. package/pd-cli/dist/services/console-launcher.js.map +1 -1
  203. package/pd-cli/dist/services/service-host/managed-run.d.ts.map +1 -1
  204. package/pd-cli/dist/services/service-host/managed-run.js +25 -8
  205. package/pd-cli/dist/services/service-host/managed-run.js.map +1 -1
  206. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts +12 -0
  207. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts.map +1 -1
  208. package/pd-cli/dist/services/service-host/scheduler/service-status.js +16 -7
  209. package/pd-cli/dist/services/service-host/scheduler/service-status.js.map +1 -1
  210. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts +7 -5
  211. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts.map +1 -1
  212. package/pd-cli/dist/services/service-host/status/service-run-status.js +1 -1
  213. package/pd-cli/dist/services/service-host/status/service-run-status.js.map +1 -1
  214. package/pd-cli/package.json +1 -1
  215. package/pd-mcp-server/dist/submit-assembly.js +61 -18
  216. package/pd-mcp-server/dist/version.d.ts +1 -1
  217. package/pd-mcp-server/dist/version.js +1 -1
  218. package/pd-mcp-server/package.json +1 -1
  219. package/plugin/dist/bundle.js +493 -493
  220. package/plugin/dist/openclaw-worker.js +263 -263
  221. package/plugin/dist/openclaw.plugin.json +1 -1
  222. package/plugin/openclaw.plugin.json +1 -1
  223. package/plugin/package.json +1 -1
  224. package/release-manager/dist/i18n.js +72 -0
  225. package/release-manager/dist/installer.js +542 -31
  226. package/release-manager/dist/installers/codex-host-installer.js +1 -1
  227. package/release-manager/dist/installers/index.js +4 -0
  228. package/release-manager/dist/mvp-config.js +1 -1
  229. package/release-manager/dist/service-host-bridge.js +228 -48
  230. package/release-manager/dist/service-host-provisioning.js +595 -0
  231. package/release-manager/dist/update/apply-payload.js +44 -2
  232. package/release-manager/dist/update/console-surface.js +6 -1
  233. package/release-manager/dist/update/install-layout.js +49 -7
  234. package/release-manager/dist/update/release-manager-authority.js +45 -3
  235. package/release-manager/dist/update/release-manager.js +29 -1
  236. package/release-manager/dist/update/transaction-progress.js +207 -0
  237. package/release-manager/dist/utils/env.js +55 -43
  238. package/release-manager/package.json +5 -5
  239. package/workbuddy-adapter/dist/codec/input-decoder.d.ts +21 -0
  240. package/workbuddy-adapter/dist/codec/input-decoder.js +50 -1
  241. package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.d.ts +68 -0
  242. package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.js +225 -0
  243. package/workbuddy-adapter/dist/pd-hook.js +60 -0
  244. package/workbuddy-adapter/dist/worker/workspace-worker.js +46 -44
  245. package/workbuddy-adapter/package.json +1 -1
  246. package/console/dist/server/utils/gateway.d.ts +0 -29
  247. package/console/dist/server/utils/gateway.js +0 -175
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Release handover — a Console never keeps serving a release that is no
3
+ * longer the installed one.
4
+ *
5
+ * An update replaces the runtime on disk and, at its commit point, writes the
6
+ * active release record. The Console process that carried the update is NOT
7
+ * restarted by that: it goes on answering from the code it started with, so
8
+ * the Owner finishes an update, is told "restart the console", and keeps
9
+ * looking at the old version until they do. Every restart path that existed
10
+ * needed the Owner's hand (Ctrl+C, reopening the Companion).
11
+ *
12
+ * This module closes that gap from the inside. While it serves, a Console
13
+ * re-reads the active release record; the moment it names a different release
14
+ * than the one this process started on, the Console starts its own successor
15
+ * on the installed code and, once the successor is serving on the same port,
16
+ * exits. The Owner's tab reloads into the new version with nothing to do.
17
+ *
18
+ * Safety properties, in order of importance:
19
+ * - NEVER leave the port unserved, and never leave it worse than before. This
20
+ * process stops accepting only after the successor exists; if the successor
21
+ * does not answer in time it is STOPPED first — it may be listening already —
22
+ * and only then is the port taken back. This process exits only once a
23
+ * console answers on the port.
24
+ * - The record is the ONLY trigger. It is written after the transaction
25
+ * journal reached `confirmed`, so a failed or rolled-back update (record
26
+ * unchanged) and a mid-flight update (record not yet written) never hand
27
+ * over. A record that cannot be read is not a change.
28
+ * - One handover per change: the watch fires once, then stops.
29
+ * - The successor is a fixed module of the installed build — never a path
30
+ * this process was handed — and its launch line travels over stdin as data.
31
+ * - The successor must not hold the installed runtime open. It works from the
32
+ * directory its launcher was run from, like any console, never from inside
33
+ * the runtime: on Windows a working directory keeps its tree from being
34
+ * renamed, and the next update starts by renaming the runtime away.
35
+ *
36
+ * Two consoles do NOT hand themselves over, and both are decisions about
37
+ * ownership rather than capability:
38
+ *
39
+ * - one the Companion launched. The Companion hands over the console it owns
40
+ * by stopping it and relaunching through its own launcher — the only
41
+ * sequence in which it still owns what comes next. A console that replaced
42
+ * itself underneath it comes back as somebody else's process: its restart
43
+ * ladder then waits for a "new" process that never starts, or adopts the
44
+ * successor as a foreign instance. So here the Companion stays in charge.
45
+ * - one that does not run from the installed runtime (a repository build, a
46
+ * pre-canonical layout). The files an update replaces are not the ones this
47
+ * process runs from, so a successor started beside it would be the same
48
+ * code again — a restart to nowhere.
49
+ *
50
+ * `PD_CONSOLE_RELEASE_HANDOVER=off` disables the watch for one process.
51
+ */
52
+ import * as http from 'node:http';
53
+ import { type ActiveReleaseRecord, type ActiveReleaseVerdict } from '@principles/install-layout';
54
+ /** `off` disables the release watch for this process (the rollback lever). */
55
+ export declare const CONSOLE_RELEASE_HANDOVER_ENV = "PD_CONSOLE_RELEASE_HANDOVER";
56
+ export declare const HANDOVER_BIND_WAIT_MS = 20000;
57
+ export declare const HANDOVER_BIND_RETRY_MS = 250;
58
+ export declare const RELEASE_WATCH_INTERVAL_MS = 2000;
59
+ /** How long the predecessor waits for its successor to answer on the port. */
60
+ export declare const HANDOVER_HEALTHY_TIMEOUT_MS = 20000;
61
+ /** How long to wait for a stopped successor to actually be gone. */
62
+ export declare const HANDOVER_ABANDON_WAIT_MS = 5000;
63
+ /** How long "address in use" is tolerated while the port is taken back. */
64
+ export declare const HANDOVER_RELISTEN_RETRY_MS = 5000;
65
+ /** What identifies "the release this process started on". */
66
+ export interface ReleaseIdentity {
67
+ readonly generation: number;
68
+ readonly releaseId: string;
69
+ }
70
+ export declare function releaseIdentityOf(record: ActiveReleaseRecord): ReleaseIdentity;
71
+ /** True when `current` is a release other than `baseline` — in either direction, a downgrade is a change too. */
72
+ export declare function isReleaseSuperseded(baseline: ReleaseIdentity, current: ActiveReleaseRecord): boolean;
73
+ /**
74
+ * The marker the Companion puts on everything it launches. A Console carrying
75
+ * it was started by the Companion's own launcher, which is what makes the
76
+ * Console "managed" on the Companion side.
77
+ */
78
+ export declare const COMPANION_INVOCATION_SOURCE = "companion";
79
+ export declare function isCompanionLaunched(env: Readonly<Record<string, string | undefined>>): boolean;
80
+ /**
81
+ * Whether this console hands itself over to a new release, and — when it does
82
+ * not — why, in words a log reader can act on (rc-9: never a silent "off").
83
+ * The reasons are ordered by who owns the decision: the Companion that
84
+ * launched this console, the installer's own probe, the operator's switch,
85
+ * and lastly what this process is running from.
86
+ */
87
+ export type ReleaseHandoverDecision = {
88
+ readonly watch: true;
89
+ } | {
90
+ readonly watch: false;
91
+ readonly reason: string;
92
+ };
93
+ /**
94
+ * True when `runningFrom` — the directory this process loaded its server code
95
+ * from — IS the installed Console's. Only then does the successor beside this
96
+ * file belong to the release an update just laid down.
97
+ *
98
+ * Both sides are resolved to their real path: the installed location may be
99
+ * reached through a link, and Node already hands `import.meta.url` as the real
100
+ * path. Anything that cannot be resolved is "not installed" — never a guess.
101
+ */
102
+ export declare function isInstalledConsoleCode(runningFrom: string, installedConsoleDir: string): boolean;
103
+ export declare function decideReleaseHandoverWatch(env: Readonly<Record<string, string | undefined>>, runsInstalledCode: boolean): ReleaseHandoverDecision;
104
+ /**
105
+ * Who switches this console to the new release once an update has activated
106
+ * it. The page asks, because what it should say — and how long it should wait
107
+ * — depends on the answer.
108
+ */
109
+ export type ReleaseHandoverOwner =
110
+ /** This process: it starts a successor on the installed code and exits once that serves. */
111
+ 'console'
112
+ /** The Companion that launched this process: it stops and relaunches the console it owns. */
113
+ | 'companion'
114
+ /** Nobody. The console goes on serving the previous release until it is restarted by hand. */
115
+ | 'manual';
116
+ /**
117
+ * The handover owner of THIS process. `'console'` only while its watch is
118
+ * actually running — not merely entitled to run — so a page told to wait is
119
+ * always waiting for something real.
120
+ */
121
+ export declare function releaseHandoverOwner(env?: Readonly<Record<string, string | undefined>>): ReleaseHandoverOwner;
122
+ export interface ReleaseHandoverWatch {
123
+ stop(): void;
124
+ }
125
+ export interface ReleaseHandoverWatchOptions {
126
+ /** `<pdHome>/active.json` — the installation authority. */
127
+ readonly recordPath: string;
128
+ /** Called at most once, with the record that superseded this process. */
129
+ readonly onSuperseded: (current: ActiveReleaseRecord) => void;
130
+ readonly intervalMs?: number;
131
+ /** Seams (tests); production reads the record through install-layout. */
132
+ readonly readRecord?: (recordPath: string) => ActiveReleaseVerdict;
133
+ readonly log?: (message: string) => void;
134
+ }
135
+ /**
136
+ * Starts re-reading the active release record. Returns null — and watches
137
+ * nothing — when there is no readable record to be the baseline: with no
138
+ * installation there is nothing this process could be stale relative to.
139
+ */
140
+ export declare function startReleaseHandoverWatch(options: ReleaseHandoverWatchOptions): ReleaseHandoverWatch | null;
141
+ /** The part of a forked child the handover needs; tests hand in an EventEmitter with a `pid` and a `kill`. */
142
+ export interface SuccessorProcess {
143
+ readonly pid?: number;
144
+ once(event: 'spawn', listener: () => void): unknown;
145
+ once(event: 'error', listener: (error: Error) => void): unknown;
146
+ once(event: 'exit', listener: () => void): unknown;
147
+ /** Ends the process. Called only ever on the successor THIS process started. */
148
+ kill(): void;
149
+ }
150
+ /** The successor's whole launch line: this process's own command-line arguments. */
151
+ export interface ConsoleSuccessorSpec {
152
+ readonly args: readonly string[];
153
+ }
154
+ export interface SuccessorLaunch {
155
+ /**
156
+ * Where `./successor.js` is resolved from. Production leaves it alone: the
157
+ * build's own directory, which an update has already replaced with the
158
+ * installed release's copy. Tests point at a directory holding a stand-in.
159
+ */
160
+ readonly cwd?: string;
161
+ }
162
+ /**
163
+ * Starts the successor: the installed build's own successor module, detached
164
+ * and unattended so it outlives this process, with the launch line on its
165
+ * stdin. Null when it could not be started — the caller then keeps serving.
166
+ *
167
+ * The directory above only serves to resolve the module path: the successor
168
+ * is told where this process was working and leaves the build's directory at
169
+ * once (see successor.ts). It must not go on working from inside the installed
170
+ * runtime — on Windows a working directory keeps its tree from being renamed,
171
+ * and the next update starts by renaming the runtime away.
172
+ */
173
+ export declare function startConsoleSuccessor(spec: ConsoleSuccessorSpec, log: (message: string) => void, launch?: SuccessorLaunch): SuccessorProcess | null;
174
+ /**
175
+ * The url that asks the console on `port` to name itself. The transaction
176
+ * route answers it from the journal directory alone — no diagnostics, no
177
+ * database — so a console can answer the moment it is listening. `/api/health`
178
+ * cannot serve here: it runs diagnostics with budgets longer than a handover
179
+ * can wait, so a healthy successor would look absent.
180
+ */
181
+ export declare function consoleIdentityUrl(host: string, port: number): string;
182
+ /**
183
+ * The pid of the console answering at `url`, or null when nobody does, the
184
+ * answer is not a console's, or it does not arrive in time. Never rejects.
185
+ */
186
+ export declare function probeConsolePid(url: string, timeoutMs: number): Promise<number | null>;
187
+ export interface ConsoleListenRequest {
188
+ readonly server: http.Server;
189
+ readonly port: number;
190
+ readonly host: string;
191
+ readonly onListening: () => void;
192
+ /** Receives the error that ends the attempts — a port that stays taken, or any other error. */
193
+ readonly giveUp: (error: Error & {
194
+ code?: string;
195
+ }) => void;
196
+ /** How long "address in use" is retried. 0 (the default) means not at all. */
197
+ readonly retryInUseForMs?: number;
198
+ readonly retryMs?: number;
199
+ }
200
+ /**
201
+ * Binds the console. A handover successor boots while its predecessor is
202
+ * still releasing the port, so for it "address in use" means "try again" —
203
+ * but only for a bounded time, after which it is the dead end it always was.
204
+ * Any other error is never retried.
205
+ */
206
+ export interface ConsoleListener {
207
+ /**
208
+ * Binds again after the port was released for a handover, retrying
209
+ * "address in use" for `retryInUseForMs` (a successor that was just stopped
210
+ * may still be letting go). Rejects with the error that ended the attempts.
211
+ * That failure is the handover's to report — it is not the dead end a
212
+ * boot-time bind failure is, so it never reaches `giveUp`.
213
+ */
214
+ relisten(retryInUseForMs: number): Promise<void>;
215
+ }
216
+ export declare function listenWithHandoverRetry(request: ConsoleListenRequest): ConsoleListener;
217
+ export interface ServingWaitOptions {
218
+ readonly intervalMs?: number;
219
+ readonly sleep?: (ms: number) => Promise<void>;
220
+ }
221
+ /**
222
+ * Resolves with the first answer `probe` gives that is not null, or null at
223
+ * the deadline. Never rejects.
224
+ */
225
+ export declare function waitUntilAnswer<T>(probe: () => Promise<T | null>, timeoutMs: number, options?: ServingWaitOptions): Promise<T | null>;
226
+ /**
227
+ * Stops the successor this process started, and resolves once it is gone — or
228
+ * when `waitMs` has passed, whichever comes first: a successor that will not
229
+ * die must not hold this console's decision about its own port for good.
230
+ */
231
+ export declare function stopSuccessor(successor: SuccessorProcess | null, waitMs?: number): Promise<void>;
232
+ export interface ReleaseHandoverDeps {
233
+ readonly startSuccessor: () => SuccessorProcess | null;
234
+ /** Stops accepting connections; in-flight requests still finish. */
235
+ readonly stopAccepting: () => Promise<void>;
236
+ /** The pid of the console answering on the port again, or null at the deadline. */
237
+ readonly waitForSuccessor: () => Promise<number | null>;
238
+ /** Ends the successor this process started, and resolves once it is gone (within a bound). */
239
+ readonly abandonSuccessor: () => Promise<void>;
240
+ /** Binds the port again. Rejects when it cannot be taken back. */
241
+ readonly resumeAccepting: () => Promise<void>;
242
+ /** Ends this process. Called only once the port is someone's — or when it can be nobody's. */
243
+ readonly exit: (code: number) => void;
244
+ readonly log?: (message: string) => void;
245
+ readonly spawnTimeoutMs?: number;
246
+ }
247
+ /**
248
+ * Hands the port over to a successor running the installed release.
249
+ *
250
+ * Every failure keeps this process serving, or leaves it no worse off: a
251
+ * successor that cannot be started is reported and dropped; one that never
252
+ * answers is stopped before the port is taken back — it may be listening
253
+ * already, and binding over a live listener is not possible. The port goes
254
+ * unserved only for the successor's own boot time.
255
+ */
256
+ export declare function performReleaseHandover(deps: ReleaseHandoverDeps): Promise<void>;
@@ -0,0 +1,402 @@
1
+ /**
2
+ * Release handover — a Console never keeps serving a release that is no
3
+ * longer the installed one.
4
+ *
5
+ * An update replaces the runtime on disk and, at its commit point, writes the
6
+ * active release record. The Console process that carried the update is NOT
7
+ * restarted by that: it goes on answering from the code it started with, so
8
+ * the Owner finishes an update, is told "restart the console", and keeps
9
+ * looking at the old version until they do. Every restart path that existed
10
+ * needed the Owner's hand (Ctrl+C, reopening the Companion).
11
+ *
12
+ * This module closes that gap from the inside. While it serves, a Console
13
+ * re-reads the active release record; the moment it names a different release
14
+ * than the one this process started on, the Console starts its own successor
15
+ * on the installed code and, once the successor is serving on the same port,
16
+ * exits. The Owner's tab reloads into the new version with nothing to do.
17
+ *
18
+ * Safety properties, in order of importance:
19
+ * - NEVER leave the port unserved, and never leave it worse than before. This
20
+ * process stops accepting only after the successor exists; if the successor
21
+ * does not answer in time it is STOPPED first — it may be listening already —
22
+ * and only then is the port taken back. This process exits only once a
23
+ * console answers on the port.
24
+ * - The record is the ONLY trigger. It is written after the transaction
25
+ * journal reached `confirmed`, so a failed or rolled-back update (record
26
+ * unchanged) and a mid-flight update (record not yet written) never hand
27
+ * over. A record that cannot be read is not a change.
28
+ * - One handover per change: the watch fires once, then stops.
29
+ * - The successor is a fixed module of the installed build — never a path
30
+ * this process was handed — and its launch line travels over stdin as data.
31
+ * - The successor must not hold the installed runtime open. It works from the
32
+ * directory its launcher was run from, like any console, never from inside
33
+ * the runtime: on Windows a working directory keeps its tree from being
34
+ * renamed, and the next update starts by renaming the runtime away.
35
+ *
36
+ * Two consoles do NOT hand themselves over, and both are decisions about
37
+ * ownership rather than capability:
38
+ *
39
+ * - one the Companion launched. The Companion hands over the console it owns
40
+ * by stopping it and relaunching through its own launcher — the only
41
+ * sequence in which it still owns what comes next. A console that replaced
42
+ * itself underneath it comes back as somebody else's process: its restart
43
+ * ladder then waits for a "new" process that never starts, or adopts the
44
+ * successor as a foreign instance. So here the Companion stays in charge.
45
+ * - one that does not run from the installed runtime (a repository build, a
46
+ * pre-canonical layout). The files an update replaces are not the ones this
47
+ * process runs from, so a successor started beside it would be the same
48
+ * code again — a restart to nowhere.
49
+ *
50
+ * `PD_CONSOLE_RELEASE_HANDOVER=off` disables the watch for one process.
51
+ */
52
+ import { fork } from 'node:child_process';
53
+ import * as fs from 'node:fs';
54
+ import * as http from 'node:http';
55
+ import * as path from 'node:path';
56
+ import { fileURLToPath } from 'node:url';
57
+ import { readActiveReleaseRecord } from '@principles/install-layout';
58
+ /** `off` disables the release watch for this process (the rollback lever). */
59
+ export const CONSOLE_RELEASE_HANDOVER_ENV = 'PD_CONSOLE_RELEASE_HANDOVER';
60
+ export const HANDOVER_BIND_WAIT_MS = 20_000;
61
+ export const HANDOVER_BIND_RETRY_MS = 250;
62
+ export const RELEASE_WATCH_INTERVAL_MS = 2_000;
63
+ /** How long the predecessor waits for its successor to answer on the port. */
64
+ export const HANDOVER_HEALTHY_TIMEOUT_MS = 20_000;
65
+ /** How long to wait for a stopped successor to actually be gone. */
66
+ export const HANDOVER_ABANDON_WAIT_MS = 5_000;
67
+ /** How long "address in use" is tolerated while the port is taken back. */
68
+ export const HANDOVER_RELISTEN_RETRY_MS = 5_000;
69
+ export function releaseIdentityOf(record) {
70
+ return { generation: record.generation, releaseId: record.releaseId };
71
+ }
72
+ /** True when `current` is a release other than `baseline` — in either direction, a downgrade is a change too. */
73
+ export function isReleaseSuperseded(baseline, current) {
74
+ return current.generation !== baseline.generation || current.releaseId !== baseline.releaseId;
75
+ }
76
+ /**
77
+ * The marker the Companion puts on everything it launches. A Console carrying
78
+ * it was started by the Companion's own launcher, which is what makes the
79
+ * Console "managed" on the Companion side.
80
+ */
81
+ export const COMPANION_INVOCATION_SOURCE = 'companion';
82
+ export function isCompanionLaunched(env) {
83
+ return env.PD_INVOCATION_SOURCE === COMPANION_INVOCATION_SOURCE;
84
+ }
85
+ /** Where the build files this module among the Console's (`tsc` mirrors `src/`). */
86
+ const SERVER_OUTPUT_SEGMENTS = ['dist', 'server'];
87
+ /**
88
+ * True when `runningFrom` — the directory this process loaded its server code
89
+ * from — IS the installed Console's. Only then does the successor beside this
90
+ * file belong to the release an update just laid down.
91
+ *
92
+ * Both sides are resolved to their real path: the installed location may be
93
+ * reached through a link, and Node already hands `import.meta.url` as the real
94
+ * path. Anything that cannot be resolved is "not installed" — never a guess.
95
+ */
96
+ export function isInstalledConsoleCode(runningFrom, installedConsoleDir) {
97
+ const real = (target) => {
98
+ try {
99
+ const resolved = fs.realpathSync.native(target);
100
+ return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
101
+ }
102
+ catch {
103
+ return null;
104
+ }
105
+ };
106
+ const running = real(runningFrom);
107
+ const installed = real(path.join(installedConsoleDir, ...SERVER_OUTPUT_SEGMENTS));
108
+ return running !== null && running === installed;
109
+ }
110
+ export function decideReleaseHandoverWatch(env, runsInstalledCode) {
111
+ if (isCompanionLaunched(env)) {
112
+ return { watch: false, reason: 'the Companion relaunches this console after an update' };
113
+ }
114
+ // The installer's verification probe is killed right after it answers; a
115
+ // handover from inside it would leave a stray Console on a probe port.
116
+ if (env.PD_CONSOLE_VERIFY_NONCE !== undefined) {
117
+ return { watch: false, reason: 'installer verification probe' };
118
+ }
119
+ if (env[CONSOLE_RELEASE_HANDOVER_ENV] === 'off') {
120
+ return { watch: false, reason: `disabled by ${CONSOLE_RELEASE_HANDOVER_ENV}=off` };
121
+ }
122
+ if (!runsInstalledCode) {
123
+ return { watch: false, reason: 'not the installed console — a restart would bring back the same code' };
124
+ }
125
+ return { watch: true };
126
+ }
127
+ let watchArmed = false;
128
+ /**
129
+ * The handover owner of THIS process. `'console'` only while its watch is
130
+ * actually running — not merely entitled to run — so a page told to wait is
131
+ * always waiting for something real.
132
+ */
133
+ export function releaseHandoverOwner(env = process.env) {
134
+ if (watchArmed)
135
+ return 'console';
136
+ return isCompanionLaunched(env) ? 'companion' : 'manual';
137
+ }
138
+ /**
139
+ * Starts re-reading the active release record. Returns null — and watches
140
+ * nothing — when there is no readable record to be the baseline: with no
141
+ * installation there is nothing this process could be stale relative to.
142
+ */
143
+ export function startReleaseHandoverWatch(options) {
144
+ const read = options.readRecord ?? readActiveReleaseRecord;
145
+ const log = options.log ?? ((message) => console.log(message));
146
+ const baseline = read(options.recordPath);
147
+ if (!baseline.ok) {
148
+ log(`[pd-console] Release handover watch not started (${baseline.reason}): ${baseline.detail}`);
149
+ return null;
150
+ }
151
+ const identity = releaseIdentityOf(baseline.record);
152
+ const timer = setInterval(() => {
153
+ const current = read(options.recordPath);
154
+ if (!current.ok || !isReleaseSuperseded(identity, current.record))
155
+ return;
156
+ clearInterval(timer);
157
+ // One handover per change: having fired, this process is no longer waiting
158
+ // for anything — should the handover be called off, it is a plain console.
159
+ watchArmed = false;
160
+ options.onSuperseded(current.record);
161
+ }, options.intervalMs ?? RELEASE_WATCH_INTERVAL_MS);
162
+ // A watch must never be what keeps a Console alive.
163
+ timer.unref?.();
164
+ watchArmed = true;
165
+ return {
166
+ stop: () => {
167
+ clearInterval(timer);
168
+ watchArmed = false;
169
+ },
170
+ };
171
+ }
172
+ /**
173
+ * Starts the successor: the installed build's own successor module, detached
174
+ * and unattended so it outlives this process, with the launch line on its
175
+ * stdin. Null when it could not be started — the caller then keeps serving.
176
+ *
177
+ * The directory above only serves to resolve the module path: the successor
178
+ * is told where this process was working and leaves the build's directory at
179
+ * once (see successor.ts). It must not go on working from inside the installed
180
+ * runtime — on Windows a working directory keeps its tree from being renamed,
181
+ * and the next update starts by renaming the runtime away.
182
+ */
183
+ export function startConsoleSuccessor(spec, log, launch = {}) {
184
+ const buildDirectory = path.dirname(fileURLToPath(import.meta.url));
185
+ try {
186
+ const child = fork('./successor.js', [], {
187
+ cwd: launch.cwd ?? buildDirectory,
188
+ // stdin carries the launch line; the successor has no terminal to talk
189
+ // to. `fork` insists on an IPC channel — the successor closes it as soon
190
+ // as it has read its configuration, so it outlives this process.
191
+ stdio: ['pipe', 'ignore', 'ignore', 'ipc'],
192
+ detached: true,
193
+ windowsHide: true,
194
+ });
195
+ child.stdin?.end(`${JSON.stringify({ args: spec.args, cwd: process.cwd() })}\n`);
196
+ child.unref();
197
+ return child;
198
+ }
199
+ catch (error) {
200
+ log(`[pd-console] Could not start the successor console: ${error instanceof Error ? error.message : String(error)}`);
201
+ return null;
202
+ }
203
+ }
204
+ /** A transaction id that names no transaction: it only asks the console to identify itself (it matches the route's id pattern). */
205
+ const IDENTITY_PROBE_ID = 'handover-identity-probe';
206
+ /**
207
+ * The url that asks the console on `port` to name itself. The transaction
208
+ * route answers it from the journal directory alone — no diagnostics, no
209
+ * database — so a console can answer the moment it is listening. `/api/health`
210
+ * cannot serve here: it runs diagnostics with budgets longer than a handover
211
+ * can wait, so a healthy successor would look absent.
212
+ */
213
+ export function consoleIdentityUrl(host, port) {
214
+ const authority = host.includes(':') ? `[${host}]:${port}` : `${host}:${port}`;
215
+ return `http://${authority}/api/update/transaction/${IDENTITY_PROBE_ID}`;
216
+ }
217
+ const IDENTITY_BODY_LIMIT = 4096;
218
+ /**
219
+ * The pid of the console answering at `url`, or null when nobody does, the
220
+ * answer is not a console's, or it does not arrive in time. Never rejects.
221
+ */
222
+ export function probeConsolePid(url, timeoutMs) {
223
+ return new Promise((resolve) => {
224
+ let settled = false;
225
+ const finish = (pid) => {
226
+ if (settled)
227
+ return;
228
+ settled = true;
229
+ resolve(pid);
230
+ };
231
+ const request = http.get(url, (response) => {
232
+ response.on('error', () => finish(null));
233
+ response.on('close', () => finish(null));
234
+ if (response.statusCode !== 200) {
235
+ response.resume();
236
+ finish(null);
237
+ return;
238
+ }
239
+ let body = '';
240
+ response.setEncoding('utf8');
241
+ response.on('data', (chunk) => {
242
+ body += chunk;
243
+ // Bounded (rc-8): an answer this long is not the one-line fact asked for.
244
+ if (body.length > IDENTITY_BODY_LIMIT)
245
+ request.destroy();
246
+ });
247
+ response.on('end', () => {
248
+ let pid;
249
+ try {
250
+ const value = JSON.parse(body);
251
+ const data = typeof value === 'object' && value !== null ? Reflect.get(value, 'data') : undefined;
252
+ pid = typeof data === 'object' && data !== null ? Reflect.get(data, 'serverPid') : undefined;
253
+ }
254
+ catch {
255
+ pid = undefined;
256
+ }
257
+ finish(typeof pid === 'number' && Number.isSafeInteger(pid) && pid > 0 ? pid : null);
258
+ });
259
+ });
260
+ request.setTimeout(timeoutMs, () => {
261
+ request.destroy();
262
+ finish(null);
263
+ });
264
+ request.on('error', () => finish(null));
265
+ });
266
+ }
267
+ export function listenWithHandoverRetry(request) {
268
+ const { server, port, host, onListening, giveUp } = request;
269
+ const retryMs = request.retryMs ?? HANDOVER_BIND_RETRY_MS;
270
+ let retryUntil = Date.now() + (request.retryInUseForMs ?? 0);
271
+ /** Set while a `relisten` is pending: a bind failure then is reported there. */
272
+ let pendingRelisten = null;
273
+ server.on('listening', onListening);
274
+ server.on('error', (error) => {
275
+ if (error.code === 'EADDRINUSE' && Date.now() < retryUntil) {
276
+ // Ref'd on purpose: until the port is theirs, this retry is what keeps a
277
+ // successor alive.
278
+ setTimeout(() => { server.listen(port, host); }, retryMs);
279
+ return;
280
+ }
281
+ const reject = pendingRelisten;
282
+ pendingRelisten = null;
283
+ if (reject !== null) {
284
+ reject(error);
285
+ return;
286
+ }
287
+ giveUp(error);
288
+ });
289
+ server.listen(port, host);
290
+ return {
291
+ relisten: (retryInUseForMs) => new Promise((resolve, reject) => {
292
+ pendingRelisten = reject;
293
+ retryUntil = Date.now() + retryInUseForMs;
294
+ server.once('listening', () => {
295
+ pendingRelisten = null;
296
+ resolve();
297
+ });
298
+ server.listen(port, host);
299
+ }),
300
+ };
301
+ }
302
+ /**
303
+ * Resolves with the first answer `probe` gives that is not null, or null at
304
+ * the deadline. Never rejects.
305
+ */
306
+ export async function waitUntilAnswer(probe, timeoutMs, options = {}) {
307
+ const intervalMs = options.intervalMs ?? HANDOVER_BIND_RETRY_MS;
308
+ const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
309
+ const deadline = Date.now() + timeoutMs;
310
+ for (;;) {
311
+ const answer = await probe();
312
+ if (answer !== null)
313
+ return answer;
314
+ if (Date.now() >= deadline)
315
+ return null;
316
+ await sleep(Math.min(intervalMs, Math.max(0, deadline - Date.now())));
317
+ }
318
+ }
319
+ /**
320
+ * Stops the successor this process started, and resolves once it is gone — or
321
+ * when `waitMs` has passed, whichever comes first: a successor that will not
322
+ * die must not hold this console's decision about its own port for good.
323
+ */
324
+ export async function stopSuccessor(successor, waitMs = HANDOVER_ABANDON_WAIT_MS) {
325
+ if (successor === null)
326
+ return;
327
+ const gone = new Promise((resolve) => { successor.once('exit', () => resolve()); });
328
+ successor.kill();
329
+ await Promise.race([gone, new Promise((resolve) => { setTimeout(resolve, waitMs); })]);
330
+ }
331
+ /**
332
+ * Hands the port over to a successor running the installed release.
333
+ *
334
+ * Every failure keeps this process serving, or leaves it no worse off: a
335
+ * successor that cannot be started is reported and dropped; one that never
336
+ * answers is stopped before the port is taken back — it may be listening
337
+ * already, and binding over a live listener is not possible. The port goes
338
+ * unserved only for the successor's own boot time.
339
+ */
340
+ export async function performReleaseHandover(deps) {
341
+ const log = deps.log ?? ((message) => console.log(message));
342
+ const keepServing = (why) => {
343
+ log(`[pd-console] Release handover skipped — this console keeps serving (${why}).`);
344
+ };
345
+ let successor;
346
+ try {
347
+ successor = deps.startSuccessor();
348
+ }
349
+ catch (error) {
350
+ keepServing(`successor could not be started: ${error instanceof Error ? error.message : String(error)}`);
351
+ return;
352
+ }
353
+ if (successor === null) {
354
+ keepServing('successor could not be started');
355
+ return;
356
+ }
357
+ let spawned = false;
358
+ const created = await new Promise((resolve) => {
359
+ const timer = setTimeout(() => resolve(false), deps.spawnTimeoutMs ?? 10_000);
360
+ successor?.once('error', (error) => {
361
+ clearTimeout(timer);
362
+ if (spawned) {
363
+ // Still this process's child (it is stopped below if it never
364
+ // answers), so it can still report — but the handover is under way.
365
+ log(`[pd-console] The successor reported an error after it started: ${error.message}`);
366
+ return;
367
+ }
368
+ keepServing(`successor failed to start: ${error.message}`);
369
+ resolve(false);
370
+ });
371
+ successor?.once('spawn', () => {
372
+ spawned = true;
373
+ clearTimeout(timer);
374
+ resolve(true);
375
+ });
376
+ });
377
+ if (!created)
378
+ return;
379
+ log(`[pd-console] Installed release changed — handing over to the new release (successor pid ${successor.pid}).`);
380
+ await deps.stopAccepting();
381
+ const serving = await deps.waitForSuccessor();
382
+ if (serving !== null) {
383
+ // Said plainly, because in a terminal this is the moment `pd console open`
384
+ // returns to the prompt: the console did not stop, it moved. Whoever
385
+ // answers was started after the release changed, so it runs the new code.
386
+ const who = serving === successor.pid ? 'The successor console' : `Another console`;
387
+ log(`[pd-console] ${who} (pid ${serving}) is serving on the new release; this console exits.`);
388
+ deps.exit(0);
389
+ return;
390
+ }
391
+ log('[pd-console] Successor did not come up in time — stopping it and taking the port back.');
392
+ await deps.abandonSuccessor();
393
+ try {
394
+ await deps.resumeAccepting();
395
+ }
396
+ catch (error) {
397
+ log(`[pd-console] Could not take the port back: ${error instanceof Error ? error.message : String(error)}`);
398
+ deps.exit(1);
399
+ return;
400
+ }
401
+ log('[pd-console] Port taken back — this console keeps serving the previous release, and will not hand itself over again before it is restarted.');
402
+ }
@@ -161,6 +161,7 @@ async function handleRunDemo(res, _workspaceDir) {
161
161
  child = spawn(cmd, [...extraArgs, 'demo', 'story-a', '--workspace', tempWorkspace, '--json'], {
162
162
  stdio: ['pipe', 'pipe', 'pipe'],
163
163
  // No shell:true — argv is passed directly to the OS.
164
+ windowsHide: true,
164
165
  });
165
166
  }
166
167
  catch (err) {