@unbrained/pm-cli 2026.6.11 → 2026.6.12
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 +28 -0
- package/dist/cli/commands/completion.js +20 -8
- package/dist/cli/commands/completion.js.map +1 -1
- package/dist/cli/commands/create.js +6 -3
- package/dist/cli/commands/create.js.map +1 -1
- package/dist/cli/commands/docs.d.ts +2 -0
- package/dist/cli/commands/docs.js +2 -2
- package/dist/cli/commands/docs.js.map +1 -1
- package/dist/cli/commands/files.d.ts +2 -0
- package/dist/cli/commands/files.js +2 -2
- package/dist/cli/commands/files.js.map +1 -1
- package/dist/cli/commands/health.d.ts +1 -1
- package/dist/cli/commands/health.js +77 -2
- package/dist/cli/commands/health.js.map +1 -1
- package/dist/cli/commands/history-repair.d.ts +36 -0
- package/dist/cli/commands/history-repair.js +68 -3
- package/dist/cli/commands/history-repair.js.map +1 -1
- package/dist/cli/commands/index.d.ts +1 -1
- package/dist/cli/commands/index.js +3 -3
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/linked-artifacts.d.ts +18 -0
- package/dist/cli/commands/linked-artifacts.js +26 -3
- package/dist/cli/commands/linked-artifacts.js.map +1 -1
- package/dist/cli/commands/plan.d.ts +6 -0
- package/dist/cli/commands/plan.js +93 -32
- package/dist/cli/commands/plan.js.map +1 -1
- package/dist/cli/commands/validate.d.ts +20 -0
- package/dist/cli/commands/validate.js +292 -28
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/help-content.js +7 -3
- package/dist/cli/help-content.js.map +1 -1
- package/dist/cli/register-mutation.js +47 -16
- package/dist/cli/register-mutation.js.map +1 -1
- package/dist/cli/register-operations.js +10 -2
- package/dist/cli/register-operations.js.map +1 -1
- package/dist/cli/register-setup.js +16 -16
- package/dist/cli/register-setup.js.map +1 -1
- package/dist/cli-bundle/chunks/{chunk-P2PSODAQ.js → chunk-35P4GT6E.js} +110 -9
- package/dist/cli-bundle/chunks/chunk-35P4GT6E.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-B65UUCGQ.js → chunk-37CYVF73.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-J3GD64J2.js → chunk-7AMK6DOW.js} +4 -4
- package/dist/cli-bundle/chunks/{chunk-J3GD64J2.js.map → chunk-7AMK6DOW.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-IKOH24GZ.js → chunk-AX4GEVQC.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-IKOH24GZ.js.map → chunk-AX4GEVQC.js.map} +2 -2
- package/dist/cli-bundle/chunks/chunk-C6SAP27O.js +187 -0
- package/dist/cli-bundle/chunks/chunk-C6SAP27O.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-EKS6O2IR.js +217 -0
- package/dist/cli-bundle/chunks/chunk-EKS6O2IR.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-PSD7F7DX.js → chunk-KBPQHXWG.js} +17 -4
- package/dist/cli-bundle/chunks/chunk-KBPQHXWG.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-3SLOMKCJ.js → chunk-L5EPZQIC.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-NAWVUHXH.js +220 -0
- package/dist/cli-bundle/chunks/chunk-NAWVUHXH.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-UOO6BYIA.js → chunk-PNYAAB4S.js} +21 -188
- package/dist/cli-bundle/chunks/chunk-PNYAAB4S.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-R2OUQVBK.js +190 -0
- package/dist/cli-bundle/chunks/chunk-R2OUQVBK.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-LCSCXBGT.js → chunk-R4VWYWRN.js} +19 -193
- package/dist/cli-bundle/chunks/chunk-R4VWYWRN.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-7RIT3OCD.js → chunk-SO55HRA5.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-FXRU333M.js → chunk-UIG4TW2H.js} +110 -9
- package/dist/cli-bundle/chunks/chunk-UIG4TW2H.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-E5DUIJA4.js → chunk-WPDMBIX6.js} +16 -3
- package/dist/cli-bundle/chunks/chunk-WPDMBIX6.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-IH4MBKK7.js → chunk-XWMF3POR.js} +2 -2
- package/dist/cli-bundle/chunks/{contracts-3NKWYKKU.js → contracts-2G66IGIA.js} +2 -2
- package/dist/cli-bundle/chunks/{contracts-MIXBWJIB.js → contracts-PJCHYSO5.js} +2 -2
- package/dist/cli-bundle/chunks/{create-IFA26O2I.js → create-5433DP3G.js} +2 -2
- package/dist/cli-bundle/chunks/{create-JVXYHYH4.js → create-VWLWS34Z.js} +2 -2
- package/dist/cli-bundle/chunks/{docs-5WMBVQT2.js → docs-I3BAF5WH.js} +4 -4
- package/dist/cli-bundle/chunks/docs-I3BAF5WH.js.map +1 -0
- package/dist/cli-bundle/chunks/{docs-MB53UJAJ.js → docs-MXLGZUIT.js} +3 -3
- package/dist/cli-bundle/chunks/docs-MXLGZUIT.js.map +7 -0
- package/dist/cli-bundle/chunks/{files-GVMNVLCB.js → files-FYP3MDPX.js} +3 -3
- package/dist/cli-bundle/chunks/files-FYP3MDPX.js.map +7 -0
- package/dist/cli-bundle/chunks/{files-DLB5LJEP.js → files-GUXUM2MB.js} +4 -4
- package/dist/cli-bundle/chunks/files-GUXUM2MB.js.map +1 -0
- package/dist/cli-bundle/chunks/{gc-2WEPW6D6.js → gc-FENB2ESG.js} +12 -174
- package/dist/cli-bundle/chunks/gc-FENB2ESG.js.map +1 -0
- package/dist/cli-bundle/chunks/{gc-4Z3IKHAZ.js → gc-KGQG66SA.js} +10 -179
- package/dist/cli-bundle/chunks/gc-KGQG66SA.js.map +7 -0
- package/dist/cli-bundle/chunks/{health-YO5LRWN4.js → health-7MTXAVR2.js} +71 -4
- package/dist/cli-bundle/chunks/health-7MTXAVR2.js.map +7 -0
- package/dist/cli-bundle/chunks/{health-4ZYB3IYQ.js → health-E4D7KGHD.js} +72 -5
- package/dist/cli-bundle/chunks/health-E4D7KGHD.js.map +1 -0
- package/dist/cli-bundle/chunks/{history-repair-KVPFJKOS.js → history-repair-OSQOKJ3E.js} +61 -3
- package/dist/cli-bundle/chunks/history-repair-OSQOKJ3E.js.map +7 -0
- package/dist/cli-bundle/chunks/{history-repair-RUGKD3YR.js → history-repair-SBK7P34V.js} +62 -4
- package/dist/cli-bundle/chunks/history-repair-SBK7P34V.js.map +1 -0
- package/dist/cli-bundle/chunks/{plan-VNUG3WZZ.js → plan-2YTQYWGM.js} +52 -12
- package/dist/cli-bundle/chunks/plan-2YTQYWGM.js.map +1 -0
- package/dist/cli-bundle/chunks/{plan-FQLMJRLZ.js → plan-7IVSICR6.js} +51 -11
- package/dist/cli-bundle/chunks/plan-7IVSICR6.js.map +7 -0
- package/dist/cli-bundle/chunks/{register-list-query-VHDXWEPP.js → register-list-query-4UPMHONX.js} +3 -3
- package/dist/cli-bundle/chunks/{register-list-query-NPE3ECJQ.js → register-list-query-7VOW2C3W.js} +3 -3
- package/dist/cli-bundle/chunks/{register-mutation-EAYNLGOS.js → register-mutation-FARSGYRD.js} +43 -26
- package/dist/cli-bundle/chunks/{register-mutation-EAYNLGOS.js.map → register-mutation-FARSGYRD.js.map} +2 -2
- package/dist/cli-bundle/chunks/{register-mutation-DG53FCBV.js → register-mutation-LJDNVREU.js} +44 -27
- package/dist/cli-bundle/chunks/{register-mutation-DG53FCBV.js.map → register-mutation-LJDNVREU.js.map} +1 -1
- package/dist/cli-bundle/chunks/{register-operations-AM6KTWB6.js → register-operations-FFTYAL42.js} +17 -13
- package/dist/cli-bundle/chunks/register-operations-FFTYAL42.js.map +1 -0
- package/dist/cli-bundle/chunks/{register-operations-FWFE64JG.js → register-operations-HCJKDUA6.js} +16 -12
- package/dist/cli-bundle/chunks/{register-operations-FWFE64JG.js.map → register-operations-HCJKDUA6.js.map} +2 -2
- package/dist/cli-bundle/chunks/{register-setup-IKX5524L.js → register-setup-6AVIUOCC.js} +19 -19
- package/dist/cli-bundle/chunks/register-setup-6AVIUOCC.js.map +1 -0
- package/dist/cli-bundle/chunks/{register-setup-G4QYI3RX.js → register-setup-KVNLO5OJ.js} +18 -18
- package/dist/cli-bundle/chunks/register-setup-KVNLO5OJ.js.map +7 -0
- package/dist/cli-bundle/chunks/{update-2EVXOC7V.js → update-36JM7YZT.js} +3 -3
- package/dist/cli-bundle/chunks/{update-5A2B6QYB.js → update-I246PCLO.js} +3 -3
- package/dist/cli-bundle/chunks/{update-many-V4LA3C4H.js → update-many-F4IKDWZB.js} +3 -3
- package/dist/cli-bundle/chunks/{update-many-TUGU5YXQ.js → update-many-NTWZ5YT3.js} +3 -3
- package/dist/cli-bundle/chunks/{validate-EQTT6WVX.js → validate-46KCRHL7.js} +448 -36
- package/dist/cli-bundle/chunks/validate-46KCRHL7.js.map +1 -0
- package/dist/cli-bundle/chunks/{validate-XN4I4DPL.js → validate-CRFMPTYD.js} +468 -35
- package/dist/cli-bundle/chunks/validate-CRFMPTYD.js.map +7 -0
- package/dist/cli-bundle/main.js +24 -10
- package/dist/cli-bundle/main.js.map +2 -2
- package/dist/core/diagnostics/remediation.js +19 -6
- package/dist/core/diagnostics/remediation.js.map +1 -1
- package/dist/core/lock/lock-gc.d.ts +31 -0
- package/dist/core/lock/lock-gc.js +120 -62
- package/dist/core/lock/lock-gc.js.map +1 -1
- package/dist/core/telemetry/consent.js +18 -3
- package/dist/core/telemetry/consent.js.map +1 -1
- package/dist/core/validate/fix-planning.d.ts +130 -0
- package/dist/core/validate/fix-planning.js +202 -0
- package/dist/core/validate/fix-planning.js.map +1 -0
- package/dist/core/validate/missing-by-type.d.ts +21 -0
- package/dist/core/validate/missing-by-type.js +39 -0
- package/dist/core/validate/missing-by-type.js.map +1 -0
- package/dist/core/validate/stale-file-classification.d.ts +41 -0
- package/dist/core/validate/stale-file-classification.js +73 -0
- package/dist/core/validate/stale-file-classification.js.map +1 -0
- package/dist/mcp/server.js +41 -8
- package/dist/mcp/server.js.map +1 -1
- package/dist/sdk/cli-contracts/tool-parameter-tables.js +38 -2
- package/dist/sdk/cli-contracts/tool-parameter-tables.js.map +1 -1
- package/dist/sdk/cli-contracts.d.ts +6 -1
- package/dist/sdk/cli-contracts.js +74 -7
- package/dist/sdk/cli-contracts.js.map +1 -1
- package/docs/AGENT_GUIDE.md +6 -1
- package/docs/COMMANDS.md +23 -1
- package/package.json +1 -1
- package/dist/cli-bundle/chunks/chunk-E5DUIJA4.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-FXRU333M.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-LCSCXBGT.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-P2PSODAQ.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-PSD7F7DX.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-UOO6BYIA.js.map +0 -1
- package/dist/cli-bundle/chunks/docs-5WMBVQT2.js.map +0 -1
- package/dist/cli-bundle/chunks/docs-MB53UJAJ.js.map +0 -7
- package/dist/cli-bundle/chunks/files-DLB5LJEP.js.map +0 -1
- package/dist/cli-bundle/chunks/files-GVMNVLCB.js.map +0 -7
- package/dist/cli-bundle/chunks/gc-2WEPW6D6.js.map +0 -1
- package/dist/cli-bundle/chunks/gc-4Z3IKHAZ.js.map +0 -7
- package/dist/cli-bundle/chunks/health-4ZYB3IYQ.js.map +0 -1
- package/dist/cli-bundle/chunks/health-YO5LRWN4.js.map +0 -7
- package/dist/cli-bundle/chunks/history-repair-KVPFJKOS.js.map +0 -7
- package/dist/cli-bundle/chunks/history-repair-RUGKD3YR.js.map +0 -1
- package/dist/cli-bundle/chunks/plan-FQLMJRLZ.js.map +0 -7
- package/dist/cli-bundle/chunks/plan-VNUG3WZZ.js.map +0 -1
- package/dist/cli-bundle/chunks/register-operations-AM6KTWB6.js.map +0 -1
- package/dist/cli-bundle/chunks/register-setup-G4QYI3RX.js.map +0 -7
- package/dist/cli-bundle/chunks/register-setup-IKX5524L.js.map +0 -1
- package/dist/cli-bundle/chunks/validate-EQTT6WVX.js.map +0 -1
- package/dist/cli-bundle/chunks/validate-XN4I4DPL.js.map +0 -7
- /package/dist/cli-bundle/chunks/{chunk-B65UUCGQ.js.map → chunk-37CYVF73.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-3SLOMKCJ.js.map → chunk-L5EPZQIC.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-7RIT3OCD.js.map → chunk-SO55HRA5.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-IH4MBKK7.js.map → chunk-XWMF3POR.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{contracts-3NKWYKKU.js.map → contracts-2G66IGIA.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{contracts-MIXBWJIB.js.map → contracts-PJCHYSO5.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{create-IFA26O2I.js.map → create-5433DP3G.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{create-JVXYHYH4.js.map → create-VWLWS34Z.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{register-list-query-VHDXWEPP.js.map → register-list-query-4UPMHONX.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{register-list-query-NPE3ECJQ.js.map → register-list-query-7VOW2C3W.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-2EVXOC7V.js.map → update-36JM7YZT.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-5A2B6QYB.js.map → update-I246PCLO.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-many-V4LA3C4H.js.map → update-many-F4IKDWZB.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-many-TUGU5YXQ.js.map → update-many-NTWZ5YT3.js.map} +0 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="490c7409-913e-57cd-871b-a7eeb568b87c")}catch(e){}}();
|
|
3
|
+
import {
|
|
4
|
+
verifyHistoryChain
|
|
5
|
+
} from "./chunk-ZYNJNPYD.js";
|
|
6
|
+
import {
|
|
7
|
+
hashDocument
|
|
8
|
+
} from "./chunk-HI7STVF2.js";
|
|
9
|
+
import {
|
|
10
|
+
getHistoryPath,
|
|
11
|
+
writeFileAtomic
|
|
12
|
+
} from "./chunk-A6LXQFO7.js";
|
|
13
|
+
|
|
14
|
+
// dist/core/history/drift-scan.js
|
|
15
|
+
import fs from "fs/promises";
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
var DRIFT_CACHE_VERSION = 2;
|
|
19
|
+
var DRIFT_CACHE_FILENAME = "history-drift-cache.json";
|
|
20
|
+
function getDriftCachePath(pmRoot) {
|
|
21
|
+
return path.join(pmRoot, "runtime", DRIFT_CACHE_FILENAME);
|
|
22
|
+
}
|
|
23
|
+
async function loadDriftCache(pmRoot) {
|
|
24
|
+
try {
|
|
25
|
+
const raw = await fs.readFile(getDriftCachePath(pmRoot), "utf8");
|
|
26
|
+
const parsed = JSON.parse(raw);
|
|
27
|
+
if (parsed.version !== DRIFT_CACHE_VERSION || typeof parsed.entries !== "object" || parsed.entries === null) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return parsed;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function isErrno(error, code) {
|
|
36
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === code;
|
|
37
|
+
}
|
|
38
|
+
function hashContent(raw) {
|
|
39
|
+
return createHash("sha256").update(raw).digest("hex");
|
|
40
|
+
}
|
|
41
|
+
async function readHistoryContentHash(historyPath) {
|
|
42
|
+
const raw = await fs.readFile(historyPath, "utf8");
|
|
43
|
+
return hashContent(raw);
|
|
44
|
+
}
|
|
45
|
+
async function verifyHistoryStream(historyPath) {
|
|
46
|
+
const raw = await fs.readFile(historyPath, "utf8");
|
|
47
|
+
const contentHash = hashContent(raw);
|
|
48
|
+
if (raw.trim().length === 0) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const entries = [];
|
|
52
|
+
let latestAfterHash = null;
|
|
53
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
54
|
+
const trimmed = line.trim();
|
|
55
|
+
if (trimmed.length === 0) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const parsed = JSON.parse(trimmed);
|
|
59
|
+
if (typeof parsed.after_hash !== "string" || parsed.after_hash.trim().length === 0) {
|
|
60
|
+
throw new Error("missing after_hash");
|
|
61
|
+
}
|
|
62
|
+
entries.push(parsed);
|
|
63
|
+
latestAfterHash = parsed.after_hash;
|
|
64
|
+
}
|
|
65
|
+
if (!latestAfterHash) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
latestAfterHash,
|
|
70
|
+
chainOk: verifyHistoryChain(entries).ok,
|
|
71
|
+
contentHash
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async function scanHistoryDrift(pmRoot, items) {
|
|
75
|
+
const missingStreams = [];
|
|
76
|
+
const unreadableStreams = [];
|
|
77
|
+
const hashMismatches = [];
|
|
78
|
+
const chainMismatches = [];
|
|
79
|
+
const cache = await loadDriftCache(pmRoot);
|
|
80
|
+
const previousEntries = cache?.entries ?? {};
|
|
81
|
+
const nextEntries = {};
|
|
82
|
+
let cacheDirty = false;
|
|
83
|
+
for (const item of items) {
|
|
84
|
+
const historyPath = getHistoryPath(pmRoot, item.id);
|
|
85
|
+
let stat;
|
|
86
|
+
try {
|
|
87
|
+
stat = await fs.stat(historyPath);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (isErrno(error, "ENOENT")) {
|
|
90
|
+
missingStreams.push(item.id);
|
|
91
|
+
} else {
|
|
92
|
+
unreadableStreams.push(item.id);
|
|
93
|
+
}
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const loadStreamVerification = async () => {
|
|
97
|
+
try {
|
|
98
|
+
return await verifyHistoryStream(historyPath);
|
|
99
|
+
} catch {
|
|
100
|
+
return "unreadable";
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const loadFreshVerification = async () => {
|
|
104
|
+
const loaded = await loadStreamVerification();
|
|
105
|
+
if (loaded === "unreadable") {
|
|
106
|
+
unreadableStreams.push(item.id);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
if (!loaded) {
|
|
110
|
+
missingStreams.push(item.id);
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return loaded;
|
|
114
|
+
};
|
|
115
|
+
const cached = previousEntries[item.id];
|
|
116
|
+
let verification;
|
|
117
|
+
const metadataMatchesCache = cached !== void 0 && cached.mtime_ms === stat.mtimeMs && cached.ctime_ms === stat.ctimeMs && cached.size === stat.size;
|
|
118
|
+
const cachedContentHash = typeof cached?.content_hash === "string" && cached.content_hash.length > 0 ? cached.content_hash : void 0;
|
|
119
|
+
const canUseCache = metadataMatchesCache && cachedContentHash !== void 0;
|
|
120
|
+
if (canUseCache && cached) {
|
|
121
|
+
let currentContentHash;
|
|
122
|
+
try {
|
|
123
|
+
currentContentHash = await readHistoryContentHash(historyPath);
|
|
124
|
+
} catch {
|
|
125
|
+
unreadableStreams.push(item.id);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (currentContentHash === cachedContentHash) {
|
|
129
|
+
verification = {
|
|
130
|
+
latestAfterHash: cached.latest_after_hash,
|
|
131
|
+
chainOk: cached.chain_ok,
|
|
132
|
+
contentHash: currentContentHash
|
|
133
|
+
};
|
|
134
|
+
} else {
|
|
135
|
+
cacheDirty = true;
|
|
136
|
+
const refreshed = await loadFreshVerification();
|
|
137
|
+
if (!refreshed) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
verification = refreshed;
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
cacheDirty = true;
|
|
144
|
+
const refreshed = await loadFreshVerification();
|
|
145
|
+
if (!refreshed) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
verification = refreshed;
|
|
149
|
+
}
|
|
150
|
+
if (!verification.chainOk) {
|
|
151
|
+
chainMismatches.push(item.id);
|
|
152
|
+
}
|
|
153
|
+
nextEntries[item.id] = {
|
|
154
|
+
mtime_ms: stat.mtimeMs,
|
|
155
|
+
ctime_ms: stat.ctimeMs,
|
|
156
|
+
size: stat.size,
|
|
157
|
+
content_hash: verification.contentHash,
|
|
158
|
+
latest_after_hash: verification.latestAfterHash,
|
|
159
|
+
chain_ok: verification.chainOk
|
|
160
|
+
};
|
|
161
|
+
const { body, ...frontMatter } = item;
|
|
162
|
+
const currentHash = hashDocument({
|
|
163
|
+
metadata: frontMatter,
|
|
164
|
+
body
|
|
165
|
+
});
|
|
166
|
+
if (currentHash !== verification.latestAfterHash) {
|
|
167
|
+
hashMismatches.push(item.id);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (cacheDirty || Object.keys(previousEntries).length !== Object.keys(nextEntries).length) {
|
|
171
|
+
const cachePath = getDriftCachePath(pmRoot);
|
|
172
|
+
try {
|
|
173
|
+
await fs.mkdir(path.dirname(cachePath), { recursive: true });
|
|
174
|
+
await writeFileAtomic(cachePath, JSON.stringify({ version: DRIFT_CACHE_VERSION, entries: nextEntries }));
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const driftedItems = [.../* @__PURE__ */ new Set([...missingStreams, ...unreadableStreams, ...hashMismatches, ...chainMismatches])].sort((a, b) => a.localeCompare(b));
|
|
179
|
+
return { missingStreams, unreadableStreams, hashMismatches, chainMismatches, driftedItems };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export {
|
|
183
|
+
scanHistoryDrift
|
|
184
|
+
};
|
|
185
|
+
//# sourceMappingURL=chunk-C6SAP27O.js.map
|
|
186
|
+
|
|
187
|
+
//# debugId=490c7409-913e-57cd-871b-a7eeb568b87c
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../core/history/drift-scan.ts"],"sourcesContent":["import fs from \"fs/promises\";\nimport { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport { getHistoryPath } from \"../store/paths.js\";\nimport { writeFileAtomic } from \"../fs/fs-utils.js\";\nimport { hashDocument } from \"./history.js\";\nimport { verifyHistoryChain } from \"./replay.js\";\nimport type { HistoryEntry, ItemMetadata } from \"../../types/index.js\";\n\nexport interface DriftScanResult {\n missingStreams: string[];\n unreadableStreams: string[];\n hashMismatches: string[];\n chainMismatches: string[];\n driftedItems: string[];\n}\n\nconst DRIFT_CACHE_VERSION = 2;\nconst DRIFT_CACHE_FILENAME = \"history-drift-cache.json\";\n\ninterface DriftCacheEntry {\n mtime_ms: number;\n ctime_ms: number;\n size: number;\n content_hash: string;\n latest_after_hash: string;\n chain_ok: boolean;\n}\n\ninterface DriftCacheEnvelope {\n version: number;\n entries: Record<string, DriftCacheEntry>;\n}\n\nfunction getDriftCachePath(pmRoot: string): string {\n return path.join(pmRoot, \"runtime\", DRIFT_CACHE_FILENAME);\n}\n\nasync function loadDriftCache(pmRoot: string): Promise<DriftCacheEnvelope | null> {\n try {\n const raw = await fs.readFile(getDriftCachePath(pmRoot), \"utf8\");\n const parsed = JSON.parse(raw) as DriftCacheEnvelope;\n if (parsed.version !== DRIFT_CACHE_VERSION || typeof parsed.entries !== \"object\" || parsed.entries === null) {\n return null;\n }\n return parsed;\n } catch {\n return null;\n }\n}\n\nfunction isErrno(error: unknown, code: string): boolean {\n return typeof error === \"object\" && error !== null && \"code\" in error && (error as { code?: string }).code === code;\n}\n\ninterface StreamVerification {\n latestAfterHash: string;\n chainOk: boolean;\n contentHash: string;\n}\n\nfunction hashContent(raw: string): string {\n return createHash(\"sha256\").update(raw).digest(\"hex\");\n}\n\nasync function readHistoryContentHash(historyPath: string): Promise<string> {\n const raw = await fs.readFile(historyPath, \"utf8\");\n return hashContent(raw);\n}\n\n/**\n * Read and fully verify one history stream's hash chain. Returns null for an\n * empty/missing stream (caller records it as a missing stream).\n */\nasync function verifyHistoryStream(historyPath: string): Promise<StreamVerification | null> {\n const raw = await fs.readFile(historyPath, \"utf8\");\n const contentHash = hashContent(raw);\n if (raw.trim().length === 0) {\n return null;\n }\n const entries: HistoryEntry[] = [];\n let latestAfterHash: string | null = null;\n for (const line of raw.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (trimmed.length === 0) {\n continue;\n }\n const parsed = JSON.parse(trimmed) as HistoryEntry;\n if (typeof parsed.after_hash !== \"string\" || parsed.after_hash.trim().length === 0) {\n throw new Error(\"missing after_hash\");\n }\n entries.push(parsed);\n latestAfterHash = parsed.after_hash;\n }\n /* c8 ignore start -- defensive guard for future history schema changes. */\n if (!latestAfterHash) {\n return null;\n }\n /* c8 ignore stop */\n return {\n latestAfterHash,\n chainOk: verifyHistoryChain(entries).ok,\n contentHash,\n };\n}\n\n/**\n * Scan every item's history stream for drift (missing/unreadable streams, broken\n * hash chains, and item/history hash mismatches).\n *\n * Full chain re-verification of a 17MB+ history tree is the dominant cost of\n * `pm health`. We cache the per-stream verification keyed by the history file's\n * mtime/ctime/size + content hash: metadata-stable replacements (same stat tuple)\n * can still happen, so each metadata hit recomputes a content hash guard before\n * trusting the cached chain/hash verification.\n */\nexport async function scanHistoryDrift(\n pmRoot: string,\n items: Array<ItemMetadata & { body: string }>,\n): Promise<DriftScanResult> {\n const missingStreams: string[] = [];\n const unreadableStreams: string[] = [];\n const hashMismatches: string[] = [];\n const chainMismatches: string[] = [];\n\n const cache = await loadDriftCache(pmRoot);\n const previousEntries: Record<string, DriftCacheEntry> = cache?.entries ?? {};\n const nextEntries: Record<string, DriftCacheEntry> = {};\n let cacheDirty = false;\n\n for (const item of items) {\n const historyPath = getHistoryPath(pmRoot, item.id);\n\n let stat: Awaited<ReturnType<typeof fs.stat>>;\n try {\n stat = await fs.stat(historyPath);\n } catch (error: unknown) {\n if (isErrno(error, \"ENOENT\")) {\n missingStreams.push(item.id);\n } else {\n unreadableStreams.push(item.id);\n }\n continue;\n }\n\n const loadStreamVerification = async (): Promise<StreamVerification | null | \"unreadable\"> => {\n try {\n return await verifyHistoryStream(historyPath);\n } catch {\n return \"unreadable\";\n }\n };\n\n const loadFreshVerification = async (): Promise<StreamVerification | null> => {\n const loaded = await loadStreamVerification();\n if (loaded === \"unreadable\") {\n unreadableStreams.push(item.id);\n return null;\n }\n if (!loaded) {\n missingStreams.push(item.id);\n return null;\n }\n return loaded;\n };\n\n const cached = previousEntries[item.id];\n let verification: StreamVerification;\n const metadataMatchesCache =\n cached !== undefined &&\n cached.mtime_ms === stat.mtimeMs &&\n cached.ctime_ms === stat.ctimeMs &&\n cached.size === stat.size;\n const cachedContentHash =\n typeof cached?.content_hash === \"string\" && cached.content_hash.length > 0 ? cached.content_hash : undefined;\n const canUseCache = metadataMatchesCache && cachedContentHash !== undefined;\n if (canUseCache && cached) {\n let currentContentHash: string;\n try {\n currentContentHash = await readHistoryContentHash(historyPath);\n } catch {\n unreadableStreams.push(item.id);\n continue;\n }\n if (currentContentHash === cachedContentHash) {\n verification = {\n latestAfterHash: cached.latest_after_hash,\n chainOk: cached.chain_ok,\n contentHash: currentContentHash,\n };\n } else {\n cacheDirty = true;\n const refreshed = await loadFreshVerification();\n if (!refreshed) {\n continue;\n }\n verification = refreshed;\n }\n } else {\n cacheDirty = true;\n const refreshed = await loadFreshVerification();\n if (!refreshed) {\n continue;\n }\n verification = refreshed;\n }\n\n if (!verification.chainOk) {\n chainMismatches.push(item.id);\n }\n nextEntries[item.id] = {\n mtime_ms: stat.mtimeMs,\n ctime_ms: stat.ctimeMs,\n size: stat.size,\n content_hash: verification.contentHash,\n latest_after_hash: verification.latestAfterHash,\n chain_ok: verification.chainOk,\n };\n\n const { body, ...frontMatter } = item;\n const currentHash = hashDocument({\n metadata: frontMatter as ItemMetadata,\n body,\n });\n if (currentHash !== verification.latestAfterHash) {\n hashMismatches.push(item.id);\n }\n }\n\n if (cacheDirty || Object.keys(previousEntries).length !== Object.keys(nextEntries).length) {\n const cachePath = getDriftCachePath(pmRoot);\n try {\n await fs.mkdir(path.dirname(cachePath), { recursive: true });\n await writeFileAtomic(cachePath, JSON.stringify({ version: DRIFT_CACHE_VERSION, entries: nextEntries }));\n } catch {\n // Best-effort cache write: a failed persist must never fail a health scan.\n }\n }\n\n const driftedItems = [...new Set([...missingStreams, ...unreadableStreams, ...hashMismatches, ...chainMismatches])].sort((a, b) =>\n a.localeCompare(b),\n );\n return { missingStreams, unreadableStreams, hashMismatches, chainMismatches, driftedItems };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,OAAO,QAAQ;AACf,SAAS,kBAAkB;AAC3B,OAAO,UAAU;AAejB,IAAM,sBAAsB;AAC5B,IAAM,uBAAuB;AAgB7B,SAAS,kBAAkB,QAAc;AACvC,SAAO,KAAK,KAAK,QAAQ,WAAW,oBAAoB;AAC1D;AAEA,eAAe,eAAe,QAAc;AAC1C,MAAI;AACF,UAAM,MAAM,MAAM,GAAG,SAAS,kBAAkB,MAAM,GAAG,MAAM;AAC/D,UAAM,SAAS,KAAK,MAAM,GAAG;AAC7B,QAAI,OAAO,YAAY,uBAAuB,OAAO,OAAO,YAAY,YAAY,OAAO,YAAY,MAAM;AAC3G,aAAO;IACT;AACA,WAAO;EACT,QAAQ;AACN,WAAO;EACT;AACF;AAEA,SAAS,QAAQ,OAAgB,MAAY;AAC3C,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,SAAU,MAA4B,SAAS;AACjH;AAQA,SAAS,YAAY,KAAW;AAC9B,SAAO,WAAW,QAAQ,EAAE,OAAO,GAAG,EAAE,OAAO,KAAK;AACtD;AAEA,eAAe,uBAAuB,aAA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a;MAC3B,mBAAmB,aAAa;MAChC,UAAU,aAAa;;AAGzB,UAAM,EAAE,MAAM,GAAG,YAAW,IAAK;AACjC,UAAM,cAAc,aAAa;MAC/B,UAAU;MACV;KACD;AACD,QAAI,gBAAgB,aAAa,iBAAiB;AAChD,qBAAe,KAAK,KAAK,EAAE;IAC7B;EACF;AAEA,MAAI,cAAc,OAAO,KAAK,eAAe,EAAE,WAAW,OAAO,KAAK,WAAW,EAAE,QAAQ;AACzF,UAAM,YAAY,kBAAkB,MAAM;AAC1C,QAAI;AACF,YAAM,GAAG,MAAM,KAAK,QAAQ,SAAS,GAAG,EAAE,WAAW,KAAI,CAAE;AAC3D,YAAM,gBAAgB,WAAW,KAAK,UAAU,EAAE,SAAS,qBAAqB,SAAS,YAAW,CAAE,CAAC;IACzG,QAAQ;IAER;EACF;AAEA,QAAM,eAAe,CAAC,GAAG,oBAAI,IAAI,CAAC,GAAG,gBAAgB,GAAG,mBAAmB,GAAG,gBAAgB,GAAG,eAAe,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,MAC3H,EAAE,cAAc,CAAC,CAAC;AAEpB,SAAO,EAAE,gBAAgB,mBAAmB,gBAAgB,iBAAiB,aAAY;AAC3F","debugId":"490c7409-913e-57cd-871b-a7eeb568b87c"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// dist/core/lock/lock-gc.js
|
|
2
|
+
|
|
3
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="24d21b8b-52d9-5838-867f-b59f2e90d106")}catch(e){}}();
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
function parseLock(raw) {
|
|
7
|
+
let parsed;
|
|
8
|
+
try {
|
|
9
|
+
parsed = JSON.parse(raw);
|
|
10
|
+
} catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const candidate = parsed;
|
|
17
|
+
const { id, owner, created_at, ttl_seconds } = candidate;
|
|
18
|
+
if (typeof id !== "string" || typeof owner !== "string" || typeof created_at !== "string" || typeof ttl_seconds !== "number" || !Number.isFinite(ttl_seconds)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return { id, owner, created_at, ttl_seconds };
|
|
22
|
+
}
|
|
23
|
+
function isErrno(error, code) {
|
|
24
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === code;
|
|
25
|
+
}
|
|
26
|
+
function classifyLockContent(file, raw, nowMs) {
|
|
27
|
+
const lock = parseLock(raw);
|
|
28
|
+
if (lock === null) {
|
|
29
|
+
return {
|
|
30
|
+
detail: "unparseable_json",
|
|
31
|
+
entry: {
|
|
32
|
+
file,
|
|
33
|
+
id: null,
|
|
34
|
+
owner: null,
|
|
35
|
+
created_at: null,
|
|
36
|
+
ttl_seconds: null,
|
|
37
|
+
age_seconds: null,
|
|
38
|
+
stale: false,
|
|
39
|
+
reason: "unparseable"
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const createdAtMs = Date.parse(lock.created_at);
|
|
44
|
+
if (!Number.isFinite(createdAtMs)) {
|
|
45
|
+
return {
|
|
46
|
+
detail: "invalid_timestamp",
|
|
47
|
+
entry: {
|
|
48
|
+
file,
|
|
49
|
+
id: lock.id,
|
|
50
|
+
owner: lock.owner,
|
|
51
|
+
created_at: lock.created_at,
|
|
52
|
+
ttl_seconds: lock.ttl_seconds,
|
|
53
|
+
age_seconds: null,
|
|
54
|
+
stale: false,
|
|
55
|
+
reason: "unparseable"
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const ageMs = nowMs - createdAtMs;
|
|
60
|
+
const age_seconds = Math.floor(ageMs / 1e3);
|
|
61
|
+
const stale = ageMs > lock.ttl_seconds * 1e3;
|
|
62
|
+
return {
|
|
63
|
+
detail: stale ? "expired" : "active",
|
|
64
|
+
entry: {
|
|
65
|
+
file,
|
|
66
|
+
id: lock.id,
|
|
67
|
+
owner: lock.owner,
|
|
68
|
+
created_at: lock.created_at,
|
|
69
|
+
ttl_seconds: lock.ttl_seconds,
|
|
70
|
+
age_seconds,
|
|
71
|
+
stale,
|
|
72
|
+
reason: stale ? "expired" : "active"
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async function scanLockHealth(pmRoot, now) {
|
|
77
|
+
const nowMs = now ?? Date.now();
|
|
78
|
+
const locksDir = path.join(pmRoot, "locks");
|
|
79
|
+
const scan = {
|
|
80
|
+
scanned: 0,
|
|
81
|
+
active_lock_count: 0,
|
|
82
|
+
stale_lock_count: 0,
|
|
83
|
+
unreadable_lock_count: 0,
|
|
84
|
+
unparseable_lock_count: 0
|
|
85
|
+
};
|
|
86
|
+
let dirEntries;
|
|
87
|
+
try {
|
|
88
|
+
const rawDir = await fs.readdir(locksDir);
|
|
89
|
+
dirEntries = rawDir.filter((f) => f.endsWith(".lock")).sort();
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (isErrno(error, "ENOENT")) {
|
|
92
|
+
return scan;
|
|
93
|
+
}
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
for (const file of dirEntries) {
|
|
97
|
+
let raw;
|
|
98
|
+
try {
|
|
99
|
+
raw = await fs.readFile(path.join(locksDir, file), "utf8");
|
|
100
|
+
} catch (readError) {
|
|
101
|
+
if (isErrno(readError, "ENOENT")) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
scan.scanned += 1;
|
|
105
|
+
scan.unreadable_lock_count += 1;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
scan.scanned += 1;
|
|
109
|
+
const { detail } = classifyLockContent(file, raw, nowMs);
|
|
110
|
+
if (detail === "active") {
|
|
111
|
+
scan.active_lock_count += 1;
|
|
112
|
+
} else if (detail === "expired") {
|
|
113
|
+
scan.stale_lock_count += 1;
|
|
114
|
+
} else {
|
|
115
|
+
scan.unparseable_lock_count += 1;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return scan;
|
|
119
|
+
}
|
|
120
|
+
async function runLockGc(pmRoot, options) {
|
|
121
|
+
const { dryRun, hooks } = options;
|
|
122
|
+
const nowMs = options.now ?? Date.now();
|
|
123
|
+
const locksDir = path.join(pmRoot, "locks");
|
|
124
|
+
const result = {
|
|
125
|
+
scanned: 0,
|
|
126
|
+
removed: [],
|
|
127
|
+
retained: [],
|
|
128
|
+
warnings: [],
|
|
129
|
+
entries: []
|
|
130
|
+
};
|
|
131
|
+
let dirEntries;
|
|
132
|
+
try {
|
|
133
|
+
const raw = await fs.readdir(locksDir);
|
|
134
|
+
dirEntries = raw.filter((f) => f.endsWith(".lock")).sort();
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (isErrno(error, "ENOENT")) {
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
for (const file of dirEntries) {
|
|
142
|
+
result.scanned += 1;
|
|
143
|
+
const absPath = path.join(locksDir, file);
|
|
144
|
+
const relPath = `locks/${file}`;
|
|
145
|
+
if (hooks?.onRead) {
|
|
146
|
+
const hookWarnings = await hooks.onRead(absPath);
|
|
147
|
+
result.warnings.push(...hookWarnings);
|
|
148
|
+
}
|
|
149
|
+
let raw;
|
|
150
|
+
try {
|
|
151
|
+
raw = await fs.readFile(absPath, "utf8");
|
|
152
|
+
} catch (readError) {
|
|
153
|
+
if (isErrno(readError, "ENOENT")) {
|
|
154
|
+
result.scanned -= 1;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
result.warnings.push(`lock_unreadable:${file}`);
|
|
158
|
+
result.retained.push(relPath);
|
|
159
|
+
result.entries.push({
|
|
160
|
+
file,
|
|
161
|
+
id: null,
|
|
162
|
+
owner: null,
|
|
163
|
+
created_at: null,
|
|
164
|
+
ttl_seconds: null,
|
|
165
|
+
age_seconds: null,
|
|
166
|
+
stale: false,
|
|
167
|
+
reason: "unparseable"
|
|
168
|
+
});
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const classified = classifyLockContent(file, raw, nowMs);
|
|
172
|
+
if (classified.detail === "unparseable_json") {
|
|
173
|
+
result.warnings.push(`lock_unparseable:${file}`);
|
|
174
|
+
result.retained.push(relPath);
|
|
175
|
+
result.entries.push(classified.entry);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (classified.detail === "invalid_timestamp") {
|
|
179
|
+
result.warnings.push(`lock_invalid_timestamp:${file}`);
|
|
180
|
+
result.retained.push(relPath);
|
|
181
|
+
result.entries.push(classified.entry);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (classified.detail === "active") {
|
|
185
|
+
result.retained.push(relPath);
|
|
186
|
+
result.entries.push(classified.entry);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (!dryRun) {
|
|
190
|
+
try {
|
|
191
|
+
await fs.unlink(absPath);
|
|
192
|
+
} catch (unlinkError) {
|
|
193
|
+
if (!isErrno(unlinkError, "ENOENT")) {
|
|
194
|
+
result.warnings.push(`lock_remove_failed:${file}`);
|
|
195
|
+
result.retained.push(relPath);
|
|
196
|
+
result.entries.push(classified.entry);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (hooks?.onWrite) {
|
|
201
|
+
const hookWarnings = await hooks.onWrite(absPath);
|
|
202
|
+
result.warnings.push(...hookWarnings);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
result.removed.push(relPath);
|
|
206
|
+
result.entries.push(classified.entry);
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export {
|
|
212
|
+
scanLockHealth,
|
|
213
|
+
runLockGc
|
|
214
|
+
};
|
|
215
|
+
//# sourceMappingURL=chunk-EKS6O2IR.js.map
|
|
216
|
+
|
|
217
|
+
//# debugId=24d21b8b-52d9-5838-867f-b59f2e90d106
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../core/lock/lock-gc.ts"],"sourcesContent":["/**\n * lock-gc.ts — Stale lock file garbage collector.\n *\n * Safety-first policy: if a lock file cannot be read or parsed, it is RETAINED\n * rather than deleted. We only remove locks whose staleness can be conclusively\n * determined from the lock's own embedded `ttl_seconds` field.\n *\n * Staleness formula: (now_ms - Date.parse(created_at)) > ttl_seconds * 1000\n * Zero ttl means any lock older than 0 ms is stale. Negative ttl means always stale.\n */\n\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\nexport interface StaleLockScanEntry {\n /** e.g. \"pm-abc1.lock\" */\n file: string;\n /** parsed id, or null if unparseable */\n id: string | null;\n owner: string | null;\n created_at: string | null;\n ttl_seconds: number | null;\n /** floor((now - created_at)/1000), null if unparseable */\n age_seconds: number | null;\n /** true only when classified expired */\n stale: boolean;\n reason: \"expired\" | \"active\" | \"unparseable\";\n}\n\nexport interface LockGcHooks {\n onRead?: (lockPath: string) => Promise<string[]> | string[];\n onWrite?: (lockPath: string) => Promise<string[]> | string[];\n}\n\nexport interface LockGcOptions {\n dryRun: boolean;\n /** epoch ms; defaults to Date.now() — injectable for deterministic tests */\n now?: number;\n hooks?: LockGcHooks;\n}\n\nexport interface LockGcResult {\n /** number of *.lock files examined */\n scanned: number;\n /** relative paths like \"locks/pm-abc1.lock\" (removed, or would-remove under dryRun) */\n removed: string[];\n /** relative paths retained (active OR unparseable — never delete what we can't reason about) */\n retained: string[];\n warnings: string[];\n /** one per scanned *.lock file, sorted by file name asc */\n entries: StaleLockScanEntry[];\n}\n\ninterface ParsedLock {\n id: string;\n owner: string;\n created_at: string;\n ttl_seconds: number;\n}\n\nfunction parseLock(raw: string): ParsedLock | null {\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw) as unknown;\n } catch {\n return null;\n }\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n return null;\n }\n const candidate = parsed as Record<string, unknown>;\n const { id, owner, created_at, ttl_seconds } = candidate;\n if (\n typeof id !== \"string\" ||\n typeof owner !== \"string\" ||\n typeof created_at !== \"string\" ||\n typeof ttl_seconds !== \"number\" ||\n !Number.isFinite(ttl_seconds)\n ) {\n return null;\n }\n return { id, owner, created_at, ttl_seconds };\n}\n\nfunction isErrno(error: unknown, code: string): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n (error as { code?: string }).code === code\n );\n}\n\n/**\n * Fine-grained classification outcome for one readable lock file's content.\n * `unparseable_json` and `invalid_timestamp` both surface as the coarse\n * `reason: \"unparseable\"` on the scan entry (gc retains both), but stay\n * distinct here so callers can emit precise warnings.\n */\nexport type LockClassificationDetail = \"active\" | \"expired\" | \"unparseable_json\" | \"invalid_timestamp\";\n\nexport interface LockContentClassification {\n detail: LockClassificationDetail;\n entry: StaleLockScanEntry;\n}\n\n/**\n * Pure classification of one lock file's raw content against `nowMs`. This is\n * the single staleness/parse policy shared by `pm gc --scope locks` (which acts\n * on it) and the `pm health` locks check (which only reports it).\n */\nexport function classifyLockContent(file: string, raw: string, nowMs: number): LockContentClassification {\n const lock = parseLock(raw);\n if (lock === null) {\n return {\n detail: \"unparseable_json\",\n entry: {\n file,\n id: null,\n owner: null,\n created_at: null,\n ttl_seconds: null,\n age_seconds: null,\n stale: false,\n reason: \"unparseable\",\n },\n };\n }\n const createdAtMs = Date.parse(lock.created_at);\n if (!Number.isFinite(createdAtMs)) {\n return {\n detail: \"invalid_timestamp\",\n entry: {\n file,\n id: lock.id,\n owner: lock.owner,\n created_at: lock.created_at,\n ttl_seconds: lock.ttl_seconds,\n age_seconds: null,\n stale: false,\n reason: \"unparseable\",\n },\n };\n }\n const ageMs = nowMs - createdAtMs;\n const age_seconds = Math.floor(ageMs / 1000);\n const stale = ageMs > lock.ttl_seconds * 1000;\n return {\n detail: stale ? \"expired\" : \"active\",\n entry: {\n file,\n id: lock.id,\n owner: lock.owner,\n created_at: lock.created_at,\n ttl_seconds: lock.ttl_seconds,\n age_seconds,\n stale,\n reason: stale ? \"expired\" : \"active\",\n },\n };\n}\n\nexport interface LockHealthScan {\n /** number of *.lock files examined (ghost files that vanish mid-scan are skipped) */\n scanned: number;\n active_lock_count: number;\n stale_lock_count: number;\n unreadable_lock_count: number;\n /** invalid JSON, wrong shape, or an unparseable created_at timestamp */\n unparseable_lock_count: number;\n}\n\n/**\n * Read-only locks scan for `pm health`: classifies every lock file with the\n * same policy `pm gc --scope locks` uses but never removes anything.\n */\nexport async function scanLockHealth(pmRoot: string, now?: number): Promise<LockHealthScan> {\n const nowMs = now ?? Date.now();\n const locksDir = path.join(pmRoot, \"locks\");\n const scan: LockHealthScan = {\n scanned: 0,\n active_lock_count: 0,\n stale_lock_count: 0,\n unreadable_lock_count: 0,\n unparseable_lock_count: 0,\n };\n\n let dirEntries: string[];\n try {\n const rawDir = await fs.readdir(locksDir);\n dirEntries = rawDir.filter((f) => f.endsWith(\".lock\")).sort();\n } catch (error: unknown) {\n if (isErrno(error, \"ENOENT\")) {\n return scan;\n }\n throw error;\n }\n\n for (const file of dirEntries) {\n let raw: string;\n try {\n raw = await fs.readFile(path.join(locksDir, file), \"utf8\");\n } catch (readError: unknown) {\n if (isErrno(readError, \"ENOENT\")) {\n // Disappeared between readdir and readFile — treat as a ghost; skip quietly.\n continue;\n }\n scan.scanned += 1;\n scan.unreadable_lock_count += 1;\n continue;\n }\n scan.scanned += 1;\n const { detail } = classifyLockContent(file, raw, nowMs);\n if (detail === \"active\") {\n scan.active_lock_count += 1;\n } else if (detail === \"expired\") {\n scan.stale_lock_count += 1;\n } else {\n scan.unparseable_lock_count += 1;\n }\n }\n\n return scan;\n}\n\nexport async function runLockGc(pmRoot: string, options: LockGcOptions): Promise<LockGcResult> {\n const { dryRun, hooks } = options;\n const nowMs = options.now ?? Date.now();\n const locksDir = path.join(pmRoot, \"locks\");\n\n const result: LockGcResult = {\n scanned: 0,\n removed: [],\n retained: [],\n warnings: [],\n entries: [],\n };\n\n let dirEntries: string[];\n try {\n const raw = await fs.readdir(locksDir);\n dirEntries = raw.filter((f) => f.endsWith(\".lock\")).sort();\n } catch (error: unknown) {\n if (isErrno(error, \"ENOENT\")) {\n return result;\n }\n throw error;\n }\n\n for (const file of dirEntries) {\n result.scanned += 1;\n const absPath = path.join(locksDir, file);\n const relPath = `locks/${file}`;\n\n // --- onRead hook ---\n if (hooks?.onRead) {\n const hookWarnings = await hooks.onRead(absPath);\n result.warnings.push(...hookWarnings);\n }\n\n // --- read file ---\n let raw: string;\n try {\n raw = await fs.readFile(absPath, \"utf8\");\n } catch (readError: unknown) {\n if (isErrno(readError, \"ENOENT\")) {\n // Disappeared between readdir and readFile — treat as a ghost; skip quietly.\n result.scanned -= 1;\n continue;\n }\n result.warnings.push(`lock_unreadable:${file}`);\n result.retained.push(relPath);\n result.entries.push({\n file,\n id: null,\n owner: null,\n created_at: null,\n ttl_seconds: null,\n age_seconds: null,\n stale: false,\n reason: \"unparseable\",\n });\n continue;\n }\n\n // --- classify (shared with the read-only pm health locks scan) ---\n const classified = classifyLockContent(file, raw, nowMs);\n if (classified.detail === \"unparseable_json\") {\n result.warnings.push(`lock_unparseable:${file}`);\n result.retained.push(relPath);\n result.entries.push(classified.entry);\n continue;\n }\n if (classified.detail === \"invalid_timestamp\") {\n result.warnings.push(`lock_invalid_timestamp:${file}`);\n result.retained.push(relPath);\n result.entries.push(classified.entry);\n continue;\n }\n if (classified.detail === \"active\") {\n result.retained.push(relPath);\n result.entries.push(classified.entry);\n continue;\n }\n\n // --- stale: remove or preview ---\n if (!dryRun) {\n try {\n await fs.unlink(absPath);\n } catch (unlinkError: unknown) {\n if (!isErrno(unlinkError, \"ENOENT\")) {\n result.warnings.push(`lock_remove_failed:${file}`);\n result.retained.push(relPath);\n result.entries.push(classified.entry);\n continue;\n }\n // ENOENT on unlink = already gone (race); treat as removed\n }\n // onWrite hook after successful removal\n if (hooks?.onWrite) {\n const hookWarnings = await hooks.onWrite(absPath);\n result.warnings.push(...hookWarnings);\n }\n }\n\n result.removed.push(relPath);\n result.entries.push(classified.entry);\n }\n\n return result;\n}\n"],"names":[],"mappings":";;;AAWA,OAAO,QAAQ;AACf,OAAO,UAAU;AAgDjB,SAAS,UAAU,KAAW;AAC5B,MAAI;AACJ,MAAI;AACF,aAAS,KAAK,MAAM,GAAG;EACzB,QAAQ;AACN,WAAO;EACT;AACA,MAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,MAAM,QAAQ,MAAM,GAAG;AAC1E,WAAO;EACT;AACA,QAAM,YAAY;AAClB,QAAM,EAAE,IAAI,OAAO,YAAY,YAAW,IAAK;AAC/C,MACE,OAAO,OAAO,YACd,OAAO,UAAU,YACjB,OAAO,eAAe,YACtB,OAAO,gBAAgB,YACvB,CAAC,OAAO,SAAS,WAAW,GAC5B;AACA,WAAO;EACT;AACA,SAAO,EAAE,IAAI,OAAO,YAAY,YAAW;AAC7C;AAEA,SAAS,QAAQ,OAAgB,MAAY;AAC3C,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAA4B,SAAS;AAE1C;AAoBM,SAAU,oBAAoB,MAAc,KAAa,OAAa;AAC1E,QAAM,OAAO,UAAU,GAAG;AAC1B,MAAI,SAAS,MAAM;AACjB,WAAO;MACL,QAAQ;MACR,OAAO;QACL;QACA,IAAI;QACJ,OAAO;QACP,YAAY;QACZ,aAAa;QACb,aAAa;QACb,OAAO;QACP,QAAQ;;;EAGd;AACA,QAAM,cAAc,KAAK,MAAM,KAAK,UAAU;AAC9C,MAAI,CAAC,OAAO,SAAS,WAAW,GAAG;AACjC,WAAO;MACL,QAAQ;MACR,OAAO;QACL;QACA,IAAI,KAAK;QACT,OAAO,KAAK;QACZ,YAAY,KAAK;QACjB,aAAa,KAA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AC5B,aAAO,QAAQ,KAAK,WAAW,KAAK;AACpC;IACF;AACA,QAAI,WAAW,WAAW,qBAAqB;AAC7C,aAAO,SAAS,KAAK,0BAA0B,IAAI,EAAE;AACrD,aAAO,SAAS,KAAK,OAAO;AAC5B,aAAO,QAAQ,KAAK,WAAW,KAAK;AACpC;IACF;AACA,QAAI,WAAW,WAAW,UAAU;AAClC,aAAO,SAAS,KAAK,OAAO;AAC5B,aAAO,QAAQ,KAAK,WAAW,KAAK;AACpC;IACF;AAGA,QAAI,CAAC,QAAQ;AACX,UAAI;AACF,cAAM,GAAG,OAAO,OAAO;MACzB,SAAS,aAAsB;AAC7B,YAAI,CAAC,QAAQ,aAAa,QAAQ,GAAG;AACnC,iBAAO,SAAS,KAAK,sBAAsB,IAAI,EAAE;AACjD,iBAAO,SAAS,KAAK,OAAO;AAC5B,iBAAO,QAAQ,KAAK,WAAW,KAAK;AACpC;QACF;MAEF;AAEA,UAAI,OAAO,SAAS;AAClB,cAAM,eAAe,MAAM,MAAM,QAAQ,OAAO;AAChD,eAAO,SAAS,KAAK,GAAG,YAAY;MACtC;IACF;AAEA,WAAO,QAAQ,KAAK,OAAO;AAC3B,WAAO,QAAQ,KAAK,WAAW,KAAK;EACtC;AAEA,SAAO;AACT","debugId":"24d21b8b-52d9-5838-867f-b59f2e90d106"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6c6ef3fd-209c-57f0-9c48-93147244af26")}catch(e){}}();
|
|
3
3
|
import {
|
|
4
4
|
resolveAuthor
|
|
5
5
|
} from "./chunk-J27KIHTG.js";
|
|
@@ -152,6 +152,19 @@ async function expandAddGlobEntries(entries) {
|
|
|
152
152
|
}
|
|
153
153
|
return expanded;
|
|
154
154
|
}
|
|
155
|
+
function applyStandaloneNote(adds, note, hasAddFlags) {
|
|
156
|
+
if (note === void 0) {
|
|
157
|
+
return adds;
|
|
158
|
+
}
|
|
159
|
+
if (!hasAddFlags) {
|
|
160
|
+
throw new PmCliError("--note requires --add or --add-glob in the same invocation (the note annotates the links being added)", EXIT_CODE.USAGE);
|
|
161
|
+
}
|
|
162
|
+
const trimmed = note.trim();
|
|
163
|
+
if (trimmed.length === 0) {
|
|
164
|
+
return adds;
|
|
165
|
+
}
|
|
166
|
+
return adds.map((entry) => entry.note === void 0 ? { ...entry, note: trimmed } : entry);
|
|
167
|
+
}
|
|
155
168
|
function artifactKey(value) {
|
|
156
169
|
return `${value.path}::${value.scope}`;
|
|
157
170
|
}
|
|
@@ -232,7 +245,7 @@ async function runLinkedArtifacts(id, options, global, config) {
|
|
|
232
245
|
const parsedAdds = parseAddEntries(resolvedAdds, config.bareNoun);
|
|
233
246
|
const addGlobs = parseAddGlobEntries(resolvedAddGlobs);
|
|
234
247
|
const expandedGlobAdds = await expandAddGlobEntries(addGlobs);
|
|
235
|
-
const adds = [...parsedAdds, ...expandedGlobAdds];
|
|
248
|
+
const adds = applyStandaloneNote([...parsedAdds, ...expandedGlobAdds], options.note, parsedAdds.length > 0 || addGlobs.length > 0);
|
|
236
249
|
const removes = parseRemoveEntries(resolvedRemoves);
|
|
237
250
|
const migrations = parseMigrateEntries(resolvedMigrations);
|
|
238
251
|
const shouldMutate = adds.length > 0 || removes.length > 0 || migrations.length > 0;
|
|
@@ -341,6 +354,6 @@ export {
|
|
|
341
354
|
runLinkedArtifacts,
|
|
342
355
|
renameArtifactsResultKey
|
|
343
356
|
};
|
|
344
|
-
//# sourceMappingURL=chunk-
|
|
357
|
+
//# sourceMappingURL=chunk-KBPQHXWG.js.map
|
|
345
358
|
|
|
346
|
-
//# debugId=
|
|
359
|
+
//# debugId=6c6ef3fd-209c-57f0-9c48-93147244af26
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../cli/commands/linked-artifacts.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport fg from \"fast-glob\";\nimport { pathExists } from \"../../core/fs/fs-utils.js\";\nimport { getActiveExtensionRegistrations } from \"../../core/extensions/index.js\";\nimport { createStdinTokenResolver, parseCsvKv } from \"../../core/item/parse.js\";\nimport { resolveItemTypeRegistry } from \"../../core/item/type-registry.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { listAllFrontMatter, locateItem, mutateItem, readLocatedItem } from \"../../core/store/item-store.js\";\nimport { getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport { SCOPE_VALUES } from \"../../types/index.js\";\nimport { resolveAuthor } from \"../../core/shared/author.js\";\nimport type { LinkScope } from \"../../types/index.js\";\n\nexport type LinkedArtifact = {\n path: string;\n scope: LinkScope;\n note?: string;\n};\n\nexport interface LinkedArtifactCommandOptions {\n add?: string[];\n addGlob?: string[];\n remove?: string[];\n migrate?: string[];\n /**\n * GH-170 (pm-pfnx): standalone note applied to every link added by --add /\n * --add-glob in the same invocation. A per-entry embedded note (the\n * `path=...,note=...` pair syntax) takes precedence over this flag.\n * Requires at least one --add/--add-glob; rejected otherwise.\n */\n note?: string;\n list?: boolean;\n appendStable?: boolean;\n validatePaths?: boolean;\n audit?: boolean;\n author?: string;\n message?: string;\n force?: boolean;\n}\n\nexport interface PathMigration {\n from: string;\n to: string;\n}\n\nexport interface AddGlobEntry {\n pattern: string;\n scope: LinkScope;\n note?: string;\n}\n\nexport interface LinkedPathValidation {\n checked: number;\n existing_files: string[];\n missing_paths: string[];\n non_file_paths: string[];\n}\n\nexport interface LinkedPathAuditEntry {\n path: string;\n linked_by_count: number;\n linked_item_ids: string[];\n}\n\nexport interface LinkedArtifactResult {\n id: string;\n changed: boolean;\n count: number;\n migrations_applied?: number;\n validation?: LinkedPathValidation;\n audit?: LinkedPathAuditEntry[];\n artifacts: LinkedArtifact[];\n}\n\n/**\n * Configuration that adapts the shared linked-artifact command core to a\n * specific resource kind (files or docs) while preserving every behavioral\n * detail of the original twin implementations.\n */\nexport interface LinkedArtifactKindConfig {\n /** Metadata key under which the artifacts are stored (e.g. \"files\" | \"docs\"). */\n metadataKey: \"files\" | \"docs\";\n /** Mutation op recorded in history (e.g. \"files_add\" | \"docs_add\"). */\n op: \"files_add\" | \"docs_add\";\n /** Noun used in the \"bare <noun> path\" --add usage error (e.g. \"file\" | \"doc\"). */\n bareNoun: \"file\" | \"doc\";\n /**\n * Whether this kind honors the append-stable option. files supports it;\n * docs always sorts and must never expose append-stable behavior.\n */\n supportsAppendStable: boolean;\n}\n\nexport function ensureScope(raw: string | undefined): LinkScope {\n const value = (raw ?? \"project\") as LinkScope;\n if (!SCOPE_VALUES.includes(value)) {\n throw new PmCliError(\n `Invalid scope \"${raw}\". Valid scopes: ${SCOPE_VALUES.join(\", \")} (default: project).`,\n EXIT_CODE.USAGE,\n );\n }\n return value;\n}\n\nexport function looksLikeStructuredPathEntry(raw: string): boolean {\n if (raw.startsWith(\"```\") || raw.includes(\"\\n\")) {\n return true;\n }\n return /^(?:[-*+]\\s+)?(?:path|scope|note)\\s*[:=]/i.test(raw);\n}\n\nexport function parseAddEntries(raw: string[] | undefined, bareNoun: \"file\" | \"doc\"): LinkedArtifact[] {\n if (!raw) return [];\n return raw.map((entry) => {\n const trimmed = entry.trim();\n const kv = looksLikeStructuredPathEntry(trimmed) ? parseCsvKv(entry, \"--add\") : { path: trimmed };\n if (!kv.path) {\n throw new PmCliError(`--add requires path=<value> or a bare ${bareNoun} path`, EXIT_CODE.USAGE);\n }\n return {\n path: kv.path,\n scope: ensureScope(kv.scope),\n note: kv.note?.trim() || undefined,\n };\n });\n}\n\nexport function parseAddGlobEntries(raw: string[] | undefined): AddGlobEntry[] {\n if (!raw) return [];\n return raw.map((entry) => {\n const trimmed = entry.trim();\n if (!trimmed) {\n throw new PmCliError(\"--add-glob requires a glob pattern value\", EXIT_CODE.USAGE);\n }\n if (trimmed.includes(\"=\") || /^(?:[-*+]\\s+)?(?:pattern|glob|path)\\s*[:=]/i.test(trimmed) || trimmed.startsWith(\"```\")) {\n const kv = parseCsvKv(trimmed, \"--add-glob\");\n const pattern = kv.pattern?.trim() || kv.glob?.trim() || kv.path?.trim();\n if (!pattern) {\n throw new PmCliError(\"--add-glob key/value form requires pattern=<glob>\", EXIT_CODE.USAGE);\n }\n return {\n pattern,\n scope: ensureScope(kv.scope),\n note: kv.note?.trim() || undefined,\n };\n }\n return {\n pattern: trimmed,\n scope: \"project\",\n };\n });\n}\n\nexport function parseRemoveEntries(raw: string[] | undefined): string[] {\n if (!raw) return [];\n return raw.map((entry) => {\n const trimmed = entry.trim();\n if (!trimmed) {\n throw new PmCliError(\"--remove requires a path value\", EXIT_CODE.USAGE);\n }\n if (trimmed.includes(\"=\") || /^(?:[-*+]\\s+)?path\\s*[:=]/i.test(trimmed) || trimmed.startsWith(\"```\")) {\n const kv = parseCsvKv(trimmed, \"--remove\");\n if (!kv.path) {\n throw new PmCliError(\"--remove key/value form requires path=<value>\", EXIT_CODE.USAGE);\n }\n return kv.path;\n }\n return trimmed;\n });\n}\n\nexport function parseMigrateEntries(raw: string[] | undefined): PathMigration[] {\n if (!raw) return [];\n return raw.map((entry) => {\n const kv = parseCsvKv(entry, \"--migrate\");\n const from = kv.from?.trim();\n const to = kv.to?.trim();\n if (!from || !to) {\n throw new PmCliError(\"--migrate requires from=<value> and to=<value>\", EXIT_CODE.USAGE);\n }\n return { from, to };\n });\n}\n\nexport function applyPathMigrations(artifactPath: string, migrations: PathMigration[]): string {\n let next = artifactPath;\n for (const migration of migrations) {\n if (next.startsWith(migration.from)) {\n next = `${migration.to}${next.slice(migration.from.length)}`;\n }\n }\n return next;\n}\n\nexport function normalizeLinkedPath(value: string): string {\n return value.split(path.sep).join(\"/\");\n}\n\nexport async function expandAddGlobEntries(entries: AddGlobEntry[]): Promise<LinkedArtifact[]> {\n const expanded: LinkedArtifact[] = [];\n for (const entry of entries) {\n const absolutePattern = path.isAbsolute(entry.pattern);\n const matches = await fg(entry.pattern, {\n cwd: process.cwd(),\n absolute: absolutePattern,\n onlyFiles: true,\n dot: true,\n unique: true,\n followSymbolicLinks: true,\n });\n const sortedMatches = [...new Set(matches.map((match) => normalizeLinkedPath(path.normalize(match))))].sort((left, right) =>\n left.localeCompare(right),\n );\n for (const matchedPath of sortedMatches) {\n expanded.push({\n path: matchedPath,\n scope: entry.scope,\n note: entry.note,\n });\n }\n }\n return expanded;\n}\n\n/**\n * GH-170 (pm-pfnx): apply a standalone --note to the links added in this\n * invocation. Semantics (documented on pm-pfnx): the note is attached to EVERY\n * entry added via --add/--add-glob so a single flag annotates the whole batch\n * predictably; a per-entry embedded `note=` wins over the standalone flag; and\n * --note without any --add/--add-glob flag is a usage error because there is\n * nothing to annotate (it never retro-edits existing links). `hasAddFlags`\n * reflects flag presence, not match count, so a glob that legitimately matches\n * zero files is not an error.\n */\nexport function applyStandaloneNote(\n adds: LinkedArtifact[],\n note: string | undefined,\n hasAddFlags: boolean,\n): LinkedArtifact[] {\n if (note === undefined) {\n return adds;\n }\n if (!hasAddFlags) {\n throw new PmCliError(\n \"--note requires --add or --add-glob in the same invocation (the note annotates the links being added)\",\n EXIT_CODE.USAGE,\n );\n }\n const trimmed = note.trim();\n if (trimmed.length === 0) {\n return adds;\n }\n return adds.map((entry) => (entry.note === undefined ? { ...entry, note: trimmed } : entry));\n}\n\nexport function artifactKey(value: Pick<LinkedArtifact, \"path\" | \"scope\">): string {\n return `${value.path}::${value.scope}`;\n}\n\nexport function sortLinkedArtifacts(artifacts: LinkedArtifact[]): LinkedArtifact[] {\n return [...artifacts].sort((left, right) => {\n const byPath = left.path.localeCompare(right.path);\n if (byPath !== 0) return byPath;\n return left.scope.localeCompare(right.scope);\n });\n}\n\nexport function dedupeLinkedArtifacts(artifacts: LinkedArtifact[]): LinkedArtifact[] {\n return [...new Map(artifacts.map((entry) => [artifactKey(entry), entry])).values()].map((entry) => ({\n ...entry,\n note: entry.note?.trim() || undefined,\n }));\n}\n\nexport async function validateLinkedPaths(paths: string[]): Promise<LinkedPathValidation> {\n const uniquePaths = [...new Set(paths)].sort((left, right) => left.localeCompare(right));\n const existingFiles: string[] = [];\n const missingPaths: string[] = [];\n const nonFilePaths: string[] = [];\n for (const relativePath of uniquePaths) {\n const resolvedPath = path.isAbsolute(relativePath) ? relativePath : path.resolve(process.cwd(), relativePath);\n try {\n const stats = await fs.stat(resolvedPath);\n if (stats.isFile()) {\n existingFiles.push(relativePath);\n } else {\n nonFilePaths.push(relativePath);\n }\n } catch (error: unknown) {\n if (typeof error === \"object\" && error !== null && \"code\" in error && (error as { code?: string }).code === \"ENOENT\") {\n missingPaths.push(relativePath);\n continue;\n }\n nonFilePaths.push(relativePath);\n }\n }\n return {\n checked: uniquePaths.length,\n existing_files: existingFiles,\n missing_paths: missingPaths,\n non_file_paths: nonFilePaths,\n };\n}\n\nexport function buildLinkedPathAudit(\n paths: string[],\n allItems: Array<{ id: string; artifacts?: LinkedArtifact[] }>,\n): LinkedPathAuditEntry[] {\n const index = new Map<string, Set<string>>();\n for (const item of allItems) {\n for (const linkedArtifact of item.artifacts ?? []) {\n const seen = index.get(linkedArtifact.path) ?? new Set<string>();\n seen.add(item.id);\n index.set(linkedArtifact.path, seen);\n }\n }\n return [...new Set(paths)]\n .sort((left, right) => left.localeCompare(right))\n .map((linkedPath) => {\n const linkedIds = [...(index.get(linkedPath) ?? new Set<string>())].sort((left, right) => left.localeCompare(right));\n return {\n path: linkedPath,\n linked_by_count: linkedIds.length,\n linked_item_ids: linkedIds,\n };\n });\n}\n\n/**\n * Shared linked-artifact list/mutate command core used by runFiles and runDocs.\n * The kind config selects metadata key, op, bare-path noun, and whether\n * append-stable ordering is honored, preserving each twin's exact semantics.\n */\nexport async function runLinkedArtifacts(\n id: string,\n options: LinkedArtifactCommandOptions,\n global: GlobalOptions,\n config: LinkedArtifactKindConfig,\n): Promise<LinkedArtifactResult> {\n const { metadataKey } = config;\n const stdinResolver = createStdinTokenResolver();\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());\n const resolvedAdds = await stdinResolver.resolveList(options.add, \"--add\");\n const resolvedAddGlobs = await stdinResolver.resolveList(options.addGlob, \"--add-glob\");\n const resolvedRemoves = await stdinResolver.resolveList(options.remove, \"--remove\");\n const resolvedMigrations = await stdinResolver.resolveList(options.migrate, \"--migrate\");\n const parsedAdds = parseAddEntries(resolvedAdds, config.bareNoun);\n const addGlobs = parseAddGlobEntries(resolvedAddGlobs);\n const expandedGlobAdds = await expandAddGlobEntries(addGlobs);\n const adds = applyStandaloneNote(\n [...parsedAdds, ...expandedGlobAdds],\n options.note,\n parsedAdds.length > 0 || addGlobs.length > 0,\n );\n const removes = parseRemoveEntries(resolvedRemoves);\n const migrations = parseMigrateEntries(resolvedMigrations);\n const shouldMutate = adds.length > 0 || removes.length > 0 || migrations.length > 0;\n\n const collectAuditItems = async (): Promise<Array<{ id: string; artifacts?: LinkedArtifact[] }>> =>\n (await listAllFrontMatter(pmRoot, settings.item_format, typeRegistry.type_to_folder, undefined, settings.schema)).map((entry) => ({\n id: entry.id,\n artifacts: (entry as Record<string, unknown>)[metadataKey] as LinkedArtifact[] | undefined,\n }));\n\n if (!shouldMutate) {\n const located = await locateItem(pmRoot, id, settings.id_prefix, settings.item_format, typeRegistry.type_to_folder);\n if (!located) {\n throw new PmCliError(`Item ${id} not found`, EXIT_CODE.NOT_FOUND);\n }\n const loaded = await readLocatedItem(located, { schema: settings.schema });\n const artifacts = ((loaded.document.metadata as Record<string, unknown>)[metadataKey] as LinkedArtifact[] | undefined) ?? [];\n return {\n id: located.id,\n artifacts,\n changed: false,\n count: artifacts.length,\n validation: options.validatePaths ? await validateLinkedPaths(artifacts.map((entry) => entry.path)) : undefined,\n audit: options.audit ? buildLinkedPathAudit(artifacts.map((entry) => entry.path), await collectAuditItems()) : undefined,\n };\n }\n\n const author = resolveAuthor(options.author, settings.author_default);\n const result = await mutateItem({\n pmRoot,\n settings,\n id,\n op: config.op,\n author,\n message: options.message,\n force: options.force,\n mutate(document) {\n const metadata = document.metadata as Record<string, unknown>;\n const next = [...((metadata[metadataKey] as LinkedArtifact[] | undefined) ?? [])];\n let migrationCount = 0;\n if (migrations.length > 0) {\n for (let index = 0; index < next.length; index += 1) {\n const migratedPath = applyPathMigrations(next[index].path, migrations);\n if (migratedPath !== next[index].path) {\n next[index] = { ...next[index], path: migratedPath };\n migrationCount += 1;\n }\n }\n }\n const migratedAdds = adds.map((entry) => {\n const migratedPath = applyPathMigrations(entry.path, migrations);\n if (migratedPath !== entry.path) {\n migrationCount += 1;\n }\n return {\n ...entry,\n path: migratedPath,\n };\n });\n const migratedRemoves = removes.map((entry) => applyPathMigrations(entry, migrations));\n for (const add of migratedAdds) {\n const exists = next.some((entry) => entry.path === add.path && entry.scope === add.scope);\n if (!exists) {\n next.push(add);\n }\n }\n if (migratedRemoves.length > 0) {\n for (let i = next.length - 1; i >= 0; i -= 1) {\n if (migratedRemoves.includes(next[i].path)) {\n next.splice(i, 1);\n }\n }\n }\n const deduped = dedupeLinkedArtifacts(next);\n const normalized = config.supportsAppendStable && options.appendStable ? deduped : sortLinkedArtifacts(deduped);\n if (normalized.length > 0) {\n metadata[metadataKey] = normalized;\n } else {\n delete metadata[metadataKey];\n }\n return { changedFields: [metadataKey], warnings: migrationCount > 0 ? [`path_migrations_applied:${migrationCount}`] : [] };\n },\n });\n\n const artifacts = ((result.item as Record<string, unknown>)[metadataKey] as LinkedArtifact[] | undefined) ?? [];\n const migrationWarning = result.warnings.find((warning) => warning.startsWith(\"path_migrations_applied:\"));\n const migrationCount = migrationWarning ? Number(migrationWarning.slice(\"path_migrations_applied:\".length)) : 0;\n const allItems = options.audit ? await collectAuditItems() : [];\n return {\n id: result.item.id,\n artifacts,\n changed: true,\n count: artifacts.length,\n migrations_applied: migrationCount > 0 ? migrationCount : undefined,\n validation: options.validatePaths ? await validateLinkedPaths(artifacts.map((entry) => entry.path)) : undefined,\n audit: options.audit ? buildLinkedPathAudit(artifacts.map((entry) => entry.path), allItems) : undefined,\n };\n}\n\n/**\n * Re-key the generic `artifacts` field to the resource-specific name (files/docs)\n * while preserving the original key order and presence so kind-specific result\n * shapes (and their deterministic JSON key ordering) stay byte-identical.\n */\nexport function renameArtifactsResultKey(result: LinkedArtifactResult, key: \"files\" | \"docs\"): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [field, value] of Object.entries(result)) {\n out[field === \"artifacts\" ? key : field] = value;\n }\n return out;\n}\n"],"names":["artifacts","migrationCount"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,QAAQ;AA+FT,SAAU,YAAY,KAAuB;AACjD,QAAM,QAAS,OAAO;AACtB,MAAI,CAAC,aAAa,SAAS,KAAK,GAAG;AACjC,UAAM,IAAI,WACR,kBAAkB,GAAG,oBAAoB,aAAa,KAAK,IAAI,CAAC,wBAChE,UAAU,KAAK;EAEnB;AACA,SAAO;AACT;AAEM,SAAU,6BAA6B,KAAW;AACtD,MAAI,IAAI,WAAW,KAAK,KAAK,IAAI,SAAS,IAAI,GAAG;AAC/C,WAAO;EACT;AACA,SAAO,4CAA4C,KAAK,GAAG;AAC7D;AAEM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AAI;IACtG,OAAO,QAAQ,QAAQ,qBAAqB,UAAU,IAAI,CAAC,UAAU,MAAM,IAAI,GAAG,QAAQ,IAAI;;AAElG;AAOM,SAAU,yBAAyB,QAA8B,KAAqB;AAC1F,QAAM,MAA+B,CAAA;AACrC,aAAW,CAAC,OAAO,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACnD,QAAI,UAAU,cAAc,MAAM,KAAK,IAAI;EAC7C;AACA,SAAO;AACT","debugId":"6c6ef3fd-209c-57f0-9c48-93147244af26"}
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
parseTests,
|
|
19
19
|
parseTypeOptionEntries,
|
|
20
20
|
resolvePriority
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-AX4GEVQC.js";
|
|
22
22
|
import {
|
|
23
23
|
applyTagRemovals,
|
|
24
24
|
createStdinTokenResolver,
|
|
@@ -1711,4 +1711,4 @@ async function runUpdate(id, options, global2) {
|
|
|
1711
1711
|
export {
|
|
1712
1712
|
runUpdate
|
|
1713
1713
|
};
|
|
1714
|
-
//# sourceMappingURL=chunk-
|
|
1714
|
+
//# sourceMappingURL=chunk-L5EPZQIC.js.map
|