@brucewaynedecoy/make-docs 1.0.0-rc.1 → 2.0.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/LICENSE +21 -201
- package/README.md +36 -27
- package/dist/backup-73HQNKMC.js +20 -0
- package/dist/backup-73HQNKMC.js.map +1 -0
- package/dist/chunk-3BAJQXGH.js +1575 -0
- package/dist/chunk-3BAJQXGH.js.map +1 -0
- package/dist/chunk-64CTKJO7.js +4136 -0
- package/dist/chunk-64CTKJO7.js.map +1 -0
- package/dist/chunk-BENO4IH5.js +875 -0
- package/dist/chunk-BENO4IH5.js.map +1 -0
- package/dist/chunk-D4HDZEJT.js +37 -0
- package/dist/chunk-D4HDZEJT.js.map +1 -0
- package/dist/chunk-G5EF63GG.js +1291 -0
- package/dist/chunk-G5EF63GG.js.map +1 -0
- package/dist/chunk-GNP6HRVP.js +523 -0
- package/dist/chunk-GNP6HRVP.js.map +1 -0
- package/dist/chunk-HJYIQTMD.js +204 -0
- package/dist/chunk-HJYIQTMD.js.map +1 -0
- package/dist/chunk-LQ5NSWCJ.js +39 -0
- package/dist/chunk-LQ5NSWCJ.js.map +1 -0
- package/dist/chunk-LRVV7UDD.js +2340 -0
- package/dist/chunk-LRVV7UDD.js.map +1 -0
- package/dist/chunk-LVQSJF63.js +24674 -0
- package/dist/chunk-LVQSJF63.js.map +1 -0
- package/dist/chunk-MXBHCHSM.js +13995 -0
- package/dist/chunk-MXBHCHSM.js.map +1 -0
- package/dist/chunk-Z5K4FHYP.js +922 -0
- package/dist/chunk-Z5K4FHYP.js.map +1 -0
- package/dist/index.js +3798 -250
- package/dist/index.js.map +1 -1
- package/dist/self-YYXOLDKU.js +653 -0
- package/dist/self-YYXOLDKU.js.map +1 -0
- package/dist/server-O2ZELIMX.js +512 -0
- package/dist/server-O2ZELIMX.js.map +1 -0
- package/dist/setup-system-HZROFNMP.js +544 -0
- package/dist/setup-system-HZROFNMP.js.map +1 -0
- package/dist/{skills-command-3ESCZ75U.js → skills-command-MGGHY7HU.js} +190 -32
- package/dist/skills-command-MGGHY7HU.js.map +1 -0
- package/dist/uninstall-3UXXXNFO.js +223 -0
- package/dist/uninstall-3UXXXNFO.js.map +1 -0
- package/dist/virtual_make-docs-first-party-skills-ZII74YOB.js +11 -0
- package/dist/virtual_make-docs-first-party-skills-ZII74YOB.js.map +1 -0
- package/package.json +9 -6
- package/skill-registry.json +328 -125
- package/skill-registry.schema.json +221 -45
- package/template/.make-docs/AGENTS.md +18 -0
- package/template/.make-docs/CLAUDE.md +18 -0
- package/template/.make-docs/archive/AGENTS.md +11 -0
- package/template/.make-docs/archive/CLAUDE.md +11 -0
- package/template/.make-docs/system/AGENTS.md +12 -0
- package/template/.make-docs/system/CLAUDE.md +12 -0
- package/template/.make-docs/system/contracts/AGENTS.md +13 -0
- package/template/.make-docs/system/contracts/CLAUDE.md +13 -0
- package/template/{docs/assets/references → .make-docs/system/contracts}/commit-message-convention.md +4 -4
- package/template/.make-docs/system/contracts/coverage-pass-contract.md +198 -0
- package/template/.make-docs/system/contracts/deferred-obligation-contract.md +128 -0
- package/template/{docs/assets/references → .make-docs/system/contracts}/design-contract.md +7 -2
- package/template/{docs/assets/references → .make-docs/system/contracts}/guide-contract.md +21 -19
- package/template/{docs/assets/references → .make-docs/system/contracts}/history-record-contract.md +17 -11
- package/template/.make-docs/system/contracts/human-experience-contract.md +134 -0
- package/template/.make-docs/system/contracts/naive-uat-contract.md +231 -0
- package/template/.make-docs/system/contracts/output-contract.md +277 -0
- package/template/.make-docs/system/contracts/performance-evidence-governance.md +257 -0
- package/template/.make-docs/system/contracts/system-resource-contract.md +93 -0
- package/template/.make-docs/system/prompts/AGENTS.md +12 -0
- package/template/.make-docs/system/prompts/CLAUDE.md +12 -0
- package/template/.make-docs/system/prompts/coverage-pass-maintainer-guide.prompt.md +20 -0
- package/template/.make-docs/system/prompts/coverage-pass-prd-reconciliation.prompt.md +18 -0
- package/template/.make-docs/system/prompts/coverage-pass-testing-uat.prompt.md +46 -0
- package/template/.make-docs/system/prompts/coverage-pass-user-guide.prompt.md +20 -0
- package/template/.make-docs/system/prompts/designs-to-plan-change.prompt.md +18 -0
- package/template/.make-docs/system/prompts/designs-to-plan.prompt.md +14 -0
- package/template/.make-docs/system/prompts/docs-path-hygiene-cleanup.prompt.md +29 -0
- package/template/.make-docs/system/prompts/naive-uat-facilitator.prompt.md +28 -0
- package/template/.make-docs/system/prompts/naive-uat-tester.prompt.md +20 -0
- package/template/.make-docs/system/prompts/performance-coverage.prompt.md +63 -0
- package/template/.make-docs/system/prompts/plan-to-prd-change.prompt.md +12 -0
- package/template/.make-docs/system/prompts/plan-to-prd-green-field.prompt.md +10 -0
- package/template/.make-docs/system/prompts/prd-change-to-work.prompt.md +14 -0
- package/template/.make-docs/system/prompts/prd-to-work-full-prd.prompt.md +10 -0
- package/template/.make-docs/system/prompts/prd-to-work-prd-feature.prompt.md +10 -0
- package/template/.make-docs/system/prompts/request-to-design.prompt.md +20 -0
- package/template/.make-docs/system/prompts/session-to-history-record.prompt.md +23 -0
- package/template/{docs/assets → .make-docs/system}/prompts/work-to-commit-message.prompt.md +2 -2
- package/template/.make-docs/system/prompts/work-to-guides.prompt.md +22 -0
- package/template/.make-docs/system/references/AGENTS.md +14 -0
- package/template/.make-docs/system/references/CLAUDE.md +14 -0
- package/template/{docs/assets → .make-docs/system}/references/design-workflow.md +15 -2
- package/template/.make-docs/system/references/execution-workflow.md +189 -0
- package/template/.make-docs/system/references/human-experience.md +138 -0
- package/template/.make-docs/system/references/lifecycle.md +153 -0
- package/template/.make-docs/system/references/naive-uat-validation.md +65 -0
- package/template/.make-docs/system/references/naive-uat-workflow.md +64 -0
- package/template/.make-docs/system/references/path-and-link-hygiene.md +101 -0
- package/template/.make-docs/system/references/performance-evidence.md +114 -0
- package/template/.make-docs/system/references/planning-workflow.md +209 -0
- package/template/.make-docs/system/references/prd-change-management.md +165 -0
- package/template/{docs/assets → .make-docs/system}/references/wave-model.md +10 -8
- package/template/.make-docs/system/templates/AGENTS.md +12 -0
- package/template/.make-docs/system/templates/CLAUDE.md +12 -0
- package/template/.make-docs/system/templates/design.md +79 -0
- package/template/{docs/assets/templates/guide-developer.md → .make-docs/system/templates/guide-maintainer.md} +7 -3
- package/template/{docs/assets → .make-docs/system}/templates/guide-user.md +6 -2
- package/template/{docs/assets → .make-docs/system}/templates/history-record.md +6 -3
- package/template/.make-docs/system/templates/naive-uat-scenario.md +91 -0
- package/template/.make-docs/system/templates/performance-evidence-profile.md +252 -0
- package/template/.make-docs/system/templates/plan-overview.md +76 -0
- package/template/.make-docs/system/templates/plan-prd-change.md +155 -0
- package/template/{docs/assets → .make-docs/system}/templates/plan-prd-decompose.md +10 -0
- package/template/{docs/assets → .make-docs/system}/templates/plan-prd.md +28 -2
- package/template/{docs/assets → .make-docs/system}/templates/prd-architecture.md +13 -0
- package/template/.make-docs/system/templates/prd-glossary.md +28 -0
- package/template/.make-docs/system/templates/prd-index.md +70 -0
- package/template/{docs/assets → .make-docs/system}/templates/prd-overview.md +13 -0
- package/template/.make-docs/system/templates/prd-reference.md +30 -0
- package/template/{docs/assets → .make-docs/system}/templates/prd-risk-register.md +16 -1
- package/template/{docs/assets → .make-docs/system}/templates/prd-subsystem.md +15 -0
- package/template/.make-docs/system/templates/work-index.md +58 -0
- package/template/.make-docs/system/templates/work-phase.md +107 -0
- package/template/.make-docs/system-resources.catalog.json +91 -0
- package/template/.make-docs/system-resources.schema.json +204 -0
- package/template/AGENTS.md +8 -1
- package/template/CLAUDE.md +8 -1
- package/template/docs/AGENTS.codex-only.md +22 -0
- package/template/docs/AGENTS.md +21 -13
- package/template/docs/CLAUDE.claude-only.md +22 -0
- package/template/docs/CLAUDE.md +21 -13
- package/template/docs/assets/AGENTS.md +11 -7
- package/template/docs/assets/CLAUDE.md +11 -7
- package/template/docs/designs/AGENTS.md +8 -3
- package/template/docs/designs/CLAUDE.md +8 -3
- package/template/docs/plans/AGENTS.md +10 -3
- package/template/docs/plans/CLAUDE.md +10 -3
- package/template/docs/prd/AGENTS.md +14 -4
- package/template/docs/prd/CLAUDE.md +14 -4
- package/template/docs/work/AGENTS.md +10 -3
- package/template/docs/work/CLAUDE.md +10 -3
- package/dist/chunk-HP3HBG7F.js +0 -626
- package/dist/chunk-HP3HBG7F.js.map +0 -1
- package/dist/chunk-QRFH4J6H.js +0 -1194
- package/dist/chunk-QRFH4J6H.js.map +0 -1
- package/dist/chunk-WM3OXYTW.js +0 -2630
- package/dist/chunk-WM3OXYTW.js.map +0 -1
- package/dist/skills-command-3ESCZ75U.js.map +0 -1
- package/dist/uninstall-GQE4SJF2.js +0 -150
- package/dist/uninstall-GQE4SJF2.js.map +0 -1
- package/template/.make-docs/scripts/check_path_hygiene.py +0 -435
- package/template/docs/assets/archive/AGENTS.md +0 -20
- package/template/docs/assets/archive/CLAUDE.md +0 -20
- package/template/docs/assets/history/AGENTS.md +0 -12
- package/template/docs/assets/history/CLAUDE.md +0 -12
- package/template/docs/assets/prompts/AGENTS.md +0 -8
- package/template/docs/assets/prompts/CLAUDE.md +0 -8
- package/template/docs/assets/prompts/designs-to-plan-change.prompt.md +0 -14
- package/template/docs/assets/prompts/designs-to-plan.prompt.md +0 -10
- package/template/docs/assets/prompts/docs-path-hygiene-cleanup.prompt.md +0 -27
- package/template/docs/assets/prompts/plan-to-prd-change.prompt.md +0 -8
- package/template/docs/assets/prompts/plan-to-prd-green-field.prompt.md +0 -6
- package/template/docs/assets/prompts/prd-change-to-work.prompt.md +0 -10
- package/template/docs/assets/prompts/prd-to-work-full-prd.prompt.md +0 -6
- package/template/docs/assets/prompts/prd-to-work-prd-feature.prompt.md +0 -6
- package/template/docs/assets/prompts/request-to-design.prompt.md +0 -16
- package/template/docs/assets/prompts/session-to-history-record.prompt.md +0 -19
- package/template/docs/assets/prompts/work-to-guides.prompt.md +0 -18
- package/template/docs/assets/references/AGENTS.md +0 -9
- package/template/docs/assets/references/CLAUDE.md +0 -9
- package/template/docs/assets/references/execution-workflow.md +0 -157
- package/template/docs/assets/references/output-contract.md +0 -221
- package/template/docs/assets/references/path-and-link-hygiene.md +0 -49
- package/template/docs/assets/references/planning-workflow.md +0 -160
- package/template/docs/assets/references/prd-change-management.md +0 -129
- package/template/docs/assets/templates/AGENTS.md +0 -8
- package/template/docs/assets/templates/CLAUDE.md +0 -8
- package/template/docs/assets/templates/design.md +0 -30
- package/template/docs/assets/templates/plan-overview.md +0 -32
- package/template/docs/assets/templates/plan-prd-change.md +0 -99
- package/template/docs/assets/templates/prd-change-addition.md +0 -45
- package/template/docs/assets/templates/prd-change-revision.md +0 -45
- package/template/docs/assets/templates/prd-glossary.md +0 -15
- package/template/docs/assets/templates/prd-index.md +0 -45
- package/template/docs/assets/templates/prd-reference.md +0 -17
- package/template/docs/assets/templates/work-index.md +0 -21
- package/template/docs/assets/templates/work-phase.md +0 -34
- package/template/docs/guides/AGENTS.md +0 -15
- package/template/docs/guides/CLAUDE.md +0 -15
- /package/template/{docs/assets → .make-docs/system}/prompts/update-readme-green-field.prompt.md +0 -0
- /package/template/{docs/assets → .make-docs/system}/references/harness-capability-matrix.md +0 -0
|
@@ -0,0 +1,1575 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
NO_ACCESS,
|
|
4
|
+
fingerprintEntry,
|
|
5
|
+
getFirstPartyHarnessAdapter,
|
|
6
|
+
validateHarnessMethodSelection
|
|
7
|
+
} from "./chunk-LRVV7UDD.js";
|
|
8
|
+
import {
|
|
9
|
+
CURRENT_STORE_SCHEMA_VERSION,
|
|
10
|
+
GLOBAL_CONFIG_FILE,
|
|
11
|
+
GLOBAL_MANIFEST_FILE,
|
|
12
|
+
STORE_DATABASE_FILE,
|
|
13
|
+
StoreSchemaNewerError,
|
|
14
|
+
StoreUnavailableError,
|
|
15
|
+
acquireStoreAccess,
|
|
16
|
+
canonicalInstallationPath,
|
|
17
|
+
classifyStoreCheckpoint9State,
|
|
18
|
+
getGlobalConfigPath,
|
|
19
|
+
getGlobalManifestPath,
|
|
20
|
+
getManifestPath,
|
|
21
|
+
getStoreDatabasePath,
|
|
22
|
+
listMigrationState,
|
|
23
|
+
loadManifest,
|
|
24
|
+
openStoreDatabase,
|
|
25
|
+
openStoreSqliteConnection,
|
|
26
|
+
platform,
|
|
27
|
+
readDeclarativeProjectId,
|
|
28
|
+
readMigrationState,
|
|
29
|
+
recordMigrationState,
|
|
30
|
+
resolveStoreRoot,
|
|
31
|
+
validateInstallationStoreRoot,
|
|
32
|
+
withInstallationDatabase
|
|
33
|
+
} from "./chunk-MXBHCHSM.js";
|
|
34
|
+
|
|
35
|
+
// src/store/global-config.ts
|
|
36
|
+
import { existsSync, readFileSync } from "fs";
|
|
37
|
+
|
|
38
|
+
// src/store/json-files.ts
|
|
39
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
40
|
+
import path from "path";
|
|
41
|
+
function writeStoreJsonFile(filePath, value) {
|
|
42
|
+
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
43
|
+
const tempPath = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
44
|
+
writeFileSync(tempPath, `${JSON.stringify(value, null, 2)}
|
|
45
|
+
`, "utf8");
|
|
46
|
+
platform.atomicReplace(tempPath, filePath);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/store/global-config.ts
|
|
50
|
+
var GLOBAL_CONFIG_SCHEMA_VERSION = 1;
|
|
51
|
+
var DEFAULT_GLOBAL_CONFIG_SETTINGS = {
|
|
52
|
+
selfUpdate: "prompt",
|
|
53
|
+
marketplaceAutoRegistration: false,
|
|
54
|
+
harnesses: {}
|
|
55
|
+
};
|
|
56
|
+
var DEFAULT_HARNESS_ACCESS_CEILING = Object.freeze({
|
|
57
|
+
store: "write",
|
|
58
|
+
project: "write",
|
|
59
|
+
hostConfig: "none"
|
|
60
|
+
});
|
|
61
|
+
function defaultGlobalConfig() {
|
|
62
|
+
return {
|
|
63
|
+
schemaVersion: GLOBAL_CONFIG_SCHEMA_VERSION,
|
|
64
|
+
settings: { ...DEFAULT_GLOBAL_CONFIG_SETTINGS, harnesses: {} }
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function loadGlobalConfig(storeRoot) {
|
|
68
|
+
const configPath = getGlobalConfigPath(storeRoot);
|
|
69
|
+
const warnings = [];
|
|
70
|
+
if (!existsSync(configPath)) {
|
|
71
|
+
return {
|
|
72
|
+
config: defaultGlobalConfig(),
|
|
73
|
+
path: configPath,
|
|
74
|
+
loadedFromDisk: false,
|
|
75
|
+
warnings
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
let raw;
|
|
79
|
+
try {
|
|
80
|
+
raw = JSON.parse(readFileSync(configPath, "utf8"));
|
|
81
|
+
} catch (error) {
|
|
82
|
+
warnings.push(
|
|
83
|
+
`Global config at ${configPath} is not valid JSON (${toMessage(error)}); using defaults. This is recoverable operational state, not project data.`
|
|
84
|
+
);
|
|
85
|
+
return {
|
|
86
|
+
config: defaultGlobalConfig(),
|
|
87
|
+
path: configPath,
|
|
88
|
+
loadedFromDisk: false,
|
|
89
|
+
warnings
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
config: normalizeGlobalConfig(raw, configPath, warnings),
|
|
94
|
+
path: configPath,
|
|
95
|
+
loadedFromDisk: true,
|
|
96
|
+
warnings
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function writeGlobalConfig(storeRoot, config) {
|
|
100
|
+
const configPath = getGlobalConfigPath(storeRoot);
|
|
101
|
+
writeStoreJsonFile(configPath, config);
|
|
102
|
+
return configPath;
|
|
103
|
+
}
|
|
104
|
+
function normalizeGlobalConfig(raw, configPath, warnings) {
|
|
105
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
106
|
+
warnings.push(
|
|
107
|
+
`Global config at ${configPath} is not a JSON object; using defaults.`
|
|
108
|
+
);
|
|
109
|
+
return defaultGlobalConfig();
|
|
110
|
+
}
|
|
111
|
+
const record2 = raw;
|
|
112
|
+
const settingsRaw = typeof record2.settings === "object" && record2.settings !== null && !Array.isArray(record2.settings) ? record2.settings : {};
|
|
113
|
+
const settings = {
|
|
114
|
+
...settingsRaw,
|
|
115
|
+
...DEFAULT_GLOBAL_CONFIG_SETTINGS,
|
|
116
|
+
harnesses: {}
|
|
117
|
+
};
|
|
118
|
+
const selfUpdate = settingsRaw.selfUpdate;
|
|
119
|
+
if (selfUpdate === "prompt" || selfUpdate === "auto" || selfUpdate === "off") {
|
|
120
|
+
settings.selfUpdate = selfUpdate;
|
|
121
|
+
} else if (selfUpdate !== void 0) {
|
|
122
|
+
warnings.push(
|
|
123
|
+
`Global config setting "selfUpdate" has unsupported value ${JSON.stringify(selfUpdate)}; using "${DEFAULT_GLOBAL_CONFIG_SETTINGS.selfUpdate}".`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
const marketplaceAutoRegistration = settingsRaw.marketplaceAutoRegistration;
|
|
127
|
+
if (typeof marketplaceAutoRegistration === "boolean") {
|
|
128
|
+
settings.marketplaceAutoRegistration = marketplaceAutoRegistration;
|
|
129
|
+
} else if (marketplaceAutoRegistration !== void 0) {
|
|
130
|
+
warnings.push(
|
|
131
|
+
'Global config setting "marketplaceAutoRegistration" must be a boolean; using the default (false).'
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const harnesses = settingsRaw.harnesses;
|
|
135
|
+
if (harnesses !== void 0) {
|
|
136
|
+
if (typeof harnesses !== "object" || harnesses === null || Array.isArray(harnesses)) {
|
|
137
|
+
warnings.push(
|
|
138
|
+
'Global config setting "harnesses" must be an object; using no selected harnesses.'
|
|
139
|
+
);
|
|
140
|
+
} else {
|
|
141
|
+
for (const [harness, value] of Object.entries(harnesses)) {
|
|
142
|
+
if (!/^[a-z][a-z0-9-]*$/.test(harness)) {
|
|
143
|
+
warnings.push(`Global config harness ${JSON.stringify(harness)} is not a safe identifier; it was ignored.`);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
147
|
+
warnings.push(`Global config harness "${harness}" must be an object; it was ignored.`);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const intent = value;
|
|
151
|
+
const selected = intent.selected;
|
|
152
|
+
const maximumMethod = intent.maximumMethod;
|
|
153
|
+
if (typeof selected !== "boolean") {
|
|
154
|
+
warnings.push(`Global config harness "${harness}" must declare a boolean selected value; it was ignored.`);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (maximumMethod !== null && (typeof maximumMethod !== "string" || !/^[a-z][a-z0-9-]*$/.test(maximumMethod))) {
|
|
158
|
+
warnings.push(`Global config harness "${harness}" has an unsafe maximumMethod; it was ignored.`);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (selected && maximumMethod === null) {
|
|
162
|
+
warnings.push(`Global config harness "${harness}" is selected but has no maximumMethod; it was ignored.`);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const adapter = getFirstPartyHarnessAdapter(harness);
|
|
166
|
+
if (adapter && maximumMethod !== null) {
|
|
167
|
+
try {
|
|
168
|
+
validateHarnessMethodSelection({
|
|
169
|
+
harnessId: harness,
|
|
170
|
+
method: maximumMethod
|
|
171
|
+
});
|
|
172
|
+
} catch (error) {
|
|
173
|
+
warnings.push(`Global config harness "${harness}" has an unsupported maximumMethod (${toMessage(error)}); it was ignored.`);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (selected && maximumMethod === "none") {
|
|
178
|
+
warnings.push(`Global config harness "${harness}" is selected but maximumMethod is none; it was ignored.`);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const accessCeiling = normalizeHarnessAccessCeiling(
|
|
182
|
+
intent.accessCeiling,
|
|
183
|
+
selected ? DEFAULT_HARNESS_ACCESS_CEILING : NO_ACCESS,
|
|
184
|
+
configPath,
|
|
185
|
+
harness,
|
|
186
|
+
warnings
|
|
187
|
+
);
|
|
188
|
+
if (!accessCeiling) continue;
|
|
189
|
+
settings.harnesses[harness] = {
|
|
190
|
+
...intent,
|
|
191
|
+
selected,
|
|
192
|
+
maximumMethod,
|
|
193
|
+
accessCeiling
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
...record2,
|
|
200
|
+
schemaVersion: typeof record2.schemaVersion === "number" ? record2.schemaVersion : GLOBAL_CONFIG_SCHEMA_VERSION,
|
|
201
|
+
settings
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function normalizeHarnessAccessCeiling(value, fallback, configPath, harness, warnings) {
|
|
205
|
+
if (value === void 0) return { ...fallback };
|
|
206
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
207
|
+
warnings.push(`Global config harness "${harness}" has an invalid accessCeiling at ${configPath}; it was ignored.`);
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
const record2 = value;
|
|
211
|
+
const keys = Object.keys(record2).sort();
|
|
212
|
+
if (keys.join(",") !== "hostConfig,project,store" || !isAccessLevel(record2.store) || !isAccessLevel(record2.project) || record2.hostConfig !== "none") {
|
|
213
|
+
warnings.push(`Global config harness "${harness}" has an invalid accessCeiling at ${configPath}; it was ignored.`);
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
store: record2.store,
|
|
218
|
+
project: record2.project,
|
|
219
|
+
hostConfig: "none"
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function isAccessLevel(value) {
|
|
223
|
+
return value === "none" || value === "read" || value === "write";
|
|
224
|
+
}
|
|
225
|
+
function toMessage(error) {
|
|
226
|
+
return error instanceof Error ? error.message : String(error);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/store/project-identity.ts
|
|
230
|
+
import path2 from "path";
|
|
231
|
+
function resolveProjectIdentity(repoRoot) {
|
|
232
|
+
const rootPath = path2.resolve(repoRoot);
|
|
233
|
+
const manifestPath = getManifestPath(rootPath);
|
|
234
|
+
try {
|
|
235
|
+
const projectId = readDeclarativeProjectId(rootPath);
|
|
236
|
+
if (projectId) return { status: "resolved", projectId, rootPath, manifestPath: path2.join(rootPath, ".make-docs/config.yaml") };
|
|
237
|
+
const manifest = loadManifest(rootPath);
|
|
238
|
+
if (!manifest) {
|
|
239
|
+
return { status: "no-manifest", rootPath, manifestPath };
|
|
240
|
+
}
|
|
241
|
+
if (!manifest.projectId) {
|
|
242
|
+
return { status: "unminted", rootPath, manifestPath };
|
|
243
|
+
}
|
|
244
|
+
return { status: "resolved", projectId: manifest.projectId, rootPath, manifestPath };
|
|
245
|
+
} catch (error) {
|
|
246
|
+
return {
|
|
247
|
+
status: "unreadable",
|
|
248
|
+
rootPath,
|
|
249
|
+
manifestPath,
|
|
250
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/store/harness-integration-receipts.ts
|
|
256
|
+
import path3 from "path";
|
|
257
|
+
function recordHarnessIntegrationReceipt(targetRoot, storeRoot, receipt) {
|
|
258
|
+
assertHarnessIntegrationReceipt(receipt);
|
|
259
|
+
const currentId = currentReceiptRecordId(
|
|
260
|
+
receipt.scope,
|
|
261
|
+
receipt.harnessId,
|
|
262
|
+
receipt.connectionMethod
|
|
263
|
+
);
|
|
264
|
+
if (receipt.scope === "project") {
|
|
265
|
+
recordMigrationState(targetRoot, "receipt", receipt.operationId, receipt, storeRoot);
|
|
266
|
+
recordMigrationState(targetRoot, "receipt", currentId, receipt, storeRoot);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const recordId = machineReceiptRecordId(receipt.operationId);
|
|
270
|
+
withInstallationDatabase(targetRoot, (db) => {
|
|
271
|
+
const write = db.prepare(
|
|
272
|
+
"INSERT INTO tool_operations (operation_id,operation,status,pid,hostname,metadata_json,started_at,finished_at) VALUES (?,?,'completed',?,?,?,?,?) ON CONFLICT(operation_id) DO UPDATE SET status='completed',metadata_json=excluded.metadata_json,finished_at=excluded.finished_at"
|
|
273
|
+
);
|
|
274
|
+
write.run(recordId, "setup.system.receipt", process.pid, platform.hostname, JSON.stringify(receipt), receipt.verifiedAt, receipt.verifiedAt);
|
|
275
|
+
write.run(currentId, "setup.system.receipt-current", process.pid, platform.hostname, JSON.stringify(receipt), receipt.verifiedAt, receipt.verifiedAt);
|
|
276
|
+
}, { storeRoot });
|
|
277
|
+
}
|
|
278
|
+
function readCurrentHarnessIntegrationReceipt(targetRoot, storeRoot, scope, harnessId, connectionMethod) {
|
|
279
|
+
const currentId = currentReceiptRecordId(scope, harnessId, connectionMethod);
|
|
280
|
+
if (scope === "project") {
|
|
281
|
+
const current = readMigrationState(targetRoot, "receipt", currentId, storeRoot);
|
|
282
|
+
if (isHarnessIntegrationReceipt(current)) return current;
|
|
283
|
+
return latestReceipt(
|
|
284
|
+
listProjectHarnessIntegrationReceipts(targetRoot, storeRoot).filter((receipt) => receipt.harnessId === harnessId && receipt.connectionMethod === connectionMethod)
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
return withInstallationDatabase(targetRoot, (db) => {
|
|
288
|
+
const current = db.prepare(
|
|
289
|
+
"SELECT metadata_json FROM tool_operations WHERE operation_id=? AND operation='setup.system.receipt-current' AND status='completed'"
|
|
290
|
+
).get(currentId);
|
|
291
|
+
const currentValue = current ? parseJson(current.metadata_json) : null;
|
|
292
|
+
if (isHarnessIntegrationReceipt(currentValue)) return currentValue;
|
|
293
|
+
const rows = db.prepare(
|
|
294
|
+
"SELECT metadata_json FROM tool_operations WHERE operation='setup.system.receipt' AND status='completed' ORDER BY finished_at DESC"
|
|
295
|
+
).all();
|
|
296
|
+
return latestReceipt(rows.map((row) => parseJson(row.metadata_json)).filter(isHarnessIntegrationReceipt).filter((receipt) => receipt.scope === "machine" && receipt.harnessId === harnessId && receipt.connectionMethod === connectionMethod));
|
|
297
|
+
}, { storeRoot, readOnly: true });
|
|
298
|
+
}
|
|
299
|
+
function machineReceiptRecordId(operationId) {
|
|
300
|
+
return `harness-receipt:${operationId}`;
|
|
301
|
+
}
|
|
302
|
+
function currentReceiptRecordId(scope, harnessId, connectionMethod) {
|
|
303
|
+
return `harness-receipt-current:${scope}:${harnessId}:${connectionMethod}`;
|
|
304
|
+
}
|
|
305
|
+
function listProjectHarnessIntegrationReceipts(targetRoot, storeRoot) {
|
|
306
|
+
return uniqueReceipts(listMigrationState(targetRoot, "receipt", storeRoot).filter(isHarnessIntegrationReceipt).filter((receipt) => receipt.scope === "project"));
|
|
307
|
+
}
|
|
308
|
+
function assertHarnessIntegrationReceipt(value) {
|
|
309
|
+
if (!isHarnessIntegrationReceipt(value)) {
|
|
310
|
+
throw new Error("Harness access receipt is malformed or lacks exact ownership evidence.");
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function isHarnessIntegrationReceipt(value) {
|
|
314
|
+
if (!isStoredHarnessIntegrationReceipt(value)) return false;
|
|
315
|
+
const adapter = typeof value.harnessId === "string" ? getFirstPartyHarnessAdapter(value.harnessId) : void 0;
|
|
316
|
+
return adapter !== void 0 && value.adapterVersion === adapter.version && adapter.methods.some((method) => method.id === value.connectionMethod) && value.result === "verified" && value.verificationResult === "passed" && value.driftState === "current" && value.recoveryStatus === "complete";
|
|
317
|
+
}
|
|
318
|
+
function isStoredHarnessIntegrationReceipt(value) {
|
|
319
|
+
if (!isRecord(value)) return false;
|
|
320
|
+
const adapter = typeof value.harnessId === "string" ? getFirstPartyHarnessAdapter(value.harnessId) : void 0;
|
|
321
|
+
return (value.schemaVersion === 1 || value.schemaVersion === 2) && isSafeId(value.operationId) && adapter !== void 0 && value.adapterId === adapter.id && Number.isSafeInteger(value.adapterVersion) && Number(value.adapterVersion) > 0 && (value.connectionMethod === "mcp" || value.connectionMethod === "command-rules" || value.connectionMethod === "permission-rules") && (value.scope === "machine" || value.scope === "project") && (value.schemaVersion === 1 ? isExecutable(value.executable) : value.executable === void 0) && isSafeId(value.appliedVersion) && isTimestamp(value.verifiedAt) && Array.isArray(value.entries) && value.entries.length > 0 && value.entries.every(isReceiptEntry) && (value.result === "verified" || value.result === "failed" || value.result === "partial") && (value.verificationResult === "passed" || value.verificationResult === "failed" || value.verificationResult === "blocked") && (value.driftState === "current" || value.driftState === "missing" || value.driftState === "drifted" || value.driftState === "unsupported" || value.driftState === "blocked") && (value.recoveryStatus === "complete" || value.recoveryStatus === "incomplete" || value.recoveryStatus === "recovery-required");
|
|
322
|
+
}
|
|
323
|
+
function isExecutable(value) {
|
|
324
|
+
if (!isRecord(value)) return false;
|
|
325
|
+
if (value.kind !== "make-docs" || value.productMarker !== "@brucewaynedecoy/make-docs:package-bin" || value.packageName !== "@brucewaynedecoy/make-docs" || !isSafeId(value.packageVersion) || !path3.isAbsolute(String(value.path)) || !path3.isAbsolute(String(value.packageRoot)) || !isSafeRelativePath(value.binRelativePath) || !isSha256(value.sha256) || !Number.isSafeInteger(value.size) || Number(value.size) < 1) return false;
|
|
326
|
+
return platform.samePath(
|
|
327
|
+
String(value.path),
|
|
328
|
+
path3.resolve(String(value.packageRoot), String(value.binRelativePath))
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
function isReceiptEntry(value) {
|
|
332
|
+
return isRecord(value) && isSafeNativePath(value.path) && isSafeId(value.entryId) && value.ownership === "make-docs" && isNullableSha256(value.beforeEntryFingerprint) && isNullableSha256(value.beforeFileFingerprint) && isNativeValueOrNull(value.beforeValue) && isSha256(value.entryFingerprint) && isSha256(value.fileFingerprint) && isNativeValue(value.value) && value.entryFingerprint === fingerprintEntry(value.value) && (value.beforeValue === null ? value.beforeEntryFingerprint === null : value.beforeEntryFingerprint === fingerprintEntry(value.beforeValue));
|
|
333
|
+
}
|
|
334
|
+
function isSafeNativePath(value) {
|
|
335
|
+
if (typeof value !== "string" || value.length === 0 || /[\r\n\0]/.test(value)) return false;
|
|
336
|
+
if (value.includes("\\") || path3.posix.isAbsolute(value) || /^[A-Za-z]:/.test(value)) return false;
|
|
337
|
+
const normalized = path3.posix.normalize(value);
|
|
338
|
+
return normalized !== "." && normalized === value && normalized !== ".." && !normalized.startsWith("../");
|
|
339
|
+
}
|
|
340
|
+
function isSafeRelativePath(value) {
|
|
341
|
+
if (typeof value !== "string" || value.length === 0 || /[\r\n\0]/.test(value)) return false;
|
|
342
|
+
if (value.includes("\\") || path3.posix.isAbsolute(value) || /^[A-Za-z]:/.test(value)) return false;
|
|
343
|
+
const normalized = path3.posix.normalize(value);
|
|
344
|
+
return normalized !== "." && normalized === value && normalized !== ".." && !normalized.startsWith("../");
|
|
345
|
+
}
|
|
346
|
+
function isNativeValueOrNull(value) {
|
|
347
|
+
return value === null || isNativeValue(value);
|
|
348
|
+
}
|
|
349
|
+
function isNativeValue(value) {
|
|
350
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") return true;
|
|
351
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
352
|
+
if (Array.isArray(value)) return value.every(isNativeValue);
|
|
353
|
+
return isRecord(value) && Object.values(value).every(isNativeValue);
|
|
354
|
+
}
|
|
355
|
+
function isRecord(value) {
|
|
356
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
357
|
+
}
|
|
358
|
+
function isSafeId(value) {
|
|
359
|
+
return typeof value === "string" && value.length > 0 && value.length <= 256 && !/[\r\n\0]/.test(value);
|
|
360
|
+
}
|
|
361
|
+
function isNullableSha256(value) {
|
|
362
|
+
return value === null || isSha256(value);
|
|
363
|
+
}
|
|
364
|
+
function isSha256(value) {
|
|
365
|
+
return typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
366
|
+
}
|
|
367
|
+
function isTimestamp(value) {
|
|
368
|
+
return typeof value === "string" && Number.isFinite(Date.parse(value));
|
|
369
|
+
}
|
|
370
|
+
function parseJson(value) {
|
|
371
|
+
try {
|
|
372
|
+
return JSON.parse(value);
|
|
373
|
+
} catch {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
function latestReceipt(receipts) {
|
|
378
|
+
return receipts.sort(compareReceiptNewestFirst)[0] ?? null;
|
|
379
|
+
}
|
|
380
|
+
function compareReceiptNewestFirst(left, right) {
|
|
381
|
+
return Date.parse(right.verifiedAt) - Date.parse(left.verifiedAt);
|
|
382
|
+
}
|
|
383
|
+
function uniqueReceipts(receipts) {
|
|
384
|
+
const byOperation = /* @__PURE__ */ new Map();
|
|
385
|
+
for (const receipt of receipts) {
|
|
386
|
+
const existing = byOperation.get(receipt.operationId);
|
|
387
|
+
if (!existing || Date.parse(receipt.verifiedAt) > Date.parse(existing.verifiedAt)) {
|
|
388
|
+
byOperation.set(receipt.operationId, receipt);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return [...byOperation.values()];
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// src/store/harness-system-operations.ts
|
|
395
|
+
import { createHash, randomUUID } from "crypto";
|
|
396
|
+
import { existsSync as existsSync2 } from "fs";
|
|
397
|
+
import path4 from "path";
|
|
398
|
+
var OPERATION = "setup.system.harness";
|
|
399
|
+
function prepareHarnessSystemOperation(input) {
|
|
400
|
+
const targetRoot = canonicalInstallationPath(input.targetRoot);
|
|
401
|
+
const storeRoot = validateInstallationStoreRoot(targetRoot, input.storeRoot);
|
|
402
|
+
const ownershipReceipt = input.plan.state === "drifted" ? readCurrentHarnessIntegrationReceipt(
|
|
403
|
+
targetRoot,
|
|
404
|
+
storeRoot,
|
|
405
|
+
"machine",
|
|
406
|
+
input.harnessId,
|
|
407
|
+
input.plan.connectionMethod
|
|
408
|
+
) : null;
|
|
409
|
+
assertReviewedPlan(input.plan, input.adapterId, input.harnessId, ownershipReceipt);
|
|
410
|
+
if (!input.appliedVersion.trim()) throw new Error("Machine setup needs an applied version.");
|
|
411
|
+
if (!Number.isFinite(Date.parse(input.verifiedAt))) {
|
|
412
|
+
throw new Error("Machine setup needs a valid verification time.");
|
|
413
|
+
}
|
|
414
|
+
const pending = {
|
|
415
|
+
schemaVersion: 1,
|
|
416
|
+
kind: OPERATION,
|
|
417
|
+
operationId: randomUUID(),
|
|
418
|
+
adapterId: input.adapterId,
|
|
419
|
+
harnessId: input.harnessId,
|
|
420
|
+
connectionMethod: input.plan.connectionMethod,
|
|
421
|
+
targetRoot,
|
|
422
|
+
plan: input.plan,
|
|
423
|
+
planFingerprint: fingerprintJson(input.plan),
|
|
424
|
+
appliedVersion: input.appliedVersion,
|
|
425
|
+
verifiedAt: input.verifiedAt,
|
|
426
|
+
ownershipReceipt
|
|
427
|
+
};
|
|
428
|
+
const savedJson = JSON.stringify(pending);
|
|
429
|
+
withInstallationDatabase(targetRoot, (db) => {
|
|
430
|
+
db.exec("BEGIN IMMEDIATE");
|
|
431
|
+
try {
|
|
432
|
+
assertNoOtherStoreWork(db, targetRoot);
|
|
433
|
+
db.prepare(
|
|
434
|
+
"INSERT INTO tool_operations (operation_id,operation,status,pid,hostname,metadata_json,started_at,finished_at) VALUES (?,?,'pending',?,?,?,?,NULL)"
|
|
435
|
+
).run(
|
|
436
|
+
pending.operationId,
|
|
437
|
+
OPERATION,
|
|
438
|
+
process.pid,
|
|
439
|
+
platform.hostname,
|
|
440
|
+
savedJson,
|
|
441
|
+
pending.verifiedAt
|
|
442
|
+
);
|
|
443
|
+
db.exec("COMMIT");
|
|
444
|
+
} catch (error) {
|
|
445
|
+
db.exec("ROLLBACK");
|
|
446
|
+
throw error;
|
|
447
|
+
}
|
|
448
|
+
}, { storeRoot });
|
|
449
|
+
const saved = readPendingHarnessSystemOperation(targetRoot, storeRoot, pending.operationId);
|
|
450
|
+
if (!saved || JSON.stringify(saved) !== savedJson) {
|
|
451
|
+
throw new Error(
|
|
452
|
+
`Machine setup intent ${pending.operationId} did not pass Store readback. No native file was changed.`
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
return saved;
|
|
456
|
+
}
|
|
457
|
+
function readPendingHarnessSystemOperation(targetRootInput, storeRootInput, operationId) {
|
|
458
|
+
const targetRoot = canonicalInstallationPath(targetRootInput);
|
|
459
|
+
const storeRoot = validateInstallationStoreRoot(targetRoot, storeRootInput);
|
|
460
|
+
if (!existsSync2(getStoreDatabasePath(storeRoot))) return null;
|
|
461
|
+
if (classifyStoreCheckpoint9State(storeRoot).state === "supported-legacy") return null;
|
|
462
|
+
return withInstallationDatabase(targetRoot, (db) => {
|
|
463
|
+
const row = operationId ? db.prepare(
|
|
464
|
+
"SELECT operation_id,metadata_json FROM tool_operations WHERE operation_id=? AND operation=? AND status='pending'"
|
|
465
|
+
).get(operationId, OPERATION) : db.prepare(
|
|
466
|
+
"SELECT operation_id,metadata_json FROM tool_operations WHERE operation=? AND status='pending' ORDER BY started_at,operation_id LIMIT 1"
|
|
467
|
+
).get(OPERATION);
|
|
468
|
+
if (!row) return null;
|
|
469
|
+
let value;
|
|
470
|
+
try {
|
|
471
|
+
value = JSON.parse(row.metadata_json);
|
|
472
|
+
} catch {
|
|
473
|
+
throw invalidPending(row.operation_id);
|
|
474
|
+
}
|
|
475
|
+
const pending = validatePending(value, row.operation_id, targetRoot);
|
|
476
|
+
assertDurableOwnershipReceipt(db, pending);
|
|
477
|
+
return pending;
|
|
478
|
+
}, { storeRoot, readOnly: true });
|
|
479
|
+
}
|
|
480
|
+
function completeHarnessSystemOperation(targetRootInput, storeRootInput, pending, receipt) {
|
|
481
|
+
const targetRoot = canonicalInstallationPath(targetRootInput);
|
|
482
|
+
const storeRoot = validateInstallationStoreRoot(targetRoot, storeRootInput);
|
|
483
|
+
const exact = validatePending(pending, pending.operationId, targetRoot);
|
|
484
|
+
assertReceiptMatchesPlan(receipt, exact);
|
|
485
|
+
const pendingJson = JSON.stringify(exact);
|
|
486
|
+
withInstallationDatabase(targetRoot, (db) => {
|
|
487
|
+
db.exec("BEGIN IMMEDIATE");
|
|
488
|
+
try {
|
|
489
|
+
assertNoOtherStoreWork(db, targetRoot, exact.operationId);
|
|
490
|
+
const storedReceipt = db.prepare(
|
|
491
|
+
"SELECT metadata_json FROM tool_operations WHERE operation_id=? AND operation='setup.system.receipt' AND status='completed'"
|
|
492
|
+
).get(`harness-receipt:${exact.operationId}`);
|
|
493
|
+
if (!storedReceipt || storedReceipt.metadata_json !== JSON.stringify(receipt)) {
|
|
494
|
+
throw new Error(
|
|
495
|
+
`Machine setup ${exact.operationId} has no exact verified Store receipt. Keep it pending for recovery.`
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
const result = db.prepare(
|
|
499
|
+
"UPDATE tool_operations SET status='completed',metadata_json=?,finished_at=? WHERE operation_id=? AND operation=? AND status='pending' AND metadata_json=?"
|
|
500
|
+
).run(
|
|
501
|
+
JSON.stringify({ ...exact, receiptOperationId: receipt.operationId }),
|
|
502
|
+
receipt.verifiedAt,
|
|
503
|
+
exact.operationId,
|
|
504
|
+
OPERATION,
|
|
505
|
+
pendingJson
|
|
506
|
+
);
|
|
507
|
+
if (result.changes !== 1) throw changedPending(exact.operationId);
|
|
508
|
+
db.exec("COMMIT");
|
|
509
|
+
} catch (error) {
|
|
510
|
+
db.exec("ROLLBACK");
|
|
511
|
+
throw error;
|
|
512
|
+
}
|
|
513
|
+
}, { storeRoot });
|
|
514
|
+
}
|
|
515
|
+
function validatePending(value, rowOperationId, expectedTargetRoot) {
|
|
516
|
+
if (!value || typeof value !== "object") throw invalidPending(rowOperationId);
|
|
517
|
+
const pending = value;
|
|
518
|
+
if (pending.schemaVersion !== 1 || pending.kind !== OPERATION || pending.operationId !== rowOperationId || typeof pending.adapterId !== "string" || pending.harnessId !== "codex" && pending.harnessId !== "claude-code" || typeof pending.targetRoot !== "string" || canonicalInstallationPath(pending.targetRoot) !== expectedTargetRoot || !pending.plan || typeof pending.plan !== "object" || typeof pending.planFingerprint !== "string" || typeof pending.appliedVersion !== "string" || !pending.appliedVersion.trim() || typeof pending.verifiedAt !== "string" || !Number.isFinite(Date.parse(pending.verifiedAt))) {
|
|
519
|
+
throw invalidPending(rowOperationId);
|
|
520
|
+
}
|
|
521
|
+
if (pending.ownershipReceipt !== null && typeof pending.ownershipReceipt !== "object") {
|
|
522
|
+
throw invalidPending(rowOperationId);
|
|
523
|
+
}
|
|
524
|
+
assertReviewedPlan(
|
|
525
|
+
pending.plan,
|
|
526
|
+
pending.adapterId,
|
|
527
|
+
pending.harnessId,
|
|
528
|
+
pending.ownershipReceipt ?? null
|
|
529
|
+
);
|
|
530
|
+
if (pending.connectionMethod !== pending.plan.connectionMethod || pending.planFingerprint !== fingerprintJson(pending.plan)) {
|
|
531
|
+
throw invalidPending(rowOperationId);
|
|
532
|
+
}
|
|
533
|
+
return pending;
|
|
534
|
+
}
|
|
535
|
+
function assertReviewedPlan(plan, adapterId, harnessId, ownershipReceipt) {
|
|
536
|
+
if (plan.schemaVersion !== 1 || plan.kind !== "apply" || plan.adapterId !== adapterId || plan.harnessId !== harnessId || plan.scope !== "machine" || !path4.isAbsolute(plan.root) || path4.normalize(plan.root) !== plan.root || !/^[0-9a-f]{64}$/.test(plan.reviewFingerprint) || plan.state === "blocked" || plan.state === "unsupported" || !Array.isArray(plan.changes) || plan.changes.length === 0) {
|
|
537
|
+
throw new Error("Machine setup needs one exact reviewed machine harness plan.");
|
|
538
|
+
}
|
|
539
|
+
for (const change of plan.changes) assertReviewedChange(plan.root, change);
|
|
540
|
+
if (plan.state === "drifted") {
|
|
541
|
+
assertReceiptOwnedDrift(plan, ownershipReceipt);
|
|
542
|
+
} else if (ownershipReceipt !== null) {
|
|
543
|
+
throw new Error("Only a reviewed drift repair can carry an ownership receipt.");
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function assertReceiptOwnedDrift(plan, receipt) {
|
|
547
|
+
if (!receipt || receipt.schemaVersion !== 1 && receipt.schemaVersion !== 2 || receipt.adapterId !== plan.adapterId || receipt.adapterVersion !== plan.adapterVersion || receipt.harnessId !== plan.harnessId || receipt.connectionMethod !== plan.connectionMethod || receipt.scope !== "machine" || receipt.result !== "verified" || receipt.verificationResult !== "passed" || receipt.driftState !== "current" || receipt.recoveryStatus !== "complete" || receipt.entries.length !== plan.changes.length) {
|
|
548
|
+
throw new Error("A drift repair needs the exact current Make Docs ownership receipt.");
|
|
549
|
+
}
|
|
550
|
+
for (let index = 0; index < plan.changes.length; index++) {
|
|
551
|
+
const change = plan.changes[index];
|
|
552
|
+
const entry = receipt.entries[index];
|
|
553
|
+
if (change.action !== "update" || change.ownership !== "make-docs-owned" || change.blockedReason || entry.ownership !== "make-docs" || entry.path !== change.path || entry.entryId !== change.entryId || entry.entryFingerprint !== change.beforeEntryFingerprint || JSON.stringify(entry.value) !== JSON.stringify(change.beforeEntryValue) || fingerprintEntry(entry.value) !== entry.entryFingerprint) {
|
|
554
|
+
throw new Error(
|
|
555
|
+
`Drift repair target ${change.path} is not the exact receipt-owned native entry.`
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function assertDurableOwnershipReceipt(db, pending) {
|
|
561
|
+
const receipt = pending.ownershipReceipt;
|
|
562
|
+
if (!receipt) return;
|
|
563
|
+
const row = db.prepare(
|
|
564
|
+
"SELECT metadata_json FROM tool_operations WHERE operation_id=? AND operation='setup.system.receipt' AND status='completed'"
|
|
565
|
+
).get(`harness-receipt:${receipt.operationId}`);
|
|
566
|
+
if (!row || row.metadata_json !== JSON.stringify(receipt)) {
|
|
567
|
+
throw new Error(
|
|
568
|
+
`Pending machine setup ${pending.operationId} lost its exact ownership receipt. Preserve it for manual recovery.`
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function assertReviewedChange(root, change) {
|
|
573
|
+
const resolved = path4.resolve(root, change.path);
|
|
574
|
+
if (!change.path || path4.isAbsolute(change.path) || resolved !== root && !resolved.startsWith(`${root}${path4.sep}`) || !(/* @__PURE__ */ new Set(["create", "update", "remove", "none"])).has(change.action) || !(/* @__PURE__ */ new Set(["missing", "make-docs-owned", "unverified"])).has(change.ownership) || change.blockedReason || !isFingerprint(change.beforeFileFingerprint, true) || !isFingerprint(change.afterFileFingerprint, false) || !entryMatches(change.beforeEntryValue, change.beforeEntryFingerprint) || change.afterEntryValue === null || !entryMatches(change.afterEntryValue, change.afterEntryFingerprint)) {
|
|
575
|
+
throw new Error(`Machine setup has an unsafe or incomplete reviewed change: ${change.path}.`);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
function assertReceiptMatchesPlan(receipt, pending) {
|
|
579
|
+
const plan = pending.plan;
|
|
580
|
+
if (receipt.schemaVersion !== 2 || receipt.operationId !== pending.operationId || receipt.adapterId !== pending.adapterId || receipt.adapterVersion !== plan.adapterVersion || receipt.harnessId !== pending.harnessId || receipt.connectionMethod !== pending.connectionMethod || receipt.scope !== "machine" || receipt.appliedVersion !== pending.appliedVersion || receipt.verifiedAt !== pending.verifiedAt || receipt.result !== "verified" || receipt.verificationResult !== "passed" || receipt.driftState !== "current" || receipt.recoveryStatus !== "complete" || receipt.entries.length !== plan.changes.length) {
|
|
581
|
+
throw new Error(`Machine setup receipt does not match pending plan ${pending.operationId}.`);
|
|
582
|
+
}
|
|
583
|
+
for (let index = 0; index < plan.changes.length; index++) {
|
|
584
|
+
const change = plan.changes[index];
|
|
585
|
+
const entry = receipt.entries[index];
|
|
586
|
+
if (entry.path !== change.path || entry.entryId !== change.entryId || entry.ownership !== "make-docs" || entry.beforeEntryFingerprint !== change.beforeEntryFingerprint || entry.beforeFileFingerprint !== change.beforeFileFingerprint || JSON.stringify(entry.beforeValue) !== JSON.stringify(change.beforeEntryValue) || entry.entryFingerprint !== change.afterEntryFingerprint || entry.fileFingerprint !== change.afterFileFingerprint || JSON.stringify(entry.value) !== JSON.stringify(change.afterEntryValue) || fingerprintEntry(entry.value) !== entry.entryFingerprint) {
|
|
587
|
+
throw new Error(`Machine setup receipt changed reviewed target ${change.path}.`);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
function assertNoOtherStoreWork(db, targetRoot, ownOperationId) {
|
|
592
|
+
const tool = db.prepare(
|
|
593
|
+
`SELECT operation_id FROM tool_operations WHERE status='pending'${ownOperationId ? " AND operation_id<>?" : ""} LIMIT 1`
|
|
594
|
+
).get(...ownOperationId ? [ownOperationId] : []);
|
|
595
|
+
const project = db.prepare(
|
|
596
|
+
`SELECT operations.operation_id
|
|
597
|
+
FROM installation_operations AS operations
|
|
598
|
+
JOIN installation_checkouts AS checkouts
|
|
599
|
+
ON checkouts.checkout_id=operations.checkout_id
|
|
600
|
+
WHERE operations.status='pending' AND checkouts.root_path=?
|
|
601
|
+
LIMIT 1`
|
|
602
|
+
).get(targetRoot);
|
|
603
|
+
const writer = db.prepare(
|
|
604
|
+
"SELECT root_path FROM installation_locks WHERE root_path=? LIMIT 1"
|
|
605
|
+
).get(targetRoot);
|
|
606
|
+
if (tool || project || writer) {
|
|
607
|
+
throw new Error(
|
|
608
|
+
`A Store operation is already pending (${tool?.operation_id ?? project?.operation_id ?? writer?.root_path}). Resolve it before machine setup. No native file was changed.`
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
function entryMatches(value, fingerprint) {
|
|
613
|
+
return value === null ? fingerprint === null : fingerprint === fingerprintEntry(value);
|
|
614
|
+
}
|
|
615
|
+
function isFingerprint(value, allowNull) {
|
|
616
|
+
return allowNull && value === null || typeof value === "string" && /^[0-9a-f]{64}$/.test(value);
|
|
617
|
+
}
|
|
618
|
+
function fingerprintJson(value) {
|
|
619
|
+
return createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
620
|
+
}
|
|
621
|
+
function invalidPending(operationId) {
|
|
622
|
+
return new Error(
|
|
623
|
+
`Pending machine setup ${operationId} has invalid Store evidence. Preserve it for manual recovery.`
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
function changedPending(operationId) {
|
|
627
|
+
return new Error(
|
|
628
|
+
`Pending machine setup ${operationId} changed before completion. Preserve it for Store recovery.`
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// src/store/global-manifest.ts
|
|
633
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
|
|
634
|
+
var GLOBAL_MANIFEST_SCHEMA_VERSION = 1;
|
|
635
|
+
function defaultGlobalManifest(now) {
|
|
636
|
+
return {
|
|
637
|
+
schemaVersion: GLOBAL_MANIFEST_SCHEMA_VERSION,
|
|
638
|
+
createdAt: now,
|
|
639
|
+
updatedAt: now,
|
|
640
|
+
lastBootstrap: null,
|
|
641
|
+
database: {
|
|
642
|
+
file: STORE_DATABASE_FILE,
|
|
643
|
+
schemaVersion: null,
|
|
644
|
+
status: "unavailable"
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
function loadGlobalManifest(storeRoot) {
|
|
649
|
+
const manifestPath = getGlobalManifestPath(storeRoot);
|
|
650
|
+
if (!existsSync3(manifestPath)) {
|
|
651
|
+
return null;
|
|
652
|
+
}
|
|
653
|
+
let raw;
|
|
654
|
+
try {
|
|
655
|
+
raw = JSON.parse(readFileSync2(manifestPath, "utf8"));
|
|
656
|
+
} catch {
|
|
657
|
+
return null;
|
|
658
|
+
}
|
|
659
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
662
|
+
const record2 = raw;
|
|
663
|
+
const nowFallback = (/* @__PURE__ */ new Date()).toISOString();
|
|
664
|
+
const database = typeof record2.database === "object" && record2.database !== null && !Array.isArray(record2.database) ? record2.database : {};
|
|
665
|
+
return {
|
|
666
|
+
schemaVersion: typeof record2.schemaVersion === "number" ? record2.schemaVersion : GLOBAL_MANIFEST_SCHEMA_VERSION,
|
|
667
|
+
createdAt: typeof record2.createdAt === "string" ? record2.createdAt : nowFallback,
|
|
668
|
+
updatedAt: typeof record2.updatedAt === "string" ? record2.updatedAt : nowFallback,
|
|
669
|
+
lastBootstrap: normalizeBootstrapRecord(record2.lastBootstrap),
|
|
670
|
+
database: {
|
|
671
|
+
file: typeof database.file === "string" ? database.file : STORE_DATABASE_FILE,
|
|
672
|
+
schemaVersion: typeof database.schemaVersion === "number" ? database.schemaVersion : null,
|
|
673
|
+
status: normalizeDatabaseStatus(database.status)
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function writeGlobalManifest(storeRoot, manifest) {
|
|
678
|
+
const manifestPath = getGlobalManifestPath(storeRoot);
|
|
679
|
+
writeStoreJsonFile(manifestPath, manifest);
|
|
680
|
+
return manifestPath;
|
|
681
|
+
}
|
|
682
|
+
function normalizeBootstrapRecord(value) {
|
|
683
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
686
|
+
const record2 = value;
|
|
687
|
+
if (typeof record2.packageName !== "string" || typeof record2.packageVersion !== "string" || typeof record2.nodeVersion !== "string" || typeof record2.at !== "string") {
|
|
688
|
+
return null;
|
|
689
|
+
}
|
|
690
|
+
return {
|
|
691
|
+
packageName: record2.packageName,
|
|
692
|
+
packageVersion: record2.packageVersion,
|
|
693
|
+
nodeVersion: record2.nodeVersion,
|
|
694
|
+
at: record2.at
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
function normalizeDatabaseStatus(value) {
|
|
698
|
+
if (value === "ready" || value === "created" || value === "recovered" || value === "schema-newer" || value === "unavailable") {
|
|
699
|
+
return value;
|
|
700
|
+
}
|
|
701
|
+
return "unavailable";
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// src/store/compatibility-bridge.ts
|
|
705
|
+
var STORE_COMPATIBILITY_BRIDGE_REGISTER = Object.freeze([
|
|
706
|
+
{
|
|
707
|
+
bridgeId: "w22-p5-store-schema-v1-v4",
|
|
708
|
+
oldForm: "Store schemas 1 through 4",
|
|
709
|
+
targetForm: "Store schema 5",
|
|
710
|
+
firstBridgeVersion: "2.0.0-rc",
|
|
711
|
+
owner: "Store compatibility owner",
|
|
712
|
+
oldWritesStoppedProof: "openStoreDatabase rejects schemas below 5 outside the reviewed migration path.",
|
|
713
|
+
remainingStateCheck: "PRAGMA user_version is below 5.",
|
|
714
|
+
endCondition: "No supported installation remains below schema 5.",
|
|
715
|
+
removalPhaseOrRelease: "A later owner-approved release after P6 installed-package proof",
|
|
716
|
+
requiredTests: ["schemas 1-4", "repeat", "interruption", "newer", "corrupt"],
|
|
717
|
+
retentionAndExportRule: "Keep the verified pre-conversion Store backup until separate cleanup approval.",
|
|
718
|
+
separateDeletionApproval: true
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
bridgeId: "w22-p5-checkout-object-numbers",
|
|
722
|
+
oldForm: "installation_checkouts.root_device and root_inode",
|
|
723
|
+
targetForm: "checkout id, platform path key, and bounded live verification evidence",
|
|
724
|
+
firstBridgeVersion: "2.0.0-rc",
|
|
725
|
+
owner: "Store identity owner",
|
|
726
|
+
oldWritesStoppedProof: "The schema-5 checkout writer omits both fields and schema 5 has no such columns.",
|
|
727
|
+
remainingStateCheck: "Schema below 5 has either legacy column.",
|
|
728
|
+
endCondition: "All supported Stores are schema 5 and archived values remain history only.",
|
|
729
|
+
removalPhaseOrRelease: "W22 P5 field retirement; history cleanup needs later approval",
|
|
730
|
+
requiredTests: ["moved checkout", "clone", "repeat", "rollback", "all core platforms"],
|
|
731
|
+
retentionAndExportRule: "Archive exact strings as legacy-import evidence. Do not use them as identity.",
|
|
732
|
+
separateDeletionApproval: true
|
|
733
|
+
},
|
|
734
|
+
{
|
|
735
|
+
bridgeId: "w22-p5-checkpoint-receipts",
|
|
736
|
+
oldForm: "store_checkpoint_journal rows",
|
|
737
|
+
targetForm: "store_migration_receipts history",
|
|
738
|
+
firstBridgeVersion: "2.0.0-rc",
|
|
739
|
+
owner: "Store migration owner",
|
|
740
|
+
oldWritesStoppedProof: "Checkpoint 9 writes store_migration_receipts after schema-5 cutover.",
|
|
741
|
+
remainingStateCheck: "Count rows present only in store_checkpoint_journal.",
|
|
742
|
+
endCondition: "Every old receipt has a byte-equivalent target history row.",
|
|
743
|
+
removalPhaseOrRelease: "Later compatibility cleanup after export and owner approval",
|
|
744
|
+
requiredTests: ["receipt copy", "readback", "projection retry", "repeat"],
|
|
745
|
+
retentionAndExportRule: "Preserve old rows as private local history until separately approved export or deletion.",
|
|
746
|
+
separateDeletionApproval: true
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
bridgeId: "w22-p5-installation-transfers",
|
|
750
|
+
oldForm: "installation_transfers rows",
|
|
751
|
+
targetForm: "legacy-import migration record source evidence",
|
|
752
|
+
firstBridgeVersion: "2.0.0-rc",
|
|
753
|
+
owner: "Installation migration owner",
|
|
754
|
+
oldWritesStoppedProof: "Legacy import writes source evidence only to installation_migration_records.",
|
|
755
|
+
remainingStateCheck: "Count installation_transfers rows.",
|
|
756
|
+
endCondition: "Supported local-state transfer is complete and retained source evidence is readable.",
|
|
757
|
+
removalPhaseOrRelease: "Later transfer-bridge cleanup after owner approval",
|
|
758
|
+
requiredTests: ["legacy import", "repeat", "interruption", "source readback"],
|
|
759
|
+
retentionAndExportRule: "Retain existing transfer rows as private history. Do not delete source evidence in P5.",
|
|
760
|
+
separateDeletionApproval: true
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
bridgeId: "w22-p5-installation-ledger",
|
|
764
|
+
oldForm: "installation ledger records with legacy projection mirrors",
|
|
765
|
+
targetForm: "versioned installation ledger with minimum applied projection ownership",
|
|
766
|
+
firstBridgeVersion: "2.0.0-rc",
|
|
767
|
+
owner: "Installation state owner",
|
|
768
|
+
oldWritesStoppedProof: "P4 target writers omit projection selection and provider mirrors.",
|
|
769
|
+
remainingStateCheck: "Parse ledgers and count legacy resourceProjection.selectedTypes, provider, or legacy resource fields.",
|
|
770
|
+
endCondition: "Every active ledger has the target projection form or is retained as opaque history.",
|
|
771
|
+
removalPhaseOrRelease: "P5 conversion; broad-history cleanup needs later approval",
|
|
772
|
+
requiredTests: ["legacy ledger", "current ledger", "malformed ledger", "repeat"],
|
|
773
|
+
retentionAndExportRule: "Preserve the source Store backup and never delete project content during conversion.",
|
|
774
|
+
separateDeletionApproval: true
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
bridgeId: "w22-p5-harness-receipt-v1",
|
|
778
|
+
oldForm: "Harness receipt schema 1 executable proof",
|
|
779
|
+
targetForm: "Schema 2 receipt history plus call-time executable verification",
|
|
780
|
+
firstBridgeVersion: "2.0.0-rc",
|
|
781
|
+
owner: "Harness trust owner",
|
|
782
|
+
oldWritesStoppedProof: "P4 receipt writers emit schema 2 and omit executable proof.",
|
|
783
|
+
remainingStateCheck: "Count schemaVersion 1 receipt JSON in migration records and tool-operation history.",
|
|
784
|
+
endCondition: "All active receipt writes are schema 2 and schema 1 remains history only.",
|
|
785
|
+
removalPhaseOrRelease: "Later receipt-history cleanup after export and owner approval",
|
|
786
|
+
requiredTests: ["schema 1 read", "schema 2 write", "package update", "moved launch"],
|
|
787
|
+
retentionAndExportRule: "Retain valid schema 1 receipts as private history. Never use them for current access.",
|
|
788
|
+
separateDeletionApproval: true
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
bridgeId: "w22-p5-pending-operations",
|
|
792
|
+
oldForm: "Supported pending installation operation and step rows",
|
|
793
|
+
targetForm: "The same shared operation journal with target checkout and ledger readers",
|
|
794
|
+
firstBridgeVersion: "2.0.0-rc",
|
|
795
|
+
owner: "Installation recovery owner",
|
|
796
|
+
oldWritesStoppedProof: "No second recovery table or project-local marker is introduced.",
|
|
797
|
+
remainingStateCheck: "Count installation_operations with status pending and inspect plan_complete plus saved steps.",
|
|
798
|
+
endCondition: "Each pending operation reaches completed or rolled-back through the shared journal.",
|
|
799
|
+
removalPhaseOrRelease: "Normal operation retention, not bridge deletion",
|
|
800
|
+
requiredTests: ["complete plan resume", "incomplete rollback", "conflict stop", "restart"],
|
|
801
|
+
retentionAndExportRule: "Keep exact recovery evidence until the operation reaches a verified terminal state.",
|
|
802
|
+
separateDeletionApproval: true
|
|
803
|
+
}
|
|
804
|
+
]);
|
|
805
|
+
function previewStoreCompatibilityBridge(storeRoot) {
|
|
806
|
+
const classification = classifyStoreCheckpoint9State(storeRoot);
|
|
807
|
+
const base = {
|
|
808
|
+
schemaVersion: 1,
|
|
809
|
+
readOnly: true,
|
|
810
|
+
databasePath: classification.databasePath,
|
|
811
|
+
storeState: classification.state,
|
|
812
|
+
sourceSchemaVersion: classification.schemaVersion,
|
|
813
|
+
targetSchemaVersion: CURRENT_STORE_SCHEMA_VERSION
|
|
814
|
+
};
|
|
815
|
+
if (classification.state === "absent") {
|
|
816
|
+
return {
|
|
817
|
+
...base,
|
|
818
|
+
disposition: "rebuild",
|
|
819
|
+
records: [],
|
|
820
|
+
changes: {
|
|
821
|
+
store: [`Create a fresh schema-${CURRENT_STORE_SCHEMA_VERSION} Store.`],
|
|
822
|
+
project: [],
|
|
823
|
+
native: []
|
|
824
|
+
},
|
|
825
|
+
blockers: [],
|
|
826
|
+
nextAction: "Review setup. Setup can create the Store without a compatibility conversion."
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
if (classification.state === "newer-unknown") {
|
|
830
|
+
return unsafePreview(base, "unsupported", classification.reason, "Update Make Docs to a version that supports this Store.");
|
|
831
|
+
}
|
|
832
|
+
if (classification.state === "corrupt" || classification.state === "unknown" || classification.state === "indeterminate") {
|
|
833
|
+
return unsafePreview(base, "quarantine", classification.reason, "Repair or restore this preserved Store before Store-backed work.");
|
|
834
|
+
}
|
|
835
|
+
const release = acquireStoreAccess(storeRoot);
|
|
836
|
+
let db = null;
|
|
837
|
+
try {
|
|
838
|
+
db = openStoreSqliteConnection(classification.databasePath, { readOnly: true }, "preview Store compatibility bridge");
|
|
839
|
+
const version = classification.schemaVersion;
|
|
840
|
+
const tables = new Set(db.prepare("SELECT name FROM sqlite_schema WHERE type='table'").all().map((row) => row.name));
|
|
841
|
+
const records = [];
|
|
842
|
+
const changes = [];
|
|
843
|
+
const blockers = [];
|
|
844
|
+
if (version < 5) {
|
|
845
|
+
records.push(record("w22-p5-store-schema-v1-v4", "convert", 1, `Schema ${version} has a supported conversion to schema ${CURRENT_STORE_SCHEMA_VERSION}.`));
|
|
846
|
+
}
|
|
847
|
+
if (version < 6) {
|
|
848
|
+
records.push(record(
|
|
849
|
+
"w23-r0-p5-backlog-review-cache",
|
|
850
|
+
"convert",
|
|
851
|
+
1,
|
|
852
|
+
`Schema ${version} can add the optional rebuildable backlog review cache.`
|
|
853
|
+
));
|
|
854
|
+
}
|
|
855
|
+
if (version < CURRENT_STORE_SCHEMA_VERSION) {
|
|
856
|
+
changes.push(`Create and verify one Store backup before converting schema ${version} to schema ${CURRENT_STORE_SCHEMA_VERSION}.`);
|
|
857
|
+
}
|
|
858
|
+
if (version >= 3 && tables.has("installation_checkouts")) {
|
|
859
|
+
const bridgeCollisions = Number(db.prepare("SELECT COUNT(*) AS count FROM installation_migration_records WHERE kind='legacy-import' AND record_id IN ('w22-p5:checkout-object-numbers:v4','w22-p5:installation-ledger-projection:v4')").get().count);
|
|
860
|
+
if (version < 5 && bridgeCollisions) blockers.push(`${bridgeCollisions} reserved P5 bridge record(s) already exist in an older schema.`);
|
|
861
|
+
const activeLocks = Number(db.prepare("SELECT COUNT(*) AS count FROM installation_locks").get().count);
|
|
862
|
+
if (activeLocks) blockers.push(`${activeLocks} active installation lock(s) must finish before conversion.`);
|
|
863
|
+
const pendingToolOperations = Number(db.prepare("SELECT COUNT(*) AS count FROM tool_operations WHERE status='pending'").get().count);
|
|
864
|
+
if (pendingToolOperations) blockers.push(`${pendingToolOperations} pending tool operation(s) require recovery before conversion.`);
|
|
865
|
+
const columns = new Set(db.prepare("PRAGMA table_info(installation_checkouts)").all().map((row) => row.name));
|
|
866
|
+
if (columns.has("root_device") || columns.has("root_inode")) {
|
|
867
|
+
const count = countRows(db, "installation_checkouts");
|
|
868
|
+
records.push(record("w22-p5-checkout-object-numbers", "convert", count, "Archive legacy values as evidence, then remove the active identity columns."));
|
|
869
|
+
changes.push(`Archive device and inode strings for ${count} checkout row(s), then remove both active columns.`);
|
|
870
|
+
} else {
|
|
871
|
+
const count = countRecordId(db, "w22-p5:checkout-object-numbers:v4");
|
|
872
|
+
records.push(record("w22-p5-checkout-object-numbers", "retain-history", count, "Object numbers are no longer active fields."));
|
|
873
|
+
}
|
|
874
|
+
const ledgerRows = db.prepare("SELECT checkout_id, manifest_json FROM installation_ledgers ORDER BY checkout_id").all();
|
|
875
|
+
let legacyLedgers = 0;
|
|
876
|
+
for (const row of ledgerRows) {
|
|
877
|
+
const value = parseObject(row.manifest_json);
|
|
878
|
+
if (!value) {
|
|
879
|
+
blockers.push(`Installation ledger ${row.checkout_id} is malformed or unsupported.`);
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
if (hasLegacyProjection(value)) legacyLedgers++;
|
|
883
|
+
}
|
|
884
|
+
records.push(record("w22-p5-installation-ledger", legacyLedgers ? "convert" : "retain-history", ledgerRows.length, legacyLedgers ? `${legacyLedgers} ledger(s) use legacy projection mirrors.` : "All readable ledgers use the accepted projection form."));
|
|
885
|
+
if (legacyLedgers) changes.push(`Convert legacy projection mirrors in ${legacyLedgers} installation ledger(s) through the versioned reader and target writer.`);
|
|
886
|
+
const transfers = countRows(db, "installation_transfers");
|
|
887
|
+
records.push(record("w22-p5-installation-transfers", transfers ? "retain-history" : "removable-after-proof", transfers, transfers ? "Existing rows remain private history. New imports use migration records." : "No legacy transfer rows remain."));
|
|
888
|
+
const pending = Number(db.prepare("SELECT COUNT(*) AS count FROM installation_operations WHERE status='pending'").get().count);
|
|
889
|
+
records.push(record("w22-p5-pending-operations", "retain-history", pending, pending ? "Pending work remains in the shared recovery journal." : "No pending installation operation exists."));
|
|
890
|
+
const receiptVersions = countHarnessReceiptVersions(db);
|
|
891
|
+
records.push(record("w22-p5-harness-receipt-v1", "retain-history", receiptVersions.legacy, `${receiptVersions.legacy} schema-1 receipt(s) remain readable history; ${receiptVersions.current} schema-2 receipt(s) use current form.`));
|
|
892
|
+
}
|
|
893
|
+
if (tables.has("store_checkpoint_journal")) {
|
|
894
|
+
const oldReceipts = countRows(db, "store_checkpoint_journal");
|
|
895
|
+
const targetReceipts = tables.has("store_migration_receipts") ? countRows(db, "store_migration_receipts") : 0;
|
|
896
|
+
records.push(record("w22-p5-checkpoint-receipts", version < CURRENT_STORE_SCHEMA_VERSION && oldReceipts ? "convert" : "retain-history", oldReceipts, `${targetReceipts} target receipt(s) and ${oldReceipts} retained checkpoint receipt(s) are present.`));
|
|
897
|
+
if (version < CURRENT_STORE_SCHEMA_VERSION && oldReceipts) changes.push(`Copy ${oldReceipts} checkpoint receipt row(s) to target receipt history and verify readback.`);
|
|
898
|
+
}
|
|
899
|
+
const disposition = blockers.length ? "quarantine" : version < CURRENT_STORE_SCHEMA_VERSION || records.some((entry) => entry.disposition === "convert") ? "convert" : "retain-history";
|
|
900
|
+
return {
|
|
901
|
+
...base,
|
|
902
|
+
disposition,
|
|
903
|
+
records,
|
|
904
|
+
changes: { store: changes, project: [], native: [] },
|
|
905
|
+
blockers,
|
|
906
|
+
nextAction: blockers.length ? "Keep the Store unchanged. Repair the listed record, then preview setup again." : disposition === "convert" ? "Review this exact Store plan, then run setup to apply it." : "No compatibility conversion is required."
|
|
907
|
+
};
|
|
908
|
+
} finally {
|
|
909
|
+
db?.close();
|
|
910
|
+
release();
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
function unsafePreview(base, disposition, reason, nextAction) {
|
|
914
|
+
return { ...base, disposition, records: [], changes: { store: [], project: [], native: [] }, blockers: [reason], nextAction };
|
|
915
|
+
}
|
|
916
|
+
function record(bridgeId, disposition, count, reason) {
|
|
917
|
+
return { bridgeId, disposition, count, reason };
|
|
918
|
+
}
|
|
919
|
+
function countRows(db, table) {
|
|
920
|
+
return Number(db.prepare(`SELECT COUNT(*) AS count FROM ${table}`).get().count);
|
|
921
|
+
}
|
|
922
|
+
function countRecordId(db, recordId) {
|
|
923
|
+
return Number(db.prepare("SELECT COUNT(*) AS count FROM installation_migration_records WHERE record_id=?").get(recordId).count);
|
|
924
|
+
}
|
|
925
|
+
function parseObject(value) {
|
|
926
|
+
try {
|
|
927
|
+
const parsed = JSON.parse(value);
|
|
928
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
929
|
+
} catch {
|
|
930
|
+
return null;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
function hasLegacyProjection(manifest) {
|
|
934
|
+
const projection = manifest.resourceProjection;
|
|
935
|
+
if (!projection || typeof projection !== "object" || Array.isArray(projection)) return false;
|
|
936
|
+
const value = projection;
|
|
937
|
+
if ("selectedTypes" in value || "provider" in value) return true;
|
|
938
|
+
const resources = value.resources;
|
|
939
|
+
if (!resources || typeof resources !== "object" || Array.isArray(resources)) return false;
|
|
940
|
+
const legacy = /* @__PURE__ */ new Set(["type", "resourcePath", "provenanceState", "providerPackage", "providerVersion", "providerImmutableRef", "materializationMode", "sourceDigest", "adoptionReceipt", "selectionTrigger", "operationLineage", "provenanceEvidence", "competingClaims"]);
|
|
941
|
+
return Object.values(resources).some((entry) => entry && typeof entry === "object" && !Array.isArray(entry) && Object.keys(entry).some((key) => legacy.has(key)));
|
|
942
|
+
}
|
|
943
|
+
function countHarnessReceiptVersions(db) {
|
|
944
|
+
let legacy = 0;
|
|
945
|
+
let current = 0;
|
|
946
|
+
const values = [];
|
|
947
|
+
values.push(...db.prepare("SELECT record_json FROM installation_migration_records WHERE kind='receipt'").all().map((row) => row.record_json));
|
|
948
|
+
values.push(...db.prepare("SELECT metadata_json FROM tool_operations WHERE operation LIKE 'setup.system.receipt%'").all().map((row) => row.metadata_json));
|
|
949
|
+
for (const value of values) {
|
|
950
|
+
const parsed = parseObject(value);
|
|
951
|
+
if (parsed?.schemaVersion === 1) legacy++;
|
|
952
|
+
if (parsed?.schemaVersion === 2) current++;
|
|
953
|
+
}
|
|
954
|
+
return { legacy, current };
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// src/store/state-rows.ts
|
|
958
|
+
function upsertWorkEvidence(db, input) {
|
|
959
|
+
const now = input.now ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
960
|
+
db.prepare(
|
|
961
|
+
`INSERT INTO work_evidence (project_id, wave_slug, phase_path, evidence_kind, payload, repo_root, recorded_at)
|
|
962
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
963
|
+
ON CONFLICT (project_id, wave_slug, phase_path, evidence_kind) DO UPDATE SET
|
|
964
|
+
payload = excluded.payload,
|
|
965
|
+
repo_root = excluded.repo_root,
|
|
966
|
+
recorded_at = excluded.recorded_at`
|
|
967
|
+
).run(
|
|
968
|
+
input.projectId,
|
|
969
|
+
input.waveSlug,
|
|
970
|
+
input.phasePath,
|
|
971
|
+
input.evidenceKind,
|
|
972
|
+
JSON.stringify(input.payload),
|
|
973
|
+
input.repoRoot ?? null,
|
|
974
|
+
now
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
function listWorkEvidence(db, filter) {
|
|
978
|
+
const clauses = ["project_id = ?"];
|
|
979
|
+
const params = [filter.projectId];
|
|
980
|
+
if (filter.waveSlug !== void 0) {
|
|
981
|
+
clauses.push("wave_slug = ?");
|
|
982
|
+
params.push(filter.waveSlug);
|
|
983
|
+
}
|
|
984
|
+
if (filter.phasePath !== void 0) {
|
|
985
|
+
clauses.push("phase_path = ?");
|
|
986
|
+
params.push(filter.phasePath);
|
|
987
|
+
}
|
|
988
|
+
const rows = db.prepare(
|
|
989
|
+
`SELECT project_id, wave_slug, phase_path, evidence_kind, payload, repo_root, recorded_at
|
|
990
|
+
FROM work_evidence WHERE ${clauses.join(" AND ")}
|
|
991
|
+
ORDER BY wave_slug, phase_path, evidence_kind`
|
|
992
|
+
).all(...params);
|
|
993
|
+
return rows.map((row) => ({
|
|
994
|
+
projectId: String(row.project_id),
|
|
995
|
+
waveSlug: String(row.wave_slug),
|
|
996
|
+
phasePath: String(row.phase_path),
|
|
997
|
+
evidenceKind: String(row.evidence_kind),
|
|
998
|
+
payload: JSON.parse(String(row.payload)),
|
|
999
|
+
repoRoot: row.repo_root === null ? null : String(row.repo_root),
|
|
1000
|
+
recordedAt: String(row.recorded_at)
|
|
1001
|
+
}));
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// src/store/lifecycle-runs.ts
|
|
1005
|
+
import { createHash as createHash2 } from "crypto";
|
|
1006
|
+
|
|
1007
|
+
// src/operations/types.ts
|
|
1008
|
+
var OperationError = class extends Error {
|
|
1009
|
+
constructor(message) {
|
|
1010
|
+
super(message);
|
|
1011
|
+
this.name = "OperationError";
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
|
|
1015
|
+
// src/store/lifecycle-runs.ts
|
|
1016
|
+
var LIFECYCLE_STAGES = [
|
|
1017
|
+
"design",
|
|
1018
|
+
"plan",
|
|
1019
|
+
"prd",
|
|
1020
|
+
"work",
|
|
1021
|
+
"implementation",
|
|
1022
|
+
"release",
|
|
1023
|
+
"archive",
|
|
1024
|
+
"retrospective"
|
|
1025
|
+
];
|
|
1026
|
+
var LIFECYCLE_STATUSES = [
|
|
1027
|
+
"active",
|
|
1028
|
+
"paused",
|
|
1029
|
+
"completed",
|
|
1030
|
+
"failed",
|
|
1031
|
+
"abandoned"
|
|
1032
|
+
];
|
|
1033
|
+
var LifecycleRunNotFoundError = class extends OperationError {
|
|
1034
|
+
code = "lifecycle-run-not-found";
|
|
1035
|
+
constructor(projectId, runId) {
|
|
1036
|
+
super(`No lifecycle run \`${runId}\` exists for project \`${projectId}\`.`);
|
|
1037
|
+
this.name = "LifecycleRunNotFoundError";
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
var LifecycleRunExistsError = class extends OperationError {
|
|
1041
|
+
code = "lifecycle-run-exists";
|
|
1042
|
+
constructor(projectId, runId) {
|
|
1043
|
+
super(`Lifecycle run \`${runId}\` already exists for project \`${projectId}\`.`);
|
|
1044
|
+
this.name = "LifecycleRunExistsError";
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
var LifecycleVersionConflictError = class extends OperationError {
|
|
1048
|
+
code = "lifecycle-version-conflict";
|
|
1049
|
+
constructor(runId, expectedVersion, actualVersion) {
|
|
1050
|
+
super(
|
|
1051
|
+
`Lifecycle run \`${runId}\` is at version ${actualVersion}, not expected version ${expectedVersion}. Read the current run and retry with its explicit version.`
|
|
1052
|
+
);
|
|
1053
|
+
this.name = "LifecycleVersionConflictError";
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
function createLifecycleRun(db, input) {
|
|
1057
|
+
return immediateTransaction(db, () => {
|
|
1058
|
+
try {
|
|
1059
|
+
db.prepare(
|
|
1060
|
+
`INSERT INTO runs (
|
|
1061
|
+
project_id, run_id, run_type, lifecycle_stage, status, checkpoint,
|
|
1062
|
+
version, metadata, started_at, updated_at, finished_at
|
|
1063
|
+
) VALUES (?, ?, 'lifecycle', ?, 'active', ?, 1, ?, ?, ?, NULL)`
|
|
1064
|
+
).run(
|
|
1065
|
+
input.projectId,
|
|
1066
|
+
input.runId,
|
|
1067
|
+
input.lifecycleStage,
|
|
1068
|
+
input.checkpoint ?? null,
|
|
1069
|
+
JSON.stringify(input.metadata ?? {}),
|
|
1070
|
+
input.committedAt,
|
|
1071
|
+
input.committedAt
|
|
1072
|
+
);
|
|
1073
|
+
} catch (error) {
|
|
1074
|
+
if (isUniqueConstraintError(error)) {
|
|
1075
|
+
throw new LifecycleRunExistsError(input.projectId, input.runId);
|
|
1076
|
+
}
|
|
1077
|
+
throw error;
|
|
1078
|
+
}
|
|
1079
|
+
const run = readLifecycleRunOrThrow(db, input.projectId, input.runId);
|
|
1080
|
+
return {
|
|
1081
|
+
status: "captured",
|
|
1082
|
+
run,
|
|
1083
|
+
receipt: createLifecycleStoreMutationReceipt({
|
|
1084
|
+
operation: "lifecycle.start",
|
|
1085
|
+
projectId: input.projectId,
|
|
1086
|
+
runId: input.runId,
|
|
1087
|
+
resultingVersion: run.version,
|
|
1088
|
+
committedAt: input.committedAt
|
|
1089
|
+
})
|
|
1090
|
+
};
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
function readLifecycleRun(db, projectId, runId) {
|
|
1094
|
+
const row = db.prepare(
|
|
1095
|
+
`SELECT project_id, run_id, run_type, lifecycle_stage, status, checkpoint,
|
|
1096
|
+
version, metadata, started_at, updated_at, finished_at
|
|
1097
|
+
FROM runs WHERE project_id = ? AND run_id = ?`
|
|
1098
|
+
).get(projectId, runId);
|
|
1099
|
+
return row ? toLifecycleRunRow(row) : null;
|
|
1100
|
+
}
|
|
1101
|
+
function listLifecycleRuns(db, projectId) {
|
|
1102
|
+
const rows = db.prepare(
|
|
1103
|
+
`SELECT project_id, run_id, run_type, lifecycle_stage, status, checkpoint,
|
|
1104
|
+
version, metadata, started_at, updated_at, finished_at
|
|
1105
|
+
FROM runs WHERE project_id = ? ORDER BY started_at, run_id`
|
|
1106
|
+
).all(projectId);
|
|
1107
|
+
return rows.map(toLifecycleRunRow);
|
|
1108
|
+
}
|
|
1109
|
+
function transitionLifecycleRun(db, input) {
|
|
1110
|
+
return immediateTransaction(db, () => {
|
|
1111
|
+
const current = readLifecycleRunOrThrow(db, input.projectId, input.runId);
|
|
1112
|
+
assertExpectedVersion(current, input.expectedVersion);
|
|
1113
|
+
const resultingVersion = current.version + 1;
|
|
1114
|
+
const finishedAt = isTerminalStatus(input.nextStatus) ? input.committedAt : null;
|
|
1115
|
+
const result = db.prepare(
|
|
1116
|
+
`UPDATE runs SET
|
|
1117
|
+
lifecycle_stage = ?, status = ?, checkpoint = ?, version = ?,
|
|
1118
|
+
metadata = ?, updated_at = ?, finished_at = ?
|
|
1119
|
+
WHERE project_id = ? AND run_id = ? AND version = ?`
|
|
1120
|
+
).run(
|
|
1121
|
+
input.lifecycleStage ?? current.lifecycleStage,
|
|
1122
|
+
input.nextStatus,
|
|
1123
|
+
input.checkpoint === void 0 ? current.checkpoint : input.checkpoint,
|
|
1124
|
+
resultingVersion,
|
|
1125
|
+
JSON.stringify(input.metadata ?? current.metadata),
|
|
1126
|
+
input.committedAt,
|
|
1127
|
+
finishedAt,
|
|
1128
|
+
input.projectId,
|
|
1129
|
+
input.runId,
|
|
1130
|
+
input.expectedVersion
|
|
1131
|
+
);
|
|
1132
|
+
if (Number(result.changes) !== 1) {
|
|
1133
|
+
const latest = readLifecycleRunOrThrow(db, input.projectId, input.runId);
|
|
1134
|
+
throw new LifecycleVersionConflictError(
|
|
1135
|
+
input.runId,
|
|
1136
|
+
input.expectedVersion,
|
|
1137
|
+
latest.version
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1140
|
+
const run = readLifecycleRunOrThrow(db, input.projectId, input.runId);
|
|
1141
|
+
return {
|
|
1142
|
+
status: "captured",
|
|
1143
|
+
run,
|
|
1144
|
+
receipt: createLifecycleStoreMutationReceipt({
|
|
1145
|
+
operation: input.operation,
|
|
1146
|
+
projectId: input.projectId,
|
|
1147
|
+
runId: input.runId,
|
|
1148
|
+
resultingVersion,
|
|
1149
|
+
committedAt: input.committedAt
|
|
1150
|
+
})
|
|
1151
|
+
};
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
function attachLifecycleEvidence(db, input) {
|
|
1155
|
+
return immediateTransaction(db, () => {
|
|
1156
|
+
const current = readLifecycleRunOrThrow(db, input.projectId, input.runId);
|
|
1157
|
+
assertExpectedVersion(current, input.expectedVersion);
|
|
1158
|
+
try {
|
|
1159
|
+
db.prepare(
|
|
1160
|
+
`INSERT INTO run_evidence (
|
|
1161
|
+
project_id, run_id, evidence_id, evidence_kind, reference_type,
|
|
1162
|
+
reference_value, digest, recorded_at
|
|
1163
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
|
|
1164
|
+
).run(
|
|
1165
|
+
input.projectId,
|
|
1166
|
+
input.runId,
|
|
1167
|
+
input.evidenceId,
|
|
1168
|
+
input.evidenceKind,
|
|
1169
|
+
input.referenceType,
|
|
1170
|
+
input.reference,
|
|
1171
|
+
input.digest ?? null,
|
|
1172
|
+
input.committedAt
|
|
1173
|
+
);
|
|
1174
|
+
} catch (error) {
|
|
1175
|
+
if (isUniqueConstraintError(error)) {
|
|
1176
|
+
throw new OperationError(
|
|
1177
|
+
`Evidence \`${input.evidenceId}\` already exists for lifecycle run \`${input.runId}\`.`
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
throw error;
|
|
1181
|
+
}
|
|
1182
|
+
const resultingVersion = current.version + 1;
|
|
1183
|
+
const updated = db.prepare(
|
|
1184
|
+
`UPDATE runs SET version = ?, updated_at = ?
|
|
1185
|
+
WHERE project_id = ? AND run_id = ? AND version = ?`
|
|
1186
|
+
).run(
|
|
1187
|
+
resultingVersion,
|
|
1188
|
+
input.committedAt,
|
|
1189
|
+
input.projectId,
|
|
1190
|
+
input.runId,
|
|
1191
|
+
input.expectedVersion
|
|
1192
|
+
);
|
|
1193
|
+
if (Number(updated.changes) !== 1) {
|
|
1194
|
+
const latest = readLifecycleRunOrThrow(db, input.projectId, input.runId);
|
|
1195
|
+
throw new LifecycleVersionConflictError(
|
|
1196
|
+
input.runId,
|
|
1197
|
+
input.expectedVersion,
|
|
1198
|
+
latest.version
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
const run = readLifecycleRunOrThrow(db, input.projectId, input.runId);
|
|
1202
|
+
const evidence = readLifecycleEvidenceOrThrow(
|
|
1203
|
+
db,
|
|
1204
|
+
input.projectId,
|
|
1205
|
+
input.runId,
|
|
1206
|
+
input.evidenceId
|
|
1207
|
+
);
|
|
1208
|
+
return {
|
|
1209
|
+
status: "captured",
|
|
1210
|
+
run,
|
|
1211
|
+
evidence,
|
|
1212
|
+
receipt: createLifecycleStoreMutationReceipt({
|
|
1213
|
+
operation: "lifecycle.attach-evidence",
|
|
1214
|
+
projectId: input.projectId,
|
|
1215
|
+
runId: input.runId,
|
|
1216
|
+
resultingVersion,
|
|
1217
|
+
committedAt: input.committedAt
|
|
1218
|
+
})
|
|
1219
|
+
};
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
function listLifecycleEvidence(db, projectId, runId) {
|
|
1223
|
+
const rows = db.prepare(
|
|
1224
|
+
`SELECT project_id, run_id, evidence_id, evidence_kind, reference_type,
|
|
1225
|
+
reference_value, digest, recorded_at
|
|
1226
|
+
FROM run_evidence WHERE project_id = ? AND run_id = ?
|
|
1227
|
+
ORDER BY recorded_at, evidence_id`
|
|
1228
|
+
).all(projectId, runId);
|
|
1229
|
+
return rows.map(toLifecycleEvidenceRow);
|
|
1230
|
+
}
|
|
1231
|
+
function createLifecycleStoreMutationReceipt(input) {
|
|
1232
|
+
const subject = {
|
|
1233
|
+
schemaVersion: 1,
|
|
1234
|
+
operation: input.operation,
|
|
1235
|
+
projectId: input.projectId,
|
|
1236
|
+
runId: input.runId,
|
|
1237
|
+
storeSchemaVersion: CURRENT_STORE_SCHEMA_VERSION,
|
|
1238
|
+
resultingVersion: input.resultingVersion,
|
|
1239
|
+
committedAt: input.committedAt
|
|
1240
|
+
};
|
|
1241
|
+
return {
|
|
1242
|
+
schemaVersion: subject.schemaVersion,
|
|
1243
|
+
receiptId: `sha256:${createHash2("sha256").update(stableJson(subject)).digest("hex")}`,
|
|
1244
|
+
operation: subject.operation,
|
|
1245
|
+
projectId: subject.projectId,
|
|
1246
|
+
runId: subject.runId,
|
|
1247
|
+
storeSchemaVersion: subject.storeSchemaVersion,
|
|
1248
|
+
resultingVersion: subject.resultingVersion,
|
|
1249
|
+
committedAt: subject.committedAt
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
function immediateTransaction(db, apply) {
|
|
1253
|
+
db.exec("BEGIN IMMEDIATE");
|
|
1254
|
+
try {
|
|
1255
|
+
const result = apply();
|
|
1256
|
+
db.exec("COMMIT");
|
|
1257
|
+
return result;
|
|
1258
|
+
} catch (error) {
|
|
1259
|
+
try {
|
|
1260
|
+
db.exec("ROLLBACK");
|
|
1261
|
+
} catch {
|
|
1262
|
+
}
|
|
1263
|
+
throw error;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
function readLifecycleRunOrThrow(db, projectId, runId) {
|
|
1267
|
+
const run = readLifecycleRun(db, projectId, runId);
|
|
1268
|
+
if (!run) throw new LifecycleRunNotFoundError(projectId, runId);
|
|
1269
|
+
return run;
|
|
1270
|
+
}
|
|
1271
|
+
function readLifecycleEvidenceOrThrow(db, projectId, runId, evidenceId) {
|
|
1272
|
+
const row = db.prepare(
|
|
1273
|
+
`SELECT project_id, run_id, evidence_id, evidence_kind, reference_type,
|
|
1274
|
+
reference_value, digest, recorded_at
|
|
1275
|
+
FROM run_evidence
|
|
1276
|
+
WHERE project_id = ? AND run_id = ? AND evidence_id = ?`
|
|
1277
|
+
).get(projectId, runId, evidenceId);
|
|
1278
|
+
if (!row) {
|
|
1279
|
+
throw new OperationError(
|
|
1280
|
+
`Evidence \`${evidenceId}\` was not recorded for lifecycle run \`${runId}\`.`
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
return toLifecycleEvidenceRow(row);
|
|
1284
|
+
}
|
|
1285
|
+
function assertExpectedVersion(run, expectedVersion) {
|
|
1286
|
+
if (run.version !== expectedVersion) {
|
|
1287
|
+
throw new LifecycleVersionConflictError(run.runId, expectedVersion, run.version);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
function toLifecycleRunRow(row) {
|
|
1291
|
+
return {
|
|
1292
|
+
projectId: String(row.project_id),
|
|
1293
|
+
runId: String(row.run_id),
|
|
1294
|
+
runType: String(row.run_type),
|
|
1295
|
+
lifecycleStage: String(row.lifecycle_stage),
|
|
1296
|
+
status: String(row.status),
|
|
1297
|
+
checkpoint: row.checkpoint === null ? null : String(row.checkpoint),
|
|
1298
|
+
version: Number(row.version),
|
|
1299
|
+
metadata: JSON.parse(String(row.metadata)),
|
|
1300
|
+
startedAt: String(row.started_at),
|
|
1301
|
+
updatedAt: String(row.updated_at),
|
|
1302
|
+
finishedAt: row.finished_at === null ? null : String(row.finished_at)
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
function toLifecycleEvidenceRow(row) {
|
|
1306
|
+
return {
|
|
1307
|
+
projectId: String(row.project_id),
|
|
1308
|
+
runId: String(row.run_id),
|
|
1309
|
+
evidenceId: String(row.evidence_id),
|
|
1310
|
+
evidenceKind: String(row.evidence_kind),
|
|
1311
|
+
referenceType: String(row.reference_type),
|
|
1312
|
+
reference: String(row.reference_value),
|
|
1313
|
+
digest: row.digest === null ? null : String(row.digest),
|
|
1314
|
+
recordedAt: String(row.recorded_at)
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
function isTerminalStatus(status) {
|
|
1318
|
+
return status === "completed" || status === "failed" || status === "abandoned";
|
|
1319
|
+
}
|
|
1320
|
+
function isUniqueConstraintError(error) {
|
|
1321
|
+
return error instanceof Error && /UNIQUE constraint failed/i.test(error.message);
|
|
1322
|
+
}
|
|
1323
|
+
function stableJson(value) {
|
|
1324
|
+
return JSON.stringify(sortJson(value));
|
|
1325
|
+
}
|
|
1326
|
+
function sortJson(value) {
|
|
1327
|
+
if (Array.isArray(value)) return value.map(sortJson);
|
|
1328
|
+
if (value !== null && typeof value === "object") {
|
|
1329
|
+
return Object.fromEntries(
|
|
1330
|
+
Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => [key, sortJson(item)])
|
|
1331
|
+
);
|
|
1332
|
+
}
|
|
1333
|
+
return value;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
// src/store/project-state.ts
|
|
1337
|
+
function recordWorkEvidence(db, input) {
|
|
1338
|
+
upsertWorkEvidence(db, {
|
|
1339
|
+
projectId: input.projectId,
|
|
1340
|
+
waveSlug: input.identity.waveSlug,
|
|
1341
|
+
phasePath: input.identity.phasePath,
|
|
1342
|
+
evidenceKind: input.evidenceKind,
|
|
1343
|
+
payload: input.payload,
|
|
1344
|
+
repoRoot: input.identity.repoRoot,
|
|
1345
|
+
now: input.now
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
function readWorkItemEvidence(db, input) {
|
|
1349
|
+
return listWorkEvidence(db, {
|
|
1350
|
+
projectId: input.projectId,
|
|
1351
|
+
waveSlug: input.identity.waveSlug,
|
|
1352
|
+
phasePath: input.identity.phasePath
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
function listWaveEvidence(db, input) {
|
|
1356
|
+
return listWorkEvidence(db, {
|
|
1357
|
+
projectId: input.projectId,
|
|
1358
|
+
waveSlug: input.waveSlug
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
// src/store/lifecycle.ts
|
|
1363
|
+
import { existsSync as existsSync4, readdirSync, rmdirSync, statSync, unlinkSync } from "fs";
|
|
1364
|
+
import path5 from "path";
|
|
1365
|
+
var STORE_QUARANTINE_FILE_PREFIX = `${STORE_DATABASE_FILE}.corrupt-`;
|
|
1366
|
+
var KNOWN_STORE_FILES = /* @__PURE__ */ new Set([
|
|
1367
|
+
GLOBAL_CONFIG_FILE,
|
|
1368
|
+
GLOBAL_MANIFEST_FILE,
|
|
1369
|
+
STORE_DATABASE_FILE,
|
|
1370
|
+
`${STORE_DATABASE_FILE}-wal`,
|
|
1371
|
+
`${STORE_DATABASE_FILE}-shm`
|
|
1372
|
+
]);
|
|
1373
|
+
var PROJECT_MAKE_DOCS_MARKERS = [
|
|
1374
|
+
"config.yaml",
|
|
1375
|
+
"contracts",
|
|
1376
|
+
"references",
|
|
1377
|
+
"templates",
|
|
1378
|
+
"scripts",
|
|
1379
|
+
"agentics",
|
|
1380
|
+
"backup",
|
|
1381
|
+
"conflicts",
|
|
1382
|
+
"runs"
|
|
1383
|
+
];
|
|
1384
|
+
function removeGlobalStore(options = {}) {
|
|
1385
|
+
const storeRoot = resolveStoreRoot(options);
|
|
1386
|
+
const result = {
|
|
1387
|
+
status: "not-found",
|
|
1388
|
+
storeRoot,
|
|
1389
|
+
removedFiles: [],
|
|
1390
|
+
retainedEntries: [],
|
|
1391
|
+
warnings: []
|
|
1392
|
+
};
|
|
1393
|
+
let entries;
|
|
1394
|
+
try {
|
|
1395
|
+
if (!existsSync4(storeRoot) || !statSync(storeRoot).isDirectory()) {
|
|
1396
|
+
return result;
|
|
1397
|
+
}
|
|
1398
|
+
entries = readdirSync(storeRoot).sort();
|
|
1399
|
+
} catch (error) {
|
|
1400
|
+
result.status = "retained";
|
|
1401
|
+
result.warnings.push(
|
|
1402
|
+
`Could not read the make-docs global store at ${storeRoot} (${toMessage2(error)}); nothing was removed.`
|
|
1403
|
+
);
|
|
1404
|
+
return result;
|
|
1405
|
+
}
|
|
1406
|
+
const projectMarkers = entries.filter(
|
|
1407
|
+
(entry) => PROJECT_MAKE_DOCS_MARKERS.includes(entry)
|
|
1408
|
+
);
|
|
1409
|
+
if (projectMarkers.length > 0) {
|
|
1410
|
+
result.status = "refused";
|
|
1411
|
+
result.retainedEntries = entries;
|
|
1412
|
+
result.warnings.push(
|
|
1413
|
+
`Refusing to remove ${storeRoot}: it contains ${projectMarkers.join(", ")}, which marks a project .make-docs/ directory, not the machine-level store. No files were removed; repository content is never deleted by store handling.`
|
|
1414
|
+
);
|
|
1415
|
+
return result;
|
|
1416
|
+
}
|
|
1417
|
+
for (const entry of entries) {
|
|
1418
|
+
const isStoreFile = KNOWN_STORE_FILES.has(entry) || entry.startsWith(STORE_QUARANTINE_FILE_PREFIX);
|
|
1419
|
+
if (!isStoreFile) {
|
|
1420
|
+
result.retainedEntries.push(entry);
|
|
1421
|
+
continue;
|
|
1422
|
+
}
|
|
1423
|
+
try {
|
|
1424
|
+
unlinkSync(path5.join(storeRoot, entry));
|
|
1425
|
+
result.removedFiles.push(entry);
|
|
1426
|
+
} catch (error) {
|
|
1427
|
+
result.retainedEntries.push(entry);
|
|
1428
|
+
result.warnings.push(
|
|
1429
|
+
`Could not remove ${path5.join(storeRoot, entry)} (${toMessage2(error)}).`
|
|
1430
|
+
);
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
if (result.retainedEntries.length === 0) {
|
|
1434
|
+
try {
|
|
1435
|
+
rmdirSync(storeRoot);
|
|
1436
|
+
result.status = "removed";
|
|
1437
|
+
return result;
|
|
1438
|
+
} catch (error) {
|
|
1439
|
+
result.warnings.push(
|
|
1440
|
+
`Could not remove the store directory ${storeRoot} (${toMessage2(error)}).`
|
|
1441
|
+
);
|
|
1442
|
+
}
|
|
1443
|
+
} else {
|
|
1444
|
+
result.warnings.push(
|
|
1445
|
+
`The store directory ${storeRoot} was kept because it contains entries the store does not own: ${result.retainedEntries.join(", ")}.`
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
result.status = "retained";
|
|
1449
|
+
return result;
|
|
1450
|
+
}
|
|
1451
|
+
function toMessage2(error) {
|
|
1452
|
+
return error instanceof Error ? error.message : String(error);
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
// src/store/bootstrap.ts
|
|
1456
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync2 } from "fs";
|
|
1457
|
+
function bootstrapGlobalStore(options = {}) {
|
|
1458
|
+
const storeRoot = resolveStoreRoot(options);
|
|
1459
|
+
const now = (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
|
|
1460
|
+
const report = {
|
|
1461
|
+
storeRoot,
|
|
1462
|
+
configPath: getGlobalConfigPath(storeRoot),
|
|
1463
|
+
configCreated: false,
|
|
1464
|
+
manifestPath: getGlobalManifestPath(storeRoot),
|
|
1465
|
+
manifestCreated: false,
|
|
1466
|
+
databasePath: getStoreDatabasePath(storeRoot),
|
|
1467
|
+
databaseStatus: "unavailable",
|
|
1468
|
+
schemaVersion: null,
|
|
1469
|
+
warnings: []
|
|
1470
|
+
};
|
|
1471
|
+
try {
|
|
1472
|
+
mkdirSync2(storeRoot, { recursive: true, mode: 448 });
|
|
1473
|
+
} catch (error) {
|
|
1474
|
+
report.warnings.push(
|
|
1475
|
+
`Could not create the make-docs global store at ${storeRoot} (${toMessage3(error)}). Operational state will not be recorded; repository content is unaffected.`
|
|
1476
|
+
);
|
|
1477
|
+
return report;
|
|
1478
|
+
}
|
|
1479
|
+
try {
|
|
1480
|
+
if (!existsSync5(report.configPath)) {
|
|
1481
|
+
writeGlobalConfig(storeRoot, defaultGlobalConfig());
|
|
1482
|
+
report.configCreated = true;
|
|
1483
|
+
}
|
|
1484
|
+
} catch (error) {
|
|
1485
|
+
report.warnings.push(
|
|
1486
|
+
`Could not write the global config at ${report.configPath} (${toMessage3(error)}).`
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1489
|
+
try {
|
|
1490
|
+
const open = openStoreDatabase(storeRoot);
|
|
1491
|
+
try {
|
|
1492
|
+
report.schemaVersion = open.schemaVersion;
|
|
1493
|
+
if (open.recovered) {
|
|
1494
|
+
report.databaseStatus = "recovered";
|
|
1495
|
+
report.warnings.push(
|
|
1496
|
+
`The make-docs store database at ${open.databasePath} was unreadable and has been recreated (the old file was kept at ${open.quarantinedPath ?? "a quarantine path"}). This is recoverable operational-state loss (run state and recorded sign-offs); no project knowledge or repository content was lost, and state can be re-established.`
|
|
1497
|
+
);
|
|
1498
|
+
} else {
|
|
1499
|
+
report.databaseStatus = open.created ? "created" : "ready";
|
|
1500
|
+
}
|
|
1501
|
+
} finally {
|
|
1502
|
+
open.db.close();
|
|
1503
|
+
}
|
|
1504
|
+
} catch (error) {
|
|
1505
|
+
if (error instanceof StoreSchemaNewerError) {
|
|
1506
|
+
report.databaseStatus = "schema-newer";
|
|
1507
|
+
report.schemaVersion = error.databaseSchemaVersion;
|
|
1508
|
+
report.warnings.push(error.message);
|
|
1509
|
+
} else if (error instanceof StoreUnavailableError) {
|
|
1510
|
+
report.databaseStatus = "unavailable";
|
|
1511
|
+
report.warnings.push(error.message);
|
|
1512
|
+
} else {
|
|
1513
|
+
report.databaseStatus = "unavailable";
|
|
1514
|
+
report.warnings.push(
|
|
1515
|
+
`Could not open the make-docs store database at ${report.databasePath} (${toMessage3(error)}). Repository operations are unaffected.`
|
|
1516
|
+
);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
try {
|
|
1520
|
+
const existing = loadGlobalManifest(storeRoot);
|
|
1521
|
+
const manifest = existing ?? defaultGlobalManifest(now);
|
|
1522
|
+
report.manifestCreated = existing === null;
|
|
1523
|
+
manifest.updatedAt = now;
|
|
1524
|
+
manifest.lastBootstrap = {
|
|
1525
|
+
packageName: options.packageMeta?.name ?? "make-docs",
|
|
1526
|
+
packageVersion: options.packageMeta?.version ?? "unknown",
|
|
1527
|
+
nodeVersion: process.version,
|
|
1528
|
+
at: now
|
|
1529
|
+
};
|
|
1530
|
+
manifest.database = {
|
|
1531
|
+
file: "store.db",
|
|
1532
|
+
schemaVersion: report.databaseStatus === "unavailable" ? manifest.database.schemaVersion : report.schemaVersion,
|
|
1533
|
+
status: report.databaseStatus
|
|
1534
|
+
};
|
|
1535
|
+
writeGlobalManifest(storeRoot, manifest);
|
|
1536
|
+
} catch (error) {
|
|
1537
|
+
report.warnings.push(
|
|
1538
|
+
`Could not write the global manifest at ${report.manifestPath} (${toMessage3(error)}).`
|
|
1539
|
+
);
|
|
1540
|
+
}
|
|
1541
|
+
return report;
|
|
1542
|
+
}
|
|
1543
|
+
function toMessage3(error) {
|
|
1544
|
+
return error instanceof Error ? error.message : String(error);
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
export {
|
|
1548
|
+
OperationError,
|
|
1549
|
+
loadGlobalConfig,
|
|
1550
|
+
writeGlobalConfig,
|
|
1551
|
+
previewStoreCompatibilityBridge,
|
|
1552
|
+
LIFECYCLE_STAGES,
|
|
1553
|
+
LIFECYCLE_STATUSES,
|
|
1554
|
+
LifecycleRunNotFoundError,
|
|
1555
|
+
LifecycleRunExistsError,
|
|
1556
|
+
LifecycleVersionConflictError,
|
|
1557
|
+
createLifecycleRun,
|
|
1558
|
+
readLifecycleRun,
|
|
1559
|
+
listLifecycleRuns,
|
|
1560
|
+
transitionLifecycleRun,
|
|
1561
|
+
attachLifecycleEvidence,
|
|
1562
|
+
listLifecycleEvidence,
|
|
1563
|
+
recordWorkEvidence,
|
|
1564
|
+
readWorkItemEvidence,
|
|
1565
|
+
listWaveEvidence,
|
|
1566
|
+
resolveProjectIdentity,
|
|
1567
|
+
removeGlobalStore,
|
|
1568
|
+
bootstrapGlobalStore,
|
|
1569
|
+
recordHarnessIntegrationReceipt,
|
|
1570
|
+
readCurrentHarnessIntegrationReceipt,
|
|
1571
|
+
prepareHarnessSystemOperation,
|
|
1572
|
+
readPendingHarnessSystemOperation,
|
|
1573
|
+
completeHarnessSystemOperation
|
|
1574
|
+
};
|
|
1575
|
+
//# sourceMappingURL=chunk-3BAJQXGH.js.map
|