@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,1291 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ HARNESSES,
4
+ PACKAGE_ROOT,
5
+ RETIRED_PLAYBOOK_CONTRACT_HASH,
6
+ RETIRED_PLAYBOOK_CONTRACT_PATH,
7
+ TOOL_DIRECTORY_CONFIG_RELATIVE_PATH,
8
+ assertManagedPathHasNoSymlinks,
9
+ classifyAgenticFileRole,
10
+ contentEquals,
11
+ createAuditPathMetadata,
12
+ defaultSelections,
13
+ formatAgenticFileRole,
14
+ getDesiredAssets,
15
+ getDesiredSkillAssets,
16
+ getHarnessSkillDirectory,
17
+ getManifestAuditContext,
18
+ getManifestFileHash,
19
+ getManifestPath,
20
+ getRetiredManagedSkillAssets,
21
+ hasTrustedRetiredPlaybookContractOwnership,
22
+ hashText,
23
+ isInstructionManifestPath,
24
+ loadEffectiveSkillRegistry,
25
+ loadSkillRegistry,
26
+ parseManagedBlock,
27
+ readTextFile,
28
+ relativePathToTarget,
29
+ resolveInstallProfile
30
+ } from "./chunk-MXBHCHSM.js";
31
+
32
+ // src/backup-paths.ts
33
+ import path from "path";
34
+ var PROJECT_BACKUP_RELATIVE_PATH = ".make-docs/backup";
35
+ var LEGACY_PROJECT_BACKUP_RELATIVE_PATH = ".backup";
36
+ function getProjectBackupRoot(targetDir) {
37
+ return path.resolve(targetDir, PROJECT_BACKUP_RELATIVE_PATH);
38
+ }
39
+ function getLegacyProjectBackupRoot(targetDir) {
40
+ return path.resolve(targetDir, LEGACY_PROJECT_BACKUP_RELATIVE_PATH);
41
+ }
42
+ function getProjectBackupStateRoots(targetDir) {
43
+ return [
44
+ getProjectBackupRoot(targetDir),
45
+ getLegacyProjectBackupRoot(targetDir)
46
+ ];
47
+ }
48
+ function isInsideProjectBackupStateRoot(targetDir, candidatePath) {
49
+ return getProjectBackupStateRoots(targetDir).some(
50
+ (backupRoot) => isWithinRoot(backupRoot, candidatePath)
51
+ );
52
+ }
53
+ function isWithinRoot(rootPath, candidatePath) {
54
+ const relative = path.relative(path.resolve(rootPath), path.resolve(candidatePath));
55
+ return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
56
+ }
57
+
58
+ // src/audit.ts
59
+ import { existsSync, lstatSync, readFileSync, readdirSync, readlinkSync } from "fs";
60
+ import os from "os";
61
+ import path2 from "path";
62
+ var SHARED_AGENTICS_SKILL_DIR = ".make-docs/agentics/skills";
63
+ var SHARED_AGENTICS_PLUGIN_DIR = ".make-docs/agentics/plugins";
64
+ var HARNESS_SKILL_DIRS = {
65
+ "claude-code": ".claude/skills",
66
+ codex: ".agents/skills"
67
+ };
68
+ var HARNESS_PLUGIN_DIRS = {
69
+ "claude-code": ".claude/plugins",
70
+ codex: ".agents/plugins"
71
+ };
72
+ async function createAuditReport(options) {
73
+ if (typeof options?.targetDir !== "string" || options.targetDir.trim().length === 0) {
74
+ throw new TypeError("Audit targetDir must be a non-empty string.");
75
+ }
76
+ const targetDir = path2.resolve(options.targetDir);
77
+ const homeDir = path2.resolve(options.homeDir ?? os.homedir());
78
+ const removableFiles = /* @__PURE__ */ new Map();
79
+ const preservedPaths = /* @__PURE__ */ new Map();
80
+ const skippedPaths = /* @__PURE__ */ new Map();
81
+ if (options.manifest) {
82
+ await classifyManifestPresent({
83
+ targetDir,
84
+ homeDir,
85
+ manifest: options.manifest,
86
+ removableFiles,
87
+ preservedPaths,
88
+ skippedPaths
89
+ });
90
+ } else {
91
+ await classifyManifestMissing({
92
+ targetDir,
93
+ homeDir,
94
+ removableFiles,
95
+ preservedPaths,
96
+ skippedPaths
97
+ });
98
+ }
99
+ classifyProjectConfig({
100
+ targetDir,
101
+ homeDir,
102
+ preservedPaths
103
+ });
104
+ const prunableDirectories = classifyPrunableDirectories({
105
+ targetDir,
106
+ homeDir,
107
+ removableFiles: [...removableFiles.values()],
108
+ preservedPaths,
109
+ skippedPaths
110
+ });
111
+ return {
112
+ mode: options.manifest ? "manifest-present" : "manifest-missing",
113
+ targetDir,
114
+ manifestPath: getManifestPath(targetDir),
115
+ ...options.manifest ? {
116
+ skillSelectionReview: createSkillSelectionReview(
117
+ options.manifest.selections
118
+ ),
119
+ pluginSelectionReview: createPluginSelectionReview(
120
+ options.manifest.selections
121
+ )
122
+ } : {},
123
+ removableFiles: sortAuditEntries([...removableFiles.values()]),
124
+ prunableDirectories: sortPrunableDirectories(prunableDirectories).filter((entry) => path2.resolve(entry.absolutePath) !== path2.resolve(homeDir, ".make-docs")),
125
+ preservedPaths: sortAuditEntries([...preservedPaths.values()]),
126
+ skippedPaths: sortAuditEntries([...skippedPaths.values()])
127
+ };
128
+ }
129
+ async function classifyManifestPresent(options) {
130
+ const {
131
+ targetDir,
132
+ homeDir,
133
+ manifest,
134
+ removableFiles,
135
+ preservedPaths,
136
+ skippedPaths
137
+ } = options;
138
+ const auditContext = getManifestAuditContext(targetDir, manifest, homeDir);
139
+ const manifestCandidates = /* @__PURE__ */ new Map();
140
+ for (const record of auditContext.managedFiles) {
141
+ manifestCandidates.set(record.absolutePath, record);
142
+ }
143
+ for (const record of auditContext.skillFiles) {
144
+ manifestCandidates.set(
145
+ record.absolutePath,
146
+ manifestCandidates.get(record.absolutePath) ?? record
147
+ );
148
+ }
149
+ const manifestSkillContentByPath = await loadCanonicalSkillContentByPath(
150
+ targetDir,
151
+ homeDir,
152
+ auditContext.priorSelections,
153
+ [...manifestCandidates.values()].some(
154
+ (record) => record.ownershipSource === "manifest-skill-file"
155
+ )
156
+ );
157
+ const manifestRecordByPath = new Map(
158
+ [...manifestCandidates.values()].map((record) => [record.path, record])
159
+ );
160
+ for (const record of sortAuditEntries([...manifestCandidates.values()])) {
161
+ if (record.path === RETIRED_PLAYBOOK_CONTRACT_PATH) {
162
+ let trusted = hasTrustedRetiredPlaybookContractOwnership(manifest.files[record.path]);
163
+ try {
164
+ assertManagedPathHasNoSymlinks(targetDir, record.path);
165
+ trusted &&= existsSync(record.absolutePath) && lstatSync(record.absolutePath).isFile() && hashText(readTextFile(record.absolutePath)) === RETIRED_PLAYBOOK_CONTRACT_HASH;
166
+ } catch {
167
+ trusted = false;
168
+ }
169
+ addPreserved(preservedPaths, record, createReason(
170
+ trusted ? "managed-file-hash-match" : "managed-file-modified",
171
+ trusted ? "The retired contract is trusted legacy input. Only reviewed migration checkpoint 11 may remove it." : "The retired contract lacks trusted ownership or bytes, or has a symlink path, and must be preserved."
172
+ ));
173
+ continue;
174
+ }
175
+ classifyManifestRecord({
176
+ targetDir,
177
+ record,
178
+ manifestSkillContentByPath,
179
+ manifestRecordByPath,
180
+ removableFiles,
181
+ preservedPaths,
182
+ skippedPaths
183
+ });
184
+ }
185
+ }
186
+ function classifyManifestRecord(options) {
187
+ const {
188
+ targetDir,
189
+ record,
190
+ manifestSkillContentByPath,
191
+ manifestRecordByPath,
192
+ removableFiles,
193
+ preservedPaths,
194
+ skippedPaths
195
+ } = options;
196
+ if (isInsideProjectBackupRoot(targetDir, record.absolutePath)) {
197
+ addSkipped(
198
+ skippedPaths,
199
+ record,
200
+ "excluded",
201
+ createReason(
202
+ "inside-backup-root",
203
+ "Paths inside project backup state trees are excluded from removal consideration."
204
+ )
205
+ );
206
+ return;
207
+ }
208
+ if (record.pathScope === "external") {
209
+ addSkipped(
210
+ skippedPaths,
211
+ record,
212
+ "excluded",
213
+ createReason(
214
+ "outside-supported-roots",
215
+ "This path is outside both the target directory and the user home directory and is preserved conservatively."
216
+ )
217
+ );
218
+ return;
219
+ }
220
+ if (!existsSync(record.absolutePath)) {
221
+ addSkipped(
222
+ skippedPaths,
223
+ record,
224
+ "already-absent",
225
+ createReason("already-absent", "The managed path is already absent on disk.")
226
+ );
227
+ return;
228
+ }
229
+ if (record.skillExposure) {
230
+ classifyManifestSkillExposureRecord({
231
+ targetDir,
232
+ record,
233
+ manifestSkillContentByPath,
234
+ removableFiles,
235
+ preservedPaths
236
+ });
237
+ return;
238
+ }
239
+ if (record.agenticOwnership?.artifactKind === "plugin") {
240
+ classifyManifestPluginOwnershipRecord({
241
+ targetDir,
242
+ record,
243
+ manifestRecordByPath,
244
+ removableFiles,
245
+ preservedPaths
246
+ });
247
+ return;
248
+ }
249
+ if (record.agenticOwnership?.artifactKind === "skill" && record.agenticOwnership.role === "native-exposure" && record.agenticOwnership.pathKind === "directory") {
250
+ classifyPackagingSkillExposureRecord({
251
+ targetDir,
252
+ record,
253
+ removableFiles,
254
+ preservedPaths
255
+ });
256
+ return;
257
+ }
258
+ if (!lstatSync(record.absolutePath).isFile()) {
259
+ addPreserved(
260
+ preservedPaths,
261
+ record,
262
+ createReason(
263
+ "managed-file-modified",
264
+ "The managed file path is no longer a regular file and will be preserved."
265
+ )
266
+ );
267
+ return;
268
+ }
269
+ const currentBytes = readFileSync(record.absolutePath);
270
+ const currentHash = hashText(currentBytes);
271
+ if (record.ownershipSource === "managed-state") {
272
+ addRemovable(
273
+ removableFiles,
274
+ record,
275
+ createReason(
276
+ "managed-state-file",
277
+ "The make-docs manifest is CLI-managed state and is eligible for removal."
278
+ ),
279
+ currentHash,
280
+ void 0
281
+ );
282
+ return;
283
+ }
284
+ if (isInstructionPath(record.path)) {
285
+ const currentContent = currentBytes.toString("utf8");
286
+ const currentBlockHash = getManifestFileHash(record.path, currentContent);
287
+ if (currentBlockHash && record.manifestHash && currentBlockHash === record.manifestHash) {
288
+ const parsed = parseManagedBlock(currentContent);
289
+ if (parsed.prefix.trim().length > 0 || parsed.suffix.trim().length > 0) {
290
+ addPreserved(
291
+ preservedPaths,
292
+ record,
293
+ createReason(
294
+ "instruction-user-content-preserved",
295
+ "The managed block matches the manifest, but user content exists outside the block so the instruction file is preserved."
296
+ )
297
+ );
298
+ return;
299
+ }
300
+ addRemovable(
301
+ removableFiles,
302
+ record,
303
+ createReason(
304
+ "instruction-content-match",
305
+ "The instruction file's managed block matches the manifest and no user content exists outside the block."
306
+ ),
307
+ currentBlockHash,
308
+ record.manifestHash
309
+ );
310
+ return;
311
+ }
312
+ if (record.manifestHash && currentHash === record.manifestHash) {
313
+ addRemovable(
314
+ removableFiles,
315
+ record,
316
+ createReason(
317
+ "instruction-content-match",
318
+ "The legacy instruction file still matches the manifest-tracked make-docs content."
319
+ ),
320
+ currentHash,
321
+ record.manifestHash
322
+ );
323
+ return;
324
+ }
325
+ addPreserved(
326
+ preservedPaths,
327
+ record,
328
+ createReason(
329
+ "instruction-content-mismatch",
330
+ "The instruction file does not match manifest-tracked make-docs content and will be preserved."
331
+ )
332
+ );
333
+ return;
334
+ }
335
+ if (record.manifestHash && currentHash === record.manifestHash) {
336
+ addRemovable(
337
+ removableFiles,
338
+ record,
339
+ createReason(
340
+ "managed-file-hash-match",
341
+ "The file still matches the manifest-tracked make-docs content."
342
+ ),
343
+ currentHash,
344
+ record.manifestHash
345
+ );
346
+ return;
347
+ }
348
+ if (record.ownershipSource === "manifest-skill-file") {
349
+ const expectedContent = manifestSkillContentByPath?.get(record.path);
350
+ if (!expectedContent) {
351
+ addPreserved(
352
+ preservedPaths,
353
+ record,
354
+ createReason(
355
+ "manifest-skill-file-without-metadata",
356
+ `The ${formatAuditAgenticRole(record)} is tracked only by the manifest skill list and cannot be proven removable without canonical make-docs content.`
357
+ )
358
+ );
359
+ return;
360
+ }
361
+ if (contentEquals(currentBytes, expectedContent)) {
362
+ addRemovable(
363
+ removableFiles,
364
+ record,
365
+ createReason(
366
+ "managed-skill-file-content-match",
367
+ `The ${formatAuditAgenticRole(record)} exactly matches canonical make-docs skill content.`
368
+ ),
369
+ currentHash,
370
+ hashText(expectedContent)
371
+ );
372
+ return;
373
+ }
374
+ addPreserved(
375
+ preservedPaths,
376
+ record,
377
+ createReason(
378
+ "manifest-skill-file-content-mismatch",
379
+ `The manifest-tracked ${formatAuditAgenticRole(record)} does not match canonical make-docs skill content and will be preserved.`
380
+ )
381
+ );
382
+ return;
383
+ }
384
+ addPreserved(
385
+ preservedPaths,
386
+ record,
387
+ createReason(
388
+ "managed-file-modified",
389
+ "The manifest-tracked file was modified locally and will be preserved."
390
+ )
391
+ );
392
+ }
393
+ function classifyManifestSkillExposureRecord(options) {
394
+ const { targetDir, record, manifestSkillContentByPath, removableFiles, preservedPaths } = options;
395
+ const stats = lstatSync(record.absolutePath);
396
+ if (stats.isSymbolicLink()) {
397
+ const currentTarget = path2.resolve(
398
+ path2.dirname(record.absolutePath),
399
+ readlinkSync(record.absolutePath)
400
+ );
401
+ const expectedTarget = relativePathToTarget(
402
+ targetDir,
403
+ record.skillExposure?.canonicalPayloadPath ?? ""
404
+ );
405
+ if (path2.resolve(currentTarget) === path2.resolve(expectedTarget)) {
406
+ addRemovable(
407
+ removableFiles,
408
+ record,
409
+ createReason(
410
+ "managed-skill-exposure-symlink-match",
411
+ "The managed native harness exposure symlink points at the recorded canonical skill payload."
412
+ ),
413
+ hashText(readlinkSync(record.absolutePath)),
414
+ record.manifestHash
415
+ );
416
+ return;
417
+ }
418
+ }
419
+ if (stats.isDirectory() && manifestSkillContentByPath && copyMirrorMatchesCanonicalContent(record, targetDir, manifestSkillContentByPath)) {
420
+ addRemovable(
421
+ removableFiles,
422
+ record,
423
+ createReason(
424
+ "managed-skill-exposure-copy-mirror-match",
425
+ "The managed copy-mirror exposure exactly matches canonical make-docs skill content."
426
+ ),
427
+ void 0,
428
+ record.manifestHash
429
+ );
430
+ return;
431
+ }
432
+ addPreserved(
433
+ preservedPaths,
434
+ record,
435
+ createReason(
436
+ "manifest-skill-exposure-mismatch",
437
+ "The manifest-tracked native skill exposure does not match its recorded symlink target or canonical copy-mirror content and will be preserved."
438
+ )
439
+ );
440
+ }
441
+ function classifyPackagingSkillExposureRecord(options) {
442
+ const { targetDir, record, removableFiles, preservedPaths } = options;
443
+ const stats = lstatSync(record.absolutePath);
444
+ if (stats.isSymbolicLink()) {
445
+ const currentTarget = path2.resolve(
446
+ path2.dirname(record.absolutePath),
447
+ readlinkSync(record.absolutePath)
448
+ );
449
+ const expectedTarget = relativePathToTarget(
450
+ targetDir,
451
+ record.agenticOwnership?.canonicalPayloadPath ?? ""
452
+ );
453
+ if (path2.resolve(currentTarget) === path2.resolve(expectedTarget)) {
454
+ addRemovable(
455
+ removableFiles,
456
+ record,
457
+ createReason(
458
+ "managed-skill-exposure-symlink-match",
459
+ "The managed skills-bundle exposure symlink points at the recorded canonical package payload."
460
+ ),
461
+ hashText(readlinkSync(record.absolutePath)),
462
+ record.manifestHash
463
+ );
464
+ return;
465
+ }
466
+ }
467
+ addPreserved(
468
+ preservedPaths,
469
+ record,
470
+ createReason(
471
+ "manifest-skill-exposure-mismatch",
472
+ "The manifest-tracked skills-bundle exposure does not match its recorded symlink target and will be preserved."
473
+ )
474
+ );
475
+ }
476
+ function classifyManifestPluginOwnershipRecord(options) {
477
+ const { targetDir, record, manifestRecordByPath, removableFiles, preservedPaths } = options;
478
+ const ownership = record.agenticOwnership;
479
+ if (!ownership || ownership.artifactKind !== "plugin") {
480
+ return;
481
+ }
482
+ const symlinkExposureAncestor = findPluginSymlinkExposureAncestor(
483
+ record,
484
+ manifestRecordByPath
485
+ );
486
+ if (symlinkExposureAncestor && symlinkExposureAncestor.path !== record.path) {
487
+ addPreserved(
488
+ preservedPaths,
489
+ record,
490
+ createReason(
491
+ "manifest-plugin-exposure-mismatch",
492
+ "The plugin copy-mirror record is nested under a native exposure symlink and will be preserved for review instead of being removed through the symlink."
493
+ )
494
+ );
495
+ return;
496
+ }
497
+ if (ownership.role === "plugin-native-exposure") {
498
+ classifyManifestPluginExposureRecord({
499
+ targetDir,
500
+ record,
501
+ manifestRecordByPath,
502
+ removableFiles,
503
+ preservedPaths
504
+ });
505
+ return;
506
+ }
507
+ if (!lstatSync(record.absolutePath).isFile()) {
508
+ addPreserved(
509
+ preservedPaths,
510
+ record,
511
+ createReason(
512
+ "manifest-plugin-file-content-mismatch",
513
+ `The manifest-tracked ${formatAuditAgenticRole(record)} is no longer a regular file and will be preserved.`
514
+ )
515
+ );
516
+ return;
517
+ }
518
+ const currentBytes = readFileSync(record.absolutePath);
519
+ const currentHash = hashText(currentBytes);
520
+ if (record.manifestHash && currentHash === record.manifestHash) {
521
+ addRemovable(
522
+ removableFiles,
523
+ record,
524
+ createReason(
525
+ "managed-plugin-file-content-match",
526
+ `The ${formatAuditAgenticRole(record)} still matches manifest-tracked make-docs plugin content.`
527
+ ),
528
+ currentHash,
529
+ record.manifestHash
530
+ );
531
+ return;
532
+ }
533
+ addPreserved(
534
+ preservedPaths,
535
+ record,
536
+ createReason(
537
+ "manifest-plugin-file-content-mismatch",
538
+ `The manifest-tracked ${formatAuditAgenticRole(record)} was modified locally and will be preserved.`
539
+ )
540
+ );
541
+ }
542
+ function classifyManifestPluginExposureRecord(options) {
543
+ const { targetDir, record, manifestRecordByPath, removableFiles, preservedPaths } = options;
544
+ const ownership = record.agenticOwnership;
545
+ const stats = lstatSync(record.absolutePath);
546
+ if (stats.isSymbolicLink()) {
547
+ const currentTarget = path2.resolve(
548
+ path2.dirname(record.absolutePath),
549
+ readlinkSync(record.absolutePath)
550
+ );
551
+ const expectedTarget = relativePathToTarget(
552
+ targetDir,
553
+ ownership?.canonicalPayloadPath ?? ""
554
+ );
555
+ if (path2.resolve(currentTarget) === path2.resolve(expectedTarget)) {
556
+ addRemovable(
557
+ removableFiles,
558
+ record,
559
+ createReason(
560
+ "managed-plugin-exposure-symlink-match",
561
+ "The managed plugin native harness exposure symlink points at the recorded canonical plugin payload."
562
+ ),
563
+ hashText(readlinkSync(record.absolutePath)),
564
+ record.manifestHash
565
+ );
566
+ return;
567
+ }
568
+ }
569
+ if (stats.isDirectory() && pluginCopyMirrorMatchesManifestRecords(record, targetDir, manifestRecordByPath)) {
570
+ addRemovable(
571
+ removableFiles,
572
+ record,
573
+ createReason(
574
+ "managed-plugin-exposure-copy-mirror-match",
575
+ "The managed plugin copy-mirror exposure exactly matches manifest-tracked plugin payload content."
576
+ ),
577
+ void 0,
578
+ record.manifestHash
579
+ );
580
+ return;
581
+ }
582
+ addPreserved(
583
+ preservedPaths,
584
+ record,
585
+ createReason(
586
+ "manifest-plugin-exposure-mismatch",
587
+ "The manifest-tracked plugin exposure does not match its recorded symlink target or manifest-tracked copy-mirror content and will be preserved."
588
+ )
589
+ );
590
+ }
591
+ async function classifyManifestMissing(options) {
592
+ const { targetDir, homeDir, removableFiles, preservedPaths, skippedPaths } = options;
593
+ const fallbackSelections = defaultSelections();
594
+ const fallbackProfile = resolveInstallProfile(fallbackSelections);
595
+ const fallbackCandidates = /* @__PURE__ */ new Map();
596
+ const canonicalContentByPath = /* @__PURE__ */ new Map();
597
+ for (const asset of getDesiredAssets(fallbackProfile)) {
598
+ const record = createManagedPathRecord(targetDir, homeDir, asset.relativePath, "fallback", {
599
+ sourceId: asset.sourceId
600
+ });
601
+ fallbackCandidates.set(record.absolutePath, record);
602
+ canonicalContentByPath.set(record.path, asset.content);
603
+ }
604
+ const knownAgenticsRoots = getKnownAgenticsRoots(targetDir, homeDir);
605
+ const existingAgenticsRoots = knownAgenticsRoots.filter(
606
+ (root) => existsSync(root.absolutePath)
607
+ );
608
+ const existingSkillRoots = existingAgenticsRoots.filter(
609
+ (root) => root.agenticKind === "skill"
610
+ );
611
+ const scopeRootFetchFailures = /* @__PURE__ */ new Set();
612
+ if (existingSkillRoots.some((root) => root.pathScope === "project")) {
613
+ const skillRecords = await loadFallbackSkillCandidates({
614
+ targetDir,
615
+ homeDir,
616
+ selections: {
617
+ ...fallbackSelections,
618
+ skillScope: "project"
619
+ }
620
+ });
621
+ if (skillRecords) {
622
+ for (const record of skillRecords) {
623
+ fallbackCandidates.set(record.record.absolutePath, record.record);
624
+ canonicalContentByPath.set(record.record.path, record.content);
625
+ }
626
+ } else {
627
+ scopeRootFetchFailures.add("project");
628
+ }
629
+ }
630
+ if (existingSkillRoots.some((root) => root.pathScope === "home")) {
631
+ const skillRecords = await loadFallbackSkillCandidates({
632
+ targetDir,
633
+ homeDir,
634
+ selections: {
635
+ ...fallbackSelections,
636
+ skillScope: "global"
637
+ }
638
+ });
639
+ if (skillRecords) {
640
+ for (const record of skillRecords) {
641
+ fallbackCandidates.set(record.record.absolutePath, record.record);
642
+ canonicalContentByPath.set(record.record.path, record.content);
643
+ }
644
+ } else {
645
+ scopeRootFetchFailures.add("home");
646
+ }
647
+ }
648
+ for (const record of sortAuditEntries([...fallbackCandidates.values()])) {
649
+ classifyFallbackRecord({
650
+ targetDir,
651
+ record,
652
+ canonicalContentByPath,
653
+ removableFiles,
654
+ preservedPaths,
655
+ skippedPaths
656
+ });
657
+ }
658
+ for (const agenticsRoot of existingAgenticsRoots) {
659
+ const hasExistingManagedCandidateDescendant = [...fallbackCandidates.values()].some(
660
+ (record) => existsSync(record.absolutePath) && isWithinRoot2(agenticsRoot.absolutePath, record.absolutePath)
661
+ );
662
+ if (agenticsRoot.agenticKind === "skill" && scopeRootFetchFailures.has(agenticsRoot.pathScope) || !hasExistingManagedCandidateDescendant) {
663
+ addPreserved(
664
+ preservedPaths,
665
+ agenticsRoot,
666
+ createReason(
667
+ "fallback-ambiguous",
668
+ "The selected-agentics root exists, but fallback mode cannot prove which contents are make-docs-managed."
669
+ )
670
+ );
671
+ }
672
+ }
673
+ }
674
+ function classifyFallbackRecord(options) {
675
+ const {
676
+ targetDir,
677
+ record,
678
+ canonicalContentByPath,
679
+ removableFiles,
680
+ preservedPaths,
681
+ skippedPaths
682
+ } = options;
683
+ if (isInsideProjectBackupRoot(targetDir, record.absolutePath)) {
684
+ addSkipped(
685
+ skippedPaths,
686
+ record,
687
+ "excluded",
688
+ createReason(
689
+ "inside-backup-root",
690
+ "Paths inside project backup state trees are excluded from removal consideration."
691
+ )
692
+ );
693
+ return;
694
+ }
695
+ if (record.pathScope === "external") {
696
+ addSkipped(
697
+ skippedPaths,
698
+ record,
699
+ "excluded",
700
+ createReason(
701
+ "outside-supported-roots",
702
+ "This path is outside both the target directory and the user home directory and cannot be removed in fallback mode."
703
+ )
704
+ );
705
+ return;
706
+ }
707
+ if (!existsSync(record.absolutePath)) {
708
+ addSkipped(
709
+ skippedPaths,
710
+ record,
711
+ "already-absent",
712
+ createReason("already-absent", "The candidate path is already absent on disk.")
713
+ );
714
+ return;
715
+ }
716
+ if (!lstatSync(record.absolutePath).isFile()) {
717
+ addPreserved(
718
+ preservedPaths,
719
+ record,
720
+ createReason(
721
+ "fallback-ambiguous",
722
+ "Fallback mode found a non-file at an expected make-docs-managed file path and will preserve it."
723
+ )
724
+ );
725
+ return;
726
+ }
727
+ const currentBytes = readFileSync(record.absolutePath);
728
+ const currentHash = hashText(currentBytes);
729
+ if (record.ownershipSource === "managed-state") {
730
+ if (looksLikeMakeDocsManifest(record.absolutePath)) {
731
+ addRemovable(
732
+ removableFiles,
733
+ record,
734
+ createReason(
735
+ "managed-state-file",
736
+ "The make-docs manifest matches the generated manifest shape and is eligible for removal."
737
+ ),
738
+ currentHash,
739
+ void 0
740
+ );
741
+ } else {
742
+ addPreserved(
743
+ preservedPaths,
744
+ record,
745
+ createReason(
746
+ "fallback-ambiguous",
747
+ "Fallback mode found make-docs state at the expected path, but its contents do not match the generated manifest shape."
748
+ )
749
+ );
750
+ }
751
+ return;
752
+ }
753
+ if (isInstructionPath(record.path)) {
754
+ const currentContent = currentBytes.toString("utf8");
755
+ const expectedContent2 = canonicalContentByPath.get(record.path);
756
+ const currentBlockHash = getManifestFileHash(record.path, currentContent);
757
+ const expectedBlockHash = typeof expectedContent2 === "string" ? getManifestFileHash(record.path, expectedContent2) : null;
758
+ const parsed = parseManagedBlock(currentContent);
759
+ const blockOnly = parsed.state === "valid" && parsed.prefix.trim().length === 0 && parsed.suffix.trim().length === 0;
760
+ if (typeof expectedContent2 === "string" && (currentContent === expectedContent2 || blockOnly && currentBlockHash && currentBlockHash === expectedBlockHash)) {
761
+ addRemovable(
762
+ removableFiles,
763
+ record,
764
+ createReason(
765
+ "fallback-root-fingerprint-match",
766
+ "The instruction file matches canonical make-docs content in fallback mode."
767
+ ),
768
+ currentHash,
769
+ expectedBlockHash ?? hashText(expectedContent2)
770
+ );
771
+ return;
772
+ }
773
+ addPreserved(
774
+ preservedPaths,
775
+ record,
776
+ createReason(
777
+ "fallback-root-fingerprint-mismatch",
778
+ "The instruction file does not match canonical make-docs content and will be preserved."
779
+ )
780
+ );
781
+ return;
782
+ }
783
+ const expectedContent = canonicalContentByPath.get(record.path);
784
+ if (expectedContent !== void 0 && contentEquals(currentBytes, expectedContent)) {
785
+ addRemovable(
786
+ removableFiles,
787
+ record,
788
+ createReason(
789
+ "fallback-canonical-content-match",
790
+ "The file exactly matches canonical make-docs content in fallback mode."
791
+ ),
792
+ currentHash,
793
+ hashText(expectedContent)
794
+ );
795
+ return;
796
+ }
797
+ addPreserved(
798
+ preservedPaths,
799
+ record,
800
+ createReason(
801
+ "fallback-ambiguous",
802
+ "Fallback mode cannot prove that this existing path is safe to remove."
803
+ )
804
+ );
805
+ }
806
+ function classifyPrunableDirectories(options) {
807
+ const { targetDir, homeDir, removableFiles, preservedPaths, skippedPaths } = options;
808
+ const removableFileSet = new Set(removableFiles.map((entry) => entry.absolutePath));
809
+ const prunableDirectories = /* @__PURE__ */ new Map();
810
+ const removableDescendantsByDirectory = /* @__PURE__ */ new Map();
811
+ for (const removableFile of removableFiles) {
812
+ const boundary = removableFile.pathScope === "project" ? targetDir : removableFile.pathScope === "home" ? homeDir : null;
813
+ if (!boundary) {
814
+ continue;
815
+ }
816
+ for (const directoryPath of getCandidateParentDirectories(
817
+ removableFile.absolutePath,
818
+ boundary,
819
+ targetDir
820
+ )) {
821
+ if (!removableDescendantsByDirectory.has(directoryPath)) {
822
+ removableDescendantsByDirectory.set(directoryPath, /* @__PURE__ */ new Set());
823
+ }
824
+ removableDescendantsByDirectory.get(directoryPath)?.add(removableFile.path);
825
+ }
826
+ }
827
+ const sortedDirectoryCandidates = [...removableDescendantsByDirectory.keys()].sort(
828
+ (left, right) => createAuditPathMetadata(targetDir, left, "directory", homeDir).ordering.pruneSortKey.localeCompare(
829
+ createAuditPathMetadata(targetDir, right, "directory", homeDir).ordering.pruneSortKey
830
+ )
831
+ );
832
+ for (const directoryPath of sortedDirectoryCandidates) {
833
+ if (!existsSync(directoryPath)) {
834
+ continue;
835
+ }
836
+ const metadata = createAuditPathMetadata(targetDir, directoryPath, "directory", homeDir);
837
+ const remainingEntries = getRemainingDirectoryEntries(
838
+ directoryPath,
839
+ removableFileSet,
840
+ prunableDirectories
841
+ );
842
+ if (remainingEntries.length === 0) {
843
+ const pruneReason = createReason(
844
+ "directory-eligible-for-prune",
845
+ "The directory becomes empty after removing audited make-docs-managed descendants."
846
+ );
847
+ prunableDirectories.set(directoryPath, {
848
+ ...metadata,
849
+ kind: "directory",
850
+ reason: pruneReason.message,
851
+ reasonCode: pruneReason.code,
852
+ removableDescendantPaths: [...removableDescendantsByDirectory.get(directoryPath) ?? []].sort(),
853
+ preservedDescendantPaths: []
854
+ });
855
+ continue;
856
+ }
857
+ const preservedDescendantPaths = describeBlockingDescendants(
858
+ targetDir,
859
+ homeDir,
860
+ remainingEntries,
861
+ preservedPaths,
862
+ skippedPaths
863
+ );
864
+ addPreserved(
865
+ preservedPaths,
866
+ metadata,
867
+ createReason(
868
+ preservedDescendantPaths.length > 0 ? "directory-contains-preserved-descendants" : "directory-contains-unmanaged-descendants",
869
+ preservedDescendantPaths.length > 0 ? "The directory still contains preserved descendants after subtracting removable make-docs paths." : "The directory still contains unmanaged descendants after subtracting removable make-docs paths."
870
+ ),
871
+ preservedDescendantPaths
872
+ );
873
+ }
874
+ return [...prunableDirectories.values()];
875
+ }
876
+ function getRemainingDirectoryEntries(directoryPath, removableFileSet, prunableDirectories) {
877
+ return readdirSync(directoryPath).map((entry) => path2.join(directoryPath, entry)).filter((entryPath) => !removableFileSet.has(entryPath) && !prunableDirectories.has(entryPath));
878
+ }
879
+ function copyMirrorMatchesCanonicalContent(record, targetDir, canonicalContentByPath) {
880
+ const expectedEntries = [...canonicalContentByPath.entries()].filter(
881
+ ([candidate]) => isDescendantAuditPath(candidate, record.path)
882
+ );
883
+ if (expectedEntries.length === 0) {
884
+ return false;
885
+ }
886
+ const expectedContentByPath = new Map(expectedEntries);
887
+ const existingFiles = listDescendantFilePaths(record.absolutePath).map(
888
+ (filePath) => normalizeAuditPath(path2.relative(targetDir, filePath))
889
+ );
890
+ if (existingFiles.length !== expectedContentByPath.size) {
891
+ return false;
892
+ }
893
+ return existingFiles.every((relativePath) => {
894
+ const expectedContent = expectedContentByPath.get(relativePath);
895
+ return expectedContent !== void 0 && contentEquals(readFileSync(relativePathToTarget(targetDir, relativePath)), expectedContent);
896
+ });
897
+ }
898
+ function pluginCopyMirrorMatchesManifestRecords(record, targetDir, manifestRecordByPath) {
899
+ const expectedEntries = [...manifestRecordByPath.values()].filter(
900
+ (candidate) => candidate.agenticOwnership?.artifactKind === "plugin" && candidate.agenticOwnership.role === "plugin-copy-mirror" && isDescendantAuditPath(candidate.path, record.path)
901
+ );
902
+ if (expectedEntries.length === 0) {
903
+ return false;
904
+ }
905
+ const expectedRecordsByPath = new Map(
906
+ expectedEntries.map((candidate) => [candidate.path, candidate])
907
+ );
908
+ const existingFiles = listDescendantFilePaths(record.absolutePath).map(
909
+ (filePath) => normalizeAuditPath(path2.relative(targetDir, filePath))
910
+ );
911
+ if (existingFiles.length !== expectedRecordsByPath.size) {
912
+ return false;
913
+ }
914
+ return existingFiles.every((relativePath) => {
915
+ const expectedRecord = expectedRecordsByPath.get(relativePath);
916
+ return expectedRecord?.manifestHash !== void 0 && hashText(readTextFile(relativePathToTarget(targetDir, relativePath))) === expectedRecord.manifestHash;
917
+ });
918
+ }
919
+ function findPluginSymlinkExposureAncestor(record, manifestRecordByPath) {
920
+ for (const candidate of manifestRecordByPath.values()) {
921
+ if (candidate.path === record.path || candidate.agenticOwnership?.artifactKind !== "plugin" || candidate.agenticOwnership.role !== "plugin-native-exposure" || !isDescendantAuditPath(record.path, candidate.path) || !existsSync(candidate.absolutePath)) {
922
+ continue;
923
+ }
924
+ try {
925
+ if (lstatSync(candidate.absolutePath).isSymbolicLink()) {
926
+ return candidate;
927
+ }
928
+ } catch {
929
+ continue;
930
+ }
931
+ }
932
+ return null;
933
+ }
934
+ function listDescendantFilePaths(root) {
935
+ return readdirSync(root, { withFileTypes: true }).flatMap((entry) => {
936
+ const entryPath = path2.join(root, entry.name);
937
+ if (entry.isDirectory()) {
938
+ return listDescendantFilePaths(entryPath);
939
+ }
940
+ if (entry.isFile()) {
941
+ return [entryPath];
942
+ }
943
+ return [];
944
+ });
945
+ }
946
+ function isDescendantAuditPath(candidate, possibleAncestor) {
947
+ return normalizeAuditPath(candidate).startsWith(`${normalizeAuditPath(possibleAncestor)}/`);
948
+ }
949
+ function normalizeAuditPath(relativePath) {
950
+ return relativePath.replace(/\\/g, "/");
951
+ }
952
+ function describeBlockingDescendants(targetDir, homeDir, entryPaths, preservedPaths, skippedPaths) {
953
+ const described = /* @__PURE__ */ new Set();
954
+ for (const entryPath of entryPaths) {
955
+ const preserved = findRecordedDescendant(entryPath, preservedPaths);
956
+ if (preserved) {
957
+ described.add(preserved.path);
958
+ continue;
959
+ }
960
+ const skipped = findRecordedDescendant(entryPath, skippedPaths);
961
+ if (skipped) {
962
+ described.add(skipped.path);
963
+ continue;
964
+ }
965
+ described.add(
966
+ createAuditPathMetadata(targetDir, entryPath, getExistingPathKind(entryPath), homeDir).path
967
+ );
968
+ }
969
+ return [...described].sort();
970
+ }
971
+ function findRecordedDescendant(rootPath, records) {
972
+ for (const record of records.values()) {
973
+ if (isWithinRoot2(rootPath, record.absolutePath)) {
974
+ return record;
975
+ }
976
+ }
977
+ return null;
978
+ }
979
+ function getCandidateParentDirectories(absoluteFilePath, boundary, targetDir) {
980
+ const directories = [];
981
+ let current = path2.dirname(absoluteFilePath);
982
+ const normalizedBoundary = path2.resolve(boundary);
983
+ while (current !== normalizedBoundary && isWithinRoot2(normalizedBoundary, current)) {
984
+ if (isInsideProjectBackupRoot(targetDir, current)) {
985
+ break;
986
+ }
987
+ directories.push(current);
988
+ current = path2.dirname(current);
989
+ }
990
+ return directories;
991
+ }
992
+ function classifyProjectConfig(options) {
993
+ const { targetDir, homeDir, preservedPaths } = options;
994
+ const absolutePath = path2.join(targetDir, TOOL_DIRECTORY_CONFIG_RELATIVE_PATH);
995
+ if (!existsSync(absolutePath)) {
996
+ return;
997
+ }
998
+ addPreserved(
999
+ preservedPaths,
1000
+ createCandidatePathRecord(
1001
+ targetDir,
1002
+ homeDir,
1003
+ TOOL_DIRECTORY_CONFIG_RELATIVE_PATH,
1004
+ getExistingPathKind(absolutePath),
1005
+ "project-config"
1006
+ ),
1007
+ createReason(
1008
+ "project-config-preserved",
1009
+ "The make-docs config file is project-owned local configuration and is preserved separately from managed files, conflicts, provider state, and cache state."
1010
+ )
1011
+ );
1012
+ }
1013
+ async function loadCanonicalSkillContentByPath(targetDir, homeDir, selections, shouldLoad) {
1014
+ if (!shouldLoad) {
1015
+ return /* @__PURE__ */ new Map();
1016
+ }
1017
+ try {
1018
+ const skillRegistry = loadSavedSkillRegistry(selections);
1019
+ const [assets, retiredAssets] = await Promise.all([
1020
+ getDesiredSkillAssets(selections, skillRegistry),
1021
+ getRetiredManagedSkillAssets(selections, skillRegistry)
1022
+ ]);
1023
+ return new Map(
1024
+ [...assets, ...retiredAssets].flatMap(
1025
+ (asset) => asset.kind === "skill-exposure" ? asset.copyMirrorAssets : [asset]
1026
+ ).map((asset) => {
1027
+ const record = createManagedPathRecord(
1028
+ targetDir,
1029
+ homeDir,
1030
+ asset.relativePath,
1031
+ "manifest-skill-file",
1032
+ { sourceId: asset.sourceId }
1033
+ );
1034
+ return [record.path, asset.content];
1035
+ })
1036
+ );
1037
+ } catch {
1038
+ return null;
1039
+ }
1040
+ }
1041
+ function createSkillSelectionReview(selections) {
1042
+ return {
1043
+ skillsEnabled: selections.skills,
1044
+ skillScope: selections.skillScope,
1045
+ selectedSkills: [...selections.selectedSkills].sort(),
1046
+ ...selections.skillManifest ? { skillManifest: structuredClone(selections.skillManifest) } : {},
1047
+ skillSelectionProvenance: [
1048
+ ...selections.skillSelectionProvenance ?? []
1049
+ ].sort((left, right) => left.skillName.localeCompare(right.skillName))
1050
+ };
1051
+ }
1052
+ function createPluginSelectionReview(selections) {
1053
+ return {
1054
+ pluginsEnabled: selections.plugins,
1055
+ pluginScope: selections.pluginScope,
1056
+ selectedPlugins: [...selections.selectedPlugins].sort(),
1057
+ ...selections.pluginManifest ? { pluginManifest: structuredClone(selections.pluginManifest) } : {},
1058
+ pluginSelectionProvenance: [
1059
+ ...selections.pluginSelectionProvenance ?? []
1060
+ ].sort((left, right) => left.pluginId.localeCompare(right.pluginId))
1061
+ };
1062
+ }
1063
+ function loadSavedSkillRegistry(selections) {
1064
+ const savedManifest = selections.skillManifest;
1065
+ if (!savedManifest || savedManifest.source === "built-in") {
1066
+ return loadSkillRegistry(PACKAGE_ROOT);
1067
+ }
1068
+ if (savedManifest.source === "file" && savedManifest.path) {
1069
+ return loadEffectiveSkillRegistry({
1070
+ packageRoot: PACKAGE_ROOT,
1071
+ manifestReference: savedManifest.path
1072
+ }).registry;
1073
+ }
1074
+ throw new Error(
1075
+ "Saved remote-pinned skill manifests require explicit migration review before lifecycle audit expansion."
1076
+ );
1077
+ }
1078
+ async function loadFallbackSkillCandidates(options) {
1079
+ try {
1080
+ const assets = await getDesiredSkillAssets(options.selections);
1081
+ return assets.flatMap(
1082
+ (asset) => (asset.kind === "skill-exposure" ? asset.copyMirrorAssets : [asset]).map(
1083
+ (resolvedAsset) => ({
1084
+ record: createManagedPathRecord(
1085
+ options.targetDir,
1086
+ options.homeDir,
1087
+ resolvedAsset.relativePath,
1088
+ "fallback",
1089
+ { sourceId: resolvedAsset.sourceId }
1090
+ ),
1091
+ content: resolvedAsset.content
1092
+ })
1093
+ )
1094
+ );
1095
+ } catch {
1096
+ return null;
1097
+ }
1098
+ }
1099
+ function getKnownAgenticsRoots(targetDir, homeDir) {
1100
+ return [
1101
+ {
1102
+ ...createCandidatePathRecord(
1103
+ targetDir,
1104
+ homeDir,
1105
+ path2.join(targetDir, SHARED_AGENTICS_SKILL_DIR),
1106
+ "directory",
1107
+ "fallback"
1108
+ ),
1109
+ pathScope: "project",
1110
+ agenticKind: "skill"
1111
+ },
1112
+ {
1113
+ ...createCandidatePathRecord(
1114
+ targetDir,
1115
+ homeDir,
1116
+ path2.join(homeDir, SHARED_AGENTICS_SKILL_DIR),
1117
+ "directory",
1118
+ "fallback"
1119
+ ),
1120
+ pathScope: "home",
1121
+ agenticKind: "skill"
1122
+ },
1123
+ {
1124
+ ...createCandidatePathRecord(
1125
+ targetDir,
1126
+ homeDir,
1127
+ path2.join(targetDir, SHARED_AGENTICS_PLUGIN_DIR),
1128
+ "directory",
1129
+ "fallback"
1130
+ ),
1131
+ pathScope: "project",
1132
+ agenticKind: "plugin"
1133
+ },
1134
+ {
1135
+ ...createCandidatePathRecord(
1136
+ targetDir,
1137
+ homeDir,
1138
+ path2.join(homeDir, SHARED_AGENTICS_PLUGIN_DIR),
1139
+ "directory",
1140
+ "fallback"
1141
+ ),
1142
+ pathScope: "home",
1143
+ agenticKind: "plugin"
1144
+ },
1145
+ {
1146
+ ...createCandidatePathRecord(targetDir, homeDir, path2.join(homeDir, ".agents/skills"), "directory", "fallback"),
1147
+ pathScope: "home",
1148
+ agenticKind: "skill"
1149
+ },
1150
+ ...HARNESSES.flatMap((harness) => [
1151
+ {
1152
+ ...createCandidatePathRecord(
1153
+ targetDir,
1154
+ homeDir,
1155
+ path2.join(targetDir, HARNESS_SKILL_DIRS[harness]),
1156
+ "directory",
1157
+ "fallback"
1158
+ ),
1159
+ pathScope: "project",
1160
+ agenticKind: "skill"
1161
+ },
1162
+ {
1163
+ ...createCandidatePathRecord(
1164
+ targetDir,
1165
+ homeDir,
1166
+ getHarnessSkillDirectory(harness, "global", homeDir),
1167
+ "directory",
1168
+ "fallback"
1169
+ ),
1170
+ pathScope: "home",
1171
+ agenticKind: "skill"
1172
+ },
1173
+ {
1174
+ ...createCandidatePathRecord(
1175
+ targetDir,
1176
+ homeDir,
1177
+ path2.join(targetDir, HARNESS_PLUGIN_DIRS[harness]),
1178
+ "directory",
1179
+ "fallback"
1180
+ ),
1181
+ pathScope: "project",
1182
+ agenticKind: "plugin"
1183
+ },
1184
+ {
1185
+ ...createCandidatePathRecord(
1186
+ targetDir,
1187
+ homeDir,
1188
+ path2.join(homeDir, HARNESS_PLUGIN_DIRS[harness]),
1189
+ "directory",
1190
+ "fallback"
1191
+ ),
1192
+ pathScope: "home",
1193
+ agenticKind: "plugin"
1194
+ }
1195
+ ])
1196
+ ];
1197
+ }
1198
+ function createManagedPathRecord(targetDir, homeDir, auditPath, ownershipSource, options) {
1199
+ const agenticRole = classifyAgenticFileRole({
1200
+ relativePath: auditPath,
1201
+ sourceId: options?.sourceId
1202
+ });
1203
+ const kind = options?.skillExposure ? "directory" : "file";
1204
+ return {
1205
+ ...createAuditPathMetadata(targetDir, auditPath, kind, homeDir),
1206
+ ownershipSource,
1207
+ sourceId: options?.sourceId,
1208
+ manifestHash: options?.manifestHash,
1209
+ skillExposure: options?.skillExposure,
1210
+ ...agenticRole ? { agenticRole } : {}
1211
+ };
1212
+ }
1213
+ function createCandidatePathRecord(targetDir, homeDir, auditPath, kind, ownershipSource) {
1214
+ const agenticRole = classifyAgenticFileRole({ relativePath: auditPath });
1215
+ return {
1216
+ ...createAuditPathMetadata(targetDir, auditPath, kind, homeDir),
1217
+ ownershipSource,
1218
+ ...agenticRole ? { agenticRole } : {}
1219
+ };
1220
+ }
1221
+ function addRemovable(removableFiles, record, reason, currentHash, expectedHash) {
1222
+ removableFiles.set(record.absolutePath, {
1223
+ ...record,
1224
+ kind: record.kind === "directory" ? "directory" : "file",
1225
+ reason: reason.message,
1226
+ reasonCode: reason.code,
1227
+ currentHash,
1228
+ expectedHash
1229
+ });
1230
+ }
1231
+ function addPreserved(preservedPaths, record, reason, preservedDescendantPaths) {
1232
+ preservedPaths.set(record.absolutePath, {
1233
+ ...record,
1234
+ reason: reason.message,
1235
+ reasonCode: reason.code,
1236
+ preservedDescendantPaths
1237
+ });
1238
+ }
1239
+ function addSkipped(skippedPaths, record, status, reason) {
1240
+ skippedPaths.set(record.absolutePath, {
1241
+ ...record,
1242
+ reason: reason.message,
1243
+ reasonCode: reason.code,
1244
+ status
1245
+ });
1246
+ }
1247
+ function createReason(code, message) {
1248
+ return { code, message };
1249
+ }
1250
+ function formatAuditAgenticRole(record) {
1251
+ return formatAgenticFileRole(record.agenticRole) ?? "agentic file";
1252
+ }
1253
+ function isInstructionPath(auditPath) {
1254
+ return isInstructionManifestPath(auditPath);
1255
+ }
1256
+ function isInsideProjectBackupRoot(targetDir, absolutePath) {
1257
+ return isInsideProjectBackupStateRoot(targetDir, absolutePath);
1258
+ }
1259
+ function isWithinRoot2(rootPath, candidatePath) {
1260
+ const relative = path2.relative(path2.resolve(rootPath), path2.resolve(candidatePath));
1261
+ return relative === "" || !relative.startsWith("..") && !path2.isAbsolute(relative);
1262
+ }
1263
+ function getExistingPathKind(absolutePath) {
1264
+ return lstatSync(absolutePath).isDirectory() ? "directory" : "file";
1265
+ }
1266
+ function looksLikeMakeDocsManifest(filePath) {
1267
+ try {
1268
+ const raw = JSON.parse(readTextFile(filePath));
1269
+ return typeof raw.schemaVersion === "number" && typeof raw.packageName === "string" && typeof raw.packageVersion === "string" && typeof raw.profileId === "string" && typeof raw.updatedAt === "string" && typeof raw.selections === "object" && raw.selections !== null && typeof raw.files === "object" && raw.files !== null;
1270
+ } catch {
1271
+ return false;
1272
+ }
1273
+ }
1274
+ function sortAuditEntries(entries) {
1275
+ return [...entries].sort(
1276
+ (left, right) => left.ordering.sortKey.localeCompare(right.ordering.sortKey)
1277
+ );
1278
+ }
1279
+ function sortPrunableDirectories(entries) {
1280
+ return [...entries].sort(
1281
+ (left, right) => left.ordering.pruneSortKey.localeCompare(right.ordering.pruneSortKey)
1282
+ );
1283
+ }
1284
+
1285
+ export {
1286
+ getProjectBackupRoot,
1287
+ getProjectBackupStateRoots,
1288
+ isWithinRoot,
1289
+ createAuditReport
1290
+ };
1291
+ //# sourceMappingURL=chunk-G5EF63GG.js.map