orkeon-code 1.0.0-rc.1 → 1.0.0-rc.3

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 (443) hide show
  1. package/.orkeon-runtime +11 -0
  2. package/.orkeon-version +1 -1
  3. package/NOTICE.md +1 -1
  4. package/README.fr.md +16 -22
  5. package/README.md +16 -22
  6. package/config/appsettings.jev.example.json +4 -1
  7. package/config/appsettings.kev.example.json +4 -1
  8. package/config/appsettings.liquid.example.json +4 -1
  9. package/config/appsettings.ollama-whisper.example.json +1 -0
  10. package/config/appsettings.whisper.example.json +1 -0
  11. package/mcp/whisper/README.md +2 -1
  12. package/orkeon-code +508 -80
  13. package/orkeon-code.ps1 +129 -11
  14. package/package.json +3 -1
  15. package/scripts/dev-run.sh +139 -0
  16. package/src/commands/.orkeon/orkeon-cli.d.ts +1 -4
  17. package/src/commands/_lib/args.ts +5 -4
  18. package/src/commands/_lib/dev/dev-batches.ts +34 -36
  19. package/src/commands/_lib/dev/dev-implement.ts +11 -14
  20. package/src/commands/_lib/dev/dev-source.ts +7 -11
  21. package/src/commands/_lib/dev/dev.ts +34 -37
  22. package/src/commands/_lib/dev/markers.ts +7 -0
  23. package/src/commands/_lib/dev/messages.ts +112 -0
  24. package/src/commands/_lib/dev-step.ts +16 -13
  25. package/src/commands/_lib/dispatch.ts +62 -39
  26. package/src/commands/_lib/git/branch.ts +9 -10
  27. package/src/commands/_lib/git/commit.ts +9 -13
  28. package/src/commands/_lib/git/diff.ts +22 -12
  29. package/src/commands/_lib/git/messages.ts +54 -0
  30. package/src/commands/_lib/git/review.ts +9 -10
  31. package/src/commands/_lib/memory/memory-admit.ts +19 -21
  32. package/src/commands/_lib/memory/memory.ts +3 -2
  33. package/src/commands/_lib/memory/messages.ts +32 -0
  34. package/src/commands/_lib/messages.ts +48 -0
  35. package/src/commands/_lib/project/messages.ts +8 -0
  36. package/src/commands/_lib/session/export.ts +3 -2
  37. package/src/commands/_lib/session/messages.ts +87 -0
  38. package/src/commands/_lib/session/prompts.ts +4 -0
  39. package/src/commands/_lib/session/resume.ts +15 -24
  40. package/src/commands/_lib/session/tasks.ts +20 -23
  41. package/src/commands/_lib/settings/advisor.ts +11 -16
  42. package/src/commands/_lib/settings/agents.ts +18 -28
  43. package/src/commands/_lib/settings/choices.ts +8 -0
  44. package/src/commands/_lib/settings/config.ts +43 -43
  45. package/src/commands/_lib/settings/effort.ts +147 -0
  46. package/src/commands/_lib/settings/hooks.ts +12 -20
  47. package/src/commands/_lib/settings/messages.ts +408 -0
  48. package/src/commands/_lib/settings/mode.ts +33 -24
  49. package/src/commands/_lib/settings/model.ts +71 -36
  50. package/src/commands/_lib/settings/output-style.ts +39 -0
  51. package/src/commands/_lib/settings/permissions.ts +71 -93
  52. package/src/commands/_lib/settings/route.ts +63 -0
  53. package/src/commands/_lib/settings/skills.ts +53 -11
  54. package/src/commands/_lib/settings/theme.ts +42 -0
  55. package/src/commands/_lib/speech/messages.ts +58 -0
  56. package/src/commands/_lib/speech/prompts.ts +4 -0
  57. package/src/commands/_lib/speech/say.ts +9 -10
  58. package/src/commands/_lib/speech/transcribe.ts +14 -23
  59. package/src/commands/_lib/speech/voice.ts +14 -18
  60. package/src/commands/_lib/status/doctor.ts +47 -28
  61. package/src/commands/_lib/status/messages.ts +101 -0
  62. package/src/commands/_lib/status/meta.ts +5 -25
  63. package/src/commands/_lib/status/status.ts +10 -11
  64. package/src/commands/_lib/status/usage-tools.ts +2 -3
  65. package/src/commands/_lib/status/usage.ts +7 -18
  66. package/src/commands/_lib/view.ts +6 -1
  67. package/src/commands/dev/dev-batches.cmd.ts +4 -3
  68. package/src/commands/dev/dev-learn.cmd.ts +3 -3
  69. package/src/commands/dev/dev-plan.cmd.ts +6 -7
  70. package/src/commands/dev/dev-spec.cmd.ts +6 -7
  71. package/src/commands/git/commit.cmd.ts +3 -3
  72. package/src/commands/git/review.cmd.ts +3 -3
  73. package/src/commands/memory/memory.cmd.ts +2 -2
  74. package/src/commands/project/analyze.cmd.ts +3 -3
  75. package/src/commands/project/debug-tool-call.cmd.ts +4 -9
  76. package/src/commands/project/init-verifiers.cmd.ts +3 -3
  77. package/src/commands/project/init.cmd.ts +3 -3
  78. package/src/commands/project/verify.cmd.ts +2 -2
  79. package/src/commands/session/assistant.cmd.ts +2 -2
  80. package/src/commands/session/compact.cmd.ts +1 -1
  81. package/src/commands/session/copy.cmd.ts +8 -7
  82. package/src/commands/session/rename.cmd.ts +3 -2
  83. package/src/commands/session/rewind.cmd.ts +3 -4
  84. package/src/commands/session/summary.cmd.ts +3 -3
  85. package/src/commands/session/tasks.cmd.ts +4 -2
  86. package/src/commands/settings/config.cmd.ts +4 -2
  87. package/src/commands/settings/effort.cmd.ts +10 -31
  88. package/src/commands/settings/fast.cmd.ts +2 -1
  89. package/src/commands/settings/mode.cmd.ts +3 -3
  90. package/src/commands/settings/model.cmd.ts +3 -2
  91. package/src/commands/settings/output-style.cmd.ts +9 -38
  92. package/src/commands/settings/permissions.cmd.ts +2 -2
  93. package/src/commands/settings/proactive.cmd.ts +2 -1
  94. package/src/commands/settings/route.cmd.ts +16 -0
  95. package/src/commands/settings/skills.cmd.ts +3 -3
  96. package/src/commands/settings/theme.cmd.ts +14 -0
  97. package/src/commands/speech/say.cmd.ts +2 -2
  98. package/src/commands/speech/transcribe.cmd.ts +2 -2
  99. package/src/commands/status/release-notes.cmd.ts +1 -1
  100. package/src/crews/.orkeon/orkeon.d.ts +539 -94
  101. package/src/crews/_probe-shared-memory/domain/messages.ts +54 -0
  102. package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +17 -12
  103. package/src/crews/_probe-shared-memory/domain/prompts.ts +5 -0
  104. package/src/crews/_probe-shared-memory/probe.ork.ts +8 -6
  105. package/src/crews/advisor/application/messages.ts +4 -0
  106. package/src/crews/advisor/application/prompts.ts +4 -0
  107. package/src/crews/advisor/application/run-advisor.ts +2 -1
  108. package/src/crews/advisor/crew.ork.ts +6 -5
  109. package/src/crews/advisor/domain/advice.ts +7 -23
  110. package/src/crews/advisor/domain/messages.ts +8 -0
  111. package/src/crews/advisor/domain/prompts.ts +26 -0
  112. package/src/crews/agent-run/application/messages.ts +18 -0
  113. package/src/crews/agent-run/application/run-agent-run.ts +5 -4
  114. package/src/crews/agent-run/crew.ork.ts +4 -4
  115. package/src/crews/analyze/application/messages.ts +27 -0
  116. package/src/crews/analyze/application/prompts.ts +4 -0
  117. package/src/crews/analyze/application/run-analyze.ts +16 -14
  118. package/src/crews/analyze/crew.ork.ts +5 -4
  119. package/src/crews/analyze/domain/harvest.ts +33 -65
  120. package/src/crews/analyze/domain/prompts.ts +86 -0
  121. package/src/crews/code-review/application/lens-material.ts +24 -0
  122. package/src/crews/code-review/application/messages.ts +17 -0
  123. package/src/crews/code-review/application/prompts.ts +10 -17
  124. package/src/crews/code-review/application/review.ts +4 -1
  125. package/src/crews/code-review/application/run-code-review.ts +13 -15
  126. package/src/crews/code-review/crew.ork.ts +6 -5
  127. package/src/crews/code-review/domain/lenses.ts +6 -45
  128. package/src/crews/code-review/domain/messages.ts +25 -0
  129. package/src/crews/code-review/domain/prompts.ts +58 -0
  130. package/src/crews/code-review/domain/report.ts +5 -6
  131. package/src/crews/code-review/domain/scope.ts +6 -12
  132. package/src/crews/dev-batches/application/messages.ts +127 -0
  133. package/src/crews/dev-batches/application/plan-close.ts +12 -12
  134. package/src/crews/dev-batches/application/prompts.ts +10 -0
  135. package/src/crews/dev-batches/application/run-dev-batches.ts +57 -50
  136. package/src/crews/dev-batches/application/run-wave.ts +24 -22
  137. package/src/crews/dev-batches/application/seed-harvest.ts +8 -7
  138. package/src/crews/dev-batches/crew.ork.ts +13 -10
  139. package/src/crews/dev-batches/domain/batches-log.ts +1 -3
  140. package/src/crews/dev-batches/domain/markers.ts +5 -0
  141. package/src/crews/dev-batches/domain/messages.ts +6 -0
  142. package/src/crews/dev-batches/domain/wave-order.ts +3 -2
  143. package/src/crews/dev-change/application/change-material.ts +44 -0
  144. package/src/crews/dev-change/application/evidence.ts +25 -22
  145. package/src/crews/dev-change/application/messages.ts +81 -0
  146. package/src/crews/dev-change/application/{change-prompt.ts → prompts.ts} +40 -43
  147. package/src/crews/dev-change/application/run-dev-change.ts +43 -34
  148. package/src/crews/dev-change/crew.ork.ts +11 -9
  149. package/src/crews/dev-change/domain/change-answer.ts +24 -20
  150. package/src/crews/dev-change/domain/change-render.ts +14 -16
  151. package/src/crews/dev-change/domain/markers.ts +28 -0
  152. package/src/crews/dev-change/domain/messages.ts +16 -0
  153. package/src/crews/dev-implement/application/close.ts +21 -18
  154. package/src/crews/dev-implement/application/locate-sheet.ts +7 -5
  155. package/src/crews/dev-implement/application/messages.ts +161 -0
  156. package/src/crews/dev-implement/application/observe.ts +4 -2
  157. package/src/crews/dev-implement/application/prompts.ts +9 -0
  158. package/src/crews/dev-implement/application/report-writes.ts +14 -9
  159. package/src/crews/dev-implement/application/run-dev-implement.ts +84 -73
  160. package/src/crews/dev-implement/application/suite-job.ts +15 -11
  161. package/src/crews/dev-implement/crew.ork.ts +2 -1
  162. package/src/crews/dev-implement/domain/contracts.ts +59 -60
  163. package/src/crews/dev-implement/domain/correction.ts +16 -15
  164. package/src/crews/dev-implement/domain/cycles.ts +2 -1
  165. package/src/crews/dev-implement/domain/markers.ts +23 -0
  166. package/src/crews/dev-implement/domain/messages.ts +58 -0
  167. package/src/crews/dev-implement/domain/prompts.ts +93 -0
  168. package/src/crews/dev-implement/domain/roles.ts +3 -7
  169. package/src/crews/dev-implement/domain/sheet-edits.ts +6 -5
  170. package/src/crews/dev-implement/domain/sheet-ticks.ts +5 -4
  171. package/src/crews/dev-implement/domain/step-checks.ts +17 -16
  172. package/src/crews/dev-implement/domain/step-section.ts +6 -4
  173. package/src/crews/dev-learn/application/learn-prompt-fit.ts +63 -0
  174. package/src/crews/dev-learn/application/messages.ts +56 -0
  175. package/src/crews/dev-learn/application/prompts.ts +96 -0
  176. package/src/crews/dev-learn/application/run-dev-learn.ts +51 -43
  177. package/src/crews/dev-learn/crew.ork.ts +5 -4
  178. package/src/crews/dev-learn/domain/learn-answer.ts +60 -37
  179. package/src/crews/dev-learn/domain/markers.ts +10 -0
  180. package/src/crews/dev-learn/domain/messages.ts +74 -0
  181. package/src/crews/dev-learn/domain/owner-lines.ts +12 -9
  182. package/src/crews/dev-learn/domain/proposals-render.ts +8 -9
  183. package/src/crews/dev-plan/application/anchor-paths.ts +57 -20
  184. package/src/crews/dev-plan/application/inventory.ts +17 -13
  185. package/src/crews/dev-plan/application/messages.ts +88 -0
  186. package/src/crews/dev-plan/application/plan-prompt-fit.ts +44 -0
  187. package/src/crews/dev-plan/application/{plan-prompt.ts → prompts.ts} +37 -55
  188. package/src/crews/dev-plan/application/run-dev-plan.ts +103 -75
  189. package/src/crews/dev-plan/crew.ork.ts +12 -9
  190. package/src/crews/dev-plan/domain/inventory-model.ts +3 -3
  191. package/src/crews/dev-plan/domain/markers.ts +18 -0
  192. package/src/crews/dev-plan/domain/messages.ts +118 -0
  193. package/src/crews/dev-plan/domain/plan-answer.ts +118 -103
  194. package/src/crews/dev-plan/domain/plan-render.ts +33 -34
  195. package/src/crews/dev-plan/domain/prompts.ts +44 -0
  196. package/src/crews/dev-spec/application/messages.ts +30 -0
  197. package/src/crews/dev-spec/application/{spec-prompt.ts → prompts.ts} +42 -47
  198. package/src/crews/dev-spec/application/run-dev-spec.ts +67 -36
  199. package/src/crews/dev-spec/application/spec-material.ts +42 -0
  200. package/src/crews/dev-spec/crew.ork.ts +11 -9
  201. package/src/crews/dev-spec/domain/markers.ts +30 -0
  202. package/src/crews/dev-spec/domain/messages.ts +39 -0
  203. package/src/crews/dev-spec/domain/spec-answer.ts +46 -47
  204. package/src/crews/dev-spec/domain/spec-render.ts +21 -21
  205. package/src/crews/dev-verify/application/audit-brief.ts +187 -0
  206. package/src/crews/dev-verify/application/audit.ts +38 -30
  207. package/src/crews/dev-verify/application/capture.ts +34 -26
  208. package/src/crews/dev-verify/application/messages.ts +119 -0
  209. package/src/crews/dev-verify/application/prompts.ts +209 -0
  210. package/src/crews/dev-verify/application/run-dev-verify.ts +60 -46
  211. package/src/crews/dev-verify/application/run-gate.ts +11 -9
  212. package/src/crews/dev-verify/crew.ork.ts +7 -7
  213. package/src/crews/dev-verify/domain/audit-answer.ts +16 -12
  214. package/src/crews/dev-verify/domain/capture-sections.ts +5 -4
  215. package/src/crews/dev-verify/domain/commands.ts +3 -3
  216. package/src/crews/dev-verify/domain/gate.ts +21 -16
  217. package/src/crews/dev-verify/domain/markers.ts +16 -0
  218. package/src/crews/dev-verify/domain/mechanical-table.ts +37 -44
  219. package/src/crews/dev-verify/domain/messages.ts +92 -0
  220. package/src/crews/dev-verify/domain/verdict.ts +4 -4
  221. package/src/crews/git-commit/application/draft.ts +38 -55
  222. package/src/crews/git-commit/application/messages.ts +17 -0
  223. package/src/crews/git-commit/application/prompts.ts +47 -0
  224. package/src/crews/git-commit/application/run-git-commit.ts +16 -13
  225. package/src/crews/git-commit/crew.ork.ts +6 -5
  226. package/src/crews/git-commit/domain/commit.ts +15 -35
  227. package/src/crews/git-commit/domain/markers.ts +4 -0
  228. package/src/crews/git-commit/domain/messages.ts +48 -0
  229. package/src/crews/init-verifiers/application/authoring.ts +2 -1
  230. package/src/crews/init-verifiers/application/messages.ts +13 -0
  231. package/src/crews/init-verifiers/application/prompts.ts +5 -1
  232. package/src/crews/init-verifiers/application/run-init-verifiers.ts +3 -2
  233. package/src/crews/init-verifiers/crew.ork.ts +6 -5
  234. package/src/crews/main-loop/application/auto-compact.ts +2 -1
  235. package/src/crews/main-loop/application/messages.ts +81 -0
  236. package/src/crews/main-loop/application/prompts.ts +12 -0
  237. package/src/crews/main-loop/application/run-main-loop.ts +64 -31
  238. package/src/crews/main-loop/application/{turn-prompt.ts → turn-context.ts} +7 -8
  239. package/src/crews/main-loop/crew.ork.ts +12 -7
  240. package/src/crews/main-loop/domain/prompt-assembly.ts +45 -228
  241. package/src/crews/main-loop/domain/prompts.ts +336 -0
  242. package/src/crews/main-loop/domain/turn-chains.ts +10 -9
  243. package/src/crews/project-init/application/detect.ts +5 -4
  244. package/src/crews/project-init/application/messages.ts +15 -0
  245. package/src/crews/project-init/application/prompts.ts +11 -7
  246. package/src/crews/project-init/crew.ork.ts +6 -5
  247. package/src/crews/project-init/domain/existing-files.ts +6 -4
  248. package/src/crews/project-init/domain/messages.ts +13 -0
  249. package/src/crews/project-init/domain/package-map.ts +3 -3
  250. package/src/crews/project-init/domain/prompts.ts +10 -0
  251. package/src/crews/session-compact/application/prompts.ts +5 -0
  252. package/src/crews/session-compact/crew.ork.ts +6 -5
  253. package/src/crews/shared-memory-admit/application/prompts.ts +5 -0
  254. package/src/crews/shared-memory-admit/crew.ork.ts +4 -3
  255. package/src/crews/speech/application/messages.ts +3 -0
  256. package/src/crews/speech/application/prompts.ts +3 -0
  257. package/src/crews/speech/application/run-speech.ts +2 -1
  258. package/src/crews/speech/crew.ork.ts +2 -1
  259. package/src/shared/application/agents/child-agent.ts +11 -7
  260. package/src/shared/application/agents/messages.ts +35 -0
  261. package/src/shared/application/agents/route-agent.ts +115 -0
  262. package/src/shared/application/agents/run-sub-agent.ts +31 -8
  263. package/src/shared/application/compaction/compact-session.ts +19 -14
  264. package/src/shared/application/compaction/messages.ts +20 -0
  265. package/src/shared/application/compaction/prune-context.ts +94 -0
  266. package/src/shared/application/compaction/pruned-llm.ts +35 -0
  267. package/src/shared/application/dev/brief-inventory.ts +6 -4
  268. package/src/shared/application/dev/close-batch.ts +9 -7
  269. package/src/shared/application/dev/find-repo-pack.ts +4 -3
  270. package/src/shared/application/dev/learn-decision.ts +20 -18
  271. package/src/shared/application/dev/load-dev-context.ts +7 -8
  272. package/src/shared/application/dev/measure-access-cost.ts +5 -4
  273. package/src/shared/application/dev/messages.ts +135 -0
  274. package/src/shared/application/dev/phase-timer.ts +54 -0
  275. package/src/shared/application/dev/plan-source.ts +12 -8
  276. package/src/shared/application/dev/preflight.ts +16 -11
  277. package/src/shared/application/dev/prompts.ts +34 -0
  278. package/src/shared/application/dev/question-round.ts +25 -17
  279. package/src/shared/application/dev/resolve-work-folder.ts +4 -3
  280. package/src/shared/application/dev/settle-questions.ts +4 -2
  281. package/src/shared/application/dev/source-review.ts +12 -8
  282. package/src/shared/application/dev/source-step.ts +12 -10
  283. package/src/shared/application/dev/spend.ts +17 -4
  284. package/src/shared/application/dev/step-precedents.ts +2 -1
  285. package/src/shared/application/dev/tool-call-policy.ts +9 -11
  286. package/src/shared/application/dev/tool-callbacks.ts +52 -5
  287. package/src/shared/application/dev/tool-trace-recorder.ts +2 -1
  288. package/src/shared/application/dev/verdict-sources.ts +5 -3
  289. package/src/shared/application/dev/wrapped-tools.ts +4 -2
  290. package/src/shared/application/extra-tools.ts +2 -1
  291. package/src/shared/application/git/batch-worktree.ts +22 -17
  292. package/src/shared/application/git/commit-files.ts +24 -19
  293. package/src/shared/application/git/merge-batch.ts +11 -7
  294. package/src/shared/application/git/messages.ts +75 -0
  295. package/src/shared/application/git/open-pull-request.ts +4 -3
  296. package/src/shared/application/host-context.ts +59 -0
  297. package/src/shared/application/host-layout-store.ts +45 -0
  298. package/src/shared/application/llm-profile.ts +4 -3
  299. package/src/shared/application/messages.ts +14 -0
  300. package/src/shared/application/permission-rules.ts +10 -0
  301. package/src/shared/application/ports/decision.ts +14 -0
  302. package/src/shared/application/ports/human.ts +25 -0
  303. package/src/shared/application/ports/llm.ts +32 -3
  304. package/src/shared/application/ports/memory.ts +1 -1
  305. package/src/shared/application/ports/theme.ts +11 -0
  306. package/src/shared/application/ports.ts +4 -2
  307. package/src/shared/application/session-io.ts +2 -1
  308. package/src/shared/application/shared-memory/admit-entries.ts +16 -14
  309. package/src/shared/application/shared-memory/harvest-after-gaps.ts +5 -8
  310. package/src/shared/application/shared-memory/harvest-mistakes.ts +3 -2
  311. package/src/shared/application/shared-memory/import-agent-memory.ts +9 -7
  312. package/src/shared/application/shared-memory/memory-files.ts +2 -1
  313. package/src/shared/application/shared-memory/memory-settings.ts +2 -1
  314. package/src/shared/application/shared-memory/messages.ts +63 -0
  315. package/src/shared/application/shared-memory/push-candidate.ts +14 -11
  316. package/src/shared/application/shared-memory/recall-precedents.ts +2 -1
  317. package/src/shared/application/skills/messages.ts +4 -0
  318. package/src/shared/application/skills/suggest-skills.ts +102 -0
  319. package/src/shared/application/workflow/messages.ts +8 -0
  320. package/src/shared/application/workflow/workflow-state.ts +7 -6
  321. package/src/shared/domain/agent-policy/behavior-flags.ts +4 -10
  322. package/src/shared/domain/agent-policy/extra-tools.ts +2 -4
  323. package/src/shared/domain/agent-policy/messages.ts +66 -0
  324. package/src/shared/domain/agent-policy/path-rules.ts +299 -0
  325. package/src/shared/domain/agent-policy/permission.ts +20 -18
  326. package/src/shared/domain/agent-policy/prompts.ts +17 -0
  327. package/src/shared/domain/agent-policy/reasoning.ts +59 -0
  328. package/src/shared/domain/agent-policy/rule-sets.ts +18 -14
  329. package/src/shared/domain/agent-policy/tool-access.ts +17 -3
  330. package/src/shared/domain/agent-registry.ts +6 -5
  331. package/src/shared/domain/agents/chain.ts +2 -2
  332. package/src/shared/domain/agents/charter.ts +8 -5
  333. package/src/shared/domain/agents/exclusive.ts +2 -1
  334. package/src/shared/domain/agents/instances.ts +18 -15
  335. package/src/shared/domain/agents/messages.ts +39 -0
  336. package/src/shared/domain/agents/model-route.ts +199 -0
  337. package/src/shared/domain/agents/prompts.ts +20 -0
  338. package/src/shared/domain/code-intel-contract.ts +5 -4
  339. package/src/shared/domain/code-intel-routing.ts +8 -61
  340. package/src/shared/domain/compact-outcome.ts +5 -3
  341. package/src/shared/domain/compaction-thresholds.ts +2 -1
  342. package/src/shared/domain/compaction.ts +22 -113
  343. package/src/shared/domain/config-schema.ts +94 -81
  344. package/src/shared/domain/context-prune.ts +176 -0
  345. package/src/shared/domain/decision/questions.ts +102 -0
  346. package/src/shared/domain/dev/access-cost.ts +19 -15
  347. package/src/shared/domain/dev/batches-concurrency.ts +5 -6
  348. package/src/shared/domain/dev/build-commands.ts +5 -4
  349. package/src/shared/domain/dev/call-guard.ts +29 -28
  350. package/src/shared/domain/dev/carried-text.ts +3 -5
  351. package/src/shared/domain/dev/learn-proposals.ts +51 -12
  352. package/src/shared/domain/dev/learn-state.ts +3 -2
  353. package/src/shared/domain/dev/markers.ts +127 -0
  354. package/src/shared/domain/dev/messages.ts +271 -0
  355. package/src/shared/domain/dev/phase-timing.ts +50 -0
  356. package/src/shared/domain/dev/plan-checks.ts +24 -23
  357. package/src/shared/domain/dev/plan-format.ts +15 -25
  358. package/src/shared/domain/dev/project-files.ts +1 -15
  359. package/src/shared/domain/dev/prompts/brief-blocks.ts +20 -0
  360. package/src/shared/domain/dev/{review-prompt.ts → prompts.ts} +91 -61
  361. package/src/shared/domain/dev/questions.ts +33 -15
  362. package/src/shared/domain/dev/repo-pack.ts +12 -9
  363. package/src/shared/domain/dev/review-answer.ts +40 -17
  364. package/src/shared/domain/dev/review-brief.ts +54 -0
  365. package/src/shared/domain/dev/reviewer-charter.ts +4 -0
  366. package/src/shared/domain/dev/sheet-facts.ts +2 -4
  367. package/src/shared/domain/dev/spec-format.ts +13 -14
  368. package/src/shared/domain/dev/step-budget.ts +4 -2
  369. package/src/shared/domain/dev/step-rules.ts +3 -4
  370. package/src/shared/domain/dev/test-commands.ts +14 -10
  371. package/src/shared/domain/dev/tool-guards.ts +4 -3
  372. package/src/shared/domain/dev/trait-pattern.ts +14 -10
  373. package/src/shared/domain/dev/verdict-format.ts +14 -21
  374. package/src/shared/domain/dev/whitespace.ts +3 -2
  375. package/src/shared/domain/dev/work-folder.ts +6 -4
  376. package/src/shared/domain/dev/yaml-subset.ts +8 -26
  377. package/src/shared/domain/error-text.ts +13 -0
  378. package/src/shared/domain/git/close.ts +14 -11
  379. package/src/shared/domain/git/messages.ts +41 -0
  380. package/src/shared/domain/git/pull-request.ts +5 -5
  381. package/src/shared/domain/host-layout.ts +147 -0
  382. package/src/shared/domain/host-paths.ts +399 -0
  383. package/src/shared/domain/llm-failure.ts +35 -7
  384. package/src/shared/domain/llm-profile.ts +22 -3
  385. package/src/shared/domain/marked-message.ts +1 -5
  386. package/src/shared/domain/markers.ts +30 -0
  387. package/src/shared/domain/messages.ts +291 -0
  388. package/src/shared/domain/model-catalog.ts +2 -9
  389. package/src/shared/domain/permission-modes.ts +4 -8
  390. package/src/shared/domain/prelude.ts +2 -2
  391. package/src/shared/domain/project-manifests.ts +3 -2
  392. package/src/shared/domain/prompts.ts +233 -0
  393. package/src/shared/domain/search-routing.ts +3 -11
  394. package/src/shared/domain/secret-patterns.ts +3 -2
  395. package/src/shared/domain/session-keys.ts +7 -0
  396. package/src/shared/domain/session-start.ts +3 -2
  397. package/src/shared/domain/shared-memory/agent-memory-import.ts +4 -2
  398. package/src/shared/domain/shared-memory/candidates.ts +3 -4
  399. package/src/shared/domain/shared-memory/entry.ts +26 -20
  400. package/src/shared/domain/shared-memory/front-matter.ts +17 -13
  401. package/src/shared/domain/shared-memory/gate.ts +4 -3
  402. package/src/shared/domain/shared-memory/harvest.ts +9 -6
  403. package/src/shared/domain/shared-memory/layout.ts +11 -8
  404. package/src/shared/domain/shared-memory/markers.ts +9 -0
  405. package/src/shared/domain/shared-memory/messages.ts +66 -0
  406. package/src/shared/domain/shared-memory/precedents-block.ts +4 -15
  407. package/src/shared/domain/shared-memory/prompts.ts +28 -0
  408. package/src/shared/domain/shared-memory/refused.ts +3 -3
  409. package/src/shared/domain/skills/prompts.ts +4 -0
  410. package/src/shared/domain/skills/shortlist.ts +149 -0
  411. package/src/shared/domain/snip-turns.ts +2 -14
  412. package/src/shared/domain/speech.ts +2 -1
  413. package/src/shared/domain/tool-trace.ts +5 -7
  414. package/src/shared/domain/verifiers.ts +7 -11
  415. package/src/shared/domain/vfs.ts +8 -1
  416. package/src/shared/domain/workflow/prompts.ts +15 -0
  417. package/src/shared/domain/workflow/state-file.ts +14 -12
  418. package/src/shared/infrastructure/globals.ts +7 -2
  419. package/src/shared/infrastructure/orkeon/child-agents.ts +11 -16
  420. package/src/shared/infrastructure/orkeon/chooser.ts +32 -0
  421. package/src/shared/infrastructure/orkeon/decision-model.ts +31 -0
  422. package/src/shared/infrastructure/orkeon/dev-deps.ts +21 -14
  423. package/src/shared/infrastructure/orkeon/files.ts +24 -6
  424. package/src/shared/infrastructure/orkeon/github-pull-requests.ts +3 -2
  425. package/src/shared/infrastructure/orkeon/host-context.ts +36 -0
  426. package/src/shared/infrastructure/orkeon/human-input.ts +1 -5
  427. package/src/shared/infrastructure/orkeon/llm-profile.ts +36 -16
  428. package/src/shared/infrastructure/orkeon/llm.ts +85 -30
  429. package/src/shared/infrastructure/orkeon/markers.ts +6 -0
  430. package/src/shared/infrastructure/orkeon/memory-store.ts +1 -1
  431. package/src/shared/infrastructure/orkeon/memory-tools.ts +18 -20
  432. package/src/shared/infrastructure/orkeon/messages.ts +15 -0
  433. package/src/shared/infrastructure/orkeon/prompts.ts +47 -0
  434. package/src/shared/infrastructure/orkeon/reasoning.ts +40 -0
  435. package/src/shared/infrastructure/orkeon/script-tools.ts +14 -19
  436. package/src/shared/infrastructure/orkeon/session-store.ts +7 -51
  437. package/src/shared/infrastructure/orkeon/shell-jobs.ts +13 -7
  438. package/src/shared/infrastructure/orkeon/shell.ts +13 -5
  439. package/src/shared/infrastructure/orkeon/tool-catalogue.ts +3 -2
  440. package/src/shared/infrastructure/orkeon/wiring.ts +68 -12
  441. package/src/crews/dev-learn/application/learn-prompt.ts +0 -140
  442. package/src/crews/dev-verify/application/auditor-prompt.ts +0 -323
  443. package/src/shared/domain/session-summary.ts +0 -13
package/orkeon-code CHANGED
@@ -11,6 +11,8 @@
11
11
  # ./orkeon-code --resume [<n> | <id>] # list the saved sessions of this project and pick one
12
12
  # ./orkeon-code trust list | add <path> | remove <path> | check <path> [--trust] # check: exit 0, 3 or 4
13
13
  # ./orkeon-code setup # write ~/.orkeon-code/appsettings.json (never the key)
14
+ # ./orkeon-code run <crew> [--inputs JSON] [--workspace DIR | --demo] [--trust] [-- orkeon run args]
15
+ # # one crew headless, through `orkeon run` (docs/headless.md)
14
16
  #
15
17
  # Folder trust: the first start in a folder asks whether you trust it, before anything of it is read
16
18
  # or mounted; `y` stores it in ~/.orkeon-code/trusted-folders.json, and every folder below it starts
@@ -36,10 +38,15 @@
36
38
  # /resume lists them inside the REPL. A bare --llm-log after -- goes to <state>/llm-logs.
37
39
  #
38
40
  # Modes (auto-detected in this order, or forced with --mode / ORKEON_CODE_MODE):
39
- # tool orkeon-repl on PATH (from the orkeon Debian package, an Orkeon release archive, or the
40
- # dotnet tool), or ORKEON_REPL="<command line>" (e.g. "dotnet /opt/orkeon/Orkeon.ConsoleApp.dll")
41
- # docker ghcr.io/orkeon/orkeon-runners:latest (the last release, not the pin), nothing else to install
41
+ # tool orkeon-repl on PATH (from the orkeon Debian package or the full Orkeon release archive: the dotnet
42
+ # tool installs `orkeon` alone, which `run` uses), or ORKEON_REPL="<command line>"
43
+ # (e.g. "dotnet /opt/orkeon/Orkeon.ConsoleApp.dll")
44
+ # docker ghcr.io/orkeon/orkeon:latest (the last release, not the pin), nothing else to install
42
45
  # source an Orkeon checkout named by ORKEON_SOURCE, built there with `dotnet build`, run from the project
46
+ # With none of them, an install whose package names a runtime (.orkeon-runtime) downloads it once, after asking,
47
+ # into ~/.orkeon-code/runtime (tool mode from then on): `orkeon-code runtime install` does it without starting,
48
+ # ORKEON_CODE_RUNTIME_DOWNLOAD=1 answers yes where there is no terminal, `orkeon-code runtime remove` deletes it.
49
+ # The packages published so far name none: put the orkeon-repl of the full Orkeon release archive of your platform on PATH instead.
43
50
  #
44
51
  # Settings: --settings, else ORKEON_CODE_SETTINGS, else config/appsettings.local.json (a clone),
45
52
  # else ~/.orkeon-code/appsettings.json, else ${XDG_CONFIG_HOME:-~/.config}/orkeon-code/appsettings.json
@@ -52,6 +59,13 @@
52
59
  # mounted on /audio (read-only), <state>/transcripts on /transcripts (read-only), and the
53
60
  # Whisper MCP server of mcp/whisper is declared to the REPL, run by uv (mcp/whisper/README.md).
54
61
  # ORKEON_CODE_VOICE=1 also opens the microphone (/voice) and the speaker (/say, voice.reply).
62
+ #
63
+ # run: <crew> is a name of src/crews (main-loop, git-commit...) or the path of a crew.ork.ts. The project, the trust,
64
+ # the settings and the mounts are the REPL's (/workspace, /output, /tmp, /user-config); the runner is `orkeon run`:
65
+ # tool mode ORKEON_CLI="<command line>", else orkeon on PATH, else the downloaded runtime's bin/orkeon, else in a
66
+ # clone the dotnet tool of .config/dotnet-tools.json; then docker (the image's orkeon entry point); then source
67
+ # (Orkeon.Scripting.Cli of ORKEON_SOURCE); then the runtime the package names, downloaded as for the REPL. The log
68
+ # lines go to stderr, the crew's result to stdout; the exit code is the runner's (0, 1, 2, 130, 75).
55
69
  set -euo pipefail
56
70
  # A CDPATH from the caller would make cd print the folder it enters, into the paths read from it.
57
71
  unset CDPATH
@@ -69,12 +83,14 @@ resolve_links() { # <path>
69
83
  # Follow symlinks, so a link from ~/.local/bin still finds the checkout or the install's version folder.
70
84
  SELF="$(resolve_links "${BASH_SOURCE[0]}")"
71
85
  ROOT="$(cd "$(dirname "$SELF")" && pwd -P)"
86
+ # The folder the launcher was started from: the relative value of a path option given to `run` after -- is read from there.
87
+ CALLER_DIR="$PWD"
72
88
  # The pin is a commit of Orkeon's main (.orkeon-version, ADR 0013): the source mode runs it; the tool and docker
73
89
  # modes run a release, which the pin never names.
74
90
  ORKEON_REF="$(tr -d '[:space:]' < "$ROOT/.orkeon-version")"
75
91
  ORKEON_PIN="${ORKEON_REF:0:7}"
76
92
  CODE_VERSION="$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$ROOT/package.json" | head -n 1)"
77
- IMAGE="${ORKEON_CODE_IMAGE:-ghcr.io/orkeon/orkeon-runners:latest}"
93
+ IMAGE="${ORKEON_CODE_IMAGE:-ghcr.io/orkeon/orkeon:latest}"
78
94
  # A clone (a .git, folder or worktree file, or the tests of an unpacked source archive) or an
79
95
  # install, whose folder is never written to.
80
96
  if [ -e "$ROOT/.git" ] || [ -d "$ROOT/tests" ]; then KIND=clone; else KIND=install; fi
@@ -83,6 +99,67 @@ CODE_HOME="${ORKEON_CODE_HOME:-$HOME/.orkeon-code}"
83
99
  die() { echo "orkeon-code: $*" >&2; exit 1; }
84
100
  warn() { echo "orkeon-code: warning: $*" >&2; }
85
101
 
102
+ # ── The runtime downloaded at the first start (ADR 0028) ───────────────────
103
+ # .orkeon-runtime names the archives published for this package: an id, their folder, a SHA-256 per platform. An
104
+ # empty id (a checkout, or a package whose release published none) means there is none. The archive is
105
+ # extracted where it is kept and runs from there.
106
+ RUNTIME_HOME="$CODE_HOME/runtime"
107
+ runtime_field() { # <key>
108
+ [ -f "$ROOT/.orkeon-runtime" ] || return 0
109
+ sed -n "s/^$1=//p" "$ROOT/.orkeon-runtime" 2>/dev/null | head -n 1 | tr -d '[:space:]'
110
+ }
111
+ RUNTIME_ID="$(runtime_field id)"
112
+ RUNTIME_REPL="$RUNTIME_HOME/${RUNTIME_ID:-none}/bin/orkeon-repl"
113
+ runtime_downloaded() { [ -n "$RUNTIME_ID" ] && [ -x "$RUNTIME_REPL" ]; }
114
+
115
+ # The platform as the archives name it; 1 when no archive is built for it.
116
+ runtime_platform() {
117
+ local os arch
118
+ case "$(uname -s)" in Linux) os=linux ;; Darwin) os=osx ;; *) return 1 ;; esac
119
+ case "$(uname -m)" in x86_64|amd64) arch=x64 ;; aarch64|arm64) arch=arm64 ;; *) return 1 ;; esac
120
+ echo "$os-$arch"
121
+ }
122
+
123
+ sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1"; else shasum -a 256 "$1"; fi | cut -d ' ' -f 1; }
124
+
125
+ # Downloads the runtime of .orkeon-runtime into $RUNTIME_HOME/<id>, checked against the sum the package carries,
126
+ # and removes the runtimes of earlier packages. Nothing is asked: the callers do.
127
+ download_runtime() {
128
+ local platform sum name work found other
129
+ if [ -z "$RUNTIME_ID" ]; then
130
+ [ "$KIND" = install ] || die "this checkout names no runtime to download (.orkeon-runtime): use Docker, orkeon-repl or ORKEON_SOURCE (see docs/getting-started.md)."
131
+ die "this package names no runtime to download (its .orkeon-runtime is empty: its release published none): put the orkeon-repl of the full archive of an Orkeon release (orkeon-<version>-<platform>) on PATH, or use Docker or ORKEON_SOURCE (see docs/getting-started.md)."
132
+ fi
133
+ platform="$(runtime_platform)" && sum="$(runtime_field "$platform")" && [ -n "$sum" ] \
134
+ || die "no Orkeon runtime is published for this platform ($(uname -s) $(uname -m)): install Docker, or the orkeon-repl tool (see docs/getting-started.md)."
135
+ name="orkeon-runtime-$RUNTIME_ID-$platform.tar.gz"
136
+ work="$RUNTIME_HOME/.$RUNTIME_ID.new"
137
+ rm -rf "$work"
138
+ mkdir -p "$work"
139
+ echo "orkeon-code: downloading $(runtime_field url)/$name" >&2
140
+ if command -v curl >/dev/null 2>&1; then curl -fSL "$([ -t 2 ] && echo --progress-bar || echo -s)" -o "$work/$name" "$(runtime_field url)/$name"
141
+ elif command -v wget >/dev/null 2>&1; then wget -q -O "$work/$name" "$(runtime_field url)/$name"
142
+ else rm -rf "$work"; die "neither curl nor wget found: the runtime cannot be downloaded."
143
+ fi || { rm -rf "$work"; die "the download of $name failed: nothing installed."; }
144
+ if [ "$(sha256 "$work/$name")" != "$sum" ]; then
145
+ rm -rf "$work"
146
+ die "checksum mismatch for $name (.orkeon-runtime says $sum): the download was deleted, nothing installed."
147
+ fi
148
+ mkdir "$work/tree"
149
+ tar -xzf "$work/$name" -C "$work/tree" || { rm -rf "$work"; die "$name cannot be extracted: nothing installed."; }
150
+ # The archive holds bin/orkeon-repl, at its root or in one folder.
151
+ found="$(find "$work/tree" -maxdepth 3 -path '*/bin/orkeon-repl' -type f | head -n 1)"
152
+ [ -n "$found" ] || { rm -rf "$work"; die "$name holds no bin/orkeon-repl: nothing installed."; }
153
+ chmod 0755 "$found"
154
+ rm -rf "$RUNTIME_HOME/${RUNTIME_ID:?}"
155
+ mv "$(dirname "$(dirname "$found")")" "$RUNTIME_HOME/$RUNTIME_ID"
156
+ rm -rf "$work"
157
+ for other in "$RUNTIME_HOME"/*; do
158
+ if [ -d "$other" ] && [ "$other" != "$RUNTIME_HOME/$RUNTIME_ID" ]; then rm -rf "$other"; fi
159
+ done
160
+ echo "orkeon-code: Orkeon $RUNTIME_ID installed in $RUNTIME_HOME/$RUNTIME_ID (orkeon-code runtime remove deletes it)." >&2
161
+ }
162
+
86
163
  # Moves the Orkeon checkout of ORKEON_SOURCE from <head> to the pin, when nothing of the user's is in the way: no
87
164
  # change to a tracked file, on main or detached, <head> an ancestor of the pin (fetched from origin's main when
88
165
  # missing). Fails, moving nothing, otherwise or with ORKEON_SOURCE_FOLLOW_PIN=0.
@@ -128,8 +205,10 @@ runtime_found() { # <forced mode or empty>
128
205
  elif v="$(dpkg-query -W -f='${Version}' orkeon 2>/dev/null)" && [ -n "$v" ]; then echo "$v ($repl, the orkeon package)"
129
206
  else echo "unknown ($repl_bin)"
130
207
  fi
208
+ elif runtime_downloaded; then echo "$RUNTIME_ID (downloaded, $RUNTIME_HOME/$RUNTIME_ID)"
131
209
  elif command -v docker >/dev/null 2>&1; then echo "image $IMAGE (docker mode, not pulled)"
132
210
  elif [ -n "${ORKEON_SOURCE:-}" ]; then source_found
211
+ elif [ -n "$RUNTIME_ID" ]; then echo "none yet ($RUNTIME_ID is downloaded at the first start)"
133
212
  else echo "none (see docs/getting-started.md)"
134
213
  fi
135
214
  }
@@ -241,8 +320,16 @@ project_slug() ( # <path>
241
320
  printf '%s-%s\n' "$(printf '%s' "$out" | tr 'A-Z' 'a-z')" "${hash:0:12}"
242
321
  )
243
322
 
244
- # <string> as a JSON string, the trust store's escaping (\ and ").
245
- json_string() { local s="${1//\\/\\\\}"; printf '"%s"' "${s//\"/\\\"}"; }
323
+ # <text> as a JSON string: \, " and every control character escaped. awk, not bash's ${s//}, whose backslashes in the
324
+ # replacement differ from bash 3.2 to 5.2; bytes, not characters (LC_ALL=C), so UTF-8 passes as it is. No node, no jq.
325
+ json_str() {
326
+ LC_ALL=C awk 'BEGIN {
327
+ s = ARGV[1]; for (i = 1; i < 32; i++) e[sprintf("%c", i)] = sprintf("\\u%04x", i)
328
+ e["\\"] = "\\\\"; e["\""] = "\\\""; e["\n"] = "\\n"; e["\t"] = "\\t"; e["\r"] = "\\r"
329
+ o = "\""; for (i = 1; i <= length(s); i++) { c = substr(s, i, 1); o = o ((c in e) ? e[c] : c) }
330
+ printf "%s\"", o
331
+ }' "$1"
332
+ }
246
333
 
247
334
  # A string field of a session file as stored (its escapes unread), or nothing.
248
335
  session_field() { # <file> <field>
@@ -380,7 +467,7 @@ if [ "${1:-}" = trust ]; then
380
467
  die "$target is not a trusted folder."
381
468
  fi
382
469
  printf '%s\n' "$kept" | write_trust_store; echo "orkeon-code: $target is no longer trusted."; exit 0 ;;
383
- check) # 0: it may start; 3: refused, no terminal; 4: declined in the terminal (scripts/run-crew.sh).
470
+ check) # 0: it may start; 3: refused, no terminal; 4: declined in the terminal (scripts/dev-run.sh).
384
471
  DECLINED=4
385
472
  folder="$(canonical_dir "${2:?trust check needs a folder}")" || die "not a folder: $2"
386
473
  ensure_trusted "$folder" "$([ "${3:-}" = --trust ] && echo 1 || echo 0)"; exit 0 ;;
@@ -393,6 +480,54 @@ fi
393
480
  case "${XDG_CONFIG_HOME:-}" in /*) CONFIG_BASE="$XDG_CONFIG_HOME" ;; *) CONFIG_BASE="$HOME/.config" ;; esac
394
481
  HOME_SETTINGS="$CODE_HOME/appsettings.json"
395
482
  LEGACY_SETTINGS="$CONFIG_BASE/orkeon-code/appsettings.json"
483
+ # Has the runtime downloaded, once: asked on the terminal, taken as agreed with ORKEON_CODE_RUNTIME_DOWNLOAD=1,
484
+ # refused without a terminal (3) and on a no (DECLINED), like the folder trust.
485
+ ensure_runtime() {
486
+ local answer
487
+ runtime_downloaded && return 0
488
+ if [ "${ORKEON_CODE_RUNTIME_DOWNLOAD:-}" != 1 ]; then
489
+ if [ ! -t 0 ]; then
490
+ echo "orkeon-code: no Orkeon runtime found, and there is no terminal to ask in before downloading one. Run" \
491
+ "'orkeon-code runtime install' once, or set ORKEON_CODE_RUNTIME_DOWNLOAD=1." >&2
492
+ exit 3
493
+ fi
494
+ {
495
+ echo "orkeon-code: no Orkeon runtime found on this machine."
496
+ echo " Orkeon $RUNTIME_ID can be downloaded once (about 120 MB) into $RUNTIME_HOME."
497
+ printf '[y] download [n] quit: '
498
+ } >&2
499
+ read -r answer || answer=""
500
+ case "$(lowered "$answer")" in
501
+ y|yes) ;;
502
+ *) echo "orkeon-code: nothing downloaded, nothing started." >&2; exit "$DECLINED" ;;
503
+ esac
504
+ fi
505
+ download_runtime
506
+ }
507
+ if [ "${1:-}" = runtime ]; then
508
+ case "${2:-}" in
509
+ install)
510
+ if runtime_downloaded; then echo "orkeon-code: Orkeon $RUNTIME_ID is already in $RUNTIME_HOME/$RUNTIME_ID."; exit 0; fi
511
+ # No runtime named, and a REPL of the user's on PATH: there is nothing to download, the start runs that one.
512
+ # ORKEON_REPL names the command line of the user's REPL: its program must be found, and its assembly or script
513
+ # (a path as its second word, `dotnet /path/Orkeon.ConsoleApp.dll`) must be there, or it is no runtime.
514
+ installed_repl=orkeon-repl; repl_target=""; repl_found=1
515
+ if [ -n "${ORKEON_REPL:-}" ]; then read -r installed_repl repl_target _ <<< "$ORKEON_REPL"; fi
516
+ command -v "$installed_repl" >/dev/null 2>&1 || repl_found=0
517
+ case "$repl_target" in */*) [ -e "$repl_target" ] || repl_found=0 ;; esac
518
+ if [ -z "$RUNTIME_ID" ] && [ -n "${ORKEON_REPL:-}" ] && [ "$repl_found" = 0 ]; then
519
+ die "nothing to download (.orkeon-runtime names no runtime), and ORKEON_REPL names no runtime found here ($ORKEON_REPL): fix ORKEON_REPL, or unset it and put the orkeon-repl of the full archive of an Orkeon release on PATH (see docs/getting-started.md)."
520
+ fi
521
+ if [ -z "$RUNTIME_ID" ] && [ "$repl_found" = 1 ]; then
522
+ echo "orkeon-code: nothing to download (.orkeon-runtime names no runtime): the runtime used is $(runtime_found tool)."; exit 0
523
+ fi
524
+ download_runtime; exit 0 ;;
525
+ remove)
526
+ rm -rf "$RUNTIME_HOME"; echo "orkeon-code: no downloaded runtime left in $RUNTIME_HOME."; exit 0 ;;
527
+ *) die "usage: orkeon-code runtime install | remove" ;;
528
+ esac
529
+ fi
530
+
396
531
  # What `orkeon init` writes and the REPL reads when no --settings is given (RunnerSettings.GetGlobalSettingsPath).
397
532
  RUNTIME_SETTINGS="$CONFIG_BASE/Orkeon/appsettings.json"
398
533
 
@@ -472,6 +607,35 @@ if [ "${1:-}" = setup ]; then
472
607
  exit 0
473
608
  fi
474
609
 
610
+ # ── run: one crew, headless ────────────────────────────────────────────────
611
+ # The crew's script: a name of src/crews, or the path of a crew.ork.ts (a probe of a clone). The start then goes
612
+ # through the project, the trust and the settings as for the REPL, and `run_crew` execs `orkeon run` at the mode.
613
+ RUN_CREW=""
614
+ RUN_INPUTS=""
615
+ RUN_USAGE="usage: orkeon-code run <crew | path/to/crew.ork.ts> [--inputs JSON] [--workspace DIR | --demo] [--trust] [--settings FILE] [--mode docker|tool|source] [-- orkeon run args]"
616
+ crew_names() {
617
+ local f n out=""
618
+ for f in "$ROOT"/src/crews/*/crew.ork.ts; do
619
+ n="${f%/crew.ork.ts}"; n="${n##*/}"
620
+ case "$n" in _*|'*') ;; *) out="${out:+$out, }$n" ;; esac
621
+ done
622
+ printf '%s' "$out"
623
+ }
624
+ if [ "${1:-}" = run ]; then
625
+ case "${2:-}" in -h|--help) echo "$RUN_USAGE"; exit 0 ;; ''|-*) die "$RUN_USAGE" ;; esac
626
+ case "$2" in
627
+ */*|*.ts)
628
+ [ -f "$2" ] || die "crew not found: $2"
629
+ RUN_CREW="$(cd "$(dirname "$2")" && pwd -P)/$(basename "$2")" ;;
630
+ *)
631
+ name_ok=1
632
+ case "$2" in *[!a-z0-9_-]*) name_ok=0 ;; esac
633
+ if [ "$name_ok" = 1 ] && [ -f "$ROOT/src/crews/$2/crew.ork.ts" ]; then RUN_CREW="$ROOT/src/crews/$2/crew.ork.ts"
634
+ else die "no crew '$2' in $ROOT/src/crews (the crews: $(crew_names))."; fi ;;
635
+ esac
636
+ shift 2
637
+ fi
638
+
475
639
  MODE="${ORKEON_CODE_MODE:-}"
476
640
  WORKSPACE=""
477
641
  SETTINGS="${ORKEON_CODE_SETTINGS:-}"
@@ -482,6 +646,7 @@ CONTINUE=0
482
646
  RESUME=0
483
647
  RESUME_CHOICE=""
484
648
  EXTRA=()
649
+ # How many words of EXTRA came before --: `orkeon-code run` reads the words after it as `orkeon run`'s.
485
650
  while [ $# -gt 0 ]; do
486
651
  case "$1" in
487
652
  --mode) MODE="${2:?--mode needs docker|tool|source}"; shift 2 ;;
@@ -493,17 +658,26 @@ while [ $# -gt 0 ]; do
493
658
  --demo) DEMO=1; shift ;;
494
659
  --version) VERSION_ONLY=1; shift ;;
495
660
  --trust) TRUST_FLAG=1; shift ;;
661
+ --inputs) RUN_INPUTS="${2:?--inputs needs a JSON object}"; shift 2 ;;
662
+ --inputs=*) RUN_INPUTS="${1#*=}"; shift ;;
496
663
  -c|--continue) CONTINUE=1; shift ;;
497
664
  --resume=*) RESUME=1; RESUME_CHOICE="${1#*=}"; shift ;;
498
665
  --resume)
499
666
  RESUME=1; shift
500
667
  case "${1:-}" in ''|-*) ;; *) RESUME_CHOICE="$1"; shift ;; esac ;;
501
- -h|--help) awk 'NR > 1 && /^set -euo pipefail/ { exit } NR > 1' "$SELF" | sed 's/^# \{0,1\}//'; exit 0 ;;
502
- --) shift; EXTRA=("$@"); break ;;
668
+ -h|--help)
669
+ if [ -n "$RUN_CREW" ]; then echo "$RUN_USAGE"; exit 0; fi
670
+ awk 'NR > 1 && /^set -euo pipefail/ { exit } NR > 1' "$SELF" | sed 's/^# \{0,1\}//'; exit 0 ;;
671
+ --) shift; EXTRA+=("$@"); break ;;
503
672
  *) EXTRA+=("$1"); shift ;;
504
673
  esac
505
674
  done
506
675
 
676
+ if [ -n "$RUN_CREW" ]; then
677
+ [ "$CONTINUE" = 0 ] && [ "$RESUME" = 0 ] && [ "$VERSION_ONLY" = 0 ] \
678
+ || die "--continue, --resume and --version are the REPL's: a run is one turn, with no session ($RUN_USAGE)."
679
+ elif [ -n "$RUN_INPUTS" ]; then die "--inputs belongs to 'orkeon-code run <crew>': the REPL reads no inputs."
680
+ fi
507
681
  if [ "$CONTINUE" = 1 ] && [ "$RESUME" = 1 ]; then die "--continue and --resume do not go together: one brings the last session back, the other the one you pick."; fi
508
682
 
509
683
  if [ "$VERSION_ONLY" = 1 ]; then
@@ -563,26 +737,247 @@ if [ -n "${ORKEON_CODE_MODEL:-}" ]; then export ORKEON_Llm__Model="$ORKEON_CODE_
563
737
  # is checked. On by default here; a settings file can still turn it off.
564
738
  export Orkeon__Security__PermissionGate__Enabled="${Orkeon__Security__PermissionGate__Enabled:-true}"
565
739
 
740
+ # The identity of a commit made in the container (/commit, the close of a dev step): the image sets none and reads no
741
+ # ~/.gitconfig of the host (HOME=/tmp), and Orkeon 1.3.0 hands GIT_AUTHOR_* and GIT_COMMITTER_* to shell_command
742
+ # (Orkeon #404). Each variable already exported is kept; one unset takes the user.name or user.email git gives on
743
+ # the host for the workspace, when git is there and gives one. Sets GIT_IDENTITY_VARS, the names to hand over.
744
+ GIT_IDENTITY_VARS=(GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL)
745
+ git_identity_env() {
746
+ local name="" email=""
747
+ if command -v git >/dev/null 2>&1; then
748
+ name="$(git -C "$WORKSPACE" config --get user.name 2>/dev/null || true)"
749
+ email="$(git -C "$WORKSPACE" config --get user.email 2>/dev/null || true)"
750
+ fi
751
+ [ -n "${GIT_AUTHOR_NAME:-}" ] || { [ -z "$name" ] || export GIT_AUTHOR_NAME="$name"; }
752
+ [ -n "${GIT_COMMITTER_NAME:-}" ] || { [ -z "$name" ] || export GIT_COMMITTER_NAME="$name"; }
753
+ [ -n "${GIT_AUTHOR_EMAIL:-}" ] || { [ -z "$email" ] || export GIT_AUTHOR_EMAIL="$email"; }
754
+ [ -n "${GIT_COMMITTER_EMAIL:-}" ] || { [ -z "$email" ] || export GIT_COMMITTER_EMAIL="$email"; }
755
+ }
756
+
757
+ # ── What the REPL and run share: the state, the user's settings, esbuild, the source build ──
758
+ # Sets SLUG, STATE, PROJECT_REL and PROJECT_STATE, and makes STATE's output/ and tmp/.
759
+ project_state() {
760
+ SLUG="$(project_slug "$WORKSPACE")"
761
+ if [ -n "${ORKEON_CODE_STATE:-}" ]; then STATE="$ORKEON_CODE_STATE"; PROJECT_REL="projects/$SLUG"
762
+ elif [ "$KIND" = clone ]; then STATE="$ROOT/.crew-output"; PROJECT_REL="projects/$SLUG"
763
+ else STATE="$CODE_HOME/projects/$SLUG"; PROJECT_REL=""; fi
764
+ mkdir -p "$STATE/output" "$STATE/tmp"
765
+ STATE="$(cd "$STATE" && pwd)"
766
+ PROJECT_STATE="$STATE${PROJECT_REL:+/$PROJECT_REL}"
767
+ }
768
+
769
+ # The user's orkeonCode block, handed to the scripts as a read-only file: they read no settings and no
770
+ # environment (V-04). Written afresh at each start; no block, or no node to read it (said), leaves the
771
+ # folder empty, and no user setting applies. The key is matched case for case, as in the .ps1. Sets USER_CONFIG_DIR.
772
+ write_user_config() {
773
+ USER_CONFIG_DIR="$STATE/user-config"
774
+ mkdir -p "$USER_CONFIG_DIR"
775
+ rm -f "$USER_CONFIG_DIR/config.json"
776
+ if command -v node >/dev/null 2>&1; then
777
+ node -e 'const fs=require("fs");const s=JSON.parse(fs.readFileSync(process.argv[1],"utf8"));if(s&&typeof s.orkeonCode==="object"&&s.orkeonCode&&!Array.isArray(s.orkeonCode))fs.writeFileSync(process.argv[2],JSON.stringify(s.orkeonCode,null,2)+"\n")' "$SETTINGS" "$USER_CONFIG_DIR/config.json" \
778
+ || warn "the orkeonCode block of $SETTINGS could not be read: no user setting applies."
779
+ elif grep -q '"orkeonCode"' "$SETTINGS"; then
780
+ warn "node is not on PATH: the orkeonCode block of $SETTINGS is not read, no user setting applies."
781
+ fi
782
+ }
783
+
784
+ # The runtime bundles each command and crew with esbuild. The Debian package and a release-archive install carry
785
+ # their own: /usr/bin/orkeon-repl (and orkeon) is a script that points the runtime at /usr/lib/orkeon/esbuild-bin,
786
+ # and an archive's wrapper at its libexec/esbuild-bin. The dotnet tool and a source build carry none: for them, use
787
+ # the one npm installed for this checkout (or, for the npm package, beside it). Exports ORKEON_ESBUILD_PATH then.
788
+ use_esbuild() { # <the runtime's program, as on PATH; empty for a source build>
789
+ local bin bundled="" found
790
+ if [ -n "$1" ] && bin="$(command -v "$1")"; then
791
+ bin="$(resolve_links "$bin")"
792
+ if [ -x "$(dirname "$(dirname "$bin")")/libexec/esbuild-bin/esbuild" ]; then bundled=1
793
+ # A launcher script that sets ORKEON_ESBUILD_PATH itself (the Debian package's).
794
+ elif [ "$(head -c 2 "$bin" 2>/dev/null)" = '#!' ] && grep -q ORKEON_ESBUILD_PATH "$bin" 2>/dev/null; then
795
+ bundled=1
796
+ fi
797
+ fi
798
+ if [ -z "$bundled" ] && [ -z "${ORKEON_ESBUILD_PATH:-}" ] && ! command -v esbuild >/dev/null 2>&1; then
799
+ found="$(find "$ROOT/node_modules/@esbuild" -path '*/bin/esbuild' -type f 2>/dev/null | head -n 1 || true)"
800
+ if [ -z "$found" ] && [ "$KIND" = clone ]; then die "esbuild not found: run 'npm ci' in $ROOT, or set ORKEON_ESBUILD_PATH."; fi
801
+ [ -n "$found" ] \
802
+ || die "esbuild not found: install Orkeon from its package or archive (it carries esbuild), or set ORKEON_ESBUILD_PATH."
803
+ export ORKEON_ESBUILD_PATH="$found"
804
+ fi
805
+ }
806
+
807
+ # Builds <project> of the Orkeon checkout ORKEON_SOURCE names and sets BUILT_DLL, its <assembly> in bin/Debug.
808
+ # The checkout should sit at the pin: one behind it is moved there (follow_pin), another commit runs, with a
809
+ # warning, never a refusal. The SDK runs in the Orkeon checkout, under its global.json, never in the project, whose
810
+ # global.json may pin another SDK ("A compatible .NET SDK was not found"). The program then starts as the built
811
+ # assembly: `dotnet <dll>` is a host command, which reads no global.json. A checkout just moved is restored by its
812
+ # build. The build is quiet and takes a minute after a move: say it runs, or it looks stuck.
813
+ build_source() { # <project> <assembly>
814
+ local restore=--no-restore head
815
+ [ -n "${ORKEON_SOURCE:-}" ] && [ -d "$ORKEON_SOURCE/$1" ] \
816
+ || die "ORKEON_SOURCE must name an Orkeon checkout ($1 not found)."
817
+ ORKEON_SOURCE="$(cd "$ORKEON_SOURCE" && pwd)"
818
+ if head="$(git -C "$ORKEON_SOURCE" rev-parse HEAD 2>/dev/null)" && [ "$head" != "$ORKEON_REF" ]; then
819
+ if follow_pin "$head"; then restore=""
820
+ else warn "ORKEON_SOURCE is at ${head:0:7}, the pin of .orkeon-version is $ORKEON_PIN: the commands were checked against the pin."
821
+ fi
822
+ fi
823
+ echo "orkeon-code: building Orkeon in $ORKEON_SOURCE..." >&2
824
+ (cd "$ORKEON_SOURCE" && dotnet build "$1" -c Debug ${restore:+"$restore"} -nologo -v quiet) >&2 \
825
+ || die "building $1 in $ORKEON_SOURCE failed (restore it once: dotnet restore Orkeon.sln)."
826
+ BUILT_DLL="$ORKEON_SOURCE/$1/bin/Debug/net10.0/$2"
827
+ [ -f "$BUILT_DLL" ] || die "$BUILT_DLL not found after the build."
828
+ }
829
+
830
+ # ── run: the crew through `orkeon run` ─────────────────────────────────────
831
+ # The orkeon tool of the clone's .config/dotnet-tools.json (Orkeon.Scripting.Cli from nuget.org), with dotnet.
832
+ clone_tool() { [ "$KIND" = clone ] && [ -f "$ROOT/.config/dotnet-tools.json" ] && command -v dotnet >/dev/null 2>&1; }
833
+
834
+ # The options of `orkeon run` (the pin's RunCommand) whose value is a file or a folder.
835
+ RUN_PATH_OPTIONS=" --llm-mock --llm-record --llm-replay --llm-log-path --inputs-file "
836
+
837
+ # Sets RUN_PATH to the value of a path option of `orkeon run`, as the runner must read it. The runner starts in the
838
+ # project, the clone or the container: a relative path that names a file or a folder of the caller's folder is made
839
+ # absolute, as the caller meant it. In docker mode, a path under the checkout or the project is named as the
840
+ # container sees it (the checkout is its /work/agent, the project its /work/project), and a file of the host
841
+ # elsewhere stops the run: the container does not see it.
842
+ run_path() { # <path> <mode>
843
+ local inside="" at_root=0 at_project=0
844
+ RUN_PATH="$1"
845
+ case "$1" in
846
+ ''|/*) ;;
847
+ *) if [ -e "$CALLER_DIR/$1" ]; then RUN_PATH="$(cd "$(dirname "$CALLER_DIR/$1")" && pwd -P)/$(basename "$1")"; fi ;;
848
+ esac
849
+ [ "$2" = docker ] || return 0
850
+ case "$RUN_PATH" in "$ROOT"/*) at_root=1 ;; esac
851
+ case "$RUN_PATH" in "$WORKSPACE"/*) at_project=1 ;; esac
852
+ # A project inside the checkout, or the checkout inside the project: the nearer folder names it.
853
+ if [ "$at_project" = 1 ] && { [ "$at_root" = 0 ] || [ "${#WORKSPACE}" -gt "${#ROOT}" ]; }; then
854
+ inside="/work/project/${RUN_PATH#"$WORKSPACE"/}"
855
+ elif [ "$at_root" = 1 ]; then inside="/work/agent/${RUN_PATH#"$ROOT"/}"
856
+ fi
857
+ if [ -n "$inside" ]; then RUN_PATH="$inside"
858
+ elif [ "${RUN_PATH#/}" != "$RUN_PATH" ] && [ -e "$RUN_PATH" ]; then
859
+ die "in docker mode the container sees only the project and the checkout: $1, given after --, lies outside both; put it under the project ($WORKSPACE) and name it from there."
860
+ fi
861
+ }
862
+
863
+ # Sets RUN_EXTRA to the words given to `orkeon run`, before or after --: the value of a path option (--llm-mock FILE,
864
+ # --llm-mock=FILE) goes through run_path, every other word is passed as given.
865
+ run_extra() { # <mode>
866
+ local v value=0
867
+ RUN_EXTRA=()
868
+ for v in ${EXTRA[@]+"${EXTRA[@]}"}; do
869
+ if [ "$value" = 1 ]; then run_path "$v" "$1"; RUN_EXTRA+=("$RUN_PATH")
870
+ else
871
+ case "$v" in
872
+ --*=*)
873
+ case "$RUN_PATH_OPTIONS" in
874
+ *" ${v%%=*} "*) run_path "${v#*=}" "$1"; RUN_EXTRA+=("${v%%=*}=$RUN_PATH") ;;
875
+ *) RUN_EXTRA+=("$v") ;;
876
+ esac ;;
877
+ *) RUN_EXTRA+=("$v") ;;
878
+ esac
879
+ fi
880
+ value=0
881
+ case "$RUN_PATH_OPTIONS" in *" $v "*) value=1 ;; esac
882
+ done
883
+ }
884
+
885
+ # Runs RUN_CREW on the project with the REPL's settings and mounts, in the mode found as the header says; never
886
+ # returns. A plain `orkeon run` writes its log lines on stdout, before the result: the console logger is sent to
887
+ # stderr, so that stdout carries the crew's result alone.
888
+ run_crew() {
889
+ local mode="$MODE" cli=() own="$RUNTIME_HOME/${RUNTIME_ID:-none}/bin/orkeon" rel v env_args user_args
890
+ if [ -z "$mode" ]; then
891
+ if [ -n "${ORKEON_CLI:-}" ] || command -v orkeon >/dev/null 2>&1 || [ -x "$own" ] || clone_tool; then mode=tool
892
+ elif command -v docker >/dev/null 2>&1; then mode=docker
893
+ elif [ -n "${ORKEON_SOURCE:-}" ]; then mode=source
894
+ elif [ -n "$RUNTIME_ID" ]; then mode=tool
895
+ else die "no Orkeon runtime found to run a crew: put the orkeon of the full archive of an Orkeon release (orkeon-<version>-<platform>) on PATH, or use Docker or ORKEON_SOURCE (see docs/headless.md)."
896
+ fi
897
+ fi
898
+ export Orkeon__Embeddings__FingerprintPath="${Orkeon__Embeddings__FingerprintPath:-/output/rag/embedding-fingerprint.json}"
899
+ export Logging__Console__LogToStandardErrorThreshold="${Logging__Console__LogToStandardErrorThreshold:-Trace}"
900
+ case "$mode" in
901
+ tool)
902
+ if [ -n "${ORKEON_CLI:-}" ]; then read -r -a cli <<< "$ORKEON_CLI"
903
+ elif command -v orkeon >/dev/null 2>&1; then cli=(orkeon)
904
+ elif [ -x "$own" ]; then cli=("$own")
905
+ elif clone_tool; then cli=(dotnet tool run orkeon)
906
+ elif [ -n "$RUNTIME_ID" ]; then
907
+ ensure_runtime
908
+ [ -x "$own" ] || die "the runtime in $RUNTIME_HOME/$RUNTIME_ID carries no bin/orkeon: install the orkeon tool, or use Docker."
909
+ cli=("$own")
910
+ else die "orkeon not found: set ORKEON_CLI, or put the orkeon of the full archive of an Orkeon release (orkeon-<version>-<platform>) on PATH (see docs/headless.md)."
911
+ fi
912
+ command -v "${cli[0]}" >/dev/null 2>&1 || die "${cli[0]} not found (see docs/headless.md)."
913
+ if [ "${cli[*]}" = "dotnet tool run orkeon" ]; then
914
+ use_esbuild ""
915
+ (cd "$ROOT" && dotnet tool restore) >&2 || die "dotnet tool restore failed in $ROOT (.config/dotnet-tools.json)."
916
+ else use_esbuild "${cli[0]}"; fi ;;
917
+ source)
918
+ build_source src/scripting/Orkeon.Scripting.Cli orkeon.dll
919
+ cli=(dotnet "$BUILT_DLL")
920
+ use_esbuild "" ;;
921
+ docker)
922
+ command -v docker >/dev/null 2>&1 || die "docker not found."
923
+ docker version --format '{{.Server.Version}}' >/dev/null 2>&1 \
924
+ || die "the Docker engine does not answer: start Docker Desktop or the Docker service, then run orkeon-code again. Without Docker, install the orkeon tool (docs/headless.md)."
925
+ rel="${RUN_CREW#"$ROOT"/}"
926
+ [ "$rel" != "$RUN_CREW" ] || die "in docker mode the crew must lie under $ROOT, the folder the container sees: $RUN_CREW"
927
+ ;;
928
+ *) die "unknown mode '$mode' (expected docker, tool or source)" ;;
929
+ esac
930
+ run_extra "$mode"
931
+ project_state
932
+ write_user_config
933
+ if [ "$mode" = docker ]; then
934
+ env_args=(-e ORKEON_ENTRYPOINT=orkeon -e HOME=/tmp -e DOTNET_CLI_HOME=/tmp
935
+ -e "Orkeon__Security__PermissionGate__Enabled=$Orkeon__Security__PermissionGate__Enabled"
936
+ -e "Orkeon__Embeddings__FingerprintPath=$Orkeon__Embeddings__FingerprintPath"
937
+ -e "Logging__Console__LogToStandardErrorThreshold=$Logging__Console__LogToStandardErrorThreshold")
938
+ git_identity_env
939
+ for v in ORKEON_Llm__ApiKey ORKEON_Llm__Model "$KEY_VAR" GITHUB_TOKEN GH_TOKEN \
940
+ Orkeon__Tools__GitHub__TokenVariable "${Orkeon__Tools__GitHub__TokenVariable:-}" "${GIT_IDENTITY_VARS[@]}"; do
941
+ if [ -n "$v" ] && [ -n "${!v:-}" ]; then env_args+=(-e "$v"); fi
942
+ done
943
+ user_args=()
944
+ if [ "$(uname -s)" = Linux ]; then user_args=(--user "$(id -u):$(id -g)"); fi
945
+ exec docker run --rm -i ${user_args[@]+"${user_args[@]}"} "${env_args[@]}" -w /work \
946
+ -v "$WORKSPACE:/work/project" -v "$ROOT:/work/agent:ro" -v "$SETTINGS:/work/settings.json:ro" -v "$STATE:/work/state" \
947
+ "$IMAGE" run "/work/agent/$rel" -s /work/settings.json \
948
+ -m /work/project:/workspace:rw /work/state/output:/output:rw /work/state/tmp:/tmp:rw /work/state/user-config:/user-config:ro \
949
+ --allow-external-mounts ${RUN_INPUTS:+--inputs "$RUN_INPUTS"} ${RUN_EXTRA[@]+"${RUN_EXTRA[@]}"}
950
+ fi
951
+ # The dotnet tool of the clone is found from its manifest, in the clone; every other runner runs from the project.
952
+ if [ "${cli[*]}" = "dotnet tool run orkeon" ]; then cd "$ROOT"; else cd "$WORKSPACE"; fi
953
+ exec "${cli[@]}" run "$RUN_CREW" -s "$SETTINGS" \
954
+ -m "$WORKSPACE:/workspace:rw" "$STATE/output:/output:rw" "$STATE/tmp:/tmp:rw" "$USER_CONFIG_DIR:/user-config:ro" \
955
+ --allow-external-mounts ${RUN_INPUTS:+--inputs "$RUN_INPUTS"} ${RUN_EXTRA[@]+"${RUN_EXTRA[@]}"}
956
+ }
957
+ if [ -n "$RUN_CREW" ]; then run_crew; fi
958
+
566
959
  # ── Mode ───────────────────────────────────────────────────────────────────
567
960
  if [ -z "$MODE" ]; then
568
- if [ -n "${ORKEON_REPL:-}" ] || command -v orkeon-repl >/dev/null 2>&1; then MODE=tool
961
+ if [ -n "${ORKEON_REPL:-}" ] || command -v orkeon-repl >/dev/null 2>&1 || runtime_downloaded; then MODE=tool
569
962
  elif command -v docker >/dev/null 2>&1; then MODE=docker
570
963
  elif [ -n "${ORKEON_SOURCE:-}" ]; then MODE=source
964
+ elif [ -n "$RUNTIME_ID" ]; then MODE=tool
571
965
  else die "no Orkeon runtime found: install Docker, or the orkeon-repl tool, or set ORKEON_SOURCE (see docs/getting-started.md)."
572
966
  fi
573
967
  fi
968
+ # The tool mode with no orkeon-repl of the user's runs the downloaded runtime, fetched now when it is missing: before
969
+ # any state is made, so a refusal leaves nothing behind.
970
+ OWN_RUNTIME=0
971
+ if [ "$MODE" = tool ] && [ -z "${ORKEON_REPL:-}" ] && ! command -v orkeon-repl >/dev/null 2>&1 && [ -n "$RUNTIME_ID" ]; then
972
+ ensure_runtime
973
+ OWN_RUNTIME=1
974
+ fi
574
975
 
575
976
  # ── State and sessions ─────────────────────────────────────────────────────
576
977
  # An install keeps one folder per project, ~/.orkeon-code/projects/<slug>; a clone's .crew-output and an
577
978
  # ORKEON_CODE_STATE may serve several projects, so their per-project part goes under projects/<slug>.
578
979
  # Either way PROJECT_STATE lies inside STATE, which docker mode mounts on /work/state.
579
- SLUG="$(project_slug "$WORKSPACE")"
580
- if [ -n "${ORKEON_CODE_STATE:-}" ]; then STATE="$ORKEON_CODE_STATE"; PROJECT_REL="projects/$SLUG"
581
- elif [ "$KIND" = clone ]; then STATE="$ROOT/.crew-output"; PROJECT_REL="projects/$SLUG"
582
- else STATE="$CODE_HOME/projects/$SLUG"; PROJECT_REL=""; fi
583
- mkdir -p "$STATE/output" "$STATE/tmp"
584
- STATE="$(cd "$STATE" && pwd)"
585
- PROJECT_STATE="$STATE${PROJECT_REL:+/$PROJECT_REL}"
980
+ project_state
586
981
  # The runtime saves the session in <SessionsDirectory>/<its slug of the project>/last.json when the REPL ends
587
982
  # (FileSessionBufferService), and reloads it at the next start. The folder is the launcher's /sessions mount,
588
983
  # outside the project; the launcher keeps its own files beside it: history/ and project.json.
@@ -596,7 +991,7 @@ if [ "$MODE" = docker ]; then RUNTIME_SLUG="$(project_slug /work/project)"; else
596
991
  now="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
597
992
  first_seen="$(session_field "$PROJECT_STATE/project.json" firstSeen)"
598
993
  {
599
- printf '{\n "path": %s,\n "slug": "%s",\n "runtimeSlug": "%s",\n' "$(json_string "$WORKSPACE")" "$SLUG" "$RUNTIME_SLUG"
994
+ printf '{\n "path": %s,\n "slug": "%s",\n "runtimeSlug": "%s",\n' "$(json_str "$WORKSPACE")" "$SLUG" "$RUNTIME_SLUG"
600
995
  printf ' "firstSeen": "%s",\n "lastSeen": "%s"\n}\n' "${first_seen:-$now}" "$now"
601
996
  } > "$PROJECT_STATE/project.json.tmp.$$" && mv -f "$PROJECT_STATE/project.json.tmp.$$" "$PROJECT_STATE/project.json" \
602
997
  || die "could not write $PROJECT_STATE/project.json."
@@ -690,6 +1085,9 @@ export Orkeon__Cli__Session__StartScript="${Orkeon__Cli__Session__StartScript-/t
690
1085
  export Orkeon__Cli__Session__Persist="${Orkeon__Cli__Session__Persist:-true}"
691
1086
  export ORKEON_Orkeon__Cli__Session__SessionsDirectory=/sessions
692
1087
  export ORKEON_Orkeon__Cli__Memory__RootDirectory=/memory
1088
+ # The embedding model's fingerprint goes beside the RAG's manifests, in /output, not in the project: the runtime's
1089
+ # default, /workspace/.orkeon/, leaves a file in the project that /commit sweeps in. A settings file may name another.
1090
+ export Orkeon__Embeddings__FingerprintPath="${Orkeon__Embeddings__FingerprintPath:-/output/rag/embedding-fingerprint.json}"
693
1091
 
694
1092
  # ── Speech-to-text (optional) ──────────────────────────────────────────────
695
1093
  # ORKEON_CODE_AUDIO_DIR names the folder of audio and video files. The Whisper
@@ -706,7 +1104,9 @@ if [ -n "${ORKEON_CODE_AUDIO_DIR:-}" ]; then
706
1104
  warn "ORKEON_CODE_AUDIO_DIR is ignored in docker mode: the Whisper server runs in tool and source modes (mcp/whisper/README.md)."
707
1105
  elif grep -qi '"whisper"[[:space:]]*:' "$SETTINGS"; then
708
1106
  warn "$SETTINGS declares a \"whisper\" MCP server: ORKEON_CODE_AUDIO_DIR is ignored, the settings file wins."
709
- elif env | grep -q '^ORKEON_MCP__Servers__whisper__'; then
1107
+ # compgen, not `env | grep -q`: grep leaves at the first match, env then dies on the closed pipe, and under pipefail
1108
+ # the test is false although the variable is there.
1109
+ elif compgen -e ORKEON_MCP__Servers__whisper__ >/dev/null; then
710
1110
  warn "the environment declares a \"whisper\" MCP server (ORKEON_MCP__Servers__whisper__*): ORKEON_CODE_AUDIO_DIR is ignored, that declaration wins."
711
1111
  elif ! UV="$(command -v uv)"; then
712
1112
  warn "ORKEON_CODE_AUDIO_DIR is set but uv is not on PATH: speech-to-text is off (mcp/whisper/README.md, 'Install')."
@@ -720,6 +1120,9 @@ if [ -n "${ORKEON_CODE_AUDIO_DIR:-}" ]; then
720
1120
  # The gate reads a server's annotations (readOnlyHint on transcribe_audio, list_audio and whisper_info)
721
1121
  # only when the server is trusted (Orkeon #223); untrusted, every tool of the server would be a write.
722
1122
  export ORKEON_MCP__Servers__whisper__TrustAnnotations=true
1123
+ # The runtime ends a server call after MCP:Servers:<id>:CallTimeout, 60 s by default (Orkeon #299):
1124
+ # a dictation records up to /voice --max (600 s) then transcribes, and a long file on a CPU takes minutes.
1125
+ export ORKEON_MCP__Servers__whisper__CallTimeout=00:15:00
723
1126
  # ORKEON_CODE_VOICE=1 opens the microphone to /voice and the speaker to /say and
724
1127
  # voice.reply: the server gets the `voice` extra (sounddevice), WHISPER_MICROPHONE=1
725
1128
  # and WHISPER_SPEAKER=1; without it, it refuses to record and only writes what it
@@ -759,18 +1162,8 @@ if [ -n "$AUDIO" ]; then
759
1162
  echo " audio : $AUDIO -> /audio (transcripts: $STATE/transcripts, model $model$([ "$(lowered "${WHISPER_DEVICE:-}")" = cuda ] && echo ' on the GPU')$([ "${ORKEON_CODE_VOICE:-}" = 1 ] && echo ', microphone and speaker on'))"
760
1163
  fi
761
1164
 
762
- # The user's orkeonCode block, handed to the scripts as a read-only file: they read no settings and no
763
- # environment (V-04). Written afresh at each start; no block, or no node to read it (said), leaves the
764
- # folder empty, and no user setting applies. The key is matched case for case, as in the .ps1.
765
- USER_CONFIG_DIR="$STATE/user-config"
766
- mkdir -p "$USER_CONFIG_DIR"
767
- rm -f "$USER_CONFIG_DIR/config.json"
768
- if command -v node >/dev/null 2>&1; then
769
- node -e 'const fs=require("fs");const s=JSON.parse(fs.readFileSync(process.argv[1],"utf8"));if(s&&typeof s.orkeonCode==="object"&&s.orkeonCode&&!Array.isArray(s.orkeonCode))fs.writeFileSync(process.argv[2],JSON.stringify(s.orkeonCode,null,2)+"\n")' "$SETTINGS" "$USER_CONFIG_DIR/config.json" \
770
- || warn "the orkeonCode block of $SETTINGS could not be read: no user setting applies."
771
- elif grep -q '"orkeonCode"' "$SETTINGS"; then
772
- warn "node is not on PATH: the orkeonCode block of $SETTINGS is not read, no user setting applies."
773
- fi
1165
+ # The user's orkeonCode block on /user-config (write_user_config).
1166
+ write_user_config
774
1167
 
775
1168
  # Sets ARGS. A function filling an array rather than mapfile: macOS ships bash 3.2.
776
1169
  # An empty <settings> passes none: the REPL then reads Orkeon's own file.
@@ -783,6 +1176,74 @@ repl_args() { # <commands> <crews> <settings> <workspace> <output> <tmp> <user-c
783
1176
  --mount "$8/$SESSIONS_SUB:/sessions:rw" --mount "$8/history:/session-history:ro" --mount "$8/memory:/memory:rw")
784
1177
  }
785
1178
 
1179
+ # The physical folders of the tool and source modes' mounts, in repl_args order from <workspace>.
1180
+ HOST_MOUNTS=("$WORKSPACE" "$STATE/output" "$STATE/tmp" "$USER_CONFIG_DIR" "$PROJECT_STATE")
1181
+
1182
+ # launch.json, beside config.json on /user-config: the host the REPL runs on (posix, wsl or windows) and the physical
1183
+ # base of each mount, the very string given to --mount, with its Windows spelling under WSL (wslpath -w; null without
1184
+ # wslpath). Docker mode hides the host on purpose: posix, no mount. Rewritten at every start. What it reads beyond the
1185
+ # rest of the launcher: WSL_DISTRO_NAME, and ORKEON_CODE_PROC_VERSION (the tests' /proc/version), nothing else (V-04).
1186
+ host_flavour() {
1187
+ if [ "$MODE" = docker ]; then echo posix
1188
+ elif [ -n "${WSL_DISTRO_NAME:-}" ] || grep -qi microsoft "${ORKEON_CODE_PROC_VERSION:-/proc/version}" 2>/dev/null; then echo wsl
1189
+ else echo posix; fi
1190
+ }
1191
+ # The distribution: WSL_DISTRO_NAME, else the share of `wslpath -w /` (\\wsl.localhost\<distro>\ or \\wsl$\<distro>\).
1192
+ wsl_distro() {
1193
+ local root rest
1194
+ if [ -n "${WSL_DISTRO_NAME:-}" ]; then printf '%s' "$WSL_DISTRO_NAME"; return; fi
1195
+ root="$(wslpath -w / 2>/dev/null)" || return 0
1196
+ case "$root" in '\\wsl.localhost\'*) rest="${root:16}" ;; '\\wsl$\'*) rest="${root:7}" ;; *) return 0 ;; esac
1197
+ printf '%s' "${rest%%\\*}"
1198
+ }
1199
+ # Where the Windows drives are mounted: `wslpath -u 'C:\'` less its /c, else [automount] root= of /etc/wsl.conf, else /mnt.
1200
+ wsl_automount_root() {
1201
+ local c root
1202
+ if c="$(wslpath -u 'C:\' 2>/dev/null)" && [ -n "$c" ]; then
1203
+ c="${c%/}"; c="${c%/c}"; printf '%s' "${c:-/}"; return
1204
+ fi
1205
+ root="$(awk -F= '/^[[:space:]]*\[/ { s = tolower($0) ~ /^[[:space:]]*\[automount\]/ }
1206
+ s && $1 ~ /^[[:space:]]*root[[:space:]]*$/ { v = $2; sub(/^[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v); print v; exit }' \
1207
+ /etc/wsl.conf 2>/dev/null)"
1208
+ if [ -n "$root" ]; then root="${root%/}"; printf '%s' "${root:-/}"; else printf '/mnt'; fi
1209
+ }
1210
+ write_launch_file() {
1211
+ local flavour file="$USER_CONFIG_DIR/launch.json" mounts=() m prev="" rest base root w sep="" has_wslpath=0 distro
1212
+ flavour="$(host_flavour)"
1213
+ if [ "$MODE" != docker ]; then
1214
+ repl_args "" "" "" "${HOST_MOUNTS[@]}"
1215
+ for m in "${ARGS[@]}" ${AUDIO_ARGS[@]+"${AUDIO_ARGS[@]}"}; do
1216
+ if [ "$prev" = --mount ]; then mounts+=("$m"); fi
1217
+ prev="$m"
1218
+ done
1219
+ fi
1220
+ if [ "$flavour" = wsl ]; then
1221
+ if command -v wslpath >/dev/null 2>&1; then has_wslpath=1
1222
+ else warn "wslpath is not on PATH: $file gives no Windows spelling of the mounts."; fi
1223
+ fi
1224
+ {
1225
+ printf '{\n "version": 1,\n "flavour": %s,\n "mode": %s,\n' "$(json_str "$flavour")" "$(json_str "$MODE")"
1226
+ if [ "$flavour" = wsl ]; then
1227
+ distro="$(wsl_distro)"
1228
+ printf ' "wsl": { "distro": %s, "automountRoot": %s },\n' \
1229
+ "$(if [ -n "$distro" ]; then json_str "$distro"; else echo null; fi)" "$(json_str "$(wsl_automount_root)")"
1230
+ fi
1231
+ printf ' "mounts": {'
1232
+ for m in ${mounts[@]+"${mounts[@]}"}; do
1233
+ rest="${m%:*}"; root="${rest##*:}"; base="${rest%:*}"
1234
+ printf '%s\n %s: { "posix": %s' "$sep" "$(json_str "$root")" "$(json_str "$base")"
1235
+ if [ "$flavour" = wsl ]; then
1236
+ if [ "$has_wslpath" = 1 ] && w="$(wslpath -w "$base" 2>/dev/null)" && [ -n "$w" ]; then
1237
+ printf ', "windows": %s' "$(json_str "$w")"
1238
+ else printf ', "windows": null'; fi
1239
+ fi
1240
+ printf ' }'; sep=,
1241
+ done
1242
+ if [ -n "$sep" ]; then printf '\n }\n}\n'; else printf '}\n}\n'; fi
1243
+ } > "$file.tmp.$$" && mv -f "$file.tmp.$$" "$file" || warn "could not write $file."
1244
+ }
1245
+ write_launch_file
1246
+
786
1247
  # The exchange log (--llm-log) would land in ./llm-logs, the project: a bare --llm-log among the REPL's
787
1248
  # arguments is sent to <project state>/llm-logs instead; an explicit --llm-log-path is passed as given (a bare
788
1249
  # --llm-log beside it is then dropped, since the runtime keeps the last path it reads).
@@ -800,18 +1261,23 @@ llm_log_args() { # <project state as the REPL sees it>
800
1261
  case "$MODE" in
801
1262
  docker)
802
1263
  command -v docker >/dev/null 2>&1 || die "docker not found."
1264
+ # `docker run` alone would answer with the pipe or the socket it could not open, and nothing about what to do.
1265
+ docker version --format '{{.Server.Version}}' >/dev/null 2>&1 \
1266
+ || die "the Docker engine does not answer: start Docker Desktop or the Docker service, then run orkeon-code again. Without Docker, install the orkeon-repl tool (docs/getting-started.md)."
803
1267
  # Everything the REPL reads sits under its working directory /work. The
804
1268
  # image is multi-arch (linux/amd64, linux/arm64): docker pulls the host's.
805
- env_args=(-e ORKEON_RUNNER=repl -e HOME=/tmp -e DOTNET_CLI_HOME=/tmp
1269
+ env_args=(-e ORKEON_ENTRYPOINT=repl -e HOME=/tmp -e DOTNET_CLI_HOME=/tmp
806
1270
  -e "Orkeon__Security__PermissionGate__Enabled=$Orkeon__Security__PermissionGate__Enabled"
807
1271
  -e "Orkeon__Cli__Session__StartScript=$Orkeon__Cli__Session__StartScript"
808
1272
  -e "Orkeon__Cli__Session__Persist=$Orkeon__Cli__Session__Persist"
809
1273
  -e ORKEON_Orkeon__Cli__Session__SessionsDirectory=/sessions
810
- -e ORKEON_Orkeon__Cli__Memory__RootDirectory=/memory)
1274
+ -e ORKEON_Orkeon__Cli__Memory__RootDirectory=/memory
1275
+ -e "Orkeon__Embeddings__FingerprintPath=$Orkeon__Embeddings__FingerprintPath")
811
1276
  # The github tool's token (Orkeon #222): GITHUB_TOKEN, GH_TOKEN, or the variable Orkeon__Tools__GitHub__TokenVariable
812
1277
  # names, each handed over only when set, with the setting itself so the runtime reads the same variable.
1278
+ git_identity_env
813
1279
  for v in ORKEON_Llm__ApiKey ORKEON_Llm__Model "$KEY_VAR" GITHUB_TOKEN GH_TOKEN \
814
- Orkeon__Tools__GitHub__TokenVariable "${Orkeon__Tools__GitHub__TokenVariable:-}"; do
1280
+ Orkeon__Tools__GitHub__TokenVariable "${Orkeon__Tools__GitHub__TokenVariable:-}" "${GIT_IDENTITY_VARS[@]}"; do
815
1281
  if [ -n "$v" ] && [ -n "${!v:-}" ]; then env_args+=(-e "$v"); fi
816
1282
  done
817
1283
  # Files the agent writes in the project belong to the caller, not to root.
@@ -832,54 +1298,16 @@ case "$MODE" in
832
1298
  ;;
833
1299
  tool|source)
834
1300
  if [ "$MODE" = tool ]; then
835
- if [ -n "${ORKEON_REPL:-}" ]; then read -r -a REPL <<< "$ORKEON_REPL"; else REPL=(orkeon-repl); fi
1301
+ if [ -n "${ORKEON_REPL:-}" ]; then read -r -a REPL <<< "$ORKEON_REPL"
1302
+ elif [ "$OWN_RUNTIME" = 1 ]; then REPL=("$RUNTIME_REPL")
1303
+ else REPL=(orkeon-repl); fi
836
1304
  command -v "${REPL[0]}" >/dev/null 2>&1 || die "${REPL[0]} not found (see docs/getting-started.md, 'Tool mode')."
837
1305
  else
838
- [ -n "${ORKEON_SOURCE:-}" ] && [ -d "$ORKEON_SOURCE/src/apps/Orkeon.ConsoleApp" ] \
839
- || die "ORKEON_SOURCE must name an Orkeon checkout (src/apps/Orkeon.ConsoleApp not found)."
840
- ORKEON_SOURCE="$(cd "$ORKEON_SOURCE" && pwd)"
841
- # The checkout should sit at the pin: one behind it is moved there (follow_pin), another commit runs, with a
842
- # warning, never a refusal.
843
- restore=--no-restore
844
- if head="$(git -C "$ORKEON_SOURCE" rev-parse HEAD 2>/dev/null)" && [ "$head" != "$ORKEON_REF" ]; then
845
- if follow_pin "$head"; then restore=""
846
- else warn "ORKEON_SOURCE is at ${head:0:7}, the pin of .orkeon-version is $ORKEON_PIN: the commands were checked against the pin."
847
- fi
848
- fi
849
- # The SDK runs in the Orkeon checkout, under its global.json, never in the
850
- # project, whose global.json may pin another SDK ("A compatible .NET SDK was
851
- # not found"). The REPL then starts as the built assembly: `dotnet <dll>`
852
- # is a host command, which reads no global.json. A checkout just moved is restored by its build.
853
- # The build is quiet and takes a minute after a move: say it runs, or it looks stuck.
854
- echo "orkeon-code: building Orkeon in $ORKEON_SOURCE..." >&2
855
- (cd "$ORKEON_SOURCE" && dotnet build src/apps/Orkeon.ConsoleApp -c Debug ${restore:+"$restore"} -nologo -v quiet) >&2 \
856
- || die "building src/apps/Orkeon.ConsoleApp in $ORKEON_SOURCE failed (restore it once: dotnet restore Orkeon.sln)."
857
- dll="$ORKEON_SOURCE/src/apps/Orkeon.ConsoleApp/bin/Debug/net10.0/Orkeon.ConsoleApp.dll"
858
- [ -f "$dll" ] || die "$dll not found after the build."
859
- REPL=(dotnet "$dll")
860
- fi
861
- # The runtime bundles each command and crew with esbuild. The Debian package
862
- # and a release-archive install carry their own: /usr/bin/orkeon-repl is a
863
- # script that points the runtime at /usr/lib/orkeon/esbuild-bin, and an
864
- # archive's wrapper at its libexec/esbuild-bin. The dotnet tool and a source
865
- # build carry none: for them, use the one npm installed for this checkout (or, for
866
- # the npm package, beside it).
867
- bundled=""
868
- if [ "$MODE" = tool ] && repl_bin="$(command -v "${REPL[0]}")"; then
869
- repl_bin="$(resolve_links "$repl_bin")"
870
- if [ -x "$(dirname "$(dirname "$repl_bin")")/libexec/esbuild-bin/esbuild" ]; then bundled=1
871
- # A launcher script that sets ORKEON_ESBUILD_PATH itself (the Debian package's).
872
- elif [ "$(head -c 2 "$repl_bin" 2>/dev/null)" = '#!' ] && grep -q ORKEON_ESBUILD_PATH "$repl_bin" 2>/dev/null; then
873
- bundled=1
874
- fi
875
- fi
876
- if [ -z "$bundled" ] && [ -z "${ORKEON_ESBUILD_PATH:-}" ] && ! command -v esbuild >/dev/null 2>&1; then
877
- found="$(find "$ROOT/node_modules/@esbuild" -path '*/bin/esbuild' -type f 2>/dev/null | head -n 1 || true)"
878
- if [ -z "$found" ] && [ "$KIND" = clone ]; then die "esbuild not found: run 'npm ci' in $ROOT, or set ORKEON_ESBUILD_PATH."; fi
879
- [ -n "$found" ] \
880
- || die "esbuild not found: install Orkeon from its package or archive (it carries esbuild), or set ORKEON_ESBUILD_PATH."
881
- export ORKEON_ESBUILD_PATH="$found"
1306
+ build_source src/apps/Orkeon.ConsoleApp Orkeon.ConsoleApp.dll
1307
+ REPL=(dotnet "$BUILT_DLL")
882
1308
  fi
1309
+ # The esbuild the runtime bundles with: its own, else the one npm installed (use_esbuild).
1310
+ use_esbuild "$([ "$MODE" = tool ] && printf '%s' "${REPL[0]}")"
883
1311
  # The REPL runs from the project. It reads its --commands-dir and --crews-dir
884
1312
  # wherever they are, and a --mount outside its working directory (here /output,
885
1313
  # /tmp, /user-config, /sessions, /session-history and /memory, in the state directory,
@@ -888,7 +1316,7 @@ case "$MODE" in
888
1316
  # /llm-logs, /cli-commands..., /crews...).
889
1317
  export ORKEON_ALLOW_EXTERNAL_MOUNTS=1
890
1318
  repl_args "$ROOT/src/commands" "$ROOT/src/crews" "$([ "$RUNTIME_OWN" = 1 ] || echo "$SETTINGS")" \
891
- "$WORKSPACE" "$STATE/output" "$STATE/tmp" "$USER_CONFIG_DIR" "$PROJECT_STATE"
1319
+ "${HOST_MOUNTS[@]}"
892
1320
  llm_log_args "$PROJECT_STATE"
893
1321
  cd "$WORKSPACE"
894
1322
  exec "${REPL[@]}" "${ARGS[@]}" ${AUDIO_ARGS[@]+"${AUDIO_ARGS[@]}"} ${EXTRA[@]+"${EXTRA[@]}"}