@hearsay-tools/squawk 0.18.0-dev.5863 → 0.18.0-dev.5876

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 (189) hide show
  1. package/README.md +5 -14
  2. package/dist/ci-wait/controller.d.ts +4 -4
  3. package/dist/ci-wait/tools.d.ts +4 -4
  4. package/dist/cli-dispatch.d.ts +0 -3
  5. package/dist/cli-dispatch.js +3 -23
  6. package/dist/cli-dispatch.js.map +1 -1
  7. package/dist/contract/health.d.ts +0 -12
  8. package/dist/contract/index.d.ts +0 -2
  9. package/dist/contract/index.js +1965 -2102
  10. package/dist/{self-update/supervisor.js → desktop-supervisor.js} +2 -2
  11. package/dist/desktop-supervisor.js.map +1 -0
  12. package/dist/home/entry.d.ts +1 -1
  13. package/dist/home/entry.js +1 -1
  14. package/dist/home/entry.js.map +1 -1
  15. package/dist/home/home.d.ts +1 -4
  16. package/dist/home/home.js +1 -5
  17. package/dist/home/home.js.map +1 -1
  18. package/dist/home/migrate.js +4 -4
  19. package/dist/home/migrate.js.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/managed-install/launcher.d.ts +14 -0
  23. package/dist/{self-update → managed-install}/launcher.js +8 -43
  24. package/dist/managed-install/launcher.js.map +1 -0
  25. package/dist/managed-install/layout.d.ts +35 -0
  26. package/dist/managed-install/layout.js +43 -0
  27. package/dist/managed-install/layout.js.map +1 -0
  28. package/dist/runs/run-exits.d.ts +301 -301
  29. package/dist/runs/store.d.ts +72 -72
  30. package/dist/serve-boot.d.ts +1 -19
  31. package/dist/serve-boot.js +1 -44
  32. package/dist/serve-boot.js.map +1 -1
  33. package/dist/serve-command.d.ts +2 -4
  34. package/dist/serve-command.js +7 -11
  35. package/dist/serve-command.js.map +1 -1
  36. package/dist/server/live-routes.d.ts +6 -6
  37. package/dist/server/server.d.ts +3 -347
  38. package/dist/server/server.js +1 -60
  39. package/dist/server/server.js.map +1 -1
  40. package/dist/server/workspace-live-routes.d.ts +6 -6
  41. package/dist/voice/routes.d.ts +19 -19
  42. package/dist/workspace/config.d.ts +0 -5
  43. package/dist/workspace/config.js +0 -4
  44. package/dist/workspace/config.js.map +1 -1
  45. package/package.json +4 -4
  46. package/web/dist/assets/activity-motion-Dj3dlCYS.js +2 -0
  47. package/web/dist/assets/{activity-route-1OFUVP3A.js → activity-route-CpjbEhk_.js} +1 -1
  48. package/web/dist/assets/{alert-dialog-Dj464rjk.js → alert-dialog-h-3h9B4l.js} +1 -1
  49. package/web/dist/assets/button-CS5tOblf.js +3 -0
  50. package/web/dist/assets/{centered-state-DGyy0SuA.js → centered-state-BmsqxbI8.js} +1 -1
  51. package/web/dist/assets/commit-diff-panel-DGx2t9Pw.js +1 -0
  52. package/web/dist/assets/{control-locations-C9II3kPz.js → control-locations-CD2r0mMU.js} +1 -1
  53. package/web/dist/assets/{diff-controls-BR2uqhwG.js → diff-controls-BHF0Pvdc.js} +1 -1
  54. package/web/dist/assets/diff-qq2vW6Xc.js +3 -0
  55. package/web/dist/assets/{diff-view-BBhxSIlf.js → diff-view-wanjAW5U.js} +5 -5
  56. package/web/dist/assets/{dropdown-menu-DhrBcVgr.js → dropdown-menu-CjLqyqwB.js} +1 -1
  57. package/web/dist/assets/{es2015-D345RR4o.js → es2015-CX0rgbM5.js} +1 -1
  58. package/web/dist/assets/file-preview-YiP5f666.js +2 -0
  59. package/web/dist/assets/format-BNCkW110.js +1 -0
  60. package/web/dist/assets/git-toolbar-D0mTYtOj.js +1 -0
  61. package/web/dist/assets/github-DizdAh0y.js +1 -0
  62. package/web/dist/assets/{global-activity-route-Dt83uvZc.js → global-activity-route-DMbPEZPP.js} +1 -1
  63. package/web/dist/assets/{image-preview-Cq1vDiEo.js → image-preview-Dy3o8upo.js} +1 -1
  64. package/web/dist/assets/index-9YmaiQ1k.css +1 -0
  65. package/web/dist/assets/index-D51Su-nT.js +34 -0
  66. package/web/dist/assets/{live-refetch-BdnmTJ_8.js → live-refetch-C2xZHKkJ.js} +1 -1
  67. package/web/dist/assets/{nav-row-styles-BZUUavOF.js → nav-row-styles-CEA9c88Q.js} +1 -1
  68. package/web/dist/assets/play-CmVAj_fu.js +1 -0
  69. package/web/dist/assets/popover-s-Wchzjn.js +1 -0
  70. package/web/dist/assets/preview-pane-connected-DQYoGd9W.js +3 -0
  71. package/web/dist/assets/{project-router-MMOk9VbW.js → project-router-BLO2IxbU.js} +1 -1
  72. package/web/dist/assets/project-scope-context-DbO9a0ii.js +4 -0
  73. package/web/dist/assets/queries-C_DEjjv2.js +1 -0
  74. package/web/dist/assets/repo-git-CSTwuYJ5.js +1 -0
  75. package/web/dist/assets/report-reader-B8D_6si1.js +1 -0
  76. package/web/dist/assets/reports-Dr312nK-.js +1 -0
  77. package/web/dist/assets/run-header-B8M6-fvb.js +2 -0
  78. package/web/dist/assets/skills-Bz-itxvq.js +1 -0
  79. package/web/dist/assets/{tab-link-BvoGfK8S.js → tab-link-CqVqRhuM.js} +1 -1
  80. package/web/dist/assets/task-changes-6F8fNE6I.js +1 -0
  81. package/web/dist/assets/task-commits-1TKZD8tP.js +1 -0
  82. package/web/dist/assets/task-files-BitTchRw.js +1 -0
  83. package/web/dist/assets/{task-github-item-npfGLu9C.js → task-github-item-ux8yQOHs.js} +1 -1
  84. package/web/dist/assets/{task-thread-DnpkXb5P.js → task-thread-DAnwO8BU.js} +7 -7
  85. package/web/dist/assets/thread-state-COdb27sX.js +4 -0
  86. package/web/dist/assets/{toaster-B1MyeHiE.js → toaster-CRVRHlMR.js} +1 -1
  87. package/web/dist/assets/use-hand-to-agent-state-CZK9cWMq.js +1 -0
  88. package/web/dist/assets/{useInfiniteQuery-BbYMWe23.js → useInfiniteQuery-DCWsxLiy.js} +1 -1
  89. package/web/dist/assets/useQuery-C2HBIY3e.js +1 -0
  90. package/web/dist/assets/workflows-CNnPn5Zx.js +7 -0
  91. package/web/dist/assets/ws-BXdlGFIZ.js +1 -0
  92. package/web/dist/assets/{zoomable-image-5pOUaPEg.js → zoomable-image-UzXCYU7Z.js} +1 -1
  93. package/web/dist/index.html +21 -26
  94. package/dist/application-update/bin-recovery.d.ts +0 -5
  95. package/dist/application-update/bin-recovery.js +0 -96
  96. package/dist/application-update/bin-recovery.js.map +0 -1
  97. package/dist/application-update/discovery.d.ts +0 -23
  98. package/dist/application-update/discovery.js +0 -139
  99. package/dist/application-update/discovery.js.map +0 -1
  100. package/dist/application-update/helper.d.ts +0 -58
  101. package/dist/application-update/helper.js +0 -363
  102. package/dist/application-update/helper.js.map +0 -1
  103. package/dist/application-update/launcher.d.ts +0 -12
  104. package/dist/application-update/launcher.js +0 -61
  105. package/dist/application-update/launcher.js.map +0 -1
  106. package/dist/application-update/lock.d.ts +0 -4
  107. package/dist/application-update/lock.js +0 -70
  108. package/dist/application-update/lock.js.map +0 -1
  109. package/dist/application-update/npm-process.d.ts +0 -17
  110. package/dist/application-update/npm-process.js +0 -156
  111. package/dist/application-update/npm-process.js.map +0 -1
  112. package/dist/application-update/runtime-layout.d.ts +0 -20
  113. package/dist/application-update/runtime-layout.js +0 -91
  114. package/dist/application-update/runtime-layout.js.map +0 -1
  115. package/dist/application-update/scoped-recovery.d.ts +0 -32
  116. package/dist/application-update/scoped-recovery.js +0 -210
  117. package/dist/application-update/scoped-recovery.js.map +0 -1
  118. package/dist/application-update/service.d.ts +0 -86
  119. package/dist/application-update/service.js +0 -523
  120. package/dist/application-update/service.js.map +0 -1
  121. package/dist/contract/application-update.d.ts +0 -32
  122. package/dist/contract/self-update.d.ts +0 -255
  123. package/dist/self-update/checkouts.d.ts +0 -46
  124. package/dist/self-update/checkouts.js +0 -284
  125. package/dist/self-update/checkouts.js.map +0 -1
  126. package/dist/self-update/cli.d.ts +0 -19
  127. package/dist/self-update/cli.js +0 -243
  128. package/dist/self-update/cli.js.map +0 -1
  129. package/dist/self-update/installer.d.ts +0 -24
  130. package/dist/self-update/installer.js +0 -139
  131. package/dist/self-update/installer.js.map +0 -1
  132. package/dist/self-update/launcher.d.ts +0 -30
  133. package/dist/self-update/launcher.js.map +0 -1
  134. package/dist/self-update/layout.d.ts +0 -108
  135. package/dist/self-update/layout.js +0 -276
  136. package/dist/self-update/layout.js.map +0 -1
  137. package/dist/self-update/pulls.d.ts +0 -30
  138. package/dist/self-update/pulls.js +0 -128
  139. package/dist/self-update/pulls.js.map +0 -1
  140. package/dist/self-update/registry.d.ts +0 -37
  141. package/dist/self-update/registry.js +0 -86
  142. package/dist/self-update/registry.js.map +0 -1
  143. package/dist/self-update/restart.d.ts +0 -25
  144. package/dist/self-update/restart.js +0 -79
  145. package/dist/self-update/restart.js.map +0 -1
  146. package/dist/self-update/semver.d.ts +0 -19
  147. package/dist/self-update/semver.js +0 -79
  148. package/dist/self-update/semver.js.map +0 -1
  149. package/dist/self-update/service.d.ts +0 -115
  150. package/dist/self-update/service.js +0 -332
  151. package/dist/self-update/service.js.map +0 -1
  152. package/dist/self-update/supervisor.js.map +0 -1
  153. package/dist/server/self-update-routes.d.ts +0 -308
  154. package/dist/server/self-update-routes.js +0 -80
  155. package/dist/server/self-update-routes.js.map +0 -1
  156. package/web/dist/assets/activity-motion-BdGFmrw-.js +0 -2
  157. package/web/dist/assets/agent-accounts-f1cxwgfz.js +0 -18
  158. package/web/dist/assets/button-CHUAMTHK.js +0 -3
  159. package/web/dist/assets/commit-diff-panel-BiNPMHC6.js +0 -1
  160. package/web/dist/assets/diff-BHwQUS2W.js +0 -3
  161. package/web/dist/assets/file-preview-D08Kq15E.js +0 -2
  162. package/web/dist/assets/git-toolbar-BnOaO_OH.js +0 -1
  163. package/web/dist/assets/github-CXc8nroh.js +0 -1
  164. package/web/dist/assets/github-sidebar-model-B0Ufci5S.js +0 -1
  165. package/web/dist/assets/index-B18AqW0Z.css +0 -1
  166. package/web/dist/assets/index-B5LayM4y.js +0 -14
  167. package/web/dist/assets/loader-circle-CZkGEdoI.js +0 -1
  168. package/web/dist/assets/markdown-D7DUNWcJ.js +0 -6
  169. package/web/dist/assets/popover-DRcRI46x.js +0 -1
  170. package/web/dist/assets/preview-pane-connected-JHeCgq7I.js +0 -3
  171. package/web/dist/assets/project-scope-context-B3M-u8R0.js +0 -4
  172. package/web/dist/assets/queries-DORTKwyN.js +0 -1
  173. package/web/dist/assets/repo-git-wEXDON29.js +0 -1
  174. package/web/dist/assets/report-reader-DJ_0htSx.js +0 -1
  175. package/web/dist/assets/reports-BIXmTBFJ.js +0 -1
  176. package/web/dist/assets/run-header-Bgtlx-vc.js +0 -2
  177. package/web/dist/assets/skills-BJ2nSfyr.js +0 -1
  178. package/web/dist/assets/skills-DFBiAuJG.js +0 -1
  179. package/web/dist/assets/skills-workflows-C21NystW.css +0 -1
  180. package/web/dist/assets/task-changes-Dz0udwrE.js +0 -1
  181. package/web/dist/assets/task-commits-5uILgm5M.js +0 -1
  182. package/web/dist/assets/task-files-DGZjTKSS.js +0 -1
  183. package/web/dist/assets/textarea-DlVUfdWG.js +0 -1
  184. package/web/dist/assets/thread-state-BfrO2t7g.js +0 -4
  185. package/web/dist/assets/use-hand-to-agent-state-DyVB4IBv.js +0 -1
  186. package/web/dist/assets/useQuery-CqqnAJvu.js +0 -1
  187. package/web/dist/assets/workflows-ByduCwgu.js +0 -7
  188. package/web/dist/assets/ws-BtSVmivO.js +0 -1
  189. /package/dist/{self-update/supervisor.d.ts → desktop-supervisor.d.ts} +0 -0
@@ -1,79 +0,0 @@
1
- import { productName } from '../home/display.js';
2
- import { shellProductEnv, productEnvEntries } from '../core/product-env.js';
3
- /**
4
- * How a cockpit comes back after an update. Two modes:
5
- *
6
- * reexec the default from a terminal: close the listener, spawn the ACTIVE entry (which,
7
- * after `activate`, is the new version) detached with the same argv, and exit. The
8
- * child inherits the terminal so its banner lands where the old one did; the port is
9
- * pinned so the browser's origin keeps working.
10
- * supervisor `CEZ_SUPERVISED=1` (the desktop shell, a systemd/launchd unit): just exit with
11
- * `RESTART_EXIT_CODE` — the supervisor relaunches through the launcher, which
12
- * resolves `current` afresh. Re-exec'ing under a supervisor would orphan the child
13
- * from the process the supervisor watches.
14
- *
15
- * Running agents are child processes of this one and die with it; boot recovery (open-mercato/cezar#367) re-queues
16
- * or resumes their runs on the next start. The dialog warns before that happens.
17
- */
18
- import { spawnDetached } from '../detached-process.js';
19
- /** Exit status meaning "relaunch me" to a supervisor. 75 is EX_TEMPFAIL — retry later. */
20
- export const RESTART_EXIT_CODE = 75;
21
- export function isSupervised(env = process.env) {
22
- return shellProductEnv('SUPERVISED', env) === '1' || shellProductEnv('DESKTOP', env) === '1';
23
- }
24
- /** Build the child argv: the same command and flags, the port pinned, no second browser tab. */
25
- export function restartArgs(args, port) {
26
- const kept = [];
27
- for (let i = 0; i < args.length; i++) {
28
- const arg = args[i];
29
- if (arg === '-p' || arg === '--port') {
30
- i++;
31
- continue;
32
- }
33
- if (arg.startsWith('--port=') || arg.startsWith('-p='))
34
- continue;
35
- if (arg === '--no-open')
36
- continue;
37
- kept.push(arg);
38
- }
39
- return [...kept, '--port', String(port), '--no-open'];
40
- }
41
- /** A restart marker belongs to this process; an inherited alias cannot shadow it. */
42
- export function restartEnv(source = process.env, rebrand) {
43
- const kept = Object.fromEntries(Object.entries(source).filter(([name]) => !/^(CEZ|HSQ)_RESTARTED_FROM$/i.test(name)));
44
- return { ...kept, ...productEnvEntries('RESTARTED_FROM', process.pid.toString(), rebrand) };
45
- }
46
- export function restartProcess(opts) {
47
- let started = false;
48
- const done = () => {
49
- if (started)
50
- return;
51
- started = true;
52
- if (opts.supervised) {
53
- process.exit(RESTART_EXIT_CODE);
54
- }
55
- const entry = opts.entry;
56
- // The replacement cockpit outlives this process and is never stopped by it.
57
- const child = spawnDetached(process.execPath, [...process.execArgv, entry, ...restartArgs(opts.args, opts.port)], {
58
- stdio: 'inherit',
59
- cwd: process.cwd(),
60
- env: restartEnv(opts.env, opts.rebrand),
61
- });
62
- child.on('error', (error) => {
63
- console.error(`${productName('cezar')}: restart failed — ${error.message}`);
64
- process.exit(1);
65
- });
66
- child.unref();
67
- // Give the spawn a beat to fail loudly before we go; the child binds the port only after the
68
- // listener below is gone, which `close()` guarantees before `done` ran.
69
- setTimeout(() => process.exit(0), 300);
70
- };
71
- if (!opts.server)
72
- return done();
73
- // SSE and WebSocket clients hold the listener open indefinitely — drop them first.
74
- opts.server.closeAllConnections?.();
75
- opts.server.close(() => done());
76
- // A listener that refuses to close (a stuck upgrade) must not pin the old version forever.
77
- setTimeout(done, 3_000).unref();
78
- }
79
- //# sourceMappingURL=restart.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"restart.js","sourceRoot":"","sources":["../../src/self-update/restart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC5E;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AASvD,0FAA0F;AAC1F,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAcpC,MAAM,UAAU,YAAY,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG;IAC/D,OAAO,eAAe,CAAC,YAAY,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,eAAe,CAAC,SAAS,EAAE,GAAG,CAAC,KAAK,GAAG,CAAC;AAC/F,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,WAAW,CAAC,IAAc,EAAE,IAAY;IACtD,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;QACrB,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YACrC,CAAC,EAAE,CAAC;YACJ,SAAS;QACX,CAAC;QACD,IAAI,GAAG,CAA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AAC,IAAI,CAAC,CAAC,EAAE;YAChH,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;YAClB,GAAG,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC;SACxC,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC1B,OAAO,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,sBAAsB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAC5E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,6FAA6F;QAC7F,wEAAwE;QACxE,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACzC,CAAC,CAAC;IACF,IAAI,CAAC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,EAAE,CAAC;IAChC,mFAAmF;IACnF,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,EAAE,CAAC;IACpC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;IAChC,2FAA2F;IAC3F,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC;AAClC,CAAC"}
@@ -1,19 +0,0 @@
1
- /**
2
- * The little semver the self-updater needs — dependency-free on purpose (the CLI's runtime deps
3
- * are six packages and this is not worth a seventh). Handles what cezar publishes:
4
- * `0.11.1`, `0.11.1-nightly.20260924.49`, `0.9.2-pr743.1156.2`, `0.1.5-develop.124`.
5
- */
6
- export type VersionChannel = 'stable' | 'nightly' | 'preview';
7
- export interface ParsedVersion {
8
- core: [number, number, number];
9
- /** Prerelease identifiers after the `-`; empty for a release. Build metadata (`+…`) is dropped. */
10
- pre: string[];
11
- }
12
- export declare function parseVersion(raw: string): ParsedVersion | null;
13
- /** semver §11 precedence: numeric core, then a release beats any prerelease of the same core,
14
- * then prerelease identifiers left to right (numbers numerically, strings lexically, a shorter
15
- * list loses). Unparseable strings sort below everything parseable. */
16
- export declare function compareVersions(a: string, b: string): number;
17
- export declare function isNewer(candidate: string, current: string): boolean;
18
- /** Which dist-tag family a published version belongs to, from its prerelease identifiers. */
19
- export declare function classifyVersion(version: string): VersionChannel;
@@ -1,79 +0,0 @@
1
- /**
2
- * The little semver the self-updater needs — dependency-free on purpose (the CLI's runtime deps
3
- * are six packages and this is not worth a seventh). Handles what cezar publishes:
4
- * `0.11.1`, `0.11.1-nightly.20260924.49`, `0.9.2-pr743.1156.2`, `0.1.5-develop.124`.
5
- */
6
- export function parseVersion(raw) {
7
- const withoutBuild = raw.trim().replace(/^v/, '').split('+')[0] ?? '';
8
- const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(withoutBuild);
9
- if (!match)
10
- return null;
11
- return {
12
- core: [Number(match[1]), Number(match[2]), Number(match[3])],
13
- pre: match[4] ? match[4].split('.') : [],
14
- };
15
- }
16
- /** semver §11 precedence: numeric core, then a release beats any prerelease of the same core,
17
- * then prerelease identifiers left to right (numbers numerically, strings lexically, a shorter
18
- * list loses). Unparseable strings sort below everything parseable. */
19
- export function compareVersions(a, b) {
20
- const pa = parseVersion(a);
21
- const pb = parseVersion(b);
22
- if (!pa || !pb)
23
- return pa ? 1 : pb ? -1 : a.localeCompare(b);
24
- return compareCore(pa.core, pb.core) || comparePrerelease(pa.pre, pb.pre);
25
- }
26
- function compareCore(a, b) {
27
- for (let i = 0; i < 3; i++) {
28
- const diff = a[i] - b[i];
29
- if (diff !== 0)
30
- return diff > 0 ? 1 : -1;
31
- }
32
- return 0;
33
- }
34
- /** A release (no identifiers) beats any prerelease; otherwise identifiers left to right, and a
35
- * shorter list loses. */
36
- function comparePrerelease(a, b) {
37
- if (a.length === 0 || b.length === 0)
38
- return Math.sign(b.length - a.length);
39
- const len = Math.max(a.length, b.length);
40
- for (let i = 0; i < len; i++) {
41
- const x = a[i];
42
- const y = b[i];
43
- if (x === undefined)
44
- return -1;
45
- if (y === undefined)
46
- return 1;
47
- const order = compareIdentifier(x, y);
48
- if (order !== 0)
49
- return order;
50
- }
51
- return 0;
52
- }
53
- /** Numbers numerically, strings lexically, and a numeric identifier before an alphanumeric one. */
54
- function compareIdentifier(x, y) {
55
- const nx = /^\d+$/.test(x) ? Number(x) : null;
56
- const ny = /^\d+$/.test(y) ? Number(y) : null;
57
- if (nx !== null && ny !== null)
58
- return Math.sign(nx - ny);
59
- if (nx !== null)
60
- return -1;
61
- if (ny !== null)
62
- return 1;
63
- return x === y ? 0 : x > y ? 1 : -1;
64
- }
65
- export function isNewer(candidate, current) {
66
- return compareVersions(candidate, current) > 0;
67
- }
68
- /** Which dist-tag family a published version belongs to, from its prerelease identifiers. */
69
- export function classifyVersion(version) {
70
- const parsed = parseVersion(version);
71
- // Unparseable is `preview`, not `stable`: the picker filters previews out, so a junk entry in
72
- // the registry document is dropped instead of being offered as a release to install.
73
- if (!parsed)
74
- return 'preview';
75
- if (parsed.pre.length === 0)
76
- return 'stable';
77
- return parsed.pre[0] === 'nightly' ? 'nightly' : 'preview';
78
- }
79
- //# sourceMappingURL=semver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"semver.js","sourceRoot":"","sources":["../../src/self-update/semver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,MAAM,YAAY,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACtE,MAAM,KAAK,GAAG,6CAA6C,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/E,IAAI,CAAC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IAAI,EAAE,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1D,IAAI,EAAE,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC,CAAC;IAC3B,IAAI,EAAE,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC;IAC1B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,SAAiB,EAAE,OAAe;IACxD,OAAO,eAAe,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;AACjD,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,8FAA8F;IAC9F,qFAAqF;IACrF,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC7C,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7D,CAAC"}
@@ -1,115 +0,0 @@
1
- /**
2
- * The self-update service behind `/api/v1/workspace/self-update` and `cezar update`. Owns the
3
- * registry cache, the release-channel setting, the managed-layout view and the ONE install job
4
- * a process runs at a time. Applying an update = install (npm) → activate (`current` link) →
5
- * restart (re-exec, or exit for a supervisor to relaunch — see `restart.ts`).
6
- */
7
- import type { SelfUpdateDevelopment, SelfUpdateJob, SelfUpdateStatus, UpdateChannel } from '../contract/index.js';
8
- import type { Home } from '../home/home.ts';
9
- import { buildCheckout } from './checkouts.ts';
10
- import { type InstallKind } from './layout.ts';
11
- import { type OpenPulls } from './pulls.ts';
12
- import { RegistryCache } from './registry.ts';
13
- export interface SelfUpdateDeps {
14
- home: Home;
15
- rebrand?: boolean | undefined;
16
- pkgName: string;
17
- version: string;
18
- /** The running entry file (`process.argv[1]`). */
19
- entry: string;
20
- /** Exit-or-reexec policy; the service only decides WHEN. */
21
- restart: () => void;
22
- /** Runs in flight across the workspace, for the dialog's warning. */
23
- activeRuns?: () => number;
24
- /** Hosted mode trims the absolute entry path off the wire (open-mercato/cezar#431). */
25
- trimPaths?: () => boolean;
26
- supervised?: boolean;
27
- /** Report only: `capability()` answers false whatever the install kind, so `apply()` can
28
- * never install or activate. For a service that has no way to restart the process. */
29
- readOnly?: boolean;
30
- env?: NodeJS.ProcessEnv;
31
- registry?: RegistryCache;
32
- /** cezar's open pull requests, for the development channel. Defaults to GitHub. */
33
- pulls?: () => Promise<OpenPulls>;
34
- /** Builds an unbuilt or stale checkout before it is linked. Defaults to npm in the worktree. */
35
- buildCheckout?: typeof buildCheckout;
36
- }
37
- export declare class SelfUpdateBusyError extends Error {
38
- constructor();
39
- }
40
- export declare class SelfUpdateService {
41
- private readonly deps;
42
- readonly installKind: InstallKind;
43
- private readonly registry;
44
- private readonly home;
45
- private readonly env;
46
- private job;
47
- private readonly pulls;
48
- constructor(deps: SelfUpdateDeps);
49
- /** The configured channel: workspace config wins, then `CEZ_UPDATE_CHANNEL`, then stable. */
50
- channel(): Promise<UpdateChannel>;
51
- setChannel(channel: UpdateChannel): Promise<void>;
52
- /** The channel's newest version when it is newer than the running one — what health's
53
- * `latestVersion` reports and the version chip pulses for. */
54
- updateAvailable(refresh?: boolean): Promise<string | null>;
55
- /** Reuse a cached snapshot immediately, refreshing stale data in the background. A cold
56
- * read waits for the bounded initial registry request so the dialog receives its result.
57
- * Active jobs must report progress before restart even when the registry is unreachable. */
58
- status(opts?: {
59
- refresh?: boolean;
60
- registryOnly?: boolean;
61
- }): Promise<SelfUpdateStatus>;
62
- /** The registry document `status` reads: the cached one while a job runs, a fresh one on
63
- * `refresh`, else the cache with a background refresh (a cold cache waits for its first read). */
64
- private statusDocument;
65
- /** The job as `status` reports it. Keep raw diagnostics for local callers, but never disclose
66
- * the managed home through hosted npm command output or the final error. npm can normalize
67
- * Windows separators. */
68
- private jobView;
69
- /**
70
- * What the development channel picks from: cezar's own worktrees and the open pull requests
71
- * with a published preview build. Worktrees only on a local cockpit — linking a checkout runs
72
- * whatever is in it, a local-machine gesture a hosted cockpit neither offers nor accepts (see
73
- * `linkDiscovered`), and never worth a git call there.
74
- */
75
- development(opts?: {
76
- refresh?: boolean;
77
- }): Promise<SelfUpdateDevelopment>;
78
- /**
79
- * Whether a HOSTED cockpit may apply `target` — hosted updates are forward-only, and "forward"
80
- * has to mean forward in TIME, not merely in semver order. cezar's nightlies are versioned
81
- * `<next-version>-nightly.<date>.<run>`, so every `0.13.0-nightly.*` outranks every later
82
- * `0.12.x` patch: a semver-only rule would let a hosted cockpit on 0.12.1 install a 0.13.0
83
- * nightly cut months earlier and restart into code that predates the guards this rule exists
84
- * to protect. The target must be listed by the registry and may not resolve to a local or
85
- * linked install. Publish dates order known releases; when dates are missing, a prerelease
86
- * outranking a stable release is refused outright.
87
- *
88
- * Returns the refusal reason, or null when the target may be applied.
89
- */
90
- forwardOnlyRefusal(target: string): Promise<string | null>;
91
- private registryTargetRefusal;
92
- capability(): {
93
- canSelfUpdate: boolean;
94
- reason?: string;
95
- };
96
- /**
97
- * Install `target` (a registry version, an already-installed id such as `0.11.1+local`, or the
98
- * id of a built cezar checkout `status()` lists — linked on the spot), activate it and restart.
99
- * Returns as soon as the job is started; progress is on `status()`.
100
- */
101
- apply(target: string, opts?: {
102
- registryOnly?: boolean;
103
- }): SelfUpdateJob;
104
- /** A checkout `status()` offers under `target`: build it when it is unbuilt or older than its
105
- * last commit, link it and return its id. Null when no checkout answers to that id — the
106
- * target is then an installed entry or a registry version. A hosted cockpit never builds or
107
- * links here (`trimPaths`), and hosted apply also refuses already-installed local/link targets. */
108
- private linkDiscovered;
109
- /** `cezar install` from a checkout or the npx cache: pack the running package into the managed
110
- * layout and activate it. Headless — the CLI prints the log. */
111
- installSelf(onLog: (line: string) => void): Promise<{
112
- id: string;
113
- entry: string;
114
- }>;
115
- }
@@ -1,332 +0,0 @@
1
- import { productIdentity } from '../home/identity.js';
2
- import { productName } from '../home/display.js';
3
- import { productEnv } from '../core/product-env.js';
4
- import { loadWorkspaceConfig, mergeWriteWorkspaceConfig } from '../workspace/config.js';
5
- import { installFromLocal, installFromRegistry } from './installer.js';
6
- import { activateManaged, writeLaunchers } from './launcher.js';
7
- import { buildCheckout, discoverCheckouts } from './checkouts.js';
8
- import { activate, detectInstallKind, findInstalled, linkCheckout, listInstalled, packageRootOf } from './layout.js';
9
- import { CEZAR_REPO, fetchOpenPulls, OpenPullsCache } from './pulls.js';
10
- import { distTagFor, RegistryCache } from './registry.js';
11
- import { classifyVersion, isNewer } from './semver.js';
12
- const LOG_CAP = 200;
13
- export class SelfUpdateBusyError extends Error {
14
- constructor() {
15
- super('an update is already running');
16
- }
17
- }
18
- export class SelfUpdateService {
19
- deps;
20
- installKind;
21
- registry;
22
- home;
23
- env;
24
- job = null;
25
- pulls;
26
- constructor(deps) {
27
- this.deps = deps;
28
- this.env = deps.env ?? process.env;
29
- this.home = deps.home;
30
- this.installKind = detectInstallKind(deps.entry, this.env, this.home);
31
- this.registry = deps.registry ?? new RegistryCache(productIdentity(deps.rebrand).rebrand ? productIdentity(deps.rebrand).npmPackage : deps.pkgName);
32
- this.pulls = new OpenPullsCache(deps.pulls ?? (() => fetchOpenPulls(CEZAR_REPO, { env: this.env })));
33
- }
34
- /** The configured channel: workspace config wins, then `CEZ_UPDATE_CHANNEL`, then stable. */
35
- async channel() {
36
- const config = await loadWorkspaceConfig(this.deps.home.workspaceConfig);
37
- if (config.updateChannel)
38
- return config.updateChannel;
39
- const seed = productEnv('UPDATE_CHANNEL', this.env);
40
- return seed === 'nightly' || seed === 'development' ? seed : 'stable';
41
- }
42
- async setChannel(channel) {
43
- await mergeWriteWorkspaceConfig((config) => {
44
- config.updateChannel = channel;
45
- }, this.deps.home);
46
- }
47
- /** The channel's newest version when it is newer than the running one — what health's
48
- * `latestVersion` reports and the version chip pulses for. */
49
- async updateAvailable(refresh = false) {
50
- const doc = refresh ? await this.registry.refresh() : await this.registry.get();
51
- const channel = await this.channel();
52
- // Development runs whatever was picked by hand; nothing is ever "newer" than a worktree.
53
- if (!doc || channel === 'development')
54
- return null;
55
- const target = doc.distTags[distTagFor(channel)];
56
- return target && isNewer(target, this.deps.version) ? target : null;
57
- }
58
- /** Reuse a cached snapshot immediately, refreshing stale data in the background. A cold
59
- * read waits for the bounded initial registry request so the dialog receives its result.
60
- * Active jobs must report progress before restart even when the registry is unreachable. */
61
- async status(opts = {}) {
62
- const doc = await this.statusDocument(opts.refresh);
63
- const channel = await this.channel();
64
- const trim = !!(opts.registryOnly || this.deps.trimPaths?.());
65
- const installed = listInstalled(this.env, this.home, this.deps.rebrand).filter(entry => !trim || entry.source === 'registry');
66
- const installedIds = new Set(installed.map((entry) => entry.id));
67
- const stable = doc?.distTags.latest ?? null;
68
- const nightly = doc?.distTags.nightly ?? null;
69
- const target = channel === 'stable' ? stable : channel === 'nightly' ? nightly : null;
70
- const { canSelfUpdate, reason } = this.capability();
71
- return {
72
- version: this.deps.version,
73
- installKind: this.installKind,
74
- entry: trim ? this.deps.entry.split(/[\\/]/).pop() ?? '' : this.deps.entry,
75
- canSelfUpdate,
76
- ...(reason ? { reason } : {}),
77
- channel,
78
- restartMode: this.deps.supervised ? 'supervisor' : 'reexec',
79
- latest: { stable, nightly },
80
- updateAvailable: target && isNewer(target, this.deps.version) ? target : null,
81
- checkedAt: doc?.fetchedAt ?? null,
82
- installed: installed.map((entry) => installedView(entry, trim)),
83
- available: availableVersions(doc, installedIds),
84
- job: this.jobView(trim),
85
- activeRuns: this.deps.activeRuns?.() ?? 0,
86
- };
87
- }
88
- /** The registry document `status` reads: the cached one while a job runs, a fresh one on
89
- * `refresh`, else the cache with a background refresh (a cold cache waits for its first read). */
90
- async statusDocument(refresh) {
91
- if (this.job?.status === 'running' || this.job?.status === 'restarting')
92
- return this.registry.current();
93
- if (refresh)
94
- return this.registry.refresh();
95
- const doc = this.registry.current();
96
- if (!doc)
97
- return this.registry.get();
98
- void this.registry.get().catch(() => { });
99
- return doc;
100
- }
101
- /** The job as `status` reports it. Keep raw diagnostics for local callers, but never disclose
102
- * the managed home through hosted npm command output or the final error. npm can normalize
103
- * Windows separators. */
104
- jobView(trim) {
105
- if (!this.job || !trim)
106
- return this.job;
107
- const roots = [this.home.config, this.home.state, this.home.data, this.home.cache, this.home.runtime, this.home.rootOverride]
108
- .filter((root) => !!root);
109
- const paths = [...new Set(roots.flatMap(root => [root, root.replaceAll('\\', '/')]))]
110
- .sort((left, right) => right.length - left.length);
111
- const redact = (line) => paths
112
- .reduce((text, path) => text.replaceAll(path, '[cezar home]'), line);
113
- return {
114
- ...this.job,
115
- log: this.job.log.map(redact),
116
- ...(this.job.error ? { error: redact(this.job.error) } : {}),
117
- };
118
- }
119
- /**
120
- * What the development channel picks from: cezar's own worktrees and the open pull requests
121
- * with a published preview build. Worktrees only on a local cockpit — linking a checkout runs
122
- * whatever is in it, a local-machine gesture a hosted cockpit neither offers nor accepts (see
123
- * `linkDiscovered`), and never worth a git call there.
124
- */
125
- async development(opts = {}) {
126
- const trim = this.deps.trimPaths?.() ?? false;
127
- const [checkouts, pulls, doc] = await Promise.all([
128
- trim ? Promise.resolve([]) : discoverCheckouts(this.env, this.home).catch(() => []),
129
- this.pulls.get(opts.refresh),
130
- opts.refresh ? this.registry.refresh() : this.registry.get(),
131
- ]);
132
- const installedIds = new Set(listInstalled(this.env, this.home, this.deps.rebrand).map((entry) => entry.id));
133
- const publishedAt = (version) => doc?.versions.find((entry) => entry.version === version)?.publishedAt ?? null;
134
- const prByBranch = new Map(pulls.items.map((pull) => [pull.branch, pull.number]));
135
- return {
136
- checkouts: checkouts.map((checkout) => ({
137
- id: checkout.id,
138
- branch: checkout.branch,
139
- version: checkout.version,
140
- worktree: checkout.worktree,
141
- built: checkout.built,
142
- linked: checkout.linked,
143
- commit: checkout.commit,
144
- builtAt: checkout.builtAt,
145
- stale: checkout.stale,
146
- task: checkout.task,
147
- pr: prByBranch.get(checkout.branch) ?? null,
148
- })),
149
- pulls: {
150
- available: pulls.available,
151
- ...(pulls.reason ? { reason: pulls.reason } : {}),
152
- repo: CEZAR_REPO,
153
- items: pulls.items.map((pull) => {
154
- const version = doc?.distTags[`pr-${pull.number}`] ?? null;
155
- return {
156
- ...pull,
157
- version,
158
- publishedAt: version ? publishedAt(version) : null,
159
- installed: version ? installedIds.has(version) : false,
160
- };
161
- }),
162
- },
163
- };
164
- }
165
- /**
166
- * Whether a HOSTED cockpit may apply `target` — hosted updates are forward-only, and "forward"
167
- * has to mean forward in TIME, not merely in semver order. cezar's nightlies are versioned
168
- * `<next-version>-nightly.<date>.<run>`, so every `0.13.0-nightly.*` outranks every later
169
- * `0.12.x` patch: a semver-only rule would let a hosted cockpit on 0.12.1 install a 0.13.0
170
- * nightly cut months earlier and restart into code that predates the guards this rule exists
171
- * to protect. The target must be listed by the registry and may not resolve to a local or
172
- * linked install. Publish dates order known releases; when dates are missing, a prerelease
173
- * outranking a stable release is refused outright.
174
- *
175
- * Returns the refusal reason, or null when the target may be applied.
176
- */
177
- async forwardOnlyRefusal(target) {
178
- const running = this.deps.version;
179
- const suffix = `apply it on the host itself (\`${productIdentity().command} use <id>\`)`;
180
- if (!isNewer(target, running)) {
181
- return `a hosted cockpit can only update forward — ${target} is not newer than the running ${running}; ${suffix}`;
182
- }
183
- const doc = this.registry.current() ?? (await this.registry.get());
184
- const sourceRefusal = this.registryTargetRefusal(target, doc);
185
- if (sourceRefusal)
186
- return sourceRefusal;
187
- const publishedAt = (version) => doc?.versions.find((entry) => entry.version === version)?.publishedAt ?? null;
188
- const targetAt = publishedAt(target);
189
- const runningAt = publishedAt(running);
190
- if (targetAt && runningAt) {
191
- return targetAt >= runningAt
192
- ? null
193
- : `a hosted cockpit can only update forward — ${target} was published before the running ${running}; ${suffix}`;
194
- }
195
- if (classifyVersion(target) !== 'stable' && classifyVersion(running) === 'stable') {
196
- return `a hosted cockpit can only update forward — ${target} is a prerelease and the registry gave no publish date to check it against; ${suffix}`;
197
- }
198
- return null;
199
- }
200
- registryTargetRefusal(target, doc = this.registry.current()) {
201
- const installed = findInstalled(target, this.env, this.home, this.deps.rebrand);
202
- if (!doc?.versions.some(entry => entry.version === target) ||
203
- (installed && (installed.source !== 'registry' || installed.id !== target || installed.version !== target))) {
204
- return `Hosted updates require a published registry version; switch local builds on the host with \`${productIdentity().command} use <id>\`.`;
205
- }
206
- return null;
207
- }
208
- capability() {
209
- if (this.deps.readOnly)
210
- return { canSelfUpdate: false, reason: `This ${productName('cezar')} was started without an updater.` };
211
- switch (this.installKind) {
212
- case 'managed':
213
- return { canSelfUpdate: true };
214
- case 'npx':
215
- return {
216
- canSelfUpdate: false,
217
- reason: `This ${productName('cezar')} runs from the npx cache, which npx replaces on its own. Install it permanently to update from here.`,
218
- };
219
- case 'global-npm':
220
- return {
221
- canSelfUpdate: false,
222
- reason: `This ${productName('cezar')} was installed with npm -g. Update it with npm, or install the managed layout to update from here.`,
223
- };
224
- case 'checkout':
225
- return { canSelfUpdate: false, reason: `This ${productName('cezar')} runs from a git checkout — rebuild it instead of updating.` };
226
- default:
227
- return { canSelfUpdate: false, reason: `${productName('cezar')} could not tell how it was installed.` };
228
- }
229
- }
230
- /**
231
- * Install `target` (a registry version, an already-installed id such as `0.11.1+local`, or the
232
- * id of a built cezar checkout `status()` lists — linked on the spot), activate it and restart.
233
- * Returns as soon as the job is started; progress is on `status()`.
234
- */
235
- apply(target, opts = {}) {
236
- if (this.job?.status === 'running' || this.job?.status === 'restarting')
237
- throw new SelfUpdateBusyError();
238
- const { canSelfUpdate, reason } = this.capability();
239
- if (!canSelfUpdate)
240
- throw new Error(reason ?? 'self-update is not available for this install');
241
- const registryOnly = opts.registryOnly || this.deps.trimPaths?.();
242
- if (registryOnly) {
243
- const refusal = this.registryTargetRefusal(target);
244
- if (refusal)
245
- throw new Error(refusal);
246
- }
247
- const job = { status: 'running', target, startedAt: new Date().toISOString(), finishedAt: null, log: [] };
248
- this.job = job;
249
- const log = (line) => {
250
- job.log.push(line);
251
- if (job.log.length > LOG_CAP)
252
- job.log.splice(0, job.log.length - LOG_CAP);
253
- };
254
- void (async () => {
255
- try {
256
- const installed = findInstalled(target, this.env, this.home, this.deps.rebrand);
257
- // A linked checkout goes through discovery too: it may need a rebuild before it runs.
258
- const linked = !registryOnly && (!installed || installed.source === 'link') ? await this.linkDiscovered(target, log) : null;
259
- const id = linked ?? installed?.id ?? (await installFromRegistry(target, { onLog: log, env: this.env, home: this.home, rebrand: this.deps.rebrand })).id;
260
- if (installed && !linked)
261
- log(`${id} is already installed`);
262
- activateManaged(id, this.env, this.home, this.deps.rebrand);
263
- log(`activated ${id}`);
264
- job.status = 'restarting';
265
- job.finishedAt = new Date().toISOString();
266
- log('restarting…');
267
- // Let the status poll that observes `restarting` get its answer before the listener goes.
268
- setTimeout(() => this.deps.restart(), 750);
269
- }
270
- catch (error) {
271
- job.status = 'failed';
272
- job.finishedAt = new Date().toISOString();
273
- job.error = error instanceof Error ? error.message : String(error);
274
- log(`failed: ${job.error}`);
275
- }
276
- })();
277
- return job;
278
- }
279
- /** A checkout `status()` offers under `target`: build it when it is unbuilt or older than its
280
- * last commit, link it and return its id. Null when no checkout answers to that id — the
281
- * target is then an installed entry or a registry version. A hosted cockpit never builds or
282
- * links here (`trimPaths`), and hosted apply also refuses already-installed local/link targets. */
283
- async linkDiscovered(target, log) {
284
- if (this.deps.trimPaths?.())
285
- return null;
286
- const checkout = (await discoverCheckouts(this.env, this.home)).find((entry) => entry.id === target);
287
- if (!checkout)
288
- return null;
289
- if (!checkout.built || checkout.stale) {
290
- log(`${checkout.built ? 'rebuilding' : 'building'} ${checkout.branch} first`);
291
- await (this.deps.buildCheckout ?? buildCheckout)(checkout, log);
292
- }
293
- log(`linking ${checkout.packageRoot} (${checkout.branch})`);
294
- return linkCheckout(checkout.packageRoot, checkout.branch, this.env, checkout.id, this.home).id;
295
- }
296
- /** `cezar install` from a checkout or the npx cache: pack the running package into the managed
297
- * layout and activate it. Headless — the CLI prints the log. */
298
- async installSelf(onLog) {
299
- // A local reinstall can replace the tree already selected by current. Refresh
300
- // before installing too, so a failed write cannot strand the active local build.
301
- if (productIdentity(this.deps.rebrand).rebrand)
302
- writeLaunchers(this.env, this.home, this.deps.rebrand);
303
- const result = await installFromLocal(packageRootOf(this.deps.entry), { onLog, env: this.env, home: this.home, rebrand: this.deps.rebrand });
304
- activate(result.id, this.env, this.home, this.deps.rebrand);
305
- return result;
306
- }
307
- }
308
- function installedView(entry, trim) {
309
- return {
310
- id: entry.id,
311
- version: entry.version,
312
- source: entry.source,
313
- installedAt: entry.installedAt,
314
- active: entry.active,
315
- ...(entry.branch ? { branch: entry.branch } : {}),
316
- ...(entry.checkout && !trim ? { checkout: entry.checkout } : {}),
317
- };
318
- }
319
- /** Previews (`-pr123.`, `-develop.`) are noise in a picker meant for stable ↔ nightly moves;
320
- * the picker lists stable releases and nightlies only. */
321
- function availableVersions(doc, installedIds) {
322
- return (doc?.versions ?? [])
323
- .filter((entry) => entry.channel !== 'preview')
324
- .slice(0, 60)
325
- .map((entry) => ({
326
- version: entry.version,
327
- channel: entry.channel,
328
- publishedAt: entry.publishedAt,
329
- installed: installedIds.has(entry.version),
330
- }));
331
- }
332
- //# sourceMappingURL=service.js.map