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
package/orkeon-code.ps1
ADDED
|
@@ -0,0 +1,939 @@
|
|
|
1
|
+
#!/usr/bin/env pwsh
|
|
2
|
+
<#
|
|
3
|
+
.SYNOPSIS
|
|
4
|
+
Start the Orkeon Code REPL on a project (Windows / PowerShell twin of ./orkeon-code).
|
|
5
|
+
|
|
6
|
+
.EXAMPLE
|
|
7
|
+
.\orkeon-code.ps1 # the current directory is the project
|
|
8
|
+
.\orkeon-code.ps1 -Workspace C:\src\app
|
|
9
|
+
.\orkeon-code.ps1 -Mode docker -Settings .\config\appsettings.local.json
|
|
10
|
+
.\orkeon-code.ps1 -Trust # this run only, without asking (nothing stored)
|
|
11
|
+
.\orkeon-code.ps1 -Continue # the last session of this project (--continue, -c)
|
|
12
|
+
.\orkeon-code.ps1 --resume [<n> | <id>] # list the saved sessions of this project and pick one
|
|
13
|
+
.\orkeon-code.ps1 trust list | add <path> | remove <path> | check <path> [--trust]
|
|
14
|
+
.\orkeon-code.ps1 setup # write %USERPROFILE%\.orkeon-code\appsettings.json (never the key)
|
|
15
|
+
|
|
16
|
+
.NOTES
|
|
17
|
+
Modes: tool (orkeon-repl on PATH, from the full Orkeon release .zip (the .msi has no orkeon-repl), the
|
|
18
|
+
Debian package or the dotnet tool, or $env:ORKEON_REPL) and docker
|
|
19
|
+
(ghcr.io/orkeon/orkeon:latest, the last release, not the pin). The source mode is only in the
|
|
20
|
+
bash launcher. Folder trust, per-project state, sessions, settings, API key, model and $env:ORKEON_CODE_AUDIO_DIR (speech-to-text,
|
|
21
|
+
tool mode): see the header of ./orkeon-code.
|
|
22
|
+
#>
|
|
23
|
+
# No positional binding: a bare word (trust, setup, a REPL argument) lands in $Extra, never in -Mode.
|
|
24
|
+
[CmdletBinding(PositionalBinding = $false)]
|
|
25
|
+
param(
|
|
26
|
+
[ValidateSet('', 'docker', 'tool')] [string] $Mode = $env:ORKEON_CODE_MODE,
|
|
27
|
+
[string] $Workspace = (Get-Location).Path,
|
|
28
|
+
[string] $Settings = $env:ORKEON_CODE_SETTINGS,
|
|
29
|
+
[switch] $Version,
|
|
30
|
+
[switch] $Trust,
|
|
31
|
+
[switch] $Continue,
|
|
32
|
+
[switch] $Resume,
|
|
33
|
+
[Parameter(ValueFromRemainingArguments = $true)] [string[]] $Extra = @()
|
|
34
|
+
)
|
|
35
|
+
$ErrorActionPreference = 'Stop'
|
|
36
|
+
|
|
37
|
+
# A subcommand of ./orkeon-code (trust, setup) is the first argument, and takes the rest as its own.
|
|
38
|
+
$Sub = $null
|
|
39
|
+
$SubArgs = @()
|
|
40
|
+
if ($Extra.Count -gt 0 -and $Extra[0] -cin @('trust', 'setup')) {
|
|
41
|
+
$Sub = $Extra[0]
|
|
42
|
+
$SubArgs = @($Extra | Select-Object -Skip 1)
|
|
43
|
+
$Extra = @()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
$resumeChoice = ''
|
|
47
|
+
$Help = $false
|
|
48
|
+
# The long options of ./orkeon-code, as a .cmd wrapper passes them (%*): --settings x, --settings=x, --workspace,
|
|
49
|
+
# --mode, --version and --trust bind the parameters above; a -- left in the arguments is dropped, and what follows
|
|
50
|
+
# it goes to the REPL as is.
|
|
51
|
+
$rest = @()
|
|
52
|
+
for ($i = 0; $i -lt $Extra.Count; $i++) {
|
|
53
|
+
$a = $Extra[$i]
|
|
54
|
+
if ($a -eq '--') {
|
|
55
|
+
if ($i + 1 -lt $Extra.Count) { $rest += $Extra[($i + 1)..($Extra.Count - 1)] }
|
|
56
|
+
break
|
|
57
|
+
}
|
|
58
|
+
$name = $a; $value = $null
|
|
59
|
+
if ($a -match '^(--(?:settings|workspace|mode))=(.*)$') { $name = $Matches[1]; $value = $Matches[2] }
|
|
60
|
+
if ($name -eq '--version') { $Version = [switch] $true }
|
|
61
|
+
elseif ($name -cin @('-h', '--help')) { $Help = $true }
|
|
62
|
+
elseif ($name -eq '--demo') { throw '--demo is only in the bash launcher (./orkeon-code --demo): it builds its fixture with scripts/setup-fixture.sh.' }
|
|
63
|
+
elseif ($name -eq '--trust') { $Trust = [switch] $true }
|
|
64
|
+
elseif ($name -cin @('--continue', '-c')) { $Continue = [switch] $true }
|
|
65
|
+
elseif ($name -match '^--resume(=(.*))?$') {
|
|
66
|
+
$Resume = [switch] $true
|
|
67
|
+
if ($Matches[1]) { $resumeChoice = $Matches[2] }
|
|
68
|
+
elseif ($i + 1 -lt $Extra.Count -and -not $Extra[$i + 1].StartsWith('-')) { $i++; $resumeChoice = $Extra[$i] }
|
|
69
|
+
}
|
|
70
|
+
elseif ($name -in @('--settings', '--workspace', '--mode')) {
|
|
71
|
+
if ($null -eq $value) {
|
|
72
|
+
if ($i + 1 -ge $Extra.Count) { throw "$name needs a value." }
|
|
73
|
+
$i++; $value = $Extra[$i]
|
|
74
|
+
}
|
|
75
|
+
if ($name -eq '--settings') { $Settings = $value }
|
|
76
|
+
elseif ($name -eq '--workspace') { $Workspace = $value }
|
|
77
|
+
elseif ($value -notin @('docker', 'tool')) {
|
|
78
|
+
# Checked before the assignment: -Mode's ValidateSet would refuse it with its own message.
|
|
79
|
+
throw "Unknown mode '$value' (--mode): docker or tool. The source mode is only in the bash launcher."
|
|
80
|
+
}
|
|
81
|
+
else { $Mode = $value }
|
|
82
|
+
} else { $rest += $a }
|
|
83
|
+
}
|
|
84
|
+
$Extra = $rest
|
|
85
|
+
# -h / --help: this file's help, as ./orkeon-code prints its header.
|
|
86
|
+
if ($Help) { Get-Help $PSCommandPath -Detailed; exit 0 }
|
|
87
|
+
# ValidateSet does not check its default ($env:ORKEON_CODE_MODE): an unknown mode is refused
|
|
88
|
+
# here rather than run as another one (./orkeon-code's source mode is not in this launcher).
|
|
89
|
+
if (-not $Sub -and $Mode -and $Mode -notin @('docker', 'tool')) {
|
|
90
|
+
throw "Unknown mode '$Mode' (-Mode, --mode or `$env:ORKEON_CODE_MODE): docker or tool. The source mode is only in the bash launcher."
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# ── Folder trust (as ./orkeon-code: the same store, the same layout, the same answers) ──
|
|
94
|
+
# Windows compares paths without case; elsewhere as they are.
|
|
95
|
+
$onWindows = [Environment]::OSVersion.Platform -eq 'Win32NT'
|
|
96
|
+
|
|
97
|
+
function Get-TrustFile { Join-Path $CodeHome 'trusted-folders.json' }
|
|
98
|
+
|
|
99
|
+
# The stored folders, as { Path; TrustedAt }; throws, naming the file, on a store it cannot read. The layout is
|
|
100
|
+
# the one Write-TrustStore gives, checked line by line as ./orkeon-code's awk does (no ConvertFrom-Json: pwsh 7 would
|
|
101
|
+
# turn the dates into DateTime, and would take a layout the bash launcher refuses).
|
|
102
|
+
function Get-TrustEntries {
|
|
103
|
+
$file = Get-TrustFile
|
|
104
|
+
if (-not (Test-Path -LiteralPath $file) -or (Get-Item -LiteralPath $file).Length -eq 0) { return }
|
|
105
|
+
$bad = "$file is not a trust store this launcher wrote: nothing is trusted, and the file is kept as it is. " +
|
|
106
|
+
'Fix it, or move it away and trust your folders again (orkeon-code trust add <path>).'
|
|
107
|
+
$str = '"((?:[^"\\\x00-\x1f]|\\["\\/])*)"'
|
|
108
|
+
$entry = '^[ \t]*\{[ \t]*"path"[ \t]*:[ \t]*' + $str + '[ \t]*,[ \t]*"trustedAt"[ \t]*:[ \t]*' + $str + '[ \t]*\}[ \t]*(,?)[ \t]*$'
|
|
109
|
+
$unescape = { param($v) [regex]::Replace($v, '\\(["\\/])', '$1') }
|
|
110
|
+
$lines = @([System.IO.File]::ReadAllLines($file) | ForEach-Object { $_ -replace "`r$", '' } | Where-Object { $_ -notmatch '^[ \t]*$' })
|
|
111
|
+
$out = @()
|
|
112
|
+
$step = 0; $comma = $false
|
|
113
|
+
foreach ($line in $lines) {
|
|
114
|
+
switch ($step) {
|
|
115
|
+
0 { if ($line -cnotmatch '^[ \t]*\{[ \t]*$') { throw $bad }; $step = 1 }
|
|
116
|
+
1 { if ($line -cnotmatch '^[ \t]*"version"[ \t]*:[ \t]*1[ \t]*,[ \t]*$') { throw $bad }; $step = 2 }
|
|
117
|
+
2 {
|
|
118
|
+
if ($line -cmatch '^[ \t]*"folders"[ \t]*:[ \t]*\[[ \t]*\][ \t]*$') { $step = 4 }
|
|
119
|
+
elseif ($line -cmatch '^[ \t]*"folders"[ \t]*:[ \t]*\[[ \t]*$') { $step = 3 }
|
|
120
|
+
else { throw $bad }
|
|
121
|
+
}
|
|
122
|
+
3 {
|
|
123
|
+
if ($line -cmatch '^[ \t]*\][ \t]*$') { if ($out.Count -gt 0 -and $comma) { throw $bad }; $step = 4 }
|
|
124
|
+
else {
|
|
125
|
+
if ($out.Count -gt 0 -and -not $comma) { throw $bad }
|
|
126
|
+
$m = [regex]::Match($line, $entry)
|
|
127
|
+
if (-not $m.Success -or -not $m.Groups[1].Value) { throw $bad }
|
|
128
|
+
$out += [pscustomobject]@{ Path = (& $unescape $m.Groups[1].Value); TrustedAt = (& $unescape $m.Groups[2].Value) }
|
|
129
|
+
$comma = $m.Groups[3].Value -eq ','
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
4 { if ($line -cnotmatch '^[ \t]*\}[ \t]*$') { throw $bad }; $step = 5 }
|
|
133
|
+
default { throw $bad }
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if ($step -ne 5) { throw $bad }
|
|
137
|
+
$out
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
# Readable and writable by the user alone where modes exist: SetUnixFileMode from .NET 7 (PowerShell 7.3), else chmod.
|
|
141
|
+
function Set-OwnerOnly([string] $path, [string] $mode) {
|
|
142
|
+
if ($onWindows) { return }
|
|
143
|
+
try { [System.IO.File]::SetUnixFileMode($path, $(if ($mode -eq '700') { 'UserRead, UserWrite, UserExecute' } else { 'UserRead, UserWrite' })) }
|
|
144
|
+
catch { & chmod $mode -- $path 2>$null }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Writes the store in ./orkeon-code's layout, one folder per line: a temporary file, then a rename.
|
|
148
|
+
function Write-TrustStore($entries) {
|
|
149
|
+
$file = Get-TrustFile
|
|
150
|
+
if (-not (Test-Path -LiteralPath $CodeHome)) { New-Item -ItemType Directory -Force -Path $CodeHome | Out-Null; Set-OwnerOnly $CodeHome '700' }
|
|
151
|
+
$escape = { param($s) ($s -replace '\\', '\\') -replace '"', '\"' }
|
|
152
|
+
$lines = @($entries | ForEach-Object { ' { "path": "' + (& $escape $_.Path) + '", "trustedAt": "' + (& $escape $_.TrustedAt) + '" }' })
|
|
153
|
+
$folders = if ($lines.Count -eq 0) { " `"folders`": []`n" } else { " `"folders`": [`n" + ($lines -join ",`n") + "`n ]`n" }
|
|
154
|
+
$tmp = "$file.tmp.$PID"
|
|
155
|
+
[System.IO.File]::WriteAllText($tmp, "{`n `"version`": 1,`n$folders}`n")
|
|
156
|
+
Set-OwnerOnly $tmp '600'
|
|
157
|
+
Move-Item -LiteralPath $tmp -Destination $file -Force
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
# The folder, full and with every link on its path resolved (bash's `pwd -P`), or $null when it is not a folder
|
|
161
|
+
# or a link on its path cannot be resolved.
|
|
162
|
+
function Get-CanonicalDir([string] $path) {
|
|
163
|
+
$item = Get-Item -LiteralPath $path -Force -ErrorAction SilentlyContinue
|
|
164
|
+
if (-not $item -or -not $item.PSIsContainer) { return $null }
|
|
165
|
+
$full = $item.FullName
|
|
166
|
+
if (-not $onWindows) {
|
|
167
|
+
$real = & sh -c 'cd -- "$1" && pwd -P' sh $full 2>$null
|
|
168
|
+
if ($LASTEXITCODE -ne 0 -or -not $real) { return $null }
|
|
169
|
+
return "$real"
|
|
170
|
+
}
|
|
171
|
+
# Windows: each component in turn; a link (symbolic link, junction) replaces the path up to it by its target.
|
|
172
|
+
for ($n = 0; $n -lt 40; $n++) {
|
|
173
|
+
$full = [System.IO.Path]::GetFullPath($full)
|
|
174
|
+
$root = [System.IO.Path]::GetPathRoot($full)
|
|
175
|
+
$parts = @($full.Substring($root.Length).Split([char[]] @('\', '/'), [StringSplitOptions]::RemoveEmptyEntries))
|
|
176
|
+
$cur = $root
|
|
177
|
+
$changed = $false
|
|
178
|
+
for ($i = 0; $i -lt $parts.Count; $i++) {
|
|
179
|
+
$cur = Join-Path $cur $parts[$i]
|
|
180
|
+
$link = Get-Item -LiteralPath $cur -Force -ErrorAction SilentlyContinue
|
|
181
|
+
if ($link -and $link.LinkType) {
|
|
182
|
+
$target = "$(@($link.Target)[0])" -replace '^\\\\\?\\', ''
|
|
183
|
+
if (-not $target) { return $null }
|
|
184
|
+
if (-not [System.IO.Path]::IsPathRooted($target)) { $target = Join-Path (Split-Path $cur -Parent) $target }
|
|
185
|
+
$full = if ($i + 1 -lt $parts.Count) { Join-Path $target ($parts[($i + 1)..($parts.Count - 1)] -join '\') } else { $target }
|
|
186
|
+
$changed = $true
|
|
187
|
+
break
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (-not $changed) {
|
|
191
|
+
if ($full.Length -gt $root.Length) { $full = $full.TrimEnd('\', '/') }
|
|
192
|
+
return $full
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
$null
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
# The stored folder that covers <folder> (itself or an ancestor), or $null.
|
|
199
|
+
function Get-TrustedBy([string] $folder) {
|
|
200
|
+
$cmp = if ($onWindows) { [StringComparison]::OrdinalIgnoreCase } else { [StringComparison]::Ordinal }
|
|
201
|
+
$sep = [string] [System.IO.Path]::DirectorySeparatorChar
|
|
202
|
+
foreach ($e in @(Get-TrustEntries)) {
|
|
203
|
+
if ([string]::Equals($e.Path, $folder, $cmp)) { return $e.Path }
|
|
204
|
+
$prefix = if ($e.Path.EndsWith($sep)) { $e.Path } else { $e.Path + $sep } # a root (/, C:\) ends with one already
|
|
205
|
+
if ($folder.StartsWith($prefix, $cmp)) { return $e.Path }
|
|
206
|
+
}
|
|
207
|
+
$null
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function Add-TrustedFolder([string] $folder) {
|
|
211
|
+
if ($folder -match '[\x00-\x1f]') { throw "A folder whose path holds a control character cannot be trusted: $folder" }
|
|
212
|
+
$entries = @(Get-TrustEntries)
|
|
213
|
+
Write-TrustStore ($entries + [pscustomobject]@{ Path = $folder; TrustedAt = [DateTime]::UtcNow.ToString('yyyy-MM-ddTHH:mm:ssZ') })
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
# Returns when <folder> may start: trusted, -Trust or CI, or trusted now in a terminal; exits otherwise
|
|
217
|
+
# (<declined> on a decline, 3 without a terminal). Nothing of the folder is read here.
|
|
218
|
+
function Confirm-Trusted([string] $folder, [bool] $given, [int] $declined) {
|
|
219
|
+
if ($given -or ($env:ORKEON_CODE_TRUST -eq '1' -and $env:CI -ceq 'true')) { return }
|
|
220
|
+
if (Get-TrustedBy $folder) { return }
|
|
221
|
+
if ([Console]::IsInputRedirected) {
|
|
222
|
+
[Console]::Error.WriteLine("orkeon-code: $folder is not a trusted folder, and there is no terminal to ask in. Trust it once with " +
|
|
223
|
+
"'orkeon-code trust add $folder', or pass --trust for this run only.")
|
|
224
|
+
exit 3
|
|
225
|
+
}
|
|
226
|
+
[Console]::Error.WriteLine('orkeon-code: do you trust the files in this folder?')
|
|
227
|
+
[Console]::Error.WriteLine(" $folder")
|
|
228
|
+
[Console]::Error.WriteLine(' The agent reads its AGENTS.md, .orkeon/config.json and .orkeon/repo.yaml, may run the commands')
|
|
229
|
+
[Console]::Error.WriteLine(" .orkeon/repo.yaml names, and git runs the folder's hooks through the shell.")
|
|
230
|
+
if ([System.IO.Path]::GetPathRoot($folder) -eq $folder -or $folder -eq (Get-CanonicalDir $HOME)) {
|
|
231
|
+
[Console]::Error.WriteLine(' This trusts every folder below it.')
|
|
232
|
+
}
|
|
233
|
+
[Console]::Error.Write('[y] trust [n] quit: ')
|
|
234
|
+
$answer = [Console]::In.ReadLine()
|
|
235
|
+
if ("$answer".Trim().ToLowerInvariant() -in @('y', 'yes')) {
|
|
236
|
+
Add-TrustedFolder $folder
|
|
237
|
+
[Console]::Error.WriteLine("orkeon-code: trusted $folder (orkeon-code trust remove $folder takes it back).")
|
|
238
|
+
} else {
|
|
239
|
+
[Console]::Error.WriteLine('orkeon-code: not trusted, nothing started.')
|
|
240
|
+
exit $declined
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
# ── Per-project state and sessions (as ./orkeon-code) ──
|
|
245
|
+
# The runtime's folder name for a project (ProjectKey.Slug, Orkeon.Infrastructure/Session/ProjectKey.cs): the last
|
|
246
|
+
# segment, each UTF-16 unit an ASCII letter or digit lowercased, else '-', then '-' and the first 12 hex of the
|
|
247
|
+
# SHA-256 of the whole path, in UTF-8.
|
|
248
|
+
function Get-ProjectSlug([string] $path) {
|
|
249
|
+
$name = ($path.TrimEnd('/', '\') -split '[/\\]')[-1]
|
|
250
|
+
$out = -join @(foreach ($c in $name.ToCharArray()) {
|
|
251
|
+
$n = [int] $c
|
|
252
|
+
if (($n -ge 48 -and $n -le 57) -or ($n -ge 65 -and $n -le 90) -or ($n -ge 97 -and $n -le 122)) { [char]::ToLowerInvariant($c) } else { '-' }
|
|
253
|
+
})
|
|
254
|
+
$sha = [System.Security.Cryptography.SHA256]::Create()
|
|
255
|
+
try { $bytes = $sha.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($path)) } finally { $sha.Dispose() }
|
|
256
|
+
"$out-" + (-join @($bytes | ForEach-Object { $_.ToString('x2') })).Substring(0, 12)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
# A string field of a JSON file as stored (its escapes unread), or $null.
|
|
260
|
+
function Get-JsonField([string] $file, [string] $field) {
|
|
261
|
+
$text = Get-Content -LiteralPath $file -Raw -Encoding UTF8 -ErrorAction SilentlyContinue
|
|
262
|
+
if ($text -match ('"' + $field + '"\s*:\s*"((?:[^"\\]|\\.)*)"')) { $Matches[1] } else { $null }
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
# Removes from history/ every file of the session $rawId (as stored, never the file name), before its new file lands
|
|
266
|
+
# there: a session /resume loaded in place goes on under its id, so its new file replaces the one it was loaded
|
|
267
|
+
# from, under its own name (no collision suffix). Nothing for an empty id.
|
|
268
|
+
function Remove-HistoryDuplicates([string] $history, [string] $rawId) {
|
|
269
|
+
if (-not $rawId) { return }
|
|
270
|
+
foreach ($other in @(Get-ChildItem -LiteralPath $history -File -Filter '*.json' -ErrorAction SilentlyContinue)) {
|
|
271
|
+
if ("$(Get-JsonField $other.FullName 'SessionId')" -eq $rawId) { Remove-Item -LiteralPath $other.FullName -Force }
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
# Moves every session file the runtime saved into history/, under <UTC time>-<session id>.json: the last.json of
|
|
276
|
+
# sessions/ and the archives /resume left beside it (<stamp>-archived.json, moved first so last.json is the newest),
|
|
277
|
+
# unless $sideOnly, and always those of side/<pid>/ (a start beside an open one, now ended). A session without a
|
|
278
|
+
# message (a start and a quit) is dropped, so it never pushes a real one out of the history; a session that goes on
|
|
279
|
+
# under the id of one already in the history replaces it there (Remove-HistoryDuplicates).
|
|
280
|
+
function Move-SessionsToHistory([string] $sessions, [string] $history, [string] $side, [bool] $sideOnly) {
|
|
281
|
+
$folders = @()
|
|
282
|
+
if (-not $sideOnly) { $folders += @(Get-ChildItem -LiteralPath $sessions -Directory -ErrorAction SilentlyContinue) }
|
|
283
|
+
foreach ($pidDir in @(Get-ChildItem -LiteralPath $side -Directory -ErrorAction SilentlyContinue)) {
|
|
284
|
+
$folders += @(Get-ChildItem -LiteralPath $pidDir.FullName -Directory -ErrorAction SilentlyContinue)
|
|
285
|
+
}
|
|
286
|
+
$files = @($folders | ForEach-Object { Get-ChildItem -LiteralPath $_.FullName -File -Filter '*.json' -ErrorAction SilentlyContinue })
|
|
287
|
+
$ordered = @($files | Where-Object { $_.Name -ne 'last.json' }) + @($files | Where-Object { $_.Name -eq 'last.json' })
|
|
288
|
+
foreach ($file in $ordered) {
|
|
289
|
+
$last = $file.FullName
|
|
290
|
+
if ((Get-Content -LiteralPath $last -Raw -Encoding UTF8 -ErrorAction SilentlyContinue) -match '"Messages"\s*:\s*\[\s*\]') {
|
|
291
|
+
Remove-Item -LiteralPath $last -Force; continue
|
|
292
|
+
}
|
|
293
|
+
$rawId = "$(Get-JsonField $last 'SessionId')"
|
|
294
|
+
$id = $rawId -replace '[^A-Za-z0-9._-]', '_'
|
|
295
|
+
if (-not $id) { $id = 'session' }
|
|
296
|
+
Remove-HistoryDuplicates $history $rawId
|
|
297
|
+
$stamp = [DateTime]::UtcNow.ToString("yyyyMMdd'T'HHmmss'Z'", [System.Globalization.CultureInfo]::InvariantCulture)
|
|
298
|
+
$target = Join-Path $history "$stamp-$id.json"; $n = 2
|
|
299
|
+
while (Test-Path -LiteralPath $target) { $target = Join-Path $history "$stamp-$id-$n.json"; $n++ }
|
|
300
|
+
Move-Item -LiteralPath $last -Destination $target -Force
|
|
301
|
+
}
|
|
302
|
+
Get-ChildItem -LiteralPath $side -Directory -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
# The history, newest first.
|
|
306
|
+
function Get-HistoryFiles([string] $history) {
|
|
307
|
+
@(Get-ChildItem -LiteralPath $history -File -Filter '*.json' -ErrorAction SilentlyContinue |
|
|
308
|
+
Sort-Object -Property Name -Descending -CaseSensitive)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
# ── Settings: setup (as ./orkeon-code setup; the key is never asked) ──
|
|
312
|
+
# One line asked on the terminal: the answer, trimmed, or <default> when empty; $null at the end of input.
|
|
313
|
+
function Read-Answer([string] $question, [string] $default) {
|
|
314
|
+
[Console]::Error.Write($question)
|
|
315
|
+
$answer = [Console]::In.ReadLine()
|
|
316
|
+
if ($null -eq $answer) { return $null }
|
|
317
|
+
$answer = $answer.Trim()
|
|
318
|
+
if ($answer) { $answer } else { $default }
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
# Writes <target> from one of the examples, with the model and the name of the key's variable; $false when the
|
|
322
|
+
# user stops or keeps the existing file.
|
|
323
|
+
function Invoke-Setup([string] $target) {
|
|
324
|
+
if ([Console]::IsInputRedirected) { throw "setup asks its questions in a terminal: run 'orkeon-code setup' in one." }
|
|
325
|
+
if (Test-Path -LiteralPath $target) {
|
|
326
|
+
$answer = Read-Answer "orkeon-code: $target exists. Replace it? [y/N] " 'n'
|
|
327
|
+
if ("$answer".ToLowerInvariant() -notin @('y', 'yes')) { [Console]::Error.WriteLine("orkeon-code: $target kept."); return $false }
|
|
328
|
+
}
|
|
329
|
+
[Console]::Error.WriteLine("orkeon-code setup: the settings go to $target. The API key never does: only the name of the")
|
|
330
|
+
[Console]::Error.WriteLine('environment variable that holds it.')
|
|
331
|
+
[Console]::Error.WriteLine(' [1] a hosted, OpenAI-compatible endpoint (config/appsettings.example.json: DeepSeek)')
|
|
332
|
+
[Console]::Error.WriteLine(' [2] Ollama on this machine, no key (config/appsettings.ollama.example.json)')
|
|
333
|
+
while ($true) {
|
|
334
|
+
$answer = Read-Answer 'Provider [1]: ' '1'
|
|
335
|
+
if ($null -eq $answer) { return $false }
|
|
336
|
+
if ($answer -eq '1') { $example = Join-Path $Root 'config/appsettings.example.json'; break }
|
|
337
|
+
if ($answer -eq '2') { $example = Join-Path $Root 'config/appsettings.ollama.example.json'; break }
|
|
338
|
+
[Console]::Error.WriteLine('orkeon-code: answer 1 or 2.')
|
|
339
|
+
}
|
|
340
|
+
$settings = Get-Content -LiteralPath $example -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
341
|
+
$defaultVar = $settings.Llm.ApiKeyEnvVar
|
|
342
|
+
while ($true) {
|
|
343
|
+
$model = Read-Answer "Model [$($settings.Llm.Model)]: " $settings.Llm.Model
|
|
344
|
+
if ($null -eq $model) { return $false }
|
|
345
|
+
# Never said back, and refused when it looks like a key: a key pasted at the wrong question.
|
|
346
|
+
if ($model -cmatch '^[A-Za-z0-9._:/@+-]+$' -and $model -cnotmatch '^sk-' -and $model -cnotmatch '^[A-Za-z0-9_-]{32,}$') { break }
|
|
347
|
+
[Console]::Error.WriteLine('orkeon-code: that is not a model id (letters, digits and . _ : / @ + -, not a key).')
|
|
348
|
+
}
|
|
349
|
+
$var = $null
|
|
350
|
+
if ($defaultVar) {
|
|
351
|
+
while ($true) {
|
|
352
|
+
$var = Read-Answer "Name of the environment variable that holds the API key [$defaultVar]: " $defaultVar
|
|
353
|
+
if ($null -eq $var) { return $false }
|
|
354
|
+
if ($var -cmatch '^[A-Z_][A-Z0-9_]{0,63}$') { break }
|
|
355
|
+
# Never said back: what was typed may be the key itself.
|
|
356
|
+
[Console]::Error.WriteLine('orkeon-code: that is not a variable name (capitals, digits and _). Type the name of the variable, never the key.')
|
|
357
|
+
}
|
|
358
|
+
$settings.Llm.ApiKeyEnvVar = $var
|
|
359
|
+
}
|
|
360
|
+
$settings.Llm.Model = $model
|
|
361
|
+
$settings._comment = 'Written by orkeon-code setup. The API key never goes in this file: ApiKeyEnvVar names the environment ' +
|
|
362
|
+
'variable that holds it, and ORKEON_Llm__ApiKey, when set, wins over everything. Every key is explained in docs/configuration.md.'
|
|
363
|
+
if (-not (Test-Path -LiteralPath $CodeHome)) { New-Item -ItemType Directory -Force -Path $CodeHome | Out-Null; Set-OwnerOnly $CodeHome '700' }
|
|
364
|
+
$tmp = "$target.tmp.$PID"
|
|
365
|
+
[System.IO.File]::WriteAllText($tmp, ($settings | ConvertTo-Json -Depth 20) + "`n")
|
|
366
|
+
Set-OwnerOnly $tmp '600'
|
|
367
|
+
Move-Item -LiteralPath $tmp -Destination $target -Force
|
|
368
|
+
[Console]::Error.WriteLine("orkeon-code: wrote $target (model $model).")
|
|
369
|
+
if ($var) { [Console]::Error.WriteLine("orkeon-code: set the key before you start: `$env:$var = '<your key>'") }
|
|
370
|
+
$true
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
# The variables set below for the REPL are put back as they were when the script ends, so that none of them stays
|
|
374
|
+
# in the PowerShell session that ran it.
|
|
375
|
+
$savedEnv = @{}
|
|
376
|
+
foreach ($name in @('ORKEON_Llm__Model', 'Orkeon__Security__PermissionGate__Enabled', 'Orkeon__Cli__Session__StartScript',
|
|
377
|
+
'Orkeon__Cli__Session__Persist', 'ORKEON_Orkeon__Cli__Session__SessionsDirectory',
|
|
378
|
+
'ORKEON_Orkeon__Cli__Memory__RootDirectory', 'Orkeon__Embeddings__FingerprintPath',
|
|
379
|
+
'ORKEON_ESBUILD_PATH',
|
|
380
|
+
'ORKEON_ALLOW_EXTERNAL_MOUNTS', 'WHISPER_AUDIO_DIR', 'WHISPER_OUT_DIR',
|
|
381
|
+
'ORKEON_MCP__Servers__whisper__Transport', 'ORKEON_MCP__Servers__whisper__Command',
|
|
382
|
+
'ORKEON_MCP__Servers__whisper__TrustAnnotations', 'ORKEON_MCP__Servers__whisper__CallTimeout',
|
|
383
|
+
'ORKEON_MCP__Servers__whisper__Args__0', 'ORKEON_MCP__Servers__whisper__Args__1',
|
|
384
|
+
'ORKEON_MCP__Servers__whisper__Args__2', 'ORKEON_MCP__Servers__whisper__Args__3',
|
|
385
|
+
'ORKEON_MCP__Servers__whisper__Args__4', 'ORKEON_MCP__Servers__whisper__Args__5',
|
|
386
|
+
'ORKEON_MCP__Servers__whisper__Args__6', 'ORKEON_MCP__Servers__whisper__Args__7',
|
|
387
|
+
'ORKEON_MCP__Servers__whisper__Args__8', 'ORKEON_MCP__Servers__whisper__Args__9',
|
|
388
|
+
'ORKEON_MCP__Servers__whisper__Args__10', 'ORKEON_MCP__Servers__whisper__Args__11',
|
|
389
|
+
'ORKEON_MCP__Servers__whisper__Args__12',
|
|
390
|
+
'WHISPER_MICROPHONE', 'WHISPER_SPEAKER', 'UV_PROJECT_ENVIRONMENT')) {
|
|
391
|
+
$savedEnv[$name] = [Environment]::GetEnvironmentVariable($name)
|
|
392
|
+
}
|
|
393
|
+
try {
|
|
394
|
+
$Root = $PSScriptRoot
|
|
395
|
+
# The pin is a commit of Orkeon's main (.orkeon-version, ADR 0013): the tool and docker modes run a release.
|
|
396
|
+
$OrkeonRef = (Get-Content (Join-Path $Root '.orkeon-version') -Raw).Trim()
|
|
397
|
+
$OrkeonPin = $OrkeonRef.Substring(0, 7)
|
|
398
|
+
$Image = if ($env:ORKEON_CODE_IMAGE) { $env:ORKEON_CODE_IMAGE } else { 'ghcr.io/orkeon/orkeon:latest' }
|
|
399
|
+
$codeVersion = (Get-Content (Join-Path $Root 'package.json') -Raw | ConvertFrom-Json).version
|
|
400
|
+
# A clone (a .git, or the tests of an unpacked source archive) or an install, whose folder is never written to:
|
|
401
|
+
# an install's state goes under ORKEON_CODE_HOME (%USERPROFILE%\.orkeon-code).
|
|
402
|
+
$IsClone = Test-Path (Join-Path $Root '.git')
|
|
403
|
+
if (-not $IsClone) { $IsClone = Test-Path (Join-Path $Root 'tests') -PathType Container }
|
|
404
|
+
$CodeHome = if ($env:ORKEON_CODE_HOME) { $env:ORKEON_CODE_HOME } else { Join-Path $HOME '.orkeon-code' }
|
|
405
|
+
# Where the settings are looked for: %APPDATA% on Windows; elsewhere the XDG base the runtime uses (an absolute
|
|
406
|
+
# XDG_CONFIG_HOME, else ~/.config), as ./orkeon-code does.
|
|
407
|
+
$configBase = if ($env:APPDATA) { $env:APPDATA }
|
|
408
|
+
elseif ($env:XDG_CONFIG_HOME -and [System.IO.Path]::IsPathRooted($env:XDG_CONFIG_HOME)) { $env:XDG_CONFIG_HOME }
|
|
409
|
+
else { Join-Path $HOME '.config' }
|
|
410
|
+
$homeSettings = Join-Path $CodeHome 'appsettings.json'
|
|
411
|
+
$legacySettings = Join-Path $configBase 'orkeon-code/appsettings.json'
|
|
412
|
+
# What `orkeon init` writes and the REPL reads when no --settings is given (RunnerSettings.GetGlobalSettingsPath).
|
|
413
|
+
$runtimeSettings = Join-Path $configBase 'Orkeon/appsettings.json'
|
|
414
|
+
|
|
415
|
+
if ($Sub -eq 'setup') { if (Invoke-Setup $homeSettings) { exit 0 } else { exit 1 } }
|
|
416
|
+
if ($Sub -eq 'trust') {
|
|
417
|
+
$verb = if ($SubArgs.Count -gt 0) { $SubArgs[0] } else { '' }
|
|
418
|
+
$arg = if ($SubArgs.Count -gt 1) { $SubArgs[1] } else { $null }
|
|
419
|
+
$usage = 'usage: orkeon-code trust list | add <path> | remove <path> | check <path> [--trust]'
|
|
420
|
+
switch -CaseSensitive ($verb) {
|
|
421
|
+
'list' {
|
|
422
|
+
foreach ($e in @(Get-TrustEntries)) { Write-Output "$($e.Path) (trusted $($e.TrustedAt))" }
|
|
423
|
+
exit 0
|
|
424
|
+
}
|
|
425
|
+
'add' {
|
|
426
|
+
if (-not $arg) { throw 'trust add needs a folder.' }
|
|
427
|
+
$folder = Get-CanonicalDir $arg
|
|
428
|
+
if (-not $folder) { throw "Not a folder: $arg" }
|
|
429
|
+
$by = Get-TrustedBy $folder
|
|
430
|
+
if ($by -eq $folder) { Write-Output "orkeon-code: $folder is already trusted."; exit 0 }
|
|
431
|
+
if ($by) { Write-Output "orkeon-code: $folder is already trusted, through $by."; exit 0 }
|
|
432
|
+
Add-TrustedFolder $folder
|
|
433
|
+
Write-Output "orkeon-code: trusted $folder."
|
|
434
|
+
exit 0
|
|
435
|
+
}
|
|
436
|
+
'remove' {
|
|
437
|
+
if (-not $arg) { throw 'trust remove needs a folder.' }
|
|
438
|
+
$target = Get-CanonicalDir $arg
|
|
439
|
+
if (-not $target) { $target = if ($arg.Length -gt [System.IO.Path]::GetPathRoot($arg).Length) { $arg.TrimEnd('\', '/') } else { $arg } }
|
|
440
|
+
$cmp = if ($onWindows) { [StringComparison]::OrdinalIgnoreCase } else { [StringComparison]::Ordinal }
|
|
441
|
+
$entries = @(Get-TrustEntries)
|
|
442
|
+
$kept = @($entries | Where-Object { -not [string]::Equals($_.Path, $target, $cmp) })
|
|
443
|
+
if ($kept.Count -eq $entries.Count) {
|
|
444
|
+
$by = Get-TrustedBy $target
|
|
445
|
+
if ($by) { throw "$target is not in the store: it is trusted through $by." }
|
|
446
|
+
throw "$target is not a trusted folder."
|
|
447
|
+
}
|
|
448
|
+
Write-TrustStore $kept
|
|
449
|
+
Write-Output "orkeon-code: $target is no longer trusted."
|
|
450
|
+
exit 0
|
|
451
|
+
}
|
|
452
|
+
'check' {
|
|
453
|
+
# 0: it may start; 3: refused, no terminal; 4: declined in the terminal.
|
|
454
|
+
if (-not $arg) { throw 'trust check needs a folder.' }
|
|
455
|
+
$folder = Get-CanonicalDir $arg
|
|
456
|
+
if (-not $folder) { throw "Not a folder: $arg" }
|
|
457
|
+
Confirm-Trusted $folder ($Trust.IsPresent -or (($SubArgs.Count -gt 2) -and $SubArgs[2] -eq '--trust')) 4
|
|
458
|
+
exit 0
|
|
459
|
+
}
|
|
460
|
+
default { throw $usage }
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if ($Version -or ($Extra -contains '--version')) {
|
|
465
|
+
# The Orkeon found, said without starting anything: the REPL has no --version flag, and docker pulls nothing.
|
|
466
|
+
$replName = if ($env:ORKEON_REPL) { ($env:ORKEON_REPL -split ' ')[0] } else { 'orkeon-repl' }
|
|
467
|
+
$replFound = Get-Command $replName -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
468
|
+
# A mode forced by -Mode or ORKEON_CODE_MODE names its runtime; otherwise the auto-detection order speaks.
|
|
469
|
+
$found = if ($Mode -eq 'docker') { "image $Image (docker mode, not pulled)" }
|
|
470
|
+
elseif ($replFound -and $replFound.Source) {
|
|
471
|
+
$replPath = (Get-Item -LiteralPath $replFound.Source).FullName
|
|
472
|
+
$target = (Get-Item -LiteralPath $replPath).Target
|
|
473
|
+
if ($target) { $replPath = [IO.Path]::GetFullPath((Join-Path (Split-Path $replPath -Parent) "$target")) }
|
|
474
|
+
# An Orkeon release archive installs bin/orkeon-repl beside its VERSION file.
|
|
475
|
+
$versionFile = Join-Path (Split-Path (Split-Path $replPath -Parent) -Parent) 'VERSION'
|
|
476
|
+
if (Test-Path -LiteralPath $versionFile) { "$((Get-Content -LiteralPath $versionFile -Raw).Trim()) ($replName, $versionFile)" }
|
|
477
|
+
else { "unknown ($replPath)" }
|
|
478
|
+
} elseif (Get-Command docker -ErrorAction SilentlyContinue) { "image $Image (docker mode, not pulled)" }
|
|
479
|
+
else { 'none (see docs/getting-started.md)' }
|
|
480
|
+
$kind = if ($IsClone) { 'clone' } else { 'install' }
|
|
481
|
+
Write-Output "orkeon-code $codeVersion ($kind`: $Root)"
|
|
482
|
+
Write-Output "Orkeon $OrkeonPin expected, found: $found"
|
|
483
|
+
exit 0
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
# Full, its link resolved: the folder checked, stored and mounted is the same one.
|
|
487
|
+
$given = $Workspace
|
|
488
|
+
$Workspace = Get-CanonicalDir $Workspace
|
|
489
|
+
if (-not $Workspace) { throw "Workspace not found: $given" }
|
|
490
|
+
# Before anything of the project is read or mounted.
|
|
491
|
+
Confirm-Trusted $Workspace $Trust.IsPresent 0
|
|
492
|
+
|
|
493
|
+
# $runtimeOwn: Orkeon's own file, which the REPL reads itself when no --settings is passed.
|
|
494
|
+
$runtimeOwn = $false
|
|
495
|
+
if (-not $Settings) {
|
|
496
|
+
$candidates = @($homeSettings, $legacySettings)
|
|
497
|
+
if ($IsClone) { $candidates = @((Join-Path $Root 'config/appsettings.local.json')) + $candidates }
|
|
498
|
+
$Settings = $candidates | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1
|
|
499
|
+
if (-not $Settings -and (Test-Path -LiteralPath $runtimeSettings)) { $Settings = $runtimeSettings; $runtimeOwn = $true }
|
|
500
|
+
if ($Settings -eq $legacySettings) { Write-Warning "$legacySettings is the old place of the settings: move it to $homeSettings." }
|
|
501
|
+
if (-not $Settings -and -not [Console]::IsInputRedirected) {
|
|
502
|
+
[Console]::Error.WriteLine('orkeon-code: no settings file yet.')
|
|
503
|
+
if (Invoke-Setup $homeSettings) { $Settings = $homeSettings }
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (-not $Settings -or -not (Test-Path $Settings)) {
|
|
507
|
+
if ($IsClone) { throw "No settings file. Run 'orkeon-code setup' in a terminal, copy config/appsettings.example.json to config/appsettings.local.json, or pass -Settings." }
|
|
508
|
+
throw "No settings file. Run 'orkeon-code setup' in a terminal, copy $(Join-Path $Root 'config/appsettings.example.json') to $homeSettings, or pass -Settings."
|
|
509
|
+
}
|
|
510
|
+
$Settings = (Resolve-Path $Settings).Path
|
|
511
|
+
|
|
512
|
+
$settingsText = Get-Content $Settings -Raw -Encoding UTF8 # Windows PowerShell 5.1 reads ANSI otherwise
|
|
513
|
+
$keyVar = if ($settingsText -match '"ApiKeyEnvVar"\s*:\s*"([A-Za-z_][A-Za-z0-9_]*)"') { $Matches[1] } else { $null }
|
|
514
|
+
if ($settingsText -notmatch '"Llm"') {
|
|
515
|
+
Write-Warning "$Settings has no `"Llm`" section: every turn would be empty."
|
|
516
|
+
} elseif (-not $env:ORKEON_Llm__ApiKey -and $keyVar -and -not [Environment]::GetEnvironmentVariable($keyVar)) {
|
|
517
|
+
Write-Warning "No API key: set `$env:$keyVar (named by Llm:ApiKeyEnvVar) or `$env:ORKEON_Llm__ApiKey."
|
|
518
|
+
}
|
|
519
|
+
if ($env:ORKEON_CODE_MODEL) { $env:ORKEON_Llm__Model = $env:ORKEON_CODE_MODEL }
|
|
520
|
+
# The host's permission gate checks every tool call against the session's rules (/permissions), then the
|
|
521
|
+
# mode, and asks you when the mode says so; off, no call is checked. On by default here; a settings file
|
|
522
|
+
# can still turn it off.
|
|
523
|
+
if (-not $env:Orkeon__Security__PermissionGate__Enabled) { $env:Orkeon__Security__PermissionGate__Enabled = 'true' }
|
|
524
|
+
|
|
525
|
+
if ($Continue -and $Resume) { throw '--continue and --resume do not go together: one brings the last session back, the other the one you pick.' }
|
|
526
|
+
|
|
527
|
+
if (-not $Mode) {
|
|
528
|
+
if ($env:ORKEON_REPL -or (Get-Command orkeon-repl -ErrorAction SilentlyContinue)) { $Mode = 'tool' }
|
|
529
|
+
elseif (Get-Command docker -ErrorAction SilentlyContinue) { $Mode = 'docker' }
|
|
530
|
+
else { throw 'No Orkeon runtime found: install Docker or the orkeon-repl tool (docs/getting-started.md).' }
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
# An install keeps one folder per project, ~/.orkeon-code/projects/<slug>; a clone's .crew-output and an
|
|
534
|
+
# ORKEON_CODE_STATE may serve several projects, so their per-project part goes under projects/<slug>. Either way
|
|
535
|
+
# $projectState lies inside $State, which docker mode mounts on /work/state.
|
|
536
|
+
$slug = Get-ProjectSlug $Workspace
|
|
537
|
+
$projectRel = "projects/$slug"
|
|
538
|
+
if ($env:ORKEON_CODE_STATE) { $State = $env:ORKEON_CODE_STATE }
|
|
539
|
+
elseif ($IsClone) { $State = Join-Path $Root '.crew-output' }
|
|
540
|
+
else { $State = Join-Path $CodeHome $projectRel; $projectRel = '' }
|
|
541
|
+
New-Item -ItemType Directory -Force -Path (Join-Path $State 'output'), (Join-Path $State 'tmp') | Out-Null
|
|
542
|
+
$State = (Resolve-Path $State).Path
|
|
543
|
+
$projectState = if ($projectRel) { Join-Path $State $projectRel } else { $State }
|
|
544
|
+
# The runtime saves the session in <SessionsDirectory>/<its slug of the project>/last.json when the REPL ends, and
|
|
545
|
+
# reloads it at the next start. The folder is the /sessions mount, outside the project; the launcher keeps its own
|
|
546
|
+
# files beside it: history/ and project.json.
|
|
547
|
+
$sessions = Join-Path $projectState 'sessions'
|
|
548
|
+
$history = Join-Path $projectState 'history'
|
|
549
|
+
# The typed memory (Orkeon #286) is kept beside them, in <RootDirectory>/<its slug>/memory.json on the /memory
|
|
550
|
+
# mount, outside the project so that neither git nor the file tools see it.
|
|
551
|
+
$memory = Join-Path $projectState 'memory'
|
|
552
|
+
New-Item -ItemType Directory -Force -Path $sessions, $history, $memory | Out-Null
|
|
553
|
+
$runtimeSlug = if ($Mode -eq 'docker') { Get-ProjectSlug '/work/project' } else { $slug }
|
|
554
|
+
$projectFile = Join-Path $projectState 'project.json'
|
|
555
|
+
$now = [DateTime]::UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", [System.Globalization.CultureInfo]::InvariantCulture)
|
|
556
|
+
$firstSeen = Get-JsonField $projectFile 'firstSeen'
|
|
557
|
+
if (-not $firstSeen) { $firstSeen = $now }
|
|
558
|
+
$escapedPath = ($Workspace -replace '\\', '\\') -replace '"', '\"'
|
|
559
|
+
[System.IO.File]::WriteAllText("$projectFile.tmp.$PID",
|
|
560
|
+
"{`n `"path`": `"$escapedPath`",`n `"slug`": `"$slug`",`n `"runtimeSlug`": `"$runtimeSlug`",`n" +
|
|
561
|
+
" `"firstSeen`": `"$firstSeen`",`n `"lastSeen`": `"$now`"`n}`n")
|
|
562
|
+
Move-Item -LiteralPath "$projectFile.tmp.$PID" -Destination $projectFile -Force
|
|
563
|
+
|
|
564
|
+
# The starts open on this project, one pid a line (a launcher waits for its REPL). Another one still running: its
|
|
565
|
+
# session is left where it is, and this one is kept beside it, in side/<pid>/, archived at the next start that
|
|
566
|
+
# finds none open.
|
|
567
|
+
$lock = Join-Path $projectState '.lock'
|
|
568
|
+
$side = Join-Path $projectState 'side'
|
|
569
|
+
$other = $null
|
|
570
|
+
$livePids = @()
|
|
571
|
+
foreach ($line in @(Get-Content -LiteralPath $lock -ErrorAction SilentlyContinue)) {
|
|
572
|
+
$otherPid = "$line".Trim()
|
|
573
|
+
if ($otherPid -match '^[0-9]{1,9}$' -and [int] $otherPid -ne $PID -and (Get-Process -Id ([int] $otherPid) -ErrorAction SilentlyContinue)) {
|
|
574
|
+
if (-not $other) { $other = $otherPid }
|
|
575
|
+
$livePids += $otherPid
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
# Left when the REPL ends, as ./orkeon-code leaves it: a pid that no longer runs is a stale lock.
|
|
579
|
+
[System.IO.File]::WriteAllText($lock, ((@($livePids) + "$PID") -join "`n") + "`n")
|
|
580
|
+
$sessionsMount = $sessions
|
|
581
|
+
$sessionsSub = 'sessions'
|
|
582
|
+
|
|
583
|
+
# Fresh unless --continue (the runtime reloads the last itself) or --resume (the chosen one is put back).
|
|
584
|
+
$sessionNote = 'fresh; --continue brings the last back, --resume lists them'
|
|
585
|
+
if ($other) {
|
|
586
|
+
Write-Warning "another session is open on this project (pid $other): it is left as it is, and this one is kept beside it, in the history from the next start."
|
|
587
|
+
$sessionNote = 'beside the open one'
|
|
588
|
+
$sessionsMount = Join-Path $side "$PID"
|
|
589
|
+
$sessionsSub = "side/$PID"
|
|
590
|
+
New-Item -ItemType Directory -Force -Path $sessionsMount | Out-Null
|
|
591
|
+
} elseif ($Continue) { $sessionNote = 'continued'; Move-SessionsToHistory $sessions $history $side $true }
|
|
592
|
+
else { Move-SessionsToHistory $sessions $history $side $false }
|
|
593
|
+
$keep = 50
|
|
594
|
+
if ($null -ne $env:ORKEON_CODE_SESSIONS_KEEP) {
|
|
595
|
+
if ($env:ORKEON_CODE_SESSIONS_KEEP -match '^[0-9]{1,4}$' -and [int] $env:ORKEON_CODE_SESSIONS_KEEP -gt 0) { $keep = [int] $env:ORKEON_CODE_SESSIONS_KEEP }
|
|
596
|
+
else { Write-Warning "ORKEON_CODE_SESSIONS_KEEP=$($env:ORKEON_CODE_SESSIONS_KEEP) is not a whole number from 1 to 9999: 50 sessions are kept." }
|
|
597
|
+
}
|
|
598
|
+
Get-HistoryFiles $history | Select-Object -Skip $keep | Remove-Item -Force
|
|
599
|
+
|
|
600
|
+
if ($Resume) {
|
|
601
|
+
$files = @(Get-HistoryFiles $history)
|
|
602
|
+
if ($files.Count -eq 0) { throw "No saved session for $Workspace yet (they are kept in $history)." }
|
|
603
|
+
if (-not $resumeChoice) {
|
|
604
|
+
[Console]::Error.WriteLine("orkeon-code: sessions of $Workspace, newest first:")
|
|
605
|
+
for ($i = 0; $i -lt $files.Count; $i++) {
|
|
606
|
+
$saved = try { Get-Content -LiteralPath $files[$i].FullName -Raw -Encoding UTF8 | ConvertFrom-Json } catch { $null }
|
|
607
|
+
$title = if ($saved -and $saved.Title) { $saved.Title } else { '(untitled)' }
|
|
608
|
+
$count = if ($saved -and $saved.Messages) { @($saved.Messages).Count } else { 0 }
|
|
609
|
+
$stem = $files[$i].BaseName
|
|
610
|
+
[Console]::Error.WriteLine(('{0,3} {1} {2} ({3} messages) {4}' -f ($i + 1), $stem.Substring(0, [Math]::Min(16, $stem.Length)), $title, $count, $(if ($stem.Length -gt 17) { $stem.Substring(17) } else { '' })))
|
|
611
|
+
}
|
|
612
|
+
if ([Console]::IsInputRedirected) {
|
|
613
|
+
[Console]::Error.WriteLine('orkeon-code: no terminal to choose in: pass --resume <number or id>.')
|
|
614
|
+
exit 2
|
|
615
|
+
}
|
|
616
|
+
$resumeChoice = Read-Answer 'Session to resume [1]: ' '1'
|
|
617
|
+
if ($null -eq $resumeChoice) { $resumeChoice = '1' }
|
|
618
|
+
}
|
|
619
|
+
$chosen = $null
|
|
620
|
+
# A number of the list first (up to four digits), else the start of an id.
|
|
621
|
+
if ($resumeChoice -match '^[1-9][0-9]{0,3}$' -and [int] $resumeChoice -le $files.Count) { $chosen = $files[[int] $resumeChoice - 1] }
|
|
622
|
+
if (-not $chosen -and $resumeChoice) {
|
|
623
|
+
$matching = @($files | Where-Object { $_.BaseName.Length -gt 17 -and $_.BaseName.Substring(17).StartsWith($resumeChoice, [StringComparison]::Ordinal) })
|
|
624
|
+
if ($matching.Count -gt 1) { throw "More than one session starts with '$resumeChoice': give more of its id." }
|
|
625
|
+
if ($matching.Count -eq 1) { $chosen = $matching[0] }
|
|
626
|
+
}
|
|
627
|
+
if (-not $chosen) { throw "No saved session '$resumeChoice' (orkeon-code --resume lists them)." }
|
|
628
|
+
if ($other) { throw "Another session is open on this project (pid $other): end it before you resume one." }
|
|
629
|
+
# The chosen session lives in one place: back in sessions/, the history losing it (the last one was archived above).
|
|
630
|
+
$target = Join-Path $sessions $runtimeSlug
|
|
631
|
+
New-Item -ItemType Directory -Force -Path $target | Out-Null
|
|
632
|
+
Move-Item -LiteralPath $chosen.FullName -Destination (Join-Path $target 'last.json') -Force
|
|
633
|
+
$sessionNote = "resumed $($chosen.BaseName.Substring([Math]::Min(17, $chosen.BaseName.Length)))"
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
# The session's start script (scripts/session-start.ork.ts), copied fresh into the agent's /tmp at every start:
|
|
637
|
+
# the runtime runs it once at the REPL's start, through its script host, and puts what it prints before the
|
|
638
|
+
# first free-text turn.
|
|
639
|
+
$startDir = Join-Path $State 'tmp/orkeon-code'
|
|
640
|
+
New-Item -ItemType Directory -Force -Path $startDir | Out-Null
|
|
641
|
+
Copy-Item -Force (Join-Path $Root 'scripts/session-start.ork.ts') (Join-Path $startDir 'session-start.ork.ts')
|
|
642
|
+
if ($null -eq [Environment]::GetEnvironmentVariable('Orkeon__Cli__Session__StartScript')) {
|
|
643
|
+
$env:Orkeon__Cli__Session__StartScript = '/tmp/orkeon-code/session-start.ork.ts'
|
|
644
|
+
}
|
|
645
|
+
# The session persists (the runtime's default in the REPL, said here; a settings file may still turn it off), in
|
|
646
|
+
# /sessions: the prefixed form wins over the settings file, since the archiving above reads that folder alone.
|
|
647
|
+
if (-not $env:Orkeon__Cli__Session__Persist) { $env:Orkeon__Cli__Session__Persist = 'true' }
|
|
648
|
+
$env:ORKEON_Orkeon__Cli__Session__SessionsDirectory = '/sessions'
|
|
649
|
+
$env:ORKEON_Orkeon__Cli__Memory__RootDirectory = '/memory'
|
|
650
|
+
# The embedding model's fingerprint beside the RAG's manifests, in /output, not in the project (see ./orkeon-code).
|
|
651
|
+
if (-not $env:Orkeon__Embeddings__FingerprintPath) { $env:Orkeon__Embeddings__FingerprintPath = '/output/rag/embedding-fingerprint.json' }
|
|
652
|
+
|
|
653
|
+
# Speech-to-text (optional): $env:ORKEON_CODE_AUDIO_DIR names the folder of audio and video files. The
|
|
654
|
+
# Whisper MCP server (mcp/whisper), started by the REPL over stdio, reads it and writes into
|
|
655
|
+
# <state>/transcripts, which the agents see as /audio and /transcripts. It is declared through the
|
|
656
|
+
# environment (ORKEON_MCP__Servers__whisper__*), so no settings file names this checkout; a settings file,
|
|
657
|
+
# or the environment, that declares a "whisper" server keeps it, and this block stays out.
|
|
658
|
+
$audio = $null
|
|
659
|
+
$audioArgs = @()
|
|
660
|
+
if ($env:ORKEON_CODE_AUDIO_DIR) {
|
|
661
|
+
$uv = Get-Command uv -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
662
|
+
if ($Mode -eq 'docker') {
|
|
663
|
+
Write-Warning 'ORKEON_CODE_AUDIO_DIR is ignored in docker mode: the Whisper server runs in tool mode (mcp/whisper/README.md).'
|
|
664
|
+
} elseif ($settingsText -match '"whisper"\s*:') {
|
|
665
|
+
Write-Warning "$Settings declares a `"whisper`" MCP server: ORKEON_CODE_AUDIO_DIR is ignored, the settings file wins."
|
|
666
|
+
} elseif (Get-ChildItem env: | Where-Object { $_.Name -like 'ORKEON_MCP__Servers__whisper__*' }) {
|
|
667
|
+
Write-Warning 'the environment declares a "whisper" MCP server (ORKEON_MCP__Servers__whisper__*): ORKEON_CODE_AUDIO_DIR is ignored, that declaration wins.'
|
|
668
|
+
} elseif (-not $uv) {
|
|
669
|
+
Write-Warning "ORKEON_CODE_AUDIO_DIR is set but uv is not on PATH: speech-to-text is off (mcp/whisper/README.md, 'Install')."
|
|
670
|
+
} else {
|
|
671
|
+
if (-not (Test-Path -LiteralPath $env:ORKEON_CODE_AUDIO_DIR -PathType Container)) {
|
|
672
|
+
throw "ORKEON_CODE_AUDIO_DIR=$($env:ORKEON_CODE_AUDIO_DIR) is not a folder."
|
|
673
|
+
}
|
|
674
|
+
$audio = (Resolve-Path -LiteralPath $env:ORKEON_CODE_AUDIO_DIR).Path
|
|
675
|
+
$transcripts = Join-Path $State 'transcripts'
|
|
676
|
+
New-Item -ItemType Directory -Force -Path $transcripts | Out-Null
|
|
677
|
+
$env:WHISPER_AUDIO_DIR = $audio
|
|
678
|
+
$env:WHISPER_OUT_DIR = $transcripts
|
|
679
|
+
$env:ORKEON_MCP__Servers__whisper__Transport = 'Stdio'
|
|
680
|
+
$env:ORKEON_MCP__Servers__whisper__Command = $uv.Source
|
|
681
|
+
# The gate reads the server's annotations (readOnlyHint) only when the server is trusted (Orkeon #223).
|
|
682
|
+
$env:ORKEON_MCP__Servers__whisper__TrustAnnotations = 'true'
|
|
683
|
+
# The runtime ends a server call after CallTimeout, 60 s by default (Orkeon #299): a dictation records up to
|
|
684
|
+
# /voice --max (600 s) then transcribes.
|
|
685
|
+
$env:ORKEON_MCP__Servers__whisper__CallTimeout = '00:15:00'
|
|
686
|
+
$whisperArgs = @('run', '--project', (Join-Path $Root 'mcp/whisper'))
|
|
687
|
+
# An install's folder is never written to: uv keeps the server's environment under ORKEON_CODE_HOME and
|
|
688
|
+
# reads uv.lock as shipped.
|
|
689
|
+
if (-not $IsClone) {
|
|
690
|
+
$whisperArgs += @('--frozen')
|
|
691
|
+
if (-not $env:UV_PROJECT_ENVIRONMENT) { $env:UV_PROJECT_ENVIRONMENT = Join-Path $CodeHome 'whisper\.venv' }
|
|
692
|
+
}
|
|
693
|
+
# The values are read as the server reads them: case and spaces aside.
|
|
694
|
+
$ttsBackend = "$env:TTS_BACKEND".Trim().ToLowerInvariant()
|
|
695
|
+
$sttBackend = "$env:WHISPER_BACKEND".Trim().ToLowerInvariant()
|
|
696
|
+
if ($env:ORKEON_CODE_VOICE -eq '1') {
|
|
697
|
+
# The microphone (/voice) and the speaker (/say, voice.reply): the `voice` extra (sounddevice),
|
|
698
|
+
# WHISPER_MICROPHONE and WHISPER_SPEAKER.
|
|
699
|
+
$whisperArgs += @('--extra', 'voice')
|
|
700
|
+
$env:WHISPER_MICROPHONE = '1'
|
|
701
|
+
$env:WHISPER_SPEAKER = '1'
|
|
702
|
+
}
|
|
703
|
+
# Piper, the default speech backend, is the `tts` extra: it writes what it would say without the speaker too.
|
|
704
|
+
if ($ttsBackend -in @('', 'piper')) { $whisperArgs += @('--extra', 'tts') }
|
|
705
|
+
# A backend on OpenAI's API or a compatible server needs the `openai` extra, once.
|
|
706
|
+
if (@($ttsBackend, $sttBackend) | Where-Object { $_ -in @('openai', 'http') }) { $whisperArgs += @('--extra', 'openai') }
|
|
707
|
+
# WHISPER_DEVICE=cuda: the cuBLAS and cuDNN wheels, which the server preloads.
|
|
708
|
+
if ("$env:WHISPER_DEVICE".Trim() -eq 'cuda') { $whisperArgs += @('--extra', 'cuda') }
|
|
709
|
+
$whisperArgs += (Join-Path $Root 'mcp/whisper/whisper_mcp.py')
|
|
710
|
+
# Args__0 to Args__12 (13 at most: run, --project, the folder, --frozen, four --extra pairs, the script), each
|
|
711
|
+
# saved above and put back when the script ends.
|
|
712
|
+
for ($i = 0; $i -lt $whisperArgs.Count; $i++) {
|
|
713
|
+
[Environment]::SetEnvironmentVariable("ORKEON_MCP__Servers__whisper__Args__$i", $whisperArgs[$i])
|
|
714
|
+
}
|
|
715
|
+
$audioArgs = @('--mount', "${audio}:/audio:ro", '--mount', "${transcripts}:/transcripts:ro")
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
Write-Host "orkeon-code on Orkeon ($Mode`: a release, the pin is $OrkeonPin)"
|
|
720
|
+
Write-Host " project : $Workspace -> /workspace"
|
|
721
|
+
if ($runtimeOwn) { Write-Host " settings : $Settings (Orkeon's own, read by the REPL)" } else { Write-Host " settings : $Settings" }
|
|
722
|
+
Write-Host " sessions : $sessionsMount ($sessionNote)"
|
|
723
|
+
if ($audio) {
|
|
724
|
+
$model = if ($env:WHISPER_MODEL) { $env:WHISPER_MODEL } elseif ($sttBackend -eq 'openai') { 'whisper-1' } else { 'small' }
|
|
725
|
+
$gpu = if ("$env:WHISPER_DEVICE".Trim() -eq 'cuda') { ' on the GPU' } else { '' }
|
|
726
|
+
$mic = if ($env:ORKEON_CODE_VOICE -eq '1') { ', microphone and speaker on' } else { '' }
|
|
727
|
+
Write-Host " audio : $audio -> /audio (transcripts: $(Join-Path $State 'transcripts'), model $model$gpu$mic)"
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
# The user's orkeonCode block, handed to the scripts as a read-only file: they read no settings and no
|
|
731
|
+
# environment (V-04). Written afresh at each start; no block leaves the folder empty, and no user setting applies.
|
|
732
|
+
$userConfigDir = Join-Path $State 'user-config'
|
|
733
|
+
New-Item -ItemType Directory -Force -Path $userConfigDir | Out-Null
|
|
734
|
+
$userConfigFile = Join-Path $userConfigDir 'config.json'
|
|
735
|
+
Remove-Item $userConfigFile -Force -ErrorAction SilentlyContinue
|
|
736
|
+
try {
|
|
737
|
+
# The key case for case, as ./orkeon-code reads it (a property name is matched without case otherwise).
|
|
738
|
+
$block = (($settingsText | ConvertFrom-Json -ErrorAction Stop).PSObject.Properties |
|
|
739
|
+
Where-Object { $_.Name -ceq 'orkeonCode' } | Select-Object -First 1).Value
|
|
740
|
+
if ($block -is [System.Management.Automation.PSCustomObject]) {
|
|
741
|
+
[System.IO.File]::WriteAllText($userConfigFile, ($block | ConvertTo-Json -Depth 10) + "`n")
|
|
742
|
+
}
|
|
743
|
+
} catch {
|
|
744
|
+
Write-Warning "The orkeonCode block of $Settings could not be read: no user setting applies."
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
# An empty <settings> passes none: the REPL then reads Orkeon's own file. <projectState> as the REPL sees it: its
|
|
748
|
+
# sessions/ on /sessions, its history/ on /session-history (read-only, for /resume), its memory/ on /memory.
|
|
749
|
+
function Get-ReplArgs($commands, $crews, $settings, $workspace, $output, $tmp, $userConfig, $projectState) {
|
|
750
|
+
@('--runner=scripted-commands', '--commands-dir', $commands, '--crews-dir', $crews)
|
|
751
|
+
if ($settings) { @('--settings', $settings) }
|
|
752
|
+
@('--mount', "${workspace}:/workspace:rw", '--mount', "${output}:/output:rw", '--mount', "${tmp}:/tmp:rw",
|
|
753
|
+
'--mount', "${userConfig}:/user-config:ro",
|
|
754
|
+
'--mount', "${projectState}/${sessionsSub}:/sessions:rw", '--mount', "${projectState}/history:/session-history:ro",
|
|
755
|
+
'--mount', "${projectState}/memory:/memory:rw")
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
# The physical folders of tool mode's mounts, in Get-ReplArgs order from <workspace>.
|
|
759
|
+
$hostMounts = @($Workspace, (Join-Path $State 'output'), (Join-Path $State 'tmp'), $userConfigDir, $projectState)
|
|
760
|
+
|
|
761
|
+
# A mount's base as Windows spells it: absolute, backslashes, no trailing separator but a drive root's (C:\); a UNC
|
|
762
|
+
# path resolved by its provider.
|
|
763
|
+
function Get-WindowsBase([string] $path) {
|
|
764
|
+
if ($path.StartsWith('\\') -or $path.StartsWith('//')) {
|
|
765
|
+
$resolved = Resolve-Path -LiteralPath $path -ErrorAction SilentlyContinue
|
|
766
|
+
if ($resolved) { $path = $resolved.ProviderPath }
|
|
767
|
+
}
|
|
768
|
+
$full = [IO.Path]::GetFullPath(($path -replace '/', '\'))
|
|
769
|
+
if ($full -match '^[A-Za-z]:\\$') { $full } else { $full.TrimEnd('\', '/') }
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
# launch.json, beside config.json on /user-config, as ./orkeon-code writes it: the host the REPL runs on (windows
|
|
773
|
+
# here, posix or wsl under pwsh elsewhere) and the physical base of each mount, the very string given to --mount,
|
|
774
|
+
# with its Windows spelling. Docker mode hides the host on purpose: posix, no mount. Rewritten at every start. What
|
|
775
|
+
# it reads beyond the rest of the launcher: WSL_DISTRO_NAME, and ORKEON_CODE_PROC_VERSION (the tests' /proc/version).
|
|
776
|
+
function Write-LaunchFile {
|
|
777
|
+
$ErrorActionPreference = 'Continue'
|
|
778
|
+
$file = Join-Path $userConfigDir 'launch.json'
|
|
779
|
+
$procVersion = if ($env:ORKEON_CODE_PROC_VERSION) { $env:ORKEON_CODE_PROC_VERSION } else { '/proc/version' }
|
|
780
|
+
$flavour = if ($Mode -eq 'docker') { 'posix' }
|
|
781
|
+
elseif ($IsWindows -or $PSVersionTable.PSEdition -eq 'Desktop') { 'windows' }
|
|
782
|
+
elseif ($env:WSL_DISTRO_NAME -or ((Test-Path -LiteralPath $procVersion) -and
|
|
783
|
+
"$(Get-Content -LiteralPath $procVersion -Raw -ErrorAction SilentlyContinue)" -match 'microsoft')) { 'wsl' }
|
|
784
|
+
else { 'posix' }
|
|
785
|
+
$wslpath = $null
|
|
786
|
+
if ($flavour -eq 'wsl') {
|
|
787
|
+
$wslpath = Get-Command wslpath -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
788
|
+
if (-not $wslpath) { Write-Warning "wslpath is not on PATH: $file gives no Windows spelling of the mounts." }
|
|
789
|
+
}
|
|
790
|
+
$launch = [ordered]@{ version = 1; flavour = $flavour; mode = $Mode }
|
|
791
|
+
if ($flavour -eq 'wsl') {
|
|
792
|
+
# The distribution: WSL_DISTRO_NAME, else the share of `wslpath -w /` (\\wsl.localhost\<distro>\ or \\wsl$\<distro>\).
|
|
793
|
+
$distro = $env:WSL_DISTRO_NAME
|
|
794
|
+
if (-not $distro -and $wslpath -and "$(& $wslpath.Source -w / 2>$null)" -match '^\\\\wsl(\.localhost|\$)\\([^\\]+)') {
|
|
795
|
+
$distro = $Matches[2]
|
|
796
|
+
}
|
|
797
|
+
# Where the Windows drives are mounted: `wslpath -u 'C:\'` less its /c, else [automount] root= of /etc/wsl.conf,
|
|
798
|
+
# else /mnt.
|
|
799
|
+
$automount = $null
|
|
800
|
+
$drive = if ($wslpath) { "$(& $wslpath.Source -u 'C:\' 2>$null)" } else { '' }
|
|
801
|
+
if ($drive) { $automount = $drive.TrimEnd('/') -replace '/c$', ''; if (-not $automount) { $automount = '/' } }
|
|
802
|
+
else {
|
|
803
|
+
$section = ''
|
|
804
|
+
foreach ($line in @(Get-Content -LiteralPath '/etc/wsl.conf' -ErrorAction SilentlyContinue)) {
|
|
805
|
+
if ($line -match '^\s*\[([^\]]*)\]') { $section = $Matches[1].Trim().ToLowerInvariant() }
|
|
806
|
+
elseif ($section -eq 'automount' -and $line -match '^\s*root\s*=\s*"?([^"]*?)"?\s*$' -and $Matches[1]) {
|
|
807
|
+
$automount = $Matches[1].TrimEnd('/'); if (-not $automount) { $automount = '/' }
|
|
808
|
+
break
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
if (-not $automount) { $automount = '/mnt' }
|
|
812
|
+
}
|
|
813
|
+
$launch['wsl'] = [ordered]@{ distro = $(if ($distro) { $distro } else { $null }); automountRoot = $automount }
|
|
814
|
+
}
|
|
815
|
+
$mounts = [ordered]@{}
|
|
816
|
+
if ($Mode -ne 'docker') {
|
|
817
|
+
$pairs = @(Get-ReplArgs '' '' '' @hostMounts) + @($audioArgs)
|
|
818
|
+
for ($i = 1; $i -lt $pairs.Count; $i++) {
|
|
819
|
+
if ($pairs[$i - 1] -cne '--mount' -or $pairs[$i] -notmatch '^(.*):([^:]+):([^:]+)$') { continue }
|
|
820
|
+
$base = $Matches[1]; $root = $Matches[2]
|
|
821
|
+
$mount = [ordered]@{}
|
|
822
|
+
if ($flavour -eq 'windows') { $mount['windows'] = Get-WindowsBase $base }
|
|
823
|
+
else {
|
|
824
|
+
$mount['posix'] = $base
|
|
825
|
+
if ($flavour -eq 'wsl') {
|
|
826
|
+
$spelled = if ($wslpath) { "$(& $wslpath.Source -w $base 2>$null)" } else { '' }
|
|
827
|
+
$mount['windows'] = $(if ($spelled) { $spelled } else { $null })
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
$mounts[$root] = $mount
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
$launch['mounts'] = $mounts
|
|
834
|
+
try {
|
|
835
|
+
# UTF-8 without a BOM on Windows PowerShell 5.1 too (Set-Content would write a BOM, or UTF-16).
|
|
836
|
+
[System.IO.File]::WriteAllText($file, ($launch | ConvertTo-Json -Depth 5 -Compress) + "`n", (New-Object System.Text.UTF8Encoding $false))
|
|
837
|
+
} catch { Write-Warning "Could not write $file." }
|
|
838
|
+
}
|
|
839
|
+
Write-LaunchFile
|
|
840
|
+
|
|
841
|
+
# The exchange log (--llm-log) would land in ./llm-logs, the project: a bare --llm-log among the REPL's arguments
|
|
842
|
+
# is sent to <projectState>/llm-logs instead; an explicit --llm-log-path is passed as given.
|
|
843
|
+
function Get-LlmLogArgs($projectState) {
|
|
844
|
+
# An explicit --llm-log-path wins: a bare --llm-log beside it is dropped (the runtime keeps the last path it reads).
|
|
845
|
+
$named = @($Extra | Where-Object { "$_" -ceq '--llm-log-path' -or "$_".StartsWith('--llm-log-path=', [StringComparison]::Ordinal) }).Count -gt 0
|
|
846
|
+
foreach ($a in $Extra) { if ($a -ceq '--llm-log') { if (-not $named) { '--llm-log-path'; "$projectState/llm-logs" } } else { $a } }
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
# Whether the Docker engine answers. Its own function, so the launcher's 'Stop' does not turn a warning on stderr
|
|
850
|
+
# into a failure.
|
|
851
|
+
function Test-DockerEngine {
|
|
852
|
+
$ErrorActionPreference = 'Continue'
|
|
853
|
+
& docker version --format '{{.Server.Version}}' 2>$null | Out-Null
|
|
854
|
+
$LASTEXITCODE -eq 0
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
if ($Mode -eq 'docker') {
|
|
858
|
+
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { throw 'docker not found.' }
|
|
859
|
+
# `docker run` alone would answer with the pipe or the socket it could not open, and nothing about what to do.
|
|
860
|
+
if (-not (Test-DockerEngine)) {
|
|
861
|
+
throw 'The Docker engine does not answer: start Docker Desktop or the Docker service, then run orkeon-code again. Without Docker, install the orkeon-repl tool (docs/getting-started.md).'
|
|
862
|
+
}
|
|
863
|
+
# Everything under the working directory /work. The image is multi-arch (linux/amd64, linux/arm64).
|
|
864
|
+
$envArgs = @('-e', 'ORKEON_ENTRYPOINT=repl', '-e', 'HOME=/tmp', '-e', 'DOTNET_CLI_HOME=/tmp',
|
|
865
|
+
'-e', "Orkeon__Security__PermissionGate__Enabled=$env:Orkeon__Security__PermissionGate__Enabled",
|
|
866
|
+
'-e', "Orkeon__Cli__Session__StartScript=$env:Orkeon__Cli__Session__StartScript",
|
|
867
|
+
'-e', "Orkeon__Cli__Session__Persist=$env:Orkeon__Cli__Session__Persist",
|
|
868
|
+
'-e', 'ORKEON_Orkeon__Cli__Session__SessionsDirectory=/sessions',
|
|
869
|
+
'-e', 'ORKEON_Orkeon__Cli__Memory__RootDirectory=/memory',
|
|
870
|
+
'-e', "Orkeon__Embeddings__FingerprintPath=$env:Orkeon__Embeddings__FingerprintPath")
|
|
871
|
+
# The github tool's token (Orkeon #222): GITHUB_TOKEN, GH_TOKEN, or the variable Orkeon__Tools__GitHub__TokenVariable
|
|
872
|
+
# names, each handed over only when set, with the setting itself so the runtime reads the same variable.
|
|
873
|
+
$tokenVar = [Environment]::GetEnvironmentVariable('Orkeon__Tools__GitHub__TokenVariable')
|
|
874
|
+
foreach ($v in @('ORKEON_Llm__ApiKey', 'ORKEON_Llm__Model', $keyVar, 'GITHUB_TOKEN', 'GH_TOKEN', 'Orkeon__Tools__GitHub__TokenVariable', $tokenVar)) {
|
|
875
|
+
if ($v -and [Environment]::GetEnvironmentVariable($v)) { $envArgs += @('-e', $v) }
|
|
876
|
+
}
|
|
877
|
+
$inState = if ($projectRel) { "/work/state/$projectRel" } else { '/work/state' }
|
|
878
|
+
$replArgs = Get-ReplArgs '/work/agent/commands' '/work/agent/crews' '/work/settings.json' `
|
|
879
|
+
'/work/project' '/work/state/output' '/work/state/tmp' '/work/state/user-config' $inState
|
|
880
|
+
$Extra = @(Get-LlmLogArgs $inState)
|
|
881
|
+
# -t only on a terminal, as ./orkeon-code: with stdin or stdout redirected docker refuses it ("not a TTY").
|
|
882
|
+
$ttyArgs = if ([Console]::IsInputRedirected -or [Console]::IsOutputRedirected) { @('-i') } else { @('-it') }
|
|
883
|
+
# Files the agent writes in the project belong to the caller, not to root (Linux; Docker Desktop maps them itself).
|
|
884
|
+
$userArgs = @()
|
|
885
|
+
if ($IsLinux) { $userArgs = @('--user', "$(& id -u):$(& id -g)") }
|
|
886
|
+
& docker run --rm @ttyArgs @userArgs @envArgs -w /work `
|
|
887
|
+
-v "${Workspace}:/work/project" -v "$(Join-Path $Root 'src'):/work/agent:ro" `
|
|
888
|
+
-v "${Settings}:/work/settings.json:ro" -v "${State}:/work/state" `
|
|
889
|
+
$Image @replArgs @Extra
|
|
890
|
+
exit $LASTEXITCODE
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
# tool mode: a release-archive install carries its own esbuild (libexec\esbuild-bin, used by
|
|
894
|
+
# its orkeon-repl wrapper), and so does the Debian package (/usr/bin/orkeon-repl, a script that
|
|
895
|
+
# points the runtime at /usr/lib/orkeon/esbuild-bin); otherwise esbuild comes from this
|
|
896
|
+
# checkout's node_modules.
|
|
897
|
+
$repl = @(if ($env:ORKEON_REPL) { $env:ORKEON_REPL -split ' ' } else { 'orkeon-repl' }) # @(): one word stays an array
|
|
898
|
+
$replCmd = Get-Command $repl[0] -ErrorAction SilentlyContinue
|
|
899
|
+
if (-not $replCmd) { throw "$($repl[0]) not found (docs/getting-started.md, 'Tool mode')." }
|
|
900
|
+
$bundled = $false
|
|
901
|
+
if ($replCmd.Source) {
|
|
902
|
+
$installRoot = Split-Path (Split-Path $replCmd.Source -Parent) -Parent
|
|
903
|
+
$bundled = (Test-Path (Join-Path $installRoot 'libexec/esbuild-bin/esbuild.exe')) -or
|
|
904
|
+
(Test-Path (Join-Path $installRoot 'libexec/esbuild-bin/esbuild'))
|
|
905
|
+
# A launcher script that sets ORKEON_ESBUILD_PATH itself (the Debian package's).
|
|
906
|
+
$firstLine = Get-Content $replCmd.Source -TotalCount 1 -ErrorAction SilentlyContinue
|
|
907
|
+
if (-not $bundled -and "$firstLine".StartsWith('#!') -and
|
|
908
|
+
(Select-String -Path $replCmd.Source -Pattern 'ORKEON_ESBUILD_PATH' -SimpleMatch -Quiet)) { $bundled = $true }
|
|
909
|
+
}
|
|
910
|
+
if (-not $bundled -and -not $env:ORKEON_ESBUILD_PATH -and -not (Get-Command esbuild -ErrorAction SilentlyContinue)) {
|
|
911
|
+
$found = Get-ChildItem (Join-Path $Root 'node_modules/@esbuild') -Recurse -Include 'esbuild.exe', 'esbuild' -File -ErrorAction SilentlyContinue |
|
|
912
|
+
Select-Object -First 1
|
|
913
|
+
if (-not $found -and $IsClone) { throw "esbuild not found: run 'npm ci' in $Root, or set ORKEON_ESBUILD_PATH." }
|
|
914
|
+
if (-not $found) { throw 'esbuild not found: install Orkeon from its package or archive (it carries esbuild), or set ORKEON_ESBUILD_PATH.' }
|
|
915
|
+
$env:ORKEON_ESBUILD_PATH = $found.FullName
|
|
916
|
+
}
|
|
917
|
+
$replArgs = Get-ReplArgs (Join-Path $Root 'src/commands') (Join-Path $Root 'src/crews') $(if ($runtimeOwn) { '' } else { $Settings }) `
|
|
918
|
+
@hostMounts
|
|
919
|
+
$Extra = @(Get-LlmLogArgs $projectState)
|
|
920
|
+
# The REPL runs from the project. It reads its --commands-dir and --crews-dir wherever they are, and
|
|
921
|
+
# a --mount outside its working directory (/output, /tmp, /user-config, /sessions, /session-history and /memory, in
|
|
922
|
+
# the state directory, and an --llm-log-path there) under ORKEON_ALLOW_EXTERNAL_MOUNTS (Orkeon GAP-49). The seven roots
|
|
923
|
+
# are distinct, and none is one the REPL keeps (/sandbox, /credentials, /llm-logs, /cli-commands..., /crews...).
|
|
924
|
+
$env:ORKEON_ALLOW_EXTERNAL_MOUNTS = '1'
|
|
925
|
+
Push-Location $Workspace
|
|
926
|
+
try {
|
|
927
|
+
$exe = $repl[0]
|
|
928
|
+
$rest = @($repl | Select-Object -Skip 1) # @(): a single argument stays an array (an if statement would unroll it)
|
|
929
|
+
& $exe @rest @replArgs @audioArgs @Extra
|
|
930
|
+
exit $LASTEXITCODE
|
|
931
|
+
} finally { Pop-Location }
|
|
932
|
+
} finally {
|
|
933
|
+
# A variable that was not set is removed: $null passed to SetEnvironmentVariable from PowerShell
|
|
934
|
+
# arrives as '', which would leave it set, and empty, for the next run.
|
|
935
|
+
foreach ($name in $savedEnv.Keys) {
|
|
936
|
+
if ($null -eq $savedEnv[$name]) { Remove-Item "env:$name" -ErrorAction SilentlyContinue }
|
|
937
|
+
else { [Environment]::SetEnvironmentVariable($name, $savedEnv[$name]) }
|
|
938
|
+
}
|
|
939
|
+
}
|