@indigoai-us/hq-cli 5.345.225 → 5.345.228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +174 -0
- package/dist/command-catalog.generated.d.ts +215 -0
- package/dist/command-catalog.generated.js +261 -0
- package/dist/commands/auth.d.ts +2 -2
- package/dist/commands/auth.js +3 -3
- package/dist/commands/core-delegate-w1b.js +92 -69
- package/dist/commands/core-delegate.d.ts +19 -1
- package/dist/commands/core-delegate.js +411 -6
- package/dist/commands/core-dm-bind-native.js +2 -1
- package/dist/commands/core-handoff.d.ts +5 -0
- package/dist/commands/core-handoff.js +1008 -14
- package/dist/commands/core-pin-native.d.ts +1 -0
- package/dist/commands/core-pin-native.js +3 -15
- package/dist/commands/core-register-project-native.d.ts +6 -0
- package/dist/commands/core-register-project-native.js +182 -52
- package/dist/commands/core-work-mesh-bind-trusted-native.js +4 -9
- package/dist/commands/daemon.js +3 -3
- package/dist/commands/deploy-domains.js +38 -2
- package/dist/commands/index-cmd.d.ts +3 -1
- package/dist/commands/index-cmd.js +12 -0
- package/dist/commands/lanes-accounts.d.ts +14 -0
- package/dist/commands/lanes-accounts.js +119 -0
- package/dist/commands/lanes-checks.js +1 -1
- package/dist/commands/lanes-move.js +10 -0
- package/dist/commands/lanes-session-start.d.ts +1 -2
- package/dist/commands/lanes-session-start.js +9 -145
- package/dist/commands/lanes-shared.d.ts +3 -0
- package/dist/commands/lanes-shared.js +9 -0
- package/dist/commands/lanes.d.ts +3 -0
- package/dist/commands/lanes.js +231 -39
- package/dist/commands/link.d.ts +8 -3
- package/dist/commands/link.js +14 -17
- package/dist/commands/mcp-registration.d.ts +65 -7
- package/dist/commands/mcp-registration.js +289 -51
- package/dist/commands/mesh.d.ts +12 -0
- package/dist/commands/mesh.js +92 -10
- package/dist/commands/reindex.js +6 -0
- package/dist/commands/repo.d.ts +13 -0
- package/dist/commands/repo.js +39 -1
- package/dist/commands/sync-held.d.ts +22 -0
- package/dist/commands/sync-held.js +167 -18
- package/dist/commands/sync-mode.d.ts +3 -1
- package/dist/commands/sync-mode.js +11 -1
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +4845 -2524
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lazy-commands.js +3 -4
- package/dist/lib/capacity/accounts.d.ts +4 -0
- package/dist/lib/capacity/accounts.js +4 -0
- package/dist/lib/capacity/route.js +14 -0
- package/dist/lib/capacity/sign-in.d.ts +18 -0
- package/dist/lib/capacity/sign-in.js +34 -1
- package/dist/lib/checkpoint-ontology/entity-file.js +4 -4
- package/dist/lib/checkpoint-ontology/merge-copies.js +7 -11
- package/dist/lib/checkpoint-ontology/plan.js +2 -1
- package/dist/lib/core-utils/archive-old-threads.js +5 -2
- package/dist/lib/core-utils/session-company.d.ts +13 -1
- package/dist/lib/core-utils/session-company.js +75 -4
- package/dist/lib/core-utils/worktree-resume.d.ts +6 -0
- package/dist/lib/core-utils/worktree-resume.js +8 -4
- package/dist/lib/daemon/background-qos.d.ts +7 -0
- package/dist/lib/daemon/background-qos.js +13 -0
- package/dist/lib/daemon/catalog.d.ts +10 -0
- package/dist/lib/daemon/catalog.js +9 -2
- package/dist/lib/daemon/hook-requests-acl-suggest.d.ts +18 -0
- package/dist/lib/daemon/hook-requests-acl-suggest.js +245 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +32 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.js +214 -0
- package/dist/lib/daemon/hook-requests-mesh-tool-writes.d.ts +44 -0
- package/dist/lib/daemon/hook-requests-mesh-tool-writes.js +292 -0
- package/dist/lib/daemon/hook-requests-mesh.d.ts +54 -0
- package/dist/lib/daemon/hook-requests-mesh.js +559 -0
- package/dist/lib/daemon/hook-requests.d.ts +417 -0
- package/dist/lib/daemon/hook-requests.js +1747 -0
- package/dist/lib/daemon/lanes-reconcile-status.d.ts +35 -0
- package/dist/lib/daemon/lanes-reconcile-status.js +86 -0
- package/dist/lib/daemon/machine-checks.d.ts +12 -2
- package/dist/lib/daemon/machine-checks.js +27 -10
- package/dist/lib/daemon/merge-sections.d.ts +24 -2
- package/dist/lib/daemon/merge-sections.js +58 -16
- package/dist/lib/daemon/ops/policy.d.ts +1 -1
- package/dist/lib/daemon/ops/policy.js +47 -6
- package/dist/lib/daemon/resolver.js +9 -2
- package/dist/lib/daemon/run.d.ts +11 -7
- package/dist/lib/daemon/run.js +195 -18
- package/dist/lib/daemon/search-index-worker-v1.d.ts +2 -0
- package/dist/lib/daemon/search-index-worker-v1.js +25 -0
- package/dist/lib/daemon/server.js +6 -1
- package/dist/lib/daemon/session-registry.d.ts +0 -1
- package/dist/lib/daemon/session-registry.js +0 -3
- package/dist/lib/daemon/supervisor.d.ts +5 -1
- package/dist/lib/daemon/supervisor.js +1 -1
- package/dist/lib/daemon/tcc-eperm.d.ts +59 -4
- package/dist/lib/daemon/tcc-eperm.js +110 -8
- package/dist/lib/doctor/fix/process-identity.d.ts +20 -2
- package/dist/lib/doctor/fix/process-identity.js +48 -5
- 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/canary-gate.js +1 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
- package/dist/lib/hot-channels/adapters/attio.js +2 -1
- package/dist/lib/hot-channels/adapters/meetings.js +2 -1
- package/dist/lib/lanes/account-company.d.ts +7 -1
- package/dist/lib/lanes/account-company.js +22 -4
- package/dist/lib/lanes/account-ownership.d.ts +65 -0
- package/dist/lib/lanes/account-ownership.js +134 -0
- package/dist/lib/lanes/accounts.js +9 -2
- package/dist/lib/lanes/claude-balance.js +9 -3
- package/dist/lib/lanes/company-outposts.d.ts +37 -0
- package/dist/lib/lanes/company-outposts.js +164 -0
- package/dist/lib/lanes/config.js +17 -0
- package/dist/lib/lanes/host-capacity.d.ts +19 -0
- package/dist/lib/lanes/host-capacity.js +37 -0
- package/dist/lib/lanes/liveness.d.ts +6 -0
- package/dist/lib/lanes/liveness.js +49 -8
- package/dist/lib/lanes/orphan-report.d.ts +15 -0
- package/dist/lib/lanes/orphan-report.js +223 -0
- package/dist/lib/lanes/orphan-sweep.d.ts +26 -0
- package/dist/lib/lanes/orphan-sweep.js +152 -0
- package/dist/lib/lanes/reaper.d.ts +2 -0
- package/dist/lib/lanes/reaper.js +11 -8
- package/dist/lib/lanes/reconcile.d.ts +8 -7
- package/dist/lib/lanes/reconcile.js +83 -3
- package/dist/lib/lanes/spawn.d.ts +0 -10
- package/dist/lib/lanes/spawn.js +51 -1
- package/dist/lib/lanes/types.d.ts +12 -0
- package/dist/lib/mesh/live/backfill-held.d.ts +13 -0
- package/dist/lib/mesh/live/backfill-held.js +23 -0
- package/dist/lib/mesh/live/daemon/mode.d.ts +8 -4
- package/dist/lib/mesh/live/daemon/mode.js +8 -4
- package/dist/lib/mesh/live/daemon/run.d.ts +14 -3
- package/dist/lib/mesh/live/daemon/run.js +116 -7
- package/dist/lib/mesh/live/direct-drain.d.ts +123 -0
- package/dist/lib/mesh/live/direct-drain.js +315 -0
- package/dist/lib/mesh/live/emit-replay.d.ts +10 -0
- package/dist/lib/mesh/live/emit-replay.js +10 -0
- package/dist/lib/mesh/live/flush.d.ts +15 -0
- package/dist/lib/mesh/live/flush.js +27 -0
- package/dist/lib/mesh/live/liveness-carry.d.ts +45 -0
- package/dist/lib/mesh/live/liveness-carry.js +141 -0
- package/dist/lib/mesh/live/spool.d.ts +19 -0
- package/dist/lib/mesh/live/spool.js +80 -0
- package/dist/lib/safe-store.d.ts +2 -0
- package/dist/lib/safe-store.js +8 -6
- package/dist/lib/search-index/index.d.ts +9 -3
- package/dist/lib/search-index/index.js +35 -10
- package/dist/lib/search-index/worker-process.d.ts +9 -0
- package/dist/lib/search-index/worker-process.js +171 -0
- package/dist/lib/session-company-lock.d.ts +3 -1
- package/dist/lib/session-company-lock.js +3 -2
- package/dist/utils/delegate-command-supervisor.d.ts +3 -0
- package/dist/utils/delegate-command-supervisor.js +44 -0
- package/dist/utils/delegate-lock.d.ts +12 -0
- package/dist/utils/delegate-lock.js +88 -0
- package/dist/utils/frontmatter.d.ts +27 -0
- package/dist/utils/frontmatter.js +33 -0
- package/dist/utils/hook-trust.d.ts +1 -0
- package/dist/utils/hook-trust.js +18 -2
- package/dist/utils/host-registration.d.ts +13 -1
- package/dist/utils/host-registration.js +98 -5
- package/dist/utils/package-use-lease.d.ts +1 -1
- package/dist/utils/package-use-lease.js +15 -7
- package/docs/anywhere-runtime.md +17 -0
- package/package.json +9 -8
- package/scripts/check-function-manifest.mjs +17 -3
package/dist/commands/mesh.js
CHANGED
|
@@ -24,8 +24,8 @@ import { ensureDefaultCompany } from "../lib/work-context/default-company.js";
|
|
|
24
24
|
import { cognitoSubFromTokens } from "../lib/work-context/person-identity.js";
|
|
25
25
|
import { DefaultCompanyUnavailableError, WorkContextError, } from "../lib/work-context/errors.js";
|
|
26
26
|
import { isValidSessionId } from "../lib/mesh/live/session-identity.js";
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
27
|
+
import { flushForEmitMode } from "../lib/mesh/live/direct-drain.js";
|
|
28
|
+
import { backfillHeldSessionsForMode, HeldBackfillRefusedError } from "../lib/mesh/live/backfill-held.js";
|
|
29
29
|
import { createSessionEventsPoster, resolveVaultApiBase, } from "../lib/mesh/live/session-events-client.js";
|
|
30
30
|
const ONLINE_MEMBERSHIP_VALIDATION_TIMEOUT_MS = 5_000;
|
|
31
31
|
// Leave 500 ms of headroom inside SessionStart's 2 s process-group limit.
|
|
@@ -37,7 +37,7 @@ import { enrichSessionEndEvent } from "../lib/mesh/live/report-summary.js";
|
|
|
37
37
|
import { emitEvents, formatEmitRejectionLines } from "../lib/mesh/live/emit.js";
|
|
38
38
|
import { readEmitRetry, writeEmitRetry } from "../lib/mesh/live/emit-retry.js";
|
|
39
39
|
import { generateUlid } from "../lib/mesh/live/ulid.js";
|
|
40
|
-
import {
|
|
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
43
|
import { buildInstallPaths, daemonServiceIsLoaded, daemonServiceStatus, detectPlatform, installDaemonIfStale, installDaemonService, resolveAbsoluteNodeBinary, resolveRunningCliEntry, uninstallDaemonService, installedUnitHqRoot, } from "../lib/mesh/live/daemon/install.js";
|
|
@@ -1611,6 +1611,11 @@ async function runContextBackfillHeld(opts) {
|
|
|
1611
1611
|
const root = workContextHomeRoot();
|
|
1612
1612
|
const meshRoot = workMeshRoot(undefined, process.env);
|
|
1613
1613
|
const dryRun = Boolean(opts.dryRun);
|
|
1614
|
+
// Direct mode refuses a real run before a token is fetched or anything is
|
|
1615
|
+
// read: exit 1 with the reason (US-038, owner decision 70).
|
|
1616
|
+
const emitMode = resolveMeshEmitMode({ env: process.env, meshRoot });
|
|
1617
|
+
if (emitMode === "direct" && !dryRun)
|
|
1618
|
+
fail(new HeldBackfillRefusedError().message);
|
|
1614
1619
|
const parsedLimit = opts.limit ? Number.parseInt(opts.limit, 10) : 0;
|
|
1615
1620
|
const limit = Number.isFinite(parsedLimit) && parsedLimit > 0 ? parsedLimit : 0;
|
|
1616
1621
|
const companyHint = opts.company?.trim() || undefined;
|
|
@@ -1643,7 +1648,7 @@ async function runContextBackfillHeld(opts) {
|
|
|
1643
1648
|
}
|
|
1644
1649
|
}
|
|
1645
1650
|
}
|
|
1646
|
-
const result = await
|
|
1651
|
+
const result = await backfillHeldSessionsForMode(emitMode, {
|
|
1647
1652
|
workMeshRoot: meshRoot,
|
|
1648
1653
|
workContextRoot: root,
|
|
1649
1654
|
hqRoot: process.env.HQ_ROOT?.trim() || findHqRoot(),
|
|
@@ -2441,14 +2446,41 @@ const HARNESSES = new Set([
|
|
|
2441
2446
|
"agent-box",
|
|
2442
2447
|
"agents-v2",
|
|
2443
2448
|
]);
|
|
2449
|
+
/**
|
|
2450
|
+
* Session lifecycle events: a hook or lane runner reports these, and they go
|
|
2451
|
+
* through the spool only (US-038 c1). The daemon delivers the spool.
|
|
2452
|
+
*/
|
|
2453
|
+
const SPOOL_ONLY_SESSION_KINDS = new Set([
|
|
2454
|
+
"session_start",
|
|
2455
|
+
"turn_start",
|
|
2456
|
+
"turn_end",
|
|
2457
|
+
"session_end",
|
|
2458
|
+
]);
|
|
2459
|
+
/**
|
|
2460
|
+
* Whether `hq mesh session <verb>` appends to the spool instead of posting.
|
|
2461
|
+
* Only a hook-tracked session (one with a local session state file) goes to
|
|
2462
|
+
* the spool: the drain needs that state to deliver the line. For such a
|
|
2463
|
+
* session `--enqueue` always appends (no network) and the lifecycle kinds do
|
|
2464
|
+
* with or without it. A session with no local state (the lane runner,
|
|
2465
|
+
* hq-delegate-transfer.sh) keeps the old direct post, even with `--enqueue`,
|
|
2466
|
+
* so its delivery and flags are exactly as before. A hand-run task-status,
|
|
2467
|
+
* blocked or note without `--enqueue` still posts directly.
|
|
2468
|
+
*/
|
|
2469
|
+
export function sessionEventGoesToSpool(kind, enqueue, hasLocalState) {
|
|
2470
|
+
if (!hasLocalState)
|
|
2471
|
+
return false;
|
|
2472
|
+
return enqueue === true || SPOOL_ONLY_SESSION_KINDS.has(kind);
|
|
2473
|
+
}
|
|
2444
2474
|
function workMeshHomeRoot() {
|
|
2445
2475
|
return workMeshRoot(os.homedir(), process.env);
|
|
2446
2476
|
}
|
|
2447
2477
|
async function runSessionEnqueue(cliKind, opts) {
|
|
2448
2478
|
const { CLI_KIND_TO_SCHEMA, resolveEnqueueSessionId } = await import("../lib/mesh/live/enqueue.js");
|
|
2449
|
-
//
|
|
2450
|
-
//
|
|
2451
|
-
//
|
|
2479
|
+
// US-038 c1: a hook-tracked session's events go through the spool only.
|
|
2480
|
+
// `--enqueue` and the lifecycle kinds append one spool line (no token, no
|
|
2481
|
+
// network) and the daemon delivers it. A session with no local state keeps
|
|
2482
|
+
// the 2026-09-08 direct post (see sessionEventGoesToSpool), as does a
|
|
2483
|
+
// hand-run task-status, blocked or note without `--enqueue`.
|
|
2452
2484
|
const kind = CLI_KIND_TO_SCHEMA[cliKind];
|
|
2453
2485
|
if (!kind)
|
|
2454
2486
|
fail(`Unknown session verb: ${cliKind}`);
|
|
@@ -2480,6 +2512,48 @@ async function runSessionEnqueue(cliKind, opts) {
|
|
|
2480
2512
|
/* prompt rebind is fail-soft */
|
|
2481
2513
|
}
|
|
2482
2514
|
}
|
|
2515
|
+
const hasLocalState = readSessionState(sessionId, workContextHomeRoot()) !== null;
|
|
2516
|
+
if (sessionEventGoesToSpool(kind, opts.enqueue, hasLocalState)) {
|
|
2517
|
+
// The spool line has no field for these, and the drain posts no
|
|
2518
|
+
// evidence, so refuse rather than drop them.
|
|
2519
|
+
const unsupported = [
|
|
2520
|
+
(opts.touchedPath ?? []).some((p) => p.trim()) ? "--touched-path" : null,
|
|
2521
|
+
opts.repoPath?.trim() ? "--repo-path" : null,
|
|
2522
|
+
].filter((flag) => flag !== null);
|
|
2523
|
+
if (unsupported.length > 0) {
|
|
2524
|
+
fail(`${unsupported.join(" and ")} cannot be carried through the Work Mesh spool for session ${sessionId} ` +
|
|
2525
|
+
"(it has local session state, so this event goes to the spool). Drop the flag; nothing was written.");
|
|
2526
|
+
}
|
|
2527
|
+
const { enqueueSessionEvent } = await import("../lib/mesh/live/enqueue.js");
|
|
2528
|
+
const toolWrites = opts.toolWrites === undefined ? undefined : Number(opts.toolWrites);
|
|
2529
|
+
const { event } = enqueueSessionEvent({
|
|
2530
|
+
kind,
|
|
2531
|
+
sessionId,
|
|
2532
|
+
harness,
|
|
2533
|
+
adapterVersion,
|
|
2534
|
+
runtimeVersion: opts.runtimeVersion?.trim() || undefined,
|
|
2535
|
+
source: "hooks",
|
|
2536
|
+
at: opts.at?.trim() || undefined,
|
|
2537
|
+
seq,
|
|
2538
|
+
eventId: opts.eventId,
|
|
2539
|
+
taskId: opts.taskId,
|
|
2540
|
+
status: opts.status,
|
|
2541
|
+
reason: opts.reason,
|
|
2542
|
+
summary: opts.summary,
|
|
2543
|
+
cwd: opts.cwd,
|
|
2544
|
+
hqRoot: opts.hqRoot?.trim() || undefined,
|
|
2545
|
+
companySlug: opts.companySlug,
|
|
2546
|
+
project: opts.project,
|
|
2547
|
+
task: opts.task,
|
|
2548
|
+
toolWrites: toolWrites !== undefined && Number.isInteger(toolWrites) && toolWrites >= 0 ? toolWrites : undefined,
|
|
2549
|
+
root: workMeshHomeRoot(),
|
|
2550
|
+
env: process.env,
|
|
2551
|
+
});
|
|
2552
|
+
if (opts.json) {
|
|
2553
|
+
console.log(JSON.stringify({ ok: true, action: "enqueue", kind, eventId: event.eventId }, null, 2));
|
|
2554
|
+
}
|
|
2555
|
+
return;
|
|
2556
|
+
}
|
|
2483
2557
|
const evidence = buildEmitEvidence({
|
|
2484
2558
|
sessionId: sessionId,
|
|
2485
2559
|
hqRoot: opts.hqRoot,
|
|
@@ -2644,7 +2718,9 @@ async function runMeshEmit(opts) {
|
|
|
2644
2718
|
let skipped = 0;
|
|
2645
2719
|
let newEvents = [];
|
|
2646
2720
|
if (opts.replayLegacy) {
|
|
2647
|
-
|
|
2721
|
+
// Direct mode: a queue that predates the drain's first run is set aside
|
|
2722
|
+
// before anything is read (US-038, owner decision 70).
|
|
2723
|
+
const backlog = readLegacyBacklogForMode(resolveMeshEmitMode(), meshRoot);
|
|
2648
2724
|
scanned = backlog.scanned;
|
|
2649
2725
|
skipped = backlog.skipped;
|
|
2650
2726
|
newEvents = backlog.events;
|
|
@@ -2674,14 +2750,20 @@ async function runSessionFlush(opts) {
|
|
|
2674
2750
|
token,
|
|
2675
2751
|
baseUrl: resolveVaultApiBase(process.env),
|
|
2676
2752
|
});
|
|
2677
|
-
|
|
2753
|
+
// In direct mode this is one drain cycle: the first run on a machine moves
|
|
2754
|
+
// the queued files aside and posts nothing (US-038, owner decision 70).
|
|
2755
|
+
const { summary, firstRun, setAside } = await flushForEmitMode(resolveMeshEmitMode(), {
|
|
2678
2756
|
reportingAllowed: () => reportingRuntimeAllowed(isMachineIdentity()),
|
|
2679
2757
|
workMeshRoot: workMeshHomeRoot(),
|
|
2680
2758
|
workContextRoot: workContextHomeRoot(),
|
|
2681
2759
|
poster,
|
|
2682
2760
|
});
|
|
2683
2761
|
if (opts.json) {
|
|
2684
|
-
console.log(JSON.stringify({ ok: true, action: "flush", ...summary }, null, 2));
|
|
2762
|
+
console.log(JSON.stringify({ ok: true, action: "flush", ...summary, firstRun, setAside }, null, 2));
|
|
2763
|
+
return;
|
|
2764
|
+
}
|
|
2765
|
+
if (firstRun) {
|
|
2766
|
+
console.log(`work-mesh flush: first run in direct mode; moved ${setAside.length} queued file(s) aside, nothing posted`);
|
|
2685
2767
|
return;
|
|
2686
2768
|
}
|
|
2687
2769
|
console.log(`work-mesh flush: claimed=${summary.claimed} posted=${summary.posted}` +
|
package/dist/commands/reindex.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { reconcileHookRegistrations } from '../lib/hook-engine/reconcile.js';
|
|
2
2
|
import { SKIP_CANARY_GATE_ENV } from '../lib/hook-engine/canary-gate.js';
|
|
3
3
|
import { trustCodexUserHooks } from '../utils/hook-trust.js';
|
|
4
|
+
import { REINDEX_FROM_HOOK_ENV } from '../utils/host-registration.js';
|
|
4
5
|
/**
|
|
5
6
|
* hq reindex — surface namespaced skills and commands, clean up retired
|
|
6
7
|
* personal-overlay mirror links, capture coding-harness session logs, regenerate
|
|
@@ -749,6 +750,11 @@ export function registerReindexCommand(program) {
|
|
|
749
750
|
// install, reindex and the Grok trust step all honor it the same way.
|
|
750
751
|
if (opts.skipHostCanaryGate)
|
|
751
752
|
process.env[SKIP_CANARY_GATE_ENV] = '1';
|
|
753
|
+
// A reindex started by a hook never changes a host's core (#3039
|
|
754
|
+
// Q-ST2-04-1, ruling (A)): the host canary gate keeps each host on the
|
|
755
|
+
// core it is on now. Read from the environment for the same reason.
|
|
756
|
+
if (opts.fromHook)
|
|
757
|
+
process.env[REINDEX_FROM_HOOK_ENV] = '1';
|
|
752
758
|
// Resolve the lock-wait bound. An explicit --lock-timeout wins; otherwise
|
|
753
759
|
// --from-hook forces 0 (refuse-fast) so a hook fired while a sync/rescue
|
|
754
760
|
// holds the shared per-root operation lock can never stall the agent.
|
package/dist/commands/repo.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ import { Command } from "commander";
|
|
|
8
8
|
* ordering, and quoting in the rest of the file are left as they were. The
|
|
9
9
|
* result is parsed back before writing; if the entry does not show up where
|
|
10
10
|
* expected, nothing is written.
|
|
11
|
+
*
|
|
12
|
+
* Folder-to-company has one store (US-030 c3): the registry that `hq link`
|
|
13
|
+
* writes and `hq resolve-company`, hqd and the MCP tool read. After the
|
|
14
|
+
* manifest write, `hq repo add` seeds that registry from the manifest the way
|
|
15
|
+
* `hq install --global` does, so the new checkout resolves at once. Seeding
|
|
16
|
+
* never replaces an `hq link` entry.
|
|
11
17
|
*/
|
|
12
18
|
export declare const MANIFEST_RELATIVE_PATH: string;
|
|
13
19
|
export declare function manifestRepos(text: string, company: string): string[] | null;
|
|
@@ -28,12 +34,19 @@ export interface RepoAddOptions {
|
|
|
28
34
|
visibility: "private" | "public";
|
|
29
35
|
name?: string;
|
|
30
36
|
dryRun?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Registry file to seed after the manifest write (the `hq link` store).
|
|
39
|
+
* Unset seeds nothing; the command passes the user's registry.
|
|
40
|
+
*/
|
|
41
|
+
registryFile?: string;
|
|
31
42
|
}
|
|
32
43
|
export interface RepoAddResult {
|
|
33
44
|
entry: string;
|
|
34
45
|
linked: boolean;
|
|
35
46
|
manifestChanged: boolean;
|
|
36
47
|
warnings: string[];
|
|
48
|
+
/** True when the registry was seeded from the manifest after the write. */
|
|
49
|
+
registrySeeded?: boolean;
|
|
37
50
|
}
|
|
38
51
|
/** Register a checkout. Throws a user-facing Error on any refusal. */
|
|
39
52
|
export declare function runRepoAdd(opts: RepoAddOptions): RepoAddResult;
|
package/dist/commands/repo.js
CHANGED
|
@@ -3,6 +3,8 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import * as yaml from "js-yaml";
|
|
5
5
|
import { findHqRoot } from "../utils/manifest.js";
|
|
6
|
+
import { readRegistry, registryFile, resolveCompanyForDir } from "../lib/registry/registry.js";
|
|
7
|
+
import { seedRegistryFromHqRoot } from "./link.js";
|
|
6
8
|
/**
|
|
7
9
|
* `hq repo add <path> --company <slug>` — register a git checkout with HQ:
|
|
8
10
|
* link it into `repos/<private|public>/<name>` and list it under
|
|
@@ -12,6 +14,12 @@ import { findHqRoot } from "../utils/manifest.js";
|
|
|
12
14
|
* ordering, and quoting in the rest of the file are left as they were. The
|
|
13
15
|
* result is parsed back before writing; if the entry does not show up where
|
|
14
16
|
* expected, nothing is written.
|
|
17
|
+
*
|
|
18
|
+
* Folder-to-company has one store (US-030 c3): the registry that `hq link`
|
|
19
|
+
* writes and `hq resolve-company`, hqd and the MCP tool read. After the
|
|
20
|
+
* manifest write, `hq repo add` seeds that registry from the manifest the way
|
|
21
|
+
* `hq install --global` does, so the new checkout resolves at once. Seeding
|
|
22
|
+
* never replaces an `hq link` entry.
|
|
15
23
|
*/
|
|
16
24
|
export const MANIFEST_RELATIVE_PATH = path.join("companies", "manifest.yaml");
|
|
17
25
|
function indentOf(line) {
|
|
@@ -271,7 +279,36 @@ export function runRepoAdd(opts) {
|
|
|
271
279
|
if (manifestChanged)
|
|
272
280
|
writeManifestAtomically(manifestPath, manifestText, nextText);
|
|
273
281
|
}
|
|
274
|
-
|
|
282
|
+
const result = { entry, linked: linkPath !== null, manifestChanged, warnings };
|
|
283
|
+
if (!opts.dryRun && opts.registryFile !== undefined) {
|
|
284
|
+
result.registrySeeded = seedRegistryAfterAdd(hqRoot, opts.registryFile, sourceReal, opts.company, warnings);
|
|
285
|
+
}
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Seed the folder-to-company registry from the manifest just written. The
|
|
290
|
+
* manifest write has already happened, so a registry failure is a warning,
|
|
291
|
+
* not an error: `hq install --global` or `hq link --seed-manifest` repairs it.
|
|
292
|
+
*/
|
|
293
|
+
function seedRegistryAfterAdd(hqRoot, file, checkout, company, warnings) {
|
|
294
|
+
try {
|
|
295
|
+
seedRegistryFromHqRoot(hqRoot, { file });
|
|
296
|
+
}
|
|
297
|
+
catch (err) {
|
|
298
|
+
warnings.push(`The HQ registry was not updated (${err instanceof Error ? err.message : String(err)}). ` +
|
|
299
|
+
`Run \`hq link --seed-manifest ${hqRoot}\` to update it.`);
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
const bound = resolveCompanyForDir(readRegistry(file), checkout);
|
|
304
|
+
if (bound.company && bound.company !== company) {
|
|
305
|
+
warnings.push(`${checkout} is linked to ${bound.company} with \`hq link\`; hq resolve-company keeps answering ${bound.company} until that link is removed (\`hq unlink\`).`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
// The seed above read and wrote this file; a failed re-read changes nothing written.
|
|
310
|
+
}
|
|
311
|
+
return true;
|
|
275
312
|
}
|
|
276
313
|
function isDanglingSymlink(p) {
|
|
277
314
|
try {
|
|
@@ -312,6 +349,7 @@ export function registerRepoCommand(program) {
|
|
|
312
349
|
visibility: opts.public ? "public" : "private",
|
|
313
350
|
name: opts.name,
|
|
314
351
|
dryRun: opts.dryRun,
|
|
352
|
+
registryFile: registryFile(),
|
|
315
353
|
});
|
|
316
354
|
for (const w of result.warnings)
|
|
317
355
|
console.warn(chalk.yellow("Warning:"), w);
|
|
@@ -23,9 +23,27 @@ export interface HeldScope {
|
|
|
23
23
|
at: string;
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
export interface CorruptIdentityRecovery {
|
|
27
|
+
recovered: boolean;
|
|
28
|
+
reason?: "none" | "unproven" | "different-person" | "several-people";
|
|
29
|
+
clearedMarker: boolean;
|
|
30
|
+
clearedScopeFiles: number;
|
|
31
|
+
/** Corrupt scope records restored with an upload hold. Absent on older hq-cloud. */
|
|
32
|
+
heldScopeFiles?: number;
|
|
33
|
+
/** True when recovery replaced the file with a hold and cleared nothing. */
|
|
34
|
+
uploadsStayHeld?: boolean;
|
|
35
|
+
}
|
|
26
36
|
interface FenceExports {
|
|
27
37
|
listPushIdentityFences: (stateDir: string) => HeldScope[];
|
|
28
38
|
releasePushIdentityFences: (stateDir: string, identities: readonly string[], slugs?: readonly string[]) => string[];
|
|
39
|
+
corruptPushIdentityHold?: (stateDir: string, journalSlug?: string) => boolean;
|
|
40
|
+
recoverCorruptPushIdentity?: (stateDir: string, identities: readonly string[], options?: {
|
|
41
|
+
personalOwnerUid?: string | null;
|
|
42
|
+
slugs?: readonly string[];
|
|
43
|
+
limitToSlugs?: boolean;
|
|
44
|
+
confirmUnproven?: boolean;
|
|
45
|
+
}) => CorruptIdentityRecovery;
|
|
46
|
+
readPersonalVaultOwnerUid?: () => string | null;
|
|
29
47
|
}
|
|
30
48
|
export declare const HELD_UNAVAILABLE_MESSAGE = "this HQ build cannot list or release held uploads yet; update HQ and try again";
|
|
31
49
|
export declare function fenceExports(mod?: Record<string, unknown>): FenceExports | undefined;
|
|
@@ -61,7 +79,11 @@ export interface ReleaseHeldOptions {
|
|
|
61
79
|
personal?: boolean;
|
|
62
80
|
yes?: boolean;
|
|
63
81
|
json?: boolean;
|
|
82
|
+
/** Restore an unreadable identity file and keep every upload held until the person confirms the files. */
|
|
83
|
+
confirmUnproven?: boolean;
|
|
64
84
|
}
|
|
85
|
+
/** Next step on this computer when saved history names nobody or more than one person. */
|
|
86
|
+
export declare const CONFIRM_UNPROVEN_COMMAND = "hq sync release-held --confirm-unproven";
|
|
65
87
|
export declare function runReleaseHeld(deps: SyncHeldDeps, options: ReleaseHeldOptions): Promise<number>;
|
|
66
88
|
/**
|
|
67
89
|
* The signed-in identity from the session token `ensureCognitoToken` selects
|
|
@@ -26,40 +26,67 @@ export function fenceExports(mod = hqCloud) {
|
|
|
26
26
|
const release = mod.releasePushIdentityFences;
|
|
27
27
|
if (typeof list !== "function" || typeof release !== "function")
|
|
28
28
|
return undefined;
|
|
29
|
+
const corrupt = mod.corruptPushIdentityHold;
|
|
30
|
+
const recover = mod.recoverCorruptPushIdentity;
|
|
31
|
+
const readOwner = mod.readPersonalVaultOwnerUid;
|
|
29
32
|
return {
|
|
30
33
|
listPushIdentityFences: list,
|
|
31
34
|
releasePushIdentityFences: release,
|
|
35
|
+
...(typeof corrupt === "function" ? { corruptPushIdentityHold: corrupt } : {}),
|
|
36
|
+
...(typeof recover === "function" ? { recoverCorruptPushIdentity: recover } : {}),
|
|
37
|
+
...(typeof readOwner === "function" ? { readPersonalVaultOwnerUid: readOwner } : {}),
|
|
32
38
|
};
|
|
33
39
|
}
|
|
34
40
|
export function scopeLabel(slug) {
|
|
35
41
|
return slug === PERSONAL_VAULT_JOURNAL_SLUG || slug === "personal" ? "personal vault" : `company ${slug}`;
|
|
36
42
|
}
|
|
43
|
+
/** A sync has written the files this hold would upload. A count of zero is a real empty list. */
|
|
44
|
+
function hasFileList(scope) {
|
|
45
|
+
const held = scope.held;
|
|
46
|
+
if (!held || !Array.isArray(held.samplePaths))
|
|
47
|
+
return false;
|
|
48
|
+
if (held.samplePaths.length > 0)
|
|
49
|
+
return true;
|
|
50
|
+
return held.count === 0;
|
|
51
|
+
}
|
|
37
52
|
function describe(scope) {
|
|
38
53
|
const since = new Date(scope.sinceMs).toISOString();
|
|
39
54
|
const lines = [` ${scopeLabel(scope.slug)}: held since ${since}`];
|
|
40
55
|
if (scope.held) {
|
|
56
|
+
const samples = scope.held.samplePaths;
|
|
41
57
|
lines.push(` ${scope.held.count} file${scope.held.count === 1 ? "" : "s"} waiting to upload (last checked ${scope.held.at})`);
|
|
42
|
-
for (const sample of
|
|
58
|
+
for (const sample of samples)
|
|
43
59
|
lines.push(` ${sample}`);
|
|
44
|
-
if (scope.held.count >
|
|
45
|
-
lines.push(
|
|
60
|
+
if (scope.held.count > samples.length)
|
|
61
|
+
lines.push(` and ${scope.held.count - samples.length} more`);
|
|
46
62
|
}
|
|
47
63
|
return lines;
|
|
48
64
|
}
|
|
65
|
+
function unnamedHoldMessage(scopes) {
|
|
66
|
+
const names = scopes.map((scope) => scopeLabel(scope.slug)).join(", ");
|
|
67
|
+
const single = scopes.length === 1;
|
|
68
|
+
return `${names} ${single ? "is" : "are"} held, but this computer has not listed the files yet, so ${single ? "that hold stays" : "those holds stay"}. Run \`hq sync\` once, then run \`hq sync release-held\` again and confirm the files it names.`;
|
|
69
|
+
}
|
|
49
70
|
export async function runSyncHeld(deps, json = false) {
|
|
50
71
|
if (!deps.exports) {
|
|
51
72
|
deps.log(`${chalk.red("✗")} ${HELD_UNAVAILABLE_MESSAGE}`);
|
|
52
73
|
return 1;
|
|
53
74
|
}
|
|
54
75
|
const scopes = deps.exports.listPushIdentityFences(deps.stateDir);
|
|
76
|
+
const corrupt = deps.exports.corruptPushIdentityHold?.(deps.stateDir) === true;
|
|
55
77
|
if (json) {
|
|
56
|
-
deps.log(JSON.stringify({ scopes }));
|
|
78
|
+
deps.log(JSON.stringify({ scopes, ...(corrupt ? { corruptIdentity: true } : {}) }));
|
|
57
79
|
return 0;
|
|
58
80
|
}
|
|
59
|
-
if (scopes.length === 0) {
|
|
81
|
+
if (scopes.length === 0 && !corrupt) {
|
|
60
82
|
deps.log("No uploads are held on this computer.");
|
|
61
83
|
return 0;
|
|
62
84
|
}
|
|
85
|
+
if (corrupt) {
|
|
86
|
+
deps.log("Uploads are held because the identity file on this computer can't be read. Run `hq sync release-held` to restore it from the account you are signed in as.");
|
|
87
|
+
}
|
|
88
|
+
if (scopes.length === 0)
|
|
89
|
+
return 0;
|
|
63
90
|
// First install also writes this hold (feedback_baa82c96). Do not say
|
|
64
91
|
// another account was signed in; that is often false and reads as a
|
|
65
92
|
// security scare. The hold is still a confirmation before upload.
|
|
@@ -68,9 +95,16 @@ export async function runSyncHeld(deps, json = false) {
|
|
|
68
95
|
for (const line of describe(scope))
|
|
69
96
|
deps.log(line);
|
|
70
97
|
deps.log("");
|
|
71
|
-
|
|
98
|
+
const unlisted = scopes.filter((scope) => !hasFileList(scope));
|
|
99
|
+
if (scopes.some(hasFileList)) {
|
|
100
|
+
deps.log("Nothing has been uploaded or deleted in the cloud. If these files are yours, run `hq sync release-held`.");
|
|
101
|
+
}
|
|
102
|
+
if (unlisted.length > 0)
|
|
103
|
+
deps.log(unnamedHoldMessage(unlisted));
|
|
72
104
|
return 0;
|
|
73
105
|
}
|
|
106
|
+
/** Next step on this computer when saved history names nobody or more than one person. */
|
|
107
|
+
export const CONFIRM_UNPROVEN_COMMAND = "hq sync release-held --confirm-unproven";
|
|
74
108
|
export async function runReleaseHeld(deps, options) {
|
|
75
109
|
if (!deps.exports) {
|
|
76
110
|
deps.log(`${chalk.red("✗")} ${HELD_UNAVAILABLE_MESSAGE}`);
|
|
@@ -81,28 +115,55 @@ export async function runReleaseHeld(deps, options) {
|
|
|
81
115
|
scopes = scopes.filter((scope) => scope.slug === PERSONAL_VAULT_JOURNAL_SLUG || scope.slug === "personal");
|
|
82
116
|
if (options.company)
|
|
83
117
|
scopes = scopes.filter((scope) => scope.slug === options.company);
|
|
84
|
-
|
|
118
|
+
const corrupt = corruptHoldRequested(deps, options);
|
|
119
|
+
if (scopes.length === 0 && !corrupt) {
|
|
85
120
|
deps.log(options.json ? JSON.stringify({ released: [] }) : "No held uploads match.");
|
|
86
121
|
return 0;
|
|
87
122
|
}
|
|
88
|
-
const needPersonal = scopes.some((scope) => scope.slug === PERSONAL_VAULT_JOURNAL_SLUG || scope.slug === "personal");
|
|
123
|
+
const needPersonal = corrupt || scopes.some((scope) => scope.slug === PERSONAL_VAULT_JOURNAL_SLUG || scope.slug === "personal");
|
|
89
124
|
const snapshot = await deps.identity({ needPersonal, interactive: true });
|
|
90
125
|
const identities = [snapshot.sub, ...(snapshot.personalUid ? [snapshot.personalUid] : [])];
|
|
91
126
|
const mine = scopes.filter((scope) => identities.includes(scope.uid));
|
|
92
|
-
|
|
127
|
+
const listed = mine.filter(hasFileList);
|
|
128
|
+
const unlisted = mine.filter((scope) => !hasFileList(scope));
|
|
129
|
+
if (mine.length === 0 && !corrupt) {
|
|
93
130
|
deps.log(options.json
|
|
94
131
|
? JSON.stringify({ released: [], reason: "not-yours" })
|
|
95
132
|
: "These held uploads belong to a different signed-in person. Sign in as that person to release them.");
|
|
96
133
|
return 1;
|
|
97
134
|
}
|
|
98
135
|
if (!options.json) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
for (const
|
|
102
|
-
|
|
136
|
+
if (listed.length > 0 && options.confirmUnproven) {
|
|
137
|
+
deps.log("These uploads stay held until you confirm which files are yours:");
|
|
138
|
+
for (const scope of listed)
|
|
139
|
+
for (const line of describe(scope))
|
|
140
|
+
deps.log(line);
|
|
141
|
+
}
|
|
142
|
+
else if (listed.length > 0) {
|
|
143
|
+
deps.log("Releasing these uploads sends the files below to the cloud as yours:");
|
|
144
|
+
for (const scope of listed)
|
|
145
|
+
for (const line of describe(scope))
|
|
146
|
+
deps.log(line);
|
|
147
|
+
}
|
|
148
|
+
if (corrupt) {
|
|
149
|
+
deps.log("The identity file on this computer can't be read. Restoring it keeps the uploads held until you review them.");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// A recovered corrupt scope is a hold with no file list until a sync records one.
|
|
153
|
+
// Releasing it would upload whatever is on disk, including another person's edits.
|
|
154
|
+
if (listed.length === 0 && !corrupt) {
|
|
155
|
+
const unnamed = unnamedHoldMessage(unlisted);
|
|
156
|
+
deps.log(options.json ? JSON.stringify({ released: [], reason: "no-file-list", message: unnamed }) : unnamed);
|
|
157
|
+
return 1;
|
|
103
158
|
}
|
|
159
|
+
if (!options.json && unlisted.length > 0)
|
|
160
|
+
deps.log(unnamedHoldMessage(unlisted));
|
|
104
161
|
if (!options.yes) {
|
|
105
|
-
const ok = await deps.confirm(
|
|
162
|
+
const ok = await deps.confirm(options.confirmUnproven
|
|
163
|
+
? "Restore the identity file and keep every upload held until you confirm which files are yours? [y/N] "
|
|
164
|
+
: corrupt && listed.length === 0
|
|
165
|
+
? "Restore the identity file from the account you are signed in as? [y/N] "
|
|
166
|
+
: "Are these files yours to upload? [y/N] ");
|
|
106
167
|
if (!ok) {
|
|
107
168
|
deps.log(options.json ? JSON.stringify({ released: [] }) : "Nothing released.");
|
|
108
169
|
return 1;
|
|
@@ -118,12 +179,99 @@ export async function runReleaseHeld(deps, options) {
|
|
|
118
179
|
: "The signed-in account changed while releasing. Nothing was released; run the command again.");
|
|
119
180
|
return 1;
|
|
120
181
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
182
|
+
// The confirm-unproven prompt keeps every upload held. It is not agreement
|
|
183
|
+
// to release the listed scopes, and --yes only skips that prompt. Release
|
|
184
|
+
// those scopes only when the person agreed to upload these exact files.
|
|
185
|
+
const withheldListed = options.confirmUnproven === true && listed.length > 0;
|
|
186
|
+
const released = listed.length === 0 || withheldListed
|
|
187
|
+
? []
|
|
188
|
+
: deps.exports.releasePushIdentityFences(deps.stateDir, identities, listed.map((scope) => scope.slug));
|
|
189
|
+
const recovery = corrupt ? restoreCorruptIdentity(deps, identities, options) : undefined;
|
|
190
|
+
// "none" means the unreadable file was already gone. That is not a refusal.
|
|
191
|
+
if (recovery && !recovery.recovered && recovery.reason !== "none") {
|
|
192
|
+
if (!options.json && released.length > 0) {
|
|
193
|
+
deps.log(`Released ${released.map(scopeLabel).join(", ")}.`);
|
|
194
|
+
}
|
|
195
|
+
deps.log(options.json
|
|
196
|
+
? JSON.stringify({ released, identityRestored: false, reason: recovery.reason })
|
|
197
|
+
: corruptRefusal(recovery.reason, released.length > 0));
|
|
198
|
+
return 1;
|
|
199
|
+
}
|
|
200
|
+
const restored = recovery?.recovered === true;
|
|
201
|
+
const heldScopeFiles = recovery?.heldScopeFiles ?? 0;
|
|
202
|
+
const stayHeld = heldScopeFiles > 0 || recovery?.uploadsStayHeld === true || withheldListed;
|
|
203
|
+
const reportCorrupt = corrupt && recovery?.reason !== "none";
|
|
204
|
+
const needsSync = unlisted.length > 0 ? unlisted.map((scope) => scope.slug) : undefined;
|
|
205
|
+
if (options.json) {
|
|
206
|
+
deps.log(JSON.stringify({
|
|
207
|
+
released,
|
|
208
|
+
...(reportCorrupt ? { identityRestored: restored } : {}),
|
|
209
|
+
...(recovery?.uploadsStayHeld === true || withheldListed ? { uploadsStayHeld: true } : {}),
|
|
210
|
+
...(needsSync ? { needsSync, ...(released.length === 0 && !withheldListed ? { reason: "no-file-list" } : {}) } : {}),
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
else if (restored && stayHeld && released.length === 0) {
|
|
214
|
+
deps.log(withheldListed
|
|
215
|
+
? "Restored the identity file and kept the uploads held. Run `hq sync release-held` again without `--confirm-unproven` and confirm the files it names."
|
|
216
|
+
: "Restored the identity file and kept the uploads held. Run `hq sync` once so the held files are listed, then run `hq sync release-held` again and confirm the files it names.");
|
|
217
|
+
}
|
|
218
|
+
else if (restored && stayHeld) {
|
|
219
|
+
deps.log(`Released ${released.map(scopeLabel).join(", ")}. Restored the identity file and kept the uploads held. Run \`hq sync\` once so the held files are listed, then run \`hq sync release-held\` again and confirm the files it names.`);
|
|
220
|
+
}
|
|
221
|
+
else if (restored && released.length === 0) {
|
|
222
|
+
deps.log("Restored the identity file from the account you are signed in as. The next sync can upload.");
|
|
223
|
+
}
|
|
224
|
+
else if (restored) {
|
|
225
|
+
deps.log(`Released ${released.map(scopeLabel).join(", ")} and restored the identity file. The next sync uploads these files.`);
|
|
226
|
+
}
|
|
227
|
+
else if (withheldListed) {
|
|
228
|
+
deps.log("Kept the uploads held. Run `hq sync release-held` without `--confirm-unproven` and confirm the files it names.");
|
|
229
|
+
}
|
|
230
|
+
else if (released.length === 0) {
|
|
231
|
+
deps.log("No held uploads match.");
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
deps.log(`Released ${released.map(scopeLabel).join(", ")}. The next sync uploads these files.`);
|
|
235
|
+
}
|
|
125
236
|
return 0;
|
|
126
237
|
}
|
|
238
|
+
function corruptHoldRequested(deps, options) {
|
|
239
|
+
const probe = deps.exports?.corruptPushIdentityHold;
|
|
240
|
+
if (!probe || !deps.exports?.recoverCorruptPushIdentity)
|
|
241
|
+
return false;
|
|
242
|
+
if (options.company)
|
|
243
|
+
return probe(deps.stateDir, options.company);
|
|
244
|
+
if (options.personal)
|
|
245
|
+
return probe(deps.stateDir, PERSONAL_VAULT_JOURNAL_SLUG) || probe(deps.stateDir, "personal");
|
|
246
|
+
return probe(deps.stateDir);
|
|
247
|
+
}
|
|
248
|
+
function restoreCorruptIdentity(deps, identities, options) {
|
|
249
|
+
const recover = deps.exports?.recoverCorruptPushIdentity;
|
|
250
|
+
if (!recover)
|
|
251
|
+
return { recovered: false, reason: "unproven", clearedMarker: false, clearedScopeFiles: 0 };
|
|
252
|
+
const personalOwnerUid = deps.exports?.readPersonalVaultOwnerUid?.() ?? null;
|
|
253
|
+
const slugs = options.company
|
|
254
|
+
? [options.company]
|
|
255
|
+
: options.personal
|
|
256
|
+
? [PERSONAL_VAULT_JOURNAL_SLUG, "personal"]
|
|
257
|
+
: undefined;
|
|
258
|
+
return recover(deps.stateDir, identities, {
|
|
259
|
+
personalOwnerUid,
|
|
260
|
+
...(slugs ? { slugs, limitToSlugs: true } : {}),
|
|
261
|
+
...(options.confirmUnproven ? { confirmUnproven: true } : {}),
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
function corruptRefusal(reason, released) {
|
|
265
|
+
const tail = released ? "The identity file was left unchanged." : "Nothing was changed.";
|
|
266
|
+
const confirm = `Run \`${CONFIRM_UNPROVEN_COMMAND}\` on this computer. It restores the file and keeps every upload held until you confirm which files are yours.`;
|
|
267
|
+
if (reason === "several-people") {
|
|
268
|
+
return `The identity file on this computer can't be read, and this computer's history names more than one person. ${tail} ${confirm}`;
|
|
269
|
+
}
|
|
270
|
+
if (reason === "different-person") {
|
|
271
|
+
return `The identity file on this computer can't be read, and the signed-in account is not the one this computer's history names. ${tail} Sign in as that account and run \`hq sync release-held\`.`;
|
|
272
|
+
}
|
|
273
|
+
return `The identity file on this computer can't be read, and no saved history on this computer names an account for it. ${tail} ${confirm}`;
|
|
274
|
+
}
|
|
127
275
|
async function confirmOnTty(question) {
|
|
128
276
|
if (process.stdin.isTTY !== true || process.stdout.isTTY !== true)
|
|
129
277
|
return false;
|
|
@@ -186,6 +334,7 @@ export function registerSyncHeldCommands(syncCmd) {
|
|
|
186
334
|
.option("--company <slug>", "Release only this company")
|
|
187
335
|
.option("--personal", "Release only the personal vault")
|
|
188
336
|
.option("--yes", "Do not ask for confirmation")
|
|
337
|
+
.option("--confirm-unproven", "Restore an unreadable identity file and keep every upload held until you confirm which files are yours")
|
|
189
338
|
.option("--json", "Print the result as JSON")
|
|
190
339
|
.action(async (options) => {
|
|
191
340
|
process.exitCode = await runReleaseHeld(createDefaultSyncHeldDeps(), options);
|
|
@@ -95,7 +95,9 @@ export declare function validateMode(mode: string): SyncMode;
|
|
|
95
95
|
* throws — auto-detect is best-effort.
|
|
96
96
|
*/
|
|
97
97
|
export declare function readActiveCompanySlug(hqRoot: string): string | undefined;
|
|
98
|
-
/**
|
|
98
|
+
/** Validate portable, company-relative sync prefixes without normalizing them. */
|
|
99
|
+
export declare function validateCustomPaths(entries: readonly string[] | undefined): void;
|
|
100
|
+
/** Parse `--paths a/,b/c/` into validated, trimmed non-empty entries. */
|
|
99
101
|
export declare function parseCustomPaths(raw: string | undefined): string[] | undefined;
|
|
100
102
|
/**
|
|
101
103
|
* Resolve a membership by company slug, then PUT the new sync-mode. Returns
|
|
@@ -69,7 +69,15 @@ export function readActiveCompanySlug(hqRoot) {
|
|
|
69
69
|
return undefined;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
/**
|
|
72
|
+
/** Validate portable, company-relative sync prefixes without normalizing them. */
|
|
73
|
+
export function validateCustomPaths(entries) {
|
|
74
|
+
for (const entry of entries ?? []) {
|
|
75
|
+
if (!entry || entry.includes("..") || /^[\\/]/.test(entry) || /^[A-Za-z]:/.test(entry)) {
|
|
76
|
+
throw new Error("Custom sync paths must be relative paths without parent ('..') components.");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Parse `--paths a/,b/c/` into validated, trimmed non-empty entries. */
|
|
73
81
|
export function parseCustomPaths(raw) {
|
|
74
82
|
if (!raw)
|
|
75
83
|
return undefined;
|
|
@@ -77,6 +85,7 @@ export function parseCustomPaths(raw) {
|
|
|
77
85
|
.split(",")
|
|
78
86
|
.map((s) => s.trim())
|
|
79
87
|
.filter((s) => s.length > 0);
|
|
88
|
+
validateCustomPaths(parts);
|
|
80
89
|
return parts.length > 0 ? parts : undefined;
|
|
81
90
|
}
|
|
82
91
|
// ── Orchestrators (pure, injectable — driven by tests) ──────────────────────
|
|
@@ -87,6 +96,7 @@ export function parseCustomPaths(raw) {
|
|
|
87
96
|
*/
|
|
88
97
|
export async function setSyncMode(options) {
|
|
89
98
|
const { mode, companySlug, customPaths, vaultClient } = options;
|
|
99
|
+
validateCustomPaths(customPaths);
|
|
90
100
|
// 1. Find the caller's membership for this company.
|
|
91
101
|
const memberships = await vaultClient.listMyMemberships();
|
|
92
102
|
// Resolve slug → uid via entity.get on each membership's companyUid in
|