@indigoai-us/hq-cli 5.345.268 → 5.345.270
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 +38 -0
- package/README.md +12 -0
- package/contracts/host-canary-release.json +7 -7
- package/dist/lib/daemon/run.js +12 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
- package/dist/lib/hook-engine/reconcile.js +8 -0
- package/dist/lib/hook-engine/stable-heal.d.ts +17 -1
- package/dist/lib/hook-engine/stable-heal.js +42 -5
- package/dist/lib/hook-engine/stable-link.d.ts +70 -0
- package/dist/lib/hook-engine/stable-link.js +300 -0
- package/dist/lib/install/hook-target.js +4 -1
- package/dist/lib/signals/steps/extract.d.ts +27 -7
- package/dist/lib/signals/steps/extract.js +88 -87
- package/dist/utils/hook-engine-crash.d.ts +86 -0
- package/dist/utils/hook-engine-crash.js +325 -0
- package/dist/utils/hook-engine-rollup.d.ts +8 -3
- package/dist/utils/hook-trust.js +7 -1
- package/dist/utils/host-registration.d.ts +12 -35
- package/dist/utils/host-registration.js +47 -177
- package/dist/utils/version-gate.d.ts +42 -4
- package/dist/utils/version-gate.js +84 -25
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [5.345.270] — 2026-11-30
|
|
6
|
+
- Fixed: wired `crates/hq-hook/tests/win_store.rs` into the `hq-hook.yml` Windows "Unit and pipe tests" list (and release archive shards), the PR test list, and the Windows PR scope selector for `src/spool`.
|
|
7
|
+
- Change `hq-hook Windows baseline` schedule from hourly (`47 * * * *`) to once nightly at 07:47 UTC (`47 7 * * *`, outside the 13:00–03:00 UTC train window) and skip scheduled runs when the `main` commit or its git tree already has a green `hq-hook Windows tests (Beaker)` result from a `train/**` run (`covered by train <run id>`, fail-closed on ambiguity or API errors).
|
|
8
|
+
- Run `hq-hook` Windows CI jobs only when the diff can affect Windows or the hook crate (failing closed on unreadable diffs or unknown paths), and let `scripts/ci/batch-train.py` honor the not-relevant verdict for non-Windows batches.
|
|
9
|
+
- Update hook-engine architecture, host-canary, and replay documentation to point at native hq-hook commands instead of removed US-027 shell adapters, and sync scripts/function-manifest.yaml with removed scripts from hq-core-staging main.
|
|
10
|
+
- `hq-hook`: isolate inherited `GIT_CONFIG_GLOBAL` runner overrides in `grok_stop_observe` and `us027_teardown` tests while keeping explicit refusal regression coverage.
|
|
11
|
+
- Avoid quadratic per-piece vector cloning during Bash word expansion in `hq-hook`, keeping long multi-piece quoted words well within the linear scan budget on Windows.
|
|
12
|
+
- Enable the full `injector` parity corpus tests on Windows in `hq-hook` (US-022 c1 preflight).
|
|
13
|
+
- Record canary-accepted hook engines in `~/.hq/bin/hq-hook/accepted-engine.json` on the non-native `core.next` registration paths (`hq reindex`, `hq install --global`, and Grok hook trust) after a real host canary pass so immediate `stable` link roll-back healing works on machines whose registrations use that path. Paths that skip or fail the canary still write no acceptance record.
|
|
14
|
+
- Fixed: `hq signals` extract on no-shell runtimes now accepts structured JSON candidates (`{"candidates":[{"kind","type","body"}]}`) and builds the pinned candidate writer argv on the host, preserving arbitrary quotes, `$`, backticks, and newlines in candidate bodies and dropping only individual invalid candidates instead of failing the whole item.
|
|
15
|
+
- Keep `~/.hq/bin/hq-hook/stable` from moving back to an older hook engine while the newer engine it names still runs; native-only and Windows roots keep using that newer engine after a CLI downgrade. The start-up heal relinks a rolled-back link at once (before the reindex) when the pinned engine was canary-accepted on this machine. An operator rollback to an older engine needs an explicit downgrade option that no command offers yet.
|
|
16
|
+
- `hq reindex` can now move Codex and Grok Build SessionStart and UserPromptSubmit to the native hook core when an HQ has personal, pack or company hooks for those events. The native core runs those hooks as the Codex and Grok adapters did, with the same payload, variables and advisory handling.
|
|
17
|
+
- Changed: the host canary record shipped with the CLI is refreshed for the 5.345.270 release build.
|
|
18
|
+
- The native Stop now accepts the hq-core v16.0.53 `master-hook.sh`. Before, it refused every Stop on a v16.0.53 core. It also writes the environment-id alias entry that this `master-hook.sh` records on every hook event, as the native PreToolUse already did. v16.0.51 and v16.0.52 roots stay on the shell Stop.
|
|
19
|
+
- Reduce native `UserPromptSubmit` hook latency in `hq-hook`: check the daemon `lanes_monitor` state before scanning `workspace/lanes/lanes`, evaluate policy triggers and frequency/retrieval lookups lazily without per-policy regex or heap churn, skip `Held::lock` directory creation on `UserPromptSubmit` for hosts that never hold reminders (Claude Code and Codex) when no held reminder or lock exists on disk, share a per-chain 1 MiB regular-file/symlink read cache for `hook-registry.json` and `hook-gate.sh` (following symlinks like bash `[ -f ]`, while a FIFO `hook-gate.sh` fails closed natively where bash would block), read listed policy files once across skill and brief scans, filter non-policy directory entries before allocating during macOS bulk manifest scans, and accept `hook-lib.sh` `436493e3` (`hq-core` v16.0.52) in `skill_command_script::classify`.
|
|
20
|
+
- Resolve `for`/`select` loop variables strictly inside closed `do ... done` bodies in `mandatory-scope-authorizer` even when the loop follows `&&`/`||` (`evt-2df47d001eec4541`), while keeping post-`done`, cross-company, and computed/glob loop cases refused.
|
|
21
|
+
- Record `mandatory-scope-authorizer` fail-closed refusal on relative operands after `.`/`source` (`evt-d1c0d86c3e1552f9`) in the `US-012` intended-differences ledger with a pinning test.
|
|
22
|
+
- Update Windows GUI no-console probe (`GuiProbe.cs` and `no-console.ps1`) from the removed legacy `hq-hook <Event>` launcher form to `hq-hook run --host claude <Event> --hq-root <root>`, and use `CREATE_NO_WINDOW` instead of `DETACHED_PROCESS` in `spawn_windows` so MSYS2 `bash.exe` starts with a hidden console and never flashes a visible window when running folder hooks.
|
|
23
|
+
- Test: pin original file descriptors in `injector::held` atomic-replace unit tests so Linux filesystems cannot reuse unlinked inodes during multi-rename rearm checks.
|
|
24
|
+
- Fixed: `codex_session_start_parity` and `grok_session_start_bind` now serialize adapter runs across `cargo nextest` worker processes using a shared advisory file lock.
|
|
25
|
+
- Test: avoid 120 redundant `fsyncSync` snapshot rewrites in the one-hour `shared-flag-reads.test.ts` poller test so it stays fast and deterministic under CI disk contention.
|
|
26
|
+
- Fixed: split `smart-ci` fixture replay crash-recovery loop in `intake.test.ts` into per-case parameterized tests so each commit-kill case runs independently within the default Vitest timeout under CI disk contention.
|
|
27
|
+
- Test-only: verify the beta.105 10-second folder-hook cut in `stop_beta105::a_folder_hook_cut_at_the_beta105_ten_second_limit_is_refused` with start/finish marker files instead of host-speed-sensitive wall-clock assertions.
|
|
28
|
+
- Expand an expandable 8.3 short-name `HOME` on Windows in `grok_adapter` so non-credential calls are allowed while credential paths under both short and long spellings stay refused (split from #3921 and #4050).
|
|
29
|
+
|
|
30
|
+
## [5.345.269] — 2026-11-29
|
|
31
|
+
- Shard `.github/workflows/hq-hook.yml` self-hosted Windows (`matrix.beaker`) `Unit and pipe tests` across 6 parallel `hq-windows` runners using a prebuilt `cargo nextest` archive (`windows-build-archive` + `windows-test-shard`), cutting release-tag Windows test wall time while preserving full target parity and all `build` job release duties.
|
|
32
|
+
- Run the hq-hook Windows baseline shard and join jobs on the AWS Windows runners: they no longer ask for the `beaker` label, so they use the same `self-hosted, Windows, X64, hq-windows` label set as the PR and train Windows jobs they are compared with.
|
|
33
|
+
- Fixed: Allow Antigravity's `schedule` timer/cron tool in `hq-hook` PreToolUse with exact argument key validation (`DurationSeconds`, `CronExpression`, `Prompt`, `TimerCondition`, `IsDaemon`, `ExactTiming`, `MaxIterations`) so Antigravity sessions can run polling loops without being refused fail-closed.
|
|
34
|
+
- Read permission-fallback flag snapshot directories via the caller's environment lookup (`TMPDIR` / `LOCALAPPDATA`) so scoped readers and unit tests do not inherit host temporary snapshot files.
|
|
35
|
+
- Fixed: `hq-hook` command rules now scan here-document bodies when a here-document is piped into another command such as `cat <<'EOF' | python3`, matching the shell hook's handling of piped here-documents.
|
|
36
|
+
- Native UserPromptSubmit `/skill` handling now has tests that run every accepted `hook-lib.sh` revision, including the released hq-core 16.0.52 library, against the shell hook. When the native check cannot decide, the refusal now gives the check's reason and the matching remedy (update the HQ CLI, or `/hq-bug`) instead of asking you to start hqd.
|
|
37
|
+
- Internal: Wait up to 10 s for WMI `Win32_ProcessStartTrace` ETW delivery in `crates/hq-hook/tests/windows/GuiProbe.cs` across positive controls and phase completions, and include `SessionId` and non-baseline Toolhelp snapshots in failure diagnostics.
|
|
38
|
+
- The hook engine now records a panic as one fixed-format line in `~/.hq/logs/hook-engine.jsonl` (location, a message class and versions; no payload or argument values), and the daemon sends each new line within minutes as a `hook_engine_crash` event under the existing telemetry consent and `HQ_TELEMETRY=0` opt-out. Hook answers and exit codes are unchanged.
|
|
39
|
+
- The version gate accepts two optional server fields: `blockedVersions`, which forces an update off a withdrawn release, and `targetVersion`, the exact release that update installs. Servers that do not send them behave as before.
|
|
40
|
+
- Changed: the host canary record shipped with the CLI is refreshed for the 5.345.269 release build.
|
|
41
|
+
- Cap concurrent child-hook spawns in `agents_v2_company_folder_hooks` tests and use bash builtins in 1-second timeout fixtures so parallel runs do not contend on macOS process startup.
|
|
42
|
+
|
|
5
43
|
## [5.345.268] — 2026-11-29
|
|
6
44
|
- Isolate `SCCACHE_SERVER_PORT` and local `SCCACHE_DIR` per runner (`beaker` -> port `4226` / `hq-sccache/beaker`, `beaker-2` -> port `4227` / `hq-sccache/beaker-2`) in all Beaker `Configure sccache (Beaker)` workflow steps so concurrent `beaker` and `beaker-2` jobs on the same Windows host do not collide on `127.0.0.1:4226` or share a local cache directory.
|
|
7
45
|
- Speed up hq-hook builds on the Beaker Windows runners: the release-tag Windows job builds in the workspace target folder again instead of a per-runner folder outside the checkout, and the release-tag, train build-archive and train Clippy jobs on Beaker use the machine-local compiler cache instead of the shared S3 cache, which those jobs could only read and which held no Beaker builds.
|
package/README.md
CHANGED
|
@@ -159,6 +159,18 @@ is about to send its fields prints this line once instead, and records it under
|
|
|
159
159
|
HQ sends a usage event when you run a signed-in command (CLI version and a timestamp; when enabled, first-sync guidance shown or followed and the flag key cli.first-sync-next-step; never command names, file contents, or secrets) to improve the CLI. Set HQ_TELEMETRY=0 to turn this off.
|
|
160
160
|
```
|
|
161
161
|
|
|
162
|
+
The `hq daemon` also sends `hook_engine_crash` when the native hook engine
|
|
163
|
+
panics. The engine writes one line per panic to `~/.hq/logs/hook-engine.jsonl`;
|
|
164
|
+
the daemon checks for new lines every five minutes and sends each once, at most
|
|
165
|
+
12 per hour (the number held back rides on the next event as
|
|
166
|
+
`properties.suppressed`). Each event carries `properties.crashId`, `signature`
|
|
167
|
+
(a hash of location and class), `location` (`file:line` in the engine source),
|
|
168
|
+
`messageClass` (a fixed set such as `unwrap-none`), `appVersion`, `engine`,
|
|
169
|
+
`release`, `os` and `arch`. It never carries the panic message, payloads,
|
|
170
|
+
arguments or paths outside the engine source. It is sent only when you have
|
|
171
|
+
opted in to telemetry (agents always collect), and never while `HQ_TELEMETRY=0`
|
|
172
|
+
is set; crashes from those periods are not sent later.
|
|
173
|
+
|
|
162
174
|
Turn telemetry off:
|
|
163
175
|
|
|
164
176
|
```bash
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": "hq.host-canary-release.v1",
|
|
3
|
-
"cliVersion": "5.345.
|
|
3
|
+
"cliVersion": "5.345.270",
|
|
4
4
|
"hosts": {
|
|
5
5
|
"claude": [
|
|
6
6
|
{
|
|
7
7
|
"passed": true,
|
|
8
|
-
"at": "2026-11-
|
|
9
|
-
"engineVersion": "0.3.1+hq.5.345.
|
|
8
|
+
"at": "2026-11-30T02:02:55.216Z",
|
|
9
|
+
"engineVersion": "0.3.1+hq.5.345.270.src.fb37f49ebae3604d89308abc7685e866c6c4e37fa36961d5511730cf3627ca96",
|
|
10
10
|
"gateSha256": "a2879dfe692233f5953bac86672947bbd82f3c5247292f3efcb80f16c3d2c6b1"
|
|
11
11
|
},
|
|
12
12
|
{
|
|
13
13
|
"passed": true,
|
|
14
|
-
"at": "2026-11-
|
|
15
|
-
"engineVersion": "0.3.1+hq.5.345.
|
|
14
|
+
"at": "2026-11-30T02:03:13.811Z",
|
|
15
|
+
"engineVersion": "0.3.1+hq.5.345.270.src.fb37f49ebae3604d89308abc7685e866c6c4e37fa36961d5511730cf3627ca96",
|
|
16
16
|
"gateSha256": "ca58a94859eae0a345c11c8d9c59303eb76350dc1cf223391037d21979c28718"
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
"passed": true,
|
|
20
|
-
"at": "2026-11-
|
|
21
|
-
"engineVersion": "0.3.1+hq.5.345.
|
|
20
|
+
"at": "2026-11-30T02:03:49.977Z",
|
|
21
|
+
"engineVersion": "0.3.1+hq.5.345.270.src.fb37f49ebae3604d89308abc7685e866c6c4e37fa36961d5511730cf3627ca96",
|
|
22
22
|
"gateSha256": "ecdbab7c2e0a1d94eb9c98f15e760390f215bc7115a217ded24b4275322722d2"
|
|
23
23
|
}
|
|
24
24
|
]
|
package/dist/lib/daemon/run.js
CHANGED
|
@@ -48,6 +48,7 @@ import { createDaemonSharedFlagReads, hqdListenerFlagGate } from "./shared-flag-
|
|
|
48
48
|
import { createDaemonKillSwitchMonitors } from "./timed-flag-monitors.js";
|
|
49
49
|
import { MACHINE_CHECKS_INTERVAL_MS, MACHINE_CHECKS_MIN_INTERVAL_MS, MACHINE_CHECKS_RESULT_FILE, readMachineCheckResults, startMachineCheckSchedule, } from "./machine-checks.js";
|
|
50
50
|
import { HOOK_ENGINE_ROLLUP_STATE_FILE, hookEngineRollupLogLine, runHookEngineRollup, } from "../../utils/hook-engine-rollup.js";
|
|
51
|
+
import { HOOK_ENGINE_CRASH_STATE_FILE, runHookEngineCrashUpload, startHookEngineCrashSchedule, } from "../../utils/hook-engine-crash.js";
|
|
51
52
|
import { createLanesReconcileWatcher } from "./lanes-reconcile-watcher.js";
|
|
52
53
|
import { createLanesReconcileStatus, withLanesReconcileUnit } from "./lanes-reconcile-status.js";
|
|
53
54
|
import { findLegacyUnits, legacyMeshUnitsToRetire, legacyOwnerLookup, } from "./legacy.js";
|
|
@@ -1310,6 +1311,16 @@ export async function runDaemon(opts) {
|
|
|
1310
1311
|
log(line.level, line.message);
|
|
1311
1312
|
},
|
|
1312
1313
|
});
|
|
1314
|
+
// hq-hook crash lines go out within minutes, not with the daily rollup
|
|
1315
|
+
// (decision 3.1); same client, consent and HQ_TELEMETRY opt-out.
|
|
1316
|
+
const hookEngineCrashes = startHookEngineCrashSchedule({
|
|
1317
|
+
log,
|
|
1318
|
+
run: () => runHookEngineCrashUpload({
|
|
1319
|
+
home,
|
|
1320
|
+
env,
|
|
1321
|
+
stateFile: path.join(paths.root, HOOK_ENGINE_CRASH_STATE_FILE),
|
|
1322
|
+
}),
|
|
1323
|
+
});
|
|
1313
1324
|
let laneReconcileWatcher = null;
|
|
1314
1325
|
let laneReconcileWatcherRoot = null;
|
|
1315
1326
|
let laneReconcileWatchFailedRoot = null;
|
|
@@ -1425,6 +1436,7 @@ export async function runDaemon(opts) {
|
|
|
1425
1436
|
laneReconcileWatcherRoot = null;
|
|
1426
1437
|
killSwitches.close();
|
|
1427
1438
|
machineChecks.close();
|
|
1439
|
+
hookEngineCrashes.close();
|
|
1428
1440
|
flagSnapshots.close();
|
|
1429
1441
|
mergeSections.close();
|
|
1430
1442
|
stateWriter.close();
|
|
@@ -384,7 +384,8 @@
|
|
|
384
384
|
".claude/hooks/master-hook.sh": [
|
|
385
385
|
"1a2439aee50652c5143ccd18561a0aa84a1e94848d02c1aa1c99157f70023f29",
|
|
386
386
|
"d5049d5fb38d2b33467d493a4a136df8f6d9021c29e722df0d1e6a17d7f452ab",
|
|
387
|
-
"774bca73a2e806b4d9ad96b803525bdf25afd2265d63c9216881aa4ced403f16"
|
|
387
|
+
"774bca73a2e806b4d9ad96b803525bdf25afd2265d63c9216881aa4ced403f16",
|
|
388
|
+
"f9a32c25f5984856a1bb91a7914495577e505c42a8c02831acf8faf049a9a806"
|
|
388
389
|
]
|
|
389
390
|
}
|
|
390
391
|
}
|
|
@@ -186,6 +186,14 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
|
|
|
186
186
|
claudeProjectNext = claudeProjectTarget(rawCoreNext, claudeNext, root, env);
|
|
187
187
|
codexNext = forHost(rawCoreNext, root, 'codex', env);
|
|
188
188
|
antigravityNext = rawCoreNext;
|
|
189
|
+
const acceptedHosts = [];
|
|
190
|
+
if (claudeNext || claudeProjectNext)
|
|
191
|
+
acceptedHosts.push('claude');
|
|
192
|
+
if (codexNext)
|
|
193
|
+
acceptedHosts.push('codex');
|
|
194
|
+
if (acceptedHosts.length > 0) {
|
|
195
|
+
getCoreNextCandidate(rawCoreNext)?.recordAccepted?.(acceptedHosts);
|
|
196
|
+
}
|
|
189
197
|
}
|
|
190
198
|
else if (rawCoreNext) {
|
|
191
199
|
const candidate = getCoreNextCandidate(rawCoreNext);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* After an update, heal the `stable` link core.next registrations name by
|
|
3
|
-
* re-running the gated reconcile
|
|
3
|
+
* re-running the gated reconcile; the heal moves the link directly only to
|
|
4
|
+
* undo a roll-back (below).
|
|
4
5
|
*
|
|
5
6
|
* `npm install -g @indigoai-us/hq-cli` pins the new engine and rewrites the
|
|
6
7
|
* `current` pointer. `stable` keeps naming the previous engine until
|
|
@@ -15,6 +16,19 @@
|
|
|
15
16
|
*
|
|
16
17
|
* The postinstall moves nothing ([`staleStableEngine`] only reports).
|
|
17
18
|
*
|
|
19
|
+
* Two cases do not wait for the reindex, so a code-complete engine never flips
|
|
20
|
+
* back:
|
|
21
|
+
* - Roll-back: `stable` names an older engine than the pinned one, and the
|
|
22
|
+
* pinned engine is recorded in the accepted-engine record
|
|
23
|
+
* ([`isAcceptedHookEngine`]): it already passed the host canary gate on this
|
|
24
|
+
* machine. Something older (an old hq-cli run with the real home) moved the
|
|
25
|
+
* link back below it. The heal relinks to the pinned engine at once, then
|
|
26
|
+
* starts the reindex as usual. A pinned engine with no acceptance record waits
|
|
27
|
+
* for the gated reindex, as after any update.
|
|
28
|
+
* - `stable` names a newer engine than this CLI pins, and its version folder is
|
|
29
|
+
* still there: an older CLI is running. The heal starts nothing, so it cannot
|
|
30
|
+
* move the link back.
|
|
31
|
+
*
|
|
18
32
|
* The roots come from the `--hq-root` arguments in the user-scope hook files,
|
|
19
33
|
* so this starts an unattended `hq reindex` in any folder named there. That is
|
|
20
34
|
* no new boundary: only someone who can already write those files (and so
|
|
@@ -60,6 +74,8 @@ export interface StableHealResult {
|
|
|
60
74
|
roots: string[];
|
|
61
75
|
/** Why no reindex was started, when stale and none was. */
|
|
62
76
|
skipped?: string;
|
|
77
|
+
/** The engine version `stable` was moved back up to before any reindex (a roll-back healed at once). */
|
|
78
|
+
relinked?: string;
|
|
63
79
|
}
|
|
64
80
|
/**
|
|
65
81
|
* The HQ roots to reconcile: each root a user-scope hook file (Claude Code,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* After an update, heal the `stable` link core.next registrations name by
|
|
3
|
-
* re-running the gated reconcile
|
|
3
|
+
* re-running the gated reconcile; the heal moves the link directly only to
|
|
4
|
+
* undo a roll-back (below).
|
|
4
5
|
*
|
|
5
6
|
* `npm install -g @indigoai-us/hq-cli` pins the new engine and rewrites the
|
|
6
7
|
* `current` pointer. `stable` keeps naming the previous engine until
|
|
@@ -15,6 +16,19 @@
|
|
|
15
16
|
*
|
|
16
17
|
* The postinstall moves nothing ([`staleStableEngine`] only reports).
|
|
17
18
|
*
|
|
19
|
+
* Two cases do not wait for the reindex, so a code-complete engine never flips
|
|
20
|
+
* back:
|
|
21
|
+
* - Roll-back: `stable` names an older engine than the pinned one, and the
|
|
22
|
+
* pinned engine is recorded in the accepted-engine record
|
|
23
|
+
* ([`isAcceptedHookEngine`]): it already passed the host canary gate on this
|
|
24
|
+
* machine. Something older (an old hq-cli run with the real home) moved the
|
|
25
|
+
* link back below it. The heal relinks to the pinned engine at once, then
|
|
26
|
+
* starts the reindex as usual. A pinned engine with no acceptance record waits
|
|
27
|
+
* for the gated reindex, as after any update.
|
|
28
|
+
* - `stable` names a newer engine than this CLI pins, and its version folder is
|
|
29
|
+
* still there: an older CLI is running. The heal starts nothing, so it cannot
|
|
30
|
+
* move the link back.
|
|
31
|
+
*
|
|
18
32
|
* The roots come from the `--hq-root` arguments in the user-scope hook files,
|
|
19
33
|
* so this starts an unattended `hq reindex` in any folder named there. That is
|
|
20
34
|
* no new boundary: only someone who can already write those files (and so
|
|
@@ -32,6 +46,7 @@ import * as path from 'node:path';
|
|
|
32
46
|
import { CORE_NEXT_LINK, hqRootArgument, userHookSettingsFile } from './registration-identity.js';
|
|
33
47
|
import { staleStableEngine } from './resolve.js';
|
|
34
48
|
import { resolveDefaultHqRoot } from '../../utils/hq-root-resolver.js';
|
|
49
|
+
import { appendStableHealLog, compareEngineVersions, engineVersionOf, isAcceptedHookEngine, linkStableEngine, stableLinkVersion } from './stable-link.js';
|
|
35
50
|
/** Set in the reindex the heal starts, so that process does not start another. */
|
|
36
51
|
export const STABLE_HEAL_ENV = 'HQ_STABLE_HEAL';
|
|
37
52
|
/**
|
|
@@ -175,16 +190,38 @@ export function healStableEngine(options = {}) {
|
|
|
175
190
|
if (!stale)
|
|
176
191
|
return { stale: null, roots: [] };
|
|
177
192
|
const now = (options.now ?? Date.now)();
|
|
193
|
+
const linked = stableLinkVersion(home);
|
|
194
|
+
const pinnedVersion = engineVersionOf(stale.pinned, home);
|
|
195
|
+
const order = linked && pinnedVersion ? compareEngineVersions(linked, pinnedVersion) : null;
|
|
196
|
+
if (order !== null && order > 0 && stale.resolved !== null) {
|
|
197
|
+
// No log line here: an older CLI reaches this on every command.
|
|
198
|
+
return { stale, roots: [], skipped: 'stable names a newer engine than this CLI pins' };
|
|
199
|
+
}
|
|
200
|
+
let relinked;
|
|
201
|
+
if (order !== null && order < 0 && isAcceptedHookEngine(home, stale.pinned, platform)) {
|
|
202
|
+
// The pinned engine already passed the host canary gate here (commitStable
|
|
203
|
+
// recorded it), so the link was rolled back below an accepted engine:
|
|
204
|
+
// relink now, not after the reindex.
|
|
205
|
+
try {
|
|
206
|
+
linkStableEngine(stale.pinned, home, platform, { now: () => now });
|
|
207
|
+
relinked = pinnedVersion;
|
|
208
|
+
appendStableHealLog(home, `stable rolled back to ${linked}; relinked to the canary-accepted pinned engine ${stale.pinned} before the reindex`, now);
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
appendStableHealLog(home, `stable rolled back to ${linked}; relink to ${stale.pinned} failed: ${error instanceof Error ? error.message : String(error)}`, now);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const extra = relinked ? { relinked } : {};
|
|
178
215
|
const last = readState(home);
|
|
179
216
|
if (last && last.pinned === stale.pinned && typeof last.at === 'number' && now - last.at >= 0 && now - last.at < STABLE_HEAL_RETRY_MS) {
|
|
180
|
-
return { stale, roots: [], skipped: 'a heal for this engine started less than an hour ago' };
|
|
217
|
+
return { stale, roots: [], skipped: 'a heal for this engine started less than an hour ago', ...extra };
|
|
181
218
|
}
|
|
182
219
|
const roots = stableHealRoots(home, env, options.cwd ?? process.cwd(), platform);
|
|
183
220
|
if (!roots.length)
|
|
184
|
-
return { stale, roots: [], skipped: 'no HQ root to reconcile' };
|
|
221
|
+
return { stale, roots: [], skipped: 'no HQ root to reconcile', ...extra };
|
|
185
222
|
const cliEntry = options.cliEntry ?? process.argv[1];
|
|
186
223
|
if (!cliEntry)
|
|
187
|
-
return { stale, roots: [], skipped: 'no CLI entry to run' };
|
|
224
|
+
return { stale, roots: [], skipped: 'no CLI entry to run', ...extra };
|
|
188
225
|
writeState(home, stale.pinned, now);
|
|
189
226
|
const childEnv = { ...env, [STABLE_HEAL_ENV]: '1', HQ_INSTALL_FOLLOWUP: '1' };
|
|
190
227
|
for (const name of GATE_WEAKENING_ENV)
|
|
@@ -209,6 +246,6 @@ export function healStableEngine(options = {}) {
|
|
|
209
246
|
finally {
|
|
210
247
|
fs.closeSync(log);
|
|
211
248
|
}
|
|
212
|
-
return { stale, roots };
|
|
249
|
+
return { stale, roots, ...extra };
|
|
213
250
|
}
|
|
214
251
|
//# sourceMappingURL=stable-heal.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Name of the release-stable link next to the pinned engine versions. */
|
|
2
|
+
export declare const STABLE_LINK_NAME = "stable";
|
|
3
|
+
/** Record of canary-accepted hook engines committed to `stable`, under the home folder. */
|
|
4
|
+
export declare const ACCEPTED_HOOK_ENGINE_RECORD: string;
|
|
5
|
+
/** Schema of [`ACCEPTED_HOOK_ENGINE_RECORD`]. */
|
|
6
|
+
export declare const ACCEPTED_HOOK_ENGINE_SCHEMA = "hq.accepted-hook-engine.v1";
|
|
7
|
+
export type CoreNextHost = 'claude' | 'codex' | 'grok' | 'fleet-local' | 'agents-v2' | 'antigravity';
|
|
8
|
+
/** One canary-accepted engine recorded when `commitStable` moved `stable` to it. */
|
|
9
|
+
export interface AcceptedHookEngineEntry {
|
|
10
|
+
engineVersion: string;
|
|
11
|
+
pinnedEngine: string;
|
|
12
|
+
acceptedAt: string;
|
|
13
|
+
hosts: CoreNextHost[];
|
|
14
|
+
}
|
|
15
|
+
export interface AcceptedHookEngineRecord {
|
|
16
|
+
schema: typeof ACCEPTED_HOOK_ENGINE_SCHEMA;
|
|
17
|
+
engines: Record<string, AcceptedHookEngineEntry>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Read `<home>/.hq/bin/hq-hook/accepted-engine.json`; null when absent,
|
|
21
|
+
* unreadable, invalid, or writable by another user.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readAcceptedHookEngineRecord(home: string, platform?: NodeJS.Platform): AcceptedHookEngineRecord | null;
|
|
24
|
+
/** True when `pinned` resolves to an engine recorded in the accepted-engine record (it passed the host canary gate here). */
|
|
25
|
+
export declare function isAcceptedHookEngine(home: string, pinned: string, platform?: NodeJS.Platform): boolean;
|
|
26
|
+
/** Thrown when `stable` names a newer, runnable engine and the caller did not ask for a downgrade. */
|
|
27
|
+
export declare class StableDowngradeRefused extends Error {
|
|
28
|
+
constructor(message: string);
|
|
29
|
+
}
|
|
30
|
+
export declare function hookEngineDir(home: string): string;
|
|
31
|
+
/** The stable path that stands for a pinned engine path. */
|
|
32
|
+
export declare function stableEnginePath(pinned: string, home: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Semver precedence of two engine version folder names: negative when `a` is
|
|
35
|
+
* older, positive when newer, 0 when equal. Null when either is not a version
|
|
36
|
+
* folder name, so the caller cannot tell which is older.
|
|
37
|
+
*/
|
|
38
|
+
export declare function compareEngineVersions(a: string, b: string): number | null;
|
|
39
|
+
/** The version folder an engine path under `<home>/.hq/bin/hq-hook` sits in; null when it is not under it. */
|
|
40
|
+
export declare function engineVersionOf(pinned: string, home: string): string | null;
|
|
41
|
+
/** The version folder name `stable` names (even when that folder is gone); null when it is not a link. */
|
|
42
|
+
export declare function stableLinkVersion(home: string): string | null;
|
|
43
|
+
/** Append one line to `<home>/.hq/logs/stable-heal.log`; best effort. */
|
|
44
|
+
export declare function appendStableHealLog(home: string, line: string, now?: number): void;
|
|
45
|
+
export interface LinkStableEngineOptions {
|
|
46
|
+
/**
|
|
47
|
+
* The person asked to move `stable` to an older engine (a repair or a
|
|
48
|
+
* downgrade they requested). Only such a command passes true.
|
|
49
|
+
*/
|
|
50
|
+
allowDowngrade?: boolean;
|
|
51
|
+
now?: () => number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Point `<home>/.hq/bin/hq-hook/stable` at the pinned engine's version folder
|
|
55
|
+
* and return the stable engine path. The link is replaced by rename, so a
|
|
56
|
+
* planted file at the temporary name or the link itself is never followed. A
|
|
57
|
+
* `stable` that is a real folder (not a link) is someone else's and is left
|
|
58
|
+
* alone: the call fails and the caller keeps the current registrations.
|
|
59
|
+
*
|
|
60
|
+
* A link that names a newer engine than `pinned`, which is still there and
|
|
61
|
+
* runnable, stays where it is: the call records the refusal in stable-heal.log
|
|
62
|
+
* and throws [`StableDowngradeRefused`], unless the person asked for the
|
|
63
|
+
* downgrade ([`LinkStableEngineOptions.allowDowngrade`]).
|
|
64
|
+
*/
|
|
65
|
+
export declare function linkStableEngine(pinned: string, home: string, platform?: NodeJS.Platform, options?: LinkStableEngineOptions): string;
|
|
66
|
+
/** A real folder or file (not a link) of this user that group and others cannot write. */
|
|
67
|
+
export declare function checkOwnedEntry(entry: string, kind: 'folder' | 'file', platform: NodeJS.Platform): void;
|
|
68
|
+
/** True when the link resolves to `folder` (Windows reports junction targets in its own spelling). */
|
|
69
|
+
export declare function pointsAt(link: string, folder: string): boolean;
|
|
70
|
+
//# sourceMappingURL=stable-link.d.ts.map
|