@indigoai-us/hq-cloud 6.15.0 → 6.15.2
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/dist/bin/sync-mutation.d.ts +16 -0
- package/dist/bin/sync-mutation.d.ts.map +1 -0
- package/dist/bin/sync-mutation.js +60 -0
- package/dist/bin/sync-mutation.js.map +1 -0
- package/dist/bin/sync-mutation.test.d.ts +2 -0
- package/dist/bin/sync-mutation.test.d.ts.map +1 -0
- package/dist/bin/sync-mutation.test.js +165 -0
- package/dist/bin/sync-mutation.test.js.map +1 -0
- package/dist/bin/sync-runner-company.d.ts +8 -0
- package/dist/bin/sync-runner-company.d.ts.map +1 -1
- package/dist/bin/sync-runner-company.js +16 -0
- package/dist/bin/sync-runner-company.js.map +1 -1
- package/dist/bin/sync-runner-company.test.d.ts +2 -0
- package/dist/bin/sync-runner-company.test.d.ts.map +1 -0
- package/dist/bin/sync-runner-company.test.js +36 -0
- package/dist/bin/sync-runner-company.test.js.map +1 -0
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +98 -8
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner.d.ts +17 -0
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +109 -0
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/conflict-recovery.test.d.ts +2 -0
- package/dist/cli/conflict-recovery.test.d.ts.map +1 -0
- package/dist/cli/conflict-recovery.test.js +201 -0
- package/dist/cli/conflict-recovery.test.js.map +1 -0
- package/dist/cli/conflict.d.ts +60 -0
- package/dist/cli/conflict.d.ts.map +1 -1
- package/dist/cli/conflict.js +333 -0
- package/dist/cli/conflict.js.map +1 -1
- package/dist/cli/sync.d.ts +35 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +100 -0
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/sync.test.js +85 -1
- package/dist/cli/sync.test.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/skill-telemetry.d.ts +6 -0
- package/dist/skill-telemetry.d.ts.map +1 -1
- package/dist/skill-telemetry.js +14 -2
- package/dist/skill-telemetry.js.map +1 -1
- package/dist/skill-telemetry.test.js +79 -0
- package/dist/skill-telemetry.test.js.map +1 -1
- package/dist/sync/candidate-uploader.d.ts +88 -0
- package/dist/sync/candidate-uploader.d.ts.map +1 -0
- package/dist/sync/candidate-uploader.js +212 -0
- package/dist/sync/candidate-uploader.js.map +1 -0
- package/dist/sync/candidate-uploader.test.d.ts +2 -0
- package/dist/sync/candidate-uploader.test.d.ts.map +1 -0
- package/dist/sync/candidate-uploader.test.js +132 -0
- package/dist/sync/candidate-uploader.test.js.map +1 -0
- package/dist/sync/delta-client.d.ts +73 -0
- package/dist/sync/delta-client.d.ts.map +1 -0
- package/dist/sync/delta-client.js +201 -0
- package/dist/sync/delta-client.js.map +1 -0
- package/dist/sync/delta-client.test.d.ts +2 -0
- package/dist/sync/delta-client.test.d.ts.map +1 -0
- package/dist/sync/delta-client.test.js +97 -0
- package/dist/sync/delta-client.test.js.map +1 -0
- package/dist/sync/durable-apply.d.ts +76 -0
- package/dist/sync/durable-apply.d.ts.map +1 -0
- package/dist/sync/durable-apply.js +530 -0
- package/dist/sync/durable-apply.js.map +1 -0
- package/dist/sync/durable-apply.test.d.ts +2 -0
- package/dist/sync/durable-apply.test.d.ts.map +1 -0
- package/dist/sync/durable-apply.test.js +180 -0
- package/dist/sync/durable-apply.test.js.map +1 -0
- package/dist/sync/event-sync.d.ts +33 -1
- package/dist/sync/event-sync.d.ts.map +1 -1
- package/dist/sync/event-sync.js +149 -1
- package/dist/sync/event-sync.js.map +1 -1
- package/dist/sync/event-sync.test.js +142 -1
- package/dist/sync/event-sync.test.js.map +1 -1
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +1 -0
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/multipart-uploader.d.ts +99 -0
- package/dist/sync/multipart-uploader.d.ts.map +1 -0
- package/dist/sync/multipart-uploader.js +447 -0
- package/dist/sync/multipart-uploader.js.map +1 -0
- package/dist/sync/multipart-uploader.test.d.ts +2 -0
- package/dist/sync/multipart-uploader.test.d.ts.map +1 -0
- package/dist/sync/multipart-uploader.test.js +119 -0
- package/dist/sync/multipart-uploader.test.js.map +1 -0
- package/dist/sync/mutation-client.d.ts +85 -0
- package/dist/sync/mutation-client.d.ts.map +1 -0
- package/dist/sync/mutation-client.js +245 -0
- package/dist/sync/mutation-client.js.map +1 -0
- package/dist/sync/mutation-client.test.d.ts +2 -0
- package/dist/sync/mutation-client.test.d.ts.map +1 -0
- package/dist/sync/mutation-client.test.js +51 -0
- package/dist/sync/mutation-client.test.js.map +1 -0
- package/dist/sync/push-receiver.d.ts +45 -0
- package/dist/sync/push-receiver.d.ts.map +1 -1
- package/dist/sync/push-receiver.js +101 -0
- package/dist/sync/push-receiver.js.map +1 -1
- package/dist/sync/push-receiver.test.js +54 -2
- package/dist/sync/push-receiver.test.js.map +1 -1
- package/dist/sync/scope-inventory-client.d.ts +69 -0
- package/dist/sync/scope-inventory-client.d.ts.map +1 -0
- package/dist/sync/scope-inventory-client.js +210 -0
- package/dist/sync/scope-inventory-client.js.map +1 -0
- package/dist/sync/scope-inventory-client.test.d.ts +2 -0
- package/dist/sync/scope-inventory-client.test.d.ts.map +1 -0
- package/dist/sync/scope-inventory-client.test.js +94 -0
- package/dist/sync/scope-inventory-client.test.js.map +1 -0
- package/dist/sync/snapshot-client.d.ts +98 -0
- package/dist/sync/snapshot-client.d.ts.map +1 -0
- package/dist/sync/snapshot-client.js +402 -0
- package/dist/sync/snapshot-client.js.map +1 -0
- package/dist/sync/snapshot-client.test.d.ts +2 -0
- package/dist/sync/snapshot-client.test.d.ts.map +1 -0
- package/dist/sync/snapshot-client.test.js +169 -0
- package/dist/sync/snapshot-client.test.js.map +1 -0
- package/dist/sync/uploader-finalization.d.ts +97 -0
- package/dist/sync/uploader-finalization.d.ts.map +1 -0
- package/dist/sync/uploader-finalization.js +273 -0
- package/dist/sync/uploader-finalization.js.map +1 -0
- package/dist/sync/uploader-finalization.test.d.ts +2 -0
- package/dist/sync/uploader-finalization.test.d.ts.map +1 -0
- package/dist/sync/uploader-finalization.test.js +92 -0
- package/dist/sync/uploader-finalization.test.js.map +1 -0
- package/dist/telemetry.d.ts +11 -1
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +21 -2
- package/dist/telemetry.js.map +1 -1
- package/dist/telemetry.test.js +80 -0
- package/dist/telemetry.test.js.map +1 -1
- package/package.json +6 -1
- package/.claude/policies/hq-cloud-esm-cannot-spy-fs-builtins.md +0 -30
- package/.claude/policies/hq-cloud-strip-types-no-parameter-properties.md +0 -22
- package/.github/workflows/ci.yml +0 -84
- package/.github/workflows/publish.yml +0 -56
- package/.github/workflows/unreleased-commits-nag.yml +0 -256
- package/eslint.config.js +0 -67
- package/pnpm-workspace.yaml +0 -2
- package/scripts/presign-transport-e2e.mjs +0 -250
- package/scripts/vault-rebaseline.sh +0 -323
- package/scripts/vault-rescue.sh +0 -332
- package/src/active-company.test.ts +0 -188
- package/src/active-company.ts +0 -168
- package/src/agent-codex-instructions.test.ts +0 -332
- package/src/agent-codex-instructions.ts +0 -309
- package/src/auth.ts +0 -146
- package/src/backup-prune.test.ts +0 -98
- package/src/backup-prune.ts +0 -182
- package/src/bin/backup-prune-runner.ts +0 -33
- package/src/bin/rescue-runner.ts +0 -25
- package/src/bin/sync-runner-company.ts +0 -695
- package/src/bin/sync-runner-events.test.ts +0 -143
- package/src/bin/sync-runner-events.ts +0 -55
- package/src/bin/sync-runner-planning.test.ts +0 -311
- package/src/bin/sync-runner-planning.ts +0 -258
- package/src/bin/sync-runner-rollup.test.ts +0 -37
- package/src/bin/sync-runner-rollup.ts +0 -97
- package/src/bin/sync-runner-telemetry.ts +0 -15
- package/src/bin/sync-runner-watch-loop.ts +0 -1235
- package/src/bin/sync-runner-watch-routes.test.ts +0 -71
- package/src/bin/sync-runner-watch-routes.ts +0 -184
- package/src/bin/sync-runner.test.ts +0 -8767
- package/src/bin/sync-runner.ts +0 -2190
- package/src/cli/accept.ts +0 -124
- package/src/cli/conflict.ts +0 -119
- package/src/cli/doctor.test.ts +0 -581
- package/src/cli/doctor.ts +0 -642
- package/src/cli/index.ts +0 -49
- package/src/cli/invite.test.ts +0 -250
- package/src/cli/invite.ts +0 -214
- package/src/cli/promote.ts +0 -157
- package/src/cli/reindex-knowledge.test.ts +0 -307
- package/src/cli/reindex-knowledge.ts +0 -450
- package/src/cli/reindex.test.ts +0 -957
- package/src/cli/reindex.ts +0 -979
- package/src/cli/rescue-classify-ordering.test.ts +0 -548
- package/src/cli/rescue-clone-diagnostics.test.ts +0 -120
- package/src/cli/rescue-core.ts +0 -3011
- package/src/cli/rescue-drift-reconcile.test.ts +0 -179
- package/src/cli/rescue-drop-dir-symlink.test.ts +0 -224
- package/src/cli/rescue-exec-bit-preserve.test.ts +0 -187
- package/src/cli/rescue-hq-root-guard.test.ts +0 -232
- package/src/cli/rescue-journal-reconcile.test.ts +0 -215
- package/src/cli/rescue-mtime-preserve.test.ts +0 -203
- package/src/cli/rescue-settings-reconcile.test.ts +0 -637
- package/src/cli/rescue-snapshot.test.ts +0 -57
- package/src/cli/rescue-snapshot.ts +0 -51
- package/src/cli/rescue.reindex.test.ts +0 -63
- package/src/cli/rescue.test.ts +0 -131
- package/src/cli/rescue.ts +0 -182
- package/src/cli/share.test.ts +0 -7843
- package/src/cli/share.ts +0 -3663
- package/src/cli/sync-scope.test.ts +0 -652
- package/src/cli/sync.test.ts +0 -5207
- package/src/cli/sync.ts +0 -3470
- package/src/cli/tombstones.ts +0 -106
- package/src/cli/watch-event-push-conflict.test.ts +0 -234
- package/src/client-info.test.ts +0 -214
- package/src/client-info.ts +0 -121
- package/src/cognito-auth.test.ts +0 -712
- package/src/cognito-auth.ts +0 -1422
- package/src/company-resolver.test.ts +0 -618
- package/src/company-resolver.ts +0 -521
- package/src/context.test.ts +0 -583
- package/src/context.ts +0 -378
- package/src/daemon-worker.ts +0 -26
- package/src/daemon.ts +0 -99
- package/src/entity-resolver.test.ts +0 -315
- package/src/entity-resolver.ts +0 -180
- package/src/ignore.test.ts +0 -466
- package/src/ignore.ts +0 -469
- package/src/index.ts +0 -439
- package/src/journal.test.ts +0 -968
- package/src/journal.ts +0 -765
- package/src/lib/cloud-authoritative.test.ts +0 -45
- package/src/lib/cloud-authoritative.ts +0 -59
- package/src/lib/conflict-file.ts +0 -86
- package/src/lib/conflict-index.ts +0 -289
- package/src/lib/conflict.test.ts +0 -348
- package/src/lib/describe-error.test.ts +0 -100
- package/src/lib/describe-error.ts +0 -58
- package/src/lib/exit-codes.ts +0 -24
- package/src/lib/machine-id.test.ts +0 -231
- package/src/lib/machine-id.ts +0 -175
- package/src/lib/net-errors.test.ts +0 -65
- package/src/lib/net-errors.ts +0 -86
- package/src/lib/readlink-safe.test.ts +0 -43
- package/src/lib/readlink-safe.ts +0 -29
- package/src/local-path-codec.test.ts +0 -138
- package/src/local-path-codec.ts +0 -161
- package/src/machine-auth.test.ts +0 -1323
- package/src/manifest-reconcile.test.ts +0 -1123
- package/src/manifest-reconcile.ts +0 -518
- package/src/object-io.test.ts +0 -1221
- package/src/object-io.ts +0 -1306
- package/src/operation-lock.test.ts +0 -484
- package/src/operation-lock.ts +0 -680
- package/src/outcome-telemetry.test.ts +0 -498
- package/src/outcome-telemetry.ts +0 -639
- package/src/personal-vault-exclusions.test.ts +0 -308
- package/src/personal-vault-exclusions.ts +0 -354
- package/src/personal-vault.test.ts +0 -756
- package/src/personal-vault.ts +0 -496
- package/src/prefix-coalesce.test.ts +0 -240
- package/src/prefix-coalesce.ts +0 -273
- package/src/public-surface.test.ts +0 -117
- package/src/qmd-reindex.test.ts +0 -877
- package/src/qmd-reindex.ts +0 -842
- package/src/read-only-state-dir.test.ts +0 -188
- package/src/remote-pull.test.ts +0 -1130
- package/src/remote-pull.ts +0 -618
- package/src/s3.symlink-materialize.test.ts +0 -492
- package/src/s3.test.ts +0 -1789
- package/src/s3.ts +0 -1532
- package/src/schemas/signal-types.test.ts +0 -82
- package/src/schemas/signal-types.ts +0 -38
- package/src/schemas/source-channels.test.ts +0 -82
- package/src/schemas/source-channels.ts +0 -53
- package/src/scope-shrink.test.ts +0 -633
- package/src/scope-shrink.ts +0 -481
- package/src/signals/get.test.ts +0 -310
- package/src/signals/get.ts +0 -75
- package/src/signals/internals.ts +0 -195
- package/src/signals/list.test.ts +0 -420
- package/src/signals/list.ts +0 -79
- package/src/signals/parse.ts +0 -8
- package/src/signals/types.ts +0 -91
- package/src/skill-telemetry.test.ts +0 -1825
- package/src/skill-telemetry.ts +0 -1439
- package/src/sources/get.test.ts +0 -293
- package/src/sources/get.ts +0 -66
- package/src/sources/internals.ts +0 -198
- package/src/sources/list.test.ts +0 -402
- package/src/sources/list.ts +0 -84
- package/src/sources/parse.ts +0 -43
- package/src/sources/types.ts +0 -84
- package/src/sync/event-sync.test.ts +0 -594
- package/src/sync/event-sync.ts +0 -545
- package/src/sync/feature-flags.test.ts +0 -378
- package/src/sync/feature-flags.ts +0 -62
- package/src/sync/index.ts +0 -76
- package/src/sync/lease-client.test.ts +0 -128
- package/src/sync/lease-client.ts +0 -207
- package/src/sync/logger.test.ts +0 -242
- package/src/sync/logger.ts +0 -79
- package/src/sync/metrics.test.ts +0 -462
- package/src/sync/metrics.ts +0 -213
- package/src/sync/pull-scope.ts +0 -265
- package/src/sync/push-event.test.ts +0 -266
- package/src/sync/push-event.ts +0 -224
- package/src/sync/push-receiver.test.ts +0 -566
- package/src/sync/push-receiver.ts +0 -1048
- package/src/sync/push-transport.ts +0 -231
- package/src/sync/realtime-rollout.test.ts +0 -86
- package/src/sync/realtime-rollout.ts +0 -262
- package/src/sync/state-store.test.ts +0 -194
- package/src/sync/state-store.ts +0 -727
- package/src/sync-core.ts +0 -58
- package/src/sync-progress.test.ts +0 -94
- package/src/sync-progress.ts +0 -140
- package/src/telemetry-events.test.ts +0 -88
- package/src/telemetry-events.ts +0 -205
- package/src/telemetry.test.ts +0 -1280
- package/src/telemetry.ts +0 -1109
- package/src/types.ts +0 -314
- package/src/vault-client.test.ts +0 -1380
- package/src/vault-client.ts +0 -1694
- package/src/version.ts +0 -24
- package/src/watch-roots.test.ts +0 -278
- package/src/watch-roots.ts +0 -162
- package/src/watcher-event-gate.test.ts +0 -212
- package/src/watcher.test.ts +0 -1079
- package/src/watcher.ts +0 -1741
- package/test/e2e/sync/cross-tenant-isolation.test.ts +0 -630
- package/test/e2e/sync/skill-telemetry-oversized-transcript.test.ts +0 -124
- package/test/e2e/sync/transient-company-leg.test.ts +0 -384
- package/test/e2e/sync/windows-unreadable-link-leg.test.ts +0 -191
- package/test/e2e/watcher-real-chokidar.test.ts +0 -165
- package/test/e2e/watcher-recursive-backend.test.ts +0 -181
- package/test/e2e/watcher-scoped-coverage.test.ts +0 -381
- package/test/invite-flow.integration.test.ts +0 -244
- package/test/joiner-manifest-reconcile.integration.test.ts +0 -322
- package/test/share-sync.integration.test.ts +0 -213
- package/tsconfig.json +0 -19
- package/vitest.config.ts +0 -22
package/src/cli/doctor.ts
DELETED
|
@@ -1,642 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `hq sync doctor` — bounded skill-key dedupe + local farm GC (US-003,
|
|
3
|
-
* hq-sync-windows-skill-symlink-collision).
|
|
4
|
-
*
|
|
5
|
-
* The mixed-version amplifier (see `canonicalVaultKeySpelling` in
|
|
6
|
-
* local-path-codec.ts) leaves the vault holding several percent-encoded
|
|
7
|
-
* GENERATIONS of every `.claude/skills/<ns>:<skill>` wrapper key (`:`, `%3A`,
|
|
8
|
-
* `%253A`, `%25253A`, …) and the local farm holding junk-named wrapper dirs.
|
|
9
|
-
* US-001/US-002 stop NEW generations from being minted; this doctor is the
|
|
10
|
-
* one-shot reconcile that collapses the families already in the wild:
|
|
11
|
-
*
|
|
12
|
-
* 1. Vault dedupe — list keys under `.claude/skills/`, group them by their
|
|
13
|
-
* decode-to-fixpoint canonical form, let the newest-bodied spelling win,
|
|
14
|
-
* (re)write the canonical `:` key when it is missing or stale, and delete
|
|
15
|
-
* every non-canonical spelling. Deletion is gated hard: only bodies that
|
|
16
|
-
* start with the `hq-symlink:` marker, or that are byte-identical to the
|
|
17
|
-
* canonical twin, are auto-deleted — anything else is surfaced for manual
|
|
18
|
-
* review, never silently removed.
|
|
19
|
-
* 2. Local farm GC — remove `.claude/skills/` entries whose names decode to
|
|
20
|
-
* a canonical wrapper that already exists on disk and whose content is
|
|
21
|
-
* exclusively symlink-farm material. A real file anywhere is a refusal.
|
|
22
|
-
*
|
|
23
|
-
* Dry-run is the DEFAULT: the full keep/rewrite/tombstone/rm plan is printed
|
|
24
|
-
* (counts + every key/path) and nothing is written until `--yes`
|
|
25
|
-
* (`options.yes`). Remote deletes respect the sync-delete-bulk-asymmetry-guard
|
|
26
|
-
* policy — same thresholds, env override, and refusal semantics as
|
|
27
|
-
* `computeDeletePlan` in share.ts. Per-item failures are loud warnings, never
|
|
28
|
-
* process-fatal (hq-sync-deliberate-skip-not-fatal-error-exit2).
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
import * as fs from "fs";
|
|
32
|
-
import * as path from "path";
|
|
33
|
-
import { resolveEntityContext } from "../context.js";
|
|
34
|
-
import { resolveObjectIO, type ObjectIO } from "../object-io.js";
|
|
35
|
-
import type { ListedRemoteObject } from "../object-io.js";
|
|
36
|
-
import { SYMLINK_BODY_PREFIX } from "../s3.js";
|
|
37
|
-
import {
|
|
38
|
-
canonicalVaultKeySpelling,
|
|
39
|
-
canonicalVaultSegmentSpelling,
|
|
40
|
-
encodeLocalVaultSegment,
|
|
41
|
-
} from "../local-path-codec.js";
|
|
42
|
-
import { withOperationLock } from "../operation-lock.js";
|
|
43
|
-
import type { VaultServiceConfig } from "../types.js";
|
|
44
|
-
|
|
45
|
-
/** Vault prefix the doctor is bounded to — the skill wrapper link farm. */
|
|
46
|
-
export const SKILLS_KEY_PREFIX = ".claude/skills/";
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Bulk-asymmetry circuit-breaker, per the sync-delete-bulk-asymmetry-guard
|
|
50
|
-
* policy: any new delete-propagation site must ship the guard inline with the
|
|
51
|
-
* SAME threshold defaults and env-var name as the reference implementation
|
|
52
|
-
* (share.ts `BULK_ASYMMETRY_*` + `isBulkAsymmetryOverride`). Here the
|
|
53
|
-
* numerator is the planned tombstone count and the denominator is every
|
|
54
|
-
* in-scope `.claude/skills/` key — a dedupe pass that wants to delete a large
|
|
55
|
-
* slice of the farm at once must be explicitly confirmed, because that shape
|
|
56
|
-
* is indistinguishable from a planner bug eating the vault.
|
|
57
|
-
*/
|
|
58
|
-
const BULK_ASYMMETRY_RATIO = 0.10;
|
|
59
|
-
const BULK_ASYMMETRY_MIN_ABS = 10;
|
|
60
|
-
|
|
61
|
-
function isBulkDeleteOverride(explicit: boolean | undefined): boolean {
|
|
62
|
-
if (explicit) return true;
|
|
63
|
-
const v = (process.env.HQ_SYNC_DELETE_BULK_OVERRIDE ?? "").toLowerCase();
|
|
64
|
-
return v === "1" || v === "true" || v === "yes";
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The narrow object-store seam the doctor needs. Structurally satisfied by
|
|
69
|
-
* every `ObjectIO` transport; tests inject an in-memory fake (the same
|
|
70
|
-
* dependency-injection convention the s3.ts suites use via
|
|
71
|
-
* `setObjectIOFactory`).
|
|
72
|
-
*/
|
|
73
|
-
export type DoctorStore = Pick<
|
|
74
|
-
ObjectIO,
|
|
75
|
-
"listObjects" | "getObject" | "putObject" | "deleteObject"
|
|
76
|
-
>;
|
|
77
|
-
|
|
78
|
-
export interface SyncDoctorOptions {
|
|
79
|
-
/** Entity whose vault to reconcile (prs_/agt_ uid, cmp_ uid, or slug). */
|
|
80
|
-
entity: string;
|
|
81
|
-
/** Vault service config (auth + region), as for `sync()`/`share()`. */
|
|
82
|
-
vaultConfig: VaultServiceConfig;
|
|
83
|
-
/** HQ root whose local `.claude/skills/` farm the GC pass walks. */
|
|
84
|
-
hqRoot: string;
|
|
85
|
-
/** Apply the plan. Default false = dry-run: print the plan, write nothing. */
|
|
86
|
-
yes?: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Explicit bulk-delete override (the `--force-bulk` CLI flag). Equivalent to
|
|
89
|
-
* `HQ_SYNC_DELETE_BULK_OVERRIDE=1`; without either, a tombstone plan that
|
|
90
|
-
* trips the asymmetry thresholds is refused (writes and local GC still run).
|
|
91
|
-
*/
|
|
92
|
-
bulkDeleteOverride?: boolean;
|
|
93
|
-
/** DI seam for tests; defaults to the entity's resolved ObjectIO. */
|
|
94
|
-
store?: DoctorStore;
|
|
95
|
-
/**
|
|
96
|
-
* Platform override for local farm-name encoding (local-path-codec
|
|
97
|
-
* convention). Decode-to-fixpoint always uses win32 semantics — junk
|
|
98
|
-
* spellings are a key-space phenomenon, not a host one — but the canonical
|
|
99
|
-
* LOCAL wrapper name a junk dir must collapse into is host-specific
|
|
100
|
-
* (`ns%3Askill` on win32, `ns:skill` on POSIX).
|
|
101
|
-
*/
|
|
102
|
-
win32?: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* The doctor takes the same per-root operation lock as `sync()`. Set when a
|
|
105
|
-
* caller (runner/daemon) already holds it for this root.
|
|
106
|
-
*/
|
|
107
|
-
operationLockAlreadyHeld?: boolean;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** One canonical key the doctor will (re)write, and the spelling it copies. */
|
|
111
|
-
export interface SkillKeyRewrite {
|
|
112
|
-
key: string;
|
|
113
|
-
/** Winning (newest-bodied) spelling whose body becomes the canonical body. */
|
|
114
|
-
fromSpelling: string;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export interface DoctorManualReviewItem {
|
|
118
|
-
key: string;
|
|
119
|
-
reason: string;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface LocalGcManualReviewItem {
|
|
123
|
-
path: string;
|
|
124
|
-
reason: string;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export interface SyncDoctorPlan {
|
|
128
|
-
/** Every listed `.claude/skills/` key (the bulk-guard denominator). */
|
|
129
|
-
inScopeKeys: number;
|
|
130
|
-
/** Canonical-spelling keys that need no action. */
|
|
131
|
-
keep: string[];
|
|
132
|
-
/** Canonical keys to (re)write from their winning spelling's body. */
|
|
133
|
-
rewrites: SkillKeyRewrite[];
|
|
134
|
-
/** Non-canonical spellings safe to delete (marker body or byte-identical). */
|
|
135
|
-
tombstones: string[];
|
|
136
|
-
/** Keys the safety gate refused to auto-delete — surfaced, never removed. */
|
|
137
|
-
manualReview: DoctorManualReviewItem[];
|
|
138
|
-
/** Junk-named local farm entries (symlink-farm content only) to remove. */
|
|
139
|
-
localRemovals: string[];
|
|
140
|
-
/** Junk-named local entries the GC refused to touch — surfaced only. */
|
|
141
|
-
localManualReview: LocalGcManualReviewItem[];
|
|
142
|
-
/** True when the tombstone plan tripped the bulk-asymmetry breaker. */
|
|
143
|
-
bulkRefused: boolean;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export interface SyncDoctorResult {
|
|
147
|
-
plan: SyncDoctorPlan;
|
|
148
|
-
/** False on dry-run (the default) and when `--yes` was absent. */
|
|
149
|
-
applied: boolean;
|
|
150
|
-
keysRewritten: number;
|
|
151
|
-
keysDeleted: number;
|
|
152
|
-
dirsRemoved: number;
|
|
153
|
-
/** Loud non-fatal warnings emitted during plan + apply. */
|
|
154
|
-
warnings: number;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** A group member whose body was fetched for winner selection / gating. */
|
|
158
|
-
interface FetchedSpelling {
|
|
159
|
-
key: string;
|
|
160
|
-
lastModified: Date;
|
|
161
|
-
body: Buffer;
|
|
162
|
-
metadata?: Record<string, string>;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** Payload for one canonical-key rewrite, staged at plan time. */
|
|
166
|
-
interface RewritePayload {
|
|
167
|
-
key: string;
|
|
168
|
-
body: Buffer;
|
|
169
|
-
metadata?: Record<string, string>;
|
|
170
|
-
/** CAS fence: canonical key was listed with this ETag. */
|
|
171
|
-
ifMatch?: string;
|
|
172
|
-
/** CAS fence: canonical key was absent at list time. */
|
|
173
|
-
ifNoneMatch?: "*";
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function isSymlinkMarkerBody(body: Buffer): boolean {
|
|
177
|
-
return (
|
|
178
|
-
body.subarray(0, SYMLINK_BODY_PREFIX.length).toString("utf-8") ===
|
|
179
|
-
SYMLINK_BODY_PREFIX
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/** Exhaustively page the skills prefix (the transport caps pages at ~1000). */
|
|
184
|
-
async function listSkillObjects(
|
|
185
|
-
store: DoctorStore,
|
|
186
|
-
): Promise<ListedRemoteObject[]> {
|
|
187
|
-
const objects: ListedRemoteObject[] = [];
|
|
188
|
-
let continuationToken: string | undefined;
|
|
189
|
-
do {
|
|
190
|
-
const page = await store.listObjects({
|
|
191
|
-
prefix: SKILLS_KEY_PREFIX,
|
|
192
|
-
continuationToken,
|
|
193
|
-
});
|
|
194
|
-
for (const object of page.objects) {
|
|
195
|
-
objects.push(object);
|
|
196
|
-
}
|
|
197
|
-
continuationToken = page.nextContinuationToken;
|
|
198
|
-
} while (continuationToken);
|
|
199
|
-
return objects;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Winner ordering: newest lastModified first ("newest-bodied spelling wins");
|
|
204
|
-
* ties prefer the canonical spelling, then the lexicographically smallest key
|
|
205
|
-
* so the plan is deterministic under equal timestamps.
|
|
206
|
-
*/
|
|
207
|
-
function pickWinner(
|
|
208
|
-
members: FetchedSpelling[],
|
|
209
|
-
canonicalKey: string,
|
|
210
|
-
): FetchedSpelling {
|
|
211
|
-
return members.reduce((best, m) => {
|
|
212
|
-
if (m.lastModified.getTime() !== best.lastModified.getTime()) {
|
|
213
|
-
return m.lastModified.getTime() > best.lastModified.getTime() ? m : best;
|
|
214
|
-
}
|
|
215
|
-
if ((m.key === canonicalKey) !== (best.key === canonicalKey)) {
|
|
216
|
-
return m.key === canonicalKey ? m : best;
|
|
217
|
-
}
|
|
218
|
-
return m.key < best.key ? m : best;
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* True when every entry under `dir` (recursively) is symlink-farm material:
|
|
224
|
-
* symlinks, or directories that themselves contain only symlink-farm
|
|
225
|
-
* material. Any regular file — or anything that is neither a symlink nor a
|
|
226
|
-
* directory (fifo, socket) — makes the tree untouchable.
|
|
227
|
-
*/
|
|
228
|
-
function containsOnlySymlinkFarmContent(dir: string): boolean {
|
|
229
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
230
|
-
for (const entry of entries) {
|
|
231
|
-
if (entry.isSymbolicLink()) continue;
|
|
232
|
-
if (entry.isDirectory()) {
|
|
233
|
-
if (!containsOnlySymlinkFarmContent(path.join(dir, entry.name))) {
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
return true;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/** lstat-based existence probe — a broken symlink wrapper still "exists". */
|
|
244
|
-
function entryExists(p: string): boolean {
|
|
245
|
-
try {
|
|
246
|
-
fs.lstatSync(p);
|
|
247
|
-
return true;
|
|
248
|
-
} catch {
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Plan the local `.claude/skills/` farm GC. Pure planning — no removal here.
|
|
255
|
-
* An entry qualifies when its name percent-decodes (to fixpoint) to a
|
|
256
|
-
* canonical wrapper name DIFFERENT from its own spelling, that canonical
|
|
257
|
-
* wrapper already exists on disk, and the entry is a symlink or a directory
|
|
258
|
-
* of exclusively symlink-farm content. Everything else that is junk-named is
|
|
259
|
-
* listed for manual review with the reason it was refused.
|
|
260
|
-
*/
|
|
261
|
-
function planLocalSkillFarmGc(
|
|
262
|
-
skillsDir: string,
|
|
263
|
-
win32: boolean,
|
|
264
|
-
warn: (message: string) => void,
|
|
265
|
-
): { removals: string[]; manualReview: LocalGcManualReviewItem[] } {
|
|
266
|
-
const removals: string[] = [];
|
|
267
|
-
const manualReview: LocalGcManualReviewItem[] = [];
|
|
268
|
-
if (!entryExists(skillsDir)) return { removals, manualReview };
|
|
269
|
-
|
|
270
|
-
let entries: fs.Dirent[];
|
|
271
|
-
try {
|
|
272
|
-
entries = fs.readdirSync(skillsDir, { withFileTypes: true });
|
|
273
|
-
} catch (err) {
|
|
274
|
-
warn(`local GC skipped — cannot read ${skillsDir}: ${String(err)}`);
|
|
275
|
-
return { removals, manualReview };
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
for (const entry of entries) {
|
|
279
|
-
// Fixpoint-decode the name (win32 key-space semantics unconditionally —
|
|
280
|
-
// a mac's literal `ns%3Askill` junk dir is junk too), then re-encode for
|
|
281
|
-
// THIS host to get the canonical local wrapper spelling.
|
|
282
|
-
const canonicalName = canonicalVaultSegmentSpelling(entry.name);
|
|
283
|
-
// A no-op canonicalization means this name is NOT an amplifier
|
|
284
|
-
// generation: generated wrapper generations always decode back to a
|
|
285
|
-
// `<ns>:<skill>` name, and canonicalVaultSegmentSpelling deliberately
|
|
286
|
-
// returns colon-free names unchanged (`foo%25bar` is a legitimate
|
|
287
|
-
// wrapper for the canonical skill name `foo%bar`, distinct from a
|
|
288
|
-
// literal `foo%bar` dir). Encoding such a name for the host would
|
|
289
|
-
// re-escape it into a different spelling (`foo%2525bar` on win32) and,
|
|
290
|
-
// if that double-encoded sibling happens to exist, `--yes` would delete
|
|
291
|
-
// the legitimate wrapper. Bail before the host encode — the amplifier
|
|
292
|
-
// family this GC exists to collapse always changes spelling here.
|
|
293
|
-
if (canonicalName === entry.name) continue;
|
|
294
|
-
const canonicalLocalName = encodeLocalVaultSegment(canonicalName, win32);
|
|
295
|
-
if (entry.name === canonicalLocalName) continue; // already canonical
|
|
296
|
-
|
|
297
|
-
const fullPath = path.join(skillsDir, entry.name);
|
|
298
|
-
if (!entryExists(path.join(skillsDir, canonicalLocalName))) {
|
|
299
|
-
manualReview.push({
|
|
300
|
-
path: fullPath,
|
|
301
|
-
reason: `canonical wrapper '${canonicalLocalName}' missing on disk — junk-named entry may be the only copy`,
|
|
302
|
-
});
|
|
303
|
-
continue;
|
|
304
|
-
}
|
|
305
|
-
if (entry.isSymbolicLink()) {
|
|
306
|
-
removals.push(fullPath);
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
if (entry.isDirectory()) {
|
|
310
|
-
let farmOnly = false;
|
|
311
|
-
try {
|
|
312
|
-
farmOnly = containsOnlySymlinkFarmContent(fullPath);
|
|
313
|
-
} catch (err) {
|
|
314
|
-
warn(`local GC cannot inspect ${fullPath}: ${String(err)}`);
|
|
315
|
-
manualReview.push({ path: fullPath, reason: "unreadable — not inspected" });
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
if (farmOnly) {
|
|
319
|
-
removals.push(fullPath);
|
|
320
|
-
} else {
|
|
321
|
-
manualReview.push({
|
|
322
|
-
path: fullPath,
|
|
323
|
-
reason: "contains real (non-symlink) files — never auto-deleted",
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
manualReview.push({
|
|
329
|
-
path: fullPath,
|
|
330
|
-
reason: "junk-named regular file — never auto-deleted",
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
return { removals, manualReview };
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/** Remove one farm entry: unlink symlinks (rmdir for win32 dir links), rm dirs. */
|
|
337
|
-
function removeFarmEntry(fullPath: string): void {
|
|
338
|
-
const st = fs.lstatSync(fullPath);
|
|
339
|
-
if (st.isSymbolicLink()) {
|
|
340
|
-
try {
|
|
341
|
-
fs.unlinkSync(fullPath);
|
|
342
|
-
} catch (err) {
|
|
343
|
-
const code = (err as NodeJS.ErrnoException).code;
|
|
344
|
-
// A Windows directory symlink is a directory reparse point; unlink()
|
|
345
|
-
// refuses it (EPERM/EISDIR) and rmdir removes the LINK, not the target.
|
|
346
|
-
if (code === "EPERM" || code === "EISDIR") {
|
|
347
|
-
fs.rmdirSync(fullPath);
|
|
348
|
-
} else {
|
|
349
|
-
throw err;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
fs.rmSync(fullPath, { recursive: true });
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Run the doctor: build the dedupe + GC plan, print it in full, and — only
|
|
359
|
-
* with `yes: true` — apply it. See the module doc for semantics.
|
|
360
|
-
*/
|
|
361
|
-
export async function syncDoctor(
|
|
362
|
-
options: SyncDoctorOptions,
|
|
363
|
-
): Promise<SyncDoctorResult> {
|
|
364
|
-
if (options.operationLockAlreadyHeld) {
|
|
365
|
-
return syncDoctorWithOperationLockHeld(options);
|
|
366
|
-
}
|
|
367
|
-
return withOperationLock(options.hqRoot, "sync-doctor", () =>
|
|
368
|
-
syncDoctorWithOperationLockHeld(options),
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
async function syncDoctorWithOperationLockHeld(
|
|
373
|
-
options: SyncDoctorOptions,
|
|
374
|
-
): Promise<SyncDoctorResult> {
|
|
375
|
-
let warnings = 0;
|
|
376
|
-
const warn = (message: string): void => {
|
|
377
|
-
warnings++;
|
|
378
|
-
console.error(` ! ${message}`);
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
const win32 = options.win32 ?? process.platform === "win32";
|
|
382
|
-
const store =
|
|
383
|
-
options.store ??
|
|
384
|
-
resolveObjectIO(
|
|
385
|
-
await resolveEntityContext(options.entity, options.vaultConfig),
|
|
386
|
-
);
|
|
387
|
-
|
|
388
|
-
// ── Vault leg: plan ────────────────────────────────────────────────────────
|
|
389
|
-
const listed = await listSkillObjects(store);
|
|
390
|
-
const groups = new Map<string, ListedRemoteObject[]>();
|
|
391
|
-
for (const obj of listed) {
|
|
392
|
-
const canonicalKey = canonicalVaultKeySpelling(obj.key);
|
|
393
|
-
const members = groups.get(canonicalKey);
|
|
394
|
-
if (members) {
|
|
395
|
-
members.push(obj);
|
|
396
|
-
} else {
|
|
397
|
-
groups.set(canonicalKey, [obj]);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
const keep: string[] = [];
|
|
402
|
-
const rewrites: SkillKeyRewrite[] = [];
|
|
403
|
-
const rewritePayloads: RewritePayload[] = [];
|
|
404
|
-
const tombstones: string[] = [];
|
|
405
|
-
const manualReview: DoctorManualReviewItem[] = [];
|
|
406
|
-
|
|
407
|
-
for (const [canonicalKey, members] of groups) {
|
|
408
|
-
// Fast path: one spelling and it is already canonical — nothing to do,
|
|
409
|
-
// and no body fetch (the common case must stay O(list), not O(get)).
|
|
410
|
-
if (members.length === 1 && members[0]!.key === canonicalKey) {
|
|
411
|
-
keep.push(canonicalKey);
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// Actionable family: fetch every member's body. A fetch failure demotes
|
|
416
|
-
// that spelling to manual review (unknown bytes are never deleted) and
|
|
417
|
-
// never aborts the run.
|
|
418
|
-
const fetched: FetchedSpelling[] = [];
|
|
419
|
-
for (const member of members) {
|
|
420
|
-
try {
|
|
421
|
-
const res = await store.getObject(member.key);
|
|
422
|
-
fetched.push({
|
|
423
|
-
key: member.key,
|
|
424
|
-
lastModified: member.lastModified,
|
|
425
|
-
body: res.body,
|
|
426
|
-
metadata: res.metadata,
|
|
427
|
-
});
|
|
428
|
-
} catch (err) {
|
|
429
|
-
warn(`body fetch failed for ${member.key}: ${String(err)} — left for manual review`);
|
|
430
|
-
manualReview.push({
|
|
431
|
-
key: member.key,
|
|
432
|
-
reason: "body fetch failed — bytes unknown, not touched",
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
if (fetched.length === 0) continue; // every member failed; all warned above
|
|
437
|
-
|
|
438
|
-
// A canonical spelling that is LISTED but whose body fetch failed means
|
|
439
|
-
// the canonical bytes are unknown — rewriting from a junk sibling could
|
|
440
|
-
// overwrite a non-marker object behind a transient read fault. Park the
|
|
441
|
-
// whole family: no rewrite, no deletes; re-run once the read recovers.
|
|
442
|
-
const canonicalListed = members.some((m) => m.key === canonicalKey);
|
|
443
|
-
const canonicalMember = fetched.find((m) => m.key === canonicalKey);
|
|
444
|
-
if (canonicalListed && canonicalMember === undefined) {
|
|
445
|
-
for (const member of fetched) {
|
|
446
|
-
manualReview.push({
|
|
447
|
-
key: member.key,
|
|
448
|
-
reason: "canonical body unknown (fetch failed) — family not touched",
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
continue;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
const winner = pickWinner(fetched, canonicalKey);
|
|
455
|
-
|
|
456
|
-
// The body the canonical key will hold after this pass: the newest-bodied
|
|
457
|
-
// spelling's. (Re)write when the canonical key is missing entirely or its
|
|
458
|
-
// bytes are stale relative to the winner.
|
|
459
|
-
const finalBody = winner.body;
|
|
460
|
-
if (!canonicalMember || !canonicalMember.body.equals(finalBody)) {
|
|
461
|
-
rewrites.push({ key: canonicalKey, fromSpelling: winner.key });
|
|
462
|
-
// CAS fence (same contract as the push path): if the canonical key was
|
|
463
|
-
// listed, the PUT lands only while its ETag is unchanged; if it was
|
|
464
|
-
// absent, only while it is still absent. A concurrent upload from
|
|
465
|
-
// another machine turns the rewrite into a 412 warning (and the
|
|
466
|
-
// failed-rewrite guard below keeps the family's tombstones), never a
|
|
467
|
-
// clobber of bytes this run has not seen.
|
|
468
|
-
const listedCanonical = members.find((m) => m.key === canonicalKey);
|
|
469
|
-
rewritePayloads.push({
|
|
470
|
-
key: canonicalKey,
|
|
471
|
-
body: finalBody,
|
|
472
|
-
metadata: winner.metadata,
|
|
473
|
-
...(listedCanonical
|
|
474
|
-
? { ifMatch: listedCanonical.etag }
|
|
475
|
-
: { ifNoneMatch: "*" as const }),
|
|
476
|
-
});
|
|
477
|
-
} else {
|
|
478
|
-
keep.push(canonicalKey);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
// Safety gate, per spelling: auto-delete ONLY symlink-marker bodies or
|
|
482
|
-
// bodies byte-identical to the canonical twin's final content.
|
|
483
|
-
for (const member of fetched) {
|
|
484
|
-
if (member.key === canonicalKey) continue;
|
|
485
|
-
if (isSymlinkMarkerBody(member.body) || member.body.equals(finalBody)) {
|
|
486
|
-
tombstones.push(member.key);
|
|
487
|
-
} else {
|
|
488
|
-
manualReview.push({
|
|
489
|
-
key: member.key,
|
|
490
|
-
reason: "body is neither a symlink marker nor byte-identical to the canonical key — not auto-deleted",
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// ── Bulk-asymmetry decision (policy: sync-delete-bulk-asymmetry-guard) ────
|
|
497
|
-
const bulkRefused =
|
|
498
|
-
!isBulkDeleteOverride(options.bulkDeleteOverride) &&
|
|
499
|
-
tombstones.length >= BULK_ASYMMETRY_MIN_ABS &&
|
|
500
|
-
listed.length > 0 &&
|
|
501
|
-
tombstones.length / listed.length >= BULK_ASYMMETRY_RATIO;
|
|
502
|
-
|
|
503
|
-
// ── Local leg: plan ───────────────────────────────────────────────────────
|
|
504
|
-
const skillsDir = path.join(options.hqRoot, ".claude", "skills");
|
|
505
|
-
const localGc = planLocalSkillFarmGc(skillsDir, win32, warn);
|
|
506
|
-
|
|
507
|
-
const plan: SyncDoctorPlan = {
|
|
508
|
-
inScopeKeys: listed.length,
|
|
509
|
-
keep,
|
|
510
|
-
rewrites,
|
|
511
|
-
tombstones,
|
|
512
|
-
manualReview,
|
|
513
|
-
localRemovals: localGc.removals,
|
|
514
|
-
localManualReview: localGc.manualReview,
|
|
515
|
-
bulkRefused,
|
|
516
|
-
};
|
|
517
|
-
printPlan(plan);
|
|
518
|
-
|
|
519
|
-
const result: SyncDoctorResult = {
|
|
520
|
-
plan,
|
|
521
|
-
applied: false,
|
|
522
|
-
keysRewritten: 0,
|
|
523
|
-
keysDeleted: 0,
|
|
524
|
-
dirsRemoved: 0,
|
|
525
|
-
warnings,
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
// ── Dry-run is the default: full plan printed, nothing written. ───────────
|
|
529
|
-
if (!options.yes) {
|
|
530
|
-
console.log("\nDry-run (default): nothing written. Re-run with --yes to apply.");
|
|
531
|
-
result.warnings = warnings;
|
|
532
|
-
return result;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
// ── Apply: canonical rewrites first (additive), then gated deletes, then
|
|
536
|
-
// local GC. Per-item failures warn and continue — never fatal. ─────────
|
|
537
|
-
// Canonical keys whose rewrite failed: their families' tombstones must NOT
|
|
538
|
-
// be deleted below — when the canonical body was missing or stale, the junk
|
|
539
|
-
// spelling may hold the newest (or only) remote copy, and deleting it after
|
|
540
|
-
// a failed rewrite would drop that body permanently.
|
|
541
|
-
const failedRewriteCanonicals = new Set<string>();
|
|
542
|
-
for (const payload of rewritePayloads) {
|
|
543
|
-
try {
|
|
544
|
-
await store.putObject({
|
|
545
|
-
key: payload.key,
|
|
546
|
-
body: payload.body,
|
|
547
|
-
// Content-type is not consulted by the engine's read path; marker
|
|
548
|
-
// records upload as octet-stream (s3.ts uploadSymlink convention).
|
|
549
|
-
contentType: "application/octet-stream",
|
|
550
|
-
metadata: payload.metadata,
|
|
551
|
-
ifMatch: payload.ifMatch,
|
|
552
|
-
ifNoneMatch: payload.ifNoneMatch,
|
|
553
|
-
});
|
|
554
|
-
result.keysRewritten++;
|
|
555
|
-
} catch (err) {
|
|
556
|
-
failedRewriteCanonicals.add(payload.key);
|
|
557
|
-
warn(`canonical rewrite failed for ${payload.key}: ${String(err)}`);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
if (bulkRefused) {
|
|
562
|
-
// Refusal is event-only (policy req #4): nothing deleted, nothing
|
|
563
|
-
// journaled away — re-run with the override once the plan is reviewed.
|
|
564
|
-
console.error(
|
|
565
|
-
` ! bulk-asymmetry circuit-breaker tripped: ${tombstones.length}/${listed.length} in-scope skill keys planned for deletion.\n` +
|
|
566
|
-
` Refusing the delete leg — review the plan above, then re-run with --force-bulk (or HQ_SYNC_DELETE_BULK_OVERRIDE=1) to apply it.`,
|
|
567
|
-
);
|
|
568
|
-
} else {
|
|
569
|
-
for (const key of tombstones) {
|
|
570
|
-
if (failedRewriteCanonicals.has(canonicalVaultKeySpelling(key))) {
|
|
571
|
-
warn(
|
|
572
|
-
`skipping delete of ${key} — its canonical rewrite failed; re-run the doctor once the write path recovers`,
|
|
573
|
-
);
|
|
574
|
-
continue;
|
|
575
|
-
}
|
|
576
|
-
try {
|
|
577
|
-
await store.deleteObject(key);
|
|
578
|
-
result.keysDeleted++;
|
|
579
|
-
} catch (err) {
|
|
580
|
-
warn(`delete failed for ${key}: ${String(err)}`);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
for (const fullPath of plan.localRemovals) {
|
|
586
|
-
try {
|
|
587
|
-
// Re-verify at apply time: the entry may have changed between plan and
|
|
588
|
-
// apply (sync pass, user edit). Positive check — remove ONLY what is
|
|
589
|
-
// still a symlink or a farm-only directory; anything else (a regular
|
|
590
|
-
// file that replaced the planned entry, a dir that grew real files) is
|
|
591
|
-
// refused rather than trusted from the plan.
|
|
592
|
-
const st = fs.lstatSync(fullPath);
|
|
593
|
-
const stillFarmEntry =
|
|
594
|
-
st.isSymbolicLink() ||
|
|
595
|
-
(st.isDirectory() && containsOnlySymlinkFarmContent(fullPath));
|
|
596
|
-
if (!stillFarmEntry) {
|
|
597
|
-
warn(`skipped ${fullPath} — no longer symlink-farm content (changed since planning)`);
|
|
598
|
-
continue;
|
|
599
|
-
}
|
|
600
|
-
removeFarmEntry(fullPath);
|
|
601
|
-
result.dirsRemoved++;
|
|
602
|
-
} catch (err) {
|
|
603
|
-
warn(`local removal failed for ${fullPath}: ${String(err)}`);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
result.applied = true;
|
|
608
|
-
result.warnings = warnings;
|
|
609
|
-
console.log(
|
|
610
|
-
`\nApplied: ${result.keysRewritten} canonical key(s) written, ${result.keysDeleted} spelling(s) deleted, ${result.dirsRemoved} local entr(ies) removed.`,
|
|
611
|
-
);
|
|
612
|
-
return result;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
/** Print the full plan: counts plus every key/path in each bucket. */
|
|
616
|
-
function printPlan(plan: SyncDoctorPlan): void {
|
|
617
|
-
console.log(`hq sync doctor — skill-key dedupe plan (${SKILLS_KEY_PREFIX})`);
|
|
618
|
-
console.log(` in-scope keys: ${plan.inScopeKeys}`);
|
|
619
|
-
console.log(` keep (canonical, no action): ${plan.keep.length}`);
|
|
620
|
-
for (const key of plan.keep) console.log(` = ${key}`);
|
|
621
|
-
console.log(` rewrite canonical: ${plan.rewrites.length}`);
|
|
622
|
-
for (const r of plan.rewrites) {
|
|
623
|
-
console.log(` + ${r.key} (body from ${r.fromSpelling})`);
|
|
624
|
-
}
|
|
625
|
-
console.log(` tombstone (delete non-canonical spelling): ${plan.tombstones.length}`);
|
|
626
|
-
for (const key of plan.tombstones) console.log(` - ${key}`);
|
|
627
|
-
console.log(` manual review (NOT deleted): ${plan.manualReview.length}`);
|
|
628
|
-
for (const item of plan.manualReview) {
|
|
629
|
-
console.log(` ? ${item.key} — ${item.reason}`);
|
|
630
|
-
}
|
|
631
|
-
console.log(` local farm GC — remove: ${plan.localRemovals.length}`);
|
|
632
|
-
for (const p of plan.localRemovals) console.log(` - ${p}`);
|
|
633
|
-
console.log(` local farm GC — manual review: ${plan.localManualReview.length}`);
|
|
634
|
-
for (const item of plan.localManualReview) {
|
|
635
|
-
console.log(` ? ${item.path} — ${item.reason}`);
|
|
636
|
-
}
|
|
637
|
-
if (plan.bulkRefused) {
|
|
638
|
-
console.log(
|
|
639
|
-
` bulk-asymmetry: delete leg WOULD BE REFUSED (${plan.tombstones.length}/${plan.inScopeKeys} keys; override with --force-bulk or HQ_SYNC_DELETE_BULK_OVERRIDE=1)`,
|
|
640
|
-
);
|
|
641
|
-
}
|
|
642
|
-
}
|
package/src/cli/index.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hq-cloud CLI entry points.
|
|
3
|
-
*
|
|
4
|
-
* Registers `hq share`, `hq sync`, and membership commands.
|
|
5
|
-
* These are consumed by @indigoai-us/hq-cli or invoked directly.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export { share } from "./share.js";
|
|
9
|
-
export type { ShareOptions, ShareResult } from "./share.js";
|
|
10
|
-
|
|
11
|
-
export { sync } from "./sync.js";
|
|
12
|
-
export type { SyncOptions, SyncResult, SyncProgressEvent } from "./sync.js";
|
|
13
|
-
|
|
14
|
-
export { resolveConflict, showDiff } from "./conflict.js";
|
|
15
|
-
export type { ConflictStrategy, ConflictInfo, ConflictResolution } from "./conflict.js";
|
|
16
|
-
|
|
17
|
-
// Membership commands (VLT-7)
|
|
18
|
-
export { invite, listInvites, revokeInvite } from "./invite.js";
|
|
19
|
-
export type { InviteOptions, InviteResult, InviteListOptions, InviteRevokeOptions } from "./invite.js";
|
|
20
|
-
|
|
21
|
-
export { accept, parseToken } from "./accept.js";
|
|
22
|
-
export type { AcceptOptions, AcceptResult } from "./accept.js";
|
|
23
|
-
|
|
24
|
-
export { promote } from "./promote.js";
|
|
25
|
-
export type { PromoteOptions, PromoteResult } from "./promote.js";
|
|
26
|
-
|
|
27
|
-
// Skill/personal-overlay mirroring + workers-registry regen (formerly the
|
|
28
|
-
// hq-core master-sync.sh hook; `hq reindex`).
|
|
29
|
-
export { reindex } from "./reindex.js";
|
|
30
|
-
export type { ReindexOptions, ReindexResult } from "./reindex.js";
|
|
31
|
-
|
|
32
|
-
// Drift-preserving HQ-core re-sync (formerly bundled only inside the HQ Sync
|
|
33
|
-
// menubar app). Now shared between the app and `hq rescue`.
|
|
34
|
-
export { rescue, buildRescueArgs } from "./rescue.js";
|
|
35
|
-
export type { RescueOptions, RescueResult } from "./rescue.js";
|
|
36
|
-
|
|
37
|
-
// Bounded skill-key dedupe + local `.claude/skills/` farm GC for the
|
|
38
|
-
// mixed-version amplifier (`hq sync doctor`, US-003
|
|
39
|
-
// hq-sync-windows-skill-symlink-collision). Dry-run by default; --yes applies.
|
|
40
|
-
export { syncDoctor, SKILLS_KEY_PREFIX } from "./doctor.js";
|
|
41
|
-
export type {
|
|
42
|
-
SyncDoctorOptions,
|
|
43
|
-
SyncDoctorResult,
|
|
44
|
-
SyncDoctorPlan,
|
|
45
|
-
SkillKeyRewrite,
|
|
46
|
-
DoctorManualReviewItem,
|
|
47
|
-
LocalGcManualReviewItem,
|
|
48
|
-
DoctorStore,
|
|
49
|
-
} from "./doctor.js";
|