@indigoai-us/hq-cli 5.345.252 → 5.345.253

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 (43) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/contracts/host-canary-release.json +5 -5
  3. package/dist/command-catalog.generated.d.ts +148 -0
  4. package/dist/command-catalog.generated.js +182 -0
  5. package/dist/command-registration-plan.d.ts +6 -0
  6. package/dist/command-registration-plan.js +1 -0
  7. package/dist/commands/ci-intake.d.ts +15 -0
  8. package/dist/commands/ci-intake.js +252 -0
  9. package/dist/commands/ci-metrics.d.ts +8 -0
  10. package/dist/commands/ci-metrics.js +55 -0
  11. package/dist/commands/ci.d.ts +13 -0
  12. package/dist/commands/ci.js +10 -0
  13. package/dist/commands/files.d.ts +62 -0
  14. package/dist/commands/files.js +249 -8
  15. package/dist/lib/bot/fleet-cron.d.ts +15 -0
  16. package/dist/lib/bot/fleet-cron.js +119 -20
  17. package/dist/lib/daemon/run.js +4 -3
  18. package/dist/lib/delivery/migrations.d.ts +32 -1
  19. package/dist/lib/delivery/migrations.js +69 -8
  20. package/dist/lib/hook-engine/adapter-core-pin.d.ts +2 -1
  21. package/dist/lib/hook-engine/adapter-core-pin.js +2 -1
  22. package/dist/lib/hook-engine/coverage.d.ts +15 -0
  23. package/dist/lib/hook-engine/coverage.js +62 -1
  24. package/dist/lib/smart-ci/cost.d.ts +72 -0
  25. package/dist/lib/smart-ci/cost.js +120 -0
  26. package/dist/lib/smart-ci/github.d.ts +112 -0
  27. package/dist/lib/smart-ci/github.js +267 -0
  28. package/dist/lib/smart-ci/intake.d.ts +288 -0
  29. package/dist/lib/smart-ci/intake.js +1078 -0
  30. package/dist/lib/smart-ci/ledger.d.ts +218 -0
  31. package/dist/lib/smart-ci/ledger.js +527 -0
  32. package/dist/lib/smart-ci/metrics.d.ts +137 -0
  33. package/dist/lib/smart-ci/metrics.js +249 -0
  34. package/dist/lib/smart-ci/records.d.ts +265 -0
  35. package/dist/lib/smart-ci/records.js +281 -0
  36. package/dist/lib/smart-ci/reducer.d.ts +67 -0
  37. package/dist/lib/smart-ci/reducer.js +261 -0
  38. package/dist/lib/sync-core/engine-holds.d.ts +14 -0
  39. package/dist/lib/sync-core/engine-holds.js +78 -11
  40. package/dist/lib/sync-core/hand-back.d.ts +1 -0
  41. package/dist/lib/sync-core/hand-back.js +7 -2
  42. package/dist/lib/sync-core/reconcile.js +10 -2
  43. package/package.json +9 -7
@@ -0,0 +1,252 @@
1
+ /**
2
+ * `hq ci intake` — record what CI does into the HQ Native run ledger.
3
+ *
4
+ * Read-only towards GitHub: it sends GET requests only and registers no
5
+ * webhook. Three modes: poll GitHub (the default), replay a recorded fixture
6
+ * (--replay-fixture), or record a past window as a fixture (--record-fixture).
7
+ */
8
+ import { execFile } from "node:child_process";
9
+ import { writeFileSync } from "node:fs";
10
+ import { hostname } from "node:os";
11
+ import { join } from "node:path";
12
+ import { gzipSync } from "node:zlib";
13
+ import { DeliveryStoreError } from "../lib/delivery/store.js";
14
+ import { GitHubReadClient, GitHubReadError } from "../lib/smart-ci/github.js";
15
+ import { DEFAULT_HOURLY_BUDGET, DEFAULT_RATE_FLOOR, IntakeInputError, Poller, findSensitive, readFixture, recordWindow, replayFixture, scrubObservation, serializeFixture } from "../lib/smart-ci/intake.js";
16
+ import { SmartCiLedger, SmartCiLedgerError, defaultLedgerDir } from "../lib/smart-ci/ledger.js";
17
+ export const DEFAULT_REPOS = ["indigoai-us/hq-cli", "indigoai-us/hq-pro"];
18
+ export const DEFAULT_RUNNER_ORG = "indigoai-us";
19
+ class UsageError extends Error {
20
+ }
21
+ function positive(value, name, fallback) {
22
+ if (value === undefined)
23
+ return fallback;
24
+ const n = Number(value);
25
+ if (!Number.isFinite(n) || n <= 0)
26
+ throw new UsageError(`${name} must be a number above zero, got ${JSON.stringify(value)}`);
27
+ return n;
28
+ }
29
+ function nonNegative(value, name, fallback) {
30
+ if (value === undefined)
31
+ return fallback;
32
+ const n = Number(value);
33
+ if (!Number.isFinite(n) || n < 0)
34
+ throw new UsageError(`${name} must be zero or more, got ${JSON.stringify(value)}`);
35
+ return n;
36
+ }
37
+ /** Environment variables `gh` would take a token from in place of the signed-in login. */
38
+ const TOKEN_ENV = ["GH_TOKEN", "GITHUB_TOKEN", "GH_ENTERPRISE_TOKEN", "GITHUB_ENTERPRISE_TOKEN"];
39
+ const runGh = (file, args, env) => new Promise((resolve) => {
40
+ execFile(file, args, { timeout: 10_000, env }, (err, stdout) => resolve(err ? "" : stdout.trim()));
41
+ });
42
+ /**
43
+ * The GitHub token of this machine's signed-in `gh` login, and nothing else.
44
+ * A token in GH_TOKEN or GITHUB_TOKEN is never used: under an Actions or App
45
+ * installation token the intake would spend the allowance CI itself runs on.
46
+ * Those variables are also taken out of the environment `gh` is asked in, so
47
+ * `gh auth token` cannot hand one back. With no signed-in login the intake
48
+ * refuses to start. The token is held in memory and never printed or logged.
49
+ */
50
+ export async function resolveGitHubToken(env = process.env, run = runGh) {
51
+ const clean = { ...env };
52
+ for (const name of TOKEN_ENV)
53
+ delete clean[name];
54
+ const token = await run("gh", ["auth", "token", "--hostname", "github.com"], clean);
55
+ if (token === "") {
56
+ throw new UsageError("No signed-in gh login. The intake reads GitHub as this machine's gh login only (GH_TOKEN and GITHUB_TOKEN are not used). Sign in with `gh auth login` and start it again.");
57
+ }
58
+ return token;
59
+ }
60
+ function sleep(ms, signal) {
61
+ return new Promise((resolve) => {
62
+ if (signal.aborted)
63
+ return resolve();
64
+ const timer = setTimeout(done, ms);
65
+ function done() {
66
+ clearTimeout(timer);
67
+ signal.removeEventListener("abort", done);
68
+ resolve();
69
+ }
70
+ signal.addEventListener("abort", done);
71
+ });
72
+ }
73
+ async function runIntake(opts) {
74
+ const out = (line) => process.stdout.write(`${line}\n`);
75
+ const storeDir = opts.storeDir ?? defaultLedgerDir();
76
+ if (opts.recordFixture !== undefined) {
77
+ const repos = opts.repo ?? [];
78
+ if (repos.length !== 1 || !opts.from || !opts.to)
79
+ throw new UsageError("--record-fixture needs exactly one --repo, --from and --to");
80
+ const client = new GitHubReadClient({ token: await resolveGitHubToken(), auditPath: opts.auditLog });
81
+ const observations = (await recordWindow(client, { repo: repos[0], from: opts.from, to: opts.to, checkRuns: opts.checkRuns, log: (l) => process.stderr.write(`${l}\n`) })).map(scrubObservation);
82
+ const text = serializeFixture({ repo: repos[0], from: opts.from, to: opts.to, recordedAt: new Date().toISOString() }, observations);
83
+ const sensitive = findSensitive(text);
84
+ if (sensitive.length > 0) {
85
+ throw new IntakeInputError(`refusing to write the fixture: line ${sensitive[0].line} still holds ${sensitive[0].what} after scrubbing (${sensitive.length} lines in all)`);
86
+ }
87
+ writeFileSync(opts.recordFixture, opts.recordFixture.endsWith(".gz") ? gzipSync(text) : text);
88
+ const counts = client.counts();
89
+ const summary = { fixture: opts.recordFixture, observations: observations.length, requests: counts.total };
90
+ out(opts.json ? JSON.stringify(summary) : `Recorded ${observations.length} observations to ${opts.recordFixture} with ${counts.total} GitHub read requests.`);
91
+ return;
92
+ }
93
+ const ledger = SmartCiLedger.open({ dir: storeDir, controllerId: `smart-ci-intake@${hostname()}` });
94
+ try {
95
+ if (opts.replayFixture !== undefined) {
96
+ const fixture = readFixture(opts.replayFixture);
97
+ const report = replayFixture(ledger, fixture, {
98
+ batchSize: positive(opts.batchSize, "--batch-size", 200),
99
+ onBatch: (done, total) => process.stderr.write(`replayed ${done}/${total}\n`),
100
+ });
101
+ out(opts.json
102
+ ? JSON.stringify(report)
103
+ : `Replayed fixture ${report.fixtureId}: ${report.applied} of ${report.total} observations applied (${report.resumedFrom} already recorded), ${report.created} records created, ${report.updated} updated, ${report.unchanged} unchanged.`);
104
+ return;
105
+ }
106
+ const repos = opts.repo && opts.repo.length > 0 ? opts.repo : [...DEFAULT_REPOS];
107
+ const intervalMs = positive(opts.intervalSeconds, "--interval-seconds", 60) * 1000;
108
+ if (intervalMs < 10_000)
109
+ throw new UsageError("--interval-seconds must be 10 or more, to stay inside the GitHub request budget");
110
+ const durationMs = opts.durationMinutes === undefined ? null : positive(opts.durationMinutes, "--duration-minutes", 60) * 60_000;
111
+ const lookbackMs = nonNegative(opts.lookbackMinutes, "--lookback-minutes", 0) * 60_000;
112
+ const auditPath = opts.auditLog ?? join(storeDir, "smart-ci-github-audit.jsonl");
113
+ const client = new GitHubReadClient({ token: await resolveGitHubToken(), auditPath });
114
+ const startedMs = Date.now();
115
+ const poller = new Poller(ledger, client, {
116
+ repos,
117
+ runnerOrg: opts.runners === false ? null : (opts.runnerOrg ?? DEFAULT_RUNNER_ORG),
118
+ startAt: new Date(startedMs - lookbackMs).toISOString(),
119
+ hourlyBudget: positive(opts.hourlyBudget, "--hourly-budget", DEFAULT_HOURLY_BUDGET),
120
+ rateFloor: nonNegative(opts.rateFloor, "--rate-floor", DEFAULT_RATE_FLOOR),
121
+ activeWindowMs: nonNegative(opts.activeWindowMinutes, "--active-window-minutes", 120) * 60_000,
122
+ checkRuns: opts.checkRuns,
123
+ log: (l) => process.stderr.write(`${l}\n`),
124
+ });
125
+ const stop = new AbortController();
126
+ const onSignal = () => stop.abort();
127
+ process.once("SIGINT", onSignal);
128
+ process.once("SIGTERM", onSignal);
129
+ let cycles = 0;
130
+ let recorded = 0;
131
+ let gaps = 0;
132
+ let archived = 0;
133
+ let sweepStartedAt = null;
134
+ const tally = (report, sweep) => {
135
+ cycles += 1;
136
+ recorded += report.created;
137
+ gaps += report.gaps;
138
+ archived += report.archived;
139
+ const line = {
140
+ at: report.startedAt,
141
+ sweep,
142
+ observations: report.observations,
143
+ created: report.created,
144
+ updated: report.updated,
145
+ runsFinalized: report.runsFinalized,
146
+ openRuns: report.openRuns,
147
+ requestsLastHour: report.requests.lastHour,
148
+ chargedLastHour: report.chargedLastHour,
149
+ rateRemaining: report.requests.rateRemaining,
150
+ gaps: report.gaps,
151
+ archived: report.archived,
152
+ skipped: report.skipped.length,
153
+ };
154
+ process.stderr.write(`${JSON.stringify(line)}\n`);
155
+ };
156
+ try {
157
+ for (;;) {
158
+ const cycleStart = Date.now();
159
+ tally(await poller.cycle(), false);
160
+ if (opts.once || stop.signal.aborted)
161
+ break;
162
+ if (durationMs !== null && Date.now() - startedMs >= durationMs)
163
+ break;
164
+ const wait = Math.max(1000, intervalMs - (Date.now() - cycleStart));
165
+ await sleep(durationMs === null ? wait : Math.min(wait, Math.max(0, startedMs + durationMs - Date.now())), stop.signal);
166
+ if (stop.signal.aborted)
167
+ break;
168
+ if (durationMs !== null && Date.now() - startedMs >= durationMs)
169
+ break;
170
+ }
171
+ if (!opts.once) {
172
+ // Before stopping, read every open run once more, so the ledger holds each job GitHub lists up to this moment.
173
+ sweepStartedAt = new Date().toISOString();
174
+ tally(await poller.finish(), true);
175
+ }
176
+ }
177
+ finally {
178
+ process.removeListener("SIGINT", onSignal);
179
+ process.removeListener("SIGTERM", onSignal);
180
+ }
181
+ const counts = client.counts();
182
+ const summary = {
183
+ repos,
184
+ startedAt: new Date(startedMs).toISOString(),
185
+ endedAt: new Date().toISOString(),
186
+ sweepStartedAt,
187
+ cycles,
188
+ recordsCreated: recorded,
189
+ recordsArchived: archived,
190
+ gaps,
191
+ requests: counts.total,
192
+ notModified: counts.notModified,
193
+ charged: counts.total - counts.notModified,
194
+ chargedLastHour: poller.chargedLastHour(),
195
+ auditLog: auditPath,
196
+ storeDir,
197
+ };
198
+ out(opts.json
199
+ ? JSON.stringify(summary)
200
+ : `Intake ran ${cycles} cycles over ${repos.join(", ")}: ${recorded} records created, ${counts.total} GitHub read requests (${counts.notModified} answered "not modified" and are not charged), ${gaps} gaps recorded. Audit log: ${auditPath}`);
201
+ }
202
+ finally {
203
+ ledger.close();
204
+ }
205
+ }
206
+ export function registerCiIntakeCommand(ci) {
207
+ ci.command("intake")
208
+ .description("Record CI jobs, checks, pull requests, pushes and runner pool state into the run ledger (read-only towards GitHub)")
209
+ .option("--repo <owner/name>", "repository to record; repeat for more (default: indigoai-us/hq-cli and indigoai-us/hq-pro)", (v, prev = []) => [...prev, v])
210
+ .option("--runner-org <org>", `org whose runner pools are sampled (default: ${DEFAULT_RUNNER_ORG})`)
211
+ .option("--no-runners", "do not sample runner pools")
212
+ .option("--no-check-runs", "do not read check runs")
213
+ .option("--store-dir <path>", "ledger directory (default: HQ_SMART_CI_STORE_DIR, else ~/.hq/delivery/ledger)")
214
+ .option("--once", "run one cycle and stop")
215
+ .option("--duration-minutes <n>", "stop after this many minutes (default: run until stopped)")
216
+ .option("--interval-seconds <n>", "seconds between cycles (default: 60)")
217
+ .option("--lookback-minutes <n>", "on a first start, also record runs created this many minutes back (default: 0)")
218
+ .option("--hourly-budget <n>", `charged GitHub requests an hour the intake allows itself, counted across restarts (default: ${DEFAULT_HOURLY_BUDGET})`)
219
+ .option("--rate-floor <n>", `make no request while the gh login has this many or fewer requests left this hour (default: ${DEFAULT_RATE_FLOOR})`)
220
+ .option("--active-window-minutes <n>", "closed records older than this move to dated archive files; 0 keeps one file (default: 120)")
221
+ .option("--audit-log <path>", "where to write one line per GitHub request (default: smart-ci-github-audit.jsonl in the ledger directory)")
222
+ .option("--replay-fixture <path>", "record a fixture file instead of polling GitHub")
223
+ .option("--batch-size <n>", "observations per commit when replaying (default: 200)")
224
+ .option("--record-fixture <path>", "read a past window from GitHub and write it as a fixture; needs one --repo, --from and --to")
225
+ .option("--from <iso>", "start of the window to record (inclusive)")
226
+ .option("--to <iso>", "end of the window to record (exclusive)")
227
+ .option("--json", "print the final summary as JSON")
228
+ .action(async (opts) => {
229
+ try {
230
+ await runIntake(opts);
231
+ }
232
+ catch (err) {
233
+ if (err instanceof UsageError || err instanceof IntakeInputError || err instanceof GitHubReadError) {
234
+ process.stderr.write(`hq ci intake: ${err.message}\n`);
235
+ process.exitCode = err instanceof UsageError ? 2 : 1;
236
+ return;
237
+ }
238
+ if (err instanceof SmartCiLedgerError) {
239
+ process.stderr.write(`hq ci intake: ${err.message}\n`);
240
+ process.exitCode = 1;
241
+ return;
242
+ }
243
+ if (err instanceof DeliveryStoreError) {
244
+ process.stderr.write(`hq ci intake: the ledger could not be used (${err.code}). Found: ${err.found}. ${err.action}\n`);
245
+ process.exitCode = 1;
246
+ return;
247
+ }
248
+ throw err;
249
+ }
250
+ });
251
+ }
252
+ //# sourceMappingURL=ci-intake.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * `hq ci metrics` — queue waits, run times, replaced-head runs, runner idle and
3
+ * cold-start minutes, PR lead times and cost per merge for one repo, read from
4
+ * the run ledger. Reads only; works while the intake is running.
5
+ */
6
+ import type { Command } from "commander";
7
+ export declare function registerCiMetricsCommand(ci: Command): void;
8
+ //# sourceMappingURL=ci-metrics.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { DeliveryStoreError } from "../lib/delivery/store.js";
2
+ import { SmartCiView, defaultLedgerDir, readSmartCiHistory } from "../lib/smart-ci/ledger.js";
3
+ import { computeMetrics, parseWhen, renderMetrics } from "../lib/smart-ci/metrics.js";
4
+ import { KIND } from "../lib/smart-ci/records.js";
5
+ function amount(value, name) {
6
+ if (value === undefined)
7
+ return undefined;
8
+ const n = Number(value);
9
+ if (!Number.isFinite(n) || n < 0)
10
+ throw new Error(`${name} must be an amount in US dollars, zero or more, got ${JSON.stringify(value)}`);
11
+ return n;
12
+ }
13
+ export function registerCiMetricsCommand(ci) {
14
+ ci.command("metrics")
15
+ .description("Print CI waits, waste and cost per merge for a repo from the run ledger")
16
+ .requiredOption("--repo <owner/name>", "repository to report on")
17
+ .requiredOption("--since <date>", "start of the window, a date (2026-11-21) or an ISO time, UTC")
18
+ .option("--until <date>", "end of the window, exclusive (default: now)")
19
+ .option("--store-dir <path>", "ledger directory (default: HQ_SMART_CI_STORE_DIR, else ~/.hq/delivery/ledger)")
20
+ .option("--deploy-workflow <name>", "workflow that deploys to production on merge (default: known per repo)")
21
+ .option("--github-billed-usd <amount>", "billed GitHub amount for this repo and window, to use in place of the estimate")
22
+ .option("--aws-fleet-usd <amount>", "AWS runner fleet amount for this window, to use in place of the estimate")
23
+ .option("--json", "print the numbers as JSON")
24
+ .action((opts) => {
25
+ try {
26
+ if (!/^[\w.-]+\/[\w.-]+$/.test(opts.repo))
27
+ throw new Error(`--repo must be owner/name, got ${JSON.stringify(opts.repo)}`);
28
+ const sinceMs = parseWhen(opts.since, "--since");
29
+ if (opts.until !== undefined)
30
+ parseWhen(opts.until, "--until");
31
+ // The active file plus the archives last written since the window began. Only the kinds the metrics use are kept in memory.
32
+ const used = new Set([KIND.job, KIND.run, KIND.pullRequest, KIND.runnerSample]);
33
+ const view = new SmartCiView(readSmartCiHistory(opts.storeDir ?? defaultLedgerDir(), { since: new Date(sinceMs).toISOString(), keep: (r) => used.has(r.kind) }));
34
+ const metrics = computeMetrics(view, {
35
+ repo: opts.repo,
36
+ since: opts.since,
37
+ until: opts.until,
38
+ deployWorkflow: opts.deployWorkflow,
39
+ githubBilledUsd: amount(opts.githubBilledUsd, "--github-billed-usd"),
40
+ awsFleetUsd: amount(opts.awsFleetUsd, "--aws-fleet-usd"),
41
+ });
42
+ process.stdout.write(opts.json ? `${JSON.stringify(metrics, null, 2)}\n` : renderMetrics(metrics));
43
+ }
44
+ catch (err) {
45
+ if (err instanceof DeliveryStoreError) {
46
+ process.stderr.write(`hq ci metrics: the ledger could not be read (${err.code}). Found: ${err.found}. ${err.action}\n`);
47
+ process.exitCode = 1;
48
+ return;
49
+ }
50
+ process.stderr.write(`hq ci metrics: ${err instanceof Error ? err.message : String(err)}\n`);
51
+ process.exitCode = 2;
52
+ }
53
+ });
54
+ }
55
+ //# sourceMappingURL=ci-metrics.js.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `hq ci` — Smart CI (smart-ci project).
3
+ *
4
+ * The parent command only. Each subcommand lives in its own file and exports a
5
+ * `registerCi...(ci)` function; a new subcommand adds one import and one line
6
+ * to CI_SUBCOMMANDS and touches nothing else here.
7
+ *
8
+ * Smart CI is watch-only: nothing under `hq ci` changes GitHub, a workflow, a
9
+ * branch rule, the batch train or the runner fleet.
10
+ */
11
+ import type { Command } from "commander";
12
+ export declare function registerCiCommand(program: Command): void;
13
+ //# sourceMappingURL=ci.d.ts.map
@@ -0,0 +1,10 @@
1
+ import { registerCiIntakeCommand } from "./ci-intake.js";
2
+ import { registerCiMetricsCommand } from "./ci-metrics.js";
3
+ /** One entry per subcommand, in help order. */
4
+ const CI_SUBCOMMANDS = [registerCiIntakeCommand, registerCiMetricsCommand];
5
+ export function registerCiCommand(program) {
6
+ const ci = program.command("ci").description("Smart CI: record and measure what CI does (watch-only)");
7
+ for (const register of CI_SUBCOMMANDS)
8
+ register(ci);
9
+ }
10
+ //# sourceMappingURL=ci.js.map
@@ -156,12 +156,59 @@ export interface FilesDeleteResponse {
156
156
  tombstoned: number;
157
157
  keys: string[];
158
158
  keysTruncated: boolean;
159
+ /** Delete-ceiling usage the server reports on a dry run, when it has a ceiling. */
160
+ deleteCeiling?: DeleteCeilingUsage;
159
161
  }
162
+ export interface DeleteCeilingUsage {
163
+ limit: number;
164
+ confirmLimit: number;
165
+ windowSeconds: number;
166
+ usedInWindow: number;
167
+ requested: number;
168
+ basis?: string;
169
+ /** Server mode (hq-pro #5656): "shadow" only watches, "enforce" stops deletes. */
170
+ mode?: "shadow" | "enforce";
171
+ /**
172
+ * False when the server only watches: a real delete over the limit still
173
+ * goes through. Absent on servers older than hq-pro #5656's mode field.
174
+ */
175
+ enforced?: boolean;
176
+ }
177
+ export declare const DELETE_CEILING_EXCEEDED_CODE = "FILES_DELETE_CEILING_EXCEEDED";
178
+ export declare const DELETE_CEILING_APPROVAL_REQUIRED_CODE = "FILES_DELETE_CEILING_APPROVAL_REQUIRED";
179
+ export declare const DELETE_CONFIRMATION_INVALID_CODE = "FILES_DELETE_CONFIRMATION_INVALID";
180
+ export declare const DELETE_CONFIRMATION_FIELD = "deleteConfirmation";
181
+ /**
182
+ * Structured 409 refusal from the hq-pro per-company delete ceiling
183
+ * (hq-pro #5656). Field names must match the server.
184
+ */
185
+ export interface FilesDeleteCeilingRefusal {
186
+ code: typeof DELETE_CEILING_EXCEEDED_CODE | typeof DELETE_CEILING_APPROVAL_REQUIRED_CODE;
187
+ error?: string;
188
+ deleteCeiling?: DeleteCeilingUsage;
189
+ confirmation: {
190
+ token: string;
191
+ expiresAt: string;
192
+ sufficient: boolean;
193
+ } | null;
194
+ approval: {
195
+ required: boolean;
196
+ roles: string[];
197
+ };
198
+ confirmationRejected?: string;
199
+ }
200
+ export declare function isWellFormedConfirmationToken(v: unknown): v is string;
201
+ export declare function parseCeilingRefusal(body: unknown): FilesDeleteCeilingRefusal | undefined;
202
+ export declare function describeCeilingRefusal(r: FilesDeleteCeilingRefusal): string;
160
203
  export declare class FilesDeleteHttpError extends Error {
161
204
  readonly status: number;
162
205
  readonly code?: string | undefined;
163
206
  constructor(status: number, message: string, code?: string | undefined);
164
207
  }
208
+ export declare class FilesDeleteCeilingError extends FilesDeleteHttpError {
209
+ readonly refusal: FilesDeleteCeilingRefusal;
210
+ constructor(status: number, refusal: FilesDeleteCeilingRefusal);
211
+ }
165
212
  /** Client-side ceiling: more objects than this in one delete needs a typed confirmation. */
166
213
  export declare const DELETE_CEILING_COUNT = 1000;
167
214
  /** Why a previewed delete is over the client-side ceiling, or undefined. */
@@ -187,6 +234,7 @@ export declare function callDeleteEndpoint(params: {
187
234
  personal?: boolean;
188
235
  prefix: string;
189
236
  dryRun: boolean;
237
+ deleteConfirmation?: string;
190
238
  }): Promise<FilesDeleteResponse>;
191
239
  interface RunFilesDeleteParams {
192
240
  prefix: string;
@@ -195,6 +243,8 @@ interface RunFilesDeleteParams {
195
243
  /** Target the caller's personal vault instead of a company vault. */
196
244
  personal?: boolean;
197
245
  companySlug: string | undefined;
246
+ /** An approved delete confirmation token to send with the real delete. */
247
+ confirmation?: string;
198
248
  }
199
249
  /**
200
250
  * The vault bucket is already company-scoped, so a delete prefix must be
@@ -226,10 +276,22 @@ export declare function stripRedundantCompanyScope(prefix: string): {
226
276
  * `--company` (or is refused), or BECOMES the company when none was given.
227
277
  */
228
278
  export declare function companySlugFromAnchor(prefix: string, personal?: boolean): string | undefined;
279
+ /**
280
+ * Handle the server's delete-ceiling refusal. The confirmation token is sent
281
+ * only after the person types the confirmation in a terminal; --yes alone
282
+ * never sends it. Returns the token to send, or undefined when the person
283
+ * declined. Exits 1 when the delete cannot be confirmed here.
284
+ */
285
+ export declare function confirmServerCeiling(refusal: FilesDeleteCeilingRefusal, deps: {
286
+ prompt: PromptFn;
287
+ isInteractive: () => boolean;
288
+ now: () => Date;
289
+ }): Promise<string | undefined>;
229
290
  export interface RunFilesDeleteDeps {
230
291
  confirm?: ConfirmFn;
231
292
  prompt?: PromptFn;
232
293
  isInteractive?: () => boolean;
294
+ now?: () => Date;
233
295
  }
234
296
  export declare function runFilesDelete(params: RunFilesDeleteParams, deps?: RunFilesDeleteDeps): Promise<void>;
235
297
  export interface FileVersionRow {