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,48 @@
|
|
|
1
|
+
// Every verdict file of the work folder (one listing per code folder, hidden folders skipped as the harness's
|
|
2
|
+
// learning script skips them), read as VerdictSource for collectLearnRows: what /dev-learn's backlog and the
|
|
3
|
+
// shared memory's harvest after a GAPS verdict both read. It reads only; a file that cannot be read becomes a
|
|
4
|
+
// warning, never a failure.
|
|
5
|
+
import type { Files } from "../ports.ts";
|
|
6
|
+
import type { WorkFolder } from "./resolve-work-folder.ts";
|
|
7
|
+
import { LEARN_FILE } from "../../domain/shared-memory/verdict-rows.ts";
|
|
8
|
+
import type { VerdictSource } from "../../domain/shared-memory/verdict-rows.ts";
|
|
9
|
+
|
|
10
|
+
export const WORK_LIST_CAP = 1000;
|
|
11
|
+
export const FOLDER_LIST_CAP = 500;
|
|
12
|
+
|
|
13
|
+
const firstLine = (e: unknown): string => (e instanceof Error ? e.message : String(e)).split("\n")[0];
|
|
14
|
+
const bare = (entry: string): string => entry.replace(/\/+$/, "");
|
|
15
|
+
|
|
16
|
+
async function listOrEmpty(files: Pick<Files, "list">, path: string, cap: number): Promise<string[]> {
|
|
17
|
+
try {
|
|
18
|
+
return await files.list(path, cap);
|
|
19
|
+
} catch {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function readVerdictSources(
|
|
25
|
+
files: Pick<Files, "read" | "list">, work: Pick<WorkFolder, "folder" | "vfsPath">,
|
|
26
|
+
): Promise<{ sources: VerdictSource[]; warnings: string[] }> {
|
|
27
|
+
const warnings: string[] = [];
|
|
28
|
+
const sources: VerdictSource[] = [];
|
|
29
|
+
if (work.vfsPath === null) return { sources, warnings };
|
|
30
|
+
const entries = await listOrEmpty(files, work.vfsPath, WORK_LIST_CAP);
|
|
31
|
+
for (const code of entries.map(bare).filter((e) => e !== "" && !e.startsWith("."))) {
|
|
32
|
+
const names = (await listOrEmpty(files, `${work.vfsPath}/${code}`, FOLDER_LIST_CAP)).map(bare);
|
|
33
|
+
if (names.length >= FOLDER_LIST_CAP) {
|
|
34
|
+
warnings.push(`${work.folder}/${code}/ lists ${FOLDER_LIST_CAP} entries or more: later files are not read`);
|
|
35
|
+
}
|
|
36
|
+
for (const name of names.filter((n) => LEARN_FILE.test(n))) {
|
|
37
|
+
try {
|
|
38
|
+
sources.push({ code, name, text: await files.read(`${work.vfsPath}/${code}/${name}`) });
|
|
39
|
+
} catch (error) {
|
|
40
|
+
warnings.push(`${work.folder}/${code}/${name} cannot be read (${firstLine(error)})`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (entries.length >= WORK_LIST_CAP) {
|
|
45
|
+
warnings.push(`${work.folder}/ lists ${WORK_LIST_CAP} entries or more: later folders are not read`);
|
|
46
|
+
}
|
|
47
|
+
return { sources, warnings };
|
|
48
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// The bodies of run_tests and run_build, the two tools a writing role of a dev step is offered in
|
|
2
|
+
// place of shell_command for its test runs and builds. Each runs one command of the pack, after the
|
|
3
|
+
// guard chain (shared/domain/dev/tool-guards.ts): the pack's own command or nothing (the integration
|
|
4
|
+
// rule of test-commands.ts, plain values in its placeholders), never a restore, never a command the
|
|
5
|
+
// step's rules deny. The whole output goes to a log file; the model gets its tail and the log's path.
|
|
6
|
+
// A refusal or a command that cannot run comes back as `{ok: false}`, never thrown: the tool's
|
|
7
|
+
// result is what the model reads. The tools themselves are built in
|
|
8
|
+
// shared/infrastructure/orkeon/script-tools.ts.
|
|
9
|
+
import type { Files, Shell, ShellResult } from "../ports.ts";
|
|
10
|
+
import type { PermissionRule } from "../../domain/agent-policy/permission.ts";
|
|
11
|
+
import type { RepoPackCommands } from "../../domain/dev/repo-pack.ts";
|
|
12
|
+
import { checkValidation } from "../../domain/dev/test-commands.ts";
|
|
13
|
+
import { buildCommandFor, coldTree, isRestore } from "../../domain/dev/build-commands.ts";
|
|
14
|
+
import { outputTail, runGuards, shellRuleGuard, stringArgument } from "../../domain/dev/tool-guards.ts";
|
|
15
|
+
import { failedTests } from "../../domain/dev/test-output.ts";
|
|
16
|
+
import type { Guard } from "../../domain/dev/tool-guards.ts";
|
|
17
|
+
|
|
18
|
+
export const RUN_TESTS_TIMEOUT_SECONDS = 600;
|
|
19
|
+
export const RUN_BUILD_TIMEOUT_SECONDS = 900;
|
|
20
|
+
|
|
21
|
+
/** What a run_tests or run_build call hands back to the model. */
|
|
22
|
+
export type WrappedRun =
|
|
23
|
+
| {
|
|
24
|
+
ok: true;
|
|
25
|
+
command: string;
|
|
26
|
+
exit: number;
|
|
27
|
+
timedOut: boolean;
|
|
28
|
+
/** run_build only: true when a red build on a cold tree made it restore once and build again. */
|
|
29
|
+
restored?: boolean;
|
|
30
|
+
/** run_tests only: the failed tests the output names (TAP `not ok`, pytest FAILED, dotnet Failed…), at most 20,
|
|
31
|
+
* so the role sees which tests failed without opening the log. */
|
|
32
|
+
failed?: string[];
|
|
33
|
+
/** At most 15 lines and 1 500 characters of the last command's output. */
|
|
34
|
+
tail: string;
|
|
35
|
+
/** The whole output, `/workspace/…`; null when it could not be written. */
|
|
36
|
+
log: string | null;
|
|
37
|
+
}
|
|
38
|
+
| { ok: false; refused: string };
|
|
39
|
+
|
|
40
|
+
/** What the tools are set up with, once the step knows its pack. */
|
|
41
|
+
export interface WrappedToolsSetup {
|
|
42
|
+
commands: RepoPackCommands;
|
|
43
|
+
/** The rules the step runs under: a shell command one of them denies is never run. */
|
|
44
|
+
rules: readonly PermissionRule[];
|
|
45
|
+
/** Where the logs go, e.g. `/workspace/todo/<code>/logs`. */
|
|
46
|
+
logFolder: string;
|
|
47
|
+
/** The batch, in front of each log's name (`F2-run_tests-1.log`): the batches of a parallel wave share no log name. */
|
|
48
|
+
batch?: string;
|
|
49
|
+
/** The step restored the tree itself already: run_build then never restores a cold tree again. */
|
|
50
|
+
restored?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface WrappedTools {
|
|
54
|
+
runTests(input: unknown): Promise<WrappedRun>;
|
|
55
|
+
runBuild(input: unknown): Promise<WrappedRun>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const firstLine = (error: unknown): string => (error instanceof Error ? error.message : String(error)).split("\n")[0];
|
|
59
|
+
|
|
60
|
+
function output(command: string, result: ShellResult): string {
|
|
61
|
+
return [`$ ${command}`, `exit ${result.exitCode}${result.timedOut === true ? " (timed out)" : ""}`,
|
|
62
|
+
result.stdout.trimEnd(), result.stderr.trimEnd()].filter((l) => l !== "").join("\n");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createWrappedTools(deps: { shell: Pick<Shell, "run">; files: Pick<Files, "write"> }, setup: WrappedToolsSetup): WrappedTools {
|
|
66
|
+
let runs = 0;
|
|
67
|
+
let restoreTried = setup.restored === true; // the one restore of the step, whatever came of it
|
|
68
|
+
const notRestore: Guard<string> = (command) =>
|
|
69
|
+
isRestore(command, setup.commands) ? `'${command}' restores: no role restores, the step did it once` : null;
|
|
70
|
+
const shellGuards: ReadonlyArray<Guard<string>> = [notRestore, shellRuleGuard(setup.rules)];
|
|
71
|
+
|
|
72
|
+
async function writeLog(tool: string, text: string): Promise<string | null> {
|
|
73
|
+
runs += 1;
|
|
74
|
+
const path = `${setup.logFolder}/${setup.batch === undefined ? "" : `${setup.batch}-`}${tool}-${runs}.log`;
|
|
75
|
+
try {
|
|
76
|
+
await deps.files.write(path, `${text}\n`);
|
|
77
|
+
return path;
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Runs `command`, or the reason it could not run. */
|
|
84
|
+
async function run(command: string, timeoutSeconds: number): Promise<ShellResult | string> {
|
|
85
|
+
try {
|
|
86
|
+
return await deps.shell.run(command, { timeoutSeconds });
|
|
87
|
+
} catch (error) {
|
|
88
|
+
return `not run: ${firstLine(error)}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
async runTests(input) {
|
|
94
|
+
const arg = stringArgument(input, "command", true);
|
|
95
|
+
if ("refused" in arg) return { ok: false, refused: arg.refused };
|
|
96
|
+
const check = checkValidation(arg.value as string, setup.commands);
|
|
97
|
+
if (!check.ok) return { ok: false, refused: check.reason };
|
|
98
|
+
const refusal = runGuards(shellGuards, check.command);
|
|
99
|
+
if (refusal !== null) return { ok: false, refused: refusal };
|
|
100
|
+
const result = await run(check.command, RUN_TESTS_TIMEOUT_SECONDS);
|
|
101
|
+
if (typeof result === "string") return { ok: false, refused: result };
|
|
102
|
+
return {
|
|
103
|
+
ok: true, command: check.command, exit: result.exitCode, timedOut: result.timedOut === true,
|
|
104
|
+
failed: failedTests(`${result.stdout}\n${result.stderr}`),
|
|
105
|
+
tail: outputTail(result.stdout, result.stderr), log: await writeLog("run_tests", output(check.command, result)),
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
async runBuild(input) {
|
|
110
|
+
const arg = stringArgument(input, "project", false);
|
|
111
|
+
if ("refused" in arg) return { ok: false, refused: arg.refused };
|
|
112
|
+
const build = buildCommandFor(setup.commands, arg.value);
|
|
113
|
+
if (!build.ok) return { ok: false, refused: build.reason };
|
|
114
|
+
const refusal = runGuards(shellGuards, build.command);
|
|
115
|
+
if (refusal !== null) return { ok: false, refused: refusal };
|
|
116
|
+
const first = await run(build.command, RUN_BUILD_TIMEOUT_SECONDS);
|
|
117
|
+
if (typeof first === "string") return { ok: false, refused: first };
|
|
118
|
+
const log = [output(build.command, first)];
|
|
119
|
+
let last = first;
|
|
120
|
+
let restored = false;
|
|
121
|
+
const restore = setup.commands.restore?.trim();
|
|
122
|
+
if (!restoreTried && first.exitCode !== 0 && first.timedOut !== true && restore && coldTree(`${first.stdout}\n${first.stderr}`)) {
|
|
123
|
+
restoreTried = true;
|
|
124
|
+
// The one restore: the tree was never restored, so no flag of the pack's build can pass.
|
|
125
|
+
const denied = shellRuleGuard(setup.rules)(restore);
|
|
126
|
+
const restoring = denied === null ? await run(restore, RUN_BUILD_TIMEOUT_SECONDS) : denied;
|
|
127
|
+
if (typeof restoring === "string") {
|
|
128
|
+
log.push(`restore not run: ${restoring}`);
|
|
129
|
+
} else {
|
|
130
|
+
log.push(output(restore, restoring));
|
|
131
|
+
if (restoring.exitCode === 0) {
|
|
132
|
+
restored = true;
|
|
133
|
+
const again = await run(build.command, RUN_BUILD_TIMEOUT_SECONDS);
|
|
134
|
+
if (typeof again === "string") log.push(again);
|
|
135
|
+
else { log.push(output(build.command, again)); last = again; }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
ok: true, command: build.command, exit: last.exitCode, timedOut: last.timedOut === true, restored,
|
|
141
|
+
tail: outputTail(last.stdout, last.stderr), log: await writeLog("run_build", log.join("\n\n")),
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The extra tools the main agent may use (the `tools.extra` setting), read from
|
|
2
|
+
// /config and checked against the tools the host registers. A tool whose MCP
|
|
3
|
+
// server did not connect, whose plugin did not load, or whose name is mistyped is
|
|
4
|
+
// left out of the catalogue: Orkeon fails the act call of an agent that names a
|
|
5
|
+
// tool the host does not register (UnknownToolError). A setting that cannot be read
|
|
6
|
+
// configures no tool and says why: the callers report it, and the stored rules on
|
|
7
|
+
// extra tools stay as written, dormant (permission-rules.ts).
|
|
8
|
+
|
|
9
|
+
import type { ToolCatalogue } from "./ports.ts";
|
|
10
|
+
import { CONFIG_FILE_PATH } from "./config-store.ts";
|
|
11
|
+
import type { ConfigStore } from "./config-store.ts";
|
|
12
|
+
import { EXTRA_TOOLS_CONFIG_KEY, parseExtraTools } from "../domain/agent-policy/extra-tools.ts";
|
|
13
|
+
import type { ExtraToolsParse } from "../domain/agent-policy/extra-tools.ts";
|
|
14
|
+
import type { ExtraTool } from "../domain/agent-policy/permission.ts";
|
|
15
|
+
|
|
16
|
+
/** The setting as read: its entries, or why it could not be read. */
|
|
17
|
+
export interface ExtraToolsRead extends ExtraToolsParse {
|
|
18
|
+
/** Why the setting could not be read; it then configures no tool, which the caller reports. */
|
|
19
|
+
unreadable?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The configured extra tools; an unreadable setting configures none, and says why. The
|
|
23
|
+
* config store reads a settings file it cannot read or parse as empty: an unset
|
|
24
|
+
* setting is told apart from one that file may hold. */
|
|
25
|
+
export async function readExtraTools(config: Pick<ConfigStore, "readValue" | "readFile">): Promise<ExtraToolsRead> {
|
|
26
|
+
try {
|
|
27
|
+
const { value, source } = await config.readValue(EXTRA_TOOLS_CONFIG_KEY);
|
|
28
|
+
if (source === "unset" && (await config.readFile()).malformed) {
|
|
29
|
+
return { tools: [], invalid: [], unreadable: `${CONFIG_FILE_PATH} could not be read or parsed` };
|
|
30
|
+
}
|
|
31
|
+
return parseExtraTools(value);
|
|
32
|
+
} catch (e: unknown) {
|
|
33
|
+
return { tools: [], invalid: [], unreadable: String((e as { message?: unknown })?.message ?? e) };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ExtraToolsResolution {
|
|
38
|
+
/** Configured and registered, each under the name the host registers it by
|
|
39
|
+
* (found case-insensitively, as Orkeon finds it): what the catalogue may offer. */
|
|
40
|
+
present: ExtraTool[];
|
|
41
|
+
/** Configured, but no tool of the host answers to the name. */
|
|
42
|
+
missing: ExtraTool[];
|
|
43
|
+
/** Entries of the setting that do not parse, as written. */
|
|
44
|
+
invalid: string[];
|
|
45
|
+
/** Why the setting could not be read, when it could not: no extra tool is configured. */
|
|
46
|
+
unreadable?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The configured extra tools, split by whether the host registers them. A
|
|
50
|
+
* registered one takes the registered name: the catalogue offers it, and the rules
|
|
51
|
+
* name it, as the host spells it. */
|
|
52
|
+
export async function resolveExtraTools(deps: {
|
|
53
|
+
config: Pick<ConfigStore, "readValue" | "readFile">;
|
|
54
|
+
catalogue: Pick<ToolCatalogue, "find">;
|
|
55
|
+
}): Promise<ExtraToolsResolution> {
|
|
56
|
+
const { tools, invalid, unreadable } = await readExtraTools(deps.config);
|
|
57
|
+
const present: ExtraTool[] = [];
|
|
58
|
+
const missing: ExtraTool[] = [];
|
|
59
|
+
for (const tool of tools) {
|
|
60
|
+
const registered = deps.catalogue.find(tool.name);
|
|
61
|
+
if (registered === undefined) missing.push(tool);
|
|
62
|
+
else present.push({ ...tool, name: registered });
|
|
63
|
+
}
|
|
64
|
+
return { present, missing, invalid, ...(unreadable === undefined ? {} : { unreadable }) };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Every configured name, registered or not: the names a permission rule may use. */
|
|
68
|
+
export function configuredNames(extras: Pick<ExtraToolsResolution, "present" | "missing">): string[] {
|
|
69
|
+
return [...extras.present, ...extras.missing].map((t) => t.name);
|
|
70
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// A batch's worktree over the Shell port: created on its own branch under /workspace/.orkeon/worktrees/<name>,
|
|
2
|
+
// removed with its branch once its work is merged, and its branch merged into the work branch by fast-forward
|
|
3
|
+
// once its audit is VALID. The removal is refused while the worktree holds uncommitted or untracked files or
|
|
4
|
+
// its branch commits the work branch lacks, as the harness's `worktree-create.sh --remove`. Never `--force`,
|
|
5
|
+
// never a push: the plan's close pushes once (crews/dev-batches/application/plan-close.ts).
|
|
6
|
+
// The worktree is created with `git worktree add --relative-paths` (git 2.48 and later, no fallback: an older git
|
|
7
|
+
// fails the create with its own message), so that its `.git` file names the main git dir relatively and git works in
|
|
8
|
+
// it inside the runtime's sandbox, where the host's absolute path does not exist (Orkeon/orkeon#188).
|
|
9
|
+
// Called by a parallel /dev-batches (crews/dev-batches/application/run-wave.ts), whose batch agents each run
|
|
10
|
+
// under their worktree as a working root.
|
|
11
|
+
import type { Shell } from "../ports.ts";
|
|
12
|
+
import { shellUnsafe } from "../../domain/git/close.ts";
|
|
13
|
+
import {
|
|
14
|
+
gitBranchDelete, gitBranchExists, gitCommitsNotIn, gitIsIgnored, gitIsMergedInto, gitWorktreeAdd, gitWorktreeHead,
|
|
15
|
+
gitWorktreeRemove, gitWorktreeStatus,
|
|
16
|
+
worktreePlace,
|
|
17
|
+
} from "../../domain/git/worktree.ts";
|
|
18
|
+
import type { WorktreePlace } from "../../domain/git/worktree.ts";
|
|
19
|
+
import { gitReason, runGit } from "./commit-files.ts";
|
|
20
|
+
import { mergeFastForward } from "./merge-batch.ts";
|
|
21
|
+
import type { MergeOutcome } from "./merge-batch.ts";
|
|
22
|
+
|
|
23
|
+
export type WorktreeOutcome =
|
|
24
|
+
| { ok: true; place: WorktreePlace; line: string }
|
|
25
|
+
| { ok: false; line: string };
|
|
26
|
+
|
|
27
|
+
const refused = (line: string): { ok: false; line: string } => ({ ok: false, line: `refused: ${line}` });
|
|
28
|
+
|
|
29
|
+
// A leading `-` would be read by git as an option (`--detach` for a base).
|
|
30
|
+
function unsafeOf(values: readonly string[]): string | null {
|
|
31
|
+
const bad = values.filter((v) => shellUnsafe(v) || v.startsWith("-"));
|
|
32
|
+
return bad.length === 0 ? null : `${bad.map((v) => `'${v}'`).join(", ")} cannot go through the shell`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Creates worktree `name` on a new branch `branch` from `base`. */
|
|
36
|
+
export async function createBatchWorktree(
|
|
37
|
+
shell: Pick<Shell, "run">, req: { name: string; branch: string; base: string },
|
|
38
|
+
): Promise<WorktreeOutcome> {
|
|
39
|
+
const place = worktreePlace(req.name);
|
|
40
|
+
if (place === null) return refused(`'${req.name}' is not a worktree name (one folder: letters, digits, . _ -)`);
|
|
41
|
+
const unsafe = unsafeOf([req.branch, req.base]);
|
|
42
|
+
if (unsafe !== null) return refused(unsafe);
|
|
43
|
+
const exists = await runGit(shell, gitBranchExists(req.branch));
|
|
44
|
+
if (exists.exitCode === 0) return refused(`branch ${req.branch} exists already: remove it or choose another name`);
|
|
45
|
+
// Not ignored, the worktree would sit in the checkout's own status as an embedded repository.
|
|
46
|
+
const ignored = await runGit(shell, gitIsIgnored(place.path));
|
|
47
|
+
if (ignored.exitCode !== 0) {
|
|
48
|
+
return refused(`${place.path} is not ignored by git: add \`.orkeon/\` to .gitignore or .git/info/exclude first`);
|
|
49
|
+
}
|
|
50
|
+
const add = await runGit(shell, gitWorktreeAdd(place.path, req.branch, req.base));
|
|
51
|
+
if (add.exitCode !== 0) return { ok: false, line: `worktree ${place.path} not created: ${gitReason(add)}` };
|
|
52
|
+
return { ok: true, place, line: `✓ worktree ${place.path} on ${req.branch}, from ${req.base}` };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Removes worktree `name` and its branch once nothing in it is lost: no change, every commit in `into`. */
|
|
56
|
+
export async function removeBatchWorktree(
|
|
57
|
+
shell: Pick<Shell, "run">, req: { name: string; branch: string; into: string },
|
|
58
|
+
): Promise<WorktreeOutcome> {
|
|
59
|
+
const place = worktreePlace(req.name);
|
|
60
|
+
if (place === null) return refused(`'${req.name}' is not a worktree name (one folder: letters, digits, . _ -)`);
|
|
61
|
+
const unsafe = unsafeOf([req.branch, req.into]);
|
|
62
|
+
if (unsafe !== null) return refused(unsafe);
|
|
63
|
+
const status = await runGit(shell, gitWorktreeStatus(place.path));
|
|
64
|
+
if (status.exitCode !== 0) return refused(`the state of ${place.path} could not be read (${gitReason(status)})`);
|
|
65
|
+
const changed = status.stdout.split("\n").filter((l) => l.trim() !== "").length;
|
|
66
|
+
if (changed > 0) return refused(`${place.path} holds ${changed} uncommitted or untracked file(s): commit or discard them first`);
|
|
67
|
+
// The worktree must stand on its branch: commits on another HEAD would go with it, the merge check not seeing them.
|
|
68
|
+
const head = await runGit(shell, gitWorktreeHead(place.path));
|
|
69
|
+
if (head.exitCode !== 0 || head.stdout.trim() !== `refs/heads/${req.branch}`) {
|
|
70
|
+
return refused(`${place.path} is not on ${req.branch} (${head.exitCode === 0 ? head.stdout.trim() : "a detached HEAD"}): check it out there first`);
|
|
71
|
+
}
|
|
72
|
+
const merged = await runGit(shell, gitIsMergedInto(req.branch, req.into));
|
|
73
|
+
if (merged.exitCode === 1) {
|
|
74
|
+
const count = await runGit(shell, gitCommitsNotIn(req.branch, req.into));
|
|
75
|
+
const n = count.exitCode === 0 ? count.stdout.trim() : "?";
|
|
76
|
+
return refused(`${req.branch} holds ${n} commit(s) not in ${req.into}: merge it first`);
|
|
77
|
+
}
|
|
78
|
+
if (merged.exitCode !== 0) return refused(`whether ${req.branch} is merged into ${req.into} could not be read (${gitReason(merged)})`);
|
|
79
|
+
const remove = await runGit(shell, gitWorktreeRemove(place.path));
|
|
80
|
+
if (remove.exitCode !== 0) return { ok: false, line: `worktree ${place.path} not removed: ${gitReason(remove)}` };
|
|
81
|
+
const branch = await runGit(shell, gitBranchDelete(req.branch));
|
|
82
|
+
return branch.exitCode === 0
|
|
83
|
+
? { ok: true, place, line: `✓ worktree ${place.path} and branch ${req.branch} removed` }
|
|
84
|
+
: { ok: true, place, line: `✓ worktree ${place.path} removed; branch ${req.branch} kept (${gitReason(branch)})` };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Merges a batch's branch into the work branch (`--ff-only`, rebased in its worktree when needed) on a VALID verdict only. */
|
|
88
|
+
export async function mergeValidBatch(
|
|
89
|
+
shell: Pick<Shell, "run">, req: { batch: string; verdict: string | null; branch: string; workBranch: string; name: string },
|
|
90
|
+
): Promise<MergeOutcome> {
|
|
91
|
+
if (req.verdict !== "VALID") {
|
|
92
|
+
return { merged: false, line: `not merged: ${req.batch}'s audit is ${req.verdict ?? "missing"}, not VALID`, handOver: [] };
|
|
93
|
+
}
|
|
94
|
+
const place = worktreePlace(req.name);
|
|
95
|
+
if (place === null) return { merged: false, line: `not merged: '${req.name}' is not a worktree name`, handOver: [] };
|
|
96
|
+
return mergeFastForward(shell, { ref: req.branch, workBranch: req.workBranch, worktree: place.path });
|
|
97
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// The git close shared by /commit (crews/git-commit) and the dev close
|
|
2
|
+
// (shared/application/dev/close-batch.ts): git's identity checked before
|
|
3
|
+
// anything is spent, an explicit file list committed, the branch pushed, and the
|
|
4
|
+
// pull request handed over. The rules and the command lines live in
|
|
5
|
+
// shared/domain/git/close.ts; this file runs them through the Shell and Files ports.
|
|
6
|
+
|
|
7
|
+
import type { Files, Shell, ShellResult } from "../ports.ts";
|
|
8
|
+
import type { GitIdent, PrSummary } from "../../domain/git/close.ts";
|
|
9
|
+
import {
|
|
10
|
+
COMMIT_MESSAGE_FALLBACK, COMMIT_MESSAGE_FILE, GIT_COMMITTER_IDENT_COMMAND, GIT_IN_PROGRESS_PROBES, GIT_DEFAULT_BRANCH_COMMAND, GIT_HEAD_COMMAND, GIT_IDENT_COMMAND,
|
|
11
|
+
ghPrCreateCommand, gitAddCommand, gitCommitCommand, gitPushCommand, indexDeletedPaths, parseDefaultBranch,
|
|
12
|
+
parseGitIdent, prBodyPath, prSlug, renderPrBody, shellUnsafe,
|
|
13
|
+
} from "../../domain/git/close.ts";
|
|
14
|
+
import { WORKSPACE } from "../../domain/vfs.ts";
|
|
15
|
+
|
|
16
|
+
export type Step = { ok: true } | { ok: false; line: string };
|
|
17
|
+
|
|
18
|
+
function firstLine(text: unknown): string {
|
|
19
|
+
return String(text ?? "").split("\n").map((l) => l.trim()).find((l) => l.length > 0) ?? "";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Runs `command`; a runtime refusal (a throw) comes back as a failed result carrying its message. */
|
|
23
|
+
export async function runGit(shell: Pick<Shell, "run">, command: string): Promise<ShellResult> {
|
|
24
|
+
try {
|
|
25
|
+
return await shell.run(command);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return { stdout: "", stderr: `refused by the runtime: ${firstLine((e as Error)?.message ?? e)}`, exitCode: -1 };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The first line git gave for a failure. */
|
|
32
|
+
export const gitReason = (r: ShellResult): string => firstLine(r.stderr) || firstLine(r.stdout) || `exit ${r.exitCode}`;
|
|
33
|
+
|
|
34
|
+
export type IdentityCheck = { ok: true; ident: GitIdent } | { ok: false; detail: string };
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* git's own identity, author then committer (`git var`): the commit needs both.
|
|
38
|
+
* None, or a check that cannot run, is not ok; nothing is ever invented.
|
|
39
|
+
*/
|
|
40
|
+
export async function readIdentity(shell: Pick<Shell, "run">): Promise<IdentityCheck> {
|
|
41
|
+
let author: GitIdent | null = null;
|
|
42
|
+
for (const command of [GIT_IDENT_COMMAND, GIT_COMMITTER_IDENT_COMMAND]) {
|
|
43
|
+
const r = await runGit(shell, command);
|
|
44
|
+
const ident = r.exitCode === 0 ? parseGitIdent(r.stdout) : null;
|
|
45
|
+
if (ident === null) return { ok: false, detail: r.exitCode === 0 ? `${command}: no email in its answer` : gitReason(r) };
|
|
46
|
+
author ??= ident;
|
|
47
|
+
}
|
|
48
|
+
return { ok: true, ident: author! };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** `note`: what is left to do by hand once the commit is made (the message file it could not remove). */
|
|
52
|
+
export type CommitOutcome = { ok: true; hash: string; note?: string } | { ok: false; line: string };
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Stages and commits `files` alone, with `message` passed through a file (no
|
|
56
|
+
* shell escaping). `status` is the one the list was selected from: a path it
|
|
57
|
+
* shows gone from the index is left out of `git add`, which refuses it, and
|
|
58
|
+
* stays in the commit's path list, which takes it from HEAD.
|
|
59
|
+
*/
|
|
60
|
+
export async function commitFiles(
|
|
61
|
+
deps: { shell: Pick<Shell, "run">; files: Pick<Files, "write"> },
|
|
62
|
+
req: { files: readonly string[]; status: string; message: string },
|
|
63
|
+
): Promise<CommitOutcome> {
|
|
64
|
+
if (req.files.length === 0) return { ok: false, line: "nothing to commit" };
|
|
65
|
+
const unsafe = req.files.filter(shellUnsafe);
|
|
66
|
+
if (unsafe.length > 0) return { ok: false, line: `cannot go through the shell: ${unsafe.join(", ")}` };
|
|
67
|
+
for (const probe of GIT_IN_PROGRESS_PROBES) {
|
|
68
|
+
const r = await runGit(deps.shell, probe);
|
|
69
|
+
if (r.exitCode === 0 && r.stdout.trim().length > 0) {
|
|
70
|
+
return { ok: false, line: "a merge or a cherry-pick is in progress: conclude it with git commit in a terminal" };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// The message is written before anything is staged: a write that fails leaves the index as it was.
|
|
74
|
+
const messageFile = await writeMessage(deps.files, req.message);
|
|
75
|
+
if (!messageFile.ok) return messageFile;
|
|
76
|
+
const gone = indexDeletedPaths(req.status);
|
|
77
|
+
const toAdd = req.files.filter((p) => !gone.includes(p));
|
|
78
|
+
if (toAdd.length > 0) {
|
|
79
|
+
const add = await runGit(deps.shell, gitAddCommand(toAdd));
|
|
80
|
+
if (add.exitCode !== 0) return { ok: false, line: `git add failed: ${gitReason(add)}` };
|
|
81
|
+
}
|
|
82
|
+
const commit = await runGit(deps.shell, gitCommitCommand(req.files, messageFile.path));
|
|
83
|
+
const note = messageFile.path === COMMIT_MESSAGE_FALLBACK ? await removeFallback(deps.shell) : null;
|
|
84
|
+
if (commit.exitCode !== 0) return { ok: false, line: `git commit failed: ${gitReason(commit)}${note === null ? "" : `; ${note}`}` };
|
|
85
|
+
const hash = (await runGit(deps.shell, GIT_HEAD_COMMAND)).stdout.trim();
|
|
86
|
+
return note === null ? { ok: true, hash } : { ok: true, hash, note };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Removes the message written under `.orkeon/`; a removal that fails is said, never silent (the file holds the message). */
|
|
90
|
+
async function removeFallback(shell: Pick<Shell, "run">): Promise<string | null> {
|
|
91
|
+
const rm = await runGit(shell, `rm -f ${COMMIT_MESSAGE_FALLBACK}`);
|
|
92
|
+
return rm.exitCode === 0 ? null : `${COMMIT_MESSAGE_FALLBACK} could not be removed (${gitReason(rm)}): remove it by hand`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The message under `.git/`, else - a linked worktree, whose `.git` is a file - under `.orkeon/`. */
|
|
96
|
+
async function writeMessage(files: Pick<Files, "write">, message: string): Promise<{ ok: true; path: string } | { ok: false; line: string }> {
|
|
97
|
+
let reason = "";
|
|
98
|
+
for (const path of [COMMIT_MESSAGE_FILE, COMMIT_MESSAGE_FALLBACK]) {
|
|
99
|
+
try {
|
|
100
|
+
await files.write(`${WORKSPACE}/${path}`, message);
|
|
101
|
+
return { ok: true, path };
|
|
102
|
+
} catch (e) {
|
|
103
|
+
reason = firstLine((e as Error)?.message ?? e);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return { ok: false, line: `the commit message could not be written (${COMMIT_MESSAGE_FILE}, ${COMMIT_MESSAGE_FALLBACK}): ${reason}` };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** `git push -u origin <branch>`; a refusal is said with git's line, nothing is forced. */
|
|
110
|
+
export async function pushBranch(shell: Pick<Shell, "run">, branch: string): Promise<Step> {
|
|
111
|
+
if (branch.trim().length === 0) return { ok: false, line: "not pushed: no branch is checked out (detached HEAD)" };
|
|
112
|
+
if (shellUnsafe(branch)) return { ok: false, line: `not pushed: the branch name '${branch}' cannot go through the shell` };
|
|
113
|
+
const r = await runGit(shell, gitPushCommand(branch));
|
|
114
|
+
return r.exitCode === 0 ? { ok: true } : { ok: false, line: `push refused, the commit stays local: ${gitReason(r)}` };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The remote's default branch, null when origin/HEAD is unset: never guessed. */
|
|
118
|
+
export async function defaultBranch(shell: Pick<Shell, "run">): Promise<string | null> {
|
|
119
|
+
const r = await runGit(shell, GIT_DEFAULT_BRANCH_COMMAND);
|
|
120
|
+
return r.exitCode === 0 ? parseDefaultBranch(r.stdout) : null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface PullRequest {
|
|
124
|
+
base: string | null;
|
|
125
|
+
head: string;
|
|
126
|
+
title: string;
|
|
127
|
+
/** The body file as the user reads it (the handed-over command names it). */
|
|
128
|
+
bodyFile: string;
|
|
129
|
+
/** The body itself, which the opener sends. */
|
|
130
|
+
body: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** The pull request opened by Orkeon Code itself: open-pull-request.ts, over the github tool.
|
|
134
|
+
* A throw is the reason it was not opened; the command is then handed over. */
|
|
135
|
+
export interface PullRequestOpener {
|
|
136
|
+
open(pr: PullRequest): Promise<{ url: string }>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface PullRequestHandOver {
|
|
140
|
+
/** The work folder: `folder` as the user reads it, `vfsPath` where it is written (null outside the mounts). */
|
|
141
|
+
work: { folder: string; vfsPath: string | null };
|
|
142
|
+
branch: string;
|
|
143
|
+
base: string | null;
|
|
144
|
+
title: string;
|
|
145
|
+
pushed: boolean;
|
|
146
|
+
/** `--pr` or `dev.prAuto`: open it rather than hand it over. */
|
|
147
|
+
open: boolean;
|
|
148
|
+
summary: PrSummary;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Writes `<work>/pr-<slug>/PR.md`, then opens the pull request through the seam, or prints the command. */
|
|
152
|
+
export async function handOverPullRequest(
|
|
153
|
+
deps: { files: Pick<Files, "write">; opener?: PullRequestOpener },
|
|
154
|
+
req: PullRequestHandOver,
|
|
155
|
+
): Promise<string[]> {
|
|
156
|
+
const slug = prSlug(req.branch);
|
|
157
|
+
const bodyFile = prBodyPath(req.work.folder, slug);
|
|
158
|
+
const lines: string[] = [];
|
|
159
|
+
const body = renderPrBody(req.summary);
|
|
160
|
+
if (req.work.vfsPath === null) {
|
|
161
|
+
lines.push(`the body could not be written (${req.work.folder} is outside the mounts): write ${bodyFile} first`);
|
|
162
|
+
} else {
|
|
163
|
+
// After the commit and the push: a body that cannot be written is said, never thrown.
|
|
164
|
+
try {
|
|
165
|
+
await deps.files.write(`${req.work.vfsPath.replace(/\/+$/, "")}/pr-${slug}/PR.md`, body);
|
|
166
|
+
lines.push(`pull request body: ${bodyFile}`);
|
|
167
|
+
} catch (e) {
|
|
168
|
+
lines.push(`⚠ the body could not be written (${firstLine((e as Error)?.message ?? e)}): write ${bodyFile} first`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const pr: PullRequest = { base: req.base, head: req.branch, title: req.title, bodyFile, body };
|
|
172
|
+
if (req.open && req.pushed && deps.opener !== undefined) {
|
|
173
|
+
try {
|
|
174
|
+
return [...lines, `✓ pull request opened: ${(await deps.opener.open(pr)).url}`];
|
|
175
|
+
} catch (e) {
|
|
176
|
+
lines.push(`✗ the pull request was not opened: ${firstLine((e as Error)?.message ?? e)}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
lines.push("to open the pull request, in a terminal:");
|
|
180
|
+
if (!req.pushed) lines.push(` ${gitPushCommand(req.branch)}`);
|
|
181
|
+
lines.push(` ${ghPrCreateCommand(pr)}`);
|
|
182
|
+
if (req.open && deps.opener === undefined) {
|
|
183
|
+
lines.push("the pull request is opened here only through the github tool, which this host does not offer: run the command above");
|
|
184
|
+
}
|
|
185
|
+
return lines;
|
|
186
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// The merge of a local batch branch into the work branch (R-16): fast-forward
|
|
2
|
+
// only. Refused while the batch has its own worktree: the branch, never pushed, is
|
|
3
|
+
// rebased there on the work branch and the fast-forward tried again; a conflict
|
|
4
|
+
// aborts the rebase and the merge is handed over. Without a worktree nothing is
|
|
5
|
+
// rewritten here (a rebase would check the batch branch out in the user's own
|
|
6
|
+
// checkout): the merge is handed over. Never a forced update, never a push.
|
|
7
|
+
// Reached through batch-worktree.ts (mergeValidBatch), which a parallel /dev-batches calls for each VALID batch.
|
|
8
|
+
|
|
9
|
+
import type { Shell } from "../ports.ts";
|
|
10
|
+
import {
|
|
11
|
+
GIT_CURRENT_BRANCH_COMMAND, gitMergeFfOnly, gitRebaseAbortIn, gitRebaseIn, isNotFastForward, shellUnsafe,
|
|
12
|
+
} from "../../domain/git/close.ts";
|
|
13
|
+
import { gitReason, runGit } from "./commit-files.ts";
|
|
14
|
+
|
|
15
|
+
export type MergeOutcome =
|
|
16
|
+
| { merged: true; rebased: boolean; line: string }
|
|
17
|
+
| { merged: false; line: string; handOver: string[] };
|
|
18
|
+
|
|
19
|
+
/** Merges `ref` into the checked-out `workBranch` by fast-forward, rebasing it in `worktree` when it has one. */
|
|
20
|
+
export async function mergeFastForward(
|
|
21
|
+
shell: Pick<Shell, "run">,
|
|
22
|
+
req: { ref: string; workBranch: string; worktree?: string },
|
|
23
|
+
): Promise<MergeOutcome> {
|
|
24
|
+
const merge = gitMergeFfOnly(req.ref);
|
|
25
|
+
// A leading `-` would be read by git as an option, as batch-worktree.ts refuses it.
|
|
26
|
+
const unsafe = [req.ref, req.workBranch, ...(req.worktree === undefined ? [] : [req.worktree])]
|
|
27
|
+
.filter((v) => shellUnsafe(v) || v.startsWith("-"));
|
|
28
|
+
if (unsafe.length > 0) {
|
|
29
|
+
return { merged: false, line: `not merged: ${unsafe.join(", ")} cannot go through the shell`, handOver: [merge] };
|
|
30
|
+
}
|
|
31
|
+
const current = (await runGit(shell, GIT_CURRENT_BRANCH_COMMAND)).stdout.trim();
|
|
32
|
+
if (current !== req.workBranch) {
|
|
33
|
+
return {
|
|
34
|
+
merged: false, line: `not merged: the checkout is on '${current || "a detached HEAD"}', not on ${req.workBranch}`,
|
|
35
|
+
handOver: [`git checkout ${req.workBranch}`, merge],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const first = await runGit(shell, merge);
|
|
39
|
+
if (first.exitCode === 0) return { merged: true, rebased: false, line: `${req.ref} merged into ${req.workBranch} (fast-forward)` };
|
|
40
|
+
// Only a refusal for not being a fast-forward is cured by a rebase: a dirty tree or an unknown ref is said as it is.
|
|
41
|
+
if (!isNotFastForward(first.stderr + first.stdout)) {
|
|
42
|
+
return { merged: false, line: `not merged: ${gitReason(first)}`, handOver: [merge] };
|
|
43
|
+
}
|
|
44
|
+
if (req.worktree === undefined) {
|
|
45
|
+
return {
|
|
46
|
+
merged: false,
|
|
47
|
+
line: `not merged: ${gitReason(first)}`,
|
|
48
|
+
handOver: [`git rebase ${req.workBranch} ${req.ref}`, `git checkout ${req.workBranch}`, merge],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const rebase = gitRebaseIn(req.worktree, req.workBranch);
|
|
52
|
+
const rebased = await runGit(shell, rebase);
|
|
53
|
+
if (rebased.exitCode !== 0) {
|
|
54
|
+
const abort = await runGit(shell, gitRebaseAbortIn(req.worktree));
|
|
55
|
+
const aborted = abort.exitCode === 0 ? "rebase aborted" : `rebase --abort failed too: ${gitReason(abort)}`;
|
|
56
|
+
return { merged: false, line: `not merged, the rebase stopped (${gitReason(rebased)}); ${aborted}`, handOver: [rebase, merge] };
|
|
57
|
+
}
|
|
58
|
+
const second = await runGit(shell, merge);
|
|
59
|
+
if (second.exitCode === 0) {
|
|
60
|
+
return { merged: true, rebased: true, line: `${req.ref} rebased on ${req.workBranch} and merged (fast-forward)` };
|
|
61
|
+
}
|
|
62
|
+
return { merged: false, line: `not merged after the rebase: ${gitReason(second)}`, handOver: [merge] };
|
|
63
|
+
}
|