@indigoai-us/hq-cli 5.345.230 → 5.345.231
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/commands/crm.js +2 -1
- package/dist/commands/packs.js +3 -2
- package/dist/commands/pkg-remove.js +2 -1
- package/dist/commands/report.js +4 -0
- package/dist/lib/daemon/hook-requests-codex-settings.d.ts +26 -0
- package/dist/lib/daemon/hook-requests-codex-settings.js +185 -0
- package/dist/lib/daemon/hook-requests-conduct-link.d.ts +1 -0
- package/dist/lib/daemon/hook-requests-conduct-link.js +21 -4
- package/dist/lib/daemon/hook-requests.d.ts +3 -2
- package/dist/lib/daemon/hook-requests.js +16 -3
- package/dist/lib/flag-registry.d.ts +7 -0
- package/dist/lib/flag-registry.js +20 -0
- package/dist/lib/hook-engine/coverage.d.ts +18 -0
- package/dist/lib/hook-engine/coverage.js +42 -1
- package/dist/lib/lanes/links.js +88 -7
- package/dist/utils/exit-after-worker.d.ts +7 -0
- package/dist/utils/exit-after-worker.js +15 -0
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [5.345.231] — 2026-11-18
|
|
6
|
+
- The daemon now runs a new `codex-settings` request note: the `.claude/settings.json` PostToolUse commands of one Codex tool call, started one by one with the payload on stdin and the variables the released Codex adapter gave its hooks (`HQ_CHECKPOINT_RUNTIME=codex`, `HQ_HARNESS=codex`, `HQ_WORK_MESH_HARNESS=codex`, `BASH_ENV=/dev/null`, `HQ_ROOT` and `CLAUDE_PROJECT_DIR` set to the root, `HQAD_EVENT_SESSION_ID`; no `HQ_WORK_MESH_DISABLED`). A command the root's settings no longer list is refused. No hook leaves this note yet, and `codex-adapter:PostToolUse` stays unclaimed.
|
|
7
|
+
- `hq-hook run --host codex PreToolUse` now refuses a Codex `apply_patch`, `Edit` or `Write` into `companies/_template/` natively, with the released Codex adapter's own message (`block_template_edit_if_needed`). It also refuses the readings other machines' adapters refused (a CR in the tool name, other case, backslashes, symlinks) and a path it cannot resolve. `codex-adapter:PreToolUse` stays unclaimed. An edit path holding a NUL byte is refused, a Git Bash `/c/...` or cygwin `/cygdrive/c/...` path is read as `C:/...`, and with no `--hq-root` the edit is refused instead of falling back to `HQ_ROOT`, `CLAUDE_PROJECT_DIR` or the cwd. A template edit in a root with no `.claude/hooks/hook-gate.sh` is refused too, where the adapter exited 0 before any check.
|
|
8
|
+
- `hq crm entity list` and `hq crm entity get` stop the background flag-registry worker before they exit with an error, so they no longer risk a crash at exit (SIGSEGV on Node 20 and 22) after printing their message.
|
|
9
|
+
- `hq report` subcommands that fail (`access`, `discard-draft`, `promote`, and the others that share the same handler) stop the background flag-registry worker before the CLI exits, so they no longer risk a crash at exit (SIGSEGV on Node 20 and 22) after printing their message.
|
|
10
|
+
- `hq packages remove`, `hq packages packs list` and `hq packages packs uninstall` stop the background flag-registry worker before they exit with an error, so the CLI no longer risks a crash at exit (SIGSEGV on Node 20 and 22) after printing its message.
|
|
11
|
+
- hq-hook: `grok-adapter:PostToolUse` is claimed (US-050). The Grok adapter's own PostToolUse work is native: the payload rebuild and output contract, the `auto-capture-registry` supplement, and beta.68's held-policy-reminder flush, which the port refuses where the adapter would run it (nothing is started and the held text stays). `master-hook:PostToolUse` keeps its own id, so PostToolUse stays on the old dispatcher. Off Unix, an `hq` found only in Git Bash's own `PATH` folders (Git's `mingw64\bin` and `usr\bin`, `~/bin`) now counts as not known, so the Grok reindex row refuses there instead of allowing.
|
|
12
|
+
- `scripts/replay-harness.mjs` replays recorded Grok Build events as Grok Build runs them: the old side through the released adapter `.grok/hooks/hq-grok-hook-adapter.sh` (from `.grok/hooks`, with `GROK_HOOK_EVENT` and `GROK_WORKSPACE_ROOT`), the new side through the Grok user bridge file and script installed in the run's home as `hq reindex` installs them, not `hq-hook run` directly. A Grok event Grok Build never sends, a root without the adapter or the bridge, and a bridge entry the harness does not model (a tool matcher, more than one command) are reported, never compared as a pass.
|
|
13
|
+
- Test the Grok SubagentStop master-hook handoff against the released adapter for each stop-gate input (stopHookActive true, snake case, non-boolean, absent, a reason, no transcript).
|
|
14
|
+
- Internal: the `hq-hook` cleanup-mcp parity test for protected workflow runners now waits until the runner's helper is up before the hook runs, so a loaded machine can no longer run the hook while only the runner is there. Test-only; no behaviour change.
|
|
15
|
+
- The hq-hook engine now lists hq-core 16.0.48 in its core pins, so the latest-release pin check passes again. The credential guard (`block-credential-file-read`) stays on its bash hook for 16.0.48: the release ships script 6512581d with arithmetic library e90d160f, which the native port does not reproduce yet, and the commands that library newly allows wait for the owner's review first. Five other hooks are recorded as running on bash for 16.0.48 for the same reasons as on 16.0.48-beta.124.
|
|
16
|
+
- Hooks: the native fleet-local PreToolUse member now matches settings records on a `pre_approval_request` the way the released adapter dispatches them: an exec approval matches as tool `Bash` and an apply_patch approval as tool `Edit`. Before, it matched on the approval type (`exec`, `apply_patch`), so a `Bash` or `Edit` matcher that blocks in the adapter was not seen. An approval type other than exec or apply_patch refuses. The member is not registered yet, so nothing live changes.
|
|
17
|
+
- Hooks: the native fleet-local PreToolUse member (not registered yet) now models the released adapter's core and template edit checks: an Edit or Write (or any path of an `apply_patch` approval) into `core/` (unless `HQ_BYPASS_CORE_PROTECT` is set) or `companies/_template/` is refused with the adapter's own message. Paths are resolved in-process, with no `realpath` program; a path that reaches a protected folder through a symlink (a dangling one included, followed to its missing target as GNU `realpath` does), a different letter case or a carriage return is refused too, and a path the check cannot resolve is refused. The runtime tool name is read as the adapter's shell reads it (NUL bytes dropped, trailing newlines cut), so `patch\n`, `Edit\n` or `write_file\n` into `core/` is refused like `patch`, `Edit` or `write_file`, and an `apply_patch` approval that carries no usable path is refused with the adapter's own "carried no paths" message.
|
|
18
|
+
- Hooks: the native fleet-local `pre_tool_call` member (not registered yet) now sets up a subagent session's inherited company scope in process, as the released fleet-local adapter does: it reads the parent from the fleet `state.db`, drops HQ's `personal` placeholder, and writes the capability, the adapter's marker and the `meta.yaml` lines. It starts no program. Where it cannot decide (a CR that changes the decision, a capability file it cannot read as JSON) it blocks the tool call.
|
|
19
|
+
Because it never starts `sqlite3`, a `sqlite3` that fails when run is not modelled: where the released adapter would then inherit nothing, native reads a readable `state.db` and inherits the parent's scope, which only narrows the session. A `state.db` it cannot read still blocks.
|
|
20
|
+
- `hq-hook` builds again: the fleet-local PreToolUse member passes the inherited-scope context (its `PATH` read and parent-scope mint) through the shared answer path that both the PreToolUse and the approval-request answers use.
|
|
21
|
+
- Let an hq-hook coverage claim name the hosts it is for (`SubagentStop@codex`), so a claim on one host no longer switches the same event on the others; claims without a host set mean every host, as before.
|
|
22
|
+
- Internal: `hq lanes link _deliver` honours `HQ_LINK_DELIVER_QUEUED_AT_OR_BEFORE` (UTC `...Z` time): it drains or claims only link messages queued at or before it and leaves later ones queued for the next PostToolUse or Stop; a value it cannot read takes nothing. The daemon's `conduct-lanes-link-deliver` note may carry `args.at`, which the daemon passes to the root's hook script as that variable. Unset, every delivery path is unchanged. Nothing writes `args.at` yet.
|
|
23
|
+
- `hq-hook bridge-plan` no longer lists `inject-policy-on-trigger`, `policy-enforcement-gate` or `image-context-guard` on a platform where the Rust state store is off (Windows until US-022), whatever their `hook-engine-port-*` flag says. master-hook then runs the bash hooks exactly as with the flag off. Before, turning `hook-engine-port-inject-policy-on-trigger` on blocked every Claude Code prompt on Windows with the injector's store-off deny. On macOS and Linux the plan is unchanged, and a port that does run still never hands a call back to bash.
|
|
24
|
+
- hq-hook: on hq-fleet-local, `hq-hook run` now claims the fleet-local adapter's SessionEnd work, including the `on_session_reset` alias. With the released settings, session end runs natively and gives the adapter's answer: exit 0 and empty stdout. A `master-hook.sh` command listed under SessionEnd for another event now goes to the HQ daemon on the same `fleet-local-settings` request note as after a tool call, with event `SessionEnd`. The daemon accepts that event. Any other settings command at session end is still refused natively, as on Codex and Grok. The `cleanup-mcp-processes` registry row now runs on that session end as the released adapter ran it, instead of being refused. It reads the exit reason from the runtime's own payload, stops the session's own MCP helpers and sweeps old temp files. It writes no report line, because the adapter drops master-hook's stderr when master-hook exits 0. The agents-v2 runtime is still refused.
|
|
25
|
+
- Internal: the native Codex SubagentStop runner in `hq-hook` now leaves a `conduct-lanes-link-deliver` or `conduct-link-inherit` request note for the HQ daemon where the released adapter's hook would start `hq`, instead of refusing, and still refuses where a note cannot carry the session id or cannot be left. It also decides payloads that carry Codex's own `hook_event_name` and skips the two rows when the registry lists them `gated: false` (the adapter then runs them with no event argument, so they exit at once), as the released adapter does; parity rows run the released adapter. Still not wired: `codex-adapter:SubagentStop` stays unclaimed while `master-hook:SubagentStop` is not modelled for Codex.
|
|
26
|
+
- `hq-hook run --host grok SubagentStart` now does the released Grok adapter's own subagent company bind and claims it (`grok-adapter:SubagentStart` in `hq-hook capabilities --json`): a subagent with a parent session takes its parent's company, then the spawn company, then the device default (read in process; no program is started from the hook), as `bind_subagent_once` did. A bind it cannot decide writes nothing and refuses the event, with the reason on stderr.
|
|
27
|
+
|
|
5
28
|
## [5.345.230] — 2026-11-18
|
|
6
29
|
- `hq-hook run --host codex PreToolUse` with no `--hq-root` no longer trusts `HQ_ROOT`, `CLAUDE_PROJECT_DIR` or the cwd as the Codex adapter's root for the explicit-path guard: it keeps a refusal from that fallback root and refuses every other Codex Bash call, because the adapter's root was its own location.
|
|
7
30
|
- The HQ daemon now takes two new hook request notes, `conduct-lanes-link-deliver` and `conduct-link-inherit`, for the two programs the Codex adapter started at SubagentStop (`hq lanes link _deliver` and the conduct-link invite settle). Each note carries only the session id; the daemon runs the HQ root's own `.claude/hooks/conduct-lanes-link-deliver.sh` or `.claude/hooks/conduct-link-inherit.sh` with `PostToolUse` and `{"session_id": ...}` on stdin, as the adapter did, and drops their output as the adapter did on SubagentStop. No hook leaves these notes yet.
|
package/dist/commands/crm.js
CHANGED
|
@@ -6,6 +6,7 @@ import { readSessionCompanyLock } from "../lib/session-company-lock.js";
|
|
|
6
6
|
import { sessionIdFromEnv } from "../lib/core-utils/session-id.js";
|
|
7
7
|
import { MULTI_COMPANY_SESSION_LOCK_FLAG } from "../lib/cli-flag-keys.js";
|
|
8
8
|
import { fastFlagEnabledDefaultOn } from "../native-fast-route.js";
|
|
9
|
+
import { exitCli } from "../utils/exit-after-worker.js";
|
|
9
10
|
async function resolveCrmCompany(requestedCompany) {
|
|
10
11
|
const lock = sessionIdFromEnv(process.env)
|
|
11
12
|
&& await fastFlagEnabledDefaultOn(MULTI_COMPANY_SESSION_LOCK_FLAG)
|
|
@@ -187,7 +188,7 @@ export function registerCrmCommand(program) {
|
|
|
187
188
|
}
|
|
188
189
|
catch (error) {
|
|
189
190
|
console.error(chalk.red(error instanceof Error ? error.message : String(error)));
|
|
190
|
-
|
|
191
|
+
return await exitCli(1);
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
194
|
entity.command("list")
|
package/dist/commands/packs.js
CHANGED
|
@@ -32,6 +32,7 @@ import { classify, PINNED_HQ_ANYWHERE_SOURCE, resolveLatest, parseMarketplaceSou
|
|
|
32
32
|
import { contributionLinks, linkStatus, listInstalledPacks, findDependentPacks, readPackManifest, unwirePack, unwireNamespacedSkills, unwirePackMcp, readHqVersion, readRecommendedPackages, packagesDir, } from '../utils/pack-contributions.js';
|
|
33
33
|
import { readInstalledPackSetup } from '../lib/packages/setup-block.js';
|
|
34
34
|
import { syncCodexPackHooks, syncCodexPackSkills } from '../lib/install/codex-pack-contributions.js';
|
|
35
|
+
import { exitCli } from '../utils/exit-after-worker.js';
|
|
35
36
|
function resolveRoot(opts) {
|
|
36
37
|
return opts.hqRoot ? path.resolve(opts.hqRoot) : findHqRoot();
|
|
37
38
|
}
|
|
@@ -450,7 +451,7 @@ export function registerPacksListCommand(parent) {
|
|
|
450
451
|
}
|
|
451
452
|
catch (e) {
|
|
452
453
|
console.error(chalk.red('packs list failed:'), e.message);
|
|
453
|
-
|
|
454
|
+
await exitCli(1);
|
|
454
455
|
}
|
|
455
456
|
});
|
|
456
457
|
}
|
|
@@ -550,7 +551,7 @@ export function registerPacksCommand(parent) {
|
|
|
550
551
|
}
|
|
551
552
|
catch (e) {
|
|
552
553
|
console.error(chalk.red('packs uninstall failed:'), e.message);
|
|
553
|
-
|
|
554
|
+
await exitCli(1);
|
|
554
555
|
}
|
|
555
556
|
});
|
|
556
557
|
}
|
|
@@ -10,6 +10,7 @@ import * as path from 'path';
|
|
|
10
10
|
import chalk from 'chalk';
|
|
11
11
|
import { resolveDefaultHqRoot } from '../utils/cognito-session.js';
|
|
12
12
|
import { removeFromRegistry, readRegistry } from '../utils/registry.js';
|
|
13
|
+
import { exitCli } from '../utils/exit-after-worker.js';
|
|
13
14
|
export function registerPackageRemoveCommand(parent) {
|
|
14
15
|
parent
|
|
15
16
|
.command('remove <slug>')
|
|
@@ -20,7 +21,7 @@ export function registerPackageRemoveCommand(parent) {
|
|
|
20
21
|
}
|
|
21
22
|
catch (error) {
|
|
22
23
|
console.error(chalk.red('Remove failed:'), error instanceof Error ? error.message : 'Unknown error');
|
|
23
|
-
|
|
24
|
+
await exitCli(1);
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
27
|
}
|
package/dist/commands/report.js
CHANGED
|
@@ -8,6 +8,7 @@ import { vaultApiFetch } from "../utils/vault-api.js";
|
|
|
8
8
|
import { DEPLOY_API_URL, deployApiRequest, deployHeaders } from "../lib/deploy-api.js";
|
|
9
9
|
import { listDeployApps } from "../lib/deploy-apps.js";
|
|
10
10
|
import { listReportTemplates } from "../lib/report-templates.js";
|
|
11
|
+
import { stopFlagRegistryWorker } from "../lib/flag-registry.js";
|
|
11
12
|
import { adoptReport, buildReportTarball, conventionReportDir, deployOrgContext, ReportPublishError, plainFailureReason, publishReport, } from "../lib/report-publish.js";
|
|
12
13
|
const REPORT_CHANNEL_STATE_FILE = "report-channels.json";
|
|
13
14
|
const REPORT_UPLOAD_TIMEOUT_MS = 120_000;
|
|
@@ -536,6 +537,9 @@ async function runReportCommand(action) {
|
|
|
536
537
|
catch (error) {
|
|
537
538
|
console.error(errorMessage(error));
|
|
538
539
|
process.exitCode = 1;
|
|
540
|
+
// The CLI still ends through main's normal finish; the flag-registry
|
|
541
|
+
// worker must not be running when it does.
|
|
542
|
+
await stopFlagRegistryWorker();
|
|
539
543
|
}
|
|
540
544
|
}
|
|
541
545
|
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type FleetLocalSettingsCommand, type HookRequest, type HookRequestResult } from "./hook-requests.js";
|
|
2
|
+
export type CodexSettingsOperation = {
|
|
3
|
+
kind: "codex-settings";
|
|
4
|
+
event: "PostToolUse";
|
|
5
|
+
commands: FleetLocalSettingsCommand[];
|
|
6
|
+
};
|
|
7
|
+
/** What the released Codex adapter exported for the hooks it started (v16.0.47 adapter lines 5, 86-100). */
|
|
8
|
+
export declare const CODEX_SETTINGS_RUNTIME = "codex";
|
|
9
|
+
/** The args of a `codex-settings` note: exactly `event` (PostToolUse) and 1 to 64 typed commands. Anything else: refused. */
|
|
10
|
+
export declare function parseCodexSettings(kind: unknown, args: Record<string, unknown>): CodexSettingsOperation | undefined;
|
|
11
|
+
/** The environment the released Codex adapter gave its settings hooks, over the daemon's own. */
|
|
12
|
+
export declare function codexSettingsEnv(base: NodeJS.ProcessEnv, root: string, session: string, id: string): NodeJS.ProcessEnv;
|
|
13
|
+
/**
|
|
14
|
+
* Run the commands of a `codex-settings` note in order. Before any starts, the root's settings file is read again: a
|
|
15
|
+
* command runs only if it is still listed there for the note's event and every file it starts resolves to a real path
|
|
16
|
+
* under the HQ root. A refused command is not started, is logged, and does not stop the rest. A command still running
|
|
17
|
+
* at the limit is ended with its process group and the commands after it are skipped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function runCodexSettings(request: HookRequest, operation: CodexSettingsOperation, options: {
|
|
20
|
+
env?: NodeJS.ProcessEnv;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
timeoutMs: number;
|
|
23
|
+
killGraceMs: number;
|
|
24
|
+
log?: (message: string) => void;
|
|
25
|
+
}): Promise<HookRequestResult>;
|
|
26
|
+
//# sourceMappingURL=hook-requests-codex-settings.d.ts.map
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `codex-settings` request note (hq-core-rust, codex-adapter:PostToolUse). On a Codex PostToolUse the native hook
|
|
3
|
+
* starts no `.claude/settings.json` command: it leaves the session id, the event, the command list it read from the
|
|
4
|
+
* settings file (the records of `hqad_iter_settings`) and the adapter's payload (the note's body), and the daemon runs
|
|
5
|
+
* the commands a moment later, as `dispatch_settings_hooks` in the released Codex adapter (hq-core v16.0.47,
|
|
6
|
+
* crates/hq-hook/tests/fixtures/codex-adapter-16.0.47/.codex/hooks/hq-codex-hook-adapter.sh) did in the hook.
|
|
7
|
+
*
|
|
8
|
+
* The command records and their programs are the same as a `fleet-local-settings` note's (`fleetLocalSettingsProgram`,
|
|
9
|
+
* `fleetLocalSettingsRefusal`). What differs is what the adapter exported for its hooks (adapter lines 5 and 86-100):
|
|
10
|
+
* `BASH_ENV=/dev/null` for every child, `HQ_ROOT` and `CLAUDE_PROJECT_DIR` set to the root,
|
|
11
|
+
* `HQ_CHECKPOINT_RUNTIME=codex`, `HQ_WORK_MESH_HARNESS=codex`, `HQ_HARNESS=codex` and `HQAD_EVENT_SESSION_ID` set to
|
|
12
|
+
* the session. The Codex adapter does not set `HQ_WORK_MESH_DISABLED`, so neither does this runner.
|
|
13
|
+
*
|
|
14
|
+
* PATH: before its first gated hook that the profile allows, the adapter runs `hq_augment_path` (from
|
|
15
|
+
* `hook-gate.sh --lib`) in its own shell (hook-adapter-core.sh `hqad_launch_registered_hook`), so that hook and every
|
|
16
|
+
* command after it see the augmented PATH. The runner does the same once, before the first gate command it starts.
|
|
17
|
+
*
|
|
18
|
+
* PostToolUse is advisory on Codex (`hqad_mode_for` answers advisory for every event but PreToolUse): a failing command
|
|
19
|
+
* does not stop the rest, and the note is done once the list has been run.
|
|
20
|
+
*/
|
|
21
|
+
import * as path from "node:path";
|
|
22
|
+
import { FLEET_LOCAL_HOOK_GATE, FLEET_LOCAL_SETTINGS_MAX_COMMANDS, fleetLocalSettingsListed, fleetLocalSettingsProgram, fleetLocalSettingsRefusal, spawnRequestProgram, } from "./hook-requests.js";
|
|
23
|
+
/** What the released Codex adapter exported for the hooks it started (v16.0.47 adapter lines 5, 86-100). */
|
|
24
|
+
export const CODEX_SETTINGS_RUNTIME = "codex";
|
|
25
|
+
const plain = (value) => typeof value === "string" && !value.includes("\0");
|
|
26
|
+
const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
|
|
27
|
+
/** The args of a `codex-settings` note: exactly `event` (PostToolUse) and 1 to 64 typed commands. Anything else: refused. */
|
|
28
|
+
export function parseCodexSettings(kind, args) {
|
|
29
|
+
if (kind !== "codex-settings")
|
|
30
|
+
return undefined;
|
|
31
|
+
const keys = Object.keys(args).sort();
|
|
32
|
+
if (keys.length !== 2 || keys[0] !== "commands" || keys[1] !== "event" || args.event !== "PostToolUse")
|
|
33
|
+
return undefined;
|
|
34
|
+
const list = args.commands;
|
|
35
|
+
if (!Array.isArray(list) || list.length === 0 || list.length > FLEET_LOCAL_SETTINGS_MAX_COMMANDS)
|
|
36
|
+
return undefined;
|
|
37
|
+
const commands = [];
|
|
38
|
+
const word = (s) => plain(s) && s.length > 0 && s.length <= 4096;
|
|
39
|
+
const script = (s) => word(s) && path.isAbsolute(s);
|
|
40
|
+
const exactly = (item, names) => {
|
|
41
|
+
const have = Object.keys(item).sort();
|
|
42
|
+
return have.length === names.length && have.every((name, i) => name === names[i]);
|
|
43
|
+
};
|
|
44
|
+
for (const entry of list) {
|
|
45
|
+
const item = record(entry);
|
|
46
|
+
if (!item)
|
|
47
|
+
return undefined;
|
|
48
|
+
if (item.type === "gate" && exactly(item, ["args", "id", "script", "type"])) {
|
|
49
|
+
if (!plain(item.id) || !/^[A-Za-z0-9._-]{1,128}$/.test(item.id) || !script(item.script))
|
|
50
|
+
return undefined;
|
|
51
|
+
if (!Array.isArray(item.args) || !item.args.every(arg => plain(arg) && arg.length <= 4096))
|
|
52
|
+
return undefined;
|
|
53
|
+
commands.push({ type: "gate", id: item.id, script: item.script, args: [...item.args] });
|
|
54
|
+
}
|
|
55
|
+
else if (item.type === "master" && exactly(item, ["event", "type"])) {
|
|
56
|
+
if (!plain(item.event) || !/^[A-Za-z]{1,64}$/.test(item.event))
|
|
57
|
+
return undefined;
|
|
58
|
+
commands.push({ type: "master", event: item.event });
|
|
59
|
+
}
|
|
60
|
+
else if (item.type === "script" && exactly(item, ["script", "type"])) {
|
|
61
|
+
if (!script(item.script))
|
|
62
|
+
return undefined;
|
|
63
|
+
commands.push({ type: "script", script: item.script });
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { kind: "codex-settings", event: "PostToolUse", commands };
|
|
70
|
+
}
|
|
71
|
+
/** The environment the released Codex adapter gave its settings hooks, over the daemon's own. */
|
|
72
|
+
export function codexSettingsEnv(base, root, session, id) {
|
|
73
|
+
return {
|
|
74
|
+
...base,
|
|
75
|
+
BASH_ENV: "/dev/null", HQ_ROOT: root, CLAUDE_PROJECT_DIR: root,
|
|
76
|
+
HQ_CHECKPOINT_RUNTIME: CODEX_SETTINGS_RUNTIME, HQ_WORK_MESH_HARNESS: CODEX_SETTINGS_RUNTIME, HQ_HARNESS: CODEX_SETTINGS_RUNTIME,
|
|
77
|
+
HQAD_EVENT_SESSION_ID: session, HQ_HOOK_REQUEST_ID: id,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The PATH the adapter's shell had after its first gated hook: the root's hook-lib and `hook-gate.sh --lib` are
|
|
82
|
+
* sourced as the adapter sourced them, and `hq_augment_path` runs only where the adapter ran it (the profile lister,
|
|
83
|
+
* the shell launcher and the hook all present, and the profile allows the id). `path` undefined: PATH is left as it
|
|
84
|
+
* is. The probe runs under `spawnRequestProgram`'s stop model (own process group, SIGTERM at the limit or when the
|
|
85
|
+
* daemon stops, SIGKILL after the grace time); `ended` true: it was stopped, and no command after it is started.
|
|
86
|
+
*/
|
|
87
|
+
function codexAugmentedPath(root, id, env, options) {
|
|
88
|
+
const probe = [
|
|
89
|
+
'. "$HQ_ROOT/core/scripts/hook-lib.sh" >/dev/null 2>&1 || true',
|
|
90
|
+
'. "$1" --lib >/dev/null 2>&1 || exit 3',
|
|
91
|
+
"command -v hq_hook_profile_allows >/dev/null 2>&1 && command -v hq_launch_shell_path >/dev/null 2>&1 || exit 3",
|
|
92
|
+
'hq_hook_profile_allows "$2" >/dev/null 2>&1 || exit 3',
|
|
93
|
+
"command -v hq_augment_path >/dev/null 2>&1 || exit 3",
|
|
94
|
+
"hq_augment_path >/dev/null 2>&1",
|
|
95
|
+
'printf %s "$PATH"',
|
|
96
|
+
].join("\n");
|
|
97
|
+
const limit = 1024 * 1024;
|
|
98
|
+
return new Promise(resolve => {
|
|
99
|
+
if (options.signal?.aborted) {
|
|
100
|
+
resolve({ path: undefined, ended: true });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const { child, settle } = spawnRequestProgram("bash", ["-c", probe, "codex-settings-path", path.join(root, FLEET_LOCAL_HOOK_GATE), id], {
|
|
104
|
+
cwd: root, env, windowsHide: true, stdio: ["ignore", "pipe", "ignore"],
|
|
105
|
+
}, { timeoutMs: options.timeoutMs, killGraceMs: options.killGraceMs, ...(options.signal ? { signal: options.signal } : {}) });
|
|
106
|
+
let out = "";
|
|
107
|
+
let over = false;
|
|
108
|
+
child.stdout?.setEncoding("utf8");
|
|
109
|
+
child.stdout?.on("data", (text) => { if (out.length + text.length > limit)
|
|
110
|
+
over = true;
|
|
111
|
+
else
|
|
112
|
+
out += text; });
|
|
113
|
+
child.stdout?.on("error", () => undefined);
|
|
114
|
+
let settled = false;
|
|
115
|
+
const finish = (code) => {
|
|
116
|
+
if (settled)
|
|
117
|
+
return;
|
|
118
|
+
settled = true;
|
|
119
|
+
const ended = settle();
|
|
120
|
+
const good = !ended && !over && code === 0 && out !== "" && !out.includes("\0");
|
|
121
|
+
resolve({ path: good ? out : undefined, ended });
|
|
122
|
+
};
|
|
123
|
+
child.once("error", () => finish(null));
|
|
124
|
+
child.once("close", code => finish(code));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function runOne(program, args, options) {
|
|
128
|
+
return new Promise(resolve => {
|
|
129
|
+
if (options.signal?.aborted) {
|
|
130
|
+
resolve({ ended: true });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const { child, settle } = spawnRequestProgram(program, args, {
|
|
134
|
+
cwd: options.cwd, env: options.env, windowsHide: true, stdio: ["pipe", "ignore", "ignore"],
|
|
135
|
+
}, { timeoutMs: options.timeoutMs, killGraceMs: options.killGraceMs, ...(options.signal ? { signal: options.signal } : {}) });
|
|
136
|
+
child.stdin?.on("error", () => undefined);
|
|
137
|
+
child.stdin?.end(options.input);
|
|
138
|
+
let settled = false;
|
|
139
|
+
const finish = () => { if (settled)
|
|
140
|
+
return; settled = true; resolve({ ended: settle() }); };
|
|
141
|
+
child.once("error", finish);
|
|
142
|
+
child.once("close", finish);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Run the commands of a `codex-settings` note in order. Before any starts, the root's settings file is read again: a
|
|
147
|
+
* command runs only if it is still listed there for the note's event and every file it starts resolves to a real path
|
|
148
|
+
* under the HQ root. A refused command is not started, is logged, and does not stop the rest. A command still running
|
|
149
|
+
* at the limit is ended with its process group and the commands after it are skipped.
|
|
150
|
+
*/
|
|
151
|
+
export async function runCodexSettings(request, operation, options) {
|
|
152
|
+
if (!request.body)
|
|
153
|
+
return { code: 1 };
|
|
154
|
+
const listed = fleetLocalSettingsListed(request.root, operation.event);
|
|
155
|
+
let augmented = false;
|
|
156
|
+
const env = codexSettingsEnv({ ...(options.env ?? process.env) }, request.root, request.session, request.id);
|
|
157
|
+
for (const command of operation.commands) {
|
|
158
|
+
const refusal = fleetLocalSettingsRefusal(request.root, command, listed);
|
|
159
|
+
if (refusal !== undefined) {
|
|
160
|
+
options.log?.(`hook request ${request.stem}: refused the ${command.type} settings command: ${refusal}`);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const started = fleetLocalSettingsProgram(request.root, command);
|
|
164
|
+
if (!started)
|
|
165
|
+
continue;
|
|
166
|
+
if (command.type === "gate" && !augmented) {
|
|
167
|
+
augmented = true;
|
|
168
|
+
const searched = await codexAugmentedPath(request.root, command.id, env, {
|
|
169
|
+
timeoutMs: options.timeoutMs, killGraceMs: options.killGraceMs, ...(options.signal ? { signal: options.signal } : {}),
|
|
170
|
+
});
|
|
171
|
+
if (searched.ended)
|
|
172
|
+
break;
|
|
173
|
+
if (searched.path !== undefined)
|
|
174
|
+
env.PATH = searched.path;
|
|
175
|
+
}
|
|
176
|
+
const ran = await runOne(started.program, started.args, {
|
|
177
|
+
cwd: request.root, env, input: request.body, timeoutMs: options.timeoutMs, killGraceMs: options.killGraceMs,
|
|
178
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
179
|
+
});
|
|
180
|
+
if (ran.ended)
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
return { code: 0 };
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=hook-requests-codex-settings.js.map
|
|
@@ -3,6 +3,7 @@ export type ConductLinkKind = "conduct-lanes-link-deliver" | "conduct-link-inher
|
|
|
3
3
|
export type ConductLinkOperation = {
|
|
4
4
|
kind: ConductLinkKind;
|
|
5
5
|
sessionId: string;
|
|
6
|
+
queuedAtOrBefore?: string;
|
|
6
7
|
};
|
|
7
8
|
/** The root's hook script each kind runs, with the event the adapter gave it. */
|
|
8
9
|
export declare const CONDUCT_LINK_SCRIPTS: Readonly<Record<ConductLinkKind, string>>;
|
|
@@ -17,7 +17,12 @@
|
|
|
17
17
|
* link once the session's companies are bound, and sweeps stale claims.
|
|
18
18
|
*
|
|
19
19
|
* Each reads only `session_id` from a root payload, so that is all the note
|
|
20
|
-
* carries (`args.session_id`, also the note's session).
|
|
20
|
+
* carries (`args.session_id`, also the note's session). A deliver note may
|
|
21
|
+
* also carry `args.at`, the event's time (UTC, `...Z`): the daemon passes it to
|
|
22
|
+
* the script as HQ_LINK_DELIVER_QUEUED_AT_OR_BEFORE, which the script's
|
|
23
|
+
* `hq lanes link _deliver` inherits, so the run takes only the messages queued
|
|
24
|
+
* at or before the event; later ones stay queued for the root's next
|
|
25
|
+
* PostToolUse or Stop, where the adapter would have delivered them. The daemon runs the
|
|
21
26
|
* root's own hook script, `bash <root>/.claude/hooks/<script> PostToolUse`,
|
|
22
27
|
* with `{"session_id": <sid>}` on stdin:
|
|
23
28
|
*
|
|
@@ -51,19 +56,27 @@ export const CONDUCT_LINK_EVENT = "PostToolUse";
|
|
|
51
56
|
* scripts' own `^[A-Za-z0-9._-]+$`, not `.` or `..`, at most 512 characters.
|
|
52
57
|
*/
|
|
53
58
|
const CONDUCT_SESSION = /^[A-Za-z0-9._-]{1,512}$/;
|
|
59
|
+
/** A deliver note's event time: the form `_deliver` reads (HQ_LINK_DELIVER_QUEUED_AT_OR_BEFORE). */
|
|
60
|
+
const EVENT_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?Z$/;
|
|
54
61
|
export function isConductLinkKind(kind) {
|
|
55
62
|
return kind === "conduct-lanes-link-deliver" || kind === "conduct-link-inherit";
|
|
56
63
|
}
|
|
57
64
|
/** The operation in a conduct note's `args`, or undefined for anything the hook does not write. */
|
|
58
65
|
export function parseConductLink(kind, args, session) {
|
|
59
|
-
const keys = Object.keys(args);
|
|
60
|
-
|
|
66
|
+
const keys = Object.keys(args).sort();
|
|
67
|
+
const timed = kind === "conduct-lanes-link-deliver" && keys.length === 2 && keys[0] === "at" && keys[1] === "session_id";
|
|
68
|
+
if (!timed && (keys.length !== 1 || keys[0] !== "session_id"))
|
|
61
69
|
return undefined;
|
|
62
70
|
const sessionId = args.session_id;
|
|
63
71
|
if (typeof sessionId !== "string" || !CONDUCT_SESSION.test(sessionId) || sessionId === "." || sessionId === ".."
|
|
64
72
|
|| sessionId !== session)
|
|
65
73
|
return undefined;
|
|
66
|
-
|
|
74
|
+
if (!timed)
|
|
75
|
+
return { kind, sessionId };
|
|
76
|
+
const at = args.at;
|
|
77
|
+
if (typeof at !== "string" || !EVENT_TIME.test(at) || !Number.isFinite(Date.parse(at)))
|
|
78
|
+
return undefined;
|
|
79
|
+
return { kind, sessionId, queuedAtOrBefore: at };
|
|
67
80
|
}
|
|
68
81
|
/** Run the root's hook script for one conduct note (see the file comment). */
|
|
69
82
|
export async function runConductLink(request, operation, base, options) {
|
|
@@ -77,6 +90,10 @@ export async function runConductLink(request, operation, base, options) {
|
|
|
77
90
|
}
|
|
78
91
|
const env = { ...base };
|
|
79
92
|
delete env.HQ_HOOK_AGENT_ID;
|
|
93
|
+
// Only a note's own event time limits the drain, never one the daemon inherited.
|
|
94
|
+
delete env.HQ_LINK_DELIVER_QUEUED_AT_OR_BEFORE;
|
|
95
|
+
if (operation.queuedAtOrBefore !== undefined)
|
|
96
|
+
env.HQ_LINK_DELIVER_QUEUED_AT_OR_BEFORE = operation.queuedAtOrBefore;
|
|
80
97
|
Object.assign(env, { HQ_ROOT: request.root, CLAUDE_PROJECT_DIR: request.root, HQ_HOOK_REQUEST_ID: request.id });
|
|
81
98
|
const input = JSON.stringify({ session_id: operation.sessionId });
|
|
82
99
|
return new Promise(resolve => {
|
|
@@ -55,6 +55,7 @@ import { type MachineCheckResult, type RunMachineChecksOptions } from "./machine
|
|
|
55
55
|
import { type MeshToolWritesOperation } from "./hook-requests-mesh-tool-writes.js";
|
|
56
56
|
import { type FleetSessionStartOperation } from "./hook-requests-fleet-session-start.js";
|
|
57
57
|
import { type ConductLinkOperation } from "./hook-requests-conduct-link.js";
|
|
58
|
+
import { type CodexSettingsOperation } from "./hook-requests-codex-settings.js";
|
|
58
59
|
/** What the daemon is asked to do. A closed list, the same as `Kind` in daemon_req.rs. */
|
|
59
60
|
export type HookOperation = {
|
|
60
61
|
kind: "reindex";
|
|
@@ -88,7 +89,7 @@ export type HookOperation = {
|
|
|
88
89
|
* adapter's payload is the note's `.body` file (`host::fleet_settings`). */
|
|
89
90
|
| {
|
|
90
91
|
kind: "fleet-local-settings";
|
|
91
|
-
event: "PostToolUse";
|
|
92
|
+
event: "PostToolUse" | "SessionEnd";
|
|
92
93
|
commands: FleetLocalSettingsCommand[];
|
|
93
94
|
}
|
|
94
95
|
/** The Work Mesh register step of a mid-session company bind (`spawn_work_mesh_register`, owner decision 36). */
|
|
@@ -107,7 +108,7 @@ export type HookOperation = {
|
|
|
107
108
|
disabled?: MeshSessionBindSwitch;
|
|
108
109
|
}
|
|
109
110
|
/** One machine check run by the daemon for a SessionStart where the hooks own the checks (the machine-check notes at the end of this file). */
|
|
110
|
-
| MachineCheckOperation | MeshOperation | MeshToolWritesOperation | FleetSessionStartOperation
|
|
111
|
+
| MachineCheckOperation | MeshOperation | MeshToolWritesOperation | CodexSettingsOperation | FleetSessionStartOperation
|
|
111
112
|
/** The Codex adapter's SubagentStop runs of the root's conduct-link hooks (hook-requests-conduct-link.ts). */
|
|
112
113
|
| ConductLinkOperation;
|
|
113
114
|
/**
|
|
@@ -60,6 +60,7 @@ import { MACHINE_CHECKS, machineCheckCollectOnlySupported, runMachineChecks } fr
|
|
|
60
60
|
import { parseMeshToolWrites, runMeshToolWrites } from "./hook-requests-mesh-tool-writes.js";
|
|
61
61
|
import { parseFleetSessionStart, runFleetSessionStart } from "./hook-requests-fleet-session-start.js";
|
|
62
62
|
import { isConductLinkKind, parseConductLink, runConductLink } from "./hook-requests-conduct-link.js";
|
|
63
|
+
import { parseCodexSettings, runCodexSettings } from "./hook-requests-codex-settings.js";
|
|
63
64
|
/** The longest note the Rust writer leaves (`NOTE_MAX_BYTES`). */
|
|
64
65
|
export const HOOK_REQUEST_MAX_BYTES = 4096;
|
|
65
66
|
/** The longest `.body` file the Rust writer leaves (`BODY_MAX_BYTES`). */
|
|
@@ -307,6 +308,12 @@ export function parseHookRequest(text, stem) {
|
|
|
307
308
|
return undefined;
|
|
308
309
|
operation = conduct;
|
|
309
310
|
}
|
|
311
|
+
else if (value.kind === "codex-settings") {
|
|
312
|
+
const codex = parseCodexSettings(value.kind, args);
|
|
313
|
+
if (!codex)
|
|
314
|
+
return undefined;
|
|
315
|
+
operation = codex;
|
|
316
|
+
}
|
|
310
317
|
else if (isMachineCheckRequestKind(value.kind)) {
|
|
311
318
|
const check = parseMachineCheckOperation(value.kind, args);
|
|
312
319
|
if (!check)
|
|
@@ -321,10 +328,11 @@ export function parseHookRequest(text, stem) {
|
|
|
321
328
|
}
|
|
322
329
|
return { stem, id: value.id, at, root: value.hqRoot, session: value.session, operation };
|
|
323
330
|
}
|
|
324
|
-
/** The args of a `fleet-local-settings` note: exactly `event` (PostToolUse) and 1 to 64 typed commands. */
|
|
331
|
+
/** The args of a `fleet-local-settings` note: exactly `event` (PostToolUse or SessionEnd) and 1 to 64 typed commands. */
|
|
325
332
|
function parseFleetLocalSettings(args) {
|
|
326
333
|
const keys = Object.keys(args).sort();
|
|
327
|
-
|
|
334
|
+
const event = args.event;
|
|
335
|
+
if (keys.length !== 2 || keys[0] !== "commands" || keys[1] !== "event" || (event !== "PostToolUse" && event !== "SessionEnd"))
|
|
328
336
|
return undefined;
|
|
329
337
|
const list = args.commands;
|
|
330
338
|
if (!Array.isArray(list) || list.length === 0 || list.length > FLEET_LOCAL_SETTINGS_MAX_COMMANDS)
|
|
@@ -362,7 +370,7 @@ function parseFleetLocalSettings(args) {
|
|
|
362
370
|
return undefined;
|
|
363
371
|
}
|
|
364
372
|
}
|
|
365
|
-
return { kind: "fleet-local-settings", event
|
|
373
|
+
return { kind: "fleet-local-settings", event, commands };
|
|
366
374
|
}
|
|
367
375
|
/** A project as the plan-sync writer leaves it: a path under the HQ root, relative, with no `..` part. */
|
|
368
376
|
function hookRequestProject(project) {
|
|
@@ -374,6 +382,7 @@ export function hookRequestHasBody(operation) {
|
|
|
374
382
|
return operation.kind === "plan-sync"
|
|
375
383
|
|| operation.kind === "startwork-prefetch"
|
|
376
384
|
|| operation.kind === "fleet-local-settings"
|
|
385
|
+
|| operation.kind === "codex-settings"
|
|
377
386
|
|| operation.kind === "fleet-session-start";
|
|
378
387
|
}
|
|
379
388
|
/** The helper a plan-sync request runs, inside the HQ root. */
|
|
@@ -407,6 +416,8 @@ export function hookRequestArguments(request) {
|
|
|
407
416
|
case "acl-suggest":
|
|
408
417
|
case "session-close": return undefined;
|
|
409
418
|
// Run by hook-requests-fleet-session-start.ts with the pinned engine.
|
|
419
|
+
// Not a CLI request: the Codex settings commands are started one by one (hook-requests-codex-settings.ts).
|
|
420
|
+
case "codex-settings": return [];
|
|
410
421
|
case "fleet-session-start": return [];
|
|
411
422
|
// Not a CLI request: the root's own conduct-link hook script is run (`runConductLink`).
|
|
412
423
|
case "conduct-lanes-link-deliver":
|
|
@@ -1592,6 +1603,8 @@ export function executeHookRequest(request, options) {
|
|
|
1592
1603
|
return runMeshToolWrites(operation, { ...options, root: request.root });
|
|
1593
1604
|
if (operation.kind === "fleet-session-start")
|
|
1594
1605
|
return runFleetSessionStart(request, operation, options);
|
|
1606
|
+
if (operation.kind === "codex-settings")
|
|
1607
|
+
return runCodexSettings(request, operation, { ...options, timeoutMs: options.timeoutMs ?? HOOK_REQUEST_KILL_MS, killGraceMs: options.killGraceMs ?? HOOK_REQUEST_KILL_GRACE_MS }).catch(() => ({ code: 1 }));
|
|
1595
1608
|
const cliArgs = hookRequestArguments(request);
|
|
1596
1609
|
if (!cliArgs)
|
|
1597
1610
|
return Promise.resolve({ code: 1 });
|
|
@@ -91,4 +91,11 @@ export declare function resolveProcessFlagGate(flagKey: string, lookup: FlagLook
|
|
|
91
91
|
export declare function currentFlagSnapshot(): FlagSnapshot | null;
|
|
92
92
|
/** Test-only reset for process-global readiness state. */
|
|
93
93
|
export declare function _resetFlagRegistryForTests(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Stop the background registry worker, if one is still running, and wait for
|
|
96
|
+
* it to end. A command that exits right after its own output calls this first:
|
|
97
|
+
* on Node 20 and 22, process.exit while an eval worker is still starting or
|
|
98
|
+
* fetching can crash the process (SIGSEGV) after the output was written.
|
|
99
|
+
*/
|
|
100
|
+
export declare function stopFlagRegistryWorker(): Promise<void>;
|
|
94
101
|
//# sourceMappingURL=flag-registry.d.ts.map
|
|
@@ -469,4 +469,24 @@ export function _resetFlagRegistryForTests() {
|
|
|
469
469
|
refreshSentry = undefined;
|
|
470
470
|
refreshDependencies = {};
|
|
471
471
|
}
|
|
472
|
+
/**
|
|
473
|
+
* Stop the background registry worker, if one is still running, and wait for
|
|
474
|
+
* it to end. A command that exits right after its own output calls this first:
|
|
475
|
+
* on Node 20 and 22, process.exit while an eval worker is still starting or
|
|
476
|
+
* fetching can crash the process (SIGSEGV) after the output was written.
|
|
477
|
+
*/
|
|
478
|
+
export async function stopFlagRegistryWorker() {
|
|
479
|
+
const worker = refreshWorker;
|
|
480
|
+
refreshWorker = null;
|
|
481
|
+
if (!worker || typeof worker.terminate !== "function")
|
|
482
|
+
return;
|
|
483
|
+
try {
|
|
484
|
+
await worker.terminate();
|
|
485
|
+
}
|
|
486
|
+
catch {
|
|
487
|
+
// Already ended or never started: nothing is left running to stop.
|
|
488
|
+
}
|
|
489
|
+
completeRefresh?.();
|
|
490
|
+
completeRefresh = null;
|
|
491
|
+
}
|
|
472
492
|
//# sourceMappingURL=flag-registry.js.map
|
|
@@ -148,6 +148,24 @@ export declare function shellHooks(root: string, host: CoreNextHost, event: stri
|
|
|
148
148
|
export declare function claimCovers(pattern: string, hook: string): boolean;
|
|
149
149
|
/** The same install-level checks as stop/precompact/guard.rs, before reindex switches the event. */
|
|
150
150
|
export declare function precompactCompatibilityHold(root: string, env?: NodeJS.ProcessEnv): string | null;
|
|
151
|
+
/** The hosts a COVERS host set may name (`Host::ALL` in crates/hq-hook/src/host/mod.rs). */
|
|
152
|
+
export declare const COVERS_HOSTS: readonly CoreNextHost[];
|
|
153
|
+
/**
|
|
154
|
+
* A `covers` key read, as crates/hq-hook/src/covers_hosts.rs `key` reads it:
|
|
155
|
+
* `Stop` claims for every host, `SubagentStop@codex,grok` for those hosts
|
|
156
|
+
* only. Null when the key cannot be read (an empty or unknown host, a second
|
|
157
|
+
* `@`, an event that is not ASCII letters): such a key claims nothing.
|
|
158
|
+
*/
|
|
159
|
+
export declare function coversKey(key: string): {
|
|
160
|
+
event: string;
|
|
161
|
+
hosts: string[] | null;
|
|
162
|
+
} | null;
|
|
163
|
+
/**
|
|
164
|
+
* What `covers` claims for `event` on `host`: `covers[event]` (every host),
|
|
165
|
+
* then the ids of each host-set key for `event` that names `host`, in key
|
|
166
|
+
* order, each id once. The same as covers_hosts.rs `claims_on`.
|
|
167
|
+
*/
|
|
168
|
+
export declare function coveredOn(covers: Readonly<Record<string, readonly string[]>> | undefined, event: string, host: CoreNextHost): string[];
|
|
151
169
|
/** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
|
|
152
170
|
export declare function uncoveredHooks(root: string, host: CoreNextHost, event: string, covers: Readonly<Record<string, readonly string[]>> | undefined, env?: NodeJS.ProcessEnv): string[];
|
|
153
171
|
/** Records the environment `target` was resolved under; returns `target`. */
|
|
@@ -1624,12 +1624,53 @@ export function precompactCompatibilityHold(root, env = process.env) {
|
|
|
1624
1624
|
}
|
|
1625
1625
|
return null;
|
|
1626
1626
|
}
|
|
1627
|
+
/** The hosts a COVERS host set may name (`Host::ALL` in crates/hq-hook/src/host/mod.rs). */
|
|
1628
|
+
export const COVERS_HOSTS = ['claude', 'codex', 'grok', 'fleet-local', 'agents-v2'];
|
|
1629
|
+
/**
|
|
1630
|
+
* A `covers` key read, as crates/hq-hook/src/covers_hosts.rs `key` reads it:
|
|
1631
|
+
* `Stop` claims for every host, `SubagentStop@codex,grok` for those hosts
|
|
1632
|
+
* only. Null when the key cannot be read (an empty or unknown host, a second
|
|
1633
|
+
* `@`, an event that is not ASCII letters): such a key claims nothing.
|
|
1634
|
+
*/
|
|
1635
|
+
export function coversKey(key) {
|
|
1636
|
+
const at = key.indexOf('@');
|
|
1637
|
+
const event = at < 0 ? key : key.slice(0, at);
|
|
1638
|
+
let hosts = null;
|
|
1639
|
+
if (at >= 0) {
|
|
1640
|
+
const set = key.slice(at + 1);
|
|
1641
|
+
hosts = set.split(',');
|
|
1642
|
+
if (set.includes('@') || !hosts.every((name) => COVERS_HOSTS.includes(name)))
|
|
1643
|
+
return null;
|
|
1644
|
+
}
|
|
1645
|
+
if (!/^[A-Za-z]+$/.test(event))
|
|
1646
|
+
return null;
|
|
1647
|
+
return { event, hosts };
|
|
1648
|
+
}
|
|
1649
|
+
/**
|
|
1650
|
+
* What `covers` claims for `event` on `host`: `covers[event]` (every host),
|
|
1651
|
+
* then the ids of each host-set key for `event` that names `host`, in key
|
|
1652
|
+
* order, each id once. The same as covers_hosts.rs `claims_on`.
|
|
1653
|
+
*/
|
|
1654
|
+
export function coveredOn(covers, event, host) {
|
|
1655
|
+
const out = [...(covers?.[event] ?? [])];
|
|
1656
|
+
for (const [key, ids] of Object.entries(covers ?? {})) {
|
|
1657
|
+
if (!key.includes('@'))
|
|
1658
|
+
continue;
|
|
1659
|
+
const read = coversKey(key);
|
|
1660
|
+
if (!read || read.event !== event || !read.hosts?.includes(host))
|
|
1661
|
+
continue;
|
|
1662
|
+
for (const id of ids)
|
|
1663
|
+
if (!out.includes(id))
|
|
1664
|
+
out.push(id);
|
|
1665
|
+
}
|
|
1666
|
+
return out;
|
|
1667
|
+
}
|
|
1627
1668
|
/** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
|
|
1628
1669
|
export function uncoveredHooks(root, host, event, covers, env = process.env) {
|
|
1629
1670
|
const hooks = shellHooks(root, host, event);
|
|
1630
1671
|
if (!hooks)
|
|
1631
1672
|
return [UNREADABLE];
|
|
1632
|
-
const covered = covers
|
|
1673
|
+
const covered = coveredOn(covers, event, host);
|
|
1633
1674
|
const missing = hooks.filter((hook) => !covered.some((claim) => claimCovers(claim, hook)));
|
|
1634
1675
|
if (event === 'Stop' && covered.includes('master-hook:Stop')) {
|
|
1635
1676
|
const hold = stopCompatibilityHold(root, env);
|
package/dist/lib/lanes/links.js
CHANGED
|
@@ -351,6 +351,82 @@ function sendQueue(root, link, child, text) {
|
|
|
351
351
|
appendDropboxMessageAtPath(pending, { at: new Date().toISOString(), text: cleanText });
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* The daemon's conduct-lanes-link-deliver run (a Codex SubagentStop note) sets
|
|
356
|
+
* HQ_LINK_DELIVER_QUEUED_AT_OR_BEFORE to the event's time, so `_deliver`
|
|
357
|
+
* takes only the messages queued at or before that event; later ones stay
|
|
358
|
+
* pending for the root's next PostToolUse or Stop. Unset: everything is taken,
|
|
359
|
+
* as before. Returns null for a value it cannot read (the caller then takes
|
|
360
|
+
* nothing).
|
|
361
|
+
*/
|
|
362
|
+
function deliverCutoff(env) {
|
|
363
|
+
const raw = env.HQ_LINK_DELIVER_QUEUED_AT_OR_BEFORE;
|
|
364
|
+
if (raw === undefined)
|
|
365
|
+
return undefined;
|
|
366
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?Z$/.test(raw))
|
|
367
|
+
return null;
|
|
368
|
+
const at = Date.parse(raw);
|
|
369
|
+
return Number.isFinite(at) ? at : null;
|
|
370
|
+
}
|
|
371
|
+
const HELD_LATER = "held-after-cutoff.jsonl";
|
|
372
|
+
/** Put back rows a cutoff held out of a take that did not finish (crash). Caller holds the queue lock. */
|
|
373
|
+
function restoreHeldRowsUnlocked(inbox) {
|
|
374
|
+
const held = path.join(inbox, HELD_LATER);
|
|
375
|
+
if (!fs.existsSync(held))
|
|
376
|
+
return;
|
|
377
|
+
const pending = path.join(inbox, "pending");
|
|
378
|
+
fs.mkdirSync(pending, { recursive: true });
|
|
379
|
+
const rows = fs.readFileSync(held, "utf8");
|
|
380
|
+
if (rows)
|
|
381
|
+
fs.appendFileSync(path.join(pending, "inbox.jsonl"), rows.endsWith("\n") ? rows : `${rows}\n`, { mode: 0o600 });
|
|
382
|
+
fs.rmSync(held, { force: true });
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Before a take with a cutoff: move the pending rows queued after the cutoff,
|
|
386
|
+
* and rows whose time cannot be read, to a held file beside pending, so the
|
|
387
|
+
* take sees only rows at or before it. Caller holds the queue lock and calls
|
|
388
|
+
* restoreHeldRowsUnlocked after the take.
|
|
389
|
+
*/
|
|
390
|
+
function holdRowsAfterCutoffUnlocked(inbox, cutoff) {
|
|
391
|
+
const file = path.join(inbox, "pending", "inbox.jsonl");
|
|
392
|
+
if (!fs.existsSync(file))
|
|
393
|
+
return;
|
|
394
|
+
const due = [];
|
|
395
|
+
const later = [];
|
|
396
|
+
for (const line of fs.readFileSync(file, "utf8").split(/\r?\n/)) {
|
|
397
|
+
if (!line)
|
|
398
|
+
continue;
|
|
399
|
+
let at = Number.NaN;
|
|
400
|
+
try {
|
|
401
|
+
const row = JSON.parse(line);
|
|
402
|
+
const value = row && typeof row === "object" ? row.at : undefined;
|
|
403
|
+
if (typeof value === "string")
|
|
404
|
+
at = Date.parse(value);
|
|
405
|
+
}
|
|
406
|
+
catch { /* unreadable rows are not ours to take */ }
|
|
407
|
+
(Number.isFinite(at) && at <= cutoff ? due : later).push(line);
|
|
408
|
+
}
|
|
409
|
+
if (!later.length)
|
|
410
|
+
return;
|
|
411
|
+
fs.writeFileSync(path.join(inbox, HELD_LATER), `${later.join("\n")}\n`, { mode: 0o600 });
|
|
412
|
+
if (due.length)
|
|
413
|
+
fs.writeFileSync(file, `${due.join("\n")}\n`, { mode: 0o600 });
|
|
414
|
+
else
|
|
415
|
+
fs.rmSync(file, { force: true });
|
|
416
|
+
}
|
|
417
|
+
/** Run a take on the queue, limited to rows queued at or before cutoff when one is given. Caller holds the queue lock. */
|
|
418
|
+
function takeUpToUnlocked(inbox, cutoff, take) {
|
|
419
|
+
restoreHeldRowsUnlocked(inbox);
|
|
420
|
+
if (cutoff === undefined)
|
|
421
|
+
return take();
|
|
422
|
+
holdRowsAfterCutoffUnlocked(inbox, cutoff);
|
|
423
|
+
try {
|
|
424
|
+
return take();
|
|
425
|
+
}
|
|
426
|
+
finally {
|
|
427
|
+
restoreHeldRowsUnlocked(inbox);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
354
430
|
/** Claims pending files by renaming the whole queue, matching conduct-inbox's no-loss drain. */
|
|
355
431
|
function drainLinkQueueUnlocked(inbox) {
|
|
356
432
|
const pending = path.join(inbox, "pending");
|
|
@@ -543,9 +619,6 @@ function claimLinkQueueUnlocked(inbox) {
|
|
|
543
619
|
}
|
|
544
620
|
return { messages: messages.join("\n"), claims };
|
|
545
621
|
}
|
|
546
|
-
function claimLinkQueue(inbox) {
|
|
547
|
-
return withLinkQueueLock(inbox, () => claimLinkQueueUnlocked(inbox));
|
|
548
|
-
}
|
|
549
622
|
function acknowledgeLinkClaims(inbox, claims) {
|
|
550
623
|
return withLinkQueueLock(inbox, () => acknowledgeLinkClaimsUnlocked(inbox, claims));
|
|
551
624
|
}
|
|
@@ -734,21 +807,29 @@ export async function runLaneLink(subcommand, options) {
|
|
|
734
807
|
const target = hookMessage(root, pointer);
|
|
735
808
|
if (options.ackMode !== undefined && options.ackMode !== "explicit")
|
|
736
809
|
throw new LaneLinkError("ack_mode_invalid", "Unsupported acknowledgement mode");
|
|
810
|
+
// A cutoff it cannot read: take nothing, everything stays queued.
|
|
811
|
+
const cutoff = deliverCutoff(env);
|
|
812
|
+
if (cutoff === null)
|
|
813
|
+
return {};
|
|
737
814
|
let claim;
|
|
738
815
|
let messages;
|
|
739
816
|
if (pointer.role === "conductor") {
|
|
740
817
|
await options.beforeConductorQueue?.();
|
|
741
|
-
const drained = withConductorQueue(root, pointer.link, sid, (inbox) => options.ackMode === "explicit"
|
|
818
|
+
const drained = withConductorQueue(root, pointer.link, sid, (inbox) => takeUpToUnlocked(inbox, cutoff, () => options.ackMode === "explicit"
|
|
742
819
|
? { claim: claimLinkQueueUnlocked(inbox), messages: "" }
|
|
743
|
-
: { claim: undefined, messages: drainLinkQueueUnlocked(inbox) });
|
|
820
|
+
: { claim: undefined, messages: drainLinkQueueUnlocked(inbox) }));
|
|
744
821
|
if (drained === null)
|
|
745
822
|
return {};
|
|
746
823
|
claim = drained.claim;
|
|
747
824
|
messages = claim ? claim.messages : drained.messages;
|
|
748
825
|
}
|
|
749
826
|
else {
|
|
750
|
-
|
|
751
|
-
|
|
827
|
+
const inbox = target.inbox;
|
|
828
|
+
const taken = withLinkQueueLock(inbox, () => takeUpToUnlocked(inbox, cutoff, () => options.ackMode === "explicit"
|
|
829
|
+
? { claim: claimLinkQueueUnlocked(inbox), messages: "" }
|
|
830
|
+
: { claim: undefined, messages: drainLinkQueueUnlocked(inbox) }));
|
|
831
|
+
claim = taken.claim;
|
|
832
|
+
messages = claim ? claim.messages : taken.messages;
|
|
752
833
|
}
|
|
753
834
|
if (!messages)
|
|
754
835
|
return {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* End the CLI with `code` after the flag-registry worker has stopped.
|
|
3
|
+
* Use `return await exitCli(code)` (or `await exitCli(code)` as the last
|
|
4
|
+
* statement) so no code runs past the call while the worker stops.
|
|
5
|
+
*/
|
|
6
|
+
export declare function exitCli(code: number): Promise<never>;
|
|
7
|
+
//# sourceMappingURL=exit-after-worker.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { stopFlagRegistryWorker } from "../lib/flag-registry.js";
|
|
2
|
+
/**
|
|
3
|
+
* End the CLI with `code` after the flag-registry worker has stopped.
|
|
4
|
+
* Use `return await exitCli(code)` (or `await exitCli(code)` as the last
|
|
5
|
+
* statement) so no code runs past the call while the worker stops.
|
|
6
|
+
*/
|
|
7
|
+
export async function exitCli(code) {
|
|
8
|
+
try {
|
|
9
|
+
await stopFlagRegistryWorker();
|
|
10
|
+
}
|
|
11
|
+
finally {
|
|
12
|
+
process.exit(code);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=exit-after-worker.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigoai-us/hq-cli",
|
|
3
|
-
"version": "5.345.
|
|
3
|
+
"version": "5.345.231",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -125,11 +125,11 @@
|
|
|
125
125
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
126
126
|
},
|
|
127
127
|
"optionalDependencies": {
|
|
128
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
129
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
130
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
131
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
132
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
133
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
128
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.231",
|
|
129
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.231",
|
|
130
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.231",
|
|
131
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.231",
|
|
132
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.231",
|
|
133
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.231"
|
|
134
134
|
}
|
|
135
135
|
}
|