@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,2340 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
assertManagedPathHasNoSymlinks,
|
|
4
|
+
platform
|
|
5
|
+
} from "./chunk-MXBHCHSM.js";
|
|
6
|
+
|
|
7
|
+
// src/harness-access/contract.ts
|
|
8
|
+
import { createHash } from "crypto";
|
|
9
|
+
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
12
|
+
var HARNESS_CALLER_IDENTITY_ENV = "MAKE_DOCS_HARNESS_CALLER_IDENTITY";
|
|
13
|
+
var HARNESS_CALLER_IDENTITY_ARG = "--make-docs-harness-caller";
|
|
14
|
+
var HARNESS_CALLER_REFERENCE_ARG = "--make-docs-harness-caller-ref";
|
|
15
|
+
var ExecutableVerificationError = class extends Error {
|
|
16
|
+
constructor(code, message, launchPath, resolvedPath, failedRule, nextAction) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.launchPath = launchPath;
|
|
20
|
+
this.resolvedPath = resolvedPath;
|
|
21
|
+
this.failedRule = failedRule;
|
|
22
|
+
this.nextAction = nextAction;
|
|
23
|
+
}
|
|
24
|
+
name = "ExecutableVerificationError";
|
|
25
|
+
};
|
|
26
|
+
var FORBIDDEN_EXECUTABLE_NAMES = /* @__PURE__ */ new Set([
|
|
27
|
+
"bash",
|
|
28
|
+
"bun",
|
|
29
|
+
"cmd",
|
|
30
|
+
"deno",
|
|
31
|
+
"node",
|
|
32
|
+
"npm",
|
|
33
|
+
"npx",
|
|
34
|
+
"pnpm",
|
|
35
|
+
"powershell",
|
|
36
|
+
"pwsh",
|
|
37
|
+
"sh",
|
|
38
|
+
"yarn",
|
|
39
|
+
"zsh"
|
|
40
|
+
]);
|
|
41
|
+
var FORBIDDEN_COMMAND_WORDS = /* @__PURE__ */ new Set([
|
|
42
|
+
"backup",
|
|
43
|
+
"remove",
|
|
44
|
+
"setup",
|
|
45
|
+
"uninstall",
|
|
46
|
+
"update"
|
|
47
|
+
]);
|
|
48
|
+
var SAFE_COMMAND_WORD = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
|
|
49
|
+
var SHA256 = /^[0-9a-f]{64}$/;
|
|
50
|
+
var PACKAGE_NAME = "@brucewaynedecoy/make-docs";
|
|
51
|
+
var PRODUCT_MARKER = "@brucewaynedecoy/make-docs:package-bin";
|
|
52
|
+
function sha256(value) {
|
|
53
|
+
return createHash("sha256").update(value).digest("hex");
|
|
54
|
+
}
|
|
55
|
+
function verifyMakeDocsExecutable(input) {
|
|
56
|
+
return verifyExecutableAgainstPackage(input, resolvePackagedExecutableIdentity());
|
|
57
|
+
}
|
|
58
|
+
function reverifyMakeDocsExecutableIdentity(executable) {
|
|
59
|
+
return verifyMakeDocsExecutable({
|
|
60
|
+
executablePath: executable.launchPath ?? executable.path,
|
|
61
|
+
expectedSha256: executable.sha256
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function verifyExecutableAgainstPackage(input, packaged) {
|
|
65
|
+
if (!path.isAbsolute(input.executablePath)) {
|
|
66
|
+
throw verificationError(
|
|
67
|
+
"executable-path-not-absolute",
|
|
68
|
+
"The Make Docs executable path must be absolute.",
|
|
69
|
+
input.executablePath,
|
|
70
|
+
null,
|
|
71
|
+
"absolute-launch-path",
|
|
72
|
+
"Run the installed `make-docs` command through its absolute package-manager link."
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (input.expectedSha256 !== void 0 && !SHA256.test(input.expectedSha256)) {
|
|
76
|
+
throw verificationError(
|
|
77
|
+
"executable-fingerprint-invalid",
|
|
78
|
+
"The expected Make Docs executable fingerprint must be a SHA-256 digest.",
|
|
79
|
+
input.executablePath,
|
|
80
|
+
null,
|
|
81
|
+
"expected-sha256",
|
|
82
|
+
"Create a new setup review from the active installed executable."
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
let launchStat;
|
|
86
|
+
try {
|
|
87
|
+
launchStat = lstatSync(input.executablePath);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
throw verificationError(
|
|
90
|
+
"executable-path-missing",
|
|
91
|
+
`The Make Docs launch path cannot be read: ${toMessage(error)}`,
|
|
92
|
+
input.executablePath,
|
|
93
|
+
null,
|
|
94
|
+
"launch-path-present",
|
|
95
|
+
"Run setup from the installed `make-docs` command or reinstall the package if the link is missing."
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
let actualPath;
|
|
99
|
+
try {
|
|
100
|
+
actualPath = realpathSync(input.executablePath);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
throw verificationError(
|
|
103
|
+
"executable-link-broken",
|
|
104
|
+
`The Make Docs launch path cannot resolve to a package binary: ${toMessage(error)}`,
|
|
105
|
+
input.executablePath,
|
|
106
|
+
null,
|
|
107
|
+
"resolved-package-bin",
|
|
108
|
+
"Repair or reinstall the broken package-manager link, then review setup again."
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
const stat = lstatSync(actualPath);
|
|
112
|
+
if (!stat.isFile()) {
|
|
113
|
+
throw verificationError(
|
|
114
|
+
"executable-not-file",
|
|
115
|
+
"The resolved Make Docs package binary is not a regular file.",
|
|
116
|
+
input.executablePath,
|
|
117
|
+
actualPath,
|
|
118
|
+
"regular-package-bin",
|
|
119
|
+
"Repair the installed package and review setup again."
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
if (!platform.acceptsExecutableMode(stat.mode)) {
|
|
123
|
+
throw verificationError(
|
|
124
|
+
"executable-not-executable",
|
|
125
|
+
"The resolved Make Docs package binary is not executable.",
|
|
126
|
+
input.executablePath,
|
|
127
|
+
actualPath,
|
|
128
|
+
"executable-package-bin",
|
|
129
|
+
"Repair the package file mode or reinstall the package, then review setup again."
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
const executableName = path.basename(input.executablePath).toLowerCase().replace(/\.exe$/, "");
|
|
133
|
+
if (FORBIDDEN_EXECUTABLE_NAMES.has(executableName)) {
|
|
134
|
+
throw verificationError(
|
|
135
|
+
"executable-runner-forbidden",
|
|
136
|
+
`A package runner or shell cannot be used as the Make Docs executable: ${executableName}.`,
|
|
137
|
+
input.executablePath,
|
|
138
|
+
actualPath,
|
|
139
|
+
"direct-make-docs-launcher",
|
|
140
|
+
"Run the installed `make-docs` command directly, then review setup again."
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
const bytes = readFileSync(actualPath);
|
|
144
|
+
const actualSha256 = sha256(bytes);
|
|
145
|
+
if (input.expectedSha256 !== void 0 && actualSha256 !== input.expectedSha256) {
|
|
146
|
+
throw verificationError(
|
|
147
|
+
"executable-fingerprint-mismatch",
|
|
148
|
+
"The Make Docs executable fingerprint does not match the reviewed executable.",
|
|
149
|
+
input.executablePath,
|
|
150
|
+
actualPath,
|
|
151
|
+
"reviewed-sha256",
|
|
152
|
+
"Create a new setup review from the current installed executable."
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (actualPath !== packaged.path) {
|
|
156
|
+
throw verificationError(
|
|
157
|
+
"executable-package-mismatch",
|
|
158
|
+
"The executable is not the exact Make Docs package binary for this installation.",
|
|
159
|
+
input.executablePath,
|
|
160
|
+
actualPath,
|
|
161
|
+
"declared-package-bin",
|
|
162
|
+
"Run the `make-docs` command installed by this package, then review setup again."
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
kind: "make-docs",
|
|
167
|
+
launchPath: input.executablePath,
|
|
168
|
+
path: packaged.path,
|
|
169
|
+
sha256: actualSha256,
|
|
170
|
+
size: bytes.byteLength,
|
|
171
|
+
productMarker: PRODUCT_MARKER,
|
|
172
|
+
packageName: PACKAGE_NAME,
|
|
173
|
+
packageVersion: packaged.packageVersion,
|
|
174
|
+
packageRoot: packaged.packageRoot,
|
|
175
|
+
binRelativePath: packaged.binRelativePath
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function verificationError(code, message, launchPath, resolvedPath, failedRule, nextAction) {
|
|
179
|
+
return new ExecutableVerificationError(
|
|
180
|
+
code,
|
|
181
|
+
message,
|
|
182
|
+
launchPath,
|
|
183
|
+
resolvedPath,
|
|
184
|
+
failedRule,
|
|
185
|
+
nextAction
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
function toMessage(error) {
|
|
189
|
+
return error instanceof Error ? error.message : String(error);
|
|
190
|
+
}
|
|
191
|
+
function resolvePackagedExecutableIdentity() {
|
|
192
|
+
let candidate = path.dirname(fileURLToPath(import.meta.url));
|
|
193
|
+
for (let depth = 0; depth < 5; depth += 1) {
|
|
194
|
+
const manifestPath = path.join(candidate, "package.json");
|
|
195
|
+
try {
|
|
196
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
197
|
+
const bin = manifest.bin;
|
|
198
|
+
if (manifest.name === PACKAGE_NAME && typeof manifest.version === "string" && manifest.version.trim() && bin && typeof bin === "object" && typeof bin["make-docs"] === "string") {
|
|
199
|
+
const binRelativePath = bin["make-docs"];
|
|
200
|
+
const packageRoot = realpathSync(candidate);
|
|
201
|
+
const executablePath = realpathSync(path.resolve(packageRoot, binRelativePath));
|
|
202
|
+
const relative = path.relative(packageRoot, executablePath);
|
|
203
|
+
if (relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
204
|
+
throw new Error("The Make Docs package binary escapes its package root.");
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
path: executablePath,
|
|
208
|
+
packageVersion: manifest.version,
|
|
209
|
+
packageRoot,
|
|
210
|
+
binRelativePath
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
} catch (error) {
|
|
214
|
+
if (error.code !== "ENOENT") throw error;
|
|
215
|
+
}
|
|
216
|
+
const parent = path.dirname(candidate);
|
|
217
|
+
if (parent === candidate) break;
|
|
218
|
+
candidate = parent;
|
|
219
|
+
}
|
|
220
|
+
throw new Error("The active Make Docs package identity could not be proved.");
|
|
221
|
+
}
|
|
222
|
+
function validateHarnessCommandRules(rules, authority) {
|
|
223
|
+
if (!rules || rules.length === 0) {
|
|
224
|
+
throw new Error("A command-rule method needs at least one registry-derived command prefix.");
|
|
225
|
+
}
|
|
226
|
+
if (!authority) {
|
|
227
|
+
throw new Error("A command-rule method needs the operation registry validation authority.");
|
|
228
|
+
}
|
|
229
|
+
const ids = /* @__PURE__ */ new Set();
|
|
230
|
+
const prefixes = /* @__PURE__ */ new Set();
|
|
231
|
+
for (const rule of rules) {
|
|
232
|
+
if (!rule.id.trim() || ids.has(rule.id)) {
|
|
233
|
+
throw new Error(`Command-rule identifiers must be non-empty and unique: ${rule.id || "<empty>"}.`);
|
|
234
|
+
}
|
|
235
|
+
ids.add(rule.id);
|
|
236
|
+
if (rule.commandPrefix.length < 2) {
|
|
237
|
+
throw new Error(`Command rule ${rule.id} is too broad. Use a command and subcommand.`);
|
|
238
|
+
}
|
|
239
|
+
if (rule.operationIds.length === 0) {
|
|
240
|
+
throw new Error(`Command rule ${rule.id} has no admitted operation.`);
|
|
241
|
+
}
|
|
242
|
+
if (isAdministrativeCommandRule(rule)) {
|
|
243
|
+
throw new Error(`Command rule ${rule.id} cannot approve lifecycle or recovery administration.`);
|
|
244
|
+
}
|
|
245
|
+
if (rule.access.hostConfig !== "none") {
|
|
246
|
+
throw new Error(`Command rule ${rule.id} cannot approve host-configuration writes.`);
|
|
247
|
+
}
|
|
248
|
+
for (const word of rule.commandPrefix) {
|
|
249
|
+
if (!SAFE_COMMAND_WORD.test(word)) {
|
|
250
|
+
throw new Error(`Command rule ${rule.id} contains an unsafe command word: ${word}.`);
|
|
251
|
+
}
|
|
252
|
+
if (FORBIDDEN_COMMAND_WORDS.has(word.toLowerCase())) {
|
|
253
|
+
throw new Error(`Command rule ${rule.id} cannot approve ${word}.`);
|
|
254
|
+
}
|
|
255
|
+
if (FORBIDDEN_EXECUTABLE_NAMES.has(word.toLowerCase().replace(/\.exe$/, ""))) {
|
|
256
|
+
throw new Error(`Command rule ${rule.id} cannot approve a wrapper or package runner: ${word}.`);
|
|
257
|
+
}
|
|
258
|
+
if (word.toLowerCase() === "make-docs") {
|
|
259
|
+
throw new Error(`Command rule ${rule.id} contains an extra executable token.`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const prefixKey = rule.commandPrefix.join("\0");
|
|
263
|
+
if (prefixes.has(prefixKey)) {
|
|
264
|
+
throw new Error(`Command prefixes must be unique: ${rule.commandPrefix.join(" ")}.`);
|
|
265
|
+
}
|
|
266
|
+
prefixes.add(prefixKey);
|
|
267
|
+
}
|
|
268
|
+
authority.validate(rules);
|
|
269
|
+
const registryRules = authority.list();
|
|
270
|
+
const candidates = new Map(registryRules.map((rule) => [rule.id, rule]));
|
|
271
|
+
if (registryRules.length !== rules.length || candidates.size !== registryRules.length) {
|
|
272
|
+
throw new Error("Command rules must contain every exact operation-registry candidate once.");
|
|
273
|
+
}
|
|
274
|
+
for (const rule of rules) {
|
|
275
|
+
const candidate = candidates.get(rule.id);
|
|
276
|
+
if (!candidate) {
|
|
277
|
+
throw new Error(`Command rule ${rule.id} is not an exact operation-registry candidate.`);
|
|
278
|
+
}
|
|
279
|
+
if (rule.operationIds.length !== 1 || rule.operationIds[0] !== candidate.operationIds[0] || rule.commandPrefix.length !== candidate.commandPrefix.length || rule.commandPrefix.some((word, index) => word !== candidate.commandPrefix[index]) || rule.access.store !== candidate.access.store || rule.access.project !== candidate.access.project || rule.access.hostConfig !== candidate.access.hostConfig) {
|
|
280
|
+
throw new Error(`Command rule ${rule.id} does not match its exact operation-registry command and access declaration.`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return Object.freeze([...rules]);
|
|
284
|
+
}
|
|
285
|
+
function listBoundedHarnessCommandRules(authority) {
|
|
286
|
+
if (!authority) return Object.freeze([]);
|
|
287
|
+
return validateHarnessCommandRules(authority.list(), authority);
|
|
288
|
+
}
|
|
289
|
+
function isAdministrativeCommandRule(rule) {
|
|
290
|
+
return rule.operationIds.some(
|
|
291
|
+
(operationId) => operationId.startsWith("lifecycle.") || operationId === "project.state.recover"
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
function canonicalJson(value) {
|
|
295
|
+
return JSON.stringify(sortJson(value));
|
|
296
|
+
}
|
|
297
|
+
function fingerprintEntry(value) {
|
|
298
|
+
return sha256(canonicalJson(value));
|
|
299
|
+
}
|
|
300
|
+
function encodeHarnessCallerIdentity(identity) {
|
|
301
|
+
assertHarnessCallerIdentityShape(identity);
|
|
302
|
+
return canonicalJson(identity);
|
|
303
|
+
}
|
|
304
|
+
function encodeHarnessCallerIdentityArgument(identity) {
|
|
305
|
+
return Buffer.from(encodeHarnessCallerIdentity(identity), "utf8").toString("base64url");
|
|
306
|
+
}
|
|
307
|
+
function encodeHarnessCallerReference(identity) {
|
|
308
|
+
assertHarnessCallerIdentityShape(identity);
|
|
309
|
+
if (identity.kind !== "make-docs-harness-caller" || identity.harnessId !== "claude-code" || identity.connectionMethod !== "permission-rules" || identity.adapterVersion !== 1) {
|
|
310
|
+
throw new Error("A caller reference needs the Claude Code permission-rules v1 identity.");
|
|
311
|
+
}
|
|
312
|
+
const root = canonicalMachineRoot(identity.root);
|
|
313
|
+
if (root !== identity.root) {
|
|
314
|
+
throw new Error("The caller reference machine root must be canonical.");
|
|
315
|
+
}
|
|
316
|
+
const encodedRoot = Buffer.from(root, "utf8").toString("base64url");
|
|
317
|
+
const digest = sha256(encodeHarnessCallerIdentity(identity));
|
|
318
|
+
return `claude-code.permission-rules.v1.${encodedRoot}.${digest}`;
|
|
319
|
+
}
|
|
320
|
+
function parseHarnessCallerReference(raw) {
|
|
321
|
+
const match = /^claude-code\.permission-rules\.v1\.([A-Za-z0-9_-]+)\.([0-9a-f]{64})$/.exec(raw);
|
|
322
|
+
if (!match) {
|
|
323
|
+
throw new Error("The harness caller reference has an invalid format.");
|
|
324
|
+
}
|
|
325
|
+
const encodedRoot = match[1];
|
|
326
|
+
const decodedBytes = Buffer.from(encodedRoot, "base64url");
|
|
327
|
+
const root = decodedBytes.toString("utf8");
|
|
328
|
+
if (!root || Buffer.from(root, "utf8").toString("base64url") !== encodedRoot) {
|
|
329
|
+
throw new Error("The harness caller reference root is not canonical base64url.");
|
|
330
|
+
}
|
|
331
|
+
if (canonicalMachineRoot(root) !== root) {
|
|
332
|
+
throw new Error("The harness caller reference root is not a canonical absolute path.");
|
|
333
|
+
}
|
|
334
|
+
return Object.freeze({
|
|
335
|
+
raw,
|
|
336
|
+
harnessId: "claude-code",
|
|
337
|
+
connectionMethod: "permission-rules",
|
|
338
|
+
adapterVersion: 1,
|
|
339
|
+
root,
|
|
340
|
+
identitySha256: match[2]
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
function canonicalMachineRoot(root) {
|
|
344
|
+
if (!path.isAbsolute(root) || root.includes("\0") || path.normalize(root) !== root) {
|
|
345
|
+
throw new Error("The harness caller reference root must be an absolute normalized path.");
|
|
346
|
+
}
|
|
347
|
+
try {
|
|
348
|
+
const stat = lstatSync(root);
|
|
349
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("not-directory");
|
|
350
|
+
return platform.describePath(root).canonicalPath;
|
|
351
|
+
} catch {
|
|
352
|
+
throw new Error("The harness caller reference root does not exist.");
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function parseHarnessCallerIdentityArgument(raw) {
|
|
356
|
+
if (!raw || !/^[A-Za-z0-9_-]+$/.test(raw)) {
|
|
357
|
+
throw new Error("The harness caller identity argument is not valid base64url.");
|
|
358
|
+
}
|
|
359
|
+
const decoded = Buffer.from(raw, "base64url").toString("utf8");
|
|
360
|
+
if (Buffer.from(decoded, "utf8").toString("base64url") !== raw) {
|
|
361
|
+
throw new Error("The harness caller identity argument is not canonical base64url.");
|
|
362
|
+
}
|
|
363
|
+
return parseHarnessCallerIdentityValue(decoded);
|
|
364
|
+
}
|
|
365
|
+
function parseHarnessCallerIdentityValue(raw) {
|
|
366
|
+
let parsed;
|
|
367
|
+
try {
|
|
368
|
+
parsed = JSON.parse(raw);
|
|
369
|
+
} catch {
|
|
370
|
+
throw new Error("The harness caller identity is not valid JSON.");
|
|
371
|
+
}
|
|
372
|
+
assertHarnessCallerIdentityShape(parsed);
|
|
373
|
+
return Object.freeze({
|
|
374
|
+
...parsed,
|
|
375
|
+
executable: Object.freeze({ ...parsed.executable })
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
function parseHarnessCallerIdentity(raw) {
|
|
379
|
+
const parsed = parseHarnessCallerIdentityValue(raw);
|
|
380
|
+
if (parsed.kind !== "make-docs-harness-caller") {
|
|
381
|
+
throw new Error("The harness caller identity is not a first-party adapter identity.");
|
|
382
|
+
}
|
|
383
|
+
return parsed;
|
|
384
|
+
}
|
|
385
|
+
function assertHarnessCallerIdentityShape(value) {
|
|
386
|
+
const generic = Boolean(
|
|
387
|
+
value && typeof value === "object" && !Array.isArray(value) && value.kind === "make-docs-generic-mcp-caller"
|
|
388
|
+
);
|
|
389
|
+
if (!isExactRecord(value, [
|
|
390
|
+
"schemaVersion",
|
|
391
|
+
"kind",
|
|
392
|
+
"adapterId",
|
|
393
|
+
"adapterVersion",
|
|
394
|
+
"harnessId",
|
|
395
|
+
"connectionMethod",
|
|
396
|
+
"scope",
|
|
397
|
+
"root",
|
|
398
|
+
"executable",
|
|
399
|
+
...generic ? ["proof"] : []
|
|
400
|
+
])) {
|
|
401
|
+
throw new Error("The harness caller identity has an invalid object shape.");
|
|
402
|
+
}
|
|
403
|
+
if (value.schemaVersion !== 1 || value.kind !== "make-docs-harness-caller" && value.kind !== "make-docs-generic-mcp-caller" || typeof value.adapterId !== "string" || !value.adapterId.trim() || !Number.isSafeInteger(value.adapterVersion) || value.adapterVersion < 1 || (generic ? typeof value.harnessId !== "string" || !/^generic-mcp-[a-z][a-z0-9-]*$/.test(value.harnessId) : value.harnessId !== "codex" && value.harnessId !== "claude-code") || !["mcp", "command-rules", "permission-rules"].includes(value.connectionMethod) || value.scope !== "machine" || typeof value.root !== "string" || !path.isAbsolute(value.root)) {
|
|
404
|
+
throw new Error("The harness caller identity fields are invalid.");
|
|
405
|
+
}
|
|
406
|
+
if (generic && (value.adapterId !== "generic-mcp" || value.adapterVersion !== 1 || value.connectionMethod !== "mcp" || typeof value.proof !== "string" || !/^[A-Za-z0-9_-]{32,}$/.test(value.proof))) {
|
|
407
|
+
throw new Error("The generic MCP caller identity fields are invalid.");
|
|
408
|
+
}
|
|
409
|
+
assertExecutableIdentityShape(value.executable);
|
|
410
|
+
}
|
|
411
|
+
function assertExecutableIdentityShape(value) {
|
|
412
|
+
if (!isExactRecordWithOptionalKeys(value, [
|
|
413
|
+
"kind",
|
|
414
|
+
"path",
|
|
415
|
+
"sha256",
|
|
416
|
+
"size",
|
|
417
|
+
"productMarker",
|
|
418
|
+
"packageName",
|
|
419
|
+
"packageVersion",
|
|
420
|
+
"packageRoot",
|
|
421
|
+
"binRelativePath"
|
|
422
|
+
], ["launchPath"])) {
|
|
423
|
+
throw new Error("The harness caller executable identity has an invalid object shape.");
|
|
424
|
+
}
|
|
425
|
+
if (value.kind !== "make-docs" || value.launchPath !== void 0 && (typeof value.launchPath !== "string" || !path.isAbsolute(value.launchPath)) || typeof value.path !== "string" || !path.isAbsolute(value.path) || typeof value.sha256 !== "string" || !SHA256.test(value.sha256) || !Number.isSafeInteger(value.size) || value.size < 1 || value.productMarker !== PRODUCT_MARKER || value.packageName !== PACKAGE_NAME || typeof value.packageVersion !== "string" || !value.packageVersion.trim() || typeof value.packageRoot !== "string" || !path.isAbsolute(value.packageRoot) || typeof value.binRelativePath !== "string" || !value.binRelativePath || path.isAbsolute(value.binRelativePath) || value.binRelativePath.split(/[\\/]/).includes("..")) {
|
|
426
|
+
throw new Error("The harness caller executable identity fields are invalid.");
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
function isExactRecordWithOptionalKeys(value, requiredKeys, optionalKeys) {
|
|
430
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
431
|
+
const actual = Object.keys(value);
|
|
432
|
+
const allowed = /* @__PURE__ */ new Set([...requiredKeys, ...optionalKeys]);
|
|
433
|
+
return requiredKeys.every((key) => actual.includes(key)) && actual.every((key) => allowed.has(key));
|
|
434
|
+
}
|
|
435
|
+
function isExactRecord(value, keys) {
|
|
436
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
437
|
+
const actual = Object.keys(value).sort();
|
|
438
|
+
const expected = [...keys].sort();
|
|
439
|
+
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
440
|
+
}
|
|
441
|
+
function resolveHarnessMethodSupport(adapter, methodId) {
|
|
442
|
+
const method2 = adapter.methods.find((candidate) => candidate.id === methodId);
|
|
443
|
+
if (!method2) {
|
|
444
|
+
return {
|
|
445
|
+
state: "unsupported",
|
|
446
|
+
selectable: false,
|
|
447
|
+
reason: `${adapter.displayName} does not implement ${methodId}.`,
|
|
448
|
+
nextAction: `Choose one of the methods admitted by ${adapter.displayName}.`
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
if (method2.availability === "blocked") {
|
|
452
|
+
return {
|
|
453
|
+
state: "blocked",
|
|
454
|
+
selectable: false,
|
|
455
|
+
reason: method2.blocker ?? `${adapter.displayName} ${methodId} is blocked.`,
|
|
456
|
+
nextAction: method2.nextAction
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
return {
|
|
460
|
+
state: "available",
|
|
461
|
+
selectable: true,
|
|
462
|
+
reason: `${adapter.displayName} ${methodId} is a product-owned setup method.`,
|
|
463
|
+
nextAction: method2.nextAction
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
function sortJson(value) {
|
|
467
|
+
if (Array.isArray(value)) return value.map(sortJson);
|
|
468
|
+
if (value && typeof value === "object") {
|
|
469
|
+
return Object.fromEntries(
|
|
470
|
+
Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, sortJson(child)])
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
return value;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// src/harness-access/native.ts
|
|
477
|
+
import {
|
|
478
|
+
closeSync,
|
|
479
|
+
constants,
|
|
480
|
+
existsSync,
|
|
481
|
+
fstatSync,
|
|
482
|
+
lstatSync as lstatSync2,
|
|
483
|
+
mkdirSync,
|
|
484
|
+
openSync,
|
|
485
|
+
readFileSync as readFileSync2,
|
|
486
|
+
unlinkSync,
|
|
487
|
+
writeFileSync
|
|
488
|
+
} from "fs";
|
|
489
|
+
import path2 from "path";
|
|
490
|
+
import { randomUUID } from "crypto";
|
|
491
|
+
var harnessNativeMutationHookForTests = null;
|
|
492
|
+
var CODEX_MCP_BEGIN = "# make-docs:begin harness-access codex mcp";
|
|
493
|
+
var CODEX_MCP_END = "# make-docs:end harness-access codex mcp";
|
|
494
|
+
function createHarnessAdapter(definition) {
|
|
495
|
+
const adapter = {
|
|
496
|
+
...definition,
|
|
497
|
+
detect: (input) => detectHarness(definition, input.scope, input.root, input.path),
|
|
498
|
+
plan: (input) => planHarnessAccess(adapter, input),
|
|
499
|
+
apply: (input) => applyHarnessAccessPlan(
|
|
500
|
+
adapter,
|
|
501
|
+
input.plan,
|
|
502
|
+
input.approved,
|
|
503
|
+
input.operationId,
|
|
504
|
+
input.appliedVersion,
|
|
505
|
+
input.verifiedAt
|
|
506
|
+
),
|
|
507
|
+
applyRemoval: (input) => applyHarnessRemovalPlan(adapter, input.plan, input.approved),
|
|
508
|
+
verify: (input) => verifyHarnessAccess(adapter, input),
|
|
509
|
+
repair: (input) => planHarnessAccess(adapter, input),
|
|
510
|
+
planRemoval: (input) => planHarnessAccessRemoval(adapter, input)
|
|
511
|
+
};
|
|
512
|
+
return Object.freeze(adapter);
|
|
513
|
+
}
|
|
514
|
+
function detectHarness(adapter, scope, root, executablePath) {
|
|
515
|
+
try {
|
|
516
|
+
assertSafeRoot(root);
|
|
517
|
+
const evidence = /* @__PURE__ */ new Set();
|
|
518
|
+
for (const executableName of adapter.executableNames) {
|
|
519
|
+
if (findExecutableOnPath(executableName, executablePath)) evidence.add(`executable:${executableName}`);
|
|
520
|
+
}
|
|
521
|
+
for (const method2 of adapter.methods.filter((candidate) => candidate.scopes.includes(scope))) {
|
|
522
|
+
const relativePath = method2.nativeFile(scope);
|
|
523
|
+
assertNativePath(root, relativePath);
|
|
524
|
+
const absolutePath = path2.join(root, relativePath);
|
|
525
|
+
if (existsSync(absolutePath)) evidence.add(relativePath);
|
|
526
|
+
const nativeRoot = path2.normalize(relativePath).split(path2.sep)[0];
|
|
527
|
+
if (nativeRoot && existsSync(path2.join(root, nativeRoot))) evidence.add(nativeRoot);
|
|
528
|
+
}
|
|
529
|
+
return {
|
|
530
|
+
adapterId: adapter.id,
|
|
531
|
+
harnessId: adapter.harnessId,
|
|
532
|
+
scope,
|
|
533
|
+
state: evidence.size > 0 ? "detected" : "not-detected",
|
|
534
|
+
evidence: [...evidence].sort()
|
|
535
|
+
};
|
|
536
|
+
} catch (error) {
|
|
537
|
+
return {
|
|
538
|
+
adapterId: adapter.id,
|
|
539
|
+
harnessId: adapter.harnessId,
|
|
540
|
+
scope,
|
|
541
|
+
state: "blocked",
|
|
542
|
+
evidence: [],
|
|
543
|
+
reason: toMessage2(error)
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
function findExecutableOnPath(executableName, executablePath = process.env.PATH ?? "") {
|
|
548
|
+
return platform.findExecutable(executableName, executablePath);
|
|
549
|
+
}
|
|
550
|
+
function planHarnessAccess(adapter, input) {
|
|
551
|
+
const method2 = requireMethod(adapter, input.method, input.scope);
|
|
552
|
+
validateExecutableIdentity(input.executable);
|
|
553
|
+
assertSafeRoot(input.root);
|
|
554
|
+
const desired = desiredEntry(
|
|
555
|
+
adapter,
|
|
556
|
+
method2,
|
|
557
|
+
input.scope,
|
|
558
|
+
input.root,
|
|
559
|
+
input.executable,
|
|
560
|
+
input.commandRules,
|
|
561
|
+
input.commandRuleAuthority
|
|
562
|
+
);
|
|
563
|
+
assertNativePath(input.root, desired.path);
|
|
564
|
+
const beforeContent = readNativeContent(input.root, desired.path);
|
|
565
|
+
const receiptEntry = receiptEntryFor(adapter, input, desired.path, desired.entryId);
|
|
566
|
+
let change;
|
|
567
|
+
let state;
|
|
568
|
+
if (method2.nativeFormat === "claude-permission-json") {
|
|
569
|
+
({ change, state } = planClaudePermissionChange(desired, beforeContent, receiptEntry));
|
|
570
|
+
} else try {
|
|
571
|
+
const inspected = inspectEntry(method2.nativeFormat, beforeContent, desired.value);
|
|
572
|
+
const beforeEntryFingerprint = inspected.exists && inspected.value !== null ? fingerprintEntry(inspected.value) : null;
|
|
573
|
+
if (inspected.exists && !receiptEntry) {
|
|
574
|
+
change = blockedChange(
|
|
575
|
+
desired,
|
|
576
|
+
beforeContent,
|
|
577
|
+
beforeEntryFingerprint,
|
|
578
|
+
"The matching native entry has no exact Make Docs ownership receipt."
|
|
579
|
+
);
|
|
580
|
+
state = "blocked";
|
|
581
|
+
} else if (inspected.exists && receiptEntry && beforeEntryFingerprint !== receiptEntry.entryFingerprint) {
|
|
582
|
+
change = blockedChange(
|
|
583
|
+
desired,
|
|
584
|
+
beforeContent,
|
|
585
|
+
beforeEntryFingerprint,
|
|
586
|
+
"The native entry changed after the last verified receipt. Preserve it and review the change."
|
|
587
|
+
);
|
|
588
|
+
state = "drifted";
|
|
589
|
+
} else if (inspected.exists && beforeEntryFingerprint === fingerprintEntry(desired.value)) {
|
|
590
|
+
change = {
|
|
591
|
+
path: desired.path,
|
|
592
|
+
entryId: desired.entryId,
|
|
593
|
+
action: "none",
|
|
594
|
+
ownership: "make-docs-owned",
|
|
595
|
+
beforeFileFingerprint: fingerprintFile(beforeContent),
|
|
596
|
+
afterFileFingerprint: fingerprintFile(beforeContent),
|
|
597
|
+
beforeEntryValue: inspected.value,
|
|
598
|
+
beforeEntryFingerprint,
|
|
599
|
+
afterEntryFingerprint: beforeEntryFingerprint,
|
|
600
|
+
afterEntryValue: desired.value
|
|
601
|
+
};
|
|
602
|
+
state = "current";
|
|
603
|
+
} else {
|
|
604
|
+
const afterContent = applyEntry(method2.nativeFormat, beforeContent, desired.value);
|
|
605
|
+
change = {
|
|
606
|
+
path: desired.path,
|
|
607
|
+
entryId: desired.entryId,
|
|
608
|
+
action: beforeContent === null ? "create" : "update",
|
|
609
|
+
ownership: inspected.exists ? "make-docs-owned" : "missing",
|
|
610
|
+
beforeFileFingerprint: fingerprintFile(beforeContent),
|
|
611
|
+
afterFileFingerprint: fingerprintFile(afterContent),
|
|
612
|
+
beforeEntryValue: inspected.value,
|
|
613
|
+
beforeEntryFingerprint,
|
|
614
|
+
afterEntryFingerprint: fingerprintEntry(desired.value),
|
|
615
|
+
afterEntryValue: desired.value
|
|
616
|
+
};
|
|
617
|
+
state = inspected.exists ? "drifted" : "missing";
|
|
618
|
+
}
|
|
619
|
+
} catch (error) {
|
|
620
|
+
change = blockedChange(desired, beforeContent, null, toMessage2(error));
|
|
621
|
+
state = "blocked";
|
|
622
|
+
}
|
|
623
|
+
return sealPlan({
|
|
624
|
+
schemaVersion: 1,
|
|
625
|
+
kind: "apply",
|
|
626
|
+
adapterId: adapter.id,
|
|
627
|
+
adapterVersion: adapter.version,
|
|
628
|
+
harnessId: adapter.harnessId,
|
|
629
|
+
connectionMethod: method2.id,
|
|
630
|
+
scope: input.scope,
|
|
631
|
+
root: path2.normalize(input.root),
|
|
632
|
+
executable: input.executable,
|
|
633
|
+
state,
|
|
634
|
+
changes: [change],
|
|
635
|
+
reviewFingerprint: "",
|
|
636
|
+
nextAction: state === "blocked" || state === "drifted" && change.action === "none" ? change.blockedReason ?? "Review the native entry before any change." : change.action === "none" ? "No change is needed." : "Review and approve this exact native-file change."
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
function applyHarnessAccessPlan(adapter, plan, approved, operationId, appliedVersion, verifiedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
640
|
+
assertPlanForAdapter(adapter, plan, "apply");
|
|
641
|
+
assertReviewFingerprint(plan);
|
|
642
|
+
if (!approved) throw new Error("Harness access apply needs explicit approval.");
|
|
643
|
+
if (!operationId.trim()) throw new Error("Harness access apply needs an operation identifier.");
|
|
644
|
+
if (!appliedVersion.trim()) throw new Error("Harness access apply needs an applied product version.");
|
|
645
|
+
if (!Number.isFinite(Date.parse(verifiedAt))) {
|
|
646
|
+
throw new Error("Harness access apply needs a valid verification time.");
|
|
647
|
+
}
|
|
648
|
+
if (plan.state === "blocked" || plan.state === "unsupported") {
|
|
649
|
+
throw new Error(`Harness access cannot apply while its state is ${plan.state}.`);
|
|
650
|
+
}
|
|
651
|
+
const blocker = plan.changes.find((change) => change.blockedReason);
|
|
652
|
+
if (blocker?.blockedReason) throw new Error(blocker.blockedReason);
|
|
653
|
+
const changedPaths = [];
|
|
654
|
+
for (const change of plan.changes) {
|
|
655
|
+
if (change.action === "none") continue;
|
|
656
|
+
if (change.blockedReason) throw new Error(change.blockedReason);
|
|
657
|
+
const liveContent = readNativeContent(plan.root, change.path);
|
|
658
|
+
if (fingerprintFile(liveContent) === change.afterFileFingerprint) continue;
|
|
659
|
+
if (fingerprintFile(liveContent) !== change.beforeFileFingerprint) {
|
|
660
|
+
throw new Error(`Native configuration changed after review: ${change.path}.`);
|
|
661
|
+
}
|
|
662
|
+
if (change.afterEntryValue === null) {
|
|
663
|
+
throw new Error(`The reviewed plan has no target native entry for ${change.path}.`);
|
|
664
|
+
}
|
|
665
|
+
const method2 = requireMethod(adapter, plan.connectionMethod, plan.scope);
|
|
666
|
+
const afterContent = applyEntry(
|
|
667
|
+
method2.nativeFormat,
|
|
668
|
+
liveContent,
|
|
669
|
+
change.afterEntryValue,
|
|
670
|
+
change.beforeEntryValue
|
|
671
|
+
);
|
|
672
|
+
if (fingerprintFile(afterContent) !== change.afterFileFingerprint) {
|
|
673
|
+
throw new Error(`The live native file cannot reproduce the reviewed change: ${change.path}.`);
|
|
674
|
+
}
|
|
675
|
+
writeNativeContent(
|
|
676
|
+
plan.root,
|
|
677
|
+
change.path,
|
|
678
|
+
afterContent,
|
|
679
|
+
change.beforeFileFingerprint
|
|
680
|
+
);
|
|
681
|
+
changedPaths.push(change.path);
|
|
682
|
+
}
|
|
683
|
+
const entries = receiptEntriesFromPlan(plan);
|
|
684
|
+
const receipt = {
|
|
685
|
+
schemaVersion: 2,
|
|
686
|
+
operationId,
|
|
687
|
+
adapterId: adapter.id,
|
|
688
|
+
adapterVersion: adapter.version,
|
|
689
|
+
harnessId: adapter.harnessId,
|
|
690
|
+
connectionMethod: plan.connectionMethod,
|
|
691
|
+
scope: plan.scope,
|
|
692
|
+
appliedVersion,
|
|
693
|
+
verifiedAt,
|
|
694
|
+
entries,
|
|
695
|
+
result: "verified",
|
|
696
|
+
verificationResult: "passed",
|
|
697
|
+
driftState: "current",
|
|
698
|
+
recoveryStatus: "complete"
|
|
699
|
+
};
|
|
700
|
+
const verification2 = verifyAgainstReceipt(adapter, plan.root, receipt);
|
|
701
|
+
if (verification2.state !== "current") {
|
|
702
|
+
throw new Error(verification2.reason ?? "The native harness change did not verify.");
|
|
703
|
+
}
|
|
704
|
+
return { changedPaths, verification: verification2, receipt };
|
|
705
|
+
}
|
|
706
|
+
function verifyHarnessAccess(adapter, input) {
|
|
707
|
+
const method2 = requireMethod(adapter, input.method, input.scope);
|
|
708
|
+
validateExecutableIdentity(input.executable);
|
|
709
|
+
assertSafeRoot(input.root);
|
|
710
|
+
const desired = desiredEntry(
|
|
711
|
+
adapter,
|
|
712
|
+
method2,
|
|
713
|
+
input.scope,
|
|
714
|
+
input.root,
|
|
715
|
+
input.executable,
|
|
716
|
+
input.commandRules,
|
|
717
|
+
input.commandRuleAuthority
|
|
718
|
+
);
|
|
719
|
+
const receiptEntry = receiptEntryFor(adapter, input, desired.path, desired.entryId);
|
|
720
|
+
const content = readNativeContent(input.root, desired.path);
|
|
721
|
+
try {
|
|
722
|
+
const inspected = inspectEntry(method2.nativeFormat, content, desired.value);
|
|
723
|
+
if (!inspected.exists || inspected.value === null) {
|
|
724
|
+
return verification(adapter, method2.id, input.scope, "missing", [], "The native entry is absent.");
|
|
725
|
+
}
|
|
726
|
+
const entryFingerprint = fingerprintEntry(inspected.value);
|
|
727
|
+
if (!receiptEntry) {
|
|
728
|
+
return verification(
|
|
729
|
+
adapter,
|
|
730
|
+
method2.id,
|
|
731
|
+
input.scope,
|
|
732
|
+
"blocked",
|
|
733
|
+
[],
|
|
734
|
+
"The native entry exists, but no exact Make Docs ownership receipt proves it."
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
if (entryFingerprint !== receiptEntry.entryFingerprint) {
|
|
738
|
+
return verification(
|
|
739
|
+
adapter,
|
|
740
|
+
method2.id,
|
|
741
|
+
input.scope,
|
|
742
|
+
"drifted",
|
|
743
|
+
[],
|
|
744
|
+
"The native entry differs from the verified receipt."
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
if (entryFingerprint !== fingerprintEntry(desired.value)) {
|
|
748
|
+
return verification(
|
|
749
|
+
adapter,
|
|
750
|
+
method2.id,
|
|
751
|
+
input.scope,
|
|
752
|
+
"drifted",
|
|
753
|
+
[],
|
|
754
|
+
"The verified native entry does not match the current reviewed intent."
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
return verification(adapter, method2.id, input.scope, "current", [
|
|
758
|
+
makeReceiptEntry(desired.path, desired.entryId, inspected.value, content, receiptEntry)
|
|
759
|
+
]);
|
|
760
|
+
} catch (error) {
|
|
761
|
+
return verification(adapter, method2.id, input.scope, "blocked", [], toMessage2(error));
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
function planHarnessAccessRemoval(adapter, input) {
|
|
765
|
+
const method2 = requireMethod(adapter, input.method, input.scope);
|
|
766
|
+
validateExecutableIdentity(input.executable);
|
|
767
|
+
assertSafeRoot(input.root);
|
|
768
|
+
validateReceiptIdentity(adapter, input, input.receipt);
|
|
769
|
+
const receiptEntry = input.receipt.entries[0];
|
|
770
|
+
if (!receiptEntry || input.receipt.entries.length !== 1) {
|
|
771
|
+
throw new Error("This adapter expects one exact native entry receipt.");
|
|
772
|
+
}
|
|
773
|
+
assertNativePath(input.root, receiptEntry.path);
|
|
774
|
+
const beforeContent = readNativeContent(input.root, receiptEntry.path);
|
|
775
|
+
let change;
|
|
776
|
+
let state = "current";
|
|
777
|
+
try {
|
|
778
|
+
const inspected = inspectEntry(method2.nativeFormat, beforeContent, receiptEntry.value);
|
|
779
|
+
if (!inspected.exists || inspected.value === null) {
|
|
780
|
+
change = {
|
|
781
|
+
path: receiptEntry.path,
|
|
782
|
+
entryId: receiptEntry.entryId,
|
|
783
|
+
action: "none",
|
|
784
|
+
ownership: "missing",
|
|
785
|
+
beforeFileFingerprint: fingerprintFile(beforeContent),
|
|
786
|
+
afterFileFingerprint: fingerprintFile(beforeContent),
|
|
787
|
+
beforeEntryValue: null,
|
|
788
|
+
beforeEntryFingerprint: null,
|
|
789
|
+
afterEntryFingerprint: null,
|
|
790
|
+
afterEntryValue: null
|
|
791
|
+
};
|
|
792
|
+
state = "missing";
|
|
793
|
+
} else if (fingerprintEntry(inspected.value) !== receiptEntry.entryFingerprint) {
|
|
794
|
+
change = blockedChange(
|
|
795
|
+
{ path: receiptEntry.path, entryId: receiptEntry.entryId, value: receiptEntry.value },
|
|
796
|
+
beforeContent,
|
|
797
|
+
fingerprintEntry(inspected.value),
|
|
798
|
+
"The native entry changed after the receipt. Preserve it and review removal manually."
|
|
799
|
+
);
|
|
800
|
+
state = "drifted";
|
|
801
|
+
} else {
|
|
802
|
+
const afterContent = removeEntry(method2.nativeFormat, beforeContent, receiptEntry.value);
|
|
803
|
+
change = {
|
|
804
|
+
path: receiptEntry.path,
|
|
805
|
+
entryId: receiptEntry.entryId,
|
|
806
|
+
action: "remove",
|
|
807
|
+
ownership: "make-docs-owned",
|
|
808
|
+
beforeFileFingerprint: fingerprintFile(beforeContent),
|
|
809
|
+
afterFileFingerprint: fingerprintFile(afterContent),
|
|
810
|
+
beforeEntryValue: inspected.value,
|
|
811
|
+
beforeEntryFingerprint: receiptEntry.entryFingerprint,
|
|
812
|
+
afterEntryFingerprint: null,
|
|
813
|
+
afterEntryValue: null
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
} catch (error) {
|
|
817
|
+
change = blockedChange(
|
|
818
|
+
{ path: receiptEntry.path, entryId: receiptEntry.entryId, value: receiptEntry.value },
|
|
819
|
+
beforeContent,
|
|
820
|
+
null,
|
|
821
|
+
toMessage2(error)
|
|
822
|
+
);
|
|
823
|
+
state = "blocked";
|
|
824
|
+
}
|
|
825
|
+
return sealPlan({
|
|
826
|
+
schemaVersion: 1,
|
|
827
|
+
kind: "remove",
|
|
828
|
+
adapterId: adapter.id,
|
|
829
|
+
adapterVersion: adapter.version,
|
|
830
|
+
harnessId: adapter.harnessId,
|
|
831
|
+
connectionMethod: method2.id,
|
|
832
|
+
scope: input.scope,
|
|
833
|
+
root: path2.normalize(input.root),
|
|
834
|
+
executable: input.executable,
|
|
835
|
+
state,
|
|
836
|
+
changes: [change],
|
|
837
|
+
reviewFingerprint: "",
|
|
838
|
+
nextAction: change.blockedReason ?? (change.action === "none" ? "The exact Make Docs entry is already absent." : "Review and approve removal of this exact Make Docs-owned entry.")
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
function applyHarnessRemovalPlan(adapter, plan, approved) {
|
|
842
|
+
assertPlanForAdapter(adapter, plan, "remove");
|
|
843
|
+
assertReviewFingerprint(plan);
|
|
844
|
+
if (!approved) throw new Error("Harness access removal needs explicit approval.");
|
|
845
|
+
if (plan.state === "blocked" || plan.state === "drifted" || plan.state === "unsupported") {
|
|
846
|
+
throw new Error(`Harness access cannot be removed while its state is ${plan.state}.`);
|
|
847
|
+
}
|
|
848
|
+
const changedPaths = [];
|
|
849
|
+
for (const change of plan.changes) {
|
|
850
|
+
if (change.action === "none") continue;
|
|
851
|
+
const liveContent = readNativeContent(plan.root, change.path);
|
|
852
|
+
if (fingerprintFile(liveContent) === change.afterFileFingerprint) continue;
|
|
853
|
+
if (fingerprintFile(liveContent) !== change.beforeFileFingerprint) {
|
|
854
|
+
throw new Error(`Native configuration changed after removal review: ${change.path}.`);
|
|
855
|
+
}
|
|
856
|
+
if (change.beforeEntryValue === null) {
|
|
857
|
+
throw new Error(`The reviewed removal has no exact native entry for ${change.path}.`);
|
|
858
|
+
}
|
|
859
|
+
const method2 = requireMethod(adapter, plan.connectionMethod, plan.scope);
|
|
860
|
+
const afterContent = removeEntry(method2.nativeFormat, liveContent, change.beforeEntryValue);
|
|
861
|
+
if (fingerprintFile(afterContent) !== change.afterFileFingerprint) {
|
|
862
|
+
throw new Error(`The live native file cannot reproduce the reviewed removal: ${change.path}.`);
|
|
863
|
+
}
|
|
864
|
+
writeNativeContent(
|
|
865
|
+
plan.root,
|
|
866
|
+
change.path,
|
|
867
|
+
afterContent,
|
|
868
|
+
change.beforeFileFingerprint
|
|
869
|
+
);
|
|
870
|
+
changedPaths.push(change.path);
|
|
871
|
+
}
|
|
872
|
+
const removalVerification = verifyRemovalPlan(adapter, plan);
|
|
873
|
+
if (removalVerification.state !== "missing") {
|
|
874
|
+
throw new Error(removalVerification.reason ?? "The native harness removal did not verify.");
|
|
875
|
+
}
|
|
876
|
+
return { changedPaths, verification: removalVerification };
|
|
877
|
+
}
|
|
878
|
+
function verifyRemovalPlan(adapter, plan) {
|
|
879
|
+
const method2 = requireMethod(adapter, plan.connectionMethod, plan.scope);
|
|
880
|
+
try {
|
|
881
|
+
for (const change of plan.changes) {
|
|
882
|
+
if (change.beforeEntryValue === null) continue;
|
|
883
|
+
const content = readNativeContent(plan.root, change.path);
|
|
884
|
+
const inspected = inspectEntry(method2.nativeFormat, content, change.beforeEntryValue);
|
|
885
|
+
if (inspected.exists) {
|
|
886
|
+
return verification(
|
|
887
|
+
adapter,
|
|
888
|
+
plan.connectionMethod,
|
|
889
|
+
plan.scope,
|
|
890
|
+
"drifted",
|
|
891
|
+
[],
|
|
892
|
+
`The exact Make Docs-owned native entry remains after removal: ${change.path}.`
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
return verification(
|
|
897
|
+
adapter,
|
|
898
|
+
plan.connectionMethod,
|
|
899
|
+
plan.scope,
|
|
900
|
+
"missing",
|
|
901
|
+
[],
|
|
902
|
+
"The exact Make Docs-owned native entry is absent."
|
|
903
|
+
);
|
|
904
|
+
} catch (error) {
|
|
905
|
+
return verification(adapter, plan.connectionMethod, plan.scope, "blocked", [], toMessage2(error));
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
function desiredEntry(adapter, method2, scope, root, executable, commandRules, commandRuleAuthority) {
|
|
909
|
+
const nativePath = method2.nativeFile(scope);
|
|
910
|
+
const callerIdentity = makeHarnessCallerIdentity(adapter, method2.id, root, executable);
|
|
911
|
+
const encodedCallerIdentity = encodeHarnessCallerIdentity(callerIdentity);
|
|
912
|
+
switch (method2.nativeFormat) {
|
|
913
|
+
case "codex-mcp-toml": {
|
|
914
|
+
const command = tomlString(executable.path);
|
|
915
|
+
const value = [
|
|
916
|
+
CODEX_MCP_BEGIN,
|
|
917
|
+
"[mcp_servers.make_docs]",
|
|
918
|
+
`command = ${command}`,
|
|
919
|
+
`args = [${tomlString("mcp")}]`,
|
|
920
|
+
"[mcp_servers.make_docs.env]",
|
|
921
|
+
`${HARNESS_CALLER_IDENTITY_ENV} = ${tomlString(encodedCallerIdentity)}`,
|
|
922
|
+
CODEX_MCP_END
|
|
923
|
+
].join("\n");
|
|
924
|
+
return { path: nativePath, entryId: "mcp_servers.make_docs", value };
|
|
925
|
+
}
|
|
926
|
+
case "claude-mcp-json":
|
|
927
|
+
return {
|
|
928
|
+
path: nativePath,
|
|
929
|
+
entryId: "mcpServers.make-docs",
|
|
930
|
+
value: {
|
|
931
|
+
command: executable.path,
|
|
932
|
+
args: ["mcp"],
|
|
933
|
+
env: { [HARNESS_CALLER_IDENTITY_ENV]: encodedCallerIdentity }
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
case "codex-command-rules": {
|
|
937
|
+
if (/\s/.test(executable.path)) {
|
|
938
|
+
throw new Error("Codex command rules need an executable path with no whitespace.");
|
|
939
|
+
}
|
|
940
|
+
const rules = validateHarnessCommandRules(commandRules, commandRuleAuthority);
|
|
941
|
+
const launchPrefix = codexRuleLaunchPrefix(
|
|
942
|
+
encodeHarnessCallerIdentityArgument(callerIdentity),
|
|
943
|
+
executable.path
|
|
944
|
+
);
|
|
945
|
+
const lines = [
|
|
946
|
+
"# Managed by Make Docs. Review through make-docs setup.",
|
|
947
|
+
...[...rules].sort((left, right) => left.id.localeCompare(right.id)).map(
|
|
948
|
+
(rule) => `prefix_rule(pattern = [${[...launchPrefix, ...rule.commandPrefix].map((word) => JSON.stringify(word)).join(", ")}], decision = "allow")`
|
|
949
|
+
),
|
|
950
|
+
""
|
|
951
|
+
];
|
|
952
|
+
return { path: nativePath, entryId: "make-docs.command-rules", value: lines.join("\n") };
|
|
953
|
+
}
|
|
954
|
+
case "claude-permission-json": {
|
|
955
|
+
if (/\s/.test(executable.path)) {
|
|
956
|
+
throw new Error("Claude Code permission rules need an executable path with no whitespace.");
|
|
957
|
+
}
|
|
958
|
+
const rules = validateHarnessCommandRules(commandRules, commandRuleAuthority);
|
|
959
|
+
const launchPrefix = claudePermissionRuleLaunchPrefix(
|
|
960
|
+
encodeHarnessCallerReference(callerIdentity),
|
|
961
|
+
executable.path
|
|
962
|
+
);
|
|
963
|
+
const values = [...rules].sort((left, right) => left.id.localeCompare(right.id)).map((rule) => `Bash(${[...launchPrefix, ...rule.commandPrefix].join(" ")}:*)`).sort();
|
|
964
|
+
return { path: nativePath, entryId: "permissions.allow.make-docs", value: values };
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
function codexRuleLaunchPrefix(encodedCallerIdentity, executablePath) {
|
|
969
|
+
return Object.freeze([
|
|
970
|
+
executablePath,
|
|
971
|
+
HARNESS_CALLER_IDENTITY_ARG,
|
|
972
|
+
encodedCallerIdentity
|
|
973
|
+
]);
|
|
974
|
+
}
|
|
975
|
+
function claudePermissionRuleLaunchPrefix(callerReference, executablePath) {
|
|
976
|
+
return Object.freeze([
|
|
977
|
+
executablePath,
|
|
978
|
+
HARNESS_CALLER_REFERENCE_ARG,
|
|
979
|
+
callerReference
|
|
980
|
+
]);
|
|
981
|
+
}
|
|
982
|
+
function makeHarnessCallerIdentity(adapter, connectionMethod, root, executable) {
|
|
983
|
+
return {
|
|
984
|
+
schemaVersion: 1,
|
|
985
|
+
kind: "make-docs-harness-caller",
|
|
986
|
+
adapterId: adapter.id,
|
|
987
|
+
adapterVersion: adapter.version,
|
|
988
|
+
harnessId: adapter.harnessId,
|
|
989
|
+
connectionMethod,
|
|
990
|
+
scope: "machine",
|
|
991
|
+
root: platform.describePath(root).canonicalPath,
|
|
992
|
+
executable: { ...executable }
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
function planClaudePermissionChange(desired, content, receiptEntry) {
|
|
996
|
+
try {
|
|
997
|
+
const desiredInspected = inspectEntry("claude-permission-json", content, desired.value);
|
|
998
|
+
const desiredFingerprint = fingerprintEntry(desired.value);
|
|
999
|
+
const receiptValues = receiptEntry ? requireClaudePermissionRuleArray(receiptEntry.value, "receipt") : [];
|
|
1000
|
+
if (receiptValues.some((value) => !isMakeDocsClaudePermissionRule(value))) {
|
|
1001
|
+
throw new Error("The receipt contains a permission rule that Make Docs cannot prove it owns.");
|
|
1002
|
+
}
|
|
1003
|
+
const receiptSet = new Set(receiptValues);
|
|
1004
|
+
const unowned = listMakeDocsClaudePermissionRules(content).filter((value) => !receiptSet.has(value));
|
|
1005
|
+
if (unowned.length > 0) {
|
|
1006
|
+
return {
|
|
1007
|
+
change: blockedChange(
|
|
1008
|
+
desired,
|
|
1009
|
+
content,
|
|
1010
|
+
desiredInspected.value === null ? null : fingerprintEntry(desiredInspected.value),
|
|
1011
|
+
"A Make Docs-shaped Claude permission rule has no exact ownership receipt."
|
|
1012
|
+
),
|
|
1013
|
+
state: "blocked"
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
const desiredIsComplete = desiredInspected.exists && desiredInspected.value !== null && fingerprintEntry(desiredInspected.value) === desiredFingerprint;
|
|
1017
|
+
if (desiredIsComplete) {
|
|
1018
|
+
if (!receiptEntry) {
|
|
1019
|
+
return {
|
|
1020
|
+
change: blockedChange(
|
|
1021
|
+
desired,
|
|
1022
|
+
content,
|
|
1023
|
+
desiredFingerprint,
|
|
1024
|
+
"The matching native entry has no exact Make Docs ownership receipt."
|
|
1025
|
+
),
|
|
1026
|
+
state: "blocked"
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
if (receiptEntry.entryFingerprint !== desiredFingerprint) {
|
|
1030
|
+
return {
|
|
1031
|
+
change: blockedChange(
|
|
1032
|
+
desired,
|
|
1033
|
+
content,
|
|
1034
|
+
desiredFingerprint,
|
|
1035
|
+
"The Claude permission rules do not match the exact rules in the ownership receipt."
|
|
1036
|
+
),
|
|
1037
|
+
state: "drifted"
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
return {
|
|
1041
|
+
change: {
|
|
1042
|
+
path: desired.path,
|
|
1043
|
+
entryId: desired.entryId,
|
|
1044
|
+
action: "none",
|
|
1045
|
+
ownership: "make-docs-owned",
|
|
1046
|
+
beforeFileFingerprint: fingerprintFile(content),
|
|
1047
|
+
afterFileFingerprint: fingerprintFile(content),
|
|
1048
|
+
beforeEntryValue: desiredInspected.value,
|
|
1049
|
+
beforeEntryFingerprint: desiredFingerprint,
|
|
1050
|
+
afterEntryFingerprint: desiredFingerprint,
|
|
1051
|
+
afterEntryValue: desired.value
|
|
1052
|
+
},
|
|
1053
|
+
state: "current"
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
if (receiptEntry) {
|
|
1057
|
+
const ownedInspected = inspectEntry("claude-permission-json", content, receiptEntry.value);
|
|
1058
|
+
const ownedFingerprint = ownedInspected.value === null ? null : fingerprintEntry(ownedInspected.value);
|
|
1059
|
+
if (!ownedInspected.exists || ownedFingerprint !== receiptEntry.entryFingerprint) {
|
|
1060
|
+
return {
|
|
1061
|
+
change: blockedChange(
|
|
1062
|
+
desired,
|
|
1063
|
+
content,
|
|
1064
|
+
ownedFingerprint,
|
|
1065
|
+
"The receipt-owned Claude permission rules are missing, changed, or incomplete."
|
|
1066
|
+
),
|
|
1067
|
+
state: "drifted"
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
const afterContent2 = applyEntry(
|
|
1071
|
+
"claude-permission-json",
|
|
1072
|
+
content,
|
|
1073
|
+
desired.value,
|
|
1074
|
+
receiptEntry.value
|
|
1075
|
+
);
|
|
1076
|
+
return {
|
|
1077
|
+
change: {
|
|
1078
|
+
path: desired.path,
|
|
1079
|
+
entryId: desired.entryId,
|
|
1080
|
+
action: "update",
|
|
1081
|
+
ownership: "make-docs-owned",
|
|
1082
|
+
beforeFileFingerprint: fingerprintFile(content),
|
|
1083
|
+
afterFileFingerprint: fingerprintFile(afterContent2),
|
|
1084
|
+
beforeEntryValue: ownedInspected.value,
|
|
1085
|
+
beforeEntryFingerprint: ownedFingerprint,
|
|
1086
|
+
afterEntryFingerprint: desiredFingerprint,
|
|
1087
|
+
afterEntryValue: desired.value
|
|
1088
|
+
},
|
|
1089
|
+
state: "drifted"
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
if (desiredInspected.exists) {
|
|
1093
|
+
return {
|
|
1094
|
+
change: blockedChange(
|
|
1095
|
+
desired,
|
|
1096
|
+
content,
|
|
1097
|
+
desiredInspected.value === null ? null : fingerprintEntry(desiredInspected.value),
|
|
1098
|
+
"The partial Make Docs Claude permission entry has no exact ownership receipt."
|
|
1099
|
+
),
|
|
1100
|
+
state: "blocked"
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
const afterContent = applyEntry("claude-permission-json", content, desired.value);
|
|
1104
|
+
return {
|
|
1105
|
+
change: {
|
|
1106
|
+
path: desired.path,
|
|
1107
|
+
entryId: desired.entryId,
|
|
1108
|
+
action: content === null ? "create" : "update",
|
|
1109
|
+
ownership: "missing",
|
|
1110
|
+
beforeFileFingerprint: fingerprintFile(content),
|
|
1111
|
+
afterFileFingerprint: fingerprintFile(afterContent),
|
|
1112
|
+
beforeEntryValue: null,
|
|
1113
|
+
beforeEntryFingerprint: null,
|
|
1114
|
+
afterEntryFingerprint: desiredFingerprint,
|
|
1115
|
+
afterEntryValue: desired.value
|
|
1116
|
+
},
|
|
1117
|
+
state: "missing"
|
|
1118
|
+
};
|
|
1119
|
+
} catch (error) {
|
|
1120
|
+
return {
|
|
1121
|
+
change: blockedChange(desired, content, null, toMessage2(error)),
|
|
1122
|
+
state: "blocked"
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
function requireClaudePermissionRuleArray(value, source) {
|
|
1127
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string")) {
|
|
1128
|
+
throw new Error(`The ${source} Claude permission entry is malformed.`);
|
|
1129
|
+
}
|
|
1130
|
+
return value;
|
|
1131
|
+
}
|
|
1132
|
+
function listMakeDocsClaudePermissionRules(content) {
|
|
1133
|
+
if (content === null) return [];
|
|
1134
|
+
const root = parseJsonObject(content);
|
|
1135
|
+
if (root.permissions === void 0) return [];
|
|
1136
|
+
if (!isRecord(root.permissions)) throw new Error("The native permissions value is not an object.");
|
|
1137
|
+
const allow = root.permissions.allow;
|
|
1138
|
+
if (allow === void 0) return [];
|
|
1139
|
+
if (!Array.isArray(allow) || allow.some((value) => typeof value !== "string")) {
|
|
1140
|
+
throw new Error("The native permissions.allow value is not a string array.");
|
|
1141
|
+
}
|
|
1142
|
+
return allow.filter(isMakeDocsClaudePermissionRule);
|
|
1143
|
+
}
|
|
1144
|
+
function isMakeDocsClaudePermissionRule(value) {
|
|
1145
|
+
return value.startsWith(`Bash(/usr/bin/env ${HARNESS_CALLER_IDENTITY_ENV}=`) || value.includes(` ${HARNESS_CALLER_REFERENCE_ARG} `);
|
|
1146
|
+
}
|
|
1147
|
+
function inspectEntry(format, content, expectedValue) {
|
|
1148
|
+
if (content === null) return { exists: false, value: null };
|
|
1149
|
+
switch (format) {
|
|
1150
|
+
case "codex-mcp-toml": {
|
|
1151
|
+
const block = locateCodexMcpBlock(content);
|
|
1152
|
+
if (!block && /\[\s*mcp_servers\.make_docs\s*\]/.test(content)) {
|
|
1153
|
+
throw new Error("A user-owned Codex MCP entry already uses mcp_servers.make_docs.");
|
|
1154
|
+
}
|
|
1155
|
+
return block ? { exists: true, value: block.content } : { exists: false, value: null };
|
|
1156
|
+
}
|
|
1157
|
+
case "codex-command-rules":
|
|
1158
|
+
return { exists: content.length > 0, value: content.length > 0 ? content : null };
|
|
1159
|
+
case "claude-mcp-json": {
|
|
1160
|
+
const root = parseJsonObject(content);
|
|
1161
|
+
const servers = root.mcpServers;
|
|
1162
|
+
if (servers === void 0) return { exists: false, value: null };
|
|
1163
|
+
if (!isRecord(servers)) throw new Error("The native mcpServers value is not an object.");
|
|
1164
|
+
return Object.hasOwn(servers, "make-docs") ? { exists: true, value: asNativeValue(servers["make-docs"]) } : { exists: false, value: null };
|
|
1165
|
+
}
|
|
1166
|
+
case "claude-permission-json": {
|
|
1167
|
+
const root = parseJsonObject(content);
|
|
1168
|
+
const permissions = root.permissions;
|
|
1169
|
+
if (permissions === void 0) return { exists: false, value: null };
|
|
1170
|
+
if (!isRecord(permissions)) throw new Error("The native permissions value is not an object.");
|
|
1171
|
+
const allow = permissions.allow;
|
|
1172
|
+
if (allow === void 0) return { exists: false, value: null };
|
|
1173
|
+
if (!Array.isArray(allow) || allow.some((value) => typeof value !== "string")) {
|
|
1174
|
+
throw new Error("The native permissions.allow value is not a string array.");
|
|
1175
|
+
}
|
|
1176
|
+
if (!Array.isArray(expectedValue) || expectedValue.some((value) => typeof value !== "string")) {
|
|
1177
|
+
throw new Error("The reviewed Make Docs permission entry is malformed.");
|
|
1178
|
+
}
|
|
1179
|
+
const expected = new Set(expectedValue);
|
|
1180
|
+
const present = allow.filter((value) => expected.has(value)).sort();
|
|
1181
|
+
return present.length > 0 ? { exists: true, value: present } : { exists: false, value: null };
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
function applyEntry(format, content, value, priorOwnedValue) {
|
|
1186
|
+
switch (format) {
|
|
1187
|
+
case "codex-mcp-toml": {
|
|
1188
|
+
if (typeof value !== "string") throw new Error("The Codex MCP entry is malformed.");
|
|
1189
|
+
const source = content ?? "";
|
|
1190
|
+
const block = locateCodexMcpBlock(source);
|
|
1191
|
+
if (block) return source.slice(0, block.start) + value + source.slice(block.end);
|
|
1192
|
+
return source.trimEnd() ? `${source.trimEnd()}
|
|
1193
|
+
|
|
1194
|
+
${value}
|
|
1195
|
+
` : `${value}
|
|
1196
|
+
`;
|
|
1197
|
+
}
|
|
1198
|
+
case "codex-command-rules":
|
|
1199
|
+
if (typeof value !== "string") throw new Error("The Codex command-rule entry is malformed.");
|
|
1200
|
+
return value;
|
|
1201
|
+
case "claude-mcp-json": {
|
|
1202
|
+
const root = content === null ? {} : parseJsonObject(content);
|
|
1203
|
+
const servers = root.mcpServers === void 0 ? {} : root.mcpServers;
|
|
1204
|
+
if (!isRecord(servers)) throw new Error("The native mcpServers value is not an object.");
|
|
1205
|
+
root.mcpServers = { ...servers, "make-docs": value };
|
|
1206
|
+
return `${JSON.stringify(root, null, 2)}
|
|
1207
|
+
`;
|
|
1208
|
+
}
|
|
1209
|
+
case "claude-permission-json": {
|
|
1210
|
+
const desired = requireClaudePermissionRuleArray(value, "reviewed");
|
|
1211
|
+
const root = content === null ? {} : parseJsonObject(content);
|
|
1212
|
+
const permissions = root.permissions === void 0 ? {} : root.permissions;
|
|
1213
|
+
if (!isRecord(permissions)) throw new Error("The native permissions value is not an object.");
|
|
1214
|
+
const allow = permissions.allow === void 0 ? [] : permissions.allow;
|
|
1215
|
+
if (!Array.isArray(allow) || allow.some((entry) => typeof entry !== "string")) {
|
|
1216
|
+
throw new Error("The native permissions.allow value is not a string array.");
|
|
1217
|
+
}
|
|
1218
|
+
const remove = priorOwnedValue === void 0 || priorOwnedValue === null ? /* @__PURE__ */ new Set() : new Set(requireClaudePermissionRuleArray(priorOwnedValue, "receipt"));
|
|
1219
|
+
const preserved = allow.filter((entry) => !remove.has(entry));
|
|
1220
|
+
const merged = [.../* @__PURE__ */ new Set([...preserved, ...desired])];
|
|
1221
|
+
root.permissions = { ...permissions, allow: merged };
|
|
1222
|
+
return `${JSON.stringify(root, null, 2)}
|
|
1223
|
+
`;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
function removeEntry(format, content, receiptValue) {
|
|
1228
|
+
if (content === null) return null;
|
|
1229
|
+
switch (format) {
|
|
1230
|
+
case "codex-mcp-toml": {
|
|
1231
|
+
const block = locateCodexMcpBlock(content);
|
|
1232
|
+
if (!block) return content;
|
|
1233
|
+
const remaining = `${content.slice(0, block.start)}${content.slice(block.end)}`.replace(/\n{3,}/g, "\n\n").trim();
|
|
1234
|
+
return remaining ? `${remaining}
|
|
1235
|
+
` : null;
|
|
1236
|
+
}
|
|
1237
|
+
case "codex-command-rules":
|
|
1238
|
+
return null;
|
|
1239
|
+
case "claude-mcp-json": {
|
|
1240
|
+
const root = parseJsonObject(content);
|
|
1241
|
+
if (!isRecord(root.mcpServers)) throw new Error("The native mcpServers value is not an object.");
|
|
1242
|
+
const servers = { ...root.mcpServers };
|
|
1243
|
+
delete servers["make-docs"];
|
|
1244
|
+
root.mcpServers = servers;
|
|
1245
|
+
return `${JSON.stringify(root, null, 2)}
|
|
1246
|
+
`;
|
|
1247
|
+
}
|
|
1248
|
+
case "claude-permission-json": {
|
|
1249
|
+
if (!Array.isArray(receiptValue) || receiptValue.some((entry) => typeof entry !== "string")) {
|
|
1250
|
+
throw new Error("The receipt permission entry is malformed.");
|
|
1251
|
+
}
|
|
1252
|
+
const root = parseJsonObject(content);
|
|
1253
|
+
if (!isRecord(root.permissions)) throw new Error("The native permissions value is not an object.");
|
|
1254
|
+
const permissions = { ...root.permissions };
|
|
1255
|
+
if (!Array.isArray(permissions.allow) || permissions.allow.some((entry) => typeof entry !== "string")) {
|
|
1256
|
+
throw new Error("The native permissions.allow value is not a string array.");
|
|
1257
|
+
}
|
|
1258
|
+
const remove = new Set(receiptValue);
|
|
1259
|
+
permissions.allow = permissions.allow.filter((entry) => !remove.has(entry));
|
|
1260
|
+
root.permissions = permissions;
|
|
1261
|
+
return `${JSON.stringify(root, null, 2)}
|
|
1262
|
+
`;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
function locateCodexMcpBlock(content) {
|
|
1267
|
+
if (content.includes("\0")) throw new Error("The Codex configuration contains a null byte.");
|
|
1268
|
+
if (/^(<{7}|={7}|>{7})/m.test(content)) {
|
|
1269
|
+
throw new Error("The Codex configuration contains unresolved conflict markers.");
|
|
1270
|
+
}
|
|
1271
|
+
validateCodexTomlContainer(content);
|
|
1272
|
+
const begins = indexesOf(content, CODEX_MCP_BEGIN);
|
|
1273
|
+
const ends = indexesOf(content, CODEX_MCP_END);
|
|
1274
|
+
if (begins.length !== ends.length || begins.length > 1) {
|
|
1275
|
+
throw new Error("The Codex Make Docs managed block markers are malformed.");
|
|
1276
|
+
}
|
|
1277
|
+
if (begins.length === 0) return null;
|
|
1278
|
+
if (ends[0] < begins[0]) throw new Error("The Codex Make Docs managed block markers are reversed.");
|
|
1279
|
+
const lineEnd = content.indexOf("\n", ends[0] + CODEX_MCP_END.length);
|
|
1280
|
+
const end = lineEnd === -1 ? content.length : lineEnd + 1;
|
|
1281
|
+
return { start: begins[0], end, content: content.slice(begins[0], ends[0] + CODEX_MCP_END.length) };
|
|
1282
|
+
}
|
|
1283
|
+
var TOML_VALUE_NODE = Object.freeze({ kind: "value" });
|
|
1284
|
+
function tomlTable(declaration) {
|
|
1285
|
+
return { kind: "table", declaration, entries: /* @__PURE__ */ new Map() };
|
|
1286
|
+
}
|
|
1287
|
+
function resolveTomlHeader(root, path3, arrayTable) {
|
|
1288
|
+
let parent = root;
|
|
1289
|
+
for (const part of path3.slice(0, -1)) {
|
|
1290
|
+
const existing2 = parent.entries.get(part);
|
|
1291
|
+
if (existing2 === void 0) {
|
|
1292
|
+
const implicit = tomlTable("implicit-header");
|
|
1293
|
+
parent.entries.set(part, implicit);
|
|
1294
|
+
parent = implicit;
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
if (existing2.kind === "table") {
|
|
1298
|
+
parent = existing2;
|
|
1299
|
+
continue;
|
|
1300
|
+
}
|
|
1301
|
+
if (existing2.kind === "array-table") {
|
|
1302
|
+
const active = existing2.elements.at(-1);
|
|
1303
|
+
if (active) {
|
|
1304
|
+
parent = active;
|
|
1305
|
+
continue;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
throw new Error("The Codex configuration has a duplicate or conflicting table header.");
|
|
1309
|
+
}
|
|
1310
|
+
const leaf = path3.at(-1);
|
|
1311
|
+
if (leaf === void 0) {
|
|
1312
|
+
throw new Error("The Codex configuration has a malformed table header.");
|
|
1313
|
+
}
|
|
1314
|
+
const existing = parent.entries.get(leaf);
|
|
1315
|
+
if (arrayTable) {
|
|
1316
|
+
if (existing !== void 0 && existing.kind !== "array-table") {
|
|
1317
|
+
throw new Error("The Codex configuration has a duplicate or conflicting table header.");
|
|
1318
|
+
}
|
|
1319
|
+
const array = existing ?? { kind: "array-table", elements: [] };
|
|
1320
|
+
if (existing === void 0) parent.entries.set(leaf, array);
|
|
1321
|
+
const element = tomlTable("explicit");
|
|
1322
|
+
array.elements.push(element);
|
|
1323
|
+
return element;
|
|
1324
|
+
}
|
|
1325
|
+
if (existing === void 0) {
|
|
1326
|
+
const table = tomlTable("explicit");
|
|
1327
|
+
parent.entries.set(leaf, table);
|
|
1328
|
+
return table;
|
|
1329
|
+
}
|
|
1330
|
+
if (existing.kind !== "table" || existing.declaration !== "implicit-header") {
|
|
1331
|
+
throw new Error("The Codex configuration has a duplicate or conflicting table header.");
|
|
1332
|
+
}
|
|
1333
|
+
existing.declaration = "explicit";
|
|
1334
|
+
return existing;
|
|
1335
|
+
}
|
|
1336
|
+
function defineTomlValue(table, path3) {
|
|
1337
|
+
let parent = table;
|
|
1338
|
+
for (const part of path3.slice(0, -1)) {
|
|
1339
|
+
const existing = parent.entries.get(part);
|
|
1340
|
+
if (existing === void 0) {
|
|
1341
|
+
const implicit = tomlTable("implicit-assignment");
|
|
1342
|
+
parent.entries.set(part, implicit);
|
|
1343
|
+
parent = implicit;
|
|
1344
|
+
continue;
|
|
1345
|
+
}
|
|
1346
|
+
if (existing.kind !== "table") {
|
|
1347
|
+
throw new Error("The Codex configuration has a duplicate or conflicting assignment.");
|
|
1348
|
+
}
|
|
1349
|
+
parent = existing;
|
|
1350
|
+
}
|
|
1351
|
+
const leaf = path3.at(-1);
|
|
1352
|
+
if (leaf === void 0 || parent.entries.has(leaf)) {
|
|
1353
|
+
throw new Error("The Codex configuration has a duplicate or conflicting assignment.");
|
|
1354
|
+
}
|
|
1355
|
+
parent.entries.set(leaf, TOML_VALUE_NODE);
|
|
1356
|
+
}
|
|
1357
|
+
function validateCodexTomlContainer(content) {
|
|
1358
|
+
if (content.includes('"""') || content.includes("'''")) {
|
|
1359
|
+
throw new Error("The Codex configuration contains multiline TOML that this bounded writer cannot validate.");
|
|
1360
|
+
}
|
|
1361
|
+
const root = tomlTable("root");
|
|
1362
|
+
let table = root;
|
|
1363
|
+
for (const statement of splitTomlStatements(content)) {
|
|
1364
|
+
if (statement.startsWith("[")) {
|
|
1365
|
+
const arrayTable = statement.startsWith("[[");
|
|
1366
|
+
const openLength = arrayTable ? 2 : 1;
|
|
1367
|
+
const close = arrayTable ? "]]" : "]";
|
|
1368
|
+
if (!statement.endsWith(close)) {
|
|
1369
|
+
throw new Error("The Codex configuration has a malformed table header.");
|
|
1370
|
+
}
|
|
1371
|
+
const key = statement.slice(openLength, -openLength).trim();
|
|
1372
|
+
table = resolveTomlHeader(root, parseTomlKeyPath(key, "table header"), arrayTable);
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
const equals = findTopLevelTomlEquals(statement);
|
|
1376
|
+
if (equals < 0) {
|
|
1377
|
+
throw new Error("The Codex configuration has a malformed assignment.");
|
|
1378
|
+
}
|
|
1379
|
+
const keyPath = parseTomlKeyPath(statement.slice(0, equals).trim(), "assignment key");
|
|
1380
|
+
const valueSource = statement.slice(equals + 1).trim();
|
|
1381
|
+
if (!valueSource) throw new Error("The Codex configuration has an empty assignment value.");
|
|
1382
|
+
new TomlValueSyntaxParser(valueSource).parse();
|
|
1383
|
+
defineTomlValue(table, keyPath);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
function splitTomlStatements(content) {
|
|
1387
|
+
const statements = [];
|
|
1388
|
+
let pending = "";
|
|
1389
|
+
let collectionStack = [];
|
|
1390
|
+
for (const sourceLine of content.split(/\r?\n/)) {
|
|
1391
|
+
const line = stripTomlComment(sourceLine);
|
|
1392
|
+
if (!line.trim() && !pending) continue;
|
|
1393
|
+
pending += `${pending ? "\n" : ""}${line}`;
|
|
1394
|
+
collectionStack = scanTomlCollections(line, collectionStack);
|
|
1395
|
+
if (collectionStack.includes("}")) {
|
|
1396
|
+
throw new Error("The Codex configuration has a multiline inline table.");
|
|
1397
|
+
}
|
|
1398
|
+
if (collectionStack.length === 0) {
|
|
1399
|
+
if (pending.trim()) statements.push(pending.trim());
|
|
1400
|
+
pending = "";
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
if (collectionStack.length !== 0) {
|
|
1404
|
+
throw new Error("The Codex configuration has an unfinished collection value.");
|
|
1405
|
+
}
|
|
1406
|
+
if (pending.trim()) statements.push(pending.trim());
|
|
1407
|
+
return statements;
|
|
1408
|
+
}
|
|
1409
|
+
function stripTomlComment(line) {
|
|
1410
|
+
let quote = null;
|
|
1411
|
+
let escaped = false;
|
|
1412
|
+
for (let index = 0; index < line.length; index += 1) {
|
|
1413
|
+
const character = line[index];
|
|
1414
|
+
if (quote) {
|
|
1415
|
+
if (escaped) {
|
|
1416
|
+
escaped = false;
|
|
1417
|
+
continue;
|
|
1418
|
+
}
|
|
1419
|
+
if (quote === '"' && character === "\\") {
|
|
1420
|
+
escaped = true;
|
|
1421
|
+
continue;
|
|
1422
|
+
}
|
|
1423
|
+
if (character === quote) quote = null;
|
|
1424
|
+
if (character === "\n" || character === "\r") {
|
|
1425
|
+
throw new Error("The Codex configuration has an unfinished string value.");
|
|
1426
|
+
}
|
|
1427
|
+
continue;
|
|
1428
|
+
}
|
|
1429
|
+
if (character === "#") return line.slice(0, index);
|
|
1430
|
+
if (character === "'" || character === '"') {
|
|
1431
|
+
quote = character;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
if (quote) throw new Error("The Codex configuration has an unfinished string value.");
|
|
1435
|
+
return line;
|
|
1436
|
+
}
|
|
1437
|
+
function scanTomlCollections(line, initial) {
|
|
1438
|
+
const stack = [...initial];
|
|
1439
|
+
let quote = null;
|
|
1440
|
+
let escaped = false;
|
|
1441
|
+
for (const character of line) {
|
|
1442
|
+
if (quote) {
|
|
1443
|
+
if (escaped) {
|
|
1444
|
+
escaped = false;
|
|
1445
|
+
} else if (quote === '"' && character === "\\") {
|
|
1446
|
+
escaped = true;
|
|
1447
|
+
} else if (character === quote) {
|
|
1448
|
+
quote = null;
|
|
1449
|
+
}
|
|
1450
|
+
continue;
|
|
1451
|
+
}
|
|
1452
|
+
if (character === "'" || character === '"') {
|
|
1453
|
+
quote = character;
|
|
1454
|
+
continue;
|
|
1455
|
+
}
|
|
1456
|
+
if (character === "[" || character === "{") {
|
|
1457
|
+
stack.push(character === "[" ? "]" : "}");
|
|
1458
|
+
} else if (character === "]" || character === "}") {
|
|
1459
|
+
if (stack.pop() !== character) {
|
|
1460
|
+
throw new Error("The Codex configuration has unbalanced collection delimiters.");
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
return stack;
|
|
1465
|
+
}
|
|
1466
|
+
function findTopLevelTomlEquals(source) {
|
|
1467
|
+
let quote = null;
|
|
1468
|
+
let escaped = false;
|
|
1469
|
+
let depth = 0;
|
|
1470
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
1471
|
+
const character = source[index];
|
|
1472
|
+
if (quote) {
|
|
1473
|
+
if (escaped) escaped = false;
|
|
1474
|
+
else if (quote === '"' && character === "\\") escaped = true;
|
|
1475
|
+
else if (character === quote) quote = null;
|
|
1476
|
+
continue;
|
|
1477
|
+
}
|
|
1478
|
+
if (character === "'" || character === '"') quote = character;
|
|
1479
|
+
else if (character === "[" || character === "{") depth += 1;
|
|
1480
|
+
else if (character === "]" || character === "}") depth -= 1;
|
|
1481
|
+
else if (character === "=" && depth === 0) return index;
|
|
1482
|
+
}
|
|
1483
|
+
return -1;
|
|
1484
|
+
}
|
|
1485
|
+
function parseTomlKeyPath(source, location) {
|
|
1486
|
+
const parser = new TomlKeySyntaxParser(source);
|
|
1487
|
+
const pathParts = parser.parse();
|
|
1488
|
+
if (pathParts.length === 0) {
|
|
1489
|
+
throw new Error(`The Codex configuration has an empty ${location}.`);
|
|
1490
|
+
}
|
|
1491
|
+
return pathParts;
|
|
1492
|
+
}
|
|
1493
|
+
var TomlKeySyntaxParser = class {
|
|
1494
|
+
constructor(source) {
|
|
1495
|
+
this.source = source;
|
|
1496
|
+
}
|
|
1497
|
+
index = 0;
|
|
1498
|
+
parse() {
|
|
1499
|
+
const parts = [];
|
|
1500
|
+
while (true) {
|
|
1501
|
+
this.skipWhitespace();
|
|
1502
|
+
parts.push(this.parsePart());
|
|
1503
|
+
this.skipWhitespace();
|
|
1504
|
+
if (this.index === this.source.length) return parts;
|
|
1505
|
+
if (this.source[this.index] !== ".") {
|
|
1506
|
+
throw new Error("The Codex configuration has a malformed key.");
|
|
1507
|
+
}
|
|
1508
|
+
this.index += 1;
|
|
1509
|
+
this.skipWhitespace();
|
|
1510
|
+
if (this.index === this.source.length) {
|
|
1511
|
+
throw new Error("The Codex configuration has an unfinished dotted key.");
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
parsePart() {
|
|
1516
|
+
const quote = this.source[this.index];
|
|
1517
|
+
if (quote === "'" || quote === '"') {
|
|
1518
|
+
const start2 = this.index;
|
|
1519
|
+
this.index = consumeTomlString(this.source, this.index);
|
|
1520
|
+
const quoted = this.source.slice(start2, this.index);
|
|
1521
|
+
return quote === "'" ? quoted.slice(1, -1) : JSON.parse(quoted);
|
|
1522
|
+
}
|
|
1523
|
+
const start = this.index;
|
|
1524
|
+
while (/[A-Za-z0-9_-]/.test(this.source[this.index] ?? "")) this.index += 1;
|
|
1525
|
+
if (start === this.index) throw new Error("The Codex configuration has a malformed key.");
|
|
1526
|
+
return this.source.slice(start, this.index);
|
|
1527
|
+
}
|
|
1528
|
+
skipWhitespace() {
|
|
1529
|
+
while (this.source[this.index] === " " || this.source[this.index] === " ") this.index += 1;
|
|
1530
|
+
}
|
|
1531
|
+
};
|
|
1532
|
+
var TomlValueSyntaxParser = class {
|
|
1533
|
+
constructor(source) {
|
|
1534
|
+
this.source = source;
|
|
1535
|
+
}
|
|
1536
|
+
index = 0;
|
|
1537
|
+
parse() {
|
|
1538
|
+
this.skipWhitespaceAndNewlines();
|
|
1539
|
+
this.parseValue();
|
|
1540
|
+
this.skipWhitespaceAndNewlines();
|
|
1541
|
+
if (this.index !== this.source.length) {
|
|
1542
|
+
throw new Error("The Codex configuration has trailing text after a value.");
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
parseValue() {
|
|
1546
|
+
const character = this.source[this.index];
|
|
1547
|
+
if (character === "'" || character === '"') {
|
|
1548
|
+
this.index = consumeTomlString(this.source, this.index);
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
if (character === "[") return this.parseArray();
|
|
1552
|
+
if (character === "{") return this.parseInlineTable();
|
|
1553
|
+
const start = this.index;
|
|
1554
|
+
while (this.index < this.source.length && !/[\s,\]}]/.test(this.source[this.index])) {
|
|
1555
|
+
this.index += 1;
|
|
1556
|
+
}
|
|
1557
|
+
const token = this.source.slice(start, this.index);
|
|
1558
|
+
if (!isValidTomlBareValue(token)) {
|
|
1559
|
+
throw new Error(`The Codex configuration has an invalid TOML value: ${token || "<empty>"}.`);
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
parseArray() {
|
|
1563
|
+
this.index += 1;
|
|
1564
|
+
this.skipWhitespaceAndNewlines();
|
|
1565
|
+
if (this.source[this.index] === "]") {
|
|
1566
|
+
this.index += 1;
|
|
1567
|
+
return;
|
|
1568
|
+
}
|
|
1569
|
+
while (true) {
|
|
1570
|
+
this.parseValue();
|
|
1571
|
+
this.skipWhitespaceAndNewlines();
|
|
1572
|
+
if (this.source[this.index] === "]") {
|
|
1573
|
+
this.index += 1;
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
if (this.source[this.index] !== ",") {
|
|
1577
|
+
throw new Error("The Codex configuration has a malformed TOML array.");
|
|
1578
|
+
}
|
|
1579
|
+
this.index += 1;
|
|
1580
|
+
this.skipWhitespaceAndNewlines();
|
|
1581
|
+
if (this.source[this.index] === "]") {
|
|
1582
|
+
this.index += 1;
|
|
1583
|
+
return;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
parseInlineTable() {
|
|
1588
|
+
this.index += 1;
|
|
1589
|
+
this.skipInlineWhitespace();
|
|
1590
|
+
if (this.source[this.index] === "}") {
|
|
1591
|
+
this.index += 1;
|
|
1592
|
+
return;
|
|
1593
|
+
}
|
|
1594
|
+
while (true) {
|
|
1595
|
+
const keyStart = this.index;
|
|
1596
|
+
const equals = this.findInlineEquals();
|
|
1597
|
+
parseTomlKeyPath(this.source.slice(keyStart, equals).trim(), "inline-table key");
|
|
1598
|
+
this.index = equals + 1;
|
|
1599
|
+
this.skipInlineWhitespace();
|
|
1600
|
+
this.parseValue();
|
|
1601
|
+
this.skipInlineWhitespace();
|
|
1602
|
+
if (this.source[this.index] === "}") {
|
|
1603
|
+
this.index += 1;
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
if (this.source[this.index] !== ",") {
|
|
1607
|
+
throw new Error("The Codex configuration has a malformed TOML inline table.");
|
|
1608
|
+
}
|
|
1609
|
+
this.index += 1;
|
|
1610
|
+
this.skipInlineWhitespace();
|
|
1611
|
+
if (this.source[this.index] === "}") {
|
|
1612
|
+
throw new Error("The Codex configuration has a trailing inline-table comma.");
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
findInlineEquals() {
|
|
1617
|
+
let quote = null;
|
|
1618
|
+
let escaped = false;
|
|
1619
|
+
for (let index = this.index; index < this.source.length; index += 1) {
|
|
1620
|
+
const character = this.source[index];
|
|
1621
|
+
if (quote) {
|
|
1622
|
+
if (escaped) escaped = false;
|
|
1623
|
+
else if (quote === '"' && character === "\\") escaped = true;
|
|
1624
|
+
else if (character === quote) quote = null;
|
|
1625
|
+
continue;
|
|
1626
|
+
}
|
|
1627
|
+
if (character === "'" || character === '"') quote = character;
|
|
1628
|
+
else if (character === "=") return index;
|
|
1629
|
+
else if (character === "," || character === "}" || character === "\n") break;
|
|
1630
|
+
}
|
|
1631
|
+
throw new Error("The Codex configuration has a malformed TOML inline table.");
|
|
1632
|
+
}
|
|
1633
|
+
skipWhitespaceAndNewlines() {
|
|
1634
|
+
while (/\s/.test(this.source[this.index] ?? "")) this.index += 1;
|
|
1635
|
+
}
|
|
1636
|
+
skipInlineWhitespace() {
|
|
1637
|
+
while (this.source[this.index] === " " || this.source[this.index] === " ") this.index += 1;
|
|
1638
|
+
if (this.source[this.index] === "\n" || this.source[this.index] === "\r") {
|
|
1639
|
+
throw new Error("The Codex configuration has a multiline TOML inline table.");
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1643
|
+
function consumeTomlString(source, start) {
|
|
1644
|
+
const quote = source[start];
|
|
1645
|
+
let escaped = false;
|
|
1646
|
+
for (let index = start + 1; index < source.length; index += 1) {
|
|
1647
|
+
const character = source[index];
|
|
1648
|
+
if (character === "\n" || character === "\r") {
|
|
1649
|
+
throw new Error("The Codex configuration has an unfinished string value.");
|
|
1650
|
+
}
|
|
1651
|
+
if (quote === '"' && escaped) {
|
|
1652
|
+
if (!/[btnfr"\\]/.test(character) && character !== "u" && character !== "U") {
|
|
1653
|
+
throw new Error("The Codex configuration has an invalid TOML string escape.");
|
|
1654
|
+
}
|
|
1655
|
+
if (character === "u" || character === "U") {
|
|
1656
|
+
const length = character === "u" ? 4 : 8;
|
|
1657
|
+
const hex = source.slice(index + 1, index + 1 + length);
|
|
1658
|
+
if (!new RegExp(`^[0-9A-Fa-f]{${length}}$`).test(hex)) {
|
|
1659
|
+
throw new Error("The Codex configuration has an invalid TOML Unicode escape.");
|
|
1660
|
+
}
|
|
1661
|
+
const codePoint2 = Number.parseInt(hex, 16);
|
|
1662
|
+
if (codePoint2 <= 8 || codePoint2 >= 11 && codePoint2 <= 31 || codePoint2 === 127 || codePoint2 > 1114111 || codePoint2 >= 55296 && codePoint2 <= 57343) {
|
|
1663
|
+
throw new Error("The Codex configuration has an invalid TOML Unicode code point.");
|
|
1664
|
+
}
|
|
1665
|
+
index += length;
|
|
1666
|
+
}
|
|
1667
|
+
escaped = false;
|
|
1668
|
+
continue;
|
|
1669
|
+
}
|
|
1670
|
+
if (quote === '"' && character === "\\") {
|
|
1671
|
+
escaped = true;
|
|
1672
|
+
continue;
|
|
1673
|
+
}
|
|
1674
|
+
if (character === quote) return index + 1;
|
|
1675
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
1676
|
+
if (codePoint <= 8 || codePoint >= 11 && codePoint <= 31 || codePoint === 127) {
|
|
1677
|
+
throw new Error("The Codex configuration has a control character in a string.");
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
throw new Error("The Codex configuration has an unfinished string value.");
|
|
1681
|
+
}
|
|
1682
|
+
function isValidTomlBareValue(value) {
|
|
1683
|
+
if (value === "true" || value === "false" || value === "inf" || value === "+inf" || value === "-inf") {
|
|
1684
|
+
return true;
|
|
1685
|
+
}
|
|
1686
|
+
if (value === "nan" || value === "+nan" || value === "-nan") return true;
|
|
1687
|
+
if (/^0x[0-9A-Fa-f](?:_?[0-9A-Fa-f])*$/.test(value)) return true;
|
|
1688
|
+
if (/^0o[0-7](?:_?[0-7])*$/.test(value)) return true;
|
|
1689
|
+
if (/^0b[01](?:_?[01])*$/.test(value)) return true;
|
|
1690
|
+
if (/^[+-]?(?:0|[1-9](?:_?\d)*)$/.test(value)) return true;
|
|
1691
|
+
if (/^[+-]?(?:(?:0|[1-9](?:_?\d)*)\.\d(?:_?\d)*(?:[eE][+-]?\d(?:_?\d)*)?|(?:0|[1-9](?:_?\d)*)[eE][+-]?\d(?:_?\d)*)$/.test(value)) {
|
|
1692
|
+
return true;
|
|
1693
|
+
}
|
|
1694
|
+
return isValidTomlDateOrTime(value);
|
|
1695
|
+
}
|
|
1696
|
+
function isValidTomlDateOrTime(value) {
|
|
1697
|
+
const dateTime = /^(\d{4})-(\d{2})-(\d{2})[Tt ](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|([+-])(\d{2}):(\d{2}))?$/.exec(value);
|
|
1698
|
+
if (dateTime) {
|
|
1699
|
+
const [, year, month, day, hour, minute, second, , offsetHour, offsetMinute] = dateTime;
|
|
1700
|
+
return isValidTomlDate(year, month, day) && isValidTomlTime(hour, minute, second) && (!offsetHour || Number(offsetHour) <= 23 && Number(offsetMinute) <= 59);
|
|
1701
|
+
}
|
|
1702
|
+
const date = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
1703
|
+
if (date) return isValidTomlDate(date[1], date[2], date[3]);
|
|
1704
|
+
const time = /^(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?$/.exec(value);
|
|
1705
|
+
return Boolean(time && isValidTomlTime(time[1], time[2], time[3]));
|
|
1706
|
+
}
|
|
1707
|
+
function isValidTomlDate(year, month, day) {
|
|
1708
|
+
const date = new Date(Date.UTC(Number(year), Number(month) - 1, Number(day)));
|
|
1709
|
+
return Number(month) >= 1 && Number(month) <= 12 && Number(day) >= 1 && date.getUTCFullYear() === Number(year) && date.getUTCMonth() === Number(month) - 1 && date.getUTCDate() === Number(day);
|
|
1710
|
+
}
|
|
1711
|
+
function isValidTomlTime(hour, minute, second) {
|
|
1712
|
+
return Number(hour) <= 23 && Number(minute) <= 59 && Number(second) <= 59;
|
|
1713
|
+
}
|
|
1714
|
+
function receiptEntryFor(adapter, input, nativePath, entryId) {
|
|
1715
|
+
if (!input.receipt) return void 0;
|
|
1716
|
+
validateReceiptIdentity(adapter, input, input.receipt);
|
|
1717
|
+
if (input.receipt.entries.length !== 1) {
|
|
1718
|
+
throw new Error("This adapter expects one exact native entry receipt.");
|
|
1719
|
+
}
|
|
1720
|
+
const entry = input.receipt.entries[0];
|
|
1721
|
+
if (entry.path !== nativePath || entry.entryId !== entryId) {
|
|
1722
|
+
throw new Error("The harness receipt does not identify this exact native entry.");
|
|
1723
|
+
}
|
|
1724
|
+
return entry;
|
|
1725
|
+
}
|
|
1726
|
+
function validateReceiptIdentity(adapter, input, receipt) {
|
|
1727
|
+
if (receipt.schemaVersion !== 1 && receipt.schemaVersion !== 2 || receipt.adapterId !== adapter.id || receipt.adapterVersion !== adapter.version || receipt.harnessId !== adapter.harnessId || receipt.connectionMethod !== input.method || receipt.scope !== input.scope || receipt.result !== "verified" || receipt.verificationResult !== "passed" || receipt.driftState !== "current" || receipt.recoveryStatus !== "complete" || !receipt.appliedVersion.trim() || !Number.isFinite(Date.parse(receipt.verifiedAt)) || receipt.entries.some(
|
|
1728
|
+
(entry) => entry.ownership !== "make-docs" || fingerprintEntry(entry.value) !== entry.entryFingerprint || !/^[0-9a-f]{64}$/.test(entry.fileFingerprint)
|
|
1729
|
+
)) {
|
|
1730
|
+
throw new Error("The harness receipt does not match this exact adapter, method, scope, and managed entry.");
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
function receiptEntriesFromPlan(plan) {
|
|
1734
|
+
return plan.changes.map((change) => {
|
|
1735
|
+
if (change.afterEntryValue === null || !change.afterEntryFingerprint || !change.afterFileFingerprint) {
|
|
1736
|
+
throw new Error(`The reviewed plan has no verifiable result for ${change.path}.`);
|
|
1737
|
+
}
|
|
1738
|
+
const live = readNativeContent(plan.root, change.path);
|
|
1739
|
+
if (fingerprintFile(live) !== change.afterFileFingerprint) {
|
|
1740
|
+
throw new Error(`The applied native file does not match the reviewed result: ${change.path}.`);
|
|
1741
|
+
}
|
|
1742
|
+
return makeReceiptEntry(change.path, change.entryId, change.afterEntryValue, live, {
|
|
1743
|
+
beforeEntryFingerprint: change.beforeEntryFingerprint,
|
|
1744
|
+
beforeFileFingerprint: change.beforeFileFingerprint,
|
|
1745
|
+
beforeValue: change.beforeEntryValue
|
|
1746
|
+
});
|
|
1747
|
+
});
|
|
1748
|
+
}
|
|
1749
|
+
function verifyAgainstReceipt(adapter, root, receipt) {
|
|
1750
|
+
const method2 = requireMethod(adapter, receipt.connectionMethod, receipt.scope);
|
|
1751
|
+
const verifiedEntries = [];
|
|
1752
|
+
try {
|
|
1753
|
+
for (const entry of receipt.entries) {
|
|
1754
|
+
const content = readNativeContent(root, entry.path);
|
|
1755
|
+
const inspected = inspectEntry(method2.nativeFormat, content, entry.value);
|
|
1756
|
+
if (!inspected.exists || inspected.value === null) {
|
|
1757
|
+
return verification(adapter, method2.id, receipt.scope, "missing", [], "The applied native entry is absent.");
|
|
1758
|
+
}
|
|
1759
|
+
if (fingerprintEntry(inspected.value) !== entry.entryFingerprint) {
|
|
1760
|
+
return verification(adapter, method2.id, receipt.scope, "drifted", [], "The applied native entry differs from its receipt.");
|
|
1761
|
+
}
|
|
1762
|
+
verifiedEntries.push(makeReceiptEntry(entry.path, entry.entryId, inspected.value, content, entry));
|
|
1763
|
+
}
|
|
1764
|
+
return verification(adapter, method2.id, receipt.scope, "current", verifiedEntries);
|
|
1765
|
+
} catch (error) {
|
|
1766
|
+
return verification(adapter, method2.id, receipt.scope, "blocked", [], toMessage2(error));
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
function makeReceiptEntry(nativePath, entryId, value, content, previous) {
|
|
1770
|
+
if (content === null) throw new Error(`Cannot record an absent native file: ${nativePath}.`);
|
|
1771
|
+
return {
|
|
1772
|
+
path: nativePath,
|
|
1773
|
+
entryId,
|
|
1774
|
+
ownership: "make-docs",
|
|
1775
|
+
beforeEntryFingerprint: previous?.beforeEntryFingerprint ?? null,
|
|
1776
|
+
beforeFileFingerprint: previous?.beforeFileFingerprint ?? null,
|
|
1777
|
+
beforeValue: previous?.beforeValue ?? null,
|
|
1778
|
+
entryFingerprint: fingerprintEntry(value),
|
|
1779
|
+
fileFingerprint: sha256(content),
|
|
1780
|
+
value
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
function requireMethod(adapter, methodId, scope) {
|
|
1784
|
+
const method2 = adapter.methods.find((candidate) => candidate.id === methodId);
|
|
1785
|
+
if (!method2 || !method2.scopes.includes(scope)) {
|
|
1786
|
+
throw new Error(`${adapter.displayName} does not implement ${methodId} for ${scope} scope.`);
|
|
1787
|
+
}
|
|
1788
|
+
return method2;
|
|
1789
|
+
}
|
|
1790
|
+
function assertSafeRoot(root) {
|
|
1791
|
+
if (!path2.isAbsolute(root)) throw new Error("A harness native-configuration root must be absolute.");
|
|
1792
|
+
const stat = lstatSync2(root);
|
|
1793
|
+
if (stat.isSymbolicLink()) throw new Error("A harness native-configuration root must not be a symbolic link.");
|
|
1794
|
+
if (!stat.isDirectory()) throw new Error("A harness native-configuration root must be a directory.");
|
|
1795
|
+
}
|
|
1796
|
+
function assertNativePath(root, relativePath) {
|
|
1797
|
+
if (!relativePath || path2.isAbsolute(relativePath)) {
|
|
1798
|
+
throw new Error(`Harness native path must be relative: ${relativePath}.`);
|
|
1799
|
+
}
|
|
1800
|
+
assertManagedPathHasNoSymlinks(root, relativePath);
|
|
1801
|
+
}
|
|
1802
|
+
function readNativeContent(root, relativePath) {
|
|
1803
|
+
assertNativePath(root, relativePath);
|
|
1804
|
+
const absolutePath = path2.join(root, relativePath);
|
|
1805
|
+
const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
1806
|
+
let fd;
|
|
1807
|
+
try {
|
|
1808
|
+
fd = openSync(absolutePath, constants.O_RDONLY | noFollow);
|
|
1809
|
+
} catch (error) {
|
|
1810
|
+
if (error.code === "ENOENT") return null;
|
|
1811
|
+
if (error.code === "ELOOP") {
|
|
1812
|
+
throw new Error(`Harness native file is a symbolic link: ${relativePath}.`);
|
|
1813
|
+
}
|
|
1814
|
+
throw error;
|
|
1815
|
+
}
|
|
1816
|
+
let bytes;
|
|
1817
|
+
try {
|
|
1818
|
+
const stat = fstatSync(fd);
|
|
1819
|
+
if (!stat.isFile()) {
|
|
1820
|
+
throw new Error(`Harness native path is not a regular file: ${relativePath}.`);
|
|
1821
|
+
}
|
|
1822
|
+
bytes = readFileSync2(fd);
|
|
1823
|
+
} finally {
|
|
1824
|
+
closeSync(fd);
|
|
1825
|
+
}
|
|
1826
|
+
try {
|
|
1827
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
1828
|
+
} catch {
|
|
1829
|
+
throw new Error(`Harness native file is not valid UTF-8: ${relativePath}.`);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
function writeNativeContent(root, relativePath, content, expectedBeforeFingerprint) {
|
|
1833
|
+
assertNativePath(root, relativePath);
|
|
1834
|
+
const absolutePath = path2.join(root, relativePath);
|
|
1835
|
+
if (content !== null) ensureNativeParent(root, relativePath);
|
|
1836
|
+
const parent = path2.dirname(absolutePath);
|
|
1837
|
+
const guard = openParentGuard(parent);
|
|
1838
|
+
try {
|
|
1839
|
+
assertParentGuard(root, relativePath, guard);
|
|
1840
|
+
const liveBefore = readNativeContent(root, relativePath);
|
|
1841
|
+
if (fingerprintFile(liveBefore) !== expectedBeforeFingerprint) {
|
|
1842
|
+
throw new Error(`Native configuration changed immediately before replacement: ${relativePath}.`);
|
|
1843
|
+
}
|
|
1844
|
+
if (content === null) {
|
|
1845
|
+
if (liveBefore === null) return;
|
|
1846
|
+
const targetGuard = openTargetGuard(absolutePath, relativePath);
|
|
1847
|
+
try {
|
|
1848
|
+
prepareNativeMutationGuards(guard, targetGuard);
|
|
1849
|
+
harnessNativeMutationHookForTests?.({
|
|
1850
|
+
action: "remove",
|
|
1851
|
+
absolutePath,
|
|
1852
|
+
relativePath
|
|
1853
|
+
});
|
|
1854
|
+
assertNativeMutationBoundary(root, relativePath, guard, targetGuard);
|
|
1855
|
+
unlinkSync(absolutePath);
|
|
1856
|
+
assertParentGuard(root, relativePath, guard);
|
|
1857
|
+
if (readNativeContent(root, relativePath) !== null) {
|
|
1858
|
+
throw new Error(`Harness native file still exists after removal: ${relativePath}.`);
|
|
1859
|
+
}
|
|
1860
|
+
} finally {
|
|
1861
|
+
closeTargetGuard(targetGuard);
|
|
1862
|
+
}
|
|
1863
|
+
return;
|
|
1864
|
+
}
|
|
1865
|
+
const temporary = path2.join(
|
|
1866
|
+
parent,
|
|
1867
|
+
`.${path2.basename(relativePath)}.${randomUUID()}.tmp`
|
|
1868
|
+
);
|
|
1869
|
+
writeFileSync(temporary, content, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
1870
|
+
try {
|
|
1871
|
+
assertParentGuard(root, relativePath, guard);
|
|
1872
|
+
const finalBefore = readNativeContent(root, relativePath);
|
|
1873
|
+
if (fingerprintFile(finalBefore) !== expectedBeforeFingerprint) {
|
|
1874
|
+
throw new Error(
|
|
1875
|
+
`Native configuration changed immediately before replacement: ${relativePath}.`
|
|
1876
|
+
);
|
|
1877
|
+
}
|
|
1878
|
+
const targetGuard = openTargetGuard(absolutePath, relativePath);
|
|
1879
|
+
try {
|
|
1880
|
+
prepareNativeMutationGuards(guard, targetGuard);
|
|
1881
|
+
harnessNativeMutationHookForTests?.({
|
|
1882
|
+
action: "replace",
|
|
1883
|
+
absolutePath,
|
|
1884
|
+
relativePath
|
|
1885
|
+
});
|
|
1886
|
+
assertNativeMutationBoundary(root, relativePath, guard, targetGuard);
|
|
1887
|
+
platform.atomicReplace(temporary, absolutePath);
|
|
1888
|
+
assertParentGuard(root, relativePath, guard);
|
|
1889
|
+
if (fingerprintFile(readNativeContent(root, relativePath)) !== fingerprintFile(content)) {
|
|
1890
|
+
throw new Error(`Harness native file does not match the reviewed content: ${relativePath}.`);
|
|
1891
|
+
}
|
|
1892
|
+
} finally {
|
|
1893
|
+
closeTargetGuard(targetGuard);
|
|
1894
|
+
}
|
|
1895
|
+
} catch (error) {
|
|
1896
|
+
try {
|
|
1897
|
+
assertParentGuard(root, relativePath, guard);
|
|
1898
|
+
if (existsSync(temporary)) unlinkSync(temporary);
|
|
1899
|
+
} catch {
|
|
1900
|
+
}
|
|
1901
|
+
throw error;
|
|
1902
|
+
}
|
|
1903
|
+
} finally {
|
|
1904
|
+
if (guard.fd !== null) closeSync(guard.fd);
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
function captureNativeObjectIdentity(stats) {
|
|
1908
|
+
return {
|
|
1909
|
+
device: stats.dev,
|
|
1910
|
+
inode: stats.ino,
|
|
1911
|
+
mode: stats.mode,
|
|
1912
|
+
size: stats.size,
|
|
1913
|
+
birthtimeNs: stats.birthtimeNs,
|
|
1914
|
+
ctimeNs: stats.ctimeNs
|
|
1915
|
+
};
|
|
1916
|
+
}
|
|
1917
|
+
function matchesNativeObjectIdentity(stats, identity) {
|
|
1918
|
+
if (identity.device !== 0n || identity.inode !== 0n) {
|
|
1919
|
+
return stats.dev === identity.device && stats.ino === identity.inode;
|
|
1920
|
+
}
|
|
1921
|
+
const stableBirth = identity.birthtimeNs > 0n && stats.birthtimeNs > 0n;
|
|
1922
|
+
return stats.mode === identity.mode && stats.size === identity.size && (stableBirth ? stats.birthtimeNs === identity.birthtimeNs : stats.ctimeNs === identity.ctimeNs);
|
|
1923
|
+
}
|
|
1924
|
+
function ensureNativeParent(root, relativePath) {
|
|
1925
|
+
const parentRelative = path2.dirname(relativePath);
|
|
1926
|
+
if (parentRelative === ".") return;
|
|
1927
|
+
let current = root;
|
|
1928
|
+
for (const segment of path2.normalize(parentRelative).split(path2.sep).filter(Boolean)) {
|
|
1929
|
+
current = path2.join(current, segment);
|
|
1930
|
+
try {
|
|
1931
|
+
mkdirSync(current, { mode: 448 });
|
|
1932
|
+
} catch (error) {
|
|
1933
|
+
if (error.code !== "EEXIST") throw error;
|
|
1934
|
+
}
|
|
1935
|
+
assertManagedPathHasNoSymlinks(root, path2.relative(root, current));
|
|
1936
|
+
const stat = lstatSync2(current);
|
|
1937
|
+
if (!stat.isDirectory()) {
|
|
1938
|
+
throw new Error(`Harness native parent is not a directory: ${path2.relative(root, current)}.`);
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
function openParentGuard(parent) {
|
|
1943
|
+
const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
1944
|
+
const directory = typeof constants.O_DIRECTORY === "number" ? constants.O_DIRECTORY : 0;
|
|
1945
|
+
const fd = openSync(parent, constants.O_RDONLY | noFollow | directory);
|
|
1946
|
+
const stat = fstatSync(fd);
|
|
1947
|
+
if (!stat.isDirectory()) {
|
|
1948
|
+
closeSync(fd);
|
|
1949
|
+
throw new Error("Harness native parent is not a directory.");
|
|
1950
|
+
}
|
|
1951
|
+
return {
|
|
1952
|
+
fd,
|
|
1953
|
+
path: parent,
|
|
1954
|
+
guard: platform.captureFileGuard(stat, "directory"),
|
|
1955
|
+
objectIdentity: captureNativeObjectIdentity(fstatSync(fd, { bigint: true }))
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
function assertParentGuard(root, relativePath, guard) {
|
|
1959
|
+
assertNativePath(root, relativePath);
|
|
1960
|
+
const descriptor = guard.fd === null ? null : fstatSync(guard.fd);
|
|
1961
|
+
const descriptorIdentity = guard.fd === null ? null : fstatSync(guard.fd, { bigint: true });
|
|
1962
|
+
const live = lstatSync2(guard.path);
|
|
1963
|
+
const liveIdentity = lstatSync2(guard.path, { bigint: true });
|
|
1964
|
+
if (live.isSymbolicLink() || !live.isDirectory() || !platform.matchesFileGuard(live, guard.guard) || !matchesNativeObjectIdentity(liveIdentity, guard.objectIdentity) || descriptorIdentity !== null && !matchesNativeObjectIdentity(descriptorIdentity, guard.objectIdentity) || descriptor !== null && !platform.matchesFileGuard(descriptor, guard.guard)) {
|
|
1965
|
+
throw new Error(`Harness native parent changed after review: ${relativePath}.`);
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
function openTargetGuard(absolutePath, relativePath) {
|
|
1969
|
+
const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
1970
|
+
let fd;
|
|
1971
|
+
try {
|
|
1972
|
+
fd = openSync(absolutePath, constants.O_RDONLY | noFollow);
|
|
1973
|
+
} catch (error) {
|
|
1974
|
+
if (error.code === "ENOENT") return { exists: false };
|
|
1975
|
+
if (error.code === "ELOOP") {
|
|
1976
|
+
throw new Error(`Harness native file is a symbolic link: ${relativePath}.`);
|
|
1977
|
+
}
|
|
1978
|
+
throw error;
|
|
1979
|
+
}
|
|
1980
|
+
try {
|
|
1981
|
+
const descriptor = fstatSync(fd);
|
|
1982
|
+
const live = lstatSync2(absolutePath);
|
|
1983
|
+
if (!descriptor.isFile() || live.isSymbolicLink() || !live.isFile() || !platform.sameFileObject(descriptor, live, "file")) {
|
|
1984
|
+
throw new Error(`Harness native target changed after review: ${relativePath}.`);
|
|
1985
|
+
}
|
|
1986
|
+
return {
|
|
1987
|
+
exists: true,
|
|
1988
|
+
fd,
|
|
1989
|
+
guard: platform.captureFileGuard(descriptor, "file"),
|
|
1990
|
+
objectIdentity: captureNativeObjectIdentity(fstatSync(fd, { bigint: true }))
|
|
1991
|
+
};
|
|
1992
|
+
} catch (error) {
|
|
1993
|
+
closeSync(fd);
|
|
1994
|
+
throw error;
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
function closeTargetGuard(guard) {
|
|
1998
|
+
if (guard.exists && guard.fd !== null) {
|
|
1999
|
+
closeSync(guard.fd);
|
|
2000
|
+
guard.fd = null;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
function prepareNativeMutationGuards(parentGuard, targetGuard) {
|
|
2004
|
+
if (platform.canMutateOpenPaths) return;
|
|
2005
|
+
closeTargetGuard(targetGuard);
|
|
2006
|
+
if (parentGuard.fd !== null) {
|
|
2007
|
+
closeSync(parentGuard.fd);
|
|
2008
|
+
parentGuard.fd = null;
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
function assertNativeMutationBoundary(root, relativePath, parentGuard, targetGuard) {
|
|
2012
|
+
assertParentGuard(root, relativePath, parentGuard);
|
|
2013
|
+
const absolutePath = path2.join(root, relativePath);
|
|
2014
|
+
if (!targetGuard.exists) {
|
|
2015
|
+
try {
|
|
2016
|
+
lstatSync2(absolutePath);
|
|
2017
|
+
} catch (error) {
|
|
2018
|
+
if (error.code === "ENOENT") return;
|
|
2019
|
+
throw error;
|
|
2020
|
+
}
|
|
2021
|
+
throw new Error(`Harness native target changed after review: ${relativePath}.`);
|
|
2022
|
+
}
|
|
2023
|
+
const descriptor = targetGuard.fd === null ? null : fstatSync(targetGuard.fd);
|
|
2024
|
+
const descriptorIdentity = targetGuard.fd === null ? null : fstatSync(targetGuard.fd, { bigint: true });
|
|
2025
|
+
let live;
|
|
2026
|
+
let liveIdentity;
|
|
2027
|
+
try {
|
|
2028
|
+
live = lstatSync2(absolutePath);
|
|
2029
|
+
liveIdentity = lstatSync2(absolutePath, { bigint: true });
|
|
2030
|
+
} catch (error) {
|
|
2031
|
+
if (error.code === "ENOENT") {
|
|
2032
|
+
throw new Error(`Harness native target changed after review: ${relativePath}.`);
|
|
2033
|
+
}
|
|
2034
|
+
throw error;
|
|
2035
|
+
}
|
|
2036
|
+
if (descriptor !== null && (!descriptor.isFile() || !platform.matchesFileGuard(descriptor, targetGuard.guard)) || descriptorIdentity !== null && !matchesNativeObjectIdentity(descriptorIdentity, targetGuard.objectIdentity) || live.isSymbolicLink() || !live.isFile() || !platform.matchesFileGuard(live, targetGuard.guard) || !matchesNativeObjectIdentity(liveIdentity, targetGuard.objectIdentity)) {
|
|
2037
|
+
throw new Error(`Harness native target changed after review: ${relativePath}.`);
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
function blockedChange(desired, beforeContent, beforeEntryFingerprint, reason) {
|
|
2041
|
+
return {
|
|
2042
|
+
path: desired.path,
|
|
2043
|
+
entryId: desired.entryId,
|
|
2044
|
+
action: "none",
|
|
2045
|
+
ownership: "unverified",
|
|
2046
|
+
beforeFileFingerprint: fingerprintFile(beforeContent),
|
|
2047
|
+
afterFileFingerprint: fingerprintFile(beforeContent),
|
|
2048
|
+
beforeEntryValue: null,
|
|
2049
|
+
beforeEntryFingerprint,
|
|
2050
|
+
afterEntryFingerprint: null,
|
|
2051
|
+
afterEntryValue: null,
|
|
2052
|
+
blockedReason: reason
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
function verification(adapter, connectionMethod, scope, state, entries, reason) {
|
|
2056
|
+
return {
|
|
2057
|
+
adapterId: adapter.id,
|
|
2058
|
+
adapterVersion: adapter.version,
|
|
2059
|
+
harnessId: adapter.harnessId,
|
|
2060
|
+
connectionMethod,
|
|
2061
|
+
scope,
|
|
2062
|
+
state,
|
|
2063
|
+
entries,
|
|
2064
|
+
...reason ? { reason } : {}
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
function sealPlan(plan) {
|
|
2068
|
+
const reviewFingerprint = planFingerprint(plan);
|
|
2069
|
+
return { ...plan, reviewFingerprint };
|
|
2070
|
+
}
|
|
2071
|
+
function planFingerprint(plan) {
|
|
2072
|
+
const { reviewFingerprint: _ignored, ...reviewed } = plan;
|
|
2073
|
+
return sha256(JSON.stringify(reviewed));
|
|
2074
|
+
}
|
|
2075
|
+
function assertReviewFingerprint(plan) {
|
|
2076
|
+
if (plan.reviewFingerprint !== planFingerprint(plan)) {
|
|
2077
|
+
throw new Error("The harness access plan changed after review.");
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
function assertPlanForAdapter(adapter, plan, kind) {
|
|
2081
|
+
if (plan.schemaVersion !== 1 || plan.kind !== kind || plan.adapterId !== adapter.id || plan.adapterVersion !== adapter.version || plan.harnessId !== adapter.harnessId) {
|
|
2082
|
+
throw new Error("The harness access plan does not belong to this adapter and action.");
|
|
2083
|
+
}
|
|
2084
|
+
assertSafeRoot(plan.root);
|
|
2085
|
+
}
|
|
2086
|
+
function validateExecutableIdentity(executable) {
|
|
2087
|
+
if (executable.kind !== "make-docs" || !path2.isAbsolute(executable.path) || !/^[0-9a-f]{64}$/.test(executable.sha256) || !Number.isSafeInteger(executable.size) || executable.size < 1 || executable.productMarker !== "@brucewaynedecoy/make-docs:package-bin" || executable.packageName !== "@brucewaynedecoy/make-docs" || !executable.packageVersion.trim() || !path2.isAbsolute(executable.packageRoot) || !executable.binRelativePath) {
|
|
2088
|
+
throw new Error("The adapter needs a verified Make Docs executable identity.");
|
|
2089
|
+
}
|
|
2090
|
+
const stat = lstatSync2(executable.path);
|
|
2091
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
2092
|
+
throw new Error("The verified Make Docs executable is no longer a regular file.");
|
|
2093
|
+
}
|
|
2094
|
+
const bytes = readFileSync2(executable.path);
|
|
2095
|
+
if (bytes.byteLength !== executable.size || sha256(bytes) !== executable.sha256) {
|
|
2096
|
+
throw new Error("The verified Make Docs executable changed after verification.");
|
|
2097
|
+
}
|
|
2098
|
+
const verified = reverifyMakeDocsExecutableIdentity(executable);
|
|
2099
|
+
if (verified.productMarker !== executable.productMarker || verified.packageName !== executable.packageName || verified.packageVersion !== executable.packageVersion || verified.packageRoot !== executable.packageRoot || verified.binRelativePath !== executable.binRelativePath) {
|
|
2100
|
+
throw new Error("The verified Make Docs package identity changed after verification.");
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
function parseJsonObject(content) {
|
|
2104
|
+
let value;
|
|
2105
|
+
try {
|
|
2106
|
+
value = JSON.parse(content);
|
|
2107
|
+
} catch (error) {
|
|
2108
|
+
throw new Error(`The native JSON file is malformed: ${toMessage2(error)}`);
|
|
2109
|
+
}
|
|
2110
|
+
if (!isRecord(value)) throw new Error("The native JSON root is not an object.");
|
|
2111
|
+
return value;
|
|
2112
|
+
}
|
|
2113
|
+
function asNativeValue(value) {
|
|
2114
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
|
|
2115
|
+
if (Array.isArray(value)) return value.map(asNativeValue);
|
|
2116
|
+
if (isRecord(value)) {
|
|
2117
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, asNativeValue(child)]));
|
|
2118
|
+
}
|
|
2119
|
+
throw new Error("The native entry contains a value that JSON cannot preserve.");
|
|
2120
|
+
}
|
|
2121
|
+
function isRecord(value) {
|
|
2122
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
2123
|
+
}
|
|
2124
|
+
function fingerprintFile(content) {
|
|
2125
|
+
return content === null ? null : sha256(content);
|
|
2126
|
+
}
|
|
2127
|
+
function indexesOf(content, token) {
|
|
2128
|
+
const indexes = [];
|
|
2129
|
+
let offset = 0;
|
|
2130
|
+
while (offset < content.length) {
|
|
2131
|
+
const index = content.indexOf(token, offset);
|
|
2132
|
+
if (index === -1) break;
|
|
2133
|
+
indexes.push(index);
|
|
2134
|
+
offset = index + token.length;
|
|
2135
|
+
}
|
|
2136
|
+
return indexes;
|
|
2137
|
+
}
|
|
2138
|
+
function tomlString(value) {
|
|
2139
|
+
return JSON.stringify(value);
|
|
2140
|
+
}
|
|
2141
|
+
function toMessage2(error) {
|
|
2142
|
+
return error instanceof Error ? error.message : String(error);
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
// src/harness-access/registry.ts
|
|
2146
|
+
function method(id, nativeFormat, nativeFile, options) {
|
|
2147
|
+
return Object.freeze({
|
|
2148
|
+
id,
|
|
2149
|
+
scopes: Object.freeze(["machine", "project"]),
|
|
2150
|
+
nativeFormat,
|
|
2151
|
+
requiresExecutable: true,
|
|
2152
|
+
requiresCommandRules: options.requiresCommandRules ?? false,
|
|
2153
|
+
nativeFile,
|
|
2154
|
+
ownedEntries: Object.freeze([options.ownedEntry]),
|
|
2155
|
+
allowedStoreOperations: options.requiresCommandRules ? "bounded-command-rule-registry" : "active-operation-registry",
|
|
2156
|
+
implementationState: "implemented",
|
|
2157
|
+
availability: options.availability ?? "available",
|
|
2158
|
+
blocker: options.blocker ?? null,
|
|
2159
|
+
nextAction: options.nextAction ?? "Review this method, then apply the grouped setup plan"
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
var CODEX_HARNESS_ADAPTER = createHarnessAdapter({
|
|
2163
|
+
id: "make-docs.codex",
|
|
2164
|
+
version: 1,
|
|
2165
|
+
harnessId: "codex",
|
|
2166
|
+
displayName: "Codex",
|
|
2167
|
+
executableNames: Object.freeze(["codex"]),
|
|
2168
|
+
projectRouterFiles: Object.freeze(["AGENTS.md"]),
|
|
2169
|
+
skillRoots: Object.freeze([".agents/skills", ".codex/skills"]),
|
|
2170
|
+
methods: Object.freeze([
|
|
2171
|
+
method("mcp", "codex-mcp-toml", () => ".codex/config.toml", {
|
|
2172
|
+
ownedEntry: "mcp_servers.make_docs"
|
|
2173
|
+
}),
|
|
2174
|
+
method(
|
|
2175
|
+
"command-rules",
|
|
2176
|
+
"codex-command-rules",
|
|
2177
|
+
() => ".codex/rules/make-docs.rules",
|
|
2178
|
+
{ ownedEntry: "make-docs.command-rules", requiresCommandRules: true }
|
|
2179
|
+
)
|
|
2180
|
+
])
|
|
2181
|
+
});
|
|
2182
|
+
var CLAUDE_CODE_HARNESS_ADAPTER = createHarnessAdapter({
|
|
2183
|
+
id: "make-docs.claude-code",
|
|
2184
|
+
version: 1,
|
|
2185
|
+
harnessId: "claude-code",
|
|
2186
|
+
displayName: "Claude Code",
|
|
2187
|
+
executableNames: Object.freeze(["claude"]),
|
|
2188
|
+
projectRouterFiles: Object.freeze(["CLAUDE.md"]),
|
|
2189
|
+
skillRoots: Object.freeze([".claude/skills"]),
|
|
2190
|
+
methods: Object.freeze([
|
|
2191
|
+
method(
|
|
2192
|
+
"mcp",
|
|
2193
|
+
"claude-mcp-json",
|
|
2194
|
+
(scope) => scope === "machine" ? ".claude.json" : ".mcp.json",
|
|
2195
|
+
{ ownedEntry: "mcpServers.make-docs" }
|
|
2196
|
+
),
|
|
2197
|
+
method(
|
|
2198
|
+
"permission-rules",
|
|
2199
|
+
"claude-permission-json",
|
|
2200
|
+
() => ".claude/settings.json",
|
|
2201
|
+
{
|
|
2202
|
+
ownedEntry: "permissions.allow.make-docs",
|
|
2203
|
+
requiresCommandRules: true,
|
|
2204
|
+
availability: "blocked",
|
|
2205
|
+
blocker: "Claude Code does not select or preserve the exact receipt-bound Make Docs command for permission-rule matching.",
|
|
2206
|
+
nextAction: "Use Claude Code MCP setup while Make Docs evaluates a shorter safe command carrier"
|
|
2207
|
+
}
|
|
2208
|
+
)
|
|
2209
|
+
])
|
|
2210
|
+
});
|
|
2211
|
+
var FIRST_PARTY_HARNESS_ADAPTERS = Object.freeze([
|
|
2212
|
+
CODEX_HARNESS_ADAPTER,
|
|
2213
|
+
CLAUDE_CODE_HARNESS_ADAPTER
|
|
2214
|
+
]);
|
|
2215
|
+
var PI_HARNESS_SUPPORT = Object.freeze({
|
|
2216
|
+
harnessId: "pi",
|
|
2217
|
+
state: "unsupported",
|
|
2218
|
+
publicSupportClaim: false,
|
|
2219
|
+
reason: "Make Docs does not ship a first-party Pi adapter."
|
|
2220
|
+
});
|
|
2221
|
+
function getFirstPartyHarnessAdapter(harnessId) {
|
|
2222
|
+
return FIRST_PARTY_HARNESS_ADAPTERS.find((adapter) => adapter.harnessId === harnessId);
|
|
2223
|
+
}
|
|
2224
|
+
function requireFirstPartyHarnessAdapter(harnessId) {
|
|
2225
|
+
const adapter = getFirstPartyHarnessAdapter(harnessId);
|
|
2226
|
+
if (!adapter) throw new Error(`No admitted first-party harness adapter exists for ${harnessId}.`);
|
|
2227
|
+
return adapter;
|
|
2228
|
+
}
|
|
2229
|
+
function validateHarnessMethodSelection(input) {
|
|
2230
|
+
const adapter = requireFirstPartyHarnessAdapter(input.harnessId);
|
|
2231
|
+
if (input.method === "none") return null;
|
|
2232
|
+
const method2 = adapter.methods.find((candidate) => candidate.id === input.method);
|
|
2233
|
+
if (!method2 || input.scope && !method2.scopes.includes(input.scope)) {
|
|
2234
|
+
const scope = input.scope ? ` for ${input.scope} scope` : "";
|
|
2235
|
+
throw new Error(`${adapter.displayName} does not admit ${input.method}${scope}.`);
|
|
2236
|
+
}
|
|
2237
|
+
return method2;
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
// src/operations/access.ts
|
|
2241
|
+
var NO_ACCESS = Object.freeze({
|
|
2242
|
+
store: "none",
|
|
2243
|
+
project: "none",
|
|
2244
|
+
hostConfig: "none"
|
|
2245
|
+
});
|
|
2246
|
+
var PROJECT_READ_ACCESS = Object.freeze({
|
|
2247
|
+
store: "none",
|
|
2248
|
+
project: "read",
|
|
2249
|
+
hostConfig: "none"
|
|
2250
|
+
});
|
|
2251
|
+
var STORE_READ_PROJECT_READ_ACCESS = Object.freeze({
|
|
2252
|
+
store: "read",
|
|
2253
|
+
project: "read",
|
|
2254
|
+
hostConfig: "none"
|
|
2255
|
+
});
|
|
2256
|
+
var STORE_WRITE_PROJECT_READ_ACCESS = Object.freeze({
|
|
2257
|
+
store: "write",
|
|
2258
|
+
project: "read",
|
|
2259
|
+
hostConfig: "none"
|
|
2260
|
+
});
|
|
2261
|
+
var STORE_WRITE_PROJECT_WRITE_ACCESS = Object.freeze({
|
|
2262
|
+
store: "write",
|
|
2263
|
+
project: "write",
|
|
2264
|
+
hostConfig: "none"
|
|
2265
|
+
});
|
|
2266
|
+
var PROJECT_WRITE_ACCESS = Object.freeze({
|
|
2267
|
+
store: "none",
|
|
2268
|
+
project: "write",
|
|
2269
|
+
hostConfig: "none"
|
|
2270
|
+
});
|
|
2271
|
+
function cloneOperationAccess(access) {
|
|
2272
|
+
return { ...access };
|
|
2273
|
+
}
|
|
2274
|
+
function assertOperationAccess(operation, access, mutation) {
|
|
2275
|
+
if (!isRecord2(access)) {
|
|
2276
|
+
throw new Error(`Operation \`${operation}\` must declare complete access metadata.`);
|
|
2277
|
+
}
|
|
2278
|
+
const keys = Object.keys(access).sort();
|
|
2279
|
+
if (keys.join(",") !== "hostConfig,project,store") {
|
|
2280
|
+
throw new Error(
|
|
2281
|
+
`Operation \`${operation}\` access metadata must declare only store, project, and hostConfig.`
|
|
2282
|
+
);
|
|
2283
|
+
}
|
|
2284
|
+
if (!isAccessLevel(access.store) || !isAccessLevel(access.project)) {
|
|
2285
|
+
throw new Error(
|
|
2286
|
+
`Operation \`${operation}\` access.store and access.project must be none, read, or write.`
|
|
2287
|
+
);
|
|
2288
|
+
}
|
|
2289
|
+
if (access.hostConfig !== "none" && access.hostConfig !== "write") {
|
|
2290
|
+
throw new Error(
|
|
2291
|
+
`Operation \`${operation}\` access.hostConfig must be none or write.`
|
|
2292
|
+
);
|
|
2293
|
+
}
|
|
2294
|
+
if (mutation === "read" && (access.store === "write" || access.project === "write" || access.hostConfig === "write")) {
|
|
2295
|
+
throw new Error(
|
|
2296
|
+
`Read-only operation \`${operation}\` cannot declare write access.`
|
|
2297
|
+
);
|
|
2298
|
+
}
|
|
2299
|
+
if (mutation === "write" && access.store !== "write" && access.project !== "write" && access.hostConfig !== "write") {
|
|
2300
|
+
throw new Error(
|
|
2301
|
+
`Mutating operation \`${operation}\` must declare the state that it writes.`
|
|
2302
|
+
);
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
function isRecord2(value) {
|
|
2306
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2307
|
+
}
|
|
2308
|
+
function isAccessLevel(value) {
|
|
2309
|
+
return value === "none" || value === "read" || value === "write";
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
export {
|
|
2313
|
+
HARNESS_CALLER_IDENTITY_ENV,
|
|
2314
|
+
HARNESS_CALLER_IDENTITY_ARG,
|
|
2315
|
+
HARNESS_CALLER_REFERENCE_ARG,
|
|
2316
|
+
ExecutableVerificationError,
|
|
2317
|
+
sha256,
|
|
2318
|
+
verifyMakeDocsExecutable,
|
|
2319
|
+
listBoundedHarnessCommandRules,
|
|
2320
|
+
fingerprintEntry,
|
|
2321
|
+
encodeHarnessCallerIdentity,
|
|
2322
|
+
parseHarnessCallerReference,
|
|
2323
|
+
parseHarnessCallerIdentityArgument,
|
|
2324
|
+
parseHarnessCallerIdentityValue,
|
|
2325
|
+
parseHarnessCallerIdentity,
|
|
2326
|
+
resolveHarnessMethodSupport,
|
|
2327
|
+
FIRST_PARTY_HARNESS_ADAPTERS,
|
|
2328
|
+
getFirstPartyHarnessAdapter,
|
|
2329
|
+
requireFirstPartyHarnessAdapter,
|
|
2330
|
+
validateHarnessMethodSelection,
|
|
2331
|
+
NO_ACCESS,
|
|
2332
|
+
PROJECT_READ_ACCESS,
|
|
2333
|
+
STORE_READ_PROJECT_READ_ACCESS,
|
|
2334
|
+
STORE_WRITE_PROJECT_READ_ACCESS,
|
|
2335
|
+
STORE_WRITE_PROJECT_WRITE_ACCESS,
|
|
2336
|
+
PROJECT_WRITE_ACCESS,
|
|
2337
|
+
cloneOperationAccess,
|
|
2338
|
+
assertOperationAccess
|
|
2339
|
+
};
|
|
2340
|
+
//# sourceMappingURL=chunk-LRVV7UDD.js.map
|