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,738 @@
|
|
|
1
|
+
// The planner's answer: the JSON schema the plan is extracted into, and the check that
|
|
2
|
+
// turns the extraction into a PlanAnswer or the list of what is wrong with it. Pure, no
|
|
3
|
+
// IO. The model decides the batches, steps, tests and anchors; code derives what it must
|
|
4
|
+
// not decide (batch ids, the Ids cells, the traceability batches, the build step, the
|
|
5
|
+
// anchors' path:line). Whether a path exists in the repository is not checked here: the
|
|
6
|
+
// application lists the folders once this check has passed.
|
|
7
|
+
|
|
8
|
+
import type { Checked } from "../../../shared/domain/agents/charter.ts";
|
|
9
|
+
import { DESIGN_RULE_IDS } from "../../../shared/domain/dev/design-rules.ts";
|
|
10
|
+
import type { ChangeKind, SourceKind } from "../../../shared/domain/dev/spec-format.ts";
|
|
11
|
+
|
|
12
|
+
export type TestLevel = "unit" | "integration" | "pinned";
|
|
13
|
+
export type ElementLayer = "domain" | "application" | "adapter" | "test";
|
|
14
|
+
/** ref: an inventory entry shown to the model (ref set, path absent); create: a file to create (path set);
|
|
15
|
+
* existing: a file of the repository the index does not hold — .md, .json, .yaml… (path set). */
|
|
16
|
+
export type AnchorKind = "ref" | "create" | "existing";
|
|
17
|
+
export interface AnchorRef { kind: AnchorKind; ref?: string; path?: string; member?: string }
|
|
18
|
+
export interface PlanTest { name: string; level: TestLevel; project: string; ids: string[]; covers: string[] } // covers: "U<n>" of unpinned rows
|
|
19
|
+
export interface PlanStep {
|
|
20
|
+
title: string;
|
|
21
|
+
tests: PlanTest[];
|
|
22
|
+
note: string; // "" or ≤ 2 lines: what merges into one cycle, what needs a container
|
|
23
|
+
anchors: { tests: AnchorRef[]; doubles: AnchorRef[]; production: AnchorRef[] };
|
|
24
|
+
}
|
|
25
|
+
export interface PlanBatch {
|
|
26
|
+
name: string; intent: string; reason: string; // reason: the summary's Reason cell
|
|
27
|
+
documentation: boolean;
|
|
28
|
+
dependsOn: string[]; // "F<n>" of earlier batches
|
|
29
|
+
design: { appliedRules: string[]; aggregate: string; invariants: string; consistency: string; events: string; accessCost: string };
|
|
30
|
+
decisions: string[];
|
|
31
|
+
declarative: string[]; // artefacts written without a red test first; [] = none
|
|
32
|
+
steps: PlanStep[]; // behaviour steps only, 2..5 (1..5 for documentation)
|
|
33
|
+
buildScope: string; // the "Build and tests — scope:" text
|
|
34
|
+
testPolicy: { fast: string; integration: string; notRun: string };
|
|
35
|
+
elements: Array<{ layer: ElementLayer; signature: string; rule: string }>;
|
|
36
|
+
}
|
|
37
|
+
export interface PlanAnswer {
|
|
38
|
+
feature: string;
|
|
39
|
+
layers: string[];
|
|
40
|
+
reuse: string[]; // inventory refs
|
|
41
|
+
outOfScope: string[];
|
|
42
|
+
assumptions: string[]; // the Scope line's; the sheets' ## Assumptions stay empty
|
|
43
|
+
nonApplicable: Array<{ id: string; reason: string }>;
|
|
44
|
+
traceability: Array<{ id: string; owners: string[] }>;
|
|
45
|
+
design: Array<{ ids: string[]; aggregate: string; invariant: string; consistency: string; batch: number }>; // batch: 1-based
|
|
46
|
+
batches: PlanBatch[];
|
|
47
|
+
}
|
|
48
|
+
export interface PlanCheckContext {
|
|
49
|
+
sourceIds: readonly string[]; // UC/BR/CH of the source
|
|
50
|
+
shownRefs: ReadonlySet<string>; // the inventory refs the prompt showed
|
|
51
|
+
refPaths: ReadonlyMap<string, string>; // ref → relative path (shared-anchor check)
|
|
52
|
+
refNames: ReadonlyMap<string, string>; // ref → entry name (a production ref anchor's member)
|
|
53
|
+
kind: SourceKind; changeKind?: ChangeKind;
|
|
54
|
+
pinned: readonly string[]; // pinnedBy of "what must not change" rows
|
|
55
|
+
unpinned: readonly string[]; // "U1".."Un"
|
|
56
|
+
/** The work folder, relative (e.g. "workbench"): a created or existing anchor may not sit under it. */
|
|
57
|
+
workFolder?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const MAX_BATCHES = 8;
|
|
61
|
+
const MAX_PROBLEMS = 60;
|
|
62
|
+
export const MAX_TITLE = 100;
|
|
63
|
+
export const MAX_TEST_NAME = 120;
|
|
64
|
+
export const MAX_SIGNATURE = 200;
|
|
65
|
+
export const MAX_FEATURE = 80;
|
|
66
|
+
export const MIN_NA_REASON = 10;
|
|
67
|
+
const BUILD_STEP = "Build and tests";
|
|
68
|
+
const LEVELS: readonly TestLevel[] = ["unit", "integration", "pinned"];
|
|
69
|
+
const LAYERS: readonly ElementLayer[] = ["domain", "application", "adapter", "test"];
|
|
70
|
+
const KINDS: readonly AnchorKind[] = ["ref", "create", "existing"];
|
|
71
|
+
const DOC_PATH = /\.(md|mdx|rst|adoc|txt)$/i;
|
|
72
|
+
const LABELS = /Applied rules|Non-applicable rules/;
|
|
73
|
+
const LINE_BREAK = /\r\n|\r|\n/;
|
|
74
|
+
/** A line the harness or the parser reads as structure: a heading, a TDD line, a table row, a box, a quote. */
|
|
75
|
+
const LINE_MARKER = /^(#|TDD:|\||- \[|> )/;
|
|
76
|
+
/** A path:line, or a path: what an owner of the traceability may not be. */
|
|
77
|
+
const OWNER_PATH = /:\d|\//;
|
|
78
|
+
|
|
79
|
+
const STRING = { type: "string" };
|
|
80
|
+
const STRINGS = { type: "array", items: STRING };
|
|
81
|
+
/** A field of the schema with what it holds, in a few words: the runtime prints the schema whole after the prompt,
|
|
82
|
+
* so a field whose name says what it holds goes without one. */
|
|
83
|
+
const said = (schema: object, description: string): object => ({ ...schema, description });
|
|
84
|
+
const text = (description: string): object => said(STRING, description);
|
|
85
|
+
const texts = (description: string): object => said(STRINGS, description);
|
|
86
|
+
const listOf = (items: object, description?: string): object =>
|
|
87
|
+
description === undefined ? { type: "array", items } : said({ type: "array", items }, description);
|
|
88
|
+
const objectOf = (properties: Record<string, object>, description?: string): object => {
|
|
89
|
+
const schema = { type: "object", properties, required: Object.keys(properties) };
|
|
90
|
+
return description === undefined ? schema : said(schema, description);
|
|
91
|
+
};
|
|
92
|
+
/** An anchor; its fields are described once, on the anchors object, as the schema repeats it per list. */
|
|
93
|
+
const ANCHOR = {
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
kind: { type: "string", enum: [...KINDS] },
|
|
97
|
+
ref: STRING,
|
|
98
|
+
path: STRING,
|
|
99
|
+
member: STRING,
|
|
100
|
+
},
|
|
101
|
+
required: ["kind"],
|
|
102
|
+
};
|
|
103
|
+
const ANCHORS = listOf(ANCHOR);
|
|
104
|
+
|
|
105
|
+
export const PLAN_ANSWER_SCHEMA: object = objectOf({
|
|
106
|
+
feature: text(`Max ${MAX_FEATURE} chars`),
|
|
107
|
+
layers: texts("Folders touched"),
|
|
108
|
+
reuse: texts("I<n> refs alone"),
|
|
109
|
+
outOfScope: STRINGS,
|
|
110
|
+
assumptions: texts("Assumed, never an open question answered"),
|
|
111
|
+
nonApplicable: listOf(objectOf({
|
|
112
|
+
id: { type: "string", enum: [...DESIGN_RULE_IDS] },
|
|
113
|
+
reason: text(`Stands alone, min ${MIN_NA_REASON} chars`),
|
|
114
|
+
}), "Rules no batch applies"),
|
|
115
|
+
traceability: listOf(objectOf({
|
|
116
|
+
id: STRING,
|
|
117
|
+
owners: texts("Type or member names, never a path"),
|
|
118
|
+
}), "One row per source id"),
|
|
119
|
+
design: listOf(objectOf({
|
|
120
|
+
ids: texts("Source UC/BR/CH ids"),
|
|
121
|
+
aggregate: STRING,
|
|
122
|
+
invariant: STRING,
|
|
123
|
+
consistency: STRING,
|
|
124
|
+
batch: said({ type: "integer" }, "1-based batch"),
|
|
125
|
+
})),
|
|
126
|
+
batches: listOf(objectOf({
|
|
127
|
+
name: STRING,
|
|
128
|
+
intent: text("What it delivers"),
|
|
129
|
+
reason: text("Why it is cut here"),
|
|
130
|
+
documentation: said({ type: "boolean" }, "Docs alone, no code"),
|
|
131
|
+
dependsOn: texts("F<n> of earlier batches, n its place from 1"),
|
|
132
|
+
design: objectOf({
|
|
133
|
+
appliedRules: STRINGS,
|
|
134
|
+
aggregate: STRING,
|
|
135
|
+
invariants: STRING,
|
|
136
|
+
consistency: STRING,
|
|
137
|
+
events: STRING,
|
|
138
|
+
accessCost: text("Storage or network reached"),
|
|
139
|
+
}, "All written; a sentence if none applies"),
|
|
140
|
+
decisions: texts("Choices made, why"),
|
|
141
|
+
declarative: texts("Pure declarations, no test of their own"),
|
|
142
|
+
steps: listOf(objectOf({
|
|
143
|
+
title: text(`Behaviour, max ${MAX_TITLE} chars`),
|
|
144
|
+
tests: listOf(objectOf({
|
|
145
|
+
name: text(`As the repository names tests, unique, max ${MAX_TEST_NAME} chars`),
|
|
146
|
+
level: said({ type: "string", enum: [...LEVELS] }, "pinned: one the brief pins"),
|
|
147
|
+
project: STRING,
|
|
148
|
+
ids: texts("UC/BR/CH ids it proves"),
|
|
149
|
+
covers: texts("U<n> rows characterised"),
|
|
150
|
+
})),
|
|
151
|
+
note: text("Empty or 2 lines: merged cycle, container"),
|
|
152
|
+
anchors: objectOf({
|
|
153
|
+
tests: ANCHORS,
|
|
154
|
+
doubles: ANCHORS,
|
|
155
|
+
production: ANCHORS,
|
|
156
|
+
}, "Files filled or created. kind ref: a shown entry, I<n> in ref; create: a new file, existing: an unindexed one, " +
|
|
157
|
+
"both by relative path; member: the one filled, omitted if new"),
|
|
158
|
+
}), "Behaviour steps; code adds the build"),
|
|
159
|
+
buildScope: text("Scope of the build step code adds"),
|
|
160
|
+
testPolicy: objectOf({
|
|
161
|
+
fast: STRING,
|
|
162
|
+
integration: STRING,
|
|
163
|
+
notRun: text("Not run, why"),
|
|
164
|
+
}, "Sheet test policy, a sentence each"),
|
|
165
|
+
elements: listOf(objectOf({
|
|
166
|
+
layer: { type: "string", enum: [...LAYERS] },
|
|
167
|
+
signature: text(`Max ${MAX_SIGNATURE} chars, never a body`),
|
|
168
|
+
rule: text("What it does or gains"),
|
|
169
|
+
})),
|
|
170
|
+
}), `At most ${MAX_BATCHES}, cut by behaviour`),
|
|
171
|
+
}, "Text fields: one line (a note two), no |; no backtick in a test name, project, path, member or owner; " +
|
|
172
|
+
"no line opens with #, TDD:, |, - [ or >");
|
|
173
|
+
|
|
174
|
+
// ---- rule 1: the shape --------------------------------------------------------------
|
|
175
|
+
|
|
176
|
+
type Obj = Record<string, unknown>;
|
|
177
|
+
const isObj = (v: unknown): v is Obj => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
178
|
+
|
|
179
|
+
/** Reads one field of the right type, or records `<field> is missing or not a <type>`. */
|
|
180
|
+
class Reader {
|
|
181
|
+
readonly problems: string[] = [];
|
|
182
|
+
|
|
183
|
+
private miss(field: string, type: string): void {
|
|
184
|
+
const what = type.startsWith("one of") ? type : `${/^[aeiou]/.test(type) ? "an" : "a"} ${type}`;
|
|
185
|
+
this.problems.push(`${field} is missing or not ${what}`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
str(o: Obj, key: string, at: string): string {
|
|
189
|
+
const v = o[key];
|
|
190
|
+
if (typeof v !== "string") { this.miss(at + key, "string"); return ""; }
|
|
191
|
+
return v;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
optStr(o: Obj, key: string, at: string): string | undefined {
|
|
195
|
+
const v = o[key];
|
|
196
|
+
if (v === undefined) return undefined;
|
|
197
|
+
if (typeof v !== "string") { this.miss(at + key, "string"); return undefined; }
|
|
198
|
+
return v;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
bool(o: Obj, key: string, at: string): boolean {
|
|
202
|
+
const v = o[key];
|
|
203
|
+
if (typeof v !== "boolean") { this.miss(at + key, "boolean"); return false; }
|
|
204
|
+
return v;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
int(o: Obj, key: string, at: string): number {
|
|
208
|
+
const v = o[key];
|
|
209
|
+
if (typeof v !== "number" || !Number.isInteger(v)) { this.miss(at + key, "integer"); return 0; }
|
|
210
|
+
return v;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
oneOf<T extends string>(o: Obj, key: string, at: string, values: readonly T[], type: string): T {
|
|
214
|
+
const v = o[key];
|
|
215
|
+
if (typeof v !== "string" || !values.includes(v.trim() as T)) { this.miss(at + key, type); return values[0]; }
|
|
216
|
+
return v.trim() as T;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
obj(o: Obj, key: string, at: string): Obj {
|
|
220
|
+
const v = o[key];
|
|
221
|
+
if (!isObj(v)) { this.miss(at + key, "object"); return {}; }
|
|
222
|
+
return v;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
list<T>(o: Obj, key: string, at: string, item: (v: unknown, at: string) => T | undefined): T[] {
|
|
226
|
+
const v = o[key];
|
|
227
|
+
if (!Array.isArray(v)) { this.miss(at + key, "list"); return []; }
|
|
228
|
+
const out: T[] = [];
|
|
229
|
+
v.forEach((x, i) => {
|
|
230
|
+
const r = item(x, `${at}${key}[${i}]`);
|
|
231
|
+
if (r !== undefined) out.push(r);
|
|
232
|
+
});
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
strings(o: Obj, key: string, at: string): string[] {
|
|
237
|
+
return this.list(o, key, at, (x, here) => {
|
|
238
|
+
if (typeof x !== "string") { this.miss(here, "string"); return undefined; }
|
|
239
|
+
return x;
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
objects<T>(o: Obj, key: string, at: string, read: (item: Obj, at: string) => T): T[] {
|
|
244
|
+
return this.list(o, key, at, (x, here) => {
|
|
245
|
+
if (!isObj(x)) { this.miss(here, "object"); return undefined; }
|
|
246
|
+
return read(x, `${here}.`);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function readAnswer(value: Obj, r: Reader): PlanAnswer {
|
|
252
|
+
const anchor = (a: Obj, at: string): AnchorRef => {
|
|
253
|
+
const out: AnchorRef = { kind: r.oneOf(a, "kind", at, KINDS, "one of ref, create, existing") };
|
|
254
|
+
const ref = r.optStr(a, "ref", at);
|
|
255
|
+
const path = r.optStr(a, "path", at);
|
|
256
|
+
const member = r.optStr(a, "member", at);
|
|
257
|
+
if (ref !== undefined) out.ref = ref;
|
|
258
|
+
if (path !== undefined) out.path = path;
|
|
259
|
+
if (member !== undefined) out.member = member;
|
|
260
|
+
return out;
|
|
261
|
+
};
|
|
262
|
+
const test = (t: Obj, at: string): PlanTest => ({
|
|
263
|
+
name: r.str(t, "name", at),
|
|
264
|
+
level: r.oneOf(t, "level", at, LEVELS, "one of unit, integration, pinned"),
|
|
265
|
+
project: r.str(t, "project", at),
|
|
266
|
+
ids: r.strings(t, "ids", at),
|
|
267
|
+
covers: r.strings(t, "covers", at),
|
|
268
|
+
});
|
|
269
|
+
const step = (s: Obj, at: string): PlanStep => {
|
|
270
|
+
const anchors = r.obj(s, "anchors", at);
|
|
271
|
+
const here = `${at}anchors.`;
|
|
272
|
+
return {
|
|
273
|
+
title: r.str(s, "title", at),
|
|
274
|
+
tests: r.objects(s, "tests", at, test),
|
|
275
|
+
note: r.str(s, "note", at),
|
|
276
|
+
anchors: {
|
|
277
|
+
tests: r.objects(anchors, "tests", here, anchor),
|
|
278
|
+
doubles: r.objects(anchors, "doubles", here, anchor),
|
|
279
|
+
production: r.objects(anchors, "production", here, anchor),
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
const batch = (b: Obj, at: string): PlanBatch => {
|
|
284
|
+
const design = r.obj(b, "design", at);
|
|
285
|
+
const policy = r.obj(b, "testPolicy", at);
|
|
286
|
+
const d = `${at}design.`;
|
|
287
|
+
const p = `${at}testPolicy.`;
|
|
288
|
+
return {
|
|
289
|
+
name: r.str(b, "name", at),
|
|
290
|
+
intent: r.str(b, "intent", at),
|
|
291
|
+
reason: r.str(b, "reason", at),
|
|
292
|
+
documentation: r.bool(b, "documentation", at),
|
|
293
|
+
dependsOn: r.strings(b, "dependsOn", at),
|
|
294
|
+
design: {
|
|
295
|
+
appliedRules: r.strings(design, "appliedRules", d),
|
|
296
|
+
aggregate: r.str(design, "aggregate", d),
|
|
297
|
+
invariants: r.str(design, "invariants", d),
|
|
298
|
+
consistency: r.str(design, "consistency", d),
|
|
299
|
+
events: r.str(design, "events", d),
|
|
300
|
+
accessCost: r.str(design, "accessCost", d),
|
|
301
|
+
},
|
|
302
|
+
decisions: r.strings(b, "decisions", at),
|
|
303
|
+
declarative: r.strings(b, "declarative", at),
|
|
304
|
+
steps: r.objects(b, "steps", at, step),
|
|
305
|
+
buildScope: r.str(b, "buildScope", at),
|
|
306
|
+
testPolicy: { fast: r.str(policy, "fast", p), integration: r.str(policy, "integration", p), notRun: r.str(policy, "notRun", p) },
|
|
307
|
+
elements: r.objects(b, "elements", at, (e, here) => ({
|
|
308
|
+
layer: r.oneOf(e, "layer", here, LAYERS, "one of domain, application, adapter, test"),
|
|
309
|
+
signature: r.str(e, "signature", here),
|
|
310
|
+
rule: r.str(e, "rule", here),
|
|
311
|
+
})),
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
return {
|
|
315
|
+
feature: r.str(value, "feature", ""),
|
|
316
|
+
layers: r.strings(value, "layers", ""),
|
|
317
|
+
reuse: r.strings(value, "reuse", ""),
|
|
318
|
+
outOfScope: r.strings(value, "outOfScope", ""),
|
|
319
|
+
assumptions: r.strings(value, "assumptions", ""),
|
|
320
|
+
nonApplicable: r.objects(value, "nonApplicable", "", (n, at) => ({
|
|
321
|
+
id: r.oneOf(n, "id", at, DESIGN_RULE_IDS, "design rule id"),
|
|
322
|
+
reason: r.str(n, "reason", at),
|
|
323
|
+
})),
|
|
324
|
+
traceability: r.objects(value, "traceability", "", (t, at) => ({ id: r.str(t, "id", at), owners: r.strings(t, "owners", at) })),
|
|
325
|
+
design: r.objects(value, "design", "", (d, at) => ({
|
|
326
|
+
ids: r.strings(d, "ids", at),
|
|
327
|
+
aggregate: r.str(d, "aggregate", at),
|
|
328
|
+
invariant: r.str(d, "invariant", at),
|
|
329
|
+
consistency: r.str(d, "consistency", at),
|
|
330
|
+
batch: r.int(d, "batch", at),
|
|
331
|
+
})),
|
|
332
|
+
batches: r.objects(value, "batches", "", batch),
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// ---- trimming ----------------------------------------------------------------------
|
|
337
|
+
|
|
338
|
+
const trimAll = (xs: readonly string[]): string[] => xs.map((x) => x.trim());
|
|
339
|
+
const trimNote = (note: string): string => note.trim().split(LINE_BREAK).map((l) => l.trimEnd()).join("\n");
|
|
340
|
+
|
|
341
|
+
/** A path in one spelling, so every rule compares the same string: no `./` segment, no doubled or trailing `/`
|
|
342
|
+
* (a leading `/` is kept, for rule 14 to refuse it). */
|
|
343
|
+
function normalPath(raw: string): string {
|
|
344
|
+
const path = raw.trim();
|
|
345
|
+
const segments = path.split("/").filter((s) => s !== "" && s !== ".");
|
|
346
|
+
return (path.startsWith("/") ? "/" : "") + segments.join("/");
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function trimAnchor(a: AnchorRef): AnchorRef {
|
|
350
|
+
const out: AnchorRef = { kind: a.kind };
|
|
351
|
+
if (a.ref !== undefined) out.ref = a.ref.trim();
|
|
352
|
+
if (a.path !== undefined) out.path = normalPath(a.path);
|
|
353
|
+
if (a.member !== undefined) out.member = a.member.trim();
|
|
354
|
+
return out;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** The slips a model makes in the shape, mended where they have a single reading: a source id
|
|
358
|
+
* written in a test's covers moves to its ids, a ref anchor's path equal to its ref's path is
|
|
359
|
+
* dropped, a reuse entry that starts with a shown ref ("I3 class Account") keeps the ref alone. */
|
|
360
|
+
function mended(a: PlanAnswer, ctx: PlanCheckContext): PlanAnswer {
|
|
361
|
+
const test = (t: PlanTest): PlanTest => {
|
|
362
|
+
const moved = t.covers.filter((u) => !ctx.unpinned.includes(u) && ctx.sourceIds.includes(u));
|
|
363
|
+
if (moved.length === 0) return t;
|
|
364
|
+
return { ...t, ids: [...t.ids, ...moved.filter((id) => !t.ids.includes(id))], covers: t.covers.filter((u) => !moved.includes(u)) };
|
|
365
|
+
};
|
|
366
|
+
const anchor = (x: AnchorRef): AnchorRef => {
|
|
367
|
+
if (x.kind !== "ref" || x.ref === undefined || x.path === undefined || ctx.refPaths.get(x.ref) !== x.path) return x;
|
|
368
|
+
const { path: _path, ...rest } = x;
|
|
369
|
+
return rest;
|
|
370
|
+
};
|
|
371
|
+
const reuse = (r: string): string => {
|
|
372
|
+
const lead = /^(I\d+)\b/.exec(r)?.[1];
|
|
373
|
+
return lead !== undefined && lead !== r && ctx.shownRefs.has(lead) ? lead : r;
|
|
374
|
+
};
|
|
375
|
+
return {
|
|
376
|
+
...a,
|
|
377
|
+
reuse: a.reuse.map(reuse),
|
|
378
|
+
batches: a.batches.map((b) => ({
|
|
379
|
+
...b,
|
|
380
|
+
steps: b.steps.map((s) => ({
|
|
381
|
+
...s,
|
|
382
|
+
tests: s.tests.map(test),
|
|
383
|
+
anchors: { tests: s.anchors.tests.map(anchor), doubles: s.anchors.doubles.map(anchor), production: s.anchors.production.map(anchor) },
|
|
384
|
+
})),
|
|
385
|
+
})),
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function trimmed(a: PlanAnswer): PlanAnswer {
|
|
390
|
+
return {
|
|
391
|
+
feature: a.feature.trim(),
|
|
392
|
+
layers: trimAll(a.layers),
|
|
393
|
+
reuse: trimAll(a.reuse),
|
|
394
|
+
outOfScope: trimAll(a.outOfScope),
|
|
395
|
+
assumptions: trimAll(a.assumptions),
|
|
396
|
+
nonApplicable: a.nonApplicable.map((n) => ({ id: n.id.trim(), reason: n.reason.trim() })),
|
|
397
|
+
traceability: a.traceability.map((t) => ({ id: t.id.trim(), owners: trimAll(t.owners) })),
|
|
398
|
+
design: a.design.map((d) => ({
|
|
399
|
+
ids: trimAll(d.ids), aggregate: d.aggregate.trim(), invariant: d.invariant.trim(), consistency: d.consistency.trim(), batch: d.batch,
|
|
400
|
+
})),
|
|
401
|
+
batches: a.batches.map((b) => ({
|
|
402
|
+
name: b.name.trim(), intent: b.intent.trim(), reason: b.reason.trim(), documentation: b.documentation,
|
|
403
|
+
dependsOn: trimAll(b.dependsOn),
|
|
404
|
+
design: {
|
|
405
|
+
appliedRules: trimAll(b.design.appliedRules), aggregate: b.design.aggregate.trim(), invariants: b.design.invariants.trim(),
|
|
406
|
+
consistency: b.design.consistency.trim(), events: b.design.events.trim(), accessCost: b.design.accessCost.trim(),
|
|
407
|
+
},
|
|
408
|
+
decisions: trimAll(b.decisions),
|
|
409
|
+
declarative: trimAll(b.declarative),
|
|
410
|
+
steps: b.steps.map((s) => ({
|
|
411
|
+
title: s.title.trim(),
|
|
412
|
+
tests: s.tests.map((t) => ({ name: t.name.trim(), level: t.level, project: t.project.trim(), ids: trimAll(t.ids), covers: trimAll(t.covers) })),
|
|
413
|
+
note: trimNote(s.note),
|
|
414
|
+
anchors: { tests: s.anchors.tests.map(trimAnchor), doubles: s.anchors.doubles.map(trimAnchor), production: s.anchors.production.map(trimAnchor) },
|
|
415
|
+
})),
|
|
416
|
+
buildScope: b.buildScope.trim(),
|
|
417
|
+
testPolicy: { fast: b.testPolicy.fast.trim(), integration: b.testPolicy.integration.trim(), notRun: b.testPolicy.notRun.trim() },
|
|
418
|
+
elements: b.elements.map((e) => ({ layer: e.layer, signature: e.signature.trim(), rule: e.rule.trim() })),
|
|
419
|
+
})),
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// ---- the cells ---------------------------------------------------------------------
|
|
424
|
+
|
|
425
|
+
type CellKind = "code" | "prose" | "note";
|
|
426
|
+
interface Cell { where: string; field: string; value: string; kind: CellKind }
|
|
427
|
+
|
|
428
|
+
/** The longest batch name or step title a problem's label quotes: the re-ask names what the model wrote,
|
|
429
|
+
* not only an index of an answer it no longer sees. */
|
|
430
|
+
export const LABEL_QUOTE = 60;
|
|
431
|
+
/** A `"` of the text becomes `'`, so the quote it sits in ends where the name ends. */
|
|
432
|
+
const quoted = (text: string): string => {
|
|
433
|
+
const one = text.replace(/\s+/g, " ").replace(/"/g, "'").trim();
|
|
434
|
+
if (one === "") return "";
|
|
435
|
+
const chars = Array.from(one);
|
|
436
|
+
return ` "${chars.length > LABEL_QUOTE ? `${chars.slice(0, LABEL_QUOTE).join("")}…` : one}"`;
|
|
437
|
+
};
|
|
438
|
+
/** `B1 "<name>"`, the name left out when empty. */
|
|
439
|
+
const batchLabel = (b: PlanBatch, k: number): string => `B${k + 1}${quoted(b.name)}`;
|
|
440
|
+
/** `B1 "<name>" S2 "<title>"`; the anchor path check labels its problems the same way. */
|
|
441
|
+
export const stepLabel = (b: PlanBatch, k: number, j: number): string => `${batchLabel(b, k)} S${j + 1}${quoted(b.steps[j]?.title ?? "")}`;
|
|
442
|
+
const testLabel = (b: PlanBatch, k: number, j: number, m: number): string => `${stepLabel(b, k, j)} T${m + 1}`;
|
|
443
|
+
/** `design row 2 (<first id>)`, the id left out when the row has none. */
|
|
444
|
+
const designRow = (d: PlanAnswer["design"][number], i: number): string => {
|
|
445
|
+
const first = d.ids.find((id) => id !== "");
|
|
446
|
+
return `design row ${i + 1}${first === undefined ? "" : ` (${first})`}`;
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
function cellsOf(a: PlanAnswer): Cell[] {
|
|
450
|
+
const cells: Cell[] = [];
|
|
451
|
+
const add = (where: string, field: string, value: string, kind: CellKind): void => { cells.push({ where, field, value, kind }); };
|
|
452
|
+
add("plan", "feature", a.feature, "prose");
|
|
453
|
+
a.layers.forEach((v, i) => add("plan", `layers[${i}]`, v, "prose"));
|
|
454
|
+
a.outOfScope.forEach((v, i) => add("plan", `outOfScope[${i}]`, v, "prose"));
|
|
455
|
+
a.assumptions.forEach((v, i) => add("plan", `assumptions[${i}]`, v, "prose"));
|
|
456
|
+
a.nonApplicable.forEach((n, i) => add("plan", `nonApplicable[${i}].reason`, n.reason, "prose"));
|
|
457
|
+
a.traceability.forEach((t, i) => t.owners.forEach((o, j) => add("plan", `traceability[${i}].owners[${j}]`, o, "code")));
|
|
458
|
+
a.design.forEach((d, i) => {
|
|
459
|
+
const where = designRow(d, i);
|
|
460
|
+
add(where, "aggregate", d.aggregate, "code");
|
|
461
|
+
add(where, "invariant", d.invariant, "prose");
|
|
462
|
+
add(where, "consistency", d.consistency, "prose");
|
|
463
|
+
});
|
|
464
|
+
a.batches.forEach((b, k) => {
|
|
465
|
+
const where = batchLabel(b, k);
|
|
466
|
+
for (const f of ["name", "intent", "reason", "buildScope"] as const) add(where, f, b[f], "prose");
|
|
467
|
+
for (const f of ["aggregate", "invariants", "consistency", "events", "accessCost"] as const) add(where, `design.${f}`, b.design[f], "prose");
|
|
468
|
+
for (const f of ["fast", "integration", "notRun"] as const) add(where, `testPolicy.${f}`, b.testPolicy[f], "prose");
|
|
469
|
+
b.decisions.forEach((v, i) => add(where, `decisions[${i}]`, v, "prose"));
|
|
470
|
+
b.declarative.forEach((v, i) => add(where, `declarative[${i}]`, v, "prose"));
|
|
471
|
+
b.elements.forEach((e, i) => {
|
|
472
|
+
add(where, `elements[${i}].signature`, e.signature, "code");
|
|
473
|
+
add(where, `elements[${i}].rule`, e.rule, "prose");
|
|
474
|
+
});
|
|
475
|
+
b.steps.forEach((s, j) => {
|
|
476
|
+
const at = stepLabel(b, k, j);
|
|
477
|
+
add(at, "title", s.title, "prose");
|
|
478
|
+
add(at, "note", s.note, "note");
|
|
479
|
+
for (const column of ["tests", "doubles", "production"] as const) {
|
|
480
|
+
s.anchors[column].forEach((x, i) => {
|
|
481
|
+
if (x.path !== undefined) add(at, `anchors.${column}[${i}].path`, x.path, "code");
|
|
482
|
+
if (x.member !== undefined) add(at, `anchors.${column}[${i}].member`, x.member, "code");
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
s.tests.forEach((t, m) => {
|
|
486
|
+
add(testLabel(b, k, j, m), "name", t.name, "code");
|
|
487
|
+
add(testLabel(b, k, j, m), "project", t.project, "code");
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
return cells;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function cellProblems(cells: readonly Cell[]): string[] {
|
|
495
|
+
const out: string[] = [];
|
|
496
|
+
for (const c of cells) {
|
|
497
|
+
const head = `${c.where}: ${c.field}`;
|
|
498
|
+
if (c.kind === "code" && /[|`\r\n]/.test(c.value)) out.push(`${head} holds a |, a backtick or a line break`);
|
|
499
|
+
if (c.kind === "prose" && /[|\r\n]/.test(c.value)) out.push(`${head} holds a | or a line break`);
|
|
500
|
+
if (c.kind === "note" && (c.value.includes("|") || c.value.split(LINE_BREAK).length > 2)) {
|
|
501
|
+
out.push(`${head} holds a | or a line break`);
|
|
502
|
+
}
|
|
503
|
+
if (LABELS.test(c.value)) out.push(`${head} holds the label Applied rules or Non-applicable rules`);
|
|
504
|
+
if (c.value.split(LINE_BREAK).some((l) => LINE_MARKER.test(l.trimStart()))) {
|
|
505
|
+
out.push(`${head} starts a line with one of #, TDD:, |, - [, >`);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return out;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// ---- the plan's rules --------------------------------------------------------------
|
|
512
|
+
|
|
513
|
+
const isDocPath = (path: string): boolean => DOC_PATH.test(path) || path.startsWith("docs/");
|
|
514
|
+
|
|
515
|
+
function allAnchors(s: PlanStep): AnchorRef[] {
|
|
516
|
+
return [...s.anchors.tests, ...s.anchors.doubles, ...s.anchors.production];
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function pathOf(a: AnchorRef, ctx: PlanCheckContext): string | undefined {
|
|
520
|
+
return a.kind === "ref" ? (a.ref === undefined ? undefined : ctx.refPaths.get(a.ref)) : a.path;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function anchorProblems(a: AnchorRef, at: string, ctx: PlanCheckContext, inventoryPaths: ReadonlySet<string>): string[] {
|
|
524
|
+
if (a.kind === "ref") {
|
|
525
|
+
if (a.ref === undefined || a.path !== undefined) return [`${at}: a ref anchor needs a ref only`];
|
|
526
|
+
return ctx.shownRefs.has(a.ref) ? [] : [`${at}: anchor ${a.ref} is not an inventory entry shown`];
|
|
527
|
+
}
|
|
528
|
+
if (a.path === undefined || a.ref !== undefined) return [`${at}: ${a.kind === "existing" ? "an" : "a"} ${a.kind} anchor needs a path only`];
|
|
529
|
+
const path = a.path;
|
|
530
|
+
const work = ctx.workFolder?.replace(/^\/+|\/+$/g, "");
|
|
531
|
+
const banned = [".claude/", ".orkeon/", ...(work ? [`${work}/`] : [])];
|
|
532
|
+
if (path === "" || path.startsWith("/") || /^[A-Za-z]:/.test(path) || path.includes("\\") || path.split("/").includes("..") ||
|
|
533
|
+
banned.some((p) => path.startsWith(p))) {
|
|
534
|
+
return [`${at}: ${path} cannot be anchored there`];
|
|
535
|
+
}
|
|
536
|
+
if (path.includes(":")) return [`${at}: anchor path "${path}" holds ":"`];
|
|
537
|
+
if (a.kind === "existing" && inventoryPaths.has(path)) return [`${at}: ${path} is in the inventory: use its ref`];
|
|
538
|
+
return [];
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function stepProblems(b: PlanBatch, k: number, ctx: PlanCheckContext, inventoryPaths: ReadonlySet<string>): string[] {
|
|
542
|
+
const out: string[] = [];
|
|
543
|
+
const titles = new Map<string, number>();
|
|
544
|
+
b.steps.forEach((s, j) => {
|
|
545
|
+
const at = stepLabel(b, k, j);
|
|
546
|
+
// 5: the title.
|
|
547
|
+
if (s.title === "") out.push(`${at}: the title is empty`);
|
|
548
|
+
else if (s.title.length > MAX_TITLE) out.push(`${at}: the title is longer than ${MAX_TITLE} characters`);
|
|
549
|
+
else if (s.title === BUILD_STEP) out.push(`${at}: the title is ${BUILD_STEP}, the step code adds`);
|
|
550
|
+
const first = titles.get(s.title);
|
|
551
|
+
if (s.title !== "" && first !== undefined) out.push(`${at}: the title repeats step ${first + 1}`);
|
|
552
|
+
else titles.set(s.title, j);
|
|
553
|
+
// 6, 7: the tests.
|
|
554
|
+
if (s.tests.length === 0) out.push(`${at}: no test`);
|
|
555
|
+
s.tests.forEach((t, m) => {
|
|
556
|
+
const here = testLabel(b, k, j, m);
|
|
557
|
+
if (t.name === "") out.push(`${here}: the name is empty`);
|
|
558
|
+
else if (t.name.length > MAX_TEST_NAME) out.push(`${here}: the name is longer than ${MAX_TEST_NAME} characters`);
|
|
559
|
+
if (t.project === "") out.push(`${here}: the project is empty`);
|
|
560
|
+
for (const id of t.ids) if (!ctx.sourceIds.includes(id)) out.push(`${here}: ${id} is not an id of the source`);
|
|
561
|
+
for (const u of t.covers) if (!ctx.unpinned.includes(u)) out.push(`${here}: ${u} is not an unpinned row`);
|
|
562
|
+
if (t.ids.length === 0 && t.covers.length === 0) out.push(`${here}: names no id`);
|
|
563
|
+
});
|
|
564
|
+
// 13, 14, 26: each anchor.
|
|
565
|
+
for (const a of allAnchors(s)) out.push(...anchorProblems(a, at, ctx, inventoryPaths));
|
|
566
|
+
// 27: a production ref anchor's member is the entry, or the entry's last dotted segment.
|
|
567
|
+
for (const a of s.anchors.production) {
|
|
568
|
+
const name = a.kind === "ref" && a.ref !== undefined ? ctx.refNames.get(a.ref) : undefined;
|
|
569
|
+
if (name === undefined || a.member === undefined || a.member === "") continue;
|
|
570
|
+
if (a.member !== name && a.member !== name.slice(name.lastIndexOf(".") + 1)) {
|
|
571
|
+
out.push(`${at}: anchor ${a.ref}: member "${a.member}" is not ${name}; leave member out to add a member to it`);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
// 15: the columns a step needs.
|
|
575
|
+
if (!b.documentation && s.anchors.tests.length === 0) out.push(`${at}: no test anchor`);
|
|
576
|
+
if (s.anchors.production.length === 0) out.push(`${at}: no production anchor`);
|
|
577
|
+
});
|
|
578
|
+
return out;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function batchProblems(b: PlanBatch, k: number, ctx: PlanCheckContext, inventoryPaths: ReadonlySet<string>): string[] {
|
|
582
|
+
const out: string[] = [];
|
|
583
|
+
const at = batchLabel(b, k);
|
|
584
|
+
// 3: the fields a sheet prints.
|
|
585
|
+
const fields: Array<[string, string]> = [
|
|
586
|
+
["name", b.name], ["intent", b.intent], ["reason", b.reason], ["buildScope", b.buildScope],
|
|
587
|
+
["testPolicy.fast", b.testPolicy.fast], ["testPolicy.integration", b.testPolicy.integration], ["testPolicy.notRun", b.testPolicy.notRun],
|
|
588
|
+
["design.aggregate", b.design.aggregate], ["design.invariants", b.design.invariants], ["design.consistency", b.design.consistency],
|
|
589
|
+
["design.events", b.design.events], ["design.accessCost", b.design.accessCost],
|
|
590
|
+
];
|
|
591
|
+
for (const [field, value] of fields) if (value === "") out.push(`${at}: ${field} is empty`);
|
|
592
|
+
// 4: the step count.
|
|
593
|
+
const min = b.documentation ? 1 : 2;
|
|
594
|
+
if (b.steps.length < min || b.steps.length > 5) {
|
|
595
|
+
out.push(`${at}: ${b.steps.length} behaviour steps; 2 to 5 (1 to 5 for documentation)`);
|
|
596
|
+
}
|
|
597
|
+
out.push(...stepProblems(b, k, ctx, inventoryPaths));
|
|
598
|
+
// 11: applied rules are design rule ids.
|
|
599
|
+
for (const id of b.design.appliedRules) if (!DESIGN_RULE_IDS.includes(id)) out.push(`${at}: ${id} is not a design rule id`);
|
|
600
|
+
// 12: earlier batches only.
|
|
601
|
+
for (const dep of b.dependsOn) {
|
|
602
|
+
const m = /^F(\d+)$/.exec(dep);
|
|
603
|
+
if (m === null || Number(m[1]) < 1 || Number(m[1]) > k) out.push(`${at}: depends on ${dep}, which is not an earlier batch`);
|
|
604
|
+
}
|
|
605
|
+
// 16: documentation stands alone (production paths).
|
|
606
|
+
const production = b.steps.flatMap((s) => s.anchors.production).map((a) => pathOf(a, ctx)).filter((p): p is string => p !== undefined);
|
|
607
|
+
const docs = production.filter(isDocPath);
|
|
608
|
+
if ((docs.length > 0 && !b.documentation) || (b.documentation && docs.length < production.length)) {
|
|
609
|
+
out.push(`${at}: documentation and code in one batch`);
|
|
610
|
+
}
|
|
611
|
+
// 20, 21: the code elements.
|
|
612
|
+
if (!b.documentation && b.elements.length === 0) out.push(`${at}: no code element`);
|
|
613
|
+
b.elements.forEach((e, i) => {
|
|
614
|
+
if (e.signature.length > MAX_SIGNATURE) out.push(`${at}: element ${i + 1} is longer than ${MAX_SIGNATURE} characters`);
|
|
615
|
+
if (e.signature.includes("{")) out.push(`${at}: element ${i + 1} holds a body`);
|
|
616
|
+
});
|
|
617
|
+
return out;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function traceProblems(a: PlanAnswer, ctx: PlanCheckContext): string[] {
|
|
621
|
+
const out: string[] = [];
|
|
622
|
+
// 8: every source id carried by a test.
|
|
623
|
+
const carried = new Set(a.batches.flatMap((b) => b.steps.flatMap((s) => s.tests.flatMap((t) => t.ids))));
|
|
624
|
+
for (const id of ctx.sourceIds) if (!carried.has(id)) out.push(`${id}: no test carries it`);
|
|
625
|
+
// 9: every source id owned by code.
|
|
626
|
+
const rows = new Map<string, number>();
|
|
627
|
+
for (const t of a.traceability) {
|
|
628
|
+
// 28: an owner names a type or a member, never a path.
|
|
629
|
+
for (const o of t.owners) if (OWNER_PATH.test(o)) out.push(`traceability: owner "${o}" is a path, name the type or member`);
|
|
630
|
+
if (!ctx.sourceIds.includes(t.id)) { out.push(`traceability: ${t.id} is not an id of the source`); continue; }
|
|
631
|
+
if (rows.has(t.id)) { out.push(`traceability: ${t.id} appears twice`); continue; }
|
|
632
|
+
rows.set(t.id, t.owners.filter((o) => o !== "").length);
|
|
633
|
+
}
|
|
634
|
+
for (const id of ctx.sourceIds) if ((rows.get(id) ?? 0) === 0) out.push(`${id}: no code owner`);
|
|
635
|
+
return out;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
function designRuleProblems(a: PlanAnswer): string[] {
|
|
639
|
+
const out: string[] = [];
|
|
640
|
+
const applied = new Set(a.batches.flatMap((b) => b.design.appliedRules));
|
|
641
|
+
for (const id of DESIGN_RULE_IDS) {
|
|
642
|
+
const na = a.nonApplicable.filter((n) => n.id === id);
|
|
643
|
+
if (applied.has(id) && na.length > 0) out.push(`${id}: applied and non-applicable`);
|
|
644
|
+
else if (!applied.has(id) && na.length === 0) out.push(`${id}: neither applied nor non-applicable`);
|
|
645
|
+
else if (na.length > 1) out.push(`${id}: non-applicable twice`);
|
|
646
|
+
else if (na.length === 1 && na[0].reason.length < MIN_NA_REASON) out.push(`${id}: N/A without a reason`);
|
|
647
|
+
}
|
|
648
|
+
return out;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/** 17: two batches sharing an anchor path are ordered, directly or through others. */
|
|
652
|
+
function sharedAnchorProblems(a: PlanAnswer, ctx: PlanCheckContext): string[] {
|
|
653
|
+
const out: string[] = [];
|
|
654
|
+
const before: Array<Set<number>> = [];
|
|
655
|
+
a.batches.forEach((b, k) => {
|
|
656
|
+
const reach = new Set<number>();
|
|
657
|
+
for (const dep of b.dependsOn) {
|
|
658
|
+
const m = /^F(\d+)$/.exec(dep);
|
|
659
|
+
const i = m === null ? -1 : Number(m[1]) - 1;
|
|
660
|
+
if (i < 0 || i >= k) continue;
|
|
661
|
+
reach.add(i);
|
|
662
|
+
for (const x of before[i]) reach.add(x);
|
|
663
|
+
}
|
|
664
|
+
before.push(reach);
|
|
665
|
+
});
|
|
666
|
+
const paths = a.batches.map((b) => new Set(b.steps.flatMap(allAnchors).map((x) => pathOf(x, ctx)).filter((p): p is string => p !== undefined)));
|
|
667
|
+
for (let k = 0; k < paths.length; k++) {
|
|
668
|
+
for (let m = k + 1; m < paths.length; m++) {
|
|
669
|
+
const shared = [...paths[k]].filter((p) => paths[m].has(p)).sort();
|
|
670
|
+
if (shared.length > 0 && !before[m].has(k)) out.push(`${batchLabel(a.batches[k], k)} and ${batchLabel(a.batches[m], m)} share ${shared[0]} and neither depends on the other`);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
return out;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function changeProblems(a: PlanAnswer, ctx: PlanCheckContext): string[] {
|
|
677
|
+
if (ctx.kind !== "change") return [];
|
|
678
|
+
const out: string[] = [];
|
|
679
|
+
const tests = a.batches.flatMap((b) => b.steps.flatMap((s, j) => s.tests.map((t) => ({ t, first: j === 0 }))));
|
|
680
|
+
// 22: every pinned behaviour keeps its pinned test.
|
|
681
|
+
for (const name of ctx.pinned) {
|
|
682
|
+
const n = name.trim();
|
|
683
|
+
if (!tests.some(({ t }) => t.level === "pinned" && t.name === n)) out.push(`pinned test ${n} is not in the plan`);
|
|
684
|
+
}
|
|
685
|
+
// 23: every unpinned row gets a characterisation test, first in its batch.
|
|
686
|
+
for (const u of ctx.unpinned) {
|
|
687
|
+
const covering = tests.filter(({ t }) => t.covers.includes(u));
|
|
688
|
+
if (covering.length === 0) out.push(`${u}: no characterisation test`);
|
|
689
|
+
else if (!covering.some(({ first }) => first)) out.push(`${u}: its test is not in the first step`);
|
|
690
|
+
}
|
|
691
|
+
return out;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function capped(problems: readonly string[]): string[] {
|
|
695
|
+
if (problems.length <= MAX_PROBLEMS) return [...problems];
|
|
696
|
+
return [...problems.slice(0, MAX_PROBLEMS), `… ${problems.length - MAX_PROBLEMS} more problems`];
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
export function checkPlanAnswer(value: unknown, ctx: PlanCheckContext): Checked<PlanAnswer> {
|
|
700
|
+
if (!isObj(value)) return { ok: false, problems: ["the answer is not an object"] };
|
|
701
|
+
const reader = new Reader();
|
|
702
|
+
const read = readAnswer(value, reader);
|
|
703
|
+
if (reader.problems.length > 0) return { ok: false, problems: capped(reader.problems) };
|
|
704
|
+
const a = mended(trimmed(read), ctx);
|
|
705
|
+
const problems: string[] = [];
|
|
706
|
+
// 24: the plan's own fields.
|
|
707
|
+
if (a.feature === "") problems.push("feature is empty");
|
|
708
|
+
else if (a.feature.length > MAX_FEATURE) problems.push(`feature is longer than ${MAX_FEATURE} characters`);
|
|
709
|
+
if (a.layers.filter((l) => l !== "").length === 0) problems.push("layers is empty");
|
|
710
|
+
problems.push(...cellProblems(cellsOf(a)));
|
|
711
|
+
// 2: the batch count.
|
|
712
|
+
if (a.batches.length < 1 || a.batches.length > MAX_BATCHES) {
|
|
713
|
+
problems.push(`between 1 and ${MAX_BATCHES} batches, not ${a.batches.length}`);
|
|
714
|
+
}
|
|
715
|
+
// 6: test names unique across the plan.
|
|
716
|
+
const names = new Map<string, string>();
|
|
717
|
+
a.batches.forEach((b, k) => b.steps.forEach((s, j) => s.tests.forEach((t, m) => {
|
|
718
|
+
if (t.name === "") return;
|
|
719
|
+
const first = names.get(t.name);
|
|
720
|
+
if (first !== undefined) problems.push(`${testLabel(b, k, j, m)}: the name repeats ${first}`);
|
|
721
|
+
else names.set(t.name, testLabel(b, k, j, m));
|
|
722
|
+
})));
|
|
723
|
+
const inventoryPaths = new Set(ctx.refPaths.values());
|
|
724
|
+
a.batches.forEach((b, k) => problems.push(...batchProblems(b, k, ctx, inventoryPaths)));
|
|
725
|
+
problems.push(...traceProblems(a, ctx));
|
|
726
|
+
problems.push(...designRuleProblems(a));
|
|
727
|
+
problems.push(...sharedAnchorProblems(a, ctx));
|
|
728
|
+
// 18: reuse names shown entries.
|
|
729
|
+
for (const ref of a.reuse) if (!ctx.shownRefs.has(ref)) problems.push(`reuse: ${ref} is not an inventory entry shown`);
|
|
730
|
+
// 19: design rows.
|
|
731
|
+
a.design.forEach((d, i) => {
|
|
732
|
+
if (d.batch < 1 || d.batch > a.batches.length) problems.push(`${designRow(d, i)}: batch ${d.batch} is not a batch of the plan`);
|
|
733
|
+
for (const id of d.ids) if (!ctx.sourceIds.includes(id)) problems.push(`${designRow(d, i)}: ${id} is not an id of the source`);
|
|
734
|
+
});
|
|
735
|
+
problems.push(...changeProblems(a, ctx));
|
|
736
|
+
if (problems.length > 0) return { ok: false, problems: capped(problems) };
|
|
737
|
+
return { ok: true, value: a };
|
|
738
|
+
}
|