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

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 (552) hide show
  1. package/.orkeon-runtime +10 -0
  2. package/.orkeon-version +1 -0
  3. package/LICENSE.md +21 -0
  4. package/NOTICE.md +17 -0
  5. package/README.fr.md +163 -0
  6. package/README.md +156 -2
  7. package/config/appsettings.anthropic.example.json +77 -0
  8. package/config/appsettings.example.json +71 -0
  9. package/config/appsettings.jev.example.json +131 -0
  10. package/config/appsettings.kev.example.json +133 -0
  11. package/config/appsettings.liquid.example.json +132 -0
  12. package/config/appsettings.ollama-whisper.example.json +93 -0
  13. package/config/appsettings.ollama.example.json +70 -0
  14. package/config/appsettings.whisper.example.json +32 -0
  15. package/mcp/whisper/README.md +294 -0
  16. package/mcp/whisper/pyproject.toml +32 -0
  17. package/mcp/whisper/uv.lock +1641 -0
  18. package/mcp/whisper/whisper_mcp.py +1053 -0
  19. package/orkeon-code +1092 -0
  20. package/orkeon-code.mjs +71 -0
  21. package/orkeon-code.ps1 +939 -0
  22. package/package.json +58 -4
  23. package/scripts/install.ps1 +156 -0
  24. package/scripts/install.sh +148 -0
  25. package/scripts/session-start.ork.ts +90 -0
  26. package/scripts/session-start.sh +74 -0
  27. package/scripts/setup-fixture.sh +88 -0
  28. package/src/commands/.orkeon/orkeon-cli.d.ts +559 -0
  29. package/src/commands/_lib/args.ts +194 -0
  30. package/src/commands/_lib/dev/dev-batches.ts +366 -0
  31. package/src/commands/_lib/dev/dev-implement.ts +185 -0
  32. package/src/commands/_lib/dev/dev-source.ts +61 -0
  33. package/src/commands/_lib/dev/dev.ts +341 -0
  34. package/src/commands/_lib/dev/markers.ts +7 -0
  35. package/src/commands/_lib/dev/messages.ts +112 -0
  36. package/src/commands/_lib/dev-step.ts +145 -0
  37. package/src/commands/_lib/dispatch.ts +254 -0
  38. package/src/commands/_lib/effort.ts +15 -0
  39. package/src/commands/_lib/git/branch.ts +94 -0
  40. package/src/commands/_lib/git/commit.ts +90 -0
  41. package/src/commands/_lib/git/diff.ts +107 -0
  42. package/src/commands/_lib/git/messages.ts +54 -0
  43. package/src/commands/_lib/git/review.ts +108 -0
  44. package/src/commands/_lib/memory/memory-admit.ts +148 -0
  45. package/src/commands/_lib/memory/memory.ts +52 -0
  46. package/src/commands/_lib/memory/messages.ts +32 -0
  47. package/src/commands/_lib/messages.ts +48 -0
  48. package/src/commands/_lib/pr-context.ts +32 -0
  49. package/src/commands/_lib/project/analyze.ts +24 -0
  50. package/src/commands/_lib/project/messages.ts +8 -0
  51. package/src/commands/_lib/session/export.ts +105 -0
  52. package/src/commands/_lib/session/messages.ts +87 -0
  53. package/src/commands/_lib/session/prompts.ts +4 -0
  54. package/src/commands/_lib/session/resume.ts +151 -0
  55. package/src/commands/_lib/session/tasks.ts +181 -0
  56. package/src/commands/_lib/settings/advisor.ts +75 -0
  57. package/src/commands/_lib/settings/agents.ts +137 -0
  58. package/src/commands/_lib/settings/choices.ts +8 -0
  59. package/src/commands/_lib/settings/config.ts +141 -0
  60. package/src/commands/_lib/settings/effort.ts +147 -0
  61. package/src/commands/_lib/settings/hooks.ts +50 -0
  62. package/src/commands/_lib/settings/messages.ts +408 -0
  63. package/src/commands/_lib/settings/mode.ts +100 -0
  64. package/src/commands/_lib/settings/model.ts +181 -0
  65. package/src/commands/_lib/settings/output-style.ts +39 -0
  66. package/src/commands/_lib/settings/permissions.ts +287 -0
  67. package/src/commands/_lib/settings/route.ts +63 -0
  68. package/src/commands/_lib/settings/session-config.ts +49 -0
  69. package/src/commands/_lib/settings/skills.ts +93 -0
  70. package/src/commands/_lib/settings/theme.ts +42 -0
  71. package/src/commands/_lib/speech/messages.ts +58 -0
  72. package/src/commands/_lib/speech/prompts.ts +4 -0
  73. package/src/commands/_lib/speech/say.ts +95 -0
  74. package/src/commands/_lib/speech/transcribe.ts +121 -0
  75. package/src/commands/_lib/speech/voice.ts +142 -0
  76. package/src/commands/_lib/status/cache.ts +31 -0
  77. package/src/commands/_lib/status/context.ts +57 -0
  78. package/src/commands/_lib/status/doctor.ts +205 -0
  79. package/src/commands/_lib/status/messages.ts +100 -0
  80. package/src/commands/_lib/status/meta.ts +24 -0
  81. package/src/commands/_lib/status/status.ts +128 -0
  82. package/src/commands/_lib/status/usage-tools.ts +48 -0
  83. package/src/commands/_lib/status/usage.ts +128 -0
  84. package/src/commands/_lib/view.ts +34 -0
  85. package/src/commands/dev/dev-batches.cmd.ts +109 -0
  86. package/src/commands/dev/dev-learn.cmd.ts +29 -0
  87. package/src/commands/dev/dev-plan.cmd.ts +51 -0
  88. package/src/commands/dev/dev-spec.cmd.ts +54 -0
  89. package/src/commands/dev/dev-status.cmd.ts +16 -0
  90. package/src/commands/git/branch.cmd.ts +27 -0
  91. package/src/commands/git/commit.cmd.ts +48 -0
  92. package/src/commands/git/diff.cmd.ts +26 -0
  93. package/src/commands/git/review.cmd.ts +36 -0
  94. package/src/commands/memory/memory.cmd.ts +48 -0
  95. package/src/commands/project/analyze.cmd.ts +32 -0
  96. package/src/commands/project/debug-tool-call.cmd.ts +62 -0
  97. package/src/commands/project/files.cmd.ts +22 -0
  98. package/src/commands/project/init-verifiers.cmd.ts +14 -0
  99. package/src/commands/project/init.cmd.ts +14 -0
  100. package/src/commands/project/verify.cmd.ts +27 -0
  101. package/src/commands/session/assistant.cmd.ts +40 -0
  102. package/src/commands/session/btw.cmd.ts +18 -0
  103. package/src/commands/session/clear.cmd.ts +19 -0
  104. package/src/commands/session/compact.cmd.ts +16 -0
  105. package/src/commands/session/copy.cmd.ts +45 -0
  106. package/src/commands/session/exit.cmd.ts +9 -0
  107. package/src/commands/session/export.cmd.ts +28 -0
  108. package/src/commands/session/rename.cmd.ts +18 -0
  109. package/src/commands/session/resume.cmd.ts +19 -0
  110. package/src/commands/session/rewind.cmd.ts +25 -0
  111. package/src/commands/session/summary.cmd.ts +27 -0
  112. package/src/commands/session/tasks.cmd.ts +46 -0
  113. package/src/commands/settings/advisor.cmd.ts +38 -0
  114. package/src/commands/settings/agents.cmd.ts +19 -0
  115. package/src/commands/settings/config.cmd.ts +19 -0
  116. package/src/commands/settings/effort.cmd.ts +19 -0
  117. package/src/commands/settings/fast.cmd.ts +18 -0
  118. package/src/commands/settings/hooks.cmd.ts +17 -0
  119. package/src/commands/settings/mode.cmd.ts +20 -0
  120. package/src/commands/settings/model.cmd.ts +21 -0
  121. package/src/commands/settings/output-style.cmd.ts +19 -0
  122. package/src/commands/settings/permissions.cmd.ts +25 -0
  123. package/src/commands/settings/proactive.cmd.ts +16 -0
  124. package/src/commands/settings/route.cmd.ts +16 -0
  125. package/src/commands/settings/skills.cmd.ts +17 -0
  126. package/src/commands/settings/theme.cmd.ts +14 -0
  127. package/src/commands/speech/say.cmd.ts +24 -0
  128. package/src/commands/speech/transcribe.cmd.ts +29 -0
  129. package/src/commands/speech/voice.cmd.ts +30 -0
  130. package/src/commands/status/context.cmd.ts +18 -0
  131. package/src/commands/status/doctor.cmd.ts +27 -0
  132. package/src/commands/status/release-notes.cmd.ts +9 -0
  133. package/src/commands/status/status.cmd.ts +25 -0
  134. package/src/commands/status/usage.cmd.ts +21 -0
  135. package/src/crews/.orkeon/orkeon.d.ts +4391 -0
  136. package/src/crews/_probe-shared-memory/domain/messages.ts +54 -0
  137. package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +188 -0
  138. package/src/crews/_probe-shared-memory/domain/prompts.ts +5 -0
  139. package/src/crews/_probe-shared-memory/probe.ork.ts +100 -0
  140. package/src/crews/advisor/application/messages.ts +4 -0
  141. package/src/crews/advisor/application/prompts.ts +4 -0
  142. package/src/crews/advisor/application/run-advisor.ts +41 -0
  143. package/src/crews/advisor/crew.ork.ts +44 -0
  144. package/src/crews/advisor/domain/advice.ts +119 -0
  145. package/src/crews/advisor/domain/messages.ts +8 -0
  146. package/src/crews/advisor/domain/prompts.ts +26 -0
  147. package/src/crews/agent-run/application/messages.ts +18 -0
  148. package/src/crews/agent-run/application/run-agent-run.ts +43 -0
  149. package/src/crews/agent-run/crew.ork.ts +67 -0
  150. package/src/crews/analyze/application/messages.ts +27 -0
  151. package/src/crews/analyze/application/prompts.ts +4 -0
  152. package/src/crews/analyze/application/run-analyze.ts +120 -0
  153. package/src/crews/analyze/crew.ork.ts +41 -0
  154. package/src/crews/analyze/domain/harvest.ts +269 -0
  155. package/src/crews/analyze/domain/prompts.ts +86 -0
  156. package/src/crews/code-review/application/lens-material.ts +24 -0
  157. package/src/crews/code-review/application/messages.ts +17 -0
  158. package/src/crews/code-review/application/prompts.ts +126 -0
  159. package/src/crews/code-review/application/review.ts +74 -0
  160. package/src/crews/code-review/application/run-code-review.ts +121 -0
  161. package/src/crews/code-review/crew.ork.ts +52 -0
  162. package/src/crews/code-review/domain/lenses.ts +154 -0
  163. package/src/crews/code-review/domain/messages.ts +25 -0
  164. package/src/crews/code-review/domain/prompts.ts +58 -0
  165. package/src/crews/code-review/domain/report.ts +58 -0
  166. package/src/crews/code-review/domain/scope.ts +106 -0
  167. package/src/crews/dev-batches/application/messages.ts +127 -0
  168. package/src/crews/dev-batches/application/plan-close.ts +181 -0
  169. package/src/crews/dev-batches/application/prompts.ts +10 -0
  170. package/src/crews/dev-batches/application/run-dev-batches.ts +676 -0
  171. package/src/crews/dev-batches/application/run-wave.ts +452 -0
  172. package/src/crews/dev-batches/application/seed-harvest.ts +163 -0
  173. package/src/crews/dev-batches/crew.ork.ts +146 -0
  174. package/src/crews/dev-batches/domain/batch-waves.ts +70 -0
  175. package/src/crews/dev-batches/domain/batches-budget.ts +52 -0
  176. package/src/crews/dev-batches/domain/batches-log.ts +52 -0
  177. package/src/crews/dev-batches/domain/markers.ts +5 -0
  178. package/src/crews/dev-batches/domain/messages.ts +6 -0
  179. package/src/crews/dev-batches/domain/wave-order.ts +44 -0
  180. package/src/crews/dev-change/application/change-material.ts +44 -0
  181. package/src/crews/dev-change/application/evidence.ts +172 -0
  182. package/src/crews/dev-change/application/messages.ts +81 -0
  183. package/src/crews/dev-change/application/prompts.ts +101 -0
  184. package/src/crews/dev-change/application/run-dev-change.ts +324 -0
  185. package/src/crews/dev-change/crew.ork.ts +114 -0
  186. package/src/crews/dev-change/domain/change-answer.ts +163 -0
  187. package/src/crews/dev-change/domain/change-render.ts +77 -0
  188. package/src/crews/dev-change/domain/markers.ts +28 -0
  189. package/src/crews/dev-change/domain/messages.ts +16 -0
  190. package/src/crews/dev-implement/application/close.ts +186 -0
  191. package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
  192. package/src/crews/dev-implement/application/locate-sheet.ts +82 -0
  193. package/src/crews/dev-implement/application/messages.ts +161 -0
  194. package/src/crews/dev-implement/application/observe.ts +52 -0
  195. package/src/crews/dev-implement/application/prompts.ts +9 -0
  196. package/src/crews/dev-implement/application/report-writes.ts +46 -0
  197. package/src/crews/dev-implement/application/run-dev-implement.ts +822 -0
  198. package/src/crews/dev-implement/application/run-role.ts +27 -0
  199. package/src/crews/dev-implement/application/suite-job.ts +122 -0
  200. package/src/crews/dev-implement/application/touched.ts +74 -0
  201. package/src/crews/dev-implement/crew.ork.ts +69 -0
  202. package/src/crews/dev-implement/domain/contracts.ts +255 -0
  203. package/src/crews/dev-implement/domain/correction.ts +103 -0
  204. package/src/crews/dev-implement/domain/cycles.ts +36 -0
  205. package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
  206. package/src/crews/dev-implement/domain/markers.ts +23 -0
  207. package/src/crews/dev-implement/domain/messages.ts +58 -0
  208. package/src/crews/dev-implement/domain/prompts.ts +93 -0
  209. package/src/crews/dev-implement/domain/roles.ts +49 -0
  210. package/src/crews/dev-implement/domain/sheet-edits.ts +76 -0
  211. package/src/crews/dev-implement/domain/sheet-ticks.ts +23 -0
  212. package/src/crews/dev-implement/domain/step-checks.ts +137 -0
  213. package/src/crews/dev-implement/domain/step-section.ts +129 -0
  214. package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
  215. package/src/crews/dev-learn/application/learn-prompt-fit.ts +63 -0
  216. package/src/crews/dev-learn/application/messages.ts +51 -0
  217. package/src/crews/dev-learn/application/prompts.ts +99 -0
  218. package/src/crews/dev-learn/application/run-dev-learn.ts +558 -0
  219. package/src/crews/dev-learn/crew.ork.ts +53 -0
  220. package/src/crews/dev-learn/domain/learn-answer.ts +233 -0
  221. package/src/crews/dev-learn/domain/messages.ts +65 -0
  222. package/src/crews/dev-learn/domain/owner-lines.ts +89 -0
  223. package/src/crews/dev-learn/domain/proposals-render.ts +95 -0
  224. package/src/crews/dev-plan/application/anchor-paths.ts +113 -0
  225. package/src/crews/dev-plan/application/inventory.ts +174 -0
  226. package/src/crews/dev-plan/application/messages.ts +88 -0
  227. package/src/crews/dev-plan/application/plan-prompt-fit.ts +44 -0
  228. package/src/crews/dev-plan/application/prompts.ts +141 -0
  229. package/src/crews/dev-plan/application/run-dev-plan.ts +483 -0
  230. package/src/crews/dev-plan/crew.ork.ts +112 -0
  231. package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
  232. package/src/crews/dev-plan/domain/markers.ts +18 -0
  233. package/src/crews/dev-plan/domain/messages.ts +118 -0
  234. package/src/crews/dev-plan/domain/plan-answer.ts +753 -0
  235. package/src/crews/dev-plan/domain/plan-render.ts +306 -0
  236. package/src/crews/dev-plan/domain/prompts.ts +44 -0
  237. package/src/crews/dev-spec/application/messages.ts +30 -0
  238. package/src/crews/dev-spec/application/prompts.ts +93 -0
  239. package/src/crews/dev-spec/application/run-dev-spec.ts +237 -0
  240. package/src/crews/dev-spec/application/spec-material.ts +42 -0
  241. package/src/crews/dev-spec/crew.ork.ts +110 -0
  242. package/src/crews/dev-spec/domain/markers.ts +30 -0
  243. package/src/crews/dev-spec/domain/messages.ts +39 -0
  244. package/src/crews/dev-spec/domain/spec-answer.ts +252 -0
  245. package/src/crews/dev-spec/domain/spec-render.ts +76 -0
  246. package/src/crews/dev-verify/application/audit-brief.ts +187 -0
  247. package/src/crews/dev-verify/application/audit.ts +267 -0
  248. package/src/crews/dev-verify/application/capture.ts +311 -0
  249. package/src/crews/dev-verify/application/messages.ts +119 -0
  250. package/src/crews/dev-verify/application/prompts.ts +209 -0
  251. package/src/crews/dev-verify/application/run-dev-verify.ts +423 -0
  252. package/src/crews/dev-verify/application/run-gate.ts +204 -0
  253. package/src/crews/dev-verify/crew.ork.ts +103 -0
  254. package/src/crews/dev-verify/domain/audit-answer.ts +154 -0
  255. package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
  256. package/src/crews/dev-verify/domain/capture-sections.ts +138 -0
  257. package/src/crews/dev-verify/domain/commands.ts +103 -0
  258. package/src/crews/dev-verify/domain/gate.ts +131 -0
  259. package/src/crews/dev-verify/domain/markers.ts +16 -0
  260. package/src/crews/dev-verify/domain/mechanical-table.ts +156 -0
  261. package/src/crews/dev-verify/domain/messages.ts +92 -0
  262. package/src/crews/dev-verify/domain/runtime-cut.ts +13 -0
  263. package/src/crews/dev-verify/domain/sheet-facts.ts +4 -0
  264. package/src/crews/dev-verify/domain/text.ts +20 -0
  265. package/src/crews/dev-verify/domain/verdict.ts +127 -0
  266. package/src/crews/git-commit/application/draft.ts +133 -0
  267. package/src/crews/git-commit/application/messages.ts +15 -0
  268. package/src/crews/git-commit/application/prompts.ts +47 -0
  269. package/src/crews/git-commit/application/run-git-commit.ts +117 -0
  270. package/src/crews/git-commit/crew.ork.ts +53 -0
  271. package/src/crews/git-commit/domain/commit.ts +200 -0
  272. package/src/crews/git-commit/domain/markers.ts +4 -0
  273. package/src/crews/git-commit/domain/messages.ts +48 -0
  274. package/src/crews/init-verifiers/application/authoring.ts +90 -0
  275. package/src/crews/init-verifiers/application/messages.ts +13 -0
  276. package/src/crews/init-verifiers/application/prompts.ts +107 -0
  277. package/src/crews/init-verifiers/application/run-init-verifiers.ts +26 -0
  278. package/src/crews/init-verifiers/crew.ork.ts +35 -0
  279. package/src/crews/init-verifiers/domain/commands-section.ts +36 -0
  280. package/src/crews/init-verifiers/domain/readiness.ts +23 -0
  281. package/src/crews/main-loop/application/auto-compact.ts +78 -0
  282. package/src/crews/main-loop/application/context-gather.ts +133 -0
  283. package/src/crews/main-loop/application/messages.ts +81 -0
  284. package/src/crews/main-loop/application/prompts.ts +12 -0
  285. package/src/crews/main-loop/application/run-main-loop.ts +383 -0
  286. package/src/crews/main-loop/application/turn-context.ts +111 -0
  287. package/src/crews/main-loop/crew.ork.ts +124 -0
  288. package/src/crews/main-loop/domain/autocompact.ts +27 -0
  289. package/src/crews/main-loop/domain/prompt-assembly.ts +338 -0
  290. package/src/crews/main-loop/domain/prompts.ts +336 -0
  291. package/src/crews/main-loop/domain/turn-chains.ts +130 -0
  292. package/src/crews/project-init/application/detect.ts +123 -0
  293. package/src/crews/project-init/application/messages.ts +15 -0
  294. package/src/crews/project-init/application/prompts.ts +105 -0
  295. package/src/crews/project-init/application/run-project-init.ts +31 -0
  296. package/src/crews/project-init/crew.ork.ts +36 -0
  297. package/src/crews/project-init/domain/conventions.ts +36 -0
  298. package/src/crews/project-init/domain/existing-files.ts +65 -0
  299. package/src/crews/project-init/domain/messages.ts +13 -0
  300. package/src/crews/project-init/domain/package-map.ts +73 -0
  301. package/src/crews/project-init/domain/prompts.ts +10 -0
  302. package/src/crews/session-compact/application/prompts.ts +5 -0
  303. package/src/crews/session-compact/crew.ork.ts +56 -0
  304. package/src/crews/shared-memory-admit/application/prompts.ts +5 -0
  305. package/src/crews/shared-memory-admit/crew.ork.ts +49 -0
  306. package/src/crews/speech/application/messages.ts +3 -0
  307. package/src/crews/speech/application/prompts.ts +3 -0
  308. package/src/crews/speech/application/run-speech.ts +26 -0
  309. package/src/crews/speech/crew.ork.ts +38 -0
  310. package/src/shared/application/agents/child-agent.ts +259 -0
  311. package/src/shared/application/agents/messages.ts +35 -0
  312. package/src/shared/application/agents/route-agent.ts +115 -0
  313. package/src/shared/application/agents/run-sub-agent.ts +119 -0
  314. package/src/shared/application/answer-language.ts +14 -0
  315. package/src/shared/application/attached-skills.ts +36 -0
  316. package/src/shared/application/compaction/compact-session.ts +242 -0
  317. package/src/shared/application/compaction/extract-memories.ts +38 -0
  318. package/src/shared/application/compaction/messages.ts +20 -0
  319. package/src/shared/application/compaction/prune-context.ts +94 -0
  320. package/src/shared/application/compaction/pruned-llm.ts +35 -0
  321. package/src/shared/application/compaction/restore-context.ts +78 -0
  322. package/src/shared/application/config-store.ts +123 -0
  323. package/src/shared/application/dev/brief-inventory.ts +115 -0
  324. package/src/shared/application/dev/close-batch.ts +85 -0
  325. package/src/shared/application/dev/find-repo-pack.ts +78 -0
  326. package/src/shared/application/dev/learn-decision.ts +254 -0
  327. package/src/shared/application/dev/load-dev-context.ts +265 -0
  328. package/src/shared/application/dev/measure-access-cost.ts +69 -0
  329. package/src/shared/application/dev/messages.ts +132 -0
  330. package/src/shared/application/dev/phase-timer.ts +54 -0
  331. package/src/shared/application/dev/plan-source.ts +116 -0
  332. package/src/shared/application/dev/preflight.ts +71 -0
  333. package/src/shared/application/dev/project-files.ts +17 -0
  334. package/src/shared/application/dev/prompts.ts +34 -0
  335. package/src/shared/application/dev/question-round.ts +60 -0
  336. package/src/shared/application/dev/resolve-work-folder.ts +134 -0
  337. package/src/shared/application/dev/script-tool-slot.ts +27 -0
  338. package/src/shared/application/dev/settle-questions.ts +57 -0
  339. package/src/shared/application/dev/source-review.ts +67 -0
  340. package/src/shared/application/dev/source-step.ts +152 -0
  341. package/src/shared/application/dev/spend.ts +55 -0
  342. package/src/shared/application/dev/step-precedents.ts +90 -0
  343. package/src/shared/application/dev/tool-call-policy.ts +87 -0
  344. package/src/shared/application/dev/tool-callbacks.ts +262 -0
  345. package/src/shared/application/dev/tool-trace-recorder.ts +46 -0
  346. package/src/shared/application/dev/verdict-sources.ts +50 -0
  347. package/src/shared/application/dev/wrapped-tools.ts +147 -0
  348. package/src/shared/application/extra-tools.ts +71 -0
  349. package/src/shared/application/git/batch-worktree.ts +102 -0
  350. package/src/shared/application/git/commit-files.ts +191 -0
  351. package/src/shared/application/git/merge-batch.ts +67 -0
  352. package/src/shared/application/git/messages.ts +75 -0
  353. package/src/shared/application/git/open-pull-request.ts +52 -0
  354. package/src/shared/application/host-context.ts +59 -0
  355. package/src/shared/application/host-layout-store.ts +45 -0
  356. package/src/shared/application/instructions-file.ts +19 -0
  357. package/src/shared/application/json-file.ts +34 -0
  358. package/src/shared/application/llm-profile.ts +36 -0
  359. package/src/shared/application/messages.ts +14 -0
  360. package/src/shared/application/permission-rules.ts +169 -0
  361. package/src/shared/application/ports/approvals.ts +20 -0
  362. package/src/shared/application/ports/clock.ts +5 -0
  363. package/src/shared/application/ports/code-index.ts +93 -0
  364. package/src/shared/application/ports/crew.ts +60 -0
  365. package/src/shared/application/ports/decision.ts +14 -0
  366. package/src/shared/application/ports/files.ts +21 -0
  367. package/src/shared/application/ports/human.ts +38 -0
  368. package/src/shared/application/ports/llm.ts +83 -0
  369. package/src/shared/application/ports/memory.ts +30 -0
  370. package/src/shared/application/ports/progress.ts +23 -0
  371. package/src/shared/application/ports/runtime.ts +15 -0
  372. package/src/shared/application/ports/session.ts +74 -0
  373. package/src/shared/application/ports/shared-memory.ts +26 -0
  374. package/src/shared/application/ports/shell.ts +40 -0
  375. package/src/shared/application/ports/telemetry.ts +45 -0
  376. package/src/shared/application/ports/theme.ts +11 -0
  377. package/src/shared/application/ports/tools.ts +46 -0
  378. package/src/shared/application/ports/usage.ts +45 -0
  379. package/src/shared/application/ports.ts +29 -0
  380. package/src/shared/application/project-manifests.ts +106 -0
  381. package/src/shared/application/session-io.ts +85 -0
  382. package/src/shared/application/session-state.ts +36 -0
  383. package/src/shared/application/shared-memory/admit-entries.ts +179 -0
  384. package/src/shared/application/shared-memory/harvest-after-gaps.ts +69 -0
  385. package/src/shared/application/shared-memory/harvest-mistakes.ts +45 -0
  386. package/src/shared/application/shared-memory/import-agent-memory.ts +119 -0
  387. package/src/shared/application/shared-memory/memory-files.ts +111 -0
  388. package/src/shared/application/shared-memory/memory-settings.ts +94 -0
  389. package/src/shared/application/shared-memory/messages.ts +63 -0
  390. package/src/shared/application/shared-memory/push-candidate.ts +149 -0
  391. package/src/shared/application/shared-memory/recall-precedents.ts +70 -0
  392. package/src/shared/application/skills/messages.ts +4 -0
  393. package/src/shared/application/skills/suggest-skills.ts +102 -0
  394. package/src/shared/application/state-snapshot.ts +38 -0
  395. package/src/shared/application/workflow/messages.ts +8 -0
  396. package/src/shared/application/workflow/workflow-state.ts +136 -0
  397. package/src/shared/domain/agent-policy/behavior-flags.ts +162 -0
  398. package/src/shared/domain/agent-policy/extra-tools.ts +67 -0
  399. package/src/shared/domain/agent-policy/memory-categories.ts +6 -0
  400. package/src/shared/domain/agent-policy/messages.ts +66 -0
  401. package/src/shared/domain/agent-policy/mode-policy.ts +51 -0
  402. package/src/shared/domain/agent-policy/output-styles.ts +11 -0
  403. package/src/shared/domain/agent-policy/path-rules.ts +299 -0
  404. package/src/shared/domain/agent-policy/permission.ts +625 -0
  405. package/src/shared/domain/agent-policy/prompts.ts +17 -0
  406. package/src/shared/domain/agent-policy/reasoning.ts +59 -0
  407. package/src/shared/domain/agent-policy/rule-sets.ts +416 -0
  408. package/src/shared/domain/agent-policy/tool-access.ts +91 -0
  409. package/src/shared/domain/agent-registry.ts +143 -0
  410. package/src/shared/domain/agents/built-in-charters.ts +43 -0
  411. package/src/shared/domain/agents/chain.ts +30 -0
  412. package/src/shared/domain/agents/charter.ts +64 -0
  413. package/src/shared/domain/agents/exclusive.ts +25 -0
  414. package/src/shared/domain/agents/instances.ts +252 -0
  415. package/src/shared/domain/agents/messages.ts +39 -0
  416. package/src/shared/domain/agents/model-route.ts +199 -0
  417. package/src/shared/domain/agents/prompts.ts +20 -0
  418. package/src/shared/domain/code-intel-contract.ts +357 -0
  419. package/src/shared/domain/code-intel-routing.ts +60 -0
  420. package/src/shared/domain/compact-outcome.ts +46 -0
  421. package/src/shared/domain/compaction-thresholds.ts +162 -0
  422. package/src/shared/domain/compaction.ts +288 -0
  423. package/src/shared/domain/config-schema.ts +434 -0
  424. package/src/shared/domain/context-prune.ts +176 -0
  425. package/src/shared/domain/decision/questions.ts +102 -0
  426. package/src/shared/domain/dev/access-cost.ts +230 -0
  427. package/src/shared/domain/dev/artefacts.ts +50 -0
  428. package/src/shared/domain/dev/batches-concurrency.ts +35 -0
  429. package/src/shared/domain/dev/batches-state.ts +49 -0
  430. package/src/shared/domain/dev/build-commands.ts +45 -0
  431. package/src/shared/domain/dev/call-guard.ts +342 -0
  432. package/src/shared/domain/dev/carried-text.ts +47 -0
  433. package/src/shared/domain/dev/design-rules.ts +100 -0
  434. package/src/shared/domain/dev/learn-proposals.ts +176 -0
  435. package/src/shared/domain/dev/learn-state.ts +94 -0
  436. package/src/shared/domain/dev/markers.ts +107 -0
  437. package/src/shared/domain/dev/messages.ts +259 -0
  438. package/src/shared/domain/dev/path-args.ts +42 -0
  439. package/src/shared/domain/dev/path-rebase.ts +93 -0
  440. package/src/shared/domain/dev/phase-timing.ts +50 -0
  441. package/src/shared/domain/dev/plan-checks.ts +191 -0
  442. package/src/shared/domain/dev/plan-format.ts +170 -0
  443. package/src/shared/domain/dev/project-files.ts +29 -0
  444. package/src/shared/domain/dev/prompts/brief-blocks.ts +20 -0
  445. package/src/shared/domain/dev/prompts.ts +251 -0
  446. package/src/shared/domain/dev/questions.ts +267 -0
  447. package/src/shared/domain/dev/reading-rule.ts +41 -0
  448. package/src/shared/domain/dev/repo-pack.ts +240 -0
  449. package/src/shared/domain/dev/review-answer.ts +173 -0
  450. package/src/shared/domain/dev/review-brief.ts +54 -0
  451. package/src/shared/domain/dev/reviewer-charter.ts +35 -0
  452. package/src/shared/domain/dev/sheet-facts.ts +81 -0
  453. package/src/shared/domain/dev/spec-format.ts +182 -0
  454. package/src/shared/domain/dev/step-budget.ts +74 -0
  455. package/src/shared/domain/dev/step-rules.ts +109 -0
  456. package/src/shared/domain/dev/test-commands.ts +94 -0
  457. package/src/shared/domain/dev/test-output.ts +33 -0
  458. package/src/shared/domain/dev/test-paths.ts +40 -0
  459. package/src/shared/domain/dev/tool-guards.ts +65 -0
  460. package/src/shared/domain/dev/trait-pattern.ts +87 -0
  461. package/src/shared/domain/dev/verdict-format.ts +162 -0
  462. package/src/shared/domain/dev/whitespace.ts +35 -0
  463. package/src/shared/domain/dev/work-folder.ts +68 -0
  464. package/src/shared/domain/dev/yaml-subset.ts +385 -0
  465. package/src/shared/domain/error-text.ts +13 -0
  466. package/src/shared/domain/git/close.ts +274 -0
  467. package/src/shared/domain/git/messages.ts +20 -0
  468. package/src/shared/domain/git/pull-request.ts +96 -0
  469. package/src/shared/domain/git/worktree.ts +46 -0
  470. package/src/shared/domain/host-layout.ts +147 -0
  471. package/src/shared/domain/host-paths.ts +399 -0
  472. package/src/shared/domain/index-languages.ts +16 -0
  473. package/src/shared/domain/instructions-file.ts +18 -0
  474. package/src/shared/domain/iso-day.ts +4 -0
  475. package/src/shared/domain/llm-failure.ts +134 -0
  476. package/src/shared/domain/llm-profile.ts +44 -0
  477. package/src/shared/domain/marked-message.ts +29 -0
  478. package/src/shared/domain/markers.ts +30 -0
  479. package/src/shared/domain/messages.ts +291 -0
  480. package/src/shared/domain/model-catalog.ts +79 -0
  481. package/src/shared/domain/permission-modes.ts +99 -0
  482. package/src/shared/domain/prelude.ts +92 -0
  483. package/src/shared/domain/project-manifests.ts +84 -0
  484. package/src/shared/domain/prompts.ts +233 -0
  485. package/src/shared/domain/search-routing.ts +77 -0
  486. package/src/shared/domain/secret-patterns.ts +46 -0
  487. package/src/shared/domain/session-keys.ts +92 -0
  488. package/src/shared/domain/session-start.ts +61 -0
  489. package/src/shared/domain/severity.ts +72 -0
  490. package/src/shared/domain/sha1.ts +61 -0
  491. package/src/shared/domain/shared-memory/agent-memory-import.ts +145 -0
  492. package/src/shared/domain/shared-memory/candidates.ts +40 -0
  493. package/src/shared/domain/shared-memory/entry.ts +151 -0
  494. package/src/shared/domain/shared-memory/front-matter.ts +187 -0
  495. package/src/shared/domain/shared-memory/gate.ts +45 -0
  496. package/src/shared/domain/shared-memory/harvest.ts +64 -0
  497. package/src/shared/domain/shared-memory/layout.ts +190 -0
  498. package/src/shared/domain/shared-memory/markers.ts +9 -0
  499. package/src/shared/domain/shared-memory/messages.ts +66 -0
  500. package/src/shared/domain/shared-memory/precedents-block.ts +82 -0
  501. package/src/shared/domain/shared-memory/prompts.ts +28 -0
  502. package/src/shared/domain/shared-memory/refused.ts +84 -0
  503. package/src/shared/domain/shared-memory/verdict-rows.ts +134 -0
  504. package/src/shared/domain/skills/prompts.ts +4 -0
  505. package/src/shared/domain/skills/shortlist.ts +149 -0
  506. package/src/shared/domain/snip-turns.ts +33 -0
  507. package/src/shared/domain/speech.ts +21 -0
  508. package/src/shared/domain/strip.ts +88 -0
  509. package/src/shared/domain/tool-trace.ts +120 -0
  510. package/src/shared/domain/types.ts +67 -0
  511. package/src/shared/domain/verifiers.ts +33 -0
  512. package/src/shared/domain/vfs.ts +16 -0
  513. package/src/shared/domain/workflow/prompts.ts +15 -0
  514. package/src/shared/domain/workflow/state-file.ts +142 -0
  515. package/src/shared/infrastructure/globals.ts +57 -0
  516. package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
  517. package/src/shared/infrastructure/orkeon/child-agents.ts +122 -0
  518. package/src/shared/infrastructure/orkeon/chooser.ts +32 -0
  519. package/src/shared/infrastructure/orkeon/code-index.ts +120 -0
  520. package/src/shared/infrastructure/orkeon/crew-host.ts +27 -0
  521. package/src/shared/infrastructure/orkeon/crew-memory.ts +12 -0
  522. package/src/shared/infrastructure/orkeon/decision-model.ts +31 -0
  523. package/src/shared/infrastructure/orkeon/dev-deps.ts +179 -0
  524. package/src/shared/infrastructure/orkeon/files.ts +58 -0
  525. package/src/shared/infrastructure/orkeon/github-pull-requests.ts +30 -0
  526. package/src/shared/infrastructure/orkeon/host-context.ts +36 -0
  527. package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
  528. package/src/shared/infrastructure/orkeon/human-input.ts +55 -0
  529. package/src/shared/infrastructure/orkeon/llm-profile.ts +58 -0
  530. package/src/shared/infrastructure/orkeon/llm.ts +164 -0
  531. package/src/shared/infrastructure/orkeon/markers.ts +6 -0
  532. package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
  533. package/src/shared/infrastructure/orkeon/memory-tools.ts +129 -0
  534. package/src/shared/infrastructure/orkeon/messages.ts +15 -0
  535. package/src/shared/infrastructure/orkeon/permission-rules.ts +42 -0
  536. package/src/shared/infrastructure/orkeon/progress.ts +24 -0
  537. package/src/shared/infrastructure/orkeon/prompts.ts +47 -0
  538. package/src/shared/infrastructure/orkeon/reasoning.ts +40 -0
  539. package/src/shared/infrastructure/orkeon/run-state.ts +17 -0
  540. package/src/shared/infrastructure/orkeon/runtime-info.ts +30 -0
  541. package/src/shared/infrastructure/orkeon/runtime-tools.ts +60 -0
  542. package/src/shared/infrastructure/orkeon/script-tools.ts +129 -0
  543. package/src/shared/infrastructure/orkeon/session-store.ts +94 -0
  544. package/src/shared/infrastructure/orkeon/session-switch.ts +23 -0
  545. package/src/shared/infrastructure/orkeon/shared-memory.ts +61 -0
  546. package/src/shared/infrastructure/orkeon/shell-jobs.ts +81 -0
  547. package/src/shared/infrastructure/orkeon/shell.ts +39 -0
  548. package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
  549. package/src/shared/infrastructure/orkeon/tool-catalogue.ts +76 -0
  550. package/src/shared/infrastructure/orkeon/tool-results.ts +120 -0
  551. package/src/shared/infrastructure/orkeon/usage.ts +74 -0
  552. package/src/shared/infrastructure/orkeon/wiring.ts +174 -0
@@ -0,0 +1,94 @@
1
+ // The /dev-learn state: the verdict rows already treated and the decision taken on each
2
+ // motif. Orkeon Code keeps its own file; the harness's file is only read, so a row the
3
+ // harness treated is not proposed again here. Pure, no IO.
4
+ import { fieldHasTheWrongShape, THE_TOP_LEVEL } from "./messages.ts";
5
+
6
+ /** Orkeon Code's own /dev-learn state, relative to /workspace (temp/04:172-175). */
7
+ export const LEARN_STATE_FILE = ".orkeon/dev-learn-state.json";
8
+ /** The harness's state (LC:11-12,82): read, never written. */
9
+ export const HARNESS_LEARN_STATE_FILE = ".claude/local/dev-learn-state.json";
10
+
11
+ export type Decision = "accepted" | "refused";
12
+ export interface DecisionRecord { motif: string; decision: Decision; date: string; axis: string; title: string }
13
+ export interface LearnState { version: 1; treated: string[]; decisions: DecisionRecord[] }
14
+ export interface HarnessLearnState { treated: string[]; refused: string[] }
15
+ export type StateRead<T> = { ok: true; state: T } | { ok: false; problem: string };
16
+
17
+ const RECORD_KEYS = ["motif", "date", "axis", "title"] as const;
18
+
19
+ export function emptyLearnState(): LearnState {
20
+ return { version: 1, treated: [], decisions: [] };
21
+ }
22
+
23
+ function isRecord(v: unknown): v is Record<string, unknown> {
24
+ return typeof v === "object" && v !== null && !Array.isArray(v);
25
+ }
26
+
27
+ function isStringList(v: unknown): v is string[] {
28
+ return Array.isArray(v) && v.every((x) => typeof x === "string");
29
+ }
30
+
31
+ function firstLine(e: unknown): string {
32
+ return (e instanceof Error ? e.message : String(e)).split("\n")[0];
33
+ }
34
+
35
+ function decisionRecord(v: unknown): DecisionRecord | null {
36
+ if (!isRecord(v)) return null;
37
+ if (v.decision !== "accepted" && v.decision !== "refused") return null;
38
+ if (!RECORD_KEYS.every((k) => typeof v[k] === "string")) return null;
39
+ return { motif: v.motif as string, decision: v.decision, date: v.date as string, axis: v.axis as string, title: v.title as string };
40
+ }
41
+
42
+ /** null text (absent file) → empty state. Invalid JSON or shape → a problem (never silently emptied). */
43
+ export function parseLearnState(text: string | null): StateRead<LearnState> {
44
+ if (text === null) return { ok: true, state: emptyLearnState() };
45
+ const wrong = (field: string): StateRead<LearnState> =>
46
+ ({ ok: false, problem: fieldHasTheWrongShape(LEARN_STATE_FILE, field) });
47
+ let raw: unknown;
48
+ try {
49
+ raw = JSON.parse(text);
50
+ } catch (e) {
51
+ return { ok: false, problem: `${LEARN_STATE_FILE} is not JSON (${firstLine(e)})` };
52
+ }
53
+ if (!isRecord(raw)) return wrong(THE_TOP_LEVEL);
54
+ if (raw.version !== 1) return wrong("version");
55
+ if (!isStringList(raw.treated)) return wrong("treated");
56
+ if (!Array.isArray(raw.decisions)) return wrong("decisions");
57
+ const decisions: DecisionRecord[] = [];
58
+ for (const [i, d] of raw.decisions.entries()) {
59
+ const record = decisionRecord(d);
60
+ if (record === null) return wrong(`decisions[${i}]`);
61
+ decisions.push(record);
62
+ }
63
+ return { ok: true, state: { version: 1, treated: [...raw.treated], decisions } };
64
+ }
65
+
66
+ export function serializeLearnState(state: LearnState): string {
67
+ return JSON.stringify(state, null, 1) + "\n";
68
+ }
69
+
70
+ /** As LC:95-106: anything unreadable or of the wrong shape counts as empty lists; non-string items are dropped. */
71
+ export function parseHarnessLearnState(text: string | null): HarnessLearnState {
72
+ let raw: unknown = {};
73
+ if (text !== null) {
74
+ try {
75
+ raw = JSON.parse(text);
76
+ } catch {
77
+ raw = {};
78
+ }
79
+ }
80
+ const obj = isRecord(raw) ? raw : {};
81
+ const list = (v: unknown): string[] => (Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : []);
82
+ return { treated: list(obj.treated), refused: list(obj.refused) };
83
+ }
84
+
85
+ /** The state with the decision recorded (replacing an earlier one on the same motif) and rows treated. */
86
+ export function withDecision(state: LearnState, record: DecisionRecord, rows: readonly string[]): LearnState {
87
+ const treated = [...new Set([...state.treated, ...rows])].sort();
88
+ const decisions = [...state.decisions.filter((d) => d.motif !== record.motif), { ...record }];
89
+ return { version: 1, treated, decisions };
90
+ }
91
+
92
+ export function decisionOf(state: LearnState, motif: string): DecisionRecord | undefined {
93
+ return state.decisions.find((d) => d.motif === motif);
94
+ }
@@ -0,0 +1,107 @@
1
+ // The markers of the dev workflow's files: the headings, verdict words and lines a prompt or a renderer writes and
2
+ // a parser of shared/domain/dev reads back (ADR 0026).
3
+
4
+ // ── Open questions and decisions ────────────────────────────────────────────
5
+
6
+ export const OPEN_QUESTIONS_HEADER = ["| # | Severity | Question | Impact | Options |", "|---|---|---|---|---|"];
7
+
8
+ export const DECISIONS_HEADER = ["| # | Question | Answer | Date |", "|---|---|---|---|"];
9
+
10
+ /** The option a person picks to keep a question open; never written as an option of the file. */
11
+ export const LEAVE_OPEN = "Leave it open";
12
+
13
+ export const RECOMMENDED_MARK = " (recommended)";
14
+
15
+ export const OPEN_QUESTIONS_HEADING = /^## .*Open questions/;
16
+
17
+ export const DECISIONS_HEADING = /^## (\d+\. )?Decisions\s*$/;
18
+
19
+ // ── Specs and change briefs ─────────────────────────────────────────────────
20
+
21
+ export const MUST_NOT_CHANGE = /^## (\d+\. )?What must not change/;
22
+
23
+ export const BLOCKING_CELL = /\| *Blocking *\|/;
24
+
25
+ export const ID_HEADING = /^#{3,4} (UC|BR|CH)-(\d+)\s*[—:-]\s*(.+)$/;
26
+
27
+ export const SPEC_TITLE = /^# (\S+) — (.+)$/;
28
+
29
+ export const BRIEF_TITLE = /^# (\S+) — (.+) — (bug|refactor|perf)\s*$/;
30
+
31
+ export const STATEMENT = "**Statement**";
32
+
33
+ // ── Plans and batch sheets ──────────────────────────────────────────────────
34
+
35
+ export const PLAN_TITLE = /^# (\S+)-PLAN — (.+)$/;
36
+
37
+ export const SUMMARY_HEADING = /^## 0\. Summary/;
38
+
39
+ export const BATCH_LINE = /^### Batch (F\d+) — (.+) — (open|done \((\d{4}-\d{2}-\d{2})\))$/;
40
+
41
+ export const BATCH_PREFIX = /^### Batch (F\d+) — (.*)$/;
42
+
43
+ export const STEP_BOX = /^- \[( |x|X)\] (\d+)\. (.*)$/;
44
+
45
+ export const SHEET_TITLE = /^# (\S+)-PLAN-(F\d+) — (.+?)( — done \((\d{4}-\d{2}-\d{2})\))?$/;
46
+
47
+ export const DEPENDS_ON = /\*\*Depends on\*\*: (.+)$/;
48
+
49
+ export const STEP_HEADING = /^### Step (\d+) — (.+)$/;
50
+
51
+ export const TDD_LINE = /^TDD: RED \[( |x|X)\] GREEN \[( |x|X)\] COST \[( |x|X)\]$/;
52
+
53
+ export const DONE_LINE = /^Done \((\d{4}-\d{2}-\d{2})\) — /;
54
+
55
+ export const ASSUMPTION_ROW = /^\|\s*(H\d+)\s*\|(.*)\|(.*)\|\s*$/;
56
+
57
+ export const ASSUMPTION_BULLET = /^- (H\d+) — (.*) — to be validated by (.+)$/;
58
+
59
+ export const TICKED_TDD_LINE = "TDD: RED [x] GREEN [x] COST [x]";
60
+
61
+ export const OPEN_BOX = /(RED|GREEN|COST) \[ \]/;
62
+
63
+ export const APPLIED_ROW = /^\| *Applied rules *\|/;
64
+
65
+ export const BUILD_STEP = "Build and tests";
66
+
67
+ /** The state a batch line carries once the plan's review left Blocking questions: written by /dev-plan, read
68
+ * back as a state of its own, no parse problem. */
69
+ export const BLOCKED_STATE = "blocked";
70
+
71
+ // ── Verdicts ────────────────────────────────────────────────────────────────
72
+
73
+ export const VERDICT_TITLE = /^# (\S+)-VERIFY-(F\d+) — (\d{4}-\d{2}-\d{2} \d{2}:\d{2}) — (\S+)$/;
74
+
75
+ export const VERDICT_HEADING = /^##\s+Verdict\s+—\s+(VALID|GAPS)\s*$/;
76
+
77
+ export const VALIDATIONS_LINE = /^Validations: (.+)$/;
78
+
79
+ export const NOT_RUN_LINE = /^Not run: (.+)$/;
80
+
81
+ export const MEASURE_LINE = /^Measure: (.+)$/;
82
+
83
+ export const CORRECTION_LINE = /^\s*→ \/dev-batches (\S+) (F\d+) — correction: (.+)$/m;
84
+
85
+ export const CLOSE_LINE = /^\s*→ \/dev-batches (\S+) (F\d+) --close\s*$/;
86
+
87
+ /** The gap of the row dev-verify writes when the step's budget stopped the audit: not a finding of the code, so
88
+ * neither the learning harvest nor a resumed audit takes it as one. Its reason goes in the evidence. */
89
+ export const AUDIT_UNFINISHED_GAP = "the audit did not finish: the step's budget ran out";
90
+
91
+ /** The opening of the line dev-verify writes when a batch is VALID; /dev-batches looks for it in the audit's output. */
92
+ export const batchValidOpening = (batch: string): string => `→ Batch ${batch} VALID.`;
93
+ /** The VALID line of a batch, at the start of a line of dev-verify's output. */
94
+ export const batchValidLine = (batch: string): RegExp =>
95
+ new RegExp("^" + batchValidOpening(batch).replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "m");
96
+
97
+ // ── Written by /dev-plan's sheet, read and edited by /dev-implement ─────────
98
+
99
+ export const ASSUMPTIONS_SECTION = "## Assumptions";
100
+ export const ASSUMPTIONS_TABLE_HEAD = ["| # | Assumption | To be validated by |", "|---|------------|--------------------|"];
101
+ export const DECISIONS_SECTION = "## Decisions";
102
+ /** The TDD line of a step not yet run: TDD_LINE reads it, OPEN_BOX finds its boxes. */
103
+ export const OPEN_TDD_LINE = "TDD: RED [ ] GREEN [ ] COST [ ]";
104
+ /** The name of the sheet's test policy section, after its `## `. */
105
+ export const TEST_POLICY_SECTION = "Test policy and scopes";
106
+ /** The head of a step's test table, in a sheet and in a correction step. */
107
+ export const STEP_TESTS_TABLE_HEAD = ["| # | Test | Level | Project | Ids |", "|---|------|-------|---------|-----|"];
@@ -0,0 +1,259 @@
1
+ // The messages of shared/domain/dev: the problems a parser or a check reports and the stops the user reads
2
+ // (ADR 0026).
3
+
4
+ // ── Parse problems of the dev files ─────────────────────────────────────
5
+
6
+ export const unknownBatchLine = (line: string): string => `unknown batch line '${line}'`;
7
+ export const malformedSummaryRow = (row: string): string => `malformed summary row '${row}'`;
8
+ export const malformedTddLine = (line: string): string => `malformed TDD line '${line}'`;
9
+ export const tddLineOutsideStep = (line: string): string => `TDD line outside a step '${line}'`;
10
+ export const twoTddLines = (step: number): string => `step ${step} has two TDD: lines`;
11
+ export const unknownVerdictTitle = (title: string): string => `unknown verdict title '${title}'`;
12
+ export const unknownVerdictLine = (line: string): string => `unknown verdict line '${line}'`;
13
+ export const unknownSeverity = (severity: string): string => `unknown severity '${severity}'`;
14
+ export const malformedGapRow = (row: string): string => `malformed gap row '${row}'`;
15
+ export const duplicatedId = (id: string): string => `duplicated id ${id}`;
16
+ export const idInChangeBrief = (id: string): string => `${id} in a change brief`;
17
+ export const BRIEF_TITLE_NAMES_NO_KIND = "the brief's title names no kind (bug, refactor or perf)";
18
+
19
+ // ── The Blocking stop of /dev-plan ──────────────────────────────────────
20
+
21
+ export const blockingQuestionsOpen = (shown: string, count: number): string =>
22
+ `dev-plan: ${shown} has ${count} open Blocking question(s); no plan is written.`;
23
+ export const settleThemFirst = (settle: string, code: string, change: boolean): string =>
24
+ `→ Settle them first: ${settle} ${code}${change ? " <its kind: bug, refactor or perf>" : ""}, or edit the file; then /dev-plan ${code}.`;
25
+
26
+ // ── A question as a model gives it ──────────────────────────────────────
27
+
28
+ export const severityMustBe = (k: number): string => `question ${k}: severity must be Blocking or Major`;
29
+ export const questionOneLine = (k: number, max: number): string =>
30
+ `question ${k}: one line of at most ${max} characters ending with ?, no '|'`;
31
+ export const impactOneLine = (k: number): string => `question ${k}: the impact is one line, no '|'`;
32
+ export const optionCount = (k: number, max: number): string =>
33
+ `question ${k}: no option, or 2 to ${max} options with the recommended one first`;
34
+ export const optionOneLine = (k: number, max: number): string =>
35
+ `question ${k}: an option is one line of at most ${max} characters, no ';' nor '|'`;
36
+ export const notAnOptionToList = (k: number, option: string): string => `question ${k}: '${option}' is not an option to list`;
37
+ export const twoOptionsSame = (k: number): string => `question ${k}: two options read the same`;
38
+
39
+ // ── The self-check of a plan ────────────────────────────────────────────
40
+
41
+ export const stepOneMissing = (sheet: string): string => `${sheet}: step 1 is missing: the sheet has no step`;
42
+ export const stepOutOfOrder = (sheet: string, step: number, expected: number): string =>
43
+ `${sheet}: step ${step} is numbered out of order (expected ${expected})`;
44
+ export const stepHasNoTdd = (sheet: string, step: number): string => `${sheet}: step ${step} has no TDD: line`;
45
+ export const lastStepIsNot = (sheet: string, step: number, build: string): string =>
46
+ `${sheet}: step ${step} is the last step and is not ${build}`;
47
+ export const buildStepHoldsTdd = (sheet: string, step: number, build: string): string =>
48
+ `${sheet}: step ${step} is ${build} and holds a TDD: line`;
49
+ export const anchorRowsMismatch = (sheet: string, rows: number, steps: number): string =>
50
+ `${sheet}: ## Anchors has ${rows} rows for ${steps} steps`;
51
+ export const designIdsNeither = (missing: readonly string[]): string =>
52
+ `design ids neither applied nor non-applicable: ${missing.join(", ")}`;
53
+ export const batchesDiffer = (summary: string, lines: string, sheets: string): string =>
54
+ `batches differ: summary ${summary}, plan lines ${lines}, sheets ${sheets}`;
55
+ export const dependsOnDiffers = (sheet: string, summary: string, own: string): string =>
56
+ `${sheet}: Depends on differs between the summary (${summary}) and the sheet (${own})`;
57
+ export const noTraceabilityRow = (id: string): string => `${id}: no row of ## 2. Traceability`;
58
+ export const noTestNamesIt = (id: string): string => `${id}: no test of any sheet's ## TDD sequence names it`;
59
+ export const notASourceId = (sheet: string, id: string): string => `${sheet}: ${id} is not an id of the source`;
60
+ export const noAppliedRulesRow = (sheet: string): string => `${sheet}: no Applied rules row`;
61
+ export const assumptionsNotEmpty = (sheet: string): string => `${sheet}: ## Assumptions is not empty`;
62
+ export const idOutsideBatch = (sheet: string, id: string): string =>
63
+ `${sheet}: ${id} appears in ## TDD sequence outside the batch's ids`;
64
+
65
+ // ── The call guard of a dev step: why a call is refused ────────────────
66
+
67
+ export const packGivesNo = (key: string): string => `the pack gives no ${key}: no rule on it`;
68
+ export const notRunInMode = (step: string, tool: string, mode: string): string =>
69
+ `${step}: '${tool}' is not run in mode '${mode}': the host has no permission gate, so the crew's ` +
70
+ `callback applies the mode itself`;
71
+ export const ruleSetOrigin = (id: string): string => `the rule set ${id}`;
72
+ export const rewriteRuleOrigin = (role: string): string => `the ${role}'s rewrite rule`;
73
+ export const rootsOrigin = (role: string): string => `the ${role}'s roots`;
74
+ export const refusedByRule = (step: string, rule: string, origin: string, how: string): string =>
75
+ `${step}: refused by '${rule}' of ${origin}${how}`;
76
+ export const whichPathReaches = (path: string): string => `, which '${path}' reaches`;
77
+ export const whichPathCanReach = (path: string): string => `, which '${path}' can reach`;
78
+ export const editBatchRefused = (step: string, why: string): string => `${step}: edit_batch refused: ${why}`;
79
+ export const validateNotRun = (validate: string): string => `validate '${validate}' is not run in a dev step`;
80
+ export const NO_LIST_OF_OPERATIONS = "no list of operations";
81
+ export const operationNamesNoPath = (n: number): string => `operation ${n} names no path`;
82
+ export const operationUnknownKind = (n: number, kind: string): string => `operation ${n} has the unknown kind '${kind}'`;
83
+
84
+ // ── The access cost of a batch ──────────────────────────────────────────
85
+
86
+ export const NO_CODE_INDEX_WIRED = "the crew wires no code index; judge the Cost axis from the diff";
87
+ export const CODE_INDEX_EMPTY = "the code index is empty";
88
+ export const codeIndexHolds = (roots: readonly string[], workspace: string): string =>
89
+ `the code index holds ${roots.join(", ")}, not ${workspace}`;
90
+ export const notIndexedReason = (holds: string): string =>
91
+ `not indexed — ${holds}: run /analyze, then audit the batch again; judge the Cost axis from the diff`;
92
+ export const backToDesign = (blocking: number): string => `${blocking} - back to design`;
93
+ export const costLine = (reads: string, writes: string, verdict: string): string =>
94
+ `Cost: ${reads} + ${writes} through ports outside loops; ` +
95
+ `in a loop, a lambda or a memory filter: ${verdict}`;
96
+ export const PORTS_OUTSIDE_LOOPS = "Ports outside loops";
97
+ export const PORTS_IN_A_LOOP = "Ports in a loop";
98
+ export const PORTS_IN_A_LAMBDA = "Ports in a lambda";
99
+ export const MEMORY_FILTER_ON_AWAITED = "Memory filter on an awaited result";
100
+ export const NO_MEMBER_INDEXED = "no member of the changed files in the code index";
101
+ export const noneAwaitsAPort = (members: string): string => `${members}, none awaits a port or filters in memory`;
102
+ export const noChangedFile = (where: string): string => `no changed file${where}\n`;
103
+ export const costNotComputed = (reason: string): string => `Cost: not computed — ${reason}`;
104
+ export const cutAtLines = (lines: number): string => `[cut at ${lines} lines]`;
105
+
106
+ // ── The answer of a dev reviewer ────────────────────────────────────────
107
+
108
+ export const QUESTION_EMPTY = "it is empty";
109
+ export const questionLongerThan = (max: number): string => `it is longer than ${max} characters`;
110
+ export const QUESTION_NO_MARK = "it does not end with ?";
111
+ export const rowSeverityMustBe = (k: number): string => `row ${k}: severity must be Blocking or Major`;
112
+ export const rowOneClosedQuestion = (k: number, fault: string): string =>
113
+ `row ${k}: the question must be one closed question ending with ? (${fault})`;
114
+ export const rowEvidenceEmpty = (k: number): string => `row ${k}: evidence is empty`;
115
+ export const rowEvidenceCitesNothing = (k: number): string => `row ${k}: evidence cites no path:line, § section or heading`;
116
+ /** What follows the evidence of a row kept although it cites nothing. */
117
+ export const NO_CITATION = "(no citation)";
118
+ export const rowTargetNotOneOf = (k: number, named: string, targets: string): string =>
119
+ `row ${k}: target '${named}' is not one of ${targets}`;
120
+ export const rowTwoTargets = (k: number, named: string): string => `row ${k}: target '${named}' names two targets`;
121
+ export const ANSWER_NOT_AN_OBJECT = "the answer is not an object";
122
+ export const VERDICT_CLEAR_OR_GAPS = "verdict must be CLEAR or GAPS";
123
+ export const ROWS_MUST_BE_A_LIST = "rows must be a list";
124
+ export const atMostRows = (max: number, count: number): string => `at most ${max} rows, not ${count}`;
125
+ export const rowRepeats = (k: number, first: number): string => `row ${k}: repeats row ${first}`;
126
+
127
+ // ── The YAML subset of the repository pack ──────────────────────────────
128
+
129
+ export const YAML_PROBLEMS = {
130
+ tab: "a tab in the indentation",
131
+ tabInLine: "a tab outside quotes and comments",
132
+ marker: "a document marker is not supported",
133
+ anchor: "anchors, aliases and tags are not supported",
134
+ flowMap: "a flow mapping is not supported",
135
+ flowOpen: "a flow sequence must close on its line",
136
+ flowNested: "a nested flow sequence is not supported",
137
+ flowAfter: "text after a closing bracket",
138
+ flowEmpty: "an empty item in a flow sequence",
139
+ moreIndented: "a more-indented line inside a folded block is not supported",
140
+ quoteOpen: "a quoted scalar must close on its line",
141
+ quoteAfter: "text after a closing quote",
142
+ colon: "': ' inside a plain value: quote it",
143
+ key: "a mapping key must be a plain name",
144
+ indent: "bad indentation (a value continued on the next line is not supported)",
145
+ itemForKey: "a sequence item where a mapping key was expected",
146
+ keyForItem: "a mapping key where a sequence item was expected",
147
+ nestedItem: "a nested sequence item on one line is not supported",
148
+ } as const;
149
+ export const ambiguousNumber = (v: string): string => `an ambiguous number '${v}': quote it`;
150
+ export const ambiguousDate = (v: string): string => `an ambiguous date '${v}': quote it`;
151
+ export const unknownEscape = (e: string): string => `an unknown escape '\\${e}' in a double-quoted scalar`;
152
+ export const plainCannotStartWith = (c: string): string => `a plain value cannot start with '${c}': quote it`;
153
+ export const onlyFoldedBlock = (indicator: string): string => `only the folded block '>-' is supported, not '${indicator}'`;
154
+
155
+ // ── The repository pack ─────────────────────────────────────────────────
156
+
157
+ export const expectedMapping = (kind: string): string => `expected a mapping, found a ${kind}`;
158
+ export const expectedString = (kind: string): string => `expected a string, found a ${kind}`;
159
+ export const LIST_FOUND_MAPPING = "expected a list of strings, found a mapping";
160
+ export const listHolding = (kind: string): string => `expected a list of strings, found a list holding a ${kind}`;
161
+ export const testsAlsoSourceRoot = (tests: string, key: string): string =>
162
+ `'${tests}' is also layout.${key}: the test author and the implementer would both be refused that folder; ` +
163
+ `drop layout.tests and name the test files with layout.test_files ("${tests}/*.test.ts")`;
164
+ export const PACK_NOT_A_MAPPING = "the pack is not a mapping";
165
+ export const noRepositoryPack = (key: string): string => `no repository pack: add ${key} to .orkeon/repo.yaml`;
166
+ export const packHasNo = (pack: string, key: string): string => `the repository pack ${pack} has no ${key}: add it there`;
167
+
168
+ // ── Test traits and test commands ───────────────────────────────────────
169
+
170
+ export const TRAIT_NAME_CHARS = "a trait name takes letters, digits, '_' and '-'";
171
+ export const PATTERN_EMPTY = "the pattern is empty";
172
+ export const PATTERN_TOO_LONG = "the pattern is longer than 80 characters";
173
+ export const PATTERN_NO_TAB_OR_BREAK = "a tab or a line break is not allowed";
174
+ export const PATTERN_NO_SINGLE_QUOTE = "a single quote is not allowed";
175
+ export const PATTERN_NO_PIPE = "a '|' is not allowed: the runtime's shell refuses it";
176
+ export const PATTERN_ONE_ID = "the pattern must hold <id> exactly once";
177
+ export const PATTERN_ONE_NAME = "the pattern may hold <name> once at most";
178
+ export const PATTERN_ANGLES = "'<' and '>' may only enclose <id> and <name>";
179
+ export const PATTERN_TOO_SHORT = "the pattern needs at least two characters around <id>";
180
+ export const valueHoldsDotDot = (value: string): string => `the value '${value}' holds a '..' segment`;
181
+ export const valueNotPlain = (value: string): string => `the value '${value}' is not one plain relative name`;
182
+ export const NOT_ONE_LINE = "not one line of at most 400 characters";
183
+ export const SHELL_OPERATOR_OUTSIDE_QUOTES = "a shell operator outside double quotes";
184
+ export const PACK_HAS_NO_TEST_COMMAND = "the pack has no test_class, test_project or test_integration";
185
+ export const nothingMayFollow = (rest: string): string => `nothing may follow the pack's command: '${rest}'`;
186
+ export const INTEGRATION_WITHOUT_FILTER = "test_integration without a filter is a whole suite";
187
+ export const NOT_A_PACK_TEST_COMMAND = "not one of the pack's test_class, test_project or test_integration commands";
188
+ export const AS_THE_PACK_NAMES_IT = "as the pack names it";
189
+ export const validationLineText = (command: string, exit: number, scope: string, tests: string | number): string =>
190
+ `\`${command}\` — exit ${exit}, scope ${scope}, ${tests} tests`;
191
+
192
+ // ── Concurrency of /dev-batches ─────────────────────────────────────────
193
+
194
+ export const concurrencyNotWhole = (raw: string): string => `concurrency must be a whole number from 1, not '${raw}'`;
195
+ export const concurrencyAtMost = (n: number, max: number): string => `concurrency ${n} refused: at most ${max} batches at once`;
196
+ export const concurrencyModeAsks = (n: number, mode: string): string =>
197
+ `concurrency ${n} refused: the session mode ${mode} asks before shell commands, and two batches would ask at once: ` +
198
+ "/mode bypassPermissions, or run with --concurrency 1";
199
+ export const concurrencyGitFails = (n: number): string =>
200
+ `concurrency ${n} refused: git does not work inside a worktree under this shell confinement (Tools:Shell:Confinement:Mode)` +
201
+ "; a runtime from Orkeon/orkeon#191 on binds a linked worktree's git dir: update it, or run with --concurrency 1";
202
+
203
+ // ── Build commands, tool arguments, whitespace, work folder ─────────────
204
+
205
+ export const PACK_HAS_NO_BUILD = "the pack has no commands.build";
206
+ export const PACK_HAS_NO_BUILD_TEST = "the pack has no commands.build_test to build one project";
207
+ export const buildTestPlaceholders = (holes: number, template: string): string =>
208
+ `commands.build_test has ${holes} placeholders, not one: '${template}'`;
209
+ export const stepRulesDenyShell = (command: string): string => `the rules of this step deny the shell command '${command}'`;
210
+ export const argumentNotAString = (key: string): string => `'${key}' is not a string`;
211
+ export const argumentNotOneLine = (key: string, max: number): string => `'${key}' is not one line of at most ${max} characters`;
212
+ export const trailingWhitespace = (lines: number): string => `trailing whitespace on ${lines} line${lines === 1 ? "" : "s"}`;
213
+ export const ONE_BLANK_LINE_AT_EOF = "a blank line at EOF removed";
214
+ export const blankLinesAtEof = (blank: number): string => `${blank} blank lines at EOF removed`;
215
+ export const AN_ABSOLUTE_PATH = "an absolute path";
216
+ export const AN_EMPTY_SEGMENT = "an empty segment";
217
+ export const notARelativeFolder = (value: string, reason: string): string =>
218
+ `'${value}' is not a relative folder of the checkout: ${reason}`;
219
+
220
+ // ── /dev-learn ──────────────────────────────────────────────────────────
221
+
222
+ export const THE_TOP_LEVEL = "the top level";
223
+ export const hasTheWrongShape = (what: string): string => `${what} has the wrong shape`;
224
+ export const fieldHasTheWrongShape = (file: string, field: string): string => `${file}: ${field} has the wrong shape`;
225
+ export const acceptedHarness = (id: string, title: string): string =>
226
+ `accepted ${id} — ${title}: a harness file is never edited here; apply this in the orkeon-workshop repository:`;
227
+ export const acceptedRepository = (id: string, title: string, path: string): string =>
228
+ `accepted ${id} — ${title}: ${path} is not edited by /dev-learn; make the change in a batch (/dev-spec <code> refactor, or by hand):`;
229
+
230
+ // ── The timing line of /dev-spec and /dev-plan ──────────────────────────
231
+
232
+ export const timingSeconds = (seconds: number): string => `${seconds} s`;
233
+ export const timingMinutes = (minutes: number, seconds: number): string => `${minutes} min ${seconds} s`;
234
+ export const timingAttempts = (n: number): string => `(${n} attempts)`;
235
+ export const timingRounds = (n: number): string => `(${n} rounds)`;
236
+ export const timingPasses = (n: number): string => `(${n} passes)`;
237
+ /** One phase: its name, its duration, then its runs when it ran more than once ("" otherwise). */
238
+ export const timingPhase = (phase: string, duration: string, runs: string): string =>
239
+ `${phase} ${duration}${runs === "" ? "" : ` ${runs}`}`;
240
+ export const TIMING_SEPARATOR = " · ";
241
+ export const timingLine = (phases: string, total: string): string => `timing: ${phases} — total ${total}`;
242
+
243
+ // ── The permission gate of a dev step ───────────────────────────────────
244
+
245
+ export const GATE_ONLY_HINT = " /dev-batches <code> F<n> --audit --gate-only runs no model and needs no gate.";
246
+ export const gateIsOff = (step: string, setting: string, command: string, gateOnly: string): string =>
247
+ `${step}: refused: the host's permission gate is off (${setting} is not true), so the step's rule ` +
248
+ `sets and its read-only mode would check nothing. The launcher turns the gate on unless a settings file turns ` +
249
+ `it off: remove that setting, restart the REPL and run /${command} again.${gateOnly}`;
250
+
251
+ // The self-checks shared by the spec, the brief, the plan and the learning
252
+ export const rowIsEmpty = (name: string, row: number): string => `${name} ${row} is empty`;
253
+ export const fieldEmpty = (at: string, field: string): string => `${at}: ${field} is empty`;
254
+ export const nameOneLine = (max: number): string => `name: one line of at most ${max} characters, no '—'`;
255
+ export const idNameOneLine = (id: string, max: number): string => `${id}: the name is one line of at most ${max} characters`;
256
+ export const statementOneLine = (id: string, max: number): string =>
257
+ `${id}: the statement is one testable line of at most ${max} characters`;
258
+ export const TBD_WITHOUT_QUESTION = "a TBD in the body has no open question";
259
+ export const tooManyQuestions = (max: number): string => `questions: at most ${max}`;
@@ -0,0 +1,42 @@
1
+ // A relative path a dev agent hands a tool, resolved under the project before the tool runs. The runtime resolves
2
+ // one too since Orkeon #206 (against the agent's root, else /workspace); the resolution here is for Orkeon Code's
3
+ // own guard and hooks, which judge the call before the runtime sees it and must see one absolute form. The base is
4
+ // the checkout, `/workspace`, or a batch's working root. The guard judges the resolved path, in the same form it
5
+ // always matched a relative one in (call-guard's pathForms). Pure.
6
+ import { sameToolName } from "../agent-policy/permission.ts";
7
+ import { OPERATIONS_TOOL, PATH_READ_TOOLS, PATH_WRITE_TOOLS } from "../agent-policy/rule-sets.ts";
8
+ import { WORKSPACE } from "../vfs.ts";
9
+ import { normalisePath } from "./call-guard.ts";
10
+
11
+ /** The tools whose `path` names one file or folder. */
12
+ const PATH_TOOLS: readonly string[] = [...PATH_READ_TOOLS, ...PATH_WRITE_TOOLS];
13
+
14
+ /** `path` under `base` when relative, normalised as the guard matches it (a leading `..` climbs out of the base, and the
15
+ * runtime refuses what no mount holds); an absolute path as it is. */
16
+ export function resolvedPath(path: string, base: string = WORKSPACE): string {
17
+ return path.startsWith("/") ? path : normalisePath(`${base}/${path}`);
18
+ }
19
+
20
+ const relative = (path: unknown): path is string => typeof path === "string" && path !== "" && !path.startsWith("/");
21
+
22
+ /** The call's input with every relative `path` resolved under `base` (an edit_batch: each operation's), or null
23
+ * when the call names no relative path: the input then goes to the tool as it is. */
24
+ export function resolvePathInput(tool: string, input: unknown, base: string = WORKSPACE): unknown | null {
25
+ if (input === null || typeof input !== "object" || Array.isArray(input)) return null;
26
+ const args = input as Readonly<Record<string, unknown>>;
27
+ if (PATH_TOOLS.some((name) => sameToolName(tool, name))) {
28
+ return relative(args.path) ? { ...args, path: resolvedPath(args.path, base) } : null;
29
+ }
30
+ if (sameToolName(tool, OPERATIONS_TOOL) && Array.isArray(args.operations)) {
31
+ let changed = false;
32
+ const operations = args.operations.map((op: unknown) => {
33
+ if (op === null || typeof op !== "object") return op;
34
+ const path = (op as { path?: unknown }).path;
35
+ if (!relative(path)) return op;
36
+ changed = true;
37
+ return { ...(op as Record<string, unknown>), path: resolvedPath(path, base) };
38
+ });
39
+ return changed ? { ...args, operations } : null;
40
+ }
41
+ return null;
42
+ }
@@ -0,0 +1,93 @@
1
+ // A batch of a parallel /dev-batches runs under its worktree, `/workspace/.orkeon/worktrees/<name>` (its working
2
+ // root), while the dev crews' code names the checkout `/workspace` everywhere: `/workspace` stays the logical
3
+ // checkout, and these functions map it at each boundary of the batch - onto the root on the way to the runtime
4
+ // and the model, back to `/workspace` on the way in. A path already under the root, a relative path and another
5
+ // mount (`/output`, `/tmp`) are kept; without a root every function is the identity. Pure.
6
+ import { WORKSPACE } from "../vfs.ts";
7
+
8
+ type Root = string | null | undefined;
9
+
10
+ /** A character that continues a path segment: `/workspace` followed by one is another name (`/workspaces`). */
11
+ const SEGMENT = /[\w.-]/;
12
+
13
+ /** True when the path ends at `at`: nothing that continues its name, or a dot that ends a sentence. */
14
+ const ends = (text: string, at: number): boolean =>
15
+ at >= text.length || !SEGMENT.test(text[at]) || (text[at] === "." && (at + 1 >= text.length || /[\s"'`)\]]/.test(text[at + 1])));
16
+
17
+ /** `path` with its leading `/workspace` on the root; anything else as it is. */
18
+ export function toRoot(path: string, root?: Root): string {
19
+ if (!root || isUnder(path, root) || !isUnder(path, WORKSPACE)) return path;
20
+ return root + path.slice(WORKSPACE.length);
21
+ }
22
+
23
+ /** `path` with its leading root back on `/workspace`; anything else as it is. */
24
+ export function fromRoot(path: string, root?: Root): string {
25
+ if (!root || !isUnder(path, root)) return path;
26
+ return WORKSPACE + path.slice(root.length);
27
+ }
28
+
29
+ function isUnder(path: string, folder: string): boolean {
30
+ return path.startsWith(folder) && (path.length === folder.length || path[folder.length] === "/");
31
+ }
32
+
33
+ /** Every `/workspace` path of a text (a command, a tool's result) on the root, but one already under it. */
34
+ export function textToRoot(text: string, root?: Root): string {
35
+ if (!root || !text.includes(WORKSPACE)) return text;
36
+ return rebase(text, root, false);
37
+ }
38
+
39
+ /**
40
+ * A brief (a prompt, a system text) with the paths it names on the root, as textToRoot, but for what it quotes of
41
+ * the files: a `/workspace` right after a quote (a constant of the code, `"/workspace"`) and everything inside a
42
+ * fenced block (``` or ~~~: code, a diff) are kept as the files hold them.
43
+ */
44
+ export function briefToRoot(text: string, root?: Root): string {
45
+ if (!root || !text.includes(WORKSPACE)) return text;
46
+ let fence: string | null = null;
47
+ return text.split("\n").map((line) => {
48
+ const mark = /^\s*(```|~~~)/.exec(line)?.[1];
49
+ if (mark !== undefined) {
50
+ if (fence === null) fence = mark;
51
+ else if (fence === mark) fence = null;
52
+ return line;
53
+ }
54
+ return fence !== null || !line.includes(WORKSPACE) ? line : rebase(line, root, true);
55
+ }).join("\n");
56
+ }
57
+
58
+ function rebase(text: string, root: string, keepQuoted: boolean): string {
59
+ let out = "";
60
+ let from = 0;
61
+ for (let at = text.indexOf(WORKSPACE); at >= 0; at = text.indexOf(WORKSPACE, at + 1)) {
62
+ const starts = at === 0 || !/[\w./-]/.test(text[at - 1]);
63
+ if (!starts || !ends(text, at + WORKSPACE.length)) continue;
64
+ if (keepQuoted && at > 0 && (text[at - 1] === '"' || text[at - 1] === "'")) continue;
65
+ if (text.startsWith(root, at) && ends(text, at + root.length)) continue;
66
+ out += text.slice(from, at) + root;
67
+ from = at + WORKSPACE.length;
68
+ }
69
+ return out + text.slice(from);
70
+ }
71
+
72
+ /** Every path under the root of a text (a command's output, a call the model made) back on `/workspace`. */
73
+ export function textFromRoot(text: string, root?: Root): string {
74
+ if (!root || !text.includes(root)) return text;
75
+ let out = "";
76
+ let from = 0;
77
+ for (let at = text.indexOf(root); at >= 0; at = text.indexOf(root, at + 1)) {
78
+ if (!ends(text, at + root.length) || (at > 0 && /[\w./-]/.test(text[at - 1]))) continue;
79
+ out += text.slice(from, at) + WORKSPACE;
80
+ from = at + root.length;
81
+ }
82
+ return out + text.slice(from);
83
+ }
84
+
85
+ /** `value` with `map` applied to each string it holds, at any depth; keys and other values kept. */
86
+ export function mapStrings<T>(value: T, map: (text: string) => string): T {
87
+ if (typeof value === "string") return map(value) as T;
88
+ if (Array.isArray(value)) return value.map((v) => mapStrings(v, map)) as T;
89
+ if (value === null || typeof value !== "object") return value;
90
+ const out: Record<string, unknown> = {};
91
+ for (const [k, v] of Object.entries(value as Record<string, unknown>)) out[k] = mapStrings(v, map);
92
+ return out as T;
93
+ }
@@ -0,0 +1,50 @@
1
+ // Where the time of a dev step went: the milliseconds of each named phase, summed over its runs, the phases in the
2
+ // order they first started, and the one line the step's summary ends with. Pure: the caller measures, this adds up and
3
+ // renders. A timing whose clock never moved (total 0 ms) renders nothing: there is nothing to say.
4
+ import {
5
+ TIMING_SEPARATOR, timingAttempts, timingLine as timingText, timingMinutes, timingPasses, timingPhase, timingRounds,
6
+ timingSeconds,
7
+ } from "./messages.ts";
8
+
9
+ /** What a phase run more than once counts: the tries of one call, the rounds of a dialogue, the passes of a write. */
10
+ export type RunUnit = "attempt" | "round" | "pass";
11
+
12
+ export interface PhaseTime { readonly phase: string; readonly ms: number; readonly runs: number; readonly unit: RunUnit }
13
+
14
+ export type PhaseTiming = readonly PhaseTime[];
15
+
16
+ export const NO_TIMING: PhaseTiming = [];
17
+
18
+ /** `timing` with a place for `phase` when it has none yet, run 0 times: a phase takes its place when it starts, so a
19
+ * phase timed inside another comes after it. */
20
+ export function startPhase(timing: PhaseTiming, phase: string, unit: RunUnit = "attempt"): PhaseTiming {
21
+ return timing.some((p) => p.phase === phase) ? timing : [...timing, { phase, ms: 0, runs: 0, unit }];
22
+ }
23
+
24
+ /** `timing` with one run more and `ms` more under `phase` (a negative duration counts as 0), its first unit kept. */
25
+ export function recordPhase(timing: PhaseTiming, phase: string, ms: number, unit: RunUnit = "attempt"): PhaseTiming {
26
+ const spent = Math.max(0, ms);
27
+ return startPhase(timing, phase, unit).map((p) => (p.phase === phase ? { ...p, ms: p.ms + spent, runs: p.runs + 1 } : p));
28
+ }
29
+
30
+ export function timingTotalMs(timing: PhaseTiming): number {
31
+ return timing.reduce((sum, p) => sum + p.ms, 0);
32
+ }
33
+
34
+ /** Whole seconds under a minute, minutes and seconds from there. */
35
+ export function durationText(ms: number): string {
36
+ const seconds = Math.round(Math.max(0, ms) / 1000);
37
+ if (seconds < 60) return timingSeconds(seconds);
38
+ return timingMinutes(Math.floor(seconds / 60), seconds % 60);
39
+ }
40
+
41
+ const RUNS: Record<RunUnit, (n: number) => string> = { attempt: timingAttempts, round: timingRounds, pass: timingPasses };
42
+
43
+ /** The summary's timing line, the phases that never ran left out; "" for a timing with no time spent. */
44
+ export function timingLine(timing: PhaseTiming): string {
45
+ const ran = timing.filter((p) => p.runs > 0);
46
+ const total = timingTotalMs(ran);
47
+ if (total === 0) return "";
48
+ const phases = ran.map((p) => timingPhase(p.phase, durationText(p.ms), p.runs > 1 ? RUNS[p.unit](p.runs) : ""));
49
+ return timingText(phases.join(TIMING_SEPARATOR), durationText(total));
50
+ }