orkeon-code 1.0.0-rc.1 → 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 (440) hide show
  1. package/.orkeon-runtime +10 -0
  2. package/.orkeon-version +1 -1
  3. package/NOTICE.md +1 -1
  4. package/README.fr.md +16 -22
  5. package/README.md +16 -22
  6. package/config/appsettings.jev.example.json +4 -1
  7. package/config/appsettings.kev.example.json +4 -1
  8. package/config/appsettings.liquid.example.json +4 -1
  9. package/config/appsettings.ollama-whisper.example.json +1 -0
  10. package/config/appsettings.whisper.example.json +1 -0
  11. package/mcp/whisper/README.md +2 -1
  12. package/orkeon-code +206 -11
  13. package/orkeon-code.ps1 +109 -7
  14. package/package.json +2 -1
  15. package/src/commands/.orkeon/orkeon-cli.d.ts +1 -4
  16. package/src/commands/_lib/args.ts +5 -4
  17. package/src/commands/_lib/dev/dev-batches.ts +34 -36
  18. package/src/commands/_lib/dev/dev-implement.ts +11 -14
  19. package/src/commands/_lib/dev/dev-source.ts +7 -11
  20. package/src/commands/_lib/dev/dev.ts +34 -37
  21. package/src/commands/_lib/dev/markers.ts +7 -0
  22. package/src/commands/_lib/dev/messages.ts +112 -0
  23. package/src/commands/_lib/dev-step.ts +16 -13
  24. package/src/commands/_lib/dispatch.ts +62 -39
  25. package/src/commands/_lib/git/branch.ts +9 -10
  26. package/src/commands/_lib/git/commit.ts +9 -13
  27. package/src/commands/_lib/git/diff.ts +22 -12
  28. package/src/commands/_lib/git/messages.ts +54 -0
  29. package/src/commands/_lib/git/review.ts +9 -10
  30. package/src/commands/_lib/memory/memory-admit.ts +19 -21
  31. package/src/commands/_lib/memory/memory.ts +3 -2
  32. package/src/commands/_lib/memory/messages.ts +32 -0
  33. package/src/commands/_lib/messages.ts +48 -0
  34. package/src/commands/_lib/project/messages.ts +8 -0
  35. package/src/commands/_lib/session/export.ts +3 -2
  36. package/src/commands/_lib/session/messages.ts +87 -0
  37. package/src/commands/_lib/session/prompts.ts +4 -0
  38. package/src/commands/_lib/session/resume.ts +15 -24
  39. package/src/commands/_lib/session/tasks.ts +20 -23
  40. package/src/commands/_lib/settings/advisor.ts +11 -16
  41. package/src/commands/_lib/settings/agents.ts +18 -28
  42. package/src/commands/_lib/settings/choices.ts +8 -0
  43. package/src/commands/_lib/settings/config.ts +43 -43
  44. package/src/commands/_lib/settings/effort.ts +147 -0
  45. package/src/commands/_lib/settings/hooks.ts +12 -20
  46. package/src/commands/_lib/settings/messages.ts +408 -0
  47. package/src/commands/_lib/settings/mode.ts +33 -24
  48. package/src/commands/_lib/settings/model.ts +71 -36
  49. package/src/commands/_lib/settings/output-style.ts +39 -0
  50. package/src/commands/_lib/settings/permissions.ts +71 -93
  51. package/src/commands/_lib/settings/route.ts +63 -0
  52. package/src/commands/_lib/settings/skills.ts +53 -11
  53. package/src/commands/_lib/settings/theme.ts +42 -0
  54. package/src/commands/_lib/speech/messages.ts +58 -0
  55. package/src/commands/_lib/speech/prompts.ts +4 -0
  56. package/src/commands/_lib/speech/say.ts +9 -10
  57. package/src/commands/_lib/speech/transcribe.ts +14 -23
  58. package/src/commands/_lib/speech/voice.ts +14 -18
  59. package/src/commands/_lib/status/doctor.ts +47 -28
  60. package/src/commands/_lib/status/messages.ts +100 -0
  61. package/src/commands/_lib/status/meta.ts +3 -24
  62. package/src/commands/_lib/status/status.ts +10 -11
  63. package/src/commands/_lib/status/usage-tools.ts +2 -3
  64. package/src/commands/_lib/status/usage.ts +7 -18
  65. package/src/commands/_lib/view.ts +6 -1
  66. package/src/commands/dev/dev-batches.cmd.ts +4 -3
  67. package/src/commands/dev/dev-learn.cmd.ts +3 -3
  68. package/src/commands/dev/dev-plan.cmd.ts +6 -7
  69. package/src/commands/dev/dev-spec.cmd.ts +6 -7
  70. package/src/commands/git/commit.cmd.ts +3 -3
  71. package/src/commands/git/review.cmd.ts +3 -3
  72. package/src/commands/memory/memory.cmd.ts +2 -2
  73. package/src/commands/project/analyze.cmd.ts +3 -3
  74. package/src/commands/project/debug-tool-call.cmd.ts +4 -9
  75. package/src/commands/project/init-verifiers.cmd.ts +3 -3
  76. package/src/commands/project/init.cmd.ts +3 -3
  77. package/src/commands/project/verify.cmd.ts +2 -2
  78. package/src/commands/session/assistant.cmd.ts +2 -2
  79. package/src/commands/session/compact.cmd.ts +1 -1
  80. package/src/commands/session/copy.cmd.ts +8 -7
  81. package/src/commands/session/rename.cmd.ts +3 -2
  82. package/src/commands/session/rewind.cmd.ts +3 -4
  83. package/src/commands/session/summary.cmd.ts +3 -3
  84. package/src/commands/session/tasks.cmd.ts +4 -2
  85. package/src/commands/settings/config.cmd.ts +4 -2
  86. package/src/commands/settings/effort.cmd.ts +10 -31
  87. package/src/commands/settings/fast.cmd.ts +2 -1
  88. package/src/commands/settings/mode.cmd.ts +3 -3
  89. package/src/commands/settings/model.cmd.ts +3 -2
  90. package/src/commands/settings/output-style.cmd.ts +9 -38
  91. package/src/commands/settings/permissions.cmd.ts +2 -2
  92. package/src/commands/settings/proactive.cmd.ts +2 -1
  93. package/src/commands/settings/route.cmd.ts +16 -0
  94. package/src/commands/settings/skills.cmd.ts +3 -3
  95. package/src/commands/settings/theme.cmd.ts +14 -0
  96. package/src/commands/speech/say.cmd.ts +2 -2
  97. package/src/commands/speech/transcribe.cmd.ts +2 -2
  98. package/src/commands/status/release-notes.cmd.ts +1 -1
  99. package/src/crews/.orkeon/orkeon.d.ts +538 -93
  100. package/src/crews/_probe-shared-memory/domain/messages.ts +54 -0
  101. package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +17 -12
  102. package/src/crews/_probe-shared-memory/domain/prompts.ts +5 -0
  103. package/src/crews/_probe-shared-memory/probe.ork.ts +5 -3
  104. package/src/crews/advisor/application/messages.ts +4 -0
  105. package/src/crews/advisor/application/prompts.ts +4 -0
  106. package/src/crews/advisor/application/run-advisor.ts +2 -1
  107. package/src/crews/advisor/crew.ork.ts +5 -4
  108. package/src/crews/advisor/domain/advice.ts +7 -23
  109. package/src/crews/advisor/domain/messages.ts +8 -0
  110. package/src/crews/advisor/domain/prompts.ts +26 -0
  111. package/src/crews/agent-run/application/messages.ts +18 -0
  112. package/src/crews/agent-run/application/run-agent-run.ts +5 -4
  113. package/src/crews/agent-run/crew.ork.ts +3 -3
  114. package/src/crews/analyze/application/messages.ts +27 -0
  115. package/src/crews/analyze/application/prompts.ts +4 -0
  116. package/src/crews/analyze/application/run-analyze.ts +16 -14
  117. package/src/crews/analyze/crew.ork.ts +5 -4
  118. package/src/crews/analyze/domain/harvest.ts +33 -65
  119. package/src/crews/analyze/domain/prompts.ts +86 -0
  120. package/src/crews/code-review/application/lens-material.ts +24 -0
  121. package/src/crews/code-review/application/messages.ts +17 -0
  122. package/src/crews/code-review/application/prompts.ts +10 -17
  123. package/src/crews/code-review/application/review.ts +4 -1
  124. package/src/crews/code-review/application/run-code-review.ts +13 -15
  125. package/src/crews/code-review/crew.ork.ts +5 -4
  126. package/src/crews/code-review/domain/lenses.ts +6 -45
  127. package/src/crews/code-review/domain/messages.ts +25 -0
  128. package/src/crews/code-review/domain/prompts.ts +58 -0
  129. package/src/crews/code-review/domain/report.ts +5 -6
  130. package/src/crews/code-review/domain/scope.ts +6 -12
  131. package/src/crews/dev-batches/application/messages.ts +127 -0
  132. package/src/crews/dev-batches/application/plan-close.ts +12 -12
  133. package/src/crews/dev-batches/application/prompts.ts +10 -0
  134. package/src/crews/dev-batches/application/run-dev-batches.ts +57 -50
  135. package/src/crews/dev-batches/application/run-wave.ts +24 -22
  136. package/src/crews/dev-batches/application/seed-harvest.ts +8 -7
  137. package/src/crews/dev-batches/crew.ork.ts +12 -9
  138. package/src/crews/dev-batches/domain/batches-log.ts +1 -3
  139. package/src/crews/dev-batches/domain/markers.ts +5 -0
  140. package/src/crews/dev-batches/domain/messages.ts +6 -0
  141. package/src/crews/dev-batches/domain/wave-order.ts +3 -2
  142. package/src/crews/dev-change/application/change-material.ts +44 -0
  143. package/src/crews/dev-change/application/evidence.ts +25 -22
  144. package/src/crews/dev-change/application/messages.ts +81 -0
  145. package/src/crews/dev-change/application/{change-prompt.ts → prompts.ts} +40 -43
  146. package/src/crews/dev-change/application/run-dev-change.ts +43 -34
  147. package/src/crews/dev-change/crew.ork.ts +11 -9
  148. package/src/crews/dev-change/domain/change-answer.ts +24 -20
  149. package/src/crews/dev-change/domain/change-render.ts +13 -15
  150. package/src/crews/dev-change/domain/markers.ts +28 -0
  151. package/src/crews/dev-change/domain/messages.ts +16 -0
  152. package/src/crews/dev-implement/application/close.ts +21 -18
  153. package/src/crews/dev-implement/application/locate-sheet.ts +7 -5
  154. package/src/crews/dev-implement/application/messages.ts +161 -0
  155. package/src/crews/dev-implement/application/observe.ts +4 -2
  156. package/src/crews/dev-implement/application/prompts.ts +9 -0
  157. package/src/crews/dev-implement/application/report-writes.ts +14 -9
  158. package/src/crews/dev-implement/application/run-dev-implement.ts +84 -73
  159. package/src/crews/dev-implement/application/suite-job.ts +15 -11
  160. package/src/crews/dev-implement/crew.ork.ts +2 -1
  161. package/src/crews/dev-implement/domain/contracts.ts +59 -60
  162. package/src/crews/dev-implement/domain/correction.ts +16 -15
  163. package/src/crews/dev-implement/domain/cycles.ts +2 -1
  164. package/src/crews/dev-implement/domain/markers.ts +23 -0
  165. package/src/crews/dev-implement/domain/messages.ts +58 -0
  166. package/src/crews/dev-implement/domain/prompts.ts +93 -0
  167. package/src/crews/dev-implement/domain/roles.ts +3 -7
  168. package/src/crews/dev-implement/domain/sheet-edits.ts +6 -5
  169. package/src/crews/dev-implement/domain/sheet-ticks.ts +5 -4
  170. package/src/crews/dev-implement/domain/step-checks.ts +17 -16
  171. package/src/crews/dev-implement/domain/step-section.ts +6 -4
  172. package/src/crews/dev-learn/application/learn-prompt-fit.ts +63 -0
  173. package/src/crews/dev-learn/application/messages.ts +51 -0
  174. package/src/crews/dev-learn/application/{learn-prompt.ts → prompts.ts} +24 -65
  175. package/src/crews/dev-learn/application/run-dev-learn.ts +37 -32
  176. package/src/crews/dev-learn/crew.ork.ts +4 -3
  177. package/src/crews/dev-learn/domain/learn-answer.ts +25 -27
  178. package/src/crews/dev-learn/domain/messages.ts +65 -0
  179. package/src/crews/dev-learn/domain/owner-lines.ts +12 -9
  180. package/src/crews/dev-learn/domain/proposals-render.ts +8 -9
  181. package/src/crews/dev-plan/application/anchor-paths.ts +57 -20
  182. package/src/crews/dev-plan/application/inventory.ts +17 -13
  183. package/src/crews/dev-plan/application/messages.ts +88 -0
  184. package/src/crews/dev-plan/application/plan-prompt-fit.ts +44 -0
  185. package/src/crews/dev-plan/application/{plan-prompt.ts → prompts.ts} +37 -55
  186. package/src/crews/dev-plan/application/run-dev-plan.ts +103 -75
  187. package/src/crews/dev-plan/crew.ork.ts +11 -8
  188. package/src/crews/dev-plan/domain/inventory-model.ts +3 -3
  189. package/src/crews/dev-plan/domain/markers.ts +18 -0
  190. package/src/crews/dev-plan/domain/messages.ts +118 -0
  191. package/src/crews/dev-plan/domain/plan-answer.ts +118 -103
  192. package/src/crews/dev-plan/domain/plan-render.ts +30 -31
  193. package/src/crews/dev-plan/domain/prompts.ts +44 -0
  194. package/src/crews/dev-spec/application/messages.ts +30 -0
  195. package/src/crews/dev-spec/application/{spec-prompt.ts → prompts.ts} +42 -47
  196. package/src/crews/dev-spec/application/run-dev-spec.ts +67 -36
  197. package/src/crews/dev-spec/application/spec-material.ts +42 -0
  198. package/src/crews/dev-spec/crew.ork.ts +11 -9
  199. package/src/crews/dev-spec/domain/markers.ts +30 -0
  200. package/src/crews/dev-spec/domain/messages.ts +39 -0
  201. package/src/crews/dev-spec/domain/spec-answer.ts +46 -47
  202. package/src/crews/dev-spec/domain/spec-render.ts +18 -18
  203. package/src/crews/dev-verify/application/audit-brief.ts +187 -0
  204. package/src/crews/dev-verify/application/audit.ts +38 -30
  205. package/src/crews/dev-verify/application/capture.ts +34 -26
  206. package/src/crews/dev-verify/application/messages.ts +119 -0
  207. package/src/crews/dev-verify/application/prompts.ts +209 -0
  208. package/src/crews/dev-verify/application/run-dev-verify.ts +60 -46
  209. package/src/crews/dev-verify/application/run-gate.ts +11 -9
  210. package/src/crews/dev-verify/crew.ork.ts +6 -6
  211. package/src/crews/dev-verify/domain/audit-answer.ts +16 -12
  212. package/src/crews/dev-verify/domain/capture-sections.ts +5 -4
  213. package/src/crews/dev-verify/domain/commands.ts +3 -3
  214. package/src/crews/dev-verify/domain/gate.ts +21 -16
  215. package/src/crews/dev-verify/domain/markers.ts +16 -0
  216. package/src/crews/dev-verify/domain/mechanical-table.ts +37 -44
  217. package/src/crews/dev-verify/domain/messages.ts +92 -0
  218. package/src/crews/dev-verify/domain/verdict.ts +4 -4
  219. package/src/crews/git-commit/application/draft.ts +16 -37
  220. package/src/crews/git-commit/application/messages.ts +15 -0
  221. package/src/crews/git-commit/application/prompts.ts +47 -0
  222. package/src/crews/git-commit/application/run-git-commit.ts +13 -12
  223. package/src/crews/git-commit/crew.ork.ts +5 -4
  224. package/src/crews/git-commit/domain/commit.ts +15 -35
  225. package/src/crews/git-commit/domain/markers.ts +4 -0
  226. package/src/crews/git-commit/domain/messages.ts +48 -0
  227. package/src/crews/init-verifiers/application/authoring.ts +2 -1
  228. package/src/crews/init-verifiers/application/messages.ts +13 -0
  229. package/src/crews/init-verifiers/application/prompts.ts +5 -1
  230. package/src/crews/init-verifiers/application/run-init-verifiers.ts +3 -2
  231. package/src/crews/init-verifiers/crew.ork.ts +5 -4
  232. package/src/crews/main-loop/application/auto-compact.ts +2 -1
  233. package/src/crews/main-loop/application/messages.ts +81 -0
  234. package/src/crews/main-loop/application/prompts.ts +12 -0
  235. package/src/crews/main-loop/application/run-main-loop.ts +63 -30
  236. package/src/crews/main-loop/application/{turn-prompt.ts → turn-context.ts} +7 -8
  237. package/src/crews/main-loop/crew.ork.ts +12 -7
  238. package/src/crews/main-loop/domain/prompt-assembly.ts +45 -228
  239. package/src/crews/main-loop/domain/prompts.ts +336 -0
  240. package/src/crews/main-loop/domain/turn-chains.ts +10 -9
  241. package/src/crews/project-init/application/detect.ts +5 -4
  242. package/src/crews/project-init/application/messages.ts +15 -0
  243. package/src/crews/project-init/application/prompts.ts +11 -7
  244. package/src/crews/project-init/crew.ork.ts +5 -4
  245. package/src/crews/project-init/domain/existing-files.ts +6 -4
  246. package/src/crews/project-init/domain/messages.ts +13 -0
  247. package/src/crews/project-init/domain/package-map.ts +3 -3
  248. package/src/crews/project-init/domain/prompts.ts +10 -0
  249. package/src/crews/session-compact/application/prompts.ts +5 -0
  250. package/src/crews/session-compact/crew.ork.ts +5 -4
  251. package/src/crews/shared-memory-admit/application/prompts.ts +5 -0
  252. package/src/crews/shared-memory-admit/crew.ork.ts +3 -2
  253. package/src/crews/speech/application/messages.ts +3 -0
  254. package/src/crews/speech/application/prompts.ts +3 -0
  255. package/src/crews/speech/application/run-speech.ts +2 -1
  256. package/src/crews/speech/crew.ork.ts +2 -1
  257. package/src/shared/application/agents/child-agent.ts +11 -7
  258. package/src/shared/application/agents/messages.ts +35 -0
  259. package/src/shared/application/agents/route-agent.ts +115 -0
  260. package/src/shared/application/agents/run-sub-agent.ts +31 -8
  261. package/src/shared/application/compaction/compact-session.ts +19 -14
  262. package/src/shared/application/compaction/messages.ts +20 -0
  263. package/src/shared/application/compaction/prune-context.ts +94 -0
  264. package/src/shared/application/compaction/pruned-llm.ts +35 -0
  265. package/src/shared/application/dev/brief-inventory.ts +6 -4
  266. package/src/shared/application/dev/close-batch.ts +9 -7
  267. package/src/shared/application/dev/find-repo-pack.ts +4 -3
  268. package/src/shared/application/dev/learn-decision.ts +20 -18
  269. package/src/shared/application/dev/load-dev-context.ts +7 -8
  270. package/src/shared/application/dev/measure-access-cost.ts +5 -4
  271. package/src/shared/application/dev/messages.ts +132 -0
  272. package/src/shared/application/dev/phase-timer.ts +54 -0
  273. package/src/shared/application/dev/plan-source.ts +12 -8
  274. package/src/shared/application/dev/preflight.ts +8 -8
  275. package/src/shared/application/dev/prompts.ts +34 -0
  276. package/src/shared/application/dev/question-round.ts +25 -17
  277. package/src/shared/application/dev/resolve-work-folder.ts +4 -3
  278. package/src/shared/application/dev/settle-questions.ts +4 -2
  279. package/src/shared/application/dev/source-review.ts +12 -8
  280. package/src/shared/application/dev/source-step.ts +12 -10
  281. package/src/shared/application/dev/spend.ts +17 -4
  282. package/src/shared/application/dev/step-precedents.ts +2 -1
  283. package/src/shared/application/dev/tool-call-policy.ts +9 -11
  284. package/src/shared/application/dev/tool-callbacks.ts +52 -5
  285. package/src/shared/application/dev/tool-trace-recorder.ts +2 -1
  286. package/src/shared/application/dev/verdict-sources.ts +5 -3
  287. package/src/shared/application/dev/wrapped-tools.ts +4 -2
  288. package/src/shared/application/extra-tools.ts +2 -1
  289. package/src/shared/application/git/batch-worktree.ts +22 -17
  290. package/src/shared/application/git/commit-files.ts +24 -19
  291. package/src/shared/application/git/merge-batch.ts +11 -7
  292. package/src/shared/application/git/messages.ts +75 -0
  293. package/src/shared/application/git/open-pull-request.ts +4 -3
  294. package/src/shared/application/host-context.ts +59 -0
  295. package/src/shared/application/host-layout-store.ts +45 -0
  296. package/src/shared/application/llm-profile.ts +4 -3
  297. package/src/shared/application/messages.ts +14 -0
  298. package/src/shared/application/permission-rules.ts +10 -0
  299. package/src/shared/application/ports/decision.ts +14 -0
  300. package/src/shared/application/ports/human.ts +25 -0
  301. package/src/shared/application/ports/llm.ts +32 -3
  302. package/src/shared/application/ports/memory.ts +1 -1
  303. package/src/shared/application/ports/theme.ts +11 -0
  304. package/src/shared/application/ports.ts +4 -2
  305. package/src/shared/application/session-io.ts +2 -1
  306. package/src/shared/application/shared-memory/admit-entries.ts +16 -14
  307. package/src/shared/application/shared-memory/harvest-after-gaps.ts +5 -8
  308. package/src/shared/application/shared-memory/harvest-mistakes.ts +3 -2
  309. package/src/shared/application/shared-memory/import-agent-memory.ts +9 -7
  310. package/src/shared/application/shared-memory/memory-files.ts +2 -1
  311. package/src/shared/application/shared-memory/memory-settings.ts +2 -1
  312. package/src/shared/application/shared-memory/messages.ts +63 -0
  313. package/src/shared/application/shared-memory/push-candidate.ts +14 -11
  314. package/src/shared/application/shared-memory/recall-precedents.ts +2 -1
  315. package/src/shared/application/skills/messages.ts +4 -0
  316. package/src/shared/application/skills/suggest-skills.ts +102 -0
  317. package/src/shared/application/workflow/messages.ts +8 -0
  318. package/src/shared/application/workflow/workflow-state.ts +7 -6
  319. package/src/shared/domain/agent-policy/behavior-flags.ts +4 -10
  320. package/src/shared/domain/agent-policy/extra-tools.ts +2 -4
  321. package/src/shared/domain/agent-policy/messages.ts +66 -0
  322. package/src/shared/domain/agent-policy/path-rules.ts +299 -0
  323. package/src/shared/domain/agent-policy/permission.ts +20 -18
  324. package/src/shared/domain/agent-policy/prompts.ts +17 -0
  325. package/src/shared/domain/agent-policy/reasoning.ts +59 -0
  326. package/src/shared/domain/agent-policy/rule-sets.ts +18 -14
  327. package/src/shared/domain/agent-policy/tool-access.ts +17 -3
  328. package/src/shared/domain/agent-registry.ts +6 -5
  329. package/src/shared/domain/agents/chain.ts +2 -2
  330. package/src/shared/domain/agents/charter.ts +8 -5
  331. package/src/shared/domain/agents/exclusive.ts +2 -1
  332. package/src/shared/domain/agents/instances.ts +18 -15
  333. package/src/shared/domain/agents/messages.ts +39 -0
  334. package/src/shared/domain/agents/model-route.ts +199 -0
  335. package/src/shared/domain/agents/prompts.ts +20 -0
  336. package/src/shared/domain/code-intel-contract.ts +5 -4
  337. package/src/shared/domain/code-intel-routing.ts +8 -61
  338. package/src/shared/domain/compact-outcome.ts +5 -3
  339. package/src/shared/domain/compaction-thresholds.ts +2 -1
  340. package/src/shared/domain/compaction.ts +22 -113
  341. package/src/shared/domain/config-schema.ts +94 -81
  342. package/src/shared/domain/context-prune.ts +176 -0
  343. package/src/shared/domain/decision/questions.ts +102 -0
  344. package/src/shared/domain/dev/access-cost.ts +19 -15
  345. package/src/shared/domain/dev/batches-concurrency.ts +5 -6
  346. package/src/shared/domain/dev/build-commands.ts +5 -4
  347. package/src/shared/domain/dev/call-guard.ts +29 -28
  348. package/src/shared/domain/dev/carried-text.ts +3 -5
  349. package/src/shared/domain/dev/learn-proposals.ts +5 -4
  350. package/src/shared/domain/dev/learn-state.ts +3 -2
  351. package/src/shared/domain/dev/markers.ts +107 -0
  352. package/src/shared/domain/dev/messages.ts +259 -0
  353. package/src/shared/domain/dev/phase-timing.ts +50 -0
  354. package/src/shared/domain/dev/plan-checks.ts +24 -23
  355. package/src/shared/domain/dev/plan-format.ts +14 -24
  356. package/src/shared/domain/dev/project-files.ts +1 -15
  357. package/src/shared/domain/dev/prompts/brief-blocks.ts +20 -0
  358. package/src/shared/domain/dev/{review-prompt.ts → prompts.ts} +91 -61
  359. package/src/shared/domain/dev/questions.ts +33 -15
  360. package/src/shared/domain/dev/repo-pack.ts +12 -9
  361. package/src/shared/domain/dev/review-answer.ts +40 -17
  362. package/src/shared/domain/dev/review-brief.ts +54 -0
  363. package/src/shared/domain/dev/reviewer-charter.ts +4 -0
  364. package/src/shared/domain/dev/sheet-facts.ts +2 -4
  365. package/src/shared/domain/dev/spec-format.ts +13 -14
  366. package/src/shared/domain/dev/step-budget.ts +4 -2
  367. package/src/shared/domain/dev/step-rules.ts +3 -4
  368. package/src/shared/domain/dev/test-commands.ts +14 -10
  369. package/src/shared/domain/dev/tool-guards.ts +4 -3
  370. package/src/shared/domain/dev/trait-pattern.ts +14 -10
  371. package/src/shared/domain/dev/verdict-format.ts +14 -21
  372. package/src/shared/domain/dev/whitespace.ts +3 -2
  373. package/src/shared/domain/dev/work-folder.ts +4 -3
  374. package/src/shared/domain/dev/yaml-subset.ts +8 -26
  375. package/src/shared/domain/error-text.ts +13 -0
  376. package/src/shared/domain/git/close.ts +5 -4
  377. package/src/shared/domain/git/messages.ts +20 -0
  378. package/src/shared/domain/git/pull-request.ts +5 -5
  379. package/src/shared/domain/host-layout.ts +147 -0
  380. package/src/shared/domain/host-paths.ts +399 -0
  381. package/src/shared/domain/llm-failure.ts +35 -7
  382. package/src/shared/domain/llm-profile.ts +22 -3
  383. package/src/shared/domain/marked-message.ts +1 -5
  384. package/src/shared/domain/markers.ts +30 -0
  385. package/src/shared/domain/messages.ts +291 -0
  386. package/src/shared/domain/model-catalog.ts +2 -9
  387. package/src/shared/domain/permission-modes.ts +4 -8
  388. package/src/shared/domain/prelude.ts +2 -2
  389. package/src/shared/domain/project-manifests.ts +3 -2
  390. package/src/shared/domain/prompts.ts +233 -0
  391. package/src/shared/domain/search-routing.ts +3 -11
  392. package/src/shared/domain/secret-patterns.ts +3 -2
  393. package/src/shared/domain/session-keys.ts +7 -0
  394. package/src/shared/domain/session-start.ts +3 -2
  395. package/src/shared/domain/shared-memory/agent-memory-import.ts +4 -2
  396. package/src/shared/domain/shared-memory/candidates.ts +3 -4
  397. package/src/shared/domain/shared-memory/entry.ts +26 -20
  398. package/src/shared/domain/shared-memory/front-matter.ts +17 -13
  399. package/src/shared/domain/shared-memory/gate.ts +4 -3
  400. package/src/shared/domain/shared-memory/harvest.ts +9 -6
  401. package/src/shared/domain/shared-memory/layout.ts +11 -8
  402. package/src/shared/domain/shared-memory/markers.ts +9 -0
  403. package/src/shared/domain/shared-memory/messages.ts +66 -0
  404. package/src/shared/domain/shared-memory/precedents-block.ts +4 -15
  405. package/src/shared/domain/shared-memory/prompts.ts +28 -0
  406. package/src/shared/domain/shared-memory/refused.ts +3 -3
  407. package/src/shared/domain/skills/prompts.ts +4 -0
  408. package/src/shared/domain/skills/shortlist.ts +149 -0
  409. package/src/shared/domain/snip-turns.ts +2 -14
  410. package/src/shared/domain/speech.ts +2 -1
  411. package/src/shared/domain/tool-trace.ts +5 -7
  412. package/src/shared/domain/verifiers.ts +7 -11
  413. package/src/shared/domain/vfs.ts +8 -1
  414. package/src/shared/domain/workflow/prompts.ts +15 -0
  415. package/src/shared/domain/workflow/state-file.ts +14 -12
  416. package/src/shared/infrastructure/globals.ts +7 -2
  417. package/src/shared/infrastructure/orkeon/child-agents.ts +11 -16
  418. package/src/shared/infrastructure/orkeon/chooser.ts +32 -0
  419. package/src/shared/infrastructure/orkeon/decision-model.ts +31 -0
  420. package/src/shared/infrastructure/orkeon/dev-deps.ts +21 -14
  421. package/src/shared/infrastructure/orkeon/files.ts +24 -6
  422. package/src/shared/infrastructure/orkeon/github-pull-requests.ts +3 -2
  423. package/src/shared/infrastructure/orkeon/host-context.ts +36 -0
  424. package/src/shared/infrastructure/orkeon/human-input.ts +1 -5
  425. package/src/shared/infrastructure/orkeon/llm-profile.ts +36 -16
  426. package/src/shared/infrastructure/orkeon/llm.ts +85 -30
  427. package/src/shared/infrastructure/orkeon/markers.ts +6 -0
  428. package/src/shared/infrastructure/orkeon/memory-store.ts +1 -1
  429. package/src/shared/infrastructure/orkeon/memory-tools.ts +18 -20
  430. package/src/shared/infrastructure/orkeon/messages.ts +15 -0
  431. package/src/shared/infrastructure/orkeon/prompts.ts +47 -0
  432. package/src/shared/infrastructure/orkeon/reasoning.ts +40 -0
  433. package/src/shared/infrastructure/orkeon/script-tools.ts +14 -19
  434. package/src/shared/infrastructure/orkeon/session-store.ts +7 -51
  435. package/src/shared/infrastructure/orkeon/shell-jobs.ts +13 -7
  436. package/src/shared/infrastructure/orkeon/shell.ts +13 -5
  437. package/src/shared/infrastructure/orkeon/tool-catalogue.ts +3 -2
  438. package/src/shared/infrastructure/orkeon/wiring.ts +68 -12
  439. package/src/crews/dev-verify/application/auditor-prompt.ts +0 -323
  440. package/src/shared/domain/session-summary.ts +0 -13
@@ -23,15 +23,16 @@ import {
23
23
  } from "../../shared/infrastructure/orkeon/wiring.ts";
24
24
  import { readMemorySettings } from "../../shared/application/shared-memory/memory-settings.ts";
25
25
  import { admitEntries, admitReport, admittedCandidates } from "../../shared/application/shared-memory/admit-entries.ts";
26
+ import { ADMITTER_GOAL, ADMITTER_ROLE } from "./application/prompts.ts";
26
27
 
27
28
  const ports = { files: orkeonFiles(), shell: orkeonShell(), config: orkeonConfigStore(), memory: orkeonSharedMemory() };
28
29
 
29
30
  const admitter = orkeonAgent()
30
31
  .name("memory-admitter")
31
- .role("Shared memory keeper")
32
+ .role(ADMITTER_ROLE)
32
33
  // NO tools on purpose: every write is code's, decided by the operator in /memory-admit.
33
34
  .tools([])
34
- .goal("Apply the admissions the operator confirmed, then re-index the shared memory.")
35
+ .goal(ADMITTER_GOAL)
35
36
  .body(async () => {
36
37
  const settings = await readMemorySettings(ports);
37
38
  const outcome = await admitEntries({ ...ports, clock: orkeonClock() }, settings, { admit: admittedCandidates(inputs()), refuse: [] });
@@ -0,0 +1,3 @@
1
+ // The text the operator reads from the speech crew.
2
+
3
+ export const NO_TOOL_TO_CALL = "no tool to call: this crew is started by /transcribe, /voice or /say";
@@ -0,0 +1,3 @@
1
+ // The text the speech crew gives its agent.
2
+
3
+ export const SPEAKER_GOAL = "Make the call to the speech server the command names and return its text.";
@@ -6,6 +6,7 @@
6
6
  // which the command prints.
7
7
  import type { Logger, ToolCatalogue } from "../../../shared/application/ports.ts";
8
8
  import { nothingReturned, parsePrelude, toolFailure } from "../../../shared/domain/prelude.ts";
9
+ import { NO_TOOL_TO_CALL } from "./messages.ts";
9
10
 
10
11
  /** The ports of the call. */
11
12
  export interface SpeechDeps {
@@ -16,7 +17,7 @@ export interface SpeechDeps {
16
17
  /** Make the call the input names and answer its text; a failed call throws the tool's message. */
17
18
  export async function runSpeech(input: unknown, deps: SpeechDeps): Promise<string> {
18
19
  const call = parsePrelude(input);
19
- if (call === null) throw new Error("no tool to call: this crew is started by /transcribe, /voice or /say");
20
+ if (call === null) throw new Error(NO_TOOL_TO_CALL);
20
21
  deps.log.info(`${call.label}: ${call.tool}`);
21
22
  const outcome = await deps.tools.callText(call.tool, call.args);
22
23
  if (!outcome.ok) throw toolFailure(call.tool, outcome.failure);
@@ -15,6 +15,7 @@
15
15
  import { CrewBuilder, publishCrew, inputs } from "../../shared/infrastructure/globals.ts";
16
16
  import { orkeonAgent, orkeonToolCalls } from "../../shared/infrastructure/orkeon/wiring.ts";
17
17
  import { runSpeech } from "./application/run-speech.ts";
18
+ import { SPEAKER_GOAL } from "./application/prompts.ts";
18
19
 
19
20
  const tools = orkeonToolCalls();
20
21
 
@@ -24,7 +25,7 @@ const speaker = orkeonAgent()
24
25
  // NO tools on purpose: the call below is the command's, made through the tools
25
26
  // namespace, not offered to a model.
26
27
  .tools([])
27
- .goal("Make the call to the speech server the command names and return its text.")
28
+ .goal(SPEAKER_GOAL)
28
29
  .body(async (_input: any, ctx: any) => await runSpeech(inputs(), { tools, log: ctx.log }))
29
30
  .build();
30
31
 
@@ -9,6 +9,10 @@
9
9
  import type { ActRequest, ChildRuntime, Logger, SessionStore } from "../ports.ts";
10
10
  import { INSTANCE_STATES, SNAPSHOT_HEARTBEAT_MS, parseRequest, requestKey, snapshotKey } from "../../domain/agents/instances.ts";
11
11
  import type { InstanceRecord, InstanceState, RunSnapshot } from "../../domain/agents/instances.ts";
12
+ import {
13
+ CHILD_ENDED_WITHOUT_REPLY, CHILD_FAILED, STOPPED_BY_TASKS_STOP, instancesNotWritten, startedInBackground, tasksStopLine,
14
+ waitReturnedAtOnce,
15
+ } from "./messages.ts";
12
16
 
13
17
  type StateBag = Pick<SessionStore, "readState" | "writeState">;
14
18
 
@@ -48,7 +52,7 @@ export function readChildOutcome(raw: unknown): ChildOutcome | undefined {
48
52
  const v = raw as Record<string, unknown> | null | undefined;
49
53
  if (v === null || typeof v !== "object") return undefined;
50
54
  if (v.ok === true && typeof v.reply === "string") return { ok: true, reply: v.reply };
51
- if (v.ok === false) return { ok: false, error: typeof v.error === "string" ? v.error : "the child failed" };
55
+ if (v.ok === false) return { ok: false, error: typeof v.error === "string" ? v.error : CHILD_FAILED };
52
56
  return undefined;
53
57
  }
54
58
 
@@ -97,7 +101,7 @@ export function createChildBoard(deps: BoardDeps, run: { crew: string; step: str
97
101
  written = text;
98
102
  writtenAt = at;
99
103
  } catch (error) {
100
- if (!warned) deps.log.warn(`${run.crew}: the agent instances could not be written for /tasks: ${firstLine(error)}`);
104
+ if (!warned) deps.log.warn(instancesNotWritten(run.crew, firstLine(error)));
101
105
  warned = true;
102
106
  }
103
107
  }
@@ -119,7 +123,7 @@ export function createChildBoard(deps: BoardDeps, run: { crew: string; step: str
119
123
  // Ids restart at a1 in every run: a stop meant for another run is dropped, never served here.
120
124
  if (request.run !== startedAt) return;
121
125
  record.stopRequested = runtime.stop(record.id) || undefined;
122
- deps.log.info(`${run.crew}: /tasks stop ${record.id} (${record.agent})${record.stopRequested ? "" : ": it was no longer running"}`);
126
+ deps.log.info(tasksStopLine(run.crew, record.id, record.agent, record.stopRequested));
123
127
  }
124
128
 
125
129
  return {
@@ -197,7 +201,7 @@ export async function runChildAct(deps: ChildDeps, call: ChildCall): Promise<str
197
201
  };
198
202
  await resolveId();
199
203
  board.add(record);
200
- log.info(`${call.agent} ${record.id || "?"} started in the background: ${call.task}`);
204
+ log.info(startedInBackground(call.agent, record.id || "?", call.task));
201
205
  let early = 0;
202
206
  try {
203
207
  for (;;) {
@@ -208,7 +212,7 @@ export async function runChildAct(deps: ChildDeps, call: ChildCall): Promise<str
208
212
  if (stopped && (outcome !== undefined || (row !== undefined && row.state !== "running"))) {
209
213
  // A stopped child's act rejects, and its body leaves that failure: the stop is what happened.
210
214
  record.state = "stopped";
211
- record.error = "stopped by /tasks stop";
215
+ record.error = STOPPED_BY_TASKS_STOP;
212
216
  break;
213
217
  }
214
218
  if (outcome !== undefined) {
@@ -219,7 +223,7 @@ export async function runChildAct(deps: ChildDeps, call: ChildCall): Promise<str
219
223
  }
220
224
  if (row !== undefined && row.state !== "running") {
221
225
  record.state = asState(row.state);
222
- record.error = "the child ended without leaving a reply";
226
+ record.error = CHILD_ENDED_WITHOUT_REPLY;
223
227
  break;
224
228
  }
225
229
  await board.serve(runtime);
@@ -230,7 +234,7 @@ export async function runChildAct(deps: ChildDeps, call: ChildCall): Promise<str
230
234
  early += 1;
231
235
  if (early >= MAX_EARLY_WAKES) {
232
236
  record.state = "failed";
233
- record.error = `the wait for ${call.agent} returned at once ${early} times in a row`;
237
+ record.error = waitReturnedAtOnce(call.agent, early);
234
238
  runtime.stop(record.id);
235
239
  break;
236
240
  }
@@ -0,0 +1,35 @@
1
+ // The text the agent services report: the lines of a background child and the problems of a sub-agent's answer.
2
+
3
+ // child-agent.ts
4
+ export const CHILD_FAILED = "the child failed";
5
+ export const instancesNotWritten = (crew: string, reason: string): string =>
6
+ `${crew}: the agent instances could not be written for /tasks: ${reason}`;
7
+ export const tasksStopLine = (crew: string, id: string, agent: string, stopRequested: boolean | undefined): string =>
8
+ `${crew}: /tasks stop ${id} (${agent})${stopRequested ? "" : ": it was no longer running"}`;
9
+ export const startedInBackground = (agent: string, id: string, task: string): string =>
10
+ `${agent} ${id} started in the background: ${task}`;
11
+ export const STOPPED_BY_TASKS_STOP = "stopped by /tasks stop";
12
+ export const CHILD_ENDED_WITHOUT_REPLY = "the child ended without leaving a reply";
13
+ export const waitReturnedAtOnce = (agent: string, early: number): string =>
14
+ `the wait for ${agent} returned at once ${early} times in a row`;
15
+
16
+ // run-sub-agent.ts
17
+ /** The log line of an answer refused and asked again: what was wrong with it. */
18
+ export const answerAskedAgain = (who: string, problems: readonly string[]): string =>
19
+ `${who}: answer refused, asked again: ${problems.join("; ")}`;
20
+ export const answerDidNotParse = (reason: string): string => `the answer did not parse: ${reason}`;
21
+ export const briefTooLong = (length: number, max: number): string => `the brief is ${length} characters, over ${max}`;
22
+ export const ROUTE_WITHOUT_DECISION_MODEL =
23
+ "route.agents is on and the host has no decision model: the session's profile stands (set Orkeon:Decision:Provider, or Orkeon:TypeSafe)";
24
+ export const routeKeepsProfile = (profile: string, ladder: string): string =>
25
+ `route.agents is on and the session's llm.profile '${profile}' is not on the ladder (${ladder}): it stands`;
26
+ export const routedLine = (crew: string, profile: string, why: string): string => `route: ${crew} on '${profile}' (${why})`;
27
+ export const ROUTE_WHY = {
28
+ model: "the decision model's pick",
29
+ floor: "raised by a rule of .orkeon/route-rules.json",
30
+ ceiling: "held at the session's profile",
31
+ "low-confidence": "the pick was not sure enough, the session's profile stands",
32
+ "no-answer": "the decision model did not answer, the session's profile stands",
33
+ } as const;
34
+ export const pickedWith = (picked: string, confidence: number): string => `picked '${picked}' at ${confidence.toFixed(2)}`;
35
+ export const HOST_DEFAULT_MODEL = "the host's default model";
@@ -0,0 +1,115 @@
1
+ // The profile a crew is launched on (ADR 0027): with `route.agents` on and a decision model on the host, the model
2
+ // reads the command and picks a rung of `route.ladder`; the project's rules raise a floor and the session's profile
3
+ // is the ceiling (shared/domain/agents/model-route.ts). It fails open at every step: the setting off or unreadable,
4
+ // no decision model, a session on a profile outside the ladder, a model that does not answer, throws or is not sure
5
+ // leave the session's profile as it is. A routed launch also carries the session's profile, which the crew falls
6
+ // back on when the host declares no profile of the rung's name (orkeon/llm-profile.ts). Each routed launch is logged
7
+ // and kept for `/route why`. The act of a sub-agent inside a crew (a reviewer, the auditor) is routed by the same
8
+ // decision, under its charter's name (actRoute): it is moved only when the model decided, and off the crew's profile.
9
+ import type { DecisionModel, Files, Logger, SessionStore } from "../ports.ts";
10
+ import type { ConfigStore } from "../config-store.ts";
11
+ import { WORKSPACE } from "../../domain/vfs.ts";
12
+ import { ROUTE_RECENT_STATE_KEY } from "../../domain/session-keys.ts";
13
+ import type { DecisionAnswers } from "../../domain/decision/questions.ts";
14
+ import type { RouteChoice, RouteRules } from "../../domain/agents/model-route.ts";
15
+ import {
16
+ NO_ROUTE_RULES, ROUTE_AGENTS_CONFIG_KEY, ROUTE_LADDER_CONFIG_KEY, ROUTE_RULES_FILE, ladderOf, parseRecords, parseRouteRules,
17
+ routable, routeDecided, routeFloor, routeOf, routeOn, routeQuestions, routeState, withRecord,
18
+ } from "../../domain/agents/model-route.ts";
19
+ import {
20
+ HOST_DEFAULT_MODEL, ROUTE_WHY, ROUTE_WITHOUT_DECISION_MODEL, pickedWith, routeKeepsProfile, routedLine,
21
+ } from "./messages.ts";
22
+
23
+ export interface RouteDeps {
24
+ config: Pick<ConfigStore, "readValue">;
25
+ decision: DecisionModel;
26
+ files: Pick<Files, "read">;
27
+ session: Pick<SessionStore, "readState" | "writeState">;
28
+ log: Pick<Logger, "info" | "warn">;
29
+ }
30
+
31
+ /** What is routed: the crew, and the command that launches it, as typed. */
32
+ export interface RouteTask {
33
+ crew: string;
34
+ brief: string;
35
+ }
36
+
37
+ async function setting(config: RouteDeps["config"], key: string): Promise<unknown> {
38
+ try {
39
+ return (await config.readValue(key)).value;
40
+ } catch {
41
+ return undefined;
42
+ }
43
+ }
44
+
45
+ /** The project's floors; none when the file is absent or unreadable. */
46
+ async function rulesOf(files: RouteDeps["files"]): Promise<RouteRules> {
47
+ try {
48
+ return parseRouteRules(await files.read(`${WORKSPACE}/${ROUTE_RULES_FILE}`));
49
+ } catch {
50
+ return NO_ROUTE_RULES;
51
+ }
52
+ }
53
+
54
+ /** Why a choice stands, with the model's pick when it made one. */
55
+ export function routeWhy(choice: Pick<RouteChoice, "reason" | "picked" | "confidence">): string {
56
+ const why = ROUTE_WHY[choice.reason];
57
+ return choice.picked === undefined || choice.confidence === undefined ? why : `${why}; ${pickedWith(choice.picked, choice.confidence)}`;
58
+ }
59
+
60
+ async function remember(session: RouteDeps["session"], crew: string, choice: RouteChoice): Promise<void> {
61
+ try {
62
+ const records = withRecord(parseRecords(await session.readState(ROUTE_RECENT_STATE_KEY)), { crew, ...choice });
63
+ await session.writeState(ROUTE_RECENT_STATE_KEY, JSON.stringify(records));
64
+ } catch { /* the record is a convenience: the launch goes on without it */ }
65
+ }
66
+
67
+ /** The choice made for `task`, logged and kept; null when nothing was asked (the setting off, no decision model, a
68
+ * session's profile outside the ladder). */
69
+ async function choose(deps: RouteDeps, task: RouteTask, sessionProfile: string | null): Promise<RouteChoice | null> {
70
+ if (!routeOn(await setting(deps.config, ROUTE_AGENTS_CONFIG_KEY))) return null;
71
+ if (!deps.decision.available()) {
72
+ deps.log.warn(ROUTE_WITHOUT_DECISION_MODEL);
73
+ return null;
74
+ }
75
+ const ladder = ladderOf(await setting(deps.config, ROUTE_LADDER_CONFIG_KEY));
76
+ if (sessionProfile !== null && !routable(sessionProfile, ladder)) {
77
+ deps.log.info(routeKeepsProfile(sessionProfile, ladder.join(",")));
78
+ return null;
79
+ }
80
+ const floor = routeFloor(await rulesOf(deps.files), task.crew, task.brief, ladder);
81
+ let answers: DecisionAnswers | null = null;
82
+ try {
83
+ answers = await deps.decision.ask(routeState(task.crew, task.brief), routeQuestions(ladder));
84
+ } catch { /* a decision model that throws is one that did not answer */ }
85
+ const choice = routeOf(answers, ladder, sessionProfile, floor);
86
+ deps.log.info(routedLine(task.crew, choice.profile ?? HOST_DEFAULT_MODEL, routeWhy(choice)));
87
+ await remember(deps.session, task.crew, choice);
88
+ return choice;
89
+ }
90
+
91
+ /** The profile `task.crew` is launched on, the session being on `sessionProfile` (null: the host's default model). */
92
+ export async function routeAgent(deps: RouteDeps, task: RouteTask, sessionProfile: string | null): Promise<string | null> {
93
+ const choice = await choose(deps, task, sessionProfile);
94
+ return choice === null ? sessionProfile : choice.profile;
95
+ }
96
+
97
+ /** The profile one sub-agent act is moved to; null leaves the act on the profile the crew's agent runs on. */
98
+ export type ActRoute = (task: RouteTask) => Promise<string | null>;
99
+
100
+ /** The profiles a crew's acts are routed between: the session's (the ceiling) and the one the crew runs on. */
101
+ export interface ActProfiles {
102
+ session: string | null;
103
+ crew: string | null;
104
+ }
105
+
106
+ /** The route of a crew's sub-agent acts: the launch's decision, with the session's profile as the ceiling. It moves
107
+ * an act only on a decision (routeDecided): nothing asked, no answer or an unsure pick leave the act where the crew
108
+ * runs, as does an answer that is the crew's own profile. */
109
+ export function actRoute(deps: RouteDeps, profiles: ActProfiles): ActRoute {
110
+ return async (task) => {
111
+ const choice = await choose(deps, task, profiles.session);
112
+ if (choice === null || !routeDecided(choice.reason) || choice.profile === profiles.crew) return null;
113
+ return choice.profile;
114
+ };
115
+ }
@@ -4,12 +4,17 @@
4
4
  // over the same reply, with the problems found; no second act is made. A call
5
5
  // that throws a cancellation (the host cancelled the run, /tasks stop stopped the
6
6
  // child) is `cancelled`; a step budget spent during the extraction is the model's
7
- // failure, not an answer that did not parse.
7
+ // failure, not an answer that did not parse. A route, when given, is asked once before the act for the profile it
8
+ // runs on (route-agent.ts actRoute): null, or a route that throws, leaves the act on the agent's own profile; the
9
+ // extractions are never routed.
8
10
 
9
- import type { Llm } from "../ports.ts";
11
+ import type { Llm, Logger } from "../ports.ts";
12
+ import type { ActRoute } from "./route-agent.ts";
10
13
  import { MAX_BRIEF_CHARS, charterProblems } from "../../domain/agents/charter.ts";
11
14
  import type { Charter, Checked } from "../../domain/agents/charter.ts";
12
15
  import { readBudgetExhausted } from "../../domain/dev/step-budget.ts";
16
+ import { answerAskedAgain, answerDidNotParse, briefTooLong } from "./messages.ts";
17
+ import { errorText } from "../../domain/error-text.ts";
13
18
 
14
19
  export interface SubAgentCall<T> {
15
20
  charter: Charter;
@@ -24,6 +29,8 @@ export interface SubAgentCall<T> {
24
29
  /** The extraction prompt over the act's final reply; `problems` is empty on the first try. */
25
30
  answerPrompt: (reply: string, problems: readonly string[]) => string;
26
31
  check: (value: unknown) => Checked<T>;
32
+ /** The check of the second try, when it may accept what the first refused; `check` when absent. */
33
+ lastCheck?: (value: unknown) => Checked<T>;
27
34
  }
28
35
 
29
36
  export type SubAgentFailure = "invalid-charter" | "brief-too-long" | "model-failed" | "cancelled" | "unparsable";
@@ -52,6 +59,7 @@ type Answer<T> = Checked<T> | { ok: false; reason: "cancelled" | "model-failed";
52
59
 
53
60
  async function tryAnswer<T>(
54
61
  llm: Pick<Llm, "extract">, call: SubAgentCall<T>, reply: string, problems: readonly string[],
62
+ check: (value: unknown) => Checked<T>,
55
63
  ): Promise<Answer<T>> {
56
64
  let value: unknown;
57
65
  try {
@@ -59,21 +67,34 @@ async function tryAnswer<T>(
59
67
  } catch (error) {
60
68
  const reason = failureOf(error);
61
69
  if (reason === "cancelled" || readBudgetExhausted(error) !== null) return { ok: false, reason, problems: [firstLine(error)] };
62
- return { ok: false, problems: [`the answer did not parse: ${firstLine(error)}`] };
70
+ return { ok: false, problems: [answerDidNotParse(errorText(error))] };
63
71
  }
64
- return call.check(value);
72
+ return check(value);
65
73
  }
66
74
 
67
- export async function runSubAgent<T>(llm: Pick<Llm, "act" | "extract">, call: SubAgentCall<T>): Promise<SubAgentOutcome<T>> {
75
+ /** The profile the act of `call` is moved to: none without a route, when it answers null, or when it throws. */
76
+ async function routedProfile(route: ActRoute | undefined, crew: string, brief: string): Promise<string | null> {
77
+ if (route === undefined) return null;
78
+ try {
79
+ return await route({ crew, brief });
80
+ } catch {
81
+ return null;
82
+ }
83
+ }
84
+
85
+ export async function runSubAgent<T>(
86
+ llm: Pick<Llm, "act" | "extract">, call: SubAgentCall<T>, route?: ActRoute, log?: Pick<Logger, "info">,
87
+ ): Promise<SubAgentOutcome<T>> {
68
88
  const { charter, brief } = call;
69
89
  const invalid = charterProblems(charter);
70
90
  if (invalid.length > 0) return { ok: false, reason: "invalid-charter", problems: invalid, reply: "" };
71
91
  if (brief.length > MAX_BRIEF_CHARS) {
72
92
  return {
73
93
  ok: false, reason: "brief-too-long", reply: "",
74
- problems: [`the brief is ${brief.length} characters, over ${MAX_BRIEF_CHARS}`],
94
+ problems: [briefTooLong(brief.length, MAX_BRIEF_CHARS)],
75
95
  };
76
96
  }
97
+ const profile = await routedProfile(route, charter.name, brief);
77
98
  let reply: string;
78
99
  try {
79
100
  reply = await llm.act(brief, {
@@ -81,15 +102,17 @@ export async function runSubAgent<T>(llm: Pick<Llm, "act" | "extract">, call: Su
81
102
  permissionMode: charter.mode,
82
103
  maxIterations: charter.maxIterations,
83
104
  ...(charter.model === undefined ? {} : { model: charter.model }),
105
+ ...(profile === null ? {} : { profile }),
84
106
  ...(call.tools === undefined ? {} : { tools: [...call.tools] }),
85
107
  });
86
108
  } catch (error) {
87
109
  return { ok: false, reason: failureOf(error), problems: [firstLine(error)], reply: "" };
88
110
  }
89
- const first = await tryAnswer(llm, call, reply, []);
111
+ const first = await tryAnswer(llm, call, reply, [], call.check);
90
112
  if (first.ok) return { ok: true, value: first.value, reply, tries: 1 };
91
113
  if ("reason" in first) return { ok: false, reason: first.reason, problems: first.problems, reply };
92
- const second = await tryAnswer(llm, call, reply, first.problems);
114
+ log?.info(answerAskedAgain(charter.name, first.problems));
115
+ const second = await tryAnswer(llm, call, reply, first.problems, call.lastCheck ?? call.check);
93
116
  if (second.ok) return { ok: true, value: second.value, reply, tries: 2 };
94
117
  if ("reason" in second) return { ok: false, reason: second.reason, problems: second.problems, reply };
95
118
  return { ok: false, reason: "unparsable", problems: second.problems, reply };
@@ -36,6 +36,11 @@ import { isoDay } from "../../domain/iso-day.ts";
36
36
  import { pendingRequestLength } from "../../domain/marked-message.ts";
37
37
  import { runtimeTurnsToKeep } from "../../domain/snip-turns.ts";
38
38
  import type { SessionMsg } from "../../domain/types.ts";
39
+ import { BUFFER_TOO_SMALL } from "../../domain/markers.ts";
40
+ import {
41
+ PHASE_ATTACHED_SKILLS, PHASE_RECENT_FILES, PHASE_SUMMARY, SUMMARY_CAME_BACK_EMPTY, bufferWasSnipped, couldNotBeWritten,
42
+ filesReinjected, noStateFileWritten, skillsReinjected, snipNoticeNotWritten, snippedLine, stateNotWritten, stateWrittenTo,
43
+ } from "./messages.ts";
39
44
 
40
45
  /** The ports the pipeline runs on. */
41
46
  export interface CompactDeps {
@@ -82,7 +87,7 @@ export async function compactSession(
82
87
  // git alone. /compact (force) refreshes it whatever the buffer holds.
83
88
  if (force) state = await writeState(deps, "manual");
84
89
  if (raw.stored.length <= MIN_COMPACTABLE)
85
- return withState({ status: "skipped", reason: "buffer too small" });
90
+ return withState({ status: "skipped", reason: BUFFER_TOO_SMALL });
86
91
  const { used } = gated ?? await session.readBudget();
87
92
  if (!force) state = await writeState(deps, "auto");
88
93
 
@@ -96,29 +101,29 @@ export async function compactSession(
96
101
  const memories = await extractMemories(llm, memory, transcript, isoDay(deps.clock()));
97
102
 
98
103
  // 2. The summary, from the buffer as it stands: the prompt clips the transcript head and tail.
99
- await progress.report(compactPhase(2, "synthesizing the summary"));
104
+ await progress.report(compactPhase(2, PHASE_SUMMARY));
100
105
  const summary = await summarise(llm, transcript, opts.focus);
101
106
  if ("failure" in summary) return withState(await snipFallback(deps, raw.messages, summary.failure));
102
107
  const buffer = buildCompactedBuffer(raw.stored[0], summary.text);
103
108
  if (memories.length > 0) buffer.push(buildMemoryRecapMessage(memories));
104
109
  // 3. Re-inject the recently-touched files so the agent keeps its working
105
110
  // context (paths harvested from the buffer before the compaction).
106
- await progress.report(compactPhase(3, "restoring recent files"));
111
+ await progress.report(compactPhase(3, PHASE_RECENT_FILES));
107
112
  const restored = await restoreRecentFiles(files, raw.messages);
108
113
  if (restored.length > 0) {
109
114
  buffer.push(...restored);
110
- note(log, `post-compaction restore: ${restored.length} file(s) re-injected`);
115
+ note(log, filesReinjected(restored.length));
111
116
  }
112
117
  // 4. Re-inject the ATTACHED SKILLS under their own budget. Files came
113
118
  // back because the agent was touching them; skills come back because the
114
119
  // operator attached them and expects them to outlive every compaction —
115
120
  // which is exactly what "the agent forgot the rules" looks like when they
116
121
  // do not.
117
- await progress.report(compactPhase(4, "restoring attached skills"));
122
+ await progress.report(compactPhase(4, PHASE_ATTACHED_SKILLS));
118
123
  const skills = await restoreAttachedSkills(session, files);
119
124
  if (skills.length > 0) {
120
125
  buffer.push(...skills);
121
- note(log, `post-compaction restore: ${skills.length} skill(s) re-injected`);
126
+ note(log, skillsReinjected(skills.length));
122
127
  }
123
128
  // 5. The pointer to the state file written at step 0, last: what to read first.
124
129
  if (state !== null && "path" in state) buffer.push(buildRestoredStateMessage(`${WORKSPACE}/${state.path}`, state.firstOpen));
@@ -143,7 +148,7 @@ async function summarise(llm: Llm, transcript: string, focus: string | undefined
143
148
  const prompt = buildSummaryPrompt(transcript, focus);
144
149
  const reply = await llm.complete(prompt.user, { system: prompt.system });
145
150
  const text = extractSummary(String(reply ?? ""));
146
- return text.length === 0 ? { failure: "the summary came back empty" } : { text };
151
+ return text.length === 0 ? { failure: SUMMARY_CAME_BACK_EMPTY } : { text };
147
152
  } catch (e: any) {
148
153
  return { failure: String(e?.message ?? e) };
149
154
  }
@@ -166,9 +171,9 @@ async function snipFallback(deps: CompactDeps, messages: readonly SessionMsg[],
166
171
  try {
167
172
  await leaveSnipNotice(deps.session);
168
173
  } catch (e: any) {
169
- note(deps.log, `the notice of the snip could not be written: ${String(e?.message ?? e).split("\n")[0]}`);
174
+ note(deps.log, snipNoticeNotWritten(String(e?.message ?? e).split("\n")[0]));
170
175
  }
171
- note(deps.log, `compaction path: no summary (${reason}), the buffer was snipped`);
176
+ note(deps.log, bufferWasSnipped(reason));
172
177
  return { status: "failed", reason, fallback: "snip" };
173
178
  }
174
179
 
@@ -187,13 +192,13 @@ async function writeState(deps: CompactDeps, trigger: "manual" | "auto"): Promis
187
192
  try {
188
193
  const state = await deps.workflow(trigger);
189
194
  if (state !== null) {
190
- note(deps.log, "path" in state ? `state of the batch in progress written to ${state.path}` : `no state file written: ${state.skipped}`);
195
+ note(deps.log, "path" in state ? stateWrittenTo(state.path) : noStateFileWritten(state.skipped));
191
196
  }
192
197
  return state;
193
198
  } catch (e: any) {
194
199
  const reason = String(e?.message ?? e).split("\n")[0];
195
- try { deps.log.warn(`the state of the batch in progress could not be written: ${reason}`); } catch { /* best-effort */ }
196
- return { skipped: `it could not be written (${reason})` };
200
+ try { deps.log.warn(stateNotWritten(reason)); } catch { /* best-effort */ }
201
+ return { skipped: couldNotBeWritten(reason) };
197
202
  }
198
203
  }
199
204
 
@@ -205,10 +210,10 @@ export async function snipBuffer(
205
210
  ): Promise<string> {
206
211
  const { messages } = await deps.session.readMessages();
207
212
  const keep = runtimeTurnsToKeep(messages, turns);
208
- if (keep === null) return `snipped: 0 removed, ${messages.length} kept.`;
213
+ if (keep === null) return snippedLine(0, messages.length);
209
214
  const { removed, retained } = await deps.session.snip(keep);
210
215
  if (removed > 0) await leaveSnipNotice(deps.session);
211
- return `snipped: ${removed} removed, ${retained} kept.`;
216
+ return snippedLine(removed, retained);
212
217
  }
213
218
 
214
219
  /** The `compaction.trigger` setting as a token count; undefined when unset, invalid
@@ -0,0 +1,20 @@
1
+ // The text the compaction reports: its progress phases, its log lines and the outcome of a snip.
2
+
3
+ export const PHASE_SUMMARY = "synthesizing the summary";
4
+ export const PHASE_RECENT_FILES = "restoring recent files";
5
+ export const PHASE_ATTACHED_SKILLS = "restoring attached skills";
6
+ export const filesReinjected = (count: number): string => `post-compaction restore: ${count} file(s) re-injected`;
7
+ export const skillsReinjected = (count: number): string => `post-compaction restore: ${count} skill(s) re-injected`;
8
+ export const SUMMARY_CAME_BACK_EMPTY = "the summary came back empty";
9
+ export const snipNoticeNotWritten = (reason: string): string => `the notice of the snip could not be written: ${reason}`;
10
+ export const bufferWasSnipped = (reason: string): string => `compaction path: no summary (${reason}), the buffer was snipped`;
11
+ export const stateWrittenTo = (path: string): string => `state of the batch in progress written to ${path}`;
12
+ export const noStateFileWritten = (skipped: string): string => `no state file written: ${skipped}`;
13
+ export const stateNotWritten = (reason: string): string => `the state of the batch in progress could not be written: ${reason}`;
14
+ export const couldNotBeWritten = (reason: string): string => `it could not be written (${reason})`;
15
+ export const snippedLine = (removed: number, kept: number): string => `snipped: ${removed} removed, ${kept} kept.`;
16
+ export const PRUNE_WITHOUT_DECISION_MODEL =
17
+ "compaction.prune is on and the host has no decision model: nothing is pruned (set Orkeon:Decision:Provider, or Orkeon:TypeSafe)";
18
+ export const PRUNE_DECISION_FAILED = "context pruning: the decision model did not answer, nothing more is pruned in this act";
19
+ export const prunedLine = (judged: number, dropped: number, cut: number, freedTokens: number): string =>
20
+ `context pruning: ${judged} tool result(s) judged, ${dropped} removed, ${cut} cut, about ${freedTokens} tokens freed`;
@@ -0,0 +1,94 @@
1
+ // The pruning of a turn's tool loop, bound for one act (ADR 0027): with `compaction.prune` on and a decision model on
2
+ // the host, the act carries a callback the runtime asks once its loop passes 40 % of the window. The callback keeps
3
+ // the small results without asking, has the decision model judge the others by batches, oldest first, and answers
4
+ // the runtime's verdicts; a result judged needed is left unanswered and judged again once it has aged. It fails
5
+ // open at every step: a setting that cannot be read, no decision model, a model that does not answer leave the
6
+ // loop as it is, and a model that failed once is not asked again in that act. One binding serves one act: the main
7
+ // loop binds it itself, the dev crews get it from their Llm (pruned-llm.ts).
8
+ import type { ActRequest, DecisionModel, Logger, SessionStore } from "../ports.ts";
9
+ import type { ConfigStore } from "../config-store.ts";
10
+ import { DEFAULT_CONTEXT_WINDOW } from "../../domain/compaction-thresholds.ts";
11
+ import type { ContextPressure, PressureCall, PruneVerdict } from "../../domain/context-prune.ts";
12
+ import {
13
+ PRUNE_BATCH_CALLS, PRUNE_CONFIG_KEY, PRUNE_MAX_CALLS, dueForJudging, pressureSettings, pruneOn, pruneQuestions, pruneState, pruneTally,
14
+ pruneVerdicts, worthJudging,
15
+ } from "../../domain/context-prune.ts";
16
+ import { PRUNE_DECISION_FAILED, PRUNE_WITHOUT_DECISION_MODEL, prunedLine } from "./messages.ts";
17
+
18
+ /** What the pruning adds to an act's request; nothing when it is off. */
19
+ export type ContextPruning = Pick<ActRequest, "onContextPressure" | "contextPressure">;
20
+
21
+ export interface PruneDeps {
22
+ config: Pick<ConfigStore, "readValue">;
23
+ decision: DecisionModel;
24
+ session: Pick<SessionStore, "readBudget">;
25
+ log: Pick<Logger, "info" | "warn">;
26
+ }
27
+
28
+ async function settingOn(config: PruneDeps["config"]): Promise<boolean> {
29
+ try {
30
+ const value = (await config.readValue(PRUNE_CONFIG_KEY)).value;
31
+ return pruneOn(typeof value === "string" ? value : null);
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
36
+
37
+ async function windowOf(session: PruneDeps["session"]): Promise<number> {
38
+ try {
39
+ const { window } = await session.readBudget();
40
+ return window > 0 ? window : DEFAULT_CONTEXT_WINDOW;
41
+ } catch {
42
+ return DEFAULT_CONTEXT_WINDOW;
43
+ }
44
+ }
45
+
46
+ /** The callback of one act working on `request`. Its memory is the act's: the model that failed, and the age at
47
+ * which each result was last judged needed (the runtime numbers the calls of an act, `call-1`, `call-2`...). */
48
+ function judge(deps: Pick<PruneDeps, "decision" | "log">, request: string): NonNullable<ActRequest["onContextPressure"]> {
49
+ let failed = false;
50
+ const keptAt = new Map<string, number>();
51
+ return async (pressure: ContextPressure) => {
52
+ const verdicts: Record<string, PruneVerdict> = {};
53
+ if (failed) return verdicts;
54
+ const due: PressureCall[] = [];
55
+ for (const call of pressure.calls) {
56
+ // A small result is settled for the loop: nothing to free, never offered again.
57
+ if (!worthJudging(call)) verdicts[call.id] = "keep";
58
+ else if (dueForJudging(call, keptAt.get(call.id))) due.push(call);
59
+ }
60
+ const asked = due.slice(0, PRUNE_MAX_CALLS);
61
+ const batches: PressureCall[][] = [];
62
+ for (let start = 0; start < asked.length; start += PRUNE_BATCH_CALLS) batches.push(asked.slice(start, start + PRUNE_BATCH_CALLS));
63
+ // The batches are asked together: the model turn waits for the slowest, not for their sum.
64
+ const replies = await Promise.all(batches.map((batch) => deps.decision.ask(pruneState(request, batch), pruneQuestions(batch))));
65
+ const judged: Record<string, PruneVerdict> = {};
66
+ replies.forEach((answers, i) => {
67
+ if (answers === null) failed = true;
68
+ else Object.assign(judged, pruneVerdicts(batches[i], answers));
69
+ });
70
+ if (failed) deps.log.warn(PRUNE_DECISION_FAILED);
71
+ for (const call of asked) {
72
+ const verdict = judged[call.id];
73
+ // A result judged needed is left unanswered, so the runtime offers it again; it is judged again once aged.
74
+ if (verdict === "keep") keptAt.set(call.id, call.age);
75
+ else if (verdict !== undefined) verdicts[call.id] = verdict;
76
+ }
77
+ const tally = pruneTally(asked, judged);
78
+ if (tally.judged > 0) deps.log.info(prunedLine(tally.judged, tally.dropped, tally.cut, tally.freedTokens));
79
+ return verdicts;
80
+ };
81
+ }
82
+
83
+ /** What an act working on `request` carries: the callback and its settings, or nothing. */
84
+ export async function contextPruning(deps: PruneDeps, request: string): Promise<ContextPruning> {
85
+ if (!await settingOn(deps.config)) return {};
86
+ if (!deps.decision.available()) {
87
+ deps.log.warn(PRUNE_WITHOUT_DECISION_MODEL);
88
+ return {};
89
+ }
90
+ return {
91
+ contextPressure: pressureSettings(await windowOf(deps.session)),
92
+ onContextPressure: judge(deps, request),
93
+ };
94
+ }
@@ -0,0 +1,35 @@
1
+ // An Llm whose acts carry the pruning of their tool loop (prune-context.ts, ADR 0032): the crews whose acts are made
2
+ // by a use case that knows nothing of the pruning (the sub-agents and the roles of the dev crews) get it from the
3
+ // Llm they are handed. Each act asks for its own binding, on its prompt. It adds nothing, and the request leaves as
4
+ // it came, when the binding is empty (the setting off, no decision model), when asking for it fails, and when the
5
+ // request already carries a callback of its own.
6
+ import type { ActRequest, Llm } from "../ports.ts";
7
+ import type { ContextPruning } from "./prune-context.ts";
8
+
9
+ /** What binds the pruning of one act working on `request`: `contextPruning` over the entry point's ports. */
10
+ export type PruningFor = (request: string) => Promise<ContextPruning>;
11
+
12
+ async function bindingOf(prune: PruningFor, prompt: string): Promise<ContextPruning> {
13
+ try {
14
+ return await prune(prompt);
15
+ } catch {
16
+ return {};
17
+ }
18
+ }
19
+
20
+ async function prunedRequest(prune: PruningFor, prompt: string, request: ActRequest): Promise<ActRequest> {
21
+ if (request.onContextPressure !== undefined) return request;
22
+ const binding = await bindingOf(prune, prompt);
23
+ return binding.onContextPressure === undefined ? request : { ...request, ...binding };
24
+ }
25
+
26
+ /** `llm` with the pruning `prune` binds on each of its acts; its other calls unchanged. */
27
+ export function prunedLlm(llm: Llm, prune: PruningFor): Llm {
28
+ return {
29
+ act: async (prompt, request) => llm.act(prompt, await prunedRequest(prune, prompt, request)),
30
+ complete: (prompt, request) => llm.complete(prompt, request),
31
+ extract: (prompt, schema) => llm.extract(prompt, schema),
32
+ permissionGateEnabled: () => llm.permissionGateEnabled(),
33
+ effortSent: (request) => llm.effortSent(request),
34
+ };
35
+ }