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,142 @@
1
+ // The start of a dev step, in its command's dispatch: the host's gate must be on, then the gate is
2
+ // handed the session's rules and the step's rule sets (shared/domain/dev/step-rules.ts), just before
3
+ // the crew is launched; the /hooks registry is read for the crew's input (its tool callbacks run the hooks). Not a
4
+ // command file: the loader reads *.cmd.ts only.
5
+ import type { PermissionRules, SessionStore, ToolCatalogue } from "../../shared/application/ports.ts";
6
+ import type { SessionIo } from "../../shared/application/session-io.ts";
7
+ import type { ConfigStore } from "../../shared/application/config-store.ts";
8
+ import { configuredNames, resolveExtraTools } from "../../shared/application/extra-tools.ts";
9
+ import { syncStepRules } from "../../shared/application/permission-rules.ts";
10
+ import { readMemoryDir } from "../../shared/application/shared-memory/memory-settings.ts";
11
+ import { memoryWriteRules } from "../../shared/domain/shared-memory/layout.ts";
12
+ import { readJsonArray } from "../../shared/application/session-state.ts";
13
+ import { HOOKS_STATE_KEY } from "../../shared/domain/session-keys.ts";
14
+ import { deniesEveryCall, formatRule } from "../../shared/domain/agent-policy/permission.ts";
15
+ import { parseSessionRules } from "../../shared/domain/git/pull-request.ts";
16
+ import type { RuleSetId } from "../../shared/domain/agent-policy/rule-sets.ts";
17
+ import { STEP_RULE_SETS, gateProblem, stepCommand, stepRules } from "../../shared/domain/dev/step-rules.ts";
18
+ import type { DevStep } from "../../shared/domain/dev/step-rules.ts";
19
+ import { isCode } from "../../shared/domain/dev/artefacts.ts";
20
+ import { policyFor } from "../../shared/domain/agent-policy/mode-policy.ts";
21
+ import { isPermissionMode } from "../../shared/domain/permission-modes.ts";
22
+ import type { ActiveWorkflow } from "../../shared/domain/workflow/state-file.ts";
23
+ import { writeActiveWorkflow } from "../../shared/application/workflow/workflow-state.ts";
24
+
25
+ export interface DevStepDeps {
26
+ session: Pick<SessionStore, "readState">;
27
+ gate: PermissionRules;
28
+ config: Pick<ConfigStore, "readValue" | "readFile">;
29
+ catalogue: Pick<ToolCatalogue, "find">;
30
+ }
31
+
32
+ export type DevStepStart =
33
+ | {
34
+ ok: true; lines: string[]; sets: readonly RuleSetId[]; rules: number; hooks: unknown[];
35
+ /** What the crew's input carries besides the step's own arguments: the /hooks registry, and
36
+ * `memoryRecall: false` when a rule in the gate denies every call of memory_recall. */
37
+ input: { hooks: unknown[]; memoryRecall?: false };
38
+ }
39
+ | { ok: false; line: string };
40
+
41
+ /** The step dev-verify runs: none with --gate-only, which runs no model. */
42
+ export function devVerifyStep(args: { gateOnly: boolean }): DevStep | null {
43
+ return args.gateOnly ? null : "dev-verify";
44
+ }
45
+
46
+ /** Refuses when the host says its gate is off; otherwise puts the session's rules, then the step's
47
+ * rule sets, in the gate, and returns the warning lines the command prints before launching and the
48
+ * /hooks registry the crew's input carries. */
49
+ export async function startDevStep(step: DevStep, deps: DevStepDeps): Promise<DevStepStart> {
50
+ const problem = gateProblem(deps.gate.enabled(), step);
51
+ if (problem?.refuse) return { ok: false, line: problem.line };
52
+ const lines = problem ? [problem.line] : [];
53
+ const extras = await resolveExtraTools(deps);
54
+ const sync = await syncStepRules({
55
+ session: deps.session, gate: deps.gate, extraNames: configuredNames(extras), rules: stepRules(step),
56
+ builtIn: memoryWriteRules((await readMemoryDir(deps.config)).dir),
57
+ });
58
+ if (!sync.applied) {
59
+ lines.push(`warning: the host keeps no session rules: /${stepCommand(step)}'s rule sets are not in the host's gate, the crew's callback alone checks them.`);
60
+ }
61
+ for (const r of sync.overridden) {
62
+ lines.push(`warning: the session's rule '${formatRule(r)}' is left out of the gate during /${stepCommand(step)}: the step denies the same calls.`);
63
+ }
64
+ const hooks = await readJsonArray(deps.session, HOOKS_STATE_KEY);
65
+ const memoryDenied = deniesEveryCall(gateRules(deps.gate), "memory_recall");
66
+ return {
67
+ ok: true, lines, sets: STEP_RULE_SETS[step], rules: sync.step.length, hooks,
68
+ input: { hooks, ...(memoryDenied ? { memoryRecall: false as const } : {}) },
69
+ };
70
+ }
71
+
72
+ /** The rules in the gate, parsed; none when the host keeps none. */
73
+ function gateRules(gate: PermissionRules) {
74
+ try {
75
+ return gate.available() ? parseSessionRules(gate.list()) : [];
76
+ } catch {
77
+ return [];
78
+ }
79
+ }
80
+
81
+ /**
82
+ * The line refusing a step that writes files when the session's mode is read-only, or could not be read (`""`:
83
+ * a step never writes on a mode it does not know); null when it may run. `writes` says what the step writes.
84
+ */
85
+ export function writeModeRefusal(mode: string, step: string, writes: string): string | null {
86
+ if (mode === "") return `✗ refused: the session mode could not be read, and /${stepCommand(step)} ${writes}: run it again`;
87
+ if (!isPermissionMode(mode)) return `✗ refused: the session mode ${mode} is not one Orkeon Code knows, and /${stepCommand(step)} ${writes}: /mode default, then run it again`;
88
+ if (!policyFor(mode).readOnly) return null;
89
+ return `✗ refused: the session mode ${mode} is read-only, and /${stepCommand(step)} ${writes}: /mode default, then run it again`;
90
+ }
91
+
92
+ /** writeModeRefusal over the session's effective mode, read here: a read that fails refuses. */
93
+ export async function readWriteModeRefusal(
94
+ session: Pick<SessionIo, "resolveEffectiveSessionMode">, step: string, writes: string,
95
+ ): Promise<string | null> {
96
+ let mode = "";
97
+ try {
98
+ mode = String((await session.resolveEffectiveSessionMode()).mode ?? "");
99
+ } catch { /* unknown: refused below */ }
100
+ return writeModeRefusal(mode, step, writes);
101
+ }
102
+
103
+ /** Before a launch of dev-implement's chain (the audit, then the close), which runs no dispatch of its own: the
104
+ * gate must still be on, and the step's rules are put back on top of whatever the gate holds (an /assistant turn
105
+ * in between hands it the session's rules alone). The gate is not cleared: the rules an earlier hop added stay
106
+ * until the next sync (the next command, the next /assistant turn): an earlier hop's allows with them, but the
107
+ * gate puts every deny before an allow, so this step's denies still win. The session's own rules and mode are read
108
+ * again by the hop itself (readPullRequestContext, Orkeon #220) and handed to the crew. Null when the
109
+ * launch may go, else the line refusing it. */
110
+ export function reapplyStepRules(gate: PermissionRules, step: DevStep): string | null {
111
+ const problem = gateProblem(gate.enabled(), step);
112
+ if (problem?.refuse) return problem.line;
113
+ if (!gate.available()) return null;
114
+ for (const rule of stepRules(step)) gate.add(rule);
115
+ return null;
116
+ }
117
+
118
+ /** The batch a step works on, for the state file a compaction writes: the code is the plan
119
+ * token when it is a code, the folder of a `.../<CODE>-PLAN.md` path, else null (the writer
120
+ * then looks for the batch's open sheet). */
121
+ export function activeWorkflowOf(args: { batch: string; plan: string | null }): ActiveWorkflow {
122
+ const plan = args.plan;
123
+ if (plan === null) return { code: null, phase: args.batch };
124
+ if (!plan.endsWith("-PLAN.md")) return { code: isCode(plan) ? plan : null, phase: args.batch };
125
+ const parts = plan.replace(/\\/g, "/").split("/").filter((p) => p.length > 0);
126
+ const folder = parts.length >= 2 ? parts[parts.length - 2] : "";
127
+ return { code: isCode(folder) ? folder : null, phase: args.batch };
128
+ }
129
+
130
+ /** Records the batch in progress in the session; a session that cannot keep it costs the
131
+ * state file only, so the failure comes back as a warning line, never a refusal. */
132
+ export async function markActiveWorkflow(
133
+ session: Pick<SessionStore, "writeState">, args: { batch: string; plan: string | null },
134
+ ): Promise<string | null> {
135
+ try {
136
+ await writeActiveWorkflow(session, activeWorkflowOf(args));
137
+ return null;
138
+ } catch (error) {
139
+ const reason = error instanceof Error ? error.message : String(error);
140
+ return `warning: the batch in progress could not be recorded (${reason}): a compaction will write no state file for it.`;
141
+ }
142
+ }
@@ -0,0 +1,231 @@
1
+ // Presentation helpers shared by the slash-command handlers. Kept under
2
+ // commands/_lib/ — the loader's SearchPattern is "*.cmd.ts", so this file is
3
+ // never loaded as a command (it is only bundled into the handlers that import
4
+ // it). No domain logic here; just the control-plane glue (SPEC §2). The entry
5
+ // point wires the crew host and the permission gate from its context
6
+ // (createCrewHost(ctx.services), createPermissionRules(ctx.services)) and hands
7
+ // them over with the command's log.
8
+
9
+ import type { CrewHost, CrewLaunchOptions, PermissionRules, ToolCatalogue } from "../../shared/application/ports.ts";
10
+ import type { ConfigStore } from "../../shared/application/config-store.ts";
11
+ import type { SessionIo } from "../../shared/application/session-io.ts";
12
+ import { configuredNames, resolveExtraTools } from "../../shared/application/extra-tools.ts";
13
+ import { readLlmProfile } from "../../shared/application/llm-profile.ts";
14
+ import { syncPermissionRules } from "../../shared/application/permission-rules.ts";
15
+ import { readMemoryDir } from "../../shared/application/shared-memory/memory-settings.ts";
16
+ import { memoryWriteRules } from "../../shared/domain/shared-memory/layout.ts";
17
+ import { formatRule } from "../../shared/domain/agent-policy/permission.ts";
18
+ import { chainDepthLine, chainDepthRefusal } from "../../shared/domain/agents/chain.ts";
19
+ import { exclusiveLine, exclusiveRefusal } from "../../shared/domain/agents/exclusive.ts";
20
+ import { LLM_PROFILE_INPUT_KEY } from "../../shared/domain/llm-profile.ts";
21
+ import { errorText } from "../../shared/domain/prelude.ts";
22
+ import type { EpilogueCall, PreludeCall } from "../../shared/domain/prelude.ts";
23
+ import type { StartOutput } from "../../shared/domain/session-start.ts";
24
+ import { SPEAK_TOOL, VOICE_REPLY_CONFIG_KEY, voiceReplyEpilogue, voiceReplyOn } from "../../shared/domain/speech.ts";
25
+ import {
26
+ EXTRA_TOOLS_CONFIG_KEY, EXTRA_TOOL_ENTRY_RULE, formatExtraTool,
27
+ } from "../../shared/domain/agent-policy/extra-tools.ts";
28
+
29
+ /** The command's log as the runtime hands it to a command: a line and its details. */
30
+ export interface CommandLog {
31
+ info(message: string, data?: object): void;
32
+ warn(message: string, data?: object): void;
33
+ }
34
+
35
+ /** What a crew launch needs: the host that runs crews, the command's log, and the session's `llm.profile` when
36
+ * the command read it (withLlmProfile): the crew input then carries it as `llmProfile`, and every agent of the
37
+ * crew runs on that profile. Undefined or null, the input carries nothing and the agents run on the host's default model. */
38
+ export interface LaunchDeps {
39
+ crews: Pick<CrewHost, "launch">;
40
+ log: Pick<CommandLog, "info">;
41
+ llmProfile?: string | null;
42
+ }
43
+
44
+ /** `deps` with the session's `llm.profile` read: what every command hands launchCrew. A setting that cannot be
45
+ * read, or holds no profile name, is warned about and the launch goes on without it. */
46
+ export async function withLlmProfile<D extends LaunchDeps & { log: Pick<CommandLog, "warn"> }>(
47
+ deps: D, config: Pick<ConfigStore, "readValue" | "readFile">,
48
+ ): Promise<D & { llmProfile: string | null }> {
49
+ const read = await readLlmProfile(config);
50
+ if (read.warning !== undefined) deps.log.warn(read.warning);
51
+ return { ...deps, llmProfile: read.profile };
52
+ }
53
+
54
+ /** A crew's completion, as an async command's `completed` receives it; `intent` names the crew that answered,
55
+ * `streamed` says the console already showed the answer as it was generated (Orkeon #228). */
56
+ export interface CrewCompletion {
57
+ success: boolean;
58
+ intent?: string;
59
+ payload?: string;
60
+ error?: string;
61
+ streamed?: boolean;
62
+ }
63
+
64
+ /** What a launch hands back to the runtime: the ticket, or the refusal of a hop past MaxChainDepth or of a crew
65
+ * already running; the runtime prints `message`. */
66
+ export type LaunchResult = { ticket: string } | { refused: string; message: string };
67
+
68
+ /** Launch a crew on the script-host and return its ticket (async commands). The
69
+ * launch is logged with the ticket, plus `details` when the caller has any. A
70
+ * launch from a `completed` past the chain's limit (V-A5, shared/domain/agents/chain.ts,
71
+ * `chain depth <d> reached (MaxChainDepth <l>, /<command>)`) comes back as `{ refused }`
72
+ * with the line saying so, as does a crew launched with `{ exclusive: true }` while its
73
+ * previous launch runs (Orkeon #239, shared/domain/agents/exclusive.ts, `crew '<name>'
74
+ * already running (ticket <t>)`); any other failure throws. A driver relaunching its own
75
+ * work passes `{ chain: "continue" }` as `options` (Orkeon #221) and keeps the parent's depth. */
76
+ export function launchCrew(
77
+ deps: LaunchDeps,
78
+ crew: string,
79
+ input: Record<string, unknown> = {},
80
+ details: Record<string, unknown> = {},
81
+ options?: CrewLaunchOptions,
82
+ ): LaunchResult {
83
+ const profile = deps.llmProfile ?? null;
84
+ if (profile !== null) {
85
+ input = { ...input, [LLM_PROFILE_INPUT_KEY]: profile };
86
+ details = { ...details, llmProfile: profile };
87
+ }
88
+ let ticket: string;
89
+ try {
90
+ ticket = deps.crews.launch(crew, input, options);
91
+ } catch (error) {
92
+ const busy = exclusiveRefusal(error);
93
+ if (busy !== null) {
94
+ const line = exclusiveLine(busy);
95
+ deps.log.info(line, { ...busy, ...details });
96
+ return { refused: line, message: line };
97
+ }
98
+ const refusal = chainDepthRefusal(error);
99
+ if (refusal === null) throw error;
100
+ const line = chainDepthLine(crew, refusal);
101
+ deps.log.info(line, { ...refusal, ...details });
102
+ return { refused: line, message: line };
103
+ }
104
+ deps.log.info(crew + " launched", { ticket, ...details });
105
+ return { ticket };
106
+ }
107
+
108
+ /** What launching the main loop reads: the session (its mode and rules), the
109
+ * `tools.extra` setting and the tools the host registers; and what it drives:
110
+ * the host's permission gate and the crew launch. */
111
+ export interface MainLoopLaunchDeps extends LaunchDeps {
112
+ log: CommandLog;
113
+ session: Pick<SessionIo, "readState" | "resolveEffectiveSessionMode">;
114
+ config: Pick<ConfigStore, "readValue" | "readFile">;
115
+ catalogue: Pick<ToolCatalogue, "find">;
116
+ gate: PermissionRules;
117
+ }
118
+
119
+ /**
120
+ * Launch the main loop with everything that decides its tool catalogue, which
121
+ * the crew builds at load time, synchronously, from its inputs alone:
122
+ * - the mode: the request's `mode:` prefix, else the session's (/mode, else the
123
+ * fallback), resolved here, with where it came from for the crew to log;
124
+ * - the extra tools the host registers, each configured one it does not
125
+ * register warned about and left out;
126
+ * - the session's rules, handed to the host gate first, so the turn runs under
127
+ * the rules the session holds whatever the gate kept from an earlier command,
128
+ * then the built-in denies on the shared memory's candidates and entries.
129
+ * A `prelude` (a tool call the crew makes before the turn: /transcribe --then,
130
+ * /voice --go) rides along as it is. With voice.reply on, an epilogue has the crew read the
131
+ * answer aloud with the speech server's speak, when the host registers it. The start
132
+ * script's output (`sessionStart`, the first turn of a session) rides along too.
133
+ */
134
+ export async function launchMainLoop(
135
+ deps: MainLoopLaunchDeps,
136
+ input: { prompt: string; permissionMode: string | null; prelude?: PreludeCall; sessionStart?: StartOutput | null },
137
+ ): Promise<LaunchResult> {
138
+ const { session, log } = deps;
139
+ const resolved = input.permissionMode === null ? await session.resolveEffectiveSessionMode() : null;
140
+ const permissionMode = resolved ? resolved.mode : input.permissionMode;
141
+
142
+ const extras = await resolveExtraTools(deps);
143
+ for (const tool of extras.missing) {
144
+ log.warn(
145
+ `extra tool '${tool.name}' is not registered by the host and is left out ` +
146
+ "(its MCP server did not connect, its plugin did not load, or the name is mistyped)",
147
+ );
148
+ }
149
+ for (const entry of extras.invalid) {
150
+ log.warn(`${EXTRA_TOOLS_CONFIG_KEY}: '${entry}' is ignored (${EXTRA_TOOL_ENTRY_RULE})`);
151
+ }
152
+ if (extras.unreadable !== undefined) {
153
+ log.warn(`${EXTRA_TOOLS_CONFIG_KEY} could not be read (${extras.unreadable}): no extra tool this turn`);
154
+ }
155
+
156
+ const builtIn = memoryWriteRules((await readMemoryDir(deps.config)).dir);
157
+ const sync = await syncPermissionRules({ session, gate: deps.gate, extraNames: configuredNames(extras), builtIn });
158
+ for (const rule of sync.overridden) {
159
+ log.warn(`permission rule '${formatRule(rule)}' is left out of the gate: no tool of the model writes the shared memory's candidates or entries`);
160
+ }
161
+ for (const rule of sync.dormant) {
162
+ log.warn(
163
+ `permission rule '${rule}' is dormant: ${EXTRA_TOOLS_CONFIG_KEY} does not list its tool, the gate does not get it`,
164
+ );
165
+ }
166
+ if (sync.invalid.length > 0) {
167
+ log.warn(`${sync.invalid.length} stored permission entr(ies) are not rules and were ignored`);
168
+ }
169
+ if (!sync.applied) log.warn("the host keeps no session rules: the gate decides each call from the mode alone");
170
+ const epilogue = await voiceReply(deps);
171
+ const profiled = deps.llmProfile === undefined ? await withLlmProfile(deps, deps.config) : deps;
172
+ return launchCrew(
173
+ profiled,
174
+ "main-loop",
175
+ {
176
+ prompt: input.prompt,
177
+ permissionMode,
178
+ ...(resolved ? { permissionModeVia: resolved.via } : {}),
179
+ permissionRules: sync.rules.map(formatRule),
180
+ extraTools: extras.present.map(formatExtraTool),
181
+ ...(input.prelude ? { prelude: input.prelude } : {}),
182
+ ...(epilogue ? { epilogue } : {}),
183
+ ...(input.sessionStart ? { sessionStart: input.sessionStart } : {}),
184
+ },
185
+ {
186
+ permissionMode, permissionRules: sync.rules.length, extraTools: extras.present.length,
187
+ ...(input.prelude ? { prelude: input.prelude.tool } : {}),
188
+ ...(epilogue ? { epilogue: epilogue.tool } : {}),
189
+ ...(input.sessionStart ? { sessionStartLines: input.sessionStart.lines.length } : {}),
190
+ },
191
+ { onMain: true },
192
+ );
193
+ }
194
+
195
+ /** The epilogue voice.reply asks for: speak under its registered name when the setting
196
+ * is on and the host registers it; none otherwise, with a warning when it is on. */
197
+ async function voiceReply(deps: Pick<MainLoopLaunchDeps, "config" | "catalogue" | "log">): Promise<EpilogueCall | undefined> {
198
+ let value: string | undefined;
199
+ try {
200
+ value = (await deps.config.readValue(VOICE_REPLY_CONFIG_KEY)).value;
201
+ } catch (error) {
202
+ deps.log.warn(`${VOICE_REPLY_CONFIG_KEY} could not be read (${errorText(error)}): the answer is not read aloud this turn`);
203
+ return undefined;
204
+ }
205
+ if (!voiceReplyOn(value)) return undefined;
206
+ const speak = deps.catalogue.find(SPEAK_TOOL);
207
+ if (speak === undefined) {
208
+ deps.log.warn(
209
+ `${VOICE_REPLY_CONFIG_KEY} is on but the host registers no '${SPEAK_TOOL}': the answer is not read aloud ` +
210
+ "(start orkeon-code with ORKEON_CODE_AUDIO_DIR and ORKEON_CODE_VOICE=1)",
211
+ );
212
+ return undefined;
213
+ }
214
+ return voiceReplyEpilogue(speak);
215
+ }
216
+
217
+ /** Write a crew-completion line: `<okPrefix><payload>` or `✗ <label> failed: …`; nothing for a success the console
218
+ * already streamed, or the answer would show twice (Orkeon #228). */
219
+ export function writeCompleted(
220
+ out: { writeLine(text: string): void },
221
+ result: CrewCompletion,
222
+ label: string,
223
+ okPrefix = "",
224
+ ): void {
225
+ if (result.success && result.streamed === true) return;
226
+ out.writeLine(
227
+ result.success
228
+ ? okPrefix + result.payload
229
+ : "✗ " + label + " failed: " + (result.error ?? "unknown"),
230
+ );
231
+ }
@@ -0,0 +1,15 @@
1
+ // The effort level a command hands its crew (A-3): the one /effort stored, which the crew forwards to the
2
+ // provider (`act({effort})`, AgentBuilder.effort); null when none is stored or the session cannot say, so an
3
+ // unconfigured session turns no thinking on.
4
+ import type { SessionIo } from "../../shared/application/session-io.ts";
5
+ import { EFFORT_STATE_KEY } from "../../shared/domain/session-keys.ts";
6
+ import { providerEffort } from "../../shared/domain/agent-policy/behavior-flags.ts";
7
+ import type { EffortLevel } from "../../shared/domain/agent-policy/behavior-flags.ts";
8
+
9
+ export async function storedEffort(session: Pick<SessionIo, "readState">): Promise<EffortLevel | null> {
10
+ try {
11
+ return providerEffort(await session.readState(EFFORT_STATE_KEY)) ?? null;
12
+ } catch {
13
+ return null;
14
+ }
15
+ }
@@ -0,0 +1,95 @@
1
+ // /branch — the uncommitted-changes guard, and the validation of a branch name
2
+ // before it reaches the shell (B-11 deepening); runBranch runs them over the
3
+ // Shell port. Lives under commands/_lib/ — the loader's SearchPattern is
4
+ // "*.cmd.ts", so this file is never loaded as a command.
5
+
6
+ import type { Logger, Shell } from "../../../shared/application/ports.ts";
7
+ import type { CommandView } from "../view.ts";
8
+
9
+ /** True when `git status --porcelain` reported at least one changed path. */
10
+ export function hasUncommittedChanges(porcelain: unknown): boolean {
11
+ return String(porcelain ?? "")
12
+ .split("\n")
13
+ .some((line) => line.trim().length > 0);
14
+ }
15
+
16
+ /** Branch names git itself accepts, minus anything a shell would reinterpret. */
17
+ const SAFE_BRANCH = /^[A-Za-z0-9._/\-]+$/;
18
+
19
+ export type BranchPlan =
20
+ | { action: "show" }
21
+ | { action: "checkout"; branch: string }
22
+ | { action: "refuse"; reason: string };
23
+
24
+ /**
25
+ * What `/branch [name]` should do.
26
+ *
27
+ * A bare `/branch` shows the current one (an addition of Orkeon Code: it is the question
28
+ * asked most often and it costs nothing). A name is validated before it reaches the
29
+ * shell — the tool allowlists `git`, so an unvalidated name is not an injection,
30
+ * but `git checkout --orphan` typed as a "branch" is a different operation than the
31
+ * one the operator asked for.
32
+ */
33
+ export function planBranch(tokens: readonly string[]): BranchPlan {
34
+ const name = String((tokens ?? [])[0] ?? "").trim();
35
+ if (name.length === 0) return { action: "show" };
36
+ if (name.startsWith("-")) {
37
+ return { action: "refuse", reason: `'${name}' looks like an option, not a branch name` };
38
+ }
39
+ if (!SAFE_BRANCH.test(name)) {
40
+ return {
41
+ action: "refuse",
42
+ reason: `'${name}' is not a plausible branch name (letters, digits, '.', '_', '/', '-')`,
43
+ };
44
+ }
45
+ return { action: "checkout", branch: name };
46
+ }
47
+
48
+ /**
49
+ * The refusal text for a dirty working tree.
50
+ *
51
+ * A refusal, not a warning: `git checkout` with local modifications either fails
52
+ * with git's own error or carries the changes onto the new branch, and the second
53
+ * outcome is the one that loses work quietly. The message names both ways out.
54
+ */
55
+ export function describeDirtyTreeRefusal(branch: string, porcelain: string): string {
56
+ const changed = porcelain.split("\n").filter((l) => l.trim().length > 0);
57
+ const shown = changed.slice(0, 5).map((l) => ` ${l.trim()}`).join("\n");
58
+ return (
59
+ `refusing to check out '${branch}': ${changed.length} uncommitted change(s) in the working tree.\n` +
60
+ `${shown}${changed.length > 5 ? `\n … and ${changed.length - 5} more` : ""}\n` +
61
+ "Commit them (/commit) or stash them first — a checkout would either fail or carry them across."
62
+ );
63
+ }
64
+
65
+ export interface BranchDeps {
66
+ shell: Shell;
67
+ log: Pick<Logger, "warn">;
68
+ }
69
+
70
+ /** `/branch [name]`, from the command's raw tokens: the current branch, or the
71
+ * checkout of the named one unless the working tree holds changes. */
72
+ export async function runBranch(tokens: readonly string[], deps: BranchDeps): Promise<CommandView> {
73
+ const { shell } = deps;
74
+ const plan = planBranch(tokens);
75
+
76
+ if (plan.action === "refuse") return { text: plan.reason };
77
+
78
+ if (plan.action === "show") {
79
+ const r = await shell.run("git branch --show-current");
80
+ return { text: r.stdout.trim() || r.stderr.trim() || "(detached HEAD)" };
81
+ }
82
+
83
+ const status = await shell.run("git status --porcelain");
84
+ const porcelain = status.stdout;
85
+ if (status.exitCode === 0 && hasUncommittedChanges(porcelain)) {
86
+ deps.log.warn(`/branch refused: uncommitted changes block the checkout of '${plan.branch}'`);
87
+ return { text: describeDirtyTreeRefusal(plan.branch, porcelain) };
88
+ }
89
+
90
+ const r = await shell.run(`git checkout ${plan.branch}`);
91
+ if (r.exitCode !== 0) {
92
+ return { text: `checkout failed: ${r.stderr.trim() || r.stdout.trim() || `exit code ${r.exitCode}`}` };
93
+ }
94
+ return { text: r.stderr.trim() || r.stdout.trim() || `switched to '${plan.branch}'` };
95
+ }
@@ -0,0 +1,94 @@
1
+ // /commit: the gate before the git-commit crew is launched (B-1). The arguments, the effective permission mode
2
+ // (the read-only modes are refused here, so the operator learns why without a crew round-trip; the crew
3
+ // re-checks), the plan and its confirmation, then the crew's input: the mode, the paths, push and pull request,
4
+ // the author's note when one is given, and what the crew needs to open the pull request itself (pr-context.ts), read only when the run may reach it.
5
+ import type { Logger } from "../../../shared/application/ports.ts";
6
+ import type { SessionIo } from "../../../shared/application/session-io.ts";
7
+ import { pullRequestCrewInputs } from "../../../shared/domain/git/pull-request.ts";
8
+ import { buildCommitPlan, isCommitPermitted, parseCommitArgs } from "../../../crews/git-commit/domain/commit.ts";
9
+ import { commandLine, splitWords } from "../args.ts";
10
+ import { readPullRequestContext } from "../pr-context.ts";
11
+ import type { PullRequestContext, PullRequestContextPorts } from "../pr-context.ts";
12
+
13
+ export interface CommitCommandDeps {
14
+ session: Pick<SessionIo, "resolveEffectiveSessionMode">;
15
+ /** Asks the yes/no question: true approves; anything else, or a throw, refuses. */
16
+ confirm(question: string): Promise<unknown>;
17
+ write(line: string): void;
18
+ log: Pick<Logger, "info">;
19
+ pr: PullRequestContextPorts;
20
+ }
21
+
22
+ export type CommitDispatch = { refused: string } | { input: Record<string, unknown> };
23
+
24
+ /**
25
+ * Asks for confirmation, distinguishing "declined" from "cannot ask".
26
+ *
27
+ * A headless session's prompt throws (or returns something that is not a boolean), and
28
+ * treating that as approval is how an unattended run commits a whole tree. Anything that
29
+ * is not an explicit `true` refuses, and the two cases are reported differently because
30
+ * the remedy differs: one is "answer yes", the other is "pass --yes".
31
+ */
32
+ async function confirmOrRefuse(deps: Pick<CommitCommandDeps, "confirm" | "write">, notice: string, question: string): Promise<string | null> {
33
+ deps.write(notice);
34
+ let answer: unknown;
35
+ try {
36
+ answer = await deps.confirm(question);
37
+ } catch (e: any) {
38
+ return (
39
+ "refused: /commit needs a confirmation and this session cannot prompt " +
40
+ `(${String(e?.message ?? e)}). Re-run as '/commit --yes' if you intend to stage ` +
41
+ "and commit the changed files unattended."
42
+ );
43
+ }
44
+ if (answer === true) return null;
45
+ if (typeof answer !== "boolean") {
46
+ return (
47
+ "refused: the confirmation prompt returned no answer (non-interactive session). " +
48
+ "Re-run as '/commit --yes' to stage and commit the changed files unattended."
49
+ );
50
+ }
51
+ return "cancelled — nothing was staged and nothing was committed.";
52
+ }
53
+
54
+ /** `/commit [--yes] [--push] [--pr] [--note <text>] [<path>…]`, from the command's raw tokens: the refusal, written,
55
+ * or the crew's input. The REPL keeps the quotes in the raw tokens: the line is split again, so
56
+ * `--note "the reason in several words"` reads as one note. */
57
+ export async function runCommitCommand(tokens: readonly string[], deps: CommitCommandDeps): Promise<CommitDispatch> {
58
+ const parsed = parseCommitArgs(splitWords(commandLine(tokens)).map((w) => w.text));
59
+ if (!parsed.ok) {
60
+ deps.write(parsed.text);
61
+ return { refused: parsed.text };
62
+ }
63
+ const { yes, push, pr, paths, note } = parsed.args;
64
+ const { mode, via } = await deps.session.resolveEffectiveSessionMode();
65
+
66
+ const permitted = isCommitPermitted(mode);
67
+ if (!permitted.allowed) {
68
+ deps.write(`✗ refused: ${permitted.reason}`);
69
+ return { refused: permitted.reason };
70
+ }
71
+
72
+ if (!yes) {
73
+ const plan = buildCommitPlan({ push, pr, paths });
74
+ const refusal = await confirmOrRefuse(deps, plan.notice, plan.question);
75
+ if (refusal !== null) {
76
+ deps.write(`✗ ${refusal}`);
77
+ return { refused: refusal };
78
+ }
79
+ }
80
+
81
+ deps.log.info(`commit approved — permission mode '${mode}' (${via})`);
82
+ const context: PullRequestContext | null = pr || push ? await readPullRequestContext(deps.pr) : null;
83
+ // A yes to a plan that named the pull request is the question the github call needs; --yes asked nothing.
84
+ return {
85
+ input: {
86
+ permissionMode: mode, paths, push, pr,
87
+ ...(note === undefined ? {} : { note }),
88
+ ...pullRequestCrewInputs({
89
+ pr, push, yes,
90
+ read: () => ({ githubTool: context?.githubTool ?? false, permissionRules: context?.permissionRules ?? [] }),
91
+ }),
92
+ },
93
+ };
94
+ }