orkeon-code 0.0.0-stage → 1.0.0-rc.2
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-runtime +10 -0
- package/.orkeon-version +1 -0
- package/LICENSE.md +21 -0
- package/NOTICE.md +17 -0
- package/README.fr.md +163 -0
- package/README.md +156 -2
- package/config/appsettings.anthropic.example.json +77 -0
- package/config/appsettings.example.json +71 -0
- package/config/appsettings.jev.example.json +131 -0
- package/config/appsettings.kev.example.json +133 -0
- package/config/appsettings.liquid.example.json +132 -0
- package/config/appsettings.ollama-whisper.example.json +93 -0
- package/config/appsettings.ollama.example.json +70 -0
- package/config/appsettings.whisper.example.json +32 -0
- package/mcp/whisper/README.md +294 -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 +1092 -0
- package/orkeon-code.mjs +71 -0
- package/orkeon-code.ps1 +939 -0
- package/package.json +58 -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 +559 -0
- package/src/commands/_lib/args.ts +194 -0
- package/src/commands/_lib/dev/dev-batches.ts +366 -0
- package/src/commands/_lib/dev/dev-implement.ts +185 -0
- package/src/commands/_lib/dev/dev-source.ts +61 -0
- package/src/commands/_lib/dev/dev.ts +341 -0
- package/src/commands/_lib/dev/markers.ts +7 -0
- package/src/commands/_lib/dev/messages.ts +112 -0
- package/src/commands/_lib/dev-step.ts +145 -0
- package/src/commands/_lib/dispatch.ts +254 -0
- package/src/commands/_lib/effort.ts +15 -0
- package/src/commands/_lib/git/branch.ts +94 -0
- package/src/commands/_lib/git/commit.ts +90 -0
- package/src/commands/_lib/git/diff.ts +107 -0
- package/src/commands/_lib/git/messages.ts +54 -0
- package/src/commands/_lib/git/review.ts +108 -0
- package/src/commands/_lib/memory/memory-admit.ts +148 -0
- package/src/commands/_lib/memory/memory.ts +52 -0
- package/src/commands/_lib/memory/messages.ts +32 -0
- package/src/commands/_lib/messages.ts +48 -0
- package/src/commands/_lib/pr-context.ts +32 -0
- package/src/commands/_lib/project/analyze.ts +24 -0
- package/src/commands/_lib/project/messages.ts +8 -0
- package/src/commands/_lib/session/export.ts +105 -0
- package/src/commands/_lib/session/messages.ts +87 -0
- package/src/commands/_lib/session/prompts.ts +4 -0
- package/src/commands/_lib/session/resume.ts +151 -0
- package/src/commands/_lib/session/tasks.ts +181 -0
- package/src/commands/_lib/settings/advisor.ts +75 -0
- package/src/commands/_lib/settings/agents.ts +137 -0
- package/src/commands/_lib/settings/choices.ts +8 -0
- package/src/commands/_lib/settings/config.ts +141 -0
- package/src/commands/_lib/settings/effort.ts +147 -0
- package/src/commands/_lib/settings/hooks.ts +50 -0
- package/src/commands/_lib/settings/messages.ts +408 -0
- package/src/commands/_lib/settings/mode.ts +100 -0
- package/src/commands/_lib/settings/model.ts +181 -0
- package/src/commands/_lib/settings/output-style.ts +39 -0
- package/src/commands/_lib/settings/permissions.ts +287 -0
- package/src/commands/_lib/settings/route.ts +63 -0
- package/src/commands/_lib/settings/session-config.ts +49 -0
- package/src/commands/_lib/settings/skills.ts +93 -0
- package/src/commands/_lib/settings/theme.ts +42 -0
- package/src/commands/_lib/speech/messages.ts +58 -0
- package/src/commands/_lib/speech/prompts.ts +4 -0
- package/src/commands/_lib/speech/say.ts +95 -0
- package/src/commands/_lib/speech/transcribe.ts +121 -0
- package/src/commands/_lib/speech/voice.ts +142 -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 +205 -0
- package/src/commands/_lib/status/messages.ts +100 -0
- package/src/commands/_lib/status/meta.ts +24 -0
- package/src/commands/_lib/status/status.ts +128 -0
- package/src/commands/_lib/status/usage-tools.ts +48 -0
- package/src/commands/_lib/status/usage.ts +128 -0
- package/src/commands/_lib/view.ts +34 -0
- package/src/commands/dev/dev-batches.cmd.ts +109 -0
- package/src/commands/dev/dev-learn.cmd.ts +29 -0
- package/src/commands/dev/dev-plan.cmd.ts +51 -0
- package/src/commands/dev/dev-spec.cmd.ts +54 -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 +62 -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 +45 -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 +18 -0
- package/src/commands/session/resume.cmd.ts +19 -0
- package/src/commands/session/rewind.cmd.ts +25 -0
- package/src/commands/session/summary.cmd.ts +27 -0
- package/src/commands/session/tasks.cmd.ts +46 -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 +19 -0
- package/src/commands/settings/effort.cmd.ts +19 -0
- package/src/commands/settings/fast.cmd.ts +18 -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 +21 -0
- package/src/commands/settings/output-style.cmd.ts +19 -0
- package/src/commands/settings/permissions.cmd.ts +25 -0
- package/src/commands/settings/proactive.cmd.ts +16 -0
- package/src/commands/settings/route.cmd.ts +16 -0
- package/src/commands/settings/skills.cmd.ts +17 -0
- package/src/commands/settings/theme.cmd.ts +14 -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 +4391 -0
- package/src/crews/_probe-shared-memory/domain/messages.ts +54 -0
- package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +188 -0
- package/src/crews/_probe-shared-memory/domain/prompts.ts +5 -0
- package/src/crews/_probe-shared-memory/probe.ork.ts +100 -0
- package/src/crews/advisor/application/messages.ts +4 -0
- package/src/crews/advisor/application/prompts.ts +4 -0
- package/src/crews/advisor/application/run-advisor.ts +41 -0
- package/src/crews/advisor/crew.ork.ts +44 -0
- package/src/crews/advisor/domain/advice.ts +119 -0
- package/src/crews/advisor/domain/messages.ts +8 -0
- package/src/crews/advisor/domain/prompts.ts +26 -0
- package/src/crews/agent-run/application/messages.ts +18 -0
- package/src/crews/agent-run/application/run-agent-run.ts +43 -0
- package/src/crews/agent-run/crew.ork.ts +67 -0
- package/src/crews/analyze/application/messages.ts +27 -0
- package/src/crews/analyze/application/prompts.ts +4 -0
- package/src/crews/analyze/application/run-analyze.ts +120 -0
- package/src/crews/analyze/crew.ork.ts +41 -0
- package/src/crews/analyze/domain/harvest.ts +269 -0
- package/src/crews/analyze/domain/prompts.ts +86 -0
- package/src/crews/code-review/application/lens-material.ts +24 -0
- package/src/crews/code-review/application/messages.ts +17 -0
- package/src/crews/code-review/application/prompts.ts +126 -0
- package/src/crews/code-review/application/review.ts +74 -0
- package/src/crews/code-review/application/run-code-review.ts +121 -0
- package/src/crews/code-review/crew.ork.ts +52 -0
- package/src/crews/code-review/domain/lenses.ts +154 -0
- package/src/crews/code-review/domain/messages.ts +25 -0
- package/src/crews/code-review/domain/prompts.ts +58 -0
- package/src/crews/code-review/domain/report.ts +58 -0
- package/src/crews/code-review/domain/scope.ts +106 -0
- package/src/crews/dev-batches/application/messages.ts +127 -0
- package/src/crews/dev-batches/application/plan-close.ts +181 -0
- package/src/crews/dev-batches/application/prompts.ts +10 -0
- package/src/crews/dev-batches/application/run-dev-batches.ts +676 -0
- package/src/crews/dev-batches/application/run-wave.ts +452 -0
- package/src/crews/dev-batches/application/seed-harvest.ts +163 -0
- package/src/crews/dev-batches/crew.ork.ts +146 -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 +52 -0
- package/src/crews/dev-batches/domain/markers.ts +5 -0
- package/src/crews/dev-batches/domain/messages.ts +6 -0
- package/src/crews/dev-batches/domain/wave-order.ts +44 -0
- package/src/crews/dev-change/application/change-material.ts +44 -0
- package/src/crews/dev-change/application/evidence.ts +172 -0
- package/src/crews/dev-change/application/messages.ts +81 -0
- package/src/crews/dev-change/application/prompts.ts +101 -0
- package/src/crews/dev-change/application/run-dev-change.ts +324 -0
- package/src/crews/dev-change/crew.ork.ts +114 -0
- package/src/crews/dev-change/domain/change-answer.ts +163 -0
- package/src/crews/dev-change/domain/change-render.ts +77 -0
- package/src/crews/dev-change/domain/markers.ts +28 -0
- package/src/crews/dev-change/domain/messages.ts +16 -0
- package/src/crews/dev-implement/application/close.ts +186 -0
- package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
- package/src/crews/dev-implement/application/locate-sheet.ts +82 -0
- package/src/crews/dev-implement/application/messages.ts +161 -0
- package/src/crews/dev-implement/application/observe.ts +52 -0
- package/src/crews/dev-implement/application/prompts.ts +9 -0
- package/src/crews/dev-implement/application/report-writes.ts +46 -0
- package/src/crews/dev-implement/application/run-dev-implement.ts +822 -0
- package/src/crews/dev-implement/application/run-role.ts +27 -0
- package/src/crews/dev-implement/application/suite-job.ts +122 -0
- package/src/crews/dev-implement/application/touched.ts +74 -0
- package/src/crews/dev-implement/crew.ork.ts +69 -0
- package/src/crews/dev-implement/domain/contracts.ts +255 -0
- package/src/crews/dev-implement/domain/correction.ts +103 -0
- package/src/crews/dev-implement/domain/cycles.ts +36 -0
- package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
- package/src/crews/dev-implement/domain/markers.ts +23 -0
- package/src/crews/dev-implement/domain/messages.ts +58 -0
- package/src/crews/dev-implement/domain/prompts.ts +93 -0
- package/src/crews/dev-implement/domain/roles.ts +49 -0
- package/src/crews/dev-implement/domain/sheet-edits.ts +76 -0
- package/src/crews/dev-implement/domain/sheet-ticks.ts +23 -0
- package/src/crews/dev-implement/domain/step-checks.ts +137 -0
- package/src/crews/dev-implement/domain/step-section.ts +129 -0
- package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
- package/src/crews/dev-learn/application/learn-prompt-fit.ts +63 -0
- package/src/crews/dev-learn/application/messages.ts +51 -0
- package/src/crews/dev-learn/application/prompts.ts +99 -0
- package/src/crews/dev-learn/application/run-dev-learn.ts +558 -0
- package/src/crews/dev-learn/crew.ork.ts +53 -0
- package/src/crews/dev-learn/domain/learn-answer.ts +233 -0
- package/src/crews/dev-learn/domain/messages.ts +65 -0
- package/src/crews/dev-learn/domain/owner-lines.ts +89 -0
- package/src/crews/dev-learn/domain/proposals-render.ts +95 -0
- package/src/crews/dev-plan/application/anchor-paths.ts +113 -0
- package/src/crews/dev-plan/application/inventory.ts +174 -0
- package/src/crews/dev-plan/application/messages.ts +88 -0
- package/src/crews/dev-plan/application/plan-prompt-fit.ts +44 -0
- package/src/crews/dev-plan/application/prompts.ts +141 -0
- package/src/crews/dev-plan/application/run-dev-plan.ts +483 -0
- package/src/crews/dev-plan/crew.ork.ts +112 -0
- package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
- package/src/crews/dev-plan/domain/markers.ts +18 -0
- package/src/crews/dev-plan/domain/messages.ts +118 -0
- package/src/crews/dev-plan/domain/plan-answer.ts +753 -0
- package/src/crews/dev-plan/domain/plan-render.ts +306 -0
- package/src/crews/dev-plan/domain/prompts.ts +44 -0
- package/src/crews/dev-spec/application/messages.ts +30 -0
- package/src/crews/dev-spec/application/prompts.ts +93 -0
- package/src/crews/dev-spec/application/run-dev-spec.ts +237 -0
- package/src/crews/dev-spec/application/spec-material.ts +42 -0
- package/src/crews/dev-spec/crew.ork.ts +110 -0
- package/src/crews/dev-spec/domain/markers.ts +30 -0
- package/src/crews/dev-spec/domain/messages.ts +39 -0
- package/src/crews/dev-spec/domain/spec-answer.ts +252 -0
- package/src/crews/dev-spec/domain/spec-render.ts +76 -0
- package/src/crews/dev-verify/application/audit-brief.ts +187 -0
- package/src/crews/dev-verify/application/audit.ts +267 -0
- package/src/crews/dev-verify/application/capture.ts +311 -0
- package/src/crews/dev-verify/application/messages.ts +119 -0
- package/src/crews/dev-verify/application/prompts.ts +209 -0
- package/src/crews/dev-verify/application/run-dev-verify.ts +423 -0
- package/src/crews/dev-verify/application/run-gate.ts +204 -0
- package/src/crews/dev-verify/crew.ork.ts +103 -0
- package/src/crews/dev-verify/domain/audit-answer.ts +154 -0
- package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
- package/src/crews/dev-verify/domain/capture-sections.ts +138 -0
- package/src/crews/dev-verify/domain/commands.ts +103 -0
- package/src/crews/dev-verify/domain/gate.ts +131 -0
- package/src/crews/dev-verify/domain/markers.ts +16 -0
- package/src/crews/dev-verify/domain/mechanical-table.ts +156 -0
- package/src/crews/dev-verify/domain/messages.ts +92 -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 +133 -0
- package/src/crews/git-commit/application/messages.ts +15 -0
- package/src/crews/git-commit/application/prompts.ts +47 -0
- package/src/crews/git-commit/application/run-git-commit.ts +117 -0
- package/src/crews/git-commit/crew.ork.ts +53 -0
- package/src/crews/git-commit/domain/commit.ts +200 -0
- package/src/crews/git-commit/domain/markers.ts +4 -0
- package/src/crews/git-commit/domain/messages.ts +48 -0
- package/src/crews/init-verifiers/application/authoring.ts +90 -0
- package/src/crews/init-verifiers/application/messages.ts +13 -0
- package/src/crews/init-verifiers/application/prompts.ts +107 -0
- package/src/crews/init-verifiers/application/run-init-verifiers.ts +26 -0
- package/src/crews/init-verifiers/crew.ork.ts +35 -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 +78 -0
- package/src/crews/main-loop/application/context-gather.ts +133 -0
- package/src/crews/main-loop/application/messages.ts +81 -0
- package/src/crews/main-loop/application/prompts.ts +12 -0
- package/src/crews/main-loop/application/run-main-loop.ts +383 -0
- package/src/crews/main-loop/application/turn-context.ts +111 -0
- package/src/crews/main-loop/crew.ork.ts +124 -0
- package/src/crews/main-loop/domain/autocompact.ts +27 -0
- package/src/crews/main-loop/domain/prompt-assembly.ts +338 -0
- package/src/crews/main-loop/domain/prompts.ts +336 -0
- package/src/crews/main-loop/domain/turn-chains.ts +130 -0
- package/src/crews/project-init/application/detect.ts +123 -0
- package/src/crews/project-init/application/messages.ts +15 -0
- package/src/crews/project-init/application/prompts.ts +105 -0
- package/src/crews/project-init/application/run-project-init.ts +31 -0
- package/src/crews/project-init/crew.ork.ts +36 -0
- package/src/crews/project-init/domain/conventions.ts +36 -0
- package/src/crews/project-init/domain/existing-files.ts +65 -0
- package/src/crews/project-init/domain/messages.ts +13 -0
- package/src/crews/project-init/domain/package-map.ts +73 -0
- package/src/crews/project-init/domain/prompts.ts +10 -0
- package/src/crews/session-compact/application/prompts.ts +5 -0
- package/src/crews/session-compact/crew.ork.ts +56 -0
- package/src/crews/shared-memory-admit/application/prompts.ts +5 -0
- package/src/crews/shared-memory-admit/crew.ork.ts +49 -0
- package/src/crews/speech/application/messages.ts +3 -0
- package/src/crews/speech/application/prompts.ts +3 -0
- package/src/crews/speech/application/run-speech.ts +26 -0
- package/src/crews/speech/crew.ork.ts +38 -0
- package/src/shared/application/agents/child-agent.ts +259 -0
- package/src/shared/application/agents/messages.ts +35 -0
- package/src/shared/application/agents/route-agent.ts +115 -0
- package/src/shared/application/agents/run-sub-agent.ts +119 -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 +242 -0
- package/src/shared/application/compaction/extract-memories.ts +38 -0
- package/src/shared/application/compaction/messages.ts +20 -0
- package/src/shared/application/compaction/prune-context.ts +94 -0
- package/src/shared/application/compaction/pruned-llm.ts +35 -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 +115 -0
- package/src/shared/application/dev/close-batch.ts +85 -0
- package/src/shared/application/dev/find-repo-pack.ts +78 -0
- package/src/shared/application/dev/learn-decision.ts +254 -0
- package/src/shared/application/dev/load-dev-context.ts +265 -0
- package/src/shared/application/dev/measure-access-cost.ts +69 -0
- package/src/shared/application/dev/messages.ts +132 -0
- package/src/shared/application/dev/phase-timer.ts +54 -0
- package/src/shared/application/dev/plan-source.ts +116 -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/prompts.ts +34 -0
- package/src/shared/application/dev/question-round.ts +60 -0
- package/src/shared/application/dev/resolve-work-folder.ts +134 -0
- package/src/shared/application/dev/script-tool-slot.ts +27 -0
- package/src/shared/application/dev/settle-questions.ts +57 -0
- package/src/shared/application/dev/source-review.ts +67 -0
- package/src/shared/application/dev/source-step.ts +152 -0
- package/src/shared/application/dev/spend.ts +55 -0
- package/src/shared/application/dev/step-precedents.ts +90 -0
- package/src/shared/application/dev/tool-call-policy.ts +87 -0
- package/src/shared/application/dev/tool-callbacks.ts +262 -0
- package/src/shared/application/dev/tool-trace-recorder.ts +46 -0
- package/src/shared/application/dev/verdict-sources.ts +50 -0
- package/src/shared/application/dev/wrapped-tools.ts +147 -0
- package/src/shared/application/extra-tools.ts +71 -0
- package/src/shared/application/git/batch-worktree.ts +102 -0
- package/src/shared/application/git/commit-files.ts +191 -0
- package/src/shared/application/git/merge-batch.ts +67 -0
- package/src/shared/application/git/messages.ts +75 -0
- package/src/shared/application/git/open-pull-request.ts +52 -0
- package/src/shared/application/host-context.ts +59 -0
- package/src/shared/application/host-layout-store.ts +45 -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 +36 -0
- package/src/shared/application/messages.ts +14 -0
- package/src/shared/application/permission-rules.ts +169 -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/decision.ts +14 -0
- package/src/shared/application/ports/files.ts +21 -0
- package/src/shared/application/ports/human.ts +38 -0
- package/src/shared/application/ports/llm.ts +83 -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/theme.ts +11 -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 +29 -0
- package/src/shared/application/project-manifests.ts +106 -0
- package/src/shared/application/session-io.ts +85 -0
- package/src/shared/application/session-state.ts +36 -0
- package/src/shared/application/shared-memory/admit-entries.ts +179 -0
- package/src/shared/application/shared-memory/harvest-after-gaps.ts +69 -0
- package/src/shared/application/shared-memory/harvest-mistakes.ts +45 -0
- package/src/shared/application/shared-memory/import-agent-memory.ts +119 -0
- package/src/shared/application/shared-memory/memory-files.ts +111 -0
- package/src/shared/application/shared-memory/memory-settings.ts +94 -0
- package/src/shared/application/shared-memory/messages.ts +63 -0
- package/src/shared/application/shared-memory/push-candidate.ts +149 -0
- package/src/shared/application/shared-memory/recall-precedents.ts +70 -0
- package/src/shared/application/skills/messages.ts +4 -0
- package/src/shared/application/skills/suggest-skills.ts +102 -0
- package/src/shared/application/state-snapshot.ts +38 -0
- package/src/shared/application/workflow/messages.ts +8 -0
- package/src/shared/application/workflow/workflow-state.ts +136 -0
- package/src/shared/domain/agent-policy/behavior-flags.ts +162 -0
- package/src/shared/domain/agent-policy/extra-tools.ts +67 -0
- package/src/shared/domain/agent-policy/memory-categories.ts +6 -0
- package/src/shared/domain/agent-policy/messages.ts +66 -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/path-rules.ts +299 -0
- package/src/shared/domain/agent-policy/permission.ts +625 -0
- package/src/shared/domain/agent-policy/prompts.ts +17 -0
- package/src/shared/domain/agent-policy/reasoning.ts +59 -0
- package/src/shared/domain/agent-policy/rule-sets.ts +416 -0
- package/src/shared/domain/agent-policy/tool-access.ts +91 -0
- package/src/shared/domain/agent-registry.ts +143 -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 +64 -0
- package/src/shared/domain/agents/exclusive.ts +25 -0
- package/src/shared/domain/agents/instances.ts +252 -0
- package/src/shared/domain/agents/messages.ts +39 -0
- package/src/shared/domain/agents/model-route.ts +199 -0
- package/src/shared/domain/agents/prompts.ts +20 -0
- package/src/shared/domain/code-intel-contract.ts +357 -0
- package/src/shared/domain/code-intel-routing.ts +60 -0
- package/src/shared/domain/compact-outcome.ts +46 -0
- package/src/shared/domain/compaction-thresholds.ts +162 -0
- package/src/shared/domain/compaction.ts +288 -0
- package/src/shared/domain/config-schema.ts +434 -0
- package/src/shared/domain/context-prune.ts +176 -0
- package/src/shared/domain/decision/questions.ts +102 -0
- package/src/shared/domain/dev/access-cost.ts +230 -0
- package/src/shared/domain/dev/artefacts.ts +50 -0
- package/src/shared/domain/dev/batches-concurrency.ts +35 -0
- package/src/shared/domain/dev/batches-state.ts +49 -0
- package/src/shared/domain/dev/build-commands.ts +45 -0
- package/src/shared/domain/dev/call-guard.ts +342 -0
- package/src/shared/domain/dev/carried-text.ts +47 -0
- package/src/shared/domain/dev/design-rules.ts +100 -0
- package/src/shared/domain/dev/learn-proposals.ts +176 -0
- package/src/shared/domain/dev/learn-state.ts +94 -0
- package/src/shared/domain/dev/markers.ts +107 -0
- package/src/shared/domain/dev/messages.ts +259 -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/phase-timing.ts +50 -0
- package/src/shared/domain/dev/plan-checks.ts +191 -0
- package/src/shared/domain/dev/plan-format.ts +170 -0
- package/src/shared/domain/dev/project-files.ts +29 -0
- package/src/shared/domain/dev/prompts/brief-blocks.ts +20 -0
- package/src/shared/domain/dev/prompts.ts +251 -0
- package/src/shared/domain/dev/questions.ts +267 -0
- package/src/shared/domain/dev/reading-rule.ts +41 -0
- package/src/shared/domain/dev/repo-pack.ts +240 -0
- package/src/shared/domain/dev/review-answer.ts +173 -0
- package/src/shared/domain/dev/review-brief.ts +54 -0
- package/src/shared/domain/dev/reviewer-charter.ts +35 -0
- package/src/shared/domain/dev/sheet-facts.ts +81 -0
- package/src/shared/domain/dev/spec-format.ts +182 -0
- package/src/shared/domain/dev/step-budget.ts +74 -0
- package/src/shared/domain/dev/step-rules.ts +109 -0
- package/src/shared/domain/dev/test-commands.ts +94 -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 +65 -0
- package/src/shared/domain/dev/trait-pattern.ts +87 -0
- package/src/shared/domain/dev/verdict-format.ts +162 -0
- package/src/shared/domain/dev/whitespace.ts +35 -0
- package/src/shared/domain/dev/work-folder.ts +68 -0
- package/src/shared/domain/dev/yaml-subset.ts +385 -0
- package/src/shared/domain/error-text.ts +13 -0
- package/src/shared/domain/git/close.ts +274 -0
- package/src/shared/domain/git/messages.ts +20 -0
- package/src/shared/domain/git/pull-request.ts +96 -0
- package/src/shared/domain/git/worktree.ts +46 -0
- package/src/shared/domain/host-layout.ts +147 -0
- package/src/shared/domain/host-paths.ts +399 -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 +134 -0
- package/src/shared/domain/llm-profile.ts +44 -0
- package/src/shared/domain/marked-message.ts +29 -0
- package/src/shared/domain/markers.ts +30 -0
- package/src/shared/domain/messages.ts +291 -0
- package/src/shared/domain/model-catalog.ts +79 -0
- package/src/shared/domain/permission-modes.ts +99 -0
- package/src/shared/domain/prelude.ts +92 -0
- package/src/shared/domain/project-manifests.ts +84 -0
- package/src/shared/domain/prompts.ts +233 -0
- package/src/shared/domain/search-routing.ts +77 -0
- package/src/shared/domain/secret-patterns.ts +46 -0
- package/src/shared/domain/session-keys.ts +92 -0
- package/src/shared/domain/session-start.ts +61 -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 +145 -0
- package/src/shared/domain/shared-memory/candidates.ts +40 -0
- package/src/shared/domain/shared-memory/entry.ts +151 -0
- package/src/shared/domain/shared-memory/front-matter.ts +187 -0
- package/src/shared/domain/shared-memory/gate.ts +45 -0
- package/src/shared/domain/shared-memory/harvest.ts +64 -0
- package/src/shared/domain/shared-memory/layout.ts +190 -0
- package/src/shared/domain/shared-memory/markers.ts +9 -0
- package/src/shared/domain/shared-memory/messages.ts +66 -0
- package/src/shared/domain/shared-memory/precedents-block.ts +82 -0
- package/src/shared/domain/shared-memory/prompts.ts +28 -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/skills/prompts.ts +4 -0
- package/src/shared/domain/skills/shortlist.ts +149 -0
- package/src/shared/domain/snip-turns.ts +33 -0
- package/src/shared/domain/speech.ts +21 -0
- package/src/shared/domain/strip.ts +88 -0
- package/src/shared/domain/tool-trace.ts +120 -0
- package/src/shared/domain/types.ts +67 -0
- package/src/shared/domain/verifiers.ts +33 -0
- package/src/shared/domain/vfs.ts +16 -0
- package/src/shared/domain/workflow/prompts.ts +15 -0
- package/src/shared/domain/workflow/state-file.ts +142 -0
- package/src/shared/infrastructure/globals.ts +57 -0
- package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
- package/src/shared/infrastructure/orkeon/child-agents.ts +122 -0
- package/src/shared/infrastructure/orkeon/chooser.ts +32 -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/decision-model.ts +31 -0
- package/src/shared/infrastructure/orkeon/dev-deps.ts +179 -0
- package/src/shared/infrastructure/orkeon/files.ts +58 -0
- package/src/shared/infrastructure/orkeon/github-pull-requests.ts +30 -0
- package/src/shared/infrastructure/orkeon/host-context.ts +36 -0
- package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
- package/src/shared/infrastructure/orkeon/human-input.ts +55 -0
- package/src/shared/infrastructure/orkeon/llm-profile.ts +58 -0
- package/src/shared/infrastructure/orkeon/llm.ts +164 -0
- package/src/shared/infrastructure/orkeon/markers.ts +6 -0
- package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
- package/src/shared/infrastructure/orkeon/memory-tools.ts +129 -0
- package/src/shared/infrastructure/orkeon/messages.ts +15 -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/prompts.ts +47 -0
- package/src/shared/infrastructure/orkeon/reasoning.ts +40 -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 +129 -0
- package/src/shared/infrastructure/orkeon/session-store.ts +94 -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 +81 -0
- package/src/shared/infrastructure/orkeon/shell.ts +39 -0
- package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
- package/src/shared/infrastructure/orkeon/tool-catalogue.ts +76 -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 +174 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// The git close of a change: who commits (git's own identity), which files (an
|
|
2
|
+
// explicit list, never the work folder), the command lines that commit, push and
|
|
3
|
+
// merge them, and the pull request body and command handed over. Pure: nothing
|
|
4
|
+
// here runs a command; shared/application/git runs these lines through the Shell port.
|
|
5
|
+
import { ASSUMPTIONS_HEADING, ASSUMPTIONS_BY_ID_HEAD, FILES_PER_LAYER_HEADING, noIdentityStop } from "./messages.ts";
|
|
6
|
+
|
|
7
|
+
/** Q-10's switch: `true` asks the close to open the pull request itself. Omitted = false. */
|
|
8
|
+
export const DEV_PR_AUTO_CONFIG_KEY = "dev.prAuto";
|
|
9
|
+
|
|
10
|
+
/** Where the message goes for `git commit -F` (relative to /workspace; never tracked). */
|
|
11
|
+
export const COMMIT_MESSAGE_FILE = ".git/ORKEON_COMMITMSG";
|
|
12
|
+
/** In a linked worktree `.git` is a file: the message goes there instead, and is removed after the commit. */
|
|
13
|
+
export const COMMIT_MESSAGE_FALLBACK = ".orkeon/ORKEON_COMMITMSG";
|
|
14
|
+
export const GIT_IDENT_COMMAND = "git var GIT_AUTHOR_IDENT";
|
|
15
|
+
/** A commit needs the committer too: with only GIT_AUTHOR_* set it would fail after the draft was paid for. */
|
|
16
|
+
export const GIT_COMMITTER_IDENT_COMMAND = "git var GIT_COMMITTER_IDENT";
|
|
17
|
+
/** Names as they are (an accented name is not C-quoted); untracked files one by one. */
|
|
18
|
+
export const GIT_STATUS_COMMAND = "git -c core.quotePath=false status --short --untracked-files=all";
|
|
19
|
+
export const GIT_HEAD_COMMAND = "git rev-parse --short HEAD";
|
|
20
|
+
export const GIT_DEFAULT_BRANCH_COMMAND = "git symbolic-ref --short refs/remotes/origin/HEAD";
|
|
21
|
+
export const GIT_CURRENT_BRANCH_COMMAND = "git branch --show-current";
|
|
22
|
+
/** A merge or a cherry-pick in progress refuses a partial commit: each probe exits 0 while one is. */
|
|
23
|
+
export const GIT_IN_PROGRESS_PROBES: readonly string[] = [
|
|
24
|
+
"git rev-parse -q --verify MERGE_HEAD", "git rev-parse -q --verify CHERRY_PICK_HEAD",
|
|
25
|
+
];
|
|
26
|
+
/** What git says when a merge is refused only for not being a fast-forward. */
|
|
27
|
+
export function isNotFastForward(stderr: string): boolean {
|
|
28
|
+
return /fast-forward/i.test(String(stderr ?? ""));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface GitIdent { name: string; email: string }
|
|
32
|
+
|
|
33
|
+
/** The identity of `git var GIT_AUTHOR_IDENT` (`Name <email> <time> <tz>`), null when it holds no usable email. */
|
|
34
|
+
export function parseGitIdent(stdout: string): GitIdent | null {
|
|
35
|
+
const line = String(stdout ?? "").split("\n")[0].trim();
|
|
36
|
+
const m = /^(.*?)\s*<([^<>\s]+)>/.exec(line);
|
|
37
|
+
if (m === null || m[2].endsWith(".(none)")) return null;
|
|
38
|
+
return { name: m[1].trim(), email: m[2] };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The two commands that give git an identity; the user types them with their own name and email. */
|
|
42
|
+
export const IDENTITY_HANDOVER: readonly string[] = [
|
|
43
|
+
"git config --global user.name \"<your name>\"",
|
|
44
|
+
"git config --global user.email <your email>",
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
/** The stop when git has no identity: git's reason, then the two commands, one per line. Never an invented identity. */
|
|
48
|
+
export function identityStop(detail: string, rerun: string): string {
|
|
49
|
+
return [
|
|
50
|
+
noIdentityStop(detail, rerun),
|
|
51
|
+
...IDENTITY_HANDOVER.map((c) => ` ${c}`),
|
|
52
|
+
].join("\n");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A `git status --short` path with its quotes removed (an escaped name keeps its backslashes, so it reads unsafe). */
|
|
56
|
+
function unquote(path: string): string {
|
|
57
|
+
return path.trim().replace(/^"(.*)"$/, "$1");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Every path a `git status --short` lists, once, in order: both sides of a rename. */
|
|
61
|
+
export function changedPaths(status: string): string[] {
|
|
62
|
+
const out: string[] = [];
|
|
63
|
+
for (const line of String(status ?? "").split("\n")) {
|
|
64
|
+
// `AD`: added, then deleted from the worktree; neither HEAD nor the worktree holds it, so there is nothing to commit.
|
|
65
|
+
if (line.length <= 3 || line.startsWith("AD ")) continue;
|
|
66
|
+
const rest = line.slice(3);
|
|
67
|
+
const arrow = rest.indexOf(" -> ");
|
|
68
|
+
const paths = arrow >= 0 ? [rest.slice(0, arrow), rest.slice(arrow + 4)] : [rest];
|
|
69
|
+
for (const p of paths.map(unquote)) if (p.length > 0 && !out.includes(p)) out.push(p);
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The paths already gone from the index (a staged deletion, the old side of a
|
|
76
|
+
* staged rename): `git add` refuses them ("did not match any files"), while the
|
|
77
|
+
* commit's own path list takes them from HEAD.
|
|
78
|
+
*/
|
|
79
|
+
export function indexDeletedPaths(status: string): string[] {
|
|
80
|
+
const out: string[] = [];
|
|
81
|
+
for (const line of String(status ?? "").split("\n")) {
|
|
82
|
+
if (line.length <= 3) continue;
|
|
83
|
+
const rest = line.slice(3);
|
|
84
|
+
if (line[0] === "D") out.push(unquote(rest));
|
|
85
|
+
else if (line[0] === "R" && rest.includes(" -> ")) out.push(unquote(rest.slice(0, rest.indexOf(" -> "))));
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** True when the runtime's shell (no shell: quote-aware split, no escape, forbidden operators) cannot carry `s`. */
|
|
91
|
+
export function shellUnsafe(s: string): boolean {
|
|
92
|
+
return s.length === 0 || /['"\\\r\n`;|]/.test(s) || s.includes("$(") || s.includes("&&");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** `s` single-quoted for a POSIX shell (a quote inside becomes `'\''`). */
|
|
96
|
+
export function shellQuote(s: string): string {
|
|
97
|
+
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function under(path: string, folder: string): boolean {
|
|
101
|
+
return folder.length > 0 && (path === folder || path.startsWith(folder + "/"));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function bare(path: string): string {
|
|
105
|
+
let p = path.trim();
|
|
106
|
+
while (p.startsWith("./")) p = p.slice(2);
|
|
107
|
+
return p.replace(/\/+$/, "");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface CommitSelection {
|
|
111
|
+
/** The files the commit holds, in the status's order. */
|
|
112
|
+
files: string[];
|
|
113
|
+
/** Changed files of the work folder, left out. */
|
|
114
|
+
leftOut: string[];
|
|
115
|
+
/** Named paths inside the work folder: refused. */
|
|
116
|
+
inWorkFolder: string[];
|
|
117
|
+
/** Named paths with no change: refused. */
|
|
118
|
+
unchanged: string[];
|
|
119
|
+
/** Selected paths the shell cannot carry: refused. */
|
|
120
|
+
unsafe: string[];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The files a commit holds: the changed paths of `status` (or those equal to or
|
|
125
|
+
* under a `named` path), never one of the work folder unless `namedWorkFolder`
|
|
126
|
+
* lets a path named inside it through (/commit: the user's explicit choice, for a
|
|
127
|
+
* work folder the repository tracks; the dev close never). A work folder given as
|
|
128
|
+
* an absolute path lies outside the checkout and excludes nothing.
|
|
129
|
+
*/
|
|
130
|
+
export function selectCommitFiles(req: {
|
|
131
|
+
status: string; workFolder: string; named?: readonly string[]; namedWorkFolder?: boolean;
|
|
132
|
+
}): CommitSelection {
|
|
133
|
+
const work = req.workFolder.startsWith("/") ? "" : bare(req.workFolder);
|
|
134
|
+
const changed = changedPaths(req.status);
|
|
135
|
+
const inWorkFolder: string[] = [];
|
|
136
|
+
const unchanged: string[] = [];
|
|
137
|
+
let picked: string[] = [];
|
|
138
|
+
const allowed: string[] = [];
|
|
139
|
+
const named = (req.named ?? []).map(String).filter((n) => n.trim().length > 0);
|
|
140
|
+
if (named.length === 0) {
|
|
141
|
+
picked = changed;
|
|
142
|
+
} else {
|
|
143
|
+
for (const raw of named) {
|
|
144
|
+
const n = bare(raw);
|
|
145
|
+
if (n === "" || n === ".") { picked.push(...changed); continue; }
|
|
146
|
+
if (under(n, work) && req.namedWorkFolder !== true) { inWorkFolder.push(n); continue; }
|
|
147
|
+
const hits = changed.filter((p) => p === n || p.startsWith(n + "/"));
|
|
148
|
+
if (hits.length === 0) unchanged.push(n);
|
|
149
|
+
picked.push(...hits);
|
|
150
|
+
if (under(n, work)) allowed.push(...hits);
|
|
151
|
+
}
|
|
152
|
+
picked = changed.filter((p) => picked.includes(p));
|
|
153
|
+
}
|
|
154
|
+
const out = (p: string): boolean => under(p, work) && !allowed.includes(p);
|
|
155
|
+
const files = picked.filter((p) => !out(p));
|
|
156
|
+
return {
|
|
157
|
+
files,
|
|
158
|
+
leftOut: picked.filter(out),
|
|
159
|
+
inWorkFolder,
|
|
160
|
+
unchanged,
|
|
161
|
+
unsafe: files.filter(shellUnsafe),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const quoted = (paths: readonly string[]): string => paths.map(shellQuote).join(" ");
|
|
166
|
+
|
|
167
|
+
// Every path list is literal: `a[1].ts` names that file, never a glob matching `a1.ts`.
|
|
168
|
+
export function gitAddCommand(files: readonly string[]): string {
|
|
169
|
+
return `git --literal-pathspecs add -- ${quoted(files)}`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const BRANCH_WORD = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
173
|
+
|
|
174
|
+
/** A work branch from the pack's `contrib.branch` pattern: its first alternative before `/`, then `slug`
|
|
175
|
+
* (`<code>` for a /dev-batches run, `<code>-f<n>` for a typed close of one batch). Null when no prefix can be read. */
|
|
176
|
+
export function workBranchFromPattern(pattern: string, slug: string): string | null {
|
|
177
|
+
const slash = pattern.indexOf("/");
|
|
178
|
+
if (slash <= 0) return null;
|
|
179
|
+
const prefix = pattern.slice(0, slash).split("|")[0].trim();
|
|
180
|
+
return BRANCH_WORD.test(prefix) ? `${prefix}/${slug}` : null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** A path list on the commit itself: changes staged elsewhere stay staged and out of it. */
|
|
184
|
+
export function gitCommitCommand(files: readonly string[], messageFile: string = COMMIT_MESSAGE_FILE): string {
|
|
185
|
+
return `git --literal-pathspecs commit -F ${messageFile} -- ${quoted(files)}`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function gitDiffCommand(files: readonly string[]): string {
|
|
189
|
+
return `git --literal-pathspecs diff HEAD -- ${quoted(files)}`;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function gitPushCommand(branch: string): string {
|
|
193
|
+
return `git push -u origin ${shellQuote(branch)}`;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** HEAD and the remote-tracking ref of `branch`, one hash per line: equal, the branch is on origin already. */
|
|
197
|
+
export function gitPushedCheckCommand(branch: string): string {
|
|
198
|
+
return `git rev-parse HEAD ${shellQuote(`refs/remotes/origin/${branch}`)}`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Whether the two hashes `gitPushedCheckCommand` printed are one: the push was made, by hand or by a run. */
|
|
202
|
+
export function isPushed(stdout: string): boolean {
|
|
203
|
+
const [head, remote] = String(stdout ?? "").trim().split("\n").map((l) => l.trim());
|
|
204
|
+
return head !== undefined && head.length > 0 && head === remote;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function gitMergeFfOnly(ref: string): string {
|
|
208
|
+
return `git merge --ff-only ${shellQuote(ref)}`;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function gitRebaseIn(worktree: string, onto: string): string {
|
|
212
|
+
return `git -C ${shellQuote(worktree)} rebase ${shellQuote(onto)}`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function gitRebaseAbortIn(worktree: string): string {
|
|
216
|
+
return `git -C ${shellQuote(worktree)} rebase --abort`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** `origin/main` -> `main`; null when origin/HEAD is unset. */
|
|
220
|
+
export function parseDefaultBranch(stdout: string): string | null {
|
|
221
|
+
const b = String(stdout ?? "").trim().replace(/^origin\//, "");
|
|
222
|
+
return b.length > 0 ? b : null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** A folder name from a branch name: anything but letters, digits, `.`, `_`, `-` becomes `-`. */
|
|
226
|
+
export function prSlug(branch: string): string {
|
|
227
|
+
const s = String(branch ?? "").replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
228
|
+
return s.length > 0 ? s : "change";
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** `<work>/pr-<slug>/PR.md`, the body file the harness writes too. */
|
|
232
|
+
export function prBodyPath(workFolder: string, slug: string): string {
|
|
233
|
+
return `${workFolder.replace(/\/+$/, "")}/pr-${slug}/PR.md`;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface PrSummary {
|
|
237
|
+
/** The `## Batch` paragraph. */
|
|
238
|
+
batch: string;
|
|
239
|
+
layers: Array<{ layer: string; paths: string[] }>;
|
|
240
|
+
validations?: string[];
|
|
241
|
+
assumptions?: Array<{ id: string; assumption: string; by: string }>;
|
|
242
|
+
audit?: string;
|
|
243
|
+
notRun?: string;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const NONE = "None.";
|
|
247
|
+
|
|
248
|
+
/** The body of the pull request, under the template's headings, none removed or added; `None.` where nothing is said. */
|
|
249
|
+
export function renderPrBody(s: PrSummary): string {
|
|
250
|
+
const layers = s.layers.filter((l) => l.paths.length > 0)
|
|
251
|
+
.map((l) => `- ${l.layer}: ${l.paths.map((p) => `\`${p}\``).join(", ")}`);
|
|
252
|
+
const validations = (s.validations ?? []).map((v) => `- ${v}`);
|
|
253
|
+
const assumptions = (s.assumptions ?? []).length === 0 ? [NONE] : [
|
|
254
|
+
ASSUMPTIONS_BY_ID_HEAD,
|
|
255
|
+
"|----|------------|--------------------|",
|
|
256
|
+
...(s.assumptions ?? []).map((a) => `| ${a.id} | ${a.assumption} | ${a.by} |`),
|
|
257
|
+
];
|
|
258
|
+
const text = (v: string | undefined): string => (v ?? "").trim() || NONE;
|
|
259
|
+
return [
|
|
260
|
+
"## Batch", "", text(s.batch), "",
|
|
261
|
+
FILES_PER_LAYER_HEADING, "", ...(layers.length > 0 ? layers : [NONE]), "",
|
|
262
|
+
"## Validations", "", ...(validations.length > 0 ? validations : [NONE]), "",
|
|
263
|
+
ASSUMPTIONS_HEADING, "", ...assumptions, "",
|
|
264
|
+
"## Audit", "", text(s.audit), "",
|
|
265
|
+
"## Not run", "", text(s.notRun), "",
|
|
266
|
+
].join("\n");
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** The `gh pr create` line handed over, for the user's own shell; `--base` left out when unknown (gh's default). */
|
|
270
|
+
export function ghPrCreateCommand(req: { base: string | null; head: string; title: string; bodyFile: string }): string {
|
|
271
|
+
const arg = (s: string): string => (/^[A-Za-z0-9._/@:+-]+$/.test(s) ? s : shellQuote(s));
|
|
272
|
+
const base = req.base === null ? "" : ` --base ${arg(req.base)}`;
|
|
273
|
+
return `gh pr create${base} --head ${arg(req.head)} --title ${shellQuote(req.title)} --body-file ${arg(req.bodyFile)}`;
|
|
274
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The text of the git workflow shown to the user: the stop without an identity, the refusals of a pull
|
|
2
|
+
// request, the headings of its body.
|
|
3
|
+
|
|
4
|
+
export const noIdentityStop = (detail: string, rerun: string): string =>
|
|
5
|
+
`✗ stopped: git has no identity for the commit (${detail}). Set one in a terminal, then re-run ${rerun}:`;
|
|
6
|
+
|
|
7
|
+
// ── The body of a pull request ──────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
export const ASSUMPTIONS_BY_ID_HEAD = "| Id | Assumption | To be validated by |";
|
|
10
|
+
export const FILES_PER_LAYER_HEADING = "## Files, per layer";
|
|
11
|
+
export const ASSUMPTIONS_HEADING = "## Assumptions to validate";
|
|
12
|
+
|
|
13
|
+
// ── Why a pull request is not opened ────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
export const modeDoesNotRun = (mode: string, tool: string): string => `mode '${mode}' does not run ${tool}`;
|
|
16
|
+
export const denyRuleCovers = (tool: string, action: string): string => `a deny rule of /permissions covers ${tool} ${action}`;
|
|
17
|
+
export const dontAskNeedsAllow = (tool: string): string => `mode 'dontAsk' runs ${tool} only under an allow rule`;
|
|
18
|
+
export const asksFirstNotAsked = (tool: string, mode: string, rule: string): string =>
|
|
19
|
+
`${tool} asks first in mode '${mode}' and this run did not ask: ` +
|
|
20
|
+
`'/permissions add ${rule}' lets it open the pull request`;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The pull request Orkeon Code opens itself with the runtime's `github` tool
|
|
2
|
+
// (W0-C, Q-10): where origin lives on GitHub, and whether the call may run. Pure,
|
|
3
|
+
// no IO. A command's or a crew's own tool call is not seen by the host gate
|
|
4
|
+
// (docs/permissions.md, "What the gate does not see"), so the decision mirrors
|
|
5
|
+
// the gate here (ModePermissionGate): `github` is an edit (permission.ts) the
|
|
6
|
+
// gate asks about in `default` and `acceptEdits`, runs in `bypassPermissions`
|
|
7
|
+
// and refuses in `plan` and `dontAsk`; a deny rule wins in every mode, an allow
|
|
8
|
+
// rule spares the question in every mode but `plan`. One point is stricter than
|
|
9
|
+
// the gate: an unknown mode refuses (the gate reads it as `default`).
|
|
10
|
+
|
|
11
|
+
import { parseStoredRule, ruleDecision } from "../agent-policy/permission.ts";
|
|
12
|
+
import type { PermissionRule } from "../agent-policy/permission.ts";
|
|
13
|
+
import { isPermissionMode } from "../permission-modes.ts";
|
|
14
|
+
import { asksFirstNotAsked, denyRuleCovers, dontAskNeedsAllow, modeDoesNotRun } from "./messages.ts";
|
|
15
|
+
|
|
16
|
+
/** The tool, and the action of its call. */
|
|
17
|
+
export const GITHUB_TOOL = "github";
|
|
18
|
+
export const GITHUB_CREATE_PR = "create_pr";
|
|
19
|
+
|
|
20
|
+
/** The rule that lets /commit and the dev close open the pull request without a question. */
|
|
21
|
+
export const GITHUB_ALLOW_RULE = "allow github action=create_pr";
|
|
22
|
+
|
|
23
|
+
/** origin's URL, as the user configured it. */
|
|
24
|
+
export const GIT_REMOTE_URL_COMMAND = "git remote get-url origin";
|
|
25
|
+
|
|
26
|
+
export interface GitHubRepo { owner: string; repo: string }
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The repository of a github.com remote: `https://github.com/<owner>/<repo>(.git)`
|
|
30
|
+
* (a user name before the host allowed), `git@github.com:<owner>/<repo>(.git)` and
|
|
31
|
+
* `ssh://git@github.com/<owner>/<repo>(.git)`. Null for any other host, a GitHub
|
|
32
|
+
* Enterprise one included: the tool talks to api.github.com alone.
|
|
33
|
+
*/
|
|
34
|
+
export function parseGitHubRemote(url: string): GitHubRepo | null {
|
|
35
|
+
const u = String(url ?? "").trim();
|
|
36
|
+
const m = /^(?:https?:\/\/(?:[^@/]+@)?github\.com\/|ssh:\/\/git@github\.com(?::\d+)?\/|git@github\.com:)([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+?)(?:\.git)?\/?$/i.exec(u);
|
|
37
|
+
return m === null ? null : { owner: m[1], repo: m[2] };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The input of the `create_pr` call, as the tool declares it (tools.generated.d.ts `github`). */
|
|
41
|
+
export type CreatePrArgs = {
|
|
42
|
+
action: typeof GITHUB_CREATE_PR;
|
|
43
|
+
owner: string;
|
|
44
|
+
repo: string;
|
|
45
|
+
base: string;
|
|
46
|
+
head: string;
|
|
47
|
+
title: string;
|
|
48
|
+
body: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type PrPermission = { ok: true } | { ok: false; reason: string };
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Whether the `create_pr` call may run, as the host gate would decide it. `asked`:
|
|
55
|
+
* the user confirmed a plan that named the pull request (the question the gate
|
|
56
|
+
* would have asked in `default` and `acceptEdits`); a crew that cannot ask passes
|
|
57
|
+
* false. An unknown mode refuses, as the gate classifies one fail-closed.
|
|
58
|
+
*/
|
|
59
|
+
export function pullRequestPermission(req: {
|
|
60
|
+
mode: string;
|
|
61
|
+
rules: readonly PermissionRule[];
|
|
62
|
+
asked: boolean;
|
|
63
|
+
args: Readonly<Record<string, unknown>>;
|
|
64
|
+
}): PrPermission {
|
|
65
|
+
if (!isPermissionMode(req.mode) || req.mode === "plan") {
|
|
66
|
+
return { ok: false, reason: modeDoesNotRun(req.mode, GITHUB_TOOL) };
|
|
67
|
+
}
|
|
68
|
+
const rule = ruleDecision(req.rules, GITHUB_TOOL, req.args);
|
|
69
|
+
if (rule === "deny") return { ok: false, reason: denyRuleCovers(GITHUB_TOOL, GITHUB_CREATE_PR) };
|
|
70
|
+
if (rule === "allow") return { ok: true };
|
|
71
|
+
if (req.mode === "dontAsk") return { ok: false, reason: dontAskNeedsAllow(GITHUB_TOOL) };
|
|
72
|
+
if (req.mode === "bypassPermissions" || req.asked) return { ok: true };
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
reason: asksFirstNotAsked(GITHUB_TOOL, req.mode, GITHUB_ALLOW_RULE),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The session's rules as a crew receives them (an array, or one per line), read as the gate reads
|
|
80
|
+
* them; a line that is no rule is left out. */
|
|
81
|
+
export function parseSessionRules(raw: unknown): PermissionRule[] {
|
|
82
|
+
const lines = Array.isArray(raw) ? raw : String(raw ?? "").split("\n");
|
|
83
|
+
return lines.map((line) => parseStoredRule(String(line ?? "").trim())).filter((r): r is PermissionRule => r !== null);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* What /commit hands its crew for the pull request: `prAsked` only when `--pr` was confirmed
|
|
88
|
+
* at the prompt (`--yes` asked nothing); the tool and the rules, read when the run may reach the
|
|
89
|
+
* pull request (`--push` or `--pr`). The rules are those of the launch: one added while the crew
|
|
90
|
+
* runs is not seen, where the gate reads them at each call.
|
|
91
|
+
*/
|
|
92
|
+
export function pullRequestCrewInputs(req: {
|
|
93
|
+
pr: boolean; push: boolean; yes: boolean; read: () => { githubTool: boolean; permissionRules: string[] };
|
|
94
|
+
}): { prAsked: boolean; githubTool?: boolean; permissionRules?: string[] } {
|
|
95
|
+
return { prAsked: req.pr && !req.yes, ...(req.pr || req.push ? req.read() : {}) };
|
|
96
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// A batch's worktree: its name, where it lives - `/workspace/.orkeon/worktrees/<name>`, already under the
|
|
2
|
+
// project's mount and never under `.claude/` (the harness's) - and the git command lines that create,
|
|
3
|
+
// inspect and remove it. The shell runs in /workspace, so git is given the path relative to it; the
|
|
4
|
+
// absolute VFS path is the working root a batch's agent runs under (a parallel /dev-batches). The worktree is
|
|
5
|
+
// created with `--relative-paths` (git 2.48 and later): otherwise git writes the host's absolute path of the main
|
|
6
|
+
// git dir into the worktree's `.git` file, a path that does not exist in the runtime's sandbox, where the mounts sit
|
|
7
|
+
// at virtual paths (Orkeon/orkeon#188). An older git refuses the option, and its own message is the refusal. Pure.
|
|
8
|
+
import { shellQuote } from "./close.ts";
|
|
9
|
+
import { WORKSPACE } from "../vfs.ts";
|
|
10
|
+
|
|
11
|
+
export const WORKTREES_FOLDER = ".orkeon/worktrees";
|
|
12
|
+
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
13
|
+
|
|
14
|
+
export interface WorktreePlace {
|
|
15
|
+
name: string;
|
|
16
|
+
/** For git, relative to /workspace. */
|
|
17
|
+
path: string;
|
|
18
|
+
/** The VFS path: the batch's working root. */
|
|
19
|
+
root: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The place of worktree `name`; null for a name that is not one folder (`/`, `..`, a leading `-` or `.`). */
|
|
23
|
+
export function worktreePlace(name: string): WorktreePlace | null {
|
|
24
|
+
if (!NAME.test(name) || name.includes("..")) return null;
|
|
25
|
+
const path = `${WORKTREES_FOLDER}/${name}`;
|
|
26
|
+
return { name, path, root: `${WORKSPACE}/${path}` };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A batch's worktree: `<code>-F<n>`. */
|
|
30
|
+
export const batchWorktreeName = (code: string, batch: string): string => `${code}-${batch}`;
|
|
31
|
+
/** A batch's branch, never pushed: `batches/<code>/F<n>`. */
|
|
32
|
+
export const batchBranch = (code: string, batch: string): string => `batches/${code}/${batch}`;
|
|
33
|
+
|
|
34
|
+
export const gitBranchExists = (branch: string): string => `git rev-parse --verify --quiet ${shellQuote(`refs/heads/${branch}`)}`;
|
|
35
|
+
export const gitWorktreeAdd = (path: string, branch: string, base: string): string =>
|
|
36
|
+
`git worktree add --relative-paths -b ${shellQuote(branch)} ${shellQuote(path)} ${shellQuote(base)}`;
|
|
37
|
+
export const gitIsIgnored = (path: string): string => `git check-ignore -q ${shellQuote(path)}`;
|
|
38
|
+
export const gitWorktreeHead = (path: string): string => `git -C ${shellQuote(path)} symbolic-ref -q HEAD`;
|
|
39
|
+
export const gitWorktreeStatus = (path: string): string => `git -C ${shellQuote(path)} status --porcelain --untracked-files=all`;
|
|
40
|
+
export const gitIsMergedInto = (branch: string, into: string): string =>
|
|
41
|
+
`git merge-base --is-ancestor ${shellQuote(`refs/heads/${branch}`)} ${shellQuote(into)}`;
|
|
42
|
+
export const gitCommitsNotIn = (branch: string, into: string): string =>
|
|
43
|
+
`git rev-list --count ${shellQuote(`refs/heads/${branch}`)} --not ${shellQuote(into)}`;
|
|
44
|
+
// Never `--force`: git itself refuses a worktree with changes the status check missed.
|
|
45
|
+
export const gitWorktreeRemove = (path: string): string => `git worktree remove ${shellQuote(path)}`;
|
|
46
|
+
export const gitBranchDelete = (branch: string): string => `git branch -d ${shellQuote(branch)}`;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// The host Orkeon Code was started on, as the launcher wrote it to /user-config/launch.json (docs/architecture.md,
|
|
2
|
+
// "The VFS and the host platform"): its flavour (a posix system, WSL, native Windows) and the physical base of each
|
|
3
|
+
// VFS mount, in the spellings the launcher knows. The code never learns these bases from the runtime, which hides
|
|
4
|
+
// them (list_mounts answers virtual paths only): the launcher is the one holder. Without the file, or with one it
|
|
5
|
+
// cannot read, the layout is IDENTITY_HOST and every conversion of host-paths.ts is the identity. Pure.
|
|
6
|
+
import {
|
|
7
|
+
LAUNCH_MOUNTS_NOT_AN_OBJECT, LAUNCH_NOT_AN_OBJECT, launchFlavourIsNot, launchVersionIsNot, mountHasNoBases,
|
|
8
|
+
mountNoUsableBase, noMountBase, notAMountPoint, posixBaseNotAbsolute, windowsBaseNotADrive, wslWhere,
|
|
9
|
+
} from "./messages.ts";
|
|
10
|
+
|
|
11
|
+
export type HostFlavour = "posix" | "wsl" | "windows";
|
|
12
|
+
|
|
13
|
+
/** One mount and its physical base as the launcher passed it to `--mount`, in each spelling it knows. */
|
|
14
|
+
export interface MountBase {
|
|
15
|
+
/** The virtual path, `/workspace`. */
|
|
16
|
+
virtual: string;
|
|
17
|
+
/** The base as the posix side spells it (`/mnt/c/ici est/mon repertoire`, `/home/me/x`): absent on native Windows. */
|
|
18
|
+
posix?: string;
|
|
19
|
+
/** The base as Windows spells it (`C:\ici est\mon repertoire`, `\\wsl.localhost\Ubuntu\home\me\x`): absent on a
|
|
20
|
+
* plain posix host, and under WSL when the launcher had no `wslpath`. */
|
|
21
|
+
windows?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface HostLayout {
|
|
25
|
+
flavour: HostFlavour;
|
|
26
|
+
/** The WSL distribution (`Ubuntu`), for the `\\wsl$\<distro>\` and `\\wsl.localhost\<distro>\` spellings. */
|
|
27
|
+
distro?: string;
|
|
28
|
+
/** Where WSL mounts the Windows drives: `/mnt` (then `C:` is `/mnt/c`). */
|
|
29
|
+
automountRoot: string;
|
|
30
|
+
mounts: MountBase[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** No host facts: a posix host whose bases are unknown, every conversion the identity. */
|
|
34
|
+
export const IDENTITY_HOST: HostLayout = Object.freeze({ flavour: "posix", automountRoot: "/mnt", mounts: [] }) as HostLayout;
|
|
35
|
+
|
|
36
|
+
/** The version of launch.json this code reads. */
|
|
37
|
+
export const HOST_LAYOUT_VERSION = 1;
|
|
38
|
+
|
|
39
|
+
const FLAVOURS: readonly HostFlavour[] = ["posix", "wsl", "windows"];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The layout a launch.json holds. Anything unusable (not an object, another version, an unknown flavour) is
|
|
43
|
+
* IDENTITY_HOST with the reason in `problems`; a mount entry that is not usable is dropped and named there, the
|
|
44
|
+
* others kept. Each base is normalised: no trailing separator (a drive root keeps `C:\`), the drive letter
|
|
45
|
+
* upper-cased in a Windows spelling and lower-cased under the automount root, `/` for `\` in a Windows spelling.
|
|
46
|
+
*/
|
|
47
|
+
export function parseHostLayout(raw: unknown): { layout: HostLayout; problems: string[] } {
|
|
48
|
+
const problems: string[] = [];
|
|
49
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
50
|
+
return { layout: IDENTITY_HOST, problems: [LAUNCH_NOT_AN_OBJECT] };
|
|
51
|
+
}
|
|
52
|
+
const o = raw as Record<string, unknown>;
|
|
53
|
+
if (o.version !== HOST_LAYOUT_VERSION) {
|
|
54
|
+
return { layout: IDENTITY_HOST, problems: [launchVersionIsNot(String(o.version), HOST_LAYOUT_VERSION)] };
|
|
55
|
+
}
|
|
56
|
+
if (typeof o.flavour !== "string" || !FLAVOURS.includes(o.flavour as HostFlavour)) {
|
|
57
|
+
return { layout: IDENTITY_HOST, problems: [launchFlavourIsNot(String(o.flavour))] };
|
|
58
|
+
}
|
|
59
|
+
const flavour = o.flavour as HostFlavour;
|
|
60
|
+
const wsl = flavour === "wsl" && o.wsl !== null && typeof o.wsl === "object" ? (o.wsl as Record<string, unknown>) : {};
|
|
61
|
+
const distro = typeof wsl.distro === "string" && wsl.distro !== "" ? wsl.distro : undefined;
|
|
62
|
+
const automountRoot = typeof wsl.automountRoot === "string" && wsl.automountRoot.startsWith("/")
|
|
63
|
+
? trimTrailing(wsl.automountRoot, "/") || "/"
|
|
64
|
+
: "/mnt";
|
|
65
|
+
const mounts: MountBase[] = [];
|
|
66
|
+
const plain = o.mounts !== null && typeof o.mounts === "object" && !Array.isArray(o.mounts);
|
|
67
|
+
if (o.mounts !== undefined && !plain) problems.push(LAUNCH_MOUNTS_NOT_AN_OBJECT);
|
|
68
|
+
const entries = plain ? Object.entries(o.mounts as Record<string, unknown>) : [];
|
|
69
|
+
for (const [virtual, bases] of entries) {
|
|
70
|
+
const mount = parseMount(virtual, bases, automountRoot, problems);
|
|
71
|
+
if (mount !== null) mounts.push(mount);
|
|
72
|
+
}
|
|
73
|
+
return { layout: { flavour, ...(distro === undefined ? {} : { distro }), automountRoot, mounts }, problems };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function parseMount(virtual: string, bases: unknown, automountRoot: string, problems: string[]): MountBase | null {
|
|
77
|
+
if (!/^\/[^/\\]+$/.test(virtual)) {
|
|
78
|
+
problems.push(notAMountPoint(virtual));
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
if (bases === null || typeof bases !== "object" || Array.isArray(bases)) {
|
|
82
|
+
problems.push(mountHasNoBases(virtual));
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const b = bases as Record<string, unknown>;
|
|
86
|
+
const posix = typeof b.posix === "string" ? normalisePosixBase(b.posix, automountRoot) : undefined;
|
|
87
|
+
const windows = typeof b.windows === "string" ? normaliseWindowsBase(b.windows) : undefined;
|
|
88
|
+
if (typeof b.posix === "string" && posix === undefined) problems.push(posixBaseNotAbsolute(virtual, b.posix));
|
|
89
|
+
if (typeof b.windows === "string" && windows === undefined) problems.push(windowsBaseNotADrive(virtual, b.windows));
|
|
90
|
+
if (posix === undefined && windows === undefined) {
|
|
91
|
+
if (typeof b.posix !== "string" && typeof b.windows !== "string") problems.push(mountNoUsableBase(virtual));
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
return { virtual, ...(posix === undefined ? {} : { posix }), ...(windows === undefined ? {} : { windows }) };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** An absolute posix base without its trailing `/`; the drive letter lower-cased under the automount root. */
|
|
98
|
+
function normalisePosixBase(base: string, automountRoot: string): string | undefined {
|
|
99
|
+
if (!base.startsWith("/")) return undefined;
|
|
100
|
+
const trimmed = trimTrailing(base, "/");
|
|
101
|
+
if (trimmed === "") return undefined;
|
|
102
|
+
const root = automountRoot === "/" ? "" : automountRoot;
|
|
103
|
+
const drive = new RegExp(`^${escapeRegExp(root)}/([A-Za-z])(/|$)`).exec(trimmed);
|
|
104
|
+
return drive === null ? trimmed : `${root}/${drive[1].toLowerCase()}${trimmed.slice(root.length + 2)}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** A Windows base with `\`, no trailing separator (a drive root keeps `C:\`), its drive letter upper-cased. */
|
|
108
|
+
function normaliseWindowsBase(base: string): string | undefined {
|
|
109
|
+
const backslashed = base.replace(/\//g, "\\");
|
|
110
|
+
const drive = /^([A-Za-z]):(\\|$)/.exec(backslashed);
|
|
111
|
+
if (drive !== null) {
|
|
112
|
+
const rest = trimTrailing(backslashed.slice(2), "\\");
|
|
113
|
+
return `${drive[1].toUpperCase()}:${rest === "" ? "\\" : rest}`;
|
|
114
|
+
}
|
|
115
|
+
if (/^\\\\[^\\]+\\[^\\]+/.test(backslashed)) return trimTrailing(backslashed, "\\");
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function trimTrailing(text: string, char: string): string {
|
|
120
|
+
let end = text.length;
|
|
121
|
+
while (end > 0 && text[end - 1] === char) end--;
|
|
122
|
+
return text.slice(0, end);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function escapeRegExp(text: string): string {
|
|
126
|
+
return text.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** True when `layout` carries no host fact: a posix flavour and no mount. */
|
|
130
|
+
export function isIdentityHost(layout: HostLayout): boolean {
|
|
131
|
+
return layout.flavour === "posix" && layout.mounts.length === 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The layout in a line, for /doctor: the flavour, under WSL the distribution and the automount root, then each mount
|
|
135
|
+
* with its base as the host spells it, the Windows spelling in parentheses under WSL when the launcher knew it. */
|
|
136
|
+
export function describeHostLayout(layout: HostLayout): string {
|
|
137
|
+
const where = layout.flavour === "wsl"
|
|
138
|
+
? wslWhere(layout.distro ?? "distribution unknown", layout.automountRoot)
|
|
139
|
+
: layout.flavour;
|
|
140
|
+
if (layout.mounts.length === 0) return noMountBase(where);
|
|
141
|
+
const bases = layout.mounts.map((m) => {
|
|
142
|
+
const base = layout.flavour === "windows" ? (m.windows ?? m.posix) : (m.posix ?? m.windows);
|
|
143
|
+
const other = layout.flavour === "wsl" && m.posix !== undefined && m.windows !== undefined ? ` (${m.windows})` : "";
|
|
144
|
+
return `${m.virtual} = ${base ?? "?"}${other}`;
|
|
145
|
+
});
|
|
146
|
+
return `${where}: ${bases.join(", ")}`;
|
|
147
|
+
}
|