orkeon-code 0.0.0-stage → 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (423) hide show
  1. package/.orkeon-version +1 -0
  2. package/LICENSE.md +21 -0
  3. package/NOTICE.md +17 -0
  4. package/README.fr.md +169 -0
  5. package/README.md +162 -2
  6. package/config/appsettings.anthropic.example.json +77 -0
  7. package/config/appsettings.example.json +71 -0
  8. package/config/appsettings.jev.example.json +128 -0
  9. package/config/appsettings.kev.example.json +130 -0
  10. package/config/appsettings.liquid.example.json +129 -0
  11. package/config/appsettings.ollama-whisper.example.json +92 -0
  12. package/config/appsettings.ollama.example.json +70 -0
  13. package/config/appsettings.whisper.example.json +31 -0
  14. package/mcp/whisper/README.md +293 -0
  15. package/mcp/whisper/pyproject.toml +32 -0
  16. package/mcp/whisper/uv.lock +1641 -0
  17. package/mcp/whisper/whisper_mcp.py +1053 -0
  18. package/orkeon-code +897 -0
  19. package/orkeon-code.mjs +71 -0
  20. package/orkeon-code.ps1 +837 -0
  21. package/package.json +57 -4
  22. package/scripts/install.ps1 +156 -0
  23. package/scripts/install.sh +148 -0
  24. package/scripts/session-start.ork.ts +90 -0
  25. package/scripts/session-start.sh +74 -0
  26. package/scripts/setup-fixture.sh +88 -0
  27. package/src/commands/.orkeon/orkeon-cli.d.ts +562 -0
  28. package/src/commands/_lib/args.ts +193 -0
  29. package/src/commands/_lib/dev/dev-batches.ts +368 -0
  30. package/src/commands/_lib/dev/dev-implement.ts +188 -0
  31. package/src/commands/_lib/dev/dev-source.ts +65 -0
  32. package/src/commands/_lib/dev/dev.ts +344 -0
  33. package/src/commands/_lib/dev-step.ts +142 -0
  34. package/src/commands/_lib/dispatch.ts +231 -0
  35. package/src/commands/_lib/effort.ts +15 -0
  36. package/src/commands/_lib/git/branch.ts +95 -0
  37. package/src/commands/_lib/git/commit.ts +94 -0
  38. package/src/commands/_lib/git/diff.ts +97 -0
  39. package/src/commands/_lib/git/review.ts +109 -0
  40. package/src/commands/_lib/memory/memory-admit.ts +150 -0
  41. package/src/commands/_lib/memory/memory.ts +51 -0
  42. package/src/commands/_lib/pr-context.ts +32 -0
  43. package/src/commands/_lib/project/analyze.ts +24 -0
  44. package/src/commands/_lib/session/export.ts +104 -0
  45. package/src/commands/_lib/session/resume.ts +160 -0
  46. package/src/commands/_lib/session/tasks.ts +184 -0
  47. package/src/commands/_lib/settings/advisor.ts +80 -0
  48. package/src/commands/_lib/settings/agents.ts +147 -0
  49. package/src/commands/_lib/settings/config.ts +141 -0
  50. package/src/commands/_lib/settings/hooks.ts +58 -0
  51. package/src/commands/_lib/settings/mode.ts +91 -0
  52. package/src/commands/_lib/settings/model.ts +146 -0
  53. package/src/commands/_lib/settings/permissions.ts +309 -0
  54. package/src/commands/_lib/settings/session-config.ts +49 -0
  55. package/src/commands/_lib/settings/skills.ts +51 -0
  56. package/src/commands/_lib/speech/say.ts +96 -0
  57. package/src/commands/_lib/speech/transcribe.ts +130 -0
  58. package/src/commands/_lib/speech/voice.ts +146 -0
  59. package/src/commands/_lib/status/cache.ts +31 -0
  60. package/src/commands/_lib/status/context.ts +57 -0
  61. package/src/commands/_lib/status/doctor.ts +186 -0
  62. package/src/commands/_lib/status/meta.ts +45 -0
  63. package/src/commands/_lib/status/status.ts +129 -0
  64. package/src/commands/_lib/status/usage-tools.ts +49 -0
  65. package/src/commands/_lib/status/usage.ts +139 -0
  66. package/src/commands/_lib/view.ts +29 -0
  67. package/src/commands/dev/dev-batches.cmd.ts +108 -0
  68. package/src/commands/dev/dev-learn.cmd.ts +29 -0
  69. package/src/commands/dev/dev-plan.cmd.ts +52 -0
  70. package/src/commands/dev/dev-spec.cmd.ts +55 -0
  71. package/src/commands/dev/dev-status.cmd.ts +16 -0
  72. package/src/commands/git/branch.cmd.ts +27 -0
  73. package/src/commands/git/commit.cmd.ts +48 -0
  74. package/src/commands/git/diff.cmd.ts +26 -0
  75. package/src/commands/git/review.cmd.ts +36 -0
  76. package/src/commands/memory/memory.cmd.ts +48 -0
  77. package/src/commands/project/analyze.cmd.ts +32 -0
  78. package/src/commands/project/debug-tool-call.cmd.ts +67 -0
  79. package/src/commands/project/files.cmd.ts +22 -0
  80. package/src/commands/project/init-verifiers.cmd.ts +14 -0
  81. package/src/commands/project/init.cmd.ts +14 -0
  82. package/src/commands/project/verify.cmd.ts +27 -0
  83. package/src/commands/session/assistant.cmd.ts +40 -0
  84. package/src/commands/session/btw.cmd.ts +18 -0
  85. package/src/commands/session/clear.cmd.ts +19 -0
  86. package/src/commands/session/compact.cmd.ts +16 -0
  87. package/src/commands/session/copy.cmd.ts +44 -0
  88. package/src/commands/session/exit.cmd.ts +9 -0
  89. package/src/commands/session/export.cmd.ts +28 -0
  90. package/src/commands/session/rename.cmd.ts +17 -0
  91. package/src/commands/session/resume.cmd.ts +19 -0
  92. package/src/commands/session/rewind.cmd.ts +26 -0
  93. package/src/commands/session/summary.cmd.ts +27 -0
  94. package/src/commands/session/tasks.cmd.ts +44 -0
  95. package/src/commands/settings/advisor.cmd.ts +38 -0
  96. package/src/commands/settings/agents.cmd.ts +19 -0
  97. package/src/commands/settings/config.cmd.ts +17 -0
  98. package/src/commands/settings/effort.cmd.ts +40 -0
  99. package/src/commands/settings/fast.cmd.ts +17 -0
  100. package/src/commands/settings/hooks.cmd.ts +17 -0
  101. package/src/commands/settings/mode.cmd.ts +20 -0
  102. package/src/commands/settings/model.cmd.ts +20 -0
  103. package/src/commands/settings/output-style.cmd.ts +48 -0
  104. package/src/commands/settings/permissions.cmd.ts +25 -0
  105. package/src/commands/settings/proactive.cmd.ts +15 -0
  106. package/src/commands/settings/skills.cmd.ts +17 -0
  107. package/src/commands/speech/say.cmd.ts +24 -0
  108. package/src/commands/speech/transcribe.cmd.ts +29 -0
  109. package/src/commands/speech/voice.cmd.ts +30 -0
  110. package/src/commands/status/context.cmd.ts +18 -0
  111. package/src/commands/status/doctor.cmd.ts +27 -0
  112. package/src/commands/status/release-notes.cmd.ts +9 -0
  113. package/src/commands/status/status.cmd.ts +25 -0
  114. package/src/commands/status/usage.cmd.ts +21 -0
  115. package/src/crews/.orkeon/orkeon.d.ts +3946 -0
  116. package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +183 -0
  117. package/src/crews/_probe-shared-memory/probe.ork.ts +98 -0
  118. package/src/crews/advisor/application/run-advisor.ts +40 -0
  119. package/src/crews/advisor/crew.ork.ts +43 -0
  120. package/src/crews/advisor/domain/advice.ts +135 -0
  121. package/src/crews/agent-run/application/run-agent-run.ts +42 -0
  122. package/src/crews/agent-run/crew.ork.ts +67 -0
  123. package/src/crews/analyze/application/run-analyze.ts +118 -0
  124. package/src/crews/analyze/crew.ork.ts +40 -0
  125. package/src/crews/analyze/domain/harvest.ts +301 -0
  126. package/src/crews/code-review/application/prompts.ts +133 -0
  127. package/src/crews/code-review/application/review.ts +71 -0
  128. package/src/crews/code-review/application/run-code-review.ts +123 -0
  129. package/src/crews/code-review/crew.ork.ts +51 -0
  130. package/src/crews/code-review/domain/lenses.ts +193 -0
  131. package/src/crews/code-review/domain/report.ts +59 -0
  132. package/src/crews/code-review/domain/scope.ts +112 -0
  133. package/src/crews/dev-batches/application/plan-close.ts +181 -0
  134. package/src/crews/dev-batches/application/run-dev-batches.ts +669 -0
  135. package/src/crews/dev-batches/application/run-wave.ts +450 -0
  136. package/src/crews/dev-batches/application/seed-harvest.ts +162 -0
  137. package/src/crews/dev-batches/crew.ork.ts +143 -0
  138. package/src/crews/dev-batches/domain/batch-waves.ts +70 -0
  139. package/src/crews/dev-batches/domain/batches-budget.ts +52 -0
  140. package/src/crews/dev-batches/domain/batches-log.ts +54 -0
  141. package/src/crews/dev-batches/domain/wave-order.ts +43 -0
  142. package/src/crews/dev-change/application/change-prompt.ts +104 -0
  143. package/src/crews/dev-change/application/evidence.ts +169 -0
  144. package/src/crews/dev-change/application/run-dev-change.ts +315 -0
  145. package/src/crews/dev-change/crew.ork.ts +112 -0
  146. package/src/crews/dev-change/domain/change-answer.ts +159 -0
  147. package/src/crews/dev-change/domain/change-render.ts +79 -0
  148. package/src/crews/dev-implement/application/close.ts +183 -0
  149. package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
  150. package/src/crews/dev-implement/application/locate-sheet.ts +80 -0
  151. package/src/crews/dev-implement/application/observe.ts +50 -0
  152. package/src/crews/dev-implement/application/report-writes.ts +41 -0
  153. package/src/crews/dev-implement/application/run-dev-implement.ts +811 -0
  154. package/src/crews/dev-implement/application/run-role.ts +27 -0
  155. package/src/crews/dev-implement/application/suite-job.ts +118 -0
  156. package/src/crews/dev-implement/application/touched.ts +74 -0
  157. package/src/crews/dev-implement/crew.ork.ts +68 -0
  158. package/src/crews/dev-implement/domain/contracts.ts +256 -0
  159. package/src/crews/dev-implement/domain/correction.ts +102 -0
  160. package/src/crews/dev-implement/domain/cycles.ts +35 -0
  161. package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
  162. package/src/crews/dev-implement/domain/roles.ts +53 -0
  163. package/src/crews/dev-implement/domain/sheet-edits.ts +75 -0
  164. package/src/crews/dev-implement/domain/sheet-ticks.ts +22 -0
  165. package/src/crews/dev-implement/domain/step-checks.ts +136 -0
  166. package/src/crews/dev-implement/domain/step-section.ts +127 -0
  167. package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
  168. package/src/crews/dev-learn/application/learn-prompt.ts +140 -0
  169. package/src/crews/dev-learn/application/run-dev-learn.ts +553 -0
  170. package/src/crews/dev-learn/crew.ork.ts +52 -0
  171. package/src/crews/dev-learn/domain/learn-answer.ts +235 -0
  172. package/src/crews/dev-learn/domain/owner-lines.ts +86 -0
  173. package/src/crews/dev-learn/domain/proposals-render.ts +96 -0
  174. package/src/crews/dev-plan/application/anchor-paths.ts +76 -0
  175. package/src/crews/dev-plan/application/inventory.ts +170 -0
  176. package/src/crews/dev-plan/application/plan-prompt.ts +159 -0
  177. package/src/crews/dev-plan/application/run-dev-plan.ts +455 -0
  178. package/src/crews/dev-plan/crew.ork.ts +109 -0
  179. package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
  180. package/src/crews/dev-plan/domain/plan-answer.ts +738 -0
  181. package/src/crews/dev-plan/domain/plan-render.ts +307 -0
  182. package/src/crews/dev-spec/application/run-dev-spec.ts +206 -0
  183. package/src/crews/dev-spec/application/spec-prompt.ts +98 -0
  184. package/src/crews/dev-spec/crew.ork.ts +108 -0
  185. package/src/crews/dev-spec/domain/spec-answer.ts +253 -0
  186. package/src/crews/dev-spec/domain/spec-render.ts +76 -0
  187. package/src/crews/dev-verify/application/audit.ts +259 -0
  188. package/src/crews/dev-verify/application/auditor-prompt.ts +323 -0
  189. package/src/crews/dev-verify/application/capture.ts +303 -0
  190. package/src/crews/dev-verify/application/run-dev-verify.ts +409 -0
  191. package/src/crews/dev-verify/application/run-gate.ts +202 -0
  192. package/src/crews/dev-verify/crew.ork.ts +103 -0
  193. package/src/crews/dev-verify/domain/audit-answer.ts +150 -0
  194. package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
  195. package/src/crews/dev-verify/domain/capture-sections.ts +137 -0
  196. package/src/crews/dev-verify/domain/commands.ts +103 -0
  197. package/src/crews/dev-verify/domain/gate.ts +126 -0
  198. package/src/crews/dev-verify/domain/mechanical-table.ts +163 -0
  199. package/src/crews/dev-verify/domain/runtime-cut.ts +13 -0
  200. package/src/crews/dev-verify/domain/sheet-facts.ts +4 -0
  201. package/src/crews/dev-verify/domain/text.ts +20 -0
  202. package/src/crews/dev-verify/domain/verdict.ts +127 -0
  203. package/src/crews/git-commit/application/draft.ts +154 -0
  204. package/src/crews/git-commit/application/run-git-commit.ts +116 -0
  205. package/src/crews/git-commit/crew.ork.ts +52 -0
  206. package/src/crews/git-commit/domain/commit.ts +220 -0
  207. package/src/crews/init-verifiers/application/authoring.ts +89 -0
  208. package/src/crews/init-verifiers/application/prompts.ts +103 -0
  209. package/src/crews/init-verifiers/application/run-init-verifiers.ts +25 -0
  210. package/src/crews/init-verifiers/crew.ork.ts +34 -0
  211. package/src/crews/init-verifiers/domain/commands-section.ts +36 -0
  212. package/src/crews/init-verifiers/domain/readiness.ts +23 -0
  213. package/src/crews/main-loop/application/auto-compact.ts +77 -0
  214. package/src/crews/main-loop/application/context-gather.ts +133 -0
  215. package/src/crews/main-loop/application/run-main-loop.ts +350 -0
  216. package/src/crews/main-loop/application/turn-prompt.ts +112 -0
  217. package/src/crews/main-loop/crew.ork.ts +119 -0
  218. package/src/crews/main-loop/domain/autocompact.ts +27 -0
  219. package/src/crews/main-loop/domain/prompt-assembly.ts +521 -0
  220. package/src/crews/main-loop/domain/turn-chains.ts +129 -0
  221. package/src/crews/project-init/application/detect.ts +122 -0
  222. package/src/crews/project-init/application/prompts.ts +101 -0
  223. package/src/crews/project-init/application/run-project-init.ts +31 -0
  224. package/src/crews/project-init/crew.ork.ts +35 -0
  225. package/src/crews/project-init/domain/conventions.ts +36 -0
  226. package/src/crews/project-init/domain/existing-files.ts +63 -0
  227. package/src/crews/project-init/domain/package-map.ts +73 -0
  228. package/src/crews/session-compact/crew.ork.ts +55 -0
  229. package/src/crews/shared-memory-admit/crew.ork.ts +48 -0
  230. package/src/crews/speech/application/run-speech.ts +25 -0
  231. package/src/crews/speech/crew.ork.ts +37 -0
  232. package/src/shared/application/agents/child-agent.ts +255 -0
  233. package/src/shared/application/agents/run-sub-agent.ts +96 -0
  234. package/src/shared/application/answer-language.ts +14 -0
  235. package/src/shared/application/attached-skills.ts +36 -0
  236. package/src/shared/application/compaction/compact-session.ts +237 -0
  237. package/src/shared/application/compaction/extract-memories.ts +38 -0
  238. package/src/shared/application/compaction/restore-context.ts +78 -0
  239. package/src/shared/application/config-store.ts +123 -0
  240. package/src/shared/application/dev/brief-inventory.ts +113 -0
  241. package/src/shared/application/dev/close-batch.ts +83 -0
  242. package/src/shared/application/dev/find-repo-pack.ts +77 -0
  243. package/src/shared/application/dev/learn-decision.ts +252 -0
  244. package/src/shared/application/dev/load-dev-context.ts +266 -0
  245. package/src/shared/application/dev/measure-access-cost.ts +68 -0
  246. package/src/shared/application/dev/plan-source.ts +112 -0
  247. package/src/shared/application/dev/preflight.ts +71 -0
  248. package/src/shared/application/dev/project-files.ts +17 -0
  249. package/src/shared/application/dev/question-round.ts +52 -0
  250. package/src/shared/application/dev/resolve-work-folder.ts +133 -0
  251. package/src/shared/application/dev/script-tool-slot.ts +27 -0
  252. package/src/shared/application/dev/settle-questions.ts +55 -0
  253. package/src/shared/application/dev/source-review.ts +63 -0
  254. package/src/shared/application/dev/source-step.ts +150 -0
  255. package/src/shared/application/dev/spend.ts +42 -0
  256. package/src/shared/application/dev/step-precedents.ts +89 -0
  257. package/src/shared/application/dev/tool-call-policy.ts +89 -0
  258. package/src/shared/application/dev/tool-callbacks.ts +215 -0
  259. package/src/shared/application/dev/tool-trace-recorder.ts +45 -0
  260. package/src/shared/application/dev/verdict-sources.ts +48 -0
  261. package/src/shared/application/dev/wrapped-tools.ts +145 -0
  262. package/src/shared/application/extra-tools.ts +70 -0
  263. package/src/shared/application/git/batch-worktree.ts +97 -0
  264. package/src/shared/application/git/commit-files.ts +186 -0
  265. package/src/shared/application/git/merge-batch.ts +63 -0
  266. package/src/shared/application/git/open-pull-request.ts +51 -0
  267. package/src/shared/application/instructions-file.ts +19 -0
  268. package/src/shared/application/json-file.ts +34 -0
  269. package/src/shared/application/llm-profile.ts +35 -0
  270. package/src/shared/application/permission-rules.ts +159 -0
  271. package/src/shared/application/ports/approvals.ts +20 -0
  272. package/src/shared/application/ports/clock.ts +5 -0
  273. package/src/shared/application/ports/code-index.ts +93 -0
  274. package/src/shared/application/ports/crew.ts +60 -0
  275. package/src/shared/application/ports/files.ts +21 -0
  276. package/src/shared/application/ports/human.ts +13 -0
  277. package/src/shared/application/ports/llm.ts +54 -0
  278. package/src/shared/application/ports/memory.ts +30 -0
  279. package/src/shared/application/ports/progress.ts +23 -0
  280. package/src/shared/application/ports/runtime.ts +15 -0
  281. package/src/shared/application/ports/session.ts +74 -0
  282. package/src/shared/application/ports/shared-memory.ts +26 -0
  283. package/src/shared/application/ports/shell.ts +40 -0
  284. package/src/shared/application/ports/telemetry.ts +45 -0
  285. package/src/shared/application/ports/tools.ts +46 -0
  286. package/src/shared/application/ports/usage.ts +45 -0
  287. package/src/shared/application/ports.ts +27 -0
  288. package/src/shared/application/project-manifests.ts +106 -0
  289. package/src/shared/application/session-io.ts +84 -0
  290. package/src/shared/application/session-state.ts +36 -0
  291. package/src/shared/application/shared-memory/admit-entries.ts +177 -0
  292. package/src/shared/application/shared-memory/harvest-after-gaps.ts +72 -0
  293. package/src/shared/application/shared-memory/harvest-mistakes.ts +44 -0
  294. package/src/shared/application/shared-memory/import-agent-memory.ts +117 -0
  295. package/src/shared/application/shared-memory/memory-files.ts +110 -0
  296. package/src/shared/application/shared-memory/memory-settings.ts +93 -0
  297. package/src/shared/application/shared-memory/push-candidate.ts +146 -0
  298. package/src/shared/application/shared-memory/recall-precedents.ts +69 -0
  299. package/src/shared/application/state-snapshot.ts +38 -0
  300. package/src/shared/application/workflow/workflow-state.ts +135 -0
  301. package/src/shared/domain/agent-policy/behavior-flags.ts +168 -0
  302. package/src/shared/domain/agent-policy/extra-tools.ts +69 -0
  303. package/src/shared/domain/agent-policy/memory-categories.ts +6 -0
  304. package/src/shared/domain/agent-policy/mode-policy.ts +51 -0
  305. package/src/shared/domain/agent-policy/output-styles.ts +11 -0
  306. package/src/shared/domain/agent-policy/permission.ts +623 -0
  307. package/src/shared/domain/agent-policy/rule-sets.ts +412 -0
  308. package/src/shared/domain/agent-policy/tool-access.ts +77 -0
  309. package/src/shared/domain/agent-registry.ts +142 -0
  310. package/src/shared/domain/agents/built-in-charters.ts +43 -0
  311. package/src/shared/domain/agents/chain.ts +30 -0
  312. package/src/shared/domain/agents/charter.ts +61 -0
  313. package/src/shared/domain/agents/exclusive.ts +24 -0
  314. package/src/shared/domain/agents/instances.ts +249 -0
  315. package/src/shared/domain/code-intel-contract.ts +356 -0
  316. package/src/shared/domain/code-intel-routing.ts +113 -0
  317. package/src/shared/domain/compact-outcome.ts +44 -0
  318. package/src/shared/domain/compaction-thresholds.ts +161 -0
  319. package/src/shared/domain/compaction.ts +379 -0
  320. package/src/shared/domain/config-schema.ts +421 -0
  321. package/src/shared/domain/dev/access-cost.ts +226 -0
  322. package/src/shared/domain/dev/artefacts.ts +50 -0
  323. package/src/shared/domain/dev/batches-concurrency.ts +36 -0
  324. package/src/shared/domain/dev/batches-state.ts +49 -0
  325. package/src/shared/domain/dev/build-commands.ts +44 -0
  326. package/src/shared/domain/dev/call-guard.ts +341 -0
  327. package/src/shared/domain/dev/carried-text.ts +49 -0
  328. package/src/shared/domain/dev/design-rules.ts +100 -0
  329. package/src/shared/domain/dev/learn-proposals.ts +175 -0
  330. package/src/shared/domain/dev/learn-state.ts +93 -0
  331. package/src/shared/domain/dev/path-args.ts +42 -0
  332. package/src/shared/domain/dev/path-rebase.ts +93 -0
  333. package/src/shared/domain/dev/plan-checks.ts +190 -0
  334. package/src/shared/domain/dev/plan-format.ts +180 -0
  335. package/src/shared/domain/dev/project-files.ts +43 -0
  336. package/src/shared/domain/dev/questions.ts +249 -0
  337. package/src/shared/domain/dev/reading-rule.ts +41 -0
  338. package/src/shared/domain/dev/repo-pack.ts +237 -0
  339. package/src/shared/domain/dev/review-answer.ts +150 -0
  340. package/src/shared/domain/dev/review-prompt.ts +221 -0
  341. package/src/shared/domain/dev/reviewer-charter.ts +31 -0
  342. package/src/shared/domain/dev/sheet-facts.ts +83 -0
  343. package/src/shared/domain/dev/spec-format.ts +183 -0
  344. package/src/shared/domain/dev/step-budget.ts +72 -0
  345. package/src/shared/domain/dev/step-rules.ts +110 -0
  346. package/src/shared/domain/dev/test-commands.ts +90 -0
  347. package/src/shared/domain/dev/test-output.ts +33 -0
  348. package/src/shared/domain/dev/test-paths.ts +40 -0
  349. package/src/shared/domain/dev/tool-guards.ts +64 -0
  350. package/src/shared/domain/dev/trait-pattern.ts +83 -0
  351. package/src/shared/domain/dev/verdict-format.ts +169 -0
  352. package/src/shared/domain/dev/whitespace.ts +34 -0
  353. package/src/shared/domain/dev/work-folder.ts +67 -0
  354. package/src/shared/domain/dev/yaml-subset.ts +403 -0
  355. package/src/shared/domain/git/close.ts +273 -0
  356. package/src/shared/domain/git/pull-request.ts +96 -0
  357. package/src/shared/domain/git/worktree.ts +46 -0
  358. package/src/shared/domain/index-languages.ts +16 -0
  359. package/src/shared/domain/instructions-file.ts +18 -0
  360. package/src/shared/domain/iso-day.ts +4 -0
  361. package/src/shared/domain/llm-failure.ts +106 -0
  362. package/src/shared/domain/llm-profile.ts +25 -0
  363. package/src/shared/domain/marked-message.ts +33 -0
  364. package/src/shared/domain/model-catalog.ts +86 -0
  365. package/src/shared/domain/permission-modes.ts +103 -0
  366. package/src/shared/domain/prelude.ts +92 -0
  367. package/src/shared/domain/project-manifests.ts +83 -0
  368. package/src/shared/domain/search-routing.ts +85 -0
  369. package/src/shared/domain/secret-patterns.ts +45 -0
  370. package/src/shared/domain/session-keys.ts +85 -0
  371. package/src/shared/domain/session-start.ts +60 -0
  372. package/src/shared/domain/session-summary.ts +13 -0
  373. package/src/shared/domain/severity.ts +72 -0
  374. package/src/shared/domain/sha1.ts +61 -0
  375. package/src/shared/domain/shared-memory/agent-memory-import.ts +143 -0
  376. package/src/shared/domain/shared-memory/candidates.ts +41 -0
  377. package/src/shared/domain/shared-memory/entry.ts +145 -0
  378. package/src/shared/domain/shared-memory/front-matter.ts +183 -0
  379. package/src/shared/domain/shared-memory/gate.ts +44 -0
  380. package/src/shared/domain/shared-memory/harvest.ts +61 -0
  381. package/src/shared/domain/shared-memory/layout.ts +187 -0
  382. package/src/shared/domain/shared-memory/precedents-block.ts +93 -0
  383. package/src/shared/domain/shared-memory/refused.ts +84 -0
  384. package/src/shared/domain/shared-memory/verdict-rows.ts +134 -0
  385. package/src/shared/domain/snip-turns.ts +45 -0
  386. package/src/shared/domain/speech.ts +20 -0
  387. package/src/shared/domain/strip.ts +88 -0
  388. package/src/shared/domain/tool-trace.ts +122 -0
  389. package/src/shared/domain/types.ts +67 -0
  390. package/src/shared/domain/verifiers.ts +37 -0
  391. package/src/shared/domain/vfs.ts +9 -0
  392. package/src/shared/domain/workflow/state-file.ts +140 -0
  393. package/src/shared/infrastructure/globals.ts +52 -0
  394. package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
  395. package/src/shared/infrastructure/orkeon/child-agents.ts +127 -0
  396. package/src/shared/infrastructure/orkeon/code-index.ts +120 -0
  397. package/src/shared/infrastructure/orkeon/crew-host.ts +27 -0
  398. package/src/shared/infrastructure/orkeon/crew-memory.ts +12 -0
  399. package/src/shared/infrastructure/orkeon/dev-deps.ts +172 -0
  400. package/src/shared/infrastructure/orkeon/files.ts +40 -0
  401. package/src/shared/infrastructure/orkeon/github-pull-requests.ts +29 -0
  402. package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
  403. package/src/shared/infrastructure/orkeon/human-input.ts +59 -0
  404. package/src/shared/infrastructure/orkeon/llm-profile.ts +38 -0
  405. package/src/shared/infrastructure/orkeon/llm.ts +109 -0
  406. package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
  407. package/src/shared/infrastructure/orkeon/memory-tools.ts +131 -0
  408. package/src/shared/infrastructure/orkeon/permission-rules.ts +42 -0
  409. package/src/shared/infrastructure/orkeon/progress.ts +24 -0
  410. package/src/shared/infrastructure/orkeon/run-state.ts +17 -0
  411. package/src/shared/infrastructure/orkeon/runtime-info.ts +30 -0
  412. package/src/shared/infrastructure/orkeon/runtime-tools.ts +60 -0
  413. package/src/shared/infrastructure/orkeon/script-tools.ts +134 -0
  414. package/src/shared/infrastructure/orkeon/session-store.ts +138 -0
  415. package/src/shared/infrastructure/orkeon/session-switch.ts +23 -0
  416. package/src/shared/infrastructure/orkeon/shared-memory.ts +61 -0
  417. package/src/shared/infrastructure/orkeon/shell-jobs.ts +75 -0
  418. package/src/shared/infrastructure/orkeon/shell.ts +31 -0
  419. package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
  420. package/src/shared/infrastructure/orkeon/tool-catalogue.ts +75 -0
  421. package/src/shared/infrastructure/orkeon/tool-results.ts +120 -0
  422. package/src/shared/infrastructure/orkeon/usage.ts +74 -0
  423. package/src/shared/infrastructure/orkeon/wiring.ts +118 -0
@@ -0,0 +1,160 @@
1
+ // /resume — the sessions of this project the launcher kept, and the one to bring back. The runtime
2
+ // saves the conversation after each turn and when the REPL ends (Persist), outside the project; the
3
+ // next start of `orkeon-code` moves it to the project's history and starts fresh, and mounts that
4
+ // history read-only on /session-history. `/resume` lists them; `/resume <n | id>` loads one in place
5
+ // (Orkeon #227): the session of now is saved to an archive beside its own file first (the launcher
6
+ // moves it to the history at the next start), then the chosen file replaces the buffer, the state bag,
7
+ // the id and the title. `orkeon-code --resume <id>` (or `--continue` for the last one) does the same
8
+ // at start. Lives under commands/_lib/ — the loader's SearchPattern is "*.cmd.ts", so this file is
9
+ // never loaded as a command.
10
+
11
+ import type { Clock, Files, SessionMessages, SessionStore, SessionSwitch } from "../../../shared/application/ports.ts";
12
+ import { LOADED_SESSION_STATE_KEY } from "../../../shared/domain/session-keys.ts";
13
+ import type { CommandView } from "../view.ts";
14
+
15
+ /** Where the launcher mounts the project's saved sessions. */
16
+ export const HISTORY_ROOT = "/session-history";
17
+ /** The newest sessions read and shown; the launcher's --resume lists them all. */
18
+ export const SHOWN_SESSIONS = 10;
19
+ /** The names listed at most (the launcher keeps 50 by default). */
20
+ const MAX_LISTED = 500;
21
+ const TAIL_TURNS = 3;
22
+
23
+ export interface ResumeDeps {
24
+ files: Pick<Files, "read" | "list">;
25
+ session: Pick<SessionStore, "readMessages" | "readState" | "writeState">;
26
+ /** The session saved and loaded in place; absent when the host does not persist the session. */
27
+ switch?: SessionSwitch;
28
+ clock: Clock;
29
+ }
30
+
31
+ export type SessionRow = { id: string; saved: string; title: string; messages: string };
32
+
33
+ /** `<yyyymmddTHHMMSSZ>-<id>.json`, as the launcher names a saved session. */
34
+ const SAVED_NAME = /^(\d{8}T\d{6}Z)-(.+)\.json$/;
35
+
36
+ /** What the listing says under the table. */
37
+ export const HOW_TO_RESUME =
38
+ "`/resume <number or id>` brings one back in place of this session, which is archived; " +
39
+ "`orkeon-code --resume <id>` does the same at start, `orkeon-code --continue` brings back the session you quit.";
40
+
41
+ /** What a host that does not persist the session leaves `/resume <n|id>` with. */
42
+ export const NO_SWITCH =
43
+ "cannot switch in place: the REPL runs without a persisted session (Orkeon:Cli:Session:Persist off); " +
44
+ "quit (/exit), then start `orkeon-code --resume <id>`.";
45
+
46
+ /** `20261024T101500Z` as `2026-10-24 10:15 UTC`. */
47
+ function savedAt(stamp: string): string {
48
+ return `${stamp.slice(0, 4)}-${stamp.slice(4, 6)}-${stamp.slice(6, 8)} ${stamp.slice(9, 11)}:${stamp.slice(11, 13)} UTC`;
49
+ }
50
+
51
+ /** The time now as the launcher stamps a saved session, `20261024T101500Z`. */
52
+ export function stampOf(clock: Clock): string {
53
+ return clock().toISOString().replace(/[-:]/g, "").slice(0, 15) + "Z";
54
+ }
55
+
56
+ /** One row per saved session: its id, when it was saved, its title and its number of messages. */
57
+ async function readRow(files: ResumeDeps["files"], name: string, stamp: string, id: string, current: boolean): Promise<SessionRow> {
58
+ const row = { id, saved: savedAt(stamp) };
59
+ const mark = current ? " (this session)" : "";
60
+ try {
61
+ const saved = JSON.parse(await files.read(`${HISTORY_ROOT}/${name}`));
62
+ const title = typeof saved?.Title === "string" && saved.Title.trim() ? saved.Title.trim() : "(untitled)";
63
+ const messages = Array.isArray(saved?.Messages) ? String(saved.Messages.length) : "?";
64
+ return { ...row, title: title + mark, messages };
65
+ } catch (e: any) {
66
+ return { ...row, title: `(unreadable: ${String(e?.message ?? e).split("\n")[0]})${mark}`, messages: "?" };
67
+ }
68
+ }
69
+
70
+ /** The saved sessions' file names, newest first; null when the history is not mounted. */
71
+ async function savedNames(files: ResumeDeps["files"]): Promise<string[] | null> {
72
+ try {
73
+ return (await files.list(HISTORY_ROOT, MAX_LISTED))
74
+ // A name, or a path when the host lists paths.
75
+ .map((n) => n.replace(/\/$/, "").split("/").pop() ?? "")
76
+ .filter((n) => SAVED_NAME.test(n))
77
+ .sort()
78
+ .reverse();
79
+ } catch {
80
+ return null;
81
+ }
82
+ }
83
+
84
+ const idOf = (name: string): string => SAVED_NAME.exec(name)![2];
85
+
86
+ /** The file `choice` names: a number of the shown list, else the start of an id that matches one session. */
87
+ export function chooseSaved(names: readonly string[], choice: string): { name: string } | { refused: string } {
88
+ const shown = names.slice(0, SHOWN_SESSIONS);
89
+ if (/^[1-9]\d{0,3}$/.test(choice)) {
90
+ const n = Number(choice);
91
+ if (n <= shown.length) return { name: shown[n - 1] };
92
+ }
93
+ const matches = names.filter((name) => idOf(name).startsWith(choice));
94
+ if (matches.length === 1) return { name: matches[0] };
95
+ if (matches.length > 1) return { refused: `more than one saved session starts with '${choice}': give more of its id.` };
96
+ return { refused: `no saved session '${choice}' (/resume lists them).` };
97
+ }
98
+
99
+ /** Load `name` in place: the session of now archived beside its own file first, then the swap. */
100
+ async function loadSaved(deps: ResumeDeps, name: string): Promise<CommandView> {
101
+ const id = idOf(name);
102
+ if (deps.switch === undefined) return { text: NO_SWITCH };
103
+ let archive = "";
104
+ try {
105
+ const own = await deps.switch.save();
106
+ archive = `${own.slice(0, own.lastIndexOf("/") + 1)}${stampOf(deps.clock)}-archived.json`;
107
+ await deps.switch.save(archive);
108
+ const count = await deps.switch.load(`${HISTORY_ROOT}/${name}`);
109
+ await deps.session.writeState(LOADED_SESSION_STATE_KEY, name).catch(() => undefined);
110
+ return {
111
+ text: `loaded ${id} (${count} message(s)): the next turn continues it. ` +
112
+ `The session you left is archived at ${archive}; the next start of orkeon-code moves it to the history.`,
113
+ };
114
+ } catch (e: any) {
115
+ const reason = String(e?.message ?? e).split("\n")[0];
116
+ return { text: `could not load ${id}: ${reason}. This session is unchanged${archive ? `; its archive ${archive} stays` : ""}.` };
117
+ }
118
+ }
119
+
120
+ /** The saved sessions, newest first, then the current buffer's last turns; with `choice`, that one loaded in place. */
121
+ export async function runResume(deps: ResumeDeps, choice?: string): Promise<CommandView> {
122
+ const names = await savedNames(deps.files);
123
+ const wanted = choice?.trim() ?? "";
124
+
125
+ if (wanted.length > 0) {
126
+ if (names === null) return { text: `no saved session to load: ${HISTORY_ROOT} is not mounted (start the REPL with orkeon-code).` };
127
+ if (names.length === 0) return { text: "no saved session to load: this project has none yet." };
128
+ const chosen = chooseSaved(names, wanted);
129
+ return "refused" in chosen ? { text: chosen.refused } : loadSaved(deps, chosen.name);
130
+ }
131
+
132
+ const lines: string[] = [];
133
+ let table: SessionRow[] | undefined;
134
+ if (names === null) {
135
+ lines.push(`no saved sessions to list: ${HISTORY_ROOT} is not mounted (start the REPL with orkeon-code).`);
136
+ } else if (names.length === 0) {
137
+ lines.push("no saved session for this project yet: the next start of orkeon-code keeps this one.");
138
+ } else {
139
+ const loadedFrom = await deps.session.readState(LOADED_SESSION_STATE_KEY).catch(() => null);
140
+ table = [];
141
+ for (const name of names.slice(0, SHOWN_SESSIONS)) {
142
+ const [, stamp, id] = SAVED_NAME.exec(name)!;
143
+ table.push(await readRow(deps.files, name, stamp, id, name === loadedFrom));
144
+ }
145
+ const more = names.length - table.length;
146
+ lines.push(
147
+ `${names.length} saved session(s) of this project, newest first${more > 0 ? ` (${more} more: orkeon-code --resume lists them all)` : ""}.`,
148
+ HOW_TO_RESUME,
149
+ );
150
+ }
151
+
152
+ const { messages } = await deps.session.readMessages()
153
+ .catch((): SessionMessages => ({ stored: [], messages: [] }));
154
+ const tail = messages.slice(-TAIL_TURNS)
155
+ .map((m) => ` ${m.role}: ${m.content.slice(0, 200)}${m.content.length > 200 ? "…" : ""}`);
156
+ const text = messages.length === 0
157
+ ? "this session's buffer is empty."
158
+ : `this session: ${messages.length} message(s) in the buffer. Last turns:\n${tail.join("\n")}`;
159
+ return { lines, table, text };
160
+ }
@@ -0,0 +1,184 @@
1
+ // /tasks (E-1, A-3) — the session task list, and the agent instances of the dev crews. The task
2
+ // list is one JSON array in the state bag (add, done, clear; /clear empties it). The instances are
3
+ // the children a dev crew runs (the reviewer of /dev-plan, the auditor of dev-verify): the crew
4
+ // writes its run in the state bag while they run (shared/application/agents/child-agent.ts), and
5
+ // reads there the stop /tasks leaves for one of them, at its next look. A send to a running instance
6
+ // is refused; to an ended one it is a repair by a new run (crews/agent-run), whose brief carries the
7
+ // previous report: the entry point launches it and its completion prints the answer. A repair runs
8
+ // at the effort /effort holds now. The list also shows the tool approvals the background tasks wait
9
+ // on (Orkeon #198), read from the host: a task blocked on the operator reads as such.
10
+
11
+ import type { PendingApproval, PendingApprovals, SessionStore } from "../../../shared/application/ports.ts";
12
+ import { readJsonArray, writeJson } from "../../../shared/application/session-state.ts";
13
+ import { TASKS_STATE_KEY } from "../../../shared/domain/session-keys.ts";
14
+ import {
15
+ CHILD_CREWS, buildRepairBrief, describeInstance, instanceRows, locateInstance, parseRequest, parseSnapshot,
16
+ requestKey, sendVerdict, settleSnapshot, snapshotKey, stopVerdict,
17
+ } from "../../../shared/domain/agents/instances.ts";
18
+ import type { InstanceRequest, Located, RunSnapshot } from "../../../shared/domain/agents/instances.ts";
19
+ import { storedEffort } from "../effort.ts";
20
+ import type { CommandView } from "../view.ts";
21
+
22
+ export const TASKS_USAGE =
23
+ "usage: /tasks [list | add <subject> | done <n> | clear | show <id> | stop <id> | send <id> <message> | repair <id> [note]]";
24
+
25
+ /** The note a repair carries when the operator gives none. */
26
+ export const DEFAULT_REPAIR_NOTE = "Check your previous report against the brief again and correct what is wrong or missing.";
27
+
28
+ /** The crew that repairs an instance by a new run. */
29
+ export const REPAIR_CREW = "agent-run";
30
+
31
+ export interface TasksDeps {
32
+ session: Pick<SessionStore, "readState" | "writeState">;
33
+ clock: () => Date;
34
+ /** The tool approvals waiting for the operator, as the host shows them. */
35
+ approvals: PendingApprovals;
36
+ }
37
+
38
+ /** What to do with an approval listed: the answers the main prompt takes. */
39
+ export const ANSWER_TEXT = "answer it from the main prompt: [y] once / [s] session / [n] no";
40
+
41
+ /** What the entry point shows, and the crew it launches for a repair. */
42
+ export interface TasksOutcome {
43
+ view: CommandView;
44
+ launch?: { crew: string; input: Record<string, unknown>; details: Record<string, unknown> };
45
+ }
46
+
47
+ interface Task { subject: string; done: boolean }
48
+
49
+ async function readSnapshots({ session, clock }: TasksDeps): Promise<RunSnapshot[]> {
50
+ const read = async (crew: string) => {
51
+ try {
52
+ const s = parseSnapshot(await session.readState(snapshotKey(crew)));
53
+ return s === null ? null : settleSnapshot(s, clock());
54
+ } catch {
55
+ return null;
56
+ }
57
+ };
58
+ return (await Promise.all(CHILD_CREWS.map(read))).filter((s): s is RunSnapshot => s !== null);
59
+ }
60
+
61
+ /** One approval as the list shows it: the task's ticket and command (the status line's words), the tool, the input. */
62
+ const approvalLine = (a: PendingApproval): string =>
63
+ `${a.taskId === null ? "no task" : `${a.taskId} ${a.command ?? "?"}`}: waits for approval of ${a.tool} · ${a.input}`;
64
+
65
+ /** The approvals waiting, as lines; a host whose read fails shows none. */
66
+ function approvalLines({ approvals }: TasksDeps): string[] {
67
+ try {
68
+ return approvals.list().map(approvalLine);
69
+ } catch {
70
+ return [];
71
+ }
72
+ }
73
+
74
+ async function list(tasks: Task[], deps: TasksDeps): Promise<TasksOutcome> {
75
+ const rows = instanceRows(await readSnapshots(deps));
76
+ const waiting = approvalLines(deps);
77
+ const taskLines = tasks.map((t, i) => `#${i + 1} [${t.done ? "done" : "open"}] ${t.subject}`);
78
+ if (rows.length === 0 && waiting.length === 0) {
79
+ if (tasks.length === 0) return { view: { text: "no tasks and no agent instances. usage: /tasks add <subject>" } };
80
+ return { view: { table: tasks.map((t, i) => ({ n: i + 1, status: t.done ? "done" : "open", subject: t.subject })) } };
81
+ }
82
+ const lines = [tasks.length === 0 ? "tasks: none" : "tasks:", ...taskLines];
83
+ if (waiting.length > 0) lines.push("waiting for approval:", ...waiting);
84
+ if (rows.length === 0) return { view: { lines, text: ANSWER_TEXT } };
85
+ return {
86
+ view: {
87
+ lines: [...lines, "agent instances:"],
88
+ table: rows,
89
+ text: "/tasks show <id> · stop <id> · send <id> <message> · repair <id> [note]",
90
+ },
91
+ };
92
+ }
93
+
94
+ const ref = (l: Located) => `${l.snapshot.crew}:${l.record.id}`;
95
+
96
+ async function locate(deps: TasksDeps, id: string | undefined): Promise<{ ok: true; found: Located } | { ok: false; view: CommandView }> {
97
+ if (!id) return { ok: false, view: { text: TASKS_USAGE } };
98
+ const located = locateInstance(await readSnapshots(deps), id);
99
+ return located.ok ? located : { ok: false, view: { text: located.text } };
100
+ }
101
+
102
+ /** Leaves `request` for the crew, unless one of the same run it has not read yet is already there. */
103
+ async function leaveRequest(deps: TasksDeps, l: Located, request: InstanceRequest): Promise<string | null> {
104
+ const key = requestKey(l.snapshot.crew, l.record.id);
105
+ if (parseRequest(await deps.session.readState(key).catch(() => null))?.run === request.run) {
106
+ return `${ref(l)}: a request the crew has not read yet is already waiting; /tasks show ${l.record.id} once it has`;
107
+ }
108
+ await deps.session.writeState(key, JSON.stringify(request));
109
+ return null;
110
+ }
111
+
112
+ async function repair(deps: TasksDeps, l: Located, message: string): Promise<TasksOutcome> {
113
+ return {
114
+ view: {
115
+ lines: [`${ref(l)} has ended: a new run of ${l.record.charter} answers, with the previous report in its brief (not its live context).`],
116
+ },
117
+ launch: {
118
+ crew: REPAIR_CREW,
119
+ input: {
120
+ charter: l.record.charter, step: l.snapshot.step, system: l.record.system, brief: buildRepairBrief(l.record, message),
121
+ effort: await storedEffort(deps.session),
122
+ },
123
+ details: { instance: ref(l), charter: l.record.charter },
124
+ },
125
+ };
126
+ }
127
+
128
+ /** `/tasks …` from the command's raw tokens. */
129
+ export async function runTasks(tokens: readonly string[], deps: TasksDeps): Promise<TasksOutcome> {
130
+ const [sub, ...rest] = tokens;
131
+ const tasks = (await readJsonArray(deps.session, TASKS_STATE_KEY)) as Task[];
132
+ switch ((sub ?? "list").toLowerCase()) {
133
+ case "list":
134
+ return list(tasks, deps);
135
+ case "add": {
136
+ const subject = rest.join(" ");
137
+ if (!subject) return { view: { text: "usage: /tasks add <subject>" } };
138
+ tasks.push({ subject, done: false });
139
+ await writeJson(deps.session, TASKS_STATE_KEY, tasks);
140
+ return { view: { text: `task #${tasks.length} added: ${subject}` } };
141
+ }
142
+ case "done": {
143
+ const n = Number(rest[0]);
144
+ if (!Number.isInteger(n) || n < 1 || n > tasks.length) return { view: { text: `usage: /tasks done <1-${tasks.length || 1}>` } };
145
+ tasks[n - 1].done = true;
146
+ await writeJson(deps.session, TASKS_STATE_KEY, tasks);
147
+ return { view: { text: `task #${n} done: ${tasks[n - 1].subject}` } };
148
+ }
149
+ case "clear":
150
+ await writeJson(deps.session, TASKS_STATE_KEY, []);
151
+ return { view: { text: `task list cleared (${tasks.length} removed).` } };
152
+ case "show": {
153
+ const l = await locate(deps, rest[0]);
154
+ return l.ok ? { view: { lines: describeInstance(l.found) } } : { view: l.view };
155
+ }
156
+ case "stop": {
157
+ const l = await locate(deps, rest[0]);
158
+ if (!l.ok) return { view: l.view };
159
+ const verdict = stopVerdict(l.found);
160
+ if (!verdict.ok) return { view: { text: verdict.text } };
161
+ const waiting = await leaveRequest(deps, l.found, { action: "stop", run: l.found.snapshot.startedAt, at: deps.clock().toISOString() });
162
+ return { view: { text: waiting ?? `stop asked for ${ref(l.found)}: the crew ends it at its next look (about a second); /tasks shows it` } };
163
+ }
164
+ case "send": {
165
+ const l = await locate(deps, rest[0]);
166
+ if (!l.ok) return { view: l.view };
167
+ const message = rest.slice(1).join(" ").trim();
168
+ if (!message) return { view: { text: "usage: /tasks send <id> <message>" } };
169
+ const verdict = sendVerdict(l.found);
170
+ if (verdict.kind === "refused") return { view: { text: verdict.text } };
171
+ return repair(deps, l.found, message);
172
+ }
173
+ case "repair": {
174
+ const l = await locate(deps, rest[0]);
175
+ if (!l.ok) return { view: l.view };
176
+ if (l.found.record.state === "running") {
177
+ return { view: { text: `${ref(l.found)} is running: a repair is for an ended instance (/tasks stop ${l.found.record.id} first)` } };
178
+ }
179
+ return repair(deps, l.found, rest.slice(1).join(" ").trim() || DEFAULT_REPAIR_NOTE);
180
+ }
181
+ default:
182
+ return { view: { text: TASKS_USAGE } };
183
+ }
184
+ }
@@ -0,0 +1,80 @@
1
+ // /advisor: show, set or disable the advisor model (the /config key advisor.model), or ask for the second
2
+ // opinion it exists for. Only `review` (or `run`) costs an LLM call: it answers `{ launch: true }` and the
3
+ // command starts the advisor crew; every other form answers the lines the command prints.
4
+ //
5
+ // The model is checked against the host's declared catalogue and warned about, not refused:
6
+ // `Llm:AvailableModels` is a hand-written hint that can lag the provider (same rule as /model).
7
+ import { CONFIG_FILE_PATH } from "../../../shared/application/config-store.ts";
8
+ import type { ConfigStore } from "../../../shared/application/config-store.ts";
9
+ import type { Logger, SessionMetadata, Telemetry } from "../../../shared/application/ports.ts";
10
+ import { judgeModelChoice } from "../../../shared/domain/model-catalog.ts";
11
+
12
+ const ADVISOR_KEY = "advisor.model";
13
+
14
+ export interface AdvisorDeps {
15
+ config: Pick<ConfigStore, "readValue" | "readFile" | "writeFile">;
16
+ telemetry: Pick<Telemetry, "readMetadata">;
17
+ log: Pick<Logger, "warn">;
18
+ }
19
+
20
+ export type AdvisorOutcome = { launch: true } | { lines: string[] };
21
+
22
+ async function declaredModels(telemetry: AdvisorDeps["telemetry"]): Promise<string[]> {
23
+ const md = await telemetry.readMetadata().catch((): SessionMetadata => ({}));
24
+ return md.availableModels ?? [];
25
+ }
26
+
27
+ /** `/advisor [show | off | review | <model>]`, from the command's raw tokens. */
28
+ export async function runAdvisorCommand(tokens: readonly string[], deps: AdvisorDeps): Promise<AdvisorOutcome> {
29
+ const { config, telemetry } = deps;
30
+ const first = (tokens[0] ?? "").toLowerCase();
31
+
32
+ // `review` is the only path that costs an LLM call, so it is explicit — a bare
33
+ // /advisor shows the setting and spends nothing.
34
+ if (first === "review" || first === "run") return { launch: true };
35
+
36
+ if (tokens.length === 0 || first === "show") {
37
+ const entry = await config.readValue(ADVISOR_KEY);
38
+ const models = await declaredModels(telemetry);
39
+ const lines = [
40
+ entry.value
41
+ ? `advisor model: ${entry.value} [${entry.source}]`
42
+ : "advisor model: (unset) — /advisor review would ask the SESSION's own model, " +
43
+ "which makes it a self-review and worth much less.",
44
+ ];
45
+ if (models.length > 0) lines.push(`declared models: ${models.join(", ")}`);
46
+ lines.push("usage: /advisor <model> | /advisor off | /advisor review");
47
+ return { lines };
48
+ }
49
+
50
+ if (first === "off" || first === "disable" || first === "none") {
51
+ const { map, malformed } = await config.readFile();
52
+ if (malformed) return { lines: [`refusing to write: ${CONFIG_FILE_PATH} could not be parsed.`] };
53
+ delete map[ADVISOR_KEY];
54
+ await config.writeFile(map);
55
+ return { lines: ["advisor model disabled — /advisor review falls back to the session's own model."] };
56
+ }
57
+
58
+ // Anything else is the model name.
59
+ const requested = tokens.join(" ").trim();
60
+ const verdict = judgeModelChoice(await declaredModels(telemetry), requested);
61
+ if (verdict.warning) deps.log.warn(verdict.warning);
62
+
63
+ const { map, malformed } = await config.readFile();
64
+ if (malformed) {
65
+ return {
66
+ lines: [
67
+ `refusing to write: ${CONFIG_FILE_PATH} exists but could not be parsed, and overwriting ` +
68
+ "it would discard whatever it holds. Fix or delete it, then retry.",
69
+ ],
70
+ };
71
+ }
72
+ map[ADVISOR_KEY] = requested;
73
+ await config.writeFile(map);
74
+ return {
75
+ lines: [
76
+ `advisor model set to '${requested}' — persisted in ${CONFIG_FILE_PATH}.` +
77
+ (verdict.warning ? "\n⚠ NOT among the models this host declares; see the log." : ""),
78
+ ],
79
+ };
80
+ }
@@ -0,0 +1,147 @@
1
+ // /agents (B-12) — list, create, edit and delete saved agent configurations
2
+ // (baseline 04 §/agents: "…stored in `.orkeon/agents.json`").
3
+ //
4
+ // A FILE, not session state: a saved agent is meant to outlive the session, so
5
+ // /clear must not take someone's definitions with it. It sits beside
6
+ // config.json (B-6) under /workspace/.orkeon/, hand-editable on purpose.
7
+ //
8
+ // The listing merges two sources and labels them, because only one is mutable:
9
+ // the crews discovered by the host (what actually runs today) and this file.
10
+ // `edit` is `add` over an existing name — a REPL one-liner is a poor field editor,
11
+ // and an overwrite that says "replaced" is clearer than a partial patch.
12
+ //
13
+ // Note on scope: Orkeon Code does not DISPATCH a saved agent: no command turns a
14
+ // definition into a running agent, so the registry is honest storage, and the
15
+ // command says so rather than implying a launch. What does run as an agent is
16
+ // listed beside it: the built-in charters (A-3), each a background child of its
17
+ // dev step (the reviewer of /dev-plan, the auditor of the audit), which /tasks
18
+ // lists, stops, sends to and repairs.
19
+
20
+ import type { CrewHost, Files } from "../../../shared/application/ports.ts";
21
+ import { readJsonFile, writeJsonFile } from "../../../shared/application/json-file.ts";
22
+ import {
23
+ parseAgentRegistry, serializeAgentRegistry, validateSavedAgent,
24
+ upsertAgent, removeAgent, describeAgentRows,
25
+ } from "../../../shared/domain/agent-registry.ts";
26
+ import type { SavedAgent } from "../../../shared/domain/agent-registry.ts";
27
+ import { builtInCharterRows } from "../../../shared/domain/agents/built-in-charters.ts";
28
+ import type { CommandView } from "../view.ts";
29
+ import { WORKSPACE } from "../../../shared/domain/vfs.ts";
30
+
31
+ export const AGENTS_FILE_PATH = `${WORKSPACE}/.orkeon/agents.json`;
32
+
33
+ export const AGENTS_USAGE =
34
+ "usage: /agents [list] | add <name> <role> | <goal> | remove <name> | show <name>";
35
+
36
+ /** What the listing says of the saved agents, and of what runs instead. */
37
+ export const SAVED_AGENTS_NOTE =
38
+ "saved agents are storage only — no command runs one; the built-in charters run as children of /dev-spec, /dev-plan and /dev-batches (/tasks).";
39
+
40
+ export interface AgentsDeps {
41
+ files: Pick<Files, "read" | "write">;
42
+ crews: Pick<CrewHost, "listCrews">;
43
+ }
44
+
45
+ /** The same reading as config-store (B-6): absent is empty, and a file that could
46
+ * not be parsed — as JSON, or as a registry — is flagged so that nothing writes
47
+ * over it. */
48
+ async function readRegistry(
49
+ files: Pick<Files, "read">,
50
+ ): Promise<{ agents: SavedAgent[]; dropped: string[]; malformed: boolean }> {
51
+ const { value, malformed } = await readJsonFile(files, AGENTS_FILE_PATH);
52
+ if (malformed) return { agents: [], dropped: [], malformed: true };
53
+ try {
54
+ return { ...parseAgentRegistry(value), malformed: false };
55
+ } catch {
56
+ // An entry whose fields cannot even be read as text (`{"toString":1}`).
57
+ return { agents: [], dropped: [], malformed: true };
58
+ }
59
+ }
60
+
61
+ async function writeRegistry(files: Pick<Files, "write">, agents: readonly SavedAgent[]): Promise<void> {
62
+ await writeJsonFile(files, AGENTS_FILE_PATH, serializeAgentRegistry(agents));
63
+ }
64
+
65
+ /** `/agents [list|show|add|edit|remove|delete] …`, from the command's raw tokens. */
66
+ export async function runAgents(tokens: string[], deps: AgentsDeps): Promise<CommandView> {
67
+ const { files } = deps;
68
+ const sub = (tokens[0] ?? "list").toLowerCase();
69
+ const crews = deps.crews.listCrews();
70
+
71
+ switch (sub) {
72
+ case "list": {
73
+ const { agents, dropped, malformed } = await readRegistry(files);
74
+ const notes = [`file: ${AGENTS_FILE_PATH} (survives /clear)`];
75
+ if (dropped.length > 0) {
76
+ notes.push(`⚠ ${dropped.length} stored entr(y/ies) ignored — missing role or goal: ${dropped.join(", ")}`);
77
+ }
78
+ if (malformed) notes.push(`⚠ ${AGENTS_FILE_PATH} could not be parsed; it is left untouched.`);
79
+ notes.push(SAVED_AGENTS_NOTE);
80
+ return { table: [...describeAgentRows(crews, agents), ...builtInCharterRows()], text: notes.join("\n") };
81
+ }
82
+
83
+ case "show": {
84
+ const name = String(tokens[1] ?? "").trim().toLowerCase();
85
+ const { agents } = await readRegistry(files);
86
+ const found = agents.find((a) => a.name === name);
87
+ if (found) {
88
+ return {
89
+ text: `${found.name}\n role : ${found.role}\n goal : ${found.goal}\n` +
90
+ ` tools: ${found.tools.length > 0 ? found.tools.join(", ") : "(inherited from the crew)"}`,
91
+ };
92
+ }
93
+ if (crews.some((c) => c.toLowerCase() === name)) {
94
+ return { text: `'${name}' is a built-in crew (crews/${name}/), not a saved agent — see its crew.ork.ts.` };
95
+ }
96
+ return { text: `no saved agent '${name}'. /agents list shows what there is.` };
97
+ }
98
+
99
+ case "add":
100
+ case "edit": {
101
+ // `add <name> <role> | <goal>` — the pipe separates two free-text fields, so
102
+ // neither has to be quoted in a REPL line.
103
+ const rest = tokens.slice(1).join(" ");
104
+ const [head, ...goalParts] = rest.split("|");
105
+ const headTokens = head.trim().split(/\s+/).filter(Boolean);
106
+ const name = headTokens.shift() ?? "";
107
+ const verdict = validateSavedAgent({
108
+ name,
109
+ role: headTokens.join(" "),
110
+ goal: goalParts.join("|").trim(),
111
+ });
112
+ if (!verdict.ok) return { text: `${verdict.reason}\n${AGENTS_USAGE}` };
113
+
114
+ const { agents, malformed } = await readRegistry(files);
115
+ if (malformed) {
116
+ return {
117
+ text: `refusing to write: ${AGENTS_FILE_PATH} exists but could not be parsed, and overwriting ` +
118
+ "it would discard whatever it holds. Fix or delete it, then retry.",
119
+ };
120
+ }
121
+ const { agents: next, replaced } = upsertAgent(agents, verdict.agent);
122
+ await writeRegistry(files, next);
123
+ return { text: `agent '${verdict.agent.name}' ${replaced ? "replaced" : "saved"} in ${AGENTS_FILE_PATH}.` };
124
+ }
125
+
126
+ case "remove":
127
+ case "delete": {
128
+ const name = String(tokens[1] ?? "").trim();
129
+ if (name.length === 0) return { text: AGENTS_USAGE };
130
+ const { agents, malformed } = await readRegistry(files);
131
+ if (malformed) return { text: `refusing to write: ${AGENTS_FILE_PATH} could not be parsed.` };
132
+ const { agents: next, removed } = removeAgent(agents, name);
133
+ if (!removed) {
134
+ return {
135
+ text: crews.some((c) => c.toLowerCase() === name.toLowerCase())
136
+ ? `'${name}' is a built-in crew — it is not stored here and cannot be removed with /agents.`
137
+ : `no saved agent '${name}'.`,
138
+ };
139
+ }
140
+ await writeRegistry(files, next);
141
+ return { text: `agent '${name}' removed from ${AGENTS_FILE_PATH}.` };
142
+ }
143
+
144
+ default:
145
+ return { text: AGENTS_USAGE };
146
+ }
147
+ }