@indigoai-us/hq-cli 5.345.252 → 5.345.254
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/contracts/host-canary-release.json +11 -5
- package/dist/command-catalog.generated.d.ts +209 -0
- package/dist/command-catalog.generated.js +257 -0
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/ci-intake.d.ts +32 -0
- package/dist/commands/ci-intake.js +294 -0
- package/dist/commands/ci-metrics.d.ts +8 -0
- package/dist/commands/ci-metrics.js +55 -0
- package/dist/commands/ci-priorities.d.ts +56 -0
- package/dist/commands/ci-priorities.js +144 -0
- package/dist/commands/ci.d.ts +13 -0
- package/dist/commands/ci.js +11 -0
- package/dist/commands/cloud.d.ts +11 -0
- package/dist/commands/cloud.js +76 -0
- package/dist/commands/files.d.ts +62 -0
- package/dist/commands/files.js +249 -8
- package/dist/lib/bot/fleet-cron.d.ts +15 -0
- package/dist/lib/bot/fleet-cron.js +119 -20
- package/dist/lib/daemon/run.js +4 -3
- package/dist/lib/daemon/verified-jq.d.ts +6 -0
- package/dist/lib/daemon/verified-jq.js +17 -5
- package/dist/lib/delivery/migrations.d.ts +32 -1
- package/dist/lib/delivery/migrations.js +69 -8
- package/dist/lib/hook-engine/adapter-core-pin.d.ts +2 -1
- package/dist/lib/hook-engine/adapter-core-pin.js +2 -1
- package/dist/lib/hook-engine/coverage.d.ts +15 -0
- package/dist/lib/hook-engine/coverage.js +62 -1
- package/dist/lib/hook-engine/fleet-registration.d.ts +4 -0
- package/dist/lib/hook-engine/fleet-registration.js +25 -3
- package/dist/lib/smart-ci/cost.d.ts +72 -0
- package/dist/lib/smart-ci/cost.js +120 -0
- package/dist/lib/smart-ci/github.d.ts +112 -0
- package/dist/lib/smart-ci/github.js +267 -0
- package/dist/lib/smart-ci/intake.d.ts +288 -0
- package/dist/lib/smart-ci/intake.js +1078 -0
- package/dist/lib/smart-ci/ledger.d.ts +218 -0
- package/dist/lib/smart-ci/ledger.js +527 -0
- package/dist/lib/smart-ci/metrics.d.ts +137 -0
- package/dist/lib/smart-ci/metrics.js +249 -0
- package/dist/lib/smart-ci/priorities.d.ts +331 -0
- package/dist/lib/smart-ci/priorities.js +964 -0
- package/dist/lib/smart-ci/priority-refresh.d.ts +192 -0
- package/dist/lib/smart-ci/priority-refresh.js +366 -0
- package/dist/lib/smart-ci/priority-snapshots.d.ts +88 -0
- package/dist/lib/smart-ci/priority-snapshots.js +233 -0
- package/dist/lib/smart-ci/records.d.ts +265 -0
- package/dist/lib/smart-ci/records.js +281 -0
- package/dist/lib/smart-ci/reducer.d.ts +67 -0
- package/dist/lib/smart-ci/reducer.js +261 -0
- package/dist/lib/smart-ci/sources.d.ts +294 -0
- package/dist/lib/smart-ci/sources.js +659 -0
- package/dist/lib/smart-ci/text.d.ts +24 -0
- package/dist/lib/smart-ci/text.js +83 -0
- package/dist/lib/smart-ci/work-in-flight.d.ts +68 -0
- package/dist/lib/smart-ci/work-in-flight.js +154 -0
- package/dist/lib/sync/cli-manifest-reconcile.d.ts +20 -0
- package/dist/lib/sync/cli-manifest-reconcile.js +170 -0
- package/dist/lib/sync-core/engine-holds.d.ts +14 -0
- package/dist/lib/sync-core/engine-holds.js +78 -11
- package/dist/lib/sync-core/hand-back.d.ts +1 -0
- package/dist/lib/sync-core/hand-back.js +7 -2
- package/dist/lib/sync-core/reconcile.js +10 -2
- package/dist/utils/host-registration.d.ts +1 -0
- package/dist/utils/host-registration.js +1 -1
- package/package.json +9 -7
package/dist/commands/cloud.d.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* (also `hq daemon sync status --local`)
|
|
15
15
|
*/
|
|
16
16
|
import { Command } from "commander";
|
|
17
|
+
import { type CliManifestTarget } from "../lib/sync/cli-manifest-reconcile.js";
|
|
17
18
|
import { VaultClient, scopeLookupSkipMessage, SyncScopeLookupError, type ConflictStrategy, type EntityContext, type MembershipSyncConfig, type SyncMode, type PullScope, type ExplicitGrant, type ShareOptions, type VaultServiceConfig } from "@indigoai-us/hq-cloud";
|
|
18
19
|
import { withSyncWatchdog, type SyncWatchdogLimits } from "../utils/sync-watchdog.js";
|
|
19
20
|
import { type BannerLevel } from "../lib/narrow-hint-banner.js";
|
|
@@ -356,6 +357,7 @@ export interface PullAllVaultClient {
|
|
|
356
357
|
getEntity(uid: string): Promise<{
|
|
357
358
|
slug?: string;
|
|
358
359
|
name?: string;
|
|
360
|
+
bucketName?: string;
|
|
359
361
|
} | null>;
|
|
360
362
|
/**
|
|
361
363
|
* US-011: optional — when present, `pullAll` calls it once per
|
|
@@ -419,6 +421,15 @@ export interface PullAllDeps {
|
|
|
419
421
|
* leg falls back to `all` (legacy behavior) — only the real path injects it.
|
|
420
422
|
*/
|
|
421
423
|
resolveScope?: (companyUid: string, slug: string) => Promise<PullScope>;
|
|
424
|
+
/**
|
|
425
|
+
* After a successful company pull, restore that company in
|
|
426
|
+
* companies/manifest.yaml (feedback_cff52592). Injected so tests can
|
|
427
|
+
* assert the call without touching the filesystem. Absent = skip.
|
|
428
|
+
*/
|
|
429
|
+
reconcileManifest?: (opts: {
|
|
430
|
+
hqRoot: string;
|
|
431
|
+
targets: readonly CliManifestTarget[];
|
|
432
|
+
}) => Promise<void> | void;
|
|
422
433
|
}
|
|
423
434
|
export interface PullAllOptions {
|
|
424
435
|
hqRoot: string;
|
package/dist/commands/cloud.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { isAccessDeniedError, accessDeniedKeyOf, formatAccessDenied, } from "../utils/access-denied-hint.js";
|
|
17
17
|
import { describeSyncError, formatRemoteListNotConverging, } from "../utils/remote-list-not-converging.js";
|
|
18
18
|
import { findReadOnlyLocalOnly, isGrantEnforced, readVaultAccessManifest, } from "../lib/sync/read-only-local-only.js";
|
|
19
|
+
import { reconcileCliPullManifest, } from "../lib/sync/cli-manifest-reconcile.js";
|
|
19
20
|
import { SERVER_OWNED_FOLDERS, findServerOwnedLocalOnly, } from "../lib/sync/server-owned-local-only.js";
|
|
20
21
|
import chalk from "chalk";
|
|
21
22
|
import * as fs from "fs";
|
|
@@ -883,10 +884,16 @@ export async function pullAll(options, deps) {
|
|
|
883
884
|
const plan = [];
|
|
884
885
|
for (const m of memberships) {
|
|
885
886
|
let slug = m.companyUid;
|
|
887
|
+
let name;
|
|
888
|
+
let bucketName;
|
|
886
889
|
try {
|
|
887
890
|
const info = await deps.vaultClient.getEntity(m.companyUid);
|
|
888
891
|
if (info?.slug)
|
|
889
892
|
slug = info.slug;
|
|
893
|
+
if (info?.name)
|
|
894
|
+
name = info.name;
|
|
895
|
+
if (info?.bucketName)
|
|
896
|
+
bucketName = info.bucketName;
|
|
890
897
|
}
|
|
891
898
|
catch {
|
|
892
899
|
// Best-effort — keep UID as the row label rather than aborting the run.
|
|
@@ -897,6 +904,8 @@ export async function pullAll(options, deps) {
|
|
|
897
904
|
slug,
|
|
898
905
|
companyUid: m.companyUid,
|
|
899
906
|
...(m.membershipKey ? { membershipKey: m.membershipKey } : {}),
|
|
907
|
+
...(name ? { name } : {}),
|
|
908
|
+
...(bucketName ? { bucketName } : {}),
|
|
900
909
|
syncOptions: {
|
|
901
910
|
company: m.companyUid,
|
|
902
911
|
hqRoot: options.hqRoot,
|
|
@@ -1029,6 +1038,37 @@ export async function pullAll(options, deps) {
|
|
|
1029
1038
|
result.perCompany.push({ slug: entry.slug, error: message });
|
|
1030
1039
|
}
|
|
1031
1040
|
}
|
|
1041
|
+
// The menubar runner reconciles companies/manifest.yaml after a companies
|
|
1042
|
+
// fanout. CLI pull never did, so joiners pulled files into companies/<slug>
|
|
1043
|
+
// and still could not bind (feedback_cff52592).
|
|
1044
|
+
if (deps.reconcileManifest) {
|
|
1045
|
+
const completed = result.perCompany.filter((row) => !row.error);
|
|
1046
|
+
const targets = [];
|
|
1047
|
+
for (const entry of plan) {
|
|
1048
|
+
if (!entry.companyUid)
|
|
1049
|
+
continue;
|
|
1050
|
+
if (entry.syncOptions.personalMode === true || entry.slug === "personal") {
|
|
1051
|
+
continue;
|
|
1052
|
+
}
|
|
1053
|
+
if (!completed.some((row) => row.slug === entry.slug))
|
|
1054
|
+
continue;
|
|
1055
|
+
targets.push({
|
|
1056
|
+
slug: entry.slug,
|
|
1057
|
+
uid: entry.companyUid,
|
|
1058
|
+
...(entry.name ? { name: entry.name } : {}),
|
|
1059
|
+
...(entry.bucketName ? { bucketName: entry.bucketName } : {}),
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
if (targets.length > 0) {
|
|
1063
|
+
try {
|
|
1064
|
+
await deps.reconcileManifest({ hqRoot: options.hqRoot, targets });
|
|
1065
|
+
}
|
|
1066
|
+
catch {
|
|
1067
|
+
// Same as the runner: a reconcile write failure is diagnostic, not a
|
|
1068
|
+
// failed pull. The files are already on disk.
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1032
1072
|
return result;
|
|
1033
1073
|
}
|
|
1034
1074
|
/**
|
|
@@ -1976,6 +2016,39 @@ export function registerCloudCommands(program) {
|
|
|
1976
2016
|
aborted: result.aborted,
|
|
1977
2017
|
});
|
|
1978
2018
|
console.log(chalk.green(`\n✓ Pulled ${result.filesDownloaded} file(s) (${formatBytes(result.bytesDownloaded)}, ${result.filesSkipped} skipped, ${result.conflicts} conflicts)`));
|
|
2019
|
+
// Same post-pull restore the --all path does (feedback_cff52592).
|
|
2020
|
+
if (resolvedCompanyUid) {
|
|
2021
|
+
try {
|
|
2022
|
+
let slug = options.company ?? readActiveCompany(options.hqRoot);
|
|
2023
|
+
let name;
|
|
2024
|
+
let bucketName;
|
|
2025
|
+
try {
|
|
2026
|
+
const entity = await pullClient.entity.get(resolvedCompanyUid);
|
|
2027
|
+
if (typeof entity.slug === "string" && entity.slug.length > 0) {
|
|
2028
|
+
slug = entity.slug;
|
|
2029
|
+
}
|
|
2030
|
+
name = typeof entity.name === "string" ? entity.name : undefined;
|
|
2031
|
+
bucketName =
|
|
2032
|
+
typeof entity.bucketName === "string" ? entity.bucketName : undefined;
|
|
2033
|
+
}
|
|
2034
|
+
catch {
|
|
2035
|
+
// cloud_uid alone is enough to bind.
|
|
2036
|
+
}
|
|
2037
|
+
if (slug) {
|
|
2038
|
+
reconcileCliPullManifest(options.hqRoot, [
|
|
2039
|
+
{
|
|
2040
|
+
slug,
|
|
2041
|
+
uid: resolvedCompanyUid,
|
|
2042
|
+
...(name ? { name } : {}),
|
|
2043
|
+
...(bucketName ? { bucketName } : {}),
|
|
2044
|
+
},
|
|
2045
|
+
]);
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
catch {
|
|
2049
|
+
// Diagnostic only — files are already on disk.
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
1979
2052
|
// Emit the hint banner after success so it appears alongside the
|
|
1980
2053
|
// summary line. Mirrors the wiring in runPullAll and runNowSingle.
|
|
1981
2054
|
// Size-gated: only a large local folder is nudged.
|
|
@@ -2205,6 +2278,9 @@ async function runPullAll(hqRoot, onConflict, modeAllOverride, skipPersonal, for
|
|
|
2205
2278
|
// via the shared resolver, so the actual pull is scoped — the CLI no
|
|
2206
2279
|
// longer seeds an all-mode PullRecord that wedges the menubar runner.
|
|
2207
2280
|
resolveScope: (companyUid, slug) => resolvePullScope(realClient, companyUid, slug, hqRoot),
|
|
2281
|
+
reconcileManifest: ({ hqRoot: root, targets }) => {
|
|
2282
|
+
reconcileCliPullManifest(root, targets);
|
|
2283
|
+
},
|
|
2208
2284
|
sync: (opts) => syncLeg({
|
|
2209
2285
|
company: opts.company,
|
|
2210
2286
|
hqRoot: opts.hqRoot,
|
package/dist/commands/files.d.ts
CHANGED
|
@@ -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 {
|
package/dist/commands/files.js
CHANGED
|
@@ -678,6 +678,7 @@ export function registerFilesCommand(program) {
|
|
|
678
678
|
.option("--dry-run", "List what WOULD be deleted without deleting anything")
|
|
679
679
|
.option("--personal", "Target your own personal vault instead of a company vault (mutually exclusive with --company)")
|
|
680
680
|
.option("-y, --yes", "Skip the confirmation prompt (for scripts); not above 1000 objects")
|
|
681
|
+
.option("--confirmation <token>", "Send an hqdc_ delete confirmation token with a real company-vault delete; asks you to type the confirmation in a terminal first (not with --dry-run or --personal)")
|
|
681
682
|
.action(async (prefix, opts) => {
|
|
682
683
|
try {
|
|
683
684
|
const companySlug = files.opts().company;
|
|
@@ -692,6 +693,7 @@ export function registerFilesCommand(program) {
|
|
|
692
693
|
yes: opts.yes === true,
|
|
693
694
|
personal,
|
|
694
695
|
companySlug,
|
|
696
|
+
...(opts.confirmation !== undefined ? { confirmation: opts.confirmation } : {}),
|
|
695
697
|
});
|
|
696
698
|
}
|
|
697
699
|
catch (err) {
|
|
@@ -1350,6 +1352,112 @@ async function runShareSession(params) {
|
|
|
1350
1352
|
console.log(chalk.dim(" --no-open: copy the URL above to share manually."));
|
|
1351
1353
|
}
|
|
1352
1354
|
}
|
|
1355
|
+
export const DELETE_CEILING_EXCEEDED_CODE = "FILES_DELETE_CEILING_EXCEEDED";
|
|
1356
|
+
export const DELETE_CEILING_APPROVAL_REQUIRED_CODE = "FILES_DELETE_CEILING_APPROVAL_REQUIRED";
|
|
1357
|
+
export const DELETE_CONFIRMATION_INVALID_CODE = "FILES_DELETE_CONFIRMATION_INVALID";
|
|
1358
|
+
export const DELETE_CONFIRMATION_FIELD = "deleteConfirmation";
|
|
1359
|
+
function readUsage(v) {
|
|
1360
|
+
if (!v || typeof v !== "object")
|
|
1361
|
+
return undefined;
|
|
1362
|
+
const u = v;
|
|
1363
|
+
const n = (x) => (typeof x === "number" && Number.isFinite(x) ? x : undefined);
|
|
1364
|
+
const limit = n(u.limit);
|
|
1365
|
+
const requested = n(u.requested);
|
|
1366
|
+
const usedInWindow = n(u.usedInWindow);
|
|
1367
|
+
const windowSeconds = n(u.windowSeconds);
|
|
1368
|
+
if (limit === undefined || requested === undefined || usedInWindow === undefined || windowSeconds === undefined) {
|
|
1369
|
+
return undefined;
|
|
1370
|
+
}
|
|
1371
|
+
return {
|
|
1372
|
+
limit,
|
|
1373
|
+
requested,
|
|
1374
|
+
usedInWindow,
|
|
1375
|
+
windowSeconds,
|
|
1376
|
+
confirmLimit: n(u.confirmLimit) ?? limit,
|
|
1377
|
+
...(typeof u.basis === "string" ? { basis: u.basis } : {}),
|
|
1378
|
+
...(u.mode === "shadow" || u.mode === "enforce" ? { mode: u.mode } : {}),
|
|
1379
|
+
...(typeof u.enforced === "boolean" ? { enforced: u.enforced } : {}),
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
function safeText(v, max) {
|
|
1383
|
+
if (typeof v !== "string" || v.trim() === "")
|
|
1384
|
+
return undefined;
|
|
1385
|
+
if ([...v].some((c) => c.charCodeAt(0) < 0x20 || c.charCodeAt(0) === 0x7f))
|
|
1386
|
+
return undefined;
|
|
1387
|
+
return v.trim().slice(0, max);
|
|
1388
|
+
}
|
|
1389
|
+
export function isWellFormedConfirmationToken(v) {
|
|
1390
|
+
return typeof v === "string" && /^hqdc_[A-Za-z0-9_-]{32,123}$/.test(v);
|
|
1391
|
+
}
|
|
1392
|
+
export function parseCeilingRefusal(body) {
|
|
1393
|
+
if (!body || typeof body !== "object")
|
|
1394
|
+
return undefined;
|
|
1395
|
+
const b = body;
|
|
1396
|
+
if (b.code !== DELETE_CEILING_EXCEEDED_CODE && b.code !== DELETE_CEILING_APPROVAL_REQUIRED_CODE)
|
|
1397
|
+
return undefined;
|
|
1398
|
+
const c = b.confirmation && typeof b.confirmation === "object" ? b.confirmation : undefined;
|
|
1399
|
+
const a = b.approval && typeof b.approval === "object" ? b.approval : undefined;
|
|
1400
|
+
const expiresAt = safeText(c?.expiresAt, 64);
|
|
1401
|
+
const confirmation = c && isWellFormedConfirmationToken(c.token) && expiresAt !== undefined
|
|
1402
|
+
? { token: c.token, expiresAt, sufficient: c.sufficient === true }
|
|
1403
|
+
: null;
|
|
1404
|
+
const roles = Array.isArray(a?.roles) ? a.roles.filter((r) => typeof r === "string").slice(0, 5) : [];
|
|
1405
|
+
const usage = readUsage(b.deleteCeiling);
|
|
1406
|
+
const rejected = safeText(b.confirmationRejected, 32);
|
|
1407
|
+
const error = safeText(b.error, 600);
|
|
1408
|
+
return {
|
|
1409
|
+
code: b.code,
|
|
1410
|
+
...(error !== undefined ? { error } : {}),
|
|
1411
|
+
...(usage ? { deleteCeiling: usage } : {}),
|
|
1412
|
+
confirmation,
|
|
1413
|
+
approval: {
|
|
1414
|
+
required: a?.required === true || b.code === DELETE_CEILING_APPROVAL_REQUIRED_CODE,
|
|
1415
|
+
roles: roles.map((r) => r.slice(0, 20)),
|
|
1416
|
+
},
|
|
1417
|
+
...(rejected !== undefined ? { confirmationRejected: rejected } : {}),
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
function describeUsage(u) {
|
|
1421
|
+
const minutes = Math.max(1, Math.round(u.windowSeconds / 60));
|
|
1422
|
+
return (`This delete would remove ${u.requested} objects, and ${u.usedInWindow} were already deleted in this vault ` +
|
|
1423
|
+
`in the last ${minutes} minutes. The company's delete limit is ${u.limit} per ${minutes} minutes.`);
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* The way forward that works today when a delete needs another admin's
|
|
1427
|
+
* approval: no HQ command can send that approval yet. The server's window
|
|
1428
|
+
* total includes the requested count, so when one delete alone is over the
|
|
1429
|
+
* approval tier, waiting never helps and the only path without approval is
|
|
1430
|
+
* chunks no bigger than the limit, one window apart. Otherwise waiting for
|
|
1431
|
+
* the window to pass is the way forward.
|
|
1432
|
+
*/
|
|
1433
|
+
function ceilingWaysForward(u) {
|
|
1434
|
+
const window = u
|
|
1435
|
+
? `the ${Math.max(1, Math.round(u.windowSeconds / 60))}-minute window`
|
|
1436
|
+
: "the delete limit's time window";
|
|
1437
|
+
if (u && u.requested > u.confirmLimit) {
|
|
1438
|
+
return (`This one delete of ${u.requested} objects is over the ${u.confirmLimit}-object approval limit by itself, ` +
|
|
1439
|
+
"so waiting will not let it through. To go ahead without approval, split it into chunks of no more than " +
|
|
1440
|
+
`${u.limit} objects and wait for ${window} to pass between chunks.`);
|
|
1441
|
+
}
|
|
1442
|
+
return (`To go ahead, wait for ${window} to pass so earlier deletes stop counting. ` +
|
|
1443
|
+
"Splitting the delete into smaller prefixes does not help here, because the limit counts every delete in the window.");
|
|
1444
|
+
}
|
|
1445
|
+
function needsApproval(r) {
|
|
1446
|
+
return r.approval.required || (r.confirmation !== null && !r.confirmation.sufficient);
|
|
1447
|
+
}
|
|
1448
|
+
export function describeCeilingRefusal(r) {
|
|
1449
|
+
const parts = ["The server stopped this delete. Nothing was deleted."];
|
|
1450
|
+
if (r.deleteCeiling)
|
|
1451
|
+
parts.push(describeUsage(r.deleteCeiling));
|
|
1452
|
+
if (r.confirmationRejected)
|
|
1453
|
+
parts.push(`The confirmation sent was not accepted (${r.confirmationRejected}).`);
|
|
1454
|
+
if (needsApproval(r)) {
|
|
1455
|
+
const roles = r.approval.roles.length > 0 ? r.approval.roles.join(" or ") : "owner or admin";
|
|
1456
|
+
parts.push(`Another company ${roles} must approve this delete before it can run, and no HQ command can give that approval yet.`);
|
|
1457
|
+
parts.push(ceilingWaysForward(r.deleteCeiling));
|
|
1458
|
+
}
|
|
1459
|
+
return parts.join(" ");
|
|
1460
|
+
}
|
|
1353
1461
|
export class FilesDeleteHttpError extends Error {
|
|
1354
1462
|
status;
|
|
1355
1463
|
code;
|
|
@@ -1360,6 +1468,14 @@ export class FilesDeleteHttpError extends Error {
|
|
|
1360
1468
|
this.name = "FilesDeleteHttpError";
|
|
1361
1469
|
}
|
|
1362
1470
|
}
|
|
1471
|
+
export class FilesDeleteCeilingError extends FilesDeleteHttpError {
|
|
1472
|
+
refusal;
|
|
1473
|
+
constructor(status, refusal) {
|
|
1474
|
+
super(status, describeCeilingRefusal(refusal), refusal.code);
|
|
1475
|
+
this.refusal = refusal;
|
|
1476
|
+
this.name = "FilesDeleteCeilingError";
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1363
1479
|
/** Client-side ceiling: more objects than this in one delete needs a typed confirmation. */
|
|
1364
1480
|
export const DELETE_CEILING_COUNT = 1000;
|
|
1365
1481
|
/** Why a previewed delete is over the client-side ceiling, or undefined. */
|
|
@@ -1371,6 +1487,11 @@ export function clientCeilingReason(preview) {
|
|
|
1371
1487
|
}
|
|
1372
1488
|
/** Map a FilesDeleteHttpError to user-facing copy. */
|
|
1373
1489
|
export function formatFilesDeleteError(err, prefix) {
|
|
1490
|
+
if (err instanceof FilesDeleteCeilingError)
|
|
1491
|
+
return err.message;
|
|
1492
|
+
if (err.code === DELETE_CONFIRMATION_INVALID_CODE) {
|
|
1493
|
+
return `${err.message || "The delete confirmation was not accepted."} Nothing was deleted.`;
|
|
1494
|
+
}
|
|
1374
1495
|
if (err.status === 401) {
|
|
1375
1496
|
return "Not authenticated — please run `hq login`";
|
|
1376
1497
|
}
|
|
@@ -1420,6 +1541,7 @@ function realPrompt(message) {
|
|
|
1420
1541
|
* `personal` flag — so there is nothing for the client to get wrong or spoof.
|
|
1421
1542
|
*/
|
|
1422
1543
|
export async function callDeleteEndpoint(params) {
|
|
1544
|
+
const confirm = params.deleteConfirmation !== undefined ? { [DELETE_CONFIRMATION_FIELD]: params.deleteConfirmation } : {};
|
|
1423
1545
|
const res = await vaultApiFetch({
|
|
1424
1546
|
token: params.token,
|
|
1425
1547
|
path: "/v1/files/delete",
|
|
@@ -1429,15 +1551,20 @@ export async function callDeleteEndpoint(params) {
|
|
|
1429
1551
|
personal: true,
|
|
1430
1552
|
prefix: params.prefix,
|
|
1431
1553
|
dryRun: params.dryRun,
|
|
1554
|
+
...confirm,
|
|
1432
1555
|
}
|
|
1433
1556
|
: {
|
|
1434
1557
|
company: params.companyUid,
|
|
1435
1558
|
prefix: params.prefix,
|
|
1436
1559
|
dryRun: params.dryRun,
|
|
1560
|
+
...confirm,
|
|
1437
1561
|
},
|
|
1438
1562
|
});
|
|
1439
1563
|
if (!res.ok) {
|
|
1440
1564
|
const body = (await res.json().catch(() => ({})));
|
|
1565
|
+
const refusal = res.status === 409 ? parseCeilingRefusal(body) : undefined;
|
|
1566
|
+
if (refusal)
|
|
1567
|
+
throw new FilesDeleteCeilingError(res.status, refusal);
|
|
1441
1568
|
throw new FilesDeleteHttpError(res.status, body.message ?? body.error ?? res.statusText, body.code);
|
|
1442
1569
|
}
|
|
1443
1570
|
return (await res.json());
|
|
@@ -1624,10 +1751,63 @@ function normalizeCompanyFilePrefix(prefix, options = {}) {
|
|
|
1624
1751
|
`is already company-scoped; using bucket-relative '${scope.prefix}'.`));
|
|
1625
1752
|
return normalizeFilePrefix(scope.prefix);
|
|
1626
1753
|
}
|
|
1754
|
+
/**
|
|
1755
|
+
* Handle the server's delete-ceiling refusal. The confirmation token is sent
|
|
1756
|
+
* only after the person types the confirmation in a terminal; --yes alone
|
|
1757
|
+
* never sends it. Returns the token to send, or undefined when the person
|
|
1758
|
+
* declined. Exits 1 when the delete cannot be confirmed here.
|
|
1759
|
+
*/
|
|
1760
|
+
export async function confirmServerCeiling(refusal, deps) {
|
|
1761
|
+
const summary = describeCeilingRefusal(refusal);
|
|
1762
|
+
const confirmation = refusal.confirmation;
|
|
1763
|
+
if (needsApproval(refusal)) {
|
|
1764
|
+
console.error(chalk.red(summary));
|
|
1765
|
+
process.exit(1);
|
|
1766
|
+
}
|
|
1767
|
+
if (confirmation === null) {
|
|
1768
|
+
console.error(chalk.red(`${summary} The server did not issue a confirmation. Run the command again to get one.`));
|
|
1769
|
+
process.exit(1);
|
|
1770
|
+
}
|
|
1771
|
+
if (!deps.isInteractive()) {
|
|
1772
|
+
console.error(chalk.red(`${summary} Going ahead needs the confirmation typed in a terminal; --yes does not apply.`));
|
|
1773
|
+
process.exit(1);
|
|
1774
|
+
}
|
|
1775
|
+
const expiresAt = Date.parse(confirmation.expiresAt);
|
|
1776
|
+
const expired = () => !Number.isFinite(expiresAt) || deps.now().getTime() >= expiresAt;
|
|
1777
|
+
const expiredMessage = "The confirmation has expired or has no readable expiry time. Nothing was deleted. Run the command again.";
|
|
1778
|
+
if (expired()) {
|
|
1779
|
+
console.error(chalk.red(`${summary} ${expiredMessage}`));
|
|
1780
|
+
process.exit(1);
|
|
1781
|
+
}
|
|
1782
|
+
console.log(chalk.yellow(summary));
|
|
1783
|
+
const count = refusal.deleteCeiling?.requested;
|
|
1784
|
+
const phrase = count !== undefined ? `delete ${count} over the limit` : "delete over the limit";
|
|
1785
|
+
const answer = await deps.prompt(`Type '${phrase}' to go ahead (the confirmation expires at ${confirmation.expiresAt}): `);
|
|
1786
|
+
if (answer.trim() !== phrase) {
|
|
1787
|
+
console.log(chalk.dim("Aborted — nothing was deleted."));
|
|
1788
|
+
return undefined;
|
|
1789
|
+
}
|
|
1790
|
+
if (expired()) {
|
|
1791
|
+
console.error(chalk.red(expiredMessage));
|
|
1792
|
+
process.exit(1);
|
|
1793
|
+
}
|
|
1794
|
+
return confirmation.token;
|
|
1795
|
+
}
|
|
1627
1796
|
export async function runFilesDelete(params, deps = {}) {
|
|
1628
1797
|
const confirm = deps.confirm ?? realConfirm;
|
|
1629
1798
|
const prompt = deps.prompt ?? realPrompt;
|
|
1630
1799
|
const isInteractive = deps.isInteractive ?? (() => process.stdin.isTTY === true && process.stdout.isTTY === true);
|
|
1800
|
+
const now = deps.now ?? (() => new Date());
|
|
1801
|
+
if (params.dryRun && params.confirmation !== undefined) {
|
|
1802
|
+
console.error(chalk.red("--confirmation cannot be used with --dry-run: a dry run deletes nothing and never sends the confirmation. " +
|
|
1803
|
+
"Drop --dry-run to send it, or drop --confirmation to preview. Nothing was deleted."));
|
|
1804
|
+
process.exit(1);
|
|
1805
|
+
}
|
|
1806
|
+
if (params.personal === true && params.confirmation !== undefined) {
|
|
1807
|
+
console.error(chalk.red("--confirmation cannot be used with --personal: the delete confirmation applies only to company vaults. " +
|
|
1808
|
+
"Drop --confirmation to delete from your personal vault. Nothing was deleted."));
|
|
1809
|
+
process.exit(1);
|
|
1810
|
+
}
|
|
1631
1811
|
// Strip the local company anchor before preview/confirmation (HQ-8F/HQ-CA).
|
|
1632
1812
|
// Personal keys are already bucket-relative and must keep any such anchor.
|
|
1633
1813
|
// Deletion intentionally expands a folder spelling to a recursive glob, then
|
|
@@ -1695,6 +1875,26 @@ export async function runFilesDelete(params, deps = {}) {
|
|
|
1695
1875
|
if (overCeiling) {
|
|
1696
1876
|
console.log(chalk.yellow(`A real delete would stop here: ${overCeiling}. It needs the confirmation typed in a terminal; --yes does not skip it.`));
|
|
1697
1877
|
}
|
|
1878
|
+
const usage = readUsage(preview.deleteCeiling);
|
|
1879
|
+
if (usage && usage.usedInWindow + usage.requested > usage.limit) {
|
|
1880
|
+
const overConfirmLimit = usage.usedInWindow + usage.requested > usage.confirmLimit;
|
|
1881
|
+
if (usage.enforced === false) {
|
|
1882
|
+
// hq-pro #5656 watch-only mode: the server records the over-limit
|
|
1883
|
+
// delete but lets it through, so do not say it would be stopped.
|
|
1884
|
+
console.log(chalk.yellow("The company delete limit is in watch-only mode on the server, so a real delete would go through. " +
|
|
1885
|
+
`${describeUsage(usage)} ` +
|
|
1886
|
+
(overConfirmLimit
|
|
1887
|
+
? "Once the server enforces the limit, a delete like this would be stopped until another owner or admin approves it."
|
|
1888
|
+
: "Once the server enforces the limit, a delete like this would need a confirmation typed in a terminal.")));
|
|
1889
|
+
}
|
|
1890
|
+
else {
|
|
1891
|
+
console.log(chalk.yellow(`A real delete would be stopped by the company delete limit: ${describeUsage(usage)} ` +
|
|
1892
|
+
(overConfirmLimit
|
|
1893
|
+
? "Going ahead needs another owner or admin's approval. No HQ command can give that approval yet. " +
|
|
1894
|
+
ceilingWaysForward(usage)
|
|
1895
|
+
: "Going ahead needs a confirmation typed in a terminal.")));
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1698
1898
|
console.log(chalk.dim("Nothing was deleted (--dry-run)."));
|
|
1699
1899
|
return;
|
|
1700
1900
|
}
|
|
@@ -1730,22 +1930,63 @@ export async function runFilesDelete(params, deps = {}) {
|
|
|
1730
1930
|
return;
|
|
1731
1931
|
}
|
|
1732
1932
|
}
|
|
1933
|
+
let approvedToken;
|
|
1934
|
+
if (params.confirmation !== undefined) {
|
|
1935
|
+
if (!isWellFormedConfirmationToken(params.confirmation)) {
|
|
1936
|
+
console.error(chalk.red("--confirmation must be a delete confirmation from HQ (it starts with hqdc_). Nothing was deleted."));
|
|
1937
|
+
process.exit(1);
|
|
1938
|
+
}
|
|
1939
|
+
if (!isInteractive()) {
|
|
1940
|
+
console.error(chalk.red("--confirmation is sent only after you type the confirmation in a terminal. Nothing was deleted."));
|
|
1941
|
+
process.exit(1);
|
|
1942
|
+
}
|
|
1943
|
+
const phrase = `delete ${preview.matched} with approval`;
|
|
1944
|
+
const answer = await prompt(`Type '${phrase}' to send the approved confirmation and delete: `);
|
|
1945
|
+
if (answer.trim() !== phrase) {
|
|
1946
|
+
console.log(chalk.dim("Aborted — nothing was deleted."));
|
|
1947
|
+
return;
|
|
1948
|
+
}
|
|
1949
|
+
approvedToken = params.confirmation;
|
|
1950
|
+
}
|
|
1733
1951
|
// 3. Execute the delete.
|
|
1952
|
+
const realDelete = (deleteConfirmation) => callDeleteEndpoint({
|
|
1953
|
+
token,
|
|
1954
|
+
...scopeArgs,
|
|
1955
|
+
prefix: normalized,
|
|
1956
|
+
dryRun: false,
|
|
1957
|
+
...(deleteConfirmation !== undefined ? { deleteConfirmation } : {}),
|
|
1958
|
+
});
|
|
1734
1959
|
let result;
|
|
1735
1960
|
try {
|
|
1736
|
-
result = await
|
|
1737
|
-
token,
|
|
1738
|
-
...scopeArgs,
|
|
1739
|
-
prefix: normalized,
|
|
1740
|
-
dryRun: false,
|
|
1741
|
-
});
|
|
1961
|
+
result = await realDelete(approvedToken);
|
|
1742
1962
|
}
|
|
1743
1963
|
catch (err) {
|
|
1744
|
-
if (err instanceof
|
|
1964
|
+
if (err instanceof FilesDeleteCeilingError && approvedToken !== undefined) {
|
|
1965
|
+
console.error(chalk.red(err.message));
|
|
1966
|
+
process.exit(1);
|
|
1967
|
+
}
|
|
1968
|
+
else if (err instanceof FilesDeleteCeilingError) {
|
|
1969
|
+
const confirmed = await confirmServerCeiling(err.refusal, { prompt, isInteractive, now });
|
|
1970
|
+
if (confirmed === undefined)
|
|
1971
|
+
return;
|
|
1972
|
+
try {
|
|
1973
|
+
result = await realDelete(confirmed);
|
|
1974
|
+
}
|
|
1975
|
+
catch (retryErr) {
|
|
1976
|
+
if (retryErr instanceof FilesDeleteHttpError) {
|
|
1977
|
+
console.error(chalk.red(formatFilesDeleteError(retryErr, normalized)));
|
|
1978
|
+
process.exit(1);
|
|
1979
|
+
}
|
|
1980
|
+
throw retryErr;
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
else if (err instanceof FilesDeleteHttpError) {
|
|
1745
1984
|
console.error(chalk.red(formatFilesDeleteError(err, normalized)));
|
|
1746
1985
|
process.exit(1);
|
|
1747
1986
|
}
|
|
1748
|
-
|
|
1987
|
+
else {
|
|
1988
|
+
throw err;
|
|
1989
|
+
}
|
|
1749
1990
|
}
|
|
1750
1991
|
const deletedNoun = result.deleted === 1 ? "object" : "objects";
|
|
1751
1992
|
console.log(chalk.green(`Deleted ${result.deleted} ${deletedNoun} under '${normalized}'.`));
|
|
@@ -108,6 +108,19 @@ export declare const FLEET_HOT_SIGNAL_SYNC_NAME = "hot-signal-sync";
|
|
|
108
108
|
export declare const FLEET_HOT_SIGNAL_SYNC_SCHEDULE = "30 6 * * *";
|
|
109
109
|
export declare function fleetHotSignalSyncScript(company: string): string;
|
|
110
110
|
export declare function companyOfHotSignalSyncJob(job: FleetCronJob): string | null;
|
|
111
|
+
/**
|
|
112
|
+
* Waits between tries when a run fails because HQ could not reach the network.
|
|
113
|
+
* The job often fires the moment a laptop wakes, before Wi-Fi and DNS are back
|
|
114
|
+
* (Fleet catches up a missed daily run for up to 2 hours), so a short retry
|
|
115
|
+
* finds the connection. About 3.5 minutes in all, well inside Fleet's 1-hour
|
|
116
|
+
* script timeout.
|
|
117
|
+
*/
|
|
118
|
+
export declare const HOT_SIGNAL_SYNC_NETWORK_RETRY_DELAYS_SEC: readonly number[];
|
|
119
|
+
/**
|
|
120
|
+
* A network failure reaches the owner only once it repeats this many runs in a
|
|
121
|
+
* row. A single morning on a sleeping laptop is not worth a message.
|
|
122
|
+
*/
|
|
123
|
+
export declare const HOT_SIGNAL_SYNC_TRANSIENT_ALERT_AFTER = 2;
|
|
111
124
|
/**
|
|
112
125
|
* pnpm global installs land the CLI under `.../pnpm/global/vN/<hash>/...`.
|
|
113
126
|
* That hash folder is removed on the next CLI update. The stable launcher is
|
|
@@ -128,6 +141,8 @@ export declare function renderFleetHotSignalSyncScript(input: {
|
|
|
128
141
|
signalsEngine?: boolean;
|
|
129
142
|
/** Override the baked pnpm `bin/hq` fallback. Tests pass this. */
|
|
130
143
|
hqLauncher?: string;
|
|
144
|
+
/** Seconds between network retries. Default HOT_SIGNAL_SYNC_NETWORK_RETRY_DELAYS_SEC; tests pass zeros. */
|
|
145
|
+
networkRetryDelaysSec?: readonly number[];
|
|
131
146
|
}): string;
|
|
132
147
|
export interface EnsureFleetHotSignalSyncInput {
|
|
133
148
|
dir: string;
|