orkeon-code 0.0.0-stage → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.orkeon-runtime +10 -0
- package/.orkeon-version +1 -0
- package/LICENSE.md +21 -0
- package/NOTICE.md +17 -0
- package/README.fr.md +163 -0
- package/README.md +156 -2
- package/config/appsettings.anthropic.example.json +77 -0
- package/config/appsettings.example.json +71 -0
- package/config/appsettings.jev.example.json +131 -0
- package/config/appsettings.kev.example.json +133 -0
- package/config/appsettings.liquid.example.json +132 -0
- package/config/appsettings.ollama-whisper.example.json +93 -0
- package/config/appsettings.ollama.example.json +70 -0
- package/config/appsettings.whisper.example.json +32 -0
- package/mcp/whisper/README.md +294 -0
- package/mcp/whisper/pyproject.toml +32 -0
- package/mcp/whisper/uv.lock +1641 -0
- package/mcp/whisper/whisper_mcp.py +1053 -0
- package/orkeon-code +1092 -0
- package/orkeon-code.mjs +71 -0
- package/orkeon-code.ps1 +939 -0
- package/package.json +58 -4
- package/scripts/install.ps1 +156 -0
- package/scripts/install.sh +148 -0
- package/scripts/session-start.ork.ts +90 -0
- package/scripts/session-start.sh +74 -0
- package/scripts/setup-fixture.sh +88 -0
- package/src/commands/.orkeon/orkeon-cli.d.ts +559 -0
- package/src/commands/_lib/args.ts +194 -0
- package/src/commands/_lib/dev/dev-batches.ts +366 -0
- package/src/commands/_lib/dev/dev-implement.ts +185 -0
- package/src/commands/_lib/dev/dev-source.ts +61 -0
- package/src/commands/_lib/dev/dev.ts +341 -0
- package/src/commands/_lib/dev/markers.ts +7 -0
- package/src/commands/_lib/dev/messages.ts +112 -0
- package/src/commands/_lib/dev-step.ts +145 -0
- package/src/commands/_lib/dispatch.ts +254 -0
- package/src/commands/_lib/effort.ts +15 -0
- package/src/commands/_lib/git/branch.ts +94 -0
- package/src/commands/_lib/git/commit.ts +90 -0
- package/src/commands/_lib/git/diff.ts +107 -0
- package/src/commands/_lib/git/messages.ts +54 -0
- package/src/commands/_lib/git/review.ts +108 -0
- package/src/commands/_lib/memory/memory-admit.ts +148 -0
- package/src/commands/_lib/memory/memory.ts +52 -0
- package/src/commands/_lib/memory/messages.ts +32 -0
- package/src/commands/_lib/messages.ts +48 -0
- package/src/commands/_lib/pr-context.ts +32 -0
- package/src/commands/_lib/project/analyze.ts +24 -0
- package/src/commands/_lib/project/messages.ts +8 -0
- package/src/commands/_lib/session/export.ts +105 -0
- package/src/commands/_lib/session/messages.ts +87 -0
- package/src/commands/_lib/session/prompts.ts +4 -0
- package/src/commands/_lib/session/resume.ts +151 -0
- package/src/commands/_lib/session/tasks.ts +181 -0
- package/src/commands/_lib/settings/advisor.ts +75 -0
- package/src/commands/_lib/settings/agents.ts +137 -0
- package/src/commands/_lib/settings/choices.ts +8 -0
- package/src/commands/_lib/settings/config.ts +141 -0
- package/src/commands/_lib/settings/effort.ts +147 -0
- package/src/commands/_lib/settings/hooks.ts +50 -0
- package/src/commands/_lib/settings/messages.ts +408 -0
- package/src/commands/_lib/settings/mode.ts +100 -0
- package/src/commands/_lib/settings/model.ts +181 -0
- package/src/commands/_lib/settings/output-style.ts +39 -0
- package/src/commands/_lib/settings/permissions.ts +287 -0
- package/src/commands/_lib/settings/route.ts +63 -0
- package/src/commands/_lib/settings/session-config.ts +49 -0
- package/src/commands/_lib/settings/skills.ts +93 -0
- package/src/commands/_lib/settings/theme.ts +42 -0
- package/src/commands/_lib/speech/messages.ts +58 -0
- package/src/commands/_lib/speech/prompts.ts +4 -0
- package/src/commands/_lib/speech/say.ts +95 -0
- package/src/commands/_lib/speech/transcribe.ts +121 -0
- package/src/commands/_lib/speech/voice.ts +142 -0
- package/src/commands/_lib/status/cache.ts +31 -0
- package/src/commands/_lib/status/context.ts +57 -0
- package/src/commands/_lib/status/doctor.ts +205 -0
- package/src/commands/_lib/status/messages.ts +100 -0
- package/src/commands/_lib/status/meta.ts +24 -0
- package/src/commands/_lib/status/status.ts +128 -0
- package/src/commands/_lib/status/usage-tools.ts +48 -0
- package/src/commands/_lib/status/usage.ts +128 -0
- package/src/commands/_lib/view.ts +34 -0
- package/src/commands/dev/dev-batches.cmd.ts +109 -0
- package/src/commands/dev/dev-learn.cmd.ts +29 -0
- package/src/commands/dev/dev-plan.cmd.ts +51 -0
- package/src/commands/dev/dev-spec.cmd.ts +54 -0
- package/src/commands/dev/dev-status.cmd.ts +16 -0
- package/src/commands/git/branch.cmd.ts +27 -0
- package/src/commands/git/commit.cmd.ts +48 -0
- package/src/commands/git/diff.cmd.ts +26 -0
- package/src/commands/git/review.cmd.ts +36 -0
- package/src/commands/memory/memory.cmd.ts +48 -0
- package/src/commands/project/analyze.cmd.ts +32 -0
- package/src/commands/project/debug-tool-call.cmd.ts +62 -0
- package/src/commands/project/files.cmd.ts +22 -0
- package/src/commands/project/init-verifiers.cmd.ts +14 -0
- package/src/commands/project/init.cmd.ts +14 -0
- package/src/commands/project/verify.cmd.ts +27 -0
- package/src/commands/session/assistant.cmd.ts +40 -0
- package/src/commands/session/btw.cmd.ts +18 -0
- package/src/commands/session/clear.cmd.ts +19 -0
- package/src/commands/session/compact.cmd.ts +16 -0
- package/src/commands/session/copy.cmd.ts +45 -0
- package/src/commands/session/exit.cmd.ts +9 -0
- package/src/commands/session/export.cmd.ts +28 -0
- package/src/commands/session/rename.cmd.ts +18 -0
- package/src/commands/session/resume.cmd.ts +19 -0
- package/src/commands/session/rewind.cmd.ts +25 -0
- package/src/commands/session/summary.cmd.ts +27 -0
- package/src/commands/session/tasks.cmd.ts +46 -0
- package/src/commands/settings/advisor.cmd.ts +38 -0
- package/src/commands/settings/agents.cmd.ts +19 -0
- package/src/commands/settings/config.cmd.ts +19 -0
- package/src/commands/settings/effort.cmd.ts +19 -0
- package/src/commands/settings/fast.cmd.ts +18 -0
- package/src/commands/settings/hooks.cmd.ts +17 -0
- package/src/commands/settings/mode.cmd.ts +20 -0
- package/src/commands/settings/model.cmd.ts +21 -0
- package/src/commands/settings/output-style.cmd.ts +19 -0
- package/src/commands/settings/permissions.cmd.ts +25 -0
- package/src/commands/settings/proactive.cmd.ts +16 -0
- package/src/commands/settings/route.cmd.ts +16 -0
- package/src/commands/settings/skills.cmd.ts +17 -0
- package/src/commands/settings/theme.cmd.ts +14 -0
- package/src/commands/speech/say.cmd.ts +24 -0
- package/src/commands/speech/transcribe.cmd.ts +29 -0
- package/src/commands/speech/voice.cmd.ts +30 -0
- package/src/commands/status/context.cmd.ts +18 -0
- package/src/commands/status/doctor.cmd.ts +27 -0
- package/src/commands/status/release-notes.cmd.ts +9 -0
- package/src/commands/status/status.cmd.ts +25 -0
- package/src/commands/status/usage.cmd.ts +21 -0
- package/src/crews/.orkeon/orkeon.d.ts +4391 -0
- package/src/crews/_probe-shared-memory/domain/messages.ts +54 -0
- package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +188 -0
- package/src/crews/_probe-shared-memory/domain/prompts.ts +5 -0
- package/src/crews/_probe-shared-memory/probe.ork.ts +100 -0
- package/src/crews/advisor/application/messages.ts +4 -0
- package/src/crews/advisor/application/prompts.ts +4 -0
- package/src/crews/advisor/application/run-advisor.ts +41 -0
- package/src/crews/advisor/crew.ork.ts +44 -0
- package/src/crews/advisor/domain/advice.ts +119 -0
- package/src/crews/advisor/domain/messages.ts +8 -0
- package/src/crews/advisor/domain/prompts.ts +26 -0
- package/src/crews/agent-run/application/messages.ts +18 -0
- package/src/crews/agent-run/application/run-agent-run.ts +43 -0
- package/src/crews/agent-run/crew.ork.ts +67 -0
- package/src/crews/analyze/application/messages.ts +27 -0
- package/src/crews/analyze/application/prompts.ts +4 -0
- package/src/crews/analyze/application/run-analyze.ts +120 -0
- package/src/crews/analyze/crew.ork.ts +41 -0
- package/src/crews/analyze/domain/harvest.ts +269 -0
- package/src/crews/analyze/domain/prompts.ts +86 -0
- package/src/crews/code-review/application/lens-material.ts +24 -0
- package/src/crews/code-review/application/messages.ts +17 -0
- package/src/crews/code-review/application/prompts.ts +126 -0
- package/src/crews/code-review/application/review.ts +74 -0
- package/src/crews/code-review/application/run-code-review.ts +121 -0
- package/src/crews/code-review/crew.ork.ts +52 -0
- package/src/crews/code-review/domain/lenses.ts +154 -0
- package/src/crews/code-review/domain/messages.ts +25 -0
- package/src/crews/code-review/domain/prompts.ts +58 -0
- package/src/crews/code-review/domain/report.ts +58 -0
- package/src/crews/code-review/domain/scope.ts +106 -0
- package/src/crews/dev-batches/application/messages.ts +127 -0
- package/src/crews/dev-batches/application/plan-close.ts +181 -0
- package/src/crews/dev-batches/application/prompts.ts +10 -0
- package/src/crews/dev-batches/application/run-dev-batches.ts +676 -0
- package/src/crews/dev-batches/application/run-wave.ts +452 -0
- package/src/crews/dev-batches/application/seed-harvest.ts +163 -0
- package/src/crews/dev-batches/crew.ork.ts +146 -0
- package/src/crews/dev-batches/domain/batch-waves.ts +70 -0
- package/src/crews/dev-batches/domain/batches-budget.ts +52 -0
- package/src/crews/dev-batches/domain/batches-log.ts +52 -0
- package/src/crews/dev-batches/domain/markers.ts +5 -0
- package/src/crews/dev-batches/domain/messages.ts +6 -0
- package/src/crews/dev-batches/domain/wave-order.ts +44 -0
- package/src/crews/dev-change/application/change-material.ts +44 -0
- package/src/crews/dev-change/application/evidence.ts +172 -0
- package/src/crews/dev-change/application/messages.ts +81 -0
- package/src/crews/dev-change/application/prompts.ts +101 -0
- package/src/crews/dev-change/application/run-dev-change.ts +324 -0
- package/src/crews/dev-change/crew.ork.ts +114 -0
- package/src/crews/dev-change/domain/change-answer.ts +163 -0
- package/src/crews/dev-change/domain/change-render.ts +77 -0
- package/src/crews/dev-change/domain/markers.ts +28 -0
- package/src/crews/dev-change/domain/messages.ts +16 -0
- package/src/crews/dev-implement/application/close.ts +186 -0
- package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
- package/src/crews/dev-implement/application/locate-sheet.ts +82 -0
- package/src/crews/dev-implement/application/messages.ts +161 -0
- package/src/crews/dev-implement/application/observe.ts +52 -0
- package/src/crews/dev-implement/application/prompts.ts +9 -0
- package/src/crews/dev-implement/application/report-writes.ts +46 -0
- package/src/crews/dev-implement/application/run-dev-implement.ts +822 -0
- package/src/crews/dev-implement/application/run-role.ts +27 -0
- package/src/crews/dev-implement/application/suite-job.ts +122 -0
- package/src/crews/dev-implement/application/touched.ts +74 -0
- package/src/crews/dev-implement/crew.ork.ts +69 -0
- package/src/crews/dev-implement/domain/contracts.ts +255 -0
- package/src/crews/dev-implement/domain/correction.ts +103 -0
- package/src/crews/dev-implement/domain/cycles.ts +36 -0
- package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
- package/src/crews/dev-implement/domain/markers.ts +23 -0
- package/src/crews/dev-implement/domain/messages.ts +58 -0
- package/src/crews/dev-implement/domain/prompts.ts +93 -0
- package/src/crews/dev-implement/domain/roles.ts +49 -0
- package/src/crews/dev-implement/domain/sheet-edits.ts +76 -0
- package/src/crews/dev-implement/domain/sheet-ticks.ts +23 -0
- package/src/crews/dev-implement/domain/step-checks.ts +137 -0
- package/src/crews/dev-implement/domain/step-section.ts +129 -0
- package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
- package/src/crews/dev-learn/application/learn-prompt-fit.ts +63 -0
- package/src/crews/dev-learn/application/messages.ts +51 -0
- package/src/crews/dev-learn/application/prompts.ts +99 -0
- package/src/crews/dev-learn/application/run-dev-learn.ts +558 -0
- package/src/crews/dev-learn/crew.ork.ts +53 -0
- package/src/crews/dev-learn/domain/learn-answer.ts +233 -0
- package/src/crews/dev-learn/domain/messages.ts +65 -0
- package/src/crews/dev-learn/domain/owner-lines.ts +89 -0
- package/src/crews/dev-learn/domain/proposals-render.ts +95 -0
- package/src/crews/dev-plan/application/anchor-paths.ts +113 -0
- package/src/crews/dev-plan/application/inventory.ts +174 -0
- package/src/crews/dev-plan/application/messages.ts +88 -0
- package/src/crews/dev-plan/application/plan-prompt-fit.ts +44 -0
- package/src/crews/dev-plan/application/prompts.ts +141 -0
- package/src/crews/dev-plan/application/run-dev-plan.ts +483 -0
- package/src/crews/dev-plan/crew.ork.ts +112 -0
- package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
- package/src/crews/dev-plan/domain/markers.ts +18 -0
- package/src/crews/dev-plan/domain/messages.ts +118 -0
- package/src/crews/dev-plan/domain/plan-answer.ts +753 -0
- package/src/crews/dev-plan/domain/plan-render.ts +306 -0
- package/src/crews/dev-plan/domain/prompts.ts +44 -0
- package/src/crews/dev-spec/application/messages.ts +30 -0
- package/src/crews/dev-spec/application/prompts.ts +93 -0
- package/src/crews/dev-spec/application/run-dev-spec.ts +237 -0
- package/src/crews/dev-spec/application/spec-material.ts +42 -0
- package/src/crews/dev-spec/crew.ork.ts +110 -0
- package/src/crews/dev-spec/domain/markers.ts +30 -0
- package/src/crews/dev-spec/domain/messages.ts +39 -0
- package/src/crews/dev-spec/domain/spec-answer.ts +252 -0
- package/src/crews/dev-spec/domain/spec-render.ts +76 -0
- package/src/crews/dev-verify/application/audit-brief.ts +187 -0
- package/src/crews/dev-verify/application/audit.ts +267 -0
- package/src/crews/dev-verify/application/capture.ts +311 -0
- package/src/crews/dev-verify/application/messages.ts +119 -0
- package/src/crews/dev-verify/application/prompts.ts +209 -0
- package/src/crews/dev-verify/application/run-dev-verify.ts +423 -0
- package/src/crews/dev-verify/application/run-gate.ts +204 -0
- package/src/crews/dev-verify/crew.ork.ts +103 -0
- package/src/crews/dev-verify/domain/audit-answer.ts +154 -0
- package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
- package/src/crews/dev-verify/domain/capture-sections.ts +138 -0
- package/src/crews/dev-verify/domain/commands.ts +103 -0
- package/src/crews/dev-verify/domain/gate.ts +131 -0
- package/src/crews/dev-verify/domain/markers.ts +16 -0
- package/src/crews/dev-verify/domain/mechanical-table.ts +156 -0
- package/src/crews/dev-verify/domain/messages.ts +92 -0
- package/src/crews/dev-verify/domain/runtime-cut.ts +13 -0
- package/src/crews/dev-verify/domain/sheet-facts.ts +4 -0
- package/src/crews/dev-verify/domain/text.ts +20 -0
- package/src/crews/dev-verify/domain/verdict.ts +127 -0
- package/src/crews/git-commit/application/draft.ts +133 -0
- package/src/crews/git-commit/application/messages.ts +15 -0
- package/src/crews/git-commit/application/prompts.ts +47 -0
- package/src/crews/git-commit/application/run-git-commit.ts +117 -0
- package/src/crews/git-commit/crew.ork.ts +53 -0
- package/src/crews/git-commit/domain/commit.ts +200 -0
- package/src/crews/git-commit/domain/markers.ts +4 -0
- package/src/crews/git-commit/domain/messages.ts +48 -0
- package/src/crews/init-verifiers/application/authoring.ts +90 -0
- package/src/crews/init-verifiers/application/messages.ts +13 -0
- package/src/crews/init-verifiers/application/prompts.ts +107 -0
- package/src/crews/init-verifiers/application/run-init-verifiers.ts +26 -0
- package/src/crews/init-verifiers/crew.ork.ts +35 -0
- package/src/crews/init-verifiers/domain/commands-section.ts +36 -0
- package/src/crews/init-verifiers/domain/readiness.ts +23 -0
- package/src/crews/main-loop/application/auto-compact.ts +78 -0
- package/src/crews/main-loop/application/context-gather.ts +133 -0
- package/src/crews/main-loop/application/messages.ts +81 -0
- package/src/crews/main-loop/application/prompts.ts +12 -0
- package/src/crews/main-loop/application/run-main-loop.ts +383 -0
- package/src/crews/main-loop/application/turn-context.ts +111 -0
- package/src/crews/main-loop/crew.ork.ts +124 -0
- package/src/crews/main-loop/domain/autocompact.ts +27 -0
- package/src/crews/main-loop/domain/prompt-assembly.ts +338 -0
- package/src/crews/main-loop/domain/prompts.ts +336 -0
- package/src/crews/main-loop/domain/turn-chains.ts +130 -0
- package/src/crews/project-init/application/detect.ts +123 -0
- package/src/crews/project-init/application/messages.ts +15 -0
- package/src/crews/project-init/application/prompts.ts +105 -0
- package/src/crews/project-init/application/run-project-init.ts +31 -0
- package/src/crews/project-init/crew.ork.ts +36 -0
- package/src/crews/project-init/domain/conventions.ts +36 -0
- package/src/crews/project-init/domain/existing-files.ts +65 -0
- package/src/crews/project-init/domain/messages.ts +13 -0
- package/src/crews/project-init/domain/package-map.ts +73 -0
- package/src/crews/project-init/domain/prompts.ts +10 -0
- package/src/crews/session-compact/application/prompts.ts +5 -0
- package/src/crews/session-compact/crew.ork.ts +56 -0
- package/src/crews/shared-memory-admit/application/prompts.ts +5 -0
- package/src/crews/shared-memory-admit/crew.ork.ts +49 -0
- package/src/crews/speech/application/messages.ts +3 -0
- package/src/crews/speech/application/prompts.ts +3 -0
- package/src/crews/speech/application/run-speech.ts +26 -0
- package/src/crews/speech/crew.ork.ts +38 -0
- package/src/shared/application/agents/child-agent.ts +259 -0
- package/src/shared/application/agents/messages.ts +35 -0
- package/src/shared/application/agents/route-agent.ts +115 -0
- package/src/shared/application/agents/run-sub-agent.ts +119 -0
- package/src/shared/application/answer-language.ts +14 -0
- package/src/shared/application/attached-skills.ts +36 -0
- package/src/shared/application/compaction/compact-session.ts +242 -0
- package/src/shared/application/compaction/extract-memories.ts +38 -0
- package/src/shared/application/compaction/messages.ts +20 -0
- package/src/shared/application/compaction/prune-context.ts +94 -0
- package/src/shared/application/compaction/pruned-llm.ts +35 -0
- package/src/shared/application/compaction/restore-context.ts +78 -0
- package/src/shared/application/config-store.ts +123 -0
- package/src/shared/application/dev/brief-inventory.ts +115 -0
- package/src/shared/application/dev/close-batch.ts +85 -0
- package/src/shared/application/dev/find-repo-pack.ts +78 -0
- package/src/shared/application/dev/learn-decision.ts +254 -0
- package/src/shared/application/dev/load-dev-context.ts +265 -0
- package/src/shared/application/dev/measure-access-cost.ts +69 -0
- package/src/shared/application/dev/messages.ts +132 -0
- package/src/shared/application/dev/phase-timer.ts +54 -0
- package/src/shared/application/dev/plan-source.ts +116 -0
- package/src/shared/application/dev/preflight.ts +71 -0
- package/src/shared/application/dev/project-files.ts +17 -0
- package/src/shared/application/dev/prompts.ts +34 -0
- package/src/shared/application/dev/question-round.ts +60 -0
- package/src/shared/application/dev/resolve-work-folder.ts +134 -0
- package/src/shared/application/dev/script-tool-slot.ts +27 -0
- package/src/shared/application/dev/settle-questions.ts +57 -0
- package/src/shared/application/dev/source-review.ts +67 -0
- package/src/shared/application/dev/source-step.ts +152 -0
- package/src/shared/application/dev/spend.ts +55 -0
- package/src/shared/application/dev/step-precedents.ts +90 -0
- package/src/shared/application/dev/tool-call-policy.ts +87 -0
- package/src/shared/application/dev/tool-callbacks.ts +262 -0
- package/src/shared/application/dev/tool-trace-recorder.ts +46 -0
- package/src/shared/application/dev/verdict-sources.ts +50 -0
- package/src/shared/application/dev/wrapped-tools.ts +147 -0
- package/src/shared/application/extra-tools.ts +71 -0
- package/src/shared/application/git/batch-worktree.ts +102 -0
- package/src/shared/application/git/commit-files.ts +191 -0
- package/src/shared/application/git/merge-batch.ts +67 -0
- package/src/shared/application/git/messages.ts +75 -0
- package/src/shared/application/git/open-pull-request.ts +52 -0
- package/src/shared/application/host-context.ts +59 -0
- package/src/shared/application/host-layout-store.ts +45 -0
- package/src/shared/application/instructions-file.ts +19 -0
- package/src/shared/application/json-file.ts +34 -0
- package/src/shared/application/llm-profile.ts +36 -0
- package/src/shared/application/messages.ts +14 -0
- package/src/shared/application/permission-rules.ts +169 -0
- package/src/shared/application/ports/approvals.ts +20 -0
- package/src/shared/application/ports/clock.ts +5 -0
- package/src/shared/application/ports/code-index.ts +93 -0
- package/src/shared/application/ports/crew.ts +60 -0
- package/src/shared/application/ports/decision.ts +14 -0
- package/src/shared/application/ports/files.ts +21 -0
- package/src/shared/application/ports/human.ts +38 -0
- package/src/shared/application/ports/llm.ts +83 -0
- package/src/shared/application/ports/memory.ts +30 -0
- package/src/shared/application/ports/progress.ts +23 -0
- package/src/shared/application/ports/runtime.ts +15 -0
- package/src/shared/application/ports/session.ts +74 -0
- package/src/shared/application/ports/shared-memory.ts +26 -0
- package/src/shared/application/ports/shell.ts +40 -0
- package/src/shared/application/ports/telemetry.ts +45 -0
- package/src/shared/application/ports/theme.ts +11 -0
- package/src/shared/application/ports/tools.ts +46 -0
- package/src/shared/application/ports/usage.ts +45 -0
- package/src/shared/application/ports.ts +29 -0
- package/src/shared/application/project-manifests.ts +106 -0
- package/src/shared/application/session-io.ts +85 -0
- package/src/shared/application/session-state.ts +36 -0
- package/src/shared/application/shared-memory/admit-entries.ts +179 -0
- package/src/shared/application/shared-memory/harvest-after-gaps.ts +69 -0
- package/src/shared/application/shared-memory/harvest-mistakes.ts +45 -0
- package/src/shared/application/shared-memory/import-agent-memory.ts +119 -0
- package/src/shared/application/shared-memory/memory-files.ts +111 -0
- package/src/shared/application/shared-memory/memory-settings.ts +94 -0
- package/src/shared/application/shared-memory/messages.ts +63 -0
- package/src/shared/application/shared-memory/push-candidate.ts +149 -0
- package/src/shared/application/shared-memory/recall-precedents.ts +70 -0
- package/src/shared/application/skills/messages.ts +4 -0
- package/src/shared/application/skills/suggest-skills.ts +102 -0
- package/src/shared/application/state-snapshot.ts +38 -0
- package/src/shared/application/workflow/messages.ts +8 -0
- package/src/shared/application/workflow/workflow-state.ts +136 -0
- package/src/shared/domain/agent-policy/behavior-flags.ts +162 -0
- package/src/shared/domain/agent-policy/extra-tools.ts +67 -0
- package/src/shared/domain/agent-policy/memory-categories.ts +6 -0
- package/src/shared/domain/agent-policy/messages.ts +66 -0
- package/src/shared/domain/agent-policy/mode-policy.ts +51 -0
- package/src/shared/domain/agent-policy/output-styles.ts +11 -0
- package/src/shared/domain/agent-policy/path-rules.ts +299 -0
- package/src/shared/domain/agent-policy/permission.ts +625 -0
- package/src/shared/domain/agent-policy/prompts.ts +17 -0
- package/src/shared/domain/agent-policy/reasoning.ts +59 -0
- package/src/shared/domain/agent-policy/rule-sets.ts +416 -0
- package/src/shared/domain/agent-policy/tool-access.ts +91 -0
- package/src/shared/domain/agent-registry.ts +143 -0
- package/src/shared/domain/agents/built-in-charters.ts +43 -0
- package/src/shared/domain/agents/chain.ts +30 -0
- package/src/shared/domain/agents/charter.ts +64 -0
- package/src/shared/domain/agents/exclusive.ts +25 -0
- package/src/shared/domain/agents/instances.ts +252 -0
- package/src/shared/domain/agents/messages.ts +39 -0
- package/src/shared/domain/agents/model-route.ts +199 -0
- package/src/shared/domain/agents/prompts.ts +20 -0
- package/src/shared/domain/code-intel-contract.ts +357 -0
- package/src/shared/domain/code-intel-routing.ts +60 -0
- package/src/shared/domain/compact-outcome.ts +46 -0
- package/src/shared/domain/compaction-thresholds.ts +162 -0
- package/src/shared/domain/compaction.ts +288 -0
- package/src/shared/domain/config-schema.ts +434 -0
- package/src/shared/domain/context-prune.ts +176 -0
- package/src/shared/domain/decision/questions.ts +102 -0
- package/src/shared/domain/dev/access-cost.ts +230 -0
- package/src/shared/domain/dev/artefacts.ts +50 -0
- package/src/shared/domain/dev/batches-concurrency.ts +35 -0
- package/src/shared/domain/dev/batches-state.ts +49 -0
- package/src/shared/domain/dev/build-commands.ts +45 -0
- package/src/shared/domain/dev/call-guard.ts +342 -0
- package/src/shared/domain/dev/carried-text.ts +47 -0
- package/src/shared/domain/dev/design-rules.ts +100 -0
- package/src/shared/domain/dev/learn-proposals.ts +176 -0
- package/src/shared/domain/dev/learn-state.ts +94 -0
- package/src/shared/domain/dev/markers.ts +107 -0
- package/src/shared/domain/dev/messages.ts +259 -0
- package/src/shared/domain/dev/path-args.ts +42 -0
- package/src/shared/domain/dev/path-rebase.ts +93 -0
- package/src/shared/domain/dev/phase-timing.ts +50 -0
- package/src/shared/domain/dev/plan-checks.ts +191 -0
- package/src/shared/domain/dev/plan-format.ts +170 -0
- package/src/shared/domain/dev/project-files.ts +29 -0
- package/src/shared/domain/dev/prompts/brief-blocks.ts +20 -0
- package/src/shared/domain/dev/prompts.ts +251 -0
- package/src/shared/domain/dev/questions.ts +267 -0
- package/src/shared/domain/dev/reading-rule.ts +41 -0
- package/src/shared/domain/dev/repo-pack.ts +240 -0
- package/src/shared/domain/dev/review-answer.ts +173 -0
- package/src/shared/domain/dev/review-brief.ts +54 -0
- package/src/shared/domain/dev/reviewer-charter.ts +35 -0
- package/src/shared/domain/dev/sheet-facts.ts +81 -0
- package/src/shared/domain/dev/spec-format.ts +182 -0
- package/src/shared/domain/dev/step-budget.ts +74 -0
- package/src/shared/domain/dev/step-rules.ts +109 -0
- package/src/shared/domain/dev/test-commands.ts +94 -0
- package/src/shared/domain/dev/test-output.ts +33 -0
- package/src/shared/domain/dev/test-paths.ts +40 -0
- package/src/shared/domain/dev/tool-guards.ts +65 -0
- package/src/shared/domain/dev/trait-pattern.ts +87 -0
- package/src/shared/domain/dev/verdict-format.ts +162 -0
- package/src/shared/domain/dev/whitespace.ts +35 -0
- package/src/shared/domain/dev/work-folder.ts +68 -0
- package/src/shared/domain/dev/yaml-subset.ts +385 -0
- package/src/shared/domain/error-text.ts +13 -0
- package/src/shared/domain/git/close.ts +274 -0
- package/src/shared/domain/git/messages.ts +20 -0
- package/src/shared/domain/git/pull-request.ts +96 -0
- package/src/shared/domain/git/worktree.ts +46 -0
- package/src/shared/domain/host-layout.ts +147 -0
- package/src/shared/domain/host-paths.ts +399 -0
- package/src/shared/domain/index-languages.ts +16 -0
- package/src/shared/domain/instructions-file.ts +18 -0
- package/src/shared/domain/iso-day.ts +4 -0
- package/src/shared/domain/llm-failure.ts +134 -0
- package/src/shared/domain/llm-profile.ts +44 -0
- package/src/shared/domain/marked-message.ts +29 -0
- package/src/shared/domain/markers.ts +30 -0
- package/src/shared/domain/messages.ts +291 -0
- package/src/shared/domain/model-catalog.ts +79 -0
- package/src/shared/domain/permission-modes.ts +99 -0
- package/src/shared/domain/prelude.ts +92 -0
- package/src/shared/domain/project-manifests.ts +84 -0
- package/src/shared/domain/prompts.ts +233 -0
- package/src/shared/domain/search-routing.ts +77 -0
- package/src/shared/domain/secret-patterns.ts +46 -0
- package/src/shared/domain/session-keys.ts +92 -0
- package/src/shared/domain/session-start.ts +61 -0
- package/src/shared/domain/severity.ts +72 -0
- package/src/shared/domain/sha1.ts +61 -0
- package/src/shared/domain/shared-memory/agent-memory-import.ts +145 -0
- package/src/shared/domain/shared-memory/candidates.ts +40 -0
- package/src/shared/domain/shared-memory/entry.ts +151 -0
- package/src/shared/domain/shared-memory/front-matter.ts +187 -0
- package/src/shared/domain/shared-memory/gate.ts +45 -0
- package/src/shared/domain/shared-memory/harvest.ts +64 -0
- package/src/shared/domain/shared-memory/layout.ts +190 -0
- package/src/shared/domain/shared-memory/markers.ts +9 -0
- package/src/shared/domain/shared-memory/messages.ts +66 -0
- package/src/shared/domain/shared-memory/precedents-block.ts +82 -0
- package/src/shared/domain/shared-memory/prompts.ts +28 -0
- package/src/shared/domain/shared-memory/refused.ts +84 -0
- package/src/shared/domain/shared-memory/verdict-rows.ts +134 -0
- package/src/shared/domain/skills/prompts.ts +4 -0
- package/src/shared/domain/skills/shortlist.ts +149 -0
- package/src/shared/domain/snip-turns.ts +33 -0
- package/src/shared/domain/speech.ts +21 -0
- package/src/shared/domain/strip.ts +88 -0
- package/src/shared/domain/tool-trace.ts +120 -0
- package/src/shared/domain/types.ts +67 -0
- package/src/shared/domain/verifiers.ts +33 -0
- package/src/shared/domain/vfs.ts +16 -0
- package/src/shared/domain/workflow/prompts.ts +15 -0
- package/src/shared/domain/workflow/state-file.ts +142 -0
- package/src/shared/infrastructure/globals.ts +57 -0
- package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
- package/src/shared/infrastructure/orkeon/child-agents.ts +122 -0
- package/src/shared/infrastructure/orkeon/chooser.ts +32 -0
- package/src/shared/infrastructure/orkeon/code-index.ts +120 -0
- package/src/shared/infrastructure/orkeon/crew-host.ts +27 -0
- package/src/shared/infrastructure/orkeon/crew-memory.ts +12 -0
- package/src/shared/infrastructure/orkeon/decision-model.ts +31 -0
- package/src/shared/infrastructure/orkeon/dev-deps.ts +179 -0
- package/src/shared/infrastructure/orkeon/files.ts +58 -0
- package/src/shared/infrastructure/orkeon/github-pull-requests.ts +30 -0
- package/src/shared/infrastructure/orkeon/host-context.ts +36 -0
- package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
- package/src/shared/infrastructure/orkeon/human-input.ts +55 -0
- package/src/shared/infrastructure/orkeon/llm-profile.ts +58 -0
- package/src/shared/infrastructure/orkeon/llm.ts +164 -0
- package/src/shared/infrastructure/orkeon/markers.ts +6 -0
- package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
- package/src/shared/infrastructure/orkeon/memory-tools.ts +129 -0
- package/src/shared/infrastructure/orkeon/messages.ts +15 -0
- package/src/shared/infrastructure/orkeon/permission-rules.ts +42 -0
- package/src/shared/infrastructure/orkeon/progress.ts +24 -0
- package/src/shared/infrastructure/orkeon/prompts.ts +47 -0
- package/src/shared/infrastructure/orkeon/reasoning.ts +40 -0
- package/src/shared/infrastructure/orkeon/run-state.ts +17 -0
- package/src/shared/infrastructure/orkeon/runtime-info.ts +30 -0
- package/src/shared/infrastructure/orkeon/runtime-tools.ts +60 -0
- package/src/shared/infrastructure/orkeon/script-tools.ts +129 -0
- package/src/shared/infrastructure/orkeon/session-store.ts +94 -0
- package/src/shared/infrastructure/orkeon/session-switch.ts +23 -0
- package/src/shared/infrastructure/orkeon/shared-memory.ts +61 -0
- package/src/shared/infrastructure/orkeon/shell-jobs.ts +81 -0
- package/src/shared/infrastructure/orkeon/shell.ts +39 -0
- package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
- package/src/shared/infrastructure/orkeon/tool-catalogue.ts +76 -0
- package/src/shared/infrastructure/orkeon/tool-results.ts +120 -0
- package/src/shared/infrastructure/orkeon/usage.ts +74 -0
- package/src/shared/infrastructure/orkeon/wiring.ts +174 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// A sub-agent's act run as a background child of the crew (A-3, approach A2 of temp/03 § A). The
|
|
2
|
+
// child is an agent of the crew holding the charter's tools; it acts on the prompt and leaves its
|
|
3
|
+
// reply in the crew's memory under a key the parent chose. Meanwhile the parent body keeps the run's
|
|
4
|
+
// board — the snapshot /tasks reads in the session's state bag — and serves the stop /tasks asks
|
|
5
|
+
// for a running one. An act with `waitFor: "children"` would wait as well, but no script runs
|
|
6
|
+
// during its wait, so nothing could answer /tasks. The runtime's instance rows name the agent by
|
|
7
|
+
// its id, not its name: the child says its instance id (`ctx.instanceId`) under instanceKey first.
|
|
8
|
+
|
|
9
|
+
import type { ActRequest, ChildRuntime, Logger, SessionStore } from "../ports.ts";
|
|
10
|
+
import { INSTANCE_STATES, SNAPSHOT_HEARTBEAT_MS, parseRequest, requestKey, snapshotKey } from "../../domain/agents/instances.ts";
|
|
11
|
+
import type { InstanceRecord, InstanceState, RunSnapshot } from "../../domain/agents/instances.ts";
|
|
12
|
+
import {
|
|
13
|
+
CHILD_ENDED_WITHOUT_REPLY, CHILD_FAILED, STOPPED_BY_TASKS_STOP, instancesNotWritten, startedInBackground, tasksStopLine,
|
|
14
|
+
waitReturnedAtOnce,
|
|
15
|
+
} from "./messages.ts";
|
|
16
|
+
|
|
17
|
+
type StateBag = Pick<SessionStore, "readState" | "writeState">;
|
|
18
|
+
|
|
19
|
+
/** How long the parent waits between two looks at its child. */
|
|
20
|
+
export const CHILD_POLL_MS = 1000;
|
|
21
|
+
/** Pauses in a row that return at once before the wait gives up rather than spin. */
|
|
22
|
+
export const MAX_EARLY_WAKES = 3;
|
|
23
|
+
|
|
24
|
+
/** What the child is handed: what it acts on, how, and where it leaves its reply. */
|
|
25
|
+
export interface ChildInput {
|
|
26
|
+
key: string;
|
|
27
|
+
prompt: string;
|
|
28
|
+
request: ActRequest;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** What a child leaves under its key once its act has settled. */
|
|
32
|
+
export type ChildOutcome = { ok: true; reply: string } | { ok: false; error: string };
|
|
33
|
+
|
|
34
|
+
/** The child's input, read back from the string spawnBackground carries; null when it is not one. */
|
|
35
|
+
export function parseChildInput(raw: unknown): ChildInput | null {
|
|
36
|
+
let v: any;
|
|
37
|
+
try {
|
|
38
|
+
v = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (v === null || typeof v !== "object" || typeof v.key !== "string" || typeof v.prompt !== "string") return null;
|
|
43
|
+
const request = v.request !== null && typeof v.request === "object" ? (v.request as ActRequest) : {};
|
|
44
|
+
return { key: v.key, prompt: v.prompt, request };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Where the child leaves its instance id (`a1`…) beside its reply. */
|
|
48
|
+
export const instanceKey = (key: string): string => `${key}:instance`;
|
|
49
|
+
|
|
50
|
+
/** A stored outcome; undefined while the child has left none. */
|
|
51
|
+
export function readChildOutcome(raw: unknown): ChildOutcome | undefined {
|
|
52
|
+
const v = raw as Record<string, unknown> | null | undefined;
|
|
53
|
+
if (v === null || typeof v !== "object") return undefined;
|
|
54
|
+
if (v.ok === true && typeof v.reply === "string") return { ok: true, reply: v.reply };
|
|
55
|
+
if (v.ok === false) return { ok: false, error: typeof v.error === "string" ? v.error : CHILD_FAILED };
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const firstLine = (error: unknown): string => String((error as Error)?.message ?? error).split("\n")[0];
|
|
60
|
+
|
|
61
|
+
/** The run's board: its children, the snapshot /tasks reads, and the requests it serves. */
|
|
62
|
+
export interface ChildBoard {
|
|
63
|
+
/** A key no other child of this run uses. */
|
|
64
|
+
nextKey(): string;
|
|
65
|
+
add(record: InstanceRecord): void;
|
|
66
|
+
records(): readonly InstanceRecord[];
|
|
67
|
+
/** Writes the snapshot when it changed; a failed write is logged once and never fails the run. */
|
|
68
|
+
publish(serving: boolean): Promise<void>;
|
|
69
|
+
/** Reads and clears the pending stop of each running child of this run, and stops it. */
|
|
70
|
+
serve(runtime: Pick<ChildRuntime, "stop">): Promise<void>;
|
|
71
|
+
/** Clears what /tasks left for `id`: a request of an earlier run, or one this run no longer serves. */
|
|
72
|
+
clearRequest(id: string): Promise<void>;
|
|
73
|
+
/** The run has ended: the snapshot says so. */
|
|
74
|
+
close(): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface BoardDeps {
|
|
78
|
+
state: StateBag;
|
|
79
|
+
clock: () => Date;
|
|
80
|
+
log: Logger;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function createChildBoard(deps: BoardDeps, run: { crew: string; step: string }): ChildBoard {
|
|
84
|
+
const records: InstanceRecord[] = [];
|
|
85
|
+
const startedAt = deps.clock().toISOString();
|
|
86
|
+
let serial = 0;
|
|
87
|
+
let written = "";
|
|
88
|
+
let writtenAt = 0;
|
|
89
|
+
let warned = false;
|
|
90
|
+
let open = true;
|
|
91
|
+
const now = () => deps.clock().toISOString();
|
|
92
|
+
|
|
93
|
+
async function write(serving: boolean): Promise<void> {
|
|
94
|
+
const body: Omit<RunSnapshot, "updatedAt"> = { crew: run.crew, step: run.step, startedAt, serving, open, instances: records };
|
|
95
|
+
const text = JSON.stringify(body);
|
|
96
|
+
const at = deps.clock().getTime();
|
|
97
|
+
// Unchanged, it is written again while the run answers, so /tasks can tell a live run from a dead one.
|
|
98
|
+
if (text === written && !(serving && at - writtenAt >= SNAPSHOT_HEARTBEAT_MS)) return;
|
|
99
|
+
try {
|
|
100
|
+
await deps.state.writeState(snapshotKey(run.crew), JSON.stringify({ ...body, updatedAt: now() }));
|
|
101
|
+
written = text;
|
|
102
|
+
writtenAt = at;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
if (!warned) deps.log.warn(instancesNotWritten(run.crew, firstLine(error)));
|
|
105
|
+
warned = true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function clearRequest(id: string): Promise<void> {
|
|
110
|
+
if (id !== "") await deps.state.writeState(requestKey(run.crew, id), "").catch(() => undefined);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function serveOne(runtime: Pick<ChildRuntime, "stop">, record: InstanceRecord): Promise<void> {
|
|
114
|
+
let raw: string | null;
|
|
115
|
+
try {
|
|
116
|
+
raw = await deps.state.readState(requestKey(run.crew, record.id));
|
|
117
|
+
} catch {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const request = parseRequest(raw);
|
|
121
|
+
if (request === null) return;
|
|
122
|
+
await clearRequest(record.id);
|
|
123
|
+
// Ids restart at a1 in every run: a stop meant for another run is dropped, never served here.
|
|
124
|
+
if (request.run !== startedAt) return;
|
|
125
|
+
record.stopRequested = runtime.stop(record.id) || undefined;
|
|
126
|
+
deps.log.info(tasksStopLine(run.crew, record.id, record.agent, record.stopRequested));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
nextKey: () => `${run.crew}:child:${++serial}`,
|
|
131
|
+
add: (record) => {
|
|
132
|
+
records.push(record);
|
|
133
|
+
},
|
|
134
|
+
records: () => records,
|
|
135
|
+
publish: write,
|
|
136
|
+
async serve(runtime) {
|
|
137
|
+
for (const record of records) if (record.id !== "" && record.state === "running") await serveOne(runtime, record);
|
|
138
|
+
},
|
|
139
|
+
clearRequest,
|
|
140
|
+
async close() {
|
|
141
|
+
open = false;
|
|
142
|
+
// A run that started no child leaves the last run's snapshot alone: its instances can still be repaired.
|
|
143
|
+
if (records.length > 0) await write(false);
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface ChildCall {
|
|
149
|
+
/** The crew agent the child runs as. */
|
|
150
|
+
agent: string;
|
|
151
|
+
/** The built-in charter it runs (built-in-charters.ts). */
|
|
152
|
+
charter: string;
|
|
153
|
+
/** What it is asked, in a few words, for /tasks. */
|
|
154
|
+
task: string;
|
|
155
|
+
prompt: string;
|
|
156
|
+
request: ActRequest;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface ChildDeps {
|
|
160
|
+
runtime: ChildRuntime;
|
|
161
|
+
board: ChildBoard;
|
|
162
|
+
clock: () => Date;
|
|
163
|
+
log: Logger;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const asState = (s: string): InstanceState =>
|
|
167
|
+
(INSTANCE_STATES as readonly string[]).includes(s) ? (s as InstanceState) : "failed";
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The instance id of the child under `key`: the one it said, else the newest running instance no
|
|
171
|
+
* record of the board holds (the parent starts one child at a time, so that is the one it just
|
|
172
|
+
* started; the rows name the agent by its id, not its name, so they cannot be matched by name).
|
|
173
|
+
*/
|
|
174
|
+
async function childInstanceId(runtime: Pick<ChildRuntime, "instances" | "read">, board: ChildBoard, key: string): Promise<string> {
|
|
175
|
+
const said = await runtime.read(instanceKey(key));
|
|
176
|
+
if (typeof said === "string" && said !== "") return said;
|
|
177
|
+
const held = new Set(board.records().map((r) => r.id));
|
|
178
|
+
const fresh = runtime.instances().filter((i) => i.state === "running" && !held.has(i.id));
|
|
179
|
+
return fresh.length > 0 ? fresh[fresh.length - 1].id : "";
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* The act of `call` run by a background child; resolves to its reply, throws when it failed or was
|
|
184
|
+
* stopped (the caller's sub-agent run reads that as a failed model call).
|
|
185
|
+
*/
|
|
186
|
+
export async function runChildAct(deps: ChildDeps, call: ChildCall): Promise<string> {
|
|
187
|
+
const { runtime, board, clock, log } = deps;
|
|
188
|
+
const key = board.nextKey();
|
|
189
|
+
const input: ChildInput = { key, prompt: call.prompt, request: call.request };
|
|
190
|
+
runtime.spawn(call.agent, JSON.stringify(input));
|
|
191
|
+
const record: InstanceRecord = {
|
|
192
|
+
id: "", agent: call.agent, charter: call.charter, task: call.task,
|
|
193
|
+
state: "running", startedAt: clock().toISOString(), effort: call.request.effort, system: call.request.system ?? "",
|
|
194
|
+
brief: call.prompt,
|
|
195
|
+
};
|
|
196
|
+
const resolveId = async () => {
|
|
197
|
+
if (record.id !== "") return;
|
|
198
|
+
record.id = await childInstanceId(runtime, board, key);
|
|
199
|
+
// A request an earlier run left for this id is not this child's.
|
|
200
|
+
await board.clearRequest(record.id);
|
|
201
|
+
};
|
|
202
|
+
await resolveId();
|
|
203
|
+
board.add(record);
|
|
204
|
+
log.info(startedInBackground(call.agent, record.id || "?", call.task));
|
|
205
|
+
let early = 0;
|
|
206
|
+
try {
|
|
207
|
+
for (;;) {
|
|
208
|
+
await resolveId();
|
|
209
|
+
const outcome = readChildOutcome(await runtime.read(key));
|
|
210
|
+
const row = runtime.instances().find((i) => i.id === record.id);
|
|
211
|
+
const stopped = row?.state === "stopped" || (record.stopRequested === true && outcome?.ok !== true);
|
|
212
|
+
if (stopped && (outcome !== undefined || (row !== undefined && row.state !== "running"))) {
|
|
213
|
+
// A stopped child's act rejects, and its body leaves that failure: the stop is what happened.
|
|
214
|
+
record.state = "stopped";
|
|
215
|
+
record.error = STOPPED_BY_TASKS_STOP;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
if (outcome !== undefined) {
|
|
219
|
+
record.state = outcome.ok ? "completed" : "failed";
|
|
220
|
+
if (outcome.ok) record.reply = outcome.reply;
|
|
221
|
+
else record.error = outcome.error;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
if (row !== undefined && row.state !== "running") {
|
|
225
|
+
record.state = asState(row.state);
|
|
226
|
+
record.error = CHILD_ENDED_WITHOUT_REPLY;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
await board.serve(runtime);
|
|
230
|
+
await board.publish(true);
|
|
231
|
+
const before = clock().getTime();
|
|
232
|
+
await runtime.pause(CHILD_POLL_MS);
|
|
233
|
+
if (clock().getTime() - before < CHILD_POLL_MS / 4) {
|
|
234
|
+
early += 1;
|
|
235
|
+
if (early >= MAX_EARLY_WAKES) {
|
|
236
|
+
record.state = "failed";
|
|
237
|
+
record.error = waitReturnedAtOnce(call.agent, early);
|
|
238
|
+
runtime.stop(record.id);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
early = 0;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
} catch (error) {
|
|
246
|
+
// The wait itself failed (the run was cancelled, the host refused a read): the child goes with it.
|
|
247
|
+
record.state = "failed";
|
|
248
|
+
record.error = firstLine(error);
|
|
249
|
+
runtime.stop(record.id);
|
|
250
|
+
throw error;
|
|
251
|
+
} finally {
|
|
252
|
+
record.endedAt = clock().toISOString();
|
|
253
|
+
await board.clearRequest(record.id);
|
|
254
|
+
await board.publish(false);
|
|
255
|
+
}
|
|
256
|
+
log.info(`${call.agent} ${record.id || "?"} ${record.state}${record.error ? `: ${record.error}` : ""}`);
|
|
257
|
+
if (record.state === "completed" && record.reply !== undefined) return record.reply;
|
|
258
|
+
throw new Error(`${call.agent} ${record.id || "?"} ${record.state}: ${record.error ?? "no reply"}`);
|
|
259
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The text the agent services report: the lines of a background child and the problems of a sub-agent's answer.
|
|
2
|
+
|
|
3
|
+
// child-agent.ts
|
|
4
|
+
export const CHILD_FAILED = "the child failed";
|
|
5
|
+
export const instancesNotWritten = (crew: string, reason: string): string =>
|
|
6
|
+
`${crew}: the agent instances could not be written for /tasks: ${reason}`;
|
|
7
|
+
export const tasksStopLine = (crew: string, id: string, agent: string, stopRequested: boolean | undefined): string =>
|
|
8
|
+
`${crew}: /tasks stop ${id} (${agent})${stopRequested ? "" : ": it was no longer running"}`;
|
|
9
|
+
export const startedInBackground = (agent: string, id: string, task: string): string =>
|
|
10
|
+
`${agent} ${id} started in the background: ${task}`;
|
|
11
|
+
export const STOPPED_BY_TASKS_STOP = "stopped by /tasks stop";
|
|
12
|
+
export const CHILD_ENDED_WITHOUT_REPLY = "the child ended without leaving a reply";
|
|
13
|
+
export const waitReturnedAtOnce = (agent: string, early: number): string =>
|
|
14
|
+
`the wait for ${agent} returned at once ${early} times in a row`;
|
|
15
|
+
|
|
16
|
+
// run-sub-agent.ts
|
|
17
|
+
/** The log line of an answer refused and asked again: what was wrong with it. */
|
|
18
|
+
export const answerAskedAgain = (who: string, problems: readonly string[]): string =>
|
|
19
|
+
`${who}: answer refused, asked again: ${problems.join("; ")}`;
|
|
20
|
+
export const answerDidNotParse = (reason: string): string => `the answer did not parse: ${reason}`;
|
|
21
|
+
export const briefTooLong = (length: number, max: number): string => `the brief is ${length} characters, over ${max}`;
|
|
22
|
+
export const ROUTE_WITHOUT_DECISION_MODEL =
|
|
23
|
+
"route.agents is on and the host has no decision model: the session's profile stands (set Orkeon:Decision:Provider, or Orkeon:TypeSafe)";
|
|
24
|
+
export const routeKeepsProfile = (profile: string, ladder: string): string =>
|
|
25
|
+
`route.agents is on and the session's llm.profile '${profile}' is not on the ladder (${ladder}): it stands`;
|
|
26
|
+
export const routedLine = (crew: string, profile: string, why: string): string => `route: ${crew} on '${profile}' (${why})`;
|
|
27
|
+
export const ROUTE_WHY = {
|
|
28
|
+
model: "the decision model's pick",
|
|
29
|
+
floor: "raised by a rule of .orkeon/route-rules.json",
|
|
30
|
+
ceiling: "held at the session's profile",
|
|
31
|
+
"low-confidence": "the pick was not sure enough, the session's profile stands",
|
|
32
|
+
"no-answer": "the decision model did not answer, the session's profile stands",
|
|
33
|
+
} as const;
|
|
34
|
+
export const pickedWith = (picked: string, confidence: number): string => `picked '${picked}' at ${confidence.toFixed(2)}`;
|
|
35
|
+
export const HOST_DEFAULT_MODEL = "the host's default model";
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// The profile a crew is launched on (ADR 0027): with `route.agents` on and a decision model on the host, the model
|
|
2
|
+
// reads the command and picks a rung of `route.ladder`; the project's rules raise a floor and the session's profile
|
|
3
|
+
// is the ceiling (shared/domain/agents/model-route.ts). It fails open at every step: the setting off or unreadable,
|
|
4
|
+
// no decision model, a session on a profile outside the ladder, a model that does not answer, throws or is not sure
|
|
5
|
+
// leave the session's profile as it is. A routed launch also carries the session's profile, which the crew falls
|
|
6
|
+
// back on when the host declares no profile of the rung's name (orkeon/llm-profile.ts). Each routed launch is logged
|
|
7
|
+
// and kept for `/route why`. The act of a sub-agent inside a crew (a reviewer, the auditor) is routed by the same
|
|
8
|
+
// decision, under its charter's name (actRoute): it is moved only when the model decided, and off the crew's profile.
|
|
9
|
+
import type { DecisionModel, Files, Logger, SessionStore } from "../ports.ts";
|
|
10
|
+
import type { ConfigStore } from "../config-store.ts";
|
|
11
|
+
import { WORKSPACE } from "../../domain/vfs.ts";
|
|
12
|
+
import { ROUTE_RECENT_STATE_KEY } from "../../domain/session-keys.ts";
|
|
13
|
+
import type { DecisionAnswers } from "../../domain/decision/questions.ts";
|
|
14
|
+
import type { RouteChoice, RouteRules } from "../../domain/agents/model-route.ts";
|
|
15
|
+
import {
|
|
16
|
+
NO_ROUTE_RULES, ROUTE_AGENTS_CONFIG_KEY, ROUTE_LADDER_CONFIG_KEY, ROUTE_RULES_FILE, ladderOf, parseRecords, parseRouteRules,
|
|
17
|
+
routable, routeDecided, routeFloor, routeOf, routeOn, routeQuestions, routeState, withRecord,
|
|
18
|
+
} from "../../domain/agents/model-route.ts";
|
|
19
|
+
import {
|
|
20
|
+
HOST_DEFAULT_MODEL, ROUTE_WHY, ROUTE_WITHOUT_DECISION_MODEL, pickedWith, routeKeepsProfile, routedLine,
|
|
21
|
+
} from "./messages.ts";
|
|
22
|
+
|
|
23
|
+
export interface RouteDeps {
|
|
24
|
+
config: Pick<ConfigStore, "readValue">;
|
|
25
|
+
decision: DecisionModel;
|
|
26
|
+
files: Pick<Files, "read">;
|
|
27
|
+
session: Pick<SessionStore, "readState" | "writeState">;
|
|
28
|
+
log: Pick<Logger, "info" | "warn">;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** What is routed: the crew, and the command that launches it, as typed. */
|
|
32
|
+
export interface RouteTask {
|
|
33
|
+
crew: string;
|
|
34
|
+
brief: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function setting(config: RouteDeps["config"], key: string): Promise<unknown> {
|
|
38
|
+
try {
|
|
39
|
+
return (await config.readValue(key)).value;
|
|
40
|
+
} catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The project's floors; none when the file is absent or unreadable. */
|
|
46
|
+
async function rulesOf(files: RouteDeps["files"]): Promise<RouteRules> {
|
|
47
|
+
try {
|
|
48
|
+
return parseRouteRules(await files.read(`${WORKSPACE}/${ROUTE_RULES_FILE}`));
|
|
49
|
+
} catch {
|
|
50
|
+
return NO_ROUTE_RULES;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Why a choice stands, with the model's pick when it made one. */
|
|
55
|
+
export function routeWhy(choice: Pick<RouteChoice, "reason" | "picked" | "confidence">): string {
|
|
56
|
+
const why = ROUTE_WHY[choice.reason];
|
|
57
|
+
return choice.picked === undefined || choice.confidence === undefined ? why : `${why}; ${pickedWith(choice.picked, choice.confidence)}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function remember(session: RouteDeps["session"], crew: string, choice: RouteChoice): Promise<void> {
|
|
61
|
+
try {
|
|
62
|
+
const records = withRecord(parseRecords(await session.readState(ROUTE_RECENT_STATE_KEY)), { crew, ...choice });
|
|
63
|
+
await session.writeState(ROUTE_RECENT_STATE_KEY, JSON.stringify(records));
|
|
64
|
+
} catch { /* the record is a convenience: the launch goes on without it */ }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The choice made for `task`, logged and kept; null when nothing was asked (the setting off, no decision model, a
|
|
68
|
+
* session's profile outside the ladder). */
|
|
69
|
+
async function choose(deps: RouteDeps, task: RouteTask, sessionProfile: string | null): Promise<RouteChoice | null> {
|
|
70
|
+
if (!routeOn(await setting(deps.config, ROUTE_AGENTS_CONFIG_KEY))) return null;
|
|
71
|
+
if (!deps.decision.available()) {
|
|
72
|
+
deps.log.warn(ROUTE_WITHOUT_DECISION_MODEL);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const ladder = ladderOf(await setting(deps.config, ROUTE_LADDER_CONFIG_KEY));
|
|
76
|
+
if (sessionProfile !== null && !routable(sessionProfile, ladder)) {
|
|
77
|
+
deps.log.info(routeKeepsProfile(sessionProfile, ladder.join(",")));
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const floor = routeFloor(await rulesOf(deps.files), task.crew, task.brief, ladder);
|
|
81
|
+
let answers: DecisionAnswers | null = null;
|
|
82
|
+
try {
|
|
83
|
+
answers = await deps.decision.ask(routeState(task.crew, task.brief), routeQuestions(ladder));
|
|
84
|
+
} catch { /* a decision model that throws is one that did not answer */ }
|
|
85
|
+
const choice = routeOf(answers, ladder, sessionProfile, floor);
|
|
86
|
+
deps.log.info(routedLine(task.crew, choice.profile ?? HOST_DEFAULT_MODEL, routeWhy(choice)));
|
|
87
|
+
await remember(deps.session, task.crew, choice);
|
|
88
|
+
return choice;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The profile `task.crew` is launched on, the session being on `sessionProfile` (null: the host's default model). */
|
|
92
|
+
export async function routeAgent(deps: RouteDeps, task: RouteTask, sessionProfile: string | null): Promise<string | null> {
|
|
93
|
+
const choice = await choose(deps, task, sessionProfile);
|
|
94
|
+
return choice === null ? sessionProfile : choice.profile;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The profile one sub-agent act is moved to; null leaves the act on the profile the crew's agent runs on. */
|
|
98
|
+
export type ActRoute = (task: RouteTask) => Promise<string | null>;
|
|
99
|
+
|
|
100
|
+
/** The profiles a crew's acts are routed between: the session's (the ceiling) and the one the crew runs on. */
|
|
101
|
+
export interface ActProfiles {
|
|
102
|
+
session: string | null;
|
|
103
|
+
crew: string | null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The route of a crew's sub-agent acts: the launch's decision, with the session's profile as the ceiling. It moves
|
|
107
|
+
* an act only on a decision (routeDecided): nothing asked, no answer or an unsure pick leave the act where the crew
|
|
108
|
+
* runs, as does an answer that is the crew's own profile. */
|
|
109
|
+
export function actRoute(deps: RouteDeps, profiles: ActProfiles): ActRoute {
|
|
110
|
+
return async (task) => {
|
|
111
|
+
const choice = await choose(deps, task, profiles.session);
|
|
112
|
+
if (choice === null || !routeDecided(choice.reason) || choice.profile === profiles.crew) return null;
|
|
113
|
+
return choice.profile;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// runSubAgent: one sub-agent turn under its charter. It acts in the charter's
|
|
2
|
+
// mode with the behaviour specification as the system message, then extracts the
|
|
3
|
+
// final reply into a schema and checks it. An answer that fails is re-asked once
|
|
4
|
+
// over the same reply, with the problems found; no second act is made. A call
|
|
5
|
+
// that throws a cancellation (the host cancelled the run, /tasks stop stopped the
|
|
6
|
+
// child) is `cancelled`; a step budget spent during the extraction is the model's
|
|
7
|
+
// failure, not an answer that did not parse. A route, when given, is asked once before the act for the profile it
|
|
8
|
+
// runs on (route-agent.ts actRoute): null, or a route that throws, leaves the act on the agent's own profile; the
|
|
9
|
+
// extractions are never routed.
|
|
10
|
+
|
|
11
|
+
import type { Llm, Logger } from "../ports.ts";
|
|
12
|
+
import type { ActRoute } from "./route-agent.ts";
|
|
13
|
+
import { MAX_BRIEF_CHARS, charterProblems } from "../../domain/agents/charter.ts";
|
|
14
|
+
import type { Charter, Checked } from "../../domain/agents/charter.ts";
|
|
15
|
+
import { readBudgetExhausted } from "../../domain/dev/step-budget.ts";
|
|
16
|
+
import { answerAskedAgain, answerDidNotParse, briefTooLong } from "./messages.ts";
|
|
17
|
+
import { errorText } from "../../domain/error-text.ts";
|
|
18
|
+
|
|
19
|
+
export interface SubAgentCall<T> {
|
|
20
|
+
charter: Charter;
|
|
21
|
+
/** The charter's behaviour specification: the act's system message. */
|
|
22
|
+
system: string;
|
|
23
|
+
/** The task and its material: the act's prompt. */
|
|
24
|
+
brief: string;
|
|
25
|
+
/** The tools the act is offered, a subset of the agent's; the agent's whole catalogue when absent. */
|
|
26
|
+
tools?: readonly string[];
|
|
27
|
+
/** The JSON schema the answer is extracted into. */
|
|
28
|
+
schema: object;
|
|
29
|
+
/** The extraction prompt over the act's final reply; `problems` is empty on the first try. */
|
|
30
|
+
answerPrompt: (reply: string, problems: readonly string[]) => string;
|
|
31
|
+
check: (value: unknown) => Checked<T>;
|
|
32
|
+
/** The check of the second try, when it may accept what the first refused; `check` when absent. */
|
|
33
|
+
lastCheck?: (value: unknown) => Checked<T>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type SubAgentFailure = "invalid-charter" | "brief-too-long" | "model-failed" | "cancelled" | "unparsable";
|
|
37
|
+
|
|
38
|
+
export type SubAgentOutcome<T> =
|
|
39
|
+
| { ok: true; value: T; reply: string; tries: 1 | 2 }
|
|
40
|
+
| { ok: false; reason: SubAgentFailure; problems: string[]; reply: string };
|
|
41
|
+
|
|
42
|
+
function firstLine(error: unknown): string {
|
|
43
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
44
|
+
return message.split("\n")[0];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The .NET cancellation name, the DOM's abort, the runtime's cancel sentence, and the stop /tasks serves on a child (runChildAct). */
|
|
48
|
+
// Not TaskCanceled: .NET raises it for an HTTP timeout too, which is the model's failure.
|
|
49
|
+
const CANCEL_NAME = /^OperationCanceled(?:Exception)?$|^AbortError$/;
|
|
50
|
+
const CANCEL_MESSAGE = /\b(?:the )?(?:operation|task) was cancell?ed\b|stopped by \/tasks stop/i;
|
|
51
|
+
|
|
52
|
+
/** Why a thrown call failed: a cancellation, else the model's failure. */
|
|
53
|
+
function failureOf(error: unknown): "cancelled" | "model-failed" {
|
|
54
|
+
const name = error instanceof Error ? error.name : "";
|
|
55
|
+
return CANCEL_NAME.test(name) || CANCEL_MESSAGE.test(firstLine(error)) ? "cancelled" : "model-failed";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type Answer<T> = Checked<T> | { ok: false; reason: "cancelled" | "model-failed"; problems: string[] };
|
|
59
|
+
|
|
60
|
+
async function tryAnswer<T>(
|
|
61
|
+
llm: Pick<Llm, "extract">, call: SubAgentCall<T>, reply: string, problems: readonly string[],
|
|
62
|
+
check: (value: unknown) => Checked<T>,
|
|
63
|
+
): Promise<Answer<T>> {
|
|
64
|
+
let value: unknown;
|
|
65
|
+
try {
|
|
66
|
+
value = await llm.extract(call.answerPrompt(reply, problems), call.schema);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
const reason = failureOf(error);
|
|
69
|
+
if (reason === "cancelled" || readBudgetExhausted(error) !== null) return { ok: false, reason, problems: [firstLine(error)] };
|
|
70
|
+
return { ok: false, problems: [answerDidNotParse(errorText(error))] };
|
|
71
|
+
}
|
|
72
|
+
return check(value);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The profile the act of `call` is moved to: none without a route, when it answers null, or when it throws. */
|
|
76
|
+
async function routedProfile(route: ActRoute | undefined, crew: string, brief: string): Promise<string | null> {
|
|
77
|
+
if (route === undefined) return null;
|
|
78
|
+
try {
|
|
79
|
+
return await route({ crew, brief });
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function runSubAgent<T>(
|
|
86
|
+
llm: Pick<Llm, "act" | "extract">, call: SubAgentCall<T>, route?: ActRoute, log?: Pick<Logger, "info">,
|
|
87
|
+
): Promise<SubAgentOutcome<T>> {
|
|
88
|
+
const { charter, brief } = call;
|
|
89
|
+
const invalid = charterProblems(charter);
|
|
90
|
+
if (invalid.length > 0) return { ok: false, reason: "invalid-charter", problems: invalid, reply: "" };
|
|
91
|
+
if (brief.length > MAX_BRIEF_CHARS) {
|
|
92
|
+
return {
|
|
93
|
+
ok: false, reason: "brief-too-long", reply: "",
|
|
94
|
+
problems: [briefTooLong(brief.length, MAX_BRIEF_CHARS)],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const profile = await routedProfile(route, charter.name, brief);
|
|
98
|
+
let reply: string;
|
|
99
|
+
try {
|
|
100
|
+
reply = await llm.act(brief, {
|
|
101
|
+
system: call.system,
|
|
102
|
+
permissionMode: charter.mode,
|
|
103
|
+
maxIterations: charter.maxIterations,
|
|
104
|
+
...(charter.model === undefined ? {} : { model: charter.model }),
|
|
105
|
+
...(profile === null ? {} : { profile }),
|
|
106
|
+
...(call.tools === undefined ? {} : { tools: [...call.tools] }),
|
|
107
|
+
});
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return { ok: false, reason: failureOf(error), problems: [firstLine(error)], reply: "" };
|
|
110
|
+
}
|
|
111
|
+
const first = await tryAnswer(llm, call, reply, [], call.check);
|
|
112
|
+
if (first.ok) return { ok: true, value: first.value, reply, tries: 1 };
|
|
113
|
+
if ("reason" in first) return { ok: false, reason: first.reason, problems: first.problems, reply };
|
|
114
|
+
log?.info(answerAskedAgain(charter.name, first.problems));
|
|
115
|
+
const second = await tryAnswer(llm, call, reply, first.problems, call.lastCheck ?? call.check);
|
|
116
|
+
if (second.ok) return { ok: true, value: second.value, reply, tries: 2 };
|
|
117
|
+
if ("reason" in second) return { ok: false, reason: second.reason, problems: second.problems, reply };
|
|
118
|
+
return { ok: false, reason: "unparsable", problems: second.problems, reply };
|
|
119
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The language the session answers in (`answer.language`), read through the config port. Shared by the main
|
|
2
|
+
// loop's prompt and the crews a command hands it to (/analyze), so neither depends on the other.
|
|
3
|
+
import type { ConfigStore } from "./config-store.ts";
|
|
4
|
+
import { ANSWER_LANGUAGE_CONFIG_KEY } from "../domain/agent-policy/output-styles.ts";
|
|
5
|
+
|
|
6
|
+
/** The `answer.language` setting; "" when unset, unreadable or without a store. */
|
|
7
|
+
export async function readLanguage(config: Pick<ConfigStore, "readValue"> | undefined): Promise<string> {
|
|
8
|
+
if (config === undefined) return "";
|
|
9
|
+
try {
|
|
10
|
+
return String((await config.readValue(ANSWER_LANGUAGE_CONFIG_KEY)).value ?? "").trim();
|
|
11
|
+
} catch {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The /skills registry as the turn prompt and the compaction read it: the paths
|
|
2
|
+
// attached in the session's state bag, each with its file's content.
|
|
3
|
+
|
|
4
|
+
import type { Files, SessionStore } from "./ports.ts";
|
|
5
|
+
import { SKILLS_STATE_KEY } from "../domain/session-keys.ts";
|
|
6
|
+
import { readJsonArray } from "./session-state.ts";
|
|
7
|
+
|
|
8
|
+
export interface AttachedSkill {
|
|
9
|
+
path: string;
|
|
10
|
+
content: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* B-13: the attached /skills, WITH their content, in attachment order.
|
|
15
|
+
*
|
|
16
|
+
* The path alone would tell the model a playbook exists without letting it read
|
|
17
|
+
* one — worse than silence. A skill whose file has gone, cannot be read or is blank
|
|
18
|
+
* is dropped: the registry is a session preference, not a guarantee about the
|
|
19
|
+
* filesystem, and neither a turn nor a compaction may fail over it.
|
|
20
|
+
*/
|
|
21
|
+
export async function readAttachedSkills(
|
|
22
|
+
session: Pick<SessionStore, "readState">,
|
|
23
|
+
files: Pick<Files, "read">,
|
|
24
|
+
): Promise<AttachedSkill[]> {
|
|
25
|
+
const paths = (await readJsonArray(session, SKILLS_STATE_KEY))
|
|
26
|
+
.map((p) => String(p ?? ""))
|
|
27
|
+
.filter((p) => p.length > 0);
|
|
28
|
+
const out: AttachedSkill[] = [];
|
|
29
|
+
for (const path of paths) {
|
|
30
|
+
try {
|
|
31
|
+
const content = await files.read(path);
|
|
32
|
+
if (content.trim().length > 0) out.push({ path, content });
|
|
33
|
+
} catch { /* detached-then-deleted → skip */ }
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|