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
ADDED
|
@@ -0,0 +1,1092 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# orkeon-code: start the Orkeon Code REPL on a project.
|
|
3
|
+
#
|
|
4
|
+
# ./orkeon-code # the current directory is the project
|
|
5
|
+
# ./orkeon-code --workspace ~/src/app # another project
|
|
6
|
+
# ./orkeon-code --demo # the throwaway fixture (scripts/setup-fixture.sh)
|
|
7
|
+
# ./orkeon-code --mode docker|tool|source [--settings FILE] [-- extra REPL args]
|
|
8
|
+
# ./orkeon-code --version # Code's version, where it runs from, the Orkeon expected and found
|
|
9
|
+
# ./orkeon-code --trust # this run only, without asking (nothing stored)
|
|
10
|
+
# ./orkeon-code -c | --continue # the last session of this project, its conversation back
|
|
11
|
+
# ./orkeon-code --resume [<n> | <id>] # list the saved sessions of this project and pick one
|
|
12
|
+
# ./orkeon-code trust list | add <path> | remove <path> | check <path> [--trust] # check: exit 0, 3 or 4
|
|
13
|
+
# ./orkeon-code setup # write ~/.orkeon-code/appsettings.json (never the key)
|
|
14
|
+
#
|
|
15
|
+
# Folder trust: the first start in a folder asks whether you trust it, before anything of it is read
|
|
16
|
+
# or mounted; `y` stores it in ~/.orkeon-code/trusted-folders.json, and every folder below it starts
|
|
17
|
+
# without asking. Without a terminal an untrusted folder is refused (exit 3) unless --trust is given,
|
|
18
|
+
# or ORKEON_CODE_TRUST=1 with CI=true; neither stores anything. --demo trusts its own fixture.
|
|
19
|
+
#
|
|
20
|
+
# What runs: the Orkeon scripted-commands REPL (orkeon-repl) loads the slash
|
|
21
|
+
# commands of src/commands and the crews of src/crews. The project is mounted on
|
|
22
|
+
# the VFS path /workspace (read-write): every file tool, the shell tool and git
|
|
23
|
+
# work there. /output and /tmp are scratch mounts under the state directory, and
|
|
24
|
+
# /user-config (read-only) holds the orkeonCode block of the settings file: the
|
|
25
|
+
# user's own settings, which the project's .orkeon/config.json cannot widen.
|
|
26
|
+
#
|
|
27
|
+
# A clone (a .git or tests/ beside this script) keeps its state in .crew-output and its demo in
|
|
28
|
+
# fixtures/. An install (scripts/install.sh, npm) never writes to its own folder: its demo goes
|
|
29
|
+
# under ORKEON_CODE_HOME (default ~/.orkeon-code) in demo/, the state of each project in
|
|
30
|
+
# projects/<slug>/ (<slug>: the folder's name and a hash of its path, the runtime's own).
|
|
31
|
+
#
|
|
32
|
+
# Sessions: every start is a fresh session. The runtime saves the conversation when the REPL ends,
|
|
33
|
+
# outside the project (<state>/sessions, or .crew-output/projects/<slug>/sessions in a clone); the
|
|
34
|
+
# next start moves it to history/ beside it, where the 50 newest are kept
|
|
35
|
+
# (ORKEON_CODE_SESSIONS_KEEP). --continue brings the last one back, --resume <n or id> an older one;
|
|
36
|
+
# /resume lists them inside the REPL. A bare --llm-log after -- goes to <state>/llm-logs.
|
|
37
|
+
#
|
|
38
|
+
# Modes (auto-detected in this order, or forced with --mode / ORKEON_CODE_MODE):
|
|
39
|
+
# tool orkeon-repl on PATH (from the orkeon Debian package, an Orkeon release archive, or the
|
|
40
|
+
# dotnet tool), or ORKEON_REPL="<command line>" (e.g. "dotnet /opt/orkeon/Orkeon.ConsoleApp.dll")
|
|
41
|
+
# docker ghcr.io/orkeon/orkeon:latest (the last release, not the pin), nothing else to install
|
|
42
|
+
# source an Orkeon checkout named by ORKEON_SOURCE, built there with `dotnet build`, run from the project
|
|
43
|
+
# With none of them, an install downloads the runtime of its pin once, after asking, into ~/.orkeon-code/runtime
|
|
44
|
+
# (tool mode from then on): `orkeon-code runtime install` does it without starting, ORKEON_CODE_RUNTIME_DOWNLOAD=1
|
|
45
|
+
# answers yes where there is no terminal, `orkeon-code runtime remove` deletes it.
|
|
46
|
+
#
|
|
47
|
+
# Settings: --settings, else ORKEON_CODE_SETTINGS, else config/appsettings.local.json (a clone),
|
|
48
|
+
# else ~/.orkeon-code/appsettings.json, else ${XDG_CONFIG_HOME:-~/.config}/orkeon-code/appsettings.json
|
|
49
|
+
# (the old place, read with a warning), else Orkeon's own ${XDG_CONFIG_HOME:-~/.config}/Orkeon/appsettings.json,
|
|
50
|
+
# which the REPL then reads itself. None and a terminal: `setup` runs. Start from
|
|
51
|
+
# config/appsettings.example.json. The API key stays in the environment: the
|
|
52
|
+
# variable named by Llm:ApiKeyEnvVar, or ORKEON_Llm__ApiKey which wins.
|
|
53
|
+
# ORKEON_CODE_MODEL overrides Llm:Model for this run.
|
|
54
|
+
# ORKEON_CODE_AUDIO_DIR=<folder> turns speech-to-text on (tool and source modes): the folder is
|
|
55
|
+
# mounted on /audio (read-only), <state>/transcripts on /transcripts (read-only), and the
|
|
56
|
+
# Whisper MCP server of mcp/whisper is declared to the REPL, run by uv (mcp/whisper/README.md).
|
|
57
|
+
# ORKEON_CODE_VOICE=1 also opens the microphone (/voice) and the speaker (/say, voice.reply).
|
|
58
|
+
set -euo pipefail
|
|
59
|
+
# A CDPATH from the caller would make cd print the folder it enters, into the paths read from it.
|
|
60
|
+
unset CDPATH
|
|
61
|
+
|
|
62
|
+
# Prints <path> with every symlink of its last component followed.
|
|
63
|
+
resolve_links() { # <path>
|
|
64
|
+
local path="$1" target
|
|
65
|
+
while [ -L "$path" ]; do
|
|
66
|
+
target="$(readlink "$path")"
|
|
67
|
+
case "$target" in /*) path="$target" ;; *) path="$(dirname "$path")/$target" ;; esac
|
|
68
|
+
done
|
|
69
|
+
printf '%s\n' "$path"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# Follow symlinks, so a link from ~/.local/bin still finds the checkout or the install's version folder.
|
|
73
|
+
SELF="$(resolve_links "${BASH_SOURCE[0]}")"
|
|
74
|
+
ROOT="$(cd "$(dirname "$SELF")" && pwd -P)"
|
|
75
|
+
# The pin is a commit of Orkeon's main (.orkeon-version, ADR 0013): the source mode runs it; the tool and docker
|
|
76
|
+
# modes run a release, which the pin never names.
|
|
77
|
+
ORKEON_REF="$(tr -d '[:space:]' < "$ROOT/.orkeon-version")"
|
|
78
|
+
ORKEON_PIN="${ORKEON_REF:0:7}"
|
|
79
|
+
CODE_VERSION="$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$ROOT/package.json" | head -n 1)"
|
|
80
|
+
IMAGE="${ORKEON_CODE_IMAGE:-ghcr.io/orkeon/orkeon:latest}"
|
|
81
|
+
# A clone (a .git, folder or worktree file, or the tests of an unpacked source archive) or an
|
|
82
|
+
# install, whose folder is never written to.
|
|
83
|
+
if [ -e "$ROOT/.git" ] || [ -d "$ROOT/tests" ]; then KIND=clone; else KIND=install; fi
|
|
84
|
+
CODE_HOME="${ORKEON_CODE_HOME:-$HOME/.orkeon-code}"
|
|
85
|
+
|
|
86
|
+
die() { echo "orkeon-code: $*" >&2; exit 1; }
|
|
87
|
+
warn() { echo "orkeon-code: warning: $*" >&2; }
|
|
88
|
+
|
|
89
|
+
# ── The runtime downloaded at the first start (ADR 0028) ───────────────────
|
|
90
|
+
# .orkeon-runtime names the archives published for this package: an id, their folder, a SHA-256 per platform. An
|
|
91
|
+
# empty id (a checkout) means there is none. The archive is extracted where it is kept and runs from there.
|
|
92
|
+
RUNTIME_HOME="$CODE_HOME/runtime"
|
|
93
|
+
runtime_field() { # <key>
|
|
94
|
+
[ -f "$ROOT/.orkeon-runtime" ] || return 0
|
|
95
|
+
sed -n "s/^$1=//p" "$ROOT/.orkeon-runtime" 2>/dev/null | head -n 1 | tr -d '[:space:]'
|
|
96
|
+
}
|
|
97
|
+
RUNTIME_ID="$(runtime_field id)"
|
|
98
|
+
RUNTIME_REPL="$RUNTIME_HOME/${RUNTIME_ID:-none}/bin/orkeon-repl"
|
|
99
|
+
runtime_downloaded() { [ -n "$RUNTIME_ID" ] && [ -x "$RUNTIME_REPL" ]; }
|
|
100
|
+
|
|
101
|
+
# The platform as the archives name it; 1 when no archive is built for it.
|
|
102
|
+
runtime_platform() {
|
|
103
|
+
local os arch
|
|
104
|
+
case "$(uname -s)" in Linux) os=linux ;; Darwin) os=osx ;; *) return 1 ;; esac
|
|
105
|
+
case "$(uname -m)" in x86_64|amd64) arch=x64 ;; aarch64|arm64) arch=arm64 ;; *) return 1 ;; esac
|
|
106
|
+
echo "$os-$arch"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1"; else shasum -a 256 "$1"; fi | cut -d ' ' -f 1; }
|
|
110
|
+
|
|
111
|
+
# Downloads the runtime of .orkeon-runtime into $RUNTIME_HOME/<id>, checked against the sum the package carries,
|
|
112
|
+
# and removes the runtimes of earlier packages. Nothing is asked: the callers do.
|
|
113
|
+
download_runtime() {
|
|
114
|
+
local platform sum name work found other
|
|
115
|
+
[ -n "$RUNTIME_ID" ] || die "this checkout names no runtime to download (.orkeon-runtime): use Docker, orkeon-repl or ORKEON_SOURCE (see docs/getting-started.md)."
|
|
116
|
+
platform="$(runtime_platform)" && sum="$(runtime_field "$platform")" && [ -n "$sum" ] \
|
|
117
|
+
|| die "no Orkeon runtime is published for this platform ($(uname -s) $(uname -m)): install Docker, or the orkeon-repl tool (see docs/getting-started.md)."
|
|
118
|
+
name="orkeon-runtime-$RUNTIME_ID-$platform.tar.gz"
|
|
119
|
+
work="$RUNTIME_HOME/.$RUNTIME_ID.new"
|
|
120
|
+
rm -rf "$work"
|
|
121
|
+
mkdir -p "$work"
|
|
122
|
+
echo "orkeon-code: downloading $(runtime_field url)/$name" >&2
|
|
123
|
+
if command -v curl >/dev/null 2>&1; then curl -fSL "$([ -t 2 ] && echo --progress-bar || echo -s)" -o "$work/$name" "$(runtime_field url)/$name"
|
|
124
|
+
elif command -v wget >/dev/null 2>&1; then wget -q -O "$work/$name" "$(runtime_field url)/$name"
|
|
125
|
+
else rm -rf "$work"; die "neither curl nor wget found: the runtime cannot be downloaded."
|
|
126
|
+
fi || { rm -rf "$work"; die "the download of $name failed: nothing installed."; }
|
|
127
|
+
if [ "$(sha256 "$work/$name")" != "$sum" ]; then
|
|
128
|
+
rm -rf "$work"
|
|
129
|
+
die "checksum mismatch for $name (.orkeon-runtime says $sum): the download was deleted, nothing installed."
|
|
130
|
+
fi
|
|
131
|
+
mkdir "$work/tree"
|
|
132
|
+
tar -xzf "$work/$name" -C "$work/tree" || { rm -rf "$work"; die "$name cannot be extracted: nothing installed."; }
|
|
133
|
+
# The archive holds bin/orkeon-repl, at its root or in one folder.
|
|
134
|
+
found="$(find "$work/tree" -maxdepth 3 -path '*/bin/orkeon-repl' -type f | head -n 1)"
|
|
135
|
+
[ -n "$found" ] || { rm -rf "$work"; die "$name holds no bin/orkeon-repl: nothing installed."; }
|
|
136
|
+
chmod 0755 "$found"
|
|
137
|
+
rm -rf "$RUNTIME_HOME/${RUNTIME_ID:?}"
|
|
138
|
+
mv "$(dirname "$(dirname "$found")")" "$RUNTIME_HOME/$RUNTIME_ID"
|
|
139
|
+
rm -rf "$work"
|
|
140
|
+
for other in "$RUNTIME_HOME"/*; do
|
|
141
|
+
if [ -d "$other" ] && [ "$other" != "$RUNTIME_HOME/$RUNTIME_ID" ]; then rm -rf "$other"; fi
|
|
142
|
+
done
|
|
143
|
+
echo "orkeon-code: Orkeon $RUNTIME_ID installed in $RUNTIME_HOME/$RUNTIME_ID (orkeon-code runtime remove deletes it)." >&2
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
# Moves the Orkeon checkout of ORKEON_SOURCE from <head> to the pin, when nothing of the user's is in the way: no
|
|
147
|
+
# change to a tracked file, on main or detached, <head> an ancestor of the pin (fetched from origin's main when
|
|
148
|
+
# missing). Fails, moving nothing, otherwise or with ORKEON_SOURCE_FOLLOW_PIN=0.
|
|
149
|
+
follow_pin() { # <head>
|
|
150
|
+
local branch
|
|
151
|
+
[ "${ORKEON_SOURCE_FOLLOW_PIN:-1}" != 0 ] || return 1
|
|
152
|
+
[ -z "$(git -C "$ORKEON_SOURCE" status --porcelain --untracked-files=no --ignore-submodules=all 2>/dev/null)" ] || return 1
|
|
153
|
+
branch="$(git -C "$ORKEON_SOURCE" symbolic-ref -q --short HEAD || true)"
|
|
154
|
+
case "$branch" in ""|main) ;; *) return 1 ;; esac
|
|
155
|
+
git -C "$ORKEON_SOURCE" cat-file -e "$ORKEON_REF^{commit}" 2>/dev/null \
|
|
156
|
+
|| git -C "$ORKEON_SOURCE" fetch -q origin main 2>/dev/null || return 1
|
|
157
|
+
git -C "$ORKEON_SOURCE" merge-base --is-ancestor "$1" "$ORKEON_REF" 2>/dev/null || return 1
|
|
158
|
+
if [ -n "$branch" ]; then git -C "$ORKEON_SOURCE" merge -q --ff-only "$ORKEON_REF" >/dev/null 2>&1 || return 1
|
|
159
|
+
else git -C "$ORKEON_SOURCE" checkout -q --detach "$ORKEON_REF" 2>/dev/null || return 1
|
|
160
|
+
fi
|
|
161
|
+
echo "orkeon-code: ORKEON_SOURCE moved from ${1:0:7} to the pin $ORKEON_PIN." >&2
|
|
162
|
+
}
|
|
163
|
+
lowered() { printf '%s' "$1" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | tr '[:upper:]' '[:lower:]'; }
|
|
164
|
+
|
|
165
|
+
# The Orkeon found, said without starting anything: the REPL has no --version flag, and docker pulls nothing.
|
|
166
|
+
# A mode forced by --mode or ORKEON_CODE_MODE names its runtime; otherwise the auto-detection order speaks.
|
|
167
|
+
# The source checkout, with its commit when it is a git repository: the line compares it with the pin.
|
|
168
|
+
source_found() {
|
|
169
|
+
local head
|
|
170
|
+
[ -n "${ORKEON_SOURCE:-}" ] || { echo "source checkout (none: set ORKEON_SOURCE)"; return; }
|
|
171
|
+
if head="$(git -C "$ORKEON_SOURCE" rev-parse --short=7 HEAD 2>/dev/null)"; then echo "source checkout $ORKEON_SOURCE at $head"
|
|
172
|
+
else echo "source checkout $ORKEON_SOURCE"
|
|
173
|
+
fi
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
runtime_found() { # <forced mode or empty>
|
|
177
|
+
local repl repl_bin version_file v
|
|
178
|
+
if [ -n "${ORKEON_REPL:-}" ]; then read -r repl _ <<< "$ORKEON_REPL"; else repl=orkeon-repl; fi
|
|
179
|
+
case "$1" in
|
|
180
|
+
source) source_found; return ;;
|
|
181
|
+
docker) echo "image $IMAGE (docker mode, not pulled)"; return ;;
|
|
182
|
+
esac
|
|
183
|
+
if repl_bin="$(command -v "$repl" 2>/dev/null)"; then
|
|
184
|
+
repl_bin="$(resolve_links "$repl_bin")"
|
|
185
|
+
# An Orkeon release archive installs bin/orkeon-repl beside its VERSION file.
|
|
186
|
+
version_file="$(dirname "$(dirname "$repl_bin")")/VERSION"
|
|
187
|
+
if [ -f "$version_file" ]; then echo "$(tr -d '[:space:]' < "$version_file") ($repl, $version_file)"
|
|
188
|
+
elif v="$(dpkg-query -W -f='${Version}' orkeon 2>/dev/null)" && [ -n "$v" ]; then echo "$v ($repl, the orkeon package)"
|
|
189
|
+
else echo "unknown ($repl_bin)"
|
|
190
|
+
fi
|
|
191
|
+
elif runtime_downloaded; then echo "$RUNTIME_ID (downloaded, $RUNTIME_HOME/$RUNTIME_ID)"
|
|
192
|
+
elif command -v docker >/dev/null 2>&1; then echo "image $IMAGE (docker mode, not pulled)"
|
|
193
|
+
elif [ -n "${ORKEON_SOURCE:-}" ]; then source_found
|
|
194
|
+
elif [ -n "$RUNTIME_ID" ]; then echo "none yet ($RUNTIME_ID is downloaded at the first start)"
|
|
195
|
+
else echo "none (see docs/getting-started.md)"
|
|
196
|
+
fi
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
# ── Folder trust ───────────────────────────────────────────────────────────
|
|
200
|
+
# The store holds what the user trusted, one folder per line in the layout write_trust_store gives it: read
|
|
201
|
+
# without node (docker mode needs none), any other layout is refused, never trusted and never rewritten.
|
|
202
|
+
TRUST_FILE="$CODE_HOME/trusted-folders.json"
|
|
203
|
+
|
|
204
|
+
# Prints the stored folders, `<path><TAB><trustedAt>` per line; exits 1, naming the file, on a store it cannot read.
|
|
205
|
+
trust_entries() {
|
|
206
|
+
[ -s "$TRUST_FILE" ] || return 0
|
|
207
|
+
awk '
|
|
208
|
+
function bad() { failed = 1; exit 1 }
|
|
209
|
+
# A JSON string from its first character after the opening quote; sets STR and REST, 0 when it is not one.
|
|
210
|
+
function string(s, i, c, n) {
|
|
211
|
+
STR = ""
|
|
212
|
+
for (i = 1; i <= length(s); i++) {
|
|
213
|
+
c = substr(s, i, 1)
|
|
214
|
+
if (c == "\"") { REST = substr(s, i + 1); return 1 }
|
|
215
|
+
if (c == "\\") {
|
|
216
|
+
n = substr(s, i + 1, 1)
|
|
217
|
+
if (n == "\\" || n == "\"" || n == "/") { STR = STR n; i++; continue }
|
|
218
|
+
return 0
|
|
219
|
+
}
|
|
220
|
+
if (c ~ /[[:cntrl:]]/) return 0
|
|
221
|
+
STR = STR c
|
|
222
|
+
}
|
|
223
|
+
return 0
|
|
224
|
+
}
|
|
225
|
+
{ sub(/\r$/, "") }
|
|
226
|
+
/^[ \t]*$/ { next }
|
|
227
|
+
step == 0 { if ($0 !~ /^[ \t]*\{[ \t]*$/) bad(); step = 1; next }
|
|
228
|
+
step == 1 { if ($0 !~ /^[ \t]*"version"[ \t]*:[ \t]*1[ \t]*,[ \t]*$/) bad(); step = 2; next }
|
|
229
|
+
step == 2 {
|
|
230
|
+
if ($0 ~ /^[ \t]*"folders"[ \t]*:[ \t]*\[[ \t]*\][ \t]*$/) { step = 4; next }
|
|
231
|
+
if ($0 !~ /^[ \t]*"folders"[ \t]*:[ \t]*\[[ \t]*$/) bad(); step = 3; next
|
|
232
|
+
}
|
|
233
|
+
step == 3 && /^[ \t]*\][ \t]*$/ { if (count > 0 && comma) bad(); step = 4; next }
|
|
234
|
+
step == 3 {
|
|
235
|
+
if (count > 0 && !comma) bad()
|
|
236
|
+
line = $0
|
|
237
|
+
if (!sub(/^[ \t]*\{[ \t]*"path"[ \t]*:[ \t]*"/, "", line) || !string(line) || STR == "") bad()
|
|
238
|
+
path = STR; line = REST
|
|
239
|
+
if (!sub(/^[ \t]*,[ \t]*"trustedAt"[ \t]*:[ \t]*"/, "", line) || !string(line)) bad()
|
|
240
|
+
date = STR; line = REST
|
|
241
|
+
if (line ~ /^[ \t]*\}[ \t]*,[ \t]*$/) comma = 1
|
|
242
|
+
else if (line ~ /^[ \t]*\}[ \t]*$/) comma = 0
|
|
243
|
+
else bad()
|
|
244
|
+
count++; out[count] = path "\t" date; next
|
|
245
|
+
}
|
|
246
|
+
step == 4 { if ($0 !~ /^[ \t]*\}[ \t]*$/) bad(); step = 5; next }
|
|
247
|
+
{ bad() }
|
|
248
|
+
END {
|
|
249
|
+
if (failed || step != 5) exit 1
|
|
250
|
+
for (i = 1; i <= count; i++) print out[i]
|
|
251
|
+
}
|
|
252
|
+
' "$TRUST_FILE" || die "$TRUST_FILE is not a trust store this launcher wrote: nothing is trusted, and the file is kept as it is. Fix it, or move it away and trust your folders again (orkeon-code trust add <path>)."
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
# Writes the store from `<path><TAB><trustedAt>` lines on stdin: a temporary file, then a rename.
|
|
256
|
+
write_trust_store() {
|
|
257
|
+
local entries=() line path date first=1 tmp
|
|
258
|
+
while IFS= read -r line; do [ -n "$line" ] && entries+=("$line"); done
|
|
259
|
+
[ -d "$CODE_HOME" ] || { mkdir -p "$CODE_HOME" && chmod 700 "$CODE_HOME"; } || die "could not create $CODE_HOME."
|
|
260
|
+
tmp="$TRUST_FILE.tmp.$$"
|
|
261
|
+
(
|
|
262
|
+
umask 077
|
|
263
|
+
{
|
|
264
|
+
printf '{\n "version": 1,\n'
|
|
265
|
+
if [ ${#entries[@]} -eq 0 ]; then printf ' "folders": []\n'
|
|
266
|
+
else
|
|
267
|
+
printf ' "folders": [\n'
|
|
268
|
+
for line in "${entries[@]}"; do
|
|
269
|
+
path="${line%%$'\t'*}"; date="${line#*$'\t'}"
|
|
270
|
+
path="${path//\\/\\\\}"; path="${path//\"/\\\"}"
|
|
271
|
+
if [ "$first" = 1 ]; then first=0; else printf ',\n'; fi
|
|
272
|
+
printf ' { "path": "%s", "trustedAt": "%s" }' "$path" "$date"
|
|
273
|
+
done
|
|
274
|
+
printf '\n ]\n'
|
|
275
|
+
fi
|
|
276
|
+
printf '}\n'
|
|
277
|
+
} > "$tmp"
|
|
278
|
+
) && mv -f "$tmp" "$TRUST_FILE" || { rm -f "$tmp"; die "could not write $TRUST_FILE."; }
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
# The folder, physical (every symlink resolved), or nothing when it is not a folder.
|
|
282
|
+
canonical_dir() { (cd "$1" 2>/dev/null && pwd -P); }
|
|
283
|
+
|
|
284
|
+
# The runtime's folder name for a project (ProjectKey.Slug, Orkeon.Infrastructure/Session/ProjectKey.cs): the last
|
|
285
|
+
# segment, each UTF-16 unit an ASCII letter or digit lowercased, else '-', then '-' and the first 12 hex of the
|
|
286
|
+
# SHA-256 of the whole path. Bytes under LC_ALL=C: a 4-byte UTF-8 sequence is two UTF-16 units, any other one.
|
|
287
|
+
project_slug() ( # <path>
|
|
288
|
+
LC_ALL=C
|
|
289
|
+
key="$1"; name="$1"; out=""; i=0
|
|
290
|
+
while case "$name" in */|*\\) true ;; *) false ;; esac; do name="${name%?}"; done
|
|
291
|
+
name="${name##*[/\\]}"
|
|
292
|
+
while [ "$i" -lt "${#name}" ]; do
|
|
293
|
+
case "${name:i:1}" in
|
|
294
|
+
[A-Za-z0-9]) out="$out${name:i:1}" ;;
|
|
295
|
+
[$'\x80'-$'\xbf']) ;;
|
|
296
|
+
[$'\xf0'-$'\xf7']) out="$out--" ;;
|
|
297
|
+
*) out="$out-" ;;
|
|
298
|
+
esac
|
|
299
|
+
i=$((i + 1))
|
|
300
|
+
done
|
|
301
|
+
if command -v sha256sum >/dev/null 2>&1; then hash="$(printf '%s' "$key" | sha256sum)"
|
|
302
|
+
else hash="$(printf '%s' "$key" | shasum -a 256)"; fi
|
|
303
|
+
printf '%s-%s\n' "$(printf '%s' "$out" | tr 'A-Z' 'a-z')" "${hash:0:12}"
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
# <text> as a JSON string: \, " and every control character escaped. awk, not bash's ${s//}, whose backslashes in the
|
|
307
|
+
# replacement differ from bash 3.2 to 5.2; bytes, not characters (LC_ALL=C), so UTF-8 passes as it is. No node, no jq.
|
|
308
|
+
json_str() {
|
|
309
|
+
LC_ALL=C awk 'BEGIN {
|
|
310
|
+
s = ARGV[1]; for (i = 1; i < 32; i++) e[sprintf("%c", i)] = sprintf("\\u%04x", i)
|
|
311
|
+
e["\\"] = "\\\\"; e["\""] = "\\\""; e["\n"] = "\\n"; e["\t"] = "\\t"; e["\r"] = "\\r"
|
|
312
|
+
o = "\""; for (i = 1; i <= length(s); i++) { c = substr(s, i, 1); o = o ((c in e) ? e[c] : c) }
|
|
313
|
+
printf "%s\"", o
|
|
314
|
+
}' "$1"
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
# A string field of a session file as stored (its escapes unread), or nothing.
|
|
318
|
+
session_field() { # <file> <field>
|
|
319
|
+
{ sed -nE 's/.*"'"$2"'"[[:space:]]*:[[:space:]]*"(([^"\\]|\\.)*)".*/\1/p' "$1" 2>/dev/null || true; } | head -n 1
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
# The messages of a session file: one "Role" per message.
|
|
323
|
+
session_messages() { # <file>
|
|
324
|
+
{ grep -oE '"Role"[[:space:]]*:' "$1" 2>/dev/null || true; } | wc -l | tr -d ' '
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
# 0 when a session file holds no message ("Messages":[]): a start and a quit.
|
|
328
|
+
session_empty() { # <file>
|
|
329
|
+
grep -qE '"Messages"[[:space:]]*:[[:space:]]*\[[[:space:]]*\]' "$1" 2>/dev/null
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
# Removes from history/ every file of the session <id> (as stored, never the file name), before its new file lands
|
|
333
|
+
# there: a session /resume loaded in place goes on under its id, so its new file replaces the one it was loaded
|
|
334
|
+
# from, under its own name (no collision suffix). Nothing for an empty id.
|
|
335
|
+
drop_history_duplicates() { # <raw id>
|
|
336
|
+
local other
|
|
337
|
+
[ -n "$1" ] || return 0
|
|
338
|
+
for other in "$HISTORY"/*.json; do
|
|
339
|
+
[ -f "$other" ] || continue
|
|
340
|
+
[ "$(session_field "$other" SessionId)" = "$1" ] && rm -f "$other"
|
|
341
|
+
done
|
|
342
|
+
return 0
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
# Moves every session file the runtime saved into history/, under <UTC time>-<session id>.json: the last.json of
|
|
346
|
+
# sessions/ and the archives /resume left beside it (<stamp>-archived.json, moved first so last.json is the newest),
|
|
347
|
+
# unless <side only> is 1, and always those of side/<pid>/ (a start beside an open one, now ended). A session without
|
|
348
|
+
# a message (a start and a quit) is dropped, so it never pushes a real one out of the history; a session that goes
|
|
349
|
+
# on under the id of one already in the history replaces it there (drop_history_duplicates).
|
|
350
|
+
archive_sessions() { # [<side only>]
|
|
351
|
+
local last raw id stamp target n found=() lasts=() folders=()
|
|
352
|
+
[ "${1:-0}" = 1 ] || folders=("$SESSIONS"/*/)
|
|
353
|
+
folders+=("$PROJECT_STATE"/side/*/*/)
|
|
354
|
+
for last in "${folders[@]}"; do
|
|
355
|
+
[ -d "$last" ] || continue
|
|
356
|
+
for last in "$last"*.json; do
|
|
357
|
+
[ -f "$last" ] || continue
|
|
358
|
+
case "$last" in */last.json) lasts+=("$last") ;; *) found+=("$last") ;; esac
|
|
359
|
+
done
|
|
360
|
+
done
|
|
361
|
+
found+=("${lasts[@]}")
|
|
362
|
+
for last in "${found[@]}"; do
|
|
363
|
+
[ -f "$last" ] || continue
|
|
364
|
+
if session_empty "$last"; then rm -f "$last"; continue; fi
|
|
365
|
+
raw="$(session_field "$last" SessionId)"; id="$(printf '%s' "$raw" | tr -c 'A-Za-z0-9._-' '_')"
|
|
366
|
+
drop_history_duplicates "$raw"
|
|
367
|
+
stamp="$(date -u +%Y%m%dT%H%M%SZ)"
|
|
368
|
+
target="$HISTORY/$stamp-${id:-session}.json"; n=2
|
|
369
|
+
while [ -e "$target" ]; do target="$HISTORY/$stamp-${id:-session}-$n.json"; n=$((n + 1)); done
|
|
370
|
+
mv -f "$last" "$target" || die "could not move $last to $HISTORY."
|
|
371
|
+
done
|
|
372
|
+
for last in "$PROJECT_STATE"/side/*/; do [ -d "$last" ] && rm -rf "$last"; done
|
|
373
|
+
return 0
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
# The history, newest first, one file per line.
|
|
377
|
+
history_files() { find "$HISTORY" -maxdepth 1 -type f -name '*.json' 2>/dev/null | LC_ALL=C sort -r; }
|
|
378
|
+
|
|
379
|
+
# Prints the stored folder that covers <folder> (itself or an ancestor); 1 when none does.
|
|
380
|
+
trusted_by() { # <canonical folder>
|
|
381
|
+
local entries path
|
|
382
|
+
entries="$(trust_entries)" || exit 1
|
|
383
|
+
while IFS= read -r path; do
|
|
384
|
+
path="${path%%$'\t'*}"
|
|
385
|
+
[ -n "$path" ] || continue
|
|
386
|
+
if [ "$path" = "$1" ] || [ "$path" = / ]; then printf '%s\n' "$path"; return 0; fi
|
|
387
|
+
case "$1" in "$path"/*) printf '%s\n' "$path"; return 0 ;; esac
|
|
388
|
+
done <<< "$entries"
|
|
389
|
+
return 1
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
trust_add() { # <canonical folder>
|
|
393
|
+
local entries
|
|
394
|
+
case "$1" in *[[:cntrl:]]*) die "a folder whose path holds a control character cannot be trusted: $1" ;; esac
|
|
395
|
+
entries="$(trust_entries)" || exit 1
|
|
396
|
+
{ [ -n "$entries" ] && printf '%s\n' "$entries"; printf '%s\t%s\n' "$1" "$(date -u +%Y-%m-%dT%H:%M:%SZ)"; } | write_trust_store
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
# Returns when <folder> may start: trusted, --trust or CI, or trusted now in a terminal; exits otherwise
|
|
400
|
+
# (DECLINED on a decline, 0 for a start, 3 without a terminal). Nothing of the folder is read here.
|
|
401
|
+
DECLINED=0
|
|
402
|
+
ensure_trusted() { # <canonical folder> <1 when --trust was given>
|
|
403
|
+
local answer
|
|
404
|
+
if [ "$2" = 1 ] || { [ "${ORKEON_CODE_TRUST:-}" = 1 ] && [ "${CI:-}" = true ]; }; then return 0; fi
|
|
405
|
+
trusted_by "$1" >/dev/null && return 0
|
|
406
|
+
if [ ! -t 0 ]; then
|
|
407
|
+
echo "orkeon-code: $1 is not a trusted folder, and there is no terminal to ask in. Trust it once with" \
|
|
408
|
+
"'orkeon-code trust add $1', or pass --trust for this run only." >&2
|
|
409
|
+
exit 3
|
|
410
|
+
fi
|
|
411
|
+
{
|
|
412
|
+
echo "orkeon-code: do you trust the files in this folder?"
|
|
413
|
+
echo " $1"
|
|
414
|
+
echo " The agent reads its AGENTS.md, .orkeon/config.json and .orkeon/repo.yaml, may run the commands"
|
|
415
|
+
echo " .orkeon/repo.yaml names, and git runs the folder's hooks through the shell."
|
|
416
|
+
if [ "$1" = / ] || [ "$1" = "$(canonical_dir "$HOME")" ]; then echo " This trusts every folder below it."; fi
|
|
417
|
+
printf '[y] trust [n] quit: '
|
|
418
|
+
} >&2
|
|
419
|
+
read -r answer || answer=""
|
|
420
|
+
case "$(lowered "$answer")" in
|
|
421
|
+
y|yes) trust_add "$1"; echo "orkeon-code: trusted $1 (orkeon-code trust remove $1 takes it back)." >&2 ;;
|
|
422
|
+
*) echo "orkeon-code: not trusted, nothing started." >&2; exit "$DECLINED" ;;
|
|
423
|
+
esac
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if [ "${1:-}" = trust ]; then
|
|
427
|
+
shift
|
|
428
|
+
case "${1:-}" in
|
|
429
|
+
list)
|
|
430
|
+
entries="$(trust_entries)" || exit 1
|
|
431
|
+
if [ -n "$entries" ]; then
|
|
432
|
+
while IFS=$'\t' read -r path date; do printf '%s (trusted %s)\n' "$path" "$date"; done <<< "$entries"
|
|
433
|
+
fi
|
|
434
|
+
exit 0 ;;
|
|
435
|
+
add)
|
|
436
|
+
entries="$(trust_entries)" || exit 1
|
|
437
|
+
folder="$(canonical_dir "${2:?trust add needs a folder}")" || die "not a folder: $2"
|
|
438
|
+
if by="$(trusted_by "$folder")"; then
|
|
439
|
+
if [ "$by" = "$folder" ]; then echo "orkeon-code: $folder is already trusted."; else echo "orkeon-code: $folder is already trusted, through $by."; fi
|
|
440
|
+
exit 0
|
|
441
|
+
fi
|
|
442
|
+
trust_add "$folder"; echo "orkeon-code: trusted $folder."; exit 0 ;;
|
|
443
|
+
remove)
|
|
444
|
+
target="${2:?trust remove needs a folder}"
|
|
445
|
+
target="$(canonical_dir "$target")" || { target="${2%/}"; [ -n "$target" ] || target=/; }
|
|
446
|
+
entries="$(trust_entries)" || exit 1
|
|
447
|
+
kept="$(printf '%s\n' "$entries" | TARGET="$target" awk -F '\t' '$0 != "" && $1 != ENVIRON["TARGET"]')" || true
|
|
448
|
+
if [ "$kept" = "$entries" ]; then
|
|
449
|
+
if by="$(trusted_by "$target")"; then die "$target is not in the store: it is trusted through $by."; fi
|
|
450
|
+
die "$target is not a trusted folder."
|
|
451
|
+
fi
|
|
452
|
+
printf '%s\n' "$kept" | write_trust_store; echo "orkeon-code: $target is no longer trusted."; exit 0 ;;
|
|
453
|
+
check) # 0: it may start; 3: refused, no terminal; 4: declined in the terminal (scripts/run-crew.sh).
|
|
454
|
+
DECLINED=4
|
|
455
|
+
folder="$(canonical_dir "${2:?trust check needs a folder}")" || die "not a folder: $2"
|
|
456
|
+
ensure_trusted "$folder" "$([ "${3:-}" = --trust ] && echo 1 || echo 0)"; exit 0 ;;
|
|
457
|
+
*) die "usage: orkeon-code trust list | add <path> | remove <path> | check <path> [--trust]" ;;
|
|
458
|
+
esac
|
|
459
|
+
fi
|
|
460
|
+
|
|
461
|
+
# ── Settings: where they are looked for, and setup ─────────────────────────
|
|
462
|
+
# The XDG base the runtime itself uses (an absolute XDG_CONFIG_HOME, else ~/.config).
|
|
463
|
+
case "${XDG_CONFIG_HOME:-}" in /*) CONFIG_BASE="$XDG_CONFIG_HOME" ;; *) CONFIG_BASE="$HOME/.config" ;; esac
|
|
464
|
+
HOME_SETTINGS="$CODE_HOME/appsettings.json"
|
|
465
|
+
LEGACY_SETTINGS="$CONFIG_BASE/orkeon-code/appsettings.json"
|
|
466
|
+
# Has the runtime downloaded, once: asked on the terminal, taken as agreed with ORKEON_CODE_RUNTIME_DOWNLOAD=1,
|
|
467
|
+
# refused without a terminal (3) and on a no (DECLINED), like the folder trust.
|
|
468
|
+
ensure_runtime() {
|
|
469
|
+
local answer
|
|
470
|
+
runtime_downloaded && return 0
|
|
471
|
+
if [ "${ORKEON_CODE_RUNTIME_DOWNLOAD:-}" != 1 ]; then
|
|
472
|
+
if [ ! -t 0 ]; then
|
|
473
|
+
echo "orkeon-code: no Orkeon runtime found, and there is no terminal to ask in before downloading one. Run" \
|
|
474
|
+
"'orkeon-code runtime install' once, or set ORKEON_CODE_RUNTIME_DOWNLOAD=1." >&2
|
|
475
|
+
exit 3
|
|
476
|
+
fi
|
|
477
|
+
{
|
|
478
|
+
echo "orkeon-code: no Orkeon runtime found on this machine."
|
|
479
|
+
echo " Orkeon $RUNTIME_ID can be downloaded once (about 120 MB) into $RUNTIME_HOME."
|
|
480
|
+
printf '[y] download [n] quit: '
|
|
481
|
+
} >&2
|
|
482
|
+
read -r answer || answer=""
|
|
483
|
+
case "$(lowered "$answer")" in
|
|
484
|
+
y|yes) ;;
|
|
485
|
+
*) echo "orkeon-code: nothing downloaded, nothing started." >&2; exit "$DECLINED" ;;
|
|
486
|
+
esac
|
|
487
|
+
fi
|
|
488
|
+
download_runtime
|
|
489
|
+
}
|
|
490
|
+
if [ "${1:-}" = runtime ]; then
|
|
491
|
+
case "${2:-}" in
|
|
492
|
+
install)
|
|
493
|
+
if runtime_downloaded; then echo "orkeon-code: Orkeon $RUNTIME_ID is already in $RUNTIME_HOME/$RUNTIME_ID."; exit 0; fi
|
|
494
|
+
download_runtime; exit 0 ;;
|
|
495
|
+
remove)
|
|
496
|
+
rm -rf "$RUNTIME_HOME"; echo "orkeon-code: no downloaded runtime left in $RUNTIME_HOME."; exit 0 ;;
|
|
497
|
+
*) die "usage: orkeon-code runtime install | remove" ;;
|
|
498
|
+
esac
|
|
499
|
+
fi
|
|
500
|
+
|
|
501
|
+
# What `orkeon init` writes and the REPL reads when no --settings is given (RunnerSettings.GetGlobalSettingsPath).
|
|
502
|
+
RUNTIME_SETTINGS="$CONFIG_BASE/Orkeon/appsettings.json"
|
|
503
|
+
|
|
504
|
+
# Asks one line on the terminal; the answer, trimmed, or <default> when it is empty; 1 on end of input.
|
|
505
|
+
ask() { # <question> <default>
|
|
506
|
+
local answer
|
|
507
|
+
printf '%s' "$1" >&2
|
|
508
|
+
read -r answer || return 1
|
|
509
|
+
answer="$(printf '%s' "$answer" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
|
|
510
|
+
printf '%s\n' "${answer:-$2}"
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
# Writes $HOME_SETTINGS from one of the examples, with the model and the name of the key's variable asked on
|
|
514
|
+
# the terminal; never the key. 1 when the user stops or keeps the existing file.
|
|
515
|
+
run_setup() {
|
|
516
|
+
local answer example model var default_model default_var tmp
|
|
517
|
+
[ -t 0 ] || die "setup asks its questions in a terminal: run 'orkeon-code setup' in one."
|
|
518
|
+
if [ -f "$HOME_SETTINGS" ]; then
|
|
519
|
+
answer="$(ask "orkeon-code: $HOME_SETTINGS exists. Replace it? [y/N] " n)" || answer=n
|
|
520
|
+
case "$(lowered "$answer")" in y|yes) ;; *) echo "orkeon-code: $HOME_SETTINGS kept." >&2; return 1 ;; esac
|
|
521
|
+
fi
|
|
522
|
+
{
|
|
523
|
+
echo "orkeon-code setup: the settings go to $HOME_SETTINGS. The API key never does: only the name of the"
|
|
524
|
+
echo "environment variable that holds it."
|
|
525
|
+
echo " [1] a hosted, OpenAI-compatible endpoint (config/appsettings.example.json: DeepSeek)"
|
|
526
|
+
echo " [2] Ollama on this machine, no key (config/appsettings.ollama.example.json)"
|
|
527
|
+
} >&2
|
|
528
|
+
while :; do
|
|
529
|
+
answer="$(ask "Provider [1]: " 1)" || return 1
|
|
530
|
+
case "$answer" in
|
|
531
|
+
1) example="$ROOT/config/appsettings.example.json"; break ;;
|
|
532
|
+
2) example="$ROOT/config/appsettings.ollama.example.json"; break ;;
|
|
533
|
+
*) echo "orkeon-code: answer 1 or 2." >&2 ;;
|
|
534
|
+
esac
|
|
535
|
+
done
|
|
536
|
+
[ -f "$example" ] || die "$example not found."
|
|
537
|
+
default_model="$(sed -n 's/^[[:space:]]*"Model"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$example" | head -n 1)"
|
|
538
|
+
default_var="$(sed -n 's/.*"ApiKeyEnvVar"[[:space:]]*:[[:space:]]*"\([A-Za-z_][A-Za-z0-9_]*\)".*/\1/p' "$example" | head -n 1)"
|
|
539
|
+
while :; do
|
|
540
|
+
model="$(ask "Model [$default_model]: " "$default_model")" || return 1
|
|
541
|
+
# Never said back, and refused when it looks like a key: a key pasted at the wrong question.
|
|
542
|
+
if [[ "$model" =~ ^[A-Za-z0-9._:/@+-]+$ ]] && ! [[ "$model" =~ ^sk- ]] && ! [[ "$model" =~ ^[A-Za-z0-9_-]{32,}$ ]]; then break; fi
|
|
543
|
+
echo "orkeon-code: that is not a model id (letters, digits and . _ : / @ + -, not a key)." >&2
|
|
544
|
+
done
|
|
545
|
+
var=""
|
|
546
|
+
if [ -n "$default_var" ]; then
|
|
547
|
+
while :; do
|
|
548
|
+
var="$(ask "Name of the environment variable that holds the API key [$default_var]: " "$default_var")" || return 1
|
|
549
|
+
if [[ "$var" =~ ^[A-Z_][A-Z0-9_]{0,63}$ ]]; then break; fi
|
|
550
|
+
# Never said back: what was typed may be the key itself.
|
|
551
|
+
echo "orkeon-code: that is not a variable name (capitals, digits and _). Type the name of the variable, never the key." >&2
|
|
552
|
+
done
|
|
553
|
+
fi
|
|
554
|
+
[ -d "$CODE_HOME" ] || { mkdir -p "$CODE_HOME" && chmod 700 "$CODE_HOME"; } || die "could not create $CODE_HOME."
|
|
555
|
+
tmp="$HOME_SETTINGS.tmp.$$"
|
|
556
|
+
(
|
|
557
|
+
umask 077
|
|
558
|
+
MODEL="$model" KEY_VAR="$var" awk '
|
|
559
|
+
!c && /^[ \t]*"_comment"[ \t]*:/ {
|
|
560
|
+
print " \"_comment\": \"Written by orkeon-code setup. The API key never goes in this file: ApiKeyEnvVar names the environment variable that holds it, and ORKEON_Llm__ApiKey, when set, wins over everything. Every key is explained in docs/configuration.md.\","
|
|
561
|
+
c = 1; next
|
|
562
|
+
}
|
|
563
|
+
!m && /^[ \t]*"Model"[ \t]*:/ { sub(/"Model"[ \t]*:[ \t]*"[^"]*"/, "\"Model\": \"" ENVIRON["MODEL"] "\""); m = 1 }
|
|
564
|
+
!k && ENVIRON["KEY_VAR"] != "" && /^[ \t]*"ApiKeyEnvVar"[ \t]*:/ {
|
|
565
|
+
sub(/"ApiKeyEnvVar"[ \t]*:[ \t]*"[^"]*"/, "\"ApiKeyEnvVar\": \"" ENVIRON["KEY_VAR"] "\""); k = 1
|
|
566
|
+
}
|
|
567
|
+
{ print }
|
|
568
|
+
' "$example" > "$tmp"
|
|
569
|
+
) && chmod 600 "$tmp" && mv -f "$tmp" "$HOME_SETTINGS" || { rm -f "$tmp"; die "could not write $HOME_SETTINGS."; }
|
|
570
|
+
echo "orkeon-code: wrote $HOME_SETTINGS (model $model, mode 600)." >&2
|
|
571
|
+
if [ -n "$var" ]; then echo "orkeon-code: export the key before you start: export $var=<your key>" >&2; fi
|
|
572
|
+
return 0
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if [ "${1:-}" = setup ]; then
|
|
576
|
+
run_setup || exit 1
|
|
577
|
+
exit 0
|
|
578
|
+
fi
|
|
579
|
+
|
|
580
|
+
MODE="${ORKEON_CODE_MODE:-}"
|
|
581
|
+
WORKSPACE=""
|
|
582
|
+
SETTINGS="${ORKEON_CODE_SETTINGS:-}"
|
|
583
|
+
DEMO=0
|
|
584
|
+
VERSION_ONLY=0
|
|
585
|
+
TRUST_FLAG=0
|
|
586
|
+
CONTINUE=0
|
|
587
|
+
RESUME=0
|
|
588
|
+
RESUME_CHOICE=""
|
|
589
|
+
EXTRA=()
|
|
590
|
+
while [ $# -gt 0 ]; do
|
|
591
|
+
case "$1" in
|
|
592
|
+
--mode) MODE="${2:?--mode needs docker|tool|source}"; shift 2 ;;
|
|
593
|
+
--mode=*) MODE="${1#*=}"; shift ;;
|
|
594
|
+
--workspace) WORKSPACE="${2:?--workspace needs a directory}"; shift 2 ;;
|
|
595
|
+
--workspace=*) WORKSPACE="${1#*=}"; shift ;;
|
|
596
|
+
--settings) SETTINGS="${2:?--settings needs a file}"; shift 2 ;;
|
|
597
|
+
--settings=*) SETTINGS="${1#*=}"; shift ;;
|
|
598
|
+
--demo) DEMO=1; shift ;;
|
|
599
|
+
--version) VERSION_ONLY=1; shift ;;
|
|
600
|
+
--trust) TRUST_FLAG=1; shift ;;
|
|
601
|
+
-c|--continue) CONTINUE=1; shift ;;
|
|
602
|
+
--resume=*) RESUME=1; RESUME_CHOICE="${1#*=}"; shift ;;
|
|
603
|
+
--resume)
|
|
604
|
+
RESUME=1; shift
|
|
605
|
+
case "${1:-}" in ''|-*) ;; *) RESUME_CHOICE="$1"; shift ;; esac ;;
|
|
606
|
+
-h|--help) awk 'NR > 1 && /^set -euo pipefail/ { exit } NR > 1' "$SELF" | sed 's/^# \{0,1\}//'; exit 0 ;;
|
|
607
|
+
--) shift; EXTRA=("$@"); break ;;
|
|
608
|
+
*) EXTRA+=("$1"); shift ;;
|
|
609
|
+
esac
|
|
610
|
+
done
|
|
611
|
+
|
|
612
|
+
if [ "$CONTINUE" = 1 ] && [ "$RESUME" = 1 ]; then die "--continue and --resume do not go together: one brings the last session back, the other the one you pick."; fi
|
|
613
|
+
|
|
614
|
+
if [ "$VERSION_ONLY" = 1 ]; then
|
|
615
|
+
echo "orkeon-code $CODE_VERSION ($KIND: $ROOT)"
|
|
616
|
+
echo "Orkeon $ORKEON_PIN expected, found: $(runtime_found "$MODE")"
|
|
617
|
+
exit 0
|
|
618
|
+
fi
|
|
619
|
+
|
|
620
|
+
# ── Project ────────────────────────────────────────────────────────────────
|
|
621
|
+
if [ "$DEMO" = 1 ]; then
|
|
622
|
+
if [ "$KIND" = clone ]; then WORKSPACE="$ROOT/fixtures/sample-repo"; else WORKSPACE="$CODE_HOME/demo/sample-repo"; fi
|
|
623
|
+
bash "$ROOT/scripts/setup-fixture.sh" "$WORKSPACE" >/dev/null
|
|
624
|
+
fi
|
|
625
|
+
# Physical: the folder checked, stored and mounted is the same one, whatever link led to it.
|
|
626
|
+
WORKSPACE="$(canonical_dir "${WORKSPACE:-$PWD}")" || die "workspace not found: ${WORKSPACE:-$PWD}"
|
|
627
|
+
# Before anything of the project is read or mounted; the demo fixture is the launcher's own.
|
|
628
|
+
if [ "$DEMO" = 0 ]; then ensure_trusted "$WORKSPACE" "$TRUST_FLAG"; fi
|
|
629
|
+
|
|
630
|
+
# ── Settings ───────────────────────────────────────────────────────────────
|
|
631
|
+
# RUNTIME_OWN=1: Orkeon's own file, which the REPL reads itself when no --settings is passed.
|
|
632
|
+
RUNTIME_OWN=0
|
|
633
|
+
if [ -z "$SETTINGS" ]; then
|
|
634
|
+
cands=("$HOME_SETTINGS" "$LEGACY_SETTINGS")
|
|
635
|
+
if [ "$KIND" = clone ]; then cands=("$ROOT/config/appsettings.local.json" "${cands[@]}"); fi
|
|
636
|
+
for cand in "${cands[@]}"; do
|
|
637
|
+
if [ -f "$cand" ]; then SETTINGS="$cand"; break; fi
|
|
638
|
+
done
|
|
639
|
+
if [ -z "$SETTINGS" ] && [ -f "$RUNTIME_SETTINGS" ]; then SETTINGS="$RUNTIME_SETTINGS"; RUNTIME_OWN=1; fi
|
|
640
|
+
if [ "$SETTINGS" = "$LEGACY_SETTINGS" ]; then
|
|
641
|
+
warn "$LEGACY_SETTINGS is the old place of the settings: move it to $HOME_SETTINGS."
|
|
642
|
+
fi
|
|
643
|
+
if [ -z "$SETTINGS" ] && [ -t 0 ]; then
|
|
644
|
+
echo "orkeon-code: no settings file yet." >&2
|
|
645
|
+
if run_setup; then SETTINGS="$HOME_SETTINGS"; fi
|
|
646
|
+
fi
|
|
647
|
+
fi
|
|
648
|
+
if [ -z "$SETTINGS" ] || [ ! -f "$SETTINGS" ]; then
|
|
649
|
+
if [ "$KIND" = clone ]; then
|
|
650
|
+
die "no settings file. Run 'orkeon-code setup' in a terminal, copy config/appsettings.example.json to config/appsettings.local.json, or pass --settings FILE."
|
|
651
|
+
fi
|
|
652
|
+
die "no settings file. Run 'orkeon-code setup' in a terminal, copy $ROOT/config/appsettings.example.json to $HOME_SETTINGS, or pass --settings FILE."
|
|
653
|
+
fi
|
|
654
|
+
SETTINGS="$(cd "$(dirname "$SETTINGS")" && pwd)/$(basename "$SETTINGS")"
|
|
655
|
+
|
|
656
|
+
# The host falls back to a keyless default provider when the Llm section is
|
|
657
|
+
# missing, and every /assistant turn then returns nothing: say so up front.
|
|
658
|
+
KEY_VAR="$(sed -n 's/.*"ApiKeyEnvVar"[[:space:]]*:[[:space:]]*"\([A-Za-z_][A-Za-z0-9_]*\)".*/\1/p' "$SETTINGS" | head -n 1)"
|
|
659
|
+
if ! grep -q '"Llm"' "$SETTINGS"; then
|
|
660
|
+
warn "$SETTINGS has no \"Llm\" section: the host would use a keyless default and every turn would be empty."
|
|
661
|
+
elif [ -z "${ORKEON_Llm__ApiKey:-}" ] && [ -n "$KEY_VAR" ] && [ -z "${!KEY_VAR:-}" ]; then
|
|
662
|
+
warn "no API key: export $KEY_VAR (named by Llm:ApiKeyEnvVar) or ORKEON_Llm__ApiKey."
|
|
663
|
+
fi
|
|
664
|
+
if [ -n "${ORKEON_CODE_MODEL:-}" ]; then export ORKEON_Llm__Model="$ORKEON_CODE_MODEL"; fi
|
|
665
|
+
|
|
666
|
+
# The host's permission gate checks every tool call against the session's rules
|
|
667
|
+
# (/permissions), then the mode, and asks you when the mode says so; off, no call
|
|
668
|
+
# is checked. On by default here; a settings file can still turn it off.
|
|
669
|
+
export Orkeon__Security__PermissionGate__Enabled="${Orkeon__Security__PermissionGate__Enabled:-true}"
|
|
670
|
+
|
|
671
|
+
# ── Mode ───────────────────────────────────────────────────────────────────
|
|
672
|
+
if [ -z "$MODE" ]; then
|
|
673
|
+
if [ -n "${ORKEON_REPL:-}" ] || command -v orkeon-repl >/dev/null 2>&1 || runtime_downloaded; then MODE=tool
|
|
674
|
+
elif command -v docker >/dev/null 2>&1; then MODE=docker
|
|
675
|
+
elif [ -n "${ORKEON_SOURCE:-}" ]; then MODE=source
|
|
676
|
+
elif [ -n "$RUNTIME_ID" ]; then MODE=tool
|
|
677
|
+
else die "no Orkeon runtime found: install Docker, or the orkeon-repl tool, or set ORKEON_SOURCE (see docs/getting-started.md)."
|
|
678
|
+
fi
|
|
679
|
+
fi
|
|
680
|
+
# The tool mode with no orkeon-repl of the user's runs the downloaded runtime, fetched now when it is missing: before
|
|
681
|
+
# any state is made, so a refusal leaves nothing behind.
|
|
682
|
+
OWN_RUNTIME=0
|
|
683
|
+
if [ "$MODE" = tool ] && [ -z "${ORKEON_REPL:-}" ] && ! command -v orkeon-repl >/dev/null 2>&1 && [ -n "$RUNTIME_ID" ]; then
|
|
684
|
+
ensure_runtime
|
|
685
|
+
OWN_RUNTIME=1
|
|
686
|
+
fi
|
|
687
|
+
|
|
688
|
+
# ── State and sessions ─────────────────────────────────────────────────────
|
|
689
|
+
# An install keeps one folder per project, ~/.orkeon-code/projects/<slug>; a clone's .crew-output and an
|
|
690
|
+
# ORKEON_CODE_STATE may serve several projects, so their per-project part goes under projects/<slug>.
|
|
691
|
+
# Either way PROJECT_STATE lies inside STATE, which docker mode mounts on /work/state.
|
|
692
|
+
SLUG="$(project_slug "$WORKSPACE")"
|
|
693
|
+
if [ -n "${ORKEON_CODE_STATE:-}" ]; then STATE="$ORKEON_CODE_STATE"; PROJECT_REL="projects/$SLUG"
|
|
694
|
+
elif [ "$KIND" = clone ]; then STATE="$ROOT/.crew-output"; PROJECT_REL="projects/$SLUG"
|
|
695
|
+
else STATE="$CODE_HOME/projects/$SLUG"; PROJECT_REL=""; fi
|
|
696
|
+
mkdir -p "$STATE/output" "$STATE/tmp"
|
|
697
|
+
STATE="$(cd "$STATE" && pwd)"
|
|
698
|
+
PROJECT_STATE="$STATE${PROJECT_REL:+/$PROJECT_REL}"
|
|
699
|
+
# The runtime saves the session in <SessionsDirectory>/<its slug of the project>/last.json when the REPL ends
|
|
700
|
+
# (FileSessionBufferService), and reloads it at the next start. The folder is the launcher's /sessions mount,
|
|
701
|
+
# outside the project; the launcher keeps its own files beside it: history/ and project.json.
|
|
702
|
+
SESSIONS="$PROJECT_STATE/sessions"
|
|
703
|
+
HISTORY="$PROJECT_STATE/history"
|
|
704
|
+
# The typed memory (Orkeon #286) is kept beside them, in <RootDirectory>/<its slug>/memory.json on the /memory mount,
|
|
705
|
+
# outside the project so that neither git nor the file tools see it.
|
|
706
|
+
MEMORY="$PROJECT_STATE/memory"
|
|
707
|
+
mkdir -p "$SESSIONS" "$HISTORY" "$MEMORY"
|
|
708
|
+
if [ "$MODE" = docker ]; then RUNTIME_SLUG="$(project_slug /work/project)"; else RUNTIME_SLUG="$SLUG"; fi
|
|
709
|
+
now="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
710
|
+
first_seen="$(session_field "$PROJECT_STATE/project.json" firstSeen)"
|
|
711
|
+
{
|
|
712
|
+
printf '{\n "path": %s,\n "slug": "%s",\n "runtimeSlug": "%s",\n' "$(json_str "$WORKSPACE")" "$SLUG" "$RUNTIME_SLUG"
|
|
713
|
+
printf ' "firstSeen": "%s",\n "lastSeen": "%s"\n}\n' "${first_seen:-$now}" "$now"
|
|
714
|
+
} > "$PROJECT_STATE/project.json.tmp.$$" && mv -f "$PROJECT_STATE/project.json.tmp.$$" "$PROJECT_STATE/project.json" \
|
|
715
|
+
|| die "could not write $PROJECT_STATE/project.json."
|
|
716
|
+
|
|
717
|
+
# The starts open on this project, one pid a line (a launcher's pid is its REPL's: it execs it). Another one still
|
|
718
|
+
# running: its session is left where it is, and this one is kept beside it, in side/<pid>/, archived at the next
|
|
719
|
+
# start that finds none open.
|
|
720
|
+
LOCK="$PROJECT_STATE/.lock"
|
|
721
|
+
OTHER=""
|
|
722
|
+
live_pids=""
|
|
723
|
+
if [ -f "$LOCK" ]; then
|
|
724
|
+
while IFS= read -r other_pid; do
|
|
725
|
+
case "$other_pid" in ''|*[!0-9]*) continue ;; esac
|
|
726
|
+
if [ "$other_pid" != $$ ] && kill -0 "$other_pid" 2>/dev/null; then
|
|
727
|
+
OTHER="${OTHER:-$other_pid}"; live_pids="$live_pids$other_pid"$'\n'
|
|
728
|
+
fi
|
|
729
|
+
done < "$LOCK"
|
|
730
|
+
fi
|
|
731
|
+
printf '%s%s\n' "$live_pids" $$ > "$LOCK"
|
|
732
|
+
SESSIONS_SUB=sessions
|
|
733
|
+
|
|
734
|
+
# Fresh unless --continue (the runtime reloads the last itself) or --resume (the chosen one is put back).
|
|
735
|
+
SESSION_NOTE="fresh; --continue brings the last back, --resume lists them"
|
|
736
|
+
if [ -n "$OTHER" ]; then
|
|
737
|
+
warn "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."
|
|
738
|
+
SESSION_NOTE="beside the open one"
|
|
739
|
+
SESSIONS_SUB="side/$$"
|
|
740
|
+
mkdir -p "$PROJECT_STATE/$SESSIONS_SUB"
|
|
741
|
+
elif [ "$CONTINUE" = 1 ]; then SESSION_NOTE="continued"; archive_sessions 1
|
|
742
|
+
else archive_sessions
|
|
743
|
+
fi
|
|
744
|
+
keep="${ORKEON_CODE_SESSIONS_KEEP:-50}"
|
|
745
|
+
case "$keep" in
|
|
746
|
+
[0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9]) keep=$((10#$keep)) ;;
|
|
747
|
+
*) keep=0 ;;
|
|
748
|
+
esac
|
|
749
|
+
if [ "$keep" -lt 1 ]; then
|
|
750
|
+
warn "ORKEON_CODE_SESSIONS_KEEP=${ORKEON_CODE_SESSIONS_KEEP-} is not a whole number from 1 to 9999: 50 sessions are kept."; keep=50
|
|
751
|
+
fi
|
|
752
|
+
history_files | tail -n "+$((keep + 1))" | while IFS= read -r old; do rm -f "$old"; done
|
|
753
|
+
|
|
754
|
+
if [ "$RESUME" = 1 ]; then
|
|
755
|
+
files=()
|
|
756
|
+
while IFS= read -r f; do files+=("$f"); done < <(history_files)
|
|
757
|
+
[ ${#files[@]} -gt 0 ] || die "no saved session for $WORKSPACE yet (they are kept in $HISTORY)."
|
|
758
|
+
list_sessions() {
|
|
759
|
+
local i=1 f title
|
|
760
|
+
for f in "${files[@]}"; do
|
|
761
|
+
title="$(session_field "$f" Title)"
|
|
762
|
+
printf '%3d %s %s (%s messages) %s\n' "$i" "$(basename "$f" .json | cut -c1-16)" "${title:-(untitled)}" \
|
|
763
|
+
"$(session_messages "$f")" "$(basename "$f" .json | cut -c18-)" >&2
|
|
764
|
+
i=$((i + 1))
|
|
765
|
+
done
|
|
766
|
+
}
|
|
767
|
+
if [ -z "$RESUME_CHOICE" ]; then
|
|
768
|
+
echo "orkeon-code: sessions of $WORKSPACE, newest first:" >&2
|
|
769
|
+
list_sessions
|
|
770
|
+
if [ ! -t 0 ]; then echo "orkeon-code: no terminal to choose in: pass --resume <number or id>." >&2; exit 2; fi
|
|
771
|
+
printf 'Session to resume [1]: ' >&2
|
|
772
|
+
read -r RESUME_CHOICE || RESUME_CHOICE=""
|
|
773
|
+
RESUME_CHOICE="${RESUME_CHOICE:-1}"
|
|
774
|
+
fi
|
|
775
|
+
chosen=""
|
|
776
|
+
# A number of the list first (up to four digits), else the start of an id.
|
|
777
|
+
case "$RESUME_CHOICE" in
|
|
778
|
+
[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9])
|
|
779
|
+
if [ "$RESUME_CHOICE" -le ${#files[@]} ]; then chosen="${files[$((RESUME_CHOICE - 1))]}"; fi ;;
|
|
780
|
+
esac
|
|
781
|
+
if [ -z "$chosen" ] && [ -n "$RESUME_CHOICE" ]; then
|
|
782
|
+
for f in "${files[@]}"; do
|
|
783
|
+
case "$(basename "$f" .json | cut -c18-)" in "$RESUME_CHOICE"*) [ -z "$chosen" ] || die "more than one session starts with '$RESUME_CHOICE': give more of its id."; chosen="$f" ;; esac
|
|
784
|
+
done
|
|
785
|
+
fi
|
|
786
|
+
[ -n "$chosen" ] || die "no saved session '$RESUME_CHOICE' (orkeon-code --resume lists them)."
|
|
787
|
+
[ -z "$OTHER" ] || die "another session is open on this project (pid $OTHER): end it before you resume one."
|
|
788
|
+
# The chosen session lives in one place: back in sessions/, the history losing it (the last one was archived above).
|
|
789
|
+
mkdir -p "$SESSIONS/$RUNTIME_SLUG"
|
|
790
|
+
mv -f "$chosen" "$SESSIONS/$RUNTIME_SLUG/last.json" || die "could not put $chosen back."
|
|
791
|
+
SESSION_NOTE="resumed $(basename "$chosen" .json | cut -c18-)"
|
|
792
|
+
fi
|
|
793
|
+
|
|
794
|
+
# The session's start script (scripts/session-start.ork.ts): what a new session should know of
|
|
795
|
+
# the dev work left in progress. Copied fresh at every start into the agent's /tmp; the runtime
|
|
796
|
+
# runs it once, at the REPL's start, through its script host (a `.ork.ts`, never `sh`), and puts
|
|
797
|
+
# what it prints before the first free-text turn.
|
|
798
|
+
mkdir -p "$STATE/tmp/orkeon-code"
|
|
799
|
+
cp "$ROOT/scripts/session-start.ork.ts" "$STATE/tmp/orkeon-code/session-start.ork.ts"
|
|
800
|
+
export Orkeon__Cli__Session__StartScript="${Orkeon__Cli__Session__StartScript-/tmp/orkeon-code/session-start.ork.ts}"
|
|
801
|
+
# The session persists (the runtime's default in the REPL, said here; a settings file may still turn it off), in
|
|
802
|
+
# /sessions: the prefixed form wins over the settings file, since the archiving above reads that folder alone.
|
|
803
|
+
export Orkeon__Cli__Session__Persist="${Orkeon__Cli__Session__Persist:-true}"
|
|
804
|
+
export ORKEON_Orkeon__Cli__Session__SessionsDirectory=/sessions
|
|
805
|
+
export ORKEON_Orkeon__Cli__Memory__RootDirectory=/memory
|
|
806
|
+
# The embedding model's fingerprint goes beside the RAG's manifests, in /output, not in the project: the runtime's
|
|
807
|
+
# default, /workspace/.orkeon/, leaves a file in the project that /commit sweeps in. A settings file may name another.
|
|
808
|
+
export Orkeon__Embeddings__FingerprintPath="${Orkeon__Embeddings__FingerprintPath:-/output/rag/embedding-fingerprint.json}"
|
|
809
|
+
|
|
810
|
+
# ── Speech-to-text (optional) ──────────────────────────────────────────────
|
|
811
|
+
# ORKEON_CODE_AUDIO_DIR names the folder of audio and video files. The Whisper
|
|
812
|
+
# MCP server (mcp/whisper) runs on the host, started by the REPL over stdio: it
|
|
813
|
+
# reads that folder and writes into <state>/transcripts, which the agents see as
|
|
814
|
+
# /audio and /transcripts. The server is declared through the environment
|
|
815
|
+
# (ORKEON_MCP__Servers__whisper__*), so no settings file names this checkout; a
|
|
816
|
+
# settings file, or the environment, that declares a "whisper" server keeps it, and
|
|
817
|
+
# this block stays out.
|
|
818
|
+
AUDIO=""
|
|
819
|
+
AUDIO_ARGS=()
|
|
820
|
+
if [ -n "${ORKEON_CODE_AUDIO_DIR:-}" ]; then
|
|
821
|
+
if [ "$MODE" = docker ]; then
|
|
822
|
+
warn "ORKEON_CODE_AUDIO_DIR is ignored in docker mode: the Whisper server runs in tool and source modes (mcp/whisper/README.md)."
|
|
823
|
+
elif grep -qi '"whisper"[[:space:]]*:' "$SETTINGS"; then
|
|
824
|
+
warn "$SETTINGS declares a \"whisper\" MCP server: ORKEON_CODE_AUDIO_DIR is ignored, the settings file wins."
|
|
825
|
+
# compgen, not `env | grep -q`: grep leaves at the first match, env then dies on the closed pipe, and under pipefail
|
|
826
|
+
# the test is false although the variable is there.
|
|
827
|
+
elif compgen -e ORKEON_MCP__Servers__whisper__ >/dev/null; then
|
|
828
|
+
warn "the environment declares a \"whisper\" MCP server (ORKEON_MCP__Servers__whisper__*): ORKEON_CODE_AUDIO_DIR is ignored, that declaration wins."
|
|
829
|
+
elif ! UV="$(command -v uv)"; then
|
|
830
|
+
warn "ORKEON_CODE_AUDIO_DIR is set but uv is not on PATH: speech-to-text is off (mcp/whisper/README.md, 'Install')."
|
|
831
|
+
else
|
|
832
|
+
[ -d "$ORKEON_CODE_AUDIO_DIR" ] || die "ORKEON_CODE_AUDIO_DIR=$ORKEON_CODE_AUDIO_DIR is not a folder."
|
|
833
|
+
AUDIO="$(cd "$ORKEON_CODE_AUDIO_DIR" && pwd)"
|
|
834
|
+
mkdir -p "$STATE/transcripts"
|
|
835
|
+
export WHISPER_AUDIO_DIR="$AUDIO" WHISPER_OUT_DIR="$STATE/transcripts"
|
|
836
|
+
export ORKEON_MCP__Servers__whisper__Transport=Stdio
|
|
837
|
+
export ORKEON_MCP__Servers__whisper__Command="$UV"
|
|
838
|
+
# The gate reads a server's annotations (readOnlyHint on transcribe_audio, list_audio and whisper_info)
|
|
839
|
+
# only when the server is trusted (Orkeon #223); untrusted, every tool of the server would be a write.
|
|
840
|
+
export ORKEON_MCP__Servers__whisper__TrustAnnotations=true
|
|
841
|
+
# The runtime ends a server call after MCP:Servers:<id>:CallTimeout, 60 s by default (Orkeon #299):
|
|
842
|
+
# a dictation records up to /voice --max (600 s) then transcribes, and a long file on a CPU takes minutes.
|
|
843
|
+
export ORKEON_MCP__Servers__whisper__CallTimeout=00:15:00
|
|
844
|
+
# ORKEON_CODE_VOICE=1 opens the microphone to /voice and the speaker to /say and
|
|
845
|
+
# voice.reply: the server gets the `voice` extra (sounddevice), WHISPER_MICROPHONE=1
|
|
846
|
+
# and WHISPER_SPEAKER=1; without it, it refuses to record and only writes what it
|
|
847
|
+
# would say. Piper, the default speech backend, is the `tts` extra; a backend on
|
|
848
|
+
# OpenAI's API or a compatible server (WHISPER_BACKEND or TTS_BACKEND openai or http)
|
|
849
|
+
# needs the `openai` extra; WHISPER_DEVICE=cuda the cuBLAS and cuDNN wheels of the
|
|
850
|
+
# `cuda` extra, which the server preloads. The values are read as the server reads
|
|
851
|
+
# them: case and spaces aside.
|
|
852
|
+
tts_backend="$(lowered "${TTS_BACKEND:-}")"
|
|
853
|
+
stt_backend="$(lowered "${WHISPER_BACKEND:-}")"
|
|
854
|
+
whisper_args=(run --project "$ROOT/mcp/whisper")
|
|
855
|
+
# An install's folder is never written to: uv keeps the server's environment under ORKEON_CODE_HOME and
|
|
856
|
+
# reads uv.lock as shipped.
|
|
857
|
+
if [ "$KIND" = install ]; then
|
|
858
|
+
whisper_args+=(--frozen)
|
|
859
|
+
export UV_PROJECT_ENVIRONMENT="${UV_PROJECT_ENVIRONMENT:-$CODE_HOME/whisper/.venv}"
|
|
860
|
+
fi
|
|
861
|
+
if [ "${ORKEON_CODE_VOICE:-}" = 1 ]; then
|
|
862
|
+
whisper_args+=(--extra voice)
|
|
863
|
+
export WHISPER_MICROPHONE=1 WHISPER_SPEAKER=1
|
|
864
|
+
fi
|
|
865
|
+
if [ "${tts_backend:-piper}" = piper ]; then whisper_args+=(--extra tts); fi
|
|
866
|
+
case " $tts_backend $stt_backend " in *" openai "*|*" http "*) whisper_args+=(--extra openai) ;; esac
|
|
867
|
+
if [ "$(lowered "${WHISPER_DEVICE:-}")" = cuda ]; then whisper_args+=(--extra cuda); fi
|
|
868
|
+
whisper_args+=("$ROOT/mcp/whisper/whisper_mcp.py")
|
|
869
|
+
for i in "${!whisper_args[@]}"; do export "ORKEON_MCP__Servers__whisper__Args__$i=${whisper_args[$i]}"; done
|
|
870
|
+
AUDIO_ARGS=(--mount "$AUDIO:/audio:ro" --mount "$STATE/transcripts:/transcripts:ro")
|
|
871
|
+
fi
|
|
872
|
+
fi
|
|
873
|
+
|
|
874
|
+
if [ "$MODE" = source ]; then echo "orkeon-code $CODE_VERSION on Orkeon $ORKEON_PIN (source)"; else echo "orkeon-code $CODE_VERSION on Orkeon ($MODE: a release, the pin is $ORKEON_PIN)"; fi
|
|
875
|
+
echo " project : $WORKSPACE -> /workspace"
|
|
876
|
+
if [ "$RUNTIME_OWN" = 1 ]; then echo " settings : $SETTINGS (Orkeon's own, read by the REPL)"; else echo " settings : $SETTINGS"; fi
|
|
877
|
+
echo " sessions : $PROJECT_STATE/$SESSIONS_SUB ($SESSION_NOTE)"
|
|
878
|
+
if [ -n "$AUDIO" ]; then
|
|
879
|
+
model="${WHISPER_MODEL:-$([ "$stt_backend" = openai ] && echo whisper-1 || echo small)}"
|
|
880
|
+
echo " audio : $AUDIO -> /audio (transcripts: $STATE/transcripts, model $model$([ "$(lowered "${WHISPER_DEVICE:-}")" = cuda ] && echo ' on the GPU')$([ "${ORKEON_CODE_VOICE:-}" = 1 ] && echo ', microphone and speaker on'))"
|
|
881
|
+
fi
|
|
882
|
+
|
|
883
|
+
# The user's orkeonCode block, handed to the scripts as a read-only file: they read no settings and no
|
|
884
|
+
# environment (V-04). Written afresh at each start; no block, or no node to read it (said), leaves the
|
|
885
|
+
# folder empty, and no user setting applies. The key is matched case for case, as in the .ps1.
|
|
886
|
+
USER_CONFIG_DIR="$STATE/user-config"
|
|
887
|
+
mkdir -p "$USER_CONFIG_DIR"
|
|
888
|
+
rm -f "$USER_CONFIG_DIR/config.json"
|
|
889
|
+
if command -v node >/dev/null 2>&1; then
|
|
890
|
+
node -e 'const fs=require("fs");const s=JSON.parse(fs.readFileSync(process.argv[1],"utf8"));if(s&&typeof s.orkeonCode==="object"&&s.orkeonCode&&!Array.isArray(s.orkeonCode))fs.writeFileSync(process.argv[2],JSON.stringify(s.orkeonCode,null,2)+"\n")' "$SETTINGS" "$USER_CONFIG_DIR/config.json" \
|
|
891
|
+
|| warn "the orkeonCode block of $SETTINGS could not be read: no user setting applies."
|
|
892
|
+
elif grep -q '"orkeonCode"' "$SETTINGS"; then
|
|
893
|
+
warn "node is not on PATH: the orkeonCode block of $SETTINGS is not read, no user setting applies."
|
|
894
|
+
fi
|
|
895
|
+
|
|
896
|
+
# Sets ARGS. A function filling an array rather than mapfile: macOS ships bash 3.2.
|
|
897
|
+
# An empty <settings> passes none: the REPL then reads Orkeon's own file.
|
|
898
|
+
# <project state> is PROJECT_STATE as the REPL sees it: its sessions/ (side/<pid>/ beside an open start) on /sessions, its history/ on /session-history
|
|
899
|
+
# (read-only, for /resume), its memory/ on /memory.
|
|
900
|
+
repl_args() { # <commands> <crews> <settings> <workspace> <output> <tmp> <user-config> <project state>
|
|
901
|
+
ARGS=(--runner=scripted-commands --commands-dir "$1" --crews-dir "$2")
|
|
902
|
+
if [ -n "$3" ]; then ARGS+=(--settings "$3"); fi
|
|
903
|
+
ARGS+=(--mount "$4:/workspace:rw" --mount "$5:/output:rw" --mount "$6:/tmp:rw" --mount "$7:/user-config:ro"
|
|
904
|
+
--mount "$8/$SESSIONS_SUB:/sessions:rw" --mount "$8/history:/session-history:ro" --mount "$8/memory:/memory:rw")
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
# The physical folders of the tool and source modes' mounts, in repl_args order from <workspace>.
|
|
908
|
+
HOST_MOUNTS=("$WORKSPACE" "$STATE/output" "$STATE/tmp" "$USER_CONFIG_DIR" "$PROJECT_STATE")
|
|
909
|
+
|
|
910
|
+
# launch.json, beside config.json on /user-config: the host the REPL runs on (posix, wsl or windows) and the physical
|
|
911
|
+
# base of each mount, the very string given to --mount, with its Windows spelling under WSL (wslpath -w; null without
|
|
912
|
+
# wslpath). Docker mode hides the host on purpose: posix, no mount. Rewritten at every start. What it reads beyond the
|
|
913
|
+
# rest of the launcher: WSL_DISTRO_NAME, and ORKEON_CODE_PROC_VERSION (the tests' /proc/version), nothing else (V-04).
|
|
914
|
+
host_flavour() {
|
|
915
|
+
if [ "$MODE" = docker ]; then echo posix
|
|
916
|
+
elif [ -n "${WSL_DISTRO_NAME:-}" ] || grep -qi microsoft "${ORKEON_CODE_PROC_VERSION:-/proc/version}" 2>/dev/null; then echo wsl
|
|
917
|
+
else echo posix; fi
|
|
918
|
+
}
|
|
919
|
+
# The distribution: WSL_DISTRO_NAME, else the share of `wslpath -w /` (\\wsl.localhost\<distro>\ or \\wsl$\<distro>\).
|
|
920
|
+
wsl_distro() {
|
|
921
|
+
local root rest
|
|
922
|
+
if [ -n "${WSL_DISTRO_NAME:-}" ]; then printf '%s' "$WSL_DISTRO_NAME"; return; fi
|
|
923
|
+
root="$(wslpath -w / 2>/dev/null)" || return 0
|
|
924
|
+
case "$root" in '\\wsl.localhost\'*) rest="${root:16}" ;; '\\wsl$\'*) rest="${root:7}" ;; *) return 0 ;; esac
|
|
925
|
+
printf '%s' "${rest%%\\*}"
|
|
926
|
+
}
|
|
927
|
+
# Where the Windows drives are mounted: `wslpath -u 'C:\'` less its /c, else [automount] root= of /etc/wsl.conf, else /mnt.
|
|
928
|
+
wsl_automount_root() {
|
|
929
|
+
local c root
|
|
930
|
+
if c="$(wslpath -u 'C:\' 2>/dev/null)" && [ -n "$c" ]; then
|
|
931
|
+
c="${c%/}"; c="${c%/c}"; printf '%s' "${c:-/}"; return
|
|
932
|
+
fi
|
|
933
|
+
root="$(awk -F= '/^[[:space:]]*\[/ { s = tolower($0) ~ /^[[:space:]]*\[automount\]/ }
|
|
934
|
+
s && $1 ~ /^[[:space:]]*root[[:space:]]*$/ { v = $2; sub(/^[[:space:]]*"?/, "", v); sub(/"?[[:space:]]*$/, "", v); print v; exit }' \
|
|
935
|
+
/etc/wsl.conf 2>/dev/null)"
|
|
936
|
+
if [ -n "$root" ]; then root="${root%/}"; printf '%s' "${root:-/}"; else printf '/mnt'; fi
|
|
937
|
+
}
|
|
938
|
+
write_launch_file() {
|
|
939
|
+
local flavour file="$USER_CONFIG_DIR/launch.json" mounts=() m prev="" rest base root w sep="" has_wslpath=0 distro
|
|
940
|
+
flavour="$(host_flavour)"
|
|
941
|
+
if [ "$MODE" != docker ]; then
|
|
942
|
+
repl_args "" "" "" "${HOST_MOUNTS[@]}"
|
|
943
|
+
for m in "${ARGS[@]}" ${AUDIO_ARGS[@]+"${AUDIO_ARGS[@]}"}; do
|
|
944
|
+
if [ "$prev" = --mount ]; then mounts+=("$m"); fi
|
|
945
|
+
prev="$m"
|
|
946
|
+
done
|
|
947
|
+
fi
|
|
948
|
+
if [ "$flavour" = wsl ]; then
|
|
949
|
+
if command -v wslpath >/dev/null 2>&1; then has_wslpath=1
|
|
950
|
+
else warn "wslpath is not on PATH: $file gives no Windows spelling of the mounts."; fi
|
|
951
|
+
fi
|
|
952
|
+
{
|
|
953
|
+
printf '{\n "version": 1,\n "flavour": %s,\n "mode": %s,\n' "$(json_str "$flavour")" "$(json_str "$MODE")"
|
|
954
|
+
if [ "$flavour" = wsl ]; then
|
|
955
|
+
distro="$(wsl_distro)"
|
|
956
|
+
printf ' "wsl": { "distro": %s, "automountRoot": %s },\n' \
|
|
957
|
+
"$(if [ -n "$distro" ]; then json_str "$distro"; else echo null; fi)" "$(json_str "$(wsl_automount_root)")"
|
|
958
|
+
fi
|
|
959
|
+
printf ' "mounts": {'
|
|
960
|
+
for m in ${mounts[@]+"${mounts[@]}"}; do
|
|
961
|
+
rest="${m%:*}"; root="${rest##*:}"; base="${rest%:*}"
|
|
962
|
+
printf '%s\n %s: { "posix": %s' "$sep" "$(json_str "$root")" "$(json_str "$base")"
|
|
963
|
+
if [ "$flavour" = wsl ]; then
|
|
964
|
+
if [ "$has_wslpath" = 1 ] && w="$(wslpath -w "$base" 2>/dev/null)" && [ -n "$w" ]; then
|
|
965
|
+
printf ', "windows": %s' "$(json_str "$w")"
|
|
966
|
+
else printf ', "windows": null'; fi
|
|
967
|
+
fi
|
|
968
|
+
printf ' }'; sep=,
|
|
969
|
+
done
|
|
970
|
+
if [ -n "$sep" ]; then printf '\n }\n}\n'; else printf '}\n}\n'; fi
|
|
971
|
+
} > "$file.tmp.$$" && mv -f "$file.tmp.$$" "$file" || warn "could not write $file."
|
|
972
|
+
}
|
|
973
|
+
write_launch_file
|
|
974
|
+
|
|
975
|
+
# The exchange log (--llm-log) would land in ./llm-logs, the project: a bare --llm-log among the REPL's
|
|
976
|
+
# arguments is sent to <project state>/llm-logs instead; an explicit --llm-log-path is passed as given (a bare
|
|
977
|
+
# --llm-log beside it is then dropped, since the runtime keeps the last path it reads).
|
|
978
|
+
llm_log_args() { # <project state as the REPL sees it>
|
|
979
|
+
local a out=() named=0
|
|
980
|
+
for a in ${EXTRA[@]+"${EXTRA[@]}"}; do case "$a" in --llm-log-path|--llm-log-path=*) named=1 ;; esac; done
|
|
981
|
+
for a in ${EXTRA[@]+"${EXTRA[@]}"}; do
|
|
982
|
+
if [ "$a" = --llm-log ]; then
|
|
983
|
+
[ "$named" = 1 ] || out+=(--llm-log-path "$1/llm-logs")
|
|
984
|
+
else out+=("$a"); fi
|
|
985
|
+
done
|
|
986
|
+
EXTRA=(${out[@]+"${out[@]}"})
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
case "$MODE" in
|
|
990
|
+
docker)
|
|
991
|
+
command -v docker >/dev/null 2>&1 || die "docker not found."
|
|
992
|
+
# `docker run` alone would answer with the pipe or the socket it could not open, and nothing about what to do.
|
|
993
|
+
docker version --format '{{.Server.Version}}' >/dev/null 2>&1 \
|
|
994
|
+
|| die "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)."
|
|
995
|
+
# Everything the REPL reads sits under its working directory /work. The
|
|
996
|
+
# image is multi-arch (linux/amd64, linux/arm64): docker pulls the host's.
|
|
997
|
+
env_args=(-e ORKEON_ENTRYPOINT=repl -e HOME=/tmp -e DOTNET_CLI_HOME=/tmp
|
|
998
|
+
-e "Orkeon__Security__PermissionGate__Enabled=$Orkeon__Security__PermissionGate__Enabled"
|
|
999
|
+
-e "Orkeon__Cli__Session__StartScript=$Orkeon__Cli__Session__StartScript"
|
|
1000
|
+
-e "Orkeon__Cli__Session__Persist=$Orkeon__Cli__Session__Persist"
|
|
1001
|
+
-e ORKEON_Orkeon__Cli__Session__SessionsDirectory=/sessions
|
|
1002
|
+
-e ORKEON_Orkeon__Cli__Memory__RootDirectory=/memory
|
|
1003
|
+
-e "Orkeon__Embeddings__FingerprintPath=$Orkeon__Embeddings__FingerprintPath")
|
|
1004
|
+
# The github tool's token (Orkeon #222): GITHUB_TOKEN, GH_TOKEN, or the variable Orkeon__Tools__GitHub__TokenVariable
|
|
1005
|
+
# names, each handed over only when set, with the setting itself so the runtime reads the same variable.
|
|
1006
|
+
for v in ORKEON_Llm__ApiKey ORKEON_Llm__Model "$KEY_VAR" GITHUB_TOKEN GH_TOKEN \
|
|
1007
|
+
Orkeon__Tools__GitHub__TokenVariable "${Orkeon__Tools__GitHub__TokenVariable:-}"; do
|
|
1008
|
+
if [ -n "$v" ] && [ -n "${!v:-}" ]; then env_args+=(-e "$v"); fi
|
|
1009
|
+
done
|
|
1010
|
+
# Files the agent writes in the project belong to the caller, not to root.
|
|
1011
|
+
user_args=()
|
|
1012
|
+
if [ "$(uname -s)" = Linux ]; then user_args=(--user "$(id -u):$(id -g)"); fi
|
|
1013
|
+
tty_args=(-i)
|
|
1014
|
+
if [ -t 0 ] && [ -t 1 ]; then tty_args=(-it); fi
|
|
1015
|
+
in_state="/work/state${PROJECT_REL:+/$PROJECT_REL}"
|
|
1016
|
+
repl_args /work/agent/commands /work/agent/crews /work/settings.json \
|
|
1017
|
+
/work/project /work/state/output /work/state/tmp /work/state/user-config "$in_state"
|
|
1018
|
+
llm_log_args "$in_state"
|
|
1019
|
+
exec docker run --rm "${tty_args[@]}" ${user_args[@]+"${user_args[@]}"} "${env_args[@]}" -w /work \
|
|
1020
|
+
-v "$WORKSPACE:/work/project" \
|
|
1021
|
+
-v "$ROOT/src:/work/agent:ro" \
|
|
1022
|
+
-v "$SETTINGS:/work/settings.json:ro" \
|
|
1023
|
+
-v "$STATE:/work/state" \
|
|
1024
|
+
"$IMAGE" "${ARGS[@]}" ${EXTRA[@]+"${EXTRA[@]}"}
|
|
1025
|
+
;;
|
|
1026
|
+
tool|source)
|
|
1027
|
+
if [ "$MODE" = tool ]; then
|
|
1028
|
+
if [ -n "${ORKEON_REPL:-}" ]; then read -r -a REPL <<< "$ORKEON_REPL"
|
|
1029
|
+
elif [ "$OWN_RUNTIME" = 1 ]; then REPL=("$RUNTIME_REPL")
|
|
1030
|
+
else REPL=(orkeon-repl); fi
|
|
1031
|
+
command -v "${REPL[0]}" >/dev/null 2>&1 || die "${REPL[0]} not found (see docs/getting-started.md, 'Tool mode')."
|
|
1032
|
+
else
|
|
1033
|
+
[ -n "${ORKEON_SOURCE:-}" ] && [ -d "$ORKEON_SOURCE/src/apps/Orkeon.ConsoleApp" ] \
|
|
1034
|
+
|| die "ORKEON_SOURCE must name an Orkeon checkout (src/apps/Orkeon.ConsoleApp not found)."
|
|
1035
|
+
ORKEON_SOURCE="$(cd "$ORKEON_SOURCE" && pwd)"
|
|
1036
|
+
# The checkout should sit at the pin: one behind it is moved there (follow_pin), another commit runs, with a
|
|
1037
|
+
# warning, never a refusal.
|
|
1038
|
+
restore=--no-restore
|
|
1039
|
+
if head="$(git -C "$ORKEON_SOURCE" rev-parse HEAD 2>/dev/null)" && [ "$head" != "$ORKEON_REF" ]; then
|
|
1040
|
+
if follow_pin "$head"; then restore=""
|
|
1041
|
+
else warn "ORKEON_SOURCE is at ${head:0:7}, the pin of .orkeon-version is $ORKEON_PIN: the commands were checked against the pin."
|
|
1042
|
+
fi
|
|
1043
|
+
fi
|
|
1044
|
+
# The SDK runs in the Orkeon checkout, under its global.json, never in the
|
|
1045
|
+
# project, whose global.json may pin another SDK ("A compatible .NET SDK was
|
|
1046
|
+
# not found"). The REPL then starts as the built assembly: `dotnet <dll>`
|
|
1047
|
+
# is a host command, which reads no global.json. A checkout just moved is restored by its build.
|
|
1048
|
+
# The build is quiet and takes a minute after a move: say it runs, or it looks stuck.
|
|
1049
|
+
echo "orkeon-code: building Orkeon in $ORKEON_SOURCE..." >&2
|
|
1050
|
+
(cd "$ORKEON_SOURCE" && dotnet build src/apps/Orkeon.ConsoleApp -c Debug ${restore:+"$restore"} -nologo -v quiet) >&2 \
|
|
1051
|
+
|| die "building src/apps/Orkeon.ConsoleApp in $ORKEON_SOURCE failed (restore it once: dotnet restore Orkeon.sln)."
|
|
1052
|
+
dll="$ORKEON_SOURCE/src/apps/Orkeon.ConsoleApp/bin/Debug/net10.0/Orkeon.ConsoleApp.dll"
|
|
1053
|
+
[ -f "$dll" ] || die "$dll not found after the build."
|
|
1054
|
+
REPL=(dotnet "$dll")
|
|
1055
|
+
fi
|
|
1056
|
+
# The runtime bundles each command and crew with esbuild. The Debian package
|
|
1057
|
+
# and a release-archive install carry their own: /usr/bin/orkeon-repl is a
|
|
1058
|
+
# script that points the runtime at /usr/lib/orkeon/esbuild-bin, and an
|
|
1059
|
+
# archive's wrapper at its libexec/esbuild-bin. The dotnet tool and a source
|
|
1060
|
+
# build carry none: for them, use the one npm installed for this checkout (or, for
|
|
1061
|
+
# the npm package, beside it).
|
|
1062
|
+
bundled=""
|
|
1063
|
+
if [ "$MODE" = tool ] && repl_bin="$(command -v "${REPL[0]}")"; then
|
|
1064
|
+
repl_bin="$(resolve_links "$repl_bin")"
|
|
1065
|
+
if [ -x "$(dirname "$(dirname "$repl_bin")")/libexec/esbuild-bin/esbuild" ]; then bundled=1
|
|
1066
|
+
# A launcher script that sets ORKEON_ESBUILD_PATH itself (the Debian package's).
|
|
1067
|
+
elif [ "$(head -c 2 "$repl_bin" 2>/dev/null)" = '#!' ] && grep -q ORKEON_ESBUILD_PATH "$repl_bin" 2>/dev/null; then
|
|
1068
|
+
bundled=1
|
|
1069
|
+
fi
|
|
1070
|
+
fi
|
|
1071
|
+
if [ -z "$bundled" ] && [ -z "${ORKEON_ESBUILD_PATH:-}" ] && ! command -v esbuild >/dev/null 2>&1; then
|
|
1072
|
+
found="$(find "$ROOT/node_modules/@esbuild" -path '*/bin/esbuild' -type f 2>/dev/null | head -n 1 || true)"
|
|
1073
|
+
if [ -z "$found" ] && [ "$KIND" = clone ]; then die "esbuild not found: run 'npm ci' in $ROOT, or set ORKEON_ESBUILD_PATH."; fi
|
|
1074
|
+
[ -n "$found" ] \
|
|
1075
|
+
|| die "esbuild not found: install Orkeon from its package or archive (it carries esbuild), or set ORKEON_ESBUILD_PATH."
|
|
1076
|
+
export ORKEON_ESBUILD_PATH="$found"
|
|
1077
|
+
fi
|
|
1078
|
+
# The REPL runs from the project. It reads its --commands-dir and --crews-dir
|
|
1079
|
+
# wherever they are, and a --mount outside its working directory (here /output,
|
|
1080
|
+
# /tmp, /user-config, /sessions, /session-history and /memory, in the state directory,
|
|
1081
|
+
# and an --llm-log-path there) under ORKEON_ALLOW_EXTERNAL_MOUNTS (Orkeon GAP-49). The
|
|
1082
|
+
# seven roots are distinct, and none is one the REPL keeps (/sandbox, /credentials,
|
|
1083
|
+
# /llm-logs, /cli-commands..., /crews...).
|
|
1084
|
+
export ORKEON_ALLOW_EXTERNAL_MOUNTS=1
|
|
1085
|
+
repl_args "$ROOT/src/commands" "$ROOT/src/crews" "$([ "$RUNTIME_OWN" = 1 ] || echo "$SETTINGS")" \
|
|
1086
|
+
"${HOST_MOUNTS[@]}"
|
|
1087
|
+
llm_log_args "$PROJECT_STATE"
|
|
1088
|
+
cd "$WORKSPACE"
|
|
1089
|
+
exec "${REPL[@]}" "${ARGS[@]}" ${AUDIO_ARGS[@]+"${AUDIO_ARGS[@]}"} ${EXTRA[@]+"${EXTRA[@]}"}
|
|
1090
|
+
;;
|
|
1091
|
+
*) die "unknown mode '$MODE' (expected docker, tool or source)" ;;
|
|
1092
|
+
esac
|