@indigoai-us/hq-cli 5.345.247 → 5.345.250
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 +95 -0
- package/assets/lanes-hooks/hq-lanes-drain.sh +1 -1
- package/contracts/host-canary-release.json +14 -0
- package/dist/command-catalog.generated.d.ts +1198 -0
- package/dist/command-catalog.generated.js +1476 -0
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/core-job-run-native.js +4 -0
- package/dist/commands/core-knowledge-prefs.d.ts +1 -1
- package/dist/commands/core-knowledge-prefs.js +1 -16
- package/dist/commands/core.js +0 -2
- package/dist/commands/daemon.js +21 -0
- package/dist/commands/lanes-hold.js +7 -7
- package/dist/commands/lanes-resume.js +2 -2
- package/dist/commands/lanes-review.js +1 -1
- package/dist/commands/lanes-session-start.d.ts +1 -1
- package/dist/commands/lanes-session-start.js +3 -3
- package/dist/commands/lanes-shared.d.ts +1 -1
- package/dist/commands/lanes.d.ts +2 -2
- package/dist/commands/lanes.js +50 -50
- package/dist/commands/mesh.d.ts +25 -0
- package/dist/commands/mesh.js +48 -8
- package/dist/commands/ontology-graph.d.ts +63 -0
- package/dist/commands/ontology-graph.js +470 -0
- package/dist/commands/sync-core.js +6 -0
- package/dist/fast-scaffold.js +1 -3
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +281 -256
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +48 -1
- package/dist/lanes-monitor-check-argv.d.ts +1 -1
- package/dist/lanes-monitor-check-argv.js +1 -1
- package/dist/lanes-monitor-check-fast.d.ts +1 -1
- package/dist/lanes-monitor-check-fast.js +1 -1
- package/dist/lanes-session-start-argv.d.ts +1 -1
- package/dist/lanes-session-start-argv.js +1 -1
- package/dist/lib/capacity/sign-in.d.ts +1 -1
- package/dist/lib/capacity/sign-in.js +1 -1
- package/dist/lib/daemon/hook-requests-conduct-link.js +2 -2
- package/dist/lib/daemon/installed-cli-restart.d.ts +57 -0
- package/dist/lib/daemon/installed-cli-restart.js +114 -0
- package/dist/lib/daemon/lanes-monitor-state.d.ts +2 -2
- package/dist/lib/daemon/lanes-monitor-state.js +2 -2
- package/dist/lib/daemon/legacy-journal-gate.d.ts +32 -0
- package/dist/lib/daemon/legacy-journal-gate.js +102 -0
- package/dist/lib/daemon/machine-checks.d.ts +7 -0
- package/dist/lib/daemon/machine-checks.js +10 -0
- package/dist/lib/daemon/merge-sections.d.ts +3 -3
- package/dist/lib/daemon/merge-sections.js +7 -7
- package/dist/lib/daemon/remote-control-pools.js +1 -1
- package/dist/lib/daemon/run.d.ts +3 -1
- package/dist/lib/daemon/run.js +49 -6
- package/dist/lib/daemon/state-file.d.ts +1 -1
- package/dist/lib/daemon/state-file.js +1 -1
- 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 +2 -0
- package/dist/lib/flag-snapshot-file.js +118 -48
- package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
- package/dist/lib/hook-engine/canary-gate.js +138 -6
- package/dist/lib/hook-engine/coverage.d.ts +82 -13
- package/dist/lib/hook-engine/coverage.js +214 -18
- package/dist/lib/hook-engine/registration-identity.d.ts +5 -0
- package/dist/lib/hook-engine/registration-identity.js +1 -1
- package/dist/lib/hook-engine/resolve.d.ts +23 -0
- package/dist/lib/hook-engine/resolve.js +48 -1
- package/dist/lib/hook-engine/stable-heal.d.ts +87 -0
- package/dist/lib/hook-engine/stable-heal.js +214 -0
- package/dist/lib/hot-channels/graph-context.d.ts +105 -0
- package/dist/lib/hot-channels/graph-context.js +380 -0
- package/dist/lib/hot-channels/signals-pass.js +27 -1
- package/dist/lib/lanes/claude-credential.d.ts +1 -1
- package/dist/lib/lanes/claude-credential.js +1 -1
- package/dist/lib/lanes/delivery-core.d.ts +1 -1
- package/dist/lib/lanes/delivery-core.js +1 -1
- package/dist/lib/lanes/delivery.d.ts +10 -10
- package/dist/lib/lanes/delivery.js +8 -8
- package/dist/lib/lanes/dropbox.d.ts +1 -1
- package/dist/lib/lanes/dropbox.js +1 -1
- package/dist/lib/lanes/hooks-install.js +2 -2
- package/dist/lib/lanes/index.d.ts +1 -1
- package/dist/lib/lanes/index.js +1 -1
- package/dist/lib/lanes/monitor.js +1 -1
- package/dist/lib/lanes/quota-notice.js +1 -1
- package/dist/lib/lanes/quota.d.ts +1 -1
- package/dist/lib/lanes/quota.js +1 -1
- package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
- package/dist/lib/lanes/repo-merge-hold.js +2 -2
- package/dist/lib/lanes/spawn.d.ts +4 -4
- package/dist/lib/lanes/spawn.js +5 -5
- package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
- package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
- package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
- package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
- package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
- package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
- package/dist/lib/mesh/live/daemon/run.js +35 -2
- package/dist/lib/mesh/live/direct-drain.js +1 -1
- package/dist/lib/mesh/live/emit.d.ts +3 -0
- package/dist/lib/mesh/live/emit.js +32 -9
- package/dist/lib/mesh/live/flush.d.ts +3 -0
- package/dist/lib/mesh/live/flush.js +115 -32
- package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
- package/dist/lib/mesh/live/liveness-carry.js +1 -1
- package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
- package/dist/lib/mesh/live/reporting-privacy.js +235 -11
- package/dist/lib/mesh/live/spool.d.ts +17 -2
- package/dist/lib/mesh/live/spool.js +22 -6
- package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
- package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
- package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
- package/dist/lib/ontology-graph/legacy/index.js +1150 -0
- package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
- package/dist/lib/ontology-graph/legacy/parse.js +126 -0
- package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
- package/dist/lib/ontology-graph/legacy/report.js +254 -0
- package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
- package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
- package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
- package/dist/lib/ontology-graph/lint/checks.js +717 -0
- package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
- package/dist/lib/ontology-graph/lint/coverage.js +241 -0
- package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
- package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
- package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
- package/dist/lib/ontology-graph/lint/index.js +176 -0
- package/dist/lib/ontology-graph/model/files.d.ts +20 -0
- package/dist/lib/ontology-graph/model/files.js +89 -0
- package/dist/lib/ontology-graph/model/index.d.ts +65 -0
- package/dist/lib/ontology-graph/model/index.js +100 -0
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
- package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
- package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
- package/dist/lib/ontology-graph/model/pass.js +958 -0
- package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
- package/dist/lib/ontology-graph/model/runner.js +160 -0
- package/dist/lib/ontology-graph/model/step.d.ts +197 -0
- package/dist/lib/ontology-graph/model/step.js +526 -0
- package/dist/lib/ontology-graph/model/tasks.d.ts +183 -0
- package/dist/lib/ontology-graph/model/tasks.js +349 -0
- package/dist/lib/ontology-graph/not-implemented.d.ts +5 -0
- package/dist/lib/ontology-graph/not-implemented.js +8 -0
- package/dist/lib/ontology-graph/org/compare.d.ts +28 -0
- package/dist/lib/ontology-graph/org/compare.js +239 -0
- package/dist/lib/ontology-graph/org/derive.d.ts +67 -0
- package/dist/lib/ontology-graph/org/derive.js +359 -0
- package/dist/lib/ontology-graph/org/index.d.ts +102 -0
- package/dist/lib/ontology-graph/org/index.js +630 -0
- package/dist/lib/ontology-graph/org/load.d.ts +31 -0
- package/dist/lib/ontology-graph/org/load.js +476 -0
- package/dist/lib/ontology-graph/org/role.d.ts +38 -0
- package/dist/lib/ontology-graph/org/role.js +268 -0
- package/dist/lib/ontology-graph/org/structure.d.ts +63 -0
- package/dist/lib/ontology-graph/org/structure.js +437 -0
- package/dist/lib/ontology-graph/org/text.d.ts +97 -0
- package/dist/lib/ontology-graph/org/text.js +321 -0
- package/dist/lib/ontology-graph/org/types.d.ts +457 -0
- package/dist/lib/ontology-graph/org/types.js +80 -0
- package/dist/lib/ontology-graph/pages/index.d.ts +64 -0
- package/dist/lib/ontology-graph/pages/index.js +193 -0
- package/dist/lib/ontology-graph/pages/render.d.ts +144 -0
- package/dist/lib/ontology-graph/pages/render.js +688 -0
- package/dist/lib/ontology-graph/proposals/apply.d.ts +109 -0
- package/dist/lib/ontology-graph/proposals/apply.js +468 -0
- package/dist/lib/ontology-graph/proposals/group.d.ts +63 -0
- package/dist/lib/ontology-graph/proposals/group.js +232 -0
- package/dist/lib/ontology-graph/proposals/index.d.ts +173 -0
- package/dist/lib/ontology-graph/proposals/index.js +474 -0
- package/dist/lib/ontology-graph/proposals/model.d.ts +162 -0
- package/dist/lib/ontology-graph/proposals/model.js +196 -0
- package/dist/lib/ontology-graph/proposals/org-chart.d.ts +82 -0
- package/dist/lib/ontology-graph/proposals/org-chart.js +340 -0
- package/dist/lib/ontology-graph/read/brief.d.ts +26 -0
- package/dist/lib/ontology-graph/read/brief.js +254 -0
- package/dist/lib/ontology-graph/read/graph-index.d.ts +76 -0
- package/dist/lib/ontology-graph/read/graph-index.js +198 -0
- package/dist/lib/ontology-graph/read/index.d.ts +59 -0
- package/dist/lib/ontology-graph/read/index.js +803 -0
- package/dist/lib/ontology-graph/read/member.d.ts +7 -0
- package/dist/lib/ontology-graph/read/member.js +34 -0
- package/dist/lib/ontology-graph/read/names.d.ts +49 -0
- package/dist/lib/ontology-graph/read/names.js +297 -0
- package/dist/lib/ontology-graph/read/reader-setting.d.ts +19 -0
- package/dist/lib/ontology-graph/read/reader-setting.js +62 -0
- package/dist/lib/ontology-graph/read/test-graph.d.ts +37 -0
- package/dist/lib/ontology-graph/read/test-graph.js +150 -0
- package/dist/lib/ontology-graph/replay/buffered-store.d.ts +33 -0
- package/dist/lib/ontology-graph/replay/buffered-store.js +50 -0
- package/dist/lib/ontology-graph/replay/config.d.ts +41 -0
- package/dist/lib/ontology-graph/replay/config.js +105 -0
- package/dist/lib/ontology-graph/replay/engine.d.ts +146 -0
- package/dist/lib/ontology-graph/replay/engine.js +1240 -0
- package/dist/lib/ontology-graph/replay/extractors.d.ts +59 -0
- package/dist/lib/ontology-graph/replay/extractors.js +1555 -0
- package/dist/lib/ontology-graph/replay/index.d.ts +91 -0
- package/dist/lib/ontology-graph/replay/index.js +220 -0
- package/dist/lib/ontology-graph/replay/listing-manifest.d.ts +66 -0
- package/dist/lib/ontology-graph/replay/listing-manifest.js +242 -0
- package/dist/lib/ontology-graph/replay/member.d.ts +19 -0
- package/dist/lib/ontology-graph/replay/member.js +65 -0
- package/dist/lib/ontology-graph/replay/mentions.d.ts +58 -0
- package/dist/lib/ontology-graph/replay/mentions.js +239 -0
- package/dist/lib/ontology-graph/replay/readers.d.ts +98 -0
- package/dist/lib/ontology-graph/replay/readers.js +1251 -0
- package/dist/lib/ontology-graph/replay/rules.d.ts +127 -0
- package/dist/lib/ontology-graph/replay/rules.js +374 -0
- package/dist/lib/ontology-graph/replay/scope.d.ts +35 -0
- package/dist/lib/ontology-graph/replay/scope.js +115 -0
- package/dist/lib/ontology-graph/replay/transcripts.d.ts +39 -0
- package/dist/lib/ontology-graph/replay/transcripts.js +224 -0
- package/dist/lib/ontology-graph/replay/util.d.ts +55 -0
- package/dist/lib/ontology-graph/replay/util.js +256 -0
- package/dist/lib/ontology-graph/resolve/entity-index.d.ts +159 -0
- package/dist/lib/ontology-graph/resolve/entity-index.js +652 -0
- package/dist/lib/ontology-graph/resolve/index.d.ts +113 -0
- package/dist/lib/ontology-graph/resolve/index.js +214 -0
- package/dist/lib/ontology-graph/resolve/machine.d.ts +34 -0
- package/dist/lib/ontology-graph/resolve/machine.js +95 -0
- package/dist/lib/ontology-graph/resolve/normalize.d.ts +35 -0
- package/dist/lib/ontology-graph/resolve/normalize.js +124 -0
- package/dist/lib/ontology-graph/resolve/org-chart.d.ts +107 -0
- package/dist/lib/ontology-graph/resolve/org-chart.js +578 -0
- package/dist/lib/ontology-graph/resolve/org-layer.d.ts +78 -0
- package/dist/lib/ontology-graph/resolve/org-layer.js +159 -0
- package/dist/lib/ontology-graph/resolve/org-seed.d.ts +141 -0
- package/dist/lib/ontology-graph/resolve/org-seed.js +631 -0
- package/dist/lib/ontology-graph/resolve/org-sources.d.ts +165 -0
- package/dist/lib/ontology-graph/resolve/org-sources.js +634 -0
- package/dist/lib/ontology-graph/resolve/roster.d.ts +76 -0
- package/dist/lib/ontology-graph/resolve/roster.js +226 -0
- package/dist/lib/ontology-graph/resolve/seed.d.ts +267 -0
- package/dist/lib/ontology-graph/resolve/seed.js +1198 -0
- package/dist/lib/ontology-graph/resolve/upsert.d.ts +58 -0
- package/dist/lib/ontology-graph/resolve/upsert.js +139 -0
- package/dist/lib/ontology-graph/resolve/writer.d.ts +128 -0
- package/dist/lib/ontology-graph/resolve/writer.js +351 -0
- package/dist/lib/ontology-graph/schema/authority.d.ts +107 -0
- package/dist/lib/ontology-graph/schema/authority.js +186 -0
- package/dist/lib/ontology-graph/schema/default-schema.d.ts +10 -0
- package/dist/lib/ontology-graph/schema/default-schema.js +242 -0
- package/dist/lib/ontology-graph/schema/grammar.d.ts +57 -0
- package/dist/lib/ontology-graph/schema/grammar.js +409 -0
- package/dist/lib/ontology-graph/schema/index.d.ts +12 -0
- package/dist/lib/ontology-graph/schema/index.js +10 -0
- package/dist/lib/ontology-graph/schema/validate.d.ts +13 -0
- package/dist/lib/ontology-graph/schema/validate.js +132 -0
- package/dist/lib/ontology-graph/store/files.d.ts +34 -0
- package/dist/lib/ontology-graph/store/files.js +207 -0
- package/dist/lib/ontology-graph/store/fs.d.ts +30 -0
- package/dist/lib/ontology-graph/store/fs.js +101 -0
- package/dist/lib/ontology-graph/store/graph-store.d.ts +14 -0
- package/dist/lib/ontology-graph/store/graph-store.js +520 -0
- package/dist/lib/ontology-graph/store/index.d.ts +18 -0
- package/dist/lib/ontology-graph/store/index.js +15 -0
- package/dist/lib/ontology-graph/store/ingest.d.ts +37 -0
- package/dist/lib/ontology-graph/store/ingest.js +323 -0
- package/dist/lib/ontology-graph/store/paths.d.ts +114 -0
- package/dist/lib/ontology-graph/store/paths.js +232 -0
- package/dist/lib/ontology-graph/types.d.ts +1190 -0
- package/dist/lib/ontology-graph/types.js +131 -0
- package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
- package/dist/lib/sync-core/engine-holds.d.ts +1 -1
- package/dist/lib/sync-core/engine-holds.js +12 -2
- package/dist/lib/sync-core/hand-back.d.ts +2 -1
- package/dist/lib/sync-core/hand-back.js +16 -2
- package/dist/lib/sync-core/legacy-journal-export-child.d.ts +2 -0
- package/dist/lib/sync-core/legacy-journal-export-child.js +24 -0
- package/dist/lib/sync-core/legacy-journal-export.d.ts +39 -0
- package/dist/lib/sync-core/legacy-journal-export.js +241 -0
- package/dist/lib/sync-core/legacy-journal-reader.d.ts +15 -0
- package/dist/lib/sync-core/legacy-journal-reader.js +56 -0
- package/dist/lib/sync-core/reconcile.d.ts +3 -0
- package/dist/lib/sync-core/reconcile.js +43 -3
- package/dist/utils/cli-telemetry.d.ts +1 -0
- package/dist/utils/cli-telemetry.js +6 -3
- package/dist/utils/frontmatter.d.ts +14 -0
- package/dist/utils/frontmatter.js +18 -0
- package/dist/utils/hook-engine-rollup.d.ts +96 -0
- package/dist/utils/hook-engine-rollup.js +725 -0
- package/dist/utils/interactive-caller.js +1 -1
- package/package.json +9 -9
- package/scripts/install-hook-engine.mjs +4 -0
- package/assets/scaffold/core/scripts/knowledge-prefs.sh +0 -55
|
@@ -1,5 +1,7 @@
|
|
|
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
|
+
/** Epoch ms of a snapshot `fetched_at`, or NaN when it is not in the shared grammar. */
|
|
4
|
+
export declare function parseSnapshotTime(text: string): number;
|
|
3
5
|
export type FlagSnapshotWriteStep = "mkdir" | "chmod_dir" | "open_tmp" | "write_tmp" | "rename" | "chmod_file";
|
|
4
6
|
export declare function flagSnapshotWriteFailureTags(error: unknown): Record<string, string>;
|
|
5
7
|
export interface PersistedFlagSnapshot {
|
|
@@ -3,8 +3,42 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as os from "node:os";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import { freshAnywhereRuntimeFlags, HQ_ANYWHERE_RUNTIME_FLAG, HQ_ANYWHERE_RUNTIME_FALSE_MAX_AGE_MS } from "./anywhere-runtime-flag-key.js";
|
|
6
|
+
import { noteReplacedCompanySnapshot } from "./mesh/live/company-reporting-gaps.js";
|
|
6
7
|
export const FLAG_SNAPSHOT_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
7
8
|
const COMPANY_UID_RE = /^cmp_[A-Za-z0-9]{3,128}$/;
|
|
9
|
+
/**
|
|
10
|
+
* The one `fetched_at` grammar both snapshot readers accept: RFC 3339 with an
|
|
11
|
+
* upper-case `T`, seconds, at most nine fraction digits, and `Z` or a
|
|
12
|
+
* `+hh:mm`/`-hh:mm` offset. The hq-hook reader (crates/hq-hook/src/flags.rs
|
|
13
|
+
* `snapshot_time`) applies the same rule, so the two cannot disagree about a
|
|
14
|
+
* snapshot's age (rq_20261121230415_a549af8f50, informational 4). The shared
|
|
15
|
+
* cases are in test/fixtures/flag-snapshot-parity.json.
|
|
16
|
+
*/
|
|
17
|
+
const SNAPSHOT_TIME_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;
|
|
18
|
+
const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
19
|
+
/** Epoch ms of a snapshot `fetched_at`, or NaN when it is not in the shared grammar. */
|
|
20
|
+
export function parseSnapshotTime(text) {
|
|
21
|
+
const match = SNAPSHOT_TIME_RE.exec(text);
|
|
22
|
+
if (!match)
|
|
23
|
+
return Number.NaN;
|
|
24
|
+
const [year, month, day, hour, minute, second] = match.slice(1, 7).map(Number);
|
|
25
|
+
const leap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
26
|
+
const days = month === 2 && leap ? 29 : DAYS_IN_MONTH[month - 1];
|
|
27
|
+
if (days === undefined || day < 1 || day > days || hour > 23 || minute > 59 || second > 59)
|
|
28
|
+
return Number.NaN;
|
|
29
|
+
let offsetMs = 0;
|
|
30
|
+
if (match[8]) {
|
|
31
|
+
const offsetHour = Number(match[9]);
|
|
32
|
+
const offsetMinute = Number(match[10]);
|
|
33
|
+
if (offsetHour > 23 || offsetMinute > 59)
|
|
34
|
+
return Number.NaN;
|
|
35
|
+
offsetMs = (match[8] === "+" ? 1 : -1) * (offsetHour * 60 + offsetMinute) * 60_000;
|
|
36
|
+
}
|
|
37
|
+
const millis = match[7] ? Number(match[7].padEnd(3, "0").slice(0, 3)) : 0;
|
|
38
|
+
const at = new Date(Date.UTC(2000, 0, 1, hour, minute, second, millis));
|
|
39
|
+
at.setUTCFullYear(year, month - 1, day);
|
|
40
|
+
return at.getTime() - offsetMs;
|
|
41
|
+
}
|
|
8
42
|
function markWriteFailure(error, context) {
|
|
9
43
|
if (!error || (typeof error !== "object" && typeof error !== "function"))
|
|
10
44
|
return;
|
|
@@ -166,14 +200,15 @@ function normalizedFlagValues(flags) {
|
|
|
166
200
|
return Object.fromEntries(Object.entries(flags).filter((entry) => Boolean(entry[0].trim()) && isPersistedFlagValue(entry[0], entry[1])));
|
|
167
201
|
}
|
|
168
202
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
203
|
+
* Return only the boolean decisions. CLI gates are boolean; the engine reads
|
|
204
|
+
* port mode strings from the file itself. A value that is not a boolean is
|
|
205
|
+
* no answer for its own key only: the hq-hook reader reads each key on its
|
|
206
|
+
* own, and one bad value must not make the two readers disagree about the
|
|
207
|
+
* others (rq_20261121230415_a549af8f50, informational 4).
|
|
171
208
|
*/
|
|
172
209
|
function booleanFlagsOf(flags) {
|
|
173
210
|
const booleans = {};
|
|
174
211
|
for (const [key, value] of Object.entries(flags)) {
|
|
175
|
-
if (!isPersistedFlagValue(key, value))
|
|
176
|
-
return null;
|
|
177
212
|
if (typeof value === "boolean")
|
|
178
213
|
booleans[key] = value;
|
|
179
214
|
}
|
|
@@ -246,7 +281,7 @@ export function writePersonFlagSnapshotFile(flags, options = {}) {
|
|
|
246
281
|
fetched_at: options.fetchedAt ?? new Date().toISOString(),
|
|
247
282
|
flags: normalizedFlagValues(flags),
|
|
248
283
|
};
|
|
249
|
-
if (!Number.isFinite(
|
|
284
|
+
if (!Number.isFinite(parseSnapshotTime(snapshot.fetched_at))) {
|
|
250
285
|
throw new Error("Cannot persist a flag snapshot with an invalid fetched_at timestamp");
|
|
251
286
|
}
|
|
252
287
|
if (fallbackCacheUsed)
|
|
@@ -263,40 +298,42 @@ export function writePersonFlagSnapshotFile(flags, options = {}) {
|
|
|
263
298
|
/** Read only a fresh, correctly scoped person snapshot. Every invalid state is a cache miss. */
|
|
264
299
|
export function readPersonFlagSnapshotFile(options = {}) {
|
|
265
300
|
const env = options.env ?? process.env;
|
|
266
|
-
|
|
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`).
|
|
267
303
|
const fallback = fallbackPersonSnapshotPath(false);
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (Object.keys(value).sort().join(",") !== "fetched_at,flags,scope" ||
|
|
284
|
-
value.scope !== "person" ||
|
|
285
|
-
typeof value.fetched_at !== "string" ||
|
|
286
|
-
!value.flags || typeof value.flags !== "object" || Array.isArray(value.flags))
|
|
287
|
-
continue;
|
|
288
|
-
const fetchedAt = Date.parse(value.fetched_at);
|
|
289
|
-
const age = (options.now ?? Date.now()) - fetchedAt;
|
|
290
|
-
if (!Number.isFinite(fetchedAt) || age < 0 || age > (options.maxAgeMs ?? FLAG_SNAPSHOT_MAX_AGE_MS))
|
|
291
|
-
continue;
|
|
292
|
-
const flags = booleanFlagsOf(value.flags);
|
|
293
|
-
if (!flags)
|
|
294
|
-
continue;
|
|
295
|
-
if (file === fallback && fallback)
|
|
296
|
-
fallbackCacheUsed = true;
|
|
297
|
-
return { scope: "person", fetched_at: value.fetched_at, flags: freshAnywhereRuntimeFlags(flags, fetchedAt, options.now) };
|
|
304
|
+
const primary = parsePersonSnapshotFile(personFlagSnapshotPath(env), options);
|
|
305
|
+
const fallbackSnapshot = fallback ? parsePersonSnapshotFile(fallback, options) : null;
|
|
306
|
+
if (fallbackSnapshot && (!primary || fallbackSnapshot.fetchedAt > primary.fetchedAt)) {
|
|
307
|
+
fallbackCacheUsed = true;
|
|
308
|
+
return fallbackSnapshot.snapshot;
|
|
309
|
+
}
|
|
310
|
+
return primary?.snapshot ?? null;
|
|
311
|
+
}
|
|
312
|
+
function parsePersonSnapshotFile(file, options) {
|
|
313
|
+
let parsed;
|
|
314
|
+
try {
|
|
315
|
+
parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
return null;
|
|
298
319
|
}
|
|
299
|
-
|
|
320
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
321
|
+
return null;
|
|
322
|
+
const value = parsed;
|
|
323
|
+
if (Object.keys(value).sort().join(",") !== "fetched_at,flags,scope" ||
|
|
324
|
+
value.scope !== "person" ||
|
|
325
|
+
typeof value.fetched_at !== "string" ||
|
|
326
|
+
!value.flags || typeof value.flags !== "object" || Array.isArray(value.flags))
|
|
327
|
+
return null;
|
|
328
|
+
const fetchedAt = parseSnapshotTime(value.fetched_at);
|
|
329
|
+
const age = (options.now ?? Date.now()) - fetchedAt;
|
|
330
|
+
if (!Number.isFinite(fetchedAt) || age < 0 || age > (options.maxAgeMs ?? FLAG_SNAPSHOT_MAX_AGE_MS))
|
|
331
|
+
return null;
|
|
332
|
+
const flags = booleanFlagsOf(value.flags);
|
|
333
|
+
return {
|
|
334
|
+
snapshot: { scope: "person", fetched_at: value.fetched_at, flags: freshAnywhereRuntimeFlags(flags, fetchedAt, options.now) },
|
|
335
|
+
fetchedAt,
|
|
336
|
+
};
|
|
300
337
|
}
|
|
301
338
|
/** Write just the validated flag decisions and company scope, never auth data. */
|
|
302
339
|
export function writeFlagSnapshotFile(companyUid, flags, options = {}) {
|
|
@@ -310,9 +347,44 @@ export function writeFlagSnapshotFile(companyUid, flags, options = {}) {
|
|
|
310
347
|
fetched_at: options.fetchedAt ?? new Date().toISOString(),
|
|
311
348
|
flags: normalizedFlags,
|
|
312
349
|
};
|
|
313
|
-
if (!Number.isFinite(
|
|
350
|
+
if (!Number.isFinite(parseSnapshotTime(snapshot.fetched_at))) {
|
|
314
351
|
throw new Error("Cannot persist a flag snapshot with an invalid fetched_at timestamp");
|
|
315
352
|
}
|
|
353
|
+
// A stale snapshot that said reporting is required is about to be replaced:
|
|
354
|
+
// keep its stale stretch for Work Mesh, which no daemon flush may have seen
|
|
355
|
+
// (review of #3469, INFO-A). The primary file is looked at before every
|
|
356
|
+
// write. When the write goes to the fallback store (this process already
|
|
357
|
+
// writes there, or the primary cannot be written), the fallback's snapshot
|
|
358
|
+
// is looked at too and the newer of the two counts, as the reader picks it
|
|
359
|
+
// (round 3, INFO-3). A write to the primary never looks at the fallback
|
|
360
|
+
// location. Never stops the write.
|
|
361
|
+
const replacedAt = Date.now();
|
|
362
|
+
let primaryPrevious = null;
|
|
363
|
+
try {
|
|
364
|
+
primaryPrevious = parseSnapshotFile(companyUid, file, { maxAgeMs: Number.POSITIVE_INFINITY });
|
|
365
|
+
}
|
|
366
|
+
catch { /* nothing to keep */ }
|
|
367
|
+
let noted = null;
|
|
368
|
+
const noteReplaced = (previous) => {
|
|
369
|
+
if (!previous || (noted && parseSnapshotTime(previous.fetched_at) <= parseSnapshotTime(noted.fetched_at)))
|
|
370
|
+
return;
|
|
371
|
+
noted = previous;
|
|
372
|
+
try {
|
|
373
|
+
noteReplacedCompanySnapshot(companyUid, { fetchedAtMs: parseSnapshotTime(previous.fetched_at), flags: previous.flags }, env, FLAG_SNAPSHOT_MAX_AGE_MS, replacedAt);
|
|
374
|
+
}
|
|
375
|
+
catch { /* the snapshot is written whatever happens here */ }
|
|
376
|
+
};
|
|
377
|
+
const noteReplacedFallback = (fallbackFile) => {
|
|
378
|
+
let fallbackPrevious = null;
|
|
379
|
+
try {
|
|
380
|
+
fallbackPrevious = parseSnapshotFile(companyUid, fallbackFile, { maxAgeMs: Number.POSITIVE_INFINITY });
|
|
381
|
+
}
|
|
382
|
+
catch { /* nothing to keep */ }
|
|
383
|
+
const newer = fallbackPrevious &&
|
|
384
|
+
(!primaryPrevious || parseSnapshotTime(fallbackPrevious.fetched_at) > parseSnapshotTime(primaryPrevious.fetched_at))
|
|
385
|
+
? fallbackPrevious : primaryPrevious;
|
|
386
|
+
noteReplaced(newer);
|
|
387
|
+
};
|
|
316
388
|
const cacheRootKind = env.XDG_CACHE_HOME?.trim() ? "xdg" : "home";
|
|
317
389
|
const writeFallback = (originalError) => {
|
|
318
390
|
const fallbackFile = fallbackSnapshotPath(companyUid, true, env);
|
|
@@ -325,6 +397,7 @@ export function writeFlagSnapshotFile(companyUid, flags, options = {}) {
|
|
|
325
397
|
markFallbackFailed(error);
|
|
326
398
|
throw error;
|
|
327
399
|
}
|
|
400
|
+
noteReplacedFallback(fallbackFile);
|
|
328
401
|
try {
|
|
329
402
|
const written = writeSnapshotAt(fallbackFile, snapshot, cacheRootKind);
|
|
330
403
|
fallbackCacheUsed = true;
|
|
@@ -341,6 +414,7 @@ export function writeFlagSnapshotFile(companyUid, flags, options = {}) {
|
|
|
341
414
|
};
|
|
342
415
|
if (fallbackCacheUsed)
|
|
343
416
|
return writeFallback();
|
|
417
|
+
noteReplaced(primaryPrevious);
|
|
344
418
|
try {
|
|
345
419
|
return writeSnapshotAt(file, snapshot, cacheRootKind);
|
|
346
420
|
}
|
|
@@ -366,14 +440,12 @@ function parseSnapshotFile(companyUid, file, options) {
|
|
|
366
440
|
typeof value.fetched_at !== "string" ||
|
|
367
441
|
!value.flags || typeof value.flags !== "object" || Array.isArray(value.flags))
|
|
368
442
|
return null;
|
|
369
|
-
const fetchedAt =
|
|
443
|
+
const fetchedAt = parseSnapshotTime(value.fetched_at);
|
|
370
444
|
const age = (options.now ?? Date.now()) - fetchedAt;
|
|
371
445
|
if (!Number.isFinite(fetchedAt) || age < 0 || age > (options.maxAgeMs ?? FLAG_SNAPSHOT_MAX_AGE_MS)) {
|
|
372
446
|
return null;
|
|
373
447
|
}
|
|
374
448
|
const flags = booleanFlagsOf(value.flags);
|
|
375
|
-
if (!flags)
|
|
376
|
-
return null;
|
|
377
449
|
return {
|
|
378
450
|
company_uid: companyUid,
|
|
379
451
|
fetched_at: value.fetched_at,
|
|
@@ -386,16 +458,14 @@ export function readFlagSnapshotFile(companyUid, options = {}) {
|
|
|
386
458
|
if (!file)
|
|
387
459
|
return null;
|
|
388
460
|
const primary = parseSnapshotFile(companyUid, file, options);
|
|
389
|
-
const uid = typeof process.getuid === "function" ? process.getuid() : undefined;
|
|
390
|
-
if (primary && !fallbackCacheUsed && uid !== undefined)
|
|
391
|
-
return primary;
|
|
392
461
|
const fallback = fallbackSnapshotPath(companyUid, false, options.env);
|
|
393
462
|
const fallbackSnapshot = fallback ? parseSnapshotFile(companyUid, fallback, options) : null;
|
|
394
|
-
//
|
|
395
|
-
//
|
|
396
|
-
//
|
|
463
|
+
// Compare both valid stores on every platform, as hq-hook does
|
|
464
|
+
// (flags.rs `newest_snapshot`): a newer permission-fallback write, from a
|
|
465
|
+
// denied rename or a cache folder this process could not write, is not
|
|
466
|
+
// masked by an older primary. Equal timestamps keep the primary.
|
|
397
467
|
if (fallbackSnapshot
|
|
398
|
-
&& (!primary ||
|
|
468
|
+
&& (!primary || parseSnapshotTime(fallbackSnapshot.fetched_at) > parseSnapshotTime(primary.fetched_at))) {
|
|
399
469
|
fallbackCacheUsed = true;
|
|
400
470
|
return fallbackSnapshot;
|
|
401
471
|
}
|
|
@@ -43,10 +43,58 @@ export interface CanaryExpectation {
|
|
|
43
43
|
}
|
|
44
44
|
/** Why `record` does not let `host` switch, or null when it does. */
|
|
45
45
|
export declare function canaryRefusal(record: CanaryRecord | null, expected: CanaryExpectation): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* The release canary file (flip rollout Phase 0): the passing standard
|
|
48
|
+
* canary runs we made for the hq-hook engines this CLI release ships,
|
|
49
|
+
* written by `scripts/release-canary.mjs` from our canary machines' records
|
|
50
|
+
* and published in the package. A user's machine has no canary of its own,
|
|
51
|
+
* so the gate also accepts a shipped run for the exact engine version (which
|
|
52
|
+
* differs per platform, since the build target is part of it) and this
|
|
53
|
+
* root's gate hash. A shipped run does not age out on the user's machine; its
|
|
54
|
+
* freshness is checked when the release is published. Each host stands alone: a release may ship a passing Claude Code run
|
|
55
|
+
* and none for Codex. Publishing refuses a release without a current passing
|
|
56
|
+
* file (`scripts/release-canary.mjs --check`); a release may also ship none.
|
|
57
|
+
*/
|
|
58
|
+
export declare const RELEASE_CANARY_FILE: string;
|
|
59
|
+
/** Schema of [`RELEASE_CANARY_FILE`]. */
|
|
60
|
+
export declare const RELEASE_CANARY_SCHEMA = "hq.host-canary-release.v1";
|
|
61
|
+
/** One shipped standard canary run for a host. */
|
|
62
|
+
export interface ReleaseCanaryRun {
|
|
63
|
+
passed: boolean;
|
|
64
|
+
at: string;
|
|
65
|
+
/** The hq-hook version the run registered (one platform's build). */
|
|
66
|
+
engineVersion: string;
|
|
67
|
+
gateSha256: string | null;
|
|
68
|
+
}
|
|
69
|
+
export interface ReleaseCanary {
|
|
70
|
+
schema: typeof RELEASE_CANARY_SCHEMA;
|
|
71
|
+
/** The CLI release the file was made for. */
|
|
72
|
+
cliVersion: string;
|
|
73
|
+
hosts: Partial<Record<CanaryHost, ReleaseCanaryRun[]>>;
|
|
74
|
+
}
|
|
75
|
+
/** The release canary file inside this CLI's own package. */
|
|
76
|
+
export declare function defaultReleaseCanaryPath(): string;
|
|
77
|
+
/**
|
|
78
|
+
* The release canary at `file`; null when there is none. Throws when it
|
|
79
|
+
* cannot be read, is not one, or could have been written by another user
|
|
80
|
+
* (group- or other-writable, the standard the engine link uses): a file
|
|
81
|
+
* anyone can write is not evidence from our canary.
|
|
82
|
+
*/
|
|
83
|
+
export declare function readReleaseCanary(file: string, platform?: NodeJS.Platform): ReleaseCanary | null;
|
|
84
|
+
/**
|
|
85
|
+
* Why the shipped `release` does not let `host` switch, or null when it does.
|
|
86
|
+
* A shipped run counts under the local record's rules ([`canaryRefusal`]):
|
|
87
|
+
* Windows never, the exact engine version, this root's gate hash, not dated
|
|
88
|
+
* in the future; it has no age limit. A shipped run for this host, engine and
|
|
89
|
+
* gate that did not pass refuses, whatever else the file holds.
|
|
90
|
+
*/
|
|
91
|
+
export declare function releaseCanaryRefusal(release: ReleaseCanary | null, expected: CanaryExpectation): string | null;
|
|
46
92
|
export interface CanaryGateOptions extends Omit<CanaryExpectation, 'gateSha256'> {
|
|
47
93
|
home: string;
|
|
48
94
|
root: string;
|
|
49
95
|
env?: NodeJS.ProcessEnv;
|
|
96
|
+
/** The release canary file; defaults to the one in this CLI's package. */
|
|
97
|
+
releaseCanaryPath?: string;
|
|
50
98
|
}
|
|
51
99
|
export interface CanaryGateResult {
|
|
52
100
|
allowed: boolean;
|
|
@@ -54,11 +102,17 @@ export interface CanaryGateResult {
|
|
|
54
102
|
reason: string | null;
|
|
55
103
|
/** True when the override let a refused switch go on. */
|
|
56
104
|
skipped: boolean;
|
|
105
|
+
/** Which canary allowed the switch: this machine's record or the one the release shipped. */
|
|
106
|
+
source?: 'local' | 'release';
|
|
57
107
|
}
|
|
58
108
|
/**
|
|
59
|
-
* The gate for one host and HQ root
|
|
60
|
-
*
|
|
61
|
-
*
|
|
109
|
+
* The gate for one host and HQ root. Windows is refused before anything is
|
|
110
|
+
* read. A local run for this exact engine build and root gate decides alone:
|
|
111
|
+
* allowed when it is a current pass, refused when it failed (a machine that
|
|
112
|
+
* ran the canary and failed stays on the old core). Otherwise the release's
|
|
113
|
+
* shipped canary decides ([`releaseCanaryRefusal`]). The override lets a
|
|
114
|
+
* refused switch go on (`skipped`, with `reason` saying what was bypassed).
|
|
115
|
+
* A record or shipped file that cannot be read refuses.
|
|
62
116
|
*/
|
|
63
117
|
export declare function checkHostCanary(options: CanaryGateOptions): CanaryGateResult;
|
|
64
118
|
//# sourceMappingURL=canary-gate.d.ts.map
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
import { createHash } from 'node:crypto';
|
|
32
32
|
import * as fs from 'node:fs';
|
|
33
33
|
import * as path from 'node:path';
|
|
34
|
+
import { fileURLToPath } from 'node:url';
|
|
34
35
|
/** The canary result record, under the home folder. */
|
|
35
36
|
export const HOST_CANARY_RECORD = path.join('.hq', 'state', 'host-canary.json');
|
|
36
37
|
/** Schema of [`HOST_CANARY_RECORD`]. */
|
|
@@ -127,20 +128,151 @@ function short(hash) {
|
|
|
127
128
|
return typeof hash === 'string' ? hash.slice(0, 12) : 'none';
|
|
128
129
|
}
|
|
129
130
|
/**
|
|
130
|
-
* The
|
|
131
|
-
*
|
|
132
|
-
*
|
|
131
|
+
* The release canary file (flip rollout Phase 0): the passing standard
|
|
132
|
+
* canary runs we made for the hq-hook engines this CLI release ships,
|
|
133
|
+
* written by `scripts/release-canary.mjs` from our canary machines' records
|
|
134
|
+
* and published in the package. A user's machine has no canary of its own,
|
|
135
|
+
* so the gate also accepts a shipped run for the exact engine version (which
|
|
136
|
+
* differs per platform, since the build target is part of it) and this
|
|
137
|
+
* root's gate hash. A shipped run does not age out on the user's machine; its
|
|
138
|
+
* freshness is checked when the release is published. Each host stands alone: a release may ship a passing Claude Code run
|
|
139
|
+
* and none for Codex. Publishing refuses a release without a current passing
|
|
140
|
+
* file (`scripts/release-canary.mjs --check`); a release may also ship none.
|
|
141
|
+
*/
|
|
142
|
+
export const RELEASE_CANARY_FILE = path.join('contracts', 'host-canary-release.json');
|
|
143
|
+
/** Schema of [`RELEASE_CANARY_FILE`]. */
|
|
144
|
+
export const RELEASE_CANARY_SCHEMA = 'hq.host-canary-release.v1';
|
|
145
|
+
/** The release canary file inside this CLI's own package. */
|
|
146
|
+
export function defaultReleaseCanaryPath() {
|
|
147
|
+
// src/lib/hook-engine and dist/lib/hook-engine both sit three levels below the package root.
|
|
148
|
+
return path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..', RELEASE_CANARY_FILE);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The release canary at `file`; null when there is none. Throws when it
|
|
152
|
+
* cannot be read, is not one, or could have been written by another user
|
|
153
|
+
* (group- or other-writable, the standard the engine link uses): a file
|
|
154
|
+
* anyone can write is not evidence from our canary.
|
|
155
|
+
*/
|
|
156
|
+
export function readReleaseCanary(file, platform = process.platform) {
|
|
157
|
+
let text;
|
|
158
|
+
try {
|
|
159
|
+
if (platform !== 'win32' && (fs.statSync(file).mode & 0o022) !== 0) {
|
|
160
|
+
throw new Error('the shipped host canary is writable by other users');
|
|
161
|
+
}
|
|
162
|
+
text = fs.readFileSync(file, 'utf8');
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
if (error.code === 'ENOENT')
|
|
166
|
+
return null;
|
|
167
|
+
if (!error.code)
|
|
168
|
+
throw error;
|
|
169
|
+
throw new Error(`the shipped host canary cannot be read (${error.code})`);
|
|
170
|
+
}
|
|
171
|
+
let doc;
|
|
172
|
+
try {
|
|
173
|
+
doc = JSON.parse(text);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
throw new Error('the shipped host canary is not JSON');
|
|
177
|
+
}
|
|
178
|
+
const release = doc;
|
|
179
|
+
if (!release || release.schema !== RELEASE_CANARY_SCHEMA || !release.hosts || typeof release.hosts !== 'object' || Array.isArray(release.hosts)) {
|
|
180
|
+
throw new Error(`the shipped host canary is not a ${RELEASE_CANARY_SCHEMA} file`);
|
|
181
|
+
}
|
|
182
|
+
return release;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Why the shipped `release` does not let `host` switch, or null when it does.
|
|
186
|
+
* A shipped run counts under the local record's rules ([`canaryRefusal`]):
|
|
187
|
+
* Windows never, the exact engine version, this root's gate hash, not dated
|
|
188
|
+
* in the future; it has no age limit. A shipped run for this host, engine and
|
|
189
|
+
* gate that did not pass refuses, whatever else the file holds.
|
|
190
|
+
*/
|
|
191
|
+
export function releaseCanaryRefusal(release, expected) {
|
|
192
|
+
const platform = expected.platform ?? process.platform;
|
|
193
|
+
if (platform === 'win32')
|
|
194
|
+
return 'Windows host canaries are not supported yet';
|
|
195
|
+
if (!CANARY_HOSTS.includes(expected.host))
|
|
196
|
+
return `${expected.host} is not a host the canary runs`;
|
|
197
|
+
if (!release)
|
|
198
|
+
return 'no host canary result shipped with this release';
|
|
199
|
+
const listed = release.hosts[expected.host];
|
|
200
|
+
const runs = Array.isArray(listed) ? listed.filter((run) => run && typeof run === 'object') : [];
|
|
201
|
+
if (runs.length === 0)
|
|
202
|
+
return `no shipped host canary result for ${expected.host}`;
|
|
203
|
+
const same = runs.filter((run) => run.engineVersion === expected.engineVersion && run.gateSha256 === expected.gateSha256);
|
|
204
|
+
if (same.some((run) => run.passed !== true))
|
|
205
|
+
return `a shipped ${expected.host} canary for this hq-hook build and hq-core gate failed`;
|
|
206
|
+
let first = null;
|
|
207
|
+
for (const run of [...same, ...runs.filter((run) => !same.includes(run))]) {
|
|
208
|
+
// Owner decision 2026-11-22 ("No expiry for shipped"): a shipped run is
|
|
209
|
+
// bound to one exact build, so it does not age out on the user's machine.
|
|
210
|
+
// Freshness is checked when the release is published; a run dated in the
|
|
211
|
+
// future is still refused.
|
|
212
|
+
const refusal = canaryRefusal({ schema: CANARY_RECORD_SCHEMA, hosts: { [expected.host]: run } }, { ...expected, maxAgeMs: Number.POSITIVE_INFINITY });
|
|
213
|
+
if (refusal === null)
|
|
214
|
+
return null;
|
|
215
|
+
first ??= refusal.replace(`the last ${expected.host} canary`, `the shipped ${expected.host} canary`);
|
|
216
|
+
}
|
|
217
|
+
return first ?? `no shipped host canary result for ${expected.host}`;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* True when the local record's run for `host` is evidence about this exact
|
|
221
|
+
* engine build and this root's gate. Such a run decides the gate on its own,
|
|
222
|
+
* pass or fail, over anything the release shipped: it was made on this
|
|
223
|
+
* machine. A local run for another build or gate is stale and decides nothing.
|
|
224
|
+
*/
|
|
225
|
+
function localRunIsForThisBuild(record, host, engineVersion, gateSha256) {
|
|
226
|
+
const run = record?.hosts[host];
|
|
227
|
+
return !!run && typeof run === 'object' && run.engineVersion === engineVersion && run.gateSha256 === gateSha256;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The gate for one host and HQ root. Windows is refused before anything is
|
|
231
|
+
* read. A local run for this exact engine build and root gate decides alone:
|
|
232
|
+
* allowed when it is a current pass, refused when it failed (a machine that
|
|
233
|
+
* ran the canary and failed stays on the old core). Otherwise the release's
|
|
234
|
+
* shipped canary decides ([`releaseCanaryRefusal`]). The override lets a
|
|
235
|
+
* refused switch go on (`skipped`, with `reason` saying what was bypassed).
|
|
236
|
+
* A record or shipped file that cannot be read refuses.
|
|
133
237
|
*/
|
|
134
238
|
export function checkHostCanary(options) {
|
|
239
|
+
const platform = options.platform ?? process.platform;
|
|
135
240
|
let reason;
|
|
241
|
+
let gateSha256 = null;
|
|
242
|
+
let record = null;
|
|
136
243
|
try {
|
|
137
|
-
|
|
244
|
+
// Windows is refused before any file is read, so the reason never depends on them.
|
|
245
|
+
if (platform === 'win32')
|
|
246
|
+
throw new Error('Windows host canaries are not supported yet');
|
|
247
|
+
gateSha256 = gateScriptSha256(options.root);
|
|
248
|
+
let recordError = null;
|
|
249
|
+
try {
|
|
250
|
+
record = readCanaryRecord(options.home);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
recordError = error.message;
|
|
254
|
+
}
|
|
255
|
+
reason = recordError ?? canaryRefusal(record, { ...options, gateSha256 });
|
|
256
|
+
if (!reason)
|
|
257
|
+
return { allowed: true, reason: null, skipped: false, source: 'local' };
|
|
258
|
+
const decidedLocally = recordError !== null ||
|
|
259
|
+
(localRunIsForThisBuild(record, options.host, options.engineVersion, gateSha256) && record?.hosts[options.host]?.passed !== true);
|
|
260
|
+
if (CANARY_HOSTS.includes(options.host) && !decidedLocally) {
|
|
261
|
+
let shipped;
|
|
262
|
+
try {
|
|
263
|
+
shipped = releaseCanaryRefusal(readReleaseCanary(options.releaseCanaryPath ?? defaultReleaseCanaryPath(), platform), { ...options, gateSha256 });
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
shipped = error.message;
|
|
267
|
+
}
|
|
268
|
+
if (!shipped)
|
|
269
|
+
return { allowed: true, reason: null, skipped: false, source: 'release' };
|
|
270
|
+
reason = `${reason}; ${shipped}`;
|
|
271
|
+
}
|
|
138
272
|
}
|
|
139
273
|
catch (error) {
|
|
140
274
|
reason = error.message;
|
|
141
275
|
}
|
|
142
|
-
if (!reason)
|
|
143
|
-
return { allowed: true, reason: null, skipped: false };
|
|
144
276
|
if (canaryGateSkipped(options.env))
|
|
145
277
|
return { allowed: true, reason, skipped: true };
|
|
146
278
|
return { allowed: false, reason, skipped: false };
|
|
@@ -244,23 +244,92 @@ export declare function grokStopObserveHold(root: string, event: string): string
|
|
|
244
244
|
* for, so a missing file is not held; every hq-core release ships both.
|
|
245
245
|
*/
|
|
246
246
|
export declare const GROK_PRE_TOOL_USE_ADAPTER_PINS: readonly PinnedFile[];
|
|
247
|
-
/**
|
|
248
|
-
* The merged-write-guard-shadow wrapper and its .cjs the native Grok member models
|
|
249
|
-
* (crates/hq-hook/src/merged_write_guard.rs `SCRIPT_SHA256` 63ddff4a and `CJS_SHA256` 225e5c89; the
|
|
250
|
-
* released 742870a2 and 6f65f2b9, which pretool_merged_write_guard.rs models by the wrapper's
|
|
251
|
-
* sha256). A root without them runs no shadow row, so a missing file is not held.
|
|
252
|
-
*/
|
|
253
|
-
export declare const GROK_SHADOW_GUARD_PINS: readonly PinnedFile[];
|
|
254
247
|
/**
|
|
255
248
|
* Why Grok PreToolUse must stay on the shell adapter in `root`: the adapter or its library is not the
|
|
256
249
|
* pair the native work is modelled on, or (when `shadow`, the registry lists the claimed
|
|
257
|
-
* merged-write-guard-shadow row) the
|
|
258
|
-
*
|
|
259
|
-
* native side would answer with the v16.0.50 model, so the hold is the only guard
|
|
260
|
-
*
|
|
261
|
-
*
|
|
250
|
+
* merged-write-guard-shadow row) the shadow companions are not a set the native member accepts
|
|
251
|
+
* (`mergedWriteGuardHold`). For the adapter there is no run-time refusal to mirror: on another
|
|
252
|
+
* adapter the native side would answer with the v16.0.50 model, so the hold is the only guard, and a
|
|
253
|
+
* missing adapter file is not held. The merge-hold shim is not pinned: the claimed
|
|
254
|
+
* merge-gates-ready member reads hold records, never the shim.
|
|
262
255
|
*/
|
|
263
256
|
export declare function grokPreToolUseHold(root: string, shadow: boolean): string | null;
|
|
257
|
+
/**
|
|
258
|
+
* The dispatcher files the native PreToolUse master model reproduces, in its check order:
|
|
259
|
+
* crates/hq-hook/src/pre_tool_use_master.rs `DISPATCHER_PINS`. master-hook.sh is v16.0.48 (1a2439ae),
|
|
260
|
+
* v16.0.50 (774bca73) or v16.0.49 (d5049d5f); every other file is one revision.
|
|
261
|
+
*/
|
|
262
|
+
export declare const PRE_TOOL_USE_DISPATCHER_PINS: readonly PinnedFile[];
|
|
263
|
+
/** The Codex adapter the model reproduces on Codex only (pre_tool_use_master.rs `CODEX_ADAPTER_PIN`). */
|
|
264
|
+
export declare const PRE_TOOL_USE_CODEX_ADAPTER_PIN: PinnedFile;
|
|
265
|
+
/**
|
|
266
|
+
* The claimed vault-write guard's script and the companions it reads (crates/hq-hook/src/ports.rs
|
|
267
|
+
* `HOOK_SCRIPT_SHA256` and `HOOK_COMPANION_SHA256` for enforce-vault-write-access). Its arithmetic
|
|
268
|
+
* library is left out, as in `CLAIMED_MEMBER_IGNORES`: the claimed member does not read it. The
|
|
269
|
+
* credential guard holds that file.
|
|
270
|
+
*/
|
|
271
|
+
export declare const PRE_TOOL_USE_VAULT_GUARD_PINS: readonly PinnedFile[];
|
|
272
|
+
/**
|
|
273
|
+
* The credential guard's script revisions, each with the arithmetic library its port follows
|
|
274
|
+
* (ports.rs `HOOK_SCRIPT_SHA256`, `HOOK_COMPANION_SHA256` and `COMPANION_SCRIPT_BINDINGS`): the
|
|
275
|
+
* 16.0.48 script 6512581d and its 16.0.51-beta.44 successor 5064061f only with e90d160f, every
|
|
276
|
+
* other revision only with 0566180c.
|
|
277
|
+
*/
|
|
278
|
+
export declare const PRE_TOOL_USE_CREDENTIAL_GUARD_GENERATIONS: ReadonlyArray<readonly [string, string]>;
|
|
279
|
+
/**
|
|
280
|
+
* The native policy-frontmatter check's evaluator scripts, in the order it reads them
|
|
281
|
+
* (crates/hq-hook/src/policy_frontmatter.rs `EVAL_TRIGGER_SHA256`, `FORWARDER_LIB_SHA256`,
|
|
282
|
+
* `FLOOR_LIB_SHA256`). Each is read only once the one before it is on its pin; a missing file
|
|
283
|
+
* gives the same evaluator-unavailable answer bash gave (or skips the floor check), so it is not
|
|
284
|
+
* held.
|
|
285
|
+
*/
|
|
286
|
+
export declare const PRE_TOOL_USE_FRONTMATTER_EVALUATOR_PINS: readonly PinnedFile[];
|
|
287
|
+
/** The native image rule's script (ports.rs `HOOK_SCRIPT_SHA256` image-context-guard) and the hook-lib.sh revisions it accepts. */
|
|
288
|
+
export declare const PRE_TOOL_USE_IMAGE_GUARD_PINS: readonly PinnedFile[];
|
|
289
|
+
/**
|
|
290
|
+
* The companion sets of the native merged-write-guard-shadow member
|
|
291
|
+
* (crates/hq-hook/src/merged_write_guard.rs and merged_write_guard/release_1649.rs). The wrapper's
|
|
292
|
+
* sha256 picks the set and never refuses by itself: the v16.0.49 wrapper (742870a2) picks
|
|
293
|
+
* `released`, any other wrapper `legacy`. In a set the helper .cjs, when listed, must match; each
|
|
294
|
+
* guard may be missing (bash exits 127) but not another revision; hook-lib.sh is read only once a
|
|
295
|
+
* guard is on its pin, and must then be the set's library.
|
|
296
|
+
*/
|
|
297
|
+
export declare const MERGED_WRITE_GUARD_SETS: {
|
|
298
|
+
readonly releasedWrapper: "742870a2ada4f9357320f7708fca7363be6d81fde374948b59873c327a7d7206";
|
|
299
|
+
readonly released: {
|
|
300
|
+
readonly helper: "6f65f2b9425612f9b2ec2590dace82585230210dcd69a124a9cdeb0116ea7f30";
|
|
301
|
+
readonly guards: ReadonlyArray<readonly [string, string]>;
|
|
302
|
+
readonly hookLib: "9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f";
|
|
303
|
+
};
|
|
304
|
+
readonly legacy: {
|
|
305
|
+
readonly helper: null;
|
|
306
|
+
readonly guards: ReadonlyArray<readonly [string, string]>;
|
|
307
|
+
readonly hookLib: "df3d8ddc15a0c179227c9ba7f855c040973fcee249673156d08b2e2ff2c850b8";
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Why the native merged-write-guard-shadow member would refuse a call in `root` (reported for
|
|
312
|
+
* `event`), or null: see [`MERGED_WRITE_GUARD_SETS`]. A root with no wrapper runs no row. The member
|
|
313
|
+
* reads these files only for a session whose shadow marker is on, which `hq reindex` cannot know,
|
|
314
|
+
* so the hold assumes it is.
|
|
315
|
+
*/
|
|
316
|
+
export declare function mergedWriteGuardHold(root: string, event: string): string | null;
|
|
317
|
+
/**
|
|
318
|
+
* Why PreToolUse must stay on the old dispatcher in `root` on `host` once `master-hook:PreToolUse`
|
|
319
|
+
* is claimed there (`hooks`: the old dispatcher's PreToolUse hooks there). Each part mirrors a
|
|
320
|
+
* run-time refusal of the native PreToolUse:
|
|
321
|
+
* - the files it reproduces at pinned revisions (pre_tool_use_master.rs `hold_pins`,
|
|
322
|
+
* `changed_files_on`, checked by `guard_refusal_in` before any member): missing, not a regular
|
|
323
|
+
* file or another revision, or the credential guard's script and library not a bound pair. The
|
|
324
|
+
* Codex adapter is read on Codex only;
|
|
325
|
+
* - the policy enforcement gate beside the hook-lib.sh its revision accepts (the injector runs it
|
|
326
|
+
* on Bash calls whatever the registry lists), as for PostToolUse;
|
|
327
|
+
* - the policy-frontmatter evaluator scripts;
|
|
328
|
+
* - the merged-write-guard-shadow companions, where the registry lists that row;
|
|
329
|
+
* - on Claude Code, the image rule's script.
|
|
330
|
+
* Null when the native PreToolUse accepts every file.
|
|
331
|
+
*/
|
|
332
|
+
export declare function preToolUseHold(root: string, host: CoreNextHost, hooks?: readonly string[]): string | null;
|
|
264
333
|
/**
|
|
265
334
|
* The scripts the native first-prompt company bind rebuilds, each at one revision:
|
|
266
335
|
* `MENTION_LIBS` in crates/hq-hook/src/prompt_company_mention/bind.rs, then `SCRIPTS`, `ID_LIBS` and
|
|
@@ -295,7 +364,7 @@ export declare const POLICY_GATE_REVISIONS: ReadonlyArray<{
|
|
|
295
364
|
* a listed revision, or a hook-lib.sh that revision does not accept. As there, a root with no gate
|
|
296
365
|
* script runs no gate (no hold) and a root with no hook-lib.sh is not refused for it.
|
|
297
366
|
*/
|
|
298
|
-
export declare function policyGateHold(root: string): string | null;
|
|
367
|
+
export declare function policyGateHold(root: string, event?: string): string | null;
|
|
299
368
|
/** The (Codex adapter, hook-adapter-core.sh) pairs of crates/hq-hook/src/post_hooks/codex.rs `POST_TOOL_USE_GENERATIONS`. */
|
|
300
369
|
export declare const CODEX_POST_TOOL_USE_GENERATIONS: ReadonlyArray<readonly [string, string]>;
|
|
301
370
|
/** The (Grok adapter, hook-adapter-core.sh) pairs of crates/hq-hook/src/post_hooks/grok.rs `ADAPTER_GENERATIONS`. */
|