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,421 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import json
5
+ import os
6
+ import re
7
+ from datetime import datetime, timezone
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+
12
+ def utc_now() -> str:
13
+ return datetime.now(timezone.utc).isoformat()
14
+
15
+
16
+ def normalize_timestamp(raw: Any) -> str:
17
+ if raw is None:
18
+ return utc_now()
19
+
20
+ if isinstance(raw, (int, float)):
21
+ try:
22
+ return datetime.fromtimestamp(float(raw) / 1000.0, tz=timezone.utc).isoformat()
23
+ except Exception:
24
+ return utc_now()
25
+
26
+ text = str(raw).strip()
27
+ if not text:
28
+ return utc_now()
29
+
30
+ if text.isdigit():
31
+ try:
32
+ return datetime.fromtimestamp(float(text) / 1000.0, tz=timezone.utc).isoformat()
33
+ except Exception:
34
+ return utc_now()
35
+
36
+ return text
37
+
38
+
39
+ def parse_jsonl(path: Path) -> list[dict[str, Any]]:
40
+ if not path.exists():
41
+ return []
42
+ rows: list[dict[str, Any]] = []
43
+ for line in path.read_text(encoding="utf-8").splitlines():
44
+ line = line.strip()
45
+ if not line:
46
+ continue
47
+ try:
48
+ obj = json.loads(line)
49
+ except Exception:
50
+ continue
51
+ if isinstance(obj, dict):
52
+ rows.append(obj)
53
+ return rows
54
+
55
+
56
+ def normalize_model(raw: Any) -> str:
57
+ model = str(raw or "").strip()
58
+ return model or "unknown"
59
+
60
+
61
+ def read_seen_ids(metrics_rows: list[dict[str, Any]]) -> set[str]:
62
+ seen: set[str] = set()
63
+ for row in metrics_rows:
64
+ usage = row.get("usage", {}) if isinstance(row.get("usage", {}), dict) else {}
65
+ source = str(usage.get("source", "")).strip()
66
+ source_event_id = str(usage.get("source_event_id", "")).strip()
67
+ if source == "copilot-session" and source_event_id:
68
+ seen.add(source_event_id)
69
+ return seen
70
+
71
+
72
+ def index_existing_by_source_id(metrics_rows: list[dict[str, Any]]) -> dict[str, int]:
73
+ out: dict[str, int] = {}
74
+ for i, row in enumerate(metrics_rows):
75
+ usage = row.get("usage", {}) if isinstance(row.get("usage", {}), dict) else {}
76
+ source = str(usage.get("source", "")).strip()
77
+ source_event_id = str(usage.get("source_event_id", "")).strip()
78
+ if source == "copilot-session" and source_event_id:
79
+ out[source_event_id] = i
80
+ return out
81
+
82
+
83
+ def extract_usage_event_from_debug_row(row: dict[str, Any]) -> dict[str, Any] | None:
84
+ source_event_id = str(row.get("id") or row.get("event_id") or row.get("spanId") or "").strip()
85
+ if not source_event_id:
86
+ return None
87
+
88
+ data_candidates: list[dict[str, Any]] = []
89
+ for key in ("usage", "tokenUsage", "cost", "attrs"):
90
+ value = row.get(key)
91
+ if isinstance(value, dict):
92
+ data_candidates.append(value)
93
+
94
+ # Some event payloads keep nested data in a generic "data" envelope.
95
+ data = row.get("data")
96
+ if isinstance(data, dict):
97
+ for key in ("usage", "tokenUsage", "cost", "attrs"):
98
+ value = data.get(key)
99
+ if isinstance(value, dict):
100
+ data_candidates.append(value)
101
+
102
+ input_tokens = None
103
+ output_tokens = None
104
+ estimated_cost = 0.0
105
+
106
+ for bucket in data_candidates:
107
+ if input_tokens is None:
108
+ for key in ("input_tokens", "prompt_tokens", "inputTokens", "promptTokens"):
109
+ if key in bucket:
110
+ try:
111
+ input_tokens = int(bucket.get(key, 0) or 0)
112
+ except Exception:
113
+ input_tokens = None
114
+ break
115
+ if output_tokens is None:
116
+ for key in ("output_tokens", "completion_tokens", "outputTokens", "completionTokens"):
117
+ if key in bucket:
118
+ try:
119
+ output_tokens = int(bucket.get(key, 0) or 0)
120
+ except Exception:
121
+ output_tokens = None
122
+ break
123
+ if "estimated_cost_usd" in bucket:
124
+ try:
125
+ estimated_cost = float(bucket.get("estimated_cost_usd", 0.0) or 0.0)
126
+ except Exception:
127
+ estimated_cost = 0.0
128
+
129
+ if input_tokens is None or output_tokens is None:
130
+ return None
131
+
132
+ if input_tokens < 0 or output_tokens < 0:
133
+ return None
134
+
135
+ model = normalize_model(row.get("model") or row.get("modelId") or row.get("name"))
136
+ ts = normalize_timestamp(row.get("timestamp") or row.get("ts"))
137
+
138
+ return {
139
+ "source_event_id": source_event_id,
140
+ "timestamp": ts,
141
+ "model": model,
142
+ "input_tokens": input_tokens,
143
+ "output_tokens": output_tokens,
144
+ "estimated_cost_usd": round(estimated_cost, 6),
145
+ }
146
+
147
+
148
+ def parse_chat_sessions_usage(chat_session_rows: list[dict[str, Any]]) -> list[dict[str, Any]]:
149
+ # chatSessions JSONL is a state patch stream with records like:
150
+ # {"kind":2,"k":["requests"],"v":[{"requestId":"..."}]}
151
+ # {"kind":1,"k":["requests",N,"promptTokens"],"v":123}
152
+ # {"kind":1,"k":["requests",N,"completionTokens"],"v":45}
153
+ request_ids: list[str] = []
154
+ request_models: dict[int, str] = {}
155
+ prompt_tokens: dict[int, int] = {}
156
+ completion_tokens: dict[int, int] = {}
157
+ copilot_credits: dict[int, float] = {}
158
+ request_timestamps: dict[int, str] = {}
159
+
160
+ for row in chat_session_rows:
161
+ kind = row.get("kind")
162
+ key_path = row.get("k")
163
+ value = row.get("v")
164
+
165
+ if kind == 2 and key_path == ["requests"] and isinstance(value, list):
166
+ for item in value:
167
+ if not isinstance(item, dict):
168
+ continue
169
+ request_id = str(item.get("requestId", "")).strip()
170
+ if not request_id:
171
+ continue
172
+ request_index = len(request_ids)
173
+ request_ids.append(request_id)
174
+ request_timestamps[request_index] = normalize_timestamp(item.get("timestamp") or row.get("timestamp"))
175
+ request_models[request_index] = normalize_model(item.get("model") or item.get("modelId"))
176
+ continue
177
+
178
+ if kind != 1 or not isinstance(key_path, list) or len(key_path) < 3:
179
+ continue
180
+
181
+ if key_path[0] != "requests" or not isinstance(key_path[1], int):
182
+ continue
183
+
184
+ idx = int(key_path[1])
185
+ field = str(key_path[2])
186
+ if field == "promptTokens":
187
+ try:
188
+ prompt_tokens[idx] = int(value or 0)
189
+ except Exception:
190
+ pass
191
+ elif field == "completionTokens":
192
+ try:
193
+ completion_tokens[idx] = int(value or 0)
194
+ except Exception:
195
+ pass
196
+ elif field == "copilotCredits":
197
+ try:
198
+ copilot_credits[idx] = float(value or 0.0)
199
+ except Exception:
200
+ pass
201
+
202
+ usage_events: list[dict[str, Any]] = []
203
+ for idx, request_id in enumerate(request_ids):
204
+ in_tok = int(prompt_tokens.get(idx, -1))
205
+ out_tok = int(completion_tokens.get(idx, -1))
206
+ if in_tok < 0 or out_tok < 0:
207
+ continue
208
+
209
+ usage_events.append(
210
+ {
211
+ "source_event_id": request_id,
212
+ "timestamp": request_timestamps.get(idx, utc_now()),
213
+ "model": request_models.get(idx, "copilot/auto"),
214
+ "input_tokens": in_tok,
215
+ "output_tokens": out_tok,
216
+ "estimated_cost_usd": 0.0,
217
+ "copilot_credits": round(float(copilot_credits.get(idx, 0.0)), 6),
218
+ }
219
+ )
220
+
221
+ return usage_events
222
+
223
+
224
+ def derive_chat_sessions_path_from_session_path(session_path: Path) -> Path | None:
225
+ # Expected debug path pattern:
226
+ # .../workspaceStorage/<wsid>/GitHub.copilot-chat/debug-logs/<sid>/main.jsonl
227
+ parts = list(session_path.parts)
228
+ try:
229
+ i = parts.index("workspaceStorage")
230
+ except ValueError:
231
+ return None
232
+
233
+ if i + 1 >= len(parts):
234
+ return None
235
+
236
+ workspace_root = Path(*parts[: i + 2])
237
+ match = re.search(r"debug-logs[\\/](?P<sid>[0-9a-fA-F-]{36})", str(session_path))
238
+ if not match:
239
+ return None
240
+
241
+ sid = match.group("sid")
242
+ candidate = workspace_root / "chatSessions" / f"{sid}.jsonl"
243
+ if candidate.exists():
244
+ return candidate
245
+ return None
246
+
247
+
248
+ def build_metric(event_id: str, usage_event: dict[str, Any]) -> dict[str, Any]:
249
+ input_tokens = int(usage_event["input_tokens"])
250
+ output_tokens = int(usage_event["output_tokens"])
251
+ return {
252
+ "timestamp": str(usage_event["timestamp"]),
253
+ "event_id": event_id,
254
+ "model": str(usage_event["model"]),
255
+ "cost": {
256
+ "input_tokens": input_tokens,
257
+ "output_tokens": output_tokens,
258
+ "total_tokens": input_tokens + output_tokens,
259
+ "estimated_cost_usd": float(usage_event["estimated_cost_usd"]),
260
+ "copilot_credits": round(float(usage_event.get("copilot_credits", 0.0) or 0.0), 6),
261
+ },
262
+ "execution": {
263
+ "local_tools": 0,
264
+ "remote_tools": 0,
265
+ "tool_mode": "model-only",
266
+ },
267
+ "usage": {
268
+ "source": "copilot-session",
269
+ "source_event_id": str(usage_event["source_event_id"]),
270
+ },
271
+ "notes": "auto-ingested from VS Code Copilot session log",
272
+ }
273
+
274
+
275
+ def append_jsonl(path: Path, rows: list[dict[str, Any]]) -> None:
276
+ if not rows:
277
+ return
278
+ path.parent.mkdir(parents=True, exist_ok=True)
279
+ with path.open("a", encoding="utf-8") as fh:
280
+ for row in rows:
281
+ fh.write(json.dumps(row, ensure_ascii=False) + "\n")
282
+
283
+
284
+ def main() -> int:
285
+ parser = argparse.ArgumentParser(
286
+ description="Ingest token usage from VS Code Copilot debug session logs into iteration metrics (best effort)."
287
+ )
288
+ parser.add_argument("--session-log", default="", help="Absolute path to debug log path (file or directory)")
289
+ parser.add_argument("--chat-session-log", default="", help="Absolute path to workspaceStorage/chatSessions/<sid>.jsonl")
290
+ parser.add_argument("--metrics-log", default="observability/logs/iteration-metrics.jsonl")
291
+ parser.add_argument("--report", default="observability/logs/copilot-usage-ingest-report.json")
292
+ args = parser.parse_args()
293
+
294
+ repo_root = Path(__file__).resolve().parents[2]
295
+
296
+ session_log = args.session_log.strip()
297
+ if not session_log:
298
+ session_log = os.environ.get("VSCODE_TARGET_SESSION_LOG", "").strip()
299
+
300
+ if not session_log:
301
+ print("No session log provided. Use --session-log or set VSCODE_TARGET_SESSION_LOG.")
302
+ return 1
303
+
304
+ session_path = Path(session_log).resolve()
305
+ if session_path.is_dir():
306
+ # In this environment the variable can point to a folder; prefer main.jsonl.
307
+ candidate = session_path / "main.jsonl"
308
+ if candidate.exists():
309
+ session_path = candidate
310
+ else:
311
+ print(f"Session log directory does not contain main.jsonl: {session_path}")
312
+ return 1
313
+
314
+ if not session_path.exists():
315
+ print(f"Session log not found: {session_path}")
316
+ return 1
317
+
318
+ metrics_path = (repo_root / args.metrics_log).resolve()
319
+ report_path = (repo_root / args.report).resolve()
320
+
321
+ debug_rows = parse_jsonl(session_path)
322
+
323
+ chat_session_log = args.chat_session_log.strip()
324
+ if chat_session_log:
325
+ chat_session_path = Path(chat_session_log).resolve()
326
+ else:
327
+ chat_session_path = derive_chat_sessions_path_from_session_path(session_path)
328
+
329
+ chat_rows: list[dict[str, Any]] = []
330
+ if chat_session_path is not None and chat_session_path.exists():
331
+ chat_rows = parse_jsonl(chat_session_path)
332
+
333
+ metrics_rows = parse_jsonl(metrics_path)
334
+ seen_source_ids = read_seen_ids(metrics_rows)
335
+ existing_by_source_id = index_existing_by_source_id(metrics_rows)
336
+
337
+ to_append: list[dict[str, Any]] = []
338
+ scanned = 0
339
+ usage_found = 0
340
+ skipped_duplicates = 0
341
+ updated_existing = 0
342
+
343
+ # Prefer chatSessions since it contains per-request prompt/completion tokens.
344
+ for usage_event in parse_chat_sessions_usage(chat_rows):
345
+ scanned += 1
346
+ usage_found += 1
347
+
348
+ source_event_id = str(usage_event["source_event_id"])
349
+ if source_event_id in seen_source_ids:
350
+ skipped_duplicates += 1
351
+ existing_idx = existing_by_source_id.get(source_event_id)
352
+ if existing_idx is not None:
353
+ existing_row = metrics_rows[existing_idx]
354
+ cost = existing_row.get("cost", {}) if isinstance(existing_row.get("cost", {}), dict) else {}
355
+ existing_credits = float(cost.get("copilot_credits", 0.0) or 0.0)
356
+ incoming_credits = float(usage_event.get("copilot_credits", 0.0) or 0.0)
357
+ if incoming_credits > existing_credits:
358
+ cost["copilot_credits"] = round(incoming_credits, 6)
359
+ existing_row["cost"] = cost
360
+ updated_existing += 1
361
+ continue
362
+
363
+ synthetic_event_id = f"copilot-session::{source_event_id}"
364
+ to_append.append(build_metric(synthetic_event_id, usage_event))
365
+ seen_source_ids.add(source_event_id)
366
+
367
+ # Fallback to debug logs when chatSessions does not expose usage fields.
368
+ for row in debug_rows:
369
+ scanned += 1
370
+ usage_event = extract_usage_event_from_debug_row(row)
371
+ if usage_event is None:
372
+ continue
373
+ usage_found += 1
374
+
375
+ source_event_id = str(usage_event["source_event_id"])
376
+ if source_event_id in seen_source_ids:
377
+ skipped_duplicates += 1
378
+ continue
379
+
380
+ synthetic_event_id = f"copilot-session::{source_event_id}"
381
+ to_append.append(build_metric(synthetic_event_id, usage_event))
382
+ seen_source_ids.add(source_event_id)
383
+
384
+ append_jsonl(metrics_path, to_append)
385
+ if updated_existing > 0:
386
+ if to_append:
387
+ metrics_rows.extend(to_append)
388
+ metrics_path.parent.mkdir(parents=True, exist_ok=True)
389
+ with metrics_path.open("w", encoding="utf-8") as fh:
390
+ for row in metrics_rows:
391
+ fh.write(json.dumps(row, ensure_ascii=False) + "\n")
392
+
393
+ status = "no-usage-fields-found"
394
+ if usage_found > 0 and len(to_append) > 0:
395
+ status = "ok"
396
+ elif usage_found > 0 and len(to_append) == 0:
397
+ status = "duplicates-only"
398
+
399
+ report = {
400
+ "timestamp": utc_now(),
401
+ "session_log": str(session_path),
402
+ "chat_session_log": str(chat_session_path) if chat_session_path is not None else "",
403
+ "metrics_log": args.metrics_log.replace("\\", "/"),
404
+ "scanned_events": scanned,
405
+ "usage_events_detected": usage_found,
406
+ "inserted": len(to_append),
407
+ "updated_existing": updated_existing,
408
+ "skipped_duplicates": skipped_duplicates,
409
+ "status": status,
410
+ "note": "If status=no-usage-fields-found, this VS Code debug log currently does not expose per-turn token usage in a parseable shape.",
411
+ }
412
+
413
+ report_path.parent.mkdir(parents=True, exist_ok=True)
414
+ report_path.write_text(json.dumps(report, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
415
+
416
+ print(json.dumps(report, ensure_ascii=False, indent=2))
417
+ return 0
418
+
419
+
420
+ if __name__ == "__main__":
421
+ raise SystemExit(main())
@@ -0,0 +1,275 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import json
5
+ from collections import defaultdict
6
+ from datetime import datetime, timezone
7
+ from pathlib import Path
8
+ from typing import Any
9
+
10
+
11
+ def utc_now() -> str:
12
+ return datetime.now(timezone.utc).isoformat()
13
+
14
+
15
+ def safe_rate(num: int, den: int) -> float:
16
+ if den <= 0:
17
+ return 0.0
18
+ return num / den
19
+
20
+
21
+ def parse_jsonl(path: Path) -> list[dict[str, Any]]:
22
+ if not path.exists():
23
+ return []
24
+ rows: list[dict[str, Any]] = []
25
+ for line in path.read_text(encoding="utf-8").splitlines():
26
+ line = line.strip()
27
+ if not line:
28
+ continue
29
+ try:
30
+ obj = json.loads(line)
31
+ except Exception:
32
+ continue
33
+ if isinstance(obj, dict):
34
+ rows.append(obj)
35
+ return rows
36
+
37
+
38
+ def latest_by_event(rows: list[dict[str, Any]]) -> dict[str, dict[str, Any]]:
39
+ out: dict[str, dict[str, Any]] = {}
40
+ for row in rows:
41
+ event_id = str(row.get("event_id", "")).strip()
42
+ if not event_id:
43
+ continue
44
+ out[event_id] = row
45
+ return out
46
+
47
+
48
+ def build_report(
49
+ events: list[dict[str, Any]],
50
+ feedback_map: dict[str, dict[str, Any]],
51
+ metrics_map: dict[str, dict[str, Any]],
52
+ sources: dict[str, str],
53
+ ) -> dict[str, Any]:
54
+ total = len(events)
55
+ with_event_id = 0
56
+ metrics_covered = 0
57
+ confirmed = 0
58
+ confirmed_success = 0
59
+
60
+ total_tokens = 0
61
+ total_cost_usd = 0.0
62
+
63
+ by_mode = defaultdict(lambda: {"count": 0, "tokens": 0, "cost_usd": 0.0})
64
+ by_model = defaultdict(lambda: {"count": 0, "tokens": 0, "cost_usd": 0.0})
65
+ by_engine = defaultdict(lambda: {"count": 0, "tokens": 0, "cost_usd": 0.0})
66
+
67
+ for event in events:
68
+ event_id = str(event.get("event_id", "")).strip()
69
+ if not event_id:
70
+ continue
71
+ with_event_id += 1
72
+
73
+ fb = feedback_map.get(event_id, {})
74
+ fb_learning = fb.get("learning", {}) if isinstance(fb.get("learning", {}), dict) else {}
75
+ if str(fb_learning.get("outcome_status", "")) == "confirmed" and isinstance(fb_learning.get("success"), bool):
76
+ confirmed += 1
77
+ if bool(fb_learning.get("success")):
78
+ confirmed_success += 1
79
+
80
+ metric = metrics_map.get(event_id)
81
+ if not metric:
82
+ continue
83
+ metrics_covered += 1
84
+
85
+ cost = metric.get("cost", {}) if isinstance(metric.get("cost", {}), dict) else {}
86
+ exec_data = metric.get("execution", {}) if isinstance(metric.get("execution", {}), dict) else {}
87
+
88
+ tokens = int(cost.get("total_tokens", 0) or 0)
89
+ cost_usd = float(cost.get("estimated_cost_usd", 0.0) or 0.0)
90
+ mode = str(exec_data.get("tool_mode", "unknown"))
91
+ model = str(metric.get("model", "unknown"))
92
+ engine = str(event.get("engine", "unknown"))
93
+
94
+ total_tokens += tokens
95
+ total_cost_usd += cost_usd
96
+
97
+ by_mode[mode]["count"] += 1
98
+ by_mode[mode]["tokens"] += tokens
99
+ by_mode[mode]["cost_usd"] += cost_usd
100
+
101
+ by_model[model]["count"] += 1
102
+ by_model[model]["tokens"] += tokens
103
+ by_model[model]["cost_usd"] += cost_usd
104
+
105
+ by_engine[engine]["count"] += 1
106
+ by_engine[engine]["tokens"] += tokens
107
+ by_engine[engine]["cost_usd"] += cost_usd
108
+
109
+ tokens_per_confirmed_success = 0.0
110
+ cost_per_confirmed_success = 0.0
111
+ if confirmed_success > 0:
112
+ tokens_per_confirmed_success = round(total_tokens / confirmed_success, 2)
113
+ cost_per_confirmed_success = round(total_cost_usd / confirmed_success, 6)
114
+
115
+ report = {
116
+ "timestamp": utc_now(),
117
+ "sources": sources,
118
+ "totals": {
119
+ "events": total,
120
+ "events_with_event_id": with_event_id,
121
+ "metrics_covered": metrics_covered,
122
+ "feedback_confirmed": confirmed,
123
+ "confirmed_success": confirmed_success,
124
+ },
125
+ "kpis": {
126
+ "metrics_coverage_rate": round(safe_rate(metrics_covered, with_event_id), 4),
127
+ "confirmed_feedback_rate": round(safe_rate(confirmed, with_event_id), 4),
128
+ "confirmed_success_rate": round(safe_rate(confirmed_success, confirmed), 4),
129
+ "total_tokens": total_tokens,
130
+ "total_cost_usd": round(total_cost_usd, 6),
131
+ "tokens_per_confirmed_success": tokens_per_confirmed_success,
132
+ "cost_per_confirmed_success_usd": cost_per_confirmed_success,
133
+ },
134
+ "breakdown": {
135
+ "tool_mode": dict(sorted(by_mode.items())),
136
+ "model": dict(sorted(by_model.items())),
137
+ "engine": dict(sorted(by_engine.items())),
138
+ },
139
+ "assessment": {
140
+ "has_value_signal": confirmed_success > 0 and metrics_covered > 0,
141
+ "notes": (
142
+ "Insufficient confirmed outcomes or metrics coverage."
143
+ if not (confirmed_success > 0 and metrics_covered > 0)
144
+ else "Value signal available. Track trend, not one-point absolute values."
145
+ ),
146
+ },
147
+ }
148
+ return report
149
+
150
+
151
+ def to_markdown(report: dict[str, Any]) -> str:
152
+ totals = report.get("totals", {}) if isinstance(report.get("totals", {}), dict) else {}
153
+ kpis = report.get("kpis", {}) if isinstance(report.get("kpis", {}), dict) else {}
154
+ breakdown = report.get("breakdown", {}) if isinstance(report.get("breakdown", {}), dict) else {}
155
+ assessment = report.get("assessment", {}) if isinstance(report.get("assessment", {}), dict) else {}
156
+
157
+ lines = [
158
+ "# Iteration Value Report",
159
+ "",
160
+ f"- timestamp: {report.get('timestamp', '')}",
161
+ f"- events: {totals.get('events', 0)}",
162
+ f"- events_with_event_id: {totals.get('events_with_event_id', 0)}",
163
+ f"- metrics_covered: {totals.get('metrics_covered', 0)}",
164
+ f"- feedback_confirmed: {totals.get('feedback_confirmed', 0)}",
165
+ f"- confirmed_success: {totals.get('confirmed_success', 0)}",
166
+ "",
167
+ "## KPI",
168
+ "",
169
+ f"- metrics_coverage_rate: {round(float(kpis.get('metrics_coverage_rate', 0.0)) * 100, 2)}%",
170
+ f"- confirmed_feedback_rate: {round(float(kpis.get('confirmed_feedback_rate', 0.0)) * 100, 2)}%",
171
+ f"- confirmed_success_rate: {round(float(kpis.get('confirmed_success_rate', 0.0)) * 100, 2)}%",
172
+ f"- total_tokens: {kpis.get('total_tokens', 0)}",
173
+ f"- total_cost_usd: {kpis.get('total_cost_usd', 0.0)}",
174
+ f"- tokens_per_confirmed_success: {kpis.get('tokens_per_confirmed_success', 0.0)}",
175
+ f"- cost_per_confirmed_success_usd: {kpis.get('cost_per_confirmed_success_usd', 0.0)}",
176
+ "",
177
+ "## Breakdown",
178
+ "",
179
+ "### Tool mode",
180
+ ]
181
+
182
+ tool_mode = breakdown.get("tool_mode", {}) if isinstance(breakdown.get("tool_mode", {}), dict) else {}
183
+ if not tool_mode:
184
+ lines.append("- none")
185
+ else:
186
+ for mode, data in tool_mode.items():
187
+ if not isinstance(data, dict):
188
+ continue
189
+ lines.append(
190
+ f"- {mode}: count={data.get('count', 0)}, tokens={data.get('tokens', 0)}, cost_usd={round(float(data.get('cost_usd', 0.0)), 6)}"
191
+ )
192
+
193
+ lines.extend(["", "### Model"])
194
+ by_model = breakdown.get("model", {}) if isinstance(breakdown.get("model", {}), dict) else {}
195
+ if not by_model:
196
+ lines.append("- none")
197
+ else:
198
+ for model, data in by_model.items():
199
+ if not isinstance(data, dict):
200
+ continue
201
+ lines.append(
202
+ f"- {model}: count={data.get('count', 0)}, tokens={data.get('tokens', 0)}, cost_usd={round(float(data.get('cost_usd', 0.0)), 6)}"
203
+ )
204
+
205
+ lines.extend(["", "### Engine"])
206
+ by_engine = breakdown.get("engine", {}) if isinstance(breakdown.get("engine", {}), dict) else {}
207
+ if not by_engine:
208
+ lines.append("- none")
209
+ else:
210
+ for engine, data in by_engine.items():
211
+ if not isinstance(data, dict):
212
+ continue
213
+ lines.append(
214
+ f"- {engine}: count={data.get('count', 0)}, tokens={data.get('tokens', 0)}, cost_usd={round(float(data.get('cost_usd', 0.0)), 6)}"
215
+ )
216
+
217
+ lines.extend(
218
+ [
219
+ "",
220
+ "## Assessment",
221
+ "",
222
+ f"- has_value_signal: {assessment.get('has_value_signal', False)}",
223
+ f"- notes: {assessment.get('notes', '')}",
224
+ "",
225
+ ]
226
+ )
227
+
228
+ return "\n".join(lines)
229
+
230
+
231
+ def main() -> int:
232
+ parser = argparse.ArgumentParser(description="Build value-per-iteration report from routing, feedback and token metrics.")
233
+ parser.add_argument("--routing-log", default="observability/logs/routing-decisions.jsonl")
234
+ parser.add_argument("--feedback-log", default="observability/logs/learning-feedback.jsonl")
235
+ parser.add_argument("--metrics-log", default="observability/logs/iteration-metrics.jsonl")
236
+ parser.add_argument("--out-json", default="observability/evals/iteration-value-report.json")
237
+ parser.add_argument("--out-md", default="observability/evals/iteration-value-report.md")
238
+ args = parser.parse_args()
239
+
240
+ repo_root = Path(__file__).resolve().parents[2]
241
+ routing_path = (repo_root / args.routing_log).resolve()
242
+ feedback_path = (repo_root / args.feedback_log).resolve()
243
+ metrics_path = (repo_root / args.metrics_log).resolve()
244
+ out_json = (repo_root / args.out_json).resolve()
245
+ out_md = (repo_root / args.out_md).resolve()
246
+
247
+ events = parse_jsonl(routing_path)
248
+ feedback_rows = parse_jsonl(feedback_path)
249
+ metrics_rows = parse_jsonl(metrics_path)
250
+
251
+ report = build_report(
252
+ events,
253
+ latest_by_event(feedback_rows),
254
+ latest_by_event(metrics_rows),
255
+ {
256
+ "routing": args.routing_log.replace("\\", "/"),
257
+ "feedback": args.feedback_log.replace("\\", "/"),
258
+ "metrics": args.metrics_log.replace("\\", "/"),
259
+ },
260
+ )
261
+
262
+ out_json.parent.mkdir(parents=True, exist_ok=True)
263
+ out_md.parent.mkdir(parents=True, exist_ok=True)
264
+
265
+ out_json.write_text(json.dumps(report, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
266
+ out_md.write_text(to_markdown(report), encoding="utf-8")
267
+
268
+ print(f"Iteration value report generated.")
269
+ print(f"JSON: {out_json}")
270
+ print(f"MD: {out_md}")
271
+ return 0
272
+
273
+
274
+ if __name__ == "__main__":
275
+ raise SystemExit(main())