@blxzer/cursor-trellis 0.1.0 → 0.1.1

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 (279) hide show
  1. package/README.md +124 -5
  2. package/README.zh-CN.md +170 -0
  3. package/dist/cli/index.d.ts.map +1 -1
  4. package/dist/cli/index.js +1 -33
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/commands/init.d.ts +0 -13
  7. package/dist/commands/init.d.ts.map +1 -1
  8. package/dist/commands/init.js +7 -14
  9. package/dist/commands/init.js.map +1 -1
  10. package/dist/commands/uninstall.d.ts.map +1 -1
  11. package/dist/commands/uninstall.js +3 -32
  12. package/dist/commands/uninstall.js.map +1 -1
  13. package/dist/commands/update.d.ts.map +1 -1
  14. package/dist/commands/update.js +7 -84
  15. package/dist/commands/update.js.map +1 -1
  16. package/dist/configurators/index.d.ts +7 -8
  17. package/dist/configurators/index.d.ts.map +1 -1
  18. package/dist/configurators/index.js +11 -236
  19. package/dist/configurators/index.js.map +1 -1
  20. package/dist/configurators/workflow.d.ts.map +1 -1
  21. package/dist/configurators/workflow.js +5 -1
  22. package/dist/configurators/workflow.js.map +1 -1
  23. package/dist/templates/common/bundled-skills/smart-search-cli/SKILL.md +3 -3
  24. package/dist/templates/common/bundled-skills/trellis-meta/SKILL.md +4 -2
  25. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-agents.md +8 -15
  26. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-hooks.md +7 -7
  27. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-skills-or-commands.md +18 -21
  28. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/overview.md +2 -2
  29. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/generated-files.md +10 -7
  30. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/overview.md +4 -4
  31. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/agents.md +20 -31
  32. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/hooks-and-settings.md +20 -31
  33. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/overview.md +24 -40
  34. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/platform-map.md +28 -59
  35. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/skills-and-commands.md +12 -28
  36. package/dist/templates/common/bundled-skills/trellis-skill-creator/references/trellis-skill-locations.md +2 -2
  37. package/dist/templates/cursor/hooks.json +6 -0
  38. package/dist/templates/cursor/rules/retrieval-routing.mdc +57 -0
  39. package/dist/templates/extract.d.ts +0 -14
  40. package/dist/templates/extract.d.ts.map +1 -1
  41. package/dist/templates/extract.js +0 -34
  42. package/dist/templates/extract.js.map +1 -1
  43. package/dist/templates/markdown/agents.md +2 -6
  44. package/dist/templates/markdown/index.d.ts +1 -0
  45. package/dist/templates/markdown/index.d.ts.map +1 -1
  46. package/dist/templates/markdown/index.js +1 -0
  47. package/dist/templates/markdown/index.js.map +1 -1
  48. package/dist/templates/markdown/prompts/run-semantic-slice-12.md.txt +41 -0
  49. package/dist/templates/markdown/spec/guides/code-reuse-thinking-guide.md.txt +14 -14
  50. package/dist/templates/markdown/spec/guides/cross-layer-thinking-guide.md.txt +8 -20
  51. package/dist/templates/markdown/spec/guides/cross-platform-thinking-guide.md.txt +15 -14
  52. package/dist/templates/markdown/spec/guides/cursor-context-injection-guide.md.txt +2 -1
  53. package/dist/templates/markdown/spec/guides/cursor-semantic-compliance.md.txt +49 -0
  54. package/dist/templates/markdown/spec/guides/cursor-subagent-policy.md.txt +2 -2
  55. package/dist/templates/markdown/spec/guides/retrieval-daily-guide.md.txt +68 -20
  56. package/dist/templates/shared-hooks/index.d.ts +1 -1
  57. package/dist/templates/shared-hooks/index.d.ts.map +1 -1
  58. package/dist/templates/shared-hooks/index.js +1 -0
  59. package/dist/templates/shared-hooks/index.js.map +1 -1
  60. package/dist/templates/shared-hooks/inject-retrieval-plan.py +163 -0
  61. package/dist/templates/shared-hooks/research-end-retrieval-pack.py +2 -11
  62. package/dist/templates/trellis/index.d.ts +11 -0
  63. package/dist/templates/trellis/index.d.ts.map +1 -1
  64. package/dist/templates/trellis/index.js +22 -0
  65. package/dist/templates/trellis/index.js.map +1 -1
  66. package/dist/templates/trellis/scripts/aggregate_retrieval_telemetry.py +342 -0
  67. package/dist/templates/trellis/scripts/batch_plan_envelope.py +105 -0
  68. package/dist/templates/trellis/scripts/codegraph_session_smoke.py +76 -0
  69. package/dist/templates/trellis/scripts/common/active_task.py +116 -147
  70. package/dist/templates/trellis/scripts/common/cli_adapter.py +34 -710
  71. package/dist/templates/trellis/scripts/common/codebase_retrieval_router.py +49 -106
  72. package/dist/templates/trellis/scripts/common/git_context.py +17 -2
  73. package/dist/templates/trellis/scripts/common/project_file_stats.py +91 -0
  74. package/dist/templates/trellis/scripts/common/retrieval_adapter_metadata.py +9 -11
  75. package/dist/templates/trellis/scripts/common/retrieval_agent_instructions.py +313 -0
  76. package/dist/templates/trellis/scripts/common/retrieval_pack.py +0 -6
  77. package/dist/templates/trellis/scripts/common/retrieval_pack_context.py +0 -4
  78. package/dist/templates/trellis/scripts/common/retrieval_plan_gate.py +76 -0
  79. package/dist/templates/trellis/scripts/common/retrieval_result_ranking.py +253 -0
  80. package/dist/templates/trellis/scripts/common/retrieval_tool_classification.py +157 -0
  81. package/dist/templates/trellis/scripts/common/semantic_plan_gate.py +52 -0
  82. package/dist/templates/trellis/scripts/common/workflow_phase.py +3 -24
  83. package/dist/templates/trellis/scripts/rank_retrieval_candidates.py +80 -0
  84. package/dist/templates/trellis/scripts/route_codebase_retrieval.py +38 -11
  85. package/dist/templates/trellis/scripts/score_evidence.py +112 -0
  86. package/dist/templates/trellis/workflow.md +861 -960
  87. package/dist/types/ai-tools.d.ts +13 -16
  88. package/dist/types/ai-tools.d.ts.map +1 -1
  89. package/dist/types/ai-tools.js +5 -238
  90. package/dist/types/ai-tools.js.map +1 -1
  91. package/dist/utils/codebase-retrieval-router.d.ts +1 -8
  92. package/dist/utils/codebase-retrieval-router.d.ts.map +1 -1
  93. package/dist/utils/codebase-retrieval-router.js +39 -180
  94. package/dist/utils/codebase-retrieval-router.js.map +1 -1
  95. package/dist/utils/project-capabilities.d.ts.map +1 -1
  96. package/dist/utils/project-capabilities.js +10 -24
  97. package/dist/utils/project-capabilities.js.map +1 -1
  98. package/dist/utils/retrieval-agent-instructions.d.ts +14 -0
  99. package/dist/utils/retrieval-agent-instructions.d.ts.map +1 -0
  100. package/dist/utils/retrieval-agent-instructions.js +221 -0
  101. package/dist/utils/retrieval-agent-instructions.js.map +1 -0
  102. package/dist/utils/retrieval-execution-telemetry.d.ts +43 -85
  103. package/dist/utils/retrieval-execution-telemetry.d.ts.map +1 -1
  104. package/dist/utils/retrieval-execution-telemetry.js +289 -22
  105. package/dist/utils/retrieval-execution-telemetry.js.map +1 -1
  106. package/dist/utils/retrieval-result-ranking.js +1 -1
  107. package/dist/utils/retrieval-result-ranking.js.map +1 -1
  108. package/dist/utils/retrieval-tool-classification.d.ts +32 -0
  109. package/dist/utils/retrieval-tool-classification.d.ts.map +1 -0
  110. package/dist/utils/retrieval-tool-classification.js +113 -0
  111. package/dist/utils/retrieval-tool-classification.js.map +1 -0
  112. package/dist/utils/uninstall-scrubbers.d.ts +0 -36
  113. package/dist/utils/uninstall-scrubbers.d.ts.map +1 -1
  114. package/dist/utils/uninstall-scrubbers.js +0 -184
  115. package/dist/utils/uninstall-scrubbers.js.map +1 -1
  116. package/package.json +4 -2
  117. package/dist/commands/mem.d.ts +0 -30
  118. package/dist/commands/mem.d.ts.map +0 -1
  119. package/dist/commands/mem.js +0 -424
  120. package/dist/commands/mem.js.map +0 -1
  121. package/dist/configurators/antigravity.d.ts +0 -7
  122. package/dist/configurators/antigravity.d.ts.map +0 -1
  123. package/dist/configurators/antigravity.js +0 -19
  124. package/dist/configurators/antigravity.js.map +0 -1
  125. package/dist/configurators/claude.d.ts +0 -9
  126. package/dist/configurators/claude.d.ts.map +0 -1
  127. package/dist/configurators/claude.js +0 -72
  128. package/dist/configurators/claude.js.map +0 -1
  129. package/dist/configurators/codebuddy.d.ts +0 -10
  130. package/dist/configurators/codebuddy.d.ts.map +0 -1
  131. package/dist/configurators/codebuddy.js +0 -30
  132. package/dist/configurators/codebuddy.js.map +0 -1
  133. package/dist/configurators/codex.d.ts +0 -8
  134. package/dist/configurators/codex.d.ts.map +0 -1
  135. package/dist/configurators/codex.js +0 -87
  136. package/dist/configurators/codex.js.map +0 -1
  137. package/dist/configurators/copilot.d.ts +0 -10
  138. package/dist/configurators/copilot.d.ts.map +0 -1
  139. package/dist/configurators/copilot.js +0 -51
  140. package/dist/configurators/copilot.js.map +0 -1
  141. package/dist/configurators/droid.d.ts +0 -10
  142. package/dist/configurators/droid.d.ts.map +0 -1
  143. package/dist/configurators/droid.js +0 -30
  144. package/dist/configurators/droid.js.map +0 -1
  145. package/dist/configurators/gemini.d.ts +0 -16
  146. package/dist/configurators/gemini.d.ts.map +0 -1
  147. package/dist/configurators/gemini.js +0 -38
  148. package/dist/configurators/gemini.js.map +0 -1
  149. package/dist/configurators/kilo.d.ts +0 -7
  150. package/dist/configurators/kilo.d.ts.map +0 -1
  151. package/dist/configurators/kilo.js +0 -19
  152. package/dist/configurators/kilo.js.map +0 -1
  153. package/dist/configurators/kiro.d.ts +0 -8
  154. package/dist/configurators/kiro.d.ts.map +0 -1
  155. package/dist/configurators/kiro.js +0 -24
  156. package/dist/configurators/kiro.js.map +0 -1
  157. package/dist/configurators/opencode.d.ts +0 -14
  158. package/dist/configurators/opencode.d.ts.map +0 -1
  159. package/dist/configurators/opencode.js +0 -96
  160. package/dist/configurators/opencode.js.map +0 -1
  161. package/dist/configurators/pi.d.ts +0 -3
  162. package/dist/configurators/pi.d.ts.map +0 -1
  163. package/dist/configurators/pi.js +0 -45
  164. package/dist/configurators/pi.js.map +0 -1
  165. package/dist/configurators/qoder.d.ts +0 -11
  166. package/dist/configurators/qoder.d.ts.map +0 -1
  167. package/dist/configurators/qoder.js +0 -31
  168. package/dist/configurators/qoder.js.map +0 -1
  169. package/dist/configurators/windsurf.d.ts +0 -7
  170. package/dist/configurators/windsurf.d.ts.map +0 -1
  171. package/dist/configurators/windsurf.js +0 -19
  172. package/dist/configurators/windsurf.js.map +0 -1
  173. package/dist/templates/claude/agents/trellis-check.md +0 -124
  174. package/dist/templates/claude/agents/trellis-implement.md +0 -110
  175. package/dist/templates/claude/agents/trellis-research.md +0 -137
  176. package/dist/templates/claude/index.d.ts +0 -22
  177. package/dist/templates/claude/index.d.ts.map +0 -1
  178. package/dist/templates/claude/index.js +0 -46
  179. package/dist/templates/claude/index.js.map +0 -1
  180. package/dist/templates/claude/settings.json +0 -84
  181. package/dist/templates/codebuddy/agents/trellis-check.md +0 -115
  182. package/dist/templates/codebuddy/agents/trellis-implement.md +0 -110
  183. package/dist/templates/codebuddy/agents/trellis-research.md +0 -137
  184. package/dist/templates/codebuddy/index.d.ts +0 -15
  185. package/dist/templates/codebuddy/index.d.ts.map +0 -1
  186. package/dist/templates/codebuddy/index.js +0 -15
  187. package/dist/templates/codebuddy/index.js.map +0 -1
  188. package/dist/templates/codebuddy/settings.json +0 -70
  189. package/dist/templates/codex/agents/trellis-check.toml +0 -67
  190. package/dist/templates/codex/agents/trellis-implement.toml +0 -40
  191. package/dist/templates/codex/agents/trellis-research.toml +0 -73
  192. package/dist/templates/codex/config.toml +0 -28
  193. package/dist/templates/codex/hooks/session-start.py +0 -575
  194. package/dist/templates/codex/hooks.json +0 -15
  195. package/dist/templates/codex/index.d.ts +0 -39
  196. package/dist/templates/codex/index.d.ts.map +0 -1
  197. package/dist/templates/codex/index.js +0 -85
  198. package/dist/templates/codex/index.js.map +0 -1
  199. package/dist/templates/codex/skills/before-dev/SKILL.md +0 -40
  200. package/dist/templates/codex/skills/brainstorm/SKILL.md +0 -112
  201. package/dist/templates/codex/skills/break-loop/SKILL.md +0 -130
  202. package/dist/templates/codex/skills/check/SKILL.md +0 -98
  203. package/dist/templates/codex/skills/check-cross-layer/SKILL.md +0 -158
  204. package/dist/templates/codex/skills/create-command/SKILL.md +0 -101
  205. package/dist/templates/codex/skills/finish-work/SKILL.md +0 -90
  206. package/dist/templates/codex/skills/improve-ut/SKILL.md +0 -69
  207. package/dist/templates/codex/skills/integrate-skill/SKILL.md +0 -221
  208. package/dist/templates/codex/skills/onboard/SKILL.md +0 -363
  209. package/dist/templates/codex/skills/record-session/SKILL.md +0 -67
  210. package/dist/templates/codex/skills/start/SKILL.md +0 -66
  211. package/dist/templates/codex/skills/update-spec/SKILL.md +0 -335
  212. package/dist/templates/copilot/hooks/session-start.py +0 -557
  213. package/dist/templates/copilot/hooks.json +0 -19
  214. package/dist/templates/copilot/index.d.ts +0 -23
  215. package/dist/templates/copilot/index.d.ts.map +0 -1
  216. package/dist/templates/copilot/index.js +0 -54
  217. package/dist/templates/copilot/index.js.map +0 -1
  218. package/dist/templates/copilot/prompts/before-dev.prompt.md +0 -39
  219. package/dist/templates/copilot/prompts/brainstorm.prompt.md +0 -111
  220. package/dist/templates/copilot/prompts/break-loop.prompt.md +0 -129
  221. package/dist/templates/copilot/prompts/check-cross-layer.prompt.md +0 -157
  222. package/dist/templates/copilot/prompts/check.prompt.md +0 -97
  223. package/dist/templates/copilot/prompts/create-command.prompt.md +0 -116
  224. package/dist/templates/copilot/prompts/finish-work.prompt.md +0 -99
  225. package/dist/templates/copilot/prompts/integrate-skill.prompt.md +0 -223
  226. package/dist/templates/copilot/prompts/onboard.prompt.md +0 -362
  227. package/dist/templates/copilot/prompts/parallel.prompt.md +0 -204
  228. package/dist/templates/copilot/prompts/record-session.prompt.md +0 -66
  229. package/dist/templates/copilot/prompts/start.prompt.md +0 -63
  230. package/dist/templates/copilot/prompts/update-spec.prompt.md +0 -358
  231. package/dist/templates/droid/droids/trellis-check.md +0 -107
  232. package/dist/templates/droid/droids/trellis-implement.md +0 -102
  233. package/dist/templates/droid/droids/trellis-research.md +0 -137
  234. package/dist/templates/droid/index.d.ts +0 -15
  235. package/dist/templates/droid/index.d.ts.map +0 -1
  236. package/dist/templates/droid/index.js +0 -15
  237. package/dist/templates/droid/index.js.map +0 -1
  238. package/dist/templates/droid/settings.json +0 -70
  239. package/dist/templates/gemini/agents/trellis-check.md +0 -107
  240. package/dist/templates/gemini/agents/trellis-implement.md +0 -102
  241. package/dist/templates/gemini/agents/trellis-research.md +0 -136
  242. package/dist/templates/gemini/index.d.ts +0 -13
  243. package/dist/templates/gemini/index.d.ts.map +0 -1
  244. package/dist/templates/gemini/index.js +0 -13
  245. package/dist/templates/gemini/index.js.map +0 -1
  246. package/dist/templates/gemini/settings.json +0 -28
  247. package/dist/templates/kiro/agents/trellis-check.json +0 -26
  248. package/dist/templates/kiro/agents/trellis-implement.json +0 -26
  249. package/dist/templates/kiro/agents/trellis-research.json +0 -30
  250. package/dist/templates/kiro/index.d.ts +0 -18
  251. package/dist/templates/kiro/index.d.ts.map +0 -1
  252. package/dist/templates/kiro/index.js +0 -18
  253. package/dist/templates/kiro/index.js.map +0 -1
  254. package/dist/templates/opencode/agents/trellis-check.md +0 -122
  255. package/dist/templates/opencode/agents/trellis-implement.md +0 -118
  256. package/dist/templates/opencode/agents/trellis-research.md +0 -145
  257. package/dist/templates/opencode/lib/session-utils.js +0 -667
  258. package/dist/templates/opencode/lib/trellis-context.js +0 -336
  259. package/dist/templates/opencode/package.json +0 -5
  260. package/dist/templates/opencode/plugins/inject-subagent-context.js +0 -495
  261. package/dist/templates/opencode/plugins/inject-workflow-state.js +0 -159
  262. package/dist/templates/opencode/plugins/session-start.js +0 -101
  263. package/dist/templates/pi/agents/trellis-check.md +0 -37
  264. package/dist/templates/pi/agents/trellis-implement.md +0 -42
  265. package/dist/templates/pi/agents/trellis-research.md +0 -25
  266. package/dist/templates/pi/extensions/trellis/index.ts.txt +0 -1600
  267. package/dist/templates/pi/index.d.ts +0 -5
  268. package/dist/templates/pi/index.d.ts.map +0 -1
  269. package/dist/templates/pi/index.js +0 -12
  270. package/dist/templates/pi/index.js.map +0 -1
  271. package/dist/templates/pi/settings.json +0 -12
  272. package/dist/templates/qoder/agents/trellis-check.md +0 -108
  273. package/dist/templates/qoder/agents/trellis-implement.md +0 -103
  274. package/dist/templates/qoder/agents/trellis-research.md +0 -137
  275. package/dist/templates/qoder/index.d.ts +0 -15
  276. package/dist/templates/qoder/index.d.ts.map +0 -1
  277. package/dist/templates/qoder/index.js +0 -15
  278. package/dist/templates/qoder/index.js.map +0 -1
  279. package/dist/templates/qoder/settings.json +0 -47
@@ -0,0 +1,342 @@
1
+ #!/usr/bin/env python3
2
+ """Aggregate per-query retrieval telemetry JSONL into summary metrics (schema v2)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import json
8
+ import sys
9
+ from pathlib import Path
10
+ from typing import Any
11
+
12
+ _SCRIPT_DIR = Path(__file__).resolve().parent
13
+ if str(_SCRIPT_DIR) not in sys.path:
14
+ sys.path.insert(0, str(_SCRIPT_DIR))
15
+
16
+ from common.retrieval_tool_classification import ( # noqa: E402
17
+ classify_tool_calls,
18
+ semantic_routes_in_plan,
19
+ structural_routes_in_plan,
20
+ )
21
+
22
+ SCHEMA_VERSION = 2
23
+
24
+ SEMANTIC_OUTCOMES = (
25
+ "success",
26
+ "partial",
27
+ "resource_exhausted",
28
+ "timeout",
29
+ "not_configured",
30
+ "unavailable",
31
+ "not_run",
32
+ "unknown",
33
+ )
34
+
35
+ SEMANTIC_SKIP_REASONS = (
36
+ "rg_corrob_sufficient",
37
+ "rg_empty_semantic_required",
38
+ "trap_only_semantic_required",
39
+ "not_in_plan",
40
+ "not_applicable",
41
+ "adapter_unavailable",
42
+ "agent_stopped_early",
43
+ "unknown",
44
+ "manual_not_recorded",
45
+ )
46
+
47
+
48
+ def _rate(count: int, total: int) -> float:
49
+ return 0.0 if total == 0 else count / total
50
+
51
+
52
+ def _avg(values: list[float]) -> float:
53
+ return 0.0 if not values else sum(values) / len(values)
54
+
55
+
56
+ def compute_compliance_score(record: dict[str, Any]) -> float:
57
+ earned = 0.0
58
+ possible = 0.0
59
+
60
+ if record.get("structural_in_plan"):
61
+ possible += 1.0
62
+ if record.get("codegraph_executed"):
63
+ earned += 1.0
64
+
65
+ if record.get("semantic_in_plan"):
66
+ possible += 1.0
67
+ if record.get("semantic_executed") or record.get("semantic_skip_reason") == "rg_corrob_sufficient":
68
+ earned += 1.0
69
+
70
+ possible += 1.0
71
+ if record.get("read_verification_done"):
72
+ earned += 1.0
73
+
74
+ if record.get("plan_block_in_prompt"):
75
+ possible += 0.25
76
+ if record.get("router_cli_invoked"):
77
+ earned += 0.25
78
+
79
+ return 1.0 if possible == 0 else earned / possible
80
+
81
+
82
+ def migrate_record(raw: dict[str, Any]) -> dict[str, Any]:
83
+ routes = raw.get("routes") or raw.get("routes_in_plan") or []
84
+ if not isinstance(routes, list):
85
+ routes = []
86
+ tools = raw.get("tools_called") or []
87
+ if not isinstance(tools, list):
88
+ tools = []
89
+ platform = str(raw.get("platform", "cursor"))
90
+ classified = classify_tool_calls([str(t) for t in tools], platform=platform)
91
+
92
+ structural_in = raw.get("structural_in_plan")
93
+ if not isinstance(structural_in, bool):
94
+ structural_in = structural_routes_in_plan([str(r) for r in routes])
95
+
96
+ semantic_in = raw.get("semantic_in_plan")
97
+ if not isinstance(semantic_in, bool):
98
+ semantic_in = semantic_routes_in_plan([str(r) for r in routes])
99
+
100
+ record: dict[str, Any] = {
101
+ "schema_version": SCHEMA_VERSION,
102
+ "query_id": str(raw.get("query_id", "")),
103
+ "dataset": str(raw.get("dataset", "unknown")),
104
+ "query_text": str(raw.get("query_text", "")),
105
+ "run_id": str(raw.get("run_id", "")),
106
+ "platform": platform,
107
+ "semantic_in_plan": bool(semantic_in),
108
+ "semantic_order": raw.get("semantic_order")
109
+ if isinstance(raw.get("semantic_order"), int)
110
+ else None,
111
+ "structural_in_plan": bool(structural_in),
112
+ "codegraph_in_plan": bool(raw.get("codegraph_in_plan", structural_in)),
113
+ "fallback_hint_present": bool(raw.get("fallback_hint_present")),
114
+ "intents": list(raw.get("intents") or []),
115
+ "routes": [str(r) for r in routes],
116
+ "routes_in_plan": [str(r) for r in routes],
117
+ "project_file_count": raw.get("project_file_count")
118
+ if isinstance(raw.get("project_file_count"), int)
119
+ else None,
120
+ "tools_called": classified.tools_called,
121
+ "grep_count": raw.get("grep_count")
122
+ if isinstance(raw.get("grep_count"), int)
123
+ else classified.grep_count,
124
+ "read_count": raw.get("read_count")
125
+ if isinstance(raw.get("read_count"), int)
126
+ else classified.read_count,
127
+ "codegraph_attempted": bool(
128
+ raw.get("codegraph_attempted", classified.codegraph_attempted)
129
+ ),
130
+ "codegraph_executed": bool(
131
+ raw.get("codegraph_executed", classified.codegraph_executed)
132
+ ),
133
+ "router_cli_invoked": bool(
134
+ raw.get("router_cli_invoked", classified.router_cli_invoked)
135
+ ),
136
+ "plan_block_in_prompt": bool(raw.get("plan_block_in_prompt")),
137
+ "read_verification_done": bool(
138
+ raw.get("read_verification_done", classified.read_count > 0)
139
+ ),
140
+ "semantic_attempted": bool(
141
+ raw.get("semantic_attempted", classified.semantic_attempted)
142
+ ),
143
+ "semantic_executed": bool(
144
+ raw.get("semantic_executed", classified.semantic_executed)
145
+ ),
146
+ "semantic_outcome": str(raw.get("semantic_outcome", "unknown")),
147
+ "semantic_success": bool(raw.get("semantic_success")),
148
+ "semantic_skip_reason": raw.get("semantic_skip_reason"),
149
+ "rg_candidate_count": raw.get("rg_candidate_count")
150
+ if isinstance(raw.get("rg_candidate_count"), int)
151
+ else None,
152
+ "rg_corrob_status": str(raw.get("rg_corrob_status", "unknown")),
153
+ "trap_only": bool(raw.get("trap_only")),
154
+ "corroborated_files": list(raw.get("corroborated_files") or []),
155
+ "adapter_errors": list(raw.get("adapter_errors") or []),
156
+ "candidate_pool_recall": raw.get("candidate_pool_recall")
157
+ if isinstance(raw.get("candidate_pool_recall"), (int, float))
158
+ else None,
159
+ "final_top_k_recall": raw.get("final_top_k_recall")
160
+ if isinstance(raw.get("final_top_k_recall"), (int, float))
161
+ else None,
162
+ "answer_score": raw.get("answer_score")
163
+ if isinstance(raw.get("answer_score"), (int, float))
164
+ else None,
165
+ "compliance_score": raw.get("compliance_score")
166
+ if isinstance(raw.get("compliance_score"), (int, float))
167
+ else None,
168
+ "platform_semantic_executed": bool(
169
+ raw.get("platform_semantic_executed", classified.platform_semantic_executed)
170
+ ),
171
+ "fast_context_count": int(raw.get("fast_context_count", classified.fast_context_count)),
172
+ "cursor_fast_context_misuse": bool(
173
+ raw.get("cursor_fast_context_misuse", classified.cursor_fast_context_misuse)
174
+ ),
175
+ }
176
+ if record["compliance_score"] is None:
177
+ record["compliance_score"] = compute_compliance_score(record)
178
+ return record
179
+
180
+
181
+ def derive_metrics(records: list[dict[str, Any]]) -> dict[str, Any]:
182
+ total = len(records)
183
+ outcome_counts = {k: 0 for k in SEMANTIC_OUTCOMES}
184
+ skip_counts = {k: 0 for k in SEMANTIC_SKIP_REASONS}
185
+
186
+ semantic_plan = semantic_exec = semantic_attempt = semantic_success = 0
187
+ platform_sem_exec = fast_context_total = fast_context_misuse = 0
188
+ codegraph_plan = codegraph_exec = router_cli = plan_block = read_verify = 0
189
+ compliance_scores: list[float] = []
190
+ answer_scores: list[float] = []
191
+ pool_recalls: list[float] = []
192
+ topk_recalls: list[float] = []
193
+
194
+ for rec in records:
195
+ if rec.get("semantic_in_plan"):
196
+ semantic_plan += 1
197
+ if rec.get("semantic_executed"):
198
+ semantic_exec += 1
199
+ if rec.get("platform_semantic_executed"):
200
+ platform_sem_exec += 1
201
+ fc = rec.get("fast_context_count")
202
+ if isinstance(fc, int) and fc > 0:
203
+ fast_context_total += fc
204
+ if rec.get("cursor_fast_context_misuse"):
205
+ fast_context_misuse += 1
206
+ if rec.get("semantic_attempted"):
207
+ semantic_attempt += 1
208
+ if rec.get("semantic_success") and rec.get("semantic_outcome") == "success":
209
+ semantic_success += 1
210
+ if rec.get("codegraph_in_plan"):
211
+ codegraph_plan += 1
212
+ if rec.get("codegraph_executed"):
213
+ codegraph_exec += 1
214
+ if rec.get("router_cli_invoked"):
215
+ router_cli += 1
216
+ if rec.get("plan_block_in_prompt"):
217
+ plan_block += 1
218
+ if rec.get("read_verification_done"):
219
+ read_verify += 1
220
+
221
+ outcome = str(rec.get("semantic_outcome", "unknown"))
222
+ if outcome in outcome_counts:
223
+ outcome_counts[outcome] += 1
224
+ skip = rec.get("semantic_skip_reason")
225
+ if skip and skip in skip_counts:
226
+ skip_counts[skip] += 1
227
+
228
+ cs = rec.get("compliance_score")
229
+ if isinstance(cs, (int, float)):
230
+ compliance_scores.append(float(cs))
231
+ ans = rec.get("answer_score")
232
+ if isinstance(ans, (int, float)):
233
+ answer_scores.append(float(ans))
234
+ cpr = rec.get("candidate_pool_recall")
235
+ if isinstance(cpr, (int, float)):
236
+ pool_recalls.append(float(cpr))
237
+ ftr = rec.get("final_top_k_recall")
238
+ if isinstance(ftr, (int, float)):
239
+ topk_recalls.append(float(ftr))
240
+
241
+ avg_pool = _avg(pool_recalls)
242
+ avg_topk = _avg(topk_recalls)
243
+ recall_drop = 0.0 if avg_pool <= 0 else 1.0 - avg_topk / avg_pool
244
+
245
+ return {
246
+ "schema_version": SCHEMA_VERSION,
247
+ "total_queries": total,
248
+ "semantic_plan_count": semantic_plan,
249
+ "semantic_exec_count": semantic_exec,
250
+ "semantic_attempt_count": semantic_attempt,
251
+ "semantic_exec_success_count": semantic_success,
252
+ "semantic_plan_rate": _rate(semantic_plan, total),
253
+ "semantic_exec_rate": _rate(semantic_exec, total),
254
+ "platform_semantic_exec_count": platform_sem_exec,
255
+ "platform_semantic_exec_rate": _rate(platform_sem_exec, total),
256
+ "fast_context_invocation_total": fast_context_total,
257
+ "cursor_fast_context_misuse_count": fast_context_misuse,
258
+ "cursor_fast_context_misuse_rate": _rate(fast_context_misuse, total),
259
+ "semantic_attempt_rate": _rate(semantic_attempt, total),
260
+ "semantic_exec_success_rate": _rate(semantic_success, total),
261
+ "codegraph_plan_count": codegraph_plan,
262
+ "codegraph_exec_count": codegraph_exec,
263
+ "codegraph_plan_rate": _rate(codegraph_plan, total),
264
+ "codegraph_exec_rate": _rate(codegraph_exec, total),
265
+ "router_cli_count": router_cli,
266
+ "router_cli_rate": _rate(router_cli, total),
267
+ "plan_block_count": plan_block,
268
+ "plan_block_rate": _rate(plan_block, total),
269
+ "read_verification_count": read_verify,
270
+ "read_verification_rate": _rate(read_verify, total),
271
+ "avg_compliance_score": _avg(compliance_scores),
272
+ "avg_answer_score": _avg(answer_scores),
273
+ "semantic_outcome_counts": outcome_counts,
274
+ "semantic_skip_reason_counts": skip_counts,
275
+ "avg_candidate_pool_recall": avg_pool,
276
+ "avg_final_top_k_recall": avg_topk,
277
+ "recall_drop_rate": recall_drop,
278
+ }
279
+
280
+
281
+ def load_jsonl(path: Path) -> list[dict[str, Any]]:
282
+ records: list[dict[str, Any]] = []
283
+ for line_no, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
284
+ stripped = line.strip()
285
+ if not stripped or stripped.startswith("#"):
286
+ continue
287
+ try:
288
+ raw = json.loads(stripped)
289
+ except json.JSONDecodeError as exc:
290
+ raise ValueError(f"{path}:{line_no}: invalid JSON: {exc}") from exc
291
+ if not isinstance(raw, dict):
292
+ raise ValueError(f"{path}:{line_no}: expected JSON object per line")
293
+ records.append(migrate_record(raw))
294
+ return records
295
+
296
+
297
+ def main() -> int:
298
+ parser = argparse.ArgumentParser(description=__doc__)
299
+ parser.add_argument(
300
+ "jsonl",
301
+ type=Path,
302
+ help="Per-query telemetry JSONL (one object per line)",
303
+ )
304
+ parser.add_argument(
305
+ "--markdown",
306
+ action="store_true",
307
+ help="Print a short markdown summary for eval reports",
308
+ )
309
+ args = parser.parse_args()
310
+
311
+ if not args.jsonl.is_file():
312
+ print(f"error: file not found: {args.jsonl}", file=sys.stderr)
313
+ return 1
314
+
315
+ records = load_jsonl(args.jsonl)
316
+ metrics = derive_metrics(records)
317
+ payload = {"metrics": metrics, "record_count": len(records)}
318
+
319
+ if args.markdown:
320
+ m = metrics
321
+ print("## Retrieval telemetry (derived from JSONL)\n")
322
+ print("| Metric | Value |")
323
+ print("| --- | ---: |")
324
+ print(f"| total_queries | {m['total_queries']} |")
325
+ print(f"| semantic_plan_rate | {m['semantic_plan_rate']:.1%} |")
326
+ print(f"| semantic_exec_rate | {m['semantic_exec_rate']:.1%} |")
327
+ print(f"| platform_semantic_exec_rate | {m.get('platform_semantic_exec_rate', 0):.1%} |")
328
+ print(f"| cursor_fast_context_misuse_rate | {m.get('cursor_fast_context_misuse_rate', 0):.1%} |")
329
+ print(f"| codegraph_plan_rate | {m['codegraph_plan_rate']:.1%} |")
330
+ print(f"| codegraph_exec_rate | {m['codegraph_exec_rate']:.1%} |")
331
+ print(f"| router_cli_rate | {m['router_cli_rate']:.1%} |")
332
+ print(f"| avg_compliance_score | {m['avg_compliance_score']:.3f} |")
333
+ print(f"| avg_answer_score | {m['avg_answer_score']:.3f} |")
334
+ print("\nDo not hand-copy plan/exec rates; regenerate from JSONL with this script.")
335
+ else:
336
+ print(json.dumps(payload, indent=2, ensure_ascii=False))
337
+
338
+ return 0
339
+
340
+
341
+ if __name__ == "__main__":
342
+ raise SystemExit(main())
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env python3
2
+ """Batch route_codebase_retrieval for plan metrics (REC-06: platform-semantic on Cursor)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import json
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ _SCRIPT_DIR = Path(__file__).resolve().parent
12
+ if str(_SCRIPT_DIR) not in sys.path:
13
+ sys.path.insert(0, str(_SCRIPT_DIR))
14
+
15
+ from common.codebase_retrieval_router import route_codebase_retrieval # noqa: E402
16
+ from common.retrieval_tool_classification import ( # noqa: E402
17
+ platform_semantic_route_order,
18
+ semantic_routes_in_plan,
19
+ )
20
+
21
+
22
+ def load_queries(path: Path) -> list[dict]:
23
+ text = path.read_text(encoding="utf-8-sig")
24
+ rows: list[dict] = []
25
+ for line in text.splitlines():
26
+ stripped = line.strip()
27
+ if not stripped:
28
+ continue
29
+ rows.append(json.loads(stripped))
30
+ return rows
31
+
32
+
33
+ def main(argv: list[str] | None = None) -> int:
34
+ parser = argparse.ArgumentParser(description=__doc__)
35
+ parser.add_argument(
36
+ "--queries",
37
+ type=Path,
38
+ default=None,
39
+ help="JSONL query file (default: ./queries.jsonl under cwd)",
40
+ )
41
+ parser.add_argument("--pretty", action="store_true")
42
+ args = parser.parse_args(argv)
43
+
44
+ root = Path.cwd()
45
+ queries_path = args.queries or (root / "queries.jsonl")
46
+ if not queries_path.is_file():
47
+ print(f"error: queries file not found: {queries_path}", file=sys.stderr)
48
+ return 1
49
+
50
+ rows = load_queries(queries_path)
51
+ out: list[dict] = []
52
+ plan_sem = 0
53
+ platform_sem = 0
54
+ fast_context_sem = 0
55
+
56
+ for row in rows:
57
+ query = str(row.get("query", ""))
58
+ plan = route_codebase_retrieval(query)
59
+ routes = plan.get("routes") or []
60
+ route_ids = [str(r.get("id", "")) for r in routes if isinstance(r, dict)]
61
+ sem_in_plan = semantic_routes_in_plan(route_ids)
62
+ if sem_in_plan:
63
+ plan_sem += 1
64
+ if "platform-semantic" in route_ids:
65
+ platform_sem += 1
66
+ if "semantic-fast-context" in route_ids:
67
+ fast_context_sem += 1
68
+
69
+ out.append(
70
+ {
71
+ "id": row.get("id"),
72
+ "intents": [i["id"] for i in plan.get("intents", []) if isinstance(i, dict)],
73
+ "route_ids": route_ids,
74
+ "semantic_in_plan": sem_in_plan,
75
+ "platform_semantic_order": platform_semantic_route_order(
76
+ [r for r in routes if isinstance(r, dict)]
77
+ ),
78
+ "fallback_rg_empty": any(
79
+ "corroborated" in str(f.get("when", ""))
80
+ for f in (plan.get("fallback") or [])
81
+ if isinstance(f, dict)
82
+ ),
83
+ }
84
+ )
85
+
86
+ n = len(rows)
87
+ summary = {
88
+ "n": n,
89
+ "semantic_plan_rate": plan_sem / n if n else 0.0,
90
+ "platform_semantic_plan_rate": platform_sem / n if n else 0.0,
91
+ "semantic_fast_context_plan_rate": fast_context_sem / n if n else 0.0,
92
+ "fallback_hint_rate": sum(1 for x in out if x["fallback_rg_empty"]) / n if n else 0.0,
93
+ "note": (
94
+ "Plan rates only. semantic_exec_rate must come from session tool logs "
95
+ "and classify_tool_calls(platform=cursor)."
96
+ ),
97
+ }
98
+ payload = {"summary": summary, "queries": out}
99
+ indent = 2 if args.pretty else None
100
+ print(json.dumps(payload, ensure_ascii=False, indent=indent))
101
+ return 0
102
+
103
+
104
+ if __name__ == "__main__":
105
+ raise SystemExit(main())
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env python3
2
+ """Pre-run checks for codegraph index presence (does not start MCP)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import json
8
+ import sys
9
+ from datetime import datetime, timezone
10
+ from pathlib import Path
11
+
12
+ from common.paths import get_repo_root
13
+
14
+
15
+ def _find_codegraph_dirs(root: Path) -> list[Path]:
16
+ found: list[Path] = []
17
+ direct = root / ".codegraph"
18
+ if direct.is_dir():
19
+ found.append(direct.resolve())
20
+ for child in sorted(root.iterdir()):
21
+ if not child.is_dir():
22
+ continue
23
+ nested = child / ".codegraph"
24
+ if nested.is_dir() and nested.resolve() not in found:
25
+ found.append(nested.resolve())
26
+ return found
27
+
28
+
29
+ def main() -> int:
30
+ parser = argparse.ArgumentParser(description="Codegraph session smoke (index on disk)")
31
+ parser.add_argument(
32
+ "--root",
33
+ type=Path,
34
+ default=None,
35
+ help="Workspace root (default: Trellis repo root)",
36
+ )
37
+ parser.add_argument("--json", action="store_true", help="Machine-readable report")
38
+ args = parser.parse_args()
39
+
40
+ root = (args.root or get_repo_root()).resolve()
41
+ indexes = _find_codegraph_dirs(root)
42
+ ok = len(indexes) > 0
43
+ payload = {
44
+ "ok": ok,
45
+ "workspace_root": str(root),
46
+ "codegraph_index_paths": [str(p) for p in indexes],
47
+ "checked_at": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
48
+ "mcp_note": (
49
+ "Cursor: enable codegraph MCP in project settings; this script only checks "
50
+ "on-disk .codegraph/ directories."
51
+ ),
52
+ "run_header_fields": {
53
+ "codegraph_mcp": "configured|unknown|off",
54
+ "codegraph_index_path": str(indexes[0]) if indexes else "",
55
+ "codegraph_smoke_at": "<iso8601>",
56
+ "codegraph_smoke_ok": ok,
57
+ },
58
+ }
59
+
60
+ if args.json:
61
+ print(json.dumps(payload, indent=2))
62
+ else:
63
+ if ok:
64
+ print("Codegraph smoke: PASS")
65
+ for p in indexes:
66
+ print(f" index: {p}")
67
+ else:
68
+ print("Codegraph smoke: FAIL — no .codegraph/ under workspace root", file=sys.stderr)
69
+ print(f" root: {root}", file=sys.stderr)
70
+ print(payload["mcp_note"])
71
+
72
+ return 0 if ok else 1
73
+
74
+
75
+ if __name__ == "__main__":
76
+ raise SystemExit(main())