@indigoai-us/hq-cli 5.345.245 → 5.345.247
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 +91 -0
- package/dist/command-catalog.generated.d.ts +96 -9
- package/dist/command-catalog.generated.js +117 -9
- package/dist/commands/bot.js +1 -1
- package/dist/commands/core-checkpoint-native.d.ts +5 -1
- package/dist/commands/core-checkpoint-native.js +13 -5
- package/dist/commands/deploy-comments.js +139 -0
- package/dist/commands/deploy-list.d.ts +5 -0
- package/dist/commands/deploy-list.js +8 -0
- package/dist/commands/dm.d.ts +4 -1
- package/dist/commands/dm.js +11 -2
- package/dist/commands/files.d.ts +11 -2
- package/dist/commands/files.js +48 -3
- package/dist/commands/install-global.d.ts +15 -0
- package/dist/commands/install-global.js +98 -4
- package/dist/commands/lanes-loop.js +4 -1
- package/dist/commands/lanes.js +16 -5
- package/dist/commands/mcp-registration.d.ts +17 -0
- package/dist/commands/mcp-registration.js +119 -0
- package/dist/commands/mesh.d.ts +2 -0
- package/dist/commands/mesh.js +26 -6
- package/dist/commands/pkg-install.js +1 -1
- package/dist/commands/reindex.js +3 -2
- package/dist/commands/rescue.d.ts +22 -1
- package/dist/commands/rescue.js +56 -9
- package/dist/commands/sources.d.ts +1 -1
- package/dist/commands/sources.js +1 -1
- package/dist/commands/storage.d.ts +15 -2
- package/dist/commands/storage.js +74 -7
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +232 -225
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/agent-kit/mcp/tools.js +22 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +4 -1
- package/dist/lib/daemon/fleet-members-cache.d.ts +55 -0
- package/dist/lib/daemon/fleet-members-cache.js +266 -0
- package/dist/lib/daemon/handoff.d.ts +4 -0
- package/dist/lib/daemon/handoff.js +2 -1
- package/dist/lib/daemon/hook-requests.d.ts +2 -1
- package/dist/lib/daemon/hook-requests.js +19 -2
- package/dist/lib/daemon/install.d.ts +9 -1
- package/dist/lib/daemon/install.js +11 -2
- package/dist/lib/daemon/ops/policy.d.ts +23 -3
- package/dist/lib/daemon/ops/policy.js +62 -15
- package/dist/lib/daemon/run.js +12 -0
- package/dist/lib/daemon/server.d.ts +5 -0
- package/dist/lib/daemon/server.js +1 -1
- package/dist/lib/daemon/supervisor.d.ts +6 -0
- package/dist/lib/daemon/supervisor.js +31 -2
- package/dist/lib/doctor/checks/antigravity-wiring.d.ts +21 -0
- package/dist/lib/doctor/checks/antigravity-wiring.js +75 -0
- package/dist/lib/doctor/checks/anywhere.js +30 -0
- package/dist/lib/doctor/checks/runtime-probe.js +13 -0
- package/dist/lib/doctor/checks/sync-runtime.js +8 -1
- package/dist/lib/doctor/platform.d.ts +1 -1
- package/dist/lib/doctor/platform.js +5 -0
- package/dist/lib/doctor/registry.js +3 -0
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/hook-engine/coverage.d.ts +159 -0
- package/dist/lib/hook-engine/coverage.js +347 -0
- package/dist/lib/hook-engine/native-precompact-compatibility.json +1 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +52 -2
- package/dist/lib/hot-channels/signals-pass.js +65 -3
- package/dist/lib/install/antigravity-targets.d.ts +39 -0
- package/dist/lib/install/antigravity-targets.js +122 -0
- package/dist/lib/install/claude-targets.d.ts +6 -0
- package/dist/lib/install/claude-targets.js +9 -1
- package/dist/lib/lanes/reconcile-result.d.ts +1 -1
- package/dist/lib/lanes/reconcile.js +19 -4
- package/dist/lib/lanes/remote-control-lane.d.ts +6 -0
- package/dist/lib/lanes/remote-control-lane.js +10 -1
- package/dist/lib/lanes/spawn.d.ts +2 -0
- package/dist/lib/lanes/spawn.js +19 -3
- package/dist/lib/lanes/worker-env-scrub.d.ts +48 -0
- package/dist/lib/lanes/worker-env-scrub.js +146 -0
- package/dist/lib/lanes/worker-process.js +4 -1
- package/dist/lib/mesh/client.js +5 -1
- package/dist/lib/mesh/live/daemon/doctor.d.ts +9 -0
- package/dist/lib/mesh/live/daemon/doctor.js +51 -6
- package/dist/lib/mesh/live/daemon/install.d.ts +39 -0
- package/dist/lib/mesh/live/daemon/install.js +70 -0
- package/dist/lib/mesh/live/daemon/outbox-company.d.ts +47 -0
- package/dist/lib/mesh/live/daemon/outbox-company.js +77 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
- package/dist/lib/mesh/live/daemon/run.js +48 -3
- package/dist/lib/mesh/live/daemon/state.d.ts +5 -0
- package/dist/lib/mesh/live/daemon/system-unit.d.ts +21 -0
- package/dist/lib/mesh/live/daemon/system-unit.js +80 -0
- package/dist/lib/mesh/live/daemon/transcript-watch.d.ts +4 -1
- package/dist/lib/mesh/live/daemon/transcript-watch.js +42 -38
- package/dist/lib/mesh/live/direct-drain.js +3 -1
- package/dist/lib/mesh/live/emit.js +4 -2
- package/dist/lib/mesh/live/flush.d.ts +61 -0
- package/dist/lib/mesh/live/flush.js +434 -114
- package/dist/lib/mesh/live/paths.d.ts +10 -0
- package/dist/lib/mesh/live/paths.js +14 -0
- package/dist/lib/mesh/live/reporting-privacy.d.ts +41 -1
- package/dist/lib/mesh/live/reporting-privacy.js +81 -7
- package/dist/lib/mesh/live/spool.d.ts +171 -17
- package/dist/lib/mesh/live/spool.js +777 -62
- package/dist/lib/signals/engine.d.ts +82 -2
- package/dist/lib/signals/engine.js +389 -53
- package/dist/lib/signals/steps/extract.js +5 -0
- package/dist/lib/work-context/organize.d.ts +22 -4
- package/dist/lib/work-context/organize.js +50 -21
- package/dist/lib/work-context/paths.d.ts +6 -0
- package/dist/lib/work-context/paths.js +9 -0
- package/dist/lib/work-context/reconcile.d.ts +1 -1
- package/dist/lib/work-context/reconcile.js +1 -1
- package/dist/startup-registration.d.ts +14 -0
- package/dist/startup-registration.js +26 -0
- package/dist/utils/cli-telemetry.d.ts +6 -0
- package/dist/utils/cli-telemetry.js +154 -9
- package/dist/utils/github-tag-fallback.d.ts +7 -2
- package/dist/utils/github-tag-fallback.js +17 -8
- package/dist/utils/hq-core-source.d.ts +31 -0
- package/dist/utils/hq-core-source.js +144 -0
- package/dist/utils/interactive-caller.d.ts +6 -0
- package/dist/utils/interactive-caller.js +8 -0
- package/dist/utils/shipped-codex-hooks.d.ts +6 -4
- package/dist/utils/shipped-codex-hooks.js +22 -10
- package/dist/utils/vault-api.js +1 -0
- package/dist/utils/version-report.d.ts +3 -1
- package/dist/utils/version-report.js +13 -5
- package/docs/anywhere-runtime.md +2 -2
- package/package.json +8 -8
- package/scripts/check-function-manifest.mjs +99 -18
|
@@ -219,6 +219,14 @@ export function isCodexInstalled(env) {
|
|
|
219
219
|
return false;
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
+
/** `~/.gemini/config` — the Antigravity config root. */
|
|
223
|
+
export function antigravityConfigDir(env) {
|
|
224
|
+
return path.join(env.home, '.gemini', 'config');
|
|
225
|
+
}
|
|
226
|
+
/** `~/.gemini/config/mcp_config.json` — the GLOBAL Antigravity MCP config (App, IDE and CLI share it). */
|
|
227
|
+
export function antigravityConfigPath(env) {
|
|
228
|
+
return path.join(antigravityConfigDir(env), 'mcp_config.json');
|
|
229
|
+
}
|
|
222
230
|
/** `~/.claude.json` — the PINNED single Claude surface (top-level mcpServers). */
|
|
223
231
|
export function claudeConfigPath(env) {
|
|
224
232
|
return path.join(env.home, '.claude.json');
|
|
@@ -1315,6 +1323,117 @@ export function registerClaudeServer(opts) {
|
|
|
1315
1323
|
throw e;
|
|
1316
1324
|
}
|
|
1317
1325
|
}
|
|
1326
|
+
// ---------------------------------------------------------------------------
|
|
1327
|
+
// Antigravity/JSON surface (`~/.gemini/config/mcp_config.json`).
|
|
1328
|
+
//
|
|
1329
|
+
// Shape: {"mcpServers": {"<name>": {command, args, env}}} for stdio, or
|
|
1330
|
+
// {serverUrl, headers} for Streamable HTTP. Antigravity does not support legacy
|
|
1331
|
+
// SSE, so an `sse` manifest is skipped. Every other server and top-level key is
|
|
1332
|
+
// preserved by the merge; the file goes through writeConfigAtomic (lock, backup,
|
|
1333
|
+
// atomic replace, verify). A non-empty file that is not valid JSON aborts with
|
|
1334
|
+
// ConfigParseError and is never overwritten.
|
|
1335
|
+
//
|
|
1336
|
+
// Only `hq install --global` writes here, and only the core `hq` server. Entries
|
|
1337
|
+
// carry no `_hqPack` provenance key: Google documents a fixed set of entry keys,
|
|
1338
|
+
// so HQ adds none. An existing entry counts as HQ's own when it is a local stdio
|
|
1339
|
+
// `... mcp serve` server (see {@link isHqLocalAntigravityServer}).
|
|
1340
|
+
// ---------------------------------------------------------------------------
|
|
1341
|
+
export const antigravityConfigFormat = {
|
|
1342
|
+
parse: jsonFormat.parse,
|
|
1343
|
+
serialize: jsonFormat.serialize,
|
|
1344
|
+
emptyDoc: () => ({}),
|
|
1345
|
+
assertEntry(doc, name) {
|
|
1346
|
+
const servers = doc.mcpServers;
|
|
1347
|
+
if (!servers || typeof servers !== 'object' || Array.isArray(servers) || !(name in servers)) {
|
|
1348
|
+
throw new Error(`mcpServers.${name} not present after write`);
|
|
1349
|
+
}
|
|
1350
|
+
},
|
|
1351
|
+
};
|
|
1352
|
+
/** Build the Antigravity server def (same command/args/env as Claude and Codex). */
|
|
1353
|
+
export function buildAntigravityServerDef(manifest, resolve, secretSink) {
|
|
1354
|
+
const def = {};
|
|
1355
|
+
if (manifest.type === 'http') {
|
|
1356
|
+
if (manifest.url !== undefined)
|
|
1357
|
+
def.serverUrl = manifest.url;
|
|
1358
|
+
if (manifest.headers !== undefined)
|
|
1359
|
+
def.headers = resolveStringMap(manifest.headers, resolve, secretSink);
|
|
1360
|
+
}
|
|
1361
|
+
else {
|
|
1362
|
+
if (manifest.command !== undefined)
|
|
1363
|
+
def.command = manifest.command;
|
|
1364
|
+
if (manifest.args !== undefined)
|
|
1365
|
+
def.args = manifest.args.map((arg) => resolveSecretRefs(arg, resolve, secretSink));
|
|
1366
|
+
if (manifest.env !== undefined)
|
|
1367
|
+
def.env = resolveStringMap(manifest.env, resolve, secretSink);
|
|
1368
|
+
}
|
|
1369
|
+
return def;
|
|
1370
|
+
}
|
|
1371
|
+
/** True iff `entry` is a local stdio server launched as `<cmd> ... mcp serve` (the shape HQ writes). */
|
|
1372
|
+
export function isHqLocalAntigravityServer(entry) {
|
|
1373
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry))
|
|
1374
|
+
return false;
|
|
1375
|
+
const e = entry;
|
|
1376
|
+
if (typeof e.command !== 'string' || e.serverUrl !== undefined || e.url !== undefined)
|
|
1377
|
+
return false;
|
|
1378
|
+
if (!Array.isArray(e.args) || e.args.length < 2)
|
|
1379
|
+
return false;
|
|
1380
|
+
return e.args[e.args.length - 2] === 'mcp' && e.args[e.args.length - 1] === 'serve';
|
|
1381
|
+
}
|
|
1382
|
+
/** Merge fn for the Antigravity surface. A foreign entry of the same name throws McpNameCollisionError. */
|
|
1383
|
+
export function mergeAntigravityServer(name, def) {
|
|
1384
|
+
return (doc) => {
|
|
1385
|
+
const current = doc.mcpServers;
|
|
1386
|
+
if (current !== undefined && (current === null || typeof current !== 'object' || Array.isArray(current))) {
|
|
1387
|
+
throw new McpNameCollisionError('mcpServers in ~/.gemini/config/mcp_config.json is not an object; refusing to rewrite it.');
|
|
1388
|
+
}
|
|
1389
|
+
const servers = { ...(current ?? {}) };
|
|
1390
|
+
const existing = servers[name];
|
|
1391
|
+
if (existing !== undefined) {
|
|
1392
|
+
if (serverDefsEqual(existing, def))
|
|
1393
|
+
return doc;
|
|
1394
|
+
if (isHqLocalAntigravityServer(existing) && isHqLocalAntigravityServer(def)) {
|
|
1395
|
+
servers[name] = def;
|
|
1396
|
+
return { ...doc, mcpServers: servers };
|
|
1397
|
+
}
|
|
1398
|
+
throw new McpNameCollisionError(`MCP server "${name}" is already defined in ~/.gemini/config/mcp_config.json with a ` +
|
|
1399
|
+
'different definition — refusing to overwrite. Remove or rename the existing server, then re-install.');
|
|
1400
|
+
}
|
|
1401
|
+
servers[name] = def;
|
|
1402
|
+
return { ...doc, mcpServers: servers };
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Emit ONE server into `~/.gemini/config/mcp_config.json`, creating the file if
|
|
1407
|
+
* needed. Skips SSE manifests, which Antigravity does not support. Called only by
|
|
1408
|
+
* `hq install --global`; registerServer does not fan out to Antigravity.
|
|
1409
|
+
*/
|
|
1410
|
+
export function registerAntigravityServer(opts) {
|
|
1411
|
+
assertValidServerName(opts.name);
|
|
1412
|
+
const env = resolveEnv(opts.env);
|
|
1413
|
+
if (opts.manifest.type === 'sse') {
|
|
1414
|
+
return { skipped: true, reason: 'Antigravity supports stdio and Streamable HTTP MCP servers, not SSE' };
|
|
1415
|
+
}
|
|
1416
|
+
const secretSink = new Set();
|
|
1417
|
+
const def = buildAntigravityServerDef(opts.manifest, opts.resolveSecret ?? noSecretResolver, secretSink);
|
|
1418
|
+
try {
|
|
1419
|
+
const res = writeConfigAtomic({
|
|
1420
|
+
target: antigravityConfigPath(env),
|
|
1421
|
+
pack: opts.pack,
|
|
1422
|
+
format: antigravityConfigFormat,
|
|
1423
|
+
merge: mergeAntigravityServer(opts.name, def),
|
|
1424
|
+
assertName: opts.name,
|
|
1425
|
+
env: opts.env,
|
|
1426
|
+
lock: opts.lock,
|
|
1427
|
+
stamp: opts.stamp,
|
|
1428
|
+
});
|
|
1429
|
+
return { changed: res.changed, realTarget: res.realTarget };
|
|
1430
|
+
}
|
|
1431
|
+
catch (e) {
|
|
1432
|
+
if (secretSink.size > 0 && e instanceof Error)
|
|
1433
|
+
e.message = redactSecrets(e.message, secretSink);
|
|
1434
|
+
throw e;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1318
1437
|
/**
|
|
1319
1438
|
* Resolve the Claude target path from a (partial) env, mirroring
|
|
1320
1439
|
* {@link claudeConfigPath} but tolerating an undefined env (production default).
|
package/dist/commands/mesh.d.ts
CHANGED
|
@@ -96,6 +96,8 @@ export declare function runDaemonStatus(opts: {
|
|
|
96
96
|
daemonPid: number;
|
|
97
97
|
pid?: number;
|
|
98
98
|
} | null;
|
|
99
|
+
/** Linux: directory holding the box's system units (tests pass a fake root). */
|
|
100
|
+
systemUnitDir?: string;
|
|
99
101
|
}): Promise<void>;
|
|
100
102
|
/** Work Mesh health report: `hq daemon doctor` (and the retiring `hq mesh daemon doctor`). */
|
|
101
103
|
export declare function runMeshDaemonDoctor(opts: {
|
package/dist/commands/mesh.js
CHANGED
|
@@ -40,9 +40,10 @@ import { generateUlid } from "../lib/mesh/live/ulid.js";
|
|
|
40
40
|
import { readLegacyBacklogForMode } from "../lib/mesh/live/emit-replay.js";
|
|
41
41
|
import { resolveMeshEmitMode, writeMeshConfigMode, } from "../lib/mesh/live/daemon/mode.js";
|
|
42
42
|
import { workMeshRoot } from "../lib/mesh/live/paths.js";
|
|
43
|
-
import { buildInstallPaths, daemonServiceIsLoaded, daemonServiceStatus, detectPlatform, installDaemonIfStale, installDaemonService, resolveAbsoluteNodeBinary, resolveRunningCliEntry, uninstallDaemonService, installedUnitHqRoot, } from "../lib/mesh/live/daemon/install.js";
|
|
43
|
+
import { buildInstallPaths, daemonServiceIsLoaded, daemonServiceStatus, detectPlatform, installDaemonIfStale, installDaemonService, MESH_DAEMON_SYSTEM_UNIT_EXIT, meshSystemUnitBlockingInstall, meshSystemUnitInChargeMessage, resolveAbsoluteNodeBinary, resolveRunningCliEntry, uninstallDaemonService, installedUnitHqRoot, } from "../lib/mesh/live/daemon/install.js";
|
|
44
44
|
import { findAncestorHqRoot, resolveIfStaleHqRoot, resolveInstallHqRoot, } from "../lib/mesh/live/daemon/config.js";
|
|
45
45
|
import { daemonDir as meshDaemonDir } from "../lib/mesh/live/daemon/paths.js";
|
|
46
|
+
import { readMeshSystemUnitState } from "../lib/mesh/live/daemon/system-unit.js";
|
|
46
47
|
import { collectDaemonDoctor, formatCliIdentityLines, formatDaemonDoctor, } from "../lib/mesh/live/daemon/doctor.js";
|
|
47
48
|
import { readDaemonState } from "../lib/mesh/live/daemon/state.js";
|
|
48
49
|
import { defaultRunCommand } from "../lib/service-manager/launchd.js";
|
|
@@ -2094,7 +2095,8 @@ async function runContextOrganize(opts) {
|
|
|
2094
2095
|
fail("`--session <sid>` is required and must be a valid session id");
|
|
2095
2096
|
}
|
|
2096
2097
|
const root = workContextHomeRoot();
|
|
2097
|
-
// Cancel / timeout / incapable →
|
|
2098
|
+
// Cancel / timeout / incapable → no project is chosen and the ask is not
|
|
2099
|
+
// repeated; a session that has its company keeps it (needs_project).
|
|
2098
2100
|
if (opts.cancel || opts.settle) {
|
|
2099
2101
|
const reason = opts.settle === "timeout"
|
|
2100
2102
|
? "timeout"
|
|
@@ -2106,7 +2108,7 @@ async function runContextOrganize(opts) {
|
|
|
2106
2108
|
console.log(JSON.stringify({ ok: true, action: "settle", reason, state }, null, opts.machine ? 0 : 2));
|
|
2107
2109
|
return;
|
|
2108
2110
|
}
|
|
2109
|
-
console.log(`Work mesh: session ${sessionId}
|
|
2111
|
+
console.log(`Work mesh: session ${sessionId} settled as ${state?.contextStatus ?? "unknown"} (${reason}); ask will not repeat.`);
|
|
2110
2112
|
return;
|
|
2111
2113
|
}
|
|
2112
2114
|
const isList = opts.list ||
|
|
@@ -3065,8 +3067,8 @@ export function registerMeshCommand(program, deps = {}) {
|
|
|
3065
3067
|
.option("--create-project <title>", "Create a new project then bind")
|
|
3066
3068
|
.option("--create-task <title>", "Create a new task on the session project then bind")
|
|
3067
3069
|
.option("--untracked", "Mark the session untracked (local receipt only)")
|
|
3068
|
-
.option("--cancel", "Settle ask without binding (
|
|
3069
|
-
.option("--settle <reason>", "Settle ask: cancelled|timeout|incapable (
|
|
3070
|
+
.option("--cancel", "Settle ask without binding a project (keeps the company; never repeat)")
|
|
3071
|
+
.option("--settle <reason>", "Settle ask: cancelled|timeout|incapable (keeps the company; never repeat)")
|
|
3070
3072
|
.option("--offline", "Do not fetch candidates / submit to server")
|
|
3071
3073
|
.option("--json", "Print machine-readable JSON")
|
|
3072
3074
|
.option("--machine", "Compact JSON on stdout")
|
|
@@ -3253,6 +3255,20 @@ async function runDaemonRun(opts = {}) {
|
|
|
3253
3255
|
});
|
|
3254
3256
|
}
|
|
3255
3257
|
async function runDaemonInstall(opts) {
|
|
3258
|
+
// A Linux box whose Work Mesh runs from /etc/systemd/system/hq-mesh-daemon.service:
|
|
3259
|
+
// a user unit would start a second daemon that crash-loops on the pid lock.
|
|
3260
|
+
const systemUnit = meshSystemUnitBlockingInstall({ platform: detectPlatform(), systemUser: opts.systemUser });
|
|
3261
|
+
if (systemUnit) {
|
|
3262
|
+
const message = meshSystemUnitInChargeMessage(systemUnit);
|
|
3263
|
+
if (opts.json) {
|
|
3264
|
+
console.log(JSON.stringify({ ok: false, action: "refused", reason: "system-unit", systemUnit, message }, null, 2));
|
|
3265
|
+
}
|
|
3266
|
+
else {
|
|
3267
|
+
console.error(message);
|
|
3268
|
+
}
|
|
3269
|
+
process.exitCode = MESH_DAEMON_SYSTEM_UNIT_EXIT;
|
|
3270
|
+
return;
|
|
3271
|
+
}
|
|
3256
3272
|
// `hq daemon` runs mesh on this machine: installing a second unit would run it twice.
|
|
3257
3273
|
// An explicit --hq-root is verified the same way as below and saved for the daemon.
|
|
3258
3274
|
const explicitRoot = opts.hqRoot ? resolveInstallHqRoot({ explicit: opts.hqRoot }).root : undefined;
|
|
@@ -3355,11 +3371,14 @@ async function runDaemonUninstall(opts) {
|
|
|
3355
3371
|
}
|
|
3356
3372
|
export async function runDaemonStatus(opts, deps = {}) {
|
|
3357
3373
|
const paths = deps.paths ?? buildInstallPaths({});
|
|
3374
|
+
const run = deps.run ?? defaultRunCommand;
|
|
3358
3375
|
const result = daemonServiceStatus({
|
|
3359
3376
|
platform: deps.platform ?? detectPlatform(),
|
|
3360
3377
|
paths,
|
|
3361
|
-
isLoaded: daemonServiceIsLoaded(
|
|
3378
|
+
isLoaded: daemonServiceIsLoaded(run, deps.uid),
|
|
3362
3379
|
hqDaemonMesh: (deps.hqDaemonMesh ?? (() => hqDaemonMeshService(paths.home)))(),
|
|
3380
|
+
systemUnitDir: deps.systemUnitDir,
|
|
3381
|
+
systemUnitState: () => readMeshSystemUnitState(run),
|
|
3363
3382
|
});
|
|
3364
3383
|
const state = readDaemonState(paths.daemonDir);
|
|
3365
3384
|
const presenceRefusal = state?.presenceRefusal ?? null;
|
|
@@ -3376,6 +3395,7 @@ export async function runDaemonStatus(opts, deps = {}) {
|
|
|
3376
3395
|
...(result.recordedHqRoot !== undefined ? { hqRoot: result.recordedHqRoot } : {}),
|
|
3377
3396
|
...(result.rootValid !== undefined ? { rootValid: result.rootValid } : {}),
|
|
3378
3397
|
...(result.notice ? { notice: result.notice } : {}),
|
|
3398
|
+
...(result.systemUnit ? { systemUnit: result.systemUnit } : {}),
|
|
3379
3399
|
mqttState: state?.mqttState,
|
|
3380
3400
|
presenceRefusal,
|
|
3381
3401
|
}, null, 2));
|
|
@@ -47,7 +47,7 @@ export function registerPackageInstallCommand(parent) {
|
|
|
47
47
|
.option('--start-bot', "After install, create and start the pack's setup bot (packs with a setup: block); prints `bot: <name>`")
|
|
48
48
|
.option('--branch', 'Follow a ref instead of SHA-pinning (git content-pack flow)')
|
|
49
49
|
.option('--global', 'Install HQ into an agent runtime at user scope (requires the hq-anywhere-runtime flag)')
|
|
50
|
-
.option('--runtime <runtime>', 'Runtime for --global (claude | codex | chatgpt | grok)', 'claude')
|
|
50
|
+
.option('--runtime <runtime>', 'Runtime for --global (claude | codex | chatgpt | grok | antigravity)', 'claude')
|
|
51
51
|
.option('--via <mode>', 'With --global Claude: install directly or via plugin (direct | plugin)', 'direct')
|
|
52
52
|
.option('--marketplace-dir <dir>', 'With --via plugin: local Claude Code marketplace directory (or HQ_CLAUDE_PLUGIN_MARKETPLACE)')
|
|
53
53
|
.option('--dry-run', 'With --global: print every file and config diff without writing')
|
package/dist/commands/reindex.js
CHANGED
|
@@ -37,6 +37,7 @@ import { reindex, rescue } from '@indigoai-us/hq-cloud';
|
|
|
37
37
|
import { trustHqRuntimeHooks } from '../utils/hook-trust.js';
|
|
38
38
|
import { findHqRoot } from '../utils/manifest.js';
|
|
39
39
|
import { guardLargeFiles } from '../utils/large-file-guard.js';
|
|
40
|
+
import { resolveHqCoreSource } from '../utils/hq-core-source.js';
|
|
40
41
|
import { liveProcessCwds, recentTranscriptCwds, sessionOwnerReason, } from '../lib/core-utils/worktree-session-owner.js';
|
|
41
42
|
const HOOK_EVENTS = ['SessionStart', 'UserPromptSubmit', 'PreToolUse'];
|
|
42
43
|
const BYPASS_MODE = 'bypassPermissions';
|
|
@@ -587,7 +588,7 @@ function repairExtremeHookDrift(hqRoot, allowRepair = true, timeoutLimitMs) {
|
|
|
587
588
|
try {
|
|
588
589
|
const result = runSilently(() => rescue({
|
|
589
590
|
hqRoot,
|
|
590
|
-
source:
|
|
591
|
+
source: resolveHqCoreSource().repo,
|
|
591
592
|
ref: installedCoreRef(hqRoot),
|
|
592
593
|
paths: ['.claude'],
|
|
593
594
|
assumeYes: true,
|
|
@@ -740,7 +741,7 @@ export function registerReindexCommand(program) {
|
|
|
740
741
|
program
|
|
741
742
|
.command('reindex')
|
|
742
743
|
.alias('master-sync')
|
|
743
|
-
.description('Surface namespaced skills, materialize legacy knowledge repos, regenerate the workers registry, and trust HQ hooks for Codex, Grok, and Claude Code')
|
|
744
|
+
.description('Surface namespaced skills, materialize legacy knowledge repos, regenerate the workers registry, and trust HQ hooks for Codex, Grok, and Claude Code (Antigravity: rule and MCP come from hq install --global; hooks pending)')
|
|
744
745
|
.option('--repo-root <path>', 'HQ root to operate on (defaults to the current directory)')
|
|
745
746
|
.option('--from-hook', 'Invoked from a Claude/Codex lifecycle hook: never wait on the per-root operation lock — if a sync/rescue holds it, skip this reindex instead of blocking the session (equivalent to --lock-timeout 0)')
|
|
746
747
|
.option('--lock-timeout <seconds>', 'Bound the wait for the per-root operation lock (seconds). 0 = refuse immediately; omitted = wait indefinitely (the interactive default). --from-hook implies 0; an explicit --lock-timeout wins.')
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
* `HQ_NO_UPDATE_CHECK=1`; always best-effort.
|
|
21
21
|
*/
|
|
22
22
|
import { Command } from 'commander';
|
|
23
|
-
import { retrustCodexHooksAfterRescue } from '../utils/hook-trust.js';
|
|
23
|
+
import { retrustCodexHooksAfterRescue, trustCodexUserHooks } from '../utils/hook-trust.js';
|
|
24
|
+
import { reconcileHookRegistrations } from '../lib/hook-engine/reconcile.js';
|
|
24
25
|
import { repairDanglingReleaseLinks } from '../lib/doctor/checks/release-links.js';
|
|
25
26
|
import { type GitHubLookupDeps } from '../utils/github-tag-fallback.js';
|
|
26
27
|
export interface RescueTarget {
|
|
@@ -38,6 +39,13 @@ export declare function resolveRescueTarget(opts: {
|
|
|
38
39
|
source?: string;
|
|
39
40
|
ref?: string;
|
|
40
41
|
}, latestTag?: string): RescueTarget;
|
|
42
|
+
/**
|
|
43
|
+
* The GitHub token to hand the rescue script, which clones and downloads from
|
|
44
|
+
* the HQ_CORE_SOURCE web and codeload bases. Exported for tests. Returns
|
|
45
|
+
* undefined unless both bases are GitHub hosts, so a GitHub token never
|
|
46
|
+
* reaches an overridden non-GitHub host.
|
|
47
|
+
*/
|
|
48
|
+
export declare function rescueScriptToken(token: string | undefined): string | undefined;
|
|
41
49
|
/**
|
|
42
50
|
* Whether this invocation should try the CLI self-update. Pure + exported for
|
|
43
51
|
* tests. A dry-run (`--check`) must not mutate the global install, and
|
|
@@ -54,6 +62,19 @@ export declare function shouldAttemptSelfUpdate(opts: {
|
|
|
54
62
|
* changes the rescue's exit status, because the core update itself succeeded.
|
|
55
63
|
*/
|
|
56
64
|
export declare function retrustHooksAfterRescue(hqRoot: string, retrust?: typeof retrustCodexHooksAfterRescue): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Re-plan HQ's hook registrations after a rescue that changed files on disk,
|
|
67
|
+
* the same step `hq reindex` runs. The registration that points an event at
|
|
68
|
+
* the new core lives partly outside the HQ root (the user-scope Codex
|
|
69
|
+
* hooks.json), so a core apply never replaces it. Without this step, an event
|
|
70
|
+
* whose coverage hold now applies to the files the core apply put on disk (for
|
|
71
|
+
* example a Stop or SubagentStop the native engine does not model for the new
|
|
72
|
+
* adapter) stays on the new core and is refused natively on every call until
|
|
73
|
+
* someone runs `hq reindex` by hand. Exported for tests. Best-effort: a failure
|
|
74
|
+
* leaves the current registrations in place and is reported, but never changes
|
|
75
|
+
* the rescue's exit status, because the core update itself succeeded.
|
|
76
|
+
*/
|
|
77
|
+
export declare function reconcileHooksAfterRescue(hqRoot: string, reconcile?: (root: string) => ReturnType<typeof reconcileHookRegistrations>, trust?: typeof trustCodexUserHooks): Promise<void>;
|
|
57
78
|
/**
|
|
58
79
|
* Repair HQ-managed release links (`.agents/skills`, `.codex/claude`, ...)
|
|
59
80
|
* that do not resolve after a rescue, for example because they were laid at
|
package/dist/commands/rescue.js
CHANGED
|
@@ -5,9 +5,11 @@ import chalk from 'chalk';
|
|
|
5
5
|
import { rescue } from '@indigoai-us/hq-cloud';
|
|
6
6
|
import { findHqRoot } from '../utils/manifest.js';
|
|
7
7
|
import { selfUpdateAndReexec } from '../utils/self-update.js';
|
|
8
|
-
import { retrustCodexHooksAfterRescue } from '../utils/hook-trust.js';
|
|
8
|
+
import { retrustCodexHooksAfterRescue, trustCodexUserHooks } from '../utils/hook-trust.js';
|
|
9
|
+
import { reconcileHookRegistrations } from '../lib/hook-engine/reconcile.js';
|
|
9
10
|
import { repairDanglingReleaseLinks } from '../lib/doctor/checks/release-links.js';
|
|
10
|
-
import {
|
|
11
|
+
import { resolveGhToken } from '../utils/shipped-codex-hooks.js';
|
|
12
|
+
import { githubTokenFor, isGitHubHost, resolveHqCoreSource } from '../utils/hq-core-source.js';
|
|
11
13
|
import { GitHubApiUnavailable, onceWarning, isTransientGitHubStatus, remoteTagSha, withGitTagFallback } from '../utils/github-tag-fallback.js';
|
|
12
14
|
/**
|
|
13
15
|
* Resolve the source repo + ref from the user's flags. Pure + exported for
|
|
@@ -15,10 +17,21 @@ import { GitHubApiUnavailable, onceWarning, isTransientGitHubStatus, remoteTagSh
|
|
|
15
17
|
* for staging and when an explicit `--ref` is given.
|
|
16
18
|
*/
|
|
17
19
|
export function resolveRescueTarget(opts, latestTag) {
|
|
20
|
+
const core = resolveHqCoreSource();
|
|
18
21
|
if (opts.staging) {
|
|
19
|
-
return { source: opts.source ??
|
|
22
|
+
return { source: opts.source ?? core.stagingRepo, ref: opts.ref };
|
|
20
23
|
}
|
|
21
|
-
return { source: opts.source ??
|
|
24
|
+
return { source: opts.source ?? core.repo, ref: opts.ref ?? latestTag };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The GitHub token to hand the rescue script, which clones and downloads from
|
|
28
|
+
* the HQ_CORE_SOURCE web and codeload bases. Exported for tests. Returns
|
|
29
|
+
* undefined unless both bases are GitHub hosts, so a GitHub token never
|
|
30
|
+
* reaches an overridden non-GitHub host.
|
|
31
|
+
*/
|
|
32
|
+
export function rescueScriptToken(token) {
|
|
33
|
+
const { webBase, codeloadBase } = resolveHqCoreSource();
|
|
34
|
+
return isGitHubHost(webBase) && isGitHubHost(codeloadBase) ? token : undefined;
|
|
22
35
|
}
|
|
23
36
|
/**
|
|
24
37
|
* Whether this invocation should try the CLI self-update. Pure + exported for
|
|
@@ -51,6 +64,36 @@ export async function retrustHooksAfterRescue(hqRoot, retrust = retrustCodexHook
|
|
|
51
64
|
'Codex will skip changed HQ hooks until you run `hq reindex`.'));
|
|
52
65
|
}
|
|
53
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Re-plan HQ's hook registrations after a rescue that changed files on disk,
|
|
69
|
+
* the same step `hq reindex` runs. The registration that points an event at
|
|
70
|
+
* the new core lives partly outside the HQ root (the user-scope Codex
|
|
71
|
+
* hooks.json), so a core apply never replaces it. Without this step, an event
|
|
72
|
+
* whose coverage hold now applies to the files the core apply put on disk (for
|
|
73
|
+
* example a Stop or SubagentStop the native engine does not model for the new
|
|
74
|
+
* adapter) stays on the new core and is refused natively on every call until
|
|
75
|
+
* someone runs `hq reindex` by hand. Exported for tests. Best-effort: a failure
|
|
76
|
+
* leaves the current registrations in place and is reported, but never changes
|
|
77
|
+
* the rescue's exit status, because the core update itself succeeded.
|
|
78
|
+
*/
|
|
79
|
+
export async function reconcileHooksAfterRescue(hqRoot, reconcile = reconcileHookRegistrations, trust = trustCodexUserHooks) {
|
|
80
|
+
const advise = 'Run `hq reindex` to retry.';
|
|
81
|
+
try {
|
|
82
|
+
const { codexUserKeys, failures } = reconcile(hqRoot);
|
|
83
|
+
for (const failure of failures) {
|
|
84
|
+
console.warn(chalk.yellow(`rescue: hook registration reconcile skipped ${failure}. ${advise}`));
|
|
85
|
+
}
|
|
86
|
+
if (codexUserKeys.length) {
|
|
87
|
+
const result = await trust(hqRoot, codexUserKeys);
|
|
88
|
+
if (result.status === 'failed') {
|
|
89
|
+
console.warn(chalk.yellow(`rescue: Codex hook trust needs repair: ${result.reason ?? 'unknown error'}. ${advise}`));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.warn(chalk.yellow(`rescue: hook registration reconcile skipped: ${error.message}. ${advise}`));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
54
97
|
/**
|
|
55
98
|
* Repair HQ-managed release links (`.agents/skills`, `.codex/claude`, ...)
|
|
56
99
|
* that do not resolve after a rescue, for example because they were laid at
|
|
@@ -108,7 +151,8 @@ const GITHUB_REQUEST_TIMEOUT_MS = 30_000;
|
|
|
108
151
|
async function githubJsonRequest(url, token, fetchImpl = fetch) {
|
|
109
152
|
const signal = AbortSignal.timeout(GITHUB_REQUEST_TIMEOUT_MS);
|
|
110
153
|
try {
|
|
111
|
-
|
|
154
|
+
// Never forward a GitHub token to an overridden non-GitHub host.
|
|
155
|
+
const response = await fetchImpl(url, { headers: ghHeaders(githubTokenFor(url, token)), signal });
|
|
112
156
|
if (isTransientGitHubStatus(response.status)) {
|
|
113
157
|
throw new GitHubApiUnavailable(`GitHub API for ${url}: HTTP ${response.status}`);
|
|
114
158
|
}
|
|
@@ -127,8 +171,9 @@ async function githubJsonRequest(url, token, fetchImpl = fetch) {
|
|
|
127
171
|
}
|
|
128
172
|
/** Latest release tag for a repo, e.g. `v12.3.0`. Throws on failure. */
|
|
129
173
|
export async function getLatestReleaseTag(repo, token, deps = {}) {
|
|
174
|
+
const { apiBase } = resolveHqCoreSource();
|
|
130
175
|
return withGitTagFallback(async () => {
|
|
131
|
-
const { response, body } = await githubJsonRequest(
|
|
176
|
+
const { response, body } = await githubJsonRequest(`${apiBase}/repos/${repo}/releases/latest`, token, deps.fetchImpl);
|
|
132
177
|
if (!response.ok) {
|
|
133
178
|
throw new Error(`GitHub releases/latest for ${repo}: HTTP ${response.status}`);
|
|
134
179
|
}
|
|
@@ -139,8 +184,9 @@ export async function getLatestReleaseTag(repo, token, deps = {}) {
|
|
|
139
184
|
}
|
|
140
185
|
/** Resolve a tag to its commit SHA, dereferencing annotated tags. */
|
|
141
186
|
export async function resolveTagSha(repo, tag, token, deps = {}) {
|
|
187
|
+
const { apiBase } = resolveHqCoreSource();
|
|
142
188
|
return withGitTagFallback(async () => {
|
|
143
|
-
const { response: refRes, body: ref } = await githubJsonRequest(
|
|
189
|
+
const { response: refRes, body: ref } = await githubJsonRequest(`${apiBase}/repos/${repo}/git/ref/tags/${encodeURIComponent(tag)}`, token, deps.fetchImpl);
|
|
144
190
|
if (!refRes.ok)
|
|
145
191
|
throw new Error(`git/ref/tags/${tag} for ${repo}: HTTP ${refRes.status}`);
|
|
146
192
|
const obj = ref?.object;
|
|
@@ -149,7 +195,7 @@ export async function resolveTagSha(repo, tag, token, deps = {}) {
|
|
|
149
195
|
if (obj.type !== 'tag')
|
|
150
196
|
return obj.sha; // lightweight tag → already a commit
|
|
151
197
|
// Annotated tag → dereference to the commit it points at.
|
|
152
|
-
const { response: tagRes, body: annotated } = await githubJsonRequest(
|
|
198
|
+
const { response: tagRes, body: annotated } = await githubJsonRequest(`${apiBase}/repos/${repo}/git/tags/${obj.sha}`, token, deps.fetchImpl);
|
|
153
199
|
if (!tagRes.ok)
|
|
154
200
|
throw new Error(`git/tags/${obj.sha} for ${repo}: HTTP ${tagRes.status}`);
|
|
155
201
|
if (!annotated?.object?.sha)
|
|
@@ -237,11 +283,12 @@ export function registerRescueCommand(program) {
|
|
|
237
283
|
assumeYes: opts.yes,
|
|
238
284
|
noBackup: opts.backup === false,
|
|
239
285
|
cloudUpdate: opts.cloudUpdate,
|
|
240
|
-
ghToken: token,
|
|
286
|
+
ghToken: rescueScriptToken(token),
|
|
241
287
|
});
|
|
242
288
|
if (status === 0 && !opts.check) {
|
|
243
289
|
repairReleaseLinksAfterRescue(hqRoot);
|
|
244
290
|
await retrustHooksAfterRescue(hqRoot);
|
|
291
|
+
await reconcileHooksAfterRescue(hqRoot);
|
|
245
292
|
}
|
|
246
293
|
process.exit(status);
|
|
247
294
|
}
|
|
@@ -171,7 +171,7 @@ export interface SignalsRedoReport {
|
|
|
171
171
|
/**
|
|
172
172
|
* `hq sources signals`: queue landed documents for the signals pass and run
|
|
173
173
|
* the pass now, under the same per-person lock as `hq sources sync`. The pass
|
|
174
|
-
* keeps its cap (`--max-docs`, default
|
|
174
|
+
* keeps its cap (`--max-docs`, default 40); what the cap leaves stays queued
|
|
175
175
|
* and the next run (this command or the daily sync) picks it up.
|
|
176
176
|
*/
|
|
177
177
|
export declare function runSignalsRedo(options: SignalsRedoOptions, overrides?: SignalsRedoOverrides): Promise<SignalsRedoReport>;
|
package/dist/commands/sources.js
CHANGED
|
@@ -664,7 +664,7 @@ function renderSyncTable(company, report) {
|
|
|
664
664
|
/**
|
|
665
665
|
* `hq sources signals`: queue landed documents for the signals pass and run
|
|
666
666
|
* the pass now, under the same per-person lock as `hq sources sync`. The pass
|
|
667
|
-
* keeps its cap (`--max-docs`, default
|
|
667
|
+
* keeps its cap (`--max-docs`, default 40); what the cap leaves stays queued
|
|
668
668
|
* and the next run (this command or the daily sync) picks it up.
|
|
669
669
|
*/
|
|
670
670
|
export async function runSignalsRedo(options, overrides = {}) {
|
|
@@ -92,6 +92,8 @@ export interface CloudPruneResult {
|
|
|
92
92
|
company: string;
|
|
93
93
|
deleted_count: number;
|
|
94
94
|
deleted_bytes: number;
|
|
95
|
+
kept_recent_delete_count: number;
|
|
96
|
+
kept_recent_delete_bytes: number;
|
|
95
97
|
errors: string[];
|
|
96
98
|
/** Set when the company was not touched, e.g. the caller is not an owner/admin. */
|
|
97
99
|
skipped_reason?: string;
|
|
@@ -178,6 +180,7 @@ export interface VersionEntry {
|
|
|
178
180
|
lastModified: Date;
|
|
179
181
|
size: number;
|
|
180
182
|
isDeleteMarker: boolean;
|
|
183
|
+
lastModifiedUnknown?: boolean;
|
|
181
184
|
/**
|
|
182
185
|
* When this version stopped being current: the LastModified of the next
|
|
183
186
|
* newer version or delete marker of the same key. Unset for current entries.
|
|
@@ -211,9 +214,19 @@ export declare function getCloudStatus(company: CompanyRef, deps: StorageDeps):
|
|
|
211
214
|
* Versions eligible for prune: noncurrent content versions and noncurrent
|
|
212
215
|
* delete markers that stopped being current before the cutoff (see
|
|
213
216
|
* annotateNoncurrentSince). The current version of a key (content or delete
|
|
214
|
-
* marker) is never selected.
|
|
217
|
+
* marker) is never selected. When a key's current entry is a delete marker
|
|
218
|
+
* from the last RECENT_DELETE_KEEP_DAYS days, or the listing cannot show when
|
|
219
|
+
* or whether the key was deleted, its newest older content version is kept
|
|
220
|
+
* (with any older version whose date is unknown) and reported in
|
|
221
|
+
* keptRecentDelete.
|
|
215
222
|
*/
|
|
216
|
-
export declare function
|
|
223
|
+
export declare function planPrune(versions: VersionEntry[], cutoff: Date, now: Date): PrunePlan;
|
|
224
|
+
export declare function selectPrunable(versions: VersionEntry[], cutoff: Date, now: Date): VersionEntry[];
|
|
225
|
+
export declare const RECENT_DELETE_KEEP_DAYS = 30;
|
|
226
|
+
export interface PrunePlan {
|
|
227
|
+
prune: VersionEntry[];
|
|
228
|
+
keptRecentDelete: VersionEntry[];
|
|
229
|
+
}
|
|
217
230
|
export declare function pruneCloud(company: CompanyRef, cutoff: Date, dryRun: boolean, deps: StorageDeps): Promise<CloudPruneResult>;
|
|
218
231
|
export declare function runStorageStatus(opts: {
|
|
219
232
|
company?: string;
|
package/dist/commands/storage.js
CHANGED
|
@@ -203,6 +203,12 @@ export function annotateNoncurrentSince(entries) {
|
|
|
203
203
|
function noncurrentAge(v) {
|
|
204
204
|
return v.noncurrentSince ?? v.lastModified;
|
|
205
205
|
}
|
|
206
|
+
function entryTime(value) {
|
|
207
|
+
const d = value ? new Date(value) : undefined;
|
|
208
|
+
if (!d || Number.isNaN(d.getTime()))
|
|
209
|
+
return { lastModified: new Date(0), lastModifiedUnknown: true };
|
|
210
|
+
return { lastModified: d };
|
|
211
|
+
}
|
|
206
212
|
function toEntries(page) {
|
|
207
213
|
const out = [];
|
|
208
214
|
for (const v of page.Versions ?? []) {
|
|
@@ -212,7 +218,7 @@ function toEntries(page) {
|
|
|
212
218
|
key: v.Key,
|
|
213
219
|
versionId: v.VersionId,
|
|
214
220
|
isLatest: Boolean(v.IsLatest),
|
|
215
|
-
|
|
221
|
+
...entryTime(v.LastModified),
|
|
216
222
|
size: v.Size ?? 0,
|
|
217
223
|
isDeleteMarker: false,
|
|
218
224
|
});
|
|
@@ -224,7 +230,7 @@ function toEntries(page) {
|
|
|
224
230
|
key: m.Key,
|
|
225
231
|
versionId: m.VersionId,
|
|
226
232
|
isLatest: Boolean(m.IsLatest),
|
|
227
|
-
|
|
233
|
+
...entryTime(m.LastModified),
|
|
228
234
|
size: 0,
|
|
229
235
|
isDeleteMarker: true,
|
|
230
236
|
});
|
|
@@ -467,11 +473,60 @@ export async function getCloudStatus(company, deps) {
|
|
|
467
473
|
* Versions eligible for prune: noncurrent content versions and noncurrent
|
|
468
474
|
* delete markers that stopped being current before the cutoff (see
|
|
469
475
|
* annotateNoncurrentSince). The current version of a key (content or delete
|
|
470
|
-
* marker) is never selected.
|
|
476
|
+
* marker) is never selected. When a key's current entry is a delete marker
|
|
477
|
+
* from the last RECENT_DELETE_KEEP_DAYS days, or the listing cannot show when
|
|
478
|
+
* or whether the key was deleted, its newest older content version is kept
|
|
479
|
+
* (with any older version whose date is unknown) and reported in
|
|
480
|
+
* keptRecentDelete.
|
|
471
481
|
*/
|
|
472
|
-
export function
|
|
482
|
+
export function planPrune(versions, cutoff, now) {
|
|
473
483
|
annotateNoncurrentSince(versions);
|
|
474
|
-
|
|
484
|
+
const byKey = new Map();
|
|
485
|
+
for (const v of versions) {
|
|
486
|
+
const list = byKey.get(v.key);
|
|
487
|
+
if (list)
|
|
488
|
+
list.push(v);
|
|
489
|
+
else
|
|
490
|
+
byKey.set(v.key, [v]);
|
|
491
|
+
}
|
|
492
|
+
const keep = new Set();
|
|
493
|
+
for (const list of byKey.values())
|
|
494
|
+
for (const v of protectedVersions(list, now))
|
|
495
|
+
keep.add(v);
|
|
496
|
+
const prune = [];
|
|
497
|
+
const keptRecentDelete = [];
|
|
498
|
+
for (const v of versions) {
|
|
499
|
+
if (v.isLatest || noncurrentAge(v).getTime() >= cutoff.getTime())
|
|
500
|
+
continue;
|
|
501
|
+
if (keep.has(v))
|
|
502
|
+
keptRecentDelete.push(v);
|
|
503
|
+
else
|
|
504
|
+
prune.push(v);
|
|
505
|
+
}
|
|
506
|
+
return { prune, keptRecentDelete };
|
|
507
|
+
}
|
|
508
|
+
export function selectPrunable(versions, cutoff, now) {
|
|
509
|
+
return planPrune(versions, cutoff, now).prune;
|
|
510
|
+
}
|
|
511
|
+
export const RECENT_DELETE_KEEP_DAYS = 30;
|
|
512
|
+
function isRecentDelete(current, now) {
|
|
513
|
+
if (!current)
|
|
514
|
+
return true;
|
|
515
|
+
if (!current.isDeleteMarker)
|
|
516
|
+
return false;
|
|
517
|
+
if (current.lastModifiedUnknown)
|
|
518
|
+
return true;
|
|
519
|
+
return now.getTime() - current.lastModified.getTime() < RECENT_DELETE_KEEP_DAYS * DAY_MS;
|
|
520
|
+
}
|
|
521
|
+
function protectedVersions(list, now) {
|
|
522
|
+
if (!isRecentDelete(list.find((v) => v.isLatest), now))
|
|
523
|
+
return [];
|
|
524
|
+
const older = list.filter((v) => !v.isLatest && !v.isDeleteMarker);
|
|
525
|
+
const unknown = older.filter((v) => v.lastModifiedUnknown);
|
|
526
|
+
const newest = older
|
|
527
|
+
.filter((v) => !v.lastModifiedUnknown)
|
|
528
|
+
.reduce((best, v) => (best === undefined || v.lastModified.getTime() > best.lastModified.getTime() ? v : best), undefined);
|
|
529
|
+
return newest ? [newest, ...unknown] : unknown;
|
|
475
530
|
}
|
|
476
531
|
const DELETE_BATCH = 1000;
|
|
477
532
|
export async function pruneCloud(company, cutoff, dryRun, deps) {
|
|
@@ -479,13 +534,18 @@ export async function pruneCloud(company, cutoff, dryRun, deps) {
|
|
|
479
534
|
company: company.slug,
|
|
480
535
|
deleted_count: 0,
|
|
481
536
|
deleted_bytes: 0,
|
|
537
|
+
kept_recent_delete_count: 0,
|
|
538
|
+
kept_recent_delete_bytes: 0,
|
|
482
539
|
errors: [],
|
|
483
540
|
};
|
|
484
541
|
let store;
|
|
485
542
|
let candidates;
|
|
486
543
|
try {
|
|
487
544
|
store = await deps.openCompany(company);
|
|
488
|
-
|
|
545
|
+
const plan = planPrune(await listVersions(store), cutoff, deps.now());
|
|
546
|
+
candidates = plan.prune;
|
|
547
|
+
result.kept_recent_delete_count = plan.keptRecentDelete.length;
|
|
548
|
+
result.kept_recent_delete_bytes = plan.keptRecentDelete.reduce((sum, v) => sum + v.size, 0);
|
|
489
549
|
}
|
|
490
550
|
catch (err) {
|
|
491
551
|
result.errors.push(describeCloudError(err, "list"));
|
|
@@ -659,6 +719,8 @@ export async function runStoragePrune(opts, deps) {
|
|
|
659
719
|
company: c.slug,
|
|
660
720
|
deleted_count: 0,
|
|
661
721
|
deleted_bytes: 0,
|
|
722
|
+
kept_recent_delete_count: 0,
|
|
723
|
+
kept_recent_delete_bytes: 0,
|
|
662
724
|
errors: [],
|
|
663
725
|
skipped_reason: DELETE_ROLE_REASON,
|
|
664
726
|
});
|
|
@@ -968,6 +1030,11 @@ export function formatStoragePrune(result) {
|
|
|
968
1030
|
continue;
|
|
969
1031
|
}
|
|
970
1032
|
lines.push(`${c.company}: ${verb} ${c.deleted_count} old version(s), ${formatBytes(c.deleted_bytes)}`);
|
|
1033
|
+
if (c.kept_recent_delete_count > 0) {
|
|
1034
|
+
lines.push(` ${result.dry_run ? "Would keep" : "Kept"} ${c.kept_recent_delete_count} old version(s), ` +
|
|
1035
|
+
`${formatBytes(c.kept_recent_delete_bytes)}: the last copy of files deleted in the last ` +
|
|
1036
|
+
`${RECENT_DELETE_KEEP_DAYS} days, or whose delete date could not be read.`);
|
|
1037
|
+
}
|
|
971
1038
|
for (const e of c.errors)
|
|
972
1039
|
lines.push(chalk.red(` ${e}`));
|
|
973
1040
|
}
|
|
@@ -1285,7 +1352,7 @@ export function registerStorageCommand(program) {
|
|
|
1285
1352
|
.command("prune")
|
|
1286
1353
|
.description("Delete local autosave history and old cloud file versions before a date")
|
|
1287
1354
|
.option("--local-before <date>", "Prune local autosave history before YYYY-MM-DD")
|
|
1288
|
-
.option("--cloud-before <date>", "Delete old (noncurrent) cloud file versions before YYYY-MM-DD")
|
|
1355
|
+
.option("--cloud-before <date>", "Delete old (noncurrent) cloud file versions before YYYY-MM-DD; files deleted in the last 30 days keep their last old version")
|
|
1289
1356
|
.option("--company <slug>", "Only this company (must be one of yours)")
|
|
1290
1357
|
.option("--dry-run", "Show what would be deleted without deleting")
|
|
1291
1358
|
.option("--yes", "Skip the confirmation prompt")
|