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.
- package/.orkeon-version +1 -0
- package/LICENSE.md +21 -0
- package/NOTICE.md +17 -0
- package/README.fr.md +169 -0
- package/README.md +162 -2
- package/config/appsettings.anthropic.example.json +77 -0
- package/config/appsettings.example.json +71 -0
- package/config/appsettings.jev.example.json +128 -0
- package/config/appsettings.kev.example.json +130 -0
- package/config/appsettings.liquid.example.json +129 -0
- package/config/appsettings.ollama-whisper.example.json +92 -0
- package/config/appsettings.ollama.example.json +70 -0
- package/config/appsettings.whisper.example.json +31 -0
- package/mcp/whisper/README.md +293 -0
- package/mcp/whisper/pyproject.toml +32 -0
- package/mcp/whisper/uv.lock +1641 -0
- package/mcp/whisper/whisper_mcp.py +1053 -0
- package/orkeon-code +897 -0
- package/orkeon-code.mjs +71 -0
- package/orkeon-code.ps1 +837 -0
- package/package.json +57 -4
- package/scripts/install.ps1 +156 -0
- package/scripts/install.sh +148 -0
- package/scripts/session-start.ork.ts +90 -0
- package/scripts/session-start.sh +74 -0
- package/scripts/setup-fixture.sh +88 -0
- package/src/commands/.orkeon/orkeon-cli.d.ts +562 -0
- package/src/commands/_lib/args.ts +193 -0
- package/src/commands/_lib/dev/dev-batches.ts +368 -0
- package/src/commands/_lib/dev/dev-implement.ts +188 -0
- package/src/commands/_lib/dev/dev-source.ts +65 -0
- package/src/commands/_lib/dev/dev.ts +344 -0
- package/src/commands/_lib/dev-step.ts +142 -0
- package/src/commands/_lib/dispatch.ts +231 -0
- package/src/commands/_lib/effort.ts +15 -0
- package/src/commands/_lib/git/branch.ts +95 -0
- package/src/commands/_lib/git/commit.ts +94 -0
- package/src/commands/_lib/git/diff.ts +97 -0
- package/src/commands/_lib/git/review.ts +109 -0
- package/src/commands/_lib/memory/memory-admit.ts +150 -0
- package/src/commands/_lib/memory/memory.ts +51 -0
- package/src/commands/_lib/pr-context.ts +32 -0
- package/src/commands/_lib/project/analyze.ts +24 -0
- package/src/commands/_lib/session/export.ts +104 -0
- package/src/commands/_lib/session/resume.ts +160 -0
- package/src/commands/_lib/session/tasks.ts +184 -0
- package/src/commands/_lib/settings/advisor.ts +80 -0
- package/src/commands/_lib/settings/agents.ts +147 -0
- package/src/commands/_lib/settings/config.ts +141 -0
- package/src/commands/_lib/settings/hooks.ts +58 -0
- package/src/commands/_lib/settings/mode.ts +91 -0
- package/src/commands/_lib/settings/model.ts +146 -0
- package/src/commands/_lib/settings/permissions.ts +309 -0
- package/src/commands/_lib/settings/session-config.ts +49 -0
- package/src/commands/_lib/settings/skills.ts +51 -0
- package/src/commands/_lib/speech/say.ts +96 -0
- package/src/commands/_lib/speech/transcribe.ts +130 -0
- package/src/commands/_lib/speech/voice.ts +146 -0
- package/src/commands/_lib/status/cache.ts +31 -0
- package/src/commands/_lib/status/context.ts +57 -0
- package/src/commands/_lib/status/doctor.ts +186 -0
- package/src/commands/_lib/status/meta.ts +45 -0
- package/src/commands/_lib/status/status.ts +129 -0
- package/src/commands/_lib/status/usage-tools.ts +49 -0
- package/src/commands/_lib/status/usage.ts +139 -0
- package/src/commands/_lib/view.ts +29 -0
- package/src/commands/dev/dev-batches.cmd.ts +108 -0
- package/src/commands/dev/dev-learn.cmd.ts +29 -0
- package/src/commands/dev/dev-plan.cmd.ts +52 -0
- package/src/commands/dev/dev-spec.cmd.ts +55 -0
- package/src/commands/dev/dev-status.cmd.ts +16 -0
- package/src/commands/git/branch.cmd.ts +27 -0
- package/src/commands/git/commit.cmd.ts +48 -0
- package/src/commands/git/diff.cmd.ts +26 -0
- package/src/commands/git/review.cmd.ts +36 -0
- package/src/commands/memory/memory.cmd.ts +48 -0
- package/src/commands/project/analyze.cmd.ts +32 -0
- package/src/commands/project/debug-tool-call.cmd.ts +67 -0
- package/src/commands/project/files.cmd.ts +22 -0
- package/src/commands/project/init-verifiers.cmd.ts +14 -0
- package/src/commands/project/init.cmd.ts +14 -0
- package/src/commands/project/verify.cmd.ts +27 -0
- package/src/commands/session/assistant.cmd.ts +40 -0
- package/src/commands/session/btw.cmd.ts +18 -0
- package/src/commands/session/clear.cmd.ts +19 -0
- package/src/commands/session/compact.cmd.ts +16 -0
- package/src/commands/session/copy.cmd.ts +44 -0
- package/src/commands/session/exit.cmd.ts +9 -0
- package/src/commands/session/export.cmd.ts +28 -0
- package/src/commands/session/rename.cmd.ts +17 -0
- package/src/commands/session/resume.cmd.ts +19 -0
- package/src/commands/session/rewind.cmd.ts +26 -0
- package/src/commands/session/summary.cmd.ts +27 -0
- package/src/commands/session/tasks.cmd.ts +44 -0
- package/src/commands/settings/advisor.cmd.ts +38 -0
- package/src/commands/settings/agents.cmd.ts +19 -0
- package/src/commands/settings/config.cmd.ts +17 -0
- package/src/commands/settings/effort.cmd.ts +40 -0
- package/src/commands/settings/fast.cmd.ts +17 -0
- package/src/commands/settings/hooks.cmd.ts +17 -0
- package/src/commands/settings/mode.cmd.ts +20 -0
- package/src/commands/settings/model.cmd.ts +20 -0
- package/src/commands/settings/output-style.cmd.ts +48 -0
- package/src/commands/settings/permissions.cmd.ts +25 -0
- package/src/commands/settings/proactive.cmd.ts +15 -0
- package/src/commands/settings/skills.cmd.ts +17 -0
- package/src/commands/speech/say.cmd.ts +24 -0
- package/src/commands/speech/transcribe.cmd.ts +29 -0
- package/src/commands/speech/voice.cmd.ts +30 -0
- package/src/commands/status/context.cmd.ts +18 -0
- package/src/commands/status/doctor.cmd.ts +27 -0
- package/src/commands/status/release-notes.cmd.ts +9 -0
- package/src/commands/status/status.cmd.ts +25 -0
- package/src/commands/status/usage.cmd.ts +21 -0
- package/src/crews/.orkeon/orkeon.d.ts +3946 -0
- package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +183 -0
- package/src/crews/_probe-shared-memory/probe.ork.ts +98 -0
- package/src/crews/advisor/application/run-advisor.ts +40 -0
- package/src/crews/advisor/crew.ork.ts +43 -0
- package/src/crews/advisor/domain/advice.ts +135 -0
- package/src/crews/agent-run/application/run-agent-run.ts +42 -0
- package/src/crews/agent-run/crew.ork.ts +67 -0
- package/src/crews/analyze/application/run-analyze.ts +118 -0
- package/src/crews/analyze/crew.ork.ts +40 -0
- package/src/crews/analyze/domain/harvest.ts +301 -0
- package/src/crews/code-review/application/prompts.ts +133 -0
- package/src/crews/code-review/application/review.ts +71 -0
- package/src/crews/code-review/application/run-code-review.ts +123 -0
- package/src/crews/code-review/crew.ork.ts +51 -0
- package/src/crews/code-review/domain/lenses.ts +193 -0
- package/src/crews/code-review/domain/report.ts +59 -0
- package/src/crews/code-review/domain/scope.ts +112 -0
- package/src/crews/dev-batches/application/plan-close.ts +181 -0
- package/src/crews/dev-batches/application/run-dev-batches.ts +669 -0
- package/src/crews/dev-batches/application/run-wave.ts +450 -0
- package/src/crews/dev-batches/application/seed-harvest.ts +162 -0
- package/src/crews/dev-batches/crew.ork.ts +143 -0
- package/src/crews/dev-batches/domain/batch-waves.ts +70 -0
- package/src/crews/dev-batches/domain/batches-budget.ts +52 -0
- package/src/crews/dev-batches/domain/batches-log.ts +54 -0
- package/src/crews/dev-batches/domain/wave-order.ts +43 -0
- package/src/crews/dev-change/application/change-prompt.ts +104 -0
- package/src/crews/dev-change/application/evidence.ts +169 -0
- package/src/crews/dev-change/application/run-dev-change.ts +315 -0
- package/src/crews/dev-change/crew.ork.ts +112 -0
- package/src/crews/dev-change/domain/change-answer.ts +159 -0
- package/src/crews/dev-change/domain/change-render.ts +79 -0
- package/src/crews/dev-implement/application/close.ts +183 -0
- package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
- package/src/crews/dev-implement/application/locate-sheet.ts +80 -0
- package/src/crews/dev-implement/application/observe.ts +50 -0
- package/src/crews/dev-implement/application/report-writes.ts +41 -0
- package/src/crews/dev-implement/application/run-dev-implement.ts +811 -0
- package/src/crews/dev-implement/application/run-role.ts +27 -0
- package/src/crews/dev-implement/application/suite-job.ts +118 -0
- package/src/crews/dev-implement/application/touched.ts +74 -0
- package/src/crews/dev-implement/crew.ork.ts +68 -0
- package/src/crews/dev-implement/domain/contracts.ts +256 -0
- package/src/crews/dev-implement/domain/correction.ts +102 -0
- package/src/crews/dev-implement/domain/cycles.ts +35 -0
- package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
- package/src/crews/dev-implement/domain/roles.ts +53 -0
- package/src/crews/dev-implement/domain/sheet-edits.ts +75 -0
- package/src/crews/dev-implement/domain/sheet-ticks.ts +22 -0
- package/src/crews/dev-implement/domain/step-checks.ts +136 -0
- package/src/crews/dev-implement/domain/step-section.ts +127 -0
- package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
- package/src/crews/dev-learn/application/learn-prompt.ts +140 -0
- package/src/crews/dev-learn/application/run-dev-learn.ts +553 -0
- package/src/crews/dev-learn/crew.ork.ts +52 -0
- package/src/crews/dev-learn/domain/learn-answer.ts +235 -0
- package/src/crews/dev-learn/domain/owner-lines.ts +86 -0
- package/src/crews/dev-learn/domain/proposals-render.ts +96 -0
- package/src/crews/dev-plan/application/anchor-paths.ts +76 -0
- package/src/crews/dev-plan/application/inventory.ts +170 -0
- package/src/crews/dev-plan/application/plan-prompt.ts +159 -0
- package/src/crews/dev-plan/application/run-dev-plan.ts +455 -0
- package/src/crews/dev-plan/crew.ork.ts +109 -0
- package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
- package/src/crews/dev-plan/domain/plan-answer.ts +738 -0
- package/src/crews/dev-plan/domain/plan-render.ts +307 -0
- package/src/crews/dev-spec/application/run-dev-spec.ts +206 -0
- package/src/crews/dev-spec/application/spec-prompt.ts +98 -0
- package/src/crews/dev-spec/crew.ork.ts +108 -0
- package/src/crews/dev-spec/domain/spec-answer.ts +253 -0
- package/src/crews/dev-spec/domain/spec-render.ts +76 -0
- package/src/crews/dev-verify/application/audit.ts +259 -0
- package/src/crews/dev-verify/application/auditor-prompt.ts +323 -0
- package/src/crews/dev-verify/application/capture.ts +303 -0
- package/src/crews/dev-verify/application/run-dev-verify.ts +409 -0
- package/src/crews/dev-verify/application/run-gate.ts +202 -0
- package/src/crews/dev-verify/crew.ork.ts +103 -0
- package/src/crews/dev-verify/domain/audit-answer.ts +150 -0
- package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
- package/src/crews/dev-verify/domain/capture-sections.ts +137 -0
- package/src/crews/dev-verify/domain/commands.ts +103 -0
- package/src/crews/dev-verify/domain/gate.ts +126 -0
- package/src/crews/dev-verify/domain/mechanical-table.ts +163 -0
- package/src/crews/dev-verify/domain/runtime-cut.ts +13 -0
- package/src/crews/dev-verify/domain/sheet-facts.ts +4 -0
- package/src/crews/dev-verify/domain/text.ts +20 -0
- package/src/crews/dev-verify/domain/verdict.ts +127 -0
- package/src/crews/git-commit/application/draft.ts +154 -0
- package/src/crews/git-commit/application/run-git-commit.ts +116 -0
- package/src/crews/git-commit/crew.ork.ts +52 -0
- package/src/crews/git-commit/domain/commit.ts +220 -0
- package/src/crews/init-verifiers/application/authoring.ts +89 -0
- package/src/crews/init-verifiers/application/prompts.ts +103 -0
- package/src/crews/init-verifiers/application/run-init-verifiers.ts +25 -0
- package/src/crews/init-verifiers/crew.ork.ts +34 -0
- package/src/crews/init-verifiers/domain/commands-section.ts +36 -0
- package/src/crews/init-verifiers/domain/readiness.ts +23 -0
- package/src/crews/main-loop/application/auto-compact.ts +77 -0
- package/src/crews/main-loop/application/context-gather.ts +133 -0
- package/src/crews/main-loop/application/run-main-loop.ts +350 -0
- package/src/crews/main-loop/application/turn-prompt.ts +112 -0
- package/src/crews/main-loop/crew.ork.ts +119 -0
- package/src/crews/main-loop/domain/autocompact.ts +27 -0
- package/src/crews/main-loop/domain/prompt-assembly.ts +521 -0
- package/src/crews/main-loop/domain/turn-chains.ts +129 -0
- package/src/crews/project-init/application/detect.ts +122 -0
- package/src/crews/project-init/application/prompts.ts +101 -0
- package/src/crews/project-init/application/run-project-init.ts +31 -0
- package/src/crews/project-init/crew.ork.ts +35 -0
- package/src/crews/project-init/domain/conventions.ts +36 -0
- package/src/crews/project-init/domain/existing-files.ts +63 -0
- package/src/crews/project-init/domain/package-map.ts +73 -0
- package/src/crews/session-compact/crew.ork.ts +55 -0
- package/src/crews/shared-memory-admit/crew.ork.ts +48 -0
- package/src/crews/speech/application/run-speech.ts +25 -0
- package/src/crews/speech/crew.ork.ts +37 -0
- package/src/shared/application/agents/child-agent.ts +255 -0
- package/src/shared/application/agents/run-sub-agent.ts +96 -0
- package/src/shared/application/answer-language.ts +14 -0
- package/src/shared/application/attached-skills.ts +36 -0
- package/src/shared/application/compaction/compact-session.ts +237 -0
- package/src/shared/application/compaction/extract-memories.ts +38 -0
- package/src/shared/application/compaction/restore-context.ts +78 -0
- package/src/shared/application/config-store.ts +123 -0
- package/src/shared/application/dev/brief-inventory.ts +113 -0
- package/src/shared/application/dev/close-batch.ts +83 -0
- package/src/shared/application/dev/find-repo-pack.ts +77 -0
- package/src/shared/application/dev/learn-decision.ts +252 -0
- package/src/shared/application/dev/load-dev-context.ts +266 -0
- package/src/shared/application/dev/measure-access-cost.ts +68 -0
- package/src/shared/application/dev/plan-source.ts +112 -0
- package/src/shared/application/dev/preflight.ts +71 -0
- package/src/shared/application/dev/project-files.ts +17 -0
- package/src/shared/application/dev/question-round.ts +52 -0
- package/src/shared/application/dev/resolve-work-folder.ts +133 -0
- package/src/shared/application/dev/script-tool-slot.ts +27 -0
- package/src/shared/application/dev/settle-questions.ts +55 -0
- package/src/shared/application/dev/source-review.ts +63 -0
- package/src/shared/application/dev/source-step.ts +150 -0
- package/src/shared/application/dev/spend.ts +42 -0
- package/src/shared/application/dev/step-precedents.ts +89 -0
- package/src/shared/application/dev/tool-call-policy.ts +89 -0
- package/src/shared/application/dev/tool-callbacks.ts +215 -0
- package/src/shared/application/dev/tool-trace-recorder.ts +45 -0
- package/src/shared/application/dev/verdict-sources.ts +48 -0
- package/src/shared/application/dev/wrapped-tools.ts +145 -0
- package/src/shared/application/extra-tools.ts +70 -0
- package/src/shared/application/git/batch-worktree.ts +97 -0
- package/src/shared/application/git/commit-files.ts +186 -0
- package/src/shared/application/git/merge-batch.ts +63 -0
- package/src/shared/application/git/open-pull-request.ts +51 -0
- package/src/shared/application/instructions-file.ts +19 -0
- package/src/shared/application/json-file.ts +34 -0
- package/src/shared/application/llm-profile.ts +35 -0
- package/src/shared/application/permission-rules.ts +159 -0
- package/src/shared/application/ports/approvals.ts +20 -0
- package/src/shared/application/ports/clock.ts +5 -0
- package/src/shared/application/ports/code-index.ts +93 -0
- package/src/shared/application/ports/crew.ts +60 -0
- package/src/shared/application/ports/files.ts +21 -0
- package/src/shared/application/ports/human.ts +13 -0
- package/src/shared/application/ports/llm.ts +54 -0
- package/src/shared/application/ports/memory.ts +30 -0
- package/src/shared/application/ports/progress.ts +23 -0
- package/src/shared/application/ports/runtime.ts +15 -0
- package/src/shared/application/ports/session.ts +74 -0
- package/src/shared/application/ports/shared-memory.ts +26 -0
- package/src/shared/application/ports/shell.ts +40 -0
- package/src/shared/application/ports/telemetry.ts +45 -0
- package/src/shared/application/ports/tools.ts +46 -0
- package/src/shared/application/ports/usage.ts +45 -0
- package/src/shared/application/ports.ts +27 -0
- package/src/shared/application/project-manifests.ts +106 -0
- package/src/shared/application/session-io.ts +84 -0
- package/src/shared/application/session-state.ts +36 -0
- package/src/shared/application/shared-memory/admit-entries.ts +177 -0
- package/src/shared/application/shared-memory/harvest-after-gaps.ts +72 -0
- package/src/shared/application/shared-memory/harvest-mistakes.ts +44 -0
- package/src/shared/application/shared-memory/import-agent-memory.ts +117 -0
- package/src/shared/application/shared-memory/memory-files.ts +110 -0
- package/src/shared/application/shared-memory/memory-settings.ts +93 -0
- package/src/shared/application/shared-memory/push-candidate.ts +146 -0
- package/src/shared/application/shared-memory/recall-precedents.ts +69 -0
- package/src/shared/application/state-snapshot.ts +38 -0
- package/src/shared/application/workflow/workflow-state.ts +135 -0
- package/src/shared/domain/agent-policy/behavior-flags.ts +168 -0
- package/src/shared/domain/agent-policy/extra-tools.ts +69 -0
- package/src/shared/domain/agent-policy/memory-categories.ts +6 -0
- package/src/shared/domain/agent-policy/mode-policy.ts +51 -0
- package/src/shared/domain/agent-policy/output-styles.ts +11 -0
- package/src/shared/domain/agent-policy/permission.ts +623 -0
- package/src/shared/domain/agent-policy/rule-sets.ts +412 -0
- package/src/shared/domain/agent-policy/tool-access.ts +77 -0
- package/src/shared/domain/agent-registry.ts +142 -0
- package/src/shared/domain/agents/built-in-charters.ts +43 -0
- package/src/shared/domain/agents/chain.ts +30 -0
- package/src/shared/domain/agents/charter.ts +61 -0
- package/src/shared/domain/agents/exclusive.ts +24 -0
- package/src/shared/domain/agents/instances.ts +249 -0
- package/src/shared/domain/code-intel-contract.ts +356 -0
- package/src/shared/domain/code-intel-routing.ts +113 -0
- package/src/shared/domain/compact-outcome.ts +44 -0
- package/src/shared/domain/compaction-thresholds.ts +161 -0
- package/src/shared/domain/compaction.ts +379 -0
- package/src/shared/domain/config-schema.ts +421 -0
- package/src/shared/domain/dev/access-cost.ts +226 -0
- package/src/shared/domain/dev/artefacts.ts +50 -0
- package/src/shared/domain/dev/batches-concurrency.ts +36 -0
- package/src/shared/domain/dev/batches-state.ts +49 -0
- package/src/shared/domain/dev/build-commands.ts +44 -0
- package/src/shared/domain/dev/call-guard.ts +341 -0
- package/src/shared/domain/dev/carried-text.ts +49 -0
- package/src/shared/domain/dev/design-rules.ts +100 -0
- package/src/shared/domain/dev/learn-proposals.ts +175 -0
- package/src/shared/domain/dev/learn-state.ts +93 -0
- package/src/shared/domain/dev/path-args.ts +42 -0
- package/src/shared/domain/dev/path-rebase.ts +93 -0
- package/src/shared/domain/dev/plan-checks.ts +190 -0
- package/src/shared/domain/dev/plan-format.ts +180 -0
- package/src/shared/domain/dev/project-files.ts +43 -0
- package/src/shared/domain/dev/questions.ts +249 -0
- package/src/shared/domain/dev/reading-rule.ts +41 -0
- package/src/shared/domain/dev/repo-pack.ts +237 -0
- package/src/shared/domain/dev/review-answer.ts +150 -0
- package/src/shared/domain/dev/review-prompt.ts +221 -0
- package/src/shared/domain/dev/reviewer-charter.ts +31 -0
- package/src/shared/domain/dev/sheet-facts.ts +83 -0
- package/src/shared/domain/dev/spec-format.ts +183 -0
- package/src/shared/domain/dev/step-budget.ts +72 -0
- package/src/shared/domain/dev/step-rules.ts +110 -0
- package/src/shared/domain/dev/test-commands.ts +90 -0
- package/src/shared/domain/dev/test-output.ts +33 -0
- package/src/shared/domain/dev/test-paths.ts +40 -0
- package/src/shared/domain/dev/tool-guards.ts +64 -0
- package/src/shared/domain/dev/trait-pattern.ts +83 -0
- package/src/shared/domain/dev/verdict-format.ts +169 -0
- package/src/shared/domain/dev/whitespace.ts +34 -0
- package/src/shared/domain/dev/work-folder.ts +67 -0
- package/src/shared/domain/dev/yaml-subset.ts +403 -0
- package/src/shared/domain/git/close.ts +273 -0
- package/src/shared/domain/git/pull-request.ts +96 -0
- package/src/shared/domain/git/worktree.ts +46 -0
- package/src/shared/domain/index-languages.ts +16 -0
- package/src/shared/domain/instructions-file.ts +18 -0
- package/src/shared/domain/iso-day.ts +4 -0
- package/src/shared/domain/llm-failure.ts +106 -0
- package/src/shared/domain/llm-profile.ts +25 -0
- package/src/shared/domain/marked-message.ts +33 -0
- package/src/shared/domain/model-catalog.ts +86 -0
- package/src/shared/domain/permission-modes.ts +103 -0
- package/src/shared/domain/prelude.ts +92 -0
- package/src/shared/domain/project-manifests.ts +83 -0
- package/src/shared/domain/search-routing.ts +85 -0
- package/src/shared/domain/secret-patterns.ts +45 -0
- package/src/shared/domain/session-keys.ts +85 -0
- package/src/shared/domain/session-start.ts +60 -0
- package/src/shared/domain/session-summary.ts +13 -0
- package/src/shared/domain/severity.ts +72 -0
- package/src/shared/domain/sha1.ts +61 -0
- package/src/shared/domain/shared-memory/agent-memory-import.ts +143 -0
- package/src/shared/domain/shared-memory/candidates.ts +41 -0
- package/src/shared/domain/shared-memory/entry.ts +145 -0
- package/src/shared/domain/shared-memory/front-matter.ts +183 -0
- package/src/shared/domain/shared-memory/gate.ts +44 -0
- package/src/shared/domain/shared-memory/harvest.ts +61 -0
- package/src/shared/domain/shared-memory/layout.ts +187 -0
- package/src/shared/domain/shared-memory/precedents-block.ts +93 -0
- package/src/shared/domain/shared-memory/refused.ts +84 -0
- package/src/shared/domain/shared-memory/verdict-rows.ts +134 -0
- package/src/shared/domain/snip-turns.ts +45 -0
- package/src/shared/domain/speech.ts +20 -0
- package/src/shared/domain/strip.ts +88 -0
- package/src/shared/domain/tool-trace.ts +122 -0
- package/src/shared/domain/types.ts +67 -0
- package/src/shared/domain/verifiers.ts +37 -0
- package/src/shared/domain/vfs.ts +9 -0
- package/src/shared/domain/workflow/state-file.ts +140 -0
- package/src/shared/infrastructure/globals.ts +52 -0
- package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
- package/src/shared/infrastructure/orkeon/child-agents.ts +127 -0
- package/src/shared/infrastructure/orkeon/code-index.ts +120 -0
- package/src/shared/infrastructure/orkeon/crew-host.ts +27 -0
- package/src/shared/infrastructure/orkeon/crew-memory.ts +12 -0
- package/src/shared/infrastructure/orkeon/dev-deps.ts +172 -0
- package/src/shared/infrastructure/orkeon/files.ts +40 -0
- package/src/shared/infrastructure/orkeon/github-pull-requests.ts +29 -0
- package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
- package/src/shared/infrastructure/orkeon/human-input.ts +59 -0
- package/src/shared/infrastructure/orkeon/llm-profile.ts +38 -0
- package/src/shared/infrastructure/orkeon/llm.ts +109 -0
- package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
- package/src/shared/infrastructure/orkeon/memory-tools.ts +131 -0
- package/src/shared/infrastructure/orkeon/permission-rules.ts +42 -0
- package/src/shared/infrastructure/orkeon/progress.ts +24 -0
- package/src/shared/infrastructure/orkeon/run-state.ts +17 -0
- package/src/shared/infrastructure/orkeon/runtime-info.ts +30 -0
- package/src/shared/infrastructure/orkeon/runtime-tools.ts +60 -0
- package/src/shared/infrastructure/orkeon/script-tools.ts +134 -0
- package/src/shared/infrastructure/orkeon/session-store.ts +138 -0
- package/src/shared/infrastructure/orkeon/session-switch.ts +23 -0
- package/src/shared/infrastructure/orkeon/shared-memory.ts +61 -0
- package/src/shared/infrastructure/orkeon/shell-jobs.ts +75 -0
- package/src/shared/infrastructure/orkeon/shell.ts +31 -0
- package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
- package/src/shared/infrastructure/orkeon/tool-catalogue.ts +75 -0
- package/src/shared/infrastructure/orkeon/tool-results.ts +120 -0
- package/src/shared/infrastructure/orkeon/usage.ts +74 -0
- package/src/shared/infrastructure/orkeon/wiring.ts +118 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// The checks a plan folder must pass before any batch runs: the design ids each classified
|
|
2
|
+
// (shared with the dev-verify gate), and the self-check /dev-plan runs over the plan and
|
|
3
|
+
// sheets it has just rendered - parse-back with no problem, the same batches everywhere,
|
|
4
|
+
// every source id traced and tested, the step and anchor shapes. Pure, no IO; it reports
|
|
5
|
+
// problems and never repairs a text.
|
|
6
|
+
import { DESIGN_RULE_IDS } from "./design-rules.ts";
|
|
7
|
+
import { parseBatchSheet, parseGlobalPlan, unfencedLines } from "./plan-format.ts";
|
|
8
|
+
import type { Line } from "./plan-format.ts";
|
|
9
|
+
import { sheetFacts } from "./sheet-facts.ts";
|
|
10
|
+
import { SHEET_ID_SOURCE } from "./trait-pattern.ts";
|
|
11
|
+
|
|
12
|
+
/** The texts of a plan folder, as the gate reads them. */
|
|
13
|
+
export interface PlanFolderTexts {
|
|
14
|
+
sheets: readonly string[]; // every <planDir>/*-PLAN-F*.md
|
|
15
|
+
plans: readonly string[]; // every <planDir>/*-PLAN.md
|
|
16
|
+
all: readonly string[]; // every <planDir>/*.md
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function linesHolding(texts: readonly string[], label: string): string[] {
|
|
20
|
+
return texts.flatMap((t) => t.split("\n")).filter((l) => l.includes(label));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Design ids on no `Applied rules` line of a sheet and no `Non-applicable rules` line of a plan. */
|
|
24
|
+
export function missingDesignIds(plan: PlanFolderTexts): string[] {
|
|
25
|
+
const classified = [...linesHolding(plan.sheets, "Applied rules"), ...linesHolding(plan.plans, "Non-applicable rules")];
|
|
26
|
+
return DESIGN_RULE_IDS.filter((id) => {
|
|
27
|
+
const re = new RegExp(`(^|[^A-Z])${id}([^0-9]|$)`);
|
|
28
|
+
return !classified.some((l) => re.test(l));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SelfCheckInput {
|
|
33
|
+
plan: { name: string; text: string };
|
|
34
|
+
sheets: ReadonlyArray<{ name: string; text: string }>; // F1..Fn in order
|
|
35
|
+
sourceIds: readonly string[]; // every UC/BR/CH id of the source, sorted
|
|
36
|
+
}
|
|
37
|
+
export interface SelfCheckReport { ok: boolean; problems: string[] }
|
|
38
|
+
|
|
39
|
+
const BUILD_STEP = "Build and tests";
|
|
40
|
+
/** The one parse problem a reviewed plan may carry: a batch the review marked blocked. */
|
|
41
|
+
const BLOCKED_BATCH = /^unknown batch line '### Batch F\d+ — .+ — blocked'$/;
|
|
42
|
+
const SEPARATOR_ROW = /^\|[-: |]+\|?$/;
|
|
43
|
+
|
|
44
|
+
const idsIn = (text: string): string[] => text.match(new RegExp(SHEET_ID_SOURCE, "g")) ?? [];
|
|
45
|
+
const listed = (ids: readonly string[]): string => (ids.length === 0 ? "none" : ids.join(", "));
|
|
46
|
+
|
|
47
|
+
function cellsOf(row: string): string[] {
|
|
48
|
+
return row.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The lines of the `## ` section whose heading starts with `heading`, up to the next `## `; null when absent. */
|
|
52
|
+
function section(lines: readonly Line[], heading: string): Line[] | null {
|
|
53
|
+
const start = lines.findIndex((l) => l.text.startsWith(heading));
|
|
54
|
+
if (start < 0) return null;
|
|
55
|
+
const out: Line[] = [];
|
|
56
|
+
for (const l of lines.slice(start + 1)) {
|
|
57
|
+
if (l.text.startsWith("## ")) break;
|
|
58
|
+
out.push(l);
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The data rows of the first table of a section: the rows after its header and separator. */
|
|
64
|
+
function dataRows(lines: readonly Line[]): string[][] {
|
|
65
|
+
const rows = lines.map((l) => l.text.trim()).filter((t) => t.startsWith("|"));
|
|
66
|
+
return rows.slice(2).filter((r) => !SEPARATOR_ROW.test(r)).map(cellsOf);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The ids of the step tables' `Ids` cells, within `## TDD sequence`. */
|
|
70
|
+
function stepTableIds(tdd: readonly Line[]): string[] {
|
|
71
|
+
const out: string[] = [];
|
|
72
|
+
let column = -1;
|
|
73
|
+
for (const { text } of tdd) {
|
|
74
|
+
const t = text.trim();
|
|
75
|
+
if (!t.startsWith("|")) { column = -1; continue; }
|
|
76
|
+
if (SEPARATOR_ROW.test(t)) continue;
|
|
77
|
+
const cells = cellsOf(t);
|
|
78
|
+
if (column < 0) { column = cells.indexOf("Ids"); if (column < 0) column = cells.length + 1; continue; }
|
|
79
|
+
out.push(...idsIn(cells[column] ?? ""));
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The ids after `**Ids**:` up to `**Depends on**` (or the end of that line). */
|
|
85
|
+
function intentIds(lines: readonly Line[]): string[] {
|
|
86
|
+
const line = lines.find((l) => l.text.includes("**Ids**:"));
|
|
87
|
+
if (line === undefined) return [];
|
|
88
|
+
const after = line.text.slice(line.text.indexOf("**Ids**:"));
|
|
89
|
+
const cut = after.indexOf("**Depends on**");
|
|
90
|
+
return idsIn(cut < 0 ? after : after.slice(0, cut));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface ReadSheet { id: string; name: string; text: string; lines: Line[] }
|
|
94
|
+
|
|
95
|
+
function stepProblems(s: ReadSheet): string[] {
|
|
96
|
+
const steps = parseBatchSheet(s.text).steps;
|
|
97
|
+
if (steps.length === 0) return [`${s.id}: step 1 is missing: the sheet has no step`];
|
|
98
|
+
const out: string[] = [];
|
|
99
|
+
steps.forEach((step, i) => {
|
|
100
|
+
const last = i === steps.length - 1;
|
|
101
|
+
if (step.number !== i + 1) out.push(`${s.id}: step ${step.number} is numbered out of order (expected ${i + 1})`);
|
|
102
|
+
if (!last && step.tdd === null) out.push(`${s.id}: step ${step.number} has no TDD: line`);
|
|
103
|
+
if (last && step.title !== BUILD_STEP) out.push(`${s.id}: step ${step.number} is the last step and is not ${BUILD_STEP}`);
|
|
104
|
+
if (last && step.tdd !== null) out.push(`${s.id}: step ${step.number} is ${BUILD_STEP} and holds a TDD: line`);
|
|
105
|
+
});
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function anchorProblem(s: ReadSheet): string | null {
|
|
110
|
+
const steps = parseBatchSheet(s.text).steps.length;
|
|
111
|
+
const rows = dataRows(section(s.lines, "## Anchors") ?? []);
|
|
112
|
+
const shaped = rows.length === steps && rows.every((cells, i) => cells[0].startsWith(`${i + 1} — `));
|
|
113
|
+
return shaped ? null : `${s.id}: ## Anchors has ${rows.length} rows for ${steps} steps`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function assumptionsEmpty(s: ReadSheet): boolean {
|
|
117
|
+
const body = section(s.lines, "## Assumptions");
|
|
118
|
+
if (body === null) return false;
|
|
119
|
+
const filled = body.map((l) => l.text.trim()).filter((t) => t !== "");
|
|
120
|
+
return filled.length === 2 && filled[0].startsWith("|") && SEPARATOR_ROW.test(filled[1]);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function planSelfCheck(input: SelfCheckInput): SelfCheckReport {
|
|
124
|
+
const problems: string[] = [];
|
|
125
|
+
const global = parseGlobalPlan(input.plan.text);
|
|
126
|
+
const sheets: ReadSheet[] = input.sheets.map((s, i) => ({
|
|
127
|
+
id: parseBatchSheet(s.text).batch ?? `F${i + 1}`, name: s.name, text: s.text, lines: unfencedLines(s.text),
|
|
128
|
+
}));
|
|
129
|
+
const parsed = input.sheets.map((s) => parseBatchSheet(s.text));
|
|
130
|
+
const source = new Set(input.sourceIds);
|
|
131
|
+
|
|
132
|
+
// 1, 14: the plan parses back; a batch line the review marked blocked is tolerated.
|
|
133
|
+
for (const p of global.problems) {
|
|
134
|
+
if (!BLOCKED_BATCH.test(p.message)) problems.push(`${input.plan.name}:${p.line}: ${p.message}`);
|
|
135
|
+
}
|
|
136
|
+
// 2: every sheet parses back.
|
|
137
|
+
input.sheets.forEach((s, i) => {
|
|
138
|
+
for (const p of parsed[i].problems) problems.push(`${s.name}:${p.line}: ${p.message}`);
|
|
139
|
+
});
|
|
140
|
+
// 3: every design id applied or not applicable.
|
|
141
|
+
const texts = input.sheets.map((s) => s.text);
|
|
142
|
+
const missing = missingDesignIds({ sheets: texts, plans: [input.plan.text], all: [input.plan.text, ...texts] });
|
|
143
|
+
if (missing.length > 0) problems.push(`design ids neither applied nor non-applicable: ${missing.join(", ")}`);
|
|
144
|
+
// 4: the same batches, in order.
|
|
145
|
+
const summaryIds = global.summary.map((r) => r.id);
|
|
146
|
+
const lineIds = global.batches.map((b) => b.id);
|
|
147
|
+
const sheetIds = sheets.map((s) => s.id);
|
|
148
|
+
if (summaryIds.join() !== lineIds.join() || lineIds.join() !== sheetIds.join()) {
|
|
149
|
+
problems.push(`batches differ: summary ${listed(summaryIds)}, plan lines ${listed(lineIds)}, sheets ${listed(sheetIds)}`);
|
|
150
|
+
}
|
|
151
|
+
// 5: Depends on agrees between the summary and the sheet.
|
|
152
|
+
sheets.forEach((s, i) => {
|
|
153
|
+
const row = global.summary.find((r) => r.id === s.id);
|
|
154
|
+
if (row === undefined) return;
|
|
155
|
+
const a = listed(row.dependsOn);
|
|
156
|
+
const b = listed(parsed[i].dependsOn);
|
|
157
|
+
if (a !== b) problems.push(`${s.id}: Depends on differs between the summary (${a}) and the sheet (${b})`);
|
|
158
|
+
});
|
|
159
|
+
// 6: every source id has a traceability row.
|
|
160
|
+
const traceRows = dataRows(section(unfencedLines(input.plan.text), "## 2. Traceability") ?? []);
|
|
161
|
+
for (const id of input.sourceIds) {
|
|
162
|
+
const re = new RegExp(`^${id}(?![0-9])`);
|
|
163
|
+
if (!traceRows.some((cells) => re.test(cells[0]))) problems.push(`${id}: no row of ## 2. Traceability`);
|
|
164
|
+
}
|
|
165
|
+
// 7: every source id is named by some sheet's TDD sequence.
|
|
166
|
+
const facts = sheets.map((s) => sheetFacts(s.text));
|
|
167
|
+
const tested = new Set(facts.flatMap((f) => f.ids));
|
|
168
|
+
for (const id of input.sourceIds) {
|
|
169
|
+
if (!tested.has(id)) problems.push(`${id}: no test of any sheet's ## TDD sequence names it`);
|
|
170
|
+
}
|
|
171
|
+
sheets.forEach((s, i) => {
|
|
172
|
+
// 8: a sheet tests ids of the source only.
|
|
173
|
+
for (const id of facts[i].ids) if (!source.has(id)) problems.push(`${s.id}: ${id} is not an id of the source`);
|
|
174
|
+
// 9: behaviour steps 1..s, then the build step.
|
|
175
|
+
problems.push(...stepProblems(s));
|
|
176
|
+
// 10: one anchor row per step.
|
|
177
|
+
const anchors = anchorProblem(s);
|
|
178
|
+
if (anchors !== null) problems.push(anchors);
|
|
179
|
+
// 11: an Applied rules row.
|
|
180
|
+
if (facts[i].appliedRulesRow === null) problems.push(`${s.id}: no Applied rules row`);
|
|
181
|
+
// 12: assumptions left empty.
|
|
182
|
+
if (!assumptionsEmpty(s)) problems.push(`${s.id}: ## Assumptions is not empty`);
|
|
183
|
+
// 13: the TDD sequence names only the batch's ids.
|
|
184
|
+
const own = new Set([...stepTableIds(section(s.lines, "## TDD sequence") ?? []), ...intentIds(s.lines)]);
|
|
185
|
+
for (const id of facts[i].ids) {
|
|
186
|
+
if (!own.has(id)) problems.push(`${s.id}: ${id} appears in ## TDD sequence outside the batch's ids`);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
return { ok: problems.length === 0, problems };
|
|
190
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Dev workflow plans: the global plan `<CODE>-PLAN.md` and its batch sheets
|
|
2
|
+
// `<CODE>-PLAN-F<n>.md`, read line by line. Pure, no IO, never throws: a line that
|
|
3
|
+
// looks like a format line but does not match becomes a FormatProblem.
|
|
4
|
+
|
|
5
|
+
export interface FormatProblem { line: number; message: string }
|
|
6
|
+
export type BatchState = { kind: "open" } | { kind: "done"; date: string } | { kind: "other"; text: string };
|
|
7
|
+
export interface PlanStepBox { number: number; text: string; done: boolean; line: number }
|
|
8
|
+
export interface PlanBatch { id: string; name: string; state: BatchState; steps: PlanStepBox[]; line: number }
|
|
9
|
+
export interface SummaryRow { id: string; intent: string; ids: string; dependsOn: string[]; reason: string }
|
|
10
|
+
export interface GlobalPlan {
|
|
11
|
+
prefix?: string; feature?: string; summary: SummaryRow[]; batches: PlanBatch[]; problems: FormatProblem[];
|
|
12
|
+
}
|
|
13
|
+
export interface TddTicks { red: boolean; green: boolean; cost: boolean; line: number }
|
|
14
|
+
export interface SheetStep { number: number; title: string; tdd: TddTicks | null; doneLine?: string; line: number }
|
|
15
|
+
export interface SheetAssumption { id: string; assumption: string; by: string }
|
|
16
|
+
export interface BatchSheet {
|
|
17
|
+
prefix?: string; batch?: string; name?: string; doneDate?: string;
|
|
18
|
+
dependsOn: string[]; steps: SheetStep[]; problems: FormatProblem[];
|
|
19
|
+
/** The rows of `## Assumptions`, present when it holds one. */
|
|
20
|
+
assumptions?: SheetAssumption[];
|
|
21
|
+
}
|
|
22
|
+
export interface SheetProgress { behaviourSteps: number; red: number; green: number; cost: number; complete: number }
|
|
23
|
+
|
|
24
|
+
const PLAN_TITLE = /^# (\S+)-PLAN — (.+)$/;
|
|
25
|
+
const SUMMARY_HEADING = /^## 0\. Summary/;
|
|
26
|
+
const BATCH_LINE = /^### Batch (F\d+) — (.+) — (open|done \((\d{4}-\d{2}-\d{2})\))$/;
|
|
27
|
+
const BATCH_PREFIX = /^### Batch (F\d+) — (.*)$/;
|
|
28
|
+
const STEP_BOX = /^- \[( |x|X)\] (\d+)\. (.*)$/;
|
|
29
|
+
const SHEET_TITLE = /^# (\S+)-PLAN-(F\d+) — (.+?)( — done \((\d{4}-\d{2}-\d{2})\))?$/;
|
|
30
|
+
const DEPENDS_ON = /\*\*Depends on\*\*: (.+)$/;
|
|
31
|
+
const STEP_HEADING = /^### Step (\d+) — (.+)$/;
|
|
32
|
+
const TDD_LINE = /^TDD: RED \[( |x|X)\] GREEN \[( |x|X)\] COST \[( |x|X)\]$/;
|
|
33
|
+
const DONE_LINE = /^Done \((\d{4}-\d{2}-\d{2})\) — /;
|
|
34
|
+
// A row of `## Assumptions`: the table's `| H<n> | <text> | <by> |`, or the list line written before it.
|
|
35
|
+
const ASSUMPTION_ROW = /^\|\s*(H\d+)\s*\|(.*)\|(.*)\|\s*$/;
|
|
36
|
+
const ASSUMPTION_BULLET = /^- (H\d+) — (.*) — to be validated by (.+)$/;
|
|
37
|
+
|
|
38
|
+
export interface Line { text: string; line: number }
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The lines outside backtick fences, trimmed on the right, numbered from 1. A fence
|
|
42
|
+
* opens on a run of three backticks or more and closes only on a line holding nothing
|
|
43
|
+
* but a run at least as long, so a longer fence can quote a shorter one.
|
|
44
|
+
*/
|
|
45
|
+
export function unfencedLines(text: string): Line[] {
|
|
46
|
+
const out: Line[] = [];
|
|
47
|
+
let fence = 0; // length of the open fence, 0 outside one
|
|
48
|
+
text.split(/\r?\n/).forEach((raw, i) => {
|
|
49
|
+
const t = raw.trimEnd();
|
|
50
|
+
const run = /^`{3,}/.exec(t.trimStart())?.[0].length ?? 0;
|
|
51
|
+
if (fence === 0 && run > 0) { fence = run; return; }
|
|
52
|
+
if (fence > 0) {
|
|
53
|
+
if (run >= fence && t.trim().length === run) fence = 0;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
out.push({ text: t, line: i + 1 });
|
|
57
|
+
});
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function tableCells(line: string): string[] | null {
|
|
62
|
+
const t = line.trim();
|
|
63
|
+
if (!t.startsWith("|")) return null;
|
|
64
|
+
return t.replace(/^\|+/, "").replace(/\|+$/, "").split("|").map((c) => c.trim());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function dependsList(value: string): string[] {
|
|
68
|
+
const v = value.trim();
|
|
69
|
+
if (v === "" || v === "—" || v === "-" || /^\[?none\]?\.?$/i.test(v)) return [];
|
|
70
|
+
return v.replace(/\.$/, "").replace(/^\[/, "").replace(/\]$/, "").split(",").map((s) => s.trim()).filter((s) => s !== "");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const tick = (c: string): boolean => c === "x" || c === "X";
|
|
74
|
+
|
|
75
|
+
export function parseGlobalPlan(text: string): GlobalPlan {
|
|
76
|
+
const plan: GlobalPlan = { summary: [], batches: [], problems: [] };
|
|
77
|
+
let inSummary = false;
|
|
78
|
+
let batch: PlanBatch | null = null;
|
|
79
|
+
for (const { text: t, line } of unfencedLines(text)) {
|
|
80
|
+
if (t.startsWith("#")) {
|
|
81
|
+
batch = null;
|
|
82
|
+
if (t.startsWith("## ")) inSummary = SUMMARY_HEADING.test(t);
|
|
83
|
+
const title = PLAN_TITLE.exec(t);
|
|
84
|
+
if (title && plan.prefix === undefined) { plan.prefix = title[1]; plan.feature = title[2]; continue; }
|
|
85
|
+
if (t.startsWith("### Batch")) {
|
|
86
|
+
const m = BATCH_LINE.exec(t);
|
|
87
|
+
if (m) {
|
|
88
|
+
const state: BatchState = m[4] ? { kind: "done", date: m[4] } : { kind: "open" };
|
|
89
|
+
batch = { id: m[1], name: m[2], state, steps: [], line };
|
|
90
|
+
} else {
|
|
91
|
+
plan.problems.push({ line, message: `unknown batch line '${t}'` });
|
|
92
|
+
const p = BATCH_PREFIX.exec(t);
|
|
93
|
+
if (p) {
|
|
94
|
+
const cut = p[2].lastIndexOf(" — ");
|
|
95
|
+
const name = cut >= 0 ? p[2].slice(0, cut) : p[2];
|
|
96
|
+
const stateText = cut >= 0 ? p[2].slice(cut + 3) : "";
|
|
97
|
+
batch = { id: p[1], name, state: { kind: "other", text: stateText }, steps: [], line };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (batch) plan.batches.push(batch);
|
|
101
|
+
}
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (batch) {
|
|
105
|
+
const box = STEP_BOX.exec(t);
|
|
106
|
+
if (box) { batch.steps.push({ number: Number(box[2]), text: box[3], done: tick(box[1]), line }); continue; }
|
|
107
|
+
}
|
|
108
|
+
if (inSummary) {
|
|
109
|
+
const cells = tableCells(t);
|
|
110
|
+
if (cells && /^F\d+$/.test(cells[0])) {
|
|
111
|
+
if (cells.length < 5) {
|
|
112
|
+
plan.problems.push({ line, message: `malformed summary row '${t}'` });
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
plan.summary.push({
|
|
116
|
+
id: cells[0], intent: cells[1], ids: cells[2], dependsOn: dependsList(cells[3]),
|
|
117
|
+
reason: cells.slice(4).join(" | "),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return plan;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function parseBatchSheet(text: string): BatchSheet {
|
|
126
|
+
const sheet: BatchSheet = { dependsOn: [], steps: [], problems: [] };
|
|
127
|
+
let inIntent = false;
|
|
128
|
+
let inAssumptions = false;
|
|
129
|
+
let step: SheetStep | null = null;
|
|
130
|
+
for (const { text: t, line } of unfencedLines(text)) {
|
|
131
|
+
if (t.startsWith("#")) {
|
|
132
|
+
step = null;
|
|
133
|
+
if (t.startsWith("## ")) { inIntent = t === "## Intent"; inAssumptions = t === "## Assumptions"; }
|
|
134
|
+
const title = SHEET_TITLE.exec(t);
|
|
135
|
+
if (title && sheet.prefix === undefined) {
|
|
136
|
+
sheet.prefix = title[1];
|
|
137
|
+
sheet.batch = title[2];
|
|
138
|
+
sheet.name = title[3];
|
|
139
|
+
if (title[5]) sheet.doneDate = title[5];
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const s = STEP_HEADING.exec(t);
|
|
143
|
+
if (s) { step = { number: Number(s[1]), title: s[2], tdd: null, line }; sheet.steps.push(step); }
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (inAssumptions) {
|
|
147
|
+
const a = ASSUMPTION_ROW.exec(t) ?? ASSUMPTION_BULLET.exec(t);
|
|
148
|
+
if (a) (sheet.assumptions ??= []).push({ id: a[1], assumption: a[2].trim(), by: a[3].trim() });
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (inIntent) {
|
|
152
|
+
const d = DEPENDS_ON.exec(t);
|
|
153
|
+
if (d) { sheet.dependsOn = dependsList(d[1]); continue; }
|
|
154
|
+
}
|
|
155
|
+
if (t.startsWith("TDD:")) {
|
|
156
|
+
const m = TDD_LINE.exec(t);
|
|
157
|
+
if (!m) { sheet.problems.push({ line, message: `malformed TDD line '${t}'` }); continue; }
|
|
158
|
+
if (!step) { sheet.problems.push({ line, message: `TDD line outside a step '${t}'` }); continue; }
|
|
159
|
+
if (step.tdd !== null) { sheet.problems.push({ line, message: `step ${step.number} has two TDD: lines` }); continue; }
|
|
160
|
+
step.tdd = { red: tick(m[1]), green: tick(m[2]), cost: tick(m[3]), line };
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (step && step.tdd === null && step.doneLine === undefined && DONE_LINE.test(t)) step.doneLine = t;
|
|
164
|
+
}
|
|
165
|
+
return sheet;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Behaviour steps = steps with a TDD line (none under "Build and tests", plan-template.md:131). */
|
|
169
|
+
export function sheetProgress(sheet: BatchSheet): SheetProgress {
|
|
170
|
+
const p: SheetProgress = { behaviourSteps: 0, red: 0, green: 0, cost: 0, complete: 0 };
|
|
171
|
+
for (const s of sheet.steps) {
|
|
172
|
+
if (!s.tdd) continue;
|
|
173
|
+
p.behaviourSteps++;
|
|
174
|
+
if (s.tdd.red) p.red++;
|
|
175
|
+
if (s.tdd.green) p.green++;
|
|
176
|
+
if (s.tdd.cost) p.cost++;
|
|
177
|
+
if (s.tdd.red && s.tdd.green && s.tdd.cost) p.complete++;
|
|
178
|
+
}
|
|
179
|
+
return p;
|
|
180
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The project's files as a brief lists them, so that a reader (the auditor, the next batch's reviewer) looks for
|
|
2
|
+
// what exists instead of guessing a module's name and reading it. The list is git's (tracked and untracked files
|
|
3
|
+
// alike, the ignored ones aside), the work folder and `.orkeon/` left out, bounded; its closing line says whether it
|
|
4
|
+
// is whole (a name absent from it does not exist) or cut (glob with a pattern decides past the cut). Pure.
|
|
5
|
+
|
|
6
|
+
/** The most files a brief lists; past it the count left out is said, and glob with a pattern finds the rest. */
|
|
7
|
+
export const MAX_LISTED_FILES = 150;
|
|
8
|
+
|
|
9
|
+
export const PROJECT_FILES_HEADING = "Project files (tracked and untracked, the work folder and .orkeon/ left out):";
|
|
10
|
+
|
|
11
|
+
/** The closing line of a whole list. */
|
|
12
|
+
export const PROJECT_FILES_WHOLE_LINE = "- (the list is whole: a name absent from it does not exist)";
|
|
13
|
+
|
|
14
|
+
/** What a reader makes of the list, said only to an agent whose brief carries it: the closing line decides. */
|
|
15
|
+
export const PROJECT_LIST_RULE =
|
|
16
|
+
"When the brief lists the project's files, its last line says whether the list is whole: when it is, a name absent " +
|
|
17
|
+
"from it does not exist; past a cut, glob with a pattern decides. Never open a name you guessed, nor a folder.";
|
|
18
|
+
|
|
19
|
+
/** The closing line of a list cut at its bound, `left` files left out. */
|
|
20
|
+
export function projectFilesCutLine(left: number): string {
|
|
21
|
+
return `- … and ${left} more: a name absent above may still exist; glob with a pattern lists them`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** git's listing (one path per line) as a sorted list without duplicates, the work folder and .orkeon/ left out. */
|
|
25
|
+
export function parseTrackedFiles(stdout: string, work: string): string[] {
|
|
26
|
+
const folder = work.endsWith("/") ? work : `${work}/`;
|
|
27
|
+
const files = stdout.split("\n").map((line) => line.trim())
|
|
28
|
+
.filter((line) => line !== "" && !line.startsWith(folder) && !line.startsWith(".orkeon/"));
|
|
29
|
+
return [...new Set(files)].sort();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The lines a brief carries for `files`: none when no file is known, else the heading, one line per file up to
|
|
33
|
+
* `max`, and the closing line that says whether the list is whole or how many are left out. */
|
|
34
|
+
export function projectFileLines(files: readonly string[], max: number = MAX_LISTED_FILES): string[] {
|
|
35
|
+
if (files.length === 0) return [];
|
|
36
|
+
const shown = files.slice(0, max);
|
|
37
|
+
const left = files.length - shown.length;
|
|
38
|
+
return [
|
|
39
|
+
PROJECT_FILES_HEADING,
|
|
40
|
+
...shown.map((file) => `- ${file}`),
|
|
41
|
+
left > 0 ? projectFilesCutLine(left) : PROJECT_FILES_WHOLE_LINE,
|
|
42
|
+
];
|
|
43
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// The open questions of a spec or a change brief and the decisions a person made on them: the rows of the two
|
|
2
|
+
// tables, written and read back, and the checks of a question as a model gives it. An open row keeps the
|
|
3
|
+
// template's columns (`| # | Severity | Question | Impact | Options |`), so spec-format.ts and the harness read
|
|
4
|
+
// its severity as before; a decision row (`| # | Question | Answer | Date |`) records what was settled, in a section
|
|
5
|
+
// of its own. Pure, no IO.
|
|
6
|
+
|
|
7
|
+
export type QuestionSeverity = "Blocking" | "Major";
|
|
8
|
+
export const QUESTION_SEVERITIES: readonly QuestionSeverity[] = ["Blocking", "Major"];
|
|
9
|
+
|
|
10
|
+
/** One open question; `options[0]` is the recommended answer, `[]` when the question names none. */
|
|
11
|
+
export interface Question { id: string; severity: QuestionSeverity; question: string; impact: string; options: string[] }
|
|
12
|
+
/** One settled question: the question as it was asked, the answer the person gave, the day. */
|
|
13
|
+
export interface Decision { id: string; question: string; answer: string; date: string }
|
|
14
|
+
|
|
15
|
+
export const OPEN_QUESTIONS_HEADER = ["| # | Severity | Question | Impact | Options |", "|---|---|---|---|---|"];
|
|
16
|
+
export const DECISIONS_HEADER = ["| # | Question | Answer | Date |", "|---|---|---|---|"];
|
|
17
|
+
/** The option a person picks to keep a question open; never written as an option of the file. */
|
|
18
|
+
export const LEAVE_OPEN = "Leave it open";
|
|
19
|
+
export const RECOMMENDED_MARK = " (recommended)";
|
|
20
|
+
export const MAX_QUESTIONS = 12;
|
|
21
|
+
export const MAX_OPTIONS = 4;
|
|
22
|
+
const MAX_QUESTION_CHARS = 300;
|
|
23
|
+
const MAX_OPTION_CHARS = 120;
|
|
24
|
+
const MAX_CELL_CHARS = 300;
|
|
25
|
+
const QUESTION_ID = /^Q(\d+)$/;
|
|
26
|
+
const SEPARATOR_ROW = /^\|?[-: |]+$/;
|
|
27
|
+
|
|
28
|
+
/** A cell breaks its table when it holds a `|` or a line break. */
|
|
29
|
+
export const breaksCell = (text: string): boolean => /[|\r\n]/.test(text);
|
|
30
|
+
|
|
31
|
+
/** Two questions ask the same thing when they read the same, case and spaces aside. */
|
|
32
|
+
export const foldQuestion = (text: string): string => text.toLowerCase().replace(/[\s?]+/g, " ").trim();
|
|
33
|
+
|
|
34
|
+
export function optionsCell(options: readonly string[]): string {
|
|
35
|
+
if (options.length === 0) return "—";
|
|
36
|
+
return options.map((o, i) => `${i + 1}. ${o}${i === 0 ? RECOMMENDED_MARK : ""}`).join("; ");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The options of a cell written by optionsCell, or [] when the cell does not read as such a list. */
|
|
40
|
+
export function parseOptionsCell(cell: string): string[] {
|
|
41
|
+
const text = cell.trim();
|
|
42
|
+
if (text === "" || text === "—" || text === "-") return [];
|
|
43
|
+
const parts = text.split(/;\s*/).map((p) => p.trim()).filter((p) => p !== "");
|
|
44
|
+
const out: string[] = [];
|
|
45
|
+
for (const [i, part] of parts.entries()) {
|
|
46
|
+
const m = /^(\d+)\.\s+(.+)$/.exec(part);
|
|
47
|
+
if (m === null || Number(m[1]) !== i + 1) return [];
|
|
48
|
+
out.push(m[2].replace(/\s*\(recommended\)\s*$/i, "").trim());
|
|
49
|
+
}
|
|
50
|
+
return out.length >= 2 ? out : [];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function questionRow(q: Question): string {
|
|
54
|
+
return `| ${q.id} | ${q.severity} | ${q.question} | ${q.impact || "—"} | ${optionsCell(q.options)} |`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function decisionRow(d: Decision): string {
|
|
58
|
+
return `| ${d.id} | ${d.question} | ${d.answer} | ${d.date} |`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The table lines of a section, [] when there is no row: the section is then left out. */
|
|
62
|
+
export function questionTable(questions: readonly Question[]): string[] {
|
|
63
|
+
return questions.length === 0 ? [] : [...OPEN_QUESTIONS_HEADER, ...questions.map(questionRow)];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function decisionTable(decisions: readonly Decision[]): string[] {
|
|
67
|
+
return decisions.length === 0 ? [] : [...DECISIONS_HEADER, ...decisions.map(decisionRow)];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const cellsOf = (row: string): string[] =>
|
|
71
|
+
row.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim());
|
|
72
|
+
|
|
73
|
+
/** The data rows of the tables under each `## ` heading matching `heading`, with their header cells. */
|
|
74
|
+
function rowsUnder(text: string, heading: RegExp): Array<{ header: string[]; cells: string[] }> {
|
|
75
|
+
const out: Array<{ header: string[]; cells: string[] }> = [];
|
|
76
|
+
let inside = false;
|
|
77
|
+
let header: string[] | null = null;
|
|
78
|
+
for (const line of text.split(/\r?\n/)) {
|
|
79
|
+
if (line.startsWith("## ")) { inside = heading.test(line); header = null; continue; }
|
|
80
|
+
if (!inside) continue;
|
|
81
|
+
if (!line.includes("|")) { header = null; continue; }
|
|
82
|
+
if (SEPARATOR_ROW.test(line.trim())) continue;
|
|
83
|
+
const cells = cellsOf(line);
|
|
84
|
+
if (header === null) { header = cells; continue; }
|
|
85
|
+
out.push({ header, cells });
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const cell = (row: { header: string[]; cells: string[] }, name: string): string => {
|
|
91
|
+
const i = row.header.findIndex((h) => h.replace(/[*_`]/g, "").trim().toLowerCase() === name.toLowerCase());
|
|
92
|
+
return i < 0 ? "" : (row.cells[i] ?? "").trim();
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** The highest Q<n> of the ids, 0 when none. */
|
|
96
|
+
function highest(ids: Iterable<string>): number {
|
|
97
|
+
let max = 0;
|
|
98
|
+
for (const id of ids) {
|
|
99
|
+
const m = QUESTION_ID.exec(id);
|
|
100
|
+
if (m) max = Math.max(max, Number(m[1]));
|
|
101
|
+
}
|
|
102
|
+
return max;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const OPEN_QUESTIONS_HEADING = /^## .*Open questions/;
|
|
106
|
+
export const DECISIONS_HEADING = /^## (\d+\. )?Decisions\s*$/;
|
|
107
|
+
|
|
108
|
+
/** The open questions of a file, as written by questionRow or by hand: a row without a Q<n> id gets the next free
|
|
109
|
+
* one, a severity other than Blocking reads Major, a row without a question is skipped. */
|
|
110
|
+
export function parseOpenQuestions(text: string, taken: Iterable<string> = []): Question[] {
|
|
111
|
+
const rows = rowsUnder(text, OPEN_QUESTIONS_HEADING);
|
|
112
|
+
let next = Math.max(highest(taken), highest(rows.map((r) => cell(r, "#")))) + 1;
|
|
113
|
+
const out: Question[] = [];
|
|
114
|
+
for (const r of rows) {
|
|
115
|
+
const question = cell(r, "Question");
|
|
116
|
+
if (question === "") continue;
|
|
117
|
+
const own = cell(r, "#");
|
|
118
|
+
const id = QUESTION_ID.test(own) ? own : `Q${next++}`;
|
|
119
|
+
const severity: QuestionSeverity = cell(r, "Severity").replace(/[*_`]/g, "").trim().toLowerCase() === "blocking"
|
|
120
|
+
? "Blocking" : "Major";
|
|
121
|
+
const impact = cell(r, "Impact");
|
|
122
|
+
out.push({ id, severity, question, impact: impact === "—" ? "" : impact, options: parseOptionsCell(cell(r, "Options")) });
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function parseDecisions(text: string): Decision[] {
|
|
128
|
+
return rowsUnder(text, DECISIONS_HEADING)
|
|
129
|
+
.map((r) => ({ id: cell(r, "#"), question: cell(r, "Question"), answer: cell(r, "Answer"), date: cell(r, "Date") }))
|
|
130
|
+
.filter((d) => d.question !== "" && d.answer !== "");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** A question as a model gives it, before it has an id. */
|
|
134
|
+
export interface DraftQuestion { severity: string; question: string; impact: string; options: string[] }
|
|
135
|
+
|
|
136
|
+
export const QUESTION_SCHEMA: object = {
|
|
137
|
+
type: "object",
|
|
138
|
+
properties: {
|
|
139
|
+
severity: { type: "string", enum: [...QUESTION_SEVERITIES] },
|
|
140
|
+
question: { type: "string" },
|
|
141
|
+
impact: { type: "string" },
|
|
142
|
+
options: { type: "array", items: { type: "string" } },
|
|
143
|
+
},
|
|
144
|
+
required: ["severity", "question", "impact", "options"],
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/** What is wrong with question `k` of an answer: [] when it is one closed question fitting a row. */
|
|
148
|
+
export function draftQuestionProblems(q: DraftQuestion, k: number): string[] {
|
|
149
|
+
const problems: string[] = [];
|
|
150
|
+
if (!QUESTION_SEVERITIES.includes(q.severity as QuestionSeverity)) problems.push(`question ${k}: severity must be Blocking or Major`);
|
|
151
|
+
const text = q.question.trim();
|
|
152
|
+
if (text === "" || breaksCell(text) || text.length > MAX_QUESTION_CHARS || !text.endsWith("?")) {
|
|
153
|
+
problems.push(`question ${k}: one line of at most ${MAX_QUESTION_CHARS} characters ending with ?, no '|'`);
|
|
154
|
+
}
|
|
155
|
+
if (breaksCell(q.impact) || q.impact.length > MAX_CELL_CHARS) problems.push(`question ${k}: the impact is one line, no '|'`);
|
|
156
|
+
if (q.options.length === 1 || q.options.length > MAX_OPTIONS) {
|
|
157
|
+
problems.push(`question ${k}: no option, or 2 to ${MAX_OPTIONS} options with the recommended one first`);
|
|
158
|
+
}
|
|
159
|
+
const seen = new Set<string>();
|
|
160
|
+
for (const o of q.options) {
|
|
161
|
+
const t = o.trim();
|
|
162
|
+
if (t === "" || breaksCell(t) || t.includes(";") || t.length > MAX_OPTION_CHARS) {
|
|
163
|
+
problems.push(`question ${k}: an option is one line of at most ${MAX_OPTION_CHARS} characters, no ';' nor '|'`);
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
if (t.toLowerCase() === LEAVE_OPEN.toLowerCase()) { problems.push(`question ${k}: '${LEAVE_OPEN}' is not an option to list`); break; }
|
|
167
|
+
if (seen.has(t.toLowerCase())) { problems.push(`question ${k}: two options read the same`); break; }
|
|
168
|
+
seen.add(t.toLowerCase());
|
|
169
|
+
}
|
|
170
|
+
return problems;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The open questions after a draft: the model's, each numbered after every id already used (open or decided), a
|
|
175
|
+
* question that asks what a decision settled dropped, as is one asked twice.
|
|
176
|
+
*/
|
|
177
|
+
export function numberQuestions(
|
|
178
|
+
drafts: readonly DraftQuestion[], decisions: readonly Decision[], kept: readonly Question[] = [],
|
|
179
|
+
): Question[] {
|
|
180
|
+
const settled = new Set(decisions.map((d) => foldQuestion(d.question)));
|
|
181
|
+
const out: Question[] = [...kept];
|
|
182
|
+
const seen = new Set(out.map((q) => foldQuestion(q.question)));
|
|
183
|
+
let next = highest([...decisions.map((d) => d.id), ...kept.map((q) => q.id)]) + 1;
|
|
184
|
+
for (const d of drafts) {
|
|
185
|
+
const key = foldQuestion(d.question);
|
|
186
|
+
if (settled.has(key) || seen.has(key)) continue;
|
|
187
|
+
seen.add(key);
|
|
188
|
+
out.push({
|
|
189
|
+
id: `Q${next++}`, severity: d.severity === "Blocking" ? "Blocking" : "Major", question: d.question.trim(),
|
|
190
|
+
impact: d.impact.trim(), options: d.options.map((o) => o.trim()),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Blocking first, then Major, each in its order. */
|
|
197
|
+
export function askingOrder(questions: readonly Question[]): Question[] {
|
|
198
|
+
return [...questions.filter((q) => q.severity === "Blocking"), ...questions.filter((q) => q.severity !== "Blocking")];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** The decision a person made, its answer fitting a cell. */
|
|
202
|
+
export function decide(q: Question, answer: string, date: string): Decision {
|
|
203
|
+
const flat = answer.replace(/\s*[\r\n]+\s*/g, " ").replace(/\|/g, "/").trim();
|
|
204
|
+
return { id: q.id, question: q.question, answer: flat.length > MAX_CELL_CHARS ? `${flat.slice(0, MAX_CELL_CHARS)}…` : flat, date };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The text a person reads before answering. */
|
|
208
|
+
export function questionPrompt(label: string, q: Question): string {
|
|
209
|
+
const impact = q.impact === "" ? [] : [`Impact: ${q.impact}`];
|
|
210
|
+
return [`${label} — ${q.id} (${q.severity}): ${q.question}`, ...impact].join("\n");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* The text with its open-questions and decisions sections replaced by these tables: both old sections are taken
|
|
215
|
+
* out and the new ones written where the first of them stood (at the end when there was none). An empty table
|
|
216
|
+
* leaves its section out.
|
|
217
|
+
*/
|
|
218
|
+
export function withQuestionSections(
|
|
219
|
+
text: string, open: readonly Question[], decisions: readonly Decision[], headings: { questions: string; decisions: string },
|
|
220
|
+
): string {
|
|
221
|
+
const lines = text.replace(/\s+$/, "").split(/\r?\n/);
|
|
222
|
+
const kept: string[] = [];
|
|
223
|
+
let at = -1;
|
|
224
|
+
let skipping = false;
|
|
225
|
+
for (const line of lines) {
|
|
226
|
+
if (line.startsWith("## ")) {
|
|
227
|
+
skipping = OPEN_QUESTIONS_HEADING.test(line) || DECISIONS_HEADING.test(line);
|
|
228
|
+
if (skipping && at < 0) at = kept.length;
|
|
229
|
+
}
|
|
230
|
+
if (!skipping) kept.push(line);
|
|
231
|
+
}
|
|
232
|
+
const block = (heading: string, table: string[]): string[] => (table.length === 0 ? [] : [heading, "", ...table, ""]);
|
|
233
|
+
const inserted = [...block(headings.questions, questionTable(open)), ...block(headings.decisions, decisionTable(decisions))];
|
|
234
|
+
const where = at < 0 ? kept.length : at;
|
|
235
|
+
const head = kept.slice(0, where);
|
|
236
|
+
if (inserted.length > 0 && head.length > 0 && head[head.length - 1].trim() !== "") head.push("");
|
|
237
|
+
const out = [...head, ...inserted, ...kept.slice(where)];
|
|
238
|
+
return `${out.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd()}\n`;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** The rows of a review as questions to add: no options (asked as text), the evidence as the impact. */
|
|
242
|
+
export function reviewDrafts(rows: ReadonlyArray<{ severity: string; question: string; evidence: string; target: string }>, whole: string): DraftQuestion[] {
|
|
243
|
+
return rows.map((r) => ({
|
|
244
|
+
severity: r.severity,
|
|
245
|
+
question: (r.target === whole ? r.question : `${r.target}: ${r.question}`).replace(/[|\r\n]+/g, " ").trim(),
|
|
246
|
+
impact: `review, ${r.evidence}`.replace(/[|\r\n]+/g, " ").trim(),
|
|
247
|
+
options: [],
|
|
248
|
+
}));
|
|
249
|
+
}
|