@indigoai-us/hq-cli 5.345.212-beta.0 → 5.345.214

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 (119) hide show
  1. package/CHANGELOG.md +40 -1
  2. package/dist/bin/hq-auth-refresh.js +2 -1
  3. package/dist/command-catalog.generated.d.ts +308 -43
  4. package/dist/command-catalog.generated.js +373 -43
  5. package/dist/command-registration-plan.d.ts +15 -0
  6. package/dist/command-registration-plan.js +20 -1
  7. package/dist/commands/agent-inbox.d.ts +11 -1
  8. package/dist/commands/agent-inbox.js +128 -38
  9. package/dist/commands/agent-kit.js +2 -2
  10. package/dist/commands/agents.js +6 -1
  11. package/dist/commands/billing.js +17 -4
  12. package/dist/commands/core-handoff.js +1 -0
  13. package/dist/commands/core-hq-session-native.js +2 -2
  14. package/dist/commands/core-pin-native.js +1 -1
  15. package/dist/commands/core-policy.js +1 -1
  16. package/dist/commands/core-resolve-company-native.js +1 -1
  17. package/dist/commands/core-sentry-report-fast.d.ts +2 -0
  18. package/dist/commands/core-sentry-report-fast.js +3 -1
  19. package/dist/commands/daemon.js +68 -6
  20. package/dist/commands/files.js +2 -2
  21. package/dist/commands/integrations-api.d.ts +11 -0
  22. package/dist/commands/integrations-connect.d.ts +9 -1
  23. package/dist/commands/integrations-connect.js +154 -18
  24. package/dist/commands/integrations-core.d.ts +1 -1
  25. package/dist/commands/integrations-core.js +18 -10
  26. package/dist/commands/integrations.js +1 -1
  27. package/dist/commands/lanes-link.js +10 -5
  28. package/dist/commands/lanes.js +34 -16
  29. package/dist/commands/rescue.js +13 -0
  30. package/dist/commands/secrets.d.ts +11 -0
  31. package/dist/commands/secrets.js +41 -7
  32. package/dist/index.js +2 -0
  33. package/dist/lazy-commands.js +6 -1
  34. package/dist/lib/agent-kit/inbox-fetch.d.ts +122 -1
  35. package/dist/lib/agent-kit/inbox-fetch.js +215 -3
  36. package/dist/lib/agent-kit/inbox-redact.js +1 -1
  37. package/dist/lib/agent-kit/inbox-state.d.ts +98 -1
  38. package/dist/lib/agent-kit/inbox-state.js +261 -4
  39. package/dist/lib/agent-kit/mcp/tools.d.ts +3 -3
  40. package/dist/lib/agent-kit/mcp/tools.js +68 -25
  41. package/dist/lib/agent-kit/run/inbox.js +4 -2
  42. package/dist/lib/agent-kit/skills.js +4 -1
  43. package/dist/lib/agent-kit/wake.d.ts +9 -1
  44. package/dist/lib/agent-kit/wake.js +10 -3
  45. package/dist/lib/billing/usage-only.d.ts +4 -1
  46. package/dist/lib/billing/usage-only.js +7 -2
  47. package/dist/lib/bot/fleet-cron.js +193 -14
  48. package/dist/lib/bot/fleet-download.d.ts +2 -0
  49. package/dist/lib/bot/fleet-download.js +23 -0
  50. package/dist/lib/bot/fleet-local.d.ts +1 -0
  51. package/dist/lib/bot/fleet-local.js +41 -8
  52. package/dist/lib/capacity/ledger.d.ts +7 -0
  53. package/dist/lib/capacity/ledger.js +31 -1
  54. package/dist/lib/capacity/project.d.ts +1 -1
  55. package/dist/lib/capacity/project.js +13 -4
  56. package/dist/lib/capacity/route.d.ts +10 -0
  57. package/dist/lib/capacity/route.js +16 -0
  58. package/dist/lib/core-utils/session-id.d.ts +1 -1
  59. package/dist/lib/core-utils/session-id.js +4 -0
  60. package/dist/lib/daemon/install.d.ts +15 -0
  61. package/dist/lib/daemon/install.js +31 -0
  62. package/dist/lib/daemon/migrate.js +29 -4
  63. package/dist/lib/daemon/run.js +9 -1
  64. package/dist/lib/daemon/updater.d.ts +34 -2
  65. package/dist/lib/daemon/updater.js +51 -2
  66. package/dist/lib/doctor/__testing__/run-doctor.js +4 -0
  67. package/dist/lib/doctor/checks/jq.d.ts +27 -0
  68. package/dist/lib/doctor/checks/jq.js +82 -0
  69. package/dist/lib/doctor/checks/release-links.d.ts +50 -8
  70. package/dist/lib/doctor/checks/release-links.js +260 -24
  71. package/dist/lib/doctor/fix/apply.js +24 -8
  72. package/dist/lib/doctor/fix/remediation.js +15 -5
  73. package/dist/lib/doctor/registry.js +4 -0
  74. package/dist/lib/flag-snapshot-file.js +36 -8
  75. package/dist/lib/install/codex-targets.d.ts +52 -1
  76. package/dist/lib/install/codex-targets.js +77 -2
  77. package/dist/lib/lanes/autopilot-registry.d.ts +14 -0
  78. package/dist/lib/lanes/autopilot-registry.js +59 -7
  79. package/dist/lib/lanes/links.d.ts +14 -0
  80. package/dist/lib/lanes/links.js +320 -25
  81. package/dist/lib/lanes/monitor.d.ts +4 -1
  82. package/dist/lib/lanes/monitor.js +47 -10
  83. package/dist/lib/lanes/outpost-pruner-install.d.ts +10 -0
  84. package/dist/lib/lanes/outpost-pruner-install.js +4 -3
  85. package/dist/lib/lanes/spawn.js +8 -1
  86. package/dist/lib/lanes/watch.js +31 -0
  87. package/dist/lib/onboarding/checkpoint.d.ts +6 -0
  88. package/dist/lib/onboarding/checkpoint.js +6 -0
  89. package/dist/lib/onboarding/orchestrator.d.ts +3 -1
  90. package/dist/lib/onboarding/orchestrator.js +62 -9
  91. package/dist/lib/onboarding/types.d.ts +8 -0
  92. package/dist/lib/work-context/organize.d.ts +23 -1
  93. package/dist/lib/work-context/organize.js +25 -3
  94. package/dist/lib/work-context/reconcile.js +3 -2
  95. package/dist/main.js +3 -1
  96. package/dist/secrets-env-action.js +7 -5
  97. package/dist/sentry-init.d.ts +2 -0
  98. package/dist/sentry-init.js +13 -2
  99. package/dist/sentry.d.ts +2 -0
  100. package/dist/sentry.js +5 -1
  101. package/dist/startup-registration.js +7 -2
  102. package/dist/utils/billing-gate.d.ts +12 -16
  103. package/dist/utils/billing-gate.js +17 -18
  104. package/dist/utils/cli-network-lifecycle.d.ts +9 -0
  105. package/dist/utils/cli-network-lifecycle.js +52 -0
  106. package/dist/utils/install-tree-torn.d.ts +22 -4
  107. package/dist/utils/install-tree-torn.js +24 -0
  108. package/dist/utils/registration-plan-error.d.ts +22 -0
  109. package/dist/utils/registration-plan-error.js +27 -0
  110. package/dist/utils/safe-link.d.ts +63 -0
  111. package/dist/utils/safe-link.js +246 -0
  112. package/dist/utils/sentry-fingerprint.js +3 -0
  113. package/dist/utils/sentry-keepalive-transport.d.ts +28 -0
  114. package/dist/utils/sentry-keepalive-transport.js +70 -0
  115. package/dist/utils/unauthorized-error.d.ts +36 -0
  116. package/dist/utils/unauthorized-error.js +105 -0
  117. package/dist/utils/vault-api.js +7 -5
  118. package/package.json +7 -7
  119. package/scripts/install-hook-engine.mjs +17 -0
@@ -23,6 +23,7 @@
23
23
  * timers.
24
24
  */
25
25
  import { networkTransportErrorCode } from "../../utils/network-transport-error.js";
26
+ import { addAckPending, confirmInboxAck, readAckPending, readDoneIds, recordAckFailures } from "./inbox-state.js";
26
27
  import { KIT_REQUEST_TIMEOUT_MIN_MS, KIT_REQUEST_TIMEOUT_MS, KitRequestTimeoutError, withRequestTimeout } from "./run/request-timeout.js";
27
28
  /** Env override for the per-attempt deadline; values under the floor are raised to it. */
28
29
  export const AGENT_INBOX_TIMEOUT_ENV = "HQ_AGENT_INBOX_TIMEOUT_MS";
@@ -98,22 +99,233 @@ export async function fetchServerInboxWithRetry(deps) {
98
99
  const last = attempts >= AGENT_INBOX_MAX_ATTEMPTS;
99
100
  let retryAfterSeconds;
100
101
  try {
101
- const res = await withRequestTimeout(timeoutMs, undefined, async (signal) => {
102
+ const res = await withRequestTimeout(timeoutMs, deps.signal, async (signal) => {
102
103
  const token = await deps.mint(signal);
103
104
  return deps.fetch(token, signal);
104
105
  });
105
- if (last || !isRetryableInboxStatus(res.status)) {
106
+ if (last || deps.signal?.aborted || !isRetryableInboxStatus(res.status)) {
106
107
  return { ok: true, response: { status: res.status, body: res.body }, attempts };
107
108
  }
108
109
  retryAfterSeconds = res.retryAfterSeconds;
109
110
  }
110
111
  catch (err) {
111
- if (last || !isRetryableInboxError(err))
112
+ if (last || deps.signal?.aborted || !isRetryableInboxError(err))
112
113
  return { ok: false, error: err, attempts };
113
114
  }
114
115
  await sleep(retryDelayMs(retryAfterSeconds, random));
116
+ if (deps.signal?.aborted)
117
+ return { ok: false, error: deps.signal.reason, attempts };
115
118
  }
116
119
  }
120
+ /** Env override for the total time one batch of acks may take. */
121
+ export const AGENT_INBOX_ACK_DEADLINE_ENV = "HQ_AGENT_INBOX_ACK_DEADLINE_MS";
122
+ /** Default total time for one batch of acks (`done` with many ids). */
123
+ export const AGENT_INBOX_ACK_DEADLINE_MS = 60_000;
124
+ /** Budget for retrying unconfirmed acks at the start of an inbox read. */
125
+ export const AGENT_INBOX_READ_ACK_RETRY_MS = 10_000;
126
+ /**
127
+ * Total time for one inbox read: the ack retry plus the bounded server read.
128
+ * Kept under the 60 s tool timeout MCP clients commonly apply to
129
+ * hq_inbox_read, with room for the local work around it.
130
+ */
131
+ export const AGENT_INBOX_READ_BUDGET_MS = 45_000;
132
+ /**
133
+ * Ack answers that will not change on a retry. An id refused this way leaves
134
+ * ack-pending.json for ack-failed.json instead of being retried forever.
135
+ */
136
+ // 401 is absent on purpose: it is about the token, not the item, and one bad or
137
+ // revoked mint must not retire every pending id. A 409 is not final either.
138
+ // Both stay in ack-pending.json and are retried by the next read or done.
139
+ const PERMANENT_ACK_STATUSES = new Set([400, 403, 404]);
140
+ export function isPermanentAckStatus(status) {
141
+ return PERMANENT_ACK_STATUSES.has(status);
142
+ }
143
+ /** The inbox read's total budget passed before the server answered. */
144
+ export class InboxReadBudgetError extends Error {
145
+ budgetMs;
146
+ constructor(budgetMs) {
147
+ super(`inbox read budget (${budgetMs}ms) reached`);
148
+ this.budgetMs = budgetMs;
149
+ this.name = "InboxReadBudgetError";
150
+ }
151
+ }
152
+ /**
153
+ * fetchServerInboxWithRetry under one total budget: the in-flight attempt is
154
+ * cut at the budget and the retry delay never waits past it. Never throws.
155
+ */
156
+ export async function fetchServerInboxWithinBudget(deps, budgetMs) {
157
+ const budget = Math.max(1, Math.floor(budgetMs));
158
+ const controller = new AbortController();
159
+ const startedAt = Date.now();
160
+ const timer = setTimeout(() => controller.abort(new InboxReadBudgetError(budget)), budget);
161
+ const baseSleep = deps.sleep ?? defaultSleep;
162
+ try {
163
+ return await fetchServerInboxWithRetry({
164
+ ...deps,
165
+ signal: controller.signal,
166
+ sleep: (ms) => baseSleep(Math.max(0, Math.min(ms, startedAt + budget - Date.now()))),
167
+ });
168
+ }
169
+ finally {
170
+ clearTimeout(timer);
171
+ }
172
+ }
173
+ /** The batch deadline passed before this id's ack was confirmed. */
174
+ export class InboxAckDeadlineError extends Error {
175
+ deadlineMs;
176
+ constructor(deadlineMs) {
177
+ super(`ack batch deadline (${deadlineMs}ms) reached`);
178
+ this.deadlineMs = deadlineMs;
179
+ this.name = "InboxAckDeadlineError";
180
+ }
181
+ }
182
+ /** Batch deadline from the env; values under the kit floor are raised to it. */
183
+ export function resolveAgentInboxAckDeadlineMs(env = process.env) {
184
+ const raw = env[AGENT_INBOX_ACK_DEADLINE_ENV]?.trim();
185
+ if (!raw)
186
+ return AGENT_INBOX_ACK_DEADLINE_MS;
187
+ const n = Number(raw);
188
+ if (!Number.isFinite(n))
189
+ return AGENT_INBOX_ACK_DEADLINE_MS;
190
+ return Math.max(KIT_REQUEST_TIMEOUT_MIN_MS, Math.floor(n));
191
+ }
192
+ /**
193
+ * Ack each id on the server with the same bounded, once-retried attempt as the
194
+ * inbox read (feedback 3e376c49). Before, `hq agent inbox done` and
195
+ * `hq_inbox_done` sent one unbounded POST per id with no retry and reported a
196
+ * transient failure only as a warning line, so automation could not tell a
197
+ * completed ack from a lost one. The server ack is idempotent (processed
198
+ * marker, then delete pending), so retrying after a lost response, or the
199
+ * caller rerunning `done`, cannot double-complete an item. Never throws.
200
+ */
201
+ export async function ackServerInboxItems(ids, deps) {
202
+ const { post, deadlineMs, onAcked, ...rest } = deps;
203
+ const acked = [];
204
+ const failed = [];
205
+ const baseSleep = rest.sleep ?? defaultSleep;
206
+ const batch = new AbortController();
207
+ const startedAt = Date.now();
208
+ const timer = deadlineMs !== undefined
209
+ ? setTimeout(() => batch.abort(new InboxAckDeadlineError(deadlineMs)), deadlineMs)
210
+ : undefined;
211
+ // A retry delay never waits past the batch deadline.
212
+ const sleep = deadlineMs === undefined
213
+ ? baseSleep
214
+ : (ms) => baseSleep(Math.max(0, Math.min(ms, startedAt + deadlineMs - Date.now())));
215
+ try {
216
+ for (const id of ids) {
217
+ if (batch.signal.aborted) {
218
+ failed.push({ id, error: errorMessage(batch.signal.reason), attempts: 0, deferred: true });
219
+ continue;
220
+ }
221
+ const outcome = await fetchServerInboxWithRetry({
222
+ ...rest,
223
+ sleep,
224
+ signal: batch.signal,
225
+ fetch: (token, signal) => post(token, id, signal),
226
+ });
227
+ if (outcome.ok && outcome.response.status >= 200 && outcome.response.status < 300) {
228
+ acked.push(id);
229
+ onAcked?.(id);
230
+ }
231
+ else if (outcome.ok) {
232
+ const status = outcome.response.status;
233
+ failed.push({ id, status, attempts: outcome.attempts, ...(isPermanentAckStatus(status) ? { permanent: true } : {}) });
234
+ }
235
+ else {
236
+ failed.push({ id, error: errorMessage(outcome.error), attempts: outcome.attempts });
237
+ }
238
+ }
239
+ }
240
+ finally {
241
+ if (timer)
242
+ clearTimeout(timer);
243
+ }
244
+ return { acked, failed, complete: failed.length === 0 };
245
+ }
246
+ function errorMessage(err) {
247
+ return err instanceof Error ? err.message : String(err);
248
+ }
249
+ /** One-line description of an ack failure for a person or a log. */
250
+ export function describeInboxAckFailure(f) {
251
+ const why = f.status !== undefined ? `HTTP ${f.status}` : (f.error ?? "unknown error");
252
+ return `${f.id} (${why}${f.attempts > 1 ? `, after ${f.attempts} attempts` : ""})`;
253
+ }
254
+ /**
255
+ * The `ackFailures` string format `hq_inbox_done` has always returned, kept so
256
+ * existing parsers keep working: `"<id> (<status>)"` for an HTTP answer, and
257
+ * `"ack skipped: <id>: <message>"` when no answer arrived. Structured detail
258
+ * is in `ackFailureDetails`. `hq agent inbox done --json` uses the same two
259
+ * fields, so both surfaces have one shape.
260
+ */
261
+ export function formatInboxAckFailure(f) {
262
+ return f.status !== undefined ? `${f.id} (${f.status})` : `ack skipped: ${f.id}: ${f.error ?? "unknown error"}`;
263
+ }
264
+ /**
265
+ * `hq agent inbox done` / `hq_inbox_done` (feedback 3e376c49): record the ids
266
+ * in ack-pending.json first, ack them plus any ids an earlier call left
267
+ * unconfirmed, and move each id to done-ids.json only after its 2xx. A failed
268
+ * ack, the batch deadline or a killed process leaves the id in
269
+ * ack-pending.json, where it stays visible and is retried by the next read or
270
+ * done call. Never throws on a network failure.
271
+ */
272
+ export async function completeInboxItems(paths, ids, deps) {
273
+ const doneBefore = readDoneIds(paths);
274
+ const earlier = readAckPending(paths).filter((id) => !ids.includes(id));
275
+ addAckPending(paths, ids);
276
+ const marked = [];
277
+ const result = await ackServerInboxItems([...ids, ...earlier], {
278
+ ...deps,
279
+ onAcked: (id) => {
280
+ if (confirmInboxAck(paths, id) && ids.includes(id))
281
+ marked.push(id);
282
+ },
283
+ });
284
+ const requested = new Set(ids);
285
+ // The done output lists these ids, so they count as shown: no listing
286
+ // repeats them, and a bot that only calls done does not grow ack-failed.json.
287
+ const ackFailed = settlePermanentFailures(paths, result.failed, { reported: true });
288
+ return {
289
+ ...result,
290
+ marked,
291
+ alreadyDone: ids.filter((id) => doneBefore.has(id)),
292
+ retriedAcked: result.acked.filter((id) => !requested.has(id)),
293
+ ackPending: readAckPending(paths),
294
+ ackFailed,
295
+ requestedComplete: result.failed.every((f) => !requested.has(f.id)),
296
+ };
297
+ }
298
+ /**
299
+ * Move permanently refused ids from ack-pending.json to ack-failed.json in one
300
+ * locked write, not one rewrite per id. Returns their ids.
301
+ */
302
+ function settlePermanentFailures(paths, failed, options) {
303
+ const permanent = failed.filter((f) => f.permanent && f.status !== undefined);
304
+ recordAckFailures(paths, permanent.map((f) => ({ id: f.id, reason: `HTTP ${f.status}` })), options);
305
+ return permanent.map((f) => f.id);
306
+ }
307
+ /**
308
+ * Retry the acks an earlier `done` left unconfirmed, at the start of an inbox
309
+ * read. Returns undefined when nothing was pending. Bounded by
310
+ * AGENT_INBOX_READ_ACK_RETRY_MS (or a smaller batch deadline) so a read stays
311
+ * quick when the server is down.
312
+ */
313
+ export async function retryPendingInboxAcks(paths, deps) {
314
+ const pending = readAckPending(paths);
315
+ if (pending.length === 0)
316
+ return undefined;
317
+ const deadlineMs = Math.min(deps.deadlineMs ?? AGENT_INBOX_READ_ACK_RETRY_MS, AGENT_INBOX_READ_ACK_RETRY_MS);
318
+ const result = await ackServerInboxItems(pending, {
319
+ ...deps,
320
+ deadlineMs,
321
+ onAcked: (id) => {
322
+ confirmInboxAck(paths, id);
323
+ },
324
+ });
325
+ // Not in any output yet: the next listing shows them.
326
+ const ackFailed = settlePermanentFailures(paths, result.failed, { reported: false });
327
+ return { acked: result.acked, failed: result.failed, ackPending: readAckPending(paths), ackFailed };
328
+ }
117
329
  /** Suffix added to the degradation note when the retry also failed. */
118
330
  export const AGENT_INBOX_AFTER_ATTEMPTS_SUFFIX = ` (after ${AGENT_INBOX_MAX_ATTEMPTS} attempts)`;
119
331
  /**
@@ -18,7 +18,7 @@ import * as fs from "node:fs";
18
18
  import * as path from "node:path";
19
19
  import { writePrivateFile } from "./private-file.js";
20
20
  const INBOX_JSONL_NAME = "inbox.jsonl";
21
- const STATE_FILES = new Set(["seen-ids.json", "done-ids.json"]);
21
+ const STATE_FILES = new Set(["seen-ids.json", "done-ids.json", "ack-pending.json", "ack-failed.json"]);
22
22
  const LOCK_DIR_NAME = ".inbox-write.lock";
23
23
  const LOCK_STALE_MS = 30_000;
24
24
  const ACTING_CONTEXT_KEYS = ["mode", "ownerPersonUid", "ownerRole", "expiresAt"];
@@ -7,8 +7,33 @@
7
7
  * mirrored item whose id is not done, oldest first. This works the same
8
8
  * whether or not the kit acks on the server (`inboxAck`), so a woken bot can
9
9
  * always drain exactly what it has not handled yet and never reply twice.
10
+ *
11
+ * An id reaches done-ids.json only after the server confirmed its ack
12
+ * (feedback 3e376c49). Until then it sits in ack-pending.json, which is
13
+ * written BEFORE the ack is sent, so a failed ack or a killed process leaves a
14
+ * durable record. The next `hq agent inbox`, `hq agent inbox done`,
15
+ * `hq_inbox_read` or `hq_inbox_done` call retries those acks. An id in
16
+ * ack-pending.json stays visible: it counts as pending for the wake check and
17
+ * is listed with `ackPending: true`, so it can never be hidden while the
18
+ * server still holds it.
19
+ *
20
+ * A permanent refusal (400/403/404) is not retried forever: the id moves
21
+ * to ack-failed.json with the reason and is recorded handled locally, and the
22
+ * next listing shows it once with `ackFailed` before it drops out. A refusal
23
+ * the `done` output already listed is recorded as shown, so it is not repeated.
24
+ *
25
+ * Every read-modify-write of these files runs under the inbox mirror lock, so
26
+ * the MCP server and a CLI call cannot drop each other's update.
10
27
  */
11
28
  import type { AgentKitPaths } from "./paths.js";
29
+ export declare const ACK_PENDING_NAME = "ack-pending.json";
30
+ export declare const ACK_FAILED_NAME = "ack-failed.json";
31
+ /**
32
+ * Hard ceiling on ack-failed.json, the same as MAX_DONE_IDS. Past it the
33
+ * oldest records not shown yet are dropped and counted, and the next listing
34
+ * reports the count (re-review of hq-cli #2520: the file had no hard cap).
35
+ */
36
+ export declare const MAX_ACK_FAILED_RECORDS = 5000;
12
37
  export interface MirroredInboxEntry {
13
38
  id: string;
14
39
  mirroredAt?: string;
@@ -16,8 +41,78 @@ export interface MirroredInboxEntry {
16
41
  }
17
42
  export declare function readDoneIds(paths: Pick<AgentKitPaths, "inboxDir">): Set<string>;
18
43
  export declare function markInboxDone(paths: Pick<AgentKitPaths, "inboxDir">, ids: string[]): string[];
44
+ /**
45
+ * Ids marked handled by the bot whose server ack is not confirmed yet, oldest
46
+ * first. A missing or unreadable file is an empty list.
47
+ */
48
+ export declare function readAckPending(paths: Pick<AgentKitPaths, "inboxDir">): string[];
49
+ /** Record ids as awaiting a server ack. Call before the ack is sent. */
50
+ export declare function addAckPending(paths: Pick<AgentKitPaths, "inboxDir">, ids: string[]): void;
51
+ /**
52
+ * The server confirmed the ack for `id`: record it as done, then drop it from
53
+ * ack-pending.json, under one lock. In that order, so a kill between the two
54
+ * writes leaves the id visible and re-acked (idempotent) rather than hidden.
55
+ */
56
+ export declare function confirmInboxAck(paths: Pick<AgentKitPaths, "inboxDir">, id: string): boolean;
57
+ /** An ack the server refused permanently; listed once, then only kept for the record. */
58
+ export interface AckFailedRecord {
59
+ id: string;
60
+ /** Short reason, e.g. "HTTP 403". Never response bytes. */
61
+ reason: string;
62
+ at: string;
63
+ /** Set once a listing has shown it. */
64
+ reported?: true;
65
+ }
66
+ export declare function readAckFailed(paths: Pick<AgentKitPaths, "inboxDir">): AckFailedRecord[];
67
+ /**
68
+ * The server refused these acks permanently (400/403/404). Stop retrying
69
+ * them: record them in ack-failed.json with the reason, record them handled
70
+ * locally (the bot already answered them), and drop them from
71
+ * ack-pending.json, all in one locked read and one write per file. With
72
+ * `reported`, the caller has already shown them (the `done` output lists the
73
+ * refused ids), so no listing repeats them; otherwise the next listing shows
74
+ * each once with its reason.
75
+ */
76
+ export declare function recordAckFailures(paths: Pick<AgentKitPaths, "inboxDir">, failures: {
77
+ id: string;
78
+ reason: string;
79
+ }[], options?: {
80
+ reported?: boolean;
81
+ now?: Date;
82
+ }): void;
83
+ /** One refused ack; see recordAckFailures. The next listing shows it once. */
84
+ export declare function recordAckFailed(paths: Pick<AgentKitPaths, "inboxDir">, id: string, reason: string, now?: Date): void;
85
+ /**
86
+ * Most refused acks one listing takes. A pretty-printed record is about 130 to
87
+ * 290 characters (the id length varies), so 100 come to at most about 30,000,
88
+ * inside hq_inbox_read's 40,000-character clamp next to the rest of the
89
+ * listing. The remainder stays unreported for the next read instead of being
90
+ * retired unseen (recheck of hq-cli #2520).
91
+ */
92
+ export declare const ACK_FAILED_LISTING_LIMIT = 100;
93
+ export interface AckFailureListing {
94
+ /** Refused acks not shown before, oldest first; now marked shown. */
95
+ ackFailed: Omit<AckFailedRecord, "reported">[];
96
+ /** How many more are still unshown after this take (counted under the same lock). */
97
+ more: number;
98
+ /** Unshown refusals the hard ceiling dropped since the last listing; reset to 0 by this take. */
99
+ dropped: number;
100
+ }
101
+ /**
102
+ * Permanently refused acks not shown yet, oldest first and at most `limit` of
103
+ * them, marked as shown. A listing calls this once, so each one is visible
104
+ * exactly once with its reason; any beyond `limit` wait for the next listing.
105
+ * `more` and `dropped` are read inside the same lock, so they are exact.
106
+ */
107
+ export declare function takeAckFailureListing(paths: Pick<AgentKitPaths, "inboxDir">, limit?: number): AckFailureListing;
108
+ /** How many permanently refused acks have not been shown yet. */
109
+ export declare function countUnreportedAckFailures(paths: Pick<AgentKitPaths, "inboxDir">): number;
19
110
  /** Every mirrored entry, oldest first, de-duplicated by id (last write wins). */
20
111
  export declare function readMirroredInbox(paths: Pick<AgentKitPaths, "inboxDir">): MirroredInboxEntry[];
112
+ /**
113
+ * Mirrored items the wake check and the listings treat as pending: not done,
114
+ * or handled but with a server ack still unconfirmed (ack-pending.json).
115
+ */
21
116
  export declare function pendingInbox(paths: Pick<AgentKitPaths, "inboxDir">): MirroredInboxEntry[];
22
117
  /** One file reference carried on an inbox item (US-007 chat attachments). */
23
118
  export interface InboxAttachment {
@@ -43,7 +138,9 @@ export declare function inboxEntryAttachments(e: MirroredInboxEntry | {
43
138
  * as a bot is concerned — omitting them made an agent answer "no image came
44
139
  * through" for a DM that carried a screenshot.
45
140
  */
46
- export declare function summarizeInboxEntry(e: MirroredInboxEntry, done: boolean): {
141
+ export declare function summarizeInboxEntry(e: MirroredInboxEntry, done: boolean, ackPending?: boolean, ackFailed?: string): {
142
+ ackFailed?: string | undefined;
143
+ ackPending?: boolean | undefined;
47
144
  done: boolean;
48
145
  attachments?: InboxAttachment[] | undefined;
49
146
  id: string;