@namewta/skills-hub 0.1.49 → 0.1.52

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 (254) hide show
  1. package/README.md +4 -1
  2. package/THIRD_PARTY_NOTICES.md +19 -7
  3. package/cli.mjs +2 -2
  4. package/install.mjs +11 -4
  5. package/package.json +1 -1
  6. package/scripts/persistence/home.md +1 -1
  7. package/skills/dev/dev-build/SKILL.md +2 -0
  8. package/skills/dev/dev-build/references/implement-request.md +7 -2
  9. package/skills/dev/dev-formal-verify/SKILL.md +2 -1
  10. package/skills/dev/dev-formal-verify/references/create-check.md +3 -1
  11. package/skills/dev/dev-formal-verify/references/example.md +1 -1
  12. package/skills/dev/dev-formal-verify/references/tool-choice.md +1 -1
  13. package/skills/dev/dev-help/references/capabilities.md +6 -6
  14. package/skills/dev/dev-help/references/guide-verification.md +7 -1
  15. package/skills/dev/dev-help/references/help-method.md +7 -1
  16. package/skills/dev/dev-issue/SKILL.md +1 -0
  17. package/skills/dev/dev-issue/references/github-operations.md +8 -0
  18. package/skills/dev/dev-plan/references/plan-template.md +1 -0
  19. package/skills/dev/dev-plan/references/vertical-slicing.md +2 -0
  20. package/skills/dev/dev-pr/references/pull-request-evidence.md +2 -0
  21. package/skills/dev/dev-review/references/host-parity.md +12 -0
  22. package/skills/dev/dev-review/references/review-baseline.md +2 -0
  23. package/skills/dev/dev-setup/references/formal-options.md +1 -1
  24. package/skills/dev/dev-statechart/SKILL.md +17 -19
  25. package/skills/dev/dev-statechart/agents/openai.yaml +3 -3
  26. package/skills/dev/dev-statechart/assets/theme.css +135 -0
  27. package/skills/dev/dev-statechart/references/lean-proof.md +47 -0
  28. package/skills/dev/dev-statechart/references/render.md +15 -83
  29. package/skills/dev/dev-statechart/references/runtime.md +21 -1
  30. package/skills/dev/dev-statechart/scripts/lean/backends/lemma-chart.mjs +285 -0
  31. package/skills/dev/dev-statechart/scripts/lean/backends/mermaid.mjs +174 -0
  32. package/skills/dev/dev-statechart/scripts/lean/backends/proof-chart.mjs +540 -0
  33. package/skills/dev/dev-statechart/scripts/lean/backends/report.mjs +242 -0
  34. package/skills/dev/dev-statechart/scripts/lean/frontends/facts.mjs +234 -0
  35. package/skills/dev/dev-statechart/scripts/lean/frontends/view.mjs +217 -0
  36. package/skills/dev/dev-statechart/scripts/lean/ir.mjs +226 -0
  37. package/skills/dev/dev-statechart/scripts/lean/passes/attribute.mjs +148 -0
  38. package/skills/dev/dev-statechart/scripts/lean/passes/blocks.mjs +32 -0
  39. package/skills/dev/dev-statechart/scripts/lean/passes/budget.mjs +167 -0
  40. package/skills/dev/dev-statechart/scripts/lean/passes/check.mjs +70 -0
  41. package/skills/dev/dev-statechart/scripts/lean/passes/contract.mjs +160 -0
  42. package/skills/dev/dev-statechart/scripts/lean/passes/fold.mjs +206 -0
  43. package/skills/dev/dev-statechart/scripts/lean/passes/inline.mjs +84 -0
  44. package/skills/dev/dev-statechart/scripts/lean/passes/mark.mjs +432 -0
  45. package/skills/dev/dev-statechart/scripts/lean/passes/reduce.mjs +73 -0
  46. package/skills/dev/dev-statechart/scripts/lean/passes/trust.mjs +111 -0
  47. package/skills/dev/dev-statechart/scripts/lean/passes/view-lemmas.mjs +155 -0
  48. package/skills/dev/dev-statechart/scripts/lean/pipeline.mjs +164 -0
  49. package/skills/dev/dev-statechart/scripts/lean/run.mjs +168 -0
  50. package/skills/dev/dev-statechart/scripts/statechart.mjs +42 -23
  51. package/skills/dev/dev-statechart/scripts/worker.mjs +33 -7
  52. package/skills/dev/dev-ui-design/SKILL.md +2 -2
  53. package/skills/dev/dev-ui-design/references/interaction-review.md +9 -0
  54. package/skills/dev/dev-verify/SKILL.md +1 -1
  55. package/skills/dev/dev-verify/references/evidence-storage.md +12 -0
  56. package/skills/dev/dev-workflow/SKILL.md +6 -6
  57. package/skills/dev/dev-workflow/references/method-handoffs.md +7 -1
  58. package/skills/dev/dev-writing/SKILL.md +2 -0
  59. package/skills/dev/dev-writing/references/library-docs.md +37 -0
  60. package/skills/home/home-doctor/references/diagnosis.md +2 -2
  61. package/skills/home/home-doctor/scripts/doctor.mjs +68 -38
  62. package/skills/home/home-project-changelog/SKILL.md +7 -7
  63. package/skills/home/home-project-changelog/assets/project-changelog.example.json +188 -0
  64. package/skills/home/home-project-changelog/assets/project-changelog.schema.json +156 -0
  65. package/skills/home/home-project-changelog/assets/worker-brief.md +1 -1
  66. package/skills/home/home-project-changelog/references/git-ranges.md +2 -2
  67. package/skills/home/home-project-changelog/references/schema.md +61 -0
  68. package/skills/home/home-project-changelog/references/tools.md +28 -22
  69. package/skills/home/home-project-changelog/references/workflow.md +12 -9
  70. package/skills/home/home-project-changelog/references/writing.md +5 -3
  71. package/skills/home/home-project-changelog/scripts/changelog.mjs +42 -38
  72. package/skills/home/home-project-changelog/scripts/contract.mjs +40 -3
  73. package/skills/home/home-project-changelog/scripts/legacy-markdown.mjs +116 -0
  74. package/skills/home/home-project-changelog/scripts/migrate.mjs +122 -0
  75. package/skills/home/home-project-changelog/scripts/revision.mjs +2 -196
  76. package/skills/home/home-project-changelog/scripts/storage.mjs +120 -125
  77. package/skills/home/home-project-changelog/scripts/summary.mjs +0 -60
  78. package/skills/home/home-route/SKILL.md +2 -2
  79. package/skills/home/home-route/references/routing.md +3 -1
  80. package/skills/home/home-route/scripts/route.mjs +79 -11
  81. package/skills/home/home-setup/SKILL.md +2 -1
  82. package/skills/home/home-setup/assets/repos.schema.json +10 -0
  83. package/skills/home/home-setup/references/registry.md +18 -1
  84. package/skills/home/home-setup/scripts/registry.mjs +67 -7
  85. package/skills/home/home-website/SKILL.md +13 -9
  86. package/skills/home/home-website/assets/website/scripts/inputs.mjs +143 -128
  87. package/skills/home/home-website/assets/website/scripts/render.mjs +8 -6
  88. package/skills/home/home-website/assets/website/scripts/site.mjs +21 -10
  89. package/skills/home/home-website/assets/website/site/public/home-assets/app.js +81 -34
  90. package/skills/home/home-website/assets/website/site/public/home-assets/site.css +92 -70
  91. package/skills/home/home-website/assets/website/site/templates/favicon.png +0 -0
  92. package/skills/home/home-website/assets/website/site/templates/layout.mjs +13 -10
  93. package/skills/home/home-website/assets/website/site/templates/ledger.mjs +51 -46
  94. package/skills/home/home-website/assets/website/site/templates/model.mjs +58 -14
  95. package/skills/home/home-website/assets/website/site/templates/pages.mjs +28 -30
  96. package/skills/home/home-website/assets/website/site/templates/project-logs.mjs +3 -107
  97. package/skills/home/home-website/assets/website/site.config.json +1 -1
  98. package/skills/home/home-website/references/website.md +64 -46
  99. package/skills/home/home-website/scripts/activate.mjs +106 -0
  100. package/skills/home/home-website/scripts/init.mjs +98 -11
  101. package/skills/home/home-workflow/SKILL.md +6 -4
  102. package/skills/system/system-clash-proxy-config/SKILL.md +21 -0
  103. package/skills/system/system-clash-proxy-config/agents/openai.yaml +4 -0
  104. package/skills/system/system-clash-proxy-config/assets/clash-override.js +328 -0
  105. package/skills/system/{system-proxy → system-clash-proxy-config}/references/browser-privacy.md +2 -2
  106. package/skills/system/{system-config → system-clash-proxy-config}/references/changes.md +2 -2
  107. package/skills/system/{system-proxy → system-clash-proxy-config}/references/clash-verge.md +1 -1
  108. package/skills/system/{system-proxy → system-clash-proxy-config}/references/diagnosis.md +1 -1
  109. package/skills/system/system-clash-proxy-config/references/dns-workflow.md +42 -0
  110. package/skills/system/system-clash-proxy-config/references/egress-macos.md +31 -0
  111. package/skills/system/system-clash-proxy-config/references/egress-windows.md +37 -0
  112. package/skills/system/system-clash-proxy-config/references/egress.md +12 -0
  113. package/skills/system/{system-proxy → system-clash-proxy-config}/references/flclash.md +1 -1
  114. package/skills/system/{system-proxy → system-clash-proxy-config}/references/index.md +1 -1
  115. package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/linux-cutover.md +29 -0
  116. package/skills/system/system-clash-proxy-config/references/locale-workflow.md +9 -0
  117. package/skills/system/{system-proxy → system-clash-proxy-config}/references/mihomo.md +1 -25
  118. package/skills/system/system-clash-proxy-config/references/session.md +34 -0
  119. package/skills/system/system-clash-proxy-config/references/subscription.md +29 -0
  120. package/skills/system/{system-proxy → system-clash-proxy-config}/references/troubleshooting.md +7 -7
  121. package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/verification.md +2 -0
  122. package/skills/system/system-clash-proxy-config/scripts/prepare-session.mjs +155 -0
  123. package/skills/system/system-clash-proxy-config/scripts/run-session.mjs +138 -0
  124. package/skills/system/system-inspect/SKILL.md +1 -1
  125. package/skills/system/system-inspect/references/health-audit.md +1 -1
  126. package/upstream-skills/zh-archify/SKILL.md +11 -11
  127. package/upstream-skills/zh-archify/assets/template.html +6 -3
  128. package/upstream-skills/zh-archify/bin/archify.mjs +67 -4
  129. package/upstream-skills/zh-archify/modules/code-analysis/ARCHITECTURE.md +7 -1
  130. package/upstream-skills/zh-archify/modules/code-analysis/bin/analyze-run.mjs +2 -1
  131. package/upstream-skills/zh-archify/modules/code-analysis/bin/check.mjs +29 -15
  132. package/upstream-skills/zh-archify/modules/code-analysis/bin/drift.mjs +3 -3
  133. package/upstream-skills/zh-archify/modules/code-analysis/bin/prepare.mjs +5 -6
  134. package/upstream-skills/zh-archify/modules/code-analysis/bin/serve.mjs +66 -36
  135. package/upstream-skills/zh-archify/modules/code-analysis/bin/verify-change.mjs +43 -13
  136. package/upstream-skills/zh-archify/modules/code-analysis/docs/TECH-GUIDE.md +1 -1
  137. package/upstream-skills/zh-archify/modules/code-analysis/docs/USAGE.md +37 -4
  138. package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/functions.mjs +7 -5
  139. package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/index.mjs +4 -1
  140. package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/snapshot-host.mjs +9 -0
  141. package/upstream-skills/zh-archify/modules/code-analysis/lib/architecture-drift.mjs +28 -7
  142. package/upstream-skills/zh-archify/modules/code-analysis/lib/drift-capture.mjs +4 -3
  143. package/upstream-skills/zh-archify/modules/code-analysis/lib/git-sources.mjs +5 -3
  144. package/upstream-skills/zh-archify/modules/code-analysis/lib/output.mjs +272 -0
  145. package/upstream-skills/zh-archify/modules/code-analysis/lib/pull-request.mjs +34 -4
  146. package/upstream-skills/zh-archify/modules/code-analysis/lib/task.mjs +4 -2
  147. package/upstream-skills/zh-archify/modules/code-analysis/lib/verification-context.mjs +13 -1
  148. package/upstream-skills/zh-archify/modules/code-analysis/lib/verification-history.mjs +112 -0
  149. package/upstream-skills/zh-archify/modules/code-analysis/lib/verification.mjs +6 -2
  150. package/upstream-skills/zh-archify/modules/code-analysis/overlay/atlas.mjs +71 -5
  151. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas.css +16 -2
  152. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas.js +121 -5
  153. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas3d.js +38 -1
  154. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/overlay.css +14 -1
  155. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/overlay.js +187 -27
  156. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/verification.js +1 -1
  157. package/upstream-skills/zh-archify/modules/code-analysis/overlay/i18n.mjs +9 -0
  158. package/upstream-skills/zh-archify/modules/code-analysis/overlay/inject.mjs +1 -1
  159. package/upstream-skills/zh-archify/modules/code-analysis/overlay/page.mjs +11 -6
  160. package/upstream-skills/zh-archify/modules/code-analysis/overlay/pull-request.mjs +1 -1
  161. package/upstream-skills/zh-archify/modules/code-analysis/schemas/ai-task.schema.json +1 -0
  162. package/upstream-skills/zh-archify/modules/code-analysis/test/atlas.test.mjs +88 -0
  163. package/upstream-skills/zh-archify/modules/code-analysis/test/duplicates.test.mjs +1 -1
  164. package/upstream-skills/zh-archify/modules/code-analysis/test/external-workflow.test.mjs +1 -1
  165. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/boundary.task.json +1 -0
  166. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/boundary.task.missing.json +1 -0
  167. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/complexity.task.json +1 -0
  168. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/complexity.task.valid.json +1 -0
  169. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/import-cycle.task.changed.json +1 -0
  170. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/import-cycle.task.json +1 -0
  171. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/module-cycle.task.json +1 -0
  172. package/upstream-skills/zh-archify/modules/code-analysis/test/function-source-range.test.mjs +10 -0
  173. package/upstream-skills/zh-archify/modules/code-analysis/test/output-recovery.test.mjs +626 -0
  174. package/upstream-skills/zh-archify/modules/code-analysis/test/pull-request.test.mjs +98 -2
  175. package/upstream-skills/zh-archify/modules/code-analysis/test/review.test.mjs +37 -0
  176. package/upstream-skills/zh-archify/modules/code-analysis/test/source-panel.test.mjs +2 -1
  177. package/upstream-skills/zh-archify/modules/code-analysis/test/task.test.mjs +3 -2
  178. package/upstream-skills/zh-archify/modules/code-analysis/test/verification-history.test.mjs +216 -0
  179. package/upstream-skills/zh-archify/modules/code-analysis/test/verification.test.mjs +122 -0
  180. package/upstream-skills/zh-archify/package-lock.json +2 -2
  181. package/upstream-skills/zh-archify/package.json +1 -1
  182. package/upstream-skills/zh-archify/references/authoring-contract.md +2 -0
  183. package/upstream-skills/zh-archify/references/explainer-authoring.md +1 -1
  184. package/upstream-skills/zh-archify/renderers/architecture/render-architecture.mjs +1 -0
  185. package/upstream-skills/zh-archify/renderers/class/render-class.mjs +1 -0
  186. package/upstream-skills/zh-archify/renderers/dataflow/render-dataflow.mjs +2 -1
  187. package/upstream-skills/zh-archify/renderers/erd/render-erd.mjs +1 -0
  188. package/upstream-skills/zh-archify/renderers/lifecycle/render-lifecycle.mjs +4 -2
  189. package/upstream-skills/zh-archify/renderers/sequence/render-sequence.mjs +4 -2
  190. package/upstream-skills/zh-archify/renderers/shared/cli.mjs +7 -1
  191. package/upstream-skills/zh-archify/renderers/timeline/render-timeline.mjs +1 -0
  192. package/upstream-skills/zh-archify/renderers/tree/render-tree.mjs +1 -0
  193. package/upstream-skills/zh-archify/renderers/waterfall/render-waterfall.mjs +1 -0
  194. package/upstream-skills/zh-archify/renderers/workflow/render-workflow.mjs +3 -2
  195. package/upstream-skills/zh-archify/renderers/workflow/workflow-compiler.mjs +68 -7
  196. package/upstream-skills/zh-archify/skill-release.json +1 -1
  197. package/upstream-skills/zh-modern-web-guidance/SKILL.md +4 -11
  198. package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/language-detection.md +20 -0
  199. package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/language-model.md +22 -0
  200. package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/prompt-api.md +22 -0
  201. package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/summarizer.md +20 -0
  202. package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/translator.md +22 -0
  203. package/upstream-skills/zh-modern-web-guidance/guides/performance/custom-ml-model-inference.md +342 -0
  204. package/upstream-skills/zh-modern-web-guidance/guides/performance/data-parallel-computation.md +337 -0
  205. package/upstream-skills/zh-modern-web-guidance/guides/performance/improve-next-page-load-performance.md +4 -1
  206. package/upstream-skills/zh-modern-web-guidance/guides/performance/large-scene-rendering.md +350 -0
  207. package/upstream-skills/zh-modern-web-guidance/guides/ui-atoms/position-aware-tooltips.md +9 -0
  208. package/upstream-skills/zh-modern-web-guidance/guides/ui-atoms/viewport-aware-dropdowns.md +9 -0
  209. package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/animate-to-from-top-layer.md +9 -0
  210. package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/declarative-dialog-popover-control.md +9 -0
  211. package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/interest-triggered-tooltips.md +9 -0
  212. package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/scroll-target-on-load.md +29 -0
  213. package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/sortable-table.md +1 -0
  214. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/app-menus.md +9 -0
  215. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/context-menu.md +9 -0
  216. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/copy-button.md +9 -0
  217. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/dialog.md +10 -1
  218. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/hovercard.md +9 -0
  219. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/menu.md +9 -0
  220. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/navbar.md +9 -0
  221. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/persistent-app-tours.md +9 -0
  222. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/persistent-toast-notifications.md +9 -0
  223. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/toolbar.md +9 -0
  224. package/upstream-skills/zh-modern-web-guidance/guides/user-experience/content-first-noise-reduction.md +9 -0
  225. package/upstream-skills/zh-modern-web-guidance/guides/user-experience/natural-interactions.md +9 -0
  226. package/upstream-skills/zh-modern-web-guidance/guides/webmcp/agentic-javascript-tools.md +27 -0
  227. package/skills/home/home-project-changelog/assets/project-changelog.md +0 -35
  228. package/skills/system/system-clash-tun-egress/SKILL.md +0 -22
  229. package/skills/system/system-clash-tun-egress/agents/openai.yaml +0 -4
  230. package/skills/system/system-config/SKILL.md +0 -37
  231. package/skills/system/system-config/agents/openai.yaml +0 -4
  232. package/skills/system/system-config/references/ai-cli-config.md +0 -75
  233. package/skills/system/system-config/references/ai-cli-optimization.md +0 -37
  234. package/skills/system/system-config/references/index.md +0 -12
  235. package/skills/system/system-config/references/locale-workflow.md +0 -33
  236. package/skills/system/system-config/references/locale.md +0 -50
  237. package/skills/system/system-proxy/SKILL.md +0 -40
  238. package/skills/system/system-proxy/agents/openai.yaml +0 -4
  239. package/skills/system/system-proxy/assets/protected-rules.yaml +0 -7
  240. package/skills/system/system-proxy/references/dns-workflow.md +0 -152
  241. /package/skills/system/{system-config → system-clash-proxy-config}/assets/configuration.md +0 -0
  242. /package/skills/system/{system-proxy → system-clash-proxy-config}/assets/network.md +0 -0
  243. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/acceptance.md +0 -0
  244. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/dns-fields.md +0 -0
  245. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/dns-misconceptions.md +0 -0
  246. /package/skills/system/{system-clash-tun-egress/references/troubleshooting.md → system-clash-proxy-config/references/egress-troubleshooting.md} +0 -0
  247. /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-linux.md +0 -0
  248. /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-macos.md +0 -0
  249. /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-windows.md +0 -0
  250. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/network-performance.md +0 -0
  251. /package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/nodes-and-dns.md +0 -0
  252. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/platform-dns.md +0 -0
  253. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/platforms.md +0 -0
  254. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/tun-dns.md +0 -0
@@ -3,11 +3,11 @@ import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { DiagnosticError, fail, receipt } from '../core/index.mjs';
5
5
  import { loadPrevious, readJsonInput } from '../lib/analysis.mjs';
6
- import { reviewFindings } from '../lib/review.mjs';
7
- import { verificationContext } from '../lib/verification-context.mjs';
6
+ import { matchingPreviousPullRequest, sameVerificationRepository, verificationContexts } from '../lib/verification-history.mjs';
8
7
  import { evaluateVerification } from '../lib/verification.mjs';
8
+ import { schemaErrors } from '../schemas/index.mjs';
9
9
 
10
- const usage = 'Usage: archify code-analysis verify-change <analysis-dir> --task <task.json> [--checks <checks.json> | --checks-template]';
10
+ const usage = 'Usage: archify code-analysis verify-change <analysis-dir> --task <task.json> [--checks <checks.json> | --checks-template] [--unverified-baseline <findings.json>]';
11
11
  const INPUT_BYTES = 2 * 1024 * 1024;
12
12
  const originalTask = 'export the task again from the matching earlier analysis';
13
13
  const checksTemplate = 'generate a new checks template for the same task and analysis pair';
@@ -15,8 +15,8 @@ const reanalyze = 'run analysis again in the same output directory and keep both
15
15
  const verificationFailures = {
16
16
  'no-comparison': ['analysis', 'No usable before and after analysis captures were found.', reanalyze],
17
17
  'invalid-task': ['task', 'The task does not have the expected format.', originalTask],
18
- 'wrong-task-snapshot': ['task', 'The task does not match the previous analysis.', originalTask],
19
- 'wrong-task-findings': ['task', 'The selected findings do not match the previous analysis.', originalTask],
18
+ 'wrong-task-snapshot': ['task', 'The task does not match a retained analysis capture.', originalTask],
19
+ 'wrong-task-findings': ['task', 'The selected findings do not match the task baseline.', originalTask],
20
20
  'wrong-task-id': ['task', 'The task ID does not match the selected findings.', originalTask],
21
21
  'invalid-checks': ['checks', 'The project check results do not have the expected format.', checksTemplate],
22
22
  'wrong-checks-snapshot': ['checks', 'The project check results do not match this task and analysis pair.', checksTemplate],
@@ -45,26 +45,56 @@ function readInput(file, input) {
45
45
  catch { fail('cli/input-not-json', 'The selected file is not valid JSON.', guidance); }
46
46
  }
47
47
 
48
+ function readUnverifiedBaseline(file) {
49
+ const invalid = () => fail('cli/input-invalid', 'Select a valid findings.json file up to 64 MiB.', {
50
+ subject: { option: '--unverified-baseline' }, supportedFixes: ['pass a saved findings.json from the earlier analysis'],
51
+ });
52
+ try {
53
+ const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
54
+ try {
55
+ const stat = fs.fstatSync(fd);
56
+ if (!stat.isFile() || stat.size > 64 * 1024 * 1024) return invalid();
57
+ const bytes = Buffer.alloc(stat.size + 1);
58
+ if (fs.readSync(fd, bytes, 0, bytes.length) !== stat.size) return invalid();
59
+ const doc = JSON.parse(bytes.toString('utf8', 0, stat.size));
60
+ if (schemaErrors('findings', doc).length || (doc.repository.sourceKind ?? 'working-tree') !== 'working-tree') return invalid();
61
+ return doc;
62
+ } finally { fs.closeSync(fd); }
63
+ } catch (error) {
64
+ if (error instanceof DiagnosticError) throw error;
65
+ return invalid();
66
+ }
67
+ }
68
+
48
69
  async function run([dir, ...args]) {
49
70
  if (!dir || dir === '--help' || dir === '-h') { console.log(usage); return; }
50
71
  const invalidUsage = () => fail('cli/usage', usage, { supportedFixes: ['pass an analysis directory and --task, with either --checks or --checks-template if needed'] });
51
72
  const options = new Map();
52
73
  while (args.length) {
53
74
  const key = args.shift();
54
- if (options.has(key) || !['--task', '--checks', '--checks-template'].includes(key)) invalidUsage();
75
+ if (options.has(key) || !['--task', '--checks', '--checks-template', '--unverified-baseline'].includes(key)) invalidUsage();
55
76
  const value = key === '--checks-template' ? true : args.shift();
56
77
  if (!value || (typeof value === 'string' && value.startsWith('--'))) invalidUsage();
57
78
  options.set(key, value);
58
79
  }
59
80
  if (!options.has('--task') || (options.has('--checks') && options.has('--checks-template'))) invalidUsage();
60
81
  const current = loadPrevious(path.join(dir, 'findings.json'));
61
- const previous = loadPrevious(path.join(dir, '..', 'analysis.previous', 'findings.json'));
62
- const facts = current && previous && readJsonInput(path.join(dir, 'raw-facts.json'), 'verify-change');
63
- const review = facts && reviewFindings(current.diagnostics, {
64
- previous, analysis: current.analysis,
65
- files: [...facts.files, ...(current.externalEvidence || [])].map((f) => f.path),
66
- });
67
- const result = await evaluateVerification(verificationContext(previous, current, review), readInput(options.get('--task'), 'task'),
82
+ const contextPath = path.join(dir, 'view-context.json');
83
+ const context = fs.existsSync(contextPath) ? readJsonInput(contextPath, 'verify-change') : null;
84
+ const pinned = Boolean(context?.run?.pullRequest);
85
+ if (options.has('--unverified-baseline') && (pinned || (current?.repository?.sourceKind ?? 'working-tree') !== 'working-tree')) invalidUsage();
86
+ const previousDir = path.join(dir, '..', 'analysis.previous');
87
+ const previous = pinned ? loadPrevious(path.join(dir, 'base/findings.json'))
88
+ : sameVerificationRepository(dir, previousDir) ? loadPrevious(path.join(previousDir, 'findings.json')) : null;
89
+ const facts = current && readJsonInput(path.join(dir, 'raw-facts.json'), 'verify-change');
90
+ const previousHead = pinned && matchingPreviousPullRequest(previousDir, current, context.run.pullRequest);
91
+ let contexts = options.has('--unverified-baseline')
92
+ ? verificationContexts(dir, readUnverifiedBaseline(options.get('--unverified-baseline')), current, facts, [])
93
+ : verificationContexts(dir, previous, current, facts, pinned ? [previousHead] : undefined);
94
+ if (options.has('--unverified-baseline') && contexts) contexts = contexts.map((capture) => ({
95
+ ...capture, comparable: false, reasons: [...capture.reasons, 'legacy-owner-unverified'], newCount: null,
96
+ }));
97
+ const result = await evaluateVerification(contexts, readInput(options.get('--task'), 'task'),
68
98
  options.has('--checks') ? readInput(options.get('--checks'), 'checks') : undefined);
69
99
  if (result.error) {
70
100
  const [input, message, fix] = verificationFailures[result.error];
@@ -406,7 +406,7 @@ IR 中组件的 `sources` 指定文件;路径包含该文件的最深模块认
406
406
 
407
407
  按钮向 `/analyze` 发起 POST。请求必须来自服务提供的页面(检查 `Origin` 头),且携带为本进程生成的令牌;其他请求一律拒绝,因此另一标签页中的页面无法启动分析或选择路径。第一次接受请求时,服务器以子进程启动 `bin/analyze-run.mjs`。它通过 stdin 以 JSON 传入 `analyzeRepository` 选项,并读回一行 JSON:回执或结构化诊断。extract → graphs → evaluate → overlay 都在该进程中运行,因此大型仓库不会阻塞服务器事件循环。
408
408
 
409
- 每次运行写入 `<out>/analysis.next-<random>`。只有成功后才交换目录:当前 `<out>/analysis` 移至 `<out>/analysis.previous`,新目录变为 `<out>/analysis`。失败运行的目录会删除。当前 `findings.json` 作为 `previous` 传入,因此每次运行都携带与上一次的比较。响应是分析页面。并发点击共享同一次运行;之后的点击直接返回最新结果,不再重复运行。
409
+ 每次运行写入 `<out>/analysis.next-<random>`。只有成功后才交换目录,当前 `<out>/analysis` 移到 `<out>/analysis.previous`,新目录成为 `<out>/analysis`。失败运行的目录会移除。当前的 `findings.json` 作为 `previous` 传入,报告概览据此与上一次运行比较。本地运行还会暂存有容量上限的发现结果历史,供任务验证使用。回执将任务指定的捕获结果与当前捕获结果比较,重复的捕获共用一个历史位置。响应是分析页面。并行点击共用同一次运行,后续点击直接返回最新结果。
410
410
 
411
411
  <a id="re-analysis"></a>
412
412
  ### 重新分析
@@ -91,7 +91,11 @@ node bin/archify.mjs code-analysis prepare /path/to/repo --out out/project-analy
91
91
 
92
92
  只有存在相关图,或明确要求对齐已编写的架构边界时,才使用 `--ir architecture.json`。不要仅为解锁分析而编写 JSON。每次运行处理一个适配器,并披露其他语言;根据源码数量选择适配器。工具前置要求和首次安装影响准备时间,因此应报告实际测得的延迟,而非承诺固定速度。
93
93
 
94
- `prepare` 与 `serve` 共享提取、规则、任务和原子输出轮换,然后退出。JSON 回执给出所选范围的计数、覆盖、优先调查线索,以及 `html`(`out/project-analysis/analysis/repo.analysis.html`);没有 IR 时 `diagram` 为 null,否则指向未修改的已交付图。直接打开 HTML:工作台和 Atlas 已可离线使用,包含捕获任务、源码摘录、架构简报和手动复制回退方式。
94
+ `prepare` 与 `serve` 共用提取、规则、任务和结果发布机制,完成后退出。JSON 回执给出所选范围的计数、覆盖范围、优先调查线索和 `html`(`out/project-analysis/analysis/repo.analysis.html`)。没有 IR 时 `diagram` 为 null,否则指向未修改的已交付图。直接打开该 HTML 即可离线使用工作台与 Atlas,其中包含捕获任务、源码摘录、架构简报及手动复制的回退方式。
95
+
96
+ 报告发布和工作台的审阅保存共用输出目录锁。重试确认写入进程已经退出时,会在发布前清除其暂存内容。Linux 上,重试先核对本次系统启动及进程命名空间,再解释 PID。如果仍能看到同一 PID 且其身份可比较,重试还会检查进程启动时间。
97
+
98
+ 锁持有者仍在活动或身份无法核实时,`analysis/output-busy` 会保留该锁。空锁也会保留,因为另一个进程可能正在写入锁持有者身份。在创建锁的短暂窗口内崩溃时,重试前可能需要手工检查。需要独立重试的容器或机器应使用不同的 `--out`;遇到早于锁持有者检查机制的遗留锁时也应如此。出现 `analysis/output-recovery-required` 后,应把输出、移动计划和备份一起留作恢复。
95
99
 
96
100
  在 **Recheck after edits** 下复制保存的启动命令,并在生成报告的机器上运行。命令保留语言、区域设置、配置、基线,以及可选 IR/map。没有 IR 时,打开打印 URL 即开始分析并与捕获结果比较;有 IR 时,点击 Code Analysis。后续编辑使用 **Re-analyze**。报告绝不会自动运行命令。当前源码验证之前,任务始终是捕获快照。
97
101
 
@@ -107,12 +111,12 @@ Atlas 在右侧栏显示关系图和四个带标签的仓库总数。**Map** 与
107
111
  ## 编辑后验证先前任务
108
112
 
109
113
  1. 编辑前,打开发现结果的 **Task preview and download**,再点击 **Download task JSON**。使用 Markdown 或复制操作把任务交给开发者或编程代理。
110
- 2. 完成变更,单独运行项目检查,并在实时工作台中 **Re-analyze**,或以相同输出目录再次运行 `prepare`。保留紧邻的上一次捕获;再次运行分析会轮换这对捕获。
114
+ 2. 完成改动,单独运行项目检查,在实时工作台中选择 **Re-analyze**,或用相同的输出目录再次运行 `prepare`。按需在更新后的报告中重新打开发现结果。
111
115
  3. 在 **Verify a previous task** 下选择任务 JSON,预览分析观察。要记录项目检查,请下载检查模板,输入简短检查名称及其状态(`passed`、`failed`、`skipped` 或 `not-run`),再加载并重新预览。**Download verification JSON** 导出合并回执。准备好的 HTML 可离线工作;这些文件在浏览器中读取,绝不会发送到本地服务。
112
116
 
113
117
  回执区分观察到的发现结果变化与用户报告的检查。它不运行测试、不验证测试执行,也不证明修复。新增发现结果按捕获范围计数,不归因于该任务。在适用情况下,受限比较、证据缺失和未变化的导入报告会标为无法得出结论。重新分析前,使用原始工具和设置刷新外部报告;仅字节不同仍不能证明工具针对捕获源码运行过。不要把命令、日志或秘密放进检查名称。
114
118
 
115
- 要以无界面方式执行相同流程,将 `verify-change` 指向 `prepare` 或 `serve` 的 `analysis/` 目录。它读取旁边的 `analysis.previous/` 捕获。在包目录下的示例:
119
+ 要用无界面方式执行相同流程,将 `verify-change` 指向 `prepare` 或 `serve` 的 `analysis/` 目录。两种界面都使用任务原始的分析捕获。分析工作树时,复用输出目录可在 4 MiB 历史容量内保留最多六份不同的早期发现结果。只有仓库归属相符时,才能使用相邻的 `analysis.previous/` 捕获。PR 分析不保留该历史,验证可以使用固定的 merge base,在 PR 和固定提交均匹配时也可以使用相邻的上一 PR head。具有相同任务身份的捕获共用一个历史位置,即使补充证据的字节不同。保留的历史与规范化后的本地仓库目录及其文件系统身份绑定。目录创建后第一秒内完成的捕获,或没有可用文件系统身份的捕获,仍无归属。不能自动采用缺少归属元数据的旧输出,因为保存的命令相同不能证明该路径处的检出目录延续至今。对应任务需要独立验证过的早期捕获。若取不到此类证据,重新准备任务。能够无歧义地匹配捕获时,早期任务 JSON 仍可使用。新导出的任务包含 `source.analysisSha256`,不识别这个可选字段的旧严格校验器会拒绝它。目前的校验器仍接受缺少该字段的任务。旧捕获已轮换出去时,将验证指向仍保存该捕获的输出目录。与其他分析产物一样,保留的发现结果可能包含本地证据。输出目录应保留在本地。以下示例从包目录运行:
116
120
 
117
121
  ```sh
118
122
  node bin/archify.mjs code-analysis verify-change out/project-analysis/analysis --task task.json --checks-template > checks.json
@@ -122,6 +126,8 @@ node bin/archify.mjs code-analysis verify-change out/project-analysis/analysis -
122
126
 
123
127
  省略 `--checks` 则只记录分析观察。使用原始任务 JSON:其 ID 必须匹配所选发现结果。退出码 0 表示回执已生成(即使项目检查失败或比较无法得出结论);退出码 2 在 stdout 返回 JSON 错误,带有 `status: "error"` 与 `diagnostics`,而不是回执。`task --verify` 仍是独立的当前源码证据检查。
124
128
 
129
+ 若要查看已保存但缺少归属的工作树基线,同时避免自动将其视为可信,可把 `--unverified-baseline /path/to/old/findings.json` 和原始任务一起传给 `verify-change`。在后续运行轮换相邻目录前先保存旧文件。该文件必须是有效的发现结果文档,大小不得超过 64 MiB,且任务必须与其捕获的发现结果匹配。回执始终将 `analysis.comparable` 设为 false,记录 `legacy-owner-unverified`,将选定结果全部标为无法得出结论,且不统计新增发现结果。该基线不会并入可信历史。路径、任务或保存的命令匹配时,仍需另行调查来源,确认仓库是否连续。本选项不适用于固定提交的 PR 比较或浏览器报告。
130
+
125
131
  <a id="review-architecture-drift-between-two-commits"></a>
126
132
  ## 审阅两个提交之间的架构漂移
127
133
 
@@ -381,7 +387,7 @@ node bin/archify.mjs code-analysis check "/path/to/project" --baseline analysis-
381
387
  | --- | --- |
382
388
  | `--fail-on error\|warning\|info\|never` | 未关闭发现结果达到该级别时失败(默认 `warning`)。 |
383
389
  | `--baseline file` | 已接受发现结果不会使运行失败,除非其代码变化。 |
384
- | `--out dir` | 写入 `raw-facts`、`module-graph`、`findings`、`review` 和 `overview` JSON。自动与该目录中上一份 `findings.json` 比较。 |
390
+ | `--out dir` | 一起发布 `raw-facts`、`module-graph`、`findings`、`review` 和 `overview` JSON。自动与该目录上一次完整运行的 `findings.json` 比较。 |
385
391
  | `--compare findings.json` | 改为与指定的较早运行比较。 |
386
392
  | `--new-only` | 仅因相对于比较对象新增的发现结果失败,适合拉取请求门禁。没有上次运行可比较时,每条未关闭结果都视为新增,因此缺失比较产物不能通过门禁。 |
387
393
  | `--update-baseline [--reason text]` | 写入基线,而不执行门禁检查。 |
@@ -389,6 +395,33 @@ node bin/archify.mjs code-analysis check "/path/to/project" --baseline analysis-
389
395
 
390
396
  退出码:`0` 通过,`1` 门禁失败,`2` 分析无法运行(诊断说明原因)。未使用 `--baseline` 的失败运行会提供将当前发现结果记录到 `analysis-baseline.json` 的命令,适用于首次运行或规则变严之后。如果基线或深入查看命令包含控制字符,摘要会指向 `--json` 回执中 `gate.adopt` 或 `investigation.drillDown` 下的精确命令。打印摘要以 `path:line` 和 ID 列出导致失败的发现结果、比较计数,以及过时基线条目。
391
397
 
398
+ <a id="keep-the-pr-comparison-fixed-across-retries"></a>
399
+ ### PR 重试沿用固定的比较基线
400
+
401
+ 退出码为 `1` 的分析也可能发布报告。同一输出目录上的后续运行会将该报告用于自动比较。重试 PR 门禁时,显式传入原比较文件。
402
+
403
+ 从 PR 事件记录 base 和 head 提交。在 `BASE_TREE` 中检出两者的 merge base,在 `HEAD_TREE` 中检出所记录的 head。两条命令使用相同的 `ARCHIFY_CLI`(`bin/archify.mjs` 路径)、`ANALYSIS_LANGUAGE` 和 `ANALYSIS_CONFIG`(共享配置路径)。输出目录放在两个检出目录之外。
404
+
405
+ 为这对提交生成一次比较报告。
406
+
407
+ ```sh
408
+ node "$ARCHIFY_CLI" code-analysis check "$BASE_TREE" \
409
+ --language "$ANALYSIS_LANGUAGE" --config "$ANALYSIS_CONFIG" \
410
+ --out "$BASE_OUT" --fail-on never --json
411
+ ```
412
+
413
+ 命令以 `0` 退出后,保存 `BASE_OUT/findings.json`、比较所用的提交 ID 和工具配置。每次尝试都恢复同一文件,使用新的 `ATTEMPT_OUT`。
414
+
415
+ ```sh
416
+ mkdir -p "$ATTEMPT_OUT" || exit 2
417
+ node "$ARCHIFY_CLI" code-analysis check "$HEAD_TREE" \
418
+ --language "$ANALYSIS_LANGUAGE" --config "$ANALYSIS_CONFIG" \
419
+ --compare "$BASE_OUT/findings.json" --new-only --fail-on warning \
420
+ --out "$ATTEMPT_OUT" --json > "$ATTEMPT_OUT/receipt.json"
421
+ ```
422
+
423
+ 步骤结束时保留 CLI 退出状态。退出码为 `0` 或 `1` 时保存该次尝试的报告与回执,发现结果阻断门禁时也一样。退出码为 `2` 时保存错误回执。传给 `--compare` 的文件缺失或无效时,退出码为 `2`。
424
+
392
425
  <a id="config-files"></a>
393
426
  ## 配置文件
394
427
 
@@ -45,7 +45,7 @@ function measureFunctions(source, file, onFunction) {
45
45
  if (isFunctionWithBody(node)) {
46
46
  const name = functionName(node, source);
47
47
  if (name || !insideFunction) {
48
- let qualname = prefix + (name || anonymousName(node, source));
48
+ let qualname = prefix + (name ? functionName(node, source, true) : anonymousName(node, source));
49
49
  if (!name) {
50
50
  const n = (seen.get(qualname) || 0) + 1;
51
51
  seen.set(qualname, n);
@@ -126,7 +126,7 @@ function isBlock(node) {
126
126
  }
127
127
 
128
128
  // The name a function is known by, or null for an anonymous callback.
129
- function functionName(fn, source) {
129
+ function functionName(fn, source, qualifyAssignment = false) {
130
130
  if (ts.isConstructorDeclaration(fn)) return 'constructor';
131
131
  if ((ts.isFunctionDeclaration(fn) || ts.isFunctionExpression(fn)) && fn.name) return fn.name.text;
132
132
  if (ts.isMethodDeclaration(fn) || ts.isGetAccessorDeclaration(fn) || ts.isSetAccessorDeclaration(fn)) {
@@ -134,11 +134,11 @@ function functionName(fn, source) {
134
134
  return ts.isGetAccessorDeclaration(fn) ? `get ${base}` : ts.isSetAccessorDeclaration(fn) ? `set ${base}` : base;
135
135
  }
136
136
  if (ts.isFunctionDeclaration(fn)) return 'default'; // export default function () {}
137
- return bindingName(fn, source);
137
+ return bindingName(fn, source, qualifyAssignment);
138
138
  }
139
139
 
140
140
  // The name an expression is bound to by its parent, if any.
141
- function bindingName(node, source) {
141
+ function bindingName(node, source, qualifyAssignment = false) {
142
142
  let current = node;
143
143
  while (current.parent && (ts.isParenthesizedExpression(current.parent) || ts.isAsExpression(current.parent) || ts.isSatisfiesExpression?.(current.parent) || ts.isTypeAssertionExpression(current.parent))) current = current.parent;
144
144
  const parent = current.parent;
@@ -148,7 +148,9 @@ function bindingName(node, source) {
148
148
  if (ts.isBinaryExpression(parent) && parent.right === current && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
149
149
  const left = parent.left;
150
150
  if (ts.isIdentifier(left)) return left.text;
151
- if (ts.isPropertyAccessExpression(left)) return left.name.text;
151
+ if (ts.isPropertyAccessExpression(left)) {
152
+ return qualifyAssignment ? `${left.expression.getText(source)}.${left.name.text}` : left.name.text;
153
+ }
152
154
  }
153
155
  if (ts.isExportAssignment(parent)) return 'default';
154
156
  return null;
@@ -475,6 +475,7 @@ function resolve(record, containingFile, absRoot, fileSet, options, inputs, reso
475
475
  const correction = runtimePackageTarget(record, containingFile, absRoot, options, inputs, resolutionMode);
476
476
  if (correction && correction.status !== 'selected') return { reason: 'unknown' };
477
477
  const result = correction ? null : ts.resolveModuleName(specifier, containingFile, options, inputs, undefined, undefined, resolutionMode);
478
+ inputs.recordFailedLookups(result?.failedLookupLocations);
478
479
  const resolvedFile = correction?.file || result?.resolvedModule?.resolvedFileName;
479
480
  if (!resolvedFile) return { reason: isPathLike ? 'unknown' : 'external' };
480
481
  if (resolvedFile.split(path.sep).join('/').includes('/node_modules/')) return { reason: 'external' };
@@ -493,7 +494,9 @@ function resolve(record, containingFile, absRoot, fileSet, options, inputs, reso
493
494
  // Type declarations and TS substitutions cannot become runtime edges;
494
495
  // excluded-file boundaries remain checked against the captured file set.
495
496
  const runtimeHost = { ...inputs, fileExists: file => !/\.[cm]?tsx?$/.test(file) && inputs.fileExists(file) };
496
- const runtime = ts.resolveModuleName(specifier, containingFile, { ...options, noDtsResolution: true }, runtimeHost, undefined, undefined, resolutionMode).resolvedModule;
497
+ const runtimeResult = ts.resolveModuleName(specifier, containingFile, { ...options, noDtsResolution: true }, runtimeHost, undefined, undefined, resolutionMode);
498
+ inputs.recordFailedLookups(runtimeResult.failedLookupLocations);
499
+ const runtime = runtimeResult.resolvedModule;
497
500
  const file = runtime?.resolvedFileName;
498
501
  if (!file || !/\.[cm]?js$/.test(file)) return { reason: 'unknown' };
499
502
  if (file.split(path.sep).join('/').includes('/node_modules/')) return { reason: 'external' };
@@ -61,6 +61,15 @@ function snapshotHost(root, { contents, names, assertFileUnchanged }, { captured
61
61
  };
62
62
  return {
63
63
  reads,
64
+ recordFailedLookups(locations) {
65
+ if (!capturedOnly) return;
66
+ // TypeScript can skip host probes for directories outside the snapshot.
67
+ for (const file of locations ?? []) {
68
+ if (!file.endsWith('.json')) continue;
69
+ const absolute = path.resolve(file);
70
+ if (!captured(absolute) && !reads.has(absolute)) reads.set(absolute, undefined);
71
+ }
72
+ },
64
73
  useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
65
74
  getCurrentDirectory: () => root,
66
75
  fileExists(file) {
@@ -2,6 +2,7 @@ import path from 'node:path';
2
2
  import { createHash } from 'node:crypto';
3
3
  import { fail } from '../core/index.mjs';
4
4
  import { resolveMapping } from './diagram-mapping.mjs';
5
+ import { skippedDriftDirectory } from './drift-capture.mjs';
5
6
 
6
7
  export const DRIFT_EVIDENCE_LIMIT = 8;
7
8
  const order = (a, b) => a < b ? -1 : a > b ? 1 : 0;
@@ -38,6 +39,16 @@ function project({ facts, graph, omitted }, ir, map) {
38
39
  }
39
40
  const components = new Set([...byModule.values()].filter(v => v.length === 1).flat());
40
41
  const owner = file => byModule.get(Object.hasOwn(graph.fileModules, file) ? graph.fileModules[file] : null) || [];
42
+ const omittedOwner = file => {
43
+ // Explicit groups can claim paths outside their directory, so a skipped
44
+ // path cannot be assigned safely from its nearest directory alone.
45
+ if (graph.grouping?.groups?.length) return null;
46
+ const matches = graph.modules.filter(module => module.path && (file === module.path || file.startsWith(module.path + '/')));
47
+ const depth = Math.max(0, ...matches.map(module => module.path.length));
48
+ const nearest = matches.filter(module => module.path.length === depth);
49
+ const owners = [...new Set(nearest.flatMap(module => byModule.get(module.id) || []))];
50
+ return nearest.length === 1 && owners.length === 1 ? owners[0] : null;
51
+ };
41
52
  const errors = new Set((facts.parse_errors || []).map(e => e.path));
42
53
  const relevantErrors = [...errors].filter(file => owner(file).length);
43
54
  const ambiguity = [...byModule].filter(([, owners]) => owners.length > 1)
@@ -81,7 +92,7 @@ function project({ facts, graph, omitted }, ir, map) {
81
92
  edges.set(key, record);
82
93
  }
83
94
  }
84
- return { edges, uncertain, unresolved, components, ambiguity, owner, relevantErrors, omitted,
95
+ return { edges, uncertain, unresolved, components, ambiguity, owner, omittedOwner, relevantErrors, omitted,
85
96
  coverage: { files: facts.files.length, mappedComponents: components.size, ambiguousModules: ambiguity.length,
86
97
  unmappedModules: graph.modules.length - byModule.size, parseErrors: errors.size, scopedParseErrors: relevantErrors.length,
87
98
  unresolvedImports: facts.unresolved, skippedLinks: omitted.size } };
@@ -89,14 +100,20 @@ function project({ facts, graph, omitted }, ir, map) {
89
100
 
90
101
  const empty = () => ({ count: 0, locations: [] });
91
102
  const differs = (a = new Set(), b = new Set()) => a.size !== b.size || [...a].some(x => !b.has(x));
92
- function changedPaths(a, b) {
93
- return [...new Set([...a.keys(), ...b.keys()])].some(k => a.get(k) !== b.get(k));
94
- }
95
103
 
96
104
  export function compareArchitectureDrift({ base, head, ir, map, pins, inputs, locale }) {
97
- const left = project(base, ir, map), right = project(head, ir, map);
105
+ // A lookup on either side can depend on an omitted entry on the other side.
106
+ const resolutionInput = file => base.resolutionInputs.has(file) || head.resolutionInputs.has(file);
107
+ const retainOmissions = capture => new Map([...capture.omitted].filter(([file]) =>
108
+ !skippedDriftDirectory(file.split('/')) || resolutionInput(file)));
109
+ const left = project({ ...base, omitted: retainOmissions(base) }, ir, map);
110
+ const right = project({ ...head, omitted: retainOmissions(head) }, ir, map);
98
111
  const declared = new Set(ir.connections.map(e => pair(e.from, e.to)));
99
- const movedLink = changedPaths(left.omitted, right.omitted);
112
+ const changedOmissions = [...new Set([...left.omitted.keys(), ...right.omitted.keys()])].filter(file => left.omitted.get(file) !== right.omitted.get(file));
113
+ // Omitted manifests and configs can affect imports across component boundaries.
114
+ const resolutionOmitted = changedOmissions.some(file =>
115
+ ['package.json', 'tsconfig.json', 'jsconfig.json'].includes(path.posix.basename(file)) ||
116
+ resolutionInput(file));
100
117
  // Files read for resolution can differ naturally as imports move. A
101
118
  // different value for a shared resolution input makes absence ambiguous.
102
119
  const resolutionChanged = [...base.resolutionInputs].some(([file, digest]) =>
@@ -115,7 +132,11 @@ export function compareArchitectureDrift({ base, head, ir, map, pins, inputs, lo
115
132
  if ([left, right].some(side => side.ambiguity.some(m => m.components.includes(from) || m.components.includes(to)))) reasons.push('ambiguous-ownership');
116
133
  if ([left, right].some(side => !side.components.has(from) || !side.components.has(to))) reasons.push('component-not-mapped-on-both-sides');
117
134
  if (differs(left.unresolved.get(from), right.unresolved.get(from))) reasons.push('unresolved-imports-changed');
118
- if (movedLink) reasons.push('skipped-tree-entries-changed');
135
+ if (resolutionOmitted || changedOmissions.some(file => {
136
+ const owners = [left.omitted.has(file) ? left.omittedOwner(file) : null, right.omitted.has(file) ? right.omittedOwner(file) : null].filter(Boolean);
137
+ const known = (!left.omitted.has(file) || left.omittedOwner(file)) && (!right.omitted.has(file) || right.omittedOwner(file));
138
+ return !known || owners.includes(from) || owners.includes(to) || (left.unresolved.get(from)?.size || 0) > 0 || (right.unresolved.get(from)?.size || 0) > 0;
139
+ })) reasons.push('skipped-tree-entries-changed');
119
140
  if (resolutionChanged) reasons.push('resolution-inputs-changed');
120
141
  }
121
142
  const inDiagram = declared.has(key);
@@ -35,7 +35,7 @@ export function assertDriftPin(repo, oid, side) {
35
35
  });
36
36
  }
37
37
 
38
- const skippedDirectory = segments => segments.slice(0, -1).some(s => s === 'node_modules');
38
+ export const skippedDriftDirectory = segments => segments.slice(0, -1).includes('node_modules');
39
39
  function portableParts(name) {
40
40
  const parts = name.split('/');
41
41
  // Materialize regular blobs only, into a private staging directory. Reject
@@ -91,12 +91,13 @@ export function captureDriftTree(repo, oid, target) {
91
91
  const [mode, type, hash, sizeText] = record.slice(0, tab).trim().split(/ +/);
92
92
  const name = record.slice(tab + 1);
93
93
  const parts = portableParts(name);
94
- if (skippedDirectory(parts)) continue;
95
- assertUniquePath(seen, parts);
94
+ const excluded = skippedDriftDirectory(parts);
95
+ if (!excluded) assertUniquePath(seen, parts);
96
96
  if (mode === '120000' || mode === '160000') {
97
97
  omitted.set(name, hash);
98
98
  continue;
99
99
  }
100
+ if (excluded) continue;
100
101
  const size = Number(sizeText);
101
102
  if (type !== 'blob' || !sha.test(hash) || !Number.isSafeInteger(size) || size < 0 || size > MAX_BLOB ||
102
103
  (bytes += size) > MAX_BYTES || entries.length >= MAX_FILES) {
@@ -43,11 +43,13 @@ export async function git(cwd, args, { input = null, noLazyFetch = false } = {})
43
43
  } catch (error) { fail(error.killed ? 'pr/git-timeout' : 'pr/git-failed', error.killed ? 'Git source preparation timed out.' : 'Git could not prepare the requested source objects.', { evidence: { operation: args[0], exitCode: error.code || null }, supportedFixes: ['check local Git and repository access; retry the requested PR'] }); }
44
44
  }
45
45
 
46
- export async function materializeTree({ cache, sha, scope, target, blobSource = null, offline = false }) {
46
+ export async function materializeTree({ cache, sha, scope, target, blobSource = null, offline = false, preflightListing = null }) {
47
47
  if (!SHA.test(sha)) fail('pr/commit-invalid', 'A source snapshot needs an exact commit SHA.');
48
48
  scope = normalizeScope(scope);
49
49
  fs.mkdirSync(target, { recursive: true });
50
- const listing = await git(cache, ['ls-tree', '-rz', '--full-tree', sha, ...(scope === '.' ? [] : ['--', `${scope}/`])], { noLazyFetch: offline });
50
+ // Local scoped preparation just scanned this exact immutable commit and scope
51
+ // for its write-safety preflight. Reuse that listing within this operation.
52
+ const listing = preflightListing ?? await git(cache, ['ls-tree', '-rz', '--full-tree', sha, ...(scope === '.' ? [] : ['--', `${scope}/`])], { noLazyFetch: offline });
51
53
  const records = [], skipped = [], names = new Set();
52
54
  for (const record of listing.toString('utf8').split('\0').filter(Boolean)) {
53
55
  const match = /^(\d+) (\w+) ([a-f0-9]{40})\t([\s\S]+)$/.exec(record);
@@ -62,7 +64,7 @@ export async function materializeTree({ cache, sha, scope, target, blobSource =
62
64
  fail('pr/tree-path-unsupported', 'A Git tree path cannot be safely materialized on this system.');
63
65
  }
64
66
  names.add(folded);
65
- if (type !== 'blob' || !/^100(?:644|755)$/.test(mode)) { skipped.push({ path: relative, mode, type }); continue; }
67
+ if (type !== 'blob' || !/^100(?:644|755)$/.test(mode)) { skipped.push({ path: relative, mode, type, oid }); continue; }
66
68
  records.push({ path: relative, filename, oid, mode });
67
69
  }
68
70
  // cat-file's partial-clone fallback fetches one missing blob at a time.