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,41 @@
1
+ // The shared memory's generated lists, pure: candidates/CANDIDATES.md (the pending candidates) and
2
+ // INDEX.md (every entry of entries/). Both are views rebuilt from the files, which stay the truth.
3
+ // A decided candidate cannot be deleted (no file tool removes a file): its file is rewritten to one
4
+ // pointer line, which never parses as an entry, so it is no longer a candidate.
5
+
6
+ import type { MemoryEntry } from "./entry.ts";
7
+
8
+ export const CANDIDATES_TITLE = "# Memory candidates";
9
+ export const CANDIDATES_INTRO = "Pending candidates, waiting for /memory-admit. Generated from candidates/*.md: edit those, not this list.";
10
+ export const INDEX_TITLE = "# Shared memory";
11
+ export const INDEX_INTRO = "Every entry of entries/, admitted or superseded. Generated by /memory-admit.";
12
+
13
+ const cell = (text: string): string => text.replace(/\r?\n/g, " ").replace(/\\/g, "\\\\").replace(/\|/g, "\\|").trim();
14
+
15
+ function table(head: readonly string[], rows: ReadonlyArray<readonly string[]>): string[] {
16
+ return [`| ${head.join(" | ")} |`, `|${head.map(() => "---").join("|")}|`, ...rows.map((r) => `| ${r.map(cell).join(" | ")} |`)];
17
+ }
18
+
19
+ /** How many distinct batches a source names (`<code>/<CODE>-VERIFY-F<n>.md`), for the batches column; "-" when none. */
20
+ export function batchesOf(source: string): string {
21
+ const batches = new Set([...source.matchAll(/([^\s,:/]+)\/[^\s,/]*-VERIFY-(F\d+)/g)].map((m) => `${m[1]}/${m[2]}`));
22
+ return batches.size === 0 ? "-" : String(batches.size);
23
+ }
24
+
25
+ export function candidatesList(candidates: readonly MemoryEntry[]): string {
26
+ const rows = [...candidates].sort((a, b) => a.id.localeCompare(b.id))
27
+ .map((c) => [c.id, c.type, c.topic, c.source, batchesOf(c.source)]);
28
+ return [CANDIDATES_TITLE, "", CANDIDATES_INTRO, "", ...table(["id", "type", "topic", "source", "batches"], rows)].join("\n") + "\n";
29
+ }
30
+
31
+ export function entriesIndex(entries: readonly MemoryEntry[]): string {
32
+ const rows = [...entries].sort((a, b) => a.id.localeCompare(b.id)).map((e) => [e.id, e.type, e.status, e.title]);
33
+ return [INDEX_TITLE, "", INDEX_INTRO, "", ...table(["id", "type", "status", "title"], rows)].join("\n") + "\n";
34
+ }
35
+
36
+ /** What a decided candidate's file becomes. */
37
+ export function decidedPointer(decision: "admitted" | "refused", date: string, entryFile?: string): string {
38
+ return decision === "admitted"
39
+ ? `Admitted on ${date} as ${entryFile}. This file can be deleted.\n`
40
+ : `Refused on ${date}: its topic is in refused.md. This file can be deleted.\n`;
41
+ }
@@ -0,0 +1,145 @@
1
+ // A shared-memory entry, pure: its fields, its id scheme, and the checks that decide
2
+ // whether it may be stored as data (shape, secrets, provenance markers). Parsing the
3
+ // file lives in front-matter.ts; this module never reads or writes anything.
4
+
5
+ import { secretLikePaths, secretPatternsIn } from "../secret-patterns.ts";
6
+ import { MAX_TOPIC_CHARS, TOPIC_PATTERN } from "./refused.ts";
7
+
8
+ export const ENTRY_TYPES = ["decision", "code-structure", "method", "mistake"] as const;
9
+ export type EntryType = (typeof ENTRY_TYPES)[number];
10
+ export const ENTRY_STATUSES = ["candidate", "admitted", "superseded"] as const;
11
+ export type EntryStatus = (typeof ENTRY_STATUSES)[number];
12
+ export const SOURCE_KINDS = ["verdict", "audit", "human"] as const;
13
+ /** The front-matter keys, in the order serializeEntry writes them (temp/05 § 2). */
14
+ export const ENTRY_KEYS: readonly string[] = [
15
+ "id", "type", "title", "project", "date", "topic", "applies_when", "rationale", "correction", "detection_signal",
16
+ "source", "status", "supersedes", "superseded_by", "tags", "stack",
17
+ ];
18
+ export const ENTRY_SECTIONS = ["Context", "Content", "Evidence"] as const;
19
+ export const MAX_TITLE_CHARS = 90;
20
+ export const MAX_BODY_CHARS = 2_000;
21
+
22
+ export interface MemoryEntry {
23
+ id: string; type: EntryType; title: string; project: string; date: string; topic: string;
24
+ appliesWhen: string; rationale: string; correction?: string; detectionSignal?: string;
25
+ source: string; status: EntryStatus; supersedes: string[]; supersededBy?: string;
26
+ tags: string[]; stack: string[];
27
+ /** The text after the front matter, from "## Context" on. */
28
+ body: string;
29
+ }
30
+
31
+ const KEBAB = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
32
+ const SOURCE = /^(verdict|audit|human):\S/;
33
+ const TOKEN = /^[a-z0-9][a-z0-9.+#-]*$/;
34
+
35
+ /** "<project>-<type>-<yyyymmdd>-": what every id of this project, type and date starts with. */
36
+ export function entryIdPrefix(project: string, type: EntryType, date: string): string {
37
+ return `${project}-${type}-${date.replace(/-/g, "")}-`;
38
+ }
39
+
40
+ function isCalendarDate(text: string): boolean {
41
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text);
42
+ if (!m) return false;
43
+ const [year, month, day] = [Number(m[1]), Number(m[2]), Number(m[3])];
44
+ const date = new Date(Date.UTC(year, month - 1, day));
45
+ return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
46
+ }
47
+
48
+ const present = (value: string | undefined): boolean => value !== undefined && value.trim() !== "";
49
+
50
+ /** The front-matter values of the entry, by key, in ENTRY_KEYS order (absent optional keys left out). */
51
+ function entryValues(entry: MemoryEntry): Array<[string, string]> {
52
+ const values: Record<string, string | string[] | undefined> = {
53
+ id: entry.id, type: entry.type, title: entry.title, project: entry.project, date: entry.date, topic: entry.topic,
54
+ applies_when: entry.appliesWhen, rationale: entry.rationale, correction: entry.correction,
55
+ detection_signal: entry.detectionSignal, source: entry.source, status: entry.status, supersedes: entry.supersedes,
56
+ superseded_by: entry.supersededBy, tags: entry.tags, stack: entry.stack,
57
+ };
58
+ return ENTRY_KEYS.flatMap((key): Array<[string, string]> => {
59
+ const value = values[key];
60
+ if (value === undefined) return [];
61
+ return [[key, Array.isArray(value) ? value.join("\n") : String(value)]];
62
+ });
63
+ }
64
+
65
+ /** The paths the "## Evidence" section names, as `path` or path:line, each once. */
66
+ function evidencePaths(body: string): string[] {
67
+ const lines = body.split("\n");
68
+ const start = lines.findIndex((line) => /^## Evidence\s*$/.test(line));
69
+ if (start < 0) return [];
70
+ const end = lines.findIndex((line, i) => i > start && /^## /.test(line));
71
+ const section = lines.slice(start + 1, end < 0 ? undefined : end).join("\n");
72
+ const paths: string[] = [];
73
+ for (const m of section.matchAll(/`([^`\s]+)`/g)) paths.push(m[1].replace(/:\d+(?:-\d+)?$/, ""));
74
+ for (const m of section.replace(/`[^`]*`/g, " ").matchAll(/([^\s`'"(),;]+):\d+/g)) paths.push(m[1]);
75
+ return [...new Set(paths.filter((path) => path.length > 0))];
76
+ }
77
+
78
+ function sectionsInOrder(body: string): boolean {
79
+ const lines = body.split("\n");
80
+ let from = 0;
81
+ for (const name of ENTRY_SECTIONS) {
82
+ const at = lines.findIndex((line, i) => i >= from && line.trimEnd() === `## ${name}`);
83
+ if (at < 0) return false;
84
+ from = at + 1;
85
+ }
86
+ return true;
87
+ }
88
+
89
+ /** Every problem, in the order of the design's table; empty when the entry is admissible as data. */
90
+ export function entryProblems(entry: MemoryEntry, markers: readonly RegExp[] = []): string[] {
91
+ const problems: string[] = [];
92
+ const typeOk = (ENTRY_TYPES as readonly string[]).includes(entry.type);
93
+ const prefix = entryIdPrefix(entry.project, entry.type, entry.date);
94
+ if (!KEBAB.test(entry.id) || !entry.id.startsWith(prefix) || !KEBAB.test(entry.id.slice(prefix.length))) {
95
+ problems.push(`id '${entry.id}' is not ${entry.project}-${entry.type}-${entry.date.replace(/-/g, "")}-<slug>`);
96
+ }
97
+ if (!typeOk) problems.push(`type must be one of ${ENTRY_TYPES.join(", ")}`);
98
+ if (entry.title.length < 1 || entry.title.length > MAX_TITLE_CHARS || /[\r\n]/.test(entry.title)) {
99
+ problems.push(`title must be one line of 1 to ${MAX_TITLE_CHARS} characters`);
100
+ }
101
+ if (!KEBAB.test(entry.project)) problems.push(`project '${entry.project}' is not a kebab-case name`);
102
+ if (!isCalendarDate(entry.date)) problems.push(`date '${entry.date}' is not YYYY-MM-DD`);
103
+ if (!TOPIC_PATTERN.test(entry.topic)) {
104
+ problems.push(`topic '${entry.topic}' is not a kebab slug of at most ${MAX_TOPIC_CHARS} characters`);
105
+ }
106
+ if (!present(entry.appliesWhen)) problems.push("applies_when is empty");
107
+ if (!present(entry.rationale)) problems.push("rationale is empty");
108
+ const mistakeKeys: Array<[string, string | undefined]> = [
109
+ ["correction", entry.correction], ["detection_signal", entry.detectionSignal],
110
+ ];
111
+ for (const [key, value] of mistakeKeys) {
112
+ if (entry.type === "mistake" && !present(value)) problems.push(`a mistake needs ${key}`);
113
+ if (entry.type !== "mistake" && present(value)) problems.push(`${key} is for a mistake only`);
114
+ }
115
+ if (!SOURCE.test(entry.source)) problems.push("source must start with verdict:, audit: or human:");
116
+ if (!(ENTRY_STATUSES as readonly string[]).includes(entry.status)) {
117
+ problems.push(`status must be one of ${ENTRY_STATUSES.join(", ")}`);
118
+ }
119
+ for (const id of entry.supersedes) {
120
+ if (!id.startsWith(`${entry.project}-`)) problems.push(`supersedes '${id}' is not an entry of project ${entry.project}`);
121
+ }
122
+ if ((entry.status === "superseded") !== present(entry.supersededBy)) {
123
+ problems.push("superseded_by is set exactly when status is superseded");
124
+ }
125
+ for (const [key, items] of [["tags", entry.tags], ["stack", entry.stack]] as const) {
126
+ for (const item of items) if (!TOKEN.test(item)) problems.push(`${key} item '${item}' is not a lower-case token`);
127
+ }
128
+ if (!sectionsInOrder(entry.body)) problems.push("the body needs ## Context, ## Content and ## Evidence, in this order");
129
+ if (entry.body.length > MAX_BODY_CHARS) {
130
+ problems.push(`the body is ${entry.body.length} characters, over ${MAX_BODY_CHARS}`);
131
+ }
132
+ for (const path of secretLikePaths(evidencePaths(entry.body))) problems.push(`evidence names a secret-like file: ${path}`);
133
+ const texts: Array<[string, string]> = [...entryValues(entry), ["body", entry.body]];
134
+ for (const [key, text] of texts) {
135
+ for (const name of secretPatternsIn(text)) problems.push(`${key} looks like it holds a secret (${name})`);
136
+ }
137
+ for (const [key, text] of texts) {
138
+ for (const marker of markers) {
139
+ if (new RegExp(marker.source, marker.flags.replace(/[gy]/g, "")).test(text)) {
140
+ problems.push(`${key} carries a provenance marker (${marker.source})`);
141
+ }
142
+ }
143
+ }
144
+ return problems;
145
+ }
@@ -0,0 +1,183 @@
1
+ // The flat front matter of a memory entry, pure: "---", one "key: value" per line (a
2
+ // scalar, a JSON string, or an inline list), "---", then the body as written. No
3
+ // nesting and no comments: a "#" in a value is text. The parser is ours because the
4
+ // runtime loads no package, and it lives in the domain so the use cases test in Node.
5
+
6
+ import { ENTRY_KEYS } from "./entry.ts";
7
+ import type { EntryStatus, EntryType, MemoryEntry } from "./entry.ts";
8
+
9
+ export type FlatValue = string | string[];
10
+ export interface FrontMatter { fields: Array<{ key: string; value: FlatValue; line: number }>; body: string }
11
+ export type FrontMatterParse = { ok: true; doc: FrontMatter } | { ok: false; problems: string[] };
12
+
13
+ const FENCE = "---";
14
+ const KEY_LINE = /^([a-z][a-z_]*):(?: (.*))?$/;
15
+
16
+ class ValueError extends Error {}
17
+
18
+ /** One JSON string starting at `from`; returns the decoded text and the index after it. */
19
+ function readQuoted(text: string, from: number): { value: string; next: number } {
20
+ let i = from + 1;
21
+ while (i < text.length && text[i] !== "\"") i += text[i] === "\\" ? 2 : 1;
22
+ if (i >= text.length) throw new ValueError("bad quoted value");
23
+ let value: unknown;
24
+ try { value = JSON.parse(text.slice(from, i + 1)); } catch { throw new ValueError("bad quoted value"); }
25
+ if (typeof value !== "string") throw new ValueError("bad quoted value");
26
+ return { value, next: i + 1 };
27
+ }
28
+
29
+ function parseList(inner: string): string[] {
30
+ if (inner.trim() === "") return [];
31
+ const items: string[] = [];
32
+ let i = 0;
33
+ for (;;) {
34
+ while (inner[i] === " ") i++;
35
+ if (inner[i] === "\"") {
36
+ const quoted = readQuoted(inner, i);
37
+ items.push(quoted.value);
38
+ i = quoted.next;
39
+ while (inner[i] === " ") i++;
40
+ if (i < inner.length && inner[i] !== ",") throw new ValueError("bad quoted value");
41
+ } else {
42
+ const comma = inner.indexOf(",", i);
43
+ const item = inner.slice(i, comma < 0 ? inner.length : comma).trim();
44
+ if (/[[\]]/.test(item)) throw new ValueError("unclosed list");
45
+ if (item.includes("\"")) throw new ValueError("bad quoted value");
46
+ items.push(item);
47
+ i = comma < 0 ? inner.length : comma;
48
+ }
49
+ if (i >= inner.length) return items;
50
+ i++; // the comma
51
+ }
52
+ }
53
+
54
+ function parseValue(raw: string): FlatValue {
55
+ const text = raw.trim();
56
+ if (text.startsWith("[")) {
57
+ if (!text.endsWith("]")) throw new ValueError("unclosed list");
58
+ return parseList(text.slice(1, -1));
59
+ }
60
+ if (text.startsWith("\"")) {
61
+ const quoted = readQuoted(text, 0);
62
+ if (quoted.next !== text.length) throw new ValueError("bad quoted value");
63
+ return quoted.value;
64
+ }
65
+ return text;
66
+ }
67
+
68
+ export function parseFrontMatter(text: string): FrontMatterParse {
69
+ const lines = String(text ?? "").split("\n");
70
+ const strip = (line: string): string => line.replace(/\r$/, "");
71
+ if (strip(lines[0]) !== FENCE) return { ok: false, problems: ["line 1: the front matter must open with ---"] };
72
+ const close = lines.findIndex((line, i) => i > 0 && strip(line) === FENCE);
73
+ if (close < 0) return { ok: false, problems: ["the front matter is not closed by ---"] };
74
+ const problems: string[] = [];
75
+ const fields: FrontMatter["fields"] = [];
76
+ const seen = new Set<string>();
77
+ for (let i = 1; i < close; i++) {
78
+ const raw = strip(lines[i]);
79
+ const n = i + 1;
80
+ const m = KEY_LINE.exec(raw);
81
+ if (!m) { problems.push(`line ${n}: '${raw}' is not key: value`); continue; }
82
+ const key = m[1];
83
+ if (seen.has(key)) { problems.push(`line ${n}: duplicate key '${key}'`); continue; }
84
+ seen.add(key);
85
+ try {
86
+ fields.push({ key, value: parseValue(m[2] ?? ""), line: n });
87
+ } catch (error) {
88
+ if (!(error instanceof ValueError)) throw error;
89
+ problems.push(`line ${n}: ${error.message}`);
90
+ }
91
+ }
92
+ if (problems.length > 0) return { ok: false, problems };
93
+ return { ok: true, doc: { fields, body: lines.slice(close + 1).join("\n") } };
94
+ }
95
+
96
+ function needsQuotes(value: string): boolean {
97
+ return value === "" || value.startsWith("[") || value.startsWith("\"") || value !== value.trim()
98
+ || value.includes(": ") || value.includes(" #");
99
+ }
100
+
101
+ function itemNeedsQuotes(item: string): boolean {
102
+ return item === "" || item !== item.trim() || /[,[\]"]/.test(item) || /[\r\n]/.test(item);
103
+ }
104
+
105
+ function writeValue(key: string, value: FlatValue): string {
106
+ if (Array.isArray(value)) {
107
+ return `[${value.map((item) => (itemNeedsQuotes(item) ? JSON.stringify(item) : item)).join(", ")}]`;
108
+ }
109
+ if (/[\r\n]/.test(value)) throw new Error(`a front-matter value is one line: ${key}`);
110
+ return needsQuotes(value) ? JSON.stringify(value) : value;
111
+ }
112
+
113
+ export function serializeFrontMatter(doc: FrontMatter): string {
114
+ const lines = doc.fields.map((field) => `${field.key}: ${writeValue(field.key, field.value)}`);
115
+ return [FENCE, ...lines, FENCE].join("\n") + "\n" + doc.body;
116
+ }
117
+
118
+ const LIST_KEYS = new Set(["supersedes", "tags", "stack"]);
119
+ const OPTIONAL_KEYS = new Set(["correction", "detection_signal", "superseded_by", "supersedes", "tags", "stack"]);
120
+
121
+ export function entryFromFrontMatter(
122
+ doc: FrontMatter,
123
+ ): { ok: true; entry: MemoryEntry } | { ok: false; problems: string[] } {
124
+ const problems: string[] = [];
125
+ const text: Record<string, string> = {};
126
+ const lists: Record<string, string[]> = {};
127
+ for (const { key, value } of doc.fields) {
128
+ if (!ENTRY_KEYS.includes(key)) { problems.push(`unknown key '${key}'`); continue; }
129
+ if (LIST_KEYS.has(key)) {
130
+ if (Array.isArray(value)) lists[key] = value;
131
+ else problems.push(`${key} must be a list`);
132
+ } else if (Array.isArray(value)) {
133
+ problems.push(`${key} must be text`);
134
+ } else {
135
+ text[key] = value;
136
+ }
137
+ }
138
+ const given = new Set(doc.fields.map((field) => field.key));
139
+ for (const key of ENTRY_KEYS) {
140
+ if (!OPTIONAL_KEYS.has(key) && !given.has(key)) problems.push(`missing key '${key}'`);
141
+ }
142
+ if (problems.length > 0) return { ok: false, problems };
143
+ const entry: MemoryEntry = {
144
+ id: text.id, type: text.type as EntryType, title: text.title, project: text.project, date: text.date,
145
+ topic: text.topic, appliesWhen: text.applies_when, rationale: text.rationale,
146
+ source: text.source, status: text.status as EntryStatus,
147
+ supersedes: lists.supersedes ?? [], tags: lists.tags ?? [], stack: lists.stack ?? [],
148
+ body: doc.body,
149
+ };
150
+ if (text.correction !== undefined) entry.correction = text.correction;
151
+ if (text.detection_signal !== undefined) entry.detectionSignal = text.detection_signal;
152
+ if (text.superseded_by !== undefined) entry.supersededBy = text.superseded_by;
153
+ return { ok: true, entry };
154
+ }
155
+
156
+ /** A prose value on one line: a wrapped rationale is joined, since a front-matter scalar holds no line break. */
157
+ const joined = (text: string | undefined): string | undefined =>
158
+ text === undefined || !/[\r\n]/.test(text) ? text : text.split(/\r\n|\r|\n/).map((part) => part.trim()).filter(Boolean).join(" ");
159
+
160
+ /** The entry's front matter, keys in ENTRY_KEYS order, optional absent keys omitted; prose values joined on one line. */
161
+ export function entryToFrontMatter(entry: MemoryEntry): FrontMatter {
162
+ const values: Record<string, FlatValue | undefined> = {
163
+ id: entry.id, type: entry.type, title: entry.title, project: entry.project, date: entry.date, topic: entry.topic,
164
+ applies_when: joined(entry.appliesWhen), rationale: joined(entry.rationale), correction: joined(entry.correction),
165
+ detection_signal: joined(entry.detectionSignal), source: entry.source, status: entry.status, supersedes: entry.supersedes,
166
+ superseded_by: entry.supersededBy, tags: entry.tags, stack: entry.stack,
167
+ };
168
+ const fields: FrontMatter["fields"] = [];
169
+ for (const key of ENTRY_KEYS) {
170
+ const value = values[key];
171
+ if (value !== undefined) fields.push({ key, value, line: fields.length + 2 });
172
+ }
173
+ return { fields, body: entry.body };
174
+ }
175
+
176
+ export function parseEntry(text: string): { ok: true; entry: MemoryEntry } | { ok: false; problems: string[] } {
177
+ const parsed = parseFrontMatter(text);
178
+ return parsed.ok ? entryFromFrontMatter(parsed.doc) : parsed;
179
+ }
180
+
181
+ export function serializeEntry(entry: MemoryEntry): string {
182
+ return serializeFrontMatter(entryToFrontMatter(entry));
183
+ }
@@ -0,0 +1,44 @@
1
+ // The write gate of the shared memory, pure (temp/05 § 3): which source may admit which type,
2
+ // when an admission is confirmed by the operator, and the recurrence a harvested mistake needs.
3
+
4
+ import { ENTRY_TYPES } from "./entry.ts";
5
+ import type { EntryType, MemoryEntry } from "./entry.ts";
6
+ import { MIN_MOTIF_BATCHES } from "./verdict-rows.ts";
7
+ import { batchesOf } from "./candidates.ts";
8
+
9
+ export type SourceKind = "verdict" | "audit" | "human";
10
+
11
+ /** human: the operator decided, any type; audit: a verdict backs a structure or a mistake; verdict: a human stop
12
+ * of the dev workflow already passed, for a method or a decision. */
13
+ export const ADMITTED_TYPES_BY_SOURCE: Readonly<Record<SourceKind, readonly EntryType[]>> = {
14
+ human: ENTRY_TYPES,
15
+ audit: ["code-structure", "mistake"],
16
+ verdict: ["method", "decision"],
17
+ };
18
+
19
+ /** A mistake is harvested from audit rows only when it recurs in this many distinct batches. */
20
+ export const MISTAKE_MIN_BATCHES = MIN_MOTIF_BATCHES;
21
+
22
+ export function sourceKind(source: string): SourceKind | undefined {
23
+ const m = /^(verdict|audit|human):\S/.exec(source);
24
+ return m === null ? undefined : (m[1] as SourceKind);
25
+ }
26
+
27
+ /** Why the entry's source cannot admit its type; undefined when it can. */
28
+ export function admissionProblem(entry: Pick<MemoryEntry, "type" | "source">): string | undefined {
29
+ const kind = sourceKind(entry.source);
30
+ if (kind === undefined) return "its source is not verdict:, audit: or human:";
31
+ const types = ADMITTED_TYPES_BY_SOURCE[kind];
32
+ if (!types.includes(entry.type)) return `${kind === "audit" ? "an" : "a"} ${kind}: source admits ${types.join(" or ")}, not ${entry.type}`;
33
+ if (kind === "audit" && entry.type === "mistake") {
34
+ const batches = batchesOf(entry.source);
35
+ const n = batches === "-" ? 0 : Number(batches);
36
+ if (n < MISTAKE_MIN_BATCHES) return `an audited mistake names ${MISTAKE_MIN_BATCHES} batches' verdict files at least, this one ${n}`;
37
+ }
38
+ return undefined;
39
+ }
40
+
41
+ /** Whether the operator confirms the admission: always, unless an audit backs it and memory.autoAdmitAudited is true. */
42
+ export function asksConfirmation(entry: Pick<MemoryEntry, "source">, autoAdmitAudited: boolean): boolean {
43
+ return !(autoAdmitAudited && sourceKind(entry.source) === "audit");
44
+ }
@@ -0,0 +1,61 @@
1
+ // Mistake candidates from audit rows, pure (temp/05 § 3.2): the Blocking and Major gaps of the
2
+ // verdict files, grouped by the topic of their text, become one candidate each once they recur in
3
+ // MISTAKE_MIN_BATCHES distinct batches. Refused topics are left out and named.
4
+
5
+ import { MAX_BODY_CHARS, MAX_TITLE_CHARS, entryIdPrefix } from "./entry.ts";
6
+ import type { MemoryEntry } from "./entry.ts";
7
+ import { MISTAKE_MIN_BATCHES } from "./gate.ts";
8
+ import { topicOf } from "./refused.ts";
9
+ import type { LearnRow } from "./verdict-rows.ts";
10
+
11
+ export interface HarvestPlan {
12
+ candidates: MemoryEntry[];
13
+ /** Topics left out because refused.md holds them. */
14
+ refused: string[];
15
+ /** Topics seen in fewer batches than the threshold, with their count. */
16
+ below: Array<{ topic: string; batches: number }>;
17
+ }
18
+
19
+ const cut = (text: string, n: number): string => {
20
+ const t = text.replace(/\s+/g, " ").trim();
21
+ return t.length <= n ? t : `${t.slice(0, n - 1).trimEnd()}…`;
22
+ };
23
+
24
+ /** The body, its evidence lines cut from the end (one at least) to stay under MAX_BODY_CHARS. */
25
+ function bodyOf(rows: number, batches: number, content: string, evidence: string[]): string {
26
+ const head = ["## Context", `Harvested from ${rows} audit rows of ${batches} batches.`, "", "## Content", content, "", "## Evidence"];
27
+ const kept = [...evidence];
28
+ const text = (): string => [...head, ...kept, ...(kept.length < evidence.length ? [`- and ${evidence.length - kept.length} more rows`] : [])].join("\n") + "\n";
29
+ while (kept.length > 1 && text().length > MAX_BODY_CHARS) kept.pop();
30
+ return text();
31
+ }
32
+
33
+ export function mistakeCandidates(
34
+ rows: readonly LearnRow[], context: { project: string; date: string; refusedTopics: ReadonlySet<string> },
35
+ ): HarvestPlan {
36
+ const byTopic = new Map<string, LearnRow[]>();
37
+ for (const row of rows) {
38
+ const topic = topicOf(row.gap);
39
+ byTopic.set(topic, [...(byTopic.get(topic) ?? []), row]);
40
+ }
41
+ const plan: HarvestPlan = { candidates: [], refused: [], below: [] };
42
+ for (const [topic, group] of [...byTopic].sort(([a], [b]) => a.localeCompare(b))) {
43
+ const batches = [...new Set(group.map((r) => r.batch))].sort();
44
+ if (context.refusedTopics.has(topic)) { plan.refused.push(topic); continue; }
45
+ if (batches.length < MISTAKE_MIN_BATCHES) { plan.below.push({ topic, batches: batches.length }); continue; }
46
+ const first = group[0];
47
+ const sources = [...new Set(group.map((r) => r.source))].sort();
48
+ const evidence = group.map((r) => `- \`${r.source}:${r.line}\` (${r.batch}, ${r.severity}): ${cut(r.evidence || r.gap, 160)}`);
49
+ plan.candidates.push({
50
+ id: `${entryIdPrefix(context.project, "mistake", context.date)}${topic}`,
51
+ type: "mistake", title: cut(first.gap, MAX_TITLE_CHARS), project: context.project, date: context.date, topic,
52
+ appliesWhen: `a batch is audited on the ${first.axis} axis`,
53
+ rationale: `the audit flagged it in ${batches.length} batches: ${batches.join(", ")}`,
54
+ correction: cut(group.find((r) => r.fix.trim() !== "")?.fix ?? "see the expected fix of the rows under Evidence", 300),
55
+ detectionSignal: `an audit row on the ${first.axis} axis: ${cut(first.gap, 160)}`,
56
+ source: `audit:${sources.join(", ")}`, status: "candidate", supersedes: [], tags: [], stack: [],
57
+ body: bodyOf(group.length, batches.length, cut(first.gap, 400), evidence),
58
+ });
59
+ }
60
+ return plan;
61
+ }