@cotal-ai/cli 0.185.0 → 0.185.1

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 (104) hide show
  1. package/dist/command.d.ts.map +1 -1
  2. package/dist/command.js +15 -6
  3. package/dist/command.js.map +1 -1
  4. package/dist/commands/app-identity.d.ts.map +1 -1
  5. package/dist/commands/app-identity.js +22 -6
  6. package/dist/commands/app-identity.js.map +1 -1
  7. package/dist/commands/backup.d.ts.map +1 -1
  8. package/dist/commands/backup.js +23 -20
  9. package/dist/commands/backup.js.map +1 -1
  10. package/dist/commands/clean.d.ts.map +1 -1
  11. package/dist/commands/clean.js +4 -0
  12. package/dist/commands/clean.js.map +1 -1
  13. package/dist/commands/describe.d.ts.map +1 -1
  14. package/dist/commands/describe.js +12 -10
  15. package/dist/commands/describe.js.map +1 -1
  16. package/dist/commands/ext.d.ts.map +1 -1
  17. package/dist/commands/ext.js +4 -3
  18. package/dist/commands/ext.js.map +1 -1
  19. package/dist/commands/history-clear.d.ts +3 -0
  20. package/dist/commands/history-clear.d.ts.map +1 -1
  21. package/dist/commands/history-clear.js +19 -4
  22. package/dist/commands/history-clear.js.map +1 -1
  23. package/dist/commands/history-limit.d.ts.map +1 -1
  24. package/dist/commands/history-limit.js +10 -2
  25. package/dist/commands/history-limit.js.map +1 -1
  26. package/dist/commands/send.d.ts.map +1 -1
  27. package/dist/commands/send.js +2 -1
  28. package/dist/commands/send.js.map +1 -1
  29. package/dist/commands/service-registry.js +1 -1
  30. package/dist/commands/service-registry.js.map +1 -1
  31. package/dist/commands/setup.d.ts.map +1 -1
  32. package/dist/commands/setup.js +24 -6
  33. package/dist/commands/setup.js.map +1 -1
  34. package/dist/commands/space-delete.d.ts.map +1 -1
  35. package/dist/commands/space-delete.js +39 -9
  36. package/dist/commands/space-delete.js.map +1 -1
  37. package/dist/commands/space-registration.d.ts +1 -0
  38. package/dist/commands/space-registration.d.ts.map +1 -1
  39. package/dist/commands/space-registration.js +1 -1
  40. package/dist/commands/space-registration.js.map +1 -1
  41. package/dist/commands/spawn-foreground.d.ts.map +1 -1
  42. package/dist/commands/spawn-foreground.js +1 -0
  43. package/dist/commands/spawn-foreground.js.map +1 -1
  44. package/dist/commands/spawn-managed-launch.d.ts.map +1 -1
  45. package/dist/commands/spawn-managed-launch.js +3 -2
  46. package/dist/commands/spawn-managed-launch.js.map +1 -1
  47. package/dist/commands/spawn.d.ts.map +1 -1
  48. package/dist/commands/spawn.js +7 -4
  49. package/dist/commands/spawn.js.map +1 -1
  50. package/dist/commands/team.d.ts.map +1 -1
  51. package/dist/commands/team.js +8 -5
  52. package/dist/commands/team.js.map +1 -1
  53. package/dist/commands/update-caches.d.ts.map +1 -1
  54. package/dist/commands/update-caches.js +35 -11
  55. package/dist/commands/update-caches.js.map +1 -1
  56. package/dist/commands/update-offline.js +2 -2
  57. package/dist/commands/update-offline.js.map +1 -1
  58. package/dist/commands/update-release.d.ts.map +1 -1
  59. package/dist/commands/update-release.js +2 -2
  60. package/dist/commands/update-release.js.map +1 -1
  61. package/dist/commands/update.d.ts.map +1 -1
  62. package/dist/commands/update.js +127 -79
  63. package/dist/commands/update.js.map +1 -1
  64. package/dist/ext-loader.d.ts +2 -0
  65. package/dist/ext-loader.d.ts.map +1 -1
  66. package/dist/ext-loader.js +16 -3
  67. package/dist/ext-loader.js.map +1 -1
  68. package/dist/lib/backup-artifact.d.ts +4 -1
  69. package/dist/lib/backup-artifact.d.ts.map +1 -1
  70. package/dist/lib/backup-artifact.js +10 -3
  71. package/dist/lib/backup-artifact.js.map +1 -1
  72. package/dist/lib/endpoint-errors.d.ts +4 -3
  73. package/dist/lib/endpoint-errors.d.ts.map +1 -1
  74. package/dist/lib/endpoint-errors.js +11 -10
  75. package/dist/lib/endpoint-errors.js.map +1 -1
  76. package/dist/lib/extension-core-peer.d.ts.map +1 -1
  77. package/dist/lib/extension-core-peer.js +4 -17
  78. package/dist/lib/extension-core-peer.js.map +1 -1
  79. package/dist/lib/persona-files.d.ts.map +1 -1
  80. package/dist/lib/persona-files.js +37 -28
  81. package/dist/lib/persona-files.js.map +1 -1
  82. package/dist/lib/private-log.d.ts +2 -0
  83. package/dist/lib/private-log.d.ts.map +1 -1
  84. package/dist/lib/private-log.js +2 -0
  85. package/dist/lib/private-log.js.map +1 -1
  86. package/dist/lib/restore-streams.d.ts +4 -2
  87. package/dist/lib/restore-streams.d.ts.map +1 -1
  88. package/dist/lib/restore-streams.js +19 -8
  89. package/dist/lib/restore-streams.js.map +1 -1
  90. package/dist/lib/restore.d.ts.map +1 -1
  91. package/dist/lib/restore.js +62 -24
  92. package/dist/lib/restore.js.map +1 -1
  93. package/dist/lib/service-process.js +2 -2
  94. package/dist/lib/service-process.js.map +1 -1
  95. package/dist/seed/reconcile.js +4 -4
  96. package/dist/seed/reconcile.js.map +1 -1
  97. package/dist/seed/verify.d.ts +2 -0
  98. package/dist/seed/verify.d.ts.map +1 -1
  99. package/dist/seed/verify.js +20 -3
  100. package/dist/seed/verify.js.map +1 -1
  101. package/dist/telemetry.d.ts.map +1 -1
  102. package/dist/telemetry.js +4 -0
  103. package/dist/telemetry.js.map +1 -1
  104. package/package.json +5 -5
@@ -2,7 +2,7 @@ import { existsSync, mkdtempSync, readFileSync, realpathSync, rmSync } from "nod
2
2
  import { homedir, tmpdir } from "node:os";
3
3
  import { dirname, isAbsolute, join } from "node:path";
4
4
  import { globalConfigDir } from "@cotal-ai/core";
5
- import { CommandFailure, isCommandFailure, jsonFlag, plainFlag, presentationOf, renderReport, writeResult, claimUpdateClosureAccess, updateClosureOwner, withWindowsUpdateIdentity, homeCotalDir, readUpdateRecovery, clearUpdateRecovery, writeUpdateRecovery, readUpdateSettings, observeUpdateVersion, UPDATE_HOUR_MS, recordUpdateCompletion, recordUpdateDeferral, recordUpdateReleaseHold, recordUpdateRefusal, recordUpdateReplacement, setUpdateSetting, bindExtensionPeers, claimGlobalNpmUpdateLock, launcherInstallRoot, logicalExecutionEntry, loadExtensionsManifest, provenance, SEEDED_EXTENSIONS, targetFlags, recoveryDisposition, liveUpdateClosureOwner, recoveryProcessStartToken, observeUnownedRecovery, UnreadableConnectorSelection, } from "@cotal-ai/workspace";
5
+ import { CommandFailure, isCommandFailure, jsonFlag, plainFlag, presentationOf, renderReport, writeResult, claimUpdateClosureAccess, updateClosureOwner, withWindowsUpdateIdentity, homeCotalDir, readUpdateRecovery, clearUpdateRecovery, writeUpdateRecovery, readUpdateSettings, observeUpdateVersion, UPDATE_HOUR_MS, recordOperationContext, recordUpdateCompletion, recordUpdateDeferral, recordUpdateReleaseHold, recordUpdateRefusal, recordUpdateReplacement, setUpdateSetting, bindExtensionPeers, claimGlobalNpmUpdateLock, launcherInstallRoot, logicalExecutionEntry, loadExtensionsManifest, provenance, SEEDED_EXTENSIONS, targetFlags, recoveryDisposition, liveUpdateClosureOwner, recoveryProcessStartToken, observeUnownedRecovery, UnreadableConnectorSelection, } from "@cotal-ai/workspace";
6
6
  import { resumePublishedUpdate, retainUnusableRecovery } from "../lib/update-recovery-state.js";
7
7
  import { readUpdatePending } from "../lib/update-pending.js";
8
8
  import { snapshotUpdateClosure } from "../lib/update-snapshot.js";
@@ -16,13 +16,14 @@ import { selfArgv } from "../lib/self-exec.js";
16
16
  import { repairInstallModes } from "../lib/install-umask.js";
17
17
  import { cliVersion, installedCliVersion } from "../lib/version.js";
18
18
  import { runSeed, compareSemver, seedInstallationCurrent, assertReadableSeedState, readSeedRepairRefusal } from "../seed/reconcile.js";
19
- import { operatorInstallDiffers, operatorUpdateSpec } from "../seed/verify.js";
19
+ import { operatorInstallDiffers, operatorUpdateSpec, reconcilesOperatorExtension } from "../seed/verify.js";
20
20
  import { cliPackageRoot, entryScript, seedWriterKind } from "../seed/paths.js";
21
21
  import { refreshClientInstalls, refreshConnectorInstalls } from "./setup.js";
22
22
  import { reportCurrentConnectorState } from "./setup-current-connectors.js";
23
23
  import { c } from "../ui.js";
24
24
  import { refreshOwnedCompletions } from "../lib/completion-install.js";
25
25
  import { onFlag } from "../lib/control.js";
26
+ import { ownStdoutErrors } from "../lib/stdout-owner.js";
26
27
  import { STRICT_SEMVER, installedUpdatePrefix, verifyGlobalEntry, runNpmAsync, runNpm, runProcess, runGlobalProcess, latestNotAvailable, failure, message, } from "./update-process.js";
27
28
  import { latestVersion, latestVersionCheckRemedy, latestVersionCheckWarning, handleLatestVersionFailure, reportConnectorAccessRestored, checkReleaseArchives, ReleaseNotAvailable, ReleaseDateExcluded, DependencyCheckInterrupted, DependencyCheckNoSpace, registryNetworkFailure, deferStagingFailure, offlineUpdateMessage, waitForReleasePreflight, } from "./update-release.js";
28
29
  import { admitReconciliation, refusal, reportRunningManagers, reportUncheckedPreparedRecords } from "./update-continuity.js";
@@ -60,7 +61,7 @@ export const updateRuntime = {
60
61
  return false;
61
62
  try {
62
63
  const builtIns = new Set(Object.values(SEEDED_EXTENSIONS).map(entry => entry.pkg));
63
- return updateRuntime.extensions().filter(entry => entry.pkg.startsWith("@cotal-ai/") && !builtIns.has(entry.pkg))
64
+ return updateRuntime.extensions().filter(entry => reconcilesOperatorExtension(entry, cliVersion()) && !builtIns.has(entry.pkg))
64
65
  .every(entry => operatorInstallDiffers(entry, cliVersion()) === undefined);
65
66
  }
66
67
  catch {
@@ -171,6 +172,7 @@ export async function update(args, rt = updateRuntime) {
171
172
  });
172
173
  const environments = [...new Set([process.env, rt.env])];
173
174
  const previous = environments.map(env => ({ env, values: { TMPDIR: env.TMPDIR, TMP: env.TMP, TEMP: env.TEMP } }));
175
+ const releaseOutput = args.values.check === true ? undefined : ownStdoutErrors(() => { });
174
176
  let continuation;
175
177
  try {
176
178
  for (const env of environments)
@@ -186,6 +188,7 @@ export async function update(args, rt = updateRuntime) {
186
188
  env[key] = value;
187
189
  }
188
190
  rmSync(scratch, { recursive: true, force: true, maxRetries: 3 });
191
+ releaseOutput?.();
189
192
  }
190
193
  if (continuation) {
191
194
  const result = rt.spawn(rt.nodePath, [continuation, "update", ...args.raw], rt.env, true);
@@ -199,6 +202,12 @@ export async function update(args, rt = updateRuntime) {
199
202
  if (args.values.self === true && !process.exitCode && childBinding(rt).kind === "none")
200
203
  collectUpdateCaches(dirname(scratch));
201
204
  }
205
+ function reportConfigProtectionFailure(rt, version, error) {
206
+ rt.err(c.red(`✗ config folder protection: ${refusal(error)}`));
207
+ recordUpdateDeferral(version, `config folder protection: ${preflightDetail(error)}`);
208
+ if (isCommandFailure(error))
209
+ recordOperationContext({ reportedFailure: { outcome: error.outcome, code: error.code } });
210
+ }
202
211
  async function updateInstallation(args, rt) {
203
212
  if (args.values.check === true) {
204
213
  await checkUpdate(args, rt);
@@ -265,8 +274,7 @@ async function updateInstallation(args, rt) {
265
274
  assertConfigAncestorProtected();
266
275
  }
267
276
  catch (e) {
268
- rt.err(c.red(`✗ config folder protection: ${refusal(e)}`));
269
- recordUpdateDeferral(rt.version(), `config folder protection: ${preflightDetail(e)}`);
277
+ reportConfigProtectionFailure(rt, rt.version(), e);
270
278
  process.exitCode = 1;
271
279
  return;
272
280
  }
@@ -683,7 +691,7 @@ async function updateOperatorExtensions(rt, current) {
683
691
  rt.out(c.dim("operator extensions: none installed"));
684
692
  for (const entry of entries) {
685
693
  const recordedSpec = typeof entry.spec === "string" ? ` (recorded spec: ${entry.spec})` : "";
686
- if (!entry.pkg.startsWith("@cotal-ai/")) {
694
+ if (!reconcilesOperatorExtension(entry, current)) {
687
695
  rt.out(c.dim(`${entry.pkg}@${entry.version} - not auto-updated in v1${recordedSpec}`));
688
696
  continue;
689
697
  }
@@ -862,8 +870,7 @@ async function upgradeAndReconcile(targetVersion, current, rt, target, preflight
862
870
  assertConfigAncestorProtected();
863
871
  }
864
872
  catch (e) {
865
- rt.err(c.red(`✗ config folder protection: ${refusal(e)}`));
866
- recordUpdateDeferral(targetVersion, `config folder protection: ${preflightDetail(e)}`);
873
+ reportConfigProtectionFailure(rt, targetVersion, e);
867
874
  return 1;
868
875
  }
869
876
  let releaseGlobal;
@@ -895,86 +902,111 @@ async function upgradeAndReconcile(targetVersion, current, rt, target, preflight
895
902
  rt.err(`could not recheck the installed global CLI: ${message(error)}`);
896
903
  return 1;
897
904
  }
898
- let execution;
905
+ let interrupted = 0, hangup = false;
906
+ const interrupt = (code) => {
907
+ if (interrupted)
908
+ return;
909
+ interrupted = code;
910
+ rt.err(c.yellow("Interrupt received; finishing installation and reconciliation before exiting."));
911
+ };
912
+ const onInt = () => interrupt(130), onTerm = () => interrupt(143);
913
+ const onHup = () => { hangup = true; interrupted ||= 129; };
914
+ const releaseOutput = ownStdoutErrors(() => { });
915
+ process.on("SIGHUP", onHup);
916
+ let execution, releaseAdmission;
917
+ let releaseClosure, snapshot;
899
918
  let stagedExecution = false;
900
- if (rt.prepareExecution) {
901
- stagedExecution = true;
902
- const prepareStarted = Date.now();
919
+ try {
920
+ if (rt.prepareExecution) {
921
+ stagedExecution = true;
922
+ const prepareStarted = Date.now();
923
+ try {
924
+ rt.out(c.bold("cotal-ai binary"));
925
+ rt.out(c.dim(`installing cotal-ai@${targetVersion} beside the running version; this ${current} process stays loaded until the new version is verified`));
926
+ execution = await rt.prepareExecution(targetVersion, root);
927
+ if (hangup) {
928
+ execution.discard?.();
929
+ return 129;
930
+ }
931
+ await execution.preflight(target);
932
+ if (hangup) {
933
+ execution.discard?.();
934
+ return 129;
935
+ }
936
+ if (await rt.reportRunningManager(target) === "legacy")
937
+ throw new Error("running Manager requires a restart that cannot preserve its agents");
938
+ if (hangup) {
939
+ execution.discard?.();
940
+ return 129;
941
+ }
942
+ rt.out(`✓ new version installed and verified (${((Date.now() - prepareStarted) / 1000).toFixed(1)} s)`);
943
+ }
944
+ catch (error) {
945
+ try {
946
+ execution?.discard?.();
947
+ }
948
+ catch { /* an unpublished copy left behind selects nothing */ }
949
+ if (hangup)
950
+ return 129;
951
+ if (!execution && deferStagingFailure(error, targetVersion, rt, preflightChanged || repairedSelection))
952
+ return 0;
953
+ recordUpdateDeferral(targetVersion, `staged pre-install check refused: ${preflightDetail(error)}`);
954
+ rt.err(`staged pre-install check refused: ${message(error)}; no installed packages were replaced`);
955
+ return 1;
956
+ }
957
+ }
958
+ if (hangup) {
959
+ execution?.discard?.();
960
+ return 129;
961
+ }
903
962
  try {
904
- rt.out(c.bold("cotal-ai binary"));
905
- rt.out(c.dim(`installing cotal-ai@${targetVersion} beside the running version; this ${current} process stays loaded until the new version is verified`));
906
- execution = await rt.prepareExecution(targetVersion, root);
907
- await execution.preflight(target);
908
- if (await rt.reportRunningManager(target) === "legacy")
909
- throw new Error("running Manager requires a restart that cannot preserve its agents");
910
- rt.out(`✓ new version installed and verified (${((Date.now() - prepareStarted) / 1000).toFixed(1)} s)`);
963
+ releaseAdmission = await rt.prepareReplacement?.();
911
964
  }
912
965
  catch (error) {
913
966
  try {
914
967
  execution?.discard?.();
915
968
  }
916
969
  catch { /* an unpublished copy left behind selects nothing */ }
917
- releaseGlobal();
918
- if (!execution && deferStagingFailure(error, targetVersion, rt, preflightChanged || repairedSelection))
919
- return 0;
920
- recordUpdateDeferral(targetVersion, `staged pre-install check refused: ${preflightDetail(error)}`);
921
- rt.err(`staged pre-install check refused: ${message(error)}; no installed packages were replaced`);
970
+ if (hangup)
971
+ return 129;
972
+ recordUpdateDeferral(targetVersion, "waiting for agents to stop");
973
+ rt.err(`update admission refused: ${message(error)}`);
922
974
  return 1;
923
975
  }
924
- }
925
- let releaseAdmission;
926
- try {
927
- releaseAdmission = await rt.prepareReplacement?.();
928
- }
929
- catch (error) {
930
- try {
976
+ if (hangup) {
931
977
  execution?.discard?.();
978
+ return 129;
932
979
  }
933
- catch { /* an unpublished copy left behind selects nothing */ }
934
- releaseGlobal();
935
- recordUpdateDeferral(targetVersion, "waiting for agents to stop");
936
- rt.err(`update admission refused: ${message(error)}`);
937
- return 1;
938
- }
939
- let releaseClosure;
940
- let snapshot;
941
- const snapshotStarted = Date.now();
942
- try {
943
- releaseClosure = claimUpdateClosureAccess();
944
- rt.out("Saving update recovery snapshot");
945
- snapshot = snapshotUpdateClosure();
946
- rt.out(`✓ recovery snapshot saved (${((Date.now() - snapshotStarted) / 1000).toFixed(1)} s)`);
947
- }
948
- catch (error) {
980
+ const snapshotStarted = Date.now();
949
981
  try {
982
+ releaseClosure = claimUpdateClosureAccess();
983
+ rt.out("Saving update recovery snapshot");
984
+ snapshot = snapshotUpdateClosure();
985
+ rt.out(`✓ recovery snapshot saved (${((Date.now() - snapshotStarted) / 1000).toFixed(1)} s)`);
986
+ }
987
+ catch (error) {
988
+ try {
989
+ execution?.discard?.();
990
+ }
991
+ catch { /* an unpublished copy left behind selects nothing */ }
992
+ if (hangup)
993
+ return 129;
994
+ const detail = preflightDetail(error);
995
+ recordUpdateDeferral(targetVersion, `update snapshot refused: ${detail}`);
996
+ rt.err(`update snapshot refused: ${message(error)}`);
997
+ return 1;
998
+ }
999
+ if (hangup) {
1000
+ snapshot.discard();
950
1001
  execution?.discard?.();
1002
+ return 129;
951
1003
  }
952
- catch { /* an unpublished copy left behind selects nothing */ }
953
- releaseClosure?.();
954
- await releaseAdmission?.();
955
- releaseGlobal();
956
- const detail = preflightDetail(error);
957
- recordUpdateDeferral(targetVersion, `update snapshot refused: ${detail}`);
958
- rt.err(`update snapshot refused: ${message(error)}`);
959
- return 1;
960
- }
961
- // npm replaces the live package tree. Keep custody until it and the verified reconcile
962
- // finish, even when the terminal sends Ctrl-C during that replacement.
963
- let interrupted = 0;
964
- const interrupt = (code) => {
965
- if (interrupted)
966
- return;
967
- interrupted = code;
968
- rt.err(c.yellow("Interrupt received; finishing installation and reconciliation before exiting."));
969
- };
970
- const onInt = () => interrupt(130);
971
- const onTerm = () => interrupt(143);
972
- process.on("SIGINT", onInt);
973
- process.on("SIGTERM", onTerm);
974
- try {
975
- if (execution) {
1004
+ // npm replaces the live package tree. Keep custody until it and the verified reconcile
1005
+ // finish, even when the terminal sends Ctrl-C during that replacement.
1006
+ process.on("SIGINT", onInt);
1007
+ process.on("SIGTERM", onTerm);
1008
+ if (execution)
976
1009
  rt.out(`Switching to cotal-ai@${targetVersion}`);
977
- }
978
1010
  else {
979
1011
  rt.out(c.bold("cotal-ai binary"));
980
1012
  rt.out(c.dim(`installing cotal-ai@${targetVersion} into npm's global installation; this ${current} process remains loaded until the verified global copy takes over`));
@@ -999,6 +1031,8 @@ async function upgradeAndReconcile(targetVersion, current, rt, target, preflight
999
1031
  rt.out(reason);
1000
1032
  return interrupted;
1001
1033
  }
1034
+ if (hangup)
1035
+ return 129;
1002
1036
  if (installed.stderr)
1003
1037
  rt.stderr(installed.stderr);
1004
1038
  if (installed.status !== 0) {
@@ -1019,17 +1053,15 @@ async function upgradeAndReconcile(targetVersion, current, rt, target, preflight
1019
1053
  rt.err(c.red(`✗ installed global cotal-ai could not be verified: ${message(e)}`));
1020
1054
  return await repairReplacement(`installed entry verification failed: ${message(e)}`);
1021
1055
  }
1022
- const env = {
1023
- ...rt.env,
1024
- ...(prefix ? { npm_config_prefix: prefix } : {}),
1025
- [UPDATE_TARGET_ENV]: targetVersion,
1026
- [UPDATE_PARENT_ENV]: String(rt.pid),
1027
- ...(rt.env.COTAL_AUTO_UPDATE !== "1" ? { [UPDATE_PARENT_WAITS_ENV]: "1" } : {}),
1028
- };
1056
+ const env = { ...rt.env, ...(prefix ? { npm_config_prefix: prefix } : {}), [UPDATE_TARGET_ENV]: targetVersion, [UPDATE_PARENT_ENV]: String(rt.pid), ...(rt.env.COTAL_AUTO_UPDATE !== "1" ? { [UPDATE_PARENT_WAITS_ENV]: "1" } : {}) };
1029
1057
  delete env[EXT_UPDATE_PARENT_ENV];
1058
+ if (hangup)
1059
+ return 129;
1030
1060
  rt.out(`Reconciling installed cotal-ai@${targetVersion}`);
1031
1061
  const reconcileStarted = Date.now();
1032
1062
  const child = await rt.spawnGlobal(root, "reconcile", rt.nodePath, [entry, "update", ...targetArgv(target)], env, true);
1063
+ if (hangup)
1064
+ return 129;
1033
1065
  rt.out(`✓ installed reconciliation finished (${((Date.now() - reconcileStarted) / 1000).toFixed(1)} s)`);
1034
1066
  if (child.stderr)
1035
1067
  rt.stderr(child.stderr);
@@ -1048,10 +1080,14 @@ async function upgradeAndReconcile(targetVersion, current, rt, target, preflight
1048
1080
  activationDeferred = await rt.waitForInstalledGeneration?.(targetVersion);
1049
1081
  }
1050
1082
  catch (error) {
1083
+ if (hangup)
1084
+ return 129;
1051
1085
  rt.err(c.red(`✗ installed daemon generation: ${refusal(error)}`));
1052
1086
  return await repairReplacement(`installed daemon generation: ${message(error)}`, 1, true);
1053
1087
  }
1054
1088
  }
1089
+ if (hangup)
1090
+ return 129;
1055
1091
  try {
1056
1092
  execution?.verify(targetVersion);
1057
1093
  }
@@ -1093,6 +1129,8 @@ async function upgradeAndReconcile(targetVersion, current, rt, target, preflight
1093
1129
  return true;
1094
1130
  }
1095
1131
  async function repairReplacement(reason, failureStatus = 1, skipTargetRetry = false) {
1132
+ if (hangup)
1133
+ return 129;
1096
1134
  if (!skipTargetRetry) {
1097
1135
  rt.err(c.yellow("Retrying reconciliation of the installed generation before rollback."));
1098
1136
  try {
@@ -1109,6 +1147,8 @@ async function upgradeAndReconcile(targetVersion, current, rt, target, preflight
1109
1147
  rt.err(`reconcile retry: ${message(error)}`);
1110
1148
  }
1111
1149
  }
1150
+ if (hangup)
1151
+ return 129;
1112
1152
  rt.err(c.yellow(`Restoring verified cotal-ai@${current} through the global updater.`));
1113
1153
  try {
1114
1154
  const recovery = readUpdateRecovery();
@@ -1120,16 +1160,22 @@ async function upgradeAndReconcile(targetVersion, current, rt, target, preflight
1120
1160
  }
1121
1161
  else {
1122
1162
  await checkReleaseArchives(current, rt);
1163
+ if (hangup)
1164
+ return 129;
1123
1165
  const restored = await rt.spawnGlobal(root, "install", "npm", ["install", "-g", ...prefixArgs, `cotal-ai@${current}`], rt.env, true);
1124
1166
  if (restored.status !== 0)
1125
1167
  throw new Error(failure(restored));
1126
1168
  rt.verifyGlobalEntry(root, current);
1127
1169
  }
1170
+ if (hangup)
1171
+ return 129;
1128
1172
  snapshot.restore();
1129
1173
  if (execution)
1130
1174
  execution.verify(current);
1131
1175
  await releaseAdmission?.();
1132
1176
  releaseAdmission = await rt.prepareReplacement?.();
1177
+ if (hangup)
1178
+ return 129;
1133
1179
  if (!await reconcileVersion(current))
1134
1180
  throw new Error("previous generation reconciliation failed");
1135
1181
  snapshot.discard();
@@ -1169,6 +1215,8 @@ async function upgradeAndReconcile(targetVersion, current, rt, target, preflight
1169
1215
  finally {
1170
1216
  process.off("SIGINT", onInt);
1171
1217
  process.off("SIGTERM", onTerm);
1218
+ process.off("SIGHUP", onHup);
1219
+ releaseOutput();
1172
1220
  }
1173
1221
  }
1174
1222
  }