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,146 @@
1
+ // pushCandidate: a candidate of the shared memory from what the model or a crew proposes (the
2
+ // memory_push tool). It writes candidates/<id>.md only, never entries/: admission is
3
+ // /memory-admit's. Refused, with the reason and nothing written: a topic refused.md holds, an
4
+ // entry the domain finds invalid (shape, secrets), an unreadable refused list, a failed write.
5
+
6
+ import type { Files } from "../ports.ts";
7
+ import { ENTRY_TYPES, entryIdPrefix, entryProblems } from "../../domain/shared-memory/entry.ts";
8
+ import type { EntryType, MemoryEntry } from "../../domain/shared-memory/entry.ts";
9
+ import { topicOf } from "../../domain/shared-memory/refused.ts";
10
+ import { serializeEntry } from "../../domain/shared-memory/front-matter.ts";
11
+ import { candidatePath, entryPath } from "../../domain/shared-memory/layout.ts";
12
+ import type { MemoryLayout } from "../../domain/shared-memory/layout.ts";
13
+ import { secretLikePaths } from "../../domain/secret-patterns.ts";
14
+ import { readOrNull, refreshCandidatesList, refusedTopics, writeCandidateFile } from "./memory-files.ts";
15
+
16
+ export interface PushInput {
17
+ type: EntryType;
18
+ title: string;
19
+ topic: string;
20
+ appliesWhen: string;
21
+ rationale: string;
22
+ correction?: string;
23
+ detectionSignal?: string;
24
+ /** path:line, a commit, or a verdict file: one item each. */
25
+ evidence: string[];
26
+ tags: string[];
27
+ /** Absent: human:<date> memory_push. */
28
+ source?: string;
29
+ }
30
+
31
+ export type PushOutcome =
32
+ | { ok: true; id: string; path: string; warnings: string[] }
33
+ | { ok: false; refused: string };
34
+
35
+ export interface PushDeps {
36
+ files: Pick<Files, "read" | "write" | "list">;
37
+ clock: () => Date;
38
+ }
39
+
40
+ const text = (value: unknown): string => (typeof value === "string" ? value.trim() : "");
41
+ const list = (value: unknown): string[] =>
42
+ Array.isArray(value) ? value.filter((v): v is string => typeof v === "string").map((v) => v.trim()).filter((v) => v !== "") : [];
43
+
44
+ /** The tool's input (snake_case, as the model writes it) read as a PushInput, or why not. */
45
+ export function readPushInput(input: unknown): { ok: true; input: PushInput } | { ok: false; refused: string } {
46
+ const raw = (input !== null && typeof input === "object" ? input : {}) as Record<string, unknown>;
47
+ const type = text(raw.type);
48
+ if (!(ENTRY_TYPES as readonly string[]).includes(type)) return { ok: false, refused: `type must be one of ${ENTRY_TYPES.join(", ")}` };
49
+ const missing = ["title", "topic", "applies_when", "rationale"].filter((key) => text(raw[key]) === "");
50
+ if (missing.length > 0) return { ok: false, refused: `${missing.join(", ")} required` };
51
+ const evidence = list(raw.evidence);
52
+ if (evidence.length === 0) return { ok: false, refused: "evidence required: at least one path:line, commit or verdict file" };
53
+ const secret = secretLikePaths(evidence.flatMap((e) => e.split(/\s+/)).map((w) => w.replace(/:\d+$/, "")));
54
+ if (secret.length > 0) return { ok: false, refused: `evidence names a secret-like file: ${secret.join(", ")}` };
55
+ const pushed: PushInput = {
56
+ type: type as EntryType, title: text(raw.title), topic: text(raw.topic), appliesWhen: text(raw.applies_when),
57
+ rationale: text(raw.rationale), evidence, tags: list(raw.tags).map((t) => t.toLowerCase()),
58
+ };
59
+ if (text(raw.correction) !== "") pushed.correction = text(raw.correction);
60
+ if (text(raw.detection_signal) !== "") pushed.detectionSignal = text(raw.detection_signal);
61
+ return { ok: true, input: pushed };
62
+ }
63
+
64
+ const day = (date: Date): string => date.toISOString().slice(0, 10);
65
+
66
+ /** The candidate entry, its id not yet made unique. */
67
+ export function candidateEntry(input: PushInput, project: string, date: string): MemoryEntry {
68
+ const entry: MemoryEntry = {
69
+ id: `${entryIdPrefix(project, input.type, date)}${topicOf(input.title)}`,
70
+ type: input.type, title: input.title, project, date, topic: topicOf(input.topic),
71
+ appliesWhen: input.appliesWhen, rationale: input.rationale,
72
+ source: input.source ?? `human:${date} memory_push`, status: "candidate", supersedes: [], tags: input.tags, stack: [],
73
+ body: ["## Context", input.appliesWhen, "", "## Content", input.rationale,
74
+ ...(input.correction === undefined ? [] : ["", `Instead: ${input.correction}`]), "", "## Evidence",
75
+ ...input.evidence.map((e) => `- \`${e.replace(/`/g, "'")}\``)].join("\n") + "\n",
76
+ };
77
+ if (input.correction !== undefined) entry.correction = input.correction;
78
+ if (input.detectionSignal !== undefined) entry.detectionSignal = input.detectionSignal;
79
+ return entry;
80
+ }
81
+
82
+ /** The id itself when no candidate or entry holds it, else the first free `-2` … `-9`; null when none is. */
83
+ async function freeId(files: Pick<Files, "read">, layout: MemoryLayout, entry: MemoryEntry): Promise<string | null> {
84
+ for (let n = 1; n <= 9; n++) {
85
+ const id = n === 1 ? entry.id : `${entry.id}-${n}`;
86
+ const taken = (await readOrNull(files, candidatePath(layout, id))) !== null
87
+ || (await readOrNull(files, entryPath(layout, entry.type, id))) !== null;
88
+ if (!taken) return id;
89
+ }
90
+ return null;
91
+ }
92
+
93
+ /** The text read back is the one written, line endings and a trailing blank aside (a host may normalise them). */
94
+ const sameText = (a: string, b: string): boolean => a.replace(/\r\n/g, "\n").trimEnd() === b.replace(/\r\n/g, "\n").trimEnd();
95
+
96
+ const firstLine = (error: unknown): string => String((error as Error)?.message ?? error).split("\n")[0];
97
+
98
+ /** Writes `entry` as a candidate after the checks: refused topic, validity, a free id. */
99
+ export async function writeCandidate(
100
+ deps: Pick<PushDeps, "files">, memory: { layout: MemoryLayout }, entry: MemoryEntry,
101
+ ): Promise<PushOutcome> {
102
+ try {
103
+ if ((await refusedTopics(deps.files, memory.layout)).has(entry.topic)) {
104
+ return { ok: false, refused: `topic '${entry.topic}' was refused (refused.md): it is never proposed again` };
105
+ }
106
+ } catch (error) {
107
+ return { ok: false, refused: `refused.md cannot be read (${firstLine(error)}): nothing was written` };
108
+ }
109
+ const problems = entryProblems(entry);
110
+ if (problems.length > 0) return { ok: false, refused: `not a valid entry: ${problems.join("; ")}` };
111
+ // The Files port has no exclusive create: a concurrent push of the same title may write the same id between
112
+ // freeId and the write. The candidate is read back, and a file another push overwrote is written again under the
113
+ // next free id; a push whose write came last still wins its id (no lock without module state).
114
+ for (let attempt = 1; attempt <= 2; attempt++) {
115
+ let id: string | null;
116
+ try {
117
+ id = await freeId(deps.files, memory.layout, entry);
118
+ } catch (error) {
119
+ return { ok: false, refused: `${memory.layout.candidates} cannot be read (${firstLine(error)})` };
120
+ }
121
+ if (id === null) return { ok: false, refused: `nine candidates or entries already hold the id ${entry.id}` };
122
+ if (id !== entry.id && (await readOrNull(deps.files, entryPath(memory.layout, entry.type, entry.id)).catch(() => null)) !== null) {
123
+ return { ok: false, refused: `an admitted entry already holds ${entry.id}: supersede it rather than push it again` };
124
+ }
125
+ let path: string;
126
+ try {
127
+ path = await writeCandidateFile(deps.files, memory.layout, { ...entry, id });
128
+ } catch (error) {
129
+ return { ok: false, refused: `${memory.layout.candidates} is not writable (${firstLine(error)}): nothing was written` };
130
+ }
131
+ const kept = await readOrNull(deps.files, path).catch(() => null);
132
+ if (kept !== null && sameText(kept, serializeEntry({ ...entry, id, status: "candidate" })) === false) continue;
133
+ const listed = await refreshCandidatesList(deps.files, memory.layout);
134
+ return { ok: true, id, path, warnings: listed === null ? [] : [listed] };
135
+ }
136
+ return { ok: false, refused: `another push overwrote ${entry.id} twice: nothing was kept, push again` };
137
+ }
138
+
139
+ /** memory_push: the input read, the candidate built and written. */
140
+ export async function pushCandidate(
141
+ deps: PushDeps, memory: { layout: MemoryLayout; project: string }, raw: unknown,
142
+ ): Promise<PushOutcome> {
143
+ const read = readPushInput(raw);
144
+ if (!read.ok) return read;
145
+ return writeCandidate(deps, memory, candidateEntry(read.input, memory.project, day(deps.clock())));
146
+ }
@@ -0,0 +1,69 @@
1
+ // Recall from the shared memory: ask the index, read each hit's file, keep the admitted entries of the
2
+ // types asked, best first. The index keeps superseded entries and is no source of truth, so the status
3
+ // is read from the file itself. recallPrecedents is the best-effort form a crew step uses: a failure
4
+ // costs the block, never the step (as extract-memories.ts degrades to nothing).
5
+
6
+ import type { Files, Logger, SharedMemory } from "../ports.ts";
7
+ import { parseEntry } from "../../domain/shared-memory/front-matter.ts";
8
+ import type { EntryType } from "../../domain/shared-memory/entry.ts";
9
+ import { MAX_PRECEDENTS, RECALL_TOP_N, buildPrecedentsBlock } from "../../domain/shared-memory/precedents-block.ts";
10
+ import type { Precedent } from "../../domain/shared-memory/precedents-block.ts";
11
+ import type { MemoryLayout } from "../../domain/shared-memory/layout.ts";
12
+
13
+ export interface RecallDeps {
14
+ memory: Pick<SharedMemory, "search">;
15
+ files: Pick<Files, "read">;
16
+ }
17
+
18
+ export interface RecallRequest {
19
+ /** Where the entries are and the collection that indexes them (memory-settings.ts). */
20
+ memory: { layout: Pick<MemoryLayout, "entries">; collection: string };
21
+ query: string;
22
+ /** Only these types; absent or empty = every type. */
23
+ types?: readonly EntryType[];
24
+ /** At most this many entries, MAX_PRECEDENTS at most. */
25
+ max?: number;
26
+ }
27
+
28
+ export interface Recall {
29
+ precedents: Precedent[];
30
+ /** More admitted entries matched than were kept. */
31
+ truncated: boolean;
32
+ }
33
+
34
+ /** The admitted entries the index finds for the query. Throws when the index cannot answer. */
35
+ export async function recallEntries(deps: RecallDeps, request: RecallRequest): Promise<Recall> {
36
+ const max = Math.max(1, Math.min(MAX_PRECEDENTS, Math.floor(request.max ?? MAX_PRECEDENTS)));
37
+ const query = request.query.trim();
38
+ if (query === "") return { precedents: [], truncated: false };
39
+ const hits = await deps.memory.search(request.memory.collection, query, RECALL_TOP_N);
40
+ const under = `${request.memory.layout.entries}/`;
41
+ const types = request.types !== undefined && request.types.length > 0 ? new Set(request.types) : null;
42
+ const found: Precedent[] = [];
43
+ for (const hit of hits) {
44
+ if (!hit.sourceId.startsWith(under)) continue;
45
+ let text: string;
46
+ try {
47
+ text = await deps.files.read(hit.sourceId);
48
+ } catch {
49
+ continue; // gone since the index was built
50
+ }
51
+ const parsed = parseEntry(text);
52
+ if (!parsed.ok || parsed.entry.status !== "admitted") continue;
53
+ if (types !== null && !types.has(parsed.entry.type)) continue;
54
+ found.push({ entry: parsed.entry, path: hit.sourceId, score: hit.score });
55
+ }
56
+ return { precedents: found.slice(0, max), truncated: found.length > max };
57
+ }
58
+
59
+ /** The "## Precedents" block for a crew step's prompt; "" when nothing is recalled or the recall fails. */
60
+ export async function recallPrecedents(
61
+ deps: RecallDeps & { log: Pick<Logger, "warn"> }, request: RecallRequest,
62
+ ): Promise<string> {
63
+ try {
64
+ return buildPrecedentsBlock((await recallEntries(deps, request)).precedents);
65
+ } catch (error) {
66
+ deps.log.warn(`shared memory: recall failed, no precedents (${String((error as Error)?.message ?? error).split("\n")[0]})`);
67
+ return "";
68
+ }
69
+ }
@@ -0,0 +1,38 @@
1
+ // The state keys a use case reads many times, read once (Orkeon #263): one batch
2
+ // read of the session's state bag, then each read of those keys answered from it.
3
+ //
4
+ // A turn of the main loop reads about ten keys through readers that each take the
5
+ // SessionStore port (the behaviour flags, the output style, the hooks, the skills,
6
+ // the compaction breaker...). Rather than teach every reader a batch, the turn hands
7
+ // them a session whose readState answers the snapshot: the readers stay as they are.
8
+
9
+ import type { SessionStore } from "./ports.ts";
10
+
11
+ /** The state reads and writes of a session, the snapshot's keys answered without a call. */
12
+ export type StateSnapshot = Pick<SessionStore, "readState" | "writeState">;
13
+
14
+ /**
15
+ * Reads `keys` in one call and answers them from then on; a key outside `keys` is
16
+ * read from the session as before. A write goes to the session, then to the
17
+ * snapshot, so a later read of the key sees it. A batch read that fails leaves the
18
+ * snapshot empty: every read goes to the session, as without one (best-effort, like
19
+ * the readers themselves).
20
+ */
21
+ export async function stateSnapshot(
22
+ session: Pick<SessionStore, "readState" | "readStates" | "writeState">,
23
+ keys: readonly string[],
24
+ ): Promise<StateSnapshot> {
25
+ let values: Map<string, string | null>;
26
+ try {
27
+ values = new Map(Object.entries(await session.readStates(keys)));
28
+ } catch {
29
+ values = new Map();
30
+ }
31
+ return {
32
+ readState: async (key) => (values.has(key) ? values.get(key) ?? null : session.readState(key)),
33
+ async writeState(key, value) {
34
+ await session.writeState(key, value);
35
+ if (values.has(key)) values.set(key, value);
36
+ },
37
+ };
38
+ }
@@ -0,0 +1,135 @@
1
+ // The batch in progress, and its state file written before a compaction (step 0 of the
2
+ // compaction pipeline). The pointer is the session's (`workflow_active`, written by the
3
+ // step command that starts on a batch); the state is built from files and git only —
4
+ // the sheet, Code's event log, the reports recorded, `git status --short` — never from
5
+ // the model, so a compaction cannot get it wrong.
6
+ import type { Clock, Files, SessionStore, Shell } from "../ports.ts";
7
+ import type { ConfigStore } from "../config-store.ts";
8
+ import { WORKFLOW_ACTIVE_STATE_KEY } from "../../domain/session-keys.ts";
9
+ import {
10
+ batchesStatePath, firstOpenStep, formatActiveWorkflow, parseActiveWorkflow, renderStateFile, sheetStateSteps,
11
+ stateFilePath,
12
+ } from "../../domain/workflow/state-file.ts";
13
+ import type { ActiveWorkflow } from "../../domain/workflow/state-file.ts";
14
+ import { parseBatchesState } from "../../domain/dev/batches-state.ts";
15
+ import type { BatchesLogEntry } from "../../domain/dev/batches-state.ts";
16
+ import { listDevCodes, loadDevCode, loadDevContext } from "../dev/load-dev-context.ts";
17
+ import type { CodeSheet, DevCode } from "../dev/load-dev-context.ts";
18
+ import type { WorkFolder } from "../dev/resolve-work-folder.ts";
19
+ import { WORKSPACE } from "../../domain/vfs.ts";
20
+
21
+ export async function readActiveWorkflow(session: Pick<SessionStore, "readState">): Promise<ActiveWorkflow | null> {
22
+ return parseActiveWorkflow(await session.readState(WORKFLOW_ACTIVE_STATE_KEY));
23
+ }
24
+
25
+ export async function writeActiveWorkflow(session: Pick<SessionStore, "writeState">, active: ActiveWorkflow): Promise<void> {
26
+ await session.writeState(WORKFLOW_ACTIVE_STATE_KEY, formatActiveWorkflow(active));
27
+ }
28
+
29
+ export interface WorkflowStateDeps {
30
+ session: Pick<SessionStore, "readState">;
31
+ files: Pick<Files, "read" | "list" | "write">;
32
+ shell: Pick<Shell, "run">;
33
+ config: Pick<ConfigStore, "readValue">;
34
+ clock: Clock;
35
+ }
36
+
37
+ /** What step 0 did: the file written (relative to the project) and the first open step,
38
+ * or why it wrote none although a batch is in progress. */
39
+ export type StateWritten = { path: string; firstOpen: string | null } | { skipped: string };
40
+
41
+ const REPORTS_LISTED = 200;
42
+ const CODES_SEARCHED = 50;
43
+
44
+ const openSheet = (code: DevCode, phase: string): CodeSheet | undefined =>
45
+ code.sheets.find((s) => s.batch === phase && s.sheet.doneDate === undefined);
46
+
47
+ /** The code and sheet of the batch: the pointer's code, else the first code (by name) with
48
+ * an open sheet of that batch. */
49
+ async function findSheet(
50
+ deps: Pick<WorkflowStateDeps, "files">, work: WorkFolder, active: ActiveWorkflow,
51
+ ): Promise<{ code: DevCode; sheet: CodeSheet } | { skipped: string }> {
52
+ if (active.code !== null) {
53
+ const lookup = await loadDevCode(deps, work, active.code);
54
+ if (lookup.found === null) return { skipped: `no work code '${active.code}' in ${work.folder}/ (${lookup.reason})` };
55
+ const any = lookup.found.sheets.find((s) => s.batch === active.phase);
56
+ if (any === undefined) return { skipped: `no sheet of ${active.phase} in ${lookup.found.shown}/` };
57
+ if (any.sheet.doneDate !== undefined) return { skipped: `${lookup.found.shown}/${any.name} is done (${any.sheet.doneDate})` };
58
+ return { code: lookup.found, sheet: any };
59
+ }
60
+ const codes = (await listDevCodes(deps, work)).filter((c) => c.sheets > 0).slice(0, CODES_SEARCHED);
61
+ for (const summary of codes) {
62
+ const lookup = await loadDevCode(deps, work, summary.code);
63
+ if (lookup.found === null) continue;
64
+ const sheet = openSheet(lookup.found, active.phase);
65
+ if (sheet !== undefined) return { code: lookup.found, sheet };
66
+ }
67
+ return { skipped: `no open sheet of ${active.phase} in ${work.folder}/` };
68
+ }
69
+
70
+ /** The batch's events: Code's own log when there is one, else the log of the work code's
71
+ * folder (`<CODE>-BATCHES-STATE.md`, same line shape). */
72
+ async function readEvents(files: Pick<Files, "read">, code: DevCode, phase: string): Promise<string[]> {
73
+ let entries: BatchesLogEntry[];
74
+ try {
75
+ entries = parseBatchesState(await files.read(`${WORKSPACE}/${batchesStatePath(code.code)}`)).entries;
76
+ } catch {
77
+ entries = code.state?.state.entries ?? [];
78
+ }
79
+ return entries
80
+ .filter((e) => e.batch === phase)
81
+ .map((e) => `- ${e.date} ${e.time} ${e.batch} ${e.event}${e.detail ? ` ${e.detail}` : ""}`);
82
+ }
83
+
84
+ async function readReports(files: Pick<Files, "list">, folder: string, phase: string): Promise<string[]> {
85
+ let names: string[];
86
+ try {
87
+ names = await files.list(`${folder}/reports`, REPORTS_LISTED);
88
+ } catch {
89
+ return [];
90
+ }
91
+ const ofPhase = new RegExp(`(^|[^A-Za-z0-9])${phase}([^0-9]|$)`);
92
+ return names.map((n) => n.replace(/\/+$/, "")).filter((n) => ofPhase.test(n)).sort();
93
+ }
94
+
95
+ async function readTree(shell: Pick<Shell, "run">): Promise<{ lines: string[] } | { note: string }> {
96
+ try {
97
+ const r = await shell.run("git status --short");
98
+ if (r.exitCode !== 0) return { note: `git status failed: ${(r.stderr || r.stdout).trim().split("\n")[0] || `exit ${r.exitCode}`}` };
99
+ return { lines: r.stdout.split(/\r?\n/).filter((l) => l.trim().length > 0) };
100
+ } catch (error) {
101
+ return { note: `git status could not run: ${error instanceof Error ? error.message : String(error)}` };
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Write the state file of the batch in progress; null when no batch is. Throws when the
107
+ * work folder cannot be read or the file cannot be written: the caller logs it and goes on.
108
+ */
109
+ export async function writeWorkflowState(
110
+ deps: WorkflowStateDeps, trigger: "manual" | "auto",
111
+ ): Promise<StateWritten | null> {
112
+ const active = await readActiveWorkflow(deps.session);
113
+ if (active === null) return null;
114
+ const { work } = await loadDevContext(deps);
115
+ if (work.vfsPath === null) return { skipped: `the work folder ${work.folder}/ cannot be reached` };
116
+ const found = await findSheet(deps, work, active);
117
+ if ("skipped" in found) return found;
118
+
119
+ const { code, sheet } = found;
120
+ const steps = sheetStateSteps(sheet.sheet);
121
+ const path = stateFilePath(code.code, active.phase);
122
+ const text = renderStateFile({
123
+ code: code.code,
124
+ phase: active.phase,
125
+ at: deps.clock().toISOString().replace(/\.\d{3}Z$/, "Z"),
126
+ trigger,
127
+ sheet: `${code.shown}/${sheet.name}`,
128
+ steps,
129
+ events: await readEvents(deps.files, code, active.phase),
130
+ reports: await readReports(deps.files, `${work.vfsPath}/${code.code}`, active.phase),
131
+ tree: await readTree(deps.shell),
132
+ });
133
+ await deps.files.write(`${WORKSPACE}/${path}`, text);
134
+ return { path, firstOpen: firstOpenStep(steps) };
135
+ }
@@ -0,0 +1,168 @@
1
+ // What the persisted behavior flags actually DO. Pure, no IO.
2
+ //
3
+ // `/effort`, `/fast`, `/passes` and `/proactive` are persisted settings; this
4
+ // module is the semantics half — the loop and the review crew are the consumption
5
+ // half.
6
+ //
7
+ // The governing constraint: an UNCONFIGURED session must behave exactly as it did
8
+ // before the flags existed. Every default below is therefore the value that was hard-coded at
9
+ // the call site (40 act iterations, one review pass, nothing dropped, no extra
10
+ // clause), so turning a flag on is the only thing that changes anything.
11
+
12
+ // ── /effort → the act() iteration ladder ─────────────────────────────────
13
+
14
+ export const EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"] as const;
15
+ export type EffortLevel = (typeof EFFORT_LEVELS)[number];
16
+
17
+ /** Unset ⇒ `medium`, whose ladder rung IS the pre-B-9 hard-coded value. */
18
+ export const DEFAULT_EFFORT: EffortLevel = "medium";
19
+
20
+ /**
21
+ * Iterations granted to `ctx.llm.act` per level.
22
+ *
23
+ * The ladder bounds the tool-calling loop. Since Orkeon 1.0.0-rc.6 the level also reaches the
24
+ * provider: `act({ effort })` and `AgentBuilder.effort()` turn its thinking on at that level (A-3).
25
+ * Only a level `/effort` stored is forwarded (`providerEffort`): an unconfigured session sends none,
26
+ * so it keeps the provider's own default and the 40 iterations it always had.
27
+ *
28
+ * `xhigh` and `max` are Anthropic's two levels above `high`; to a provider whose field does not know one the
29
+ * runtime sends the highest level it knows below it, with a warning in its log. The ladder keeps climbing: a
30
+ * turn that asks the model for its most thorough reasoning is also the one given the most room to act.
31
+ */
32
+ export const EFFORT_MAX_ITERATIONS: Readonly<Record<EffortLevel, number>> = {
33
+ low: 10,
34
+ medium: 40,
35
+ high: 80,
36
+ xhigh: 120,
37
+ max: 160,
38
+ };
39
+
40
+ export function isEffortLevel(raw: unknown): raw is EffortLevel {
41
+ return EFFORT_LEVELS.includes(String(raw ?? "").trim().toLowerCase() as EffortLevel);
42
+ }
43
+
44
+ /** Normalise a stored value; anything unrecognised falls back to the default. */
45
+ export function resolveEffort(raw: unknown): EffortLevel {
46
+ const v = String(raw ?? "").trim().toLowerCase();
47
+ return isEffortLevel(v) ? (v as EffortLevel) : DEFAULT_EFFORT;
48
+ }
49
+
50
+ /** The level forwarded to the provider (`act({effort})`): a stored valid level; undefined when none is stored. */
51
+ export function providerEffort(raw: unknown): EffortLevel | undefined {
52
+ const v = String(raw ?? "").trim().toLowerCase();
53
+ return isEffortLevel(v) ? (v as EffortLevel) : undefined;
54
+ }
55
+
56
+ /** The act() iteration cap for a stored effort value. */
57
+ export function maxIterationsFor(raw: unknown): number {
58
+ return EFFORT_MAX_ITERATIONS[resolveEffort(raw)];
59
+ }
60
+
61
+ // ── /passes → review rounds ──────────────────────────────────────────────
62
+
63
+ export const MIN_PASSES = 1;
64
+ export const MAX_PASSES = 5;
65
+ /** Unset ⇒ 1 — the single fan-out /review has always done. */
66
+ export const DEFAULT_PASSES = MIN_PASSES;
67
+
68
+ /** Clamp a stored pass count into 1..5; junk ⇒ the default. */
69
+ export function resolvePasses(raw: unknown): number {
70
+ const n = Number(String(raw ?? "").trim());
71
+ if (!Number.isInteger(n)) return DEFAULT_PASSES;
72
+ return Math.min(MAX_PASSES, Math.max(MIN_PASSES, n));
73
+ }
74
+
75
+ // ── /fast → drop the advisory prompt blocks ──────────────────────────────
76
+
77
+ /**
78
+ * The blocks `/fast` omits from the assembled prompt.
79
+ *
80
+ * Chosen as the two ADVISORY blocks — the ones that widen the model's context
81
+ * without being required to answer the request — and they are also the two
82
+ * largest: an attached skill is capped at 4 000 characters EACH (B-13) and the
83
+ * memory block carries up to four categories of recalled notes.
84
+ *
85
+ * Everything else stays: the static header (identity, tool list, CLAUDE.md) is
86
+ * the cache prefix and dropping it would cost more than it saves; preferences
87
+ * and hooks are operator instructions; git context, history and the gauge are
88
+ * the situation. Dropping those would change WHAT is answered, not how fast.
89
+ *
90
+ * Fast mode is a real degradation, so the loop logs it — a shorter answer with
91
+ * no memory must never look like the model simply forgot.
92
+ */
93
+ export const FAST_MODE_DROPPED_BLOCKS = ["skills", "memory"] as const;
94
+ export type DroppableBlock = (typeof FAST_MODE_DROPPED_BLOCKS)[number];
95
+
96
+ export function fastModeDrops(fast: boolean): readonly DroppableBlock[] {
97
+ return fast ? FAST_MODE_DROPPED_BLOCKS : [];
98
+ }
99
+
100
+ // ── /proactive → the follow-up clause ────────────────────────────────────
101
+
102
+ /**
103
+ * Appended to the task block (last, with the request) rather than added as its
104
+ * own context block: it is an instruction about the ANSWER's shape, and the
105
+ * furthest thing from the task is the easiest for a model to lose.
106
+ */
107
+ export const PROACTIVE_CLAUSE =
108
+ "(Proactive mode: after the answer, suggest at most three concrete next steps under " +
109
+ "'Next steps'; leave the list out when the work is self-contained.)";
110
+
111
+ export function proactiveSuffix(on: boolean): string {
112
+ return on ? `\n\n${PROACTIVE_CLAUSE}` : "";
113
+ }
114
+
115
+ // ── the flag set the loop reads in one go ────────────────────────────────
116
+
117
+ export interface BehaviorFlags {
118
+ effort: EffortLevel;
119
+ /** The level the provider thinks at: the one /effort stored, null when it stored none (A-3). */
120
+ thinking: EffortLevel | null;
121
+ passes: number;
122
+ fast: boolean;
123
+ proactive: boolean;
124
+ /** `/model` override for this turn; empty ⇒ the boot model (B-10). */
125
+ model: string;
126
+ }
127
+
128
+ /** The unconfigured session — the pre-B-9 behaviour, byte for byte. */
129
+ export const DEFAULT_BEHAVIOR_FLAGS: BehaviorFlags = {
130
+ effort: DEFAULT_EFFORT,
131
+ thinking: null,
132
+ passes: DEFAULT_PASSES,
133
+ fast: false,
134
+ proactive: false,
135
+ model: "",
136
+ };
137
+
138
+ /** Build the flag set from raw stored strings (all optional). */
139
+ export function resolveBehaviorFlags(raw: {
140
+ effort?: unknown; passes?: unknown; fast?: unknown; proactive?: unknown; model?: unknown;
141
+ }): BehaviorFlags {
142
+ return {
143
+ effort: resolveEffort(raw?.effort),
144
+ thinking: providerEffort(raw?.effort) ?? null,
145
+ passes: resolvePasses(raw?.passes),
146
+ fast: String(raw?.fast ?? "") === "true",
147
+ proactive: String(raw?.proactive ?? "") === "true",
148
+ model: String(raw?.model ?? "").trim(),
149
+ };
150
+ }
151
+
152
+ /**
153
+ * One line naming every flag that is NOT at its default, or "" when the session
154
+ * is unconfigured. The loop logs it: a turn that behaves differently must say
155
+ * which setting made it so, otherwise the effect reads as model variance.
156
+ */
157
+ export function describeActiveFlags(flags: BehaviorFlags): string {
158
+ const active: string[] = [];
159
+ // A stored level, even `medium`, is named: it turns the provider's thinking on.
160
+ if (flags.thinking !== null) {
161
+ active.push(`effort=${flags.effort} (act maxIterations=${EFFORT_MAX_ITERATIONS[flags.effort]}, provider thinking ${flags.thinking})`);
162
+ }
163
+ if (flags.passes !== DEFAULT_PASSES) active.push(`passes=${flags.passes}`);
164
+ if (flags.fast) active.push(`fast=on (dropping ${FAST_MODE_DROPPED_BLOCKS.join(", ")})`);
165
+ if (flags.proactive) active.push("proactive=on");
166
+ if (flags.model) active.push(`model=${flags.model}`);
167
+ return active.join(" · ");
168
+ }
@@ -0,0 +1,69 @@
1
+ // The `tools.extra` setting — pure, no IO: the tools the host registers beyond
2
+ // Orkeon Code's built-in lists (an MCP server's under Orkeon's `MCP:Servers`, a
3
+ // plugin's) that the main agent may use, each with the access class that decides
4
+ // which modes offer it (mode-policy.ts). The notation:
5
+ //
6
+ // transcribe_audio:read, search_issues, create_issue:write
7
+ //
8
+ // entries separated by commas or spaces, each `<name>` or `<name>:<read|write>`.
9
+ // A name without a class is a write: the read-only modes do not offer it unless
10
+ // the user says it only reads. The host's permission gate still decides each
11
+ // call from the access the tool declares to Orkeon.
12
+
13
+ import { builtInTool, sameToolName } from "./permission.ts";
14
+ import type { ExtraTool } from "./permission.ts";
15
+
16
+ /** The /config key that lists them. */
17
+ export const EXTRA_TOOLS_CONFIG_KEY = "tools.extra";
18
+
19
+ /** What an entry must be, for messages. */
20
+ export const EXTRA_TOOL_ENTRY_RULE = "each entry is <name>[:read|:write], a tool that is not built in, named once";
21
+
22
+ /** A tool name as the host registers it: letters, digits, `_`, `-`, `.`. */
23
+ const TOOL_NAME = /^[A-Za-z0-9_][A-Za-z0-9_.-]*$/;
24
+
25
+ export interface ExtraToolsParse {
26
+ /** The valid entries, in the order given. */
27
+ tools: ExtraTool[];
28
+ /** Entries left out, as written: not the notation, a built-in tool (its class is
29
+ * Orkeon Code's), or a name given again. */
30
+ invalid: string[];
31
+ }
32
+
33
+ /**
34
+ * Parses the setting, or the list the crew receives (one entry per item). Never
35
+ * throws: what does not parse is returned in `invalid` for the caller to report.
36
+ */
37
+ export function parseExtraTools(value: unknown): ExtraToolsParse {
38
+ const entries = Array.isArray(value)
39
+ ? value.map((e) => String(e ?? "").trim())
40
+ : String(value ?? "").split(/[\s,]+/);
41
+ const tools: ExtraTool[] = [];
42
+ const invalid: string[] = [];
43
+ for (const entry of entries.filter((e) => e.length > 0)) {
44
+ const colon = entry.indexOf(":");
45
+ const name = colon < 0 ? entry : entry.slice(0, colon);
46
+ const access = colon < 0 ? "write" : entry.slice(colon + 1);
47
+ // Orkeon compares tool names case-insensitively: `File_Read` is the built-in
48
+ // `file_read`, and `Search_Issues` names `search_issues` again.
49
+ const valid = TOOL_NAME.test(name) && (access === "read" || access === "write")
50
+ && builtInTool(name) === undefined && !tools.some((t) => sameToolName(t.name, name));
51
+ if (valid) tools.push({ name, access: access as ExtraTool["access"] });
52
+ else invalid.push(entry);
53
+ }
54
+ return { tools, invalid };
55
+ }
56
+
57
+ /** One entry in the notation, class always written: `search_issues:write`. */
58
+ export function formatExtraTool(tool: ExtraTool): string {
59
+ return `${tool.name}:${tool.access}`;
60
+ }
61
+
62
+ /** Why a value of the setting is refused, or undefined when every entry parses. */
63
+ export function extraToolsProblem(value: string): string | undefined {
64
+ const { tools, invalid } = parseExtraTools(value);
65
+ if (invalid.length > 0) {
66
+ return `${EXTRA_TOOL_ENTRY_RULE}; not: ${invalid.join(", ")}`;
67
+ }
68
+ return tools.length === 0 ? "it names no tool" : undefined;
69
+ }
@@ -0,0 +1,6 @@
1
+ // Typed-memory categories — pure, no IO. The set the memory backend accepts
2
+ // (InMemoryCategoryMemoryStore), in the fixed order the prompt renders them; read
3
+ // by /memory, /export, the main-loop memory block and the compaction's memory
4
+ // extraction.
5
+
6
+ export const MEMORY_CATEGORIES = ["user", "project", "feedback", "reference"] as const;