@cleocode/core 2026.3.76 → 2026.4.2

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 (473) hide show
  1. package/dist/agents/agent-schema.d.ts.map +1 -1
  2. package/dist/audit.d.ts +1 -1
  3. package/dist/audit.d.ts.map +1 -1
  4. package/dist/bootstrap.d.ts +2 -2
  5. package/dist/bootstrap.d.ts.map +1 -1
  6. package/dist/caamp/adapter.d.ts +6 -49
  7. package/dist/caamp/adapter.d.ts.map +1 -1
  8. package/dist/caamp/index.d.ts +2 -2
  9. package/dist/caamp/index.d.ts.map +1 -1
  10. package/dist/code/index.d.ts +10 -0
  11. package/dist/code/index.d.ts.map +1 -0
  12. package/dist/code/outline.d.ts +51 -0
  13. package/dist/code/outline.d.ts.map +1 -0
  14. package/dist/code/parser.d.ts +32 -0
  15. package/dist/code/parser.d.ts.map +1 -0
  16. package/dist/code/search.d.ts +42 -0
  17. package/dist/code/search.d.ts.map +1 -0
  18. package/dist/code/unfold.d.ts +44 -0
  19. package/dist/code/unfold.d.ts.map +1 -0
  20. package/dist/compliance/protocol-enforcement.d.ts +1 -1
  21. package/dist/compliance/protocol-rules.d.ts +1 -1
  22. package/dist/compliance/protocol-types.d.ts +2 -3
  23. package/dist/compliance/protocol-types.d.ts.map +1 -1
  24. package/dist/conduit/conduit-client.d.ts +14 -0
  25. package/dist/conduit/conduit-client.d.ts.map +1 -1
  26. package/dist/conduit/factory.d.ts +11 -1
  27. package/dist/conduit/factory.d.ts.map +1 -1
  28. package/dist/conduit/http-transport.d.ts +17 -5
  29. package/dist/conduit/http-transport.d.ts.map +1 -1
  30. package/dist/conduit/index.d.ts +5 -2
  31. package/dist/conduit/index.d.ts.map +1 -1
  32. package/dist/conduit/local-transport.d.ts +91 -0
  33. package/dist/conduit/local-transport.d.ts.map +1 -0
  34. package/dist/conduit/sse-transport.d.ts +68 -0
  35. package/dist/conduit/sse-transport.d.ts.map +1 -0
  36. package/dist/crypto/credentials.d.ts.map +1 -1
  37. package/dist/error-catalog.d.ts +3 -3
  38. package/dist/error-catalog.d.ts.map +1 -1
  39. package/dist/errors.d.ts +1 -1
  40. package/dist/hooks/handlers/index.d.ts +2 -2
  41. package/dist/hooks/handlers/index.d.ts.map +1 -1
  42. package/dist/hooks/handlers/notification-hooks.d.ts +31 -0
  43. package/dist/hooks/handlers/notification-hooks.d.ts.map +1 -0
  44. package/dist/index.d.ts +1 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +4646 -3476
  47. package/dist/index.js.map +4 -4
  48. package/dist/init.d.ts +6 -6
  49. package/dist/init.d.ts.map +1 -1
  50. package/dist/injection.d.ts.map +1 -1
  51. package/dist/internal.d.ts +7 -5
  52. package/dist/internal.d.ts.map +1 -1
  53. package/dist/lib/index.d.ts +1 -0
  54. package/dist/lib/index.d.ts.map +1 -1
  55. package/dist/lib/tree-sitter-languages.d.ts +29 -0
  56. package/dist/lib/tree-sitter-languages.d.ts.map +1 -0
  57. package/dist/logger.d.ts +3 -3
  58. package/dist/memory/brain-links.d.ts.map +1 -1
  59. package/dist/memory/brain-maintenance.d.ts +13 -0
  60. package/dist/memory/brain-maintenance.d.ts.map +1 -1
  61. package/dist/memory/brain-retrieval.d.ts +1 -1
  62. package/dist/memory/brain-retrieval.d.ts.map +1 -1
  63. package/dist/memory/decisions.d.ts.map +1 -1
  64. package/dist/memory/engine-compat.d.ts +392 -25
  65. package/dist/memory/engine-compat.d.ts.map +1 -1
  66. package/dist/memory/index.d.ts +416 -3
  67. package/dist/memory/index.d.ts.map +1 -1
  68. package/dist/metrics/token-service.d.ts +3 -3
  69. package/dist/metrics/token-service.d.ts.map +1 -1
  70. package/dist/orchestration/hierarchy.d.ts +32 -0
  71. package/dist/orchestration/hierarchy.d.ts.map +1 -0
  72. package/dist/orchestration/index.d.ts +1 -0
  73. package/dist/orchestration/index.d.ts.map +1 -1
  74. package/dist/paths.d.ts +335 -2
  75. package/dist/paths.d.ts.map +1 -1
  76. package/dist/routing/capability-matrix.d.ts +3 -3
  77. package/dist/routing/capability-matrix.d.ts.map +1 -1
  78. package/dist/scaffold.d.ts +422 -11
  79. package/dist/scaffold.d.ts.map +1 -1
  80. package/dist/security/input-sanitization.d.ts +2 -2
  81. package/dist/skills/dynamic-skill-generator.d.ts +3 -2
  82. package/dist/skills/dynamic-skill-generator.d.ts.map +1 -1
  83. package/dist/skills/routing-table.d.ts +4 -4
  84. package/dist/skills/routing-table.d.ts.map +1 -1
  85. package/dist/store/agent-registry-accessor.d.ts +10 -433
  86. package/dist/store/agent-registry-accessor.d.ts.map +1 -1
  87. package/dist/store/cross-db-cleanup.d.ts +34 -0
  88. package/dist/store/cross-db-cleanup.d.ts.map +1 -1
  89. package/dist/store/provider.d.ts +1 -1
  90. package/dist/store/signaldock-sqlite.d.ts.map +1 -1
  91. package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
  92. package/dist/store/sqlite.d.ts +1 -1
  93. package/dist/store/task-store.d.ts.map +1 -1
  94. package/dist/store/tasks-schema.d.ts +4 -228
  95. package/dist/store/tasks-schema.d.ts.map +1 -1
  96. package/dist/store/validation-schemas.d.ts +4 -5
  97. package/dist/store/validation-schemas.d.ts.map +1 -1
  98. package/dist/system/archive-analytics.d.ts +1 -1
  99. package/dist/system/health.d.ts +2 -2
  100. package/dist/system/health.d.ts.map +1 -1
  101. package/dist/system/runtime.d.ts +2 -1
  102. package/dist/system/runtime.d.ts.map +1 -1
  103. package/dist/tasks/list.d.ts +1 -1
  104. package/dist/tasks/list.d.ts.map +1 -1
  105. package/dist/tasks/task-ops.d.ts +415 -3
  106. package/dist/tasks/task-ops.d.ts.map +1 -1
  107. package/dist/templates/parser.d.ts +1 -1
  108. package/dist/ui/index.d.ts +1 -1
  109. package/dist/upgrade.d.ts +1 -1
  110. package/dist/upgrade.d.ts.map +1 -1
  111. package/dist/validation/operation-gate-validators.d.ts +1 -1
  112. package/dist/validation/operation-verification-gates.d.ts +3 -3
  113. package/dist/validation/param-utils.d.ts +6 -5
  114. package/dist/validation/param-utils.d.ts.map +1 -1
  115. package/dist/validation/validate-ops.d.ts +1 -1
  116. package/dist/validation/validate-ops.d.ts.map +1 -1
  117. package/package.json +19 -7
  118. package/src/__tests__/caamp-skill-install.test.js +0 -15
  119. package/src/__tests__/caamp-skill-install.test.js.map +1 -1
  120. package/src/__tests__/caamp-skill-install.test.ts +0 -16
  121. package/src/__tests__/injection-mvi-tiers.test.js +7 -7
  122. package/src/__tests__/injection-mvi-tiers.test.js.map +1 -1
  123. package/src/__tests__/injection-mvi-tiers.test.ts +55 -103
  124. package/src/agents/agent-schema.ts +2 -5
  125. package/src/audit.ts +2 -2
  126. package/src/bootstrap.ts +5 -39
  127. package/src/caamp/adapter.ts +3 -219
  128. package/src/caamp/index.ts +1 -13
  129. package/src/cant/__tests__/cant-agent-parse.test.d.ts.map +1 -0
  130. package/src/cant/__tests__/cant-agent-parse.test.js +77 -0
  131. package/src/cant/__tests__/cant-agent-parse.test.js.map +1 -0
  132. package/src/code/index.ts +10 -0
  133. package/src/code/outline.ts +214 -0
  134. package/src/code/parser.ts +331 -0
  135. package/src/code/search.ts +173 -0
  136. package/src/code/unfold.ts +204 -0
  137. package/src/codebase-map/analyzers/architecture.ts +2 -2
  138. package/src/compliance/protocol-enforcement.ts +1 -1
  139. package/src/compliance/protocol-rules.ts +1 -1
  140. package/src/compliance/protocol-types.ts +2 -3
  141. package/src/conduit/__tests__/dual-api-e2e.test.d.ts.map +1 -0
  142. package/src/conduit/__tests__/dual-api-e2e.test.js +178 -0
  143. package/src/conduit/__tests__/dual-api-e2e.test.js.map +1 -0
  144. package/src/conduit/__tests__/dual-api-e2e.test.ts +212 -0
  145. package/src/conduit/__tests__/local-credential-flow.test.d.ts.map +1 -0
  146. package/src/conduit/__tests__/local-credential-flow.test.js +185 -0
  147. package/src/conduit/__tests__/local-credential-flow.test.js.map +1 -0
  148. package/src/conduit/__tests__/local-credential-flow.test.ts +230 -0
  149. package/src/conduit/__tests__/local-transport.test.d.ts.map +1 -0
  150. package/src/conduit/__tests__/local-transport.test.js +404 -0
  151. package/src/conduit/__tests__/local-transport.test.js.map +1 -0
  152. package/src/conduit/__tests__/local-transport.test.ts +509 -0
  153. package/src/conduit/__tests__/sse-transport.test.d.ts.map +1 -0
  154. package/src/conduit/__tests__/sse-transport.test.js +291 -0
  155. package/src/conduit/__tests__/sse-transport.test.js.map +1 -0
  156. package/src/conduit/__tests__/sse-transport.test.ts +344 -0
  157. package/src/conduit/conduit-client.ts +14 -0
  158. package/src/conduit/factory.ts +29 -8
  159. package/src/conduit/http-transport.ts +78 -16
  160. package/src/conduit/index.ts +5 -2
  161. package/src/conduit/local-transport.ts +309 -0
  162. package/src/conduit/sse-transport.ts +382 -0
  163. package/src/crypto/credentials.ts +59 -13
  164. package/src/error-catalog.ts +3 -3
  165. package/src/errors.ts +1 -1
  166. package/src/hooks/__tests__/provider-hooks.test.js +4 -4
  167. package/src/hooks/__tests__/provider-hooks.test.js.map +1 -1
  168. package/src/hooks/__tests__/provider-hooks.test.ts +4 -4
  169. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.js +2 -2
  170. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.js.map +1 -1
  171. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.ts +6 -4
  172. package/src/hooks/handlers/index.ts +2 -6
  173. package/src/hooks/handlers/notification-hooks.ts +65 -0
  174. package/src/index.ts +2 -1
  175. package/src/init.ts +14 -54
  176. package/src/injection.ts +4 -3
  177. package/src/internal.ts +7 -5
  178. package/src/lib/index.ts +8 -0
  179. package/src/lib/tree-sitter-languages.ts +88 -0
  180. package/src/logger.ts +5 -5
  181. package/src/memory/__tests__/brain-links.test.js +13 -0
  182. package/src/memory/__tests__/brain-links.test.js.map +1 -1
  183. package/src/memory/__tests__/brain-links.test.ts +14 -0
  184. package/src/memory/__tests__/brain-retrieval.test.js +9 -0
  185. package/src/memory/__tests__/brain-retrieval.test.js.map +1 -1
  186. package/src/memory/__tests__/brain-retrieval.test.ts +10 -0
  187. package/src/memory/__tests__/session-memory.test.js +16 -0
  188. package/src/memory/__tests__/session-memory.test.js.map +1 -1
  189. package/src/memory/__tests__/session-memory.test.ts +17 -0
  190. package/src/memory/brain-links.ts +17 -0
  191. package/src/memory/brain-maintenance.ts +33 -1
  192. package/src/memory/brain-retrieval.ts +19 -3
  193. package/src/memory/decisions.ts +18 -2
  194. package/src/memory/engine-compat.ts +392 -25
  195. package/src/memory/index.ts +417 -4
  196. package/src/metrics/token-service.ts +4 -4
  197. package/src/migration/index.ts +1 -1
  198. package/src/orchestration/hierarchy.ts +202 -0
  199. package/src/orchestration/index.ts +1 -0
  200. package/src/paths.ts +340 -5
  201. package/src/routing/capability-matrix.ts +49 -49
  202. package/src/scaffold.ts +428 -70
  203. package/src/security/input-sanitization.ts +4 -4
  204. package/src/sessions/__tests__/session-grade.integration.test.js +9 -9
  205. package/src/sessions/__tests__/session-grade.integration.test.ts +9 -9
  206. package/src/sessions/__tests__/session-grade.test.js +10 -10
  207. package/src/sessions/__tests__/session-grade.test.js.map +1 -1
  208. package/src/sessions/__tests__/session-grade.test.ts +10 -10
  209. package/src/sessions/session-grade.ts +4 -4
  210. package/src/skills/__tests__/dynamic-skill-generator.test.js +24 -26
  211. package/src/skills/__tests__/dynamic-skill-generator.test.js.map +1 -1
  212. package/src/skills/__tests__/dynamic-skill-generator.test.ts +24 -26
  213. package/src/skills/__tests__/routing-table.test.js +22 -22
  214. package/src/skills/__tests__/routing-table.test.js.map +1 -1
  215. package/src/skills/__tests__/routing-table.test.ts +23 -23
  216. package/src/skills/dynamic-skill-generator.ts +13 -24
  217. package/src/skills/routing-table.ts +4 -4
  218. package/src/store/__tests__/data-safety-central.test.js +8 -0
  219. package/src/store/__tests__/data-safety-central.test.js.map +1 -1
  220. package/src/store/__tests__/data-safety-central.test.ts +8 -0
  221. package/src/store/__tests__/safety-accessor.test.js +8 -0
  222. package/src/store/__tests__/safety-accessor.test.js.map +1 -1
  223. package/src/store/__tests__/safety-accessor.test.ts +8 -0
  224. package/src/store/agent-registry-accessor.ts +284 -108
  225. package/src/store/cross-db-cleanup.ts +175 -1
  226. package/src/store/provider.ts +2 -2
  227. package/src/store/signaldock-sqlite.ts +262 -60
  228. package/src/store/sqlite-data-accessor.ts +3 -0
  229. package/src/store/sqlite.ts +2 -2
  230. package/src/store/task-store.ts +8 -1
  231. package/src/store/tasks-schema.ts +5 -40
  232. package/src/system/__tests__/health.test.js +2 -2
  233. package/src/system/__tests__/health.test.js.map +1 -1
  234. package/src/system/__tests__/health.test.ts +2 -2
  235. package/src/system/archive-analytics.ts +1 -1
  236. package/src/system/health.ts +43 -19
  237. package/src/system/inject-generate.ts +20 -20
  238. package/src/system/runtime.ts +5 -4
  239. package/src/tasks/atomicity.ts +1 -1
  240. package/src/tasks/list.ts +1 -1
  241. package/src/tasks/task-ops.ts +415 -3
  242. package/src/templates/parser.ts +1 -1
  243. package/src/ui/index.ts +4 -4
  244. package/src/upgrade.ts +3 -14
  245. package/src/validation/operation-gate-validators.ts +1 -1
  246. package/src/validation/operation-verification-gates.ts +3 -3
  247. package/src/validation/param-utils.ts +11 -10
  248. package/src/validation/validate-ops.ts +6 -6
  249. package/templates/CLEO-INJECTION.md +38 -110
  250. package/dist/hooks/handlers/mcp-hooks.d.ts +0 -48
  251. package/dist/hooks/handlers/mcp-hooks.d.ts.map +0 -1
  252. package/dist/mcp/index.d.ts +0 -42
  253. package/dist/mcp/index.d.ts.map +0 -1
  254. package/src/__tests__/audit-prune.test.d.ts +0 -2
  255. package/src/__tests__/caamp-skill-install.test.d.ts +0 -14
  256. package/src/__tests__/cli-mcp-parity.integration.test.d.ts +0 -34
  257. package/src/__tests__/cli-mcp-parity.integration.test.d.ts.map +0 -1
  258. package/src/__tests__/cli-mcp-parity.integration.test.js +0 -898
  259. package/src/__tests__/cli-mcp-parity.integration.test.js.map +0 -1
  260. package/src/__tests__/cli-parity.test.d.ts +0 -9
  261. package/src/__tests__/config.test.d.ts +0 -7
  262. package/src/__tests__/core-parity.test.d.ts +0 -17
  263. package/src/__tests__/error-catalog.test.d.ts +0 -2
  264. package/src/__tests__/golden-parity.test.d.ts +0 -12
  265. package/src/__tests__/hooks.test.d.ts +0 -5
  266. package/src/__tests__/human-output.test.d.ts +0 -12
  267. package/src/__tests__/index-api-compat.test.d.ts +0 -2
  268. package/src/__tests__/init-e2e.test.d.ts +0 -12
  269. package/src/__tests__/injection-chain.test.d.ts +0 -18
  270. package/src/__tests__/injection-mvi-tiers.test.d.ts +0 -14
  271. package/src/__tests__/injection-shared.test.d.ts +0 -10
  272. package/src/__tests__/lafs-conformance.test.d.ts +0 -18
  273. package/src/__tests__/logger.test.d.ts +0 -2
  274. package/src/__tests__/mcp-install-verify.test.d.ts +0 -13
  275. package/src/__tests__/mcp-install-verify.test.d.ts.map +0 -1
  276. package/src/__tests__/mcp-install-verify.test.js +0 -177
  277. package/src/__tests__/mcp-install-verify.test.js.map +0 -1
  278. package/src/__tests__/mcp-install-verify.test.ts +0 -217
  279. package/src/__tests__/paths.test.d.ts +0 -7
  280. package/src/__tests__/project-info.test.d.ts +0 -2
  281. package/src/__tests__/rcsd-pipeline-e2e.test.d.ts +0 -14
  282. package/src/__tests__/remote.test.d.ts +0 -6
  283. package/src/__tests__/scaffold.test.d.ts +0 -6
  284. package/src/__tests__/schema-management.test.d.ts +0 -5
  285. package/src/__tests__/schema.test.d.ts +0 -2
  286. package/src/__tests__/sharing.test.d.ts +0 -6
  287. package/src/__tests__/snapshot.test.d.ts +0 -6
  288. package/src/__tests__/upgrade.test.d.ts +0 -7
  289. package/src/adapters/__tests__/discovery.test.d.ts +0 -6
  290. package/src/adapters/__tests__/manager.test.d.ts +0 -6
  291. package/src/agents/__tests__/agent-registry.test.d.ts +0 -12
  292. package/src/agents/__tests__/capacity.test.d.ts +0 -7
  293. package/src/agents/__tests__/execution-learning.test.d.ts +0 -14
  294. package/src/agents/__tests__/health-monitor.test.d.ts +0 -10
  295. package/src/agents/__tests__/registry.test.d.ts +0 -8
  296. package/src/agents/__tests__/retry.test.d.ts +0 -7
  297. package/src/compliance/__tests__/sync.test.d.ts +0 -5
  298. package/src/hooks/__tests__/provider-hooks.test.d.ts +0 -2
  299. package/src/hooks/__tests__/registry.test.d.ts +0 -2
  300. package/src/hooks/handlers/__tests__/error-hooks.test.d.ts +0 -2
  301. package/src/hooks/handlers/__tests__/file-hooks.test.d.ts +0 -2
  302. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.d.ts +0 -13
  303. package/src/hooks/handlers/__tests__/mcp-hooks.test.d.ts +0 -2
  304. package/src/hooks/handlers/__tests__/mcp-hooks.test.d.ts.map +0 -1
  305. package/src/hooks/handlers/__tests__/mcp-hooks.test.js +0 -119
  306. package/src/hooks/handlers/__tests__/mcp-hooks.test.js.map +0 -1
  307. package/src/hooks/handlers/__tests__/mcp-hooks.test.ts +0 -150
  308. package/src/hooks/handlers/__tests__/session-hooks.test.d.ts +0 -2
  309. package/src/hooks/handlers/__tests__/task-hooks.test.d.ts +0 -2
  310. package/src/hooks/handlers/mcp-hooks.ts +0 -162
  311. package/src/intelligence/__tests__/adaptive-validation.test.d.ts +0 -11
  312. package/src/intelligence/__tests__/impact.test.d.ts +0 -16
  313. package/src/intelligence/__tests__/patterns.test.d.ts +0 -8
  314. package/src/intelligence/__tests__/prediction.test.d.ts +0 -8
  315. package/src/lib/__tests__/retry.test.d.ts +0 -7
  316. package/src/lifecycle/__tests__/chain-store.test.d.ts +0 -10
  317. package/src/lifecycle/__tests__/consolidate-rcasd.test.d.ts +0 -7
  318. package/src/lifecycle/__tests__/default-chain.test.d.ts +0 -7
  319. package/src/lifecycle/__tests__/frontmatter.test.d.ts +0 -7
  320. package/src/lifecycle/__tests__/lifecycle.test.d.ts +0 -7
  321. package/src/lifecycle/__tests__/pipeline.integration.test.d.ts +0 -19
  322. package/src/lifecycle/__tests__/rcasd-paths.test.d.ts +0 -7
  323. package/src/lifecycle/__tests__/resume-schema-contract.test.d.ts +0 -16
  324. package/src/lifecycle/__tests__/stage-record-provenance.integration.test.d.ts +0 -7
  325. package/src/lifecycle/__tests__/tessera-engine.test.d.ts +0 -10
  326. package/src/mcp/index.ts +0 -163
  327. package/src/memory/__tests__/auto-extract.test.d.ts +0 -7
  328. package/src/memory/__tests__/brain-automation.test.d.ts +0 -11
  329. package/src/memory/__tests__/brain-embedding.test.d.ts +0 -2
  330. package/src/memory/__tests__/brain-links.test.d.ts +0 -8
  331. package/src/memory/__tests__/brain-migration.test.d.ts +0 -8
  332. package/src/memory/__tests__/brain-retrieval.test.d.ts +0 -10
  333. package/src/memory/__tests__/brain-search.test.d.ts +0 -8
  334. package/src/memory/__tests__/claude-mem-migration.test.d.ts +0 -12
  335. package/src/memory/__tests__/decisions.test.d.ts +0 -8
  336. package/src/memory/__tests__/engine-compat.test.d.ts +0 -12
  337. package/src/memory/__tests__/memory-bridge.test.d.ts +0 -10
  338. package/src/memory/__tests__/pipeline-manifest-sqlite.test.d.ts +0 -13
  339. package/src/memory/__tests__/session-memory.test.d.ts +0 -9
  340. package/src/metrics/__tests__/model-provider-registry.test.d.ts +0 -2
  341. package/src/metrics/__tests__/provider-detection.test.d.ts +0 -2
  342. package/src/migration/__tests__/checksum.test.d.ts +0 -8
  343. package/src/migration/__tests__/logger.test.d.ts +0 -5
  344. package/src/migration/__tests__/migration-failure.integration.test.d.ts +0 -15
  345. package/src/migration/__tests__/migration.test.d.ts +0 -13
  346. package/src/migration/__tests__/state.test.d.ts +0 -8
  347. package/src/migration/__tests__/validate.test.d.ts +0 -8
  348. package/src/nexus/__tests__/deps.test.d.ts +0 -7
  349. package/src/nexus/__tests__/nexus-e2e.test.d.ts +0 -12
  350. package/src/nexus/__tests__/permissions.test.d.ts +0 -7
  351. package/src/nexus/__tests__/query.test.d.ts +0 -7
  352. package/src/nexus/__tests__/reconcile.test.d.ts +0 -7
  353. package/src/nexus/__tests__/registry.test.d.ts +0 -7
  354. package/src/nexus/__tests__/transfer.test.d.ts +0 -8
  355. package/src/observability/__tests__/index.test.d.ts +0 -7
  356. package/src/observability/__tests__/log-filter.test.d.ts +0 -7
  357. package/src/observability/__tests__/log-parser.test.d.ts +0 -7
  358. package/src/observability/__tests__/log-reader.test.d.ts +0 -7
  359. package/src/orchestration/__tests__/autonomous-spec.test.d.ts +0 -9
  360. package/src/orchestration/__tests__/orchestration.test.d.ts +0 -7
  361. package/src/orchestration/__tests__/protocol-validators.test.d.ts +0 -9
  362. package/src/phases/__tests__/deps.test.d.ts +0 -7
  363. package/src/phases/__tests__/phases.test.d.ts +0 -7
  364. package/src/release/__tests__/artifacts.test.d.ts +0 -7
  365. package/src/release/__tests__/cancel-release.test.d.ts +0 -10
  366. package/src/release/__tests__/changelog-writer.test.d.ts +0 -6
  367. package/src/release/__tests__/push-policy.test.d.ts +0 -14
  368. package/src/release/__tests__/release.test.d.ts +0 -11
  369. package/src/sequence/__tests__/allocate.test.d.ts +0 -6
  370. package/src/sessions/__tests__/briefing-blocked.test.d.ts +0 -6
  371. package/src/sessions/__tests__/briefing.test.d.ts +0 -11
  372. package/src/sessions/__tests__/handoff-integration.test.d.ts +0 -8
  373. package/src/sessions/__tests__/handoff.test.d.ts +0 -11
  374. package/src/sessions/__tests__/index.test.d.ts +0 -2
  375. package/src/sessions/__tests__/session-cleanup.test.d.ts +0 -7
  376. package/src/sessions/__tests__/session-edge-cases.test.d.ts +0 -9
  377. package/src/sessions/__tests__/session-find.test.d.ts +0 -9
  378. package/src/sessions/__tests__/session-grade.integration.test.d.ts +0 -11
  379. package/src/sessions/__tests__/session-grade.test.d.ts +0 -6
  380. package/src/sessions/__tests__/session-memory-bridge.test.d.ts +0 -2
  381. package/src/sessions/__tests__/sessions.test.d.ts +0 -7
  382. package/src/skills/__tests__/discovery.test.d.ts +0 -6
  383. package/src/skills/__tests__/dispatch.test.d.ts +0 -6
  384. package/src/skills/__tests__/dynamic-skill-generator.test.d.ts +0 -2
  385. package/src/skills/__tests__/manifests.test.d.ts +0 -6
  386. package/src/skills/__tests__/precedence.test.d.ts +0 -6
  387. package/src/skills/__tests__/routing-table.test.d.ts +0 -2
  388. package/src/skills/__tests__/skill-paths.test.d.ts +0 -7
  389. package/src/skills/__tests__/test-utility.test.d.ts +0 -7
  390. package/src/skills/__tests__/token.test.d.ts +0 -6
  391. package/src/skills/__tests__/validation.test.d.ts +0 -6
  392. package/src/skills/__tests__/version.test.d.ts +0 -5
  393. package/src/skills/injection/__tests__/subagent.test.d.ts +0 -2
  394. package/src/skills/orchestrator/__tests__/spawn-tier.test.d.ts +0 -2
  395. package/src/spawn/__tests__/adapter-registry.test.d.ts +0 -2
  396. package/src/stats/__tests__/stats.test.d.ts +0 -7
  397. package/src/sticky/__tests__/purge.test.d.ts +0 -9
  398. package/src/store/__tests__/atomic.test.d.ts +0 -7
  399. package/src/store/__tests__/backup.test.d.ts +0 -7
  400. package/src/store/__tests__/brain-accessor-pageindex.test.d.ts +0 -12
  401. package/src/store/__tests__/brain-accessor.test.d.ts +0 -10
  402. package/src/store/__tests__/brain-pageindex.test.d.ts +0 -11
  403. package/src/store/__tests__/brain-schema.test.d.ts +0 -11
  404. package/src/store/__tests__/brain-vec.test.d.ts +0 -11
  405. package/src/store/__tests__/collision-detection.test.d.ts +0 -11
  406. package/src/store/__tests__/data-safety-central.test.d.ts +0 -20
  407. package/src/store/__tests__/db-helpers.test.d.ts +0 -7
  408. package/src/store/__tests__/e2e-safety-integration.test.d.ts +0 -13
  409. package/src/store/__tests__/git-checkpoint.test.d.ts +0 -7
  410. package/src/store/__tests__/idempotent-migration.test.d.ts +0 -5
  411. package/src/store/__tests__/import-logging.test.d.ts +0 -7
  412. package/src/store/__tests__/import-sort.test.d.ts +0 -7
  413. package/src/store/__tests__/json.test.d.ts +0 -7
  414. package/src/store/__tests__/lifecycle-schema-parity.test.d.ts +0 -2
  415. package/src/store/__tests__/migration-integration.test.d.ts +0 -15
  416. package/src/store/__tests__/migration-retry.test.d.ts +0 -10
  417. package/src/store/__tests__/migration-safety.test.d.ts +0 -21
  418. package/src/store/__tests__/migration-sqlite.test.d.ts +0 -11
  419. package/src/store/__tests__/performance-safety.test.d.ts +0 -17
  420. package/src/store/__tests__/project-detect.test.d.ts +0 -6
  421. package/src/store/__tests__/project-registry.test.d.ts +0 -7
  422. package/src/store/__tests__/provider.test.d.ts +0 -9
  423. package/src/store/__tests__/relations.test.d.ts +0 -9
  424. package/src/store/__tests__/safety-accessor.test.d.ts +0 -18
  425. package/src/store/__tests__/sequence-validation.test.d.ts +0 -11
  426. package/src/store/__tests__/session-store.test.d.ts +0 -11
  427. package/src/store/__tests__/sqlite-backup.test.d.ts +0 -14
  428. package/src/store/__tests__/sqlite.test.d.ts +0 -11
  429. package/src/store/__tests__/task-store.test.d.ts +0 -11
  430. package/src/store/__tests__/test-db-helper.d.ts +0 -61
  431. package/src/store/__tests__/write-verification.test.d.ts +0 -11
  432. package/src/system/__tests__/cleanup.test.d.ts +0 -2
  433. package/src/system/__tests__/health.test.d.ts +0 -2
  434. package/src/task-work/__tests__/start-deps.test.d.ts +0 -6
  435. package/src/tasks/__tests__/add.test.d.ts +0 -7
  436. package/src/tasks/__tests__/archive.test.d.ts +0 -7
  437. package/src/tasks/__tests__/assignee.test.d.ts +0 -14
  438. package/src/tasks/__tests__/atomicity.test.d.ts +0 -6
  439. package/src/tasks/__tests__/cancel-ops.test.d.ts +0 -7
  440. package/src/tasks/__tests__/complete-unblocks.test.d.ts +0 -6
  441. package/src/tasks/__tests__/complete.test.d.ts +0 -7
  442. package/src/tasks/__tests__/delete.test.d.ts +0 -7
  443. package/src/tasks/__tests__/dependency-check.test.d.ts +0 -7
  444. package/src/tasks/__tests__/deps-ready.test.d.ts +0 -6
  445. package/src/tasks/__tests__/epic-enforcement.test.d.ts +0 -15
  446. package/src/tasks/__tests__/find.test.d.ts +0 -7
  447. package/src/tasks/__tests__/graph-ops.test.d.ts +0 -7
  448. package/src/tasks/__tests__/hierarchy-policy.test.d.ts +0 -6
  449. package/src/tasks/__tests__/hierarchy.test.d.ts +0 -7
  450. package/src/tasks/__tests__/id-generator.test.d.ts +0 -2
  451. package/src/tasks/__tests__/labels.test.d.ts +0 -7
  452. package/src/tasks/__tests__/list.test.d.ts +0 -7
  453. package/src/tasks/__tests__/minimal-test.test.d.ts +0 -2
  454. package/src/tasks/__tests__/phase-tracking.test.d.ts +0 -7
  455. package/src/tasks/__tests__/pipeline-stage.test.d.ts +0 -14
  456. package/src/tasks/__tests__/plan-priority.test.d.ts +0 -10
  457. package/src/tasks/__tests__/priority-normalization.test.d.ts +0 -7
  458. package/src/tasks/__tests__/relates.test.d.ts +0 -9
  459. package/src/tasks/__tests__/show-deps.test.d.ts +0 -6
  460. package/src/tasks/__tests__/show.test.d.ts +0 -7
  461. package/src/tasks/__tests__/staleness.test.d.ts +0 -7
  462. package/src/tasks/__tests__/task-ops-depends.test.d.ts +0 -6
  463. package/src/tasks/__tests__/update.test.d.ts +0 -7
  464. package/src/validation/__tests__/chain-validation.test.d.ts +0 -7
  465. package/src/validation/__tests__/compliance.test.d.ts +0 -7
  466. package/src/validation/__tests__/docs-sync.test.d.ts +0 -7
  467. package/src/validation/__tests__/doctor-gitignore.test.d.ts +0 -7
  468. package/src/validation/__tests__/doctor-injection.test.d.ts +0 -11
  469. package/src/validation/__tests__/doctor.test.d.ts +0 -7
  470. package/src/validation/__tests__/engine.test.d.ts +0 -7
  471. package/src/validation/__tests__/manifest.test.d.ts +0 -7
  472. package/src/validation/__tests__/protocol-common.test.d.ts +0 -7
  473. package/src/validation/__tests__/verification.test.d.ts +0 -7
@@ -0,0 +1,214 @@
1
+ /**
2
+ * smart_outline — file structural skeleton via tree-sitter.
3
+ *
4
+ * Parses a source file and returns all top-level and nested symbols
5
+ * with signatures only (bodies collapsed). This gives agents a ~1-2K
6
+ * token overview of a file vs ~12K for a full Read.
7
+ *
8
+ * @task T151
9
+ */
10
+
11
+ import { readFileSync } from 'node:fs';
12
+ import { relative } from 'node:path';
13
+ import type { CodeSymbol } from '@cleocode/contracts';
14
+ import { detectLanguage } from '../lib/tree-sitter-languages.js';
15
+ import { parseFile } from './parser.js';
16
+
17
+ /** A symbol node in the outline tree, with optional children. */
18
+ export interface OutlineNode {
19
+ /** Symbol name. */
20
+ name: string;
21
+ /** Symbol kind (function, class, method, etc.). */
22
+ kind: string;
23
+ /** Start line (1-based). */
24
+ startLine: number;
25
+ /** End line (1-based). */
26
+ endLine: number;
27
+ /** Signature line(s) — the declaration without the body. */
28
+ signature: string;
29
+ /** Whether this symbol is exported. */
30
+ exported: boolean;
31
+ /** Nested symbols (methods inside classes, etc.). */
32
+ children: OutlineNode[];
33
+ }
34
+
35
+ /** Result of generating a smart outline for a file. */
36
+ export interface SmartOutlineResult {
37
+ /** Source file path (relative). */
38
+ filePath: string;
39
+ /** Detected language. */
40
+ language: string;
41
+ /** Top-level symbol tree. */
42
+ symbols: OutlineNode[];
43
+ /** Estimated token count for this outline. */
44
+ estimatedTokens: number;
45
+ /** Parse errors (non-fatal). */
46
+ errors: string[];
47
+ }
48
+
49
+ /**
50
+ * Extract the signature line(s) from source for a symbol.
51
+ *
52
+ * Reads the opening lines of the symbol declaration up to the first
53
+ * opening brace or colon (for Python). This gives context without
54
+ * the full implementation body.
55
+ */
56
+ function extractSignature(
57
+ lines: string[],
58
+ startLine: number,
59
+ endLine: number,
60
+ language: string,
61
+ ): string {
62
+ const start = Math.max(0, startLine - 1); // 1-based to 0-based
63
+ const end = Math.min(lines.length, endLine);
64
+
65
+ // For short symbols (< 3 lines), return the whole thing
66
+ if (end - start <= 3) {
67
+ return lines.slice(start, end).join('\n');
68
+ }
69
+
70
+ // Find the signature boundary (opening brace, colon for Python)
71
+ const sigLines: string[] = [];
72
+ for (let i = start; i < end && sigLines.length < 5; i++) {
73
+ const line = lines[i]!;
74
+ sigLines.push(line);
75
+
76
+ if (language === 'python') {
77
+ if (line.trimEnd().endsWith(':')) break;
78
+ } else {
79
+ if (line.includes('{')) break;
80
+ }
81
+ }
82
+
83
+ const bodyLines = end - start - sigLines.length;
84
+ if (bodyLines > 0) {
85
+ sigLines.push(` // ... ${bodyLines} lines`);
86
+ }
87
+
88
+ return sigLines.join('\n');
89
+ }
90
+
91
+ /**
92
+ * Build a tree from flat symbols by nesting methods inside their parent classes.
93
+ */
94
+ function buildTree(symbols: CodeSymbol[], lines: string[], language: string): OutlineNode[] {
95
+ const nodes: OutlineNode[] = [];
96
+ const classNodes = new Map<string, OutlineNode>();
97
+
98
+ // First pass: create all nodes
99
+ for (const sym of symbols) {
100
+ const node: OutlineNode = {
101
+ name: sym.name,
102
+ kind: sym.kind,
103
+ startLine: sym.startLine,
104
+ endLine: sym.endLine,
105
+ signature: extractSignature(lines, sym.startLine, sym.endLine, language),
106
+ exported: sym.exported ?? false,
107
+ children: [],
108
+ };
109
+
110
+ if (
111
+ sym.kind === 'class' ||
112
+ sym.kind === 'struct' ||
113
+ sym.kind === 'impl' ||
114
+ sym.kind === 'trait'
115
+ ) {
116
+ classNodes.set(sym.name, node);
117
+ nodes.push(node);
118
+ } else if (sym.kind === 'method' && sym.parent) {
119
+ const parent = classNodes.get(sym.parent);
120
+ if (parent) {
121
+ parent.children.push(node);
122
+ } else {
123
+ nodes.push(node);
124
+ }
125
+ } else {
126
+ // Check if this symbol is nested inside a class by line range
127
+ let nested = false;
128
+ for (const [, classNode] of classNodes) {
129
+ if (sym.startLine >= classNode.startLine && sym.endLine <= classNode.endLine) {
130
+ classNode.children.push(node);
131
+ nested = true;
132
+ break;
133
+ }
134
+ }
135
+ if (!nested) nodes.push(node);
136
+ }
137
+ }
138
+
139
+ return nodes;
140
+ }
141
+
142
+ /** Estimate token count for an outline (rough: ~4 chars per token). */
143
+ function estimateTokens(nodes: OutlineNode[]): number {
144
+ let chars = 0;
145
+ for (const node of nodes) {
146
+ chars += node.signature.length + node.name.length + node.kind.length + 20; // overhead
147
+ chars += estimateTokens(node.children);
148
+ }
149
+ return Math.ceil(chars / 4);
150
+ }
151
+
152
+ /**
153
+ * Generate a smart outline for a source file.
154
+ *
155
+ * Returns a tree of symbols with signatures only (bodies collapsed),
156
+ * suitable for giving agents a quick structural overview.
157
+ *
158
+ * @param filePath - Absolute path to source file
159
+ * @param projectRoot - Project root for relative path computation
160
+ * @returns Smart outline result with symbol tree and token estimate
161
+ */
162
+ export function smartOutline(filePath: string, projectRoot?: string): SmartOutlineResult {
163
+ const root = projectRoot ?? process.cwd();
164
+ const relPath = relative(root, filePath);
165
+ const language = detectLanguage(filePath);
166
+
167
+ if (!language) {
168
+ return {
169
+ filePath: relPath,
170
+ language: 'unknown',
171
+ symbols: [],
172
+ estimatedTokens: 0,
173
+ errors: ['Unsupported language'],
174
+ };
175
+ }
176
+
177
+ // Parse the file for symbols
178
+ const parseResult = parseFile(filePath, root);
179
+ if (parseResult.errors.length > 0 && parseResult.symbols.length === 0) {
180
+ return {
181
+ filePath: relPath,
182
+ language,
183
+ symbols: [],
184
+ estimatedTokens: 0,
185
+ errors: parseResult.errors,
186
+ };
187
+ }
188
+
189
+ // Read source lines for signature extraction
190
+ let lines: string[];
191
+ try {
192
+ lines = readFileSync(filePath, 'utf-8').split('\n');
193
+ } catch (err) {
194
+ return {
195
+ filePath: relPath,
196
+ language,
197
+ symbols: [],
198
+ estimatedTokens: 0,
199
+ errors: [`Failed to read file: ${err instanceof Error ? err.message : String(err)}`],
200
+ };
201
+ }
202
+
203
+ // Build symbol tree with signatures
204
+ const tree = buildTree(parseResult.symbols, lines, language);
205
+ const estimatedTokens = estimateTokens(tree);
206
+
207
+ return {
208
+ filePath: relPath,
209
+ language,
210
+ symbols: tree,
211
+ estimatedTokens,
212
+ errors: parseResult.errors,
213
+ };
214
+ }
@@ -0,0 +1,331 @@
1
+ /**
2
+ * Tree-sitter AST parser — query execution engine for code analysis.
3
+ *
4
+ * Resolves grammar paths from node_modules, writes S-expression query
5
+ * patterns to temp files, executes tree-sitter CLI, and parses output
6
+ * into structured CodeSymbol objects.
7
+ *
8
+ * @task T149
9
+ */
10
+
11
+ import { execFileSync } from 'node:child_process';
12
+ import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
13
+ import { tmpdir } from 'node:os';
14
+ import { join, relative } from 'node:path';
15
+ import type {
16
+ BatchParseResult,
17
+ CodeSymbol,
18
+ CodeSymbolKind,
19
+ ParseResult,
20
+ } from '@cleocode/contracts';
21
+ import { detectLanguage, type TreeSitterLanguage } from '../lib/tree-sitter-languages.js';
22
+
23
+ // ---------------------------------------------------------------------------
24
+ // Tree-sitter CLI resolution
25
+ // ---------------------------------------------------------------------------
26
+
27
+ /** Whether tree-sitter is available on this system. */
28
+ let _treeSitterAvailable: boolean | null = null;
29
+
30
+ /** Check if tree-sitter CLI is available and executable. Cached after first call. */
31
+ export function isTreeSitterAvailable(): boolean {
32
+ if (_treeSitterAvailable !== null) return _treeSitterAvailable;
33
+ try {
34
+ const bin = resolveTreeSitterBin();
35
+ // Verify the binary actually runs (broken symlinks pass existsSync)
36
+ execFileSync(bin, ['--version'], { timeout: 5000, stdio: 'pipe' });
37
+ _treeSitterAvailable = true;
38
+ } catch {
39
+ _treeSitterAvailable = false;
40
+ }
41
+ return _treeSitterAvailable;
42
+ }
43
+
44
+ /** Resolve the tree-sitter CLI binary from node_modules. */
45
+ function resolveTreeSitterBin(): string {
46
+ // Also check platform-specific binary extension for Windows
47
+ const ext = process.platform === 'win32' ? '.exe' : '';
48
+ const binName = `tree-sitter${ext}`;
49
+ const candidates = [
50
+ join(process.cwd(), 'packages', 'core', 'node_modules', '.bin', binName),
51
+ join(process.cwd(), 'node_modules', '.bin', binName),
52
+ // npm global install paths
53
+ join(process.cwd(), 'node_modules', 'tree-sitter-cli', binName),
54
+ ];
55
+ // Also try without extension (npm .cmd shim on Windows)
56
+ if (ext) {
57
+ candidates.push(
58
+ join(process.cwd(), 'packages', 'core', 'node_modules', '.bin', 'tree-sitter'),
59
+ join(process.cwd(), 'node_modules', '.bin', 'tree-sitter'),
60
+ );
61
+ }
62
+ for (const p of candidates) {
63
+ if (existsSync(p)) return p;
64
+ }
65
+ throw new Error(
66
+ 'tree-sitter CLI not found. Code analysis features (cleo code outline/search/unfold) ' +
67
+ 'require tree-sitter. Install with: npm install tree-sitter-cli',
68
+ );
69
+ }
70
+
71
+ // ---------------------------------------------------------------------------
72
+ // S-expression query patterns per language family
73
+ // ---------------------------------------------------------------------------
74
+
75
+ /** Query patterns that match function/method/class/type declarations. */
76
+ const QUERY_PATTERNS: Record<string, string> = {
77
+ // TypeScript / JavaScript
78
+ typescript: `
79
+ (function_declaration name: (identifier) @name) @definition.function
80
+ (method_definition name: (property_identifier) @name) @definition.method
81
+ (class_declaration name: (type_identifier) @name) @definition.class
82
+ (interface_declaration name: (type_identifier) @name) @definition.interface
83
+ (type_alias_declaration name: (type_identifier) @name) @definition.type
84
+ (enum_declaration name: (identifier) @name) @definition.enum
85
+ (lexical_declaration (variable_declarator name: (identifier) @name)) @definition.variable
86
+ (export_statement (function_declaration name: (identifier) @name)) @definition.function
87
+ (export_statement (class_declaration name: (type_identifier) @name)) @definition.class
88
+ (arrow_function) @definition.function
89
+ `,
90
+ javascript: `
91
+ (function_declaration name: (identifier) @name) @definition.function
92
+ (method_definition name: (property_identifier) @name) @definition.method
93
+ (class_declaration name: (identifier) @name) @definition.class
94
+ (lexical_declaration (variable_declarator name: (identifier) @name)) @definition.variable
95
+ (export_statement (function_declaration name: (identifier) @name)) @definition.function
96
+ (export_statement (class_declaration name: (identifier) @name)) @definition.class
97
+ (arrow_function) @definition.function
98
+ `,
99
+ // Python
100
+ python: `
101
+ (function_definition name: (identifier) @name) @definition.function
102
+ (class_definition name: (identifier) @name) @definition.class
103
+ (decorated_definition (function_definition name: (identifier) @name)) @definition.function
104
+ (decorated_definition (class_definition name: (identifier) @name)) @definition.class
105
+ `,
106
+ // Go
107
+ go: `
108
+ (function_declaration name: (identifier) @name) @definition.function
109
+ (method_declaration name: (field_identifier) @name) @definition.method
110
+ (type_declaration (type_spec name: (type_identifier) @name)) @definition.type
111
+ `,
112
+ // Rust
113
+ rust: `
114
+ (function_item name: (identifier) @name) @definition.function
115
+ (impl_item type: (type_identifier) @name) @definition.impl
116
+ (struct_item name: (type_identifier) @name) @definition.struct
117
+ (enum_item name: (type_identifier) @name) @definition.enum
118
+ (trait_item name: (type_identifier) @name) @definition.trait
119
+ (type_item name: (type_identifier) @name) @definition.type
120
+ (mod_item name: (identifier) @name) @definition.module
121
+ `,
122
+ // Ruby
123
+ ruby: `
124
+ (method name: (identifier) @name) @definition.method
125
+ (class name: (constant) @name) @definition.class
126
+ (module name: (constant) @name) @definition.module
127
+ (singleton_method name: (identifier) @name) @definition.method
128
+ `,
129
+ // Java / C / C++
130
+ java: `
131
+ (method_declaration name: (identifier) @name) @definition.method
132
+ (class_declaration name: (identifier) @name) @definition.class
133
+ (interface_declaration name: (identifier) @name) @definition.interface
134
+ (enum_declaration name: (identifier) @name) @definition.enum
135
+ `,
136
+ c: `
137
+ (function_definition declarator: (function_declarator declarator: (identifier) @name)) @definition.function
138
+ (struct_specifier name: (type_identifier) @name) @definition.struct
139
+ (enum_specifier name: (type_identifier) @name) @definition.enum
140
+ (type_definition declarator: (type_identifier) @name) @definition.type
141
+ `,
142
+ cpp: `
143
+ (function_definition declarator: (function_declarator declarator: (qualified_identifier) @name)) @definition.function
144
+ (function_definition declarator: (function_declarator declarator: (identifier) @name)) @definition.function
145
+ (class_specifier name: (type_identifier) @name) @definition.class
146
+ (struct_specifier name: (type_identifier) @name) @definition.struct
147
+ (enum_specifier name: (type_identifier) @name) @definition.enum
148
+ (namespace_definition name: (identifier) @name) @definition.module
149
+ `,
150
+ };
151
+
152
+ /** Map language to query pattern key. */
153
+ function queryKeyForLanguage(lang: TreeSitterLanguage): string {
154
+ if (lang === 'tsx') return 'typescript';
155
+ return lang;
156
+ }
157
+
158
+ /** Map capture name suffix to CodeSymbolKind. */
159
+ function captureToKind(capture: string): CodeSymbolKind {
160
+ const map: Record<string, CodeSymbolKind> = {
161
+ function: 'function',
162
+ method: 'method',
163
+ class: 'class',
164
+ interface: 'interface',
165
+ type: 'type',
166
+ enum: 'enum',
167
+ variable: 'variable',
168
+ constant: 'constant',
169
+ module: 'module',
170
+ import: 'import',
171
+ export: 'export',
172
+ struct: 'struct',
173
+ trait: 'trait',
174
+ impl: 'impl',
175
+ };
176
+ return map[capture] ?? 'function';
177
+ }
178
+
179
+ // ---------------------------------------------------------------------------
180
+ // Output parsing
181
+ // ---------------------------------------------------------------------------
182
+
183
+ /**
184
+ * Parse tree-sitter query output into CodeSymbol objects.
185
+ *
186
+ * tree-sitter query output format (one match per block):
187
+ * ```
188
+ * path/to/file.ts
189
+ * pattern: 0
190
+ * capture: 0 - name, start: (5, 9), end: (5, 20), text: `parseFile`
191
+ * capture: 1 - definition.function, start: (5, 0), end: (15, 1)
192
+ * ```
193
+ */
194
+ function parseQueryOutput(output: string, filePath: string, language: string): CodeSymbol[] {
195
+ const symbols: CodeSymbol[] = [];
196
+ const lines = output.split('\n');
197
+
198
+ let currentName = '';
199
+ let currentKind: CodeSymbolKind = 'function';
200
+ let endLine = 0;
201
+
202
+ for (const line of lines) {
203
+ const nameMatch = line.match(
204
+ /capture: \d+ - name, start: \(\d+, \d+\), end: \(\d+, \d+\)(?:, text: `([^`]+)`)?/,
205
+ );
206
+ if (nameMatch) {
207
+ currentName = nameMatch[1] ?? '';
208
+ continue;
209
+ }
210
+
211
+ const defMatch = line.match(
212
+ /capture: \d+ - definition\.(\w+), start: \((\d+), \d+\), end: \((\d+), \d+\)/,
213
+ );
214
+ if (defMatch && currentName) {
215
+ currentKind = captureToKind(defMatch[1]!);
216
+ const defStart = Number.parseInt(defMatch[2]!, 10) + 1;
217
+ endLine = Number.parseInt(defMatch[3]!, 10) + 1;
218
+
219
+ symbols.push({
220
+ name: currentName,
221
+ kind: currentKind,
222
+ startLine: defStart,
223
+ endLine,
224
+ filePath,
225
+ language,
226
+ });
227
+ currentName = '';
228
+ }
229
+ }
230
+
231
+ return symbols;
232
+ }
233
+
234
+ // ---------------------------------------------------------------------------
235
+ // Public API
236
+ // ---------------------------------------------------------------------------
237
+
238
+ /**
239
+ * Parse a single file and extract code symbols.
240
+ *
241
+ * @param filePath - Absolute or relative path to source file
242
+ * @param projectRoot - Project root for relative path computation
243
+ * @returns Parse result with symbols and any errors
244
+ */
245
+ export function parseFile(filePath: string, projectRoot?: string): ParseResult {
246
+ const root = projectRoot ?? process.cwd();
247
+ const relPath = relative(root, filePath);
248
+ const language = detectLanguage(filePath);
249
+
250
+ if (!language) {
251
+ return {
252
+ filePath: relPath,
253
+ language: 'unknown',
254
+ symbols: [],
255
+ errors: ['Unsupported language'],
256
+ };
257
+ }
258
+
259
+ const queryKey = queryKeyForLanguage(language);
260
+ const pattern = QUERY_PATTERNS[queryKey];
261
+ if (!pattern) {
262
+ return {
263
+ filePath: relPath,
264
+ language,
265
+ symbols: [],
266
+ errors: [`No query pattern for ${language}`],
267
+ };
268
+ }
269
+
270
+ const tmpDir = mkdtempSync(join(tmpdir(), 'cleo-ts-'));
271
+ const queryFile = join(tmpDir, 'query.scm');
272
+
273
+ try {
274
+ writeFileSync(queryFile, pattern);
275
+ const bin = resolveTreeSitterBin();
276
+
277
+ const output = execFileSync(bin, ['query', queryFile, filePath], {
278
+ encoding: 'utf-8',
279
+ timeout: 30000,
280
+ maxBuffer: 10 * 1024 * 1024, // 10MB
281
+ });
282
+
283
+ const symbols = parseQueryOutput(output, relPath, language);
284
+ return { filePath: relPath, language, symbols, errors: [] };
285
+ } catch (err) {
286
+ const msg = err instanceof Error ? err.message : String(err);
287
+ return { filePath: relPath, language, symbols: [], errors: [msg] };
288
+ } finally {
289
+ rmSync(tmpDir, { recursive: true, force: true });
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Batch-parse multiple files, grouping by language for efficiency.
295
+ *
296
+ * Files with the same language share a single query pattern file
297
+ * but each file is parsed individually (tree-sitter CLI limitation).
298
+ *
299
+ * @param filePaths - Array of file paths to parse
300
+ * @param projectRoot - Project root for relative path computation
301
+ * @returns Aggregated results with per-file breakdowns
302
+ */
303
+ export function batchParse(filePaths: string[], projectRoot?: string): BatchParseResult {
304
+ const root = projectRoot ?? process.cwd();
305
+ const results: ParseResult[] = [];
306
+ const skipped: string[] = [];
307
+
308
+ // Group files by language
309
+ const byLanguage = new Map<string, string[]>();
310
+ for (const fp of filePaths) {
311
+ const lang = detectLanguage(fp);
312
+ if (!lang) {
313
+ skipped.push(relative(root, fp));
314
+ continue;
315
+ }
316
+ const key = queryKeyForLanguage(lang);
317
+ const group = byLanguage.get(key) ?? [];
318
+ group.push(fp);
319
+ byLanguage.set(key, group);
320
+ }
321
+
322
+ // Parse each group
323
+ for (const [_queryKey, files] of byLanguage) {
324
+ for (const fp of files) {
325
+ results.push(parseFile(fp, root));
326
+ }
327
+ }
328
+
329
+ const totalSymbols = results.reduce((sum, r) => sum + r.symbols.length, 0);
330
+ return { results, skipped, totalSymbols };
331
+ }