@indigoai-us/hq-cli 5.345.226 → 5.345.228

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.
Files changed (132) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/dist/command-catalog.generated.d.ts +137 -0
  3. package/dist/command-catalog.generated.js +164 -0
  4. package/dist/commands/auth.d.ts +2 -2
  5. package/dist/commands/auth.js +3 -3
  6. package/dist/commands/core-delegate-w1b.js +92 -69
  7. package/dist/commands/core-delegate.d.ts +19 -1
  8. package/dist/commands/core-delegate.js +411 -6
  9. package/dist/commands/core-dm-bind-native.js +2 -1
  10. package/dist/commands/core-handoff.d.ts +5 -0
  11. package/dist/commands/core-handoff.js +1008 -14
  12. package/dist/commands/core-pin-native.d.ts +1 -0
  13. package/dist/commands/core-pin-native.js +3 -15
  14. package/dist/commands/core-register-project-native.d.ts +6 -0
  15. package/dist/commands/core-register-project-native.js +182 -52
  16. package/dist/commands/core-work-mesh-bind-trusted-native.js +4 -9
  17. package/dist/commands/daemon.js +2 -2
  18. package/dist/commands/index-cmd.d.ts +3 -1
  19. package/dist/commands/index-cmd.js +12 -0
  20. package/dist/commands/lanes-checks.js +1 -1
  21. package/dist/commands/lanes-session-start.d.ts +1 -2
  22. package/dist/commands/lanes-session-start.js +9 -145
  23. package/dist/commands/lanes-shared.d.ts +3 -0
  24. package/dist/commands/lanes.d.ts +3 -0
  25. package/dist/commands/lanes.js +94 -27
  26. package/dist/commands/link.d.ts +8 -3
  27. package/dist/commands/link.js +14 -17
  28. package/dist/commands/mcp-registration.d.ts +65 -7
  29. package/dist/commands/mcp-registration.js +289 -51
  30. package/dist/commands/mesh.d.ts +12 -0
  31. package/dist/commands/mesh.js +92 -10
  32. package/dist/commands/reindex.js +6 -0
  33. package/dist/commands/repo.d.ts +13 -0
  34. package/dist/commands/repo.js +39 -1
  35. package/dist/commands/sync-mode.d.ts +3 -1
  36. package/dist/commands/sync-mode.js +11 -1
  37. package/dist/lazy-commands.js +3 -4
  38. package/dist/lib/checkpoint-ontology/entity-file.js +4 -4
  39. package/dist/lib/checkpoint-ontology/merge-copies.js +7 -11
  40. package/dist/lib/checkpoint-ontology/plan.js +2 -1
  41. package/dist/lib/core-utils/archive-old-threads.js +5 -2
  42. package/dist/lib/core-utils/session-company.d.ts +13 -1
  43. package/dist/lib/core-utils/session-company.js +75 -4
  44. package/dist/lib/core-utils/worktree-resume.d.ts +6 -0
  45. package/dist/lib/core-utils/worktree-resume.js +8 -4
  46. package/dist/lib/daemon/background-qos.d.ts +7 -0
  47. package/dist/lib/daemon/background-qos.js +13 -0
  48. package/dist/lib/daemon/catalog.d.ts +9 -0
  49. package/dist/lib/daemon/catalog.js +8 -1
  50. package/dist/lib/daemon/hook-requests-acl-suggest.d.ts +18 -0
  51. package/dist/lib/daemon/hook-requests-acl-suggest.js +245 -0
  52. package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +32 -0
  53. package/dist/lib/daemon/hook-requests-fleet-session-start.js +214 -0
  54. package/dist/lib/daemon/hook-requests-mesh-tool-writes.d.ts +44 -0
  55. package/dist/lib/daemon/hook-requests-mesh-tool-writes.js +292 -0
  56. package/dist/lib/daemon/hook-requests-mesh.d.ts +54 -0
  57. package/dist/lib/daemon/hook-requests-mesh.js +559 -0
  58. package/dist/lib/daemon/hook-requests.d.ts +349 -8
  59. package/dist/lib/daemon/hook-requests.js +1312 -46
  60. package/dist/lib/daemon/machine-checks.d.ts +12 -2
  61. package/dist/lib/daemon/machine-checks.js +27 -10
  62. package/dist/lib/daemon/merge-sections.d.ts +24 -2
  63. package/dist/lib/daemon/merge-sections.js +58 -16
  64. package/dist/lib/daemon/ops/policy.js +4 -2
  65. package/dist/lib/daemon/resolver.js +9 -2
  66. package/dist/lib/daemon/run.d.ts +11 -7
  67. package/dist/lib/daemon/run.js +168 -24
  68. package/dist/lib/daemon/search-index-worker-v1.d.ts +2 -0
  69. package/dist/lib/daemon/search-index-worker-v1.js +25 -0
  70. package/dist/lib/daemon/session-registry.d.ts +0 -1
  71. package/dist/lib/daemon/session-registry.js +0 -3
  72. package/dist/lib/daemon/supervisor.d.ts +3 -1
  73. package/dist/lib/daemon/supervisor.js +1 -1
  74. package/dist/lib/daemon/tcc-eperm.d.ts +59 -4
  75. package/dist/lib/daemon/tcc-eperm.js +110 -8
  76. package/dist/lib/doctor/fix/process-identity.d.ts +20 -2
  77. package/dist/lib/doctor/fix/process-identity.js +48 -5
  78. package/dist/lib/hook-engine/canary-gate.js +1 -0
  79. package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
  80. package/dist/lib/hot-channels/adapters/attio.js +2 -1
  81. package/dist/lib/hot-channels/adapters/meetings.js +2 -1
  82. package/dist/lib/lanes/company-outposts.d.ts +37 -0
  83. package/dist/lib/lanes/company-outposts.js +164 -0
  84. package/dist/lib/lanes/liveness.d.ts +6 -0
  85. package/dist/lib/lanes/liveness.js +49 -8
  86. package/dist/lib/lanes/orphan-report.d.ts +15 -0
  87. package/dist/lib/lanes/orphan-report.js +223 -0
  88. package/dist/lib/lanes/orphan-sweep.d.ts +26 -0
  89. package/dist/lib/lanes/orphan-sweep.js +152 -0
  90. package/dist/lib/lanes/reaper.d.ts +2 -0
  91. package/dist/lib/lanes/reaper.js +11 -8
  92. package/dist/lib/lanes/reconcile.d.ts +8 -7
  93. package/dist/lib/lanes/reconcile.js +39 -0
  94. package/dist/lib/mesh/live/backfill-held.d.ts +13 -0
  95. package/dist/lib/mesh/live/backfill-held.js +23 -0
  96. package/dist/lib/mesh/live/daemon/mode.d.ts +8 -4
  97. package/dist/lib/mesh/live/daemon/mode.js +8 -4
  98. package/dist/lib/mesh/live/daemon/run.d.ts +14 -3
  99. package/dist/lib/mesh/live/daemon/run.js +116 -7
  100. package/dist/lib/mesh/live/direct-drain.d.ts +123 -0
  101. package/dist/lib/mesh/live/direct-drain.js +315 -0
  102. package/dist/lib/mesh/live/emit-replay.d.ts +10 -0
  103. package/dist/lib/mesh/live/emit-replay.js +10 -0
  104. package/dist/lib/mesh/live/flush.d.ts +15 -0
  105. package/dist/lib/mesh/live/flush.js +27 -0
  106. package/dist/lib/mesh/live/liveness-carry.d.ts +45 -0
  107. package/dist/lib/mesh/live/liveness-carry.js +141 -0
  108. package/dist/lib/mesh/live/spool.d.ts +19 -0
  109. package/dist/lib/mesh/live/spool.js +80 -0
  110. package/dist/lib/safe-store.d.ts +2 -0
  111. package/dist/lib/safe-store.js +8 -6
  112. package/dist/lib/search-index/index.d.ts +9 -3
  113. package/dist/lib/search-index/index.js +35 -10
  114. package/dist/lib/search-index/worker-process.d.ts +9 -0
  115. package/dist/lib/search-index/worker-process.js +171 -0
  116. package/dist/lib/session-company-lock.d.ts +3 -1
  117. package/dist/lib/session-company-lock.js +3 -2
  118. package/dist/utils/delegate-command-supervisor.d.ts +3 -0
  119. package/dist/utils/delegate-command-supervisor.js +44 -0
  120. package/dist/utils/delegate-lock.d.ts +12 -0
  121. package/dist/utils/delegate-lock.js +88 -0
  122. package/dist/utils/frontmatter.d.ts +27 -0
  123. package/dist/utils/frontmatter.js +33 -0
  124. package/dist/utils/hook-trust.d.ts +1 -0
  125. package/dist/utils/hook-trust.js +18 -2
  126. package/dist/utils/host-registration.d.ts +13 -1
  127. package/dist/utils/host-registration.js +98 -5
  128. package/dist/utils/package-use-lease.d.ts +1 -1
  129. package/dist/utils/package-use-lease.js +15 -7
  130. package/docs/anywhere-runtime.md +17 -0
  131. package/package.json +8 -7
  132. package/scripts/check-function-manifest.mjs +17 -3
@@ -1,6 +1,128 @@
1
+ /** Consumer for the request notes hq-hook leaves on PostToolUse
2
+ * (crates/hq-hook/src/daemon_req.rs; hq-core-rust owner decision 26).
3
+ *
4
+ * Kinds: `reindex`, `autocommit` (decision 48 for its failure file),
5
+ * `plan-sync`, `pr-footer` (decision 47), `session-close`, `mesh-session-bind`
6
+ * (decision 36), `fleet-local-settings` (US-050 c2, conductor ruling on #3042), and the mesh kinds
7
+ * `mesh-reconcile` and `mesh-register-retry` (hook-requests-mesh.ts).
8
+ * Also `fleet-session-start`, US-050 c2 (hook-requests-fleet-session-start.ts).
9
+ *
10
+ * A hook that used to re-index, commit, copy a plan or edit a pull request
11
+ * now only decides that the work is due and leaves one small file in
12
+ * `~/.hq/daemon/hook-requests/<root key>/<kind>-<key>.json`. This module is
13
+ * the other half: the running daemon takes the notes of its own HQ root,
14
+ * oldest first, and does the work. No process is added: the drainer runs in
15
+ * the daemon, beside the Stop job drainer, under the same lease.
16
+ *
17
+ * A note is data, never a command. Only the kinds listed here are accepted,
18
+ * each with its own typed fields, and the arguments of the program that is
19
+ * started are built here from the validated fields.
20
+ *
21
+ * Life of a note `X.json`:
22
+ * - Invalid (version, kind, fields, size, another HQ root): deleted, one log line, nothing runs.
23
+ * - Older than a day: deleted, one log line, never run (for an autosave the
24
+ * session's failure file is left, as for a note that is given up). The age is counted
25
+ * from the note's own time, and the hook writes a waiting note again on
26
+ * every new request for the same thing, so it is the age of the newest
27
+ * request, not of the first.
28
+ * - A folder, link or FIFO where a note or a claimed note should be is never
29
+ * run. It is deleted; one that cannot be deleted (a folder) is reported
30
+ * once per daemon run and left.
31
+ * - Claimed by renaming it to `X.run` before the work starts, so a request
32
+ * made during the work is a new `X.json` and runs afterwards.
33
+ * - A kind with text (plan-sync, fleet-local-settings) has it in `X.body`, written before the note.
34
+ * A claimed note whose body is missing or too long is deleted with one log
35
+ * line and nothing runs: the same request, made again while its first copy
36
+ * ran, loses its body when that copy finishes, and its text was just filed.
37
+ * When the first copy fails instead, its text was not filed: the body stays
38
+ * for the newer note. A body with no note and no claimed note, a day old,
39
+ * was left by a hook that died between its two writes and is deleted.
40
+ * - Done: `X.run` and its side files are deleted.
41
+ * - Not started because the work's own lock is held (`later`): put back as
42
+ * it was, no try counted, looked at again after 5 s. Only the day limit
43
+ * ends such a note.
44
+ * - Failed, or found as `X.run` at the start of a pass (the daemon stopped
45
+ * mid-work): the count in `X.attempts` goes up and the note is put back,
46
+ * unless a newer `X.json` is already there. It runs again after 5 s, then
47
+ * after 30 s. After the third failure it is deleted with one log line.
48
+ */
49
+ import { type ChildProcess, type SpawnOptions } from "node:child_process";
50
+ import { type ShareCandidate } from "./hook-requests-acl-suggest.js";
51
+ import { type MeshOperation } from "./hook-requests-mesh.js";
52
+ import { type MachineCheckResult, type RunMachineChecksOptions } from "./machine-checks.js";
53
+ import { type MeshToolWritesOperation } from "./hook-requests-mesh-tool-writes.js";
54
+ import { type FleetSessionStartOperation } from "./hook-requests-fleet-session-start.js";
1
55
  /** What the daemon is asked to do. A closed list, the same as `Kind` in daemon_req.rs. */
2
56
  export type HookOperation = {
3
57
  kind: "reindex";
58
+ } | {
59
+ kind: "acl-suggest";
60
+ candidates: ShareCandidate[];
61
+ } | {
62
+ kind: "autocommit";
63
+ path: string;
64
+ }
65
+ /** intent-hint's `/startwork <argument>` company prefetch (`startwork_prefetch` note, prompt_up6/intent_hint.rs): the prompt is the note's `.body` file. */
66
+ | {
67
+ kind: "startwork-prefetch";
68
+ sessionId: string;
69
+ }
70
+ /** File a plan under a project: `project` is a path under the HQ root, the plan text is the note's `.body` file. */
71
+ | {
72
+ kind: "plan-sync";
73
+ project: string;
74
+ } | {
75
+ kind: "pr-footer";
76
+ url: string;
77
+ }
78
+ /** hqd's `session.close`, done in the daemon's own session registry (master-hook's SessionEnd shim call). */
79
+ | {
80
+ kind: "session-close";
81
+ runtime: "claude";
82
+ sessionId: string;
83
+ }
84
+ /** The fleet-local adapter's `.claude/settings.json` PostToolUse commands for one tool call, as the hook read them; the
85
+ * adapter's payload is the note's `.body` file (`host::fleet_settings`). */
86
+ | {
87
+ kind: "fleet-local-settings";
88
+ event: "PostToolUse";
89
+ commands: FleetLocalSettingsCommand[];
90
+ }
91
+ /** The Work Mesh register step of a mid-session company bind (`spawn_work_mesh_register`, owner decision 36). */
92
+ | {
93
+ kind: "mesh-session-bind";
94
+ sessionId: string;
95
+ cwd: string;
96
+ company: string;
97
+ disabled?: MeshSessionBindSwitch;
98
+ }
99
+ /** The company-less Work Mesh register of `hq-session.sh add company` (`spawn_work_mesh_register "$sid"`, no company). */
100
+ | {
101
+ kind: "mesh-session-register";
102
+ sessionId: string;
103
+ cwd: string;
104
+ disabled?: MeshSessionBindSwitch;
105
+ }
106
+ /** 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;
108
+ /**
109
+ * One command of a `fleet-local-settings` note, a record of the adapter's `hqad_iter_settings`. Typed fields only: the
110
+ * daemon builds the program and its arguments (`fleetLocalSettingsProgram`).
111
+ * - `gate`: the root's `.claude/hooks/hook-gate.sh <id> <script> [args]`.
112
+ * - `master`: `bash <root>/.claude/hooks/master-hook.sh <event>`, for a settings entry naming another event's master-hook.
113
+ * - `script`: `<script>`, with no arguments.
114
+ */
115
+ export type FleetLocalSettingsCommand = {
116
+ type: "gate";
117
+ id: string;
118
+ script: string;
119
+ args: string[];
120
+ } | {
121
+ type: "master";
122
+ event: string;
123
+ } | {
124
+ type: "script";
125
+ script: string;
4
126
  };
5
127
  export interface HookRequest {
6
128
  /** The note's file name without `.json`. */
@@ -12,41 +134,121 @@ export interface HookRequest {
12
134
  root: string;
13
135
  session: string;
14
136
  operation: HookOperation;
137
+ /** The note's `.body` file, read by the drainer after it claims a note whose kind carries one. */
138
+ body?: Buffer;
15
139
  }
16
140
  /** The longest note the Rust writer leaves (`NOTE_MAX_BYTES`). */
17
141
  export declare const HOOK_REQUEST_MAX_BYTES = 4096;
142
+ /** The longest `.body` file the Rust writer leaves (`BODY_MAX_BYTES`). */
143
+ export declare const HOOK_REQUEST_BODY_MAX_BYTES: number;
18
144
  /** A note older than this is deleted and never run. */
19
145
  export declare const HOOK_REQUEST_MAX_AGE_MS: number;
20
146
  /** Tries per note, and the waits before the second and third. */
21
147
  export declare const HOOK_REQUEST_MAX_ATTEMPTS = 3;
22
148
  export declare const HOOK_REQUEST_RETRY_DELAYS_MS: readonly number[];
23
- /** The longest a request's program runs before it is killed. */
149
+ /** The longest a request's program runs before it is told to end (SIGTERM to its process group). */
24
150
  export declare const HOOK_REQUEST_KILL_MS = 60000;
151
+ /** How long after that the whole process group is killed. */
152
+ export declare const HOOK_REQUEST_KILL_GRACE_MS = 5000;
153
+ /** The wait before a note whose work could not start is looked at again. */
154
+ export declare const HOOK_REQUEST_LATER_MS = 5000;
155
+ /** The lock folder of `hq-autocommit.sh`, under the script's `${TMPDIR:-/tmp}`. */
156
+ export declare const AUTOCOMMIT_LOCK = "hq-autocommit.lock";
157
+ /** Failure files and shown marks older than this are removed when a new one is written. */
158
+ export declare const AUTOCOMMIT_WARNING_MAX_AGE_MS: number;
159
+ /** The longest path an `autocommit` note carries (`PATH_MAX_BYTES` in post_m5/autocommit.rs). */
160
+ export declare const HOOK_REQUEST_PATH_MAX_BYTES = 3500;
161
+ /** The autosave script of an HQ root, which the daemon runs for an `autocommit` note. */
162
+ export declare const AUTOCOMMIT_SCRIPT = ".claude/hooks/hq-autocommit.sh";
163
+ /** The script of an HQ root that prints the fingerprint for a `pr-footer` note (its fingerprint-only mode). */
164
+ export declare const PR_FOOTER_SCRIPT = "core/scripts/hq-pr-create.sh";
165
+ /** The only shape of `args.url` in a `pr-footer` note (`pull_url` in post_m5/pr_footer.rs). */
166
+ export declare const PR_FOOTER_URL: RegExp;
167
+ /** The longest URL a `pr-footer` note carries. */
168
+ export declare const PR_FOOTER_URL_MAX_BYTES = 512;
169
+ /** The footer is added no sooner than this after the hook left the note (owner decision 47: "a few seconds after the PR opens"). */
170
+ export declare const PR_FOOTER_DELAY_MS = 3000;
171
+ /** The longest each program of a `pr-footer` request runs (the script, `gh pr view`, `gh pr edit`). */
172
+ export declare const PR_FOOTER_PROGRAM_MS = 20000;
173
+ /** How often the body is read again when it changed between the read and the write, before the try fails. */
174
+ export declare const PR_FOOTER_ROUNDS = 3;
175
+ /** The most commands one `fleet-local-settings` note carries (the note itself is at most 4096 bytes). */
176
+ export declare const FLEET_LOCAL_SETTINGS_MAX_COMMANDS = 64;
177
+ /** The hook-gate and master-hook of an HQ root, which `gate` and `master` commands start. */
178
+ export declare const FLEET_LOCAL_HOOK_GATE = ".claude/hooks/hook-gate.sh";
179
+ export declare const FLEET_LOCAL_MASTER_HOOK = ".claude/hooks/master-hook.sh";
180
+ /** The hook a `mesh-session-bind` note runs, inside the HQ root (`spawn_work_mesh_register` in hq-session.sh). */
181
+ export declare const MESH_SESSION_BIND_HOOK = "core/hooks/SessionStart/35-work-mesh-session-start.sh";
182
+ /** Where that hook's output goes, inside the HQ root, as when hq-session.sh started it. */
183
+ export declare const MESH_SESSION_BIND_LOG = "workspace/logs/work-mesh-hook.log";
184
+ /** The longest `cwd` a `mesh-session-bind` note carries (`MESH_SESSION_BIND_CWD_MAX_BYTES` in daemon_req.rs). */
185
+ export declare const MESH_SESSION_BIND_CWD_MAX_BYTES = 3500;
186
+ /** The session switches that turn the Work Mesh hook off (`MeshBindSwitch` in daemon_req.rs); a note naming one starts nothing. */
187
+ export type MeshSessionBindSwitch = "HQ_WORK_MESH_DISABLED" | "HQ_DISABLED_HOOKS";
188
+ /** The script a `startwork-prefetch` note runs, inside the HQ root (`PREFETCH_SCRIPT` in prompt_up6/intent_hint.rs). */
189
+ export declare const STARTWORK_PREFETCH_SCRIPT = "core/scripts/startwork-prefetch.sh";
190
+ /** The hook leaves a prefetch note only for a prompt shorter than this (`PREFETCH_PROMPT_LIMIT` in prompt_up6/intent_hint.rs). */
191
+ export declare const STARTWORK_PREFETCH_PROMPT_LIMIT = 65536;
25
192
  /** Notes handled per pass; the drainer schedules another pass at once when reached. */
26
193
  export declare const HOOK_REQUEST_PASS_LIMIT = 64;
27
194
  /** The folder name for an HQ root: 32 hex characters of SHA-256 over its real path (`root_key` in daemon_req.rs). */
28
195
  export declare function hookRequestRootKey(root: string): string;
29
196
  /** The request folder of `root` under `home`. */
30
197
  export declare function hookRequestDir(home: string, root: string): string;
198
+ /** Where the daemon leaves a session's "autosave failed" file for the native hq-autocommit hook
199
+ * (`WARNING_PARTS` in post_m5/autocommit.rs; owner decision 48). */
200
+ export declare function autocommitWarningDir(home: string, root: string): string;
201
+ /** The name part for a session (`session_key` in post_m5/autocommit.rs). */
202
+ export declare function autocommitWarningKey(session: string): string;
203
+ /**
204
+ * Record that an autosave failed for `session`, so the native hook shows its
205
+ * warning on that session's next Write or Edit. One file per session; nothing
206
+ * is written once the hook has shown it (`.shown`). True when a file was made.
207
+ */
208
+ export declare function leaveAutocommitFailure(home: string, root: string, session: string, now?: number): boolean;
31
209
  /** Read one note. `stem` is its file name without `.json`. Undefined for anything the writer does not produce. */
32
210
  export declare function parseHookRequest(text: string, stem: string): HookRequest | undefined;
33
- /** The CLI arguments for a validated request. Nothing from the note is passed through as an argument except its checked root. */
34
- export declare function hookRequestArguments(request: HookRequest): string[];
211
+ /** Whether a note of this kind has its text in a `.body` file beside it. */
212
+ export declare function hookRequestHasBody(operation: HookOperation): boolean;
213
+ /** The helper a plan-sync request runs, inside the HQ root. */
214
+ export declare const PLAN_SYNC_HELPER = "core/scripts/session-project.sh";
215
+ /**
216
+ * The CLI arguments for a validated request (plan-sync: the helper's arguments). Nothing from the note is passed through as an argument except its checked root.
217
+ * Undefined for a request the daemon does in process (`session-close`), which never starts a program.
218
+ */
219
+ export declare function hookRequestArguments(request: HookRequest): string[] | undefined;
220
+ export interface HookRequestResult {
221
+ code: number;
222
+ later?: boolean;
223
+ }
224
+ /**
225
+ * Do a `session-close` request in the running hqd's session registry, as its `session.close` op does (allowed while HQ
226
+ * Anywhere is off). With no hqd running there is no session to close, which is done too: a retry would find the same.
227
+ * The note's root must be this daemon's root, as for every request.
228
+ */
229
+ export declare function executeSessionClose(request: HookRequest, options: {
230
+ sessions: {
231
+ close(runtime: string, sessionId: string): boolean;
232
+ } | undefined;
233
+ allowedRoot: string | undefined;
234
+ }): Promise<{
235
+ code: number;
236
+ }>;
35
237
  export interface HookRequestDrainOptions {
36
238
  home: string;
37
239
  /** The HQ root this daemon serves, read on every pass. */
38
240
  root: () => string | undefined;
39
241
  /** Must prove ownership of the canonical per-user daemon lease. */
40
242
  ownsQueue: () => boolean;
41
- /** Runs a validated request. No shell evaluation. */
42
- execute: (request: HookRequest) => Promise<{
43
- code: number;
44
- }>;
243
+ /** Runs a validated request. No shell evaluation. `later` says the work could not start and is not a try. */
244
+ execute: (request: HookRequest) => Promise<HookRequestResult>;
45
245
  log: (message: string) => void;
46
246
  /** Clock (tests). */
47
247
  now?: () => number;
48
248
  /** Waits before the second and third try (tests). */
49
249
  retryDelaysMs?: readonly number[];
250
+ /** The wait before a note whose work could not start is looked at again (tests). */
251
+ laterDelayMs?: number;
50
252
  /** The wait between fallback scans (tests). */
51
253
  scanIntervalMs?: number;
52
254
  }
@@ -62,7 +264,98 @@ export declare function drainHookRequests(options: HookRequestDrainOptions): Pro
62
264
  export declare function startHookRequestDrainer(options: HookRequestDrainOptions): {
63
265
  close(): Promise<void>;
64
266
  };
65
- /** Run a validated request through the daemon's own CLI entry point. */
267
+ /** What `hq-autocommit.sh` reads on stdin for a validated `autocommit` request: the payload fields the script uses, built here. */
268
+ export declare function autocommitInput(request: HookRequest): string;
269
+ /** What `spawnRequestProgram` returns. */
270
+ export interface RequestProgram {
271
+ child: ChildProcess;
272
+ /** Signal the program and everything it started (its process group; the program alone on Windows). */
273
+ signalAll(signal: NodeJS.Signals): void;
274
+ /**
275
+ * Call once, when the program has closed or failed to start: clears the
276
+ * timers and the abort listener. When the program was stopped (limit or
277
+ * abort), SIGKILL goes to its group once more, so nothing it started
278
+ * outlives it, and the answer is true.
279
+ */
280
+ settle(): boolean;
281
+ }
282
+ /**
283
+ * The one stop model of every request kind. `program` is started without a
284
+ * shell in its own process group (not on Windows, where the program alone is
285
+ * signalled). At `timeoutMs`, or when `signal` aborts, the group is sent
286
+ * SIGTERM, so a script can run its exit trap and the programs it started end
287
+ * with it, and SIGKILL after `killGraceMs` (default 5 s).
288
+ */
289
+ export declare function spawnRequestProgram(program: string, args: string[], spawnOptions: Omit<SpawnOptions, "shell" | "detached">, stop: {
290
+ timeoutMs: number;
291
+ killGraceMs?: number;
292
+ signal?: AbortSignal;
293
+ }): RequestProgram;
294
+ /**
295
+ * The body `pr-fingerprint-footer.sh` wrote for a pull request whose body is
296
+ * `body` (trailing newlines already removed), or undefined when a line of
297
+ * it already starts with `HQ-Fingerprint:`.
298
+ */
299
+ export declare function prFooterBody(body: string, fingerprint: string): string | undefined;
300
+ /**
301
+ * The words `eval "toks=( $rest )"` gives with `CLAUDE_PROJECT_DIR` set to `root`, for the shapes hq-hook models
302
+ * (`shell_words` in `host::fleet_settings`): blanks, single and double quotes, backslash escapes, and
303
+ * `$CLAUDE_PROJECT_DIR` or `${CLAUDE_PROJECT_DIR}`. Undefined for anything else the shell would expand or treat as syntax.
304
+ */
305
+ export declare function fleetLocalSettingsWords(text: string, root: string): string[] | undefined;
306
+ /**
307
+ * `hqad_classify_command` for one settings command, as hq-hook's `fleet_settings::classify` reads it: the record the
308
+ * hook would put in a note, or undefined for a command that gives none or that hq-hook does not model.
309
+ */
310
+ export declare function fleetLocalSettingsRecord(command: string, root: string): FleetLocalSettingsCommand | undefined;
311
+ /**
312
+ * The records the root's `.claude/settings.json` lists for `event` right now (any matcher), for the drain-time check
313
+ * that a note's command is still listed there. Exec-form entries give none (the hook puts none in a note). An absent
314
+ * or unreadable file lists nothing.
315
+ */
316
+ export declare function fleetLocalSettingsListed(root: string, event: string): FleetLocalSettingsCommand[];
317
+ /** Whether `file`'s real path (every symlink in its whole parent chain resolved) is inside the real HQ root. */
318
+ export declare function fleetLocalSettingsUnderRoot(root: string, file: string): boolean;
319
+ /**
320
+ * Why the daemon refuses one note command at drain, or undefined to run it. A note is only what a hook said a moment
321
+ * ago, so the daemon re-checks it against the root: the command must still be listed in the root's
322
+ * `.claude/settings.json` for the note's event, and every file it would start (the gate and its script, master-hook,
323
+ * the script) must resolve, with its whole parent chain, to a real path under the HQ root.
324
+ */
325
+ export declare function fleetLocalSettingsRefusal(root: string, command: FleetLocalSettingsCommand, listed: FleetLocalSettingsCommand[]): string | undefined;
326
+ /**
327
+ * The program and arguments for one `fleet-local-settings` command, as the adapter (and `child::Runner` in hq-hook)
328
+ * starts it: an executable file is started itself, any other with `bash`; master-hook always with `bash`. No shell
329
+ * reads the words. Undefined for a master command whose master-hook is not a file (the hook skipped it too).
330
+ */
331
+ export declare function fleetLocalSettingsProgram(root: string, command: FleetLocalSettingsCommand): {
332
+ program: string;
333
+ args: string[];
334
+ bashEnv: boolean;
335
+ } | undefined;
336
+ /**
337
+ * Run a validated request: the daemon's own CLI entry point, for `autocommit` the HQ root's own autosave
338
+ * script, for `plan-sync` the HQ root's own helper with the plan on stdin, as the shell hook did, for
339
+ * `pr-footer` the root's fingerprint script and `gh` (`addPrFooter`), for `mesh-session-bind` the root's
340
+ * SessionStart Work Mesh hook (`runMeshSessionBind`).
341
+ *
342
+ * Every program runs in its own process group (`spawnRequestProgram`, through
343
+ * `runRequestProgram`). At the limit the group is sent SIGTERM, so a script
344
+ * can run its exit trap and the programs it started end with it, and SIGKILL
345
+ * after the grace time. Both count as a failed try.
346
+ *
347
+ * `autocommit` only. The script exits 0 without a word when another autosave
348
+ * holds its lock, which is not a commit: a lock that is held is answered with
349
+ * `later` (the note is kept and no try is counted), without starting the
350
+ * script while the lock is younger than the script's own takeover age. The
351
+ * script's warning line on stderr ("WARNING: HQ autosave ...", once per
352
+ * session and cause) becomes the session's failure file.
353
+ *
354
+ * `plan-sync` only. A helper that is not an executable file is done (code 0),
355
+ * as the shell hook skipped it. The helper's own exit status is ignored when
356
+ * it ended by itself (the shell hook's `|| true`); a run that had to be
357
+ * stopped at the limit still counts as a failed try.
358
+ */
66
359
  export declare function executeHookRequest(request: HookRequest, options: {
67
360
  nodeBinary: string;
68
361
  hqBinary: string;
@@ -70,6 +363,54 @@ export declare function executeHookRequest(request: HookRequest, options: {
70
363
  env?: NodeJS.ProcessEnv;
71
364
  signal?: AbortSignal;
72
365
  timeoutMs?: number;
366
+ killGraceMs?: number;
367
+ home?: string;
368
+ log?: (message: string) => void;
369
+ /** `pr-footer` (tests): the wait after the note's time, the limit of each program, and the rounds. */
370
+ prFooterDelayMs?: number;
371
+ prFooterProgramMs?: number;
372
+ prFooterRounds?: number;
373
+ }): Promise<HookRequestResult>;
374
+ /** The `check-hq-update` and `check-client-health` request notes
375
+ * (crates/hq-hook/src/daemon_req.rs, `Kind::CheckHqUpdate` and
376
+ * `Kind::CheckClientHealth`; hq-core-rust decision 19 with standing rule (b)).
377
+ *
378
+ * The native SessionStart rows for these two machine checks start no program.
379
+ * When the hooks own the machine checks (master-hook's helper answers legacy)
380
+ * the row leaves one note instead, and the daemon runs that one check here on
381
+ * its next pass over the notes.
382
+ *
383
+ * The check runs through the machine-check runner (machine-checks.ts): the
384
+ * same script rules, environment and time limit as the daemon's batch. Like
385
+ * the batch it runs collect-only when the installed core advertises the mode,
386
+ * so a show-once message nobody has seen is not marked as shown; the work
387
+ * itself (the update, the bounded repair, their cooldowns) is done. Its result
388
+ * is not written to the results file: that file is the batch's, and its age is
389
+ * what the owner decision reads, so a single check must not refresh it. It runs
390
+ * as a single run (`single: true`): it never takes the batch's in-flight slot,
391
+ * so a batch tick during it runs the full batch and writes that file.
392
+ */
393
+ /** The request kinds these notes carry: each is the id of one machine check. */
394
+ export declare const MACHINE_CHECK_REQUEST_KINDS: readonly ["check-hq-update", "check-client-health"];
395
+ export type MachineCheckRequestKind = (typeof MACHINE_CHECK_REQUEST_KINDS)[number];
396
+ export type MachineCheckOperation = {
397
+ kind: MachineCheckRequestKind;
398
+ };
399
+ export declare function isMachineCheckRequestKind(kind: unknown): kind is MachineCheckRequestKind;
400
+ /** A note of one of these kinds carries no fields. Undefined for anything else. */
401
+ export declare function parseMachineCheckOperation(kind: unknown, args: Record<string, unknown>): MachineCheckOperation | undefined;
402
+ /**
403
+ * Run the note's check once in `root` (already checked to be the daemon's own
404
+ * root). Done (0) when the check ran to an answer, or when nothing is to run
405
+ * (inside a machine check); a failed try (1) when its answer is `unknown`
406
+ * (missing or refused script, timeout, crash, non-zero exit), which the
407
+ * drainer retries as any failed note.
408
+ */
409
+ export declare function runMachineCheckRequest(root: string, operation: MachineCheckOperation, options?: {
410
+ env?: NodeJS.ProcessEnv;
411
+ /** Test seams. */
412
+ run?: (options: RunMachineChecksOptions) => Promise<MachineCheckResult[]>;
413
+ collectOnlySupported?: (hqRoot: string) => boolean;
73
414
  }): Promise<{
74
415
  code: number;
75
416
  }>;