orkeon-code 0.0.0-stage → 1.0.0-rc.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 (552) hide show
  1. package/.orkeon-runtime +10 -0
  2. package/.orkeon-version +1 -0
  3. package/LICENSE.md +21 -0
  4. package/NOTICE.md +17 -0
  5. package/README.fr.md +163 -0
  6. package/README.md +156 -2
  7. package/config/appsettings.anthropic.example.json +77 -0
  8. package/config/appsettings.example.json +71 -0
  9. package/config/appsettings.jev.example.json +131 -0
  10. package/config/appsettings.kev.example.json +133 -0
  11. package/config/appsettings.liquid.example.json +132 -0
  12. package/config/appsettings.ollama-whisper.example.json +93 -0
  13. package/config/appsettings.ollama.example.json +70 -0
  14. package/config/appsettings.whisper.example.json +32 -0
  15. package/mcp/whisper/README.md +294 -0
  16. package/mcp/whisper/pyproject.toml +32 -0
  17. package/mcp/whisper/uv.lock +1641 -0
  18. package/mcp/whisper/whisper_mcp.py +1053 -0
  19. package/orkeon-code +1092 -0
  20. package/orkeon-code.mjs +71 -0
  21. package/orkeon-code.ps1 +939 -0
  22. package/package.json +58 -4
  23. package/scripts/install.ps1 +156 -0
  24. package/scripts/install.sh +148 -0
  25. package/scripts/session-start.ork.ts +90 -0
  26. package/scripts/session-start.sh +74 -0
  27. package/scripts/setup-fixture.sh +88 -0
  28. package/src/commands/.orkeon/orkeon-cli.d.ts +559 -0
  29. package/src/commands/_lib/args.ts +194 -0
  30. package/src/commands/_lib/dev/dev-batches.ts +366 -0
  31. package/src/commands/_lib/dev/dev-implement.ts +185 -0
  32. package/src/commands/_lib/dev/dev-source.ts +61 -0
  33. package/src/commands/_lib/dev/dev.ts +341 -0
  34. package/src/commands/_lib/dev/markers.ts +7 -0
  35. package/src/commands/_lib/dev/messages.ts +112 -0
  36. package/src/commands/_lib/dev-step.ts +145 -0
  37. package/src/commands/_lib/dispatch.ts +254 -0
  38. package/src/commands/_lib/effort.ts +15 -0
  39. package/src/commands/_lib/git/branch.ts +94 -0
  40. package/src/commands/_lib/git/commit.ts +90 -0
  41. package/src/commands/_lib/git/diff.ts +107 -0
  42. package/src/commands/_lib/git/messages.ts +54 -0
  43. package/src/commands/_lib/git/review.ts +108 -0
  44. package/src/commands/_lib/memory/memory-admit.ts +148 -0
  45. package/src/commands/_lib/memory/memory.ts +52 -0
  46. package/src/commands/_lib/memory/messages.ts +32 -0
  47. package/src/commands/_lib/messages.ts +48 -0
  48. package/src/commands/_lib/pr-context.ts +32 -0
  49. package/src/commands/_lib/project/analyze.ts +24 -0
  50. package/src/commands/_lib/project/messages.ts +8 -0
  51. package/src/commands/_lib/session/export.ts +105 -0
  52. package/src/commands/_lib/session/messages.ts +87 -0
  53. package/src/commands/_lib/session/prompts.ts +4 -0
  54. package/src/commands/_lib/session/resume.ts +151 -0
  55. package/src/commands/_lib/session/tasks.ts +181 -0
  56. package/src/commands/_lib/settings/advisor.ts +75 -0
  57. package/src/commands/_lib/settings/agents.ts +137 -0
  58. package/src/commands/_lib/settings/choices.ts +8 -0
  59. package/src/commands/_lib/settings/config.ts +141 -0
  60. package/src/commands/_lib/settings/effort.ts +147 -0
  61. package/src/commands/_lib/settings/hooks.ts +50 -0
  62. package/src/commands/_lib/settings/messages.ts +408 -0
  63. package/src/commands/_lib/settings/mode.ts +100 -0
  64. package/src/commands/_lib/settings/model.ts +181 -0
  65. package/src/commands/_lib/settings/output-style.ts +39 -0
  66. package/src/commands/_lib/settings/permissions.ts +287 -0
  67. package/src/commands/_lib/settings/route.ts +63 -0
  68. package/src/commands/_lib/settings/session-config.ts +49 -0
  69. package/src/commands/_lib/settings/skills.ts +93 -0
  70. package/src/commands/_lib/settings/theme.ts +42 -0
  71. package/src/commands/_lib/speech/messages.ts +58 -0
  72. package/src/commands/_lib/speech/prompts.ts +4 -0
  73. package/src/commands/_lib/speech/say.ts +95 -0
  74. package/src/commands/_lib/speech/transcribe.ts +121 -0
  75. package/src/commands/_lib/speech/voice.ts +142 -0
  76. package/src/commands/_lib/status/cache.ts +31 -0
  77. package/src/commands/_lib/status/context.ts +57 -0
  78. package/src/commands/_lib/status/doctor.ts +205 -0
  79. package/src/commands/_lib/status/messages.ts +100 -0
  80. package/src/commands/_lib/status/meta.ts +24 -0
  81. package/src/commands/_lib/status/status.ts +128 -0
  82. package/src/commands/_lib/status/usage-tools.ts +48 -0
  83. package/src/commands/_lib/status/usage.ts +128 -0
  84. package/src/commands/_lib/view.ts +34 -0
  85. package/src/commands/dev/dev-batches.cmd.ts +109 -0
  86. package/src/commands/dev/dev-learn.cmd.ts +29 -0
  87. package/src/commands/dev/dev-plan.cmd.ts +51 -0
  88. package/src/commands/dev/dev-spec.cmd.ts +54 -0
  89. package/src/commands/dev/dev-status.cmd.ts +16 -0
  90. package/src/commands/git/branch.cmd.ts +27 -0
  91. package/src/commands/git/commit.cmd.ts +48 -0
  92. package/src/commands/git/diff.cmd.ts +26 -0
  93. package/src/commands/git/review.cmd.ts +36 -0
  94. package/src/commands/memory/memory.cmd.ts +48 -0
  95. package/src/commands/project/analyze.cmd.ts +32 -0
  96. package/src/commands/project/debug-tool-call.cmd.ts +62 -0
  97. package/src/commands/project/files.cmd.ts +22 -0
  98. package/src/commands/project/init-verifiers.cmd.ts +14 -0
  99. package/src/commands/project/init.cmd.ts +14 -0
  100. package/src/commands/project/verify.cmd.ts +27 -0
  101. package/src/commands/session/assistant.cmd.ts +40 -0
  102. package/src/commands/session/btw.cmd.ts +18 -0
  103. package/src/commands/session/clear.cmd.ts +19 -0
  104. package/src/commands/session/compact.cmd.ts +16 -0
  105. package/src/commands/session/copy.cmd.ts +45 -0
  106. package/src/commands/session/exit.cmd.ts +9 -0
  107. package/src/commands/session/export.cmd.ts +28 -0
  108. package/src/commands/session/rename.cmd.ts +18 -0
  109. package/src/commands/session/resume.cmd.ts +19 -0
  110. package/src/commands/session/rewind.cmd.ts +25 -0
  111. package/src/commands/session/summary.cmd.ts +27 -0
  112. package/src/commands/session/tasks.cmd.ts +46 -0
  113. package/src/commands/settings/advisor.cmd.ts +38 -0
  114. package/src/commands/settings/agents.cmd.ts +19 -0
  115. package/src/commands/settings/config.cmd.ts +19 -0
  116. package/src/commands/settings/effort.cmd.ts +19 -0
  117. package/src/commands/settings/fast.cmd.ts +18 -0
  118. package/src/commands/settings/hooks.cmd.ts +17 -0
  119. package/src/commands/settings/mode.cmd.ts +20 -0
  120. package/src/commands/settings/model.cmd.ts +21 -0
  121. package/src/commands/settings/output-style.cmd.ts +19 -0
  122. package/src/commands/settings/permissions.cmd.ts +25 -0
  123. package/src/commands/settings/proactive.cmd.ts +16 -0
  124. package/src/commands/settings/route.cmd.ts +16 -0
  125. package/src/commands/settings/skills.cmd.ts +17 -0
  126. package/src/commands/settings/theme.cmd.ts +14 -0
  127. package/src/commands/speech/say.cmd.ts +24 -0
  128. package/src/commands/speech/transcribe.cmd.ts +29 -0
  129. package/src/commands/speech/voice.cmd.ts +30 -0
  130. package/src/commands/status/context.cmd.ts +18 -0
  131. package/src/commands/status/doctor.cmd.ts +27 -0
  132. package/src/commands/status/release-notes.cmd.ts +9 -0
  133. package/src/commands/status/status.cmd.ts +25 -0
  134. package/src/commands/status/usage.cmd.ts +21 -0
  135. package/src/crews/.orkeon/orkeon.d.ts +4391 -0
  136. package/src/crews/_probe-shared-memory/domain/messages.ts +54 -0
  137. package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +188 -0
  138. package/src/crews/_probe-shared-memory/domain/prompts.ts +5 -0
  139. package/src/crews/_probe-shared-memory/probe.ork.ts +100 -0
  140. package/src/crews/advisor/application/messages.ts +4 -0
  141. package/src/crews/advisor/application/prompts.ts +4 -0
  142. package/src/crews/advisor/application/run-advisor.ts +41 -0
  143. package/src/crews/advisor/crew.ork.ts +44 -0
  144. package/src/crews/advisor/domain/advice.ts +119 -0
  145. package/src/crews/advisor/domain/messages.ts +8 -0
  146. package/src/crews/advisor/domain/prompts.ts +26 -0
  147. package/src/crews/agent-run/application/messages.ts +18 -0
  148. package/src/crews/agent-run/application/run-agent-run.ts +43 -0
  149. package/src/crews/agent-run/crew.ork.ts +67 -0
  150. package/src/crews/analyze/application/messages.ts +27 -0
  151. package/src/crews/analyze/application/prompts.ts +4 -0
  152. package/src/crews/analyze/application/run-analyze.ts +120 -0
  153. package/src/crews/analyze/crew.ork.ts +41 -0
  154. package/src/crews/analyze/domain/harvest.ts +269 -0
  155. package/src/crews/analyze/domain/prompts.ts +86 -0
  156. package/src/crews/code-review/application/lens-material.ts +24 -0
  157. package/src/crews/code-review/application/messages.ts +17 -0
  158. package/src/crews/code-review/application/prompts.ts +126 -0
  159. package/src/crews/code-review/application/review.ts +74 -0
  160. package/src/crews/code-review/application/run-code-review.ts +121 -0
  161. package/src/crews/code-review/crew.ork.ts +52 -0
  162. package/src/crews/code-review/domain/lenses.ts +154 -0
  163. package/src/crews/code-review/domain/messages.ts +25 -0
  164. package/src/crews/code-review/domain/prompts.ts +58 -0
  165. package/src/crews/code-review/domain/report.ts +58 -0
  166. package/src/crews/code-review/domain/scope.ts +106 -0
  167. package/src/crews/dev-batches/application/messages.ts +127 -0
  168. package/src/crews/dev-batches/application/plan-close.ts +181 -0
  169. package/src/crews/dev-batches/application/prompts.ts +10 -0
  170. package/src/crews/dev-batches/application/run-dev-batches.ts +676 -0
  171. package/src/crews/dev-batches/application/run-wave.ts +452 -0
  172. package/src/crews/dev-batches/application/seed-harvest.ts +163 -0
  173. package/src/crews/dev-batches/crew.ork.ts +146 -0
  174. package/src/crews/dev-batches/domain/batch-waves.ts +70 -0
  175. package/src/crews/dev-batches/domain/batches-budget.ts +52 -0
  176. package/src/crews/dev-batches/domain/batches-log.ts +52 -0
  177. package/src/crews/dev-batches/domain/markers.ts +5 -0
  178. package/src/crews/dev-batches/domain/messages.ts +6 -0
  179. package/src/crews/dev-batches/domain/wave-order.ts +44 -0
  180. package/src/crews/dev-change/application/change-material.ts +44 -0
  181. package/src/crews/dev-change/application/evidence.ts +172 -0
  182. package/src/crews/dev-change/application/messages.ts +81 -0
  183. package/src/crews/dev-change/application/prompts.ts +101 -0
  184. package/src/crews/dev-change/application/run-dev-change.ts +324 -0
  185. package/src/crews/dev-change/crew.ork.ts +114 -0
  186. package/src/crews/dev-change/domain/change-answer.ts +163 -0
  187. package/src/crews/dev-change/domain/change-render.ts +77 -0
  188. package/src/crews/dev-change/domain/markers.ts +28 -0
  189. package/src/crews/dev-change/domain/messages.ts +16 -0
  190. package/src/crews/dev-implement/application/close.ts +186 -0
  191. package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
  192. package/src/crews/dev-implement/application/locate-sheet.ts +82 -0
  193. package/src/crews/dev-implement/application/messages.ts +161 -0
  194. package/src/crews/dev-implement/application/observe.ts +52 -0
  195. package/src/crews/dev-implement/application/prompts.ts +9 -0
  196. package/src/crews/dev-implement/application/report-writes.ts +46 -0
  197. package/src/crews/dev-implement/application/run-dev-implement.ts +822 -0
  198. package/src/crews/dev-implement/application/run-role.ts +27 -0
  199. package/src/crews/dev-implement/application/suite-job.ts +122 -0
  200. package/src/crews/dev-implement/application/touched.ts +74 -0
  201. package/src/crews/dev-implement/crew.ork.ts +69 -0
  202. package/src/crews/dev-implement/domain/contracts.ts +255 -0
  203. package/src/crews/dev-implement/domain/correction.ts +103 -0
  204. package/src/crews/dev-implement/domain/cycles.ts +36 -0
  205. package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
  206. package/src/crews/dev-implement/domain/markers.ts +23 -0
  207. package/src/crews/dev-implement/domain/messages.ts +58 -0
  208. package/src/crews/dev-implement/domain/prompts.ts +93 -0
  209. package/src/crews/dev-implement/domain/roles.ts +49 -0
  210. package/src/crews/dev-implement/domain/sheet-edits.ts +76 -0
  211. package/src/crews/dev-implement/domain/sheet-ticks.ts +23 -0
  212. package/src/crews/dev-implement/domain/step-checks.ts +137 -0
  213. package/src/crews/dev-implement/domain/step-section.ts +129 -0
  214. package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
  215. package/src/crews/dev-learn/application/learn-prompt-fit.ts +63 -0
  216. package/src/crews/dev-learn/application/messages.ts +51 -0
  217. package/src/crews/dev-learn/application/prompts.ts +99 -0
  218. package/src/crews/dev-learn/application/run-dev-learn.ts +558 -0
  219. package/src/crews/dev-learn/crew.ork.ts +53 -0
  220. package/src/crews/dev-learn/domain/learn-answer.ts +233 -0
  221. package/src/crews/dev-learn/domain/messages.ts +65 -0
  222. package/src/crews/dev-learn/domain/owner-lines.ts +89 -0
  223. package/src/crews/dev-learn/domain/proposals-render.ts +95 -0
  224. package/src/crews/dev-plan/application/anchor-paths.ts +113 -0
  225. package/src/crews/dev-plan/application/inventory.ts +174 -0
  226. package/src/crews/dev-plan/application/messages.ts +88 -0
  227. package/src/crews/dev-plan/application/plan-prompt-fit.ts +44 -0
  228. package/src/crews/dev-plan/application/prompts.ts +141 -0
  229. package/src/crews/dev-plan/application/run-dev-plan.ts +483 -0
  230. package/src/crews/dev-plan/crew.ork.ts +112 -0
  231. package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
  232. package/src/crews/dev-plan/domain/markers.ts +18 -0
  233. package/src/crews/dev-plan/domain/messages.ts +118 -0
  234. package/src/crews/dev-plan/domain/plan-answer.ts +753 -0
  235. package/src/crews/dev-plan/domain/plan-render.ts +306 -0
  236. package/src/crews/dev-plan/domain/prompts.ts +44 -0
  237. package/src/crews/dev-spec/application/messages.ts +30 -0
  238. package/src/crews/dev-spec/application/prompts.ts +93 -0
  239. package/src/crews/dev-spec/application/run-dev-spec.ts +237 -0
  240. package/src/crews/dev-spec/application/spec-material.ts +42 -0
  241. package/src/crews/dev-spec/crew.ork.ts +110 -0
  242. package/src/crews/dev-spec/domain/markers.ts +30 -0
  243. package/src/crews/dev-spec/domain/messages.ts +39 -0
  244. package/src/crews/dev-spec/domain/spec-answer.ts +252 -0
  245. package/src/crews/dev-spec/domain/spec-render.ts +76 -0
  246. package/src/crews/dev-verify/application/audit-brief.ts +187 -0
  247. package/src/crews/dev-verify/application/audit.ts +267 -0
  248. package/src/crews/dev-verify/application/capture.ts +311 -0
  249. package/src/crews/dev-verify/application/messages.ts +119 -0
  250. package/src/crews/dev-verify/application/prompts.ts +209 -0
  251. package/src/crews/dev-verify/application/run-dev-verify.ts +423 -0
  252. package/src/crews/dev-verify/application/run-gate.ts +204 -0
  253. package/src/crews/dev-verify/crew.ork.ts +103 -0
  254. package/src/crews/dev-verify/domain/audit-answer.ts +154 -0
  255. package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
  256. package/src/crews/dev-verify/domain/capture-sections.ts +138 -0
  257. package/src/crews/dev-verify/domain/commands.ts +103 -0
  258. package/src/crews/dev-verify/domain/gate.ts +131 -0
  259. package/src/crews/dev-verify/domain/markers.ts +16 -0
  260. package/src/crews/dev-verify/domain/mechanical-table.ts +156 -0
  261. package/src/crews/dev-verify/domain/messages.ts +92 -0
  262. package/src/crews/dev-verify/domain/runtime-cut.ts +13 -0
  263. package/src/crews/dev-verify/domain/sheet-facts.ts +4 -0
  264. package/src/crews/dev-verify/domain/text.ts +20 -0
  265. package/src/crews/dev-verify/domain/verdict.ts +127 -0
  266. package/src/crews/git-commit/application/draft.ts +133 -0
  267. package/src/crews/git-commit/application/messages.ts +15 -0
  268. package/src/crews/git-commit/application/prompts.ts +47 -0
  269. package/src/crews/git-commit/application/run-git-commit.ts +117 -0
  270. package/src/crews/git-commit/crew.ork.ts +53 -0
  271. package/src/crews/git-commit/domain/commit.ts +200 -0
  272. package/src/crews/git-commit/domain/markers.ts +4 -0
  273. package/src/crews/git-commit/domain/messages.ts +48 -0
  274. package/src/crews/init-verifiers/application/authoring.ts +90 -0
  275. package/src/crews/init-verifiers/application/messages.ts +13 -0
  276. package/src/crews/init-verifiers/application/prompts.ts +107 -0
  277. package/src/crews/init-verifiers/application/run-init-verifiers.ts +26 -0
  278. package/src/crews/init-verifiers/crew.ork.ts +35 -0
  279. package/src/crews/init-verifiers/domain/commands-section.ts +36 -0
  280. package/src/crews/init-verifiers/domain/readiness.ts +23 -0
  281. package/src/crews/main-loop/application/auto-compact.ts +78 -0
  282. package/src/crews/main-loop/application/context-gather.ts +133 -0
  283. package/src/crews/main-loop/application/messages.ts +81 -0
  284. package/src/crews/main-loop/application/prompts.ts +12 -0
  285. package/src/crews/main-loop/application/run-main-loop.ts +383 -0
  286. package/src/crews/main-loop/application/turn-context.ts +111 -0
  287. package/src/crews/main-loop/crew.ork.ts +124 -0
  288. package/src/crews/main-loop/domain/autocompact.ts +27 -0
  289. package/src/crews/main-loop/domain/prompt-assembly.ts +338 -0
  290. package/src/crews/main-loop/domain/prompts.ts +336 -0
  291. package/src/crews/main-loop/domain/turn-chains.ts +130 -0
  292. package/src/crews/project-init/application/detect.ts +123 -0
  293. package/src/crews/project-init/application/messages.ts +15 -0
  294. package/src/crews/project-init/application/prompts.ts +105 -0
  295. package/src/crews/project-init/application/run-project-init.ts +31 -0
  296. package/src/crews/project-init/crew.ork.ts +36 -0
  297. package/src/crews/project-init/domain/conventions.ts +36 -0
  298. package/src/crews/project-init/domain/existing-files.ts +65 -0
  299. package/src/crews/project-init/domain/messages.ts +13 -0
  300. package/src/crews/project-init/domain/package-map.ts +73 -0
  301. package/src/crews/project-init/domain/prompts.ts +10 -0
  302. package/src/crews/session-compact/application/prompts.ts +5 -0
  303. package/src/crews/session-compact/crew.ork.ts +56 -0
  304. package/src/crews/shared-memory-admit/application/prompts.ts +5 -0
  305. package/src/crews/shared-memory-admit/crew.ork.ts +49 -0
  306. package/src/crews/speech/application/messages.ts +3 -0
  307. package/src/crews/speech/application/prompts.ts +3 -0
  308. package/src/crews/speech/application/run-speech.ts +26 -0
  309. package/src/crews/speech/crew.ork.ts +38 -0
  310. package/src/shared/application/agents/child-agent.ts +259 -0
  311. package/src/shared/application/agents/messages.ts +35 -0
  312. package/src/shared/application/agents/route-agent.ts +115 -0
  313. package/src/shared/application/agents/run-sub-agent.ts +119 -0
  314. package/src/shared/application/answer-language.ts +14 -0
  315. package/src/shared/application/attached-skills.ts +36 -0
  316. package/src/shared/application/compaction/compact-session.ts +242 -0
  317. package/src/shared/application/compaction/extract-memories.ts +38 -0
  318. package/src/shared/application/compaction/messages.ts +20 -0
  319. package/src/shared/application/compaction/prune-context.ts +94 -0
  320. package/src/shared/application/compaction/pruned-llm.ts +35 -0
  321. package/src/shared/application/compaction/restore-context.ts +78 -0
  322. package/src/shared/application/config-store.ts +123 -0
  323. package/src/shared/application/dev/brief-inventory.ts +115 -0
  324. package/src/shared/application/dev/close-batch.ts +85 -0
  325. package/src/shared/application/dev/find-repo-pack.ts +78 -0
  326. package/src/shared/application/dev/learn-decision.ts +254 -0
  327. package/src/shared/application/dev/load-dev-context.ts +265 -0
  328. package/src/shared/application/dev/measure-access-cost.ts +69 -0
  329. package/src/shared/application/dev/messages.ts +132 -0
  330. package/src/shared/application/dev/phase-timer.ts +54 -0
  331. package/src/shared/application/dev/plan-source.ts +116 -0
  332. package/src/shared/application/dev/preflight.ts +71 -0
  333. package/src/shared/application/dev/project-files.ts +17 -0
  334. package/src/shared/application/dev/prompts.ts +34 -0
  335. package/src/shared/application/dev/question-round.ts +60 -0
  336. package/src/shared/application/dev/resolve-work-folder.ts +134 -0
  337. package/src/shared/application/dev/script-tool-slot.ts +27 -0
  338. package/src/shared/application/dev/settle-questions.ts +57 -0
  339. package/src/shared/application/dev/source-review.ts +67 -0
  340. package/src/shared/application/dev/source-step.ts +152 -0
  341. package/src/shared/application/dev/spend.ts +55 -0
  342. package/src/shared/application/dev/step-precedents.ts +90 -0
  343. package/src/shared/application/dev/tool-call-policy.ts +87 -0
  344. package/src/shared/application/dev/tool-callbacks.ts +262 -0
  345. package/src/shared/application/dev/tool-trace-recorder.ts +46 -0
  346. package/src/shared/application/dev/verdict-sources.ts +50 -0
  347. package/src/shared/application/dev/wrapped-tools.ts +147 -0
  348. package/src/shared/application/extra-tools.ts +71 -0
  349. package/src/shared/application/git/batch-worktree.ts +102 -0
  350. package/src/shared/application/git/commit-files.ts +191 -0
  351. package/src/shared/application/git/merge-batch.ts +67 -0
  352. package/src/shared/application/git/messages.ts +75 -0
  353. package/src/shared/application/git/open-pull-request.ts +52 -0
  354. package/src/shared/application/host-context.ts +59 -0
  355. package/src/shared/application/host-layout-store.ts +45 -0
  356. package/src/shared/application/instructions-file.ts +19 -0
  357. package/src/shared/application/json-file.ts +34 -0
  358. package/src/shared/application/llm-profile.ts +36 -0
  359. package/src/shared/application/messages.ts +14 -0
  360. package/src/shared/application/permission-rules.ts +169 -0
  361. package/src/shared/application/ports/approvals.ts +20 -0
  362. package/src/shared/application/ports/clock.ts +5 -0
  363. package/src/shared/application/ports/code-index.ts +93 -0
  364. package/src/shared/application/ports/crew.ts +60 -0
  365. package/src/shared/application/ports/decision.ts +14 -0
  366. package/src/shared/application/ports/files.ts +21 -0
  367. package/src/shared/application/ports/human.ts +38 -0
  368. package/src/shared/application/ports/llm.ts +83 -0
  369. package/src/shared/application/ports/memory.ts +30 -0
  370. package/src/shared/application/ports/progress.ts +23 -0
  371. package/src/shared/application/ports/runtime.ts +15 -0
  372. package/src/shared/application/ports/session.ts +74 -0
  373. package/src/shared/application/ports/shared-memory.ts +26 -0
  374. package/src/shared/application/ports/shell.ts +40 -0
  375. package/src/shared/application/ports/telemetry.ts +45 -0
  376. package/src/shared/application/ports/theme.ts +11 -0
  377. package/src/shared/application/ports/tools.ts +46 -0
  378. package/src/shared/application/ports/usage.ts +45 -0
  379. package/src/shared/application/ports.ts +29 -0
  380. package/src/shared/application/project-manifests.ts +106 -0
  381. package/src/shared/application/session-io.ts +85 -0
  382. package/src/shared/application/session-state.ts +36 -0
  383. package/src/shared/application/shared-memory/admit-entries.ts +179 -0
  384. package/src/shared/application/shared-memory/harvest-after-gaps.ts +69 -0
  385. package/src/shared/application/shared-memory/harvest-mistakes.ts +45 -0
  386. package/src/shared/application/shared-memory/import-agent-memory.ts +119 -0
  387. package/src/shared/application/shared-memory/memory-files.ts +111 -0
  388. package/src/shared/application/shared-memory/memory-settings.ts +94 -0
  389. package/src/shared/application/shared-memory/messages.ts +63 -0
  390. package/src/shared/application/shared-memory/push-candidate.ts +149 -0
  391. package/src/shared/application/shared-memory/recall-precedents.ts +70 -0
  392. package/src/shared/application/skills/messages.ts +4 -0
  393. package/src/shared/application/skills/suggest-skills.ts +102 -0
  394. package/src/shared/application/state-snapshot.ts +38 -0
  395. package/src/shared/application/workflow/messages.ts +8 -0
  396. package/src/shared/application/workflow/workflow-state.ts +136 -0
  397. package/src/shared/domain/agent-policy/behavior-flags.ts +162 -0
  398. package/src/shared/domain/agent-policy/extra-tools.ts +67 -0
  399. package/src/shared/domain/agent-policy/memory-categories.ts +6 -0
  400. package/src/shared/domain/agent-policy/messages.ts +66 -0
  401. package/src/shared/domain/agent-policy/mode-policy.ts +51 -0
  402. package/src/shared/domain/agent-policy/output-styles.ts +11 -0
  403. package/src/shared/domain/agent-policy/path-rules.ts +299 -0
  404. package/src/shared/domain/agent-policy/permission.ts +625 -0
  405. package/src/shared/domain/agent-policy/prompts.ts +17 -0
  406. package/src/shared/domain/agent-policy/reasoning.ts +59 -0
  407. package/src/shared/domain/agent-policy/rule-sets.ts +416 -0
  408. package/src/shared/domain/agent-policy/tool-access.ts +91 -0
  409. package/src/shared/domain/agent-registry.ts +143 -0
  410. package/src/shared/domain/agents/built-in-charters.ts +43 -0
  411. package/src/shared/domain/agents/chain.ts +30 -0
  412. package/src/shared/domain/agents/charter.ts +64 -0
  413. package/src/shared/domain/agents/exclusive.ts +25 -0
  414. package/src/shared/domain/agents/instances.ts +252 -0
  415. package/src/shared/domain/agents/messages.ts +39 -0
  416. package/src/shared/domain/agents/model-route.ts +199 -0
  417. package/src/shared/domain/agents/prompts.ts +20 -0
  418. package/src/shared/domain/code-intel-contract.ts +357 -0
  419. package/src/shared/domain/code-intel-routing.ts +60 -0
  420. package/src/shared/domain/compact-outcome.ts +46 -0
  421. package/src/shared/domain/compaction-thresholds.ts +162 -0
  422. package/src/shared/domain/compaction.ts +288 -0
  423. package/src/shared/domain/config-schema.ts +434 -0
  424. package/src/shared/domain/context-prune.ts +176 -0
  425. package/src/shared/domain/decision/questions.ts +102 -0
  426. package/src/shared/domain/dev/access-cost.ts +230 -0
  427. package/src/shared/domain/dev/artefacts.ts +50 -0
  428. package/src/shared/domain/dev/batches-concurrency.ts +35 -0
  429. package/src/shared/domain/dev/batches-state.ts +49 -0
  430. package/src/shared/domain/dev/build-commands.ts +45 -0
  431. package/src/shared/domain/dev/call-guard.ts +342 -0
  432. package/src/shared/domain/dev/carried-text.ts +47 -0
  433. package/src/shared/domain/dev/design-rules.ts +100 -0
  434. package/src/shared/domain/dev/learn-proposals.ts +176 -0
  435. package/src/shared/domain/dev/learn-state.ts +94 -0
  436. package/src/shared/domain/dev/markers.ts +107 -0
  437. package/src/shared/domain/dev/messages.ts +259 -0
  438. package/src/shared/domain/dev/path-args.ts +42 -0
  439. package/src/shared/domain/dev/path-rebase.ts +93 -0
  440. package/src/shared/domain/dev/phase-timing.ts +50 -0
  441. package/src/shared/domain/dev/plan-checks.ts +191 -0
  442. package/src/shared/domain/dev/plan-format.ts +170 -0
  443. package/src/shared/domain/dev/project-files.ts +29 -0
  444. package/src/shared/domain/dev/prompts/brief-blocks.ts +20 -0
  445. package/src/shared/domain/dev/prompts.ts +251 -0
  446. package/src/shared/domain/dev/questions.ts +267 -0
  447. package/src/shared/domain/dev/reading-rule.ts +41 -0
  448. package/src/shared/domain/dev/repo-pack.ts +240 -0
  449. package/src/shared/domain/dev/review-answer.ts +173 -0
  450. package/src/shared/domain/dev/review-brief.ts +54 -0
  451. package/src/shared/domain/dev/reviewer-charter.ts +35 -0
  452. package/src/shared/domain/dev/sheet-facts.ts +81 -0
  453. package/src/shared/domain/dev/spec-format.ts +182 -0
  454. package/src/shared/domain/dev/step-budget.ts +74 -0
  455. package/src/shared/domain/dev/step-rules.ts +109 -0
  456. package/src/shared/domain/dev/test-commands.ts +94 -0
  457. package/src/shared/domain/dev/test-output.ts +33 -0
  458. package/src/shared/domain/dev/test-paths.ts +40 -0
  459. package/src/shared/domain/dev/tool-guards.ts +65 -0
  460. package/src/shared/domain/dev/trait-pattern.ts +87 -0
  461. package/src/shared/domain/dev/verdict-format.ts +162 -0
  462. package/src/shared/domain/dev/whitespace.ts +35 -0
  463. package/src/shared/domain/dev/work-folder.ts +68 -0
  464. package/src/shared/domain/dev/yaml-subset.ts +385 -0
  465. package/src/shared/domain/error-text.ts +13 -0
  466. package/src/shared/domain/git/close.ts +274 -0
  467. package/src/shared/domain/git/messages.ts +20 -0
  468. package/src/shared/domain/git/pull-request.ts +96 -0
  469. package/src/shared/domain/git/worktree.ts +46 -0
  470. package/src/shared/domain/host-layout.ts +147 -0
  471. package/src/shared/domain/host-paths.ts +399 -0
  472. package/src/shared/domain/index-languages.ts +16 -0
  473. package/src/shared/domain/instructions-file.ts +18 -0
  474. package/src/shared/domain/iso-day.ts +4 -0
  475. package/src/shared/domain/llm-failure.ts +134 -0
  476. package/src/shared/domain/llm-profile.ts +44 -0
  477. package/src/shared/domain/marked-message.ts +29 -0
  478. package/src/shared/domain/markers.ts +30 -0
  479. package/src/shared/domain/messages.ts +291 -0
  480. package/src/shared/domain/model-catalog.ts +79 -0
  481. package/src/shared/domain/permission-modes.ts +99 -0
  482. package/src/shared/domain/prelude.ts +92 -0
  483. package/src/shared/domain/project-manifests.ts +84 -0
  484. package/src/shared/domain/prompts.ts +233 -0
  485. package/src/shared/domain/search-routing.ts +77 -0
  486. package/src/shared/domain/secret-patterns.ts +46 -0
  487. package/src/shared/domain/session-keys.ts +92 -0
  488. package/src/shared/domain/session-start.ts +61 -0
  489. package/src/shared/domain/severity.ts +72 -0
  490. package/src/shared/domain/sha1.ts +61 -0
  491. package/src/shared/domain/shared-memory/agent-memory-import.ts +145 -0
  492. package/src/shared/domain/shared-memory/candidates.ts +40 -0
  493. package/src/shared/domain/shared-memory/entry.ts +151 -0
  494. package/src/shared/domain/shared-memory/front-matter.ts +187 -0
  495. package/src/shared/domain/shared-memory/gate.ts +45 -0
  496. package/src/shared/domain/shared-memory/harvest.ts +64 -0
  497. package/src/shared/domain/shared-memory/layout.ts +190 -0
  498. package/src/shared/domain/shared-memory/markers.ts +9 -0
  499. package/src/shared/domain/shared-memory/messages.ts +66 -0
  500. package/src/shared/domain/shared-memory/precedents-block.ts +82 -0
  501. package/src/shared/domain/shared-memory/prompts.ts +28 -0
  502. package/src/shared/domain/shared-memory/refused.ts +84 -0
  503. package/src/shared/domain/shared-memory/verdict-rows.ts +134 -0
  504. package/src/shared/domain/skills/prompts.ts +4 -0
  505. package/src/shared/domain/skills/shortlist.ts +149 -0
  506. package/src/shared/domain/snip-turns.ts +33 -0
  507. package/src/shared/domain/speech.ts +21 -0
  508. package/src/shared/domain/strip.ts +88 -0
  509. package/src/shared/domain/tool-trace.ts +120 -0
  510. package/src/shared/domain/types.ts +67 -0
  511. package/src/shared/domain/verifiers.ts +33 -0
  512. package/src/shared/domain/vfs.ts +16 -0
  513. package/src/shared/domain/workflow/prompts.ts +15 -0
  514. package/src/shared/domain/workflow/state-file.ts +142 -0
  515. package/src/shared/infrastructure/globals.ts +57 -0
  516. package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
  517. package/src/shared/infrastructure/orkeon/child-agents.ts +122 -0
  518. package/src/shared/infrastructure/orkeon/chooser.ts +32 -0
  519. package/src/shared/infrastructure/orkeon/code-index.ts +120 -0
  520. package/src/shared/infrastructure/orkeon/crew-host.ts +27 -0
  521. package/src/shared/infrastructure/orkeon/crew-memory.ts +12 -0
  522. package/src/shared/infrastructure/orkeon/decision-model.ts +31 -0
  523. package/src/shared/infrastructure/orkeon/dev-deps.ts +179 -0
  524. package/src/shared/infrastructure/orkeon/files.ts +58 -0
  525. package/src/shared/infrastructure/orkeon/github-pull-requests.ts +30 -0
  526. package/src/shared/infrastructure/orkeon/host-context.ts +36 -0
  527. package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
  528. package/src/shared/infrastructure/orkeon/human-input.ts +55 -0
  529. package/src/shared/infrastructure/orkeon/llm-profile.ts +58 -0
  530. package/src/shared/infrastructure/orkeon/llm.ts +164 -0
  531. package/src/shared/infrastructure/orkeon/markers.ts +6 -0
  532. package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
  533. package/src/shared/infrastructure/orkeon/memory-tools.ts +129 -0
  534. package/src/shared/infrastructure/orkeon/messages.ts +15 -0
  535. package/src/shared/infrastructure/orkeon/permission-rules.ts +42 -0
  536. package/src/shared/infrastructure/orkeon/progress.ts +24 -0
  537. package/src/shared/infrastructure/orkeon/prompts.ts +47 -0
  538. package/src/shared/infrastructure/orkeon/reasoning.ts +40 -0
  539. package/src/shared/infrastructure/orkeon/run-state.ts +17 -0
  540. package/src/shared/infrastructure/orkeon/runtime-info.ts +30 -0
  541. package/src/shared/infrastructure/orkeon/runtime-tools.ts +60 -0
  542. package/src/shared/infrastructure/orkeon/script-tools.ts +129 -0
  543. package/src/shared/infrastructure/orkeon/session-store.ts +94 -0
  544. package/src/shared/infrastructure/orkeon/session-switch.ts +23 -0
  545. package/src/shared/infrastructure/orkeon/shared-memory.ts +61 -0
  546. package/src/shared/infrastructure/orkeon/shell-jobs.ts +81 -0
  547. package/src/shared/infrastructure/orkeon/shell.ts +39 -0
  548. package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
  549. package/src/shared/infrastructure/orkeon/tool-catalogue.ts +76 -0
  550. package/src/shared/infrastructure/orkeon/tool-results.ts +120 -0
  551. package/src/shared/infrastructure/orkeon/usage.ts +74 -0
  552. package/src/shared/infrastructure/orkeon/wiring.ts +174 -0
@@ -0,0 +1,199 @@
1
+ // Routing a crew to the cheapest profile that fits its task (ADR 0027). The host declares LLM profiles
2
+ // (`Llm:Profiles:<name>`); `route.ladder` orders some of them, cheapest first. At a crew's launch the host's
3
+ // decision model reads the command and picks a rung; rules of the project raise a floor (a path the command names,
4
+ // the crew itself); the session's own profile is the ceiling. Below a confidence, or without an answer, the session's
5
+ // profile stands. Routing picks a profile, it forbids nothing. Every number is stated with its reason. Pure.
6
+ import type { DecisionAnswers, DecisionQuestions } from "../decision/questions.ts";
7
+ import { llmProfileProblem } from "../llm-profile.ts";
8
+ import { ladderNeedsTwo, ladderRepeats } from "./messages.ts";
9
+ import { routeRung, routeStateText } from "./prompts.ts";
10
+
11
+ /** The setting that turns the routing on: `on`, anything else is off. */
12
+ export const ROUTE_AGENTS_CONFIG_KEY = "route.agents";
13
+ /** The setting that orders the profiles, cheapest first, comma-separated. */
14
+ export const ROUTE_LADDER_CONFIG_KEY = "route.ladder";
15
+ /** The ladder of the example settings: their two profiles. */
16
+ export const DEFAULT_LADDER: readonly string[] = ["small", "large"];
17
+ /** The probability of its pick under which the model is not followed: between two rungs, a pick under 0.6 is barely
18
+ * ahead of the other, and the session's profile is what the user chose. The probability is the one the answer gives
19
+ * the option picked; the answer's `confidence` is a figure of the provider's own, read only when that one is absent. */
20
+ export const ROUTE_MIN_CONFIDENCE = 0.6;
21
+ /** The command, as the decision model reads it, in characters: cut in the middle, its start and its end kept. */
22
+ export const ROUTE_BRIEF_CHARS = 4_000;
23
+ /** The choices `/route why` shows. */
24
+ export const ROUTE_RECENT = 5;
25
+ /** The project's floors, read at each routed launch. */
26
+ export const ROUTE_RULES_FILE = ".orkeon/route-rules.json";
27
+ /** The name of the question asked. */
28
+ export const ROUTE_QUESTION = "profile";
29
+
30
+ /** Why a pick stands. */
31
+ export type RouteReason = "model" | "floor" | "ceiling" | "low-confidence" | "no-answer";
32
+
33
+ export interface RouteChoice {
34
+ /** The profile the crew runs on; null: the host's default model, as without routing. */
35
+ profile: string | null;
36
+ reason: RouteReason;
37
+ /** What the model picked and how surely, when it answered. */
38
+ picked?: string;
39
+ confidence?: number;
40
+ }
41
+
42
+ /** The floors of a project: a profile of the ladder at least, for a path prefix or for a crew. */
43
+ export interface RouteRules {
44
+ paths: Readonly<Record<string, string>>;
45
+ crews: Readonly<Record<string, string>>;
46
+ }
47
+
48
+ export const NO_ROUTE_RULES: RouteRules = { paths: {}, crews: {} };
49
+
50
+ /** Whether the setting's value turns the routing on. */
51
+ export function routeOn(value: unknown): boolean {
52
+ return typeof value === "string" && value.trim().toLowerCase() === "on";
53
+ }
54
+
55
+ function names(value: string): string[] {
56
+ return value.split(",").map((name) => name.trim()).filter((name) => name.length > 0);
57
+ }
58
+
59
+ /** Why a value is refused for `route.ladder`; undefined when it is a ladder. */
60
+ export function ladderProblem(value: string): string | undefined {
61
+ const rungs = names(value);
62
+ if (rungs.length < 2) return ladderNeedsTwo(value);
63
+ for (const rung of rungs) {
64
+ const problem = llmProfileProblem(rung);
65
+ if (problem !== undefined) return problem;
66
+ }
67
+ return new Set(rungs).size === rungs.length ? undefined : ladderRepeats(value);
68
+ }
69
+
70
+ /** The ladder a setting names; the default one when it names none or what it names is no ladder. */
71
+ export function ladderOf(value: unknown): readonly string[] {
72
+ return typeof value === "string" && ladderProblem(value) === undefined ? names(value) : DEFAULT_LADDER;
73
+ }
74
+
75
+ /** The floors a rules file holds: `{ "paths": { "<prefix>": "<profile>" }, "crews": { "<crew>": "<profile>" } }`. An
76
+ * entry that is not a string is dropped; a text that is not such an object holds none. */
77
+ export function parseRouteRules(text: string): RouteRules {
78
+ let raw: unknown;
79
+ try {
80
+ raw = JSON.parse(text);
81
+ } catch {
82
+ return NO_ROUTE_RULES;
83
+ }
84
+ const section = (name: "paths" | "crews"): Record<string, string> => {
85
+ const value = (raw as Record<string, unknown> | null)?.[name];
86
+ const out: Record<string, string> = {};
87
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return out;
88
+ for (const [key, profile] of Object.entries(value)) {
89
+ if (typeof profile === "string" && key.trim().length > 0) out[key.trim()] = profile.trim();
90
+ }
91
+ return out;
92
+ };
93
+ return typeof raw === "object" && raw !== null && !Array.isArray(raw) ? { paths: section("paths"), crews: section("crews") } : NO_ROUTE_RULES;
94
+ }
95
+
96
+ /** A path as the rules compare it: slashes one way, no `/workspace/` nor `./` in front, no slash at the end. */
97
+ function bare(path: string): string {
98
+ return path.replace(/\\/g, "/").replace(/^\/workspace\//, "").replace(/^\.\//, "").replace(/\/+$/, "");
99
+ }
100
+
101
+ /** The words of a command, as paths: quotes and the punctuation around a word dropped. */
102
+ function wordsOf(brief: string): string[] {
103
+ return brief.split(/\s+/).map((word) => bare(word.replace(/^["'`(]+|["'`),;:]+$/g, ""))).filter((word) => word.length > 0);
104
+ }
105
+
106
+ /** The rung the rules ask for at least: the crew's own, and for each word of the command that is a rule's path or lies
107
+ * under it, the rule of its closest ancestor; the highest of them. 0 when no rule applies; a rule naming a profile
108
+ * outside the ladder, or whose path is empty once written bare (`/`, `./`), is ignored. */
109
+ export function routeFloor(rules: RouteRules, crew: string, brief: string, ladder: readonly string[]): number {
110
+ let floor = Math.max(0, ladder.indexOf(rules.crews[crew] ?? ""));
111
+ const prefixes = Object.keys(rules.paths)
112
+ .map((prefix) => ({ prefix: bare(prefix), profile: rules.paths[prefix] }))
113
+ .filter(({ prefix }) => prefix.length > 0);
114
+ for (const word of wordsOf(brief)) {
115
+ const closest = prefixes
116
+ .filter(({ prefix }) => word === prefix || word.startsWith(`${prefix}/`))
117
+ .sort((x, y) => y.prefix.length - x.prefix.length)[0];
118
+ if (closest !== undefined) floor = Math.max(floor, ladder.indexOf(closest.profile));
119
+ }
120
+ return floor;
121
+ }
122
+
123
+ function middleCut(text: string, max: number): string {
124
+ if (text.length <= max) return text;
125
+ const kept = max - " ... ".length;
126
+ const head = Math.ceil(kept / 2);
127
+ return `${text.slice(0, head)} ... ${text.slice(text.length - (kept - head))}`;
128
+ }
129
+
130
+ /** The state the decision model judges: the crew and the command that launches it. */
131
+ export function routeState(crew: string, brief: string): string {
132
+ return routeStateText(crew, middleCut(brief.trim(), ROUTE_BRIEF_CHARS));
133
+ }
134
+
135
+ /** One choice among the rungs, each described by its place on the ladder. */
136
+ export function routeQuestions(ladder: readonly string[]): DecisionQuestions {
137
+ const criteria: Record<string, string> = {};
138
+ ladder.forEach((rung, i) => {
139
+ criteria[rung] = routeRung(i === 0 ? "lowest" : i === ladder.length - 1 ? "highest" : "middle");
140
+ });
141
+ return { [ROUTE_QUESTION]: { type: "choice", criteria } };
142
+ }
143
+
144
+ /** Whether a session on `sessionProfile` can be routed: on the default model, or on a rung of the ladder. A session on
145
+ * another profile (a decision profile that guards its requests) keeps it. */
146
+ export function routable(sessionProfile: string | null, ladder: readonly string[]): boolean {
147
+ return sessionProfile === null || ladder.includes(sessionProfile);
148
+ }
149
+
150
+ /** The profile of a launch: the model's pick when it is sure enough, raised to the floor, never above the session's
151
+ * own rung. Without an answer, or under the bar, the session's profile; a session on the host's default model then
152
+ * takes the floor's rung when a rule sets one, since the rule is the project's own word. A session on a profile
153
+ * outside the ladder keeps it. */
154
+ export function routeOf(
155
+ answers: DecisionAnswers | null, ladder: readonly string[], sessionProfile: string | null, floor: number,
156
+ ): RouteChoice {
157
+ if (sessionProfile !== null && !ladder.includes(sessionProfile)) return { profile: sessionProfile, reason: "ceiling" };
158
+ const unrouted = (reason: RouteReason): RouteChoice =>
159
+ sessionProfile === null && floor > 0 ? { profile: ladder[floor], reason: "floor" } : { profile: sessionProfile, reason };
160
+ const answer = answers?.[ROUTE_QUESTION];
161
+ if (answer?.type !== "choice" || !ladder.includes(answer.choice)) return unrouted("no-answer");
162
+ const told = { picked: answer.choice, confidence: answer.probabilities[answer.choice] ?? answer.confidence };
163
+ if (told.confidence < ROUTE_MIN_CONFIDENCE) return { ...unrouted("low-confidence"), ...told };
164
+ const ceiling = sessionProfile === null ? ladder.length - 1 : ladder.indexOf(sessionProfile);
165
+ const picked = ladder.indexOf(answer.choice);
166
+ const raised = Math.max(picked, floor);
167
+ const rung = Math.min(raised, ceiling);
168
+ const reason: RouteReason = rung < raised ? "ceiling" : raised > picked ? "floor" : "model";
169
+ return { profile: ladder[rung], reason, ...told };
170
+ }
171
+
172
+ /** Whether a choice is a decision (the model's pick, held or raised), not the session's profile left to stand. */
173
+ export function routeDecided(reason: RouteReason): boolean {
174
+ return reason !== "no-answer" && reason !== "low-confidence";
175
+ }
176
+
177
+ /** One line of `/route why`, kept in the session. */
178
+ export interface RouteRecord {
179
+ crew: string;
180
+ profile: string | null;
181
+ reason: RouteReason;
182
+ picked?: string;
183
+ confidence?: number;
184
+ }
185
+
186
+ /** The records with `next` added, the last ROUTE_RECENT kept. */
187
+ export function withRecord(records: readonly RouteRecord[], next: RouteRecord): RouteRecord[] {
188
+ return [...records, next].slice(-ROUTE_RECENT);
189
+ }
190
+
191
+ /** The records a stored value holds; none when it is not a list of them. */
192
+ export function parseRecords(stored: string | null): RouteRecord[] {
193
+ try {
194
+ const raw: unknown = JSON.parse(stored ?? "[]");
195
+ return Array.isArray(raw) ? raw.filter((r): r is RouteRecord => typeof r?.crew === "string" && typeof r?.reason === "string") : [];
196
+ } catch {
197
+ return [];
198
+ }
199
+ }
@@ -0,0 +1,20 @@
1
+ // The text an agent reads in the brief of a repair by a new run.
2
+
3
+ /** What a cut text starts with. */
4
+ export const CUT_MARK = "[… the start is left out]\n";
5
+ export const repairOpening = (charter: string, id: string): string =>
6
+ `This is a new run of ${charter}, repairing instance ${id} of an ended run: you do not have its context,`;
7
+ export const REPAIR_INSTRUCTION =
8
+ "only what follows. Answer the operator's message below, then give the whole report again in the shape the previous brief asked for.";
9
+ export const noReport = (state: string, error: string): string => `(none: the instance ${state}${error})`;
10
+
11
+ // ── Routing a crew to a profile: what the decision model reads ──────────
12
+
13
+ export const routeStateText = (crew: string, command: string): string =>
14
+ `A coding assistant is about to run its crew '${crew}' for this command of its user:\n${command}`;
15
+ const RUNGS = {
16
+ lowest: "The cheapest, fastest model is enough: a lookup, a summary, a mechanical or fully specified task.",
17
+ middle: "A mid-range model fits: more than a mechanical task, less than a design or a change across modules.",
18
+ highest: "The strongest model is needed: a design, a change across several modules, subtle reasoning, a review that must not miss a defect.",
19
+ } as const;
20
+ export const routeRung = (place: keyof typeof RUNGS): string => RUNGS[place];
@@ -0,0 +1,357 @@
1
+ // B-14 — the VERIFIED request/response contract of the five code-intel tools.
2
+ // Pure, no IO.
3
+ //
4
+ // Every name below was read off a live call on 2026-08-05 (via `/debug-tool-call
5
+ // <tool> {json}`, which prints the raw result), not from a doc or a guess. That
6
+ // matters more than it sounds: the first draft of the code-intel probe assumed
7
+ // `symbol_name` and `direction: "callees"`, and read counts from `files_indexed`.
8
+ // All three were wrong —
9
+ // • `symbol_source` takes `fqn`;
10
+ // • `flow_trace.direction` is Forward | Backward | Both, and 'callees' is a
11
+ // typed deserialization failure;
12
+ // • `index_codebase` reports `file_count` / `node_count`, so a reader looking
13
+ // for `files_indexed` gets 0 from a successful index.
14
+ // The last one is the dangerous shape: the call SUCCEEDS and the caller reports
15
+ // "indexed 0 files", which reads exactly like an empty workspace. A wrong
16
+ // parameter name at least throws.
17
+ //
18
+ // So the readers live here, one per tool, with the field names pinned by tests
19
+ // against payloads captured from that live run. If the framework renames a field,
20
+ // a test fails instead of a probe quietly reporting zero.
21
+ import { CACHE_BYPASSED, CACHE_HIT, CACHE_MISS, cacheRefreshed } from "./messages.ts";
22
+
23
+ /** The eleven tools the main-loop catalogue grants for code intelligence.
24
+ * The first five were pinned 2026-08-05; the analysis five (dependency_graph,
25
+ * impact_analysis, package_summary, sub_graph, symbol_detail) were pinned
26
+ * 2026-08-06 from the extended probe's live run on the fixture; edge_list
27
+ * (Orkeon #280) from its published schema. */
28
+ export const CODE_INTEL_TOOLS = [
29
+ "index_codebase", "codebase_map", "codebase_search", "symbol_source", "flow_trace",
30
+ "dependency_graph", "impact_analysis", "package_summary", "sub_graph", "symbol_detail", "edge_list",
31
+ ] as const;
32
+
33
+ // ── Hybrid search + lazy freshness (captured live 2026-08-05, post-hybrid) ──
34
+ //
35
+ // codebase_search gained three surfaces, all read off live calls:
36
+ // - request `mode`: "Hybrid" (default) | "Vector" | "Lexical";
37
+ // - hit `match_origin`: "hybrid" | "vector" | "bm25" — WHY a hit ranked (an exact
38
+ // identifier reads hybrid/bm25; scores are RRF rank aggregates in hybrid mode,
39
+ // ~0.03 scale, NOT cosine);
40
+ // - response `refreshed_files`: how many edited files the lazy freshness pass
41
+ // reindexed BEFORE answering. Non-zero right after the agent's own edits.
42
+ // And rag_search takes `question` — NOT `query`. Session-4/5 lesson, third
43
+ // occurrence: the probe caught `{"query": ...} → "question parameter is required"`
44
+ // before any wiring shipped the wrong name.
45
+
46
+ /** `codebase_search.mode` vocabulary (the C# SearchMode enum, PascalCase). */
47
+ export const SEARCH_MODES = ["Hybrid", "Vector", "Lexical"] as const;
48
+
49
+ /** Hit origins the hybrid search reports. */
50
+ export const MATCH_ORIGINS = ["hybrid", "vector", "bm25"] as const;
51
+
52
+ /** `rag_search` request parameter names (verified live). */
53
+ export const RAG_SEARCH_PARAMS = ["question", "collection", "top_n"] as const;
54
+
55
+ /** Hit origin of one search hit; unknown/absent → "vector" (the pre-hybrid reading). */
56
+ export function readMatchOrigin(hit: any): string {
57
+ const v = String(hit?.match_origin ?? "").trim();
58
+ return (MATCH_ORIGINS as readonly string[]).includes(v) ? v : "vector";
59
+ }
60
+
61
+ /** Files the lazy freshness pass reindexed before this response. */
62
+ export function readRefreshedFiles(raw: any): number {
63
+ const v = Number(raw?.refreshed_files ?? 0);
64
+ return Number.isFinite(v) && v > 0 ? v : 0;
65
+ }
66
+
67
+ /** `flow_trace.direction` — the tool's own enum. Not caller/callee vocabulary. */
68
+ export const FLOW_DIRECTIONS = ["Forward", "Backward", "Both"] as const;
69
+ export type FlowDirection = (typeof FLOW_DIRECTIONS)[number];
70
+
71
+ /**
72
+ * The request parameter names, per tool, as the tools actually accept them.
73
+ * Kept as data so a probe cannot spell one differently from the pin.
74
+ */
75
+ export const CODE_INTEL_PARAMS = {
76
+ index_codebase: ["root_path"],
77
+ codebase_map: ["level", "include_metrics"],
78
+ codebase_search: ["query", "top_k", "filter_kinds"],
79
+ symbol_source: ["fqn"],
80
+ flow_trace: ["from", "to", "direction", "max_depth", "edge_kinds"],
81
+ // The analysis five — the subset each probe/command actually exercises, and the
82
+ // parameters code-intel-routing.ts names in the prompts (filter_kinds, edge_kinds, expand).
83
+ // `scope` is a NodeLevel ("L1_Package" | "L2_Module" | "L3_Symbol"), the same
84
+ // vocabulary codebase_map's `level` takes; `direction` reuses FLOW_DIRECTIONS.
85
+ dependency_graph: ["scope", "max_nodes", "include_mermaid"],
86
+ impact_analysis: ["target", "direction", "max_depth"],
87
+ package_summary: ["fqn"],
88
+ sub_graph: ["seeds", "depth", "direction", "edge_kinds"],
89
+ symbol_detail: ["fqn", "include_signature", "expand"],
90
+ // Every edge of the kinds across the index, or under root_fqn, page_size at a time (200, up to 1000); the
91
+ // response's next_cursor goes back as cursor until it is absent, and total counts them all (Orkeon #280).
92
+ edge_list: ["edge_kinds", "root_fqn", "page_size", "cursor"],
93
+ } as const;
94
+
95
+ function num(raw: any, key: string): number {
96
+ const v = raw?.[key];
97
+ return typeof v === "number" ? v : Number(v ?? 0) || 0;
98
+ }
99
+
100
+ function arr(raw: any, key: string): any[] {
101
+ const v = raw?.[key];
102
+ return Array.isArray(v) ? v : [];
103
+ }
104
+
105
+ export interface IndexSummary {
106
+ files: number;
107
+ nodes: number;
108
+ edges: number;
109
+ statements: number;
110
+ errors: string[];
111
+ /** What the index cache did (Orkeon #244): `hit`, `refreshed`, `miss` or `bypassed`; absent before #244. */
112
+ cache?: string;
113
+ /** The files a `refreshed` cache reindexed (`reindexed_file_count`), read when `cache` is. */
114
+ reindexed?: number;
115
+ }
116
+
117
+ /** `index_codebase` → counts. `file_count`, NOT `files_indexed`. */
118
+ export function readIndexSummary(raw: any): IndexSummary {
119
+ const cache = typeof raw?.cache === "string" && raw.cache !== "" ? raw.cache : undefined;
120
+ return {
121
+ files: num(raw, "file_count"),
122
+ nodes: num(raw, "node_count"),
123
+ edges: num(raw, "edge_count"),
124
+ statements: num(raw, "statement_count"),
125
+ errors: arr(raw, "errors").map((e) => String(e)),
126
+ ...(cache === undefined ? {} : { cache, reindexed: num(raw, "reindexed_file_count") }),
127
+ };
128
+ }
129
+
130
+ /** What the index cache did, in words: empty on a runtime without the cache (before Orkeon #244). */
131
+ export function indexCacheNote(idx: IndexSummary): string {
132
+ switch (idx.cache) {
133
+ case undefined: return "";
134
+ case "hit": return CACHE_HIT;
135
+ case "refreshed": return cacheRefreshed(idx.reindexed ?? 0);
136
+ case "miss": return CACHE_MISS;
137
+ case "bypassed": return CACHE_BYPASSED;
138
+ default: return `cache ${idx.cache}`;
139
+ }
140
+ }
141
+
142
+ export interface MapEntry {
143
+ fqn: string;
144
+ name: string;
145
+ kind: string;
146
+ /** `children_count`, when the node has children: the modules of a package, the symbols of a module. */
147
+ children?: number;
148
+ }
149
+
150
+ /** `codebase_map` → `entries[]` (+ `totals`), NOT `nodes[]`. */
151
+ export function readMapEntries(raw: any): MapEntry[] {
152
+ return arr(raw, "entries").map((e) => {
153
+ const children = Number(e?.children_count);
154
+ return {
155
+ fqn: String(e?.fqn ?? ""),
156
+ name: String(e?.name ?? ""),
157
+ kind: String(e?.kind ?? ""),
158
+ ...(Number.isFinite(children) && children > 0 ? { children } : {}),
159
+ };
160
+ }).filter((e) => e.fqn.length > 0);
161
+ }
162
+
163
+ /** `codebase_map.totals.symbol_count`. */
164
+ export function readMapSymbolCount(raw: any): number {
165
+ return num(raw?.totals, "symbol_count");
166
+ }
167
+
168
+ export interface SearchHit {
169
+ fqn: string;
170
+ score: number;
171
+ }
172
+
173
+ /** `codebase_search` → `hits[] { fqn, score }`, NOT `results[]`. */
174
+ export function readSearchHits(raw: any): SearchHit[] {
175
+ return arr(raw, "hits").map((h) => ({ fqn: String(h?.fqn ?? ""), score: Number(h?.score ?? 0) }))
176
+ .filter((h) => h.fqn.length > 0);
177
+ }
178
+
179
+ /** `symbol_source` → the source text (`source`; `markdown_ready_block` is the fenced form). */
180
+ export function readSymbolSource(raw: any): { source: string; file: string; lines: string } {
181
+ return {
182
+ source: String(raw?.source ?? ""),
183
+ file: String(raw?.virtual_file_path ?? ""),
184
+ lines: `${num(raw, "start_line")}-${num(raw, "end_line")}`,
185
+ };
186
+ }
187
+
188
+ export interface SearchHitWithOrigin {
189
+ fqn: string;
190
+ score: number;
191
+ origin: string;
192
+ }
193
+
194
+ /** `codebase_search` → hits with their origin; a hit without fqn is dropped. The
195
+ * origin is read on the same raw hit, so a dropped hit cannot shift the others. */
196
+ export function readSearchHitsWithOrigin(raw: any): SearchHitWithOrigin[] {
197
+ return arr(raw, "hits").map((h) => ({
198
+ fqn: String(h?.fqn ?? ""), score: Number(h?.score ?? 0), origin: readMatchOrigin(h),
199
+ })).filter((h) => h.fqn.length > 0);
200
+ }
201
+
202
+ /** The longest first line a location keeps: enough to recognise a declaration. */
203
+ const FIRST_LINE_MAX = 160;
204
+
205
+ /** `symbol_source` → path, lines, language and the first non-blank source line
206
+ * (at most 160 characters). The live payload carries no `fqn`: the requested one
207
+ * stands in when the field is absent or empty. */
208
+ export function readSymbolLocation(raw: any, requestedFqn: string): {
209
+ fqn: string; path: string; startLine: number; endLine: number; language: string; firstLine: string;
210
+ } {
211
+ const fqn = String(raw?.fqn ?? "");
212
+ const first = String(raw?.source ?? "").split("\n").map((l) => l.trim()).find((l) => l.length > 0) ?? "";
213
+ return {
214
+ fqn: fqn.length > 0 ? fqn : requestedFqn,
215
+ path: String(raw?.virtual_file_path ?? ""),
216
+ startLine: num(raw, "start_line"),
217
+ endLine: num(raw, "end_line"),
218
+ language: String(raw?.language ?? ""),
219
+ firstLine: first.slice(0, FIRST_LINE_MAX),
220
+ };
221
+ }
222
+
223
+ /** `flow_trace` → `paths[]`, NOT `edges[]`. An empty array is a valid answer. */
224
+ export function readFlowPathCount(raw: any): number {
225
+ return arr(raw, "paths").length;
226
+ }
227
+
228
+ /**
229
+ * The FQN to use for the symbol-level probes: taken from the map rather than
230
+ * invented, so the probe works on any mounted codebase. "" when the map is empty —
231
+ * the caller must then report a SKIP, not a pass on a query that asked nothing.
232
+ */
233
+ export function firstSymbolFqn(mapRaw: any): string {
234
+ return readMapEntries(mapRaw)[0]?.fqn ?? "";
235
+ }
236
+
237
+ // ── The analysis five (pinned from the extended probe's live run, 2026-08-06) ──
238
+
239
+ /** One cycle of the graph, as dependency_graph names it (Orkeon #272): its members' FQNs, sorted and capped by
240
+ * `max_cycle_members`, and its full size. */
241
+ export interface GraphCycle {
242
+ members: string[];
243
+ memberCount: number;
244
+ }
245
+
246
+ export interface GraphSummary {
247
+ nodes: Array<{ fqn: string; name: string; kind: string }>;
248
+ edges: Array<{ from: string; to: string; kind: string }>;
249
+ nodeCount: number;
250
+ edgeCount: number;
251
+ cycleCount: number;
252
+ /** The cycles named, the largest first (`max_cycles`); none on sub_graph or a runtime before #273. */
253
+ cycles: GraphCycle[];
254
+ /** True when the index cut the list of cycles or the members of one. */
255
+ cyclesTruncated: boolean;
256
+ }
257
+
258
+ /** `dependency_graph` / `sub_graph` → `nodes[] {fqn,name,kind}` + `edges[] {from,to,kind}`.
259
+ * dependency_graph additionally carries `metrics {node_count, edge_count, cycle_count}` and, since
260
+ * Orkeon #273, `cycles[] {fqns, member_count}` with `cycles_truncated`; sub_graph has no metrics block,
261
+ * so the counts fall back to the array lengths, and names no cycle.
262
+ * Two quirks pinned from the live capture (2026-08-06):
263
+ * • edge `kind` serialized as a NUMBER (the C# EdgeKind flags value, 1 = Imports) until
264
+ * Orkeon #275, and since as snake_case names ("imports, calls"); node `kind` is a
265
+ * string ("module") — both coerced to string here;
266
+ * • edge `from`/`to` are node IDs ("/path#module@0"), NOT the nodes' `fqn` —
267
+ * joining edges to nodes needs the ID prefix, not equality. */
268
+ export function readGraph(raw: any): GraphSummary {
269
+ const nodes = arr(raw, "nodes").map((n) => ({
270
+ fqn: String(n?.fqn ?? ""), name: String(n?.name ?? ""), kind: String(n?.kind ?? ""),
271
+ })).filter((n) => n.fqn.length > 0);
272
+ const edges = arr(raw, "edges").map((e) => ({
273
+ from: String(e?.from ?? ""), to: String(e?.to ?? ""), kind: String(e?.kind ?? ""),
274
+ })).filter((e) => e.from.length > 0 && e.to.length > 0);
275
+ const metrics = raw?.metrics;
276
+ const cycles = arr(raw, "cycles").map((c) => {
277
+ const members = arr(c, "fqns").map((m) => String(m ?? "")).filter((m) => m.length > 0);
278
+ return { members, memberCount: Math.max(num(c, "member_count"), members.length) };
279
+ }).filter((c) => c.members.length > 0);
280
+ return {
281
+ nodes,
282
+ edges,
283
+ nodeCount: metrics ? num(metrics, "node_count") : nodes.length,
284
+ edgeCount: metrics ? num(metrics, "edge_count") : edges.length,
285
+ cycleCount: metrics ? num(metrics, "cycle_count") : 0,
286
+ cycles,
287
+ cyclesTruncated: raw?.cycles_truncated === true,
288
+ };
289
+ }
290
+
291
+ export interface ImpactSummary {
292
+ target: string;
293
+ direct: string[];
294
+ transitive: string[];
295
+ byPackage: Record<string, number>;
296
+ }
297
+
298
+ /** `impact_analysis` → `direct_impact[]` / `transitive_impact[]` / `by_package{}`. */
299
+ export function readImpact(raw: any): ImpactSummary {
300
+ const byPackage: Record<string, number> = {};
301
+ const bp = raw?.by_package;
302
+ if (bp && typeof bp === "object" && !Array.isArray(bp)) {
303
+ for (const k of Object.keys(bp)) byPackage[k] = Number(bp[k] ?? 0) || 0;
304
+ }
305
+ return {
306
+ target: String(raw?.target ?? ""),
307
+ direct: arr(raw, "direct_impact").map((s) => String(s)),
308
+ transitive: arr(raw, "transitive_impact").map((s) => String(s)),
309
+ byPackage,
310
+ };
311
+ }
312
+
313
+ export interface PackageSummary {
314
+ fqn: string;
315
+ name: string;
316
+ files: number;
317
+ symbols: number;
318
+ dependencies: string[];
319
+ /** `public_exports`: FQNs of the package's public symbols, at most 50, in the index's order. */
320
+ exports: string[];
321
+ /** `entry_points`: FQNs of the modules named after main, program or index. */
322
+ entryPoints: string[];
323
+ }
324
+
325
+ /** `package_summary` → `file_count`/`symbol_count` (the index_codebase naming, not files_indexed). */
326
+ export function readPackageSummary(raw: any): PackageSummary {
327
+ return {
328
+ fqn: String(raw?.fqn ?? ""),
329
+ name: String(raw?.name ?? ""),
330
+ files: num(raw, "file_count"),
331
+ symbols: num(raw, "symbol_count"),
332
+ dependencies: arr(raw, "dependencies").map((s) => String(s)),
333
+ exports: arr(raw, "public_exports").map((s) => String(s)),
334
+ entryPoints: arr(raw, "entry_points").map((s) => String(s)),
335
+ };
336
+ }
337
+
338
+ export interface SymbolDetail {
339
+ fqn: string;
340
+ name: string;
341
+ kind: string;
342
+ signature: string;
343
+ callers: number;
344
+ callees: number;
345
+ }
346
+
347
+ /** `symbol_detail` → identity + `signature` + `top_callers[]`/`top_callees[]`. */
348
+ export function readSymbolDetail(raw: any): SymbolDetail {
349
+ return {
350
+ fqn: String(raw?.fqn ?? ""),
351
+ name: String(raw?.name ?? ""),
352
+ kind: String(raw?.kind ?? ""),
353
+ signature: String(raw?.signature ?? ""),
354
+ callers: arr(raw, "top_callers").length,
355
+ callees: arr(raw, "top_callees").length,
356
+ };
357
+ }
@@ -0,0 +1,60 @@
1
+ // Which code-intelligence tool answers which question: pure, no IO.
2
+ //
3
+ // An agent handed the analysis tools with no rule of use answers a structural question ("every base class",
4
+ // "who inherits X") the way it knows best: a shell script of regular expressions over the files, slower than the
5
+ // index and blind to what the index has already resolved. This module states, per question, the tool that answers
6
+ // it and the parameter that makes it answer (the edge kind, the direction, the expansion), and nothing about a tool
7
+ // the agent was not given: each line is emitted only when every tool it names is in the agent's list.
8
+ //
9
+ // Parameter names and values are Orkeon's wire names as its schemas publish them (snake_case; `inherits` stands for
10
+ // extends and implements on the graph tools and edge_list; `expand` takes the PascalCase flags, `Inheritance` giving a
11
+ // type's bases and what derives from it since Orkeon #280). code-intel-contract.ts pins the parameter names.
12
+
13
+ import {
14
+ ASK_INDEX_BEFORE_READING, ASK_INDEX_BEFORE_SCRIPTING, CODE_INTEL_ROUTING_TEXT, truncatedIsASample,
15
+ } from "./prompts.ts";
16
+
17
+ /** One question and the tool that answers it: emitted when the agent holds every tool of `tools`. */
18
+ interface RoutingLine {
19
+ readonly tools: readonly string[];
20
+ readonly text: string;
21
+ }
22
+
23
+ const ROUTING_LINES: readonly RoutingLine[] = (Object.keys(CODE_INTEL_ROUTING_TEXT) as (keyof typeof CODE_INTEL_ROUTING_TEXT)[])
24
+ .map((tool) => ({ tools: [tool], text: CODE_INTEL_ROUTING_TEXT[tool] }));
25
+
26
+ /** The analysis tools whose answer can be cut: an agent holding one gets the exhaustiveness rule. */
27
+ const BOUNDED_TOOLS: readonly string[] = [
28
+ "codebase_map", "codebase_search", "dependency_graph", "grep", "structural_search", "sub_graph",
29
+ ];
30
+
31
+ /** The analysis tools that take a `root_fqn`, the subtree they answer for: the rule names it only to their holder. */
32
+ const ROOT_FQN_TOOLS: readonly string[] = ["codebase_map", "dependency_graph", "edge_list"];
33
+
34
+ /** The agent's shell, the tool a script over the files would run in: the rules speak of scripting only to its holder. */
35
+ const SHELL_TOOL = "shell_command";
36
+
37
+ /** The exhaustiveness rule; `shell` adds the script it replaces, for an agent that could write one; `rootFqn` names
38
+ * the parameter that narrows to a subtree, for an agent holding a tool that takes it. */
39
+ function exhaustivenessRule(shell: boolean, rootFqn: boolean): string {
40
+ const narrowers = ["one package", ...(rootFqn ? ["a `root_fqn`"] : []), "a `glob`"].join(", ");
41
+ return truncatedIsASample(narrowers, shell);
42
+ }
43
+
44
+ /** The question-to-tool lines for an agent holding `tools`, one line each, then the exhaustiveness rule when it
45
+ * applies; empty when the agent holds none of the analysis tools. Scripting is named only to an agent holding the
46
+ * shell, `root_fqn` only to one holding a tool that takes it. */
47
+ export function describeCodeIntelRouting(tools: readonly string[]): string {
48
+ const lines = ROUTING_LINES
49
+ .filter((line) => line.tools.every((tool) => tools.includes(tool)))
50
+ .map((line) => `- ${line.text}.`);
51
+ if (lines.length === 0) return "";
52
+ const bounded = BOUNDED_TOOLS.some((tool) => tools.includes(tool));
53
+ const shell = tools.includes(SHELL_TOOL);
54
+ const rootFqn = ROOT_FQN_TOOLS.some((tool) => tools.includes(tool));
55
+ return [
56
+ shell ? ASK_INDEX_BEFORE_SCRIPTING : ASK_INDEX_BEFORE_READING,
57
+ ...lines,
58
+ ...(bounded ? [exhaustivenessRule(shell, rootFqn)] : []),
59
+ ].join("\n");
60
+ }