@indigoai-us/hq-cli 5.345.228 → 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.
@@ -1 +1 @@
1
- {"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.110","bundleSha256":"f07bdb64deac33e3fd132bfae7452fb8fb207e0b465b0da77b0fcc323a280bf5","formatVersion":1}
1
+ {"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.112","bundleSha256":"8c9e1034d6fc5a89949c510ab5283c7e965e3c645e4c7e00695b10e299cb6837","formatVersion":1}
@@ -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
@@ -0,0 +1,21 @@
1
+ import { type HookRequest, type HookRequestResult } from "./hook-requests.js";
2
+ export type ConductLinkKind = "conduct-lanes-link-deliver" | "conduct-link-inherit";
3
+ export type ConductLinkOperation = {
4
+ kind: ConductLinkKind;
5
+ sessionId: string;
6
+ queuedAtOrBefore?: string;
7
+ };
8
+ /** The root's hook script each kind runs, with the event the adapter gave it. */
9
+ export declare const CONDUCT_LINK_SCRIPTS: Readonly<Record<ConductLinkKind, string>>;
10
+ /** The adapter ran both through its PostToolUse dispatch (`dispatch_settings_hooks "PostToolUse" "Agent"`). */
11
+ export declare const CONDUCT_LINK_EVENT = "PostToolUse";
12
+ export declare function isConductLinkKind(kind: unknown): kind is ConductLinkKind;
13
+ /** The operation in a conduct note's `args`, or undefined for anything the hook does not write. */
14
+ export declare function parseConductLink(kind: ConductLinkKind, args: Record<string, unknown>, session: unknown): ConductLinkOperation | undefined;
15
+ /** Run the root's hook script for one conduct note (see the file comment). */
16
+ export declare function runConductLink(request: HookRequest, operation: ConductLinkOperation, base: NodeJS.ProcessEnv, options: {
17
+ signal?: AbortSignal;
18
+ timeoutMs: number;
19
+ killGraceMs: number;
20
+ }): Promise<HookRequestResult>;
21
+ //# sourceMappingURL=hook-requests-conduct-link.d.ts.map
@@ -0,0 +1,122 @@
1
+ /**
2
+ * The two programs the Codex adapter started at SubagentStop for conduct
3
+ * links, run by the daemon instead (standing rule b; `conduct_lanes_link_deliver`
4
+ * and `conduct_link_inherit_settle` in crates/hq-hook/src/daemon_req.rs).
5
+ *
6
+ * The hq-core v16.0.47 Codex adapter (`hq-codex-hook-adapter.sh`, its
7
+ * `SubagentStop)` arm) fed the completed lifecycle payload through the root's
8
+ * Agent-matched PostToolUse hooks. Two of them start programs:
9
+ *
10
+ * - `conduct-lanes-link-deliver`: `.claude/hooks/conduct-lanes-link-deliver.sh
11
+ * PostToolUse`, which for a root session with a
12
+ * `workspace/lanes-links/by-session/<sid>` pointer runs
13
+ * `hq lanes link _deliver --event PostToolUse` with the payload on stdin.
14
+ * - `conduct-link-inherit`: `.claude/hooks/conduct-link-inherit.sh PostToolUse`,
15
+ * which runs `node core/scripts/lib/conduct-link-inherit.mjs PostToolUse
16
+ * <root>`; its `settle` joins a pending claim of the session to its conduct
17
+ * link once the session's companies are bound, and sweeps stale claims.
18
+ *
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). 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
26
+ * root's own hook script, `bash <root>/.claude/hooks/<script> PostToolUse`,
27
+ * with `{"session_id": <sid>}` on stdin:
28
+ *
29
+ * - The program and its arguments are an argv array, no shell; the session id
30
+ * reaches the script only inside the JSON on stdin.
31
+ * - A root without the script: done, nothing is started (the adapter's
32
+ * launcher found no file and went on).
33
+ * - `HQ_ROOT` and `CLAUDE_PROJECT_DIR` are the note's root, as the adapter's
34
+ * launcher set them. The daemon's own `HQ_HOOK_AGENT_ID` is not the
35
+ * session's and is removed: the writer decided the event was a root's before
36
+ * it left the note.
37
+ * - Output is not read: the adapter's `emit_context` has no SubagentStop
38
+ * shape, so what the hooks printed was dropped there too.
39
+ * - Exit status ignored when the script ended by itself (both scripts exit 0
40
+ * on every path); a run stopped at the limit or by a daemon stop is a failed
41
+ * try.
42
+ */
43
+ import * as fs from "node:fs";
44
+ import * as path from "node:path";
45
+ // A cycle with hook-requests.ts, which dispatches to this module: each side uses the other only inside functions.
46
+ import { spawnRequestProgram } from "./hook-requests.js";
47
+ /** The root's hook script each kind runs, with the event the adapter gave it. */
48
+ export const CONDUCT_LINK_SCRIPTS = {
49
+ "conduct-lanes-link-deliver": ".claude/hooks/conduct-lanes-link-deliver.sh",
50
+ "conduct-link-inherit": ".claude/hooks/conduct-link-inherit.sh",
51
+ };
52
+ /** The adapter ran both through its PostToolUse dispatch (`dispatch_settings_hooks "PostToolUse" "Agent"`). */
53
+ export const CONDUCT_LINK_EVENT = "PostToolUse";
54
+ /**
55
+ * A session id a conduct note carries (`conduct_session` in daemon_req.rs): the
56
+ * scripts' own `^[A-Za-z0-9._-]+$`, not `.` or `..`, at most 512 characters.
57
+ */
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$/;
61
+ export function isConductLinkKind(kind) {
62
+ return kind === "conduct-lanes-link-deliver" || kind === "conduct-link-inherit";
63
+ }
64
+ /** The operation in a conduct note's `args`, or undefined for anything the hook does not write. */
65
+ export function parseConductLink(kind, args, session) {
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"))
69
+ return undefined;
70
+ const sessionId = args.session_id;
71
+ if (typeof sessionId !== "string" || !CONDUCT_SESSION.test(sessionId) || sessionId === "." || sessionId === ".."
72
+ || sessionId !== session)
73
+ return undefined;
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 };
80
+ }
81
+ /** Run the root's hook script for one conduct note (see the file comment). */
82
+ export async function runConductLink(request, operation, base, options) {
83
+ const script = path.join(request.root, CONDUCT_LINK_SCRIPTS[operation.kind]);
84
+ try {
85
+ if (!fs.statSync(script).isFile())
86
+ return { code: 0 };
87
+ }
88
+ catch {
89
+ return { code: 0 };
90
+ }
91
+ const env = { ...base };
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;
97
+ Object.assign(env, { HQ_ROOT: request.root, CLAUDE_PROJECT_DIR: request.root, HQ_HOOK_REQUEST_ID: request.id });
98
+ const input = JSON.stringify({ session_id: operation.sessionId });
99
+ return new Promise(resolve => {
100
+ if (options.signal?.aborted) {
101
+ resolve({ code: 1 });
102
+ return;
103
+ }
104
+ const { child, settle } = spawnRequestProgram("bash", [script, CONDUCT_LINK_EVENT], {
105
+ cwd: request.root, env, windowsHide: true, stdio: ["pipe", "ignore", "ignore"],
106
+ }, { timeoutMs: options.timeoutMs, killGraceMs: options.killGraceMs, ...(options.signal ? { signal: options.signal } : {}) });
107
+ // A script that exits before it reads leaves a closed pipe; its exit status is the result.
108
+ child.stdin?.on("error", () => undefined);
109
+ child.stdin?.end(input);
110
+ let settled = false;
111
+ const done = (exited) => {
112
+ if (settled)
113
+ return;
114
+ settled = true;
115
+ const ended = settle();
116
+ resolve({ code: !ended && exited ? 0 : 1 });
117
+ };
118
+ child.once("error", () => done(false));
119
+ child.once("close", (code, signal) => done(code !== null && signal === null));
120
+ });
121
+ }
122
+ //# sourceMappingURL=hook-requests-conduct-link.js.map
@@ -6,6 +6,8 @@
6
6
  * (decision 36), `fleet-local-settings` (US-050 c2, conductor ruling on #3042), and the mesh kinds
7
7
  * `mesh-reconcile` and `mesh-register-retry` (hook-requests-mesh.ts).
8
8
  * Also `fleet-session-start`, US-050 c2 (hook-requests-fleet-session-start.ts).
9
+ * Also `conduct-lanes-link-deliver` and `conduct-link-inherit`, the Codex adapter's
10
+ * SubagentStop conduct-link runs (hook-requests-conduct-link.ts).
9
11
  *
10
12
  * A hook that used to re-index, commit, copy a plan or edit a pull request
11
13
  * now only decides that the work is due and leaves one small file in
@@ -52,6 +54,8 @@ import { type MeshOperation } from "./hook-requests-mesh.js";
52
54
  import { type MachineCheckResult, type RunMachineChecksOptions } from "./machine-checks.js";
53
55
  import { type MeshToolWritesOperation } from "./hook-requests-mesh-tool-writes.js";
54
56
  import { type FleetSessionStartOperation } from "./hook-requests-fleet-session-start.js";
57
+ import { type ConductLinkOperation } from "./hook-requests-conduct-link.js";
58
+ import { type CodexSettingsOperation } from "./hook-requests-codex-settings.js";
55
59
  /** What the daemon is asked to do. A closed list, the same as `Kind` in daemon_req.rs. */
56
60
  export type HookOperation = {
57
61
  kind: "reindex";
@@ -85,7 +89,7 @@ export type HookOperation = {
85
89
  * adapter's payload is the note's `.body` file (`host::fleet_settings`). */
86
90
  | {
87
91
  kind: "fleet-local-settings";
88
- event: "PostToolUse";
92
+ event: "PostToolUse" | "SessionEnd";
89
93
  commands: FleetLocalSettingsCommand[];
90
94
  }
91
95
  /** The Work Mesh register step of a mid-session company bind (`spawn_work_mesh_register`, owner decision 36). */
@@ -104,7 +108,9 @@ export type HookOperation = {
104
108
  disabled?: MeshSessionBindSwitch;
105
109
  }
106
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). */
107
- | MachineCheckOperation | MeshOperation | MeshToolWritesOperation | FleetSessionStartOperation;
111
+ | MachineCheckOperation | MeshOperation | MeshToolWritesOperation | CodexSettingsOperation | FleetSessionStartOperation
112
+ /** The Codex adapter's SubagentStop runs of the root's conduct-link hooks (hook-requests-conduct-link.ts). */
113
+ | ConductLinkOperation;
108
114
  /**
109
115
  * One command of a `fleet-local-settings` note, a record of the adapter's `hqad_iter_settings`. Typed fields only: the
110
116
  * daemon builds the program and its arguments (`fleetLocalSettingsProgram`).
@@ -6,6 +6,8 @@
6
6
  * (decision 36), `fleet-local-settings` (US-050 c2, conductor ruling on #3042), and the mesh kinds
7
7
  * `mesh-reconcile` and `mesh-register-retry` (hook-requests-mesh.ts).
8
8
  * Also `fleet-session-start`, US-050 c2 (hook-requests-fleet-session-start.ts).
9
+ * Also `conduct-lanes-link-deliver` and `conduct-link-inherit`, the Codex adapter's
10
+ * SubagentStop conduct-link runs (hook-requests-conduct-link.ts).
9
11
  *
10
12
  * A hook that used to re-index, commit, copy a plan or edit a pull request
11
13
  * now only decides that the work is due and leaves one small file in
@@ -57,6 +59,8 @@ import { parseMeshOperation, runMeshReconcile, runMeshRegisterRetry } from "./ho
57
59
  import { MACHINE_CHECKS, machineCheckCollectOnlySupported, runMachineChecks } from "./machine-checks.js";
58
60
  import { parseMeshToolWrites, runMeshToolWrites } from "./hook-requests-mesh-tool-writes.js";
59
61
  import { parseFleetSessionStart, runFleetSessionStart } from "./hook-requests-fleet-session-start.js";
62
+ import { isConductLinkKind, parseConductLink, runConductLink } from "./hook-requests-conduct-link.js";
63
+ import { parseCodexSettings, runCodexSettings } from "./hook-requests-codex-settings.js";
60
64
  /** The longest note the Rust writer leaves (`NOTE_MAX_BYTES`). */
61
65
  export const HOOK_REQUEST_MAX_BYTES = 4096;
62
66
  /** The longest `.body` file the Rust writer leaves (`BODY_MAX_BYTES`). */
@@ -298,6 +302,18 @@ export function parseHookRequest(text, stem) {
298
302
  return undefined;
299
303
  operation = fleet;
300
304
  }
305
+ else if (isConductLinkKind(value.kind)) {
306
+ const conduct = parseConductLink(value.kind, args, value.session);
307
+ if (!conduct)
308
+ return undefined;
309
+ operation = conduct;
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
+ }
301
317
  else if (isMachineCheckRequestKind(value.kind)) {
302
318
  const check = parseMachineCheckOperation(value.kind, args);
303
319
  if (!check)
@@ -312,10 +328,11 @@ export function parseHookRequest(text, stem) {
312
328
  }
313
329
  return { stem, id: value.id, at, root: value.hqRoot, session: value.session, operation };
314
330
  }
315
- /** 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. */
316
332
  function parseFleetLocalSettings(args) {
317
333
  const keys = Object.keys(args).sort();
318
- if (keys.length !== 2 || keys[0] !== "commands" || keys[1] !== "event" || args.event !== "PostToolUse")
334
+ const event = args.event;
335
+ if (keys.length !== 2 || keys[0] !== "commands" || keys[1] !== "event" || (event !== "PostToolUse" && event !== "SessionEnd"))
319
336
  return undefined;
320
337
  const list = args.commands;
321
338
  if (!Array.isArray(list) || list.length === 0 || list.length > FLEET_LOCAL_SETTINGS_MAX_COMMANDS)
@@ -353,7 +370,7 @@ function parseFleetLocalSettings(args) {
353
370
  return undefined;
354
371
  }
355
372
  }
356
- return { kind: "fleet-local-settings", event: "PostToolUse", commands };
373
+ return { kind: "fleet-local-settings", event, commands };
357
374
  }
358
375
  /** A project as the plan-sync writer leaves it: a path under the HQ root, relative, with no `..` part. */
359
376
  function hookRequestProject(project) {
@@ -365,6 +382,7 @@ export function hookRequestHasBody(operation) {
365
382
  return operation.kind === "plan-sync"
366
383
  || operation.kind === "startwork-prefetch"
367
384
  || operation.kind === "fleet-local-settings"
385
+ || operation.kind === "codex-settings"
368
386
  || operation.kind === "fleet-session-start";
369
387
  }
370
388
  /** The helper a plan-sync request runs, inside the HQ root. */
@@ -398,7 +416,12 @@ export function hookRequestArguments(request) {
398
416
  case "acl-suggest":
399
417
  case "session-close": return undefined;
400
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 [];
401
421
  case "fleet-session-start": return [];
422
+ // Not a CLI request: the root's own conduct-link hook script is run (`runConductLink`).
423
+ case "conduct-lanes-link-deliver":
424
+ case "conduct-link-inherit": return [];
402
425
  }
403
426
  }
404
427
  /**
@@ -1580,6 +1603,8 @@ export function executeHookRequest(request, options) {
1580
1603
  return runMeshToolWrites(operation, { ...options, root: request.root });
1581
1604
  if (operation.kind === "fleet-session-start")
1582
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 }));
1583
1608
  const cliArgs = hookRequestArguments(request);
1584
1609
  if (!cliArgs)
1585
1610
  return Promise.resolve({ code: 1 });
@@ -1595,6 +1620,12 @@ export function executeHookRequest(request, options) {
1595
1620
  timeoutMs: options.timeoutMs ?? HOOK_REQUEST_KILL_MS, ...(options.log ? { log: options.log } : {}),
1596
1621
  }).catch(() => ({ code: 1 }));
1597
1622
  }
1623
+ if (request.operation.kind === "conduct-lanes-link-deliver" || request.operation.kind === "conduct-link-inherit") {
1624
+ return runConductLink(request, request.operation, base, {
1625
+ ...(options.signal ? { signal: options.signal } : {}), killGraceMs,
1626
+ timeoutMs: options.timeoutMs ?? HOOK_REQUEST_KILL_MS,
1627
+ }).catch(() => ({ code: 1 }));
1628
+ }
1598
1629
  if (request.operation.kind === "startwork-prefetch") {
1599
1630
  return runStartworkPrefetch(request, request.operation, base, {
1600
1631
  ...(options.signal ? { signal: options.signal } : {}), killGraceMs,