mcp-efficiency-engine 0.1.0

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 (360) hide show
  1. package/.github/CODEOWNERS +40 -0
  2. package/.github/GITHUB_MCP_INTEGRATION.md +366 -0
  3. package/.github/ISSUE_TEMPLATE/bug.md +51 -0
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +45 -0
  5. package/.github/ISSUE_TEMPLATE/question.md +18 -0
  6. package/.github/agents/backend.agent.md +18 -0
  7. package/.github/agents/community-manager.agent.md +18 -0
  8. package/.github/agents/dba.agent.md +18 -0
  9. package/.github/agents/frontend-agent.agent.md +18 -0
  10. package/.github/agents/github-repository-manager.agent.md +338 -0
  11. package/.github/agents/iot.agent.md +20 -0
  12. package/.github/agents/legacy.agent.md +18 -0
  13. package/.github/agents/rag-azure.agent.md +18 -0
  14. package/.github/agents/rag-local.agent.md +18 -0
  15. package/.github/agents/snapshot.agent.md +18 -0
  16. package/.github/agents/ux-ui.agent.md +18 -0
  17. package/.github/agents/wiki-agent.agent.md +23 -0
  18. package/.github/copilot-instructions.md +44 -0
  19. package/.github/instructions/always-on-optimization.instructions.md +54 -0
  20. package/.github/prompts/auto-route.prompt.md +33 -0
  21. package/.github/prompts/azure-rag.query.prompt.md +19 -0
  22. package/.github/prompts/backend.fix-bug.prompt.md +13 -0
  23. package/.github/prompts/cavecrew.prompt.md +16 -0
  24. package/.github/prompts/caveman-commit.prompt.md +14 -0
  25. package/.github/prompts/caveman-compress.prompt.md +15 -0
  26. package/.github/prompts/caveman-debug.prompt.md +13 -0
  27. package/.github/prompts/caveman-help.prompt.md +11 -0
  28. package/.github/prompts/caveman-review.prompt.md +15 -0
  29. package/.github/prompts/caveman-stats.prompt.md +11 -0
  30. package/.github/prompts/caveman.prompt.md +11 -0
  31. package/.github/prompts/community.post.prompt.md +14 -0
  32. package/.github/prompts/dba.query-review.prompt.md +15 -0
  33. package/.github/prompts/dev.fix-bug.prompt.md +13 -0
  34. package/.github/prompts/frontend.code.prompt.md +13 -0
  35. package/.github/prompts/legacy.impact-analysis.prompt.md +14 -0
  36. package/.github/prompts/project.kickoff-analysis.prompt.md +51 -0
  37. package/.github/prompts/rag.knowledge-answer.prompt.md +13 -0
  38. package/.github/prompts/token-saver-review.prompt.md +14 -0
  39. package/.github/prompts/ux-ui.review.prompt.md +14 -0
  40. package/.github/pull_request_template.md +71 -0
  41. package/.github/skills/ahorro-tokens/SKILL.md +36 -0
  42. package/.github/skills/azure-rag-enterprise/SKILL.md +24 -0
  43. package/.github/skills/backend-coding/SKILL.md +24 -0
  44. package/.github/skills/cavecrew/SKILL.md +17 -0
  45. package/.github/skills/caveman/SKILL.md +25 -0
  46. package/.github/skills/caveman-commit/SKILL.md +15 -0
  47. package/.github/skills/caveman-compress/SKILL.md +14 -0
  48. package/.github/skills/caveman-help/SKILL.md +19 -0
  49. package/.github/skills/caveman-mode/SKILL.md +43 -0
  50. package/.github/skills/caveman-review/SKILL.md +16 -0
  51. package/.github/skills/caveman-stats/SKILL.md +13 -0
  52. package/.github/skills/community-content/SKILL.md +22 -0
  53. package/.github/skills/database-analysis/SKILL.md +23 -0
  54. package/.github/skills/dev-coding/SKILL.md +24 -0
  55. package/.github/skills/frontend-coding/SKILL.md +24 -0
  56. package/.github/skills/human-in-the-loop/SKILL.md +47 -0
  57. package/.github/skills/iot-architecture/SKILL.md +22 -0
  58. package/.github/skills/legacy-migration/SKILL.md +22 -0
  59. package/.github/skills/rag-knowledge/SKILL.md +21 -0
  60. package/.github/skills/token-saver/SKILL.md +36 -0
  61. package/.github/skills/ux-ui-governance/SKILL.md +24 -0
  62. package/.github/skills/wiki-tools.json +24 -0
  63. package/.github/workflows/auto-devlog.yml +56 -0
  64. package/.github/workflows/auto-manage-issues.yml +64 -0
  65. package/.github/workflows/auto-sync.yml +54 -0
  66. package/.github/workflows/autodocs-sync.yml +114 -0
  67. package/.github/workflows/ci.yml +68 -0
  68. package/.github/workflows/pages.yml +59 -0
  69. package/.github/workflows/routing-evals.yml +59 -0
  70. package/.github/workflows/techriders-coverage-effective.yml +91 -0
  71. package/.vscode/mcp.json +44 -0
  72. package/AGENTS.md +160 -0
  73. package/ARCHITECTURE.md +57 -0
  74. package/FINAL_USAGE_GUIDE.md +106 -0
  75. package/LICENSE +21 -0
  76. package/README.md +385 -0
  77. package/README_WIKI.md +130 -0
  78. package/autodocs/README.md +22 -0
  79. package/autodocs/schema/wiki-node.schema.json +56 -0
  80. package/autolearning/feedback-loop.md +90 -0
  81. package/bin/install-host.js +326 -0
  82. package/bin/mcpee.js +116 -0
  83. package/context/repomix/repomix.config.json +20 -0
  84. package/memory/cross-memory-reasoning.md +17 -0
  85. package/memory/mempry-registry.yml +16 -0
  86. package/observability/evals/chat-token-usage-report.json +64 -0
  87. package/observability/evals/chat-token-usage-report.md +33 -0
  88. package/observability/evals/iteration-value-report.json +76 -0
  89. package/observability/evals/iteration-value-report.md +39 -0
  90. package/observability/evals/learning-loop-report.json +268 -0
  91. package/observability/evals/learning-loop-report.md +37 -0
  92. package/observability/evals/repo-intake-eval-cases.md +23 -0
  93. package/observability/evals/routing-eval-cases.json +68 -0
  94. package/observability/evals/routing-eval-cases.md +25 -0
  95. package/observability/evals/routing-eval-report.json +72 -0
  96. package/observability/evaluation.md +34 -0
  97. package/observability/logs/copilot-usage-ingest-report.json +13 -0
  98. package/observability/logs/iteration-metrics.jsonl +75 -0
  99. package/observability/logs/learning-feedback.jsonl +152 -0
  100. package/observability/logs/routing-decisions.jsonl +333 -0
  101. package/observability/logs/session/agent-pipeline-preflight-20260701-004146.log +8 -0
  102. package/observability/logs/session/agent-pipeline-preflight-20260701-005554.log +8 -0
  103. package/observability/logs/session/agent-pipeline-preflight-20260701-010351.log +8 -0
  104. package/observability/logs/session/agent-pipeline-preflight-20260704-145829.log +8 -0
  105. package/observability/logs/session/agent-pipeline-preflight-20260704-150021.log +8 -0
  106. package/observability/logs/session/agent-pipeline-preflight-20260704-154328.log +8 -0
  107. package/observability/logs/session/bye-20260629-221513.json +39 -0
  108. package/observability/logs/session/bye-20260629-221545.json +59 -0
  109. package/observability/logs/session/bye-20260629-222007.json +52 -0
  110. package/observability/logs/session/bye-20260629-222133.json +59 -0
  111. package/observability/logs/session/bye-20260629-222412.json +45 -0
  112. package/observability/logs/session/bye-20260629-223224.json +52 -0
  113. package/observability/logs/session/bye-20260629-224050.json +59 -0
  114. package/observability/logs/session/bye-20260630-105732.json +24 -0
  115. package/observability/logs/session/bye-20260630-211536.json +87 -0
  116. package/observability/logs/session/bye-20260630-223423.json +87 -0
  117. package/observability/logs/session/bye-20260630-232534.json +87 -0
  118. package/observability/logs/session/bye-20260701-003638.json +126 -0
  119. package/observability/logs/session/bye-20260701-003849.json +126 -0
  120. package/observability/logs/session/bye-20260701-004315.json +138 -0
  121. package/observability/logs/session/bye-20260701-004559.json +76 -0
  122. package/observability/logs/session/bye-20260701-005913.json +138 -0
  123. package/observability/logs/session/bye-20260701-010753.json +138 -0
  124. package/observability/logs/session/bye-20260703-194106.json +24 -0
  125. package/observability/logs/session/bye-20260703-233443.json +76 -0
  126. package/observability/logs/session/bye-20260703-233653.json +76 -0
  127. package/observability/logs/session/bye-20260704-150317.json +152 -0
  128. package/observability/logs/session/bye-20260704-150929.json +75 -0
  129. package/observability/logs/session/bye-20260704-151050.json +75 -0
  130. package/observability/logs/session/bye-20260705-115458.json +165 -0
  131. package/observability/logs/session/codegraph-status-20260701-004228.log +39 -0
  132. package/observability/logs/session/codegraph-status-20260701-004310.log +39 -0
  133. package/observability/logs/session/codegraph-status-20260701-005637.log +39 -0
  134. package/observability/logs/session/codegraph-status-20260701-005908.log +39 -0
  135. package/observability/logs/session/codegraph-status-20260701-010444.log +39 -0
  136. package/observability/logs/session/codegraph-status-20260701-010747.log +39 -0
  137. package/observability/logs/session/codegraph-status-20260704-150137.log +26 -0
  138. package/observability/logs/session/codegraph-status-20260704-150313.log +28 -0
  139. package/observability/logs/session/codegraph-status-20260704-154445.log +26 -0
  140. package/observability/logs/session/codegraph-status-20260705-115454.log +27 -0
  141. package/observability/logs/session/codegraph-sync-20260701-004211.log +88 -0
  142. package/observability/logs/session/codegraph-sync-20260701-004241.log +82 -0
  143. package/observability/logs/session/codegraph-sync-20260701-005620.log +89 -0
  144. package/observability/logs/session/codegraph-sync-20260701-005840.log +88 -0
  145. package/observability/logs/session/codegraph-sync-20260701-010419.log +93 -0
  146. package/observability/logs/session/codegraph-sync-20260701-010609.log +90 -0
  147. package/observability/logs/session/codegraph-sync-20260704-145856.log +70 -0
  148. package/observability/logs/session/codegraph-sync-20260704-150047.log +53 -0
  149. package/observability/logs/session/codegraph-sync-20260704-150204.log +44 -0
  150. package/observability/logs/session/codegraph-sync-20260704-154353.log +26 -0
  151. package/observability/logs/session/codegraph-sync-20260705-115337.log +32 -0
  152. package/observability/logs/session/hi-20260629-221459.json +38 -0
  153. package/observability/logs/session/hi-20260629-221945.json +59 -0
  154. package/observability/logs/session/hi-20260629-222108.json +66 -0
  155. package/observability/logs/session/hi-20260629-222352.json +45 -0
  156. package/observability/logs/session/hi-20260629-225719.json +59 -0
  157. package/observability/logs/session/hi-20260629-233722.json +52 -0
  158. package/observability/logs/session/hi-20260629-233913.json +198 -0
  159. package/observability/logs/session/hi-20260630-110156.json +177 -0
  160. package/observability/logs/session/hi-20260630-191243.json +184 -0
  161. package/observability/logs/session/hi-20260630-230050.json +234 -0
  162. package/observability/logs/session/hi-20260630-230523.json +227 -0
  163. package/observability/logs/session/hi-20260630-230855.json +227 -0
  164. package/observability/logs/session/hi-20260630-231638.json +227 -0
  165. package/observability/logs/session/hi-20260630-231756.json +219 -0
  166. package/observability/logs/session/hi-20260701-002842.json +234 -0
  167. package/observability/logs/session/hi-20260701-003458.json +282 -0
  168. package/observability/logs/session/hi-20260701-004233.json +290 -0
  169. package/observability/logs/session/hi-20260701-004554.json +236 -0
  170. package/observability/logs/session/hi-20260701-005641.json +290 -0
  171. package/observability/logs/session/hi-20260701-010450.json +290 -0
  172. package/observability/logs/session/hi-20260703-233854.json +312 -0
  173. package/observability/logs/session/hi-20260703-234448.json +318 -0
  174. package/observability/logs/session/hi-20260704-145907.json +353 -0
  175. package/observability/logs/session/hi-20260704-150141.json +392 -0
  176. package/observability/logs/session/hi-20260704-154448.json +392 -0
  177. package/observability/logs/session/iteration-value-refresh-20260701-004309.log +3 -0
  178. package/observability/logs/session/iteration-value-refresh-20260701-005907.log +3 -0
  179. package/observability/logs/session/iteration-value-refresh-20260701-010747.log +3 -0
  180. package/observability/logs/session/iteration-value-refresh-20260704-150312.log +3 -0
  181. package/observability/logs/session/iteration-value-refresh-20260705-115453.log +3 -0
  182. package/observability/logs/session/learning-loop-refresh-20260701-004309.log +3 -0
  183. package/observability/logs/session/learning-loop-refresh-20260701-005906.log +3 -0
  184. package/observability/logs/session/learning-loop-refresh-20260701-010745.log +3 -0
  185. package/observability/logs/session/learning-loop-refresh-20260704-150309.log +3 -0
  186. package/observability/logs/session/learning-loop-refresh-20260705-115450.log +3 -0
  187. package/observability/logs/session/project-notes-refresh-20260701-004227.log +1 -0
  188. package/observability/logs/session/project-notes-refresh-20260701-004308.log +1 -0
  189. package/observability/logs/session/project-notes-refresh-20260701-005636.log +1 -0
  190. package/observability/logs/session/project-notes-refresh-20260701-005906.log +1 -0
  191. package/observability/logs/session/project-notes-refresh-20260701-010443.log +1 -0
  192. package/observability/logs/session/project-notes-refresh-20260701-010744.log +1 -0
  193. package/observability/logs/session/project-notes-refresh-20260704-150133.log +1 -0
  194. package/observability/logs/session/project-notes-refresh-20260704-150309.log +1 -0
  195. package/observability/logs/session/project-notes-refresh-20260704-154442.log +1 -0
  196. package/observability/logs/session/project-notes-refresh-20260705-115449.log +1 -0
  197. package/observability/logs/session/repo-intake-20260701-004218.log +6 -0
  198. package/observability/logs/session/repo-intake-20260701-005626.log +6 -0
  199. package/observability/logs/session/repo-intake-20260701-010433.log +6 -0
  200. package/observability/logs/session/repo-intake-20260704-150053.log +6 -0
  201. package/observability/logs/session/repo-intake-20260704-154404.log +6 -0
  202. package/observability/logs/session/repo-intake-refresh-20260701-004247.log +6 -0
  203. package/observability/logs/session/repo-intake-refresh-20260701-005847.log +6 -0
  204. package/observability/logs/session/repo-intake-refresh-20260701-010615.log +6 -0
  205. package/observability/logs/session/repo-intake-refresh-20260704-150209.log +6 -0
  206. package/observability/logs/session/repo-intake-refresh-20260705-115342.log +6 -0
  207. package/observability/logs/session/repo-registry-validation-20260701-004234.log +2 -0
  208. package/observability/logs/session/repo-registry-validation-20260701-004556.log +2 -0
  209. package/observability/logs/session/repo-registry-validation-20260701-005833.log +2 -0
  210. package/observability/logs/session/repo-registry-validation-20260701-010601.log +2 -0
  211. package/observability/logs/session/repo-registry-validation-20260704-150155.log +2 -0
  212. package/observability/logs/session/repo-registry-validation-20260705-115323.log +2 -0
  213. package/observability/logs/session/repomix-refresh-20260701-003823.log +4236 -0
  214. package/observability/logs/session/repomix-refresh-20260701-004251.log +4275 -0
  215. package/observability/logs/session/repomix-refresh-20260701-005850.log +4248 -0
  216. package/observability/logs/session/repomix-refresh-20260701-010619.log +6531 -0
  217. package/observability/logs/session/repomix-refresh-20260704-150239.log +652 -0
  218. package/observability/logs/session/repomix-refresh-20260705-115419.log +178 -0
  219. package/observability/logs/session/routing-evals-20260701-004221.log +2 -0
  220. package/observability/logs/session/routing-evals-20260701-004235.log +2 -0
  221. package/observability/logs/session/routing-evals-20260701-005629.log +2 -0
  222. package/observability/logs/session/routing-evals-20260701-005834.log +2 -0
  223. package/observability/logs/session/routing-evals-20260701-010437.log +2 -0
  224. package/observability/logs/session/routing-evals-20260701-010603.log +2 -0
  225. package/observability/logs/session/routing-evals-20260704-150125.log +2 -0
  226. package/observability/logs/session/routing-evals-20260704-150157.log +2 -0
  227. package/observability/logs/session/routing-evals-20260704-154434.log +2 -0
  228. package/observability/logs/session/routing-evals-20260705-115327.log +2 -0
  229. package/observability/logs/session/sibling-discovery-refresh-20260701-004250.log +3 -0
  230. package/observability/logs/session/sibling-discovery-refresh-20260701-005850.log +3 -0
  231. package/observability/logs/session/sibling-discovery-refresh-20260701-010618.log +3 -0
  232. package/observability/logs/session/sibling-discovery-refresh-20260704-150238.log +3 -0
  233. package/observability/logs/session/sibling-discovery-refresh-20260705-115418.log +3 -0
  234. package/observability/logs.schema.json +95 -0
  235. package/observability/logs.schema.md +26 -0
  236. package/observability/metrics.md +35 -0
  237. package/observability/routing-evaluator.md +37 -0
  238. package/observability/scoring-rubric.md +38 -0
  239. package/optimization/ALWAYS_ON_OPTIMIZATION.md +98 -0
  240. package/optimization/caveman-mode.md +62 -0
  241. package/optimization/examples/login-bug.md +25 -0
  242. package/optimization/examples/sla-query.md +25 -0
  243. package/optimization/optimization-routing.md +30 -0
  244. package/optimization/policies/response-style.policy.md +45 -0
  245. package/optimization/policies/token-budget.policy.md +28 -0
  246. package/optimization/profiles/always-on.profile.md +19 -0
  247. package/optimization/profiles/architecture.profile.md +20 -0
  248. package/optimization/profiles/debug.profile.md +20 -0
  249. package/optimization/profiles/enterprise-rag.profile.md +20 -0
  250. package/optimization/profiles/training.profile.md +20 -0
  251. package/optimization/token-saver.md +58 -0
  252. package/orchestrator/corporate-routing.md +51 -0
  253. package/orchestrator/decision-matrix.md +33 -0
  254. package/orchestrator/fallback.md +29 -0
  255. package/orchestrator/repo-routing.md +58 -0
  256. package/orchestrator/router.md +75 -0
  257. package/orchestrator/wiki/__init__.py +5 -0
  258. package/orchestrator/wiki/graph_consolidator.py +506 -0
  259. package/orchestrator/wiki/incremental_engine.py +57 -0
  260. package/orchestrator/wiki/plugin_manager.py +40 -0
  261. package/package.json +70 -0
  262. package/policies/context-policy.md +25 -0
  263. package/policies/cost-policy.md +25 -0
  264. package/policies/repo-intake-policy.md +36 -0
  265. package/policies/security-policy.md +25 -0
  266. package/repo-intake/README.md +81 -0
  267. package/repo-intake/templates/agent.template.md +4 -0
  268. package/repo-intake/templates/context-manifest.template.md +4 -0
  269. package/repo-intake/templates/skill.template.md +3 -0
  270. package/repo-registry/repos.schema.json +102 -0
  271. package/repo-registry/repos.template.json +26 -0
  272. package/requirements.txt +1 -0
  273. package/scripts/README.md +109 -0
  274. package/scripts/__init__.py +0 -0
  275. package/scripts/bootstrap-portable.cmd +4 -0
  276. package/scripts/bootstrap-portable.ps1 +90 -0
  277. package/scripts/context/azure-rag-mcp-adapter.py +1 -0
  278. package/scripts/context/build-graphify.ps1 +1 -0
  279. package/scripts/context/build-repomix.ps1 +1 -0
  280. package/scripts/discovery/discover-boost-repos.cmd +4 -0
  281. package/scripts/discovery/discover-boost-repos.py +186 -0
  282. package/scripts/discovery/refresh-project-notes.py +179 -0
  283. package/scripts/github/INSTALL.md +295 -0
  284. package/scripts/github/README.md +455 -0
  285. package/scripts/github/apply-boost-templates.ps1 +163 -0
  286. package/scripts/github/apply-single-repo.ps1 +85 -0
  287. package/scripts/github/create-devlog.ps1 +380 -0
  288. package/scripts/github/manage-issues.ps1 +332 -0
  289. package/scripts/github/sync-repo.ps1 +267 -0
  290. package/scripts/intake/agent-pipeline-preflight.py +151 -0
  291. package/scripts/intake/init-template-registry.cmd +4 -0
  292. package/scripts/intake/init-template-registry.ps1 +258 -0
  293. package/scripts/intake/repo-intake.py +354 -0
  294. package/scripts/intake/resolve-routing.py +620 -0
  295. package/scripts/intake/run-repo-intake.cmd +4 -0
  296. package/scripts/intake/run-repo-intake.ps1 +46 -0
  297. package/scripts/intake/run-routing-evals.py +147 -0
  298. package/scripts/intake/validate-database-routing.py +91 -0
  299. package/scripts/intake/validate-rag-routing.py +85 -0
  300. package/scripts/intake/validate-repo-registry.ps1 +20 -0
  301. package/scripts/intake/validate-repo-registry.py +286 -0
  302. package/scripts/intake/validate-security.py +170 -0
  303. package/scripts/learning/autolearning-gate.py +71 -0
  304. package/scripts/learning/chat-token-usage-report.py +326 -0
  305. package/scripts/learning/ingest-copilot-session-usage.py +421 -0
  306. package/scripts/learning/iteration-value-report.py +275 -0
  307. package/scripts/learning/learning-loop-report.py +272 -0
  308. package/scripts/learning/record-iteration-metrics.py +116 -0
  309. package/scripts/learning/record-learning-feedback.py +91 -0
  310. package/scripts/ops/bye.ps1 +620 -0
  311. package/scripts/ops/compare-demo-results.ps1 +826 -0
  312. package/scripts/ops/demo1.ps1 +11 -0
  313. package/scripts/ops/demo2.ps1 +11 -0
  314. package/scripts/ops/demo3.ps1 +11 -0
  315. package/scripts/ops/demo4.ps1 +11 -0
  316. package/scripts/ops/hi.ps1 +1045 -0
  317. package/scripts/ops/llm-token-probe.py +164 -0
  318. package/scripts/ops/run-all-demos.ps1 +39 -0
  319. package/scripts/ops/run-demo-block.ps1 +85 -0
  320. package/scripts/ops/run-demo-session.ps1 +532 -0
  321. package/scripts/setup/optimize-engines.ps1 +183 -0
  322. package/scripts/setup/setup-codegraph.ps1 +3 -0
  323. package/scripts/setup/setup-gitnexus.ps1 +3 -0
  324. package/scripts/setup/setup-graphify.ps1 +2 -0
  325. package/scripts/setup/setup-prerequisites.ps1 +205 -0
  326. package/scripts/setup/start-gitnexus.ps1 +71 -0
  327. package/scripts/setup/validate-context.ps1 +361 -0
  328. package/scripts/wiki/__init__.py +0 -0
  329. package/scripts/wiki/compiler_main.py +189 -0
  330. package/scripts/wiki/normalizer.py +206 -0
  331. package/scripts/wiki/providers/base_provider.py +25 -0
  332. package/scripts/wiki/providers/codegraph_provider.py +49 -0
  333. package/scripts/wiki/providers/graphify_provider.py +49 -0
  334. package/scripts/wiki/providers/repo_content_provider.py +408 -0
  335. package/scripts/wiki/query_autodocs.py +60 -0
  336. package/scripts/wiki/validator.py +183 -0
  337. package/scripts/wiki/wiki_compiler.py +5 -0
  338. package/specs/architecture.spec.md +32 -0
  339. package/specs/azure-rag.spec.md +28 -0
  340. package/specs/coding-standards.spec.md +24 -0
  341. package/specs/database.spec.md +29 -0
  342. package/specs/migration.spec.md +26 -0
  343. package/specs/observability.spec.md +24 -0
  344. package/specs/optimization.spec.md +31 -0
  345. package/specs/rag.spec.md +30 -0
  346. package/specs/repo-intake.spec.md +25 -0
  347. package/specs/routing.spec.md +24 -0
  348. package/specs/security.spec.md +30 -0
  349. package/specs/wiki/provider-contract.json +33 -0
  350. package/specs/wiki/unified-knowledge-graph.json +25 -0
  351. package/templates/BOOST_README_TEMPLATE.md +96 -0
  352. package/templates/CODEOWNERS_TEMPLATE.txt +29 -0
  353. package/templates/LICENSE_MIT_TEMPLATE.txt +21 -0
  354. package/templates/PERSONAL_README_TEMPLATE.md +90 -0
  355. package/templates/README_boost_RAG_Azure.md +46 -0
  356. package/templates/README_boost_azure_iot_edge.md +48 -0
  357. package/templates/README_boost_backend.md +47 -0
  358. package/templates/README_boost_dba.md +57 -0
  359. package/templates/ci.yml.template +73 -0
  360. package/tooling/tooling.manifest.json +72 -0
@@ -0,0 +1,1045 @@
1
+ param(
2
+ [switch]$SetupIfNeeded,
3
+ [switch]$SkipIntake,
4
+ [switch]$SkipRoutingEvals,
5
+ [switch]$SkipProjectNotesRefresh,
6
+ [switch]$SkipCopilotUsageIngest,
7
+ [switch]$SkipChatTokenUsageReport,
8
+ [switch]$SkipCodegraphStatus,
9
+ [switch]$SkipMcpStartupChecks,
10
+ [switch]$SkipSiblingReposChecks,
11
+ [switch]$SkipGraphRefresh,
12
+ [switch]$SkipAgentPipelinePreflight
13
+ )
14
+
15
+ Set-StrictMode -Version Latest
16
+ $ErrorActionPreference = 'Stop'
17
+
18
+ function Get-PythonCommand {
19
+ if (Get-Command py -ErrorAction SilentlyContinue) {
20
+ return @('py', '-3')
21
+ }
22
+ if (Get-Command python -ErrorAction SilentlyContinue) {
23
+ return @('python')
24
+ }
25
+ throw 'Python is required (py or python not found in PATH).'
26
+ }
27
+
28
+ function New-StepResult {
29
+ param(
30
+ [string]$Name,
31
+ [bool]$Required,
32
+ [bool]$Success,
33
+ [double]$DurationSec,
34
+ [string]$Message
35
+ )
36
+
37
+ return [ordered]@{
38
+ name = $Name
39
+ required = $Required
40
+ success = $Success
41
+ duration_sec = [math]::Round($DurationSec, 2)
42
+ message = $Message
43
+ }
44
+ }
45
+
46
+ function Get-StepStatus {
47
+ param(
48
+ [string]$Name
49
+ )
50
+
51
+ $step = $script:Steps | Where-Object { $_.name -eq $Name } | Select-Object -Last 1
52
+ if ($null -eq $step) {
53
+ return 'skipped'
54
+ }
55
+
56
+ if ([bool]$step.success) {
57
+ return 'ok'
58
+ }
59
+
60
+ return 'failed'
61
+ }
62
+
63
+ function Test-CommandAvailable {
64
+ param(
65
+ [string]$Name
66
+ )
67
+
68
+ return [bool](Get-Command $Name -ErrorAction SilentlyContinue)
69
+ }
70
+
71
+ function Get-TokenSaverConfigPath {
72
+ param(
73
+ [string]$RepoRoot
74
+ )
75
+
76
+ return Join-Path $RepoRoot '.token-saver.json'
77
+ }
78
+
79
+ function Get-TokenSaverMode {
80
+ param(
81
+ [string]$RepoRoot
82
+ )
83
+
84
+ $configPath = Get-TokenSaverConfigPath -RepoRoot $RepoRoot
85
+ if (-not (Test-Path $configPath)) {
86
+ return 'off'
87
+ }
88
+
89
+ try {
90
+ $config = Get-Content $configPath -Raw | ConvertFrom-Json -Depth 10
91
+ $mode = [string]$config.mode
92
+ if ([string]::IsNullOrWhiteSpace($mode)) {
93
+ return 'off'
94
+ }
95
+
96
+ return $mode
97
+ }
98
+ catch {
99
+ return 'off'
100
+ }
101
+ }
102
+
103
+ function Ensure-TokenSaverActivated {
104
+ param(
105
+ [string]$RepoRoot,
106
+ [string]$DefaultMode = 'monitor'
107
+ )
108
+
109
+ $configPath = Get-TokenSaverConfigPath -RepoRoot $RepoRoot
110
+ $config = [ordered]@{}
111
+
112
+ if (Test-Path $configPath) {
113
+ try {
114
+ $existing = Get-Content $configPath -Raw | ConvertFrom-Json -Depth 20
115
+ foreach ($property in $existing.PSObject.Properties) {
116
+ $config[$property.Name] = $property.Value
117
+ }
118
+ }
119
+ catch {
120
+ # Si el JSON está corrupto, se regenera con configuración mínima segura.
121
+ $config = [ordered]@{}
122
+ }
123
+ }
124
+
125
+ $currentMode = ''
126
+ if ($config.Contains('mode')) {
127
+ $currentMode = [string]$config.mode
128
+ }
129
+
130
+ if ([string]::IsNullOrWhiteSpace($currentMode) -or $currentMode -eq 'off') {
131
+ $config.mode = $DefaultMode
132
+ }
133
+
134
+ if (-not $config.Contains('suppressLogs')) {
135
+ $config.suppressLogs = $true
136
+ }
137
+
138
+ if (-not $config.Contains('suppressRepetitiveHistory')) {
139
+ $config.suppressRepetitiveHistory = $true
140
+ }
141
+
142
+ $config | ConvertTo-Json -Depth 10 | Set-Content -Path $configPath -Encoding UTF8
143
+ }
144
+
145
+ function New-StepLogPath {
146
+ param(
147
+ [string]$StepName
148
+ )
149
+
150
+ $logDir = Join-Path $repoRoot 'observability/logs/session'
151
+ New-Item -ItemType Directory -Path $logDir -Force | Out-Null
152
+ $stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
153
+ $safeName = ($StepName.ToLowerInvariant() -replace '[^a-z0-9]+', '-') -replace '(^-|-$)', ''
154
+ return Join-Path $logDir ("{0}-{1}.log" -f $safeName, $stamp)
155
+ }
156
+
157
+ function Invoke-LoggedAction {
158
+ param(
159
+ [string]$StepName,
160
+ [scriptblock]$Action,
161
+ [string[]]$InfoLines = @()
162
+ )
163
+
164
+ $logPath = New-StepLogPath -StepName $StepName
165
+ & $Action *> $logPath
166
+ $exitCode = $LASTEXITCODE
167
+ if ($exitCode -ne 0) {
168
+ throw "$StepName failed with exit code $exitCode. Log: $logPath"
169
+ }
170
+
171
+ foreach ($infoLine in $InfoLines) {
172
+ Write-Host ("[info] {0}" -f $infoLine)
173
+ }
174
+ Write-Host ("[info] Log: {0}" -f $logPath)
175
+
176
+ return $logPath
177
+ }
178
+
179
+ function Resolve-CopilotSessionLogPath {
180
+ $fromEnv = [string]$env:VSCODE_TARGET_SESSION_LOG
181
+ if (-not [string]::IsNullOrWhiteSpace($fromEnv)) {
182
+ if (Test-Path $fromEnv) {
183
+ return (Resolve-Path $fromEnv).Path
184
+ }
185
+ }
186
+
187
+ $workspaceStorage = Join-Path $env:APPDATA 'Code\User\workspaceStorage'
188
+ if (-not (Test-Path $workspaceStorage)) {
189
+ return ''
190
+ }
191
+
192
+ $candidates = Get-ChildItem -Path $workspaceStorage -Recurse -File -Filter 'main.jsonl' -ErrorAction SilentlyContinue |
193
+ Where-Object { $_.FullName -match 'GitHub\.copilot-chat[\\/]debug-logs[\\/][0-9a-fA-F-]{36}[\\/]main\.jsonl$' } |
194
+ Sort-Object LastWriteTime -Descending
195
+
196
+ if ($null -eq $candidates -or $candidates.Count -eq 0) {
197
+ return ''
198
+ }
199
+
200
+ return $candidates[0].FullName
201
+ }
202
+
203
+ function Get-HiSummary {
204
+ param(
205
+ [string]$RepoRoot,
206
+ [datetime]$StartedAt,
207
+ [datetime]$EndedAt
208
+ )
209
+
210
+ $okCount = @($script:Steps | Where-Object { $_.success }).Count
211
+ $failedCount = @($script:Steps | Where-Object { -not $_.success -and $_.required }).Count
212
+ $optionalFailedCount = @($script:Steps | Where-Object { -not $_.success -and -not $_.required }).Count
213
+ $skipped = @()
214
+
215
+ if ($SkipSiblingReposChecks) { $skipped += 'Validate sibling repos operability' }
216
+ if ($SkipAgentPipelinePreflight) { $skipped += 'Validate agent pipeline preflight' }
217
+ if ($SkipMcpStartupChecks) { $skipped += 'Validate MCP servers start/listen capability' }
218
+ if ($SkipGraphRefresh) { $skipped += 'Refresh codegraph index sync' }
219
+ if ($SkipIntake) { $skipped += 'Run repo intake' }
220
+ if ($SkipRoutingEvals) { $skipped += 'Run routing evals' }
221
+ if ($SkipProjectNotesRefresh) { $skipped += 'Refresh project notes from observability' }
222
+ if ($SkipCopilotUsageIngest) { $skipped += 'Ingest Copilot session token usage (best effort)' }
223
+ if ($SkipChatTokenUsageReport) { $skipped += 'Refresh chat token usage report' }
224
+ if ($SkipCodegraphStatus) { $skipped += 'Check codegraph status' }
225
+
226
+ $engineSummary = [ordered]@{
227
+ memory = [ordered]@{
228
+ command_available = Test-CommandAvailable -Name 'codebase-memory-mcp'
229
+ startup_check = Get-StepStatus -Name 'Validate MCP servers start/listen capability'
230
+ }
231
+ token_saver = [ordered]@{
232
+ command_available = Test-CommandAvailable -Name 'token-saver-mcp'
233
+ mode = Get-TokenSaverMode -RepoRoot $RepoRoot
234
+ startup_check = Get-StepStatus -Name 'Validate MCP servers start/listen capability'
235
+ }
236
+ codegraph = [ordered]@{
237
+ command_available = Test-CommandAvailable -Name 'codegraph'
238
+ index_present = Test-Path (Join-Path $RepoRoot '.codegraph')
239
+ sync = Get-StepStatus -Name 'Refresh codegraph index sync'
240
+ status = Get-StepStatus -Name 'Check codegraph status'
241
+ }
242
+ gitnexus = [ordered]@{
243
+ command_available = Test-CommandAvailable -Name 'npx'
244
+ index_present = Test-Path (Join-Path $RepoRoot '.gitnexus')
245
+ startup_check = Get-StepStatus -Name 'Validate MCP servers start/listen capability'
246
+ }
247
+ repomix = [ordered]@{
248
+ command_available = Test-CommandAvailable -Name 'npx'
249
+ startup_check = Get-StepStatus -Name 'Validate MCP servers start/listen capability'
250
+ }
251
+ graphify = [ordered]@{
252
+ graph_present = Test-Path (Join-Path $RepoRoot 'context/graphify-out/graph.json')
253
+ manifest_present = Test-Path (Join-Path $RepoRoot 'context/graphify-out/manifest.json')
254
+ startup_check = Get-StepStatus -Name 'Validate MCP servers start/listen capability'
255
+ }
256
+ }
257
+
258
+ $artifactSummary = [ordered]@{
259
+ repo_registry_report = Test-Path (Join-Path $RepoRoot 'repo-intake/generated/reports/repo-registry-validation.json')
260
+ repo_intake = Get-StepStatus -Name 'Run repo intake'
261
+ routing_evals = Get-StepStatus -Name 'Run routing evals'
262
+ project_notes = Get-StepStatus -Name 'Refresh project notes from observability'
263
+ copilot_usage_ingest = Get-StepStatus -Name 'Ingest Copilot session token usage (best effort)'
264
+ chat_token_usage_report = Get-StepStatus -Name 'Refresh chat token usage report'
265
+ sibling_repos = Get-StepStatus -Name 'Validate sibling repos operability'
266
+ structure_cache = [ordered]@{
267
+ refreshed = [bool]$script:StructureCacheReport.refreshed
268
+ refresh_reason = [string]$script:StructureCacheReport.refresh_reason
269
+ changed_repos = @($script:StructureCacheReport.changed_repos).Count
270
+ }
271
+ }
272
+
273
+ return [ordered]@{
274
+ result = if ($script:HasFailures) { 'failed' } else { 'ok' }
275
+ started_at = $StartedAt.ToString('o')
276
+ ended_at = $EndedAt.ToString('o')
277
+ duration_sec = [math]::Round((($EndedAt - $StartedAt).TotalSeconds), 2)
278
+ steps = [ordered]@{
279
+ total = @($script:Steps).Count
280
+ ok = $okCount
281
+ failed_required = $failedCount
282
+ failed_optional = $optionalFailedCount
283
+ skipped = $skipped.Count
284
+ }
285
+ engines = $engineSummary
286
+ artifacts = $artifactSummary
287
+ skipped_steps = $skipped
288
+ }
289
+ }
290
+
291
+ function Write-HiSummary {
292
+ param(
293
+ [object]$Summary,
294
+ [string]$ReportPath
295
+ )
296
+
297
+ Write-Host ''
298
+ Write-Host '=== HI SUMMARY ===' -ForegroundColor Cyan
299
+ Write-Host ("Result: {0} | Duration: {1}s" -f $Summary.result.ToUpperInvariant(), $Summary.duration_sec)
300
+ Write-Host ("Steps: total={0}, ok={1}, failed_required={2}, failed_optional={3}, skipped={4}" -f $Summary.steps.total, $Summary.steps.ok, $Summary.steps.failed_required, $Summary.steps.failed_optional, $Summary.steps.skipped)
301
+ Write-Host 'Engines:'
302
+ Write-Host ("- memory: command={0}, startup={1}" -f $Summary.engines.memory.command_available, $Summary.engines.memory.startup_check)
303
+ Write-Host ("- token-saver: command={0}, mode={1}, startup={2}" -f $Summary.engines.token_saver.command_available, $Summary.engines.token_saver.mode, $Summary.engines.token_saver.startup_check)
304
+ Write-Host ("- codegraph: command={0}, index={1}, sync={2}, status={3}" -f $Summary.engines.codegraph.command_available, $Summary.engines.codegraph.index_present, $Summary.engines.codegraph.sync, $Summary.engines.codegraph.status)
305
+ Write-Host ("- gitnexus: command={0}, index={1}, startup={2}" -f $Summary.engines.gitnexus.command_available, $Summary.engines.gitnexus.index_present, $Summary.engines.gitnexus.startup_check)
306
+ Write-Host ("- repomix: command={0}, startup={1}" -f $Summary.engines.repomix.command_available, $Summary.engines.repomix.startup_check)
307
+ Write-Host ("- graphify: graph={0}, manifest={1}, startup={2}" -f $Summary.engines.graphify.graph_present, $Summary.engines.graphify.manifest_present, $Summary.engines.graphify.startup_check)
308
+ Write-Host 'Artifacts:'
309
+ Write-Host ("- repo-registry-report: {0}" -f $Summary.artifacts.repo_registry_report)
310
+ Write-Host ("- repo-intake: {0}" -f $Summary.artifacts.repo_intake)
311
+ Write-Host ("- routing-evals: {0}" -f $Summary.artifacts.routing_evals)
312
+ Write-Host ("- project-notes: {0}" -f $Summary.artifacts.project_notes)
313
+ Write-Host ("- copilot-usage-ingest: {0}" -f $Summary.artifacts.copilot_usage_ingest)
314
+ Write-Host ("- chat-token-usage-report: {0}" -f $Summary.artifacts.chat_token_usage_report)
315
+ Write-Host ("- sibling-repos: {0}" -f $Summary.artifacts.sibling_repos)
316
+ Write-Host ("- structure-cache: refreshed={0}, reason={1}, changed_repos={2}" -f $Summary.artifacts.structure_cache.refreshed, $Summary.artifacts.structure_cache.refresh_reason, $Summary.artifacts.structure_cache.changed_repos)
317
+ if (@($Summary.skipped_steps).Count -gt 0) {
318
+ Write-Host ("Skipped: {0}" -f (($Summary.skipped_steps) -join ', '))
319
+ }
320
+ Write-Host ("Report: {0}" -f $ReportPath)
321
+ }
322
+
323
+ function Invoke-Step {
324
+ param(
325
+ [string]$Name,
326
+ [scriptblock]$Action,
327
+ [bool]$Required = $true
328
+ )
329
+
330
+ $start = Get-Date
331
+ $success = $false
332
+ $message = 'ok'
333
+
334
+ try {
335
+ & $Action
336
+ $success = $true
337
+ Write-Host "[ok] $Name" -ForegroundColor Green
338
+ }
339
+ catch {
340
+ $message = $_.Exception.Message
341
+ if ($Required) {
342
+ $script:HasFailures = $true
343
+ Write-Host "[fail] $Name -> $message" -ForegroundColor Red
344
+ }
345
+ else {
346
+ Write-Host "[info] $Name -> $message" -ForegroundColor DarkYellow
347
+ }
348
+ }
349
+
350
+ $duration = ((Get-Date) - $start).TotalSeconds
351
+ $script:Steps += (New-StepResult -Name $Name -Required $Required -Success $success -DurationSec $duration -Message $message)
352
+ }
353
+
354
+ function Resolve-RepoPath {
355
+ param(
356
+ [string]$Root,
357
+ [string]$RelativePath
358
+ )
359
+
360
+ if ([System.IO.Path]::IsPathRooted($RelativePath)) {
361
+ return (Resolve-Path $RelativePath).Path
362
+ }
363
+ return [System.IO.Path]::GetFullPath((Join-Path $Root $RelativePath))
364
+ }
365
+
366
+ function Get-RepoField {
367
+ param(
368
+ [object]$Repo,
369
+ [string]$Name,
370
+ [string]$Default = ''
371
+ )
372
+
373
+ if ($null -eq $Repo) {
374
+ return $Default
375
+ }
376
+
377
+ $prop = $Repo.PSObject.Properties[$Name]
378
+ if ($null -eq $prop -or $null -eq $prop.Value) {
379
+ return $Default
380
+ }
381
+
382
+ return [string]$prop.Value
383
+ }
384
+
385
+ function Resolve-RegistryRepoPath {
386
+ param(
387
+ [string]$Root,
388
+ [object]$Repo
389
+ )
390
+
391
+ $repoType = (Get-RepoField -Repo $Repo -Name 'type' -Default 'local').ToLowerInvariant()
392
+ if ($repoType -eq 'github') {
393
+ $cacheLocation = Get-RepoField -Repo $Repo -Name 'cache_location'
394
+ if (-not [string]::IsNullOrWhiteSpace($cacheLocation)) {
395
+ return Resolve-RepoPath -Root $Root -RelativePath $cacheLocation
396
+ }
397
+
398
+ $repoName = Get-RepoField -Repo $Repo -Name 'name' -Default 'unknown'
399
+ $slug = $repoName.ToLowerInvariant() -replace '[^a-z0-9_-]+', '-'
400
+ return [System.IO.Path]::GetFullPath((Join-Path $Root (".cache/github-repos/{0}" -f $slug)))
401
+ }
402
+
403
+ $location = Get-RepoField -Repo $Repo -Name 'location'
404
+ if ([string]::IsNullOrWhiteSpace($location)) {
405
+ throw "Registry repo is missing location: $(Get-RepoField -Repo $Repo -Name 'name' -Default '<unknown>')"
406
+ }
407
+
408
+ return Resolve-RepoPath -Root $Root -RelativePath $location
409
+ }
410
+
411
+ function Get-PathLastWriteUtc {
412
+ param(
413
+ [string]$Path
414
+ )
415
+
416
+ if (-not (Test-Path $Path)) {
417
+ return [datetime]::MinValue
418
+ }
419
+
420
+ $item = Get-Item $Path -ErrorAction Stop
421
+ if (-not $item.PSIsContainer) {
422
+ return $item.LastWriteTimeUtc
423
+ }
424
+
425
+ $max = $item.LastWriteTimeUtc
426
+ $children = Get-ChildItem -Path $Path -Recurse -File -ErrorAction SilentlyContinue
427
+ foreach ($child in $children) {
428
+ if ($child.LastWriteTimeUtc -gt $max) {
429
+ $max = $child.LastWriteTimeUtc
430
+ }
431
+ }
432
+
433
+ return $max
434
+ }
435
+
436
+ function Get-StructureSnapshot {
437
+ param(
438
+ [string]$RepoRoot,
439
+ [object]$Repo
440
+ )
441
+
442
+ $repoName = Get-RepoField -Repo $Repo -Name 'name'
443
+ $slug = $repoName.ToLower() -replace '[^a-z0-9_-]+', '-'
444
+ $repoPath = Resolve-RegistryRepoPath -Root $RepoRoot -Repo $Repo
445
+ $structurePath = Join-Path $RepoRoot ("repo-intake/generated/{0}/context-manifests/structure-min.json" -f $slug)
446
+
447
+ $repoLatest = [datetime]::MinValue
448
+ if (Test-Path $repoPath) {
449
+ $pathsToCheck = @(
450
+ $repoPath,
451
+ (Join-Path $repoPath 'AGENTS.md'),
452
+ (Join-Path $repoPath 'README.md'),
453
+ (Join-Path $repoPath 'ARCHITECTURE.md'),
454
+ (Join-Path $repoPath '.github/skills'),
455
+ (Join-Path $repoPath '.github/prompts'),
456
+ (Join-Path $repoPath 'scripts'),
457
+ (Join-Path $repoPath 'specs')
458
+ )
459
+
460
+ foreach ($path in $pathsToCheck) {
461
+ $lastWrite = Get-PathLastWriteUtc -Path $path
462
+ if ($lastWrite -gt $repoLatest) {
463
+ $repoLatest = $lastWrite
464
+ }
465
+ }
466
+ }
467
+
468
+ $exists = Test-Path $structurePath
469
+ $structureMtime = [datetime]::MinValue
470
+ $cacheFingerprint = ''
471
+ $structureRepoExists = $false
472
+
473
+ if ($exists) {
474
+ $structureMtime = (Get-Item $structurePath).LastWriteTimeUtc
475
+ $structureData = Get-Content $structurePath -Raw | ConvertFrom-Json -Depth 20
476
+ $cacheFingerprint = [string]$structureData.cache_fingerprint
477
+ $structureRepoExists = [bool]$structureData.exists
478
+ }
479
+
480
+ $status = 'fresh'
481
+ if (-not $exists) {
482
+ $status = 'missing'
483
+ }
484
+ elseif ((Test-Path $repoPath) -and $repoLatest -gt $structureMtime) {
485
+ $status = 'stale'
486
+ }
487
+
488
+ return [ordered]@{
489
+ repo = $repoName
490
+ slug = $slug
491
+ version = '0'
492
+ repo_path = $repoPath
493
+ structure_path = $structurePath
494
+ structure_exists = $exists
495
+ structure_reports_repo_exists = $structureRepoExists
496
+ cache_fingerprint = $cacheFingerprint
497
+ repo_latest_change_utc = if ($repoLatest -eq [datetime]::MinValue) { '' } else { $repoLatest.ToString('o') }
498
+ structure_mtime_utc = if ($structureMtime -eq [datetime]::MinValue) { '' } else { $structureMtime.ToString('o') }
499
+ status = $status
500
+ }
501
+ }
502
+
503
+ function Test-LongRunningCommand {
504
+ param(
505
+ [string]$Name,
506
+ [string]$Command,
507
+ [int]$WarmupSec = 4,
508
+ [int]$TimeoutSec = 25
509
+ )
510
+
511
+ $outFile = Join-Path $env:TEMP ("hi-mcp-{0}-{1}.out" -f $Name, ([guid]::NewGuid().ToString('N')))
512
+ $errFile = Join-Path $env:TEMP ("hi-mcp-{0}-{1}.err" -f $Name, ([guid]::NewGuid().ToString('N')))
513
+
514
+ $proc = Start-Process -FilePath 'pwsh' -ArgumentList @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', $Command) -PassThru -RedirectStandardOutput $outFile -RedirectStandardError $errFile
515
+ $start = Get-Date
516
+ $deadline = $start.AddSeconds($TimeoutSec)
517
+ $isReady = $false
518
+
519
+ while ((Get-Date) -lt $deadline) {
520
+ if ($proc.HasExited) {
521
+ if ($proc.ExitCode -eq 0) {
522
+ $isReady = $true
523
+ break
524
+ }
525
+
526
+ $errText = ''
527
+ if (Test-Path $errFile) {
528
+ $errText = (Get-Content $errFile -Raw)
529
+ }
530
+ throw "$Name failed to start. ExitCode=$($proc.ExitCode). $errText"
531
+ }
532
+
533
+ if (((Get-Date) - $start).TotalSeconds -ge $WarmupSec) {
534
+ $isReady = $true
535
+ break
536
+ }
537
+
538
+ Start-Sleep -Milliseconds 250
539
+ }
540
+
541
+ if (-not $isReady) {
542
+ throw "$Name did not become ready within ${TimeoutSec}s"
543
+ }
544
+
545
+ if (-not $proc.HasExited) {
546
+ Stop-Process -Id $proc.Id -Force
547
+ }
548
+
549
+ Remove-Item $outFile, $errFile -ErrorAction SilentlyContinue
550
+ }
551
+
552
+ function Ensure-CodegraphInitialized {
553
+ param(
554
+ [string]$RepoRootPath
555
+ )
556
+
557
+ $indexPath = Join-Path $RepoRootPath '.codegraph'
558
+ if (Test-Path $indexPath) {
559
+ return $false
560
+ }
561
+
562
+ Write-Host '[info] CodeGraph not initialized. Running codegraph init automatically...' -ForegroundColor DarkYellow
563
+ & codegraph init
564
+ if ($LASTEXITCODE -ne 0) {
565
+ throw "codegraph init failed with exit code $LASTEXITCODE"
566
+ }
567
+
568
+ return $true
569
+ }
570
+
571
+ function Ensure-SetupPrerequisites {
572
+ if ($script:SetupAttempted) {
573
+ if (-not $script:SetupSucceeded) {
574
+ throw 'setup-prerequisites was already attempted and failed earlier in this run'
575
+ }
576
+ return $true
577
+ }
578
+
579
+ $script:SetupAttempted = $true
580
+ Write-Host '[info] Missing prerequisite detected. Running setup-prerequisites automatically...' -ForegroundColor DarkYellow
581
+ & pwsh -NoProfile -ExecutionPolicy Bypass -File .\scripts\setup\setup-prerequisites.ps1
582
+ if ($LASTEXITCODE -ne 0) {
583
+ $script:SetupSucceeded = $false
584
+ throw "setup-prerequisites failed with exit code $LASTEXITCODE"
585
+ }
586
+
587
+ $script:SetupSucceeded = $true
588
+ return $true
589
+ }
590
+
591
+ function Ensure-GitNexusIndexed {
592
+ param(
593
+ [string]$RepoRootPath
594
+ )
595
+
596
+ $indexArtifact = Join-Path (Join-Path $RepoRootPath '.gitnexus') 'lbug'
597
+ if (Test-Path $indexArtifact) {
598
+ return $false
599
+ }
600
+
601
+ if ($script:GitNexusAnalyzeAttempted) {
602
+ return $script:GitNexusAnalyzeSucceeded
603
+ }
604
+
605
+ $script:GitNexusAnalyzeAttempted = $true
606
+ Write-Host '[info] GitNexus has no index. Running gitnexus analyze automatically...' -ForegroundColor DarkYellow
607
+ & npx -y gitnexus@latest analyze
608
+ if ($LASTEXITCODE -ne 0) {
609
+ $script:GitNexusAnalyzeSucceeded = $false
610
+ Write-Host "[info] gitnexus analyze failed with exit code $LASTEXITCODE" -ForegroundColor DarkYellow
611
+ return $false
612
+ }
613
+
614
+ if (-not (Test-Path $indexArtifact)) {
615
+ $script:GitNexusAnalyzeSucceeded = $false
616
+ Write-Host '[info] gitnexus analyze finished but local index artifact was not detected' -ForegroundColor DarkYellow
617
+ return $false
618
+ }
619
+
620
+ $script:GitNexusAnalyzeSucceeded = $true
621
+ return $true
622
+ }
623
+
624
+ $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
625
+ Set-Location $repoRoot
626
+
627
+ $script:Steps = @()
628
+ $script:HasFailures = $false
629
+ $script:SetupAttempted = $false
630
+ $script:SetupSucceeded = $false
631
+ $script:GitNexusAnalyzeAttempted = $false
632
+ $script:GitNexusAnalyzeSucceeded = $false
633
+ $script:StructureCacheReport = [ordered]@{
634
+ refreshed = $false
635
+ refresh_reason = 'none'
636
+ before = @()
637
+ after = @()
638
+ changed_repos = @()
639
+ }
640
+ $script:StepLogs = [ordered]@{}
641
+ $startedAt = Get-Date
642
+
643
+ Write-Host '=== HI STARTUP ===' -ForegroundColor Cyan
644
+ Write-Host "Repo: $repoRoot"
645
+ Write-Host "Time: $startedAt"
646
+
647
+ $validateContextAction = {
648
+ & pwsh -NoProfile -ExecutionPolicy Bypass -File .\scripts\setup\validate-context.ps1
649
+ if ($LASTEXITCODE -ne 0) {
650
+ throw "validate-context failed with exit code $LASTEXITCODE"
651
+ }
652
+ }
653
+
654
+ Invoke-Step -Name 'Validate context' -Action $validateContextAction -Required $true
655
+
656
+ if ($script:HasFailures) {
657
+ $script:HasFailures = $false
658
+ Invoke-Step -Name 'Setup prerequisites' -Action {
659
+ [void](Ensure-SetupPrerequisites)
660
+ } -Required $true
661
+
662
+ Invoke-Step -Name 'Validate context (retry)' -Action $validateContextAction -Required $true
663
+ }
664
+
665
+ Invoke-Step -Name 'Validate memory/cache artifacts' -Action {
666
+ $requiredPaths = @(
667
+ 'repo-intake/generated',
668
+ 'context/graphify-out/graph.json',
669
+ 'context/graphify-out/manifest.json',
670
+ 'repo-intake/generated/reports/repo-registry-validation.json'
671
+ )
672
+
673
+ $missingArtifacts = @()
674
+ foreach ($item in $requiredPaths) {
675
+ if (-not (Test-Path $item)) {
676
+ $missingArtifacts += $item
677
+ }
678
+ }
679
+
680
+ if ($missingArtifacts.Count -gt 0 -and -not $SkipIntake) {
681
+ Write-Host '[info] Missing generated artifacts detected. Running repo intake automatically...' -ForegroundColor DarkYellow
682
+ $script:StepLogs['recover-missing-artifacts'] = Invoke-LoggedAction -StepName 'recover-missing-artifacts' -Action {
683
+ & .\scripts\intake\run-repo-intake.cmd
684
+ }
685
+ }
686
+
687
+ foreach ($item in $requiredPaths) {
688
+ if (-not (Test-Path $item)) {
689
+ throw "Missing required artifact: $item"
690
+ }
691
+ }
692
+
693
+ if (-not (Get-Command codebase-memory-mcp -ErrorAction SilentlyContinue)) {
694
+ [void](Ensure-SetupPrerequisites)
695
+ }
696
+
697
+ if (-not (Get-Command codebase-memory-mcp -ErrorAction SilentlyContinue)) {
698
+ throw 'codebase-memory-mcp command not found (memory layer unavailable)'
699
+ }
700
+ } -Required $true
701
+
702
+ Invoke-Step -Name 'Activate token-saver mode' -Action {
703
+ if (-not (Test-CommandAvailable -Name 'token-saver-mcp')) {
704
+ [void](Ensure-SetupPrerequisites)
705
+ }
706
+
707
+ if (-not (Test-CommandAvailable -Name 'token-saver-mcp')) {
708
+ throw 'token-saver-mcp command not found'
709
+ }
710
+
711
+ Ensure-TokenSaverActivated -RepoRoot $repoRoot -DefaultMode 'monitor'
712
+ $mode = Get-TokenSaverMode -RepoRoot $repoRoot
713
+ if ($mode -eq 'off') {
714
+ throw 'Token Saver remains in off mode after activation step'
715
+ }
716
+
717
+ Write-Host ("Token Saver mode: {0}" -f $mode)
718
+ } -Required $true
719
+
720
+ Invoke-Step -Name 'Check structure cache freshness' -Action {
721
+ $registryPath = Join-Path $repoRoot 'repo-registry/repos.yml'
722
+ $registry = Get-Content $registryPath -Raw | ConvertFrom-Json -Depth 20
723
+ $before = @()
724
+
725
+ foreach ($repo in $registry.repos) {
726
+ $before += (Get-StructureSnapshot -RepoRoot $repoRoot -Repo $repo)
727
+ }
728
+
729
+ $missing = @($before | Where-Object { $_.status -eq 'missing' }).Count
730
+ $stale = @($before | Where-Object { $_.status -eq 'stale' }).Count
731
+ $needsRefresh = ($missing -gt 0 -or $stale -gt 0)
732
+
733
+ $script:StructureCacheReport.before = $before
734
+ $script:StructureCacheReport.refresh_reason = if ($needsRefresh) {
735
+ "missing=$missing, stale=$stale"
736
+ }
737
+ else {
738
+ 'none'
739
+ }
740
+
741
+ if ($needsRefresh -and -not $SkipIntake) {
742
+ $script:StepLogs['structure-cache-refresh'] = Invoke-LoggedAction -StepName 'structure-cache-refresh' -Action {
743
+ & .\scripts\intake\run-repo-intake.cmd
744
+ }
745
+ $script:StructureCacheReport.refreshed = $true
746
+ }
747
+
748
+ $after = @()
749
+ foreach ($repo in $registry.repos) {
750
+ $after += (Get-StructureSnapshot -RepoRoot $repoRoot -Repo $repo)
751
+ }
752
+ $script:StructureCacheReport.after = $after
753
+
754
+ $changedRepos = @()
755
+ foreach ($beforeEntry in $before) {
756
+ $afterEntry = $after | Where-Object { $_.repo -eq $beforeEntry.repo } | Select-Object -First 1
757
+ if ($null -eq $afterEntry) {
758
+ continue
759
+ }
760
+
761
+ if ($beforeEntry.cache_fingerprint -ne $afterEntry.cache_fingerprint -or $beforeEntry.status -ne $afterEntry.status) {
762
+ $changedRepos += [ordered]@{
763
+ repo = $beforeEntry.repo
764
+ before_status = $beforeEntry.status
765
+ after_status = $afterEntry.status
766
+ before_fingerprint = $beforeEntry.cache_fingerprint
767
+ after_fingerprint = $afterEntry.cache_fingerprint
768
+ }
769
+ }
770
+ }
771
+ $script:StructureCacheReport.changed_repos = $changedRepos
772
+
773
+ Write-Host ("Structure cache status: missing={0}, stale={1}, refreshed={2}" -f $missing, $stale, $script:StructureCacheReport.refreshed)
774
+ } -Required $true
775
+
776
+ if (-not $SkipSiblingReposChecks) {
777
+ Invoke-Step -Name 'Validate sibling repos operability' -Action {
778
+ $registryPath = Join-Path $repoRoot 'repo-registry/repos.yml'
779
+ $registry = Get-Content $registryPath -Raw | ConvertFrom-Json -Depth 20
780
+
781
+ foreach ($repo in $registry.repos) {
782
+ $repoName = Get-RepoField -Repo $repo -Name 'name'
783
+ $location = Resolve-RegistryRepoPath -Root $repoRoot -Repo $repo
784
+ if (-not (Test-Path $location)) {
785
+ throw "Sibling repo path not found: $repoName -> $location"
786
+ }
787
+
788
+ $slug = $repoName.ToLower() -replace '[^a-z0-9_-]+', '-'
789
+ $manifest = Join-Path $repoRoot ("repo-intake/generated/{0}/context-manifests/manifest.json" -f $slug)
790
+ $structure = Join-Path $repoRoot ("repo-intake/generated/{0}/context-manifests/structure-min.json" -f $slug)
791
+ $capability = Join-Path $repoRoot ("repo-intake/generated/{0}/capabilities/capability.json" -f $slug)
792
+
793
+ if (-not (Test-Path $manifest)) {
794
+ throw "Missing sibling manifest: $manifest"
795
+ }
796
+ if (-not (Test-Path $structure)) {
797
+ throw "Missing sibling structure cache: $structure"
798
+ }
799
+ if (-not (Test-Path $capability)) {
800
+ throw "Missing sibling capability: $capability"
801
+ }
802
+
803
+ $structureData = Get-Content $structure -Raw | ConvertFrom-Json -Depth 20
804
+ if ([string]$structureData.repo -ne $repoName) {
805
+ throw "Structure cache repo mismatch for ${repoName}: found '$($structureData.repo)'"
806
+ }
807
+ $isOptional = (Get-RepoField -Repo $repo -Name 'optional' -Default 'false') -eq 'true'
808
+ if (-not [bool]$structureData.exists -and -not $isOptional) {
809
+ throw "Structure cache indicates missing path for required repo '$repoName'"
810
+ }
811
+ }
812
+ } -Required $true
813
+ }
814
+ else {
815
+ Write-Host '[skip] Validate sibling repos operability'
816
+ }
817
+
818
+ if (-not $SkipAgentPipelinePreflight) {
819
+ Invoke-Step -Name 'Validate agent pipeline preflight' -Action {
820
+ $py = Get-PythonCommand
821
+ $cmd = $py[0]
822
+ $pyParts = @()
823
+ if ($py.Length -gt 1) {
824
+ $pyParts = $py[1..($py.Length - 1)]
825
+ }
826
+
827
+ $script:StepLogs['agent-pipeline-preflight'] = Invoke-LoggedAction -StepName 'agent-pipeline-preflight' -Action {
828
+ & $cmd @pyParts .\scripts\intake\agent-pipeline-preflight.py
829
+ }
830
+ } -Required $true
831
+ }
832
+ else {
833
+ Write-Host '[skip] Validate agent pipeline preflight'
834
+ }
835
+
836
+ if (-not $SkipMcpStartupChecks) {
837
+ Invoke-Step -Name 'Validate MCP servers start/listen capability' -Action {
838
+ $py = Get-PythonCommand
839
+ $pyCmd = $py[0]
840
+ $pyParts = @()
841
+ if ($py.Length -gt 1) {
842
+ $pyParts = $py[1..($py.Length - 1)]
843
+ }
844
+
845
+ $graphifyCmd = "$pyCmd"
846
+ if ($pyParts.Count -gt 0) {
847
+ $graphifyCmd += " " + ($pyParts -join ' ')
848
+ }
849
+ $graphifyCmd += ' -m graphify.serve --transport stdio context/graphify-out/graph.json'
850
+
851
+ [void](Ensure-GitNexusIndexed -RepoRootPath $repoRoot)
852
+
853
+ $checks = @(
854
+ @{ name = 'token-saver-mcp'; command = 'token-saver-mcp' },
855
+ @{ name = 'codebase-memory-mcp'; command = 'codebase-memory-mcp' },
856
+ @{ name = 'codegraph'; command = 'codegraph serve --mcp' },
857
+ @{ name = 'gitnexus'; command = 'npx -y gitnexus@latest mcp' },
858
+ @{ name = 'repomix'; command = 'npx -y repomix@latest --mcp' },
859
+ @{ name = 'graphify'; command = $graphifyCmd }
860
+ )
861
+
862
+ foreach ($check in $checks) {
863
+ Test-LongRunningCommand -Name $check.name -Command $check.command
864
+ }
865
+ } -Required $true
866
+ }
867
+ else {
868
+ Write-Host '[skip] Validate MCP servers start/listen capability'
869
+ }
870
+
871
+ if (-not $SkipGraphRefresh) {
872
+ Invoke-Step -Name 'Refresh codegraph index sync' -Action {
873
+ if (-not (Get-Command codegraph -ErrorAction SilentlyContinue)) {
874
+ [void](Ensure-SetupPrerequisites)
875
+ }
876
+
877
+ if (-not (Get-Command codegraph -ErrorAction SilentlyContinue)) {
878
+ throw 'codegraph command not found'
879
+ }
880
+
881
+ [void](Ensure-CodegraphInitialized -RepoRootPath $repoRoot)
882
+
883
+ $script:StepLogs['codegraph-sync'] = Invoke-LoggedAction -StepName 'codegraph-sync' -Action {
884
+ & codegraph sync
885
+ }
886
+ } -Required $false
887
+ }
888
+ else {
889
+ Write-Host '[skip] Refresh codegraph index sync'
890
+ }
891
+
892
+ if (-not $SkipIntake) {
893
+ Invoke-Step -Name 'Run repo intake' -Action {
894
+ $script:StepLogs['repo-intake'] = Invoke-LoggedAction -StepName 'repo-intake' -Action {
895
+ & .\scripts\intake\run-repo-intake.cmd
896
+ }
897
+ } -Required $true
898
+ }
899
+ else {
900
+ Write-Host '[skip] Run repo intake'
901
+ }
902
+
903
+ if (-not $SkipRoutingEvals) {
904
+ Invoke-Step -Name 'Run routing evals' -Action {
905
+ $py = Get-PythonCommand
906
+ $cmd = $py[0]
907
+ $pyParts = @()
908
+ if ($py.Length -gt 1) {
909
+ $pyParts = $py[1..($py.Length - 1)]
910
+ }
911
+
912
+ $script:StepLogs['routing-evals'] = Invoke-LoggedAction -StepName 'routing-evals' -Action {
913
+ & $cmd @pyParts .\scripts\intake\run-routing-evals.py
914
+ }
915
+ } -Required $true
916
+ }
917
+ else {
918
+ Write-Host '[skip] Run routing evals'
919
+ }
920
+
921
+ if (-not $SkipProjectNotesRefresh) {
922
+ Invoke-Step -Name 'Refresh project notes from observability' -Action {
923
+ $py = Get-PythonCommand
924
+ $cmd = $py[0]
925
+ $pyParts = @()
926
+ if ($py.Length -gt 1) {
927
+ $pyParts = $py[1..($py.Length - 1)]
928
+ }
929
+
930
+ $script:StepLogs['project-notes-refresh'] = Invoke-LoggedAction -StepName 'project-notes-refresh' -Action {
931
+ & $cmd @pyParts .\scripts\discovery\refresh-project-notes.py
932
+ }
933
+ } -Required $false
934
+ }
935
+ else {
936
+ Write-Host '[skip] Refresh project notes from observability'
937
+ }
938
+
939
+ if (-not $SkipCopilotUsageIngest) {
940
+ Invoke-Step -Name 'Ingest Copilot session token usage (best effort)' -Action {
941
+ $py = Get-PythonCommand
942
+ $cmd = $py[0]
943
+ $pyParts = @()
944
+ if ($py.Length -gt 1) {
945
+ $pyParts = $py[1..($py.Length - 1)]
946
+ }
947
+
948
+ $sessionLogPath = Resolve-CopilotSessionLogPath
949
+ if ([string]::IsNullOrWhiteSpace($sessionLogPath)) {
950
+ Write-Host '[info] No Copilot session log found. Skipping ingest step without error.'
951
+ return
952
+ }
953
+
954
+ Write-Host ("[info] Using Copilot session log: {0}" -f $sessionLogPath)
955
+ & $cmd @pyParts .\scripts\learning\ingest-copilot-session-usage.py --session-log $sessionLogPath
956
+ if ($LASTEXITCODE -ne 0) {
957
+ throw "ingest-copilot-session-usage failed with exit code $LASTEXITCODE"
958
+ }
959
+ } -Required $false
960
+ }
961
+ else {
962
+ Write-Host '[skip] Ingest Copilot session token usage (best effort)'
963
+ }
964
+
965
+ if (-not $SkipChatTokenUsageReport) {
966
+ Invoke-Step -Name 'Refresh chat token usage report' -Action {
967
+ $py = Get-PythonCommand
968
+ $cmd = $py[0]
969
+ $pyParts = @()
970
+ if ($py.Length -gt 1) {
971
+ $pyParts = $py[1..($py.Length - 1)]
972
+ }
973
+
974
+ $plan = $env:COPILOT_PLAN
975
+ if ([string]::IsNullOrWhiteSpace($plan)) {
976
+ $plan = 'business'
977
+ }
978
+
979
+ $seats = $env:COPILOT_SEATS
980
+ if ([string]::IsNullOrWhiteSpace($seats)) {
981
+ $seats = '1'
982
+ }
983
+
984
+ Write-Host "[info] chat-token-usage-report plan=$plan seats=$seats"
985
+ & $cmd @pyParts .\scripts\learning\chat-token-usage-report.py --plan $plan --seats $seats
986
+ if ($LASTEXITCODE -ne 0) {
987
+ throw "chat-token-usage-report failed with exit code $LASTEXITCODE"
988
+ }
989
+ } -Required $false
990
+ }
991
+ else {
992
+ Write-Host '[skip] Refresh chat token usage report'
993
+ }
994
+
995
+ if (-not $SkipCodegraphStatus) {
996
+ Invoke-Step -Name 'Check codegraph status' -Action {
997
+ if (-not (Get-Command codegraph -ErrorAction SilentlyContinue)) {
998
+ [void](Ensure-SetupPrerequisites)
999
+ }
1000
+
1001
+ if (-not (Get-Command codegraph -ErrorAction SilentlyContinue)) {
1002
+ throw 'codegraph command not found'
1003
+ }
1004
+
1005
+ [void](Ensure-CodegraphInitialized -RepoRootPath $repoRoot)
1006
+
1007
+ $script:StepLogs['codegraph-status'] = Invoke-LoggedAction -StepName 'codegraph-status' -Action {
1008
+ & codegraph status
1009
+ }
1010
+ } -Required $false
1011
+ }
1012
+ else {
1013
+ Write-Host '[skip] Check codegraph status'
1014
+ }
1015
+
1016
+ $endedAt = Get-Date
1017
+ $summary = Get-HiSummary -RepoRoot $repoRoot -StartedAt $startedAt -EndedAt $endedAt
1018
+ $report = [ordered]@{
1019
+ session = 'hi'
1020
+ started_at = $startedAt.ToString('o')
1021
+ ended_at = $endedAt.ToString('o')
1022
+ duration_sec = [math]::Round((($endedAt - $startedAt).TotalSeconds), 2)
1023
+ repo = $repoRoot
1024
+ success = (-not $script:HasFailures)
1025
+ summary = $summary
1026
+ step_logs = $script:StepLogs
1027
+ structure_cache = $script:StructureCacheReport
1028
+ steps = $script:Steps
1029
+ }
1030
+
1031
+ $reportDir = Join-Path $repoRoot 'observability/logs/session'
1032
+ New-Item -ItemType Directory -Path $reportDir -Force | Out-Null
1033
+ $stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
1034
+ $reportPath = Join-Path $reportDir "hi-$stamp.json"
1035
+ $report | ConvertTo-Json -Depth 8 | Set-Content -Path $reportPath -Encoding UTF8
1036
+
1037
+ Write-HiSummary -Summary $summary -ReportPath $reportPath
1038
+
1039
+ if ($script:HasFailures) {
1040
+ Write-Host 'HI startup finished with errors.' -ForegroundColor Red
1041
+ exit 1
1042
+ }
1043
+
1044
+ Write-Host 'HI startup completed successfully.' -ForegroundColor Green
1045
+ exit 0