@indigoai-us/hq-cli 5.345.257 → 5.345.258

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [5.345.258] — 2026-11-26
6
+ - Fixed hooks switching between the hook engine and the shell scripts from one event to the next when an `hq` older than 5.345.252 also runs on the same machine. That older release asks for flags without reporting its version, gets a different answer, and saved it to the same local flag file. The CLI now saves flags to `snapshot-v2-<scope>.json`, and the CLI and `hq-hook` read only that file. The CLI still writes `snapshot-<scope>.json` with the same contents for older readers. Until a scope has a `snapshot-v2-` file, a feature that is turned off in its old file stays off; nothing else is read from the old file, so hook ports stay on the shell scripts until a current `hq` command or the daemon writes the new file.
7
+ - Changed: the host canary record shipped with the CLI is refreshed for this release build.
8
+ - Fixed: on Windows, hq-hook now starts `git` (credential-guard `rev-parse` and glob toplevel lookup) with `CREATE_NO_WINDOW`, so those probes no longer open a console window on every file read.
9
+ - Fixed: `hq sync pull` with `HQ_API_KEY` (the keyed pull used to hydrate a MicroVM) no longer fails the whole pull when the vault holds keys that normal sync never writes. It now skips `.git` internals, `.hq/` reserved files, folder markers such as `lambda/`, paths excluded by the HQ ignore files, unsafe paths (traversal, absolute, control characters), both spellings of a case-only collision, and directory overlay markers, writes the rest, and prints the skip count for each reason.
10
+ - Fixed: the keyed pull (`HQ_API_KEY`) now skips, and counts as `forbidden`, an object its key may not read (a per-object 403 from the presign route or from storage), instead of failing the whole hydrate. The object is never written. A 401, a 5xx, a size mismatch, a 403 on the list call, a 403 that did not come from storage, and a key refused on every listed object still fail the pull.
11
+ - The Rust hook engine's native PreToolUse now accepts the hq-core 16.0.52 credential-file read script, so an HQ on 16.0.52 with the new core switched on is no longer kept on the old dispatcher for that file. On such an HQ, on macOS and Linux and on every host, the native credential-file read check gives the same answer as the 16.0.52 shell version for a URL operand of `curl` or `wget` in a line with more than one command and for template files such as `example.env`. Its answers for `git grep`, `git diff`, `git log -p` and `git show` are unchanged. On such an HQ the check also refuses every Bash call when `HQ_CREDENTIAL_GUARD_BUDGET_SECONDS` is `00`, and refuses git content reads when `GIT_INDEX_FILE` is set. An HQ on an older core is answered as before. On Windows, where the native check answers, an HQ on 16.0.52 gets those two refusals and is otherwise answered as before.
12
+ - hq-hook: Codex on hq-core 16.0.51 and 16.0.52 now gets PreToolUse answers from the Rust engine. The engine reads `core/scripts/lib/hook-adapter-core.sh` at the 16.0.51 (`09f5a3e0`) and 16.0.52 (`cf1abd5c`) revisions on Codex, as it already did on Claude Code. The entry `hq reindex` writes into `.claude/settings.json` for Claude Code (`hq-hook run --host claude PreToolUse --hq-root <root>`) is read on Codex as the shell adapter reads it. Any other `.claude/settings.json` PreToolUse entry written with an `args` list is a shape HQ does not write and does not support on Codex: on any hq-core release, 16.0.50 included, the engine refuses the tool call with a message that names the settings file, and `hq reindex` keeps Codex PreToolUse on the shell dispatcher for that HQ.
13
+ - Port the `hook-lib.sh` v16.0.52 (`436493e3`) `hd_text_arg` lexer rule for `hq core handoff finalize --summary`/`--title` and pin `436493e3` in `pre_tool_use_master::DISPATCHER_PINS`.
14
+ - The native merged write check accepts the `core/scripts/hook-lib.sh` that hq-core 16.0.52 ships beside the released shadow wrapper, off Windows, so `hq reindex` no longer keeps PreToolUse on the shell dispatcher for that file on its account.
15
+
5
16
  ## [5.345.257] — 2026-11-25
6
17
  - hq-hook: on agents-v2 bots running the hq-agents-v2 #347 adapter, company PostToolUse hooks now run in the native hook engine when `HQ_MASTER_CHILD_TIMEOUT` is short enough that every hook can run to its limit inside the call budget and the adapter's 18 s start window (for example two hooks at 2 s in the 5 s budget). Before, the engine always handed these calls back to the adapter. Each hook is killed at the same limit master-hook uses. With the stock 120 s limit, more hooks than fit, or a lowered adapter budget, the call still goes to the adapter, and SessionStart is unchanged.
7
18
  - Fixed: preserve `RUSTUP_HOME` and `CARGO_HOME` in `credential_grep_sources::real_stdout` when redirecting `HOME` to the fixture directory so `round12_formatter` (`cargo fmt && git diff`) finds the runner's toolchain on AWS Linux runners.
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "schema": "hq.host-canary-release.v1",
3
- "cliVersion": "5.345.257",
3
+ "cliVersion": "5.345.258",
4
4
  "hosts": {
5
5
  "claude": [
6
6
  {
7
7
  "passed": true,
8
- "at": "2026-11-25T20:07:54.394Z",
9
- "engineVersion": "0.3.1+hq.5.345.257.src.c469d58a7b027d94faefc6a1d4b18ffed5c6a52cdcf89f7c9158542d4e2527dc",
8
+ "at": "2026-11-25T22:47:31.151Z",
9
+ "engineVersion": "0.3.1+hq.5.345.258.src.313d6d26b252570fbd1a0e799378f5a2c8722f03aefbe814ae2275bb0eb65770",
10
10
  "gateSha256": "a2879dfe692233f5953bac86672947bbd82f3c5247292f3efcb80f16c3d2c6b1"
11
11
  },
12
12
  {
13
13
  "passed": true,
14
- "at": "2026-11-25T20:08:38.408Z",
15
- "engineVersion": "0.3.1+hq.5.345.257.src.c469d58a7b027d94faefc6a1d4b18ffed5c6a52cdcf89f7c9158542d4e2527dc",
14
+ "at": "2026-11-25T22:48:04.381Z",
15
+ "engineVersion": "0.3.1+hq.5.345.258.src.313d6d26b252570fbd1a0e799378f5a2c8722f03aefbe814ae2275bb0eb65770",
16
16
  "gateSha256": "ca58a94859eae0a345c11c8d9c59303eb76350dc1cf223391037d21979c28718"
17
17
  },
18
18
  {
19
19
  "passed": true,
20
- "at": "2026-11-25T20:09:12.395Z",
21
- "engineVersion": "0.3.1+hq.5.345.257.src.c469d58a7b027d94faefc6a1d4b18ffed5c6a52cdcf89f7c9158542d4e2527dc",
20
+ "at": "2026-11-25T22:48:34.578Z",
21
+ "engineVersion": "0.3.1+hq.5.345.258.src.313d6d26b252570fbd1a0e799378f5a2c8722f03aefbe814ae2275bb0eb65770",
22
22
  "gateSha256": "ecdbab7c2e0a1d94eb9c98f15e760390f215bc7115a217ded24b4275322722d2"
23
23
  }
24
24
  ]
@@ -1906,7 +1906,10 @@ export function registerCloudCommands(program) {
1906
1906
  companySlug: options.companySlug,
1907
1907
  token: process.env.HQ_API_KEY.trim(),
1908
1908
  }, { sync: keyedSyncPull });
1909
- console.log(`Keyed pull: ${result.filesDownloaded} files downloaded; unlisted local files preserved.`);
1909
+ const skips = Object.entries(result.skipped).filter(([, count]) => count > 0);
1910
+ const skipped = skips.reduce((sum, [, count]) => sum + count, 0);
1911
+ const skipText = skipped === 0 ? "none skipped" : `${skipped} skipped (${skips.map(([reason, count]) => `${reason} ${count}`).join(", ")})`;
1912
+ console.log(`Keyed pull: ${result.filesDownloaded} files downloaded; ${skipText}; unlisted local files preserved.`);
1910
1913
  return;
1911
1914
  }
1912
1915
  const skips = refuseSyncForOffVaults("pull", {
@@ -4,9 +4,13 @@ export interface KeyedPullOptions {
4
4
  companySlug?: string;
5
5
  token: string;
6
6
  }
7
+ /** Why a listed key was not written. Counted per reason in the result. */
8
+ export type KeyedPullSkipReason = "unsafe-path" | "directory-marker" | "sync-ignored" | "case-collision" | "overlay-marker" | "forbidden";
9
+ export interface KeyedPullResult {
10
+ filesDownloaded: number;
11
+ skipped: Record<KeyedPullSkipReason, number>;
12
+ }
7
13
  /** No session discovery, journal, deletes or tombstones: absence from an
8
14
  * ACL-filtered inventory never proves deletion. */
9
- export declare function keyedSyncPull(options: KeyedPullOptions): Promise<{
10
- filesDownloaded: number;
11
- }>;
15
+ export declare function keyedSyncPull(options: KeyedPullOptions): Promise<KeyedPullResult>;
12
16
  //# sourceMappingURL=keyed-sync-pull.d.ts.map
@@ -3,12 +3,46 @@ import path from "node:path";
3
3
  import { Transform } from "node:stream";
4
4
  import { pipeline } from "node:stream/promises";
5
5
  import { GetObjectCommand } from "@aws-sdk/client-s3";
6
+ import { createIgnoreFilter, relativePathRejectionReason } from "@indigoai-us/hq-cloud";
6
7
  import { vaultApiFetch } from "../utils/vault-api.js";
7
8
  const fail = (message) => Object.assign(new Error(message), { expected: true });
8
- function safeKey(value) {
9
- return typeof value === "string" && value.length > 0 &&
10
- !/[\\:]/.test(value) && ![...value].some(char => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127) &&
11
- value.split("/").every(part => part.length > 0 && ![".", "..", ".git", ".hq"].includes(part.toLowerCase()) && !/[. ]$/.test(part));
9
+ /** The hq-cloud push/pull path grammar (traversal, absolute, empty segments,
10
+ * backslashes, NUL), plus the stricter local rules this pull has always had:
11
+ * control characters, drive colons and segments ending in a dot or space. */
12
+ function unsafePath(key) {
13
+ return relativePathRejectionReason(key) !== null || key.includes(":") ||
14
+ [...key].some(char => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127) ||
15
+ key.split("/").some(part => /[. ]$/.test(part));
16
+ }
17
+ /** Normal sync never writes `.git` internals or `.hq` reserved files. The
18
+ * ignore filter already excludes both; this keeps them out if an
19
+ * `.hqinclude` re-includes them. */
20
+ /** One object the key may not read: the presign route or its row refused
21
+ * the key (403), or storage itself refused the signed GET (403). A 403 that
22
+ * did not come from storage (a proxy or egress rule), a 401, a 5xx and every
23
+ * other failure stay fatal; a 403 on the list call never reaches here. */
24
+ function objectForbidden(err) {
25
+ if (!err || typeof err !== "object")
26
+ return false;
27
+ const e = err;
28
+ // presignedDownloadError (files-browse.ts) marks storage refusals with fromStorage.
29
+ if ("fromStorage" in e)
30
+ return e.httpStatus === 403 && e.fromStorage === true;
31
+ return e.status === 403 && e.httpStatus === undefined;
32
+ }
33
+ const reservedSegment = (key) => key.split("/").some(part => [".git", ".hq"].includes(part.toLowerCase()));
34
+ /** Classify one listed key the way the normal sync pull planner does:
35
+ * folder markers and invalid key grammar are skipped (never presigned), then
36
+ * the HQ ignore rules decide. `excluded` probes both file and directory
37
+ * hints, as the planner does, because the listing has no kind. */
38
+ function skipReason(key, excluded) {
39
+ if (key.length > 1 && key.endsWith("/") && !unsafePath(key.slice(0, -1)))
40
+ return "directory-marker";
41
+ if (unsafePath(key))
42
+ return "unsafe-path";
43
+ if (reservedSegment(key) || excluded(key))
44
+ return "sync-ignored";
45
+ return null;
12
46
  }
13
47
  /** Require a real directory chain. Hydration runs before workload execution,
14
48
  * in a launcher-owned tree without concurrent writers. */
@@ -54,8 +88,14 @@ export async function keyedSyncPull(options) {
54
88
  if (!companySlug || !/^[a-z0-9][a-z0-9_-]*$/.test(companySlug))
55
89
  throw fail("Keyed pull requires a safe --company-slug from the trusted launcher");
56
90
  const root = path.resolve(options.hqRoot, "companies", companySlug);
57
- const files = [];
58
- const names = new Set();
91
+ const listed = [];
92
+ const skipped = { "unsafe-path": 0, "directory-marker": 0, "sync-ignored": 0, "case-collision": 0, "overlay-marker": 0, forbidden: 0 };
93
+ let shouldSync;
94
+ const excluded = (key) => {
95
+ shouldSync ??= createIgnoreFilter(options.hqRoot);
96
+ const local = path.join(root, key);
97
+ return !shouldSync(local, false) && !shouldSync(local, true);
98
+ };
59
99
  const cursors = new Set();
60
100
  let cursor;
61
101
  for (let page = 0;; page++) {
@@ -81,13 +121,14 @@ export async function keyedSyncPull(options) {
81
121
  throw fail("Keyed pull inventory is incomplete or malformed");
82
122
  for (const value of body.objects) {
83
123
  const row = value;
84
- if (!row || !safeKey(row.key) || !Number.isSafeInteger(row.size) || row.size < 0)
85
- throw fail("Keyed pull inventory contains an unsafe file");
86
- const name = row.key.normalize("NFC").toLowerCase();
87
- if (names.has(name))
88
- throw fail("Keyed pull inventory contains colliding files");
89
- names.add(name);
90
- files.push({ key: row.key, size: row.size });
124
+ if (!row || typeof row.key !== "string" || !Number.isSafeInteger(row.size) || row.size < 0)
125
+ throw fail("Keyed pull inventory is incomplete or malformed");
126
+ const reason = skipReason(row.key, excluded);
127
+ if (reason) {
128
+ skipped[reason]++;
129
+ continue;
130
+ }
131
+ listed.push({ key: row.key, size: row.size });
91
132
  }
92
133
  if (!body.truncated) {
93
134
  if (body.cursor !== undefined && body.cursor !== null && body.cursor !== "")
@@ -99,17 +140,26 @@ export async function keyedSyncPull(options) {
99
140
  cursor = body.cursor;
100
141
  cursors.add(cursor);
101
142
  }
102
- for (const name of names) {
103
- const parts = name.split("/");
104
- for (let i = 1; i < parts.length; i++) {
105
- if (names.has(parts.slice(0, i).join("/")))
106
- throw fail("Keyed pull inventory has a file/directory collision");
107
- }
143
+ // Keys that differ only in case share one file on a case-folding disk.
144
+ // Normal sync has no rule for picking one live spelling, so write neither.
145
+ const fold = (key) => key.normalize("NFC").toLowerCase();
146
+ const spellings = new Map();
147
+ for (const file of listed)
148
+ spellings.set(fold(file.key), (spellings.get(fold(file.key)) ?? 0) + 1);
149
+ const unique = listed.filter(file => spellings.get(fold(file.key)) === 1 || (skipped["case-collision"]++, false));
150
+ // An object whose key is also a parent of listed objects is a directory
151
+ // overlay marker; normal sync skips it and materializes the children.
152
+ const parents = new Set();
153
+ for (const file of unique) {
154
+ const parts = fold(file.key).split("/");
155
+ for (let i = 1; i < parts.length; i++)
156
+ parents.add(parts.slice(0, i).join("/"));
108
157
  }
158
+ const files = unique.filter(file => !parents.has(fold(file.key)) || (skipped["overlay-marker"]++, false));
109
159
  for (const file of files)
110
160
  await destination(path.join(root, file.key));
111
161
  if (files.length === 0)
112
- return { filesDownloaded: 0 };
162
+ return { filesDownloaded: 0, skipped };
113
163
  await directories(root, true);
114
164
  const stage = await fs.mkdtemp(path.join(root, ".keyed-pull-"));
115
165
  try {
@@ -117,9 +167,22 @@ export async function keyedSyncPull(options) {
117
167
  // identity resolution; defer it here to avoid a static command cycle.
118
168
  const { createCompanyPresignClient } = await import("./files-browse.js");
119
169
  const client = createCompanyPresignClient({ token, companyUid: company, companySlug });
170
+ const forbidden = new Set();
120
171
  for (const [index, file] of files.entries()) {
172
+ let result;
173
+ try {
174
+ result = await client.send(new GetObjectCommand({ Bucket: "resolved-server-side", Key: file.key }));
175
+ }
176
+ catch (err) {
177
+ // Not readable with this key: count it, write nothing, keep going.
178
+ if (objectForbidden(err)) {
179
+ forbidden.add(index);
180
+ skipped.forbidden++;
181
+ continue;
182
+ }
183
+ throw fail("Keyed pull download failed; no staged files were applied");
184
+ }
121
185
  try {
122
- const result = await client.send(new GetObjectCommand({ Bucket: "resolved-server-side", Key: file.key }));
123
186
  if (!result.Body)
124
187
  throw fail("Missing body");
125
188
  let size = 0;
@@ -136,13 +199,18 @@ export async function keyedSyncPull(options) {
136
199
  throw fail("Keyed pull download failed; no staged files were applied");
137
200
  }
138
201
  }
202
+ // A key refused on every listed object is the wrong key, not a few private files.
203
+ if (forbidden.size === files.length)
204
+ throw fail("Keyed pull key could not read any listed file");
139
205
  for (const [index, file] of files.entries()) {
206
+ if (forbidden.has(index))
207
+ continue;
140
208
  const target = path.join(root, file.key);
141
209
  await destination(target);
142
210
  await directories(path.dirname(target), true);
143
211
  await fs.rename(path.join(stage, String(index)), target);
144
212
  }
145
- return { filesDownloaded: files.length };
213
+ return { filesDownloaded: files.length - forbidden.size, skipped };
146
214
  }
147
215
  finally {
148
216
  await fs.rm(stage, { recursive: true, force: true });
@@ -11,7 +11,7 @@
11
11
  import * as fs from "node:fs";
12
12
  import * as os from "node:os";
13
13
  import * as path from "node:path";
14
- import { FLAG_SNAPSHOT_MAX_AGE_MS } from "../../flag-snapshot-file.js";
14
+ import { FLAG_SNAPSHOT_MAX_AGE_MS, flagSnapshotFileName } from "../../flag-snapshot-file.js";
15
15
  export const REPLAY_RECORDER_FLAG = "core.replay-recorder";
16
16
  export const REPLAY_RECORDER_KILL_ENV = "HQ_REPLAY_RECORDER";
17
17
  export const REPLAY_RECORDER_MAX_BYTES_ENV = "HQ_REPLAY_RECORDER_MAX_BYTES";
@@ -74,7 +74,7 @@ function fallbackPersonSnapshotFile(tmpdir) {
74
74
  return null;
75
75
  }
76
76
  }
77
- return path.join(root, "hq", "flags", "snapshot-person.json");
77
+ return path.join(root, "hq", "flags", flagSnapshotFileName("person"));
78
78
  }
79
79
  /**
80
80
  * Same rule as `flags::person_flag_enabled` in the engine: the newer valid one
@@ -83,7 +83,7 @@ function fallbackPersonSnapshotFile(tmpdir) {
83
83
  */
84
84
  function personFlagOn(home, env, now, tmpdir) {
85
85
  const cacheHome = env.XDG_CACHE_HOME || path.join(home, ".cache");
86
- const primary = readPersonSnapshot(path.join(cacheHome, "hq", "flags", "snapshot-person.json"), now);
86
+ const primary = readPersonSnapshot(path.join(cacheHome, "hq", "flags", flagSnapshotFileName("person")), now);
87
87
  const fallbackFile = fallbackPersonSnapshotFile(tmpdir);
88
88
  const fallback = fallbackFile ? readPersonSnapshot(fallbackFile, now) : null;
89
89
  const chosen = primary && fallback ? (fallback.fetchedAt > primary.fetchedAt ? fallback : primary) : (primary ?? fallback);
@@ -1,5 +1,30 @@
1
1
  /** Private, synchronous, offline snapshot used by the native CLI fast route. */
2
2
  export declare const FLAG_SNAPSHOT_MAX_AGE_MS: number;
3
+ /**
4
+ * Snapshot file names. Every reader in this CLI and in hq-hook reads only the
5
+ * `snapshot-v2-` files. hq-cli before f99ed6013 asked for flags without
6
+ * reporting its version and platform, so the server answered `false` for rows
7
+ * that require that report, and it wrote that answer to `snapshot-<scope>.json`.
8
+ * Those releases never write a `snapshot-v2-` file, so what they write cannot
9
+ * reach a current reader. This CLI still writes the `snapshot-<scope>.json`
10
+ * file beside each `snapshot-v2-` file, with the same contents, for readers
11
+ * released before the rename (an older hq-hook, the hq-core shell hooks), so
12
+ * they behave as they did. The shared names are pinned in
13
+ * `crates/hq-hook/src/flags.rs` (`snapshot_file_name`).
14
+ *
15
+ * Upgrade window: until a scope has a `snapshot-v2-` file, an explicit
16
+ * `false` in its old-name file still counts, and nothing else in it does
17
+ * (`legacyFalseFlags`). A `false` is the only wrong answer an old client
18
+ * gets (a row that requires a client report fails closed), and for a
19
+ * default-on kill switch it keeps the answer the CLI gave before the rename.
20
+ * A `true` from the old file is never used, and once any `snapshot-v2-` file
21
+ * exists for the scope the old file is not read at all.
22
+ */
23
+ export declare const FLAG_SNAPSHOT_FILE_PREFIX = "snapshot-v2-";
24
+ /** The current snapshot file name for a company uid or the person scope. */
25
+ export declare function flagSnapshotFileName(scope: string): string;
26
+ /** The same file under the name hq-cli used before the rename. */
27
+ export declare function legacyFlagSnapshotPath(currentPath: string): string;
3
28
  /** Epoch ms of a snapshot `fetched_at`, or NaN when it is not in the shared grammar. */
4
29
  export declare function parseSnapshotTime(text: string): number;
5
30
  export type FlagSnapshotWriteStep = "mkdir" | "chmod_dir" | "open_tmp" | "write_tmp" | "rename" | "chmod_file";
@@ -28,17 +53,38 @@ export declare function readPersonFlagSnapshotFile(options?: {
28
53
  now?: number;
29
54
  maxAgeMs?: number;
30
55
  }): PersistedPersonFlagSnapshot | null;
56
+ /** The person `snapshot-v2-` file alone: never the old-name file. */
57
+ export declare function readCurrentPersonFlagSnapshotFile(options?: {
58
+ env?: NodeJS.ProcessEnv;
59
+ now?: number;
60
+ maxAgeMs?: number;
61
+ }): PersistedPersonFlagSnapshot | null;
31
62
  /** Write just the validated flag decisions and company scope, never auth data. */
32
63
  export declare function writeFlagSnapshotFile(companyUid: string, flags: Readonly<Record<string, unknown>>, options?: {
33
64
  env?: NodeJS.ProcessEnv;
34
65
  fetchedAt?: string;
35
66
  }): string;
36
- /** Return null for every miss, malformed file, company mismatch, or stale file. */
67
+ /**
68
+ * Return null for every miss, malformed file, company mismatch, or stale file.
69
+ * With no `snapshot-v2-` file for the company at all, the explicit `false`
70
+ * values of its old-name file answer, and only those (see
71
+ * `FLAG_SNAPSHOT_FILE_PREFIX`).
72
+ */
37
73
  export declare function readFlagSnapshotFile(companyUid: string, options?: {
38
74
  env?: NodeJS.ProcessEnv;
39
75
  now?: number;
40
76
  maxAgeMs?: number;
41
77
  }): PersistedFlagSnapshot | null;
78
+ /**
79
+ * The company's `snapshot-v2-` file alone, never the old-name file. For a
80
+ * caller that must know whether a current snapshot exists, such as the
81
+ * refresh that writes one.
82
+ */
83
+ export declare function readCurrentFlagSnapshotFile(companyUid: string, options?: {
84
+ env?: NodeJS.ProcessEnv;
85
+ now?: number;
86
+ maxAgeMs?: number;
87
+ }): PersistedFlagSnapshot | null;
42
88
  /** Resolve a default-on kill switch from offline snapshots, allowing stale decisions. */
43
89
  export declare function readDefaultOnFlagSnapshot(flagKey: string, companyUid?: string, env?: NodeJS.ProcessEnv): boolean;
44
90
  //# sourceMappingURL=flag-snapshot-file.d.ts.map
@@ -6,6 +6,43 @@ import { freshAnywhereRuntimeFlags, HQ_ANYWHERE_RUNTIME_FLAG, HQ_ANYWHERE_RUNTIM
6
6
  import { noteReplacedCompanySnapshot } from "./mesh/live/company-reporting-gaps.js";
7
7
  export const FLAG_SNAPSHOT_MAX_AGE_MS = 24 * 60 * 60 * 1000;
8
8
  const COMPANY_UID_RE = /^cmp_[A-Za-z0-9]{3,128}$/;
9
+ /**
10
+ * Snapshot file names. Every reader in this CLI and in hq-hook reads only the
11
+ * `snapshot-v2-` files. hq-cli before f99ed6013 asked for flags without
12
+ * reporting its version and platform, so the server answered `false` for rows
13
+ * that require that report, and it wrote that answer to `snapshot-<scope>.json`.
14
+ * Those releases never write a `snapshot-v2-` file, so what they write cannot
15
+ * reach a current reader. This CLI still writes the `snapshot-<scope>.json`
16
+ * file beside each `snapshot-v2-` file, with the same contents, for readers
17
+ * released before the rename (an older hq-hook, the hq-core shell hooks), so
18
+ * they behave as they did. The shared names are pinned in
19
+ * `crates/hq-hook/src/flags.rs` (`snapshot_file_name`).
20
+ *
21
+ * Upgrade window: until a scope has a `snapshot-v2-` file, an explicit
22
+ * `false` in its old-name file still counts, and nothing else in it does
23
+ * (`legacyFalseFlags`). A `false` is the only wrong answer an old client
24
+ * gets (a row that requires a client report fails closed), and for a
25
+ * default-on kill switch it keeps the answer the CLI gave before the rename.
26
+ * A `true` from the old file is never used, and once any `snapshot-v2-` file
27
+ * exists for the scope the old file is not read at all.
28
+ */
29
+ export const FLAG_SNAPSHOT_FILE_PREFIX = "snapshot-v2-";
30
+ /**
31
+ * Any age, including a `fetched_at` in the future: with `now` at infinity
32
+ * every valid timestamp has an infinite age, which an infinite limit accepts.
33
+ * Used to ask whether a scope has any `snapshot-v2-` file at all.
34
+ */
35
+ const ANY_AGE = { maxAgeMs: Number.POSITIVE_INFINITY, now: Number.POSITIVE_INFINITY };
36
+ const LEGACY_FLAG_SNAPSHOT_FILE_PREFIX = "snapshot-";
37
+ /** The current snapshot file name for a company uid or the person scope. */
38
+ export function flagSnapshotFileName(scope) {
39
+ return `${FLAG_SNAPSHOT_FILE_PREFIX}${scope}.json`;
40
+ }
41
+ /** The same file under the name hq-cli used before the rename. */
42
+ export function legacyFlagSnapshotPath(currentPath) {
43
+ const name = path.basename(currentPath);
44
+ return path.join(path.dirname(currentPath), `${LEGACY_FLAG_SNAPSHOT_FILE_PREFIX}${name.slice(FLAG_SNAPSHOT_FILE_PREFIX.length)}`);
45
+ }
9
46
  /**
10
47
  * The one `fetched_at` grammar both snapshot readers accept: RFC 3339 with an
11
48
  * upper-case `T`, seconds, at most nine fraction digits, and `Z` or a
@@ -144,7 +181,7 @@ function fallbackSnapshotPath(companyUid, create, env = process.env) {
144
181
  return undefined;
145
182
  }
146
183
  }
147
- return path.join(directories[directories.length - 1], `snapshot-${companyUid}.json`);
184
+ return path.join(directories[directories.length - 1], flagSnapshotFileName(companyUid));
148
185
  }
149
186
  function fallbackPersonSnapshotPath(create) {
150
187
  if (typeof process.getuid !== "function")
@@ -168,17 +205,17 @@ function fallbackPersonSnapshotPath(create) {
168
205
  return undefined;
169
206
  }
170
207
  }
171
- return path.join(directories[2], "snapshot-person.json");
208
+ return path.join(directories[2], flagSnapshotFileName("person"));
172
209
  }
173
210
  export function flagSnapshotPath(companyUid, env = process.env) {
174
211
  if (!COMPANY_UID_RE.test(companyUid))
175
212
  return undefined;
176
213
  const cacheHome = env.XDG_CACHE_HOME?.trim() || path.join(os.homedir(), ".cache");
177
- return path.join(cacheHome, "hq", "flags", `snapshot-${companyUid}.json`);
214
+ return path.join(cacheHome, "hq", "flags", flagSnapshotFileName(companyUid));
178
215
  }
179
216
  export function personFlagSnapshotPath(env = process.env) {
180
217
  const cacheHome = env.XDG_CACHE_HOME?.trim() || path.join(os.homedir(), ".cache");
181
- return path.join(cacheHome, "hq", "flags", "snapshot-person.json");
218
+ return path.join(cacheHome, "hq", "flags", flagSnapshotFileName("person"));
182
219
  }
183
220
  /**
184
221
  * Per-hook engine bridge flags (`hook-engine-port-<hook-id>`) carry a mode,
@@ -248,6 +285,22 @@ function writeSnapshotAt(destination, snapshot, cacheRootKind) {
248
285
  }
249
286
  return destination;
250
287
  }
288
+ /**
289
+ * Write the current snapshot file, then the same contents under the name
290
+ * hq-cli used before the rename, for readers released before it. The current
291
+ * file decides: its failure is the write's failure. A failure to write the
292
+ * old name is ignored; no current reader opens that file.
293
+ */
294
+ function writeSnapshotPair(destination, snapshot, cacheRootKind) {
295
+ const written = writeSnapshotAt(destination, snapshot, cacheRootKind);
296
+ try {
297
+ writeSnapshotAt(legacyFlagSnapshotPath(written), snapshot, cacheRootKind);
298
+ }
299
+ catch {
300
+ // Only readers released before the rename use this file.
301
+ }
302
+ return written;
303
+ }
251
304
  function writePersonFallback(snapshot, originalError) {
252
305
  const fallbackFile = fallbackPersonSnapshotPath(true);
253
306
  if (!fallbackFile) {
@@ -260,7 +313,7 @@ function writePersonFallback(snapshot, originalError) {
260
313
  throw error;
261
314
  }
262
315
  try {
263
- const written = writeSnapshotAt(fallbackFile, snapshot, "home");
316
+ const written = writeSnapshotPair(fallbackFile, snapshot, "home");
264
317
  fallbackCacheUsed = true;
265
318
  return written;
266
319
  }
@@ -287,7 +340,7 @@ export function writePersonFlagSnapshotFile(flags, options = {}) {
287
340
  if (fallbackCacheUsed)
288
341
  return writePersonFallback(snapshot);
289
342
  try {
290
- return writeSnapshotAt(personFlagSnapshotPath(env), snapshot, env.XDG_CACHE_HOME?.trim() ? "xdg" : "home");
343
+ return writeSnapshotPair(personFlagSnapshotPath(env), snapshot, env.XDG_CACHE_HOME?.trim() ? "xdg" : "home");
291
344
  }
292
345
  catch (error) {
293
346
  if (!isPermissionFailure(error))
@@ -297,14 +350,30 @@ export function writePersonFlagSnapshotFile(flags, options = {}) {
297
350
  }
298
351
  /** Read only a fresh, correctly scoped person snapshot. Every invalid state is a cache miss. */
299
352
  export function readPersonFlagSnapshotFile(options = {}) {
300
- const env = options.env ?? process.env;
301
- // Both stores are read and the newer valid one answers; equal times keep
302
- // the primary. This is the hq-hook rule (flags.rs `newest_snapshot`).
303
- const fallback = fallbackPersonSnapshotPath(false);
304
- const primary = parsePersonSnapshotFile(personFlagSnapshotPath(env), options);
305
- const fallbackSnapshot = fallback ? parsePersonSnapshotFile(fallback, options) : null;
353
+ const primaryFile = personFlagSnapshotPath(options.env ?? process.env);
354
+ const fallbackFile = fallbackPersonSnapshotPath(false);
355
+ const current = readPersonStores(primaryFile, fallbackFile, options);
356
+ if (current || readPersonStores(primaryFile, fallbackFile, ANY_AGE, false))
357
+ return current;
358
+ const legacy = legacyFalseFlags([legacyFlagSnapshotPath(primaryFile), legacyPath(fallbackFile)], (file) => parsePersonSnapshotFile(file, options));
359
+ return legacy ? { scope: "person", fetched_at: legacy.fetched_at, flags: legacy.flags } : null;
360
+ }
361
+ /** The person `snapshot-v2-` file alone: never the old-name file. */
362
+ export function readCurrentPersonFlagSnapshotFile(options = {}) {
363
+ return readPersonStores(personFlagSnapshotPath(options.env ?? process.env), fallbackPersonSnapshotPath(false), options);
364
+ }
365
+ /**
366
+ * The newer valid person snapshot of the two stores. Both are read and the
367
+ * newer one answers; equal times keep the primary. This is the hq-hook rule
368
+ * (flags.rs `newest_snapshot`). `markFallback` false leaves the store choice
369
+ * of later writes alone, for a check that a file exists.
370
+ */
371
+ function readPersonStores(primaryFile, fallbackFile, options, markFallback = true) {
372
+ const primary = parsePersonSnapshotFile(primaryFile, options);
373
+ const fallbackSnapshot = fallbackFile ? parsePersonSnapshotFile(fallbackFile, options) : null;
306
374
  if (fallbackSnapshot && (!primary || fallbackSnapshot.fetchedAt > primary.fetchedAt)) {
307
- fallbackCacheUsed = true;
375
+ if (markFallback)
376
+ fallbackCacheUsed = true;
308
377
  return fallbackSnapshot.snapshot;
309
378
  }
310
379
  return primary?.snapshot ?? null;
@@ -399,7 +468,7 @@ export function writeFlagSnapshotFile(companyUid, flags, options = {}) {
399
468
  }
400
469
  noteReplacedFallback(fallbackFile);
401
470
  try {
402
- const written = writeSnapshotAt(fallbackFile, snapshot, cacheRootKind);
471
+ const written = writeSnapshotPair(fallbackFile, snapshot, cacheRootKind);
403
472
  fallbackCacheUsed = true;
404
473
  return written;
405
474
  }
@@ -416,7 +485,7 @@ export function writeFlagSnapshotFile(companyUid, flags, options = {}) {
416
485
  return writeFallback();
417
486
  noteReplaced(primaryPrevious);
418
487
  try {
419
- return writeSnapshotAt(file, snapshot, cacheRootKind);
488
+ return writeSnapshotPair(file, snapshot, cacheRootKind);
420
489
  }
421
490
  catch (error) {
422
491
  if (!isPermissionFailure(error))
@@ -452,13 +521,36 @@ function parseSnapshotFile(companyUid, file, options) {
452
521
  flags: freshAnywhereRuntimeFlags(flags, fetchedAt, options.now),
453
522
  };
454
523
  }
455
- /** Return null for every miss, malformed file, company mismatch, or stale file. */
524
+ /**
525
+ * Return null for every miss, malformed file, company mismatch, or stale file.
526
+ * With no `snapshot-v2-` file for the company at all, the explicit `false`
527
+ * values of its old-name file answer, and only those (see
528
+ * `FLAG_SNAPSHOT_FILE_PREFIX`).
529
+ */
456
530
  export function readFlagSnapshotFile(companyUid, options = {}) {
457
531
  const file = flagSnapshotPath(companyUid, options.env);
458
532
  if (!file)
459
533
  return null;
460
- const primary = parseSnapshotFile(companyUid, file, options);
461
534
  const fallback = fallbackSnapshotPath(companyUid, false, options.env);
535
+ const current = readCompanyStores(companyUid, file, fallback, options);
536
+ if (current || readCompanyStores(companyUid, file, fallback, ANY_AGE, false))
537
+ return current;
538
+ const legacy = legacyFalseFlags([legacyFlagSnapshotPath(file), legacyPath(fallback)], (path) => parseSnapshotFile(companyUid, path, options));
539
+ return legacy ? { company_uid: companyUid, fetched_at: legacy.fetched_at, flags: legacy.flags } : null;
540
+ }
541
+ /**
542
+ * The company's `snapshot-v2-` file alone, never the old-name file. For a
543
+ * caller that must know whether a current snapshot exists, such as the
544
+ * refresh that writes one.
545
+ */
546
+ export function readCurrentFlagSnapshotFile(companyUid, options = {}) {
547
+ const file = flagSnapshotPath(companyUid, options.env);
548
+ if (!file)
549
+ return null;
550
+ return readCompanyStores(companyUid, file, fallbackSnapshotPath(companyUid, false, options.env), options);
551
+ }
552
+ function readCompanyStores(companyUid, file, fallback, options, markFallback = true) {
553
+ const primary = parseSnapshotFile(companyUid, file, options);
462
554
  const fallbackSnapshot = fallback ? parseSnapshotFile(companyUid, fallback, options) : null;
463
555
  // Compare both valid stores on every platform, as hq-hook does
464
556
  // (flags.rs `newest_snapshot`): a newer permission-fallback write, from a
@@ -466,11 +558,40 @@ export function readFlagSnapshotFile(companyUid, options = {}) {
466
558
  // masked by an older primary. Equal timestamps keep the primary.
467
559
  if (fallbackSnapshot
468
560
  && (!primary || parseSnapshotTime(fallbackSnapshot.fetched_at) > parseSnapshotTime(primary.fetched_at))) {
469
- fallbackCacheUsed = true;
561
+ if (markFallback)
562
+ fallbackCacheUsed = true;
470
563
  return fallbackSnapshot;
471
564
  }
472
565
  return primary;
473
566
  }
567
+ function legacyPath(currentPath) {
568
+ return currentPath ? legacyFlagSnapshotPath(currentPath) : undefined;
569
+ }
570
+ /**
571
+ * The explicit `false` values of the newer valid old-name file (primary or
572
+ * permission fallback), with its `fetched_at`. Null when neither is valid or
573
+ * neither holds a `false`. Never returns a `true`.
574
+ */
575
+ function legacyFalseFlags(files, parse) {
576
+ let newest = null;
577
+ for (const file of files) {
578
+ if (!file)
579
+ continue;
580
+ const parsed = parse(file);
581
+ const snapshot = parsed && "snapshot" in parsed ? parsed.snapshot : parsed;
582
+ if (snapshot && (!newest || parseSnapshotTime(snapshot.fetched_at) > parseSnapshotTime(newest.fetched_at))) {
583
+ newest = snapshot;
584
+ }
585
+ }
586
+ if (!newest)
587
+ return null;
588
+ const falses = {};
589
+ for (const [key, value] of Object.entries(newest.flags)) {
590
+ if (value === false)
591
+ falses[key] = false;
592
+ }
593
+ return Object.keys(falses).length > 0 ? { fetched_at: newest.fetched_at, flags: falses } : null;
594
+ }
474
595
  /** Resolve a default-on kill switch from offline snapshots, allowing stale decisions. */
475
596
  export function readDefaultOnFlagSnapshot(flagKey, companyUid, env = process.env) {
476
597
  // Native-route kill switches intentionally retain stale decisions. Only
@@ -493,12 +614,14 @@ export function readDefaultOnFlagSnapshot(flagKey, companyUid, env = process.env
493
614
  continue;
494
615
  }
495
616
  for (const name of names) {
496
- if (name === "snapshot-person.json") {
617
+ if (name === flagSnapshotFileName("person") || name === "snapshot-person.json") {
497
618
  if (readPersonFlagSnapshotFile(options)?.flags[flagKey] === false)
498
619
  return false;
499
620
  continue;
500
621
  }
501
- const match = /^snapshot-(cmp_[A-Za-z0-9]{3,128})\.json$/.exec(name);
622
+ // Old names too: a company with no `snapshot-v2-` file yet keeps the
623
+ // explicit `false` values of its old-name file (`readFlagSnapshotFile`).
624
+ const match = /^snapshot-(?:v2-)?(cmp_[A-Za-z0-9]{3,128})\.json$/.exec(name);
502
625
  if (match?.[1] && readFlagSnapshotFile(match[1], options)?.flags[flagKey] === false)
503
626
  return false;
504
627
  }
@@ -307,8 +307,8 @@ export declare const PRE_TOOL_USE_VAULT_GUARD_PINS: readonly PinnedFile[];
307
307
  /**
308
308
  * The credential guard's script revisions, each with the arithmetic library its port follows
309
309
  * (ports.rs `HOOK_SCRIPT_SHA256`, `HOOK_COMPANION_SHA256` and `COMPANION_SCRIPT_BINDINGS`): the
310
- * 16.0.48 script 6512581d and its 16.0.51-beta.44 successor 5064061f only with e90d160f, every
311
- * other revision only with 0566180c.
310
+ * 16.0.48 script 6512581d, its 16.0.51-beta.44 successor 5064061f and the 16.0.52 script e8f19ecc
311
+ * only with e90d160f, every other revision only with 0566180c.
312
312
  */
313
313
  export declare const PRE_TOOL_USE_CREDENTIAL_GUARD_GENERATIONS: ReadonlyArray<readonly [string, string]>;
314
314
  /**
@@ -327,19 +327,20 @@ export declare const PRE_TOOL_USE_IMAGE_GUARD_PINS: readonly PinnedFile[];
327
327
  * sha256 picks the set and never refuses by itself: the v16.0.49 wrapper (742870a2) picks
328
328
  * `released`, any other wrapper `legacy`. In a set the helper .cjs, when listed, must match; each
329
329
  * guard may be missing (bash exits 127) but not another revision; hook-lib.sh is read only once a
330
- * guard is on its pin, and must then be the set's library.
330
+ * guard is on its pin, and must then be one of the set's libraries (the released set also takes the
331
+ * v16.0.52 library 436493e3).
331
332
  */
332
333
  export declare const MERGED_WRITE_GUARD_SETS: {
333
334
  readonly releasedWrapper: "742870a2ada4f9357320f7708fca7363be6d81fde374948b59873c327a7d7206";
334
335
  readonly released: {
335
336
  readonly helper: "6f65f2b9425612f9b2ec2590dace82585230210dcd69a124a9cdeb0116ea7f30";
336
337
  readonly guards: ReadonlyArray<readonly [string, string]>;
337
- readonly hookLib: "9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f";
338
+ readonly hookLibs: readonly string[];
338
339
  };
339
340
  readonly legacy: {
340
341
  readonly helper: null;
341
342
  readonly guards: ReadonlyArray<readonly [string, string]>;
342
- readonly hookLib: "df3d8ddc15a0c179227c9ba7f855c040973fcee249673156d08b2e2ff2c850b8";
343
+ readonly hookLibs: readonly string[];
343
344
  };
344
345
  };
345
346
  /**
@@ -349,6 +350,68 @@ export declare const MERGED_WRITE_GUARD_SETS: {
349
350
  * so the hold assumes it is.
350
351
  */
351
352
  export declare function mergedWriteGuardHold(root: string, event: string): string | null;
353
+ /**
354
+ * Why a Codex `event` must stay on the shell adapter in `root`: `.claude/settings.json` holds an
355
+ * entry of that event with a non-empty `args` list (the exec form, which `hq reindex` and the
356
+ * update healer write for the engine launcher). The adapter library may run such an entry as
357
+ * master-hook (`hqad_classify_exec`), which the native work does not model, so the native
358
+ * PreToolUse refuses every Codex tool call on such a root, whatever the tool or the entry's
359
+ * matcher (pre_tool_use_master.rs `codex_exec_refusal`). Without this hold `hq reindex` would
360
+ * switch the event onto that refusal, as for `codexSubagentStopHold`.
361
+ *
362
+ * The engine's own registration for this root is not such an entry ([`engineOwnExecEntry`]):
363
+ * `hq reindex` writes it into this file for Claude Code when the new core is on, the native
364
+ * PreToolUse models what the adapter did with it (fleet_settings.rs `engine_own_master`), and a
365
+ * hold on it would undo reindex's own switch on the next run.
366
+ *
367
+ * The walk is the one in crates/hq-hook/src/host/fleet_settings.rs `unsupported_exec_form_entry`:
368
+ * the event's slot and each group's `hooks` are a list's items or an object's values, as the
369
+ * adapter's jq query walks them. The hold is wider than the run-time refusal in two ways, both of
370
+ * which only keep the event on the shell adapter: it does not ask whether master-hook.sh and
371
+ * hook-adapter-core.sh are present (without either the engine is idle before it reads the
372
+ * settings; the pinned-file hold already keeps such a root), and it reads the file with
373
+ * `JSON.parse`, which accepts a few files serde_json rejects (invalid UTF-8 read with replacement
374
+ * characters, a lone surrogate escape, nesting deeper than 128), where the engine reads no
375
+ * entry. A file that is absent or that `JSON.parse` rejects holds no such entry. Null when there
376
+ * is none.
377
+ */
378
+ export declare function codexExecFormSettingsHold(root: string, event: string): string | null;
379
+ /**
380
+ * Whether `entry` is the registration `hq reindex` writes for `event` on this root when the new
381
+ * core is on. Three tests, each the one the adapter library's `hqad_classify_exec` makes before it
382
+ * gives the entry a master record, so no entry is exempt here that the library reads another way:
383
+ * - a `command` entry whose arguments are exactly `run --host <host> <event> --hq-root <root>`, the
384
+ * host a plain word;
385
+ * - the command is the release-stable hq-hook as the library tests it ([`stableEngineCommand`]). A
386
+ * command that only contains the stable segment somewhere is not one;
387
+ * - the root value is absolute and names this root ([`ownRootValue`]).
388
+ *
389
+ * This is narrower than [`isCoreNextEntry`], which registration uses to find its entries: every
390
+ * entry this accepts, that accepts. crates/hq-hook/src/host/fleet_settings.rs `engine_own_entry` is
391
+ * the same three tests, statement for statement.
392
+ */
393
+ export declare function engineOwnExecEntry(entry: unknown, root: string, event: string, windows?: boolean): boolean;
394
+ /**
395
+ * Whether a `--hq-root` value names `root`. The value must be absolute (`/...`, or on Windows a
396
+ * drive path; a `\\?\` verbatim path or a UNC path is not one) and, trailing separators aside,
397
+ * every name in it must be a plain name: no `.`, `..` or empty segment. The separators are `/`, and
398
+ * `\` on Windows only (elsewhere a backslash is part of a name). It then names the root when it is
399
+ * the root's spelling, trailing separators aside, or when the operating system resolves it to the
400
+ * same folder as the root (`fs.realpathSync.native`, which is realpath(3), or
401
+ * `GetFinalPathNameByHandle` on Windows). Refusing `.` and `..` before resolving means no value
402
+ * depends on whether `..` is applied before or after a link. fleet_settings.rs `own_root_value` is
403
+ * the same function, resolving with `Path::canonicalize`; both answer
404
+ * crates/hq-hook/tests/fixtures/engine-own-entry/cases.json.
405
+ */
406
+ export declare function ownRootValue(value: string, root: string, windows: boolean): boolean;
407
+ /**
408
+ * The command tests of `hqad_classify_exec` for the stable link, with `cygpath` present on Windows
409
+ * (`windows`) and absent elsewhere: an absolute path with no `.`, `..` or empty segment whose
410
+ * first `.hq/bin/hq-hook/` is followed by `stable/` and an engine binary name. A Windows drive path
411
+ * is read with its separators swapped, and only when it is written with one kind of separator.
412
+ * fleet_settings.rs `stable_engine_command`.
413
+ */
414
+ export declare function stableEngineCommand(command: string, windows: boolean): boolean;
352
415
  /**
353
416
  * Why PreToolUse must stay on the old dispatcher in `root` on `host` once `master-hook:PreToolUse`
354
417
  * is claimed there (`hooks`: the old dispatcher's PreToolUse hooks there). Each part mirrors a
@@ -361,8 +424,10 @@ export declare function mergedWriteGuardHold(root: string, event: string): strin
361
424
  * on Bash calls whatever the registry lists), as for PostToolUse;
362
425
  * - the policy-frontmatter evaluator scripts;
363
426
  * - the merged-write-guard-shadow companions, where the registry lists that row;
364
- * - on Claude Code, the image rule's script.
365
- * Null when the native PreToolUse accepts every file.
427
+ * - on Claude Code, the image rule's script;
428
+ * - on Codex, a `.claude/settings.json` PreToolUse entry in the exec form
429
+ * ([`codexExecFormSettingsHold`]).
430
+ * Null when the native PreToolUse accepts every file and the settings.
366
431
  */
367
432
  export declare function preToolUseHold(root: string, host: CoreNextHost, hooks?: readonly string[]): string | null;
368
433
  /**
@@ -2046,7 +2046,13 @@ export const PRE_TOOL_USE_DISPATCHER_PINS = [
2046
2046
  ],
2047
2047
  },
2048
2048
  { relative: '.claude/hooks/turn-timing.sh', accepted: ['97c70a3251225ba9e469e41fd3fe2341cfe2936490f54571d2ca16de8e766443'] },
2049
- { relative: 'core/scripts/hook-lib.sh', accepted: ['9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f'] },
2049
+ {
2050
+ relative: 'core/scripts/hook-lib.sh',
2051
+ accepted: [
2052
+ '9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f',
2053
+ '436493e3325fb0cbcad651ae8ef42d89f4adf43fe38abd938ed6a39c0b6d17c1',
2054
+ ],
2055
+ },
2050
2056
  { relative: 'core/scripts/hq-anywhere-runtime-flag.cjs', accepted: ['8a484cef83d383b440462798ac13e26d132e10bbe509b47e0eb1a3d0db76b2b4'] },
2051
2057
  { relative: 'core/scripts/hqd-hook-flag-cache-lib.sh', accepted: ['061d264460408e9eaf43fdf0fdde662c906a9a7dacb4e7a591e684bca28c138a'] },
2052
2058
  { relative: 'core/scripts/hqd-hook-shim.sh', accepted: ['ab289ac0af680fe3bcacb110302ca8b998bdc33c6f94321d42bd04a344163eed', 'ee5e9fe729eb7e51f87b5f90cdc020be865f5b6b35ac0b5758587546b35715c0'] },
@@ -2074,7 +2080,14 @@ export const PRE_TOOL_USE_CLAUDE_DISPATCHER_PINS = [
2074
2080
  },
2075
2081
  ];
2076
2082
  export const PRE_TOOL_USE_CODEX_DISPATCHER_PINS = [
2077
- { relative: 'core/scripts/lib/hook-adapter-core.sh', accepted: ['940bb5a0a268929a4cd3f88b61a0ce619f0fdf64e5d3f25f7f18da35df466ab5'] },
2083
+ {
2084
+ relative: 'core/scripts/lib/hook-adapter-core.sh',
2085
+ accepted: [
2086
+ '940bb5a0a268929a4cd3f88b61a0ce619f0fdf64e5d3f25f7f18da35df466ab5',
2087
+ RELEASED_CLASSIFYING_ADAPTER_CORE_SHA256,
2088
+ CLASSIFYING_ADAPTER_CORE_SHA256,
2089
+ ],
2090
+ },
2078
2091
  ];
2079
2092
  /** The Codex adapter the model reproduces on Codex only (pre_tool_use_master.rs `CODEX_ADAPTER_PIN`). */
2080
2093
  export const PRE_TOOL_USE_CODEX_ADAPTER_PIN = {
@@ -2107,8 +2120,8 @@ export const PRE_TOOL_USE_VAULT_GUARD_PINS = [
2107
2120
  /**
2108
2121
  * The credential guard's script revisions, each with the arithmetic library its port follows
2109
2122
  * (ports.rs `HOOK_SCRIPT_SHA256`, `HOOK_COMPANION_SHA256` and `COMPANION_SCRIPT_BINDINGS`): the
2110
- * 16.0.48 script 6512581d and its 16.0.51-beta.44 successor 5064061f only with e90d160f, every
2111
- * other revision only with 0566180c.
2123
+ * 16.0.48 script 6512581d, its 16.0.51-beta.44 successor 5064061f and the 16.0.52 script e8f19ecc
2124
+ * only with e90d160f, every other revision only with 0566180c.
2112
2125
  */
2113
2126
  export const PRE_TOOL_USE_CREDENTIAL_GUARD_GENERATIONS = [
2114
2127
  ['25f5507cc97bfe700a8505f59463b4f42280c60d4733110c0a5faabb87cda4f3', '0566180ce52bed559d57a08247bf39c8ec1cec6b7e271da496d0c09077fc6f57'],
@@ -2117,6 +2130,7 @@ export const PRE_TOOL_USE_CREDENTIAL_GUARD_GENERATIONS = [
2117
2130
  ['30015cbcae48b7227d3e271dd73235b2eac8d7b86955ac653d30ca3c377bc599', '0566180ce52bed559d57a08247bf39c8ec1cec6b7e271da496d0c09077fc6f57'],
2118
2131
  ['6512581d1200558d4ef78dfb11eca4a92f663042c6b0b11b2e6664762139e2a0', 'e90d160fed02cbcf7e33aed679233af5a9cf9f9a87dd979aba04493a37c00ec8'],
2119
2132
  ['5064061fd64da6d56c0c974c0719f6729b23dba9ab1a768e1ba70d5a9645c8ae', 'e90d160fed02cbcf7e33aed679233af5a9cf9f9a87dd979aba04493a37c00ec8'],
2133
+ ['e8f19eccc25adfb1aa51a4d24de29714f700001a31abc21537682ee8635c76cb', 'e90d160fed02cbcf7e33aed679233af5a9cf9f9a87dd979aba04493a37c00ec8'],
2120
2134
  ];
2121
2135
  const CREDENTIAL_GUARD = '.claude/hooks/block-credential-file-read.sh';
2122
2136
  const CREDENTIAL_ARITH_LIB = '.claude/hooks/bash-arith-subst-guard-lib.sh';
@@ -2155,7 +2169,8 @@ const MERGED_WRITE_HELPER = '.claude/hooks/merged-write-guard-shadow.cjs';
2155
2169
  * sha256 picks the set and never refuses by itself: the v16.0.49 wrapper (742870a2) picks
2156
2170
  * `released`, any other wrapper `legacy`. In a set the helper .cjs, when listed, must match; each
2157
2171
  * guard may be missing (bash exits 127) but not another revision; hook-lib.sh is read only once a
2158
- * guard is on its pin, and must then be the set's library.
2172
+ * guard is on its pin, and must then be one of the set's libraries (the released set also takes the
2173
+ * v16.0.52 library 436493e3).
2159
2174
  */
2160
2175
  export const MERGED_WRITE_GUARD_SETS = {
2161
2176
  releasedWrapper: '742870a2ada4f9357320f7708fca7363be6d81fde374948b59873c327a7d7206',
@@ -2166,7 +2181,7 @@ export const MERGED_WRITE_GUARD_SETS = {
2166
2181
  ['.claude/hooks/block-core-writes.sh', 'a39061417bf31cf251c661ebc3e5bc87ee1bb2424a0552d2aeb266eec3d29fcc'],
2167
2182
  ['core/hooks/PreToolUse/10-Edit,Write,MultiEdit--block-repo-edits-use-worktree.sh', 'c4c0786ff75ef466f3cd6068e3d54b3fd68c3e3cfabb98debfe1de770523526c'],
2168
2183
  ],
2169
- hookLib: '9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f',
2184
+ hookLibs: ['9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f', '436493e3325fb0cbcad651ae8ef42d89f4adf43fe38abd938ed6a39c0b6d17c1'],
2170
2185
  },
2171
2186
  legacy: {
2172
2187
  helper: null,
@@ -2175,7 +2190,7 @@ export const MERGED_WRITE_GUARD_SETS = {
2175
2190
  ['.claude/hooks/block-core-writes.sh', 'e6c14f48c38bd01ed0f2120fd7c18022fd7dd0dac18ed09f2307414a5646932f'],
2176
2191
  ['core/hooks/PreToolUse/10-Edit,Write,MultiEdit--block-repo-edits-use-worktree.sh', 'c4c0786ff75ef466f3cd6068e3d54b3fd68c3e3cfabb98debfe1de770523526c'],
2177
2192
  ],
2178
- hookLib: 'df3d8ddc15a0c179227c9ba7f855c040973fcee249673156d08b2e2ff2c850b8',
2193
+ hookLibs: ['df3d8ddc15a0c179227c9ba7f855c040973fcee249673156d08b2e2ff2c850b8'],
2179
2194
  },
2180
2195
  };
2181
2196
  /** The sha256 of `relative` under `root`, or null when it is not a regular file or cannot be read. */
@@ -2210,7 +2225,132 @@ export function mergedWriteGuardHold(root, event) {
2210
2225
  return guards;
2211
2226
  if (!set.guards.some(([relative]) => regularFile(path.join(root, relative))))
2212
2227
  return null;
2213
- return pinnedFilesHold(root, event, [{ relative: HOOK_LIB, accepted: [set.hookLib] }]);
2228
+ return pinnedFilesHold(root, event, [{ relative: HOOK_LIB, accepted: [...set.hookLibs] }]);
2229
+ }
2230
+ /**
2231
+ * Why a Codex `event` must stay on the shell adapter in `root`: `.claude/settings.json` holds an
2232
+ * entry of that event with a non-empty `args` list (the exec form, which `hq reindex` and the
2233
+ * update healer write for the engine launcher). The adapter library may run such an entry as
2234
+ * master-hook (`hqad_classify_exec`), which the native work does not model, so the native
2235
+ * PreToolUse refuses every Codex tool call on such a root, whatever the tool or the entry's
2236
+ * matcher (pre_tool_use_master.rs `codex_exec_refusal`). Without this hold `hq reindex` would
2237
+ * switch the event onto that refusal, as for `codexSubagentStopHold`.
2238
+ *
2239
+ * The engine's own registration for this root is not such an entry ([`engineOwnExecEntry`]):
2240
+ * `hq reindex` writes it into this file for Claude Code when the new core is on, the native
2241
+ * PreToolUse models what the adapter did with it (fleet_settings.rs `engine_own_master`), and a
2242
+ * hold on it would undo reindex's own switch on the next run.
2243
+ *
2244
+ * The walk is the one in crates/hq-hook/src/host/fleet_settings.rs `unsupported_exec_form_entry`:
2245
+ * the event's slot and each group's `hooks` are a list's items or an object's values, as the
2246
+ * adapter's jq query walks them. The hold is wider than the run-time refusal in two ways, both of
2247
+ * which only keep the event on the shell adapter: it does not ask whether master-hook.sh and
2248
+ * hook-adapter-core.sh are present (without either the engine is idle before it reads the
2249
+ * settings; the pinned-file hold already keeps such a root), and it reads the file with
2250
+ * `JSON.parse`, which accepts a few files serde_json rejects (invalid UTF-8 read with replacement
2251
+ * characters, a lone surrogate escape, nesting deeper than 128), where the engine reads no
2252
+ * entry. A file that is absent or that `JSON.parse` rejects holds no such entry. Null when there
2253
+ * is none.
2254
+ */
2255
+ export function codexExecFormSettingsHold(root, event) {
2256
+ let settings;
2257
+ try {
2258
+ settings = JSON.parse(fs.readFileSync(path.join(root, '.claude', 'settings.json'), 'utf8'));
2259
+ }
2260
+ catch {
2261
+ return null;
2262
+ }
2263
+ const field = (value, key) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value[key] : undefined;
2264
+ const values = (value) => Array.isArray(value) ? value : value !== null && typeof value === 'object' ? Object.values(value) : [];
2265
+ const exec = values(field(field(settings, 'hooks'), event)).some((group) => values(field(group, 'hooks')).some((entry) => {
2266
+ const args = field(entry, 'args');
2267
+ return Array.isArray(args) && args.length > 0 && !engineOwnExecEntry(entry, root, event);
2268
+ }));
2269
+ return exec ? `unmodeled ${event} settings entry in .claude/settings.json (exec form)` : null;
2270
+ }
2271
+ /**
2272
+ * Whether `entry` is the registration `hq reindex` writes for `event` on this root when the new
2273
+ * core is on. Three tests, each the one the adapter library's `hqad_classify_exec` makes before it
2274
+ * gives the entry a master record, so no entry is exempt here that the library reads another way:
2275
+ * - a `command` entry whose arguments are exactly `run --host <host> <event> --hq-root <root>`, the
2276
+ * host a plain word;
2277
+ * - the command is the release-stable hq-hook as the library tests it ([`stableEngineCommand`]). A
2278
+ * command that only contains the stable segment somewhere is not one;
2279
+ * - the root value is absolute and names this root ([`ownRootValue`]).
2280
+ *
2281
+ * This is narrower than [`isCoreNextEntry`], which registration uses to find its entries: every
2282
+ * entry this accepts, that accepts. crates/hq-hook/src/host/fleet_settings.rs `engine_own_entry` is
2283
+ * the same three tests, statement for statement.
2284
+ */
2285
+ export function engineOwnExecEntry(entry, root, event, windows = process.platform === 'win32') {
2286
+ if (entry === null || typeof entry !== 'object' || Array.isArray(entry))
2287
+ return false;
2288
+ const { type, command, args } = entry;
2289
+ if (type !== 'command' || typeof command !== 'string')
2290
+ return false;
2291
+ if (!Array.isArray(args) || args.length !== 6 || !args.every((arg) => typeof arg === 'string'))
2292
+ return false;
2293
+ const [run, flag, host, slot, rootFlag, value] = args;
2294
+ return run === 'run' && flag === '--host' && /^[a-z][a-z0-9-]*$/.test(host) && slot === event && rootFlag === '--hq-root'
2295
+ && ownRootValue(value, root, windows) && stableEngineCommand(command, windows);
2296
+ }
2297
+ /**
2298
+ * Whether a `--hq-root` value names `root`. The value must be absolute (`/...`, or on Windows a
2299
+ * drive path; a `\\?\` verbatim path or a UNC path is not one) and, trailing separators aside,
2300
+ * every name in it must be a plain name: no `.`, `..` or empty segment. The separators are `/`, and
2301
+ * `\` on Windows only (elsewhere a backslash is part of a name). It then names the root when it is
2302
+ * the root's spelling, trailing separators aside, or when the operating system resolves it to the
2303
+ * same folder as the root (`fs.realpathSync.native`, which is realpath(3), or
2304
+ * `GetFinalPathNameByHandle` on Windows). Refusing `.` and `..` before resolving means no value
2305
+ * depends on whether `..` is applied before or after a link. fleet_settings.rs `own_root_value` is
2306
+ * the same function, resolving with `Path::canonicalize`; both answer
2307
+ * crates/hq-hook/tests/fixtures/engine-own-entry/cases.json.
2308
+ */
2309
+ export function ownRootValue(value, root, windows) {
2310
+ const drive = /^[A-Za-z]:[\\/]/.test(value);
2311
+ if (!(value.startsWith('/') || (windows && drive)))
2312
+ return false;
2313
+ const trailing = windows ? /[\\/]+$/ : /\/+$/;
2314
+ const trimmed = value.replace(trailing, '');
2315
+ const body = windows && drive ? trimmed.slice(2) : trimmed;
2316
+ const names = body.slice(1);
2317
+ if (names === '' || names.split(windows ? /[\\/]/ : /\//).some((name) => name === '' || name === '.' || name === '..'))
2318
+ return false;
2319
+ if (trimmed === root.replace(trailing, ''))
2320
+ return true;
2321
+ try {
2322
+ return normalizeRealpath(fs.realpathSync.native(value)) === normalizeRealpath(fs.realpathSync.native(root));
2323
+ }
2324
+ catch {
2325
+ return false;
2326
+ }
2327
+ }
2328
+ /** A resolved path without the `\\?\` prefix Node adds on Windows for long paths, so both sides compare alike. */
2329
+ function normalizeRealpath(resolved) {
2330
+ return resolved.startsWith('\\\\?\\') ? resolved.slice(4) : resolved;
2331
+ }
2332
+ /**
2333
+ * The command tests of `hqad_classify_exec` for the stable link, with `cygpath` present on Windows
2334
+ * (`windows`) and absent elsewhere: an absolute path with no `.`, `..` or empty segment whose
2335
+ * first `.hq/bin/hq-hook/` is followed by `stable/` and an engine binary name. A Windows drive path
2336
+ * is read with its separators swapped, and only when it is written with one kind of separator.
2337
+ * fleet_settings.rs `stable_engine_command`.
2338
+ */
2339
+ export function stableEngineCommand(command, windows) {
2340
+ const drive = /^[A-Za-z]:[\\/]/.test(command);
2341
+ if (drive && windows && command.includes('/') && command.includes('\\'))
2342
+ return false;
2343
+ const posix = drive && windows ? `/${command.slice(0, 1).toLowerCase()}${command.slice(2).replaceAll('\\', '/')}` : command;
2344
+ if (!posix.startsWith('/'))
2345
+ return false;
2346
+ const closed = `${posix}/`;
2347
+ if (['/../', '/./', '//'].some((part) => closed.includes(part)))
2348
+ return false;
2349
+ const marker = '/.hq/bin/hq-hook/';
2350
+ const at = posix.indexOf(marker);
2351
+ if (at < 0)
2352
+ return false;
2353
+ return ['stable/hq-hook', 'stable/hq-hook.exe', 'stable/hq-hook.app/Contents/MacOS/hq-hook'].includes(posix.slice(at + marker.length));
2214
2354
  }
2215
2355
  /**
2216
2356
  * Why PreToolUse must stay on the old dispatcher in `root` on `host` once `master-hook:PreToolUse`
@@ -2224,8 +2364,10 @@ export function mergedWriteGuardHold(root, event) {
2224
2364
  * on Bash calls whatever the registry lists), as for PostToolUse;
2225
2365
  * - the policy-frontmatter evaluator scripts;
2226
2366
  * - the merged-write-guard-shadow companions, where the registry lists that row;
2227
- * - on Claude Code, the image rule's script.
2228
- * Null when the native PreToolUse accepts every file.
2367
+ * - on Claude Code, the image rule's script;
2368
+ * - on Codex, a `.claude/settings.json` PreToolUse entry in the exec form
2369
+ * ([`codexExecFormSettingsHold`]).
2370
+ * Null when the native PreToolUse accepts every file and the settings.
2229
2371
  */
2230
2372
  export function preToolUseHold(root, host, hooks = []) {
2231
2373
  const files = host === 'codex'
@@ -2243,6 +2385,7 @@ export function preToolUseHold(root, host, hooks = []) {
2243
2385
  return null;
2244
2386
  };
2245
2387
  return pinnedFilesHold(root, 'PreToolUse', files)
2388
+ ?? (host === 'codex' ? codexExecFormSettingsHold(root, 'PreToolUse') : null)
2246
2389
  ?? pinnedFilesHold(root, 'PreToolUse', PRE_TOOL_USE_VAULT_GUARD_PINS)
2247
2390
  ?? pinnedFilesHold(root, 'PreToolUse', [
2248
2391
  { relative: CREDENTIAL_GUARD, accepted: [...new Set(credential.map(([script]) => script))] },
@@ -23,7 +23,7 @@ import * as fs from "node:fs";
23
23
  import * as path from "node:path";
24
24
  import { createHqFlagClient as createFlagClient } from "../../flag-client-headers.js";
25
25
  import { resolveFlagRegistryEndpoint } from "../../flag-registry-endpoint.js";
26
- import { readFlagSnapshotFile, writeFlagSnapshotFile } from "../../flag-snapshot-file.js";
26
+ import { readCurrentFlagSnapshotFile, writeFlagSnapshotFile } from "../../flag-snapshot-file.js";
27
27
  import { isNonCloudCompanySlug } from "../../work-context/company-rebind.js";
28
28
  import { isWorkContextSessionStateFileName, workContextSessionsDir } from "../../work-context/paths.js";
29
29
  import { readSessionState } from "../../work-context/state.js";
@@ -91,7 +91,7 @@ export function companiesNeedingFlagRefresh(workContextRoot, env, now = () => ne
91
91
  }
92
92
  return [...latest.values()]
93
93
  .sort((a, b) => b.at - a.at)
94
- .filter(({ uid }) => readFlagSnapshotFile(uid, { env, now: nowMs, maxAgeMs: refreshAgeMs }) === null)
94
+ .filter(({ uid }) => readCurrentFlagSnapshotFile(uid, { env, now: nowMs, maxAgeMs: refreshAgeMs }) === null)
95
95
  .slice(0, COMPANY_FLAG_REFRESH_MAX_COMPANIES)
96
96
  .map(({ uid, slug }) => (slug ? { uid, slug } : { uid }));
97
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.345.257",
3
+ "version": "5.345.258",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -128,11 +128,11 @@
128
128
  "*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
129
129
  },
130
130
  "optionalDependencies": {
131
- "@indigoai-us/hq-hook-win32-x64": "5.345.257",
132
- "@indigoai-us/hq-hook-win32-arm64": "5.345.257",
133
- "@indigoai-us/hq-hook-darwin-x64": "5.345.257",
134
- "@indigoai-us/hq-hook-darwin-arm64": "5.345.257",
135
- "@indigoai-us/hq-hook-linux-x64": "5.345.257",
136
- "@indigoai-us/hq-hook-linux-arm64": "5.345.257"
131
+ "@indigoai-us/hq-hook-win32-x64": "5.345.258",
132
+ "@indigoai-us/hq-hook-win32-arm64": "5.345.258",
133
+ "@indigoai-us/hq-hook-darwin-x64": "5.345.258",
134
+ "@indigoai-us/hq-hook-darwin-arm64": "5.345.258",
135
+ "@indigoai-us/hq-hook-linux-x64": "5.345.258",
136
+ "@indigoai-us/hq-hook-linux-arm64": "5.345.258"
137
137
  }
138
138
  }