@indigoai-us/hq-cli 5.345.108 → 5.345.110

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.
@@ -1 +1 @@
1
- {"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.67","bundleSha256":"6d94ad9a9dbfa34fd81040eff69d68a1da68ab0d1318566832fe19393bffe589","formatVersion":1}
1
+ {"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.69","bundleSha256":"f061a19c14325b3ae076aa6277c2f60269976ef43ef7ce79be2140d0ba2927a6","formatVersion":1}
package/dist/index.d.ts CHANGED
@@ -5,13 +5,21 @@ import { isVersionRequest } from "./version-request.js";
5
5
  import { isFastCoreRequest } from "./fast-scaffold.js";
6
6
  type PackageUseLeaseLoader = () => Promise<void>;
7
7
  type PackageUseUpdateProbe = () => Promise<boolean>;
8
+ /** Resolves true once the command was re-run (exit code already set). */
9
+ type PackageUseUpdateReexec = () => Promise<boolean>;
10
+ /**
11
+ * Wait (bounded) for a live updater to finish, then re-run this command from
12
+ * the new install via the same bin path. Guarded against loops by an env flag.
13
+ */
14
+ declare function waitForUpdateThenReexec(argv?: readonly string[], env?: NodeJS.ProcessEnv, waitForUpdate?: () => Promise<boolean>, run?: (command: string, args: string[], childEnv: NodeJS.ProcessEnv) => Promise<number>): Promise<boolean>;
8
15
  declare function isNpmPackageEntry(entryUrl: string): boolean;
9
- declare function dispatchWithPackageUseLease(entryUrl: string, dispatch: () => void, loadLease?: PackageUseLeaseLoader, updateRequestPending?: PackageUseUpdateProbe): void | Promise<void>;
16
+ declare function dispatchWithPackageUseLease(entryUrl: string, dispatch: () => void, loadLease?: PackageUseLeaseLoader, updateRequestPending?: PackageUseUpdateProbe, waitThenReexec?: PackageUseUpdateReexec): void | Promise<void>;
10
17
  declare function runCliEntry(entryUrl: string, dispatch: () => void, loadLease?: PackageUseLeaseLoader): void | Promise<void>;
11
18
  export declare const __test__: {
12
19
  isVersionRequest: typeof isVersionRequest;
13
20
  isFastCoreRequest: typeof isFastCoreRequest;
14
21
  dispatchWithPackageUseLease: typeof dispatchWithPackageUseLease;
22
+ waitForUpdateThenReexec: typeof waitForUpdateThenReexec;
15
23
  runCliEntry: typeof runCliEntry;
16
24
  isNpmPackageEntry: typeof isNpmPackageEntry;
17
25
  acquirePackageUseLease: (prefix: string, version: string, stateDirectory?: string) => Promise<import("./utils/package-use-lease.js").PackageUseLease>;
package/dist/index.js CHANGED
@@ -230,6 +230,36 @@ function dispatchCliEntry() {
230
230
  void runMainWithInstallTreeRecovery();
231
231
  }
232
232
  }
233
+ const REEXEC_ENV = "HQ_CLI_UPDATE_REEXEC";
234
+ /**
235
+ * Wait (bounded) for a live updater to finish, then re-run this command from
236
+ * the new install via the same bin path. Guarded against loops by an env flag.
237
+ */
238
+ async function waitForUpdateThenReexec(argv = process.argv, env = process.env, waitForUpdate = async () => {
239
+ const { waitForCurrentPackageUseUpdate } = await import("./utils/package-use-lease.js");
240
+ return waitForCurrentPackageUseUpdate();
241
+ }, run = async (command, args, childEnv) => {
242
+ const { spawn } = await import("node:child_process");
243
+ return await new Promise((resolve) => {
244
+ const child = spawn(command, args, { stdio: "inherit", env: childEnv });
245
+ child.on("error", () => resolve(1));
246
+ child.on("exit", (code, signal) => resolve(code ?? (signal ? 128 : 1)));
247
+ });
248
+ }) {
249
+ if (env[REEXEC_ENV] === "1" || !argv[1])
250
+ return false;
251
+ let finished = false;
252
+ try {
253
+ finished = await waitForUpdate();
254
+ }
255
+ catch {
256
+ return false;
257
+ }
258
+ if (!finished)
259
+ return false;
260
+ process.exitCode = await run(process.execPath, argv.slice(1), { ...env, [REEXEC_ENV]: "1" });
261
+ return true;
262
+ }
233
263
  function isNpmPackageEntry(entryUrl) {
234
264
  return /\/node_modules\/@indigoai-us\/hq-cli\/dist\/index\.js$/i.test(entryUrl);
235
265
  }
@@ -260,7 +290,7 @@ function dispatchWithPackageUseLease(entryUrl, dispatch, loadLease = async () =>
260
290
  }, updateRequestPending = async () => {
261
291
  const { currentPackageUseUpdatePending } = await import("./utils/package-use-lease.js");
262
292
  return currentPackageUseUpdatePending();
263
- }) {
293
+ }, waitThenReexec = waitForUpdateThenReexec) {
264
294
  if (!isNpmPackageEntry(entryUrl)) {
265
295
  dispatch();
266
296
  return;
@@ -270,6 +300,12 @@ function dispatchWithPackageUseLease(entryUrl, dispatch, loadLease = async () =>
270
300
  throw error;
271
301
  try {
272
302
  if (await updateRequestPending()) {
303
+ // The install tree is being replaced under this process, so the lease
304
+ // module (or a dependency) failed to load. Wait for the updater, then
305
+ // run the command again from the freshly installed package instead of
306
+ // failing a running session's command outright.
307
+ if (await waitThenReexec())
308
+ return;
273
309
  const pending = new Error("The HQ CLI package is being updated; retry after the update finishes");
274
310
  pending.name = "PackageUseUpdatePendingError";
275
311
  throw pending;
@@ -311,6 +347,7 @@ export const __test__ = {
311
347
  isVersionRequest,
312
348
  isFastCoreRequest,
313
349
  dispatchWithPackageUseLease,
350
+ waitForUpdateThenReexec,
314
351
  runCliEntry,
315
352
  isNpmPackageEntry,
316
353
  acquirePackageUseLease: async (prefix, version, stateDirectory) => {