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,74 @@
1
+ // The session port: the conversation buffer, the state bag and the context window's budget.
2
+ // Types only, re-exported by ../ports.ts.
3
+
4
+ import type { SessionMsg } from "../../domain/types.ts";
5
+
6
+ /** A conversation-buffer entry as the session holds it. Its field casing is the
7
+ * runtime's, so it is read through `SessionMessages.messages`; written back as
8
+ * read, it stays untouched. */
9
+ export type StoredMessage = unknown;
10
+
11
+ /** The conversation buffer, read once. */
12
+ export interface SessionMessages {
13
+ /** Each entry as stored, in order. */
14
+ stored: StoredMessage[];
15
+ /** The same entries, as role and content. */
16
+ messages: SessionMsg[];
17
+ }
18
+
19
+ /** The tokens of the context window by kind of entry (Orkeon #226). */
20
+ export interface TokenKinds {
21
+ system: number;
22
+ user: number;
23
+ assistant: number;
24
+ tool: number;
25
+ other: number;
26
+ }
27
+
28
+ /** Tokens used in the context window, and the window's size; by kind when the host reports it. */
29
+ export interface TokenBudget {
30
+ used: number;
31
+ window: number;
32
+ byKind?: TokenKinds;
33
+ }
34
+
35
+ /** What a snip of the conversation buffer removed and kept, in entries. */
36
+ export interface SnipResult {
37
+ removed: number;
38
+ retained: number;
39
+ }
40
+
41
+ /** The session saved now, and a saved one loaded in place (Orkeon #227): served while the host persists the
42
+ * session per project (`Orkeon:Cli:Session:Persist`), at virtual paths the file system mounts. */
43
+ export interface SessionSwitch {
44
+ /** Write the session now: to its own file, resolving to that virtual path, or to `path` in the same shape. */
45
+ save(path?: string): Promise<string>;
46
+ /** Swap the buffer, the state bag, the id and the title for those of the file at `path`; resolves to the number
47
+ * of messages loaded. A missing, unreadable or ill-shaped file rejects and the session stays as it was. */
48
+ load(path: string): Promise<number>;
49
+ }
50
+
51
+ /** The session: its conversation buffer, its state bag (string values that survive
52
+ * crew runs and are cleared by /clear), the context window's budget and
53
+ * the session's title. */
54
+ export interface SessionStore {
55
+ readMessages(): Promise<SessionMessages>;
56
+ /** Replace the conversation buffer. */
57
+ writeMessages(messages: readonly StoredMessage[]): Promise<void>;
58
+ /** Add one entry at the end of the buffer, which is neither read nor rewritten (Orkeon #263). */
59
+ appendMessage(role: string, content: string): Promise<void>;
60
+ /** Empty the conversation buffer; resolves to how many entries it removed. */
61
+ reset(): Promise<number>;
62
+ /** Cut the buffer down to its head and its last `turns` turns as the runtime counts them (Orkeon #287): a turn opens
63
+ * at each user message, the stored [turn-context] included, and is never split. Fewer turns than asked, or none
64
+ * after the head, leave the buffer untouched (0 removed). */
65
+ snip(turns: number): Promise<SnipResult>;
66
+ setTitle(title: string): Promise<void>;
67
+ /** A state value; null when unset. */
68
+ readState(key: string): Promise<string | null>;
69
+ /** Several state values in one read (Orkeon #263): every key asked, null when unset. */
70
+ readStates(keys: readonly string[]): Promise<Record<string, string | null>>;
71
+ /** Set a state value; null removes the key. */
72
+ writeState(key: string, value: string | null): Promise<void>;
73
+ readBudget(): Promise<TokenBudget>;
74
+ }
@@ -0,0 +1,26 @@
1
+ // The shared-memory port: the RAG index of the project's shared memory.
2
+ // Types only, re-exported by ../ports.ts.
3
+
4
+ /** A passage of the shared memory's index: the file it comes from (virtual path) and its score. */
5
+ export interface SharedHit {
6
+ sourceId: string;
7
+ score: number;
8
+ }
9
+
10
+ /** What an ingestion of the shared memory's index did, by source. */
11
+ export interface SharedIngest {
12
+ added: number;
13
+ reingested: number;
14
+ unchanged: number;
15
+ pruned: number;
16
+ errors: string[];
17
+ }
18
+
19
+ /** The RAG index of the shared memory (one collection per project, `memory-<project>`); its files are read and
20
+ * written through Files. Each call throws when the host cannot answer it (no RAG subsystem). */
21
+ export interface SharedMemory {
22
+ /** The best passages for `query`, one per source file, best first. */
23
+ search(collection: string, query: string, topN: number): Promise<SharedHit[]>;
24
+ /** Index `sources` (virtual paths or globs); `prune` drops the sources of the collection absent from them. */
25
+ ingest(collection: string, sources: readonly string[], options: { prune: boolean }): Promise<SharedIngest>;
26
+ }
@@ -0,0 +1,40 @@
1
+ // The shell ports: one command run to its end, and the commands run detached as jobs.
2
+ // Types only, re-exported by ../ports.ts.
3
+
4
+ /** The outcome of one shell command. */
5
+ export interface ShellResult {
6
+ stdout: string;
7
+ stderr: string;
8
+ /** -1 when the runtime reported none. */
9
+ exitCode: number;
10
+ /** True when the runtime stopped the command at its timeout; absent otherwise. */
11
+ timedOut?: boolean;
12
+ }
13
+
14
+ /** How one command runs. */
15
+ export interface ShellOptions {
16
+ /** Whole seconds before the runtime stops the command; the runtime's default when absent. */
17
+ timeoutSeconds?: number;
18
+ }
19
+
20
+ /** Runs shell commands in the project's working directory, /workspace. A command
21
+ * the runtime refuses or cannot run throws; a failing one returns its exit code. */
22
+ export interface Shell {
23
+ run(command: string, options?: ShellOptions): Promise<ShellResult>;
24
+ }
25
+
26
+ /** Where a detached job stands: running, or exited with its code (-1 when it ended without one). */
27
+ export interface ShellJobStatus { running: boolean; exitCode: number }
28
+
29
+ /** Commands run detached (the runtime's shell jobs): a long suite outlives no shell timeout, its whole
30
+ * output goes to a log file, and the caller reads its tail. A job belongs to the running crew and is
31
+ * stopped when the crew's run ends. A call the runtime refuses throws. */
32
+ export interface ShellJobs {
33
+ /** Starts `command` in /workspace; its id and the virtual path of its log. */
34
+ start(command: string): Promise<{ id: string; log: string }>;
35
+ status(id: string): Promise<ShellJobStatus>;
36
+ /** The last `lines` lines of the job's log (500 at most). */
37
+ tail(id: string, lines: number): Promise<string>;
38
+ /** Waits about `seconds` (code has no timer of its own); false when it cannot wait here. */
39
+ wait(seconds: number): Promise<boolean>;
40
+ }
@@ -0,0 +1,45 @@
1
+ // The telemetry port: what the host reports about the session and its LLM usage.
2
+ // Types only, re-exported by ../ports.ts.
3
+
4
+ /** What the host reports about the session. A field it did not report is undefined. */
5
+ export interface SessionMetadata {
6
+ title?: string;
7
+ /** The model the host booted with. */
8
+ model?: string;
9
+ messageCount?: number;
10
+ estimatedTokens?: number;
11
+ /** The models the host declares (`Llm:AvailableModels`), trimmed and deduplicated. */
12
+ availableModels?: string[];
13
+ }
14
+
15
+ /** The session's cumulative LLM usage. */
16
+ export interface SessionCost {
17
+ costUsd?: number;
18
+ totalTokens?: number;
19
+ totalCalls?: number;
20
+ }
21
+
22
+ /** The session's telemetry: its LLM usage plus the buffer's counters. */
23
+ export interface SessionStats extends SessionCost {
24
+ messageCount?: number;
25
+ estimatedTokens?: number;
26
+ /** Prompt tokens sent, over every model, as the providers counted them, when the host reports them. */
27
+ promptTokens?: number;
28
+ /** Completion tokens received, over every model, as the providers counted them, when the host reports them. */
29
+ completionTokens?: number;
30
+ /** Prompt tokens read from the provider's cache (the hits), summed over the models that report them; undefined
31
+ * when none does (Orkeon #254: not measured, never 0). */
32
+ cacheHitTokens?: number;
33
+ /** Prompt tokens written to the provider's cache, summed over the models that report them; undefined when none does. */
34
+ cacheWriteTokens?: number;
35
+ /** Completion tokens spent reasoning, summed over the models that report them; undefined when none does. */
36
+ reasoningTokens?: number;
37
+ }
38
+
39
+ /** The host's account of the session. Each read throws when the host cannot
40
+ * answer it; callers that only display a value catch and show what they have. */
41
+ export interface Telemetry {
42
+ readMetadata(): Promise<SessionMetadata>;
43
+ readCost(): Promise<SessionCost>;
44
+ readStats(): Promise<SessionStats>;
45
+ }
@@ -0,0 +1,46 @@
1
+ // The tool ports: the host's registered tools, a tool call read as text, and the permission gate's session rules.
2
+ // Types only, re-exported by ../ports.ts.
3
+
4
+ import type { PermissionRule } from "../../domain/agent-policy/permission.ts";
5
+
6
+ /** One tool call read as text: the tool's text, or its own failure message, the
7
+ * runtime's wrapping gone. */
8
+ export type ToolOutcome = { ok: true; text: string } | { ok: false; failure: string };
9
+
10
+ /** The tools the host registers, by the names it registers them under (`file_read`,
11
+ * an MCP server's `get-file-contents` or `listIssues`): a diagnostic view and the
12
+ * check of the extra tools, apart from the catalogue a mode hands the model
13
+ * (shared/domain/agent-policy). Orkeon matches a tool name case-insensitively (an
14
+ * agent's `.tools([...])`, the gate's rules), and so does `find`. */
15
+ export interface ToolCatalogue {
16
+ /** Every registered name, as registered, sorted. */
17
+ names(): string[];
18
+ /** The registered name `name` designates, compared case-insensitively; undefined
19
+ * when the host registers no such tool. */
20
+ find(name: string): string | undefined;
21
+ /** Call the tool `name` designates with `args` as given; resolves to its raw
22
+ * result, throws its failure, or that no registered tool answers to `name`. */
23
+ call(name: string, args: Record<string, unknown>): Promise<unknown>;
24
+ /** The same call, decoded: the result as text, or the tool's own failure message
25
+ * (that no registered tool answers to `name` included). Never throws. */
26
+ callText(name: string, args: Record<string, unknown>): Promise<ToolOutcome>;
27
+ }
28
+
29
+ /** The session rules of the host's permission gate, which it reads at every tool
30
+ * call before the mode: a deny refuses a matching call in every mode, an allow
31
+ * lets it run without asking in every mode but `plan`. The host keeps them until
32
+ * it exits, and removes them only all at once. */
33
+ export interface PermissionRules {
34
+ /** Whether the host keeps session rules (orkeon-repl does). When it does not,
35
+ * the gate decides from the mode alone and every other call throws. */
36
+ available(): boolean;
37
+ /** Whether the host's gate is on (`Orkeon:Security:PermissionGate:Enabled`): false, no rule
38
+ * and no mode is enforced; undefined when the host keeps no session rules. */
39
+ enabled(): boolean | undefined;
40
+ /** Put a rule in force; a rule already in force is kept once. */
41
+ add(rule: PermissionRule): void;
42
+ /** Remove every rule. */
43
+ clear(): void;
44
+ /** The rules in force, one line each: `allow shell_command command=npm test*`. */
45
+ list(): string[];
46
+ }
@@ -0,0 +1,45 @@
1
+ // The usage port: the session's LLM usage by category, as the host accounts it (Orkeon #226).
2
+ // Types only, re-exported by ../ports.ts.
3
+
4
+ /** The tokens of a set of calls: the cache counts are a part of the prompt, the reasoning a part of the completion.
5
+ * A cache or reasoning count is null when no call of the set reported it (Orkeon #254): not measured, never 0. */
6
+ export interface UsageTokens {
7
+ promptTokens: number;
8
+ completionTokens: number;
9
+ cacheHitTokens: number | null;
10
+ cacheWriteTokens: number | null;
11
+ reasoningTokens: number | null;
12
+ }
13
+
14
+ /** What a set of calls spent: `cost` is null when no call of the set was priced; `unpricedCalls` counts the calls
15
+ * nobody priced, which `cost` counts as 0 (while it is not 0, the cost is a lower bound). */
16
+ export interface UsageSpent extends UsageTokens {
17
+ calls: number;
18
+ unpricedCalls: number;
19
+ cost: number | null;
20
+ }
21
+
22
+ /** One model the provider named in its answers. */
23
+ export interface ModelUsage extends UsageSpent {
24
+ model: string;
25
+ }
26
+
27
+ /** One command instance the session keeps, the newest first. */
28
+ export interface CommandUsage extends UsageSpent {
29
+ ticket: string;
30
+ name: string;
31
+ state: string;
32
+ }
33
+
34
+ /** The session's usage of the moment: the totals over every recorded call (a call whose provider named no model is
35
+ * in the totals and in no model row), then by model and by command. */
36
+ export interface UsageReport extends UsageSpent {
37
+ totalTokens: number;
38
+ byModel: ModelUsage[];
39
+ byCommand: CommandUsage[];
40
+ }
41
+
42
+ /** The reader of the session's usage; undefined when the host keeps no account, or the read fails. */
43
+ export interface UsageReader {
44
+ report(): UsageReport | undefined;
45
+ }
@@ -0,0 +1,27 @@
1
+ // The ports: what the application layer needs from outside, named after that need
2
+ // rather than after the runtime that provides it. One file per concern under ports/,
3
+ // re-exported here so that every importer names this module; types only, so it is
4
+ // erased from every bundle. A new port goes in ports/<concern>.ts, plus its line below.
5
+ // The Orkeon adapters live in shared/infrastructure/orkeon/ (and are wired by entry
6
+ // points), the test doubles in tests/support/doubles/.
7
+
8
+ export type { Clock } from "./ports/clock.ts";
9
+ export type { ShellResult, ShellOptions, Shell, ShellJobStatus, ShellJobs } from "./ports/shell.ts";
10
+ export type { Mount, Files } from "./ports/files.ts";
11
+ export type { ProgressSpec, Progress } from "./ports/progress.ts";
12
+ export type {
13
+ StoredMessage, SessionMessages, TokenKinds, TokenBudget, SnipResult, SessionStore, SessionSwitch,
14
+ } from "./ports/session.ts";
15
+ export type { SessionMetadata, SessionCost, SessionStats, Telemetry } from "./ports/telemetry.ts";
16
+ export type { RuntimeInfo, RuntimeInfoReader } from "./ports/runtime.ts";
17
+ export type { UsageTokens, UsageSpent, ModelUsage, CommandUsage, UsageReport, UsageReader } from "./ports/usage.ts";
18
+ export type { MemoryEntry, MemoryStore } from "./ports/memory.ts";
19
+ export type { ToolOutcome, ToolCatalogue, PermissionRules } from "./ports/tools.ts";
20
+ export type { CrewHost, CrewLaunchOptions, ChildRuntime, Logger, RunState, CrewMemory } from "./ports/crew.ts";
21
+ export type { ModelOverride, CompleteRequest, ActRequest, Llm } from "./ports/llm.ts";
22
+ export type { HumanInput } from "./ports/human.ts";
23
+ export type { PendingApproval, PendingApprovals } from "./ports/approvals.ts";
24
+ export type {
25
+ MapLevel, CodeMap, CodeSearchHit, SymbolLocation, CodeIndex, AnchorClosure, AnchorIndex, CostIndex, AffectedTests,
26
+ } from "./ports/code-index.ts";
27
+ export type { SharedHit, SharedIngest, SharedMemory } from "./ports/shared-memory.ts";
@@ -0,0 +1,106 @@
1
+ // Reading the project manifests and the CI workflows, shared by /init (project-init) and
2
+ // /init-verifiers: the files that exist, each cut at MAX_CONFIG_FILE_CHARS, in the order of the domain
3
+ // module (commands first, rules after), and their rendering as material, bounded as a whole.
4
+
5
+ import type { Files } from "./ports.ts";
6
+ import {
7
+ CI_WORKFLOWS_DIR, COMMAND_MANIFESTS, CONFIG_CANDIDATES, MAX_CONFIG_FILE_CHARS, MAX_MANIFESTS_MATERIAL_CHARS,
8
+ RULE_CONFIGS, cutLine, expandCandidates, isSuffixCandidate, leftOutLine,
9
+ } from "../domain/project-manifests.ts";
10
+ import { WORKSPACE } from "../domain/vfs.ts";
11
+
12
+ /** Entries of the workspace root listed to match the suffix candidates (`*.csproj`). */
13
+ const MAX_TOP_LEVEL_ENTRIES = 200;
14
+ /** Workflow files listed under CI_WORKFLOWS_DIR. */
15
+ const MAX_WORKFLOWS = 20;
16
+
17
+ /** A manifest as read: its path relative to the workspace root, its content cut at MAX_CONFIG_FILE_CHARS;
18
+ * `cut`, when set, the characters left out of its end. */
19
+ export interface ManifestText { path: string; content: string; cut?: number }
20
+
21
+ /**
22
+ * The manifests of `candidates` that exist and are not empty, in candidate order. A suffix candidate
23
+ * (`*.csproj`) is matched against one listing of the workspace root, made only when `files` can list
24
+ * and a suffix candidate is asked; without `list` it is skipped. An absent or unreadable file is skipped.
25
+ */
26
+ export async function readManifests(
27
+ files: Pick<Files, "read"> & Partial<Pick<Files, "list">>,
28
+ candidates: readonly string[] = CONFIG_CANDIDATES,
29
+ ): Promise<ManifestText[]> {
30
+ let topLevel: string[] = [];
31
+ if (files.list && candidates.some(isSuffixCandidate)) {
32
+ try {
33
+ topLevel = await files.list(WORKSPACE, MAX_TOP_LEVEL_ENTRIES);
34
+ } catch { /* unlistable — the suffix candidates match nothing */ }
35
+ }
36
+ const found: ManifestText[] = [];
37
+ for (const path of expandCandidates(candidates, topLevel)) {
38
+ try {
39
+ const content = await files.read(`${WORKSPACE}/${path}`);
40
+ if (content.length === 0) continue;
41
+ const cut = content.length - MAX_CONFIG_FILE_CHARS;
42
+ found.push(cut > 0 ? { path, content: content.slice(0, MAX_CONFIG_FILE_CHARS), cut } : { path, content });
43
+ } catch { /* absent or unreadable — skip */ }
44
+ }
45
+ return found;
46
+ }
47
+
48
+ /** The file names under CI_WORKFLOWS_DIR; none when the folder is absent. */
49
+ export async function listCiWorkflows(files: Pick<Files, "list">): Promise<string[]> {
50
+ try {
51
+ return await files.list(`${WORKSPACE}/${CI_WORKFLOWS_DIR}`, MAX_WORKFLOWS);
52
+ } catch {
53
+ return [];
54
+ }
55
+ }
56
+
57
+ /**
58
+ * The CI workflows under CI_WORKFLOWS_DIR as manifests (path `.github/workflows/<name>`), in listing
59
+ * order, each cut at MAX_CONFIG_FILE_CHARS: often the only place the project's real check sequence is
60
+ * written. None when the folder is absent; an empty or unreadable file is skipped.
61
+ */
62
+ export async function readCiWorkflows(files: Pick<Files, "list" | "read">): Promise<ManifestText[]> {
63
+ const paths = (await listCiWorkflows(files)).map((name) => `${CI_WORKFLOWS_DIR}/${name}`);
64
+ return await readManifests(files, paths);
65
+ }
66
+
67
+ /**
68
+ * Every configuration both crews read, in the domain's order rule: the manifests that state commands, then
69
+ * the CI workflows, then the configurations that state rules, `CONTRIBUTING.md` last.
70
+ */
71
+ export async function readConfigFiles(files: Pick<Files, "list" | "read">): Promise<ManifestText[]> {
72
+ return [
73
+ ...await readManifests(files, COMMAND_MANIFESTS),
74
+ ...await readCiWorkflows(files),
75
+ ...await readManifests(files, RULE_CONFIGS),
76
+ ];
77
+ }
78
+
79
+ /** One `<file path="…">` block, its cut line closing it when the manifest was cut. */
80
+ function fileBlock(m: ManifestText): string {
81
+ const cut = (m.cut ?? 0) > 0 ? `\n${cutLine(m.cut ?? 0)}` : "";
82
+ return `<file path="${m.path}">\n${m.content}${cut}\n</file>`;
83
+ }
84
+
85
+ /**
86
+ * The manifests as material: one `<file path="…">` block each, in order, whole files kept while the total
87
+ * stays within `max` characters (a block that does not fit is left out, a later smaller one may still fit),
88
+ * then a line naming the files left out when there are any.
89
+ */
90
+ export function manifestsAsMaterial(manifests: readonly ManifestText[], max = MAX_MANIFESTS_MATERIAL_CHARS): string {
91
+ const kept: string[] = [];
92
+ const leftOut: string[] = [];
93
+ let size = 0;
94
+ for (const m of manifests) {
95
+ const block = fileBlock(m);
96
+ const added = block.length + (kept.length > 0 ? 1 : 0);
97
+ if (size + added > max) {
98
+ leftOut.push(m.path);
99
+ continue;
100
+ }
101
+ kept.push(block);
102
+ size += added;
103
+ }
104
+ if (leftOut.length > 0) kept.push(leftOutLine(leftOut, max));
105
+ return kept.join("\n");
106
+ }
@@ -0,0 +1,84 @@
1
+ // Session IO shared by commands and crews: the conversation buffer, the state
2
+ // bag and the token budget of the SessionStore port, plus the permission mode a
3
+ // session runs in, which reads the state bag and the layered /config.
4
+ //
5
+ // Built over ports (createSessionIo); the instance wired to the runtime is
6
+ // orkeonSessionIo() in shared/infrastructure/orkeon/. The dependency runs one
7
+ // way: this module reads the config store, the config store reads only the
8
+ // session's state bag (the port), never this module.
9
+
10
+ import type { SessionStore } from "./ports.ts";
11
+ import type { ConfigStore } from "./config-store.ts";
12
+ import { PERMISSION_FALLBACK_CONFIG_KEY, isPermissionMode, resolveFallbackMode } from "../domain/permission-modes.ts";
13
+ import type { FallbackResolution } from "../domain/permission-modes.ts";
14
+ import { DEFAULT_MODE_STATE_KEY } from "../domain/session-keys.ts";
15
+
16
+ export interface SessionIo extends SessionStore {
17
+ /** The session-default permission mode set by /mode, or null when unset/invalid
18
+ * (never throws — callers fall back to "default"). */
19
+ readDefaultPermissionMode(): Promise<string | null>;
20
+ /**
21
+ * Resolves the session fallback permission mode from the `permissions.fallback`
22
+ * config key.
23
+ *
24
+ * Reads the LAYERED value (settings file, overridden by the session bag) since
25
+ * B-6. Going through the layered read is not optional: a value persisted in the
26
+ * file and ignored here would be a setting that reports itself as effective and
27
+ * changes nothing — the failure mode B-6 exists to remove.
28
+ *
29
+ * Anything unreadable yields the built-in fallback: a config store that cannot be
30
+ * read must never be able to LOOSEN the policy. The decision itself is pure
31
+ * (`resolveFallbackMode`); this only fetches its input.
32
+ */
33
+ resolveSessionFallbackMode(): Promise<FallbackResolution>;
34
+ /**
35
+ * The mode a prompt runs in when it carries no explicit "mode:" prefix: the
36
+ * /mode session default if set, otherwise the resolved fallback.
37
+ */
38
+ resolveEffectiveSessionMode(): Promise<{ mode: string; via: string }>;
39
+ }
40
+
41
+ export function createSessionIo(deps: {
42
+ store: SessionStore;
43
+ config: Pick<ConfigStore, "readValue">;
44
+ }): SessionIo {
45
+ const { store, config } = deps;
46
+
47
+ async function readDefaultPermissionMode(): Promise<string | null> {
48
+ try {
49
+ const v = await store.readState(DEFAULT_MODE_STATE_KEY);
50
+ if (v != null && isPermissionMode(v)) return v;
51
+ } catch { /* session store optional */ }
52
+ return null;
53
+ }
54
+
55
+ async function resolveSessionFallbackMode(): Promise<FallbackResolution> {
56
+ let configured: unknown;
57
+ try {
58
+ configured = (await config.readValue(PERMISSION_FALLBACK_CONFIG_KEY)).value;
59
+ } catch { /* absent, malformed or unavailable → built-in */ }
60
+ return resolveFallbackMode(configured);
61
+ }
62
+
63
+ return {
64
+ readMessages: () => store.readMessages(),
65
+ writeMessages: (messages) => store.writeMessages(messages),
66
+ reset: () => store.reset(),
67
+ snip: (retain) => store.snip(retain),
68
+ setTitle: (title) => store.setTitle(title),
69
+ readState: (key) => store.readState(key),
70
+ readStates: (keys) => store.readStates(keys),
71
+ writeState: (key, value) => store.writeState(key, value),
72
+ readBudget: () => store.readBudget(),
73
+ // Throws when the session store cannot write; best-effort callers catch.
74
+ appendMessage: (role, content) => store.appendMessage(role, content),
75
+ readDefaultPermissionMode,
76
+ resolveSessionFallbackMode,
77
+ async resolveEffectiveSessionMode() {
78
+ const sessionDefault = await readDefaultPermissionMode();
79
+ if (sessionDefault) return { mode: sessionDefault, via: "session default via /mode" };
80
+ const fallback = await resolveSessionFallbackMode();
81
+ return { mode: fallback.mode, via: fallback.explanation };
82
+ },
83
+ };
84
+ }
@@ -0,0 +1,36 @@
1
+ // JSON values of the session's state bag, over the SessionStore port. The bag
2
+ // holds strings, so a list or a map is stored as JSON; every reader of one goes
3
+ // through here so that they all agree on what an unusable value reads as.
4
+
5
+ import type { SessionStore } from "./ports.ts";
6
+
7
+ /** The parsed value of `key`; undefined when unset, malformed, or when the
8
+ * session store is unavailable (a host without the session tools). */
9
+ async function readJson(session: Pick<SessionStore, "readState">, key: string): Promise<unknown> {
10
+ try {
11
+ const raw = await session.readState(key);
12
+ return raw ? JSON.parse(raw) : undefined;
13
+ } catch {
14
+ return undefined;
15
+ }
16
+ }
17
+
18
+ /** A JSON-array state value; unset, malformed, not an array or unreadable → []. */
19
+ export async function readJsonArray(session: Pick<SessionStore, "readState">, key: string): Promise<unknown[]> {
20
+ const value = await readJson(session, key);
21
+ return Array.isArray(value) ? value : [];
22
+ }
23
+
24
+ /** A JSON-object state value; unset, malformed, not an object or unreadable → {}. */
25
+ export async function readJsonObject(
26
+ session: Pick<SessionStore, "readState">,
27
+ key: string,
28
+ ): Promise<Record<string, unknown>> {
29
+ const value = await readJson(session, key);
30
+ return value && typeof value === "object" && !Array.isArray(value) ? (value as Record<string, unknown>) : {};
31
+ }
32
+
33
+ /** Persist a JSON state value. */
34
+ export async function writeJson(session: Pick<SessionStore, "writeState">, key: string, value: unknown): Promise<void> {
35
+ await session.writeState(key, JSON.stringify(value));
36
+ }