@indigoai-us/hq-cli 5.345.228 → 5.345.231

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.
@@ -91,4 +91,11 @@ export declare function resolveProcessFlagGate(flagKey: string, lookup: FlagLook
91
91
  export declare function currentFlagSnapshot(): FlagSnapshot | null;
92
92
  /** Test-only reset for process-global readiness state. */
93
93
  export declare function _resetFlagRegistryForTests(): void;
94
+ /**
95
+ * Stop the background registry worker, if one is still running, and wait for
96
+ * it to end. A command that exits right after its own output calls this first:
97
+ * on Node 20 and 22, process.exit while an eval worker is still starting or
98
+ * fetching can crash the process (SIGSEGV) after the output was written.
99
+ */
100
+ export declare function stopFlagRegistryWorker(): Promise<void>;
94
101
  //# sourceMappingURL=flag-registry.d.ts.map
@@ -469,4 +469,24 @@ export function _resetFlagRegistryForTests() {
469
469
  refreshSentry = undefined;
470
470
  refreshDependencies = {};
471
471
  }
472
+ /**
473
+ * Stop the background registry worker, if one is still running, and wait for
474
+ * it to end. A command that exits right after its own output calls this first:
475
+ * on Node 20 and 22, process.exit while an eval worker is still starting or
476
+ * fetching can crash the process (SIGSEGV) after the output was written.
477
+ */
478
+ export async function stopFlagRegistryWorker() {
479
+ const worker = refreshWorker;
480
+ refreshWorker = null;
481
+ if (!worker || typeof worker.terminate !== "function")
482
+ return;
483
+ try {
484
+ await worker.terminate();
485
+ }
486
+ catch {
487
+ // Already ended or never started: nothing is left running to stop.
488
+ }
489
+ completeRefresh?.();
490
+ completeRefresh = null;
491
+ }
472
492
  //# sourceMappingURL=flag-registry.js.map
@@ -148,6 +148,24 @@ export declare function shellHooks(root: string, host: CoreNextHost, event: stri
148
148
  export declare function claimCovers(pattern: string, hook: string): boolean;
149
149
  /** The same install-level checks as stop/precompact/guard.rs, before reindex switches the event. */
150
150
  export declare function precompactCompatibilityHold(root: string, env?: NodeJS.ProcessEnv): string | null;
151
+ /** The hosts a COVERS host set may name (`Host::ALL` in crates/hq-hook/src/host/mod.rs). */
152
+ export declare const COVERS_HOSTS: readonly CoreNextHost[];
153
+ /**
154
+ * A `covers` key read, as crates/hq-hook/src/covers_hosts.rs `key` reads it:
155
+ * `Stop` claims for every host, `SubagentStop@codex,grok` for those hosts
156
+ * only. Null when the key cannot be read (an empty or unknown host, a second
157
+ * `@`, an event that is not ASCII letters): such a key claims nothing.
158
+ */
159
+ export declare function coversKey(key: string): {
160
+ event: string;
161
+ hosts: string[] | null;
162
+ } | null;
163
+ /**
164
+ * What `covers` claims for `event` on `host`: `covers[event]` (every host),
165
+ * then the ids of each host-set key for `event` that names `host`, in key
166
+ * order, each id once. The same as covers_hosts.rs `claims_on`.
167
+ */
168
+ export declare function coveredOn(covers: Readonly<Record<string, readonly string[]>> | undefined, event: string, host: CoreNextHost): string[];
151
169
  /** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
152
170
  export declare function uncoveredHooks(root: string, host: CoreNextHost, event: string, covers: Readonly<Record<string, readonly string[]>> | undefined, env?: NodeJS.ProcessEnv): string[];
153
171
  /** Records the environment `target` was resolved under; returns `target`. */
@@ -1624,12 +1624,53 @@ export function precompactCompatibilityHold(root, env = process.env) {
1624
1624
  }
1625
1625
  return null;
1626
1626
  }
1627
+ /** The hosts a COVERS host set may name (`Host::ALL` in crates/hq-hook/src/host/mod.rs). */
1628
+ export const COVERS_HOSTS = ['claude', 'codex', 'grok', 'fleet-local', 'agents-v2'];
1629
+ /**
1630
+ * A `covers` key read, as crates/hq-hook/src/covers_hosts.rs `key` reads it:
1631
+ * `Stop` claims for every host, `SubagentStop@codex,grok` for those hosts
1632
+ * only. Null when the key cannot be read (an empty or unknown host, a second
1633
+ * `@`, an event that is not ASCII letters): such a key claims nothing.
1634
+ */
1635
+ export function coversKey(key) {
1636
+ const at = key.indexOf('@');
1637
+ const event = at < 0 ? key : key.slice(0, at);
1638
+ let hosts = null;
1639
+ if (at >= 0) {
1640
+ const set = key.slice(at + 1);
1641
+ hosts = set.split(',');
1642
+ if (set.includes('@') || !hosts.every((name) => COVERS_HOSTS.includes(name)))
1643
+ return null;
1644
+ }
1645
+ if (!/^[A-Za-z]+$/.test(event))
1646
+ return null;
1647
+ return { event, hosts };
1648
+ }
1649
+ /**
1650
+ * What `covers` claims for `event` on `host`: `covers[event]` (every host),
1651
+ * then the ids of each host-set key for `event` that names `host`, in key
1652
+ * order, each id once. The same as covers_hosts.rs `claims_on`.
1653
+ */
1654
+ export function coveredOn(covers, event, host) {
1655
+ const out = [...(covers?.[event] ?? [])];
1656
+ for (const [key, ids] of Object.entries(covers ?? {})) {
1657
+ if (!key.includes('@'))
1658
+ continue;
1659
+ const read = coversKey(key);
1660
+ if (!read || read.event !== event || !read.hosts?.includes(host))
1661
+ continue;
1662
+ for (const id of ids)
1663
+ if (!out.includes(id))
1664
+ out.push(id);
1665
+ }
1666
+ return out;
1667
+ }
1627
1668
  /** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
1628
1669
  export function uncoveredHooks(root, host, event, covers, env = process.env) {
1629
1670
  const hooks = shellHooks(root, host, event);
1630
1671
  if (!hooks)
1631
1672
  return [UNREADABLE];
1632
- const covered = covers?.[event] ?? [];
1673
+ const covered = coveredOn(covers, event, host);
1633
1674
  const missing = hooks.filter((hook) => !covered.some((claim) => claimCovers(claim, hook)));
1634
1675
  if (event === 'Stop' && covered.includes('master-hook:Stop')) {
1635
1676
  const hold = stopCompatibilityHold(root, env);
@@ -351,6 +351,82 @@ function sendQueue(root, link, child, text) {
351
351
  appendDropboxMessageAtPath(pending, { at: new Date().toISOString(), text: cleanText });
352
352
  });
353
353
  }
354
+ /**
355
+ * The daemon's conduct-lanes-link-deliver run (a Codex SubagentStop note) sets
356
+ * HQ_LINK_DELIVER_QUEUED_AT_OR_BEFORE to the event's time, so `_deliver`
357
+ * takes only the messages queued at or before that event; later ones stay
358
+ * pending for the root's next PostToolUse or Stop. Unset: everything is taken,
359
+ * as before. Returns null for a value it cannot read (the caller then takes
360
+ * nothing).
361
+ */
362
+ function deliverCutoff(env) {
363
+ const raw = env.HQ_LINK_DELIVER_QUEUED_AT_OR_BEFORE;
364
+ if (raw === undefined)
365
+ return undefined;
366
+ if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?Z$/.test(raw))
367
+ return null;
368
+ const at = Date.parse(raw);
369
+ return Number.isFinite(at) ? at : null;
370
+ }
371
+ const HELD_LATER = "held-after-cutoff.jsonl";
372
+ /** Put back rows a cutoff held out of a take that did not finish (crash). Caller holds the queue lock. */
373
+ function restoreHeldRowsUnlocked(inbox) {
374
+ const held = path.join(inbox, HELD_LATER);
375
+ if (!fs.existsSync(held))
376
+ return;
377
+ const pending = path.join(inbox, "pending");
378
+ fs.mkdirSync(pending, { recursive: true });
379
+ const rows = fs.readFileSync(held, "utf8");
380
+ if (rows)
381
+ fs.appendFileSync(path.join(pending, "inbox.jsonl"), rows.endsWith("\n") ? rows : `${rows}\n`, { mode: 0o600 });
382
+ fs.rmSync(held, { force: true });
383
+ }
384
+ /**
385
+ * Before a take with a cutoff: move the pending rows queued after the cutoff,
386
+ * and rows whose time cannot be read, to a held file beside pending, so the
387
+ * take sees only rows at or before it. Caller holds the queue lock and calls
388
+ * restoreHeldRowsUnlocked after the take.
389
+ */
390
+ function holdRowsAfterCutoffUnlocked(inbox, cutoff) {
391
+ const file = path.join(inbox, "pending", "inbox.jsonl");
392
+ if (!fs.existsSync(file))
393
+ return;
394
+ const due = [];
395
+ const later = [];
396
+ for (const line of fs.readFileSync(file, "utf8").split(/\r?\n/)) {
397
+ if (!line)
398
+ continue;
399
+ let at = Number.NaN;
400
+ try {
401
+ const row = JSON.parse(line);
402
+ const value = row && typeof row === "object" ? row.at : undefined;
403
+ if (typeof value === "string")
404
+ at = Date.parse(value);
405
+ }
406
+ catch { /* unreadable rows are not ours to take */ }
407
+ (Number.isFinite(at) && at <= cutoff ? due : later).push(line);
408
+ }
409
+ if (!later.length)
410
+ return;
411
+ fs.writeFileSync(path.join(inbox, HELD_LATER), `${later.join("\n")}\n`, { mode: 0o600 });
412
+ if (due.length)
413
+ fs.writeFileSync(file, `${due.join("\n")}\n`, { mode: 0o600 });
414
+ else
415
+ fs.rmSync(file, { force: true });
416
+ }
417
+ /** Run a take on the queue, limited to rows queued at or before cutoff when one is given. Caller holds the queue lock. */
418
+ function takeUpToUnlocked(inbox, cutoff, take) {
419
+ restoreHeldRowsUnlocked(inbox);
420
+ if (cutoff === undefined)
421
+ return take();
422
+ holdRowsAfterCutoffUnlocked(inbox, cutoff);
423
+ try {
424
+ return take();
425
+ }
426
+ finally {
427
+ restoreHeldRowsUnlocked(inbox);
428
+ }
429
+ }
354
430
  /** Claims pending files by renaming the whole queue, matching conduct-inbox's no-loss drain. */
355
431
  function drainLinkQueueUnlocked(inbox) {
356
432
  const pending = path.join(inbox, "pending");
@@ -543,9 +619,6 @@ function claimLinkQueueUnlocked(inbox) {
543
619
  }
544
620
  return { messages: messages.join("\n"), claims };
545
621
  }
546
- function claimLinkQueue(inbox) {
547
- return withLinkQueueLock(inbox, () => claimLinkQueueUnlocked(inbox));
548
- }
549
622
  function acknowledgeLinkClaims(inbox, claims) {
550
623
  return withLinkQueueLock(inbox, () => acknowledgeLinkClaimsUnlocked(inbox, claims));
551
624
  }
@@ -734,21 +807,29 @@ export async function runLaneLink(subcommand, options) {
734
807
  const target = hookMessage(root, pointer);
735
808
  if (options.ackMode !== undefined && options.ackMode !== "explicit")
736
809
  throw new LaneLinkError("ack_mode_invalid", "Unsupported acknowledgement mode");
810
+ // A cutoff it cannot read: take nothing, everything stays queued.
811
+ const cutoff = deliverCutoff(env);
812
+ if (cutoff === null)
813
+ return {};
737
814
  let claim;
738
815
  let messages;
739
816
  if (pointer.role === "conductor") {
740
817
  await options.beforeConductorQueue?.();
741
- const drained = withConductorQueue(root, pointer.link, sid, (inbox) => options.ackMode === "explicit"
818
+ const drained = withConductorQueue(root, pointer.link, sid, (inbox) => takeUpToUnlocked(inbox, cutoff, () => options.ackMode === "explicit"
742
819
  ? { claim: claimLinkQueueUnlocked(inbox), messages: "" }
743
- : { claim: undefined, messages: drainLinkQueueUnlocked(inbox) });
820
+ : { claim: undefined, messages: drainLinkQueueUnlocked(inbox) }));
744
821
  if (drained === null)
745
822
  return {};
746
823
  claim = drained.claim;
747
824
  messages = claim ? claim.messages : drained.messages;
748
825
  }
749
826
  else {
750
- claim = options.ackMode === "explicit" ? claimLinkQueue(target.inbox) : undefined;
751
- messages = claim ? claim.messages : drainLinkQueue(target.inbox);
827
+ const inbox = target.inbox;
828
+ const taken = withLinkQueueLock(inbox, () => takeUpToUnlocked(inbox, cutoff, () => options.ackMode === "explicit"
829
+ ? { claim: claimLinkQueueUnlocked(inbox), messages: "" }
830
+ : { claim: undefined, messages: drainLinkQueueUnlocked(inbox) }));
831
+ claim = taken.claim;
832
+ messages = claim ? claim.messages : taken.messages;
752
833
  }
753
834
  if (!messages)
754
835
  return {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * End the CLI with `code` after the flag-registry worker has stopped.
3
+ * Use `return await exitCli(code)` (or `await exitCli(code)` as the last
4
+ * statement) so no code runs past the call while the worker stops.
5
+ */
6
+ export declare function exitCli(code: number): Promise<never>;
7
+ //# sourceMappingURL=exit-after-worker.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { stopFlagRegistryWorker } from "../lib/flag-registry.js";
2
+ /**
3
+ * End the CLI with `code` after the flag-registry worker has stopped.
4
+ * Use `return await exitCli(code)` (or `await exitCli(code)` as the last
5
+ * statement) so no code runs past the call while the worker stops.
6
+ */
7
+ export async function exitCli(code) {
8
+ try {
9
+ await stopFlagRegistryWorker();
10
+ }
11
+ finally {
12
+ process.exit(code);
13
+ }
14
+ }
15
+ //# sourceMappingURL=exit-after-worker.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.345.228",
3
+ "version": "5.345.231",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -62,7 +62,7 @@
62
62
  "@aws-sdk/client-iot-data-plane": "^3.1096.0",
63
63
  "@aws-sdk/client-s3": "^3.1049.0",
64
64
  "@aws-sdk/dsql-signer": "^3.1146.0",
65
- "@indigoai-us/hq-cloud": "6.18.110",
65
+ "@indigoai-us/hq-cloud": "6.18.112",
66
66
  "@indigoai-us/hq-flags-client": "^0.2.0",
67
67
  "@modelcontextprotocol/sdk": "1.32.2",
68
68
  "@sentry/node": "^10.49.0",
@@ -125,11 +125,11 @@
125
125
  "*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
126
126
  },
127
127
  "optionalDependencies": {
128
- "@indigoai-us/hq-hook-win32-x64": "5.345.228",
129
- "@indigoai-us/hq-hook-win32-arm64": "5.345.228",
130
- "@indigoai-us/hq-hook-darwin-x64": "5.345.228",
131
- "@indigoai-us/hq-hook-darwin-arm64": "5.345.228",
132
- "@indigoai-us/hq-hook-linux-x64": "5.345.228",
133
- "@indigoai-us/hq-hook-linux-arm64": "5.345.228"
128
+ "@indigoai-us/hq-hook-win32-x64": "5.345.231",
129
+ "@indigoai-us/hq-hook-win32-arm64": "5.345.231",
130
+ "@indigoai-us/hq-hook-darwin-x64": "5.345.231",
131
+ "@indigoai-us/hq-hook-darwin-arm64": "5.345.231",
132
+ "@indigoai-us/hq-hook-linux-x64": "5.345.231",
133
+ "@indigoai-us/hq-hook-linux-arm64": "5.345.231"
134
134
  }
135
135
  }