@gong-ym/ai-spec-auto 0.2.3

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 (640) hide show
  1. package/.agents/commands/README.md +33 -0
  2. package/.agents/commands/claude/spec-start-review.md +88 -0
  3. package/.agents/commands/codex/spec-continue.md +74 -0
  4. package/.agents/commands/codex/spec-orchestrate.md +35 -0
  5. package/.agents/commands/codex/spec-start-review.md +88 -0
  6. package/.agents/commands/codex/spec-start.md +67 -0
  7. package/.agents/commands/codex/spec-status.md +22 -0
  8. package/.agents/commands/codex/spec-stop.md +29 -0
  9. package/.agents/commands/codex/spec-update.md +40 -0
  10. package/.agents/commands/common/branch-review.md +117 -0
  11. package/.agents/commands/common/project-init.md +25 -0
  12. package/.agents/commands/common/spec-continue.md +74 -0
  13. package/.agents/commands/common/spec-orchestrate.md +35 -0
  14. package/.agents/commands/common/spec-start-review.md +82 -0
  15. package/.agents/commands/common/spec-start.md +67 -0
  16. package/.agents/commands/common/spec-status.md +22 -0
  17. package/.agents/commands/common/spec-stop.md +29 -0
  18. package/.agents/commands/common/spec-update.md +40 -0
  19. package/.agents/commands/cursor/opsx-apply.md +55 -0
  20. package/.agents/commands/cursor/opsx-archive.md +48 -0
  21. package/.agents/commands/cursor/opsx-explore.md +45 -0
  22. package/.agents/commands/cursor/opsx-propose.md +59 -0
  23. package/.agents/commands/cursor/spec-continue.md +63 -0
  24. package/.agents/commands/cursor/spec-orchestrate.md +53 -0
  25. package/.agents/commands/cursor/spec-start-review.md +78 -0
  26. package/.agents/commands/cursor/spec-start.md +59 -0
  27. package/.agents/commands/cursor/spec-status.md +30 -0
  28. package/.agents/commands/cursor/spec-stop.md +29 -0
  29. package/.agents/commands/cursor/spec-update.md +41 -0
  30. package/.agents/flows/FRONTMATTER.md +263 -0
  31. package/.agents/flows/RUN_OUTPUT.md +263 -0
  32. package/.agents/flows/common/README.md +29 -0
  33. package/.agents/flows/common/bugfix-to-verification.md +95 -0
  34. package/.agents/flows/common/change-to-architecture-review.md +89 -0
  35. package/.agents/flows/common/change-to-release.md +94 -0
  36. package/.agents/flows/common/prd-to-delivery.md +184 -0
  37. package/.agents/flows/common/requirement-to-observability.md +97 -0
  38. package/.agents/orchestration/README.md +22 -0
  39. package/.agents/orchestration/expert-dispatch-spec.md +155 -0
  40. package/.agents/orchestration/expert-executor-spec.md +84 -0
  41. package/.agents/orchestration/expert-runtime-action-spec.md +73 -0
  42. package/.agents/orchestration/runtime-state-handoff-spec.md +264 -0
  43. package/.agents/orchestration/task-anchor-spec.md +212 -0
  44. package/.agents/orchestration/task-orchestrator-adapter-payload.md +153 -0
  45. package/.agents/orchestration/task-orchestrator-bootstrap-payload.md +145 -0
  46. package/.agents/orchestration/task-orchestrator-output-extractor-spec.md +93 -0
  47. package/.agents/orchestration/task-orchestrator-run-plan-template.md +312 -0
  48. package/.agents/orchestration/task-orchestrator-runtime-hooks.md +214 -0
  49. package/.agents/registry/README.md +63 -0
  50. package/.agents/registry/flows.json +125 -0
  51. package/.agents/registry/profiles.json +101 -0
  52. package/.agents/registry/roles.json +1266 -0
  53. package/.agents/registry/rules.json +148 -0
  54. package/.agents/registry/scenario-packages.json +123 -0
  55. package/.agents/registry/skills.json +130 -0
  56. package/.agents/roles/INDEX.md +346 -0
  57. package/.agents/roles/common/README.md +76 -0
  58. package/.agents/roles/common/archive-change.md +80 -0
  59. package/.agents/roles/common/backend-implementer.md +92 -0
  60. package/.agents/roles/common/code-guardian.md +151 -0
  61. package/.agents/roles/common/frontend-implementer.md +146 -0
  62. package/.agents/roles/common/requirement-analyst.md +138 -0
  63. package/.agents/roles/common/task-orchestrator-routing.md +301 -0
  64. package/.agents/roles/common/task-orchestrator.md +224 -0
  65. package/.agents/roles/common/tooling-implementer.md +92 -0
  66. package/.agents/roles/domains/README.md +35 -0
  67. package/.agents/roles/domains/delivery/README.md +11 -0
  68. package/.agents/roles/domains/delivery/container-specialist.md +50 -0
  69. package/.agents/roles/domains/delivery/deployment-specialist.md +50 -0
  70. package/.agents/roles/domains/delivery/pipeline-specialist.md +50 -0
  71. package/.agents/roles/domains/demand-design/README.md +16 -0
  72. package/.agents/roles/domains/demand-design/api-contract-specialist.md +52 -0
  73. package/.agents/roles/domains/demand-design/design-collaborator.md +58 -0
  74. package/.agents/roles/domains/documentation/README.md +11 -0
  75. package/.agents/roles/domains/documentation/api-doc-specialist.md +50 -0
  76. package/.agents/roles/domains/documentation/component-doc-specialist.md +49 -0
  77. package/.agents/roles/domains/documentation/technical-writing-specialist.md +48 -0
  78. package/.agents/roles/domains/engineering/README.md +17 -0
  79. package/.agents/roles/domains/engineering/architecture-advisor.md +53 -0
  80. package/.agents/roles/domains/engineering/build-specialist.md +51 -0
  81. package/.agents/roles/domains/engineering/dependency-governor.md +52 -0
  82. package/.agents/roles/domains/governance/README.md +17 -0
  83. package/.agents/roles/domains/governance/api-governance-specialist.md +51 -0
  84. package/.agents/roles/domains/governance/lint-policy-specialist.md +49 -0
  85. package/.agents/roles/domains/governance/route-governance-specialist.md +52 -0
  86. package/.agents/roles/domains/observability/README.md +11 -0
  87. package/.agents/roles/domains/observability/error-tracker.md +50 -0
  88. package/.agents/roles/domains/observability/event-instrumentation-specialist.md +51 -0
  89. package/.agents/roles/domains/observability/rum-analyst.md +50 -0
  90. package/.agents/roles/domains/performance/README.md +11 -0
  91. package/.agents/roles/domains/performance/asset-optimizer.md +50 -0
  92. package/.agents/roles/domains/performance/performance-auditor.md +56 -0
  93. package/.agents/roles/domains/performance/vitals-analyst.md +50 -0
  94. package/.agents/roles/domains/security-a11y/README.md +11 -0
  95. package/.agents/roles/domains/security-a11y/a11y-auditor.md +50 -0
  96. package/.agents/roles/domains/security-a11y/aria-specialist.md +51 -0
  97. package/.agents/roles/domains/security-a11y/security-reviewer.md +49 -0
  98. package/.agents/roles/domains/testing/README.md +12 -0
  99. package/.agents/roles/domains/testing/coverage-analyst.md +50 -0
  100. package/.agents/roles/domains/testing/e2e-test-specialist.md +51 -0
  101. package/.agents/roles/domains/testing/unit-test-specialist.md +56 -0
  102. package/.agents/roles/domains/testing/verification-reviewer.md +67 -0
  103. package/.agents/rules/README.md +87 -0
  104. package/.agents/rules/common/02-/347/274/226/347/240/201/350/247/204/350/214/203.md +45 -0
  105. package/.agents/rules/common/08-/351/200/232/347/224/250/347/272/246/346/235/237.md +63 -0
  106. package/.agents/rules/common/10-/346/226/207/346/241/243/350/247/204/350/214/203.md +101 -0
  107. package/.agents/rules/common/12-Superpowers/346/211/247/350/241/214/350/247/204/350/214/203.md +46 -0
  108. package/.agents/rules/common/14-/345/256/241/350/256/241/346/261/207/346/212/245/350/247/204/350/214/203.md +107 -0
  109. package/.agents/rules/common/15-visual-gate-wait.md +90 -0
  110. package/.agents/rules/profiles/nestjs/01-/351/241/271/347/233/256/346/246/202/350/277/260.md +27 -0
  111. package/.agents/rules/profiles/nestjs/03-/351/241/271/347/233/256/347/273/223/346/236/204.md +20 -0
  112. package/.agents/rules/profiles/nestjs/04-/346/250/241/345/235/227/347/273/223/346/236/204/350/247/204/350/214/203.md +24 -0
  113. package/.agents/rules/profiles/nestjs/05-/346/216/245/345/217/243/344/270/216/345/245/221/347/272/246/350/247/204/350/214/203.md +24 -0
  114. package/.agents/rules/profiles/nestjs/06-/346/225/260/346/215/256/350/256/277/351/227/256/350/247/204/350/214/203.md +24 -0
  115. package/.agents/rules/profiles/nestjs/07-/351/205/215/347/275/256/344/270/216/350/277/220/350/241/214/346/227/266/350/247/204/350/214/203.md +20 -0
  116. package/.agents/rules/profiles/nestjs/09-/345/274/202/345/270/270/344/270/216/346/227/245/345/277/227/350/247/204/350/214/203.md +20 -0
  117. package/.agents/rules/profiles/nestjs/11-/346/265/213/350/257/225/350/247/204/350/214/203.md +24 -0
  118. package/.agents/rules/profiles/nestjs/13-/344/273/243/347/240/201/346/240/274/345/274/217/345/214/226/344/270/216/346/243/200/346/237/245.md +20 -0
  119. package/.agents/rules/profiles/node-tooling/01-/351/241/271/347/233/256/346/246/202/350/277/260.md +30 -0
  120. package/.agents/rules/profiles/node-tooling/03-/351/241/271/347/233/256/347/273/223/346/236/204.md +37 -0
  121. package/.agents/rules/profiles/node-tooling/04-CLI/344/270/216/346/250/241/345/235/227/350/247/204/350/214/203.md +42 -0
  122. package/.agents/rules/profiles/node-tooling/05-Contract/344/270/216Schema/350/247/204/350/214/203.md +42 -0
  123. package/.agents/rules/profiles/node-tooling/06-/350/277/220/350/241/214/346/227/266/346/226/207/344/273/266/350/247/204/350/214/203.md +30 -0
  124. package/.agents/rules/profiles/node-tooling/07-/346/227/245/345/277/227/344/270/216/351/224/231/350/257/257/345/244/204/347/220/206/350/247/204/350/214/203.md +60 -0
  125. package/.agents/rules/profiles/node-tooling/09-/350/204/232/346/234/254/344/270/216/345/205/245/345/217/243/350/247/204/350/214/203.md +45 -0
  126. package/.agents/rules/profiles/node-tooling/11-/346/265/213/350/257/225/350/247/204/350/214/203.md +41 -0
  127. package/.agents/rules/profiles/node-tooling/13-/344/273/243/347/240/201/346/240/274/345/274/217/345/214/226/344/270/216/346/243/200/346/237/245.md +55 -0
  128. package/.agents/rules/profiles/react/01-/351/241/271/347/233/256/346/246/202/350/277/260.md +29 -0
  129. package/.agents/rules/profiles/react/03-/351/241/271/347/233/256/347/273/223/346/236/204.md +104 -0
  130. package/.agents/rules/profiles/react/04-/347/273/204/344/273/266/350/247/204/350/214/203.md +46 -0
  131. package/.agents/rules/profiles/react/05-API/350/247/204/350/214/203.md +67 -0
  132. package/.agents/rules/profiles/react/06-/350/267/257/347/224/261/350/247/204/350/214/203.md +54 -0
  133. package/.agents/rules/profiles/react/07-/347/212/266/346/200/201/347/256/241/347/220/206.md +226 -0
  134. package/.agents/rules/profiles/react/09-/346/240/267/345/274/217/350/247/204/350/214/203.md +71 -0
  135. package/.agents/rules/profiles/react/11-/346/265/213/350/257/225/350/247/204/350/214/203.md +80 -0
  136. package/.agents/rules/profiles/react/13-/344/273/243/347/240/201/346/240/274/345/274/217/345/214/226/344/270/216/346/243/200/346/237/245.md +159 -0
  137. package/.agents/rules/profiles/springboot/01-/351/241/271/347/233/256/346/246/202/350/277/260.md +31 -0
  138. package/.agents/rules/profiles/springboot/03-/351/241/271/347/233/256/347/273/223/346/236/204.md +37 -0
  139. package/.agents/rules/profiles/springboot/04-/345/210/206/345/261/202/350/247/204/350/214/203.md +33 -0
  140. package/.agents/rules/profiles/springboot/05-/346/216/245/345/217/243/344/270/216/345/245/221/347/272/246/350/247/204/350/214/203.md +51 -0
  141. package/.agents/rules/profiles/springboot/06-/346/225/260/346/215/256/350/256/277/351/227/256/350/247/204/350/214/203.md +34 -0
  142. package/.agents/rules/profiles/springboot/07-/351/205/215/347/275/256/344/270/216/350/277/220/350/241/214/346/227/266/350/247/204/350/214/203.md +38 -0
  143. package/.agents/rules/profiles/springboot/09-/345/274/202/345/270/270/344/270/216/346/227/245/345/277/227/350/247/204/350/214/203.md +48 -0
  144. package/.agents/rules/profiles/springboot/11-/346/265/213/350/257/225/350/247/204/350/214/203.md +43 -0
  145. package/.agents/rules/profiles/springboot/13-/344/273/243/347/240/201/346/240/274/345/274/217/345/214/226/344/270/216/346/243/200/346/237/245.md +48 -0
  146. package/.agents/rules/profiles/vue/01-/351/241/271/347/233/256/346/246/202/350/277/260.md +47 -0
  147. package/.agents/rules/profiles/vue/03-/351/241/271/347/233/256/347/273/223/346/236/204.md +106 -0
  148. package/.agents/rules/profiles/vue/04-/347/273/204/344/273/266/350/247/204/350/214/203.md +61 -0
  149. package/.agents/rules/profiles/vue/05-API/350/247/204/350/214/203.md +67 -0
  150. package/.agents/rules/profiles/vue/06-/350/267/257/347/224/261/350/247/204/350/214/203.md +69 -0
  151. package/.agents/rules/profiles/vue/07-/347/212/266/346/200/201/347/256/241/347/220/206.md +93 -0
  152. package/.agents/rules/profiles/vue/09-/346/240/267/345/274/217/350/247/204/350/214/203.md +67 -0
  153. package/.agents/rules/profiles/vue/11-/346/265/213/350/257/225/350/247/204/350/214/203.md +80 -0
  154. package/.agents/rules/profiles/vue/13-/344/273/243/347/240/201/346/240/274/345/274/217/345/214/226/344/270/216/346/243/200/346/237/245.md +159 -0
  155. package/.agents/skills/README.md +171 -0
  156. package/.agents/skills/common/archive-change/SKILL.md +180 -0
  157. package/.agents/skills/common/branch-code-reviewer/SKILL.md +459 -0
  158. package/.agents/skills/common/branch-code-reviewer/references/business-risk-guide.md +293 -0
  159. package/.agents/skills/common/branch-code-reviewer/references/html-template-guide.md +121 -0
  160. package/.agents/skills/common/config-and-secret-scan/SKILL.md +99 -0
  161. package/.agents/skills/common/create-proposal/SKILL.md +192 -0
  162. package/.agents/skills/common/create-proposal/evals/evals.json +16 -0
  163. package/.agents/skills/common/create-proposal/evals/train_queries.json +18 -0
  164. package/.agents/skills/common/create-proposal/evals/validation_queries.json +18 -0
  165. package/.agents/skills/common/create-proposal/references/interaction-spec-template.md +42 -0
  166. package/.agents/skills/common/create-test/SKILL.md +292 -0
  167. package/.agents/skills/common/dependency-impact-graph/SKILL.md +80 -0
  168. package/.agents/skills/common/execute-task/SKILL.md +206 -0
  169. package/.agents/skills/common/execute-task/evals/evals.json +16 -0
  170. package/.agents/skills/common/execute-task/evals/train_queries.json +18 -0
  171. package/.agents/skills/common/execute-task/evals/validation_queries.json +18 -0
  172. package/.agents/skills/common/find-skills/SKILL.md +144 -0
  173. package/.agents/skills/common/install-ai-spec-auto/SKILL.md +260 -0
  174. package/.agents/skills/common/install-ai-spec-auto/evals/evals.json +17 -0
  175. package/.agents/skills/common/install-ai-spec-auto/evals/train_queries.json +18 -0
  176. package/.agents/skills/common/install-ai-spec-auto/evals/validation_queries.json +18 -0
  177. package/.agents/skills/common/project-init/SKILL.md +178 -0
  178. package/.agents/skills/common/project-init/evals/evals.json +16 -0
  179. package/.agents/skills/common/project-init/evals/train_queries.json +18 -0
  180. package/.agents/skills/common/project-init/evals/validation_queries.json +18 -0
  181. package/.agents/skills/common/project-init/references/custom-rule-generation.md +89 -0
  182. package/.agents/skills/common/project-init/references/deep-scan-rules.md +67 -0
  183. package/.agents/skills/common/project-init/references/output-contracts.md +71 -0
  184. package/.agents/skills/common/project-init/references/repo-fact-gathering.md +83 -0
  185. package/.agents/skills/common/project-init/references/scope-resolution.md +76 -0
  186. package/.agents/skills/common/project-init/scripts/inspect-project.js +112 -0
  187. package/.agents/skills/common/skill-creator/LICENSE.txt +202 -0
  188. package/.agents/skills/common/skill-creator/SKILL.md +370 -0
  189. package/.agents/skills/common/skill-creator/evals/evals.json +16 -0
  190. package/.agents/skills/common/skill-creator/evals/train_queries.json +18 -0
  191. package/.agents/skills/common/skill-creator/evals/validation_queries.json +18 -0
  192. package/.agents/skills/common/skill-creator/references/output-patterns.md +82 -0
  193. package/.agents/skills/common/skill-creator/references/workflows.md +28 -0
  194. package/.agents/skills/common/skill-creator/scripts/init_skill.py +209 -0
  195. package/.agents/skills/common/skill-creator/scripts/package_skill.py +110 -0
  196. package/.agents/skills/common/skill-creator/scripts/quick_validate.py +51 -0
  197. package/.agents/skills/common/skill-optimizer/SKILL.md +102 -0
  198. package/.agents/skills/common/skill-optimizer/evals/evals.json +16 -0
  199. package/.agents/skills/common/skill-optimizer/evals/train_queries.json +18 -0
  200. package/.agents/skills/common/skill-optimizer/evals/validation_queries.json +18 -0
  201. package/.agents/skills/common/skill-optimizer/references/design-patterns.md +26 -0
  202. package/.agents/skills/common/skill-optimizer/references/review-checklist.md +22 -0
  203. package/.agents/skills/common/using-superpowers/SKILL.md +151 -0
  204. package/.agents/skills/common/wait-for-gate-signal/SKILL.md +85 -0
  205. package/.agents/skills/domains/README.md +19 -0
  206. package/.agents/skills/domains/ui-ux-pro-max/SKILL.md +58 -0
  207. package/.agents/skills/domains/web/design-analysis/SKILL.md +89 -0
  208. package/.agents/skills/domains/web/design-analysis/rules/analysis-order.md +61 -0
  209. package/.agents/skills/domains/web/design-analysis/rules/analysis-priorities.md +136 -0
  210. package/.agents/skills/domains/web/design-analysis/rules/checklist-common-misses.md +107 -0
  211. package/.agents/skills/domains/web/design-analysis/rules/implementation-common-errors.md +204 -0
  212. package/.agents/skills/domains/web/design-analysis/rules/implementation-guidelines.md +211 -0
  213. package/.agents/skills/domains/web/design-analysis/rules/output-analysis-checklist.md +247 -0
  214. package/.agents/skills/domains/web/design-analysis/rules/tools-design-guidelines.md +108 -0
  215. package/.agents/skills/domains/web/design-analysis/rules/workflow-element-extraction.md +162 -0
  216. package/.agents/skills/domains/web/design-analysis/rules/workflow-layout-map.md +131 -0
  217. package/.agents/skills/domains/web/design-analysis/rules/workflow-output-checklist.md +70 -0
  218. package/.agents/skills/domains/web/design-analysis/rules/workflow-style-summary.md +91 -0
  219. package/.agents/skills/domains/web/route-permission-map/SKILL.md +103 -0
  220. package/.agents/skills/domains/web/ui-verification/SKILL.md +114 -0
  221. package/.agents/skills/domains/web/ui-verification/evals/evals.json +16 -0
  222. package/.agents/skills/domains/web/ui-verification/evals/train_queries.json +18 -0
  223. package/.agents/skills/domains/web/ui-verification/evals/validation_queries.json +18 -0
  224. package/.agents/skills/domains/web/ui-verification/rules/comparison-content-image.md +34 -0
  225. package/.agents/skills/domains/web/ui-verification/rules/comparison-content-text.md +30 -0
  226. package/.agents/skills/domains/web/ui-verification/rules/comparison-hierarchy.md +33 -0
  227. package/.agents/skills/domains/web/ui-verification/rules/comparison-layout.md +35 -0
  228. package/.agents/skills/domains/web/ui-verification/rules/errors-alignment.md +42 -0
  229. package/.agents/skills/domains/web/ui-verification/rules/errors-button-dimensions.md +28 -0
  230. package/.agents/skills/domains/web/ui-verification/rules/errors-button-position.md +25 -0
  231. package/.agents/skills/domains/web/ui-verification/rules/errors-css-priority.md +50 -0
  232. package/.agents/skills/domains/web/ui-verification/rules/errors-flex-column-width.md +46 -0
  233. package/.agents/skills/domains/web/ui-verification/rules/errors-flex-layout.md +46 -0
  234. package/.agents/skills/domains/web/ui-verification/rules/errors-grid-container-width.md +44 -0
  235. package/.agents/skills/domains/web/ui-verification/rules/errors-page-container-width.md +39 -0
  236. package/.agents/skills/domains/web/ui-verification/rules/tools-browser-navigation.md +53 -0
  237. package/.agents/skills/domains/web/ui-verification/rules/tools-design-guidelines.md +53 -0
  238. package/.agents/skills/domains/web/ui-verification/rules/workflow-checklist.md +27 -0
  239. package/.agents/skills/domains/web/ui-verification/rules/workflow-problem-list.md +56 -0
  240. package/.agents/skills/domains/web/ui-verification/rules/workflow-reflection.md +44 -0
  241. package/.agents/skills/domains/web/ui-verification/rules/writing-alignment.md +44 -0
  242. package/.agents/skills/domains/web/ui-verification/rules/writing-element-completeness.md +63 -0
  243. package/.agents/skills/domains/web/ui-verification/rules/writing-list-layout.md +75 -0
  244. package/.agents/skills/domains/web/ui-verification/rules/writing-page-container-width.md +37 -0
  245. package/.agents/skills/domains/web/web-design-guidelines/SKILL.md +40 -0
  246. package/.agents/skills/profiles/nestjs/README.md +4 -0
  247. package/.agents/skills/profiles/node-tooling/README.md +9 -0
  248. package/.agents/skills/profiles/react/create-api/SKILL.md +145 -0
  249. package/.agents/skills/profiles/react/create-component/SKILL.md +160 -0
  250. package/.agents/skills/profiles/react/create-route/SKILL.md +168 -0
  251. package/.agents/skills/profiles/react/create-store/SKILL.md +262 -0
  252. package/.agents/skills/profiles/react/theme-variables/SKILL.md +82 -0
  253. package/.agents/skills/profiles/react/vercel-composition-patterns/AGENTS.md +899 -0
  254. package/.agents/skills/profiles/react/vercel-composition-patterns/SKILL.md +81 -0
  255. package/.agents/skills/profiles/react/vercel-composition-patterns/rules/architecture-avoid-boolean-props.md +100 -0
  256. package/.agents/skills/profiles/react/vercel-composition-patterns/rules/architecture-compound-components.md +112 -0
  257. package/.agents/skills/profiles/react/vercel-composition-patterns/rules/patterns-children-over-render-props.md +87 -0
  258. package/.agents/skills/profiles/react/vercel-composition-patterns/rules/patterns-explicit-variants.md +100 -0
  259. package/.agents/skills/profiles/react/vercel-composition-patterns/rules/state-context-interface.md +191 -0
  260. package/.agents/skills/profiles/react/vercel-composition-patterns/rules/state-decouple-implementation.md +113 -0
  261. package/.agents/skills/profiles/react/vercel-composition-patterns/rules/state-lift-state.md +125 -0
  262. package/.agents/skills/profiles/react/vercel-react-best-practices/AGENTS.md +2934 -0
  263. package/.agents/skills/profiles/react/vercel-react-best-practices/SKILL.md +136 -0
  264. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/advanced-event-handler-refs.md +55 -0
  265. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/advanced-init-once.md +42 -0
  266. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/advanced-use-latest.md +39 -0
  267. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/async-api-routes.md +38 -0
  268. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/async-defer-await.md +80 -0
  269. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/async-dependencies.md +51 -0
  270. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/async-parallel.md +28 -0
  271. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/async-suspense-boundaries.md +99 -0
  272. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/bundle-barrel-imports.md +59 -0
  273. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/bundle-conditional.md +31 -0
  274. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/bundle-defer-third-party.md +49 -0
  275. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/bundle-dynamic-imports.md +35 -0
  276. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/bundle-preload.md +50 -0
  277. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/client-event-listeners.md +74 -0
  278. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/client-localstorage-schema.md +71 -0
  279. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/client-passive-event-listeners.md +48 -0
  280. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/client-swr-dedup.md +56 -0
  281. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-batch-dom-css.md +107 -0
  282. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-cache-function-results.md +80 -0
  283. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-cache-property-access.md +28 -0
  284. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-cache-storage.md +70 -0
  285. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-combine-iterations.md +32 -0
  286. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-early-exit.md +50 -0
  287. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-hoist-regexp.md +45 -0
  288. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-index-maps.md +37 -0
  289. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-length-check-first.md +49 -0
  290. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-min-max-loop.md +82 -0
  291. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-set-map-lookups.md +24 -0
  292. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-tosorted-immutable.md +57 -0
  293. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-activity.md +26 -0
  294. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
  295. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-conditional-render.md +40 -0
  296. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-content-visibility.md +38 -0
  297. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
  298. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
  299. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
  300. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-svg-precision.md +28 -0
  301. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-usetransition-loading.md +75 -0
  302. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-defer-reads.md +39 -0
  303. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-dependencies.md +45 -0
  304. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
  305. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-derived-state.md +29 -0
  306. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-functional-setstate.md +74 -0
  307. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
  308. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
  309. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-memo.md +44 -0
  310. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
  311. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
  312. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-transitions.md +40 -0
  313. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
  314. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-after-nonblocking.md +73 -0
  315. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-auth-actions.md +96 -0
  316. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-cache-lru.md +41 -0
  317. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-cache-react.md +76 -0
  318. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-dedup-props.md +65 -0
  319. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-parallel-fetching.md +83 -0
  320. package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-serialization.md +38 -0
  321. package/.agents/skills/profiles/springboot/README.md +10 -0
  322. package/.agents/skills/profiles/vue/create-api/SKILL.md +105 -0
  323. package/.agents/skills/profiles/vue/create-component/SKILL.md +76 -0
  324. package/.agents/skills/profiles/vue/create-route/SKILL.md +141 -0
  325. package/.agents/skills/profiles/vue/create-store/SKILL.md +97 -0
  326. package/.agents/skills/profiles/vue/create-view/SKILL.md +81 -0
  327. package/.agents/skills/profiles/vue/theme-variables/SKILL.md +73 -0
  328. package/.agents/skills/profiles/vue/vue-best-practices/SKILL.md +166 -0
  329. package/.agents/skills/profiles/vue/vue-best-practices/references/animation-class-based-technique.md +254 -0
  330. package/.agents/skills/profiles/vue/vue-best-practices/references/animation-state-driven-technique.md +291 -0
  331. package/.agents/skills/profiles/vue/vue-best-practices/references/component-async.md +97 -0
  332. package/.agents/skills/profiles/vue/vue-best-practices/references/component-data-flow.md +307 -0
  333. package/.agents/skills/profiles/vue/vue-best-practices/references/component-fallthrough-attrs.md +174 -0
  334. package/.agents/skills/profiles/vue/vue-best-practices/references/component-keep-alive.md +137 -0
  335. package/.agents/skills/profiles/vue/vue-best-practices/references/component-slots.md +216 -0
  336. package/.agents/skills/profiles/vue/vue-best-practices/references/component-suspense.md +228 -0
  337. package/.agents/skills/profiles/vue/vue-best-practices/references/component-teleport.md +108 -0
  338. package/.agents/skills/profiles/vue/vue-best-practices/references/component-transition-group.md +128 -0
  339. package/.agents/skills/profiles/vue/vue-best-practices/references/component-transition.md +125 -0
  340. package/.agents/skills/profiles/vue/vue-best-practices/references/composables.md +290 -0
  341. package/.agents/skills/profiles/vue/vue-best-practices/references/directives.md +162 -0
  342. package/.agents/skills/profiles/vue/vue-best-practices/references/perf-avoid-component-abstraction-in-lists.md +159 -0
  343. package/.agents/skills/profiles/vue/vue-best-practices/references/perf-v-once-v-memo-directives.md +182 -0
  344. package/.agents/skills/profiles/vue/vue-best-practices/references/perf-virtualize-large-lists.md +187 -0
  345. package/.agents/skills/profiles/vue/vue-best-practices/references/plugins.md +166 -0
  346. package/.agents/skills/profiles/vue/vue-best-practices/references/reactivity.md +344 -0
  347. package/.agents/skills/profiles/vue/vue-best-practices/references/render-functions.md +201 -0
  348. package/.agents/skills/profiles/vue/vue-best-practices/references/sfc.md +310 -0
  349. package/.agents/skills/profiles/vue/vue-best-practices/references/state-management.md +135 -0
  350. package/.agents/skills/profiles/vue/vue-best-practices/references/updated-hook-performance.md +187 -0
  351. package/.agents/templates/common/README.md +23 -0
  352. package/.agents/templates/common/bugfix.md +22 -0
  353. package/.agents/templates/common/create-expert-package.md +458 -0
  354. package/.agents/templates/common/mock-page.md +28 -0
  355. package/.agents/templates/common/new-component.md +25 -0
  356. package/.agents/templates/common/new-page.md +31 -0
  357. package/.cursor/mcp.json +36 -0
  358. package/.qoder/README.md +114 -0
  359. package/.qoder/commands +1 -0
  360. package/.qoder/mcp.json +26 -0
  361. package/.qoder/rules +1 -0
  362. package/.qoder/skills +1 -0
  363. package/LICENSE +21 -0
  364. package/README.md +433 -0
  365. package/bin/archive-change.js +474 -0
  366. package/bin/check-command.js +62 -0
  367. package/bin/cli.js +295 -0
  368. package/bin/command-template-renderer.js +40 -0
  369. package/bin/context-command.js +102 -0
  370. package/bin/demo-runtime-smoke.js +760 -0
  371. package/bin/execution-semantics.js +821 -0
  372. package/bin/executor-command.js +93 -0
  373. package/bin/expert-dispatch.js +334 -0
  374. package/bin/expert-executor.js +1148 -0
  375. package/bin/guard-command.js +52 -0
  376. package/bin/hub-command.js +876 -0
  377. package/bin/ide-command.js +242 -0
  378. package/bin/init-command.js +193 -0
  379. package/bin/install-workflow.js +2983 -0
  380. package/bin/manifest-export.js +34 -0
  381. package/bin/profile-registry.js +90 -0
  382. package/bin/protocol-workflow.js +446 -0
  383. package/bin/repair-command.js +161 -0
  384. package/bin/repo-map.js +177 -0
  385. package/bin/report-command.js +236 -0
  386. package/bin/runtime-bootstrap.js +428 -0
  387. package/bin/runtime-embedded.js +101 -0
  388. package/bin/runtime-fallback.js +106 -0
  389. package/bin/runtime-launcher.js +116 -0
  390. package/bin/runtime-paths.js +177 -0
  391. package/bin/runtime-registry.js +289 -0
  392. package/bin/runtime-state.js +2541 -0
  393. package/bin/scan.js +96 -0
  394. package/bin/self-upgrade.js +206 -0
  395. package/bin/skill-spec-validator.js +457 -0
  396. package/bin/spec-command.js +366 -0
  397. package/bin/superpowers.js +384 -0
  398. package/bin/sync-command.js +59 -0
  399. package/bin/sync.js +1904 -0
  400. package/bin/task-orchestrator-adapter.js +341 -0
  401. package/bin/task-orchestrator-extractor.js +274 -0
  402. package/bin/task-orchestrator-runner.js +1208 -0
  403. package/bin/telemetry/README.md +66 -0
  404. package/bin/telemetry/aspect.js +153 -0
  405. package/bin/telemetry/collect.js +67 -0
  406. package/bin/telemetry/config.js +114 -0
  407. package/bin/telemetry/defaults.json +5 -0
  408. package/bin/telemetry/healthcheck.js +195 -0
  409. package/bin/telemetry/identity.js +53 -0
  410. package/bin/telemetry/index.js +25 -0
  411. package/bin/telemetry/reporter.js +83 -0
  412. package/bin/telemetry/safe.js +39 -0
  413. package/bin/validate-registry.js +740 -0
  414. package/bin/visual-bridge-config.js +117 -0
  415. package/bin/visual-bridge.js +287 -0
  416. package/bin/visual-command.js +432 -0
  417. package/bin/worktree-command.js +194 -0
  418. package/configs/common/.editorconfig +15 -0
  419. package/configs/common/.husky/commit-msg +4 -0
  420. package/configs/common/.husky/pre-commit +4 -0
  421. package/configs/common/.lintstagedrc +11 -0
  422. package/configs/common/.prettierignore +11 -0
  423. package/configs/common/.prettierrc.json +11 -0
  424. package/configs/common/.stylelintignore +14 -0
  425. package/configs/common/.stylelintrc.json +21 -0
  426. package/configs/common/commitlint.config.js +3 -0
  427. package/configs/profiles/nestjs/.gitkeep +1 -0
  428. package/configs/profiles/node-tooling/.gitkeep +1 -0
  429. package/configs/profiles/react/.eslintignore +6 -0
  430. package/configs/profiles/react/.eslintrc.js +16 -0
  431. package/configs/profiles/react/.stylelintrc.json +18 -0
  432. package/configs/profiles/springboot/.gitkeep +1 -0
  433. package/configs/profiles/vue/.eslintignore +7 -0
  434. package/configs/profiles/vue/.eslintrc.cjs +17 -0
  435. package/contracts/README.md +28 -0
  436. package/contracts/fixtures/asset-package.fixture.json +26 -0
  437. package/contracts/fixtures/asset-usage-feedback.fixture.json +14 -0
  438. package/contracts/fixtures/evidence-report.fixture.json +28 -0
  439. package/contracts/fixtures/manifest.fixture.json +20 -0
  440. package/contracts/fixtures/run-event.fixture.json +15 -0
  441. package/contracts/schemas/asset-package.schema.json +76 -0
  442. package/contracts/schemas/asset-usage-feedback.schema.json +57 -0
  443. package/contracts/schemas/evidence-report.schema.json +60 -0
  444. package/contracts/schemas/manifest.schema.json +63 -0
  445. package/contracts/schemas/run-event.schema.json +72 -0
  446. package/install.ps1 +35 -0
  447. package/install.sh +17 -0
  448. package/internal/ai-protocol-workflow.js +5600 -0
  449. package/internal/hub-client.js +98 -0
  450. package/internal/hub-sync-selection.js +69 -0
  451. package/internal/visual-hooks/README.md +481 -0
  452. package/internal/visual-hooks/config-loader.js +218 -0
  453. package/internal/visual-hooks/control-puller.js +206 -0
  454. package/internal/visual-hooks/gate-signal.js +150 -0
  455. package/internal/visual-hooks/inbox-consumer.js +469 -0
  456. package/internal/visual-hooks/index.js +197 -0
  457. package/internal/visual-hooks/push-client.js +189 -0
  458. package/internal/visual-hooks/receipt-pusher.js +176 -0
  459. package/internal/visual-hooks/runtime-state-pusher.js +128 -0
  460. package/openspec/changes/.gitkeep +0 -0
  461. package/openspec/changes/archive/.gitkeep +0 -0
  462. package/openspec/config.yaml.template +52 -0
  463. package/openspec/schemas/expert-delivery/schema.yaml +68 -0
  464. package/openspec/schemas/expert-delivery/templates/checklist.md +39 -0
  465. package/openspec/schemas/expert-delivery/templates/design.md +61 -0
  466. package/openspec/schemas/expert-delivery/templates/iterations.md +25 -0
  467. package/openspec/schemas/expert-delivery/templates/proposal.md +45 -0
  468. package/openspec/schemas/expert-delivery/templates/spec.md +29 -0
  469. package/openspec/schemas/expert-delivery/templates/tasks.md +24 -0
  470. package/openspec/specs/.gitkeep +0 -0
  471. package/package.json +73 -0
  472. package/scripts/acceptance-zero-intrusion.sh +168 -0
  473. package/scripts/hub-sync-assets.config.example.json +296 -0
  474. package/scripts/hub-sync-assets.js +2038 -0
  475. package/scripts/local-verify.sh +280 -0
  476. package/scripts/post-publish-auto-fix-check.js +404 -0
  477. package/scripts/post-publish-verify.sh +175 -0
  478. package/scripts/setup-cursor-manual-test.sh +107 -0
  479. package/scripts/setup-cursor-spec-archive-test.sh +111 -0
  480. package/scripts/setup-visual-integration.sh +225 -0
  481. package/scripts/test-integration.sh +176 -0
  482. package/scripts/update-test-project.sh +93 -0
  483. package/scripts/upload-four-web.sh +57 -0
  484. package/scripts/verify-install-ps1-bom.js +26 -0
  485. package/src/agent/agent-context.js +259 -0
  486. package/src/agent/agent-profile.js +185 -0
  487. package/src/agent/agent-templates.js +161 -0
  488. package/src/agent/agent-types.js +108 -0
  489. package/src/agent/collaboration-protocol.js +333 -0
  490. package/src/agent/conflict-handler.js +364 -0
  491. package/src/agent/file-permission.js +121 -0
  492. package/src/agent/index.js +38 -0
  493. package/src/agent/permission-audit.js +151 -0
  494. package/src/agent/review-repair-loop.js +270 -0
  495. package/src/agent/tool-permission.js +101 -0
  496. package/src/asset/asset-dependency.js +322 -0
  497. package/src/asset/asset-feedback.js +350 -0
  498. package/src/asset/asset-fork.js +300 -0
  499. package/src/asset/asset-install.js +278 -0
  500. package/src/asset/asset-installer.js +497 -0
  501. package/src/asset/asset-lifecycle.js +324 -0
  502. package/src/asset/asset-manager.js +245 -0
  503. package/src/asset/asset-package-manager.js +349 -0
  504. package/src/asset/asset-package.js +186 -0
  505. package/src/asset/asset-quality.js +262 -0
  506. package/src/asset/asset-registry.js +387 -0
  507. package/src/asset/asset-version.js +293 -0
  508. package/src/asset/index.js +86 -0
  509. package/src/cache/agent-profile-cache.js +59 -0
  510. package/src/cache/asset-cache.js +63 -0
  511. package/src/cache/global-cache.js +61 -0
  512. package/src/cache/manifest-cache.js +30 -0
  513. package/src/check/check-service.js +32 -0
  514. package/src/config/config-layer.js +343 -0
  515. package/src/config/config-loader.js +60 -0
  516. package/src/config/defaults.js +49 -0
  517. package/src/connectors/hub/asset-package.js +72 -0
  518. package/src/connectors/hub/asset-usage-feedback.js +46 -0
  519. package/src/connectors/hub/hub-connector.js +44 -0
  520. package/src/connectors/hub/index.js +21 -0
  521. package/src/connectors/visual/evidence-report.js +49 -0
  522. package/src/connectors/visual/index.js +15 -0
  523. package/src/connectors/visual/queue.js +41 -0
  524. package/src/connectors/visual/run-event.js +81 -0
  525. package/src/connectors/visual/visual-connector.js +77 -0
  526. package/src/context/context-budget.js +59 -0
  527. package/src/context/context-builder.js +285 -0
  528. package/src/context/context-loader.js +116 -0
  529. package/src/context/context-planner.js +158 -0
  530. package/src/context/types.js +96 -0
  531. package/src/contracts/index.js +63 -0
  532. package/src/executor/executor-registry.js +78 -0
  533. package/src/executor/executor-result-parser.js +44 -0
  534. package/src/executor/executor-runner.js +141 -0
  535. package/src/executor/executor-selector.js +139 -0
  536. package/src/executor/executor-timeout.js +36 -0
  537. package/src/executor/providers/base-provider-utils.js +189 -0
  538. package/src/executor/providers/claude-code-executor-provider.js +128 -0
  539. package/src/executor/providers/codex-executor-provider.js +126 -0
  540. package/src/executor/providers/cursor-executor-provider.js +99 -0
  541. package/src/executor/types.js +137 -0
  542. package/src/git/branch-manager.js +71 -0
  543. package/src/git/dirty-checker.js +43 -0
  544. package/src/git/dirty-strategy-handler.js +29 -0
  545. package/src/git/git-command.js +37 -0
  546. package/src/git/git-repository-detector.js +45 -0
  547. package/src/git/multi-repo-worktree-planner.js +88 -0
  548. package/src/git/policy.js +19 -0
  549. package/src/git/strategies/block-dirty-strategy.js +34 -0
  550. package/src/git/strategies/ignore-dirty-strategy.js +33 -0
  551. package/src/git/strategies/patch-snapshot-strategy.js +53 -0
  552. package/src/git/strategies/wip-commit-strategy.js +38 -0
  553. package/src/git/types.js +71 -0
  554. package/src/git/worktree-manager.js +85 -0
  555. package/src/governance/asset-review.js +351 -0
  556. package/src/governance/audit-log.js +368 -0
  557. package/src/governance/gray-release.js +312 -0
  558. package/src/governance/index.js +31 -0
  559. package/src/governance/policy-types.js +56 -0
  560. package/src/governance/rbac-types.js +171 -0
  561. package/src/governance/rbac.js +382 -0
  562. package/src/governance/rollback.js +360 -0
  563. package/src/governance/security-policy.js +354 -0
  564. package/src/hook/hook-config-writer.js +125 -0
  565. package/src/hub/hub-client.js +186 -0
  566. package/src/hub/hub-config.js +39 -0
  567. package/src/hub/project-facts.js +31 -0
  568. package/src/hub/runtime-feedback-reporter.js +55 -0
  569. package/src/ide/adapters/adapter-protocol.js +385 -0
  570. package/src/ide/adapters/claude-adapter.js +419 -0
  571. package/src/ide/adapters/codex-adapter.js +60 -0
  572. package/src/ide/adapters/cursor-adapter.js +484 -0
  573. package/src/ide/adapters/index.js +24 -0
  574. package/src/ide/anchors/markdown-anchor-writer.js +152 -0
  575. package/src/ide/ide-service.js +270 -0
  576. package/src/ide/ide-types.js +94 -0
  577. package/src/ide/links/link-mode-resolver.js +160 -0
  578. package/src/ide/registry/ide-registry-builder.js +165 -0
  579. package/src/incident/incident-writer.js +47 -0
  580. package/src/incident/types.js +22 -0
  581. package/src/init/ide-linker.js +126 -0
  582. package/src/init/ide-pointer-injector.js +75 -0
  583. package/src/init/init-applier.js +197 -0
  584. package/src/init/init-plan.js +294 -0
  585. package/src/init/init-service.js +65 -0
  586. package/src/init/manifest-installer.js +302 -0
  587. package/src/init/types.js +26 -0
  588. package/src/project/config-writer.js +83 -0
  589. package/src/project/context-index-writer.js +82 -0
  590. package/src/project/json-utils.js +72 -0
  591. package/src/project/local-state-writer.js +50 -0
  592. package/src/project/lock-file-writer.js +98 -0
  593. package/src/project/manifest-writer.js +126 -0
  594. package/src/project/policy-config-writer.js +91 -0
  595. package/src/project/project-config-writer.js +74 -0
  596. package/src/project/project-files.js +39 -0
  597. package/src/project/registry-index-writer.js +43 -0
  598. package/src/project/workspace-config-writer.js +63 -0
  599. package/src/run/index.js +11 -0
  600. package/src/run/run-id.js +32 -0
  601. package/src/run/run-service.js +269 -0
  602. package/src/run/run-store.js +80 -0
  603. package/src/scanner/aggregator/detection-aggregator.js +23 -0
  604. package/src/scanner/boundary/boundary-resolver.js +229 -0
  605. package/src/scanner/detectors/detector-registry.js +44 -0
  606. package/src/scanner/detectors/fastapi-detector.js +46 -0
  607. package/src/scanner/detectors/go-detector.js +46 -0
  608. package/src/scanner/detectors/nestjs-detector.js +57 -0
  609. package/src/scanner/detectors/nextjs-detector.js +52 -0
  610. package/src/scanner/detectors/react-vite-detector.js +52 -0
  611. package/src/scanner/detectors/react-webpack-detector.js +57 -0
  612. package/src/scanner/detectors/springboot-detector.js +46 -0
  613. package/src/scanner/detectors/springcloud-detector.js +46 -0
  614. package/src/scanner/detectors/springmvc-detector.js +46 -0
  615. package/src/scanner/detectors/vue-vite-detector.js +52 -0
  616. package/src/scanner/engine.js +72 -0
  617. package/src/scanner/facts/fact-extractor.js +211 -0
  618. package/src/scanner/types.js +30 -0
  619. package/src/security/asset-tamper-checker.js +188 -0
  620. package/src/security/checksum.js +40 -0
  621. package/src/spec/spec-writer.js +302 -0
  622. package/src/state-machine/circuit-breaker.js +112 -0
  623. package/src/state-machine/escape-hatch.js +49 -0
  624. package/src/state-machine/stage-runner.js +281 -0
  625. package/src/state-machine/state-machine.js +24 -0
  626. package/src/state-machine/transition-guard.js +36 -0
  627. package/src/state-machine/types.js +37 -0
  628. package/src/sync/sync-service.js +192 -0
  629. package/src/visual/agent-visual.js +142 -0
  630. package/src/visual/event-gateway.js +357 -0
  631. package/src/visual/event-mapper.js +128 -0
  632. package/src/visual/hook-dashboard.js +216 -0
  633. package/src/visual/index.js +27 -0
  634. package/src/visual/metrics.js +287 -0
  635. package/src/visual/privacy-filter.js +100 -0
  636. package/src/visual/risk-board.js +252 -0
  637. package/src/visual/timeline.js +245 -0
  638. package/src/visual/visual-client.js +94 -0
  639. package/src/visual/visual-config.js +40 -0
  640. package/src/visual/visual-reporter.js +88 -0
@@ -0,0 +1,66 @@
1
+ # bin/telemetry
2
+
3
+ 可选的匿名遥测切面(aspect),用于向 `br-ai-spec-visual` 上报 CLI 安装与使用情况。
4
+
5
+ ## 设计原则
6
+
7
+ - **零侵入**:主流程 (`bin/cli.js`、`bin/install-workflow.js` 等) 不依赖本目录。删除整个 `bin/telemetry/` 目录后 CLI 仍可正常工作。
8
+ - **降级四重保护**:
9
+ 1. `bin/cli.js` 中 `require('./telemetry')` 失败 → 使用透明 wrap,不上报。
10
+ 2. `index.js` 再次 try/catch 保护,阻止任何异常冒泡。
11
+ 3. **健康探测兜底**:上报前先 `HEAD /api/health`(500ms 超时),目标不可达直接跳过本次所有上报;探测失败时间记入本地缓存,60 秒冷却窗口内的后续 CLI 调用直接跳过探测。
12
+ 4. 网络上报 fire-and-forget + `AbortController(2000ms)`,绝不阻塞 `process.exit`。
13
+ - **可选依赖**:`node-machine-id` 放在 `optionalDependencies`,缺失时用纯 Node `os` 模块 + `sha256` 兜底。
14
+ - **用户可关闭**:`AI_SPEC_TELEMETRY_DISABLED=1` 禁用;`AI_SPEC_VISUAL_URL` 未设置时不发网络请求。
15
+
16
+ ## 文件
17
+
18
+ | 文件 | 作用 |
19
+ | --- | --- |
20
+ | `index.js` | 对外唯一入口,导出 `wrap(command, fn)`。 |
21
+ | `aspect.js` | 切面实现:在命令前后异步上报 started / success / failed。 |
22
+ | `reporter.js` | REST / WS 上报;AbortController + 超时 + 静默失败。 |
23
+ | `identity.js` | 生成 installationId(node-machine-id → sha256(mac+user+host) 兜底)。 |
24
+ | `collect.js` | 收集非敏感字段(hostname/platform/node/cliVersion/projectHash/profile…)。 |
25
+ | `config.js` | 读取环境变量 + 用户配置 + 仓库默认,三层合并。 |
26
+ | `defaults.json` | 仓库内默认配置(仅 `visualUrl` / `disabled`,**禁止写入 secret**)。 |
27
+ | `healthcheck.js` | 发送前探测 `HEAD /api/health`(500ms 超时,进程内缓存,失败 60s 冷却)。 |
28
+ | `safe.js` | 统一兜底工具 (safeCall, safeRequire)。 |
29
+
30
+ ## 配置来源(优先级由高到低)
31
+
32
+ 1. **环境变量**(临时调试、CI 注入首选)
33
+ 2. **`~/.ai-spec-auto/config.json`**(用户主目录,个人本地覆盖,可存 secret)
34
+ 3. **`bin/telemetry/defaults.json`**(仓库默认,跟随 npm 包发布;**仅放公开字段**)
35
+
36
+ ### 可配置字段
37
+
38
+ | 字段 | 环境变量 | 用户配置 key | 仓库默认 | 说明 |
39
+ | --- | --- | --- | --- | --- |
40
+ | Visual 地址 | `AI_SPEC_VISUAL_URL` | `visualUrl` | `visualUrl` | 未设置/为空则不发请求 |
41
+ | 总开关 | `AI_SPEC_TELEMETRY_DISABLED=1` | `disabled: true` | `disabled` | 任一源为 true 即关闭 |
42
+ | 鉴权密钥 | `AI_SPEC_TELEMETRY_SECRET` | `secret` | **不支持** | 与服务端 `.env` 一致;仓库绝不写入 |
43
+ | 调试输出 | `AI_SPEC_TELEMETRY_DEBUG=1` | — | — | 仅环境变量,便于排查 |
44
+
45
+ ### 用户配置示例
46
+
47
+ ```jsonc
48
+ // ~/.ai-spec-auto/config.json
49
+ {
50
+ "visualUrl": "http://127.0.0.1:3000", // 本地联调时覆盖为本机
51
+ "secret": "与服务端 .env 中的 AI_SPEC_TELEMETRY_SECRET 一致",
52
+ "disabled": false
53
+ }
54
+ ```
55
+
56
+ - 文件不存在或格式错误 → 静默回退到仓库默认,不影响 CLI。
57
+ - 权限建议:`chmod 600 ~/.ai-spec-auto/config.json`(含 secret 时)。
58
+
59
+ ### 典型场景
60
+
61
+ | 场景 | 做法 |
62
+ | --- | --- |
63
+ | 使用线上 Visual(`82.156.14.216:3001`),无 secret | **什么都不用设**,装包即走仓库默认 |
64
+ | 使用线上 Visual + 需要 secret | 在 `~/.ai-spec-auto/config.json` 写入 `secret`,或导出 `AI_SPEC_TELEMETRY_SECRET` |
65
+ | 本地联调,想打到本机 Visual | `export AI_SPEC_VISUAL_URL=http://127.0.0.1:3000`(或写入用户配置) |
66
+ | 不想参与匿名统计 | `export AI_SPEC_TELEMETRY_DISABLED=1`(或用户配置 `disabled: true`) |
@@ -0,0 +1,153 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const { collectCommon } = require('./collect');
5
+ const { getConfig, markNoticeShown } = require('./config');
6
+ const { resolveInstallationId } = require('./identity');
7
+ const { fireAndForget } = require('./reporter');
8
+ const { debugLog, safeCall, safeRequire } = require('./safe');
9
+
10
+ const healthcheck = safeRequire('./healthcheck');
11
+
12
+ const PKG_ROOT = path.join(__dirname, '..', '..');
13
+
14
+ function maybePrintFirstNotice(config) {
15
+ if (!config.enabled) return;
16
+ safeCall(function () {
17
+ if (markNoticeShown()) {
18
+ process.stderr.write(
19
+ '[ai-spec-auto] 已开启匿名使用统计(可通过 AI_SPEC_TELEMETRY_DISABLED=1 关闭)\n',
20
+ );
21
+ }
22
+ });
23
+ }
24
+
25
+ function buildPayload(command, status, extra) {
26
+ const base = collectCommon({ cwd: process.cwd(), pkgRoot: PKG_ROOT });
27
+ const payload = {
28
+ installationId: resolveInstallationId(),
29
+ command: String(command || 'unknown').slice(0, 64),
30
+ status: String(status).slice(0, 32),
31
+ hostname: base.hostname,
32
+ username: base.username,
33
+ platform: base.platform,
34
+ arch: base.arch,
35
+ osRelease: base.osRelease,
36
+ nodeVersion: base.nodeVersion,
37
+ cliVersion: base.cliVersion,
38
+ profile: base.profile,
39
+ ides: base.ides,
40
+ level: base.level,
41
+ projectHash: base.projectHash,
42
+ projectName: base.projectName,
43
+ occurredAt: new Date().toISOString(),
44
+ };
45
+ if (extra && typeof extra === 'object') {
46
+ if (typeof extra.durationMs === 'number') payload.durationMs = extra.durationMs;
47
+ if (typeof extra.errorMessage === 'string') {
48
+ payload.errorMessage = extra.errorMessage.slice(0, 2000);
49
+ }
50
+ }
51
+ return payload;
52
+ }
53
+
54
+ function wrap(command, fn) {
55
+ if (typeof fn !== 'function') {
56
+ throw new TypeError('telemetry.wrap: fn must be a function');
57
+ }
58
+ const config = getConfig();
59
+ if (!config.enabled) {
60
+ debugLog('wrap: telemetry disabled, pass-through');
61
+ return fn();
62
+ }
63
+
64
+ safeCall(function () {
65
+ maybePrintFirstNotice(config);
66
+ });
67
+
68
+ // 预热健康探测(不 await,结果会被 reporter 里的 ensureReachable 复用)。
69
+ // 这样 reporter 发 POST 前的健康查询要么已完成、要么已在进行中。
70
+ safeCall(function () {
71
+ if (healthcheck && typeof healthcheck.ensureReachable === 'function') {
72
+ const p = healthcheck.ensureReachable(config.visualUrl);
73
+ if (p && typeof p.catch === 'function') p.catch(function () {});
74
+ }
75
+ });
76
+
77
+ const pending = [];
78
+ function track(p) {
79
+ if (p && typeof p.then === 'function') pending.push(p);
80
+ }
81
+ function flushPending() {
82
+ if (pending.length === 0) return Promise.resolve();
83
+ const all = Promise.allSettled(pending.splice(0, pending.length));
84
+ // 上限 1500ms:覆盖 HEAD 健康探测(最多 500ms)+ POST 落地(一般 <500ms)
85
+ // 的组合路径,同时保证即使网络故障也不会明显拖慢 CLI 退出。
86
+ const env = process.env || {};
87
+ const raw = env.AI_SPEC_TELEMETRY_FLUSH_MS;
88
+ const parsed = raw ? parseInt(raw, 10) : NaN;
89
+ const cap = Number.isFinite(parsed) && parsed >= 100 && parsed <= 5000 ? parsed : 1500;
90
+ return Promise.race([
91
+ all,
92
+ new Promise(function (resolve) {
93
+ const t = setTimeout(resolve, cap);
94
+ if (typeof t.unref === 'function') t.unref();
95
+ }),
96
+ ]);
97
+ }
98
+
99
+ safeCall(function () {
100
+ track(fireAndForget(buildPayload(command, 'started')));
101
+ });
102
+
103
+ const startedAt = Date.now();
104
+ let result;
105
+ try {
106
+ result = fn();
107
+ } catch (error) {
108
+ safeCall(function () {
109
+ track(fireAndForget(
110
+ buildPayload(command, 'failed', {
111
+ durationMs: Date.now() - startedAt,
112
+ errorMessage: error && error.message ? String(error.message) : String(error),
113
+ }),
114
+ ));
115
+ });
116
+ return flushPending().then(function () { throw error; });
117
+ }
118
+
119
+ if (result && typeof result.then === 'function') {
120
+ return result.then(
121
+ function (value) {
122
+ safeCall(function () {
123
+ track(fireAndForget(
124
+ buildPayload(command, 'success', {
125
+ durationMs: Date.now() - startedAt,
126
+ }),
127
+ ));
128
+ });
129
+ return flushPending().then(function () { return value; });
130
+ },
131
+ function (error) {
132
+ safeCall(function () {
133
+ track(fireAndForget(
134
+ buildPayload(command, 'failed', {
135
+ durationMs: Date.now() - startedAt,
136
+ errorMessage: error && error.message ? String(error.message) : String(error),
137
+ }),
138
+ ));
139
+ });
140
+ return flushPending().then(function () { throw error; });
141
+ },
142
+ );
143
+ }
144
+
145
+ safeCall(function () {
146
+ track(fireAndForget(
147
+ buildPayload(command, 'success', { durationMs: Date.now() - startedAt }),
148
+ ));
149
+ });
150
+ return flushPending().then(function () { return result; });
151
+ }
152
+
153
+ module.exports = { wrap };
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ const crypto = require('crypto');
4
+ const fs = require('fs');
5
+ const os = require('os');
6
+ const path = require('path');
7
+ const { safeCall } = require('./safe');
8
+
9
+ function readJson(file) {
10
+ return safeCall(function () {
11
+ const raw = fs.readFileSync(file, 'utf8');
12
+ const parsed = JSON.parse(raw);
13
+ return parsed && typeof parsed === 'object' ? parsed : null;
14
+ }, null);
15
+ }
16
+
17
+ function readCliVersion(pkgRoot) {
18
+ if (!pkgRoot) return null;
19
+ const pkg = readJson(path.join(pkgRoot, 'package.json'));
20
+ return pkg && typeof pkg.version === 'string' ? pkg.version : null;
21
+ }
22
+
23
+ function readProjectMeta(cwd) {
24
+ if (!cwd || typeof cwd !== 'string') {
25
+ return { projectHash: null, projectName: null };
26
+ }
27
+ const hash = crypto.createHash('sha256').update(cwd).digest('hex').slice(0, 32);
28
+ const pkg = readJson(path.join(cwd, 'package.json'));
29
+ const name = pkg && typeof pkg.name === 'string' ? pkg.name.slice(0, 200) : null;
30
+ return { projectHash: hash, projectName: name };
31
+ }
32
+
33
+ function readInstallState(cwd) {
34
+ if (!cwd) return null;
35
+ return readJson(path.join(cwd, '.ai-spec', 'install-state.json'));
36
+ }
37
+
38
+ function pickString(value) {
39
+ return typeof value === 'string' ? value : null;
40
+ }
41
+
42
+ function collectCommon(options) {
43
+ const opts = options || {};
44
+ const cwd = opts.cwd || process.cwd();
45
+ const userInfo = safeCall(function () {
46
+ return os.userInfo();
47
+ }, {});
48
+ const state = readInstallState(cwd);
49
+ const project = readProjectMeta(cwd);
50
+
51
+ return {
52
+ hostname: safeCall(function () { return os.hostname(); }, null),
53
+ username: userInfo && userInfo.username ? String(userInfo.username).slice(0, 128) : null,
54
+ platform: safeCall(function () { return os.platform(); }, null),
55
+ arch: safeCall(function () { return os.arch(); }, null),
56
+ osRelease: safeCall(function () { return os.release(); }, null),
57
+ nodeVersion: process.version,
58
+ cliVersion: readCliVersion(opts.pkgRoot),
59
+ profile: state ? pickString(state.profile) : null,
60
+ ides: state && Array.isArray(state.ides) ? state.ides : null,
61
+ level: state ? pickString(state.level) : null,
62
+ projectHash: project.projectHash,
63
+ projectName: project.projectName,
64
+ };
65
+ }
66
+
67
+ module.exports = { collectCommon };
@@ -0,0 +1,114 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+ const { safeCall } = require('./safe');
7
+
8
+ // 仓库内默认配置(禁止含 secret)。加载失败时回退为空对象,不影响主流程。
9
+ function loadRepoDefaults() {
10
+ return safeCall(function () {
11
+ const raw = fs.readFileSync(path.join(__dirname, 'defaults.json'), 'utf8');
12
+ const parsed = JSON.parse(raw);
13
+ return parsed && typeof parsed === 'object' ? parsed : {};
14
+ }, {});
15
+ }
16
+
17
+ function getUserConfigFile() {
18
+ return path.join(os.homedir(), '.ai-spec-auto', 'config.json');
19
+ }
20
+
21
+ // 用户主目录配置,允许存放 secret、URL 覆盖、总开关。失败时回退空对象。
22
+ function loadUserConfig() {
23
+ return safeCall(function () {
24
+ const raw = fs.readFileSync(getUserConfigFile(), 'utf8');
25
+ const parsed = JSON.parse(raw);
26
+ return parsed && typeof parsed === 'object' ? parsed : {};
27
+ }, {});
28
+ }
29
+
30
+ function pickString(value) {
31
+ return typeof value === 'string' ? value.trim() : '';
32
+ }
33
+
34
+ function pickBool(value) {
35
+ if (value === true) return true;
36
+ if (typeof value === 'string') return value === '1' || value === 'true';
37
+ return false;
38
+ }
39
+
40
+ // 合并优先级(高 → 低):环境变量 > ~/.ai-spec-auto/config.json > 仓库默认。
41
+ function getConfig() {
42
+ const env = process.env || {};
43
+ const repo = loadRepoDefaults();
44
+ const user = loadUserConfig();
45
+
46
+ const envDisabled = pickBool(env.AI_SPEC_TELEMETRY_DISABLED);
47
+ const userDisabled = pickBool(user.disabled);
48
+ const repoDisabled = pickBool(repo.disabled);
49
+ const disabled = envDisabled || userDisabled || repoDisabled;
50
+
51
+ const url =
52
+ pickString(env.AI_SPEC_VISUAL_URL) ||
53
+ pickString(user.visualUrl) ||
54
+ pickString(repo.visualUrl);
55
+
56
+ // secret 仅从环境变量或用户主目录读取,绝不从仓库默认读取
57
+ const secret = pickString(env.AI_SPEC_TELEMETRY_SECRET) || pickString(user.secret);
58
+
59
+ return {
60
+ disabled,
61
+ visualUrl: url,
62
+ secret,
63
+ enabled: !disabled && url.length > 0,
64
+ };
65
+ }
66
+
67
+ function getCacheDir() {
68
+ return path.join(os.homedir(), '.ai-spec-auto');
69
+ }
70
+
71
+ function getCacheFile() {
72
+ return path.join(getCacheDir(), 'telemetry.json');
73
+ }
74
+
75
+ function ensureCacheDir() {
76
+ safeCall(function () {
77
+ fs.mkdirSync(getCacheDir(), { recursive: true });
78
+ });
79
+ }
80
+
81
+ function readCache() {
82
+ return safeCall(function () {
83
+ const raw = fs.readFileSync(getCacheFile(), 'utf8');
84
+ const parsed = JSON.parse(raw);
85
+ return parsed && typeof parsed === 'object' ? parsed : {};
86
+ }, {});
87
+ }
88
+
89
+ function writeCache(next) {
90
+ ensureCacheDir();
91
+ safeCall(function () {
92
+ fs.writeFileSync(getCacheFile(), JSON.stringify(next, null, 2), 'utf8');
93
+ });
94
+ }
95
+
96
+ function markNoticeShown() {
97
+ const cache = readCache();
98
+ if (!cache.noticeShown) {
99
+ cache.noticeShown = true;
100
+ cache.noticeShownAt = new Date().toISOString();
101
+ writeCache(cache);
102
+ return true;
103
+ }
104
+ return false;
105
+ }
106
+
107
+ module.exports = {
108
+ getConfig,
109
+ getCacheDir,
110
+ getCacheFile,
111
+ readCache,
112
+ writeCache,
113
+ markNoticeShown,
114
+ };
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema_comment": "CLI 匿名使用统计默认配置。开源默认关闭;仅 visualUrl 非空且 disabled 为 false 时启用。用户可通过 ~/.ai-spec-auto/config.json 或环境变量覆盖。禁止写入 secret。",
3
+ "visualUrl": "",
4
+ "disabled": true
5
+ }
@@ -0,0 +1,195 @@
1
+ 'use strict';
2
+
3
+ // Visual 健康探测兜底。
4
+ // 目的:当目标不可达/配置错误/服务未部署时,避免每条事件都去等 2 秒超时,
5
+ // 也避免在 Visual 日志里刷一堆无意义的失败上报。
6
+ //
7
+ // 设计约束:
8
+ // - 进程内单例(同一次 CLI 调用只探一次),不要多次网络往返
9
+ // - 先发 HEAD(默认 1500ms 超时);若超时/网络错/405/5xx,再用 GET 重试一次
10
+ // (超时翻倍,最长到 DEFAULT_TIMEOUT_MS * 2)。原因:
11
+ // * Next.js dev 模式对 /api/health 首次访问会触发冷编译,500ms 远远不够;
12
+ // * 部分反向代理(nginx 无 `proxy_method HEAD` 等配置)不支持 HEAD。
13
+ // - 任何异常都必须被吞掉;探测模块本身绝不能让主流程挂掉
14
+ // - 本地缓存(~/.ai-spec-auto/telemetry.json)里记录"最近一次失败时间",
15
+ // 下次 CLI 启动时若距失败不足 N 秒则直接跳过探测,进一步降低噪声
16
+
17
+ const { debugLog } = require('./safe');
18
+ const { readCache, writeCache } = require('./config');
19
+
20
+ // 同一进程内的探测结果缓存(null=未探过,true/false=已探过的可用性)
21
+ let probed = null;
22
+ let probing = null; // 并发保护:多条事件同时 wrap 时,共享同一个探测 Promise
23
+
24
+ // 跨进程短时间冷却:避免 CI 里连续多次 CLI 调用都去探已知宕机的服务
25
+ const COOLDOWN_MS = 60 * 1000; // 失败后 60 秒内不再探测
26
+
27
+ function buildHealthUrl(base) {
28
+ const trimmed = String(base || '').replace(/\/+$/, '');
29
+ return trimmed + '/api/health';
30
+ }
31
+
32
+ function shouldSkipByCooldown() {
33
+ try {
34
+ const cache = readCache();
35
+ if (!cache || !cache.lastHealthFailAt) return false;
36
+ const last = Date.parse(cache.lastHealthFailAt);
37
+ if (!Number.isFinite(last)) return false;
38
+ const elapsed = Date.now() - last;
39
+ return elapsed >= 0 && elapsed < COOLDOWN_MS;
40
+ } catch (_error) {
41
+ return false;
42
+ }
43
+ }
44
+
45
+ function recordFailure() {
46
+ try {
47
+ const cache = readCache() || {};
48
+ cache.lastHealthFailAt = new Date().toISOString();
49
+ writeCache(cache);
50
+ } catch (_error) {
51
+ /* ignore */
52
+ }
53
+ }
54
+
55
+ function recordSuccess() {
56
+ try {
57
+ const cache = readCache() || {};
58
+ if (cache.lastHealthFailAt) {
59
+ delete cache.lastHealthFailAt;
60
+ writeCache(cache);
61
+ }
62
+ } catch (_error) {
63
+ /* ignore */
64
+ }
65
+ }
66
+
67
+ // 默认 1500ms,单位毫秒。选这个值的原因:
68
+ // - 生产/容器内实际健康探测通常 <100ms,留一个 15 倍冗余仍很保守
69
+ // - Next.js dev 冷编译 /api/health 普遍 800~1200ms,500ms 会在 dev 场景
70
+ // 命中率接近 0,1500ms 能覆盖 95% 以上首次冷启动
71
+ // - 上限仍由 AI_SPEC_TELEMETRY_HEALTH_TIMEOUT_MS 控制(最大 10s),
72
+ // CI / 远程部署可按需调大
73
+ const DEFAULT_TIMEOUT_MS = 1500;
74
+ const MIN_TIMEOUT_MS = 100;
75
+ const MAX_TIMEOUT_MS = 10000;
76
+
77
+ function getProbeTimeoutMs() {
78
+ const env = process.env || {};
79
+ const raw = env.AI_SPEC_TELEMETRY_HEALTH_TIMEOUT_MS;
80
+ const parsed = raw ? parseInt(raw, 10) : NaN;
81
+ if (Number.isFinite(parsed) && parsed >= MIN_TIMEOUT_MS && parsed <= MAX_TIMEOUT_MS) {
82
+ return parsed;
83
+ }
84
+ return DEFAULT_TIMEOUT_MS;
85
+ }
86
+
87
+ // 判定 HEAD 的结果是否"足以说明服务可达"。405 / 501 / 超时 / 网络错等都不算,
88
+ // 需要继续用 GET 兜底再试一次。
89
+ function isHeadConclusive(response) {
90
+ if (!response) return false;
91
+ // 2xx/3xx 及大多数 4xx 足以证明服务在线、有业务处理能力;
92
+ // 405/501 是"方法不被支持",需要换方法再试一次。
93
+ if (response.status === 405 || response.status === 501) return false;
94
+ return response.status >= 200 && response.status < 500;
95
+ }
96
+
97
+ async function sendProbe(url, method, timeoutMs) {
98
+ const controller = typeof AbortController === 'function' ? new AbortController() : null;
99
+ const timer = controller
100
+ ? setTimeout(function () {
101
+ controller.abort();
102
+ }, timeoutMs)
103
+ : null;
104
+ if (timer && typeof timer.unref === 'function') timer.unref();
105
+
106
+ try {
107
+ debugLog('healthcheck:', method, url, 'timeoutMs=', timeoutMs);
108
+ const response = await fetch(url, {
109
+ method: method,
110
+ signal: controller ? controller.signal : undefined,
111
+ });
112
+ debugLog('healthcheck:', method, 'status=', response.status);
113
+ return { response: response, error: null };
114
+ } catch (error) {
115
+ debugLog(
116
+ 'healthcheck:',
117
+ method,
118
+ 'failed',
119
+ error && error.message ? error.message : error,
120
+ );
121
+ return { response: null, error: error };
122
+ } finally {
123
+ if (timer) clearTimeout(timer);
124
+ }
125
+ }
126
+
127
+ async function doProbe(baseUrl) {
128
+ if (typeof fetch !== 'function') {
129
+ debugLog('healthcheck: global fetch unavailable, assume reachable');
130
+ return true; // 旧 Node 没 fetch 时不阻拦,让 reporter 自己去超时
131
+ }
132
+
133
+ const url = buildHealthUrl(baseUrl);
134
+ const firstTimeoutMs = getProbeTimeoutMs();
135
+
136
+ // Round 1: HEAD —— 轻量、快,生产路径 >99% 会在这里返回
137
+ const head = await sendProbe(url, 'HEAD', firstTimeoutMs);
138
+ if (isHeadConclusive(head.response)) {
139
+ recordSuccess();
140
+ return true;
141
+ }
142
+
143
+ // Round 2: GET 兜底 —— 针对 Next.js dev 冷编译、不接受 HEAD 的反代等情况,
144
+ // 允许一次"更长超时 + 真实 GET"的重试。超时 ×2,封顶 MAX_TIMEOUT_MS。
145
+ const secondTimeoutMs = Math.min(firstTimeoutMs * 2, MAX_TIMEOUT_MS);
146
+ debugLog('healthcheck: HEAD inconclusive, retry with GET');
147
+ const get = await sendProbe(url, 'GET', secondTimeoutMs);
148
+ if (get.response && get.response.status >= 200 && get.response.status < 500) {
149
+ recordSuccess();
150
+ return true;
151
+ }
152
+
153
+ recordFailure();
154
+ return false;
155
+ }
156
+
157
+ // 主入口:返回 Promise<boolean>。true=可上报;false=本次会话禁用上报。
158
+ function ensureReachable(baseUrl) {
159
+ if (probed !== null) return Promise.resolve(probed);
160
+ if (probing) return probing;
161
+
162
+ if (!baseUrl) {
163
+ probed = false;
164
+ return Promise.resolve(false);
165
+ }
166
+
167
+ if (shouldSkipByCooldown()) {
168
+ debugLog('healthcheck: in cooldown window, skip reporting this session');
169
+ probed = false;
170
+ return Promise.resolve(false);
171
+ }
172
+
173
+ probing = doProbe(baseUrl)
174
+ .then(function (ok) {
175
+ probed = ok;
176
+ return ok;
177
+ })
178
+ .catch(function () {
179
+ probed = false;
180
+ return false;
181
+ })
182
+ .finally(function () {
183
+ probing = null;
184
+ });
185
+
186
+ return probing;
187
+ }
188
+
189
+ // 供测试复位
190
+ function __resetForTests() {
191
+ probed = null;
192
+ probing = null;
193
+ }
194
+
195
+ module.exports = { ensureReachable, __resetForTests };
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ const crypto = require('crypto');
4
+ const os = require('os');
5
+ const { safeCall, safeRequire } = require('./safe');
6
+
7
+ let cached = null;
8
+
9
+ function fallbackId() {
10
+ const interfaces = safeCall(function () {
11
+ return os.networkInterfaces();
12
+ }, {});
13
+ const macs = [];
14
+ if (interfaces && typeof interfaces === 'object') {
15
+ Object.keys(interfaces).forEach(function (name) {
16
+ const list = interfaces[name] || [];
17
+ list.forEach(function (entry) {
18
+ if (entry && entry.mac && entry.mac !== '00:00:00:00:00:00') {
19
+ macs.push(entry.mac);
20
+ }
21
+ });
22
+ });
23
+ }
24
+ macs.sort();
25
+ const userInfo = safeCall(function () {
26
+ return os.userInfo();
27
+ }, { username: 'unknown' });
28
+ const material = [
29
+ macs.join(','),
30
+ userInfo && userInfo.username ? userInfo.username : 'unknown',
31
+ safeCall(function () { return os.hostname(); }, 'unknown'),
32
+ safeCall(function () { return os.platform(); }, 'unknown'),
33
+ ].join('|');
34
+ return crypto.createHash('sha256').update(material).digest('hex');
35
+ }
36
+
37
+ function resolveInstallationId() {
38
+ if (cached) return cached;
39
+ const mod = safeRequire('node-machine-id');
40
+ let id = null;
41
+ if (mod && typeof mod.machineIdSync === 'function') {
42
+ id = safeCall(function () {
43
+ return mod.machineIdSync(true);
44
+ }, null);
45
+ }
46
+ if (!id || typeof id !== 'string' || id.length < 8) {
47
+ id = fallbackId();
48
+ }
49
+ cached = String(id).slice(0, 128);
50
+ return cached;
51
+ }
52
+
53
+ module.exports = { resolveInstallationId, fallbackId };
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ // 对外唯一入口。任一模块加载失败都必须返回一个"透明 wrap",调用方无感。
4
+ let impl = null;
5
+ try {
6
+ // eslint-disable-next-line global-require
7
+ impl = require('./aspect');
8
+ } catch (_error) {
9
+ impl = null;
10
+ }
11
+
12
+ function transparent(_command, fn) {
13
+ return typeof fn === 'function' ? fn() : undefined;
14
+ }
15
+
16
+ exports.wrap = function wrap(command, fn) {
17
+ if (!impl || typeof impl.wrap !== 'function') {
18
+ return transparent(command, fn);
19
+ }
20
+ try {
21
+ return impl.wrap(command, fn);
22
+ } catch (_error) {
23
+ return transparent(command, fn);
24
+ }
25
+ };