@indigoai-us/hq-cli 5.345.257 → 5.345.260
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 +31 -0
- package/assets/scaffold/core/scripts/handoff-knowledge-commit.sh +163 -5
- package/assets/scaffold/core/scripts/handoff-sync-prefetch.sh +39 -0
- package/assets/scaffold/core/scripts/handoff-sync-publish.sh +51 -3
- package/contracts/host-canary-release.json +7 -7
- package/dist/commands/cloud.d.ts +2 -7
- package/dist/commands/cloud.js +6 -30
- package/dist/commands/core-bucket-c-handoff-knowledge-native.d.ts +24 -2
- package/dist/commands/core-bucket-c-handoff-knowledge-native.js +170 -19
- package/dist/commands/core-bucket-c-handoff-sync-native.d.ts +4 -2
- package/dist/commands/core-bucket-c-handoff-sync-native.js +153 -34
- package/dist/commands/core-bucket-c-handoff-sync-worker.cjs +201 -0
- package/dist/commands/core-handoff.js +57 -14
- package/dist/commands/keyed-sync-pull.d.ts +7 -3
- package/dist/commands/keyed-sync-pull.js +90 -22
- package/dist/commands/reindex.d.ts +3 -0
- package/dist/commands/reindex.js +11 -5
- package/dist/commands/rescue.js +7 -2
- package/dist/commands/sync-core.js +24 -7
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +3227 -2138
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/canonical-person.d.ts +19 -0
- package/dist/lib/canonical-person.js +30 -0
- package/dist/lib/company-sessions-cli.d.ts +12 -0
- package/dist/lib/company-sessions-cli.js +54 -0
- package/dist/lib/company-sessions.d.ts +31 -0
- package/dist/lib/company-sessions.js +304 -0
- package/dist/lib/doctor/checks/replay-recorder.js +3 -3
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/flag-snapshot-file.d.ts +47 -1
- package/dist/lib/flag-snapshot-file.js +143 -20
- package/dist/lib/hook-engine/coverage.d.ts +115 -7
- package/dist/lib/hook-engine/coverage.js +280 -10
- package/dist/lib/mesh/live/company-flag-refresh.js +2 -2
- package/dist/lib/onboarding/orchestrator.js +4 -2
- package/dist/lib/sync-core/engine-home.d.ts +5 -1
- package/dist/lib/sync-core/engine-home.js +6 -2
- package/dist/lib/sync-core/reconcile.d.ts +5 -0
- package/dist/lib/sync-core/reconcile.js +21 -1
- package/dist/lib/sync-core/vault-uid.d.ts +2 -0
- package/dist/lib/sync-core/vault-uid.js +4 -0
- package/dist/utils/sync-operation-lock.d.ts +2 -1
- package/dist/utils/sync-operation-lock.js +13 -2
- package/package.json +8 -8
|
@@ -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
|
-
/**
|
|
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],
|
|
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], "
|
|
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",
|
|
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", "
|
|
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 =
|
|
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
|
|
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
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -168,6 +168,20 @@ export declare function coversKey(key: string): {
|
|
|
168
168
|
export declare function coveredOn(covers: Readonly<Record<string, readonly string[]>> | undefined, event: string, host: CoreNextHost): string[];
|
|
169
169
|
/** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
|
|
170
170
|
export declare function uncoveredHooks(root: string, host: CoreNextHost, event: string, covers: Readonly<Record<string, readonly string[]>> | undefined, env?: NodeJS.ProcessEnv): string[];
|
|
171
|
+
/**
|
|
172
|
+
* The two script revision sets the native `merged-write-guard-shadow` port rebuilds:
|
|
173
|
+
* legacy (`v16.0.48-beta.109`, constants in `crates/hq-hook/src/merged_write_guard.rs`) and
|
|
174
|
+
* released (`v16.0.49` / `v16.0.50`, constants in `crates/hq-hook/src/merged_write_guard/release_1649.rs`
|
|
175
|
+
* plus `Revision::Beta124` in `crates/hq-hook/src/block_core_writes.rs`).
|
|
176
|
+
*/
|
|
177
|
+
export declare const MERGED_WRITE_GUARD_PINS_LEGACY: ReadonlyArray<readonly [string, string]>;
|
|
178
|
+
export declare const MERGED_WRITE_GUARD_PINS_1649: ReadonlyArray<readonly [string, string]>;
|
|
179
|
+
/**
|
|
180
|
+
* Why `merged-write-guard-shadow` must stay on the shell registration in `root`: the wrapper
|
|
181
|
+
* script is present on disk and either the wrapper or one of its companion scripts does not match
|
|
182
|
+
* the pinned revision set that `crates/hq-hook/src/merged_write_guard.rs` rebuilds.
|
|
183
|
+
*/
|
|
184
|
+
export declare function fleetLocalMergedWriteGuardHold(root: string): string | null;
|
|
171
185
|
/**
|
|
172
186
|
* The script revisions the native SessionStart master rebuilds (hq-core v16.0.48 through v16.0.50,
|
|
173
187
|
* and the hq-core-staging fd709b39a shim and hq-session.sh):
|
|
@@ -200,6 +214,23 @@ export declare const MIGRATE_POLICY_TRIGGERS_PINS: ReadonlyArray<readonly [strin
|
|
|
200
214
|
* does not hold. Null when every present pinned file matches.
|
|
201
215
|
*/
|
|
202
216
|
export declare function migratePolicyTriggersHold(root: string): string | null;
|
|
217
|
+
/**
|
|
218
|
+
* The script revisions the native fleet-local PreToolUse adapter port models (hq-core v16.0.48
|
|
219
|
+
* through v16.0.50): `host::fleet::local_pre::RELEASED_CORE_SHA256` (`hook-adapter-core.sh`)
|
|
220
|
+
* and `host::fleet::inherit_scope::RELEASED_LIB_SHA256` (`session-scope-capability.sh`).
|
|
221
|
+
* `FleetLocalPre` matches the shell adapter when either file is absent (`DISPATCHER_UNAVAILABLE`
|
|
222
|
+
* / skip scope inheritance), and refuses any other revision present on disk.
|
|
223
|
+
* `RELEASED_CORE_SHA256` also accepts the two classifying cores of hq-core-staging #2119. This
|
|
224
|
+
* list accepts only the bd733f7b core, the one the fleet-local parity tests run against, so a
|
|
225
|
+
* root on a classifying core keeps fleet-local PreToolUse on the shell adapter.
|
|
226
|
+
*/
|
|
227
|
+
export declare const FLEET_LOCAL_PRE_TOOL_USE_PINS: readonly PinnedFile[];
|
|
228
|
+
/**
|
|
229
|
+
* Why fleet-local PreToolUse must stay on the shell adapter in `root`: a present file of
|
|
230
|
+
* [`FLEET_LOCAL_PRE_TOOL_USE_PINS`] cannot be read or is not the pinned revision. Uses the shared
|
|
231
|
+
* [`pinnedFilesHold`] helper. Null when every present file matches.
|
|
232
|
+
*/
|
|
233
|
+
export declare function fleetLocalPreToolUseHold(root: string): string | null;
|
|
203
234
|
/**
|
|
204
235
|
* The one Codex adapter pair the native Codex SubagentStop is modelled on (hq-core v16.0.47):
|
|
205
236
|
* `ADAPTER_RELEASES` and `ADAPTER_CORE_RELEASES` in crates/hq-hook/src/post_hooks/codex.rs.
|
|
@@ -304,11 +335,21 @@ export declare const PRE_TOOL_USE_CODEX_ADAPTER_PIN: PinnedFile;
|
|
|
304
335
|
* credential guard holds that file.
|
|
305
336
|
*/
|
|
306
337
|
export declare const PRE_TOOL_USE_VAULT_GUARD_PINS: readonly PinnedFile[];
|
|
338
|
+
/**
|
|
339
|
+
* Claimed PreToolUse hooks whose native member answers in place of the root's script with no port
|
|
340
|
+
* pin of its own, with the script revisions the member answers for: pre_tool_use_master.rs
|
|
341
|
+
* `CLAIMED_SCRIPT_PINS`, where the native PreToolUse refuses any other present revision. The scope
|
|
342
|
+
* authorizer: hq-core v16.0.45 to v16.0.52 and the prereleases core-pins.json lists. hq-core
|
|
343
|
+
* 16.0.53-beta.1 (36312275) adds a PowerShell check the native scope member does not have, so that
|
|
344
|
+
* root stays on the old dispatcher. A missing script is not held: the native PreToolUse refuses a
|
|
345
|
+
* registered safety guard that is missing, as master-hook did.
|
|
346
|
+
*/
|
|
347
|
+
export declare const PRE_TOOL_USE_CLAIMED_SCRIPT_PINS: readonly PinnedFile[];
|
|
307
348
|
/**
|
|
308
349
|
* The credential guard's script revisions, each with the arithmetic library its port follows
|
|
309
350
|
* (ports.rs `HOOK_SCRIPT_SHA256`, `HOOK_COMPANION_SHA256` and `COMPANION_SCRIPT_BINDINGS`): the
|
|
310
|
-
* 16.0.48 script 6512581d
|
|
311
|
-
* other revision only with 0566180c.
|
|
351
|
+
* 16.0.48 script 6512581d, its 16.0.51-beta.44 successor 5064061f and the 16.0.52 script e8f19ecc
|
|
352
|
+
* only with e90d160f, every other revision only with 0566180c.
|
|
312
353
|
*/
|
|
313
354
|
export declare const PRE_TOOL_USE_CREDENTIAL_GUARD_GENERATIONS: ReadonlyArray<readonly [string, string]>;
|
|
314
355
|
/**
|
|
@@ -327,19 +368,20 @@ export declare const PRE_TOOL_USE_IMAGE_GUARD_PINS: readonly PinnedFile[];
|
|
|
327
368
|
* sha256 picks the set and never refuses by itself: the v16.0.49 wrapper (742870a2) picks
|
|
328
369
|
* `released`, any other wrapper `legacy`. In a set the helper .cjs, when listed, must match; each
|
|
329
370
|
* 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
|
|
371
|
+
* guard is on its pin, and must then be one of the set's libraries (the released set also takes the
|
|
372
|
+
* v16.0.52 library 436493e3).
|
|
331
373
|
*/
|
|
332
374
|
export declare const MERGED_WRITE_GUARD_SETS: {
|
|
333
375
|
readonly releasedWrapper: "742870a2ada4f9357320f7708fca7363be6d81fde374948b59873c327a7d7206";
|
|
334
376
|
readonly released: {
|
|
335
377
|
readonly helper: "6f65f2b9425612f9b2ec2590dace82585230210dcd69a124a9cdeb0116ea7f30";
|
|
336
378
|
readonly guards: ReadonlyArray<readonly [string, string]>;
|
|
337
|
-
readonly
|
|
379
|
+
readonly hookLibs: readonly string[];
|
|
338
380
|
};
|
|
339
381
|
readonly legacy: {
|
|
340
382
|
readonly helper: null;
|
|
341
383
|
readonly guards: ReadonlyArray<readonly [string, string]>;
|
|
342
|
-
readonly
|
|
384
|
+
readonly hookLibs: readonly string[];
|
|
343
385
|
};
|
|
344
386
|
};
|
|
345
387
|
/**
|
|
@@ -349,6 +391,68 @@ export declare const MERGED_WRITE_GUARD_SETS: {
|
|
|
349
391
|
* so the hold assumes it is.
|
|
350
392
|
*/
|
|
351
393
|
export declare function mergedWriteGuardHold(root: string, event: string): string | null;
|
|
394
|
+
/**
|
|
395
|
+
* Why a Codex `event` must stay on the shell adapter in `root`: `.claude/settings.json` holds an
|
|
396
|
+
* entry of that event with a non-empty `args` list (the exec form, which `hq reindex` and the
|
|
397
|
+
* update healer write for the engine launcher). The adapter library may run such an entry as
|
|
398
|
+
* master-hook (`hqad_classify_exec`), which the native work does not model, so the native
|
|
399
|
+
* PreToolUse refuses every Codex tool call on such a root, whatever the tool or the entry's
|
|
400
|
+
* matcher (pre_tool_use_master.rs `codex_exec_refusal`). Without this hold `hq reindex` would
|
|
401
|
+
* switch the event onto that refusal, as for `codexSubagentStopHold`.
|
|
402
|
+
*
|
|
403
|
+
* The engine's own registration for this root is not such an entry ([`engineOwnExecEntry`]):
|
|
404
|
+
* `hq reindex` writes it into this file for Claude Code when the new core is on, the native
|
|
405
|
+
* PreToolUse models what the adapter did with it (fleet_settings.rs `engine_own_master`), and a
|
|
406
|
+
* hold on it would undo reindex's own switch on the next run.
|
|
407
|
+
*
|
|
408
|
+
* The walk is the one in crates/hq-hook/src/host/fleet_settings.rs `unsupported_exec_form_entry`:
|
|
409
|
+
* the event's slot and each group's `hooks` are a list's items or an object's values, as the
|
|
410
|
+
* adapter's jq query walks them. The hold is wider than the run-time refusal in two ways, both of
|
|
411
|
+
* which only keep the event on the shell adapter: it does not ask whether master-hook.sh and
|
|
412
|
+
* hook-adapter-core.sh are present (without either the engine is idle before it reads the
|
|
413
|
+
* settings; the pinned-file hold already keeps such a root), and it reads the file with
|
|
414
|
+
* `JSON.parse`, which accepts a few files serde_json rejects (invalid UTF-8 read with replacement
|
|
415
|
+
* characters, a lone surrogate escape, nesting deeper than 128), where the engine reads no
|
|
416
|
+
* entry. A file that is absent or that `JSON.parse` rejects holds no such entry. Null when there
|
|
417
|
+
* is none.
|
|
418
|
+
*/
|
|
419
|
+
export declare function codexExecFormSettingsHold(root: string, event: string): string | null;
|
|
420
|
+
/**
|
|
421
|
+
* Whether `entry` is the registration `hq reindex` writes for `event` on this root when the new
|
|
422
|
+
* core is on. Three tests, each the one the adapter library's `hqad_classify_exec` makes before it
|
|
423
|
+
* gives the entry a master record, so no entry is exempt here that the library reads another way:
|
|
424
|
+
* - a `command` entry whose arguments are exactly `run --host <host> <event> --hq-root <root>`, the
|
|
425
|
+
* host a plain word;
|
|
426
|
+
* - the command is the release-stable hq-hook as the library tests it ([`stableEngineCommand`]). A
|
|
427
|
+
* command that only contains the stable segment somewhere is not one;
|
|
428
|
+
* - the root value is absolute and names this root ([`ownRootValue`]).
|
|
429
|
+
*
|
|
430
|
+
* This is narrower than [`isCoreNextEntry`], which registration uses to find its entries: every
|
|
431
|
+
* entry this accepts, that accepts. crates/hq-hook/src/host/fleet_settings.rs `engine_own_entry` is
|
|
432
|
+
* the same three tests, statement for statement.
|
|
433
|
+
*/
|
|
434
|
+
export declare function engineOwnExecEntry(entry: unknown, root: string, event: string, windows?: boolean): boolean;
|
|
435
|
+
/**
|
|
436
|
+
* Whether a `--hq-root` value names `root`. The value must be absolute (`/...`, or on Windows a
|
|
437
|
+
* drive path; a `\\?\` verbatim path or a UNC path is not one) and, trailing separators aside,
|
|
438
|
+
* every name in it must be a plain name: no `.`, `..` or empty segment. The separators are `/`, and
|
|
439
|
+
* `\` on Windows only (elsewhere a backslash is part of a name). It then names the root when it is
|
|
440
|
+
* the root's spelling, trailing separators aside, or when the operating system resolves it to the
|
|
441
|
+
* same folder as the root (`fs.realpathSync.native`, which is realpath(3), or
|
|
442
|
+
* `GetFinalPathNameByHandle` on Windows). Refusing `.` and `..` before resolving means no value
|
|
443
|
+
* depends on whether `..` is applied before or after a link. fleet_settings.rs `own_root_value` is
|
|
444
|
+
* the same function, resolving with `Path::canonicalize`; both answer
|
|
445
|
+
* crates/hq-hook/tests/fixtures/engine-own-entry/cases.json.
|
|
446
|
+
*/
|
|
447
|
+
export declare function ownRootValue(value: string, root: string, windows: boolean): boolean;
|
|
448
|
+
/**
|
|
449
|
+
* The command tests of `hqad_classify_exec` for the stable link, with `cygpath` present on Windows
|
|
450
|
+
* (`windows`) and absent elsewhere: an absolute path with no `.`, `..` or empty segment whose
|
|
451
|
+
* first `.hq/bin/hq-hook/` is followed by `stable/` and an engine binary name. A Windows drive path
|
|
452
|
+
* is read with its separators swapped, and only when it is written with one kind of separator.
|
|
453
|
+
* fleet_settings.rs `stable_engine_command`.
|
|
454
|
+
*/
|
|
455
|
+
export declare function stableEngineCommand(command: string, windows: boolean): boolean;
|
|
352
456
|
/**
|
|
353
457
|
* Why PreToolUse must stay on the old dispatcher in `root` on `host` once `master-hook:PreToolUse`
|
|
354
458
|
* is claimed there (`hooks`: the old dispatcher's PreToolUse hooks there). Each part mirrors a
|
|
@@ -357,12 +461,16 @@ export declare function mergedWriteGuardHold(root: string, event: string): strin
|
|
|
357
461
|
* `changed_files_on`, checked by `guard_refusal_in` before any member): missing, not a regular
|
|
358
462
|
* file or another revision, or the credential guard's script and library not a bound pair. The
|
|
359
463
|
* Codex adapter is read on Codex only;
|
|
464
|
+
* - a claimed guard script present at a revision its native member does not answer for
|
|
465
|
+
* (`PRE_TOOL_USE_CLAIMED_SCRIPT_PINS`, pre_tool_use_master.rs `unmodelled_claimed_scripts`);
|
|
360
466
|
* - the policy enforcement gate beside the hook-lib.sh its revision accepts (the injector runs it
|
|
361
467
|
* on Bash calls whatever the registry lists), as for PostToolUse;
|
|
362
468
|
* - the policy-frontmatter evaluator scripts;
|
|
363
469
|
* - the merged-write-guard-shadow companions, where the registry lists that row;
|
|
364
|
-
* - on Claude Code, the image rule's script
|
|
365
|
-
*
|
|
470
|
+
* - on Claude Code, the image rule's script;
|
|
471
|
+
* - on Codex, a `.claude/settings.json` PreToolUse entry in the exec form
|
|
472
|
+
* ([`codexExecFormSettingsHold`]).
|
|
473
|
+
* Null when the native PreToolUse accepts every file and the settings.
|
|
366
474
|
*/
|
|
367
475
|
export declare function preToolUseHold(root: string, host: CoreNextHost, hooks?: readonly string[]): string | null;
|
|
368
476
|
/**
|