@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.
Files changed (187) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +36 -27
  3. package/dist/backup-73HQNKMC.js +20 -0
  4. package/dist/backup-73HQNKMC.js.map +1 -0
  5. package/dist/chunk-3BAJQXGH.js +1575 -0
  6. package/dist/chunk-3BAJQXGH.js.map +1 -0
  7. package/dist/chunk-64CTKJO7.js +4136 -0
  8. package/dist/chunk-64CTKJO7.js.map +1 -0
  9. package/dist/chunk-BENO4IH5.js +875 -0
  10. package/dist/chunk-BENO4IH5.js.map +1 -0
  11. package/dist/chunk-D4HDZEJT.js +37 -0
  12. package/dist/chunk-D4HDZEJT.js.map +1 -0
  13. package/dist/chunk-G5EF63GG.js +1291 -0
  14. package/dist/chunk-G5EF63GG.js.map +1 -0
  15. package/dist/chunk-GNP6HRVP.js +523 -0
  16. package/dist/chunk-GNP6HRVP.js.map +1 -0
  17. package/dist/chunk-HJYIQTMD.js +204 -0
  18. package/dist/chunk-HJYIQTMD.js.map +1 -0
  19. package/dist/chunk-LQ5NSWCJ.js +39 -0
  20. package/dist/chunk-LQ5NSWCJ.js.map +1 -0
  21. package/dist/chunk-LRVV7UDD.js +2340 -0
  22. package/dist/chunk-LRVV7UDD.js.map +1 -0
  23. package/dist/chunk-LVQSJF63.js +24674 -0
  24. package/dist/chunk-LVQSJF63.js.map +1 -0
  25. package/dist/chunk-MXBHCHSM.js +13995 -0
  26. package/dist/chunk-MXBHCHSM.js.map +1 -0
  27. package/dist/chunk-Z5K4FHYP.js +922 -0
  28. package/dist/chunk-Z5K4FHYP.js.map +1 -0
  29. package/dist/index.js +3798 -250
  30. package/dist/index.js.map +1 -1
  31. package/dist/self-YYXOLDKU.js +653 -0
  32. package/dist/self-YYXOLDKU.js.map +1 -0
  33. package/dist/server-O2ZELIMX.js +512 -0
  34. package/dist/server-O2ZELIMX.js.map +1 -0
  35. package/dist/setup-system-HZROFNMP.js +544 -0
  36. package/dist/setup-system-HZROFNMP.js.map +1 -0
  37. package/dist/{skills-command-3ESCZ75U.js → skills-command-MGGHY7HU.js} +190 -32
  38. package/dist/skills-command-MGGHY7HU.js.map +1 -0
  39. package/dist/uninstall-3UXXXNFO.js +223 -0
  40. package/dist/uninstall-3UXXXNFO.js.map +1 -0
  41. package/dist/virtual_make-docs-first-party-skills-ZII74YOB.js +11 -0
  42. package/dist/virtual_make-docs-first-party-skills-ZII74YOB.js.map +1 -0
  43. package/package.json +9 -6
  44. package/skill-registry.json +328 -125
  45. package/skill-registry.schema.json +221 -45
  46. package/template/.make-docs/AGENTS.md +18 -0
  47. package/template/.make-docs/CLAUDE.md +18 -0
  48. package/template/.make-docs/archive/AGENTS.md +11 -0
  49. package/template/.make-docs/archive/CLAUDE.md +11 -0
  50. package/template/.make-docs/system/AGENTS.md +12 -0
  51. package/template/.make-docs/system/CLAUDE.md +12 -0
  52. package/template/.make-docs/system/contracts/AGENTS.md +13 -0
  53. package/template/.make-docs/system/contracts/CLAUDE.md +13 -0
  54. package/template/{docs/assets/references → .make-docs/system/contracts}/commit-message-convention.md +4 -4
  55. package/template/.make-docs/system/contracts/coverage-pass-contract.md +198 -0
  56. package/template/.make-docs/system/contracts/deferred-obligation-contract.md +128 -0
  57. package/template/{docs/assets/references → .make-docs/system/contracts}/design-contract.md +7 -2
  58. package/template/{docs/assets/references → .make-docs/system/contracts}/guide-contract.md +21 -19
  59. package/template/{docs/assets/references → .make-docs/system/contracts}/history-record-contract.md +17 -11
  60. package/template/.make-docs/system/contracts/human-experience-contract.md +134 -0
  61. package/template/.make-docs/system/contracts/naive-uat-contract.md +231 -0
  62. package/template/.make-docs/system/contracts/output-contract.md +277 -0
  63. package/template/.make-docs/system/contracts/performance-evidence-governance.md +257 -0
  64. package/template/.make-docs/system/contracts/system-resource-contract.md +93 -0
  65. package/template/.make-docs/system/prompts/AGENTS.md +12 -0
  66. package/template/.make-docs/system/prompts/CLAUDE.md +12 -0
  67. package/template/.make-docs/system/prompts/coverage-pass-maintainer-guide.prompt.md +20 -0
  68. package/template/.make-docs/system/prompts/coverage-pass-prd-reconciliation.prompt.md +18 -0
  69. package/template/.make-docs/system/prompts/coverage-pass-testing-uat.prompt.md +46 -0
  70. package/template/.make-docs/system/prompts/coverage-pass-user-guide.prompt.md +20 -0
  71. package/template/.make-docs/system/prompts/designs-to-plan-change.prompt.md +18 -0
  72. package/template/.make-docs/system/prompts/designs-to-plan.prompt.md +14 -0
  73. package/template/.make-docs/system/prompts/docs-path-hygiene-cleanup.prompt.md +29 -0
  74. package/template/.make-docs/system/prompts/naive-uat-facilitator.prompt.md +28 -0
  75. package/template/.make-docs/system/prompts/naive-uat-tester.prompt.md +20 -0
  76. package/template/.make-docs/system/prompts/performance-coverage.prompt.md +63 -0
  77. package/template/.make-docs/system/prompts/plan-to-prd-change.prompt.md +12 -0
  78. package/template/.make-docs/system/prompts/plan-to-prd-green-field.prompt.md +10 -0
  79. package/template/.make-docs/system/prompts/prd-change-to-work.prompt.md +14 -0
  80. package/template/.make-docs/system/prompts/prd-to-work-full-prd.prompt.md +10 -0
  81. package/template/.make-docs/system/prompts/prd-to-work-prd-feature.prompt.md +10 -0
  82. package/template/.make-docs/system/prompts/request-to-design.prompt.md +20 -0
  83. package/template/.make-docs/system/prompts/session-to-history-record.prompt.md +23 -0
  84. package/template/{docs/assets → .make-docs/system}/prompts/work-to-commit-message.prompt.md +2 -2
  85. package/template/.make-docs/system/prompts/work-to-guides.prompt.md +22 -0
  86. package/template/.make-docs/system/references/AGENTS.md +14 -0
  87. package/template/.make-docs/system/references/CLAUDE.md +14 -0
  88. package/template/{docs/assets → .make-docs/system}/references/design-workflow.md +15 -2
  89. package/template/.make-docs/system/references/execution-workflow.md +189 -0
  90. package/template/.make-docs/system/references/human-experience.md +138 -0
  91. package/template/.make-docs/system/references/lifecycle.md +153 -0
  92. package/template/.make-docs/system/references/naive-uat-validation.md +65 -0
  93. package/template/.make-docs/system/references/naive-uat-workflow.md +64 -0
  94. package/template/.make-docs/system/references/path-and-link-hygiene.md +101 -0
  95. package/template/.make-docs/system/references/performance-evidence.md +114 -0
  96. package/template/.make-docs/system/references/planning-workflow.md +209 -0
  97. package/template/.make-docs/system/references/prd-change-management.md +165 -0
  98. package/template/{docs/assets → .make-docs/system}/references/wave-model.md +10 -8
  99. package/template/.make-docs/system/templates/AGENTS.md +12 -0
  100. package/template/.make-docs/system/templates/CLAUDE.md +12 -0
  101. package/template/.make-docs/system/templates/design.md +79 -0
  102. package/template/{docs/assets/templates/guide-developer.md → .make-docs/system/templates/guide-maintainer.md} +7 -3
  103. package/template/{docs/assets → .make-docs/system}/templates/guide-user.md +6 -2
  104. package/template/{docs/assets → .make-docs/system}/templates/history-record.md +6 -3
  105. package/template/.make-docs/system/templates/naive-uat-scenario.md +91 -0
  106. package/template/.make-docs/system/templates/performance-evidence-profile.md +252 -0
  107. package/template/.make-docs/system/templates/plan-overview.md +76 -0
  108. package/template/.make-docs/system/templates/plan-prd-change.md +155 -0
  109. package/template/{docs/assets → .make-docs/system}/templates/plan-prd-decompose.md +10 -0
  110. package/template/{docs/assets → .make-docs/system}/templates/plan-prd.md +28 -2
  111. package/template/{docs/assets → .make-docs/system}/templates/prd-architecture.md +13 -0
  112. package/template/.make-docs/system/templates/prd-glossary.md +28 -0
  113. package/template/.make-docs/system/templates/prd-index.md +70 -0
  114. package/template/{docs/assets → .make-docs/system}/templates/prd-overview.md +13 -0
  115. package/template/.make-docs/system/templates/prd-reference.md +30 -0
  116. package/template/{docs/assets → .make-docs/system}/templates/prd-risk-register.md +16 -1
  117. package/template/{docs/assets → .make-docs/system}/templates/prd-subsystem.md +15 -0
  118. package/template/.make-docs/system/templates/work-index.md +58 -0
  119. package/template/.make-docs/system/templates/work-phase.md +107 -0
  120. package/template/.make-docs/system-resources.catalog.json +91 -0
  121. package/template/.make-docs/system-resources.schema.json +204 -0
  122. package/template/AGENTS.md +8 -1
  123. package/template/CLAUDE.md +8 -1
  124. package/template/docs/AGENTS.codex-only.md +22 -0
  125. package/template/docs/AGENTS.md +21 -13
  126. package/template/docs/CLAUDE.claude-only.md +22 -0
  127. package/template/docs/CLAUDE.md +21 -13
  128. package/template/docs/assets/AGENTS.md +11 -7
  129. package/template/docs/assets/CLAUDE.md +11 -7
  130. package/template/docs/designs/AGENTS.md +8 -3
  131. package/template/docs/designs/CLAUDE.md +8 -3
  132. package/template/docs/plans/AGENTS.md +10 -3
  133. package/template/docs/plans/CLAUDE.md +10 -3
  134. package/template/docs/prd/AGENTS.md +14 -4
  135. package/template/docs/prd/CLAUDE.md +14 -4
  136. package/template/docs/work/AGENTS.md +10 -3
  137. package/template/docs/work/CLAUDE.md +10 -3
  138. package/dist/chunk-HP3HBG7F.js +0 -626
  139. package/dist/chunk-HP3HBG7F.js.map +0 -1
  140. package/dist/chunk-QRFH4J6H.js +0 -1194
  141. package/dist/chunk-QRFH4J6H.js.map +0 -1
  142. package/dist/chunk-WM3OXYTW.js +0 -2630
  143. package/dist/chunk-WM3OXYTW.js.map +0 -1
  144. package/dist/skills-command-3ESCZ75U.js.map +0 -1
  145. package/dist/uninstall-GQE4SJF2.js +0 -150
  146. package/dist/uninstall-GQE4SJF2.js.map +0 -1
  147. package/template/.make-docs/scripts/check_path_hygiene.py +0 -435
  148. package/template/docs/assets/archive/AGENTS.md +0 -20
  149. package/template/docs/assets/archive/CLAUDE.md +0 -20
  150. package/template/docs/assets/history/AGENTS.md +0 -12
  151. package/template/docs/assets/history/CLAUDE.md +0 -12
  152. package/template/docs/assets/prompts/AGENTS.md +0 -8
  153. package/template/docs/assets/prompts/CLAUDE.md +0 -8
  154. package/template/docs/assets/prompts/designs-to-plan-change.prompt.md +0 -14
  155. package/template/docs/assets/prompts/designs-to-plan.prompt.md +0 -10
  156. package/template/docs/assets/prompts/docs-path-hygiene-cleanup.prompt.md +0 -27
  157. package/template/docs/assets/prompts/plan-to-prd-change.prompt.md +0 -8
  158. package/template/docs/assets/prompts/plan-to-prd-green-field.prompt.md +0 -6
  159. package/template/docs/assets/prompts/prd-change-to-work.prompt.md +0 -10
  160. package/template/docs/assets/prompts/prd-to-work-full-prd.prompt.md +0 -6
  161. package/template/docs/assets/prompts/prd-to-work-prd-feature.prompt.md +0 -6
  162. package/template/docs/assets/prompts/request-to-design.prompt.md +0 -16
  163. package/template/docs/assets/prompts/session-to-history-record.prompt.md +0 -19
  164. package/template/docs/assets/prompts/work-to-guides.prompt.md +0 -18
  165. package/template/docs/assets/references/AGENTS.md +0 -9
  166. package/template/docs/assets/references/CLAUDE.md +0 -9
  167. package/template/docs/assets/references/execution-workflow.md +0 -157
  168. package/template/docs/assets/references/output-contract.md +0 -221
  169. package/template/docs/assets/references/path-and-link-hygiene.md +0 -49
  170. package/template/docs/assets/references/planning-workflow.md +0 -160
  171. package/template/docs/assets/references/prd-change-management.md +0 -129
  172. package/template/docs/assets/templates/AGENTS.md +0 -8
  173. package/template/docs/assets/templates/CLAUDE.md +0 -8
  174. package/template/docs/assets/templates/design.md +0 -30
  175. package/template/docs/assets/templates/plan-overview.md +0 -32
  176. package/template/docs/assets/templates/plan-prd-change.md +0 -99
  177. package/template/docs/assets/templates/prd-change-addition.md +0 -45
  178. package/template/docs/assets/templates/prd-change-revision.md +0 -45
  179. package/template/docs/assets/templates/prd-glossary.md +0 -15
  180. package/template/docs/assets/templates/prd-index.md +0 -45
  181. package/template/docs/assets/templates/prd-reference.md +0 -17
  182. package/template/docs/assets/templates/work-index.md +0 -21
  183. package/template/docs/assets/templates/work-phase.md +0 -34
  184. package/template/docs/guides/AGENTS.md +0 -15
  185. package/template/docs/guides/CLAUDE.md +0 -15
  186. /package/template/{docs/assets → .make-docs/system}/prompts/update-readme-green-field.prompt.md +0 -0
  187. /package/template/{docs/assets → .make-docs/system}/references/harness-capability-matrix.md +0 -0
@@ -0,0 +1,653 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ classifyCompatibilityState
4
+ } from "./chunk-BENO4IH5.js";
5
+ import "./chunk-G5EF63GG.js";
6
+ import {
7
+ bootstrapGlobalStore,
8
+ removeGlobalStore
9
+ } from "./chunk-3BAJQXGH.js";
10
+ import {
11
+ Ct,
12
+ Jt,
13
+ Rt,
14
+ Vt
15
+ } from "./chunk-Z5K4FHYP.js";
16
+ import "./chunk-LRVV7UDD.js";
17
+ import {
18
+ GLOBAL_ASSET_LOCK_FILE,
19
+ STORE_LEASE_RECOVERY_FILE,
20
+ STORE_OWNER_WAIT_MS,
21
+ StoreUnavailableError,
22
+ acquireStoreAccess,
23
+ getStoreDatabasePath,
24
+ makeStoreIssue,
25
+ openStoreSqliteConnection,
26
+ platform,
27
+ readPackageMeta,
28
+ resolveStoreRoot,
29
+ tryCreateExclusiveStoreLease,
30
+ waitForStoreAccessToDrain,
31
+ withInstallationDatabase
32
+ } from "./chunk-MXBHCHSM.js";
33
+ import "./chunk-D4HDZEJT.js";
34
+
35
+ // src/self/install-manager.ts
36
+ import { spawnSync } from "child_process";
37
+ import { realpathSync } from "fs";
38
+ var SELF_PACKAGE_NAME = (() => {
39
+ try {
40
+ return readPackageMeta().name;
41
+ } catch {
42
+ return "@brucewaynedecoy/make-docs";
43
+ }
44
+ })();
45
+ var INSTALL_MANAGER_MATRIX = [
46
+ {
47
+ id: "npm",
48
+ label: "npm (global install)",
49
+ markers: [/\/lib\/node_modules\//],
50
+ uninstallCommand: { command: "npm", args: ["uninstall", "-g", SELF_PACKAGE_NAME] },
51
+ updateCommand: {
52
+ command: "npm",
53
+ args: ["install", "-g", `${SELF_PACKAGE_NAME}@latest`]
54
+ }
55
+ },
56
+ {
57
+ id: "pnpm",
58
+ label: "pnpm (global install)",
59
+ markers: [/\/pnpm\/global\//, /\/\.local\/share\/pnpm\//, /\/Library\/pnpm\//],
60
+ uninstallCommand: { command: "pnpm", args: ["remove", "-g", SELF_PACKAGE_NAME] },
61
+ updateCommand: {
62
+ command: "pnpm",
63
+ args: ["add", "-g", `${SELF_PACKAGE_NAME}@latest`]
64
+ }
65
+ },
66
+ {
67
+ id: "bun",
68
+ label: "bun (global install)",
69
+ markers: [/\/\.bun\/install\/global\//],
70
+ uninstallCommand: { command: "bun", args: ["remove", "-g", SELF_PACKAGE_NAME] },
71
+ updateCommand: {
72
+ command: "bun",
73
+ args: ["add", "-g", `${SELF_PACKAGE_NAME}@latest`]
74
+ }
75
+ },
76
+ {
77
+ id: "homebrew",
78
+ label: "Homebrew",
79
+ markers: [/\/Cellar\/make-docs\//],
80
+ uninstallCommand: { command: "brew", args: ["uninstall", "make-docs"] },
81
+ updateCommand: { command: "brew", args: ["upgrade", "make-docs"] }
82
+ }
83
+ ];
84
+ var REMOTE_EXECUTION_MARKERS = [
85
+ /\/_npx\//,
86
+ /\/pnpm\/store\//,
87
+ /\/\.pnpm-store\//,
88
+ /\/dlx-[^/]+\//,
89
+ /\/\.bun\/install\/cache\//,
90
+ /\/bunx-[^/]+\//
91
+ ];
92
+ function detectInstallSource(options = {}) {
93
+ const realpath = options.realpath ?? defaultRealpath;
94
+ const rawCandidates = [
95
+ options.argv1 ?? process.argv[1],
96
+ options.execPath ?? process.execPath
97
+ ].filter((candidate) => Boolean(candidate));
98
+ const resolvedPaths = [
99
+ ...new Set(rawCandidates.map((candidate) => toPosixPath(realpath(candidate))))
100
+ ];
101
+ const primaryPath = resolvedPaths[0] ?? null;
102
+ if (resolvedPaths.length === 0) {
103
+ return {
104
+ kind: "ambiguous",
105
+ binaryPath: null,
106
+ candidates: [],
107
+ reason: "No script or binary path is available to inspect."
108
+ };
109
+ }
110
+ for (const resolvedPath of resolvedPaths) {
111
+ const remoteMarker = REMOTE_EXECUTION_MARKERS.find(
112
+ (marker) => marker.test(resolvedPath)
113
+ );
114
+ if (remoteMarker) {
115
+ return {
116
+ kind: "remote",
117
+ binaryPath: resolvedPath,
118
+ evidence: `${resolvedPath} matches the transient runner cache pattern ${remoteMarker}.`
119
+ };
120
+ }
121
+ }
122
+ const owners = /* @__PURE__ */ new Map();
123
+ for (const resolvedPath of resolvedPaths) {
124
+ if (!resolvedPath.includes("make-docs")) {
125
+ continue;
126
+ }
127
+ for (const spec of INSTALL_MANAGER_MATRIX) {
128
+ if (spec.markers.some((marker) => marker.test(resolvedPath))) {
129
+ owners.set(spec.id, { spec, path: resolvedPath });
130
+ }
131
+ }
132
+ }
133
+ const matches = [...owners.values()];
134
+ if (matches.length === 1) {
135
+ return {
136
+ kind: "persistent",
137
+ manager: matches[0].spec,
138
+ binaryPath: matches[0].path
139
+ };
140
+ }
141
+ if (matches.length > 1) {
142
+ return {
143
+ kind: "ambiguous",
144
+ binaryPath: primaryPath,
145
+ candidates: matches.map((match) => match.spec),
146
+ reason: `The path matches more than one install manager (${matches.map((match) => match.spec.id).join(", ")}).`
147
+ };
148
+ }
149
+ return {
150
+ kind: "ambiguous",
151
+ binaryPath: primaryPath,
152
+ candidates: [],
153
+ reason: `${primaryPath} matches no known install-manager global root or runner cache.`
154
+ };
155
+ }
156
+ function formatManagerCommand(command) {
157
+ return [command.command, ...command.args].join(" ");
158
+ }
159
+ var defaultExecCommand = async (command, args) => {
160
+ const result = spawnSync(command, args, { stdio: "inherit" });
161
+ return { exitCode: result.status };
162
+ };
163
+ function defaultRealpath(candidate) {
164
+ try {
165
+ return realpathSync(candidate);
166
+ } catch {
167
+ return candidate;
168
+ }
169
+ }
170
+ function toPosixPath(candidate) {
171
+ return candidate.split("\\").join("/");
172
+ }
173
+
174
+ // src/self/pre-v2.ts
175
+ function detectPreV2Install(input) {
176
+ const { classification } = input;
177
+ const fingerprints = [];
178
+ if (classification.evidence.manifestTrust.schemaVersion === 1) {
179
+ fingerprints.push("manifest-schema-version-1");
180
+ }
181
+ if (classification.state === "clean-v1") {
182
+ fingerprints.push("state-clean-v1");
183
+ }
184
+ if (classification.state === "modified-v1") {
185
+ fingerprints.push("state-modified-v1");
186
+ }
187
+ return { preV2: fingerprints.length > 0, fingerprints };
188
+ }
189
+ var PRE_V2_BREAKING_CHANGES = [
190
+ "Command spellings are replaced by the five-command tree (setup, run, mcp, update, uninstall); removed spellings have no aliases.",
191
+ "Project uninstall is renamed: use `make-docs setup remove` (top-level `uninstall` now removes the tool's machine footprint).",
192
+ "Run-state and work-execution evidence relocate to the global store at ~/.make-docs/, keyed by a minted project identifier.",
193
+ "MCP tool names are renamed to registry-derived identifiers.",
194
+ "The project manifest schema is upgraded and a project identifier is minted."
195
+ ];
196
+ var defaultSelfCommandOutput = {
197
+ write(text) {
198
+ process.stdout.write(`${text}
199
+ `);
200
+ }
201
+ };
202
+ async function promptPreV2Choice(input) {
203
+ if (!input.detection.preV2) {
204
+ return "backup-and-install";
205
+ }
206
+ const output = input.output ?? defaultSelfCommandOutput;
207
+ const warningLines = [
208
+ `A pre-v2 make-docs install was detected (fingerprints: ${input.detection.fingerprints.join(", ")}).`,
209
+ "Upgrading is a hard cutover; these changes can break the existing install:",
210
+ ...PRE_V2_BREAKING_CHANGES.map((change) => `- ${change}`)
211
+ ];
212
+ if (!input.interactive) {
213
+ for (const line of warningLines) {
214
+ output.write(line);
215
+ }
216
+ output.write(
217
+ `\`make-docs ${input.command}\` will not silently upgrade a pre-v2 install. Re-run in an interactive terminal to choose between backing up and installing the latest version (recommended) and cancelling, or create an explicit backup first with \`make-docs setup backup\`.`
218
+ );
219
+ return "cancel";
220
+ }
221
+ Vt(warningLines.join("\n"), `make-docs ${input.command}: pre-v2 install detected`);
222
+ const choice = await Jt({
223
+ message: "How should make-docs proceed?",
224
+ withGuide: true,
225
+ initialValue: "backup-and-install",
226
+ options: [
227
+ {
228
+ value: "backup-and-install",
229
+ label: "Back up and install the latest version (recommended)"
230
+ },
231
+ {
232
+ value: "cancel",
233
+ label: "Cancel"
234
+ }
235
+ ]
236
+ });
237
+ if (Ct(choice)) {
238
+ return "cancel";
239
+ }
240
+ return choice;
241
+ }
242
+
243
+ // src/self/uninstall-tool.ts
244
+ import { existsSync as existsSync2, readdirSync, rmdirSync } from "fs";
245
+ import { stdin, stdout } from "process";
246
+
247
+ // src/store/tool-operations.ts
248
+ import { randomUUID } from "crypto";
249
+ import path from "path";
250
+ import { existsSync, lstatSync, unlinkSync, readFileSync } from "fs";
251
+ function prepareToolOperationStore(targetDir, storeRoot) {
252
+ withInstallationDatabase(targetDir, (db) => {
253
+ db.prepare("SELECT operation_id FROM tool_operations LIMIT 1").get();
254
+ }, { storeRoot });
255
+ }
256
+ async function runRecordedToolOperation(targetDir, storeRoot, operation, metadata, delegate) {
257
+ const operationId = randomUUID();
258
+ withInstallationDatabase(targetDir, (db) => {
259
+ db.exec("BEGIN IMMEDIATE");
260
+ try {
261
+ const pending = db.prepare("SELECT operation_id, pid, hostname FROM tool_operations WHERE status='pending' LIMIT 1").get();
262
+ if (pending) throw new Error(`Tool operation ${pending.operation_id} is pending (${pending.hostname}, process ${pending.pid}). Inspect the package manager result before another tool change. No command was run.`);
263
+ const installation = db.prepare("SELECT operation_id FROM installation_operations WHERE status='pending' LIMIT 1").get();
264
+ const writer = db.prepare("SELECT root_path FROM installation_locks LIMIT 1").get();
265
+ if (installation || writer) throw new Error("An installation operation or checkout writer is pending. Resolve that work before a tool change. No command was run.");
266
+ db.prepare("INSERT INTO tool_operations (operation_id,operation,status,pid,hostname,metadata_json,started_at,finished_at) VALUES (?,?,'pending',?,?,?,?,NULL)").run(operationId, operation, process.pid, platform.hostname, JSON.stringify(metadata), (/* @__PURE__ */ new Date()).toISOString());
267
+ db.exec("COMMIT");
268
+ } catch (error) {
269
+ db.exec("ROLLBACK");
270
+ throw error;
271
+ }
272
+ }, { storeRoot });
273
+ withInstallationDatabase(targetDir, (db) => {
274
+ const saved = db.prepare("SELECT status, operation, pid, hostname FROM tool_operations WHERE operation_id=?").get(operationId);
275
+ if (!saved || saved.status !== "pending" || saved.operation !== operation || saved.pid !== process.pid || saved.hostname !== platform.hostname) {
276
+ throw new Error(`Tool intent read-back failed for ${operationId}; no package manager command was run.`);
277
+ }
278
+ }, { storeRoot, readOnly: true });
279
+ if (existsSync(path.join(storeRoot, "removal.lock"))) throw new Error(`Store removal is active; tool operation ${operationId} remains pending and no package manager command was run.`);
280
+ let result;
281
+ try {
282
+ result = await delegate();
283
+ } catch (error) {
284
+ withInstallationDatabase(targetDir, (db) => {
285
+ db.prepare("UPDATE tool_operations SET status='failed', metadata_json=?, finished_at=? WHERE operation_id=? AND status='pending'").run(JSON.stringify({ ...metadata, outcome: "delegate-threw", changeOutcome: "unknown" }), (/* @__PURE__ */ new Date()).toISOString(), operationId);
286
+ }, { storeRoot });
287
+ throw error;
288
+ }
289
+ withInstallationDatabase(targetDir, (db) => {
290
+ db.prepare("UPDATE tool_operations SET status=?, metadata_json=?, finished_at=? WHERE operation_id=? AND status='pending'").run(result.exitCode === 0 ? "completed" : "failed", JSON.stringify({ ...metadata, exitCode: result.exitCode }), (/* @__PURE__ */ new Date()).toISOString(), operationId);
291
+ }, { storeRoot });
292
+ return { operationId, result };
293
+ }
294
+ function acquireRemovalLease(storeRoot, lockPath, token) {
295
+ const started = Date.now();
296
+ const deadline = started + STORE_OWNER_WAIT_MS;
297
+ let attempts = 0;
298
+ while (true) {
299
+ try {
300
+ const result = tryCreateExclusiveStoreLease(lockPath, { token, pid: process.pid, hostname: platform.hostname, startedAt: (/* @__PURE__ */ new Date()).toISOString() });
301
+ if (result.created) return result.stat;
302
+ throw Object.assign(new Error("The Store removal lock exists."), { code: "EEXIST" });
303
+ } catch (error) {
304
+ if (error instanceof StoreUnavailableError) throw error;
305
+ if (error.code !== "EEXIST") {
306
+ throw new StoreUnavailableError(makeStoreIssue("io-error", lockPath, "create Store removal lock", error, { attempts: attempts + 1, waitedMs: Date.now() - started }));
307
+ }
308
+ if (Date.now() >= deadline) {
309
+ throw new StoreUnavailableError({ code: "contention-timeout", path: lockPath, operation: "wait for Store removal", retryable: true, attempts: attempts + 1, waitedMs: Date.now() - started, cause: "The Store removal owner is still active." });
310
+ }
311
+ const release = acquireStoreAccess(storeRoot, false, Math.max(0, deadline - Date.now()));
312
+ release();
313
+ attempts++;
314
+ }
315
+ }
316
+ }
317
+ function withStoreRemovalLock(targetDir, storeRoot, remove) {
318
+ prepareToolOperationStore(targetDir, storeRoot);
319
+ const lockPath = path.join(storeRoot, "removal.lock");
320
+ const token = randomUUID();
321
+ const lockStat = acquireRemovalLease(storeRoot, lockPath, token);
322
+ const lockGuard = platform.captureFileGuard(lockStat, "file");
323
+ try {
324
+ const assertNoStoreAccess = () => {
325
+ if (["installation-bootstrap.lock", GLOBAL_ASSET_LOCK_FILE, STORE_LEASE_RECOVERY_FILE].some((name) => lstatSync(path.join(storeRoot, name), { throwIfNoEntry: false }))) {
326
+ throw new Error("A Store schema or global asset writer is active; the Store was preserved.");
327
+ }
328
+ };
329
+ assertNoStoreAccess();
330
+ waitForStoreAccessToDrain(storeRoot);
331
+ const db = openStoreSqliteConnection(getStoreDatabasePath(storeRoot), { readOnly: true }, "inspect before removal");
332
+ try {
333
+ const tool = db.prepare("SELECT operation_id FROM tool_operations WHERE status='pending' LIMIT 1").get();
334
+ const project = db.prepare("SELECT operation_id FROM installation_operations WHERE status='pending' LIMIT 1").get();
335
+ const writer = db.prepare("SELECT root_path FROM installation_locks LIMIT 1").get();
336
+ if (tool || project || writer) throw new Error("Store removal is blocked by a pending operation or active writer. Resolve that work first; the Store was preserved.");
337
+ } finally {
338
+ db.close();
339
+ }
340
+ assertNoStoreAccess();
341
+ waitForStoreAccessToDrain(storeRoot);
342
+ return remove();
343
+ } finally {
344
+ const current = lstatSync(lockPath, { throwIfNoEntry: false });
345
+ if (current?.isFile() && platform.matchesFileGuard(current, lockGuard)) {
346
+ try {
347
+ const record = JSON.parse(readFileSync(lockPath, "utf8"));
348
+ if (record.token === token) unlinkSync(lockPath);
349
+ } catch {
350
+ }
351
+ }
352
+ }
353
+ }
354
+
355
+ // src/self/uninstall-tool.ts
356
+ async function runToolUninstallCommand(options) {
357
+ const output = options.output ?? defaultSelfCommandOutput;
358
+ const exec = options.exec ?? defaultExecCommand;
359
+ const storeRoot = resolveStoreRoot({
360
+ storeRoot: options.storeRoot,
361
+ env: options.env,
362
+ homeDir: options.homeDir
363
+ });
364
+ const detection = detectInstallSource({
365
+ argv1: options.argv1,
366
+ execPath: options.execPath,
367
+ realpath: options.realpath
368
+ });
369
+ const lines = [];
370
+ const emit = (line) => {
371
+ lines.push(line);
372
+ output.write(line);
373
+ };
374
+ emit("make-docs uninstall removes the installed binary:");
375
+ emit(
376
+ `- global Store: ${storeRoot} (${options.removeStore ? "explicit removal selected; all stored history and recovery records will be deleted" : "preserved"})`
377
+ );
378
+ emit(`- installed binary: ${describeBinaryFootprint(detection)}`);
379
+ emit(
380
+ "Repository content is never touched; to remove make-docs from a project, use `make-docs setup remove`."
381
+ );
382
+ const result = {
383
+ operationId: null,
384
+ status: "completed",
385
+ storeRoot,
386
+ detection,
387
+ storeRemoval: null,
388
+ binary: null,
389
+ lines
390
+ };
391
+ if (!options.yes) {
392
+ if (!stdin.isTTY || !stdout.isTTY) {
393
+ result.status = "refused-non-interactive";
394
+ emit(
395
+ "Uninstall confirmation requires a TTY. Re-run with `make-docs uninstall --yes` to confirm removal of the footprint listed above. Nothing was removed."
396
+ );
397
+ return result;
398
+ }
399
+ const proceed = await Rt({
400
+ message: options.removeStore ? "Remove the binary and permanently delete the global Store records listed above?" : "Remove the make-docs binary and preserve the global Store?",
401
+ initialValue: false,
402
+ active: "Yes",
403
+ inactive: "No",
404
+ withGuide: true
405
+ });
406
+ if (Ct(proceed) || !proceed) {
407
+ result.status = "cancelled";
408
+ emit("Uninstall cancelled. Nothing was removed.");
409
+ return result;
410
+ }
411
+ }
412
+ const targetDir = process.cwd();
413
+ prepareToolOperationStore(targetDir, storeRoot);
414
+ emit(`The global Store is preserved at ${storeRoot}.`);
415
+ const removeSelectedStore = () => {
416
+ if (!options.removeStore) return;
417
+ const removal = withStoreRemovalLock(targetDir, storeRoot, () => removeGlobalStore({ storeRoot, env: options.env, homeDir: options.homeDir }));
418
+ removal.retainedEntries = removal.retainedEntries.filter((entry) => entry !== "removal.lock");
419
+ removal.warnings = removal.warnings.filter((warning) => !warning.includes("removal.lock"));
420
+ if (removal.status !== "refused" && existsSync2(storeRoot) && readdirSync(storeRoot).length === 0) {
421
+ rmdirSync(storeRoot);
422
+ removal.status = "removed";
423
+ }
424
+ result.storeRemoval = removal;
425
+ emit(describeStoreRemoval(removal));
426
+ for (const warning of removal.warnings) emit(`Warning: ${warning}`);
427
+ };
428
+ if (detection.kind === "persistent") {
429
+ const command = formatManagerCommand(detection.manager.uninstallCommand);
430
+ const recorded = await runRecordedToolOperation(targetDir, storeRoot, "tool.uninstall", {
431
+ manager: detection.manager.id,
432
+ command,
433
+ binaryPath: detection.binaryPath
434
+ }, () => exec(detection.manager.uninstallCommand.command, detection.manager.uninstallCommand.args));
435
+ result.operationId = recorded.operationId;
436
+ const { exitCode } = recorded.result;
437
+ emit(`Tool operation recorded in the Store: ${recorded.operationId}`);
438
+ if (exitCode === 0) {
439
+ result.binary = {
440
+ kind: "removed",
441
+ manager: detection.manager.id,
442
+ command,
443
+ exitCode
444
+ };
445
+ emit(`Removed the installed binary via ${detection.manager.id}: ${command}`);
446
+ removeSelectedStore();
447
+ } else {
448
+ result.binary = {
449
+ kind: "failed",
450
+ manager: detection.manager.id,
451
+ command,
452
+ exitCode
453
+ };
454
+ result.status = "manual-binary-removal-required";
455
+ emit(
456
+ `The ${detection.manager.id} uninstall command failed (exit code ${exitCode ?? "unknown"}). Run it manually: ${command}`
457
+ );
458
+ }
459
+ return result;
460
+ }
461
+ if (detection.kind === "remote") {
462
+ result.binary = { kind: "not-installed", evidence: detection.evidence };
463
+ removeSelectedStore();
464
+ emit(
465
+ "No persistent make-docs binary is installed: this invocation uses a package runner. The Store remains available unless explicit removal was selected."
466
+ );
467
+ return result;
468
+ }
469
+ const candidates = detection.candidates.length > 0 ? detection.candidates : [...INSTALL_MANAGER_MATRIX];
470
+ const commands = candidates.map(
471
+ (candidate) => formatManagerCommand(candidate.uninstallCommand)
472
+ );
473
+ result.binary = {
474
+ kind: "manual",
475
+ candidates: candidates.map((candidate) => candidate.id),
476
+ commands
477
+ };
478
+ result.status = "manual-binary-removal-required";
479
+ emit(
480
+ `Could not determine which install manager owns the make-docs binary (${detection.reason})`
481
+ );
482
+ emit(
483
+ "make-docs will not guess and run a destructive global change. If you installed the binary yourself, run the matching command:"
484
+ );
485
+ for (const command of commands) {
486
+ emit(` ${command}`);
487
+ }
488
+ emit(`Affected store path: ${storeRoot}`);
489
+ return result;
490
+ }
491
+ function describeBinaryFootprint(detection) {
492
+ if (detection.kind === "persistent") {
493
+ return `${detection.binaryPath} (managed by ${detection.manager.id}; will run \`${formatManagerCommand(detection.manager.uninstallCommand)}\`)`;
494
+ }
495
+ if (detection.kind === "remote") {
496
+ return "none detected (remote execution via a package runner; nothing persistent to remove)";
497
+ }
498
+ return "ownership is ambiguous; the exact command(s) will be printed instead of executed";
499
+ }
500
+ function describeStoreRemoval(removal) {
501
+ switch (removal.status) {
502
+ case "removed":
503
+ return `Removed the global store at ${removal.storeRoot} (${removal.removedFiles.length} file(s)).`;
504
+ case "not-found":
505
+ return `No global store exists at ${removal.storeRoot}; nothing to remove.`;
506
+ case "refused":
507
+ return `Refused to remove ${removal.storeRoot}; see the warning below.`;
508
+ default:
509
+ return `The global store at ${removal.storeRoot} was partially removed; retained entries: ${removal.retainedEntries.join(", ") || "(none)"}.`;
510
+ }
511
+ }
512
+
513
+ // src/self/update-tool.ts
514
+ import path2 from "path";
515
+ import { stdin as stdin2, stdout as stdout2 } from "process";
516
+ async function runToolUpdateCommand(options) {
517
+ const output = options.output ?? defaultSelfCommandOutput;
518
+ const exec = options.exec ?? defaultExecCommand;
519
+ const classify = options.classify ?? classifyCompatibilityState;
520
+ const storeRoot = resolveStoreRoot({
521
+ storeRoot: options.storeRoot,
522
+ env: options.env,
523
+ homeDir: options.homeDir
524
+ });
525
+ const targetDir = path2.resolve(options.targetDir ?? process.cwd());
526
+ const lines = [];
527
+ const emit = (line) => {
528
+ lines.push(line);
529
+ output.write(line);
530
+ };
531
+ prepareToolOperationStore(targetDir, storeRoot);
532
+ const bootstrap = bootstrapGlobalStore({
533
+ storeRoot,
534
+ env: options.env,
535
+ homeDir: options.homeDir,
536
+ packageMeta: safeReadPackageMeta()
537
+ });
538
+ emit(
539
+ `Global store at ${bootstrap.storeRoot}: database ${bootstrap.databaseStatus}` + (bootstrap.schemaVersion === null ? "" : ` (schema version ${bootstrap.schemaVersion})`)
540
+ );
541
+ for (const warning of bootstrap.warnings) {
542
+ emit(`Warning: ${warning}`);
543
+ }
544
+ const detection = detectInstallSource({
545
+ argv1: options.argv1,
546
+ execPath: options.execPath,
547
+ realpath: options.realpath
548
+ });
549
+ const result = {
550
+ operationId: null,
551
+ status: "nothing-persistent",
552
+ storeRoot,
553
+ bootstrap,
554
+ detection,
555
+ preV2: { preV2: false, fingerprints: [] },
556
+ preV2Choice: null,
557
+ executedCommand: null,
558
+ printedCommands: [],
559
+ lines
560
+ };
561
+ const classification = await classify({ targetDir, homeDir: options.homeDir });
562
+ result.preV2 = detectPreV2Install({ targetDir, classification });
563
+ if (result.preV2.preV2) {
564
+ result.preV2Choice = await promptPreV2Choice({
565
+ detection: result.preV2,
566
+ interactive: Boolean(stdin2.isTTY && stdout2.isTTY),
567
+ command: "update",
568
+ output
569
+ });
570
+ if (result.preV2Choice === "cancel") {
571
+ result.status = "cancelled-pre-v2";
572
+ emit(
573
+ `Update cancelled: the pre-v2 install at ${targetDir} was left untouched. The global-store migration above is additive and does not affect the project.`
574
+ );
575
+ return result;
576
+ }
577
+ emit(`Backing up the pre-v2 install at ${targetDir} before updating.`);
578
+ const runBackup = options.runBackup ?? defaultRunBackup;
579
+ await runBackup(targetDir);
580
+ }
581
+ if (detection.kind === "persistent") {
582
+ const command = formatManagerCommand(detection.manager.updateCommand);
583
+ emit(`Delegating to ${detection.manager.id}: ${command}`);
584
+ const recorded = await runRecordedToolOperation(targetDir, storeRoot, "tool.update", {
585
+ manager: detection.manager.id,
586
+ command,
587
+ binaryPath: detection.binaryPath
588
+ }, () => exec(detection.manager.updateCommand.command, detection.manager.updateCommand.args));
589
+ result.operationId = recorded.operationId;
590
+ const { exitCode } = recorded.result;
591
+ emit(`Tool operation recorded in the Store: ${recorded.operationId}`);
592
+ result.executedCommand = command;
593
+ if (exitCode === 0) {
594
+ result.status = "delegated";
595
+ emit(`Update delegated to ${detection.manager.id} completed.`);
596
+ } else {
597
+ result.status = "delegate-failed";
598
+ emit(
599
+ `The ${detection.manager.id} update command failed (exit code ${exitCode ?? "unknown"}). Run it manually: ${command}`
600
+ );
601
+ }
602
+ return result;
603
+ }
604
+ if (detection.kind === "remote") {
605
+ result.status = "nothing-persistent";
606
+ emit(
607
+ "Nothing persistent to update: this invocation runs via a package runner (remote execution), and the runner fetches the requested version on each run."
608
+ );
609
+ return result;
610
+ }
611
+ const candidates = detection.candidates.length > 0 ? detection.candidates : [...INSTALL_MANAGER_MATRIX];
612
+ result.printedCommands = candidates.map(
613
+ (candidate) => formatManagerCommand(candidate.updateCommand)
614
+ );
615
+ result.status = "manual-update-required";
616
+ emit(
617
+ `Could not determine which install manager owns the make-docs binary (${detection.reason})`
618
+ );
619
+ emit(
620
+ "make-docs will not guess and run a global change. If you installed the binary yourself, run the matching command:"
621
+ );
622
+ for (const command of result.printedCommands) {
623
+ emit(` ${command}`);
624
+ }
625
+ emit(`Affected store path: ${storeRoot}`);
626
+ return result;
627
+ }
628
+ async function defaultRunBackup(targetDir) {
629
+ const { runBackupCommand } = await import("./backup-73HQNKMC.js");
630
+ await runBackupCommand({ targetDir, permissions: "allow-all" });
631
+ }
632
+ function safeReadPackageMeta() {
633
+ try {
634
+ return readPackageMeta();
635
+ } catch {
636
+ return void 0;
637
+ }
638
+ }
639
+ export {
640
+ INSTALL_MANAGER_MATRIX,
641
+ PRE_V2_BREAKING_CHANGES,
642
+ REMOTE_EXECUTION_MARKERS,
643
+ SELF_PACKAGE_NAME,
644
+ defaultExecCommand,
645
+ defaultSelfCommandOutput,
646
+ detectInstallSource,
647
+ detectPreV2Install,
648
+ formatManagerCommand,
649
+ promptPreV2Choice,
650
+ runToolUninstallCommand,
651
+ runToolUpdateCommand
652
+ };
653
+ //# sourceMappingURL=self-YYXOLDKU.js.map