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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (423) hide show
  1. package/.orkeon-version +1 -0
  2. package/LICENSE.md +21 -0
  3. package/NOTICE.md +17 -0
  4. package/README.fr.md +169 -0
  5. package/README.md +162 -2
  6. package/config/appsettings.anthropic.example.json +77 -0
  7. package/config/appsettings.example.json +71 -0
  8. package/config/appsettings.jev.example.json +128 -0
  9. package/config/appsettings.kev.example.json +130 -0
  10. package/config/appsettings.liquid.example.json +129 -0
  11. package/config/appsettings.ollama-whisper.example.json +92 -0
  12. package/config/appsettings.ollama.example.json +70 -0
  13. package/config/appsettings.whisper.example.json +31 -0
  14. package/mcp/whisper/README.md +293 -0
  15. package/mcp/whisper/pyproject.toml +32 -0
  16. package/mcp/whisper/uv.lock +1641 -0
  17. package/mcp/whisper/whisper_mcp.py +1053 -0
  18. package/orkeon-code +897 -0
  19. package/orkeon-code.mjs +71 -0
  20. package/orkeon-code.ps1 +837 -0
  21. package/package.json +57 -4
  22. package/scripts/install.ps1 +156 -0
  23. package/scripts/install.sh +148 -0
  24. package/scripts/session-start.ork.ts +90 -0
  25. package/scripts/session-start.sh +74 -0
  26. package/scripts/setup-fixture.sh +88 -0
  27. package/src/commands/.orkeon/orkeon-cli.d.ts +562 -0
  28. package/src/commands/_lib/args.ts +193 -0
  29. package/src/commands/_lib/dev/dev-batches.ts +368 -0
  30. package/src/commands/_lib/dev/dev-implement.ts +188 -0
  31. package/src/commands/_lib/dev/dev-source.ts +65 -0
  32. package/src/commands/_lib/dev/dev.ts +344 -0
  33. package/src/commands/_lib/dev-step.ts +142 -0
  34. package/src/commands/_lib/dispatch.ts +231 -0
  35. package/src/commands/_lib/effort.ts +15 -0
  36. package/src/commands/_lib/git/branch.ts +95 -0
  37. package/src/commands/_lib/git/commit.ts +94 -0
  38. package/src/commands/_lib/git/diff.ts +97 -0
  39. package/src/commands/_lib/git/review.ts +109 -0
  40. package/src/commands/_lib/memory/memory-admit.ts +150 -0
  41. package/src/commands/_lib/memory/memory.ts +51 -0
  42. package/src/commands/_lib/pr-context.ts +32 -0
  43. package/src/commands/_lib/project/analyze.ts +24 -0
  44. package/src/commands/_lib/session/export.ts +104 -0
  45. package/src/commands/_lib/session/resume.ts +160 -0
  46. package/src/commands/_lib/session/tasks.ts +184 -0
  47. package/src/commands/_lib/settings/advisor.ts +80 -0
  48. package/src/commands/_lib/settings/agents.ts +147 -0
  49. package/src/commands/_lib/settings/config.ts +141 -0
  50. package/src/commands/_lib/settings/hooks.ts +58 -0
  51. package/src/commands/_lib/settings/mode.ts +91 -0
  52. package/src/commands/_lib/settings/model.ts +146 -0
  53. package/src/commands/_lib/settings/permissions.ts +309 -0
  54. package/src/commands/_lib/settings/session-config.ts +49 -0
  55. package/src/commands/_lib/settings/skills.ts +51 -0
  56. package/src/commands/_lib/speech/say.ts +96 -0
  57. package/src/commands/_lib/speech/transcribe.ts +130 -0
  58. package/src/commands/_lib/speech/voice.ts +146 -0
  59. package/src/commands/_lib/status/cache.ts +31 -0
  60. package/src/commands/_lib/status/context.ts +57 -0
  61. package/src/commands/_lib/status/doctor.ts +186 -0
  62. package/src/commands/_lib/status/meta.ts +45 -0
  63. package/src/commands/_lib/status/status.ts +129 -0
  64. package/src/commands/_lib/status/usage-tools.ts +49 -0
  65. package/src/commands/_lib/status/usage.ts +139 -0
  66. package/src/commands/_lib/view.ts +29 -0
  67. package/src/commands/dev/dev-batches.cmd.ts +108 -0
  68. package/src/commands/dev/dev-learn.cmd.ts +29 -0
  69. package/src/commands/dev/dev-plan.cmd.ts +52 -0
  70. package/src/commands/dev/dev-spec.cmd.ts +55 -0
  71. package/src/commands/dev/dev-status.cmd.ts +16 -0
  72. package/src/commands/git/branch.cmd.ts +27 -0
  73. package/src/commands/git/commit.cmd.ts +48 -0
  74. package/src/commands/git/diff.cmd.ts +26 -0
  75. package/src/commands/git/review.cmd.ts +36 -0
  76. package/src/commands/memory/memory.cmd.ts +48 -0
  77. package/src/commands/project/analyze.cmd.ts +32 -0
  78. package/src/commands/project/debug-tool-call.cmd.ts +67 -0
  79. package/src/commands/project/files.cmd.ts +22 -0
  80. package/src/commands/project/init-verifiers.cmd.ts +14 -0
  81. package/src/commands/project/init.cmd.ts +14 -0
  82. package/src/commands/project/verify.cmd.ts +27 -0
  83. package/src/commands/session/assistant.cmd.ts +40 -0
  84. package/src/commands/session/btw.cmd.ts +18 -0
  85. package/src/commands/session/clear.cmd.ts +19 -0
  86. package/src/commands/session/compact.cmd.ts +16 -0
  87. package/src/commands/session/copy.cmd.ts +44 -0
  88. package/src/commands/session/exit.cmd.ts +9 -0
  89. package/src/commands/session/export.cmd.ts +28 -0
  90. package/src/commands/session/rename.cmd.ts +17 -0
  91. package/src/commands/session/resume.cmd.ts +19 -0
  92. package/src/commands/session/rewind.cmd.ts +26 -0
  93. package/src/commands/session/summary.cmd.ts +27 -0
  94. package/src/commands/session/tasks.cmd.ts +44 -0
  95. package/src/commands/settings/advisor.cmd.ts +38 -0
  96. package/src/commands/settings/agents.cmd.ts +19 -0
  97. package/src/commands/settings/config.cmd.ts +17 -0
  98. package/src/commands/settings/effort.cmd.ts +40 -0
  99. package/src/commands/settings/fast.cmd.ts +17 -0
  100. package/src/commands/settings/hooks.cmd.ts +17 -0
  101. package/src/commands/settings/mode.cmd.ts +20 -0
  102. package/src/commands/settings/model.cmd.ts +20 -0
  103. package/src/commands/settings/output-style.cmd.ts +48 -0
  104. package/src/commands/settings/permissions.cmd.ts +25 -0
  105. package/src/commands/settings/proactive.cmd.ts +15 -0
  106. package/src/commands/settings/skills.cmd.ts +17 -0
  107. package/src/commands/speech/say.cmd.ts +24 -0
  108. package/src/commands/speech/transcribe.cmd.ts +29 -0
  109. package/src/commands/speech/voice.cmd.ts +30 -0
  110. package/src/commands/status/context.cmd.ts +18 -0
  111. package/src/commands/status/doctor.cmd.ts +27 -0
  112. package/src/commands/status/release-notes.cmd.ts +9 -0
  113. package/src/commands/status/status.cmd.ts +25 -0
  114. package/src/commands/status/usage.cmd.ts +21 -0
  115. package/src/crews/.orkeon/orkeon.d.ts +3946 -0
  116. package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +183 -0
  117. package/src/crews/_probe-shared-memory/probe.ork.ts +98 -0
  118. package/src/crews/advisor/application/run-advisor.ts +40 -0
  119. package/src/crews/advisor/crew.ork.ts +43 -0
  120. package/src/crews/advisor/domain/advice.ts +135 -0
  121. package/src/crews/agent-run/application/run-agent-run.ts +42 -0
  122. package/src/crews/agent-run/crew.ork.ts +67 -0
  123. package/src/crews/analyze/application/run-analyze.ts +118 -0
  124. package/src/crews/analyze/crew.ork.ts +40 -0
  125. package/src/crews/analyze/domain/harvest.ts +301 -0
  126. package/src/crews/code-review/application/prompts.ts +133 -0
  127. package/src/crews/code-review/application/review.ts +71 -0
  128. package/src/crews/code-review/application/run-code-review.ts +123 -0
  129. package/src/crews/code-review/crew.ork.ts +51 -0
  130. package/src/crews/code-review/domain/lenses.ts +193 -0
  131. package/src/crews/code-review/domain/report.ts +59 -0
  132. package/src/crews/code-review/domain/scope.ts +112 -0
  133. package/src/crews/dev-batches/application/plan-close.ts +181 -0
  134. package/src/crews/dev-batches/application/run-dev-batches.ts +669 -0
  135. package/src/crews/dev-batches/application/run-wave.ts +450 -0
  136. package/src/crews/dev-batches/application/seed-harvest.ts +162 -0
  137. package/src/crews/dev-batches/crew.ork.ts +143 -0
  138. package/src/crews/dev-batches/domain/batch-waves.ts +70 -0
  139. package/src/crews/dev-batches/domain/batches-budget.ts +52 -0
  140. package/src/crews/dev-batches/domain/batches-log.ts +54 -0
  141. package/src/crews/dev-batches/domain/wave-order.ts +43 -0
  142. package/src/crews/dev-change/application/change-prompt.ts +104 -0
  143. package/src/crews/dev-change/application/evidence.ts +169 -0
  144. package/src/crews/dev-change/application/run-dev-change.ts +315 -0
  145. package/src/crews/dev-change/crew.ork.ts +112 -0
  146. package/src/crews/dev-change/domain/change-answer.ts +159 -0
  147. package/src/crews/dev-change/domain/change-render.ts +79 -0
  148. package/src/crews/dev-implement/application/close.ts +183 -0
  149. package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
  150. package/src/crews/dev-implement/application/locate-sheet.ts +80 -0
  151. package/src/crews/dev-implement/application/observe.ts +50 -0
  152. package/src/crews/dev-implement/application/report-writes.ts +41 -0
  153. package/src/crews/dev-implement/application/run-dev-implement.ts +811 -0
  154. package/src/crews/dev-implement/application/run-role.ts +27 -0
  155. package/src/crews/dev-implement/application/suite-job.ts +118 -0
  156. package/src/crews/dev-implement/application/touched.ts +74 -0
  157. package/src/crews/dev-implement/crew.ork.ts +68 -0
  158. package/src/crews/dev-implement/domain/contracts.ts +256 -0
  159. package/src/crews/dev-implement/domain/correction.ts +102 -0
  160. package/src/crews/dev-implement/domain/cycles.ts +35 -0
  161. package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
  162. package/src/crews/dev-implement/domain/roles.ts +53 -0
  163. package/src/crews/dev-implement/domain/sheet-edits.ts +75 -0
  164. package/src/crews/dev-implement/domain/sheet-ticks.ts +22 -0
  165. package/src/crews/dev-implement/domain/step-checks.ts +136 -0
  166. package/src/crews/dev-implement/domain/step-section.ts +127 -0
  167. package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
  168. package/src/crews/dev-learn/application/learn-prompt.ts +140 -0
  169. package/src/crews/dev-learn/application/run-dev-learn.ts +553 -0
  170. package/src/crews/dev-learn/crew.ork.ts +52 -0
  171. package/src/crews/dev-learn/domain/learn-answer.ts +235 -0
  172. package/src/crews/dev-learn/domain/owner-lines.ts +86 -0
  173. package/src/crews/dev-learn/domain/proposals-render.ts +96 -0
  174. package/src/crews/dev-plan/application/anchor-paths.ts +76 -0
  175. package/src/crews/dev-plan/application/inventory.ts +170 -0
  176. package/src/crews/dev-plan/application/plan-prompt.ts +159 -0
  177. package/src/crews/dev-plan/application/run-dev-plan.ts +455 -0
  178. package/src/crews/dev-plan/crew.ork.ts +109 -0
  179. package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
  180. package/src/crews/dev-plan/domain/plan-answer.ts +738 -0
  181. package/src/crews/dev-plan/domain/plan-render.ts +307 -0
  182. package/src/crews/dev-spec/application/run-dev-spec.ts +206 -0
  183. package/src/crews/dev-spec/application/spec-prompt.ts +98 -0
  184. package/src/crews/dev-spec/crew.ork.ts +108 -0
  185. package/src/crews/dev-spec/domain/spec-answer.ts +253 -0
  186. package/src/crews/dev-spec/domain/spec-render.ts +76 -0
  187. package/src/crews/dev-verify/application/audit.ts +259 -0
  188. package/src/crews/dev-verify/application/auditor-prompt.ts +323 -0
  189. package/src/crews/dev-verify/application/capture.ts +303 -0
  190. package/src/crews/dev-verify/application/run-dev-verify.ts +409 -0
  191. package/src/crews/dev-verify/application/run-gate.ts +202 -0
  192. package/src/crews/dev-verify/crew.ork.ts +103 -0
  193. package/src/crews/dev-verify/domain/audit-answer.ts +150 -0
  194. package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
  195. package/src/crews/dev-verify/domain/capture-sections.ts +137 -0
  196. package/src/crews/dev-verify/domain/commands.ts +103 -0
  197. package/src/crews/dev-verify/domain/gate.ts +126 -0
  198. package/src/crews/dev-verify/domain/mechanical-table.ts +163 -0
  199. package/src/crews/dev-verify/domain/runtime-cut.ts +13 -0
  200. package/src/crews/dev-verify/domain/sheet-facts.ts +4 -0
  201. package/src/crews/dev-verify/domain/text.ts +20 -0
  202. package/src/crews/dev-verify/domain/verdict.ts +127 -0
  203. package/src/crews/git-commit/application/draft.ts +154 -0
  204. package/src/crews/git-commit/application/run-git-commit.ts +116 -0
  205. package/src/crews/git-commit/crew.ork.ts +52 -0
  206. package/src/crews/git-commit/domain/commit.ts +220 -0
  207. package/src/crews/init-verifiers/application/authoring.ts +89 -0
  208. package/src/crews/init-verifiers/application/prompts.ts +103 -0
  209. package/src/crews/init-verifiers/application/run-init-verifiers.ts +25 -0
  210. package/src/crews/init-verifiers/crew.ork.ts +34 -0
  211. package/src/crews/init-verifiers/domain/commands-section.ts +36 -0
  212. package/src/crews/init-verifiers/domain/readiness.ts +23 -0
  213. package/src/crews/main-loop/application/auto-compact.ts +77 -0
  214. package/src/crews/main-loop/application/context-gather.ts +133 -0
  215. package/src/crews/main-loop/application/run-main-loop.ts +350 -0
  216. package/src/crews/main-loop/application/turn-prompt.ts +112 -0
  217. package/src/crews/main-loop/crew.ork.ts +119 -0
  218. package/src/crews/main-loop/domain/autocompact.ts +27 -0
  219. package/src/crews/main-loop/domain/prompt-assembly.ts +521 -0
  220. package/src/crews/main-loop/domain/turn-chains.ts +129 -0
  221. package/src/crews/project-init/application/detect.ts +122 -0
  222. package/src/crews/project-init/application/prompts.ts +101 -0
  223. package/src/crews/project-init/application/run-project-init.ts +31 -0
  224. package/src/crews/project-init/crew.ork.ts +35 -0
  225. package/src/crews/project-init/domain/conventions.ts +36 -0
  226. package/src/crews/project-init/domain/existing-files.ts +63 -0
  227. package/src/crews/project-init/domain/package-map.ts +73 -0
  228. package/src/crews/session-compact/crew.ork.ts +55 -0
  229. package/src/crews/shared-memory-admit/crew.ork.ts +48 -0
  230. package/src/crews/speech/application/run-speech.ts +25 -0
  231. package/src/crews/speech/crew.ork.ts +37 -0
  232. package/src/shared/application/agents/child-agent.ts +255 -0
  233. package/src/shared/application/agents/run-sub-agent.ts +96 -0
  234. package/src/shared/application/answer-language.ts +14 -0
  235. package/src/shared/application/attached-skills.ts +36 -0
  236. package/src/shared/application/compaction/compact-session.ts +237 -0
  237. package/src/shared/application/compaction/extract-memories.ts +38 -0
  238. package/src/shared/application/compaction/restore-context.ts +78 -0
  239. package/src/shared/application/config-store.ts +123 -0
  240. package/src/shared/application/dev/brief-inventory.ts +113 -0
  241. package/src/shared/application/dev/close-batch.ts +83 -0
  242. package/src/shared/application/dev/find-repo-pack.ts +77 -0
  243. package/src/shared/application/dev/learn-decision.ts +252 -0
  244. package/src/shared/application/dev/load-dev-context.ts +266 -0
  245. package/src/shared/application/dev/measure-access-cost.ts +68 -0
  246. package/src/shared/application/dev/plan-source.ts +112 -0
  247. package/src/shared/application/dev/preflight.ts +71 -0
  248. package/src/shared/application/dev/project-files.ts +17 -0
  249. package/src/shared/application/dev/question-round.ts +52 -0
  250. package/src/shared/application/dev/resolve-work-folder.ts +133 -0
  251. package/src/shared/application/dev/script-tool-slot.ts +27 -0
  252. package/src/shared/application/dev/settle-questions.ts +55 -0
  253. package/src/shared/application/dev/source-review.ts +63 -0
  254. package/src/shared/application/dev/source-step.ts +150 -0
  255. package/src/shared/application/dev/spend.ts +42 -0
  256. package/src/shared/application/dev/step-precedents.ts +89 -0
  257. package/src/shared/application/dev/tool-call-policy.ts +89 -0
  258. package/src/shared/application/dev/tool-callbacks.ts +215 -0
  259. package/src/shared/application/dev/tool-trace-recorder.ts +45 -0
  260. package/src/shared/application/dev/verdict-sources.ts +48 -0
  261. package/src/shared/application/dev/wrapped-tools.ts +145 -0
  262. package/src/shared/application/extra-tools.ts +70 -0
  263. package/src/shared/application/git/batch-worktree.ts +97 -0
  264. package/src/shared/application/git/commit-files.ts +186 -0
  265. package/src/shared/application/git/merge-batch.ts +63 -0
  266. package/src/shared/application/git/open-pull-request.ts +51 -0
  267. package/src/shared/application/instructions-file.ts +19 -0
  268. package/src/shared/application/json-file.ts +34 -0
  269. package/src/shared/application/llm-profile.ts +35 -0
  270. package/src/shared/application/permission-rules.ts +159 -0
  271. package/src/shared/application/ports/approvals.ts +20 -0
  272. package/src/shared/application/ports/clock.ts +5 -0
  273. package/src/shared/application/ports/code-index.ts +93 -0
  274. package/src/shared/application/ports/crew.ts +60 -0
  275. package/src/shared/application/ports/files.ts +21 -0
  276. package/src/shared/application/ports/human.ts +13 -0
  277. package/src/shared/application/ports/llm.ts +54 -0
  278. package/src/shared/application/ports/memory.ts +30 -0
  279. package/src/shared/application/ports/progress.ts +23 -0
  280. package/src/shared/application/ports/runtime.ts +15 -0
  281. package/src/shared/application/ports/session.ts +74 -0
  282. package/src/shared/application/ports/shared-memory.ts +26 -0
  283. package/src/shared/application/ports/shell.ts +40 -0
  284. package/src/shared/application/ports/telemetry.ts +45 -0
  285. package/src/shared/application/ports/tools.ts +46 -0
  286. package/src/shared/application/ports/usage.ts +45 -0
  287. package/src/shared/application/ports.ts +27 -0
  288. package/src/shared/application/project-manifests.ts +106 -0
  289. package/src/shared/application/session-io.ts +84 -0
  290. package/src/shared/application/session-state.ts +36 -0
  291. package/src/shared/application/shared-memory/admit-entries.ts +177 -0
  292. package/src/shared/application/shared-memory/harvest-after-gaps.ts +72 -0
  293. package/src/shared/application/shared-memory/harvest-mistakes.ts +44 -0
  294. package/src/shared/application/shared-memory/import-agent-memory.ts +117 -0
  295. package/src/shared/application/shared-memory/memory-files.ts +110 -0
  296. package/src/shared/application/shared-memory/memory-settings.ts +93 -0
  297. package/src/shared/application/shared-memory/push-candidate.ts +146 -0
  298. package/src/shared/application/shared-memory/recall-precedents.ts +69 -0
  299. package/src/shared/application/state-snapshot.ts +38 -0
  300. package/src/shared/application/workflow/workflow-state.ts +135 -0
  301. package/src/shared/domain/agent-policy/behavior-flags.ts +168 -0
  302. package/src/shared/domain/agent-policy/extra-tools.ts +69 -0
  303. package/src/shared/domain/agent-policy/memory-categories.ts +6 -0
  304. package/src/shared/domain/agent-policy/mode-policy.ts +51 -0
  305. package/src/shared/domain/agent-policy/output-styles.ts +11 -0
  306. package/src/shared/domain/agent-policy/permission.ts +623 -0
  307. package/src/shared/domain/agent-policy/rule-sets.ts +412 -0
  308. package/src/shared/domain/agent-policy/tool-access.ts +77 -0
  309. package/src/shared/domain/agent-registry.ts +142 -0
  310. package/src/shared/domain/agents/built-in-charters.ts +43 -0
  311. package/src/shared/domain/agents/chain.ts +30 -0
  312. package/src/shared/domain/agents/charter.ts +61 -0
  313. package/src/shared/domain/agents/exclusive.ts +24 -0
  314. package/src/shared/domain/agents/instances.ts +249 -0
  315. package/src/shared/domain/code-intel-contract.ts +356 -0
  316. package/src/shared/domain/code-intel-routing.ts +113 -0
  317. package/src/shared/domain/compact-outcome.ts +44 -0
  318. package/src/shared/domain/compaction-thresholds.ts +161 -0
  319. package/src/shared/domain/compaction.ts +379 -0
  320. package/src/shared/domain/config-schema.ts +421 -0
  321. package/src/shared/domain/dev/access-cost.ts +226 -0
  322. package/src/shared/domain/dev/artefacts.ts +50 -0
  323. package/src/shared/domain/dev/batches-concurrency.ts +36 -0
  324. package/src/shared/domain/dev/batches-state.ts +49 -0
  325. package/src/shared/domain/dev/build-commands.ts +44 -0
  326. package/src/shared/domain/dev/call-guard.ts +341 -0
  327. package/src/shared/domain/dev/carried-text.ts +49 -0
  328. package/src/shared/domain/dev/design-rules.ts +100 -0
  329. package/src/shared/domain/dev/learn-proposals.ts +175 -0
  330. package/src/shared/domain/dev/learn-state.ts +93 -0
  331. package/src/shared/domain/dev/path-args.ts +42 -0
  332. package/src/shared/domain/dev/path-rebase.ts +93 -0
  333. package/src/shared/domain/dev/plan-checks.ts +190 -0
  334. package/src/shared/domain/dev/plan-format.ts +180 -0
  335. package/src/shared/domain/dev/project-files.ts +43 -0
  336. package/src/shared/domain/dev/questions.ts +249 -0
  337. package/src/shared/domain/dev/reading-rule.ts +41 -0
  338. package/src/shared/domain/dev/repo-pack.ts +237 -0
  339. package/src/shared/domain/dev/review-answer.ts +150 -0
  340. package/src/shared/domain/dev/review-prompt.ts +221 -0
  341. package/src/shared/domain/dev/reviewer-charter.ts +31 -0
  342. package/src/shared/domain/dev/sheet-facts.ts +83 -0
  343. package/src/shared/domain/dev/spec-format.ts +183 -0
  344. package/src/shared/domain/dev/step-budget.ts +72 -0
  345. package/src/shared/domain/dev/step-rules.ts +110 -0
  346. package/src/shared/domain/dev/test-commands.ts +90 -0
  347. package/src/shared/domain/dev/test-output.ts +33 -0
  348. package/src/shared/domain/dev/test-paths.ts +40 -0
  349. package/src/shared/domain/dev/tool-guards.ts +64 -0
  350. package/src/shared/domain/dev/trait-pattern.ts +83 -0
  351. package/src/shared/domain/dev/verdict-format.ts +169 -0
  352. package/src/shared/domain/dev/whitespace.ts +34 -0
  353. package/src/shared/domain/dev/work-folder.ts +67 -0
  354. package/src/shared/domain/dev/yaml-subset.ts +403 -0
  355. package/src/shared/domain/git/close.ts +273 -0
  356. package/src/shared/domain/git/pull-request.ts +96 -0
  357. package/src/shared/domain/git/worktree.ts +46 -0
  358. package/src/shared/domain/index-languages.ts +16 -0
  359. package/src/shared/domain/instructions-file.ts +18 -0
  360. package/src/shared/domain/iso-day.ts +4 -0
  361. package/src/shared/domain/llm-failure.ts +106 -0
  362. package/src/shared/domain/llm-profile.ts +25 -0
  363. package/src/shared/domain/marked-message.ts +33 -0
  364. package/src/shared/domain/model-catalog.ts +86 -0
  365. package/src/shared/domain/permission-modes.ts +103 -0
  366. package/src/shared/domain/prelude.ts +92 -0
  367. package/src/shared/domain/project-manifests.ts +83 -0
  368. package/src/shared/domain/search-routing.ts +85 -0
  369. package/src/shared/domain/secret-patterns.ts +45 -0
  370. package/src/shared/domain/session-keys.ts +85 -0
  371. package/src/shared/domain/session-start.ts +60 -0
  372. package/src/shared/domain/session-summary.ts +13 -0
  373. package/src/shared/domain/severity.ts +72 -0
  374. package/src/shared/domain/sha1.ts +61 -0
  375. package/src/shared/domain/shared-memory/agent-memory-import.ts +143 -0
  376. package/src/shared/domain/shared-memory/candidates.ts +41 -0
  377. package/src/shared/domain/shared-memory/entry.ts +145 -0
  378. package/src/shared/domain/shared-memory/front-matter.ts +183 -0
  379. package/src/shared/domain/shared-memory/gate.ts +44 -0
  380. package/src/shared/domain/shared-memory/harvest.ts +61 -0
  381. package/src/shared/domain/shared-memory/layout.ts +187 -0
  382. package/src/shared/domain/shared-memory/precedents-block.ts +93 -0
  383. package/src/shared/domain/shared-memory/refused.ts +84 -0
  384. package/src/shared/domain/shared-memory/verdict-rows.ts +134 -0
  385. package/src/shared/domain/snip-turns.ts +45 -0
  386. package/src/shared/domain/speech.ts +20 -0
  387. package/src/shared/domain/strip.ts +88 -0
  388. package/src/shared/domain/tool-trace.ts +122 -0
  389. package/src/shared/domain/types.ts +67 -0
  390. package/src/shared/domain/verifiers.ts +37 -0
  391. package/src/shared/domain/vfs.ts +9 -0
  392. package/src/shared/domain/workflow/state-file.ts +140 -0
  393. package/src/shared/infrastructure/globals.ts +52 -0
  394. package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
  395. package/src/shared/infrastructure/orkeon/child-agents.ts +127 -0
  396. package/src/shared/infrastructure/orkeon/code-index.ts +120 -0
  397. package/src/shared/infrastructure/orkeon/crew-host.ts +27 -0
  398. package/src/shared/infrastructure/orkeon/crew-memory.ts +12 -0
  399. package/src/shared/infrastructure/orkeon/dev-deps.ts +172 -0
  400. package/src/shared/infrastructure/orkeon/files.ts +40 -0
  401. package/src/shared/infrastructure/orkeon/github-pull-requests.ts +29 -0
  402. package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
  403. package/src/shared/infrastructure/orkeon/human-input.ts +59 -0
  404. package/src/shared/infrastructure/orkeon/llm-profile.ts +38 -0
  405. package/src/shared/infrastructure/orkeon/llm.ts +109 -0
  406. package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
  407. package/src/shared/infrastructure/orkeon/memory-tools.ts +131 -0
  408. package/src/shared/infrastructure/orkeon/permission-rules.ts +42 -0
  409. package/src/shared/infrastructure/orkeon/progress.ts +24 -0
  410. package/src/shared/infrastructure/orkeon/run-state.ts +17 -0
  411. package/src/shared/infrastructure/orkeon/runtime-info.ts +30 -0
  412. package/src/shared/infrastructure/orkeon/runtime-tools.ts +60 -0
  413. package/src/shared/infrastructure/orkeon/script-tools.ts +134 -0
  414. package/src/shared/infrastructure/orkeon/session-store.ts +138 -0
  415. package/src/shared/infrastructure/orkeon/session-switch.ts +23 -0
  416. package/src/shared/infrastructure/orkeon/shared-memory.ts +61 -0
  417. package/src/shared/infrastructure/orkeon/shell-jobs.ts +75 -0
  418. package/src/shared/infrastructure/orkeon/shell.ts +31 -0
  419. package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
  420. package/src/shared/infrastructure/orkeon/tool-catalogue.ts +75 -0
  421. package/src/shared/infrastructure/orkeon/tool-results.ts +120 -0
  422. package/src/shared/infrastructure/orkeon/usage.ts +74 -0
  423. package/src/shared/infrastructure/orkeon/wiring.ts +118 -0
@@ -0,0 +1,235 @@
1
+ // The learner's answer for one axis: the JSON schema it is extracted into (snake_case
2
+ // on the wire), and the check that turns the extraction into a LearnAnswer or the list
3
+ // of what is wrong with it, so the crew can ask once more. Pure, no IO.
4
+ import type { Checked } from "../../../shared/domain/agents/charter.ts";
5
+ import type { CheckKind, MotifStatus, OwnerKind } from "../../../shared/domain/dev/learn-proposals.ts";
6
+ import { MAX_TOPIC_CHARS, TOPIC_PATTERN } from "../../../shared/domain/shared-memory/refused.ts";
7
+
8
+ export { MAX_TOPIC_CHARS };
9
+
10
+ export const MAX_MOTIFS_PER_AXIS = 3;
11
+ export const MAX_LINES_PER_MOTIF = 5;
12
+ export const MAX_LINE_CHARS = 300;
13
+ const MAX_TITLE_CHARS = 80;
14
+ /** A title longer than this is cut in a label: its first LABEL_TITLE_CHARS characters, then an ellipsis. */
15
+ export const LABEL_TITLE_CHARS = 60;
16
+ const ADDS_LINES = `1 to ${MAX_LINES_PER_MOTIF} lines added and at most ${MAX_LINES_PER_MOTIF} removed`;
17
+ const REMOVES_LINES = `removes takes out 1 to ${MAX_LINES_PER_MOTIF} lines and adds none`;
18
+ /** Why a status other than new is refused on an answer given without owner lines: it copies a line it never saw. */
19
+ export const SEEN_LINES_ONLY = (status: string): string =>
20
+ `${status} copies a line of its owner, and this answer was given without the owner lines: give status new, ` +
21
+ "or copy the line from the owner lines when they are shown";
22
+
23
+ export interface AnswerMotif {
24
+ title: string; topic: string; rows: string[]; preventiveLine: string;
25
+ owner: { kind: OwnerKind; path: string }; check: CheckKind; status: MotifStatus;
26
+ linesRemoved: string[]; linesAdded: string[]; novelty: string; keyTerm: string;
27
+ }
28
+ export interface AnswerDropped { title: string; filter: "recurrence" | "prevention" | "novelty"; reason: string }
29
+ export interface LearnAnswer { motifs: AnswerMotif[]; dropped: AnswerDropped[] }
30
+
31
+ const OWNER_KINDS: readonly OwnerKind[] = ["repository", "harness"];
32
+ const CHECK_KINDS: readonly CheckKind[] = ["test", "analyzer", "architecture-test", "gate", "rule"];
33
+ const STATUSES: readonly MotifStatus[] = ["new", "refines", "replaces", "removes"];
34
+ const FILTERS: ReadonlyArray<AnswerDropped["filter"]> = ["recurrence", "prevention", "novelty"];
35
+ const HARNESS_PACKS = ".devcontainer/harness/packs/";
36
+
37
+ const stringList = { type: "array", items: { type: "string" } };
38
+
39
+ export const LEARN_ANSWER_SCHEMA: object = {
40
+ type: "object",
41
+ properties: {
42
+ motifs: {
43
+ type: "array",
44
+ items: {
45
+ type: "object",
46
+ properties: {
47
+ title: { type: "string" },
48
+ topic: { type: "string" },
49
+ rows: stringList,
50
+ preventive_line: { type: "string" },
51
+ owner_kind: { type: "string", enum: [...OWNER_KINDS] },
52
+ owner_path: { type: "string" },
53
+ check: { type: "string", enum: [...CHECK_KINDS] },
54
+ status: { type: "string", enum: [...STATUSES] },
55
+ lines_removed: stringList,
56
+ lines_added: stringList,
57
+ novelty: { type: "string" },
58
+ key_term: { type: "string" },
59
+ },
60
+ required: [
61
+ "title", "topic", "rows", "preventive_line", "owner_kind", "owner_path", "check", "status",
62
+ "lines_added", "novelty", "key_term",
63
+ ],
64
+ },
65
+ },
66
+ dropped: {
67
+ type: "array",
68
+ items: {
69
+ type: "object",
70
+ properties: {
71
+ title: { type: "string" },
72
+ filter: { type: "string", enum: [...FILTERS] },
73
+ reason: { type: "string" },
74
+ },
75
+ required: ["title", "filter", "reason"],
76
+ },
77
+ },
78
+ },
79
+ required: ["motifs"],
80
+ };
81
+
82
+ type Obj = Record<string, unknown>;
83
+
84
+ function isPlainObject(value: unknown): value is Obj {
85
+ return typeof value === "object" && value !== null && !Array.isArray(value);
86
+ }
87
+
88
+ function text(value: unknown): string {
89
+ return typeof value === "string" ? value.trim() : "";
90
+ }
91
+
92
+ const chars = (s: string): number => Array.from(s).length;
93
+
94
+ /** `motif k "<title>"`, the title cut at 60 characters, a `"` of it written `'`, or `motif k` without a title: the
95
+ * re-ask never shows the earlier answer, so a problem names the motif by what it was called. */
96
+ export function motifLabel(k: number, title: string): string {
97
+ const t = Array.from(title.trim().replace(/"/g, "'"));
98
+ if (t.length === 0) return `motif ${k}`;
99
+ const shown = t.length <= LABEL_TITLE_CHARS ? t.join("") : t.slice(0, LABEL_TITLE_CHARS).join("") + "…";
100
+ return `motif ${k} "${shown}"`;
101
+ }
102
+
103
+ /** An absent list is empty; a list keeps its strings trimmed; anything else is null (wrong shape). */
104
+ function lines(value: unknown): string[] | null {
105
+ if (value === undefined) return [];
106
+ if (!Array.isArray(value)) return null;
107
+ return value.map(text);
108
+ }
109
+
110
+ function isRelativePath(raw: unknown): boolean {
111
+ if (typeof raw !== "string") return false;
112
+ const p = raw;
113
+ if (p === "" || p !== p.trim()) return false;
114
+ if (p.startsWith("/") || p.includes("\\")) return false;
115
+ return !p.split("/").includes("..");
116
+ }
117
+
118
+ function checkMotif(
119
+ value: unknown, k: number, shownIds: ReadonlySet<string>, ownerLinesShown: boolean, problems: string[],
120
+ ): AnswerMotif | undefined {
121
+ const item = isPlainObject(value) ? value : {};
122
+ const before = problems.length;
123
+ const title = text(item.title);
124
+ const at = motifLabel(k, title);
125
+
126
+ if (title === "" || chars(title) > MAX_TITLE_CHARS) problems.push(`${at}: title must be 1 to 80 characters`);
127
+ const topic = text(item.topic);
128
+ if (!TOPIC_PATTERN.test(topic)) problems.push(`${at}: topic '${topic}' is not a kebab slug of at most ${MAX_TOPIC_CHARS} characters`);
129
+
130
+ const rows = Array.isArray(item.rows) ? item.rows.map(text) : [];
131
+ if (rows.length === 0) problems.push(`${at}: rows is empty`);
132
+ const seen = new Set<string>();
133
+ for (const id of rows) {
134
+ if (!shownIds.has(id)) problems.push(`${at}: row '${id}' is not one of the rows given`);
135
+ else if (seen.has(id)) problems.push(`${at}: row '${id}' is listed twice`);
136
+ seen.add(id);
137
+ }
138
+
139
+ const preventiveLine = text(item.preventive_line);
140
+ const novelty = text(item.novelty);
141
+ const keyTerm = text(item.key_term);
142
+ for (const [field, v] of [["preventive_line", preventiveLine], ["novelty", novelty], ["key_term", keyTerm]] as const) {
143
+ if (v === "") problems.push(`${at}: ${field} is empty`);
144
+ }
145
+
146
+ const kind = text(item.owner_kind) as OwnerKind;
147
+ const path = typeof item.owner_path === "string" ? item.owner_path : "";
148
+ if (!OWNER_KINDS.includes(kind)) problems.push(`${at}: owner_kind must be repository or harness`);
149
+ if (!isRelativePath(item.owner_path)) {
150
+ problems.push(`${at}: owner_path '${path}' is not a relative path`);
151
+ } else if (kind === "repository" && (path === ".claude" || path.startsWith(".claude/"))) {
152
+ problems.push(`${at}: .claude/ is the harness's deployed copy: name the orkeon-workshop file with owner_kind harness`);
153
+ } else if (kind === "harness" && !path.startsWith(HARNESS_PACKS)) {
154
+ problems.push(`${at}: a harness owner is a file of the orkeon-workshop repository under ${HARNESS_PACKS}`);
155
+ }
156
+
157
+ const check = text(item.check) as CheckKind;
158
+ if (!CHECK_KINDS.includes(check)) problems.push(`${at}: check must be one of ${CHECK_KINDS.join(", ")}`);
159
+ const status = text(item.status) as MotifStatus;
160
+ if (!STATUSES.includes(status)) problems.push(`${at}: status must be new, refines, replaces or removes`);
161
+ else if (status !== "new" && !ownerLinesShown) problems.push(`${at}: ${SEEN_LINES_ONLY(status)}`);
162
+
163
+ const removed = lines(item.lines_removed);
164
+ const added = lines(item.lines_added);
165
+ const linesRule = status === "removes" ? REMOVES_LINES : ADDS_LINES;
166
+ if (added === null || removed === null || removed.length > MAX_LINES_PER_MOTIF) {
167
+ problems.push(`${at}: ${linesRule}`);
168
+ } else if (status === "removes") {
169
+ if (added.length > 0 || removed.filter((l) => l !== "").length === 0) problems.push(`${at}: ${linesRule}`);
170
+ } else if (added.length === 0 || added.length > MAX_LINES_PER_MOTIF) {
171
+ problems.push(`${at}: ${linesRule}`);
172
+ }
173
+ const rawLines = [
174
+ ...(Array.isArray(item.lines_added) ? item.lines_added : []),
175
+ ...(Array.isArray(item.lines_removed) ? item.lines_removed : []),
176
+ ];
177
+ if (rawLines.some((l) => typeof l !== "string" || chars(l.trim()) > MAX_LINE_CHARS || /[\r\n]/.test(l.trim()))) {
178
+ problems.push(`${at}: each line is one line of at most 300 characters`);
179
+ }
180
+ if ((status === "refines" || status === "replaces") && (removed ?? []).filter((l) => l !== "").length === 0) {
181
+ problems.push(`${at}: ${status} needs the line it removes`);
182
+ }
183
+
184
+ if (problems.length > before) return undefined;
185
+ return {
186
+ title, topic, rows, preventiveLine, owner: { kind, path }, check, status,
187
+ linesRemoved: removed ?? [], linesAdded: added ?? [], novelty, keyTerm,
188
+ };
189
+ }
190
+
191
+ function checkDropped(value: unknown, problems: string[]): AnswerDropped[] {
192
+ if (value === undefined) return [];
193
+ if (!Array.isArray(value)) {
194
+ problems.push("dropped 1: title, filter and reason are needed");
195
+ return [];
196
+ }
197
+ const out: AnswerDropped[] = [];
198
+ value.forEach((v, i) => {
199
+ const item = isPlainObject(v) ? v : {};
200
+ const title = text(item.title);
201
+ const filter = text(item.filter) as AnswerDropped["filter"];
202
+ const reason = text(item.reason);
203
+ if (title === "" || reason === "" || !FILTERS.includes(filter)) {
204
+ problems.push(`dropped ${i + 1}: title, filter and reason are needed`);
205
+ return;
206
+ }
207
+ out.push({ title, filter, reason });
208
+ });
209
+ return out;
210
+ }
211
+
212
+ /** shownIds: the ids handed to the model; an id outside them is a problem. ownerLinesShown: whether the prompt that
213
+ * gave this answer showed owner lines; without them, a status other than new is a problem. */
214
+ export function checkLearnAnswer(
215
+ value: unknown, shownIds: ReadonlySet<string>, ownerLinesShown: boolean,
216
+ ): Checked<LearnAnswer> {
217
+ if (!isPlainObject(value)) return { ok: false, problems: ["the answer is not an object"] };
218
+ if (!Array.isArray(value.motifs)) return { ok: false, problems: ["motifs must be a list"] };
219
+ const problems: string[] = [];
220
+ if (value.motifs.length > MAX_MOTIFS_PER_AXIS) problems.push(`at most 3 motifs, not ${value.motifs.length}`);
221
+ const motifs: AnswerMotif[] = [];
222
+ // A motif's id hashes its axis and its rows: two motifs of one set of rows would share it, and one decision.
223
+ const rowSets = new Map<string, number>();
224
+ value.motifs.forEach((m, i) => {
225
+ const motif = checkMotif(m, i + 1, shownIds, ownerLinesShown, problems);
226
+ if (!motif) return;
227
+ motifs.push(motif);
228
+ const key = [...motif.rows].sort().join(",");
229
+ const first = rowSets.get(key);
230
+ if (first === undefined) rowSets.set(key, i + 1);
231
+ else problems.push(`${motifLabel(i + 1, motif.title)}: the same rows as motif ${first}: merge them into one motif`);
232
+ });
233
+ const dropped = checkDropped(value.dropped, problems);
234
+ return problems.length > 0 ? { ok: false, problems } : { ok: true, value: { motifs, dropped } };
235
+ }
@@ -0,0 +1,86 @@
1
+ // A motif's owner file as code reads it: the lines its key term finds and the removed
2
+ // lines the file does not hold, turned into the summary written to the proposal and,
3
+ // when the answer cannot stand as it is, the problems and owner lines a re-ask shows.
4
+ // The learner sees the owner files by path only, so these lines are the first it sees
5
+ // of their content. Pure, no IO: the file is read by the use case.
6
+ import { foldText } from "../../../shared/domain/shared-memory/verdict-rows.ts";
7
+ import type { AnswerMotif } from "./learn-answer.ts";
8
+
9
+ export const MAX_OWNER_LINES_PER_MOTIF = 8;
10
+ export const MAX_OWNER_LINE_CHARS = 160;
11
+ const REMOVED_SHOWN = 60;
12
+
13
+ export interface OwnerHit { n: number; line: string }
14
+ /** hits: the lines holding the key term (1-based numbers); missing: the removed lines, trimmed, the file lacks. */
15
+ export interface OwnerMatch { hits: OwnerHit[]; missing: string[] }
16
+ /** The owner lines shown under the problems of a re-ask, each `<path>:<n>: <line>`; label: the motif as the
17
+ * problems name it. */
18
+ export interface OwnerLinesBlock { label: string; path: string; lines: string[] }
19
+ export interface OwnerReview { summary: string; problems: string[]; block: OwnerLinesBlock | null }
20
+ export type ReviewedMotif = Pick<AnswerMotif, "title" | "keyTerm" | "status" | "linesRemoved">;
21
+
22
+ const cut = (text: string, n: number): string => {
23
+ const chars = Array.from(text);
24
+ return chars.length <= n ? text : chars.slice(0, n - 1).join("") + "…";
25
+ };
26
+
27
+ const words = (text: string): Set<string> => new Set(foldText(text).split(/[^\p{L}\p{N}]+/u).filter((w) => w.length >= 3));
28
+
29
+ export function matchOwner(text: string, keyTerm: string, removed: readonly string[]): OwnerMatch {
30
+ const lines = text.split(/\r?\n/);
31
+ const term = foldText(keyTerm);
32
+ const hits = lines.flatMap((line, i) => (foldText(line).includes(term) ? [{ n: i + 1, line }] : []));
33
+ const present = new Set(lines.map((l) => l.trim()));
34
+ const missing = removed.map((l) => l.trim()).filter((l) => !present.has(l));
35
+ return { hits, missing };
36
+ }
37
+
38
+ const shownLine = (path: string, hit: OwnerHit): string => `${path}:${hit.n}: ${cut(hit.line.trim(), MAX_OWNER_LINE_CHARS)}`;
39
+
40
+ /** The hit sharing the most words with `line`, the first on a tie. */
41
+ function nearest(hits: readonly OwnerHit[], line: string): OwnerHit {
42
+ const wanted = words(line);
43
+ let best = hits[0];
44
+ let bestScore = -1;
45
+ for (const hit of hits) {
46
+ const score = [...words(hit.line)].filter((w) => wanted.has(w)).length;
47
+ if (score > bestScore) {
48
+ best = hit;
49
+ bestScore = score;
50
+ }
51
+ }
52
+ return best;
53
+ }
54
+
55
+ /** What code found in the owner, as the proposal records it. */
56
+ export function ownerSummary(motif: ReviewedMotif, path: string, match: OwnerMatch): string {
57
+ const { hits } = match;
58
+ let out = hits.length === 0
59
+ ? `'${motif.keyTerm}' not found in ${path}`
60
+ : `'${motif.keyTerm}' on ${hits.length} lines of ${path}, first ${path}:${hits[0].n}`;
61
+ if (motif.status === "new" && hits.length > 0) out += "; the owner may already say it";
62
+ for (const removed of match.missing) out += `; removed line not found: ${cut(removed, REMOVED_SHOWN)}`;
63
+ return out;
64
+ }
65
+
66
+ /** label: the motif as the problems name it (motifLabel). A new motif whose key term is in the owner, and a removed
67
+ * line the owner lacks, are problems; the owner lines go with them, and with a motif whose status copies an owner
68
+ * line, when the key term found any. path: the owner as the model names it, never the deployed copy read. */
69
+ export function reviewOwner(label: string, motif: ReviewedMotif, path: string, match: OwnerMatch): OwnerReview {
70
+ const { hits, missing } = match;
71
+ const problems: string[] = [];
72
+ if (motif.status === "new" && hits.length > 0) {
73
+ problems.push(`${label}: '${motif.keyTerm}' is on ${hits.length} lines of ${path}, shown below: keep status new only ` +
74
+ "for what they miss; else refine, replace or remove one of them, or drop the motif under novelty");
75
+ }
76
+ for (const line of missing) {
77
+ const where = hits.length > 0
78
+ ? `; nearest: ${shownLine(path, nearest(hits, line))}`
79
+ : `; '${motif.keyTerm}' finds no line there: give the motif status new`;
80
+ problems.push(`${label}: removed line not found in ${path}: "${cut(line, REMOVED_SHOWN)}"${where}`);
81
+ }
82
+ const block = (problems.length > 0 || motif.status !== "new") && hits.length > 0
83
+ ? { label, path, lines: hits.slice(0, MAX_OWNER_LINES_PER_MOTIF).map((h) => shownLine(path, h)) }
84
+ : null;
85
+ return { summary: ownerSummary(motif, path, match), problems, block };
86
+ }
@@ -0,0 +1,96 @@
1
+ // PROPOSALS.md, rendered by code from the run's ProposalsFile: a head line, one section
2
+ // per axis (a table of the motifs kept, what was dropped, then one block per motif with
3
+ // its lines), and the commands that decide. The file is read by people; proposals.json
4
+ // beside it is the source the decisions read. Pure, no IO.
5
+ import type { AxisProposal, Motif, ProposalsFile } from "../../../shared/domain/dev/learn-proposals.ts";
6
+
7
+ const TITLE_CELL = 80;
8
+ const RECONCILE_CELL = 160;
9
+ const OWNER_CELL = 200;
10
+ /** The rows shown per axis (MAX_ROWS_PER_AXIS of run-dev-learn.ts), named in the "Not shown" line. */
11
+ const ROWS_CAP = 40;
12
+ const FENCE = "```";
13
+
14
+ /** "|" → "/", line breaks → " · ", cut at max characters with "…". */
15
+ export function escapeCell(text: string, max: number): string {
16
+ const flat = text.replace(/\r\n|\r|\n/g, " · ").replace(/\|/g, "/");
17
+ const chars = Array.from(flat);
18
+ return chars.length <= max ? flat : chars.slice(0, Math.max(0, max - 1)).join("") + "…";
19
+ }
20
+
21
+ function tableRow(m: Motif): string {
22
+ const owner = `${m.owner.kind} \`${escapeCell(m.owner.path, OWNER_CELL)}\``;
23
+ const cells = [
24
+ m.id, escapeCell(m.title, TITLE_CELL), String(m.batches.length), m.status, owner, m.check,
25
+ escapeCell(m.reconcile, RECONCILE_CELL),
26
+ ];
27
+ return `| ${cells.join(" | ")} |`;
28
+ }
29
+
30
+ function motifBlock(m: Motif): string[] {
31
+ return [
32
+ `### ${m.id} — ${m.title}`,
33
+ "",
34
+ `- Rows: ${m.rows.join(", ")} (batches ${m.batches.join(", ")})`,
35
+ `- Preventive line: ${m.preventiveLine}`,
36
+ `- Why new: ${m.novelty}`,
37
+ "- Lines:",
38
+ "",
39
+ `${FENCE}diff`,
40
+ `file: ${m.owner.path}`,
41
+ ...m.linesRemoved.map((l) => `- ${l}`),
42
+ ...m.linesAdded.map((l) => `+ ${l}`),
43
+ FENCE,
44
+ ];
45
+ }
46
+
47
+ function outcomeLine(a: AxisProposal): string {
48
+ if (a.outcome === "no-motif") return "No motif kept.";
49
+ if (a.outcome === "no-proposal") return `No proposal: the answer did not parse after one re-ask (${a.reason ?? "no reason given"}).`;
50
+ return `Unchanged since ${a.reason ?? "an earlier run"}: not asked again.`;
51
+ }
52
+
53
+ function axisSection(a: AxisProposal): string[] {
54
+ const out = [`## ${a.axis} — ${a.batches} batches, ${a.gaps} gaps`, ""];
55
+ if (a.outcome === "proposed") {
56
+ out.push(
57
+ "| Id | Motif | Batches | Status | Owner | Check | Reconcile |",
58
+ "|----|-------|---------|--------|-------|-------|-----------|",
59
+ ...a.motifs.map(tableRow),
60
+ );
61
+ } else {
62
+ out.push(outcomeLine(a));
63
+ }
64
+ const notes = [
65
+ ...a.dropped.map((d) => `Dropped: ${d.title} — ${d.filter}: ${d.reason}`),
66
+ ...(a.hiddenRows > 0 ? [`Not shown to the model: ${a.hiddenRows} gaps (cap ${ROWS_CAP})`] : []),
67
+ ];
68
+ if (notes.length > 0) out.push("", ...notes);
69
+ if (a.outcome === "proposed") for (const m of a.motifs) out.push("", ...motifBlock(m));
70
+ return out;
71
+ }
72
+
73
+ function decideSection(file: ProposalsFile): string[] {
74
+ const ids = file.axes.flatMap((a) => (a.outcome === "proposed" ? a.motifs.map((m) => m.id) : []));
75
+ if (ids.length === 0) return ["## Decide", "", "Nothing to decide."];
76
+ return [
77
+ "## Decide", "",
78
+ `${FENCE}text`,
79
+ `/dev-learn --accept ${ids.join(",")}`,
80
+ ...ids.map((id) => `/dev-learn --refuse ${id}`),
81
+ FENCE,
82
+ ];
83
+ }
84
+
85
+ export function renderProposals(file: ProposalsFile): string {
86
+ const r = file.read;
87
+ const lines = [
88
+ `# Learn proposals — ${file.date}`,
89
+ "",
90
+ `Work folder \`${file.work}\`: ${r.gaps} untreated gaps across ${r.batches} batches in ${r.files} verdict files. ` +
91
+ `Treated before: ${r.treatedOrkeon} by Orkeon Code, ${r.treatedHarness} by the harness. Refused motifs: ${r.refused}.`,
92
+ ];
93
+ for (const a of file.axes) lines.push("", ...axisSection(a));
94
+ lines.push("", ...decideSection(file));
95
+ return lines.join("\n") + "\n";
96
+ }
@@ -0,0 +1,76 @@
1
+ // The anchors of a checked plan answer against the repository: a path given as existing
2
+ // must be there, a path given as a file to create must not be. One listing per folder and
3
+ // per run (40 folders at most, the cache shared by the two attempts of a run); it reads
4
+ // listings only and writes nothing. Past the cap, or in a folder whose listing the entry cap
5
+ // cut short, an existing anchor it cannot see is refused as not checked, never let through. Its problems join the answer's, for the one re-ask.
6
+ import type { Files } from "../../../shared/application/ports.ts";
7
+ import { stepLabel } from "../domain/plan-answer.ts";
8
+ import type { AnchorRef, PlanAnswer } from "../domain/plan-answer.ts";
9
+ import { WORKSPACE } from "../../../shared/domain/vfs.ts";
10
+
11
+ export const MAX_ANCHOR_FOLDERS = 40;
12
+
13
+ /** The folders listed in one run, relative to /workspace ("" for the top), with the names they hold. */
14
+ export type AnchorListings = Map<string, ReadonlySet<string>>;
15
+
16
+ export const LIST_CAP = 1000;
17
+
18
+ const folderOf = (path: string): string => {
19
+ const cut = path.lastIndexOf("/");
20
+ return cut < 0 ? "" : path.slice(0, cut);
21
+ };
22
+ const nameOf = (path: string): string => path.slice(path.lastIndexOf("/") + 1);
23
+
24
+ /**
25
+ * `<step>: <path> does not exist` / `<step>: <path> exists: …` / `<step>: anchor "<path>" not checked: …`, the step
26
+ * labelled as the answer check labels it (`B1 "<name>" S2 "<title>"`),
27
+ * each once, in plan order. `listings` carries the folders already listed in this run, and gains the new ones.
28
+ */
29
+ export async function checkAnchorPaths(
30
+ files: Pick<Files, "list">, answer: PlanAnswer, listings: AnchorListings = new Map(),
31
+ ): Promise<string[]> {
32
+ const listing = async (folder: string): Promise<ReadonlySet<string> | null> => {
33
+ const known = listings.get(folder);
34
+ if (known !== undefined) return known;
35
+ if (listings.size >= MAX_ANCHOR_FOLDERS) return null;
36
+ let names: string[];
37
+ try {
38
+ names = await files.list(folder === "" ? WORKSPACE : `${WORKSPACE}/${folder}`, LIST_CAP);
39
+ } catch {
40
+ names = [];
41
+ }
42
+ const set = new Set(names.map((n) => n.replace(/\/+$/, "")));
43
+ listings.set(folder, set);
44
+ return set;
45
+ };
46
+ const problems: string[] = [];
47
+ const seen = new Set<string>();
48
+ for (const [k, batch] of answer.batches.entries()) {
49
+ for (const [j, step] of batch.steps.entries()) {
50
+ const anchors: AnchorRef[] = [...step.anchors.tests, ...step.anchors.doubles, ...step.anchors.production];
51
+ for (const a of anchors) {
52
+ if ((a.kind !== "create" && a.kind !== "existing") || a.path === undefined) continue;
53
+ const path = a.path.replace(/^\.\//, "");
54
+ const at = stepLabel(batch, k, j);
55
+ let problem: string | null = null;
56
+ if (path.includes(":")) {
57
+ problem = `${at}: anchor path "${path}" holds ":"`;
58
+ } else {
59
+ const names = await listing(folderOf(path));
60
+ if (names === null) {
61
+ if (a.kind === "existing") problem = `${at}: anchor "${path}" not checked: more than ${MAX_ANCHOR_FOLDERS} folders`;
62
+ } else {
63
+ const present = names.has(nameOf(path));
64
+ // A listing the cap cut short may leave the name out: that is no proof it is absent.
65
+ if (a.kind === "existing" && !present && names.size >= LIST_CAP) {
66
+ problem = `${at}: anchor "${path}" not checked: its folder lists more than ${LIST_CAP} entries`;
67
+ } else if (a.kind === "existing" && !present) problem = `${at}: ${path} does not exist`;
68
+ if (a.kind === "create" && present) problem = `${at}: ${path} exists: anchor it as existing, or by its ref`;
69
+ }
70
+ }
71
+ if (problem !== null && !seen.has(problem)) { seen.add(problem); problems.push(problem); }
72
+ }
73
+ }
74
+ }
75
+ return problems;
76
+ }
@@ -0,0 +1,170 @@
1
+ // The inventory of a /dev-plan run: the code the index finds for the titles of the
2
+ // source, located, with its callers and tests - from the batch_anchors closure of each
3
+ // best entry - and the modules each file imports. It is the only module of the crew that
4
+ // calls the code index. It reads the index and builds it when it holds no root; it writes
5
+ // nothing else.
6
+ import type { AnchorIndex, CodeIndex, CodeSearchHit, Logger } from "../../../shared/application/ports.ts";
7
+ import { INVENTORY_CAPS, keepPath, layerOf } from "../domain/inventory-model.ts";
8
+ import type { Inventory, InventoryEntry } from "../domain/inventory-model.ts";
9
+ import { WORKSPACE } from "../../../shared/domain/vfs.ts";
10
+ import { indexCacheNote } from "../../../shared/domain/code-intel-contract.ts";
11
+
12
+ export interface InventoryRequest {
13
+ titles: ReadonlyArray<{ id: string; title: string }>; // source order: UC, BR, CH
14
+ workShown: string;
15
+ layout: { domain?: string; application?: string; infrastructure?: string; tests?: string } | null;
16
+ buildOutputs: readonly string[];
17
+ }
18
+
19
+ const TOP = `${WORKSPACE}/`;
20
+ const GRAPH_SCOPE = "L2_Module";
21
+
22
+ const firstLine = (e: unknown): string => (e instanceof Error ? e.message : String(e)).split("\n")[0];
23
+ const pathPart = (fqn: string): string => {
24
+ const cut = fqn.indexOf("::");
25
+ return cut >= 0 ? fqn.slice(0, cut) : fqn;
26
+ };
27
+ const absolute = (path: string): string => (path.startsWith("/") ? path : `${TOP}${path}`);
28
+ const relative = (path: string): string => (path.startsWith(TOP) ? path.slice(TOP.length) : path);
29
+ const nameOf = (fqn: string): string => {
30
+ const cut = fqn.indexOf("::");
31
+ if (cut >= 0) return fqn.slice(cut + 2);
32
+ return fqn.slice(fqn.lastIndexOf("/") + 1);
33
+ };
34
+
35
+ interface Kept { fqn: string; score: number; origin: string; forIds: Set<string> }
36
+
37
+ /** Searches each title, then fills the entries one per title, then a second, then a third. */
38
+ async function search(
39
+ index: CodeIndex, request: InventoryRequest, keep: (path: string) => string | null, state: { calls: number; warnings: string[] },
40
+ ): Promise<Kept[]> {
41
+ const titles = request.titles.slice(0, INVENTORY_CAPS.titles);
42
+ const hits: CodeSearchHit[][] = [];
43
+ for (const t of titles) {
44
+ state.calls++;
45
+ try {
46
+ const found = await index.search(t.title, INVENTORY_CAPS.topK);
47
+ hits.push(found.filter((h) => keep(pathPart(h.fqn)) !== null));
48
+ } catch (e) {
49
+ state.warnings.push(`search failed for ${t.id}: ${firstLine(e)}`);
50
+ hits.push([]);
51
+ }
52
+ }
53
+ const kept = new Map<string, Kept>();
54
+ const cursor = titles.map(() => 0);
55
+ const taken = titles.map(() => 0);
56
+ for (let pass = 0; pass < INVENTORY_CAPS.hitsPerTitle; pass++) {
57
+ for (let i = 0; i < titles.length; i++) {
58
+ if (kept.size >= INVENTORY_CAPS.entries) return [...kept.values()];
59
+ if (taken[i] > pass) continue;
60
+ while (cursor[i] < hits[i].length) {
61
+ const hit = hits[i][cursor[i]++];
62
+ const already = kept.get(hit.fqn);
63
+ if (already) { already.forIds.add(titles[i].id); continue; }
64
+ kept.set(hit.fqn, { fqn: hit.fqn, score: hit.score, origin: hit.origin, forIds: new Set([titles[i].id]) });
65
+ taken[i]++;
66
+ break;
67
+ }
68
+ }
69
+ }
70
+ return [...kept.values()];
71
+ }
72
+
73
+ /** Whether `fqn` is `owner` or one of its members (`<owner>::<member>`, as the index forms them). */
74
+ const inSubtree = (fqn: string, owner: string): boolean => fqn === owner || fqn.startsWith(`${owner}::`);
75
+
76
+ export async function buildInventory(
77
+ index: CodeIndex, anchors: AnchorIndex, request: InventoryRequest, log: Logger,
78
+ ): Promise<{ ok: true; inventory: Inventory } | { ok: false; text: string }> {
79
+ const state = { calls: 0, warnings: [] as string[] };
80
+ const refuse = (e: unknown) => ({
81
+ ok: false as const,
82
+ text: `dev-plan: the code index cannot be built (${firstLine(e)}): anchors would be guesses, so no plan is written`,
83
+ });
84
+
85
+ // 1. The index: present, or built now.
86
+ let status: Inventory["index"] = "present";
87
+ let note = "";
88
+ try {
89
+ state.calls++;
90
+ if ((await index.rootCount()) === 0) {
91
+ state.calls++;
92
+ const built = await index.index(WORKSPACE);
93
+ status = built.files === 0 ? "empty" : "built";
94
+ note = indexCacheNote(built);
95
+ }
96
+ } catch (e) {
97
+ return refuse(e);
98
+ }
99
+ log.info(`dev-plan: code index ${status}${note === "" ? "" : `; ${note}`}`);
100
+ if (status === "empty") {
101
+ state.warnings.push("the code index holds no file: every anchor is a path to create");
102
+ return { ok: true, inventory: { entries: [], index: status, titlesSearched: 0, calls: state.calls, warnings: state.warnings } };
103
+ }
104
+
105
+ // 2. The searches and the round robin.
106
+ const keep = (path: string): string | null => keepPath(absolute(path), [request.workShown], request.buildOutputs);
107
+ const titlesSearched = Math.min(request.titles.length, INVENTORY_CAPS.titles);
108
+ if (request.titles.length > INVENTORY_CAPS.titles) {
109
+ const left = request.titles.slice(INVENTORY_CAPS.titles);
110
+ state.warnings.push(`${left.length} titles not searched: ${left.map((t) => t.id).join(", ")}`);
111
+ }
112
+ const kept = await search(index, request, keep, state);
113
+ log.info(`dev-plan: ${titlesSearched} titles searched, ${kept.length} symbols kept`);
114
+
115
+ // 3. Where each kept symbol lives; refs are given to the survivors, in discovery order.
116
+ const order = new Map(request.titles.map((t, i) => [t.id, i]));
117
+ const entries: InventoryEntry[] = [];
118
+ for (const k of kept) {
119
+ state.calls++;
120
+ try {
121
+ const at = await index.symbolSource(k.fqn);
122
+ const path = keep(at.path);
123
+ if (path === null) { state.warnings.push(`${k.fqn} dropped: ${at.path} is outside what a plan may anchor`); continue; }
124
+ entries.push({
125
+ ref: `I${entries.length + 1}`, fqn: k.fqn, name: nameOf(k.fqn), path,
126
+ line: at.startLine, endLine: at.endLine, language: at.language, firstLine: at.firstLine,
127
+ layer: layerOf(path, request.layout),
128
+ forIds: [...k.forIds].sort((a, b) => (order.get(a) ?? 0) - (order.get(b) ?? 0)),
129
+ score: k.score, origin: k.origin, callers: [], imports: [],
130
+ });
131
+ } catch (e) {
132
+ state.warnings.push(`${k.fqn} dropped: ${firstLine(e)}`);
133
+ }
134
+ }
135
+ log.info(`dev-plan: ${entries.length} entries located`);
136
+
137
+ if (entries.length > 0) {
138
+ // 4. The callers and tests of the best entries: their closure without their own subtree.
139
+ const best = [...entries].sort((a, b) => b.score - a.score).slice(0, INVENTORY_CAPS.impacts);
140
+ for (const e of best) {
141
+ state.calls++;
142
+ try {
143
+ const closure = await anchors.closure([e.fqn]);
144
+ const own = relative(e.fqn);
145
+ e.callers = closure.nodes.map(relative).filter((n) => !inSubtree(n, own)).slice(0, INVENTORY_CAPS.callers);
146
+ if (closure.truncated) state.warnings.push(`closure of ${e.fqn} truncated`);
147
+ if (closure.unresolved.length > 0) state.warnings.push(`${e.fqn} unknown to batch_anchors`);
148
+ } catch (err) {
149
+ state.warnings.push(`anchors failed for ${e.fqn}: ${firstLine(err)}`);
150
+ }
151
+ }
152
+ log.info(`dev-plan: callers asked for ${best.length} entries`);
153
+
154
+ // 5. The modules each entry's file imports, from one module graph.
155
+ state.calls++;
156
+ try {
157
+ const graph = await index.dependencyGraph(GRAPH_SCOPE, INVENTORY_CAPS.graphNodes);
158
+ const fileOf = (node: string): string => relative(node.split("#")[0]);
159
+ for (const e of entries) {
160
+ const to = graph.edges.filter((edge) => fileOf(edge.from) === e.path).map((edge) => fileOf(edge.to));
161
+ e.imports = [...new Set(to)].filter((p) => p !== e.path).slice(0, INVENTORY_CAPS.imports);
162
+ }
163
+ log.info(`dev-plan: module graph of ${graph.edges.length} edges joined`);
164
+ } catch (e) {
165
+ state.warnings.push(`the module graph failed: ${firstLine(e)}`);
166
+ }
167
+ }
168
+
169
+ return { ok: true, inventory: { entries, index: status, titlesSearched, calls: state.calls, warnings: state.warnings } };
170
+ }