orkeon-code 0.0.0-stage → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.orkeon-version +1 -0
- package/LICENSE.md +21 -0
- package/NOTICE.md +17 -0
- package/README.fr.md +169 -0
- package/README.md +162 -2
- package/config/appsettings.anthropic.example.json +77 -0
- package/config/appsettings.example.json +71 -0
- package/config/appsettings.jev.example.json +128 -0
- package/config/appsettings.kev.example.json +130 -0
- package/config/appsettings.liquid.example.json +129 -0
- package/config/appsettings.ollama-whisper.example.json +92 -0
- package/config/appsettings.ollama.example.json +70 -0
- package/config/appsettings.whisper.example.json +31 -0
- package/mcp/whisper/README.md +293 -0
- package/mcp/whisper/pyproject.toml +32 -0
- package/mcp/whisper/uv.lock +1641 -0
- package/mcp/whisper/whisper_mcp.py +1053 -0
- package/orkeon-code +897 -0
- package/orkeon-code.mjs +71 -0
- package/orkeon-code.ps1 +837 -0
- package/package.json +57 -4
- package/scripts/install.ps1 +156 -0
- package/scripts/install.sh +148 -0
- package/scripts/session-start.ork.ts +90 -0
- package/scripts/session-start.sh +74 -0
- package/scripts/setup-fixture.sh +88 -0
- package/src/commands/.orkeon/orkeon-cli.d.ts +562 -0
- package/src/commands/_lib/args.ts +193 -0
- package/src/commands/_lib/dev/dev-batches.ts +368 -0
- package/src/commands/_lib/dev/dev-implement.ts +188 -0
- package/src/commands/_lib/dev/dev-source.ts +65 -0
- package/src/commands/_lib/dev/dev.ts +344 -0
- package/src/commands/_lib/dev-step.ts +142 -0
- package/src/commands/_lib/dispatch.ts +231 -0
- package/src/commands/_lib/effort.ts +15 -0
- package/src/commands/_lib/git/branch.ts +95 -0
- package/src/commands/_lib/git/commit.ts +94 -0
- package/src/commands/_lib/git/diff.ts +97 -0
- package/src/commands/_lib/git/review.ts +109 -0
- package/src/commands/_lib/memory/memory-admit.ts +150 -0
- package/src/commands/_lib/memory/memory.ts +51 -0
- package/src/commands/_lib/pr-context.ts +32 -0
- package/src/commands/_lib/project/analyze.ts +24 -0
- package/src/commands/_lib/session/export.ts +104 -0
- package/src/commands/_lib/session/resume.ts +160 -0
- package/src/commands/_lib/session/tasks.ts +184 -0
- package/src/commands/_lib/settings/advisor.ts +80 -0
- package/src/commands/_lib/settings/agents.ts +147 -0
- package/src/commands/_lib/settings/config.ts +141 -0
- package/src/commands/_lib/settings/hooks.ts +58 -0
- package/src/commands/_lib/settings/mode.ts +91 -0
- package/src/commands/_lib/settings/model.ts +146 -0
- package/src/commands/_lib/settings/permissions.ts +309 -0
- package/src/commands/_lib/settings/session-config.ts +49 -0
- package/src/commands/_lib/settings/skills.ts +51 -0
- package/src/commands/_lib/speech/say.ts +96 -0
- package/src/commands/_lib/speech/transcribe.ts +130 -0
- package/src/commands/_lib/speech/voice.ts +146 -0
- package/src/commands/_lib/status/cache.ts +31 -0
- package/src/commands/_lib/status/context.ts +57 -0
- package/src/commands/_lib/status/doctor.ts +186 -0
- package/src/commands/_lib/status/meta.ts +45 -0
- package/src/commands/_lib/status/status.ts +129 -0
- package/src/commands/_lib/status/usage-tools.ts +49 -0
- package/src/commands/_lib/status/usage.ts +139 -0
- package/src/commands/_lib/view.ts +29 -0
- package/src/commands/dev/dev-batches.cmd.ts +108 -0
- package/src/commands/dev/dev-learn.cmd.ts +29 -0
- package/src/commands/dev/dev-plan.cmd.ts +52 -0
- package/src/commands/dev/dev-spec.cmd.ts +55 -0
- package/src/commands/dev/dev-status.cmd.ts +16 -0
- package/src/commands/git/branch.cmd.ts +27 -0
- package/src/commands/git/commit.cmd.ts +48 -0
- package/src/commands/git/diff.cmd.ts +26 -0
- package/src/commands/git/review.cmd.ts +36 -0
- package/src/commands/memory/memory.cmd.ts +48 -0
- package/src/commands/project/analyze.cmd.ts +32 -0
- package/src/commands/project/debug-tool-call.cmd.ts +67 -0
- package/src/commands/project/files.cmd.ts +22 -0
- package/src/commands/project/init-verifiers.cmd.ts +14 -0
- package/src/commands/project/init.cmd.ts +14 -0
- package/src/commands/project/verify.cmd.ts +27 -0
- package/src/commands/session/assistant.cmd.ts +40 -0
- package/src/commands/session/btw.cmd.ts +18 -0
- package/src/commands/session/clear.cmd.ts +19 -0
- package/src/commands/session/compact.cmd.ts +16 -0
- package/src/commands/session/copy.cmd.ts +44 -0
- package/src/commands/session/exit.cmd.ts +9 -0
- package/src/commands/session/export.cmd.ts +28 -0
- package/src/commands/session/rename.cmd.ts +17 -0
- package/src/commands/session/resume.cmd.ts +19 -0
- package/src/commands/session/rewind.cmd.ts +26 -0
- package/src/commands/session/summary.cmd.ts +27 -0
- package/src/commands/session/tasks.cmd.ts +44 -0
- package/src/commands/settings/advisor.cmd.ts +38 -0
- package/src/commands/settings/agents.cmd.ts +19 -0
- package/src/commands/settings/config.cmd.ts +17 -0
- package/src/commands/settings/effort.cmd.ts +40 -0
- package/src/commands/settings/fast.cmd.ts +17 -0
- package/src/commands/settings/hooks.cmd.ts +17 -0
- package/src/commands/settings/mode.cmd.ts +20 -0
- package/src/commands/settings/model.cmd.ts +20 -0
- package/src/commands/settings/output-style.cmd.ts +48 -0
- package/src/commands/settings/permissions.cmd.ts +25 -0
- package/src/commands/settings/proactive.cmd.ts +15 -0
- package/src/commands/settings/skills.cmd.ts +17 -0
- package/src/commands/speech/say.cmd.ts +24 -0
- package/src/commands/speech/transcribe.cmd.ts +29 -0
- package/src/commands/speech/voice.cmd.ts +30 -0
- package/src/commands/status/context.cmd.ts +18 -0
- package/src/commands/status/doctor.cmd.ts +27 -0
- package/src/commands/status/release-notes.cmd.ts +9 -0
- package/src/commands/status/status.cmd.ts +25 -0
- package/src/commands/status/usage.cmd.ts +21 -0
- package/src/crews/.orkeon/orkeon.d.ts +3946 -0
- package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +183 -0
- package/src/crews/_probe-shared-memory/probe.ork.ts +98 -0
- package/src/crews/advisor/application/run-advisor.ts +40 -0
- package/src/crews/advisor/crew.ork.ts +43 -0
- package/src/crews/advisor/domain/advice.ts +135 -0
- package/src/crews/agent-run/application/run-agent-run.ts +42 -0
- package/src/crews/agent-run/crew.ork.ts +67 -0
- package/src/crews/analyze/application/run-analyze.ts +118 -0
- package/src/crews/analyze/crew.ork.ts +40 -0
- package/src/crews/analyze/domain/harvest.ts +301 -0
- package/src/crews/code-review/application/prompts.ts +133 -0
- package/src/crews/code-review/application/review.ts +71 -0
- package/src/crews/code-review/application/run-code-review.ts +123 -0
- package/src/crews/code-review/crew.ork.ts +51 -0
- package/src/crews/code-review/domain/lenses.ts +193 -0
- package/src/crews/code-review/domain/report.ts +59 -0
- package/src/crews/code-review/domain/scope.ts +112 -0
- package/src/crews/dev-batches/application/plan-close.ts +181 -0
- package/src/crews/dev-batches/application/run-dev-batches.ts +669 -0
- package/src/crews/dev-batches/application/run-wave.ts +450 -0
- package/src/crews/dev-batches/application/seed-harvest.ts +162 -0
- package/src/crews/dev-batches/crew.ork.ts +143 -0
- package/src/crews/dev-batches/domain/batch-waves.ts +70 -0
- package/src/crews/dev-batches/domain/batches-budget.ts +52 -0
- package/src/crews/dev-batches/domain/batches-log.ts +54 -0
- package/src/crews/dev-batches/domain/wave-order.ts +43 -0
- package/src/crews/dev-change/application/change-prompt.ts +104 -0
- package/src/crews/dev-change/application/evidence.ts +169 -0
- package/src/crews/dev-change/application/run-dev-change.ts +315 -0
- package/src/crews/dev-change/crew.ork.ts +112 -0
- package/src/crews/dev-change/domain/change-answer.ts +159 -0
- package/src/crews/dev-change/domain/change-render.ts +79 -0
- package/src/crews/dev-implement/application/close.ts +183 -0
- package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
- package/src/crews/dev-implement/application/locate-sheet.ts +80 -0
- package/src/crews/dev-implement/application/observe.ts +50 -0
- package/src/crews/dev-implement/application/report-writes.ts +41 -0
- package/src/crews/dev-implement/application/run-dev-implement.ts +811 -0
- package/src/crews/dev-implement/application/run-role.ts +27 -0
- package/src/crews/dev-implement/application/suite-job.ts +118 -0
- package/src/crews/dev-implement/application/touched.ts +74 -0
- package/src/crews/dev-implement/crew.ork.ts +68 -0
- package/src/crews/dev-implement/domain/contracts.ts +256 -0
- package/src/crews/dev-implement/domain/correction.ts +102 -0
- package/src/crews/dev-implement/domain/cycles.ts +35 -0
- package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
- package/src/crews/dev-implement/domain/roles.ts +53 -0
- package/src/crews/dev-implement/domain/sheet-edits.ts +75 -0
- package/src/crews/dev-implement/domain/sheet-ticks.ts +22 -0
- package/src/crews/dev-implement/domain/step-checks.ts +136 -0
- package/src/crews/dev-implement/domain/step-section.ts +127 -0
- package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
- package/src/crews/dev-learn/application/learn-prompt.ts +140 -0
- package/src/crews/dev-learn/application/run-dev-learn.ts +553 -0
- package/src/crews/dev-learn/crew.ork.ts +52 -0
- package/src/crews/dev-learn/domain/learn-answer.ts +235 -0
- package/src/crews/dev-learn/domain/owner-lines.ts +86 -0
- package/src/crews/dev-learn/domain/proposals-render.ts +96 -0
- package/src/crews/dev-plan/application/anchor-paths.ts +76 -0
- package/src/crews/dev-plan/application/inventory.ts +170 -0
- package/src/crews/dev-plan/application/plan-prompt.ts +159 -0
- package/src/crews/dev-plan/application/run-dev-plan.ts +455 -0
- package/src/crews/dev-plan/crew.ork.ts +109 -0
- package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
- package/src/crews/dev-plan/domain/plan-answer.ts +738 -0
- package/src/crews/dev-plan/domain/plan-render.ts +307 -0
- package/src/crews/dev-spec/application/run-dev-spec.ts +206 -0
- package/src/crews/dev-spec/application/spec-prompt.ts +98 -0
- package/src/crews/dev-spec/crew.ork.ts +108 -0
- package/src/crews/dev-spec/domain/spec-answer.ts +253 -0
- package/src/crews/dev-spec/domain/spec-render.ts +76 -0
- package/src/crews/dev-verify/application/audit.ts +259 -0
- package/src/crews/dev-verify/application/auditor-prompt.ts +323 -0
- package/src/crews/dev-verify/application/capture.ts +303 -0
- package/src/crews/dev-verify/application/run-dev-verify.ts +409 -0
- package/src/crews/dev-verify/application/run-gate.ts +202 -0
- package/src/crews/dev-verify/crew.ork.ts +103 -0
- package/src/crews/dev-verify/domain/audit-answer.ts +150 -0
- package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
- package/src/crews/dev-verify/domain/capture-sections.ts +137 -0
- package/src/crews/dev-verify/domain/commands.ts +103 -0
- package/src/crews/dev-verify/domain/gate.ts +126 -0
- package/src/crews/dev-verify/domain/mechanical-table.ts +163 -0
- package/src/crews/dev-verify/domain/runtime-cut.ts +13 -0
- package/src/crews/dev-verify/domain/sheet-facts.ts +4 -0
- package/src/crews/dev-verify/domain/text.ts +20 -0
- package/src/crews/dev-verify/domain/verdict.ts +127 -0
- package/src/crews/git-commit/application/draft.ts +154 -0
- package/src/crews/git-commit/application/run-git-commit.ts +116 -0
- package/src/crews/git-commit/crew.ork.ts +52 -0
- package/src/crews/git-commit/domain/commit.ts +220 -0
- package/src/crews/init-verifiers/application/authoring.ts +89 -0
- package/src/crews/init-verifiers/application/prompts.ts +103 -0
- package/src/crews/init-verifiers/application/run-init-verifiers.ts +25 -0
- package/src/crews/init-verifiers/crew.ork.ts +34 -0
- package/src/crews/init-verifiers/domain/commands-section.ts +36 -0
- package/src/crews/init-verifiers/domain/readiness.ts +23 -0
- package/src/crews/main-loop/application/auto-compact.ts +77 -0
- package/src/crews/main-loop/application/context-gather.ts +133 -0
- package/src/crews/main-loop/application/run-main-loop.ts +350 -0
- package/src/crews/main-loop/application/turn-prompt.ts +112 -0
- package/src/crews/main-loop/crew.ork.ts +119 -0
- package/src/crews/main-loop/domain/autocompact.ts +27 -0
- package/src/crews/main-loop/domain/prompt-assembly.ts +521 -0
- package/src/crews/main-loop/domain/turn-chains.ts +129 -0
- package/src/crews/project-init/application/detect.ts +122 -0
- package/src/crews/project-init/application/prompts.ts +101 -0
- package/src/crews/project-init/application/run-project-init.ts +31 -0
- package/src/crews/project-init/crew.ork.ts +35 -0
- package/src/crews/project-init/domain/conventions.ts +36 -0
- package/src/crews/project-init/domain/existing-files.ts +63 -0
- package/src/crews/project-init/domain/package-map.ts +73 -0
- package/src/crews/session-compact/crew.ork.ts +55 -0
- package/src/crews/shared-memory-admit/crew.ork.ts +48 -0
- package/src/crews/speech/application/run-speech.ts +25 -0
- package/src/crews/speech/crew.ork.ts +37 -0
- package/src/shared/application/agents/child-agent.ts +255 -0
- package/src/shared/application/agents/run-sub-agent.ts +96 -0
- package/src/shared/application/answer-language.ts +14 -0
- package/src/shared/application/attached-skills.ts +36 -0
- package/src/shared/application/compaction/compact-session.ts +237 -0
- package/src/shared/application/compaction/extract-memories.ts +38 -0
- package/src/shared/application/compaction/restore-context.ts +78 -0
- package/src/shared/application/config-store.ts +123 -0
- package/src/shared/application/dev/brief-inventory.ts +113 -0
- package/src/shared/application/dev/close-batch.ts +83 -0
- package/src/shared/application/dev/find-repo-pack.ts +77 -0
- package/src/shared/application/dev/learn-decision.ts +252 -0
- package/src/shared/application/dev/load-dev-context.ts +266 -0
- package/src/shared/application/dev/measure-access-cost.ts +68 -0
- package/src/shared/application/dev/plan-source.ts +112 -0
- package/src/shared/application/dev/preflight.ts +71 -0
- package/src/shared/application/dev/project-files.ts +17 -0
- package/src/shared/application/dev/question-round.ts +52 -0
- package/src/shared/application/dev/resolve-work-folder.ts +133 -0
- package/src/shared/application/dev/script-tool-slot.ts +27 -0
- package/src/shared/application/dev/settle-questions.ts +55 -0
- package/src/shared/application/dev/source-review.ts +63 -0
- package/src/shared/application/dev/source-step.ts +150 -0
- package/src/shared/application/dev/spend.ts +42 -0
- package/src/shared/application/dev/step-precedents.ts +89 -0
- package/src/shared/application/dev/tool-call-policy.ts +89 -0
- package/src/shared/application/dev/tool-callbacks.ts +215 -0
- package/src/shared/application/dev/tool-trace-recorder.ts +45 -0
- package/src/shared/application/dev/verdict-sources.ts +48 -0
- package/src/shared/application/dev/wrapped-tools.ts +145 -0
- package/src/shared/application/extra-tools.ts +70 -0
- package/src/shared/application/git/batch-worktree.ts +97 -0
- package/src/shared/application/git/commit-files.ts +186 -0
- package/src/shared/application/git/merge-batch.ts +63 -0
- package/src/shared/application/git/open-pull-request.ts +51 -0
- package/src/shared/application/instructions-file.ts +19 -0
- package/src/shared/application/json-file.ts +34 -0
- package/src/shared/application/llm-profile.ts +35 -0
- package/src/shared/application/permission-rules.ts +159 -0
- package/src/shared/application/ports/approvals.ts +20 -0
- package/src/shared/application/ports/clock.ts +5 -0
- package/src/shared/application/ports/code-index.ts +93 -0
- package/src/shared/application/ports/crew.ts +60 -0
- package/src/shared/application/ports/files.ts +21 -0
- package/src/shared/application/ports/human.ts +13 -0
- package/src/shared/application/ports/llm.ts +54 -0
- package/src/shared/application/ports/memory.ts +30 -0
- package/src/shared/application/ports/progress.ts +23 -0
- package/src/shared/application/ports/runtime.ts +15 -0
- package/src/shared/application/ports/session.ts +74 -0
- package/src/shared/application/ports/shared-memory.ts +26 -0
- package/src/shared/application/ports/shell.ts +40 -0
- package/src/shared/application/ports/telemetry.ts +45 -0
- package/src/shared/application/ports/tools.ts +46 -0
- package/src/shared/application/ports/usage.ts +45 -0
- package/src/shared/application/ports.ts +27 -0
- package/src/shared/application/project-manifests.ts +106 -0
- package/src/shared/application/session-io.ts +84 -0
- package/src/shared/application/session-state.ts +36 -0
- package/src/shared/application/shared-memory/admit-entries.ts +177 -0
- package/src/shared/application/shared-memory/harvest-after-gaps.ts +72 -0
- package/src/shared/application/shared-memory/harvest-mistakes.ts +44 -0
- package/src/shared/application/shared-memory/import-agent-memory.ts +117 -0
- package/src/shared/application/shared-memory/memory-files.ts +110 -0
- package/src/shared/application/shared-memory/memory-settings.ts +93 -0
- package/src/shared/application/shared-memory/push-candidate.ts +146 -0
- package/src/shared/application/shared-memory/recall-precedents.ts +69 -0
- package/src/shared/application/state-snapshot.ts +38 -0
- package/src/shared/application/workflow/workflow-state.ts +135 -0
- package/src/shared/domain/agent-policy/behavior-flags.ts +168 -0
- package/src/shared/domain/agent-policy/extra-tools.ts +69 -0
- package/src/shared/domain/agent-policy/memory-categories.ts +6 -0
- package/src/shared/domain/agent-policy/mode-policy.ts +51 -0
- package/src/shared/domain/agent-policy/output-styles.ts +11 -0
- package/src/shared/domain/agent-policy/permission.ts +623 -0
- package/src/shared/domain/agent-policy/rule-sets.ts +412 -0
- package/src/shared/domain/agent-policy/tool-access.ts +77 -0
- package/src/shared/domain/agent-registry.ts +142 -0
- package/src/shared/domain/agents/built-in-charters.ts +43 -0
- package/src/shared/domain/agents/chain.ts +30 -0
- package/src/shared/domain/agents/charter.ts +61 -0
- package/src/shared/domain/agents/exclusive.ts +24 -0
- package/src/shared/domain/agents/instances.ts +249 -0
- package/src/shared/domain/code-intel-contract.ts +356 -0
- package/src/shared/domain/code-intel-routing.ts +113 -0
- package/src/shared/domain/compact-outcome.ts +44 -0
- package/src/shared/domain/compaction-thresholds.ts +161 -0
- package/src/shared/domain/compaction.ts +379 -0
- package/src/shared/domain/config-schema.ts +421 -0
- package/src/shared/domain/dev/access-cost.ts +226 -0
- package/src/shared/domain/dev/artefacts.ts +50 -0
- package/src/shared/domain/dev/batches-concurrency.ts +36 -0
- package/src/shared/domain/dev/batches-state.ts +49 -0
- package/src/shared/domain/dev/build-commands.ts +44 -0
- package/src/shared/domain/dev/call-guard.ts +341 -0
- package/src/shared/domain/dev/carried-text.ts +49 -0
- package/src/shared/domain/dev/design-rules.ts +100 -0
- package/src/shared/domain/dev/learn-proposals.ts +175 -0
- package/src/shared/domain/dev/learn-state.ts +93 -0
- package/src/shared/domain/dev/path-args.ts +42 -0
- package/src/shared/domain/dev/path-rebase.ts +93 -0
- package/src/shared/domain/dev/plan-checks.ts +190 -0
- package/src/shared/domain/dev/plan-format.ts +180 -0
- package/src/shared/domain/dev/project-files.ts +43 -0
- package/src/shared/domain/dev/questions.ts +249 -0
- package/src/shared/domain/dev/reading-rule.ts +41 -0
- package/src/shared/domain/dev/repo-pack.ts +237 -0
- package/src/shared/domain/dev/review-answer.ts +150 -0
- package/src/shared/domain/dev/review-prompt.ts +221 -0
- package/src/shared/domain/dev/reviewer-charter.ts +31 -0
- package/src/shared/domain/dev/sheet-facts.ts +83 -0
- package/src/shared/domain/dev/spec-format.ts +183 -0
- package/src/shared/domain/dev/step-budget.ts +72 -0
- package/src/shared/domain/dev/step-rules.ts +110 -0
- package/src/shared/domain/dev/test-commands.ts +90 -0
- package/src/shared/domain/dev/test-output.ts +33 -0
- package/src/shared/domain/dev/test-paths.ts +40 -0
- package/src/shared/domain/dev/tool-guards.ts +64 -0
- package/src/shared/domain/dev/trait-pattern.ts +83 -0
- package/src/shared/domain/dev/verdict-format.ts +169 -0
- package/src/shared/domain/dev/whitespace.ts +34 -0
- package/src/shared/domain/dev/work-folder.ts +67 -0
- package/src/shared/domain/dev/yaml-subset.ts +403 -0
- package/src/shared/domain/git/close.ts +273 -0
- package/src/shared/domain/git/pull-request.ts +96 -0
- package/src/shared/domain/git/worktree.ts +46 -0
- package/src/shared/domain/index-languages.ts +16 -0
- package/src/shared/domain/instructions-file.ts +18 -0
- package/src/shared/domain/iso-day.ts +4 -0
- package/src/shared/domain/llm-failure.ts +106 -0
- package/src/shared/domain/llm-profile.ts +25 -0
- package/src/shared/domain/marked-message.ts +33 -0
- package/src/shared/domain/model-catalog.ts +86 -0
- package/src/shared/domain/permission-modes.ts +103 -0
- package/src/shared/domain/prelude.ts +92 -0
- package/src/shared/domain/project-manifests.ts +83 -0
- package/src/shared/domain/search-routing.ts +85 -0
- package/src/shared/domain/secret-patterns.ts +45 -0
- package/src/shared/domain/session-keys.ts +85 -0
- package/src/shared/domain/session-start.ts +60 -0
- package/src/shared/domain/session-summary.ts +13 -0
- package/src/shared/domain/severity.ts +72 -0
- package/src/shared/domain/sha1.ts +61 -0
- package/src/shared/domain/shared-memory/agent-memory-import.ts +143 -0
- package/src/shared/domain/shared-memory/candidates.ts +41 -0
- package/src/shared/domain/shared-memory/entry.ts +145 -0
- package/src/shared/domain/shared-memory/front-matter.ts +183 -0
- package/src/shared/domain/shared-memory/gate.ts +44 -0
- package/src/shared/domain/shared-memory/harvest.ts +61 -0
- package/src/shared/domain/shared-memory/layout.ts +187 -0
- package/src/shared/domain/shared-memory/precedents-block.ts +93 -0
- package/src/shared/domain/shared-memory/refused.ts +84 -0
- package/src/shared/domain/shared-memory/verdict-rows.ts +134 -0
- package/src/shared/domain/snip-turns.ts +45 -0
- package/src/shared/domain/speech.ts +20 -0
- package/src/shared/domain/strip.ts +88 -0
- package/src/shared/domain/tool-trace.ts +122 -0
- package/src/shared/domain/types.ts +67 -0
- package/src/shared/domain/verifiers.ts +37 -0
- package/src/shared/domain/vfs.ts +9 -0
- package/src/shared/domain/workflow/state-file.ts +140 -0
- package/src/shared/infrastructure/globals.ts +52 -0
- package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
- package/src/shared/infrastructure/orkeon/child-agents.ts +127 -0
- package/src/shared/infrastructure/orkeon/code-index.ts +120 -0
- package/src/shared/infrastructure/orkeon/crew-host.ts +27 -0
- package/src/shared/infrastructure/orkeon/crew-memory.ts +12 -0
- package/src/shared/infrastructure/orkeon/dev-deps.ts +172 -0
- package/src/shared/infrastructure/orkeon/files.ts +40 -0
- package/src/shared/infrastructure/orkeon/github-pull-requests.ts +29 -0
- package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
- package/src/shared/infrastructure/orkeon/human-input.ts +59 -0
- package/src/shared/infrastructure/orkeon/llm-profile.ts +38 -0
- package/src/shared/infrastructure/orkeon/llm.ts +109 -0
- package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
- package/src/shared/infrastructure/orkeon/memory-tools.ts +131 -0
- package/src/shared/infrastructure/orkeon/permission-rules.ts +42 -0
- package/src/shared/infrastructure/orkeon/progress.ts +24 -0
- package/src/shared/infrastructure/orkeon/run-state.ts +17 -0
- package/src/shared/infrastructure/orkeon/runtime-info.ts +30 -0
- package/src/shared/infrastructure/orkeon/runtime-tools.ts +60 -0
- package/src/shared/infrastructure/orkeon/script-tools.ts +134 -0
- package/src/shared/infrastructure/orkeon/session-store.ts +138 -0
- package/src/shared/infrastructure/orkeon/session-switch.ts +23 -0
- package/src/shared/infrastructure/orkeon/shared-memory.ts +61 -0
- package/src/shared/infrastructure/orkeon/shell-jobs.ts +75 -0
- package/src/shared/infrastructure/orkeon/shell.ts +31 -0
- package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
- package/src/shared/infrastructure/orkeon/tool-catalogue.ts +75 -0
- package/src/shared/infrastructure/orkeon/tool-results.ts +120 -0
- package/src/shared/infrastructure/orkeon/usage.ts +74 -0
- package/src/shared/infrastructure/orkeon/wiring.ts +118 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The charters Orkeon Code runs as children of its dev steps (A-3), by name: which step runs each one
|
|
2
|
+
// and whose rule sets apply to it. The charters themselves live beside their step (the reviewer in
|
|
3
|
+
// shared/domain/dev/, the auditor in crews/dev-verify/domain/); /agents lists these rows and the
|
|
4
|
+
// agent-run crew repairs an instance of one by a new run. Pure.
|
|
5
|
+
import { stepCommand } from "../dev/step-rules.ts";
|
|
6
|
+
|
|
7
|
+
export interface BuiltInCharter {
|
|
8
|
+
name: string;
|
|
9
|
+
/** The dev step that runs it as a child, and whose rule sets apply to a repair its run does not name. */
|
|
10
|
+
step: "dev-plan" | "dev-verify";
|
|
11
|
+
/** Every step that runs it as a child. */
|
|
12
|
+
steps: readonly string[];
|
|
13
|
+
role: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const BUILT_IN_CHARTERS: readonly BuiltInCharter[] = [
|
|
17
|
+
{ name: "dev-reviewer", step: "dev-plan", steps: ["dev-spec", "dev-change", "dev-plan"], role: "Adversarial reviewer" },
|
|
18
|
+
{ name: "dev-auditor", step: "dev-verify", steps: ["dev-verify"], role: "Batch auditor" },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
export function builtInCharter(name: string): BuiltInCharter | undefined {
|
|
22
|
+
return BUILT_IN_CHARTERS.find((c) => c.name === name);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The steps a repair can run under: those that run a charter as a child. */
|
|
26
|
+
export type RepairStep = "dev-plan" | "dev-verify" | "dev-spec" | "dev-change";
|
|
27
|
+
const REPAIR_STEPS: readonly string[] = ["dev-plan", "dev-verify", "dev-spec", "dev-change"];
|
|
28
|
+
|
|
29
|
+
/** The step a repair of `charter` runs under: the one the instance's run named (a reviewer of /dev-spec repairs under
|
|
30
|
+
* dev-spec's rule sets and budget), else the charter's own, else dev-plan's. */
|
|
31
|
+
export function repairStep(charter: string, runStep: unknown): RepairStep {
|
|
32
|
+
if (typeof runStep === "string" && REPAIR_STEPS.includes(runStep)) return runStep as RepairStep;
|
|
33
|
+
return builtInCharter(charter)?.step ?? "dev-plan";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The rows /agents lists for the built-in charters, after the crews. */
|
|
37
|
+
export function builtInCharterRows(): Array<{ name: string; kind: string; detail: string }> {
|
|
38
|
+
return BUILT_IN_CHARTERS.map((c) => ({
|
|
39
|
+
name: c.name,
|
|
40
|
+
kind: "charter (built-in)",
|
|
41
|
+
detail: `${c.role} — runs as a background child of ${[...new Set(c.steps.map((s) => `/${stepCommand(s)}`))].join(", ")}; /tasks lists, stops and repairs it`,
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// A chain of crews launched from `completed` handlers (`runCrewAsync` from a `completed`): the runtime
|
|
2
|
+
// counts each hop and refuses the one past `Orkeon:Cli:ScriptCommands:MaxChainDepth` (default 8, the
|
|
3
|
+
// first crew counted, V-A5) with a plain JS error, `chain depth <d> reached (MaxChainDepth <l>, /<command>)`,
|
|
4
|
+
// the command whose launch was refused last (`ChainDepthExceededException`, Orkeon #221). A driver reads the
|
|
5
|
+
// depth, the limit and the command off the refusal through chainDepthRefusal, rather than failing on an
|
|
6
|
+
// unexplained throw: the limit the host is configured with, never a default copied here. A driver that
|
|
7
|
+
// relaunches its own work passes `{ chain: "continue" }` to the launch (CrewLaunchOptions) and never meets
|
|
8
|
+
// the refusal. Pure.
|
|
9
|
+
|
|
10
|
+
const REFUSAL = /chain depth (\d+) reached \(MaxChainDepth (\d+)(?:, \/([^\s)]+))?\)/i;
|
|
11
|
+
|
|
12
|
+
/** What a chain refusal says: the depth reached, the limit, and the command refused when the message names it. */
|
|
13
|
+
export interface ChainDepthRefusal { depth: number; limit: number; command?: string }
|
|
14
|
+
|
|
15
|
+
/** The depth and limit of a chain refusal; null for any other failure. */
|
|
16
|
+
export function chainDepthRefusal(error: unknown): ChainDepthRefusal | null {
|
|
17
|
+
const message = error instanceof Error ? error.message : typeof error === "string" ? error : String(error ?? "");
|
|
18
|
+
const m = REFUSAL.exec(message);
|
|
19
|
+
if (m === null) return null;
|
|
20
|
+
return m[3] === undefined
|
|
21
|
+
? { depth: Number(m[1]), limit: Number(m[2]) }
|
|
22
|
+
: { depth: Number(m[1]), limit: Number(m[2]), command: m[3] };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The line a command shows for a refused hop. */
|
|
26
|
+
export function chainDepthLine(crew: string, refusal: ChainDepthRefusal): string {
|
|
27
|
+
const of = refusal.command === undefined ? "" : ` of /${refusal.command}`;
|
|
28
|
+
return `${crew} not launched: the chain of crews${of} reached its limit (depth ${refusal.depth}, limit ${refusal.limit}, ` +
|
|
29
|
+
"Orkeon:Cli:ScriptCommands:MaxChainDepth); type the next step yourself.";
|
|
30
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// A sub-agent's charter: who it is, the mode it acts in, the tools it may be
|
|
2
|
+
// offered and how many tool-call iterations it gets. Pure, no IO. For now a
|
|
3
|
+
// sub-agent acts read-only: its catalogue is the mode's own (no session rule
|
|
4
|
+
// applies yet), narrowed to the charter's list.
|
|
5
|
+
|
|
6
|
+
import type { PermissionMode } from "../permission-modes.ts";
|
|
7
|
+
import { catalogueFor } from "../agent-policy/permission.ts";
|
|
8
|
+
import { policyFor } from "../agent-policy/mode-policy.ts";
|
|
9
|
+
|
|
10
|
+
/** A check's outcome: the value, or what is wrong with it. */
|
|
11
|
+
export type Checked<T> = { ok: true; value: T } | { ok: false; problems: string[] };
|
|
12
|
+
|
|
13
|
+
/** What a sub-agent is: its identity, its mode, the tools it may be offered, its iteration cap. */
|
|
14
|
+
export interface Charter {
|
|
15
|
+
name: string;
|
|
16
|
+
role: string;
|
|
17
|
+
goal: string;
|
|
18
|
+
mode: PermissionMode;
|
|
19
|
+
tools: readonly string[];
|
|
20
|
+
disallowed: readonly string[];
|
|
21
|
+
maxIterations: number;
|
|
22
|
+
/** The model to answer with; the host's when absent. */
|
|
23
|
+
model?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const CHARTER_NAME: RegExp = /^[a-z][a-z0-9-]{1,39}$/;
|
|
27
|
+
export const MAX_CHARTER_ITERATIONS = 80;
|
|
28
|
+
/** The longest brief a sub-agent is handed, in characters (temp/03 § A "MAX_BRIEF_CHARS"). */
|
|
29
|
+
export const MAX_BRIEF_CHARS = 24_000;
|
|
30
|
+
|
|
31
|
+
function offeredIn(mode: string): string[] {
|
|
32
|
+
return catalogueFor(mode, []).tools;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** catalogueFor(mode, []).tools ∩ charter.tools − charter.disallowed, in the order of charter.tools. */
|
|
36
|
+
export function charterCatalogue(charter: Charter): string[] {
|
|
37
|
+
const offered = new Set(offeredIn(charter.mode));
|
|
38
|
+
const disallowed = new Set(charter.disallowed);
|
|
39
|
+
return charter.tools.filter((t) => offered.has(t) && !disallowed.has(t));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Empty when the charter can run. */
|
|
43
|
+
export function charterProblems(charter: Charter): string[] {
|
|
44
|
+
const { name, mode, maxIterations } = charter;
|
|
45
|
+
const problems: string[] = [];
|
|
46
|
+
if (!CHARTER_NAME.test(name)) problems.push(`charter name '${name}' is not a kebab-case name of 2 to 40 characters`);
|
|
47
|
+
if (!policyFor(mode).readOnly) {
|
|
48
|
+
problems.push(`charter ${name}: mode ${mode} can write; a sub-agent runs read-only (plan or dontAsk) for now`);
|
|
49
|
+
}
|
|
50
|
+
const offered = new Set(offeredIn(mode));
|
|
51
|
+
for (const tool of charter.tools) {
|
|
52
|
+
if (!offered.has(tool)) problems.push(`charter ${name}: ${tool} is not offered in mode ${mode}`);
|
|
53
|
+
}
|
|
54
|
+
if (charterCatalogue(charter).length === 0) {
|
|
55
|
+
problems.push(`charter ${name}: no tool left once the mode and the disallowed list apply`);
|
|
56
|
+
}
|
|
57
|
+
if (!(Number.isInteger(maxIterations) && maxIterations >= 1 && maxIterations <= MAX_CHARTER_ITERATIONS)) {
|
|
58
|
+
problems.push(`charter ${name}: maxIterations ${maxIterations} is not between 1 and 80`);
|
|
59
|
+
}
|
|
60
|
+
return problems;
|
|
61
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// An exclusive crew launch (`runCrewAsync(name, input, { exclusive: true })`, Orkeon #239): the runtime refuses
|
|
2
|
+
// a crew whose previous exclusive launch is not terminal, before any LLM call, with a plain JS error naming the
|
|
3
|
+
// running instance, `crew '<name>' already running (ticket <t>)`. The check and the registration are one step on
|
|
4
|
+
// the host, so two lines typed in the same tick cannot both pass; the crew is free again once that instance's work has
|
|
5
|
+
// ended: completed, failed, or stopped at its next cooperative checkpoint after a cancel (Orkeon #266), so a relaunch
|
|
6
|
+
// right after a cancel may still be refused. A command reads the crew and the ticket off the refusal through
|
|
7
|
+
// exclusiveRefusal and shows exclusiveLine, rather than failing on an unexplained throw. Pure.
|
|
8
|
+
|
|
9
|
+
const REFUSAL = /crew '([^']+)' already running \(ticket ([^\s)]+)\)/i;
|
|
10
|
+
|
|
11
|
+
/** What an exclusive refusal says: the crew that runs and the ticket of its instance. */
|
|
12
|
+
export interface ExclusiveRefusal { crew: string; ticket: string }
|
|
13
|
+
|
|
14
|
+
/** The crew and the ticket of an exclusive refusal; null for any other failure. */
|
|
15
|
+
export function exclusiveRefusal(error: unknown): ExclusiveRefusal | null {
|
|
16
|
+
const message = error instanceof Error ? error.message : typeof error === "string" ? error : String(error ?? "");
|
|
17
|
+
const m = REFUSAL.exec(message);
|
|
18
|
+
return m === null ? null : { crew: m[1], ticket: m[2] };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The line a command shows for a crew refused because it already runs. */
|
|
22
|
+
export function exclusiveLine(refusal: ExclusiveRefusal): string {
|
|
23
|
+
return `${refusal.crew} not launched: it is already running (ticket ${refusal.ticket}); wait for its result, then type the line again.`;
|
|
24
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// The agent instances of a crew run as /tasks sees them (A-3). The runtime keeps a crew's
|
|
2
|
+
// children (`crew.instances()`, `send`, `stop`) on the crew object of ONE run, which no command
|
|
3
|
+
// reaches: the crew writes a snapshot of its run in the session's state bag while its children
|
|
4
|
+
// run, and reads there the stop /tasks leaves for one instance. This module holds the two
|
|
5
|
+
// shapes, their reading, and what /tasks decides and shows from them. Pure, no IO.
|
|
6
|
+
|
|
7
|
+
import { AGENT_INSTANCES_STATE_PREFIX, AGENT_REQUEST_STATE_PREFIX } from "../session-keys.ts";
|
|
8
|
+
import { MAX_BRIEF_CHARS } from "./charter.ts";
|
|
9
|
+
|
|
10
|
+
export const INSTANCE_STATES = ["running", "completed", "failed", "stopped"] as const;
|
|
11
|
+
export type InstanceState = (typeof INSTANCE_STATES)[number];
|
|
12
|
+
|
|
13
|
+
/** The crews that run children and publish them: one snapshot key each. */
|
|
14
|
+
export const CHILD_CREWS = ["dev-spec", "dev-change", "dev-plan", "dev-verify"] as const;
|
|
15
|
+
|
|
16
|
+
// The runtime keeps a transcript of an ended instance for `crew.send` (`ScriptAgentInstanceOptions`, 40 messages
|
|
17
|
+
// and 32 000 characters by default). Orkeon Code sends nothing in place (sendVerdict): a repair is a new run whose
|
|
18
|
+
// brief carries the report (buildRepairBrief, within MAX_BRIEF_CHARS), so those limits bind nothing here.
|
|
19
|
+
|
|
20
|
+
/** The runtime's defaults for `crew.concurrency(n)` and `crew.maxInstances(n)`, and the bounds a crew input is held to. */
|
|
21
|
+
export const INSTANCE_LIMITS = {
|
|
22
|
+
concurrency: { fallback: 4, max: 16 },
|
|
23
|
+
maxInstances: { fallback: 32, max: 64 },
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
/** One child of the run. `system` and `brief` are what it was asked, kept for a repair by a new run. */
|
|
27
|
+
export interface InstanceRecord {
|
|
28
|
+
/** The runtime's id (`a1`…); empty until the child has said it. */
|
|
29
|
+
id: string;
|
|
30
|
+
agent: string;
|
|
31
|
+
/** The built-in charter the child runs (built-in-charters.ts). */
|
|
32
|
+
charter: string;
|
|
33
|
+
task: string;
|
|
34
|
+
state: InstanceState;
|
|
35
|
+
startedAt: string;
|
|
36
|
+
endedAt?: string;
|
|
37
|
+
effort?: string;
|
|
38
|
+
system: string;
|
|
39
|
+
brief: string;
|
|
40
|
+
reply?: string;
|
|
41
|
+
error?: string;
|
|
42
|
+
stopRequested?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* One run of a crew: `serving` while its body answers requests, `open` until the body ends. A run
|
|
47
|
+
* that answers writes it again at least every SNAPSHOT_HEARTBEAT_MS, so a snapshot older than
|
|
48
|
+
* SNAPSHOT_STALE_MS is a run that died (settleSnapshot).
|
|
49
|
+
*/
|
|
50
|
+
export interface RunSnapshot {
|
|
51
|
+
crew: string;
|
|
52
|
+
/** The dev step whose rule sets apply to the children (and to a repair). */
|
|
53
|
+
step: string;
|
|
54
|
+
startedAt: string;
|
|
55
|
+
updatedAt: string;
|
|
56
|
+
serving: boolean;
|
|
57
|
+
open: boolean;
|
|
58
|
+
instances: InstanceRecord[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** How often a run that answers writes its snapshot, changed or not. */
|
|
62
|
+
export const SNAPSHOT_HEARTBEAT_MS = 5_000;
|
|
63
|
+
/** How old the snapshot of a run that says it answers may be before /tasks takes the run for dead. */
|
|
64
|
+
export const SNAPSHOT_STALE_MS = 30_000;
|
|
65
|
+
|
|
66
|
+
/** What /tasks asks of one instance: stop it. `run` is the run's `startedAt`, so a request never reaches the next run's `a1`. */
|
|
67
|
+
export interface InstanceRequest { action: "stop"; run: string; at: string }
|
|
68
|
+
|
|
69
|
+
export const snapshotKey = (crew: string): string => `${AGENT_INSTANCES_STATE_PREFIX}${crew}`;
|
|
70
|
+
export const requestKey = (crew: string, id: string): string => `${AGENT_REQUEST_STATE_PREFIX}${crew}:${id}`;
|
|
71
|
+
|
|
72
|
+
const text = (v: unknown): string => (typeof v === "string" ? v : "");
|
|
73
|
+
const optional = (v: unknown): string | undefined => (typeof v === "string" && v !== "" ? v : undefined);
|
|
74
|
+
|
|
75
|
+
function parseRecord(raw: unknown): InstanceRecord | null {
|
|
76
|
+
const r = raw as Record<string, unknown> | null;
|
|
77
|
+
if (r === null || typeof r !== "object" || typeof r.agent !== "string") return null;
|
|
78
|
+
const state = (INSTANCE_STATES as readonly string[]).includes(String(r.state)) ? (r.state as InstanceState) : "failed";
|
|
79
|
+
return {
|
|
80
|
+
id: text(r.id), agent: r.agent, charter: text(r.charter) || r.agent, task: text(r.task), state,
|
|
81
|
+
startedAt: text(r.startedAt), endedAt: optional(r.endedAt), effort: optional(r.effort),
|
|
82
|
+
system: text(r.system), brief: text(r.brief), reply: optional(r.reply), error: optional(r.error),
|
|
83
|
+
stopRequested: r.stopRequested === true ? true : undefined,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A stored snapshot; null when there is none or it cannot be read. */
|
|
88
|
+
export function parseSnapshot(raw: string | null): RunSnapshot | null {
|
|
89
|
+
if (!raw) return null;
|
|
90
|
+
let v: Record<string, unknown>;
|
|
91
|
+
try {
|
|
92
|
+
v = JSON.parse(raw);
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
if (v === null || typeof v !== "object" || typeof v.crew !== "string" || !Array.isArray(v.instances)) return null;
|
|
97
|
+
return {
|
|
98
|
+
crew: v.crew, step: text(v.step) || v.crew, startedAt: text(v.startedAt), updatedAt: text(v.updatedAt),
|
|
99
|
+
serving: v.serving === true, open: v.open === true,
|
|
100
|
+
instances: v.instances.map(parseRecord).filter((r): r is InstanceRecord => r !== null),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A stored request; null when there is none (an empty value is a cleared one) or it cannot be read. */
|
|
105
|
+
export function parseRequest(raw: string | null): InstanceRequest | null {
|
|
106
|
+
if (!raw) return null;
|
|
107
|
+
try {
|
|
108
|
+
const v = JSON.parse(raw);
|
|
109
|
+
if (v?.action === "stop") return { action: "stop", run: text(v.run), at: text(v.at) };
|
|
110
|
+
} catch {
|
|
111
|
+
// unreadable: no request
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The snapshot as /tasks may trust it at `now`: a run that says it is open but has not written for
|
|
118
|
+
* SNAPSHOT_STALE_MS died (the host was stopped mid-run): it no longer answers, and its running
|
|
119
|
+
* children are failed, which a repair can take up.
|
|
120
|
+
*/
|
|
121
|
+
export function settleSnapshot(s: RunSnapshot, now: Date): RunSnapshot {
|
|
122
|
+
const age = now.getTime() - Date.parse(s.updatedAt);
|
|
123
|
+
// An updatedAt that does not parse dates nothing: the run cannot be shown to answer, so it is taken for dead.
|
|
124
|
+
if (!s.open || (Number.isFinite(age) && age <= SNAPSHOT_STALE_MS)) return s;
|
|
125
|
+
return {
|
|
126
|
+
...s, serving: false, open: false,
|
|
127
|
+
instances: s.instances.map((r) => r.state !== "running" ? r : { ...r, state: "failed", error: "its run stopped answering" }),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** A crew input as an integer within 1..max, else the runtime's default. */
|
|
132
|
+
function limit(raw: unknown, bounds: { fallback: number; max: number }): number {
|
|
133
|
+
const n = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
|
|
134
|
+
return Number.isInteger(n) && n >= 1 && n <= bounds.max ? n : bounds.fallback;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The `concurrency` and `maxInstances` a crew is built with, from its inputs. */
|
|
138
|
+
export function instanceLimits(raw: { concurrency?: unknown; maxInstances?: unknown } | null | undefined): {
|
|
139
|
+
concurrency: number; maxInstances: number;
|
|
140
|
+
} {
|
|
141
|
+
return {
|
|
142
|
+
concurrency: limit(raw?.concurrency, INSTANCE_LIMITS.concurrency),
|
|
143
|
+
maxInstances: limit(raw?.maxInstances, INSTANCE_LIMITS.maxInstances),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ── /tasks: which instance a reference names, and what may be done with it ──
|
|
148
|
+
|
|
149
|
+
export interface Located { snapshot: RunSnapshot; record: InstanceRecord }
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The instance `ref` names: `a1`, or `<crew>:a1` when two crews hold an `a1`. Only the last run of
|
|
153
|
+
* each crew is kept, so an id is unique within a crew.
|
|
154
|
+
*/
|
|
155
|
+
export function locateInstance(snapshots: readonly RunSnapshot[], ref: string): { ok: true; found: Located } | { ok: false; text: string } {
|
|
156
|
+
const [crew, id] = ref.includes(":") ? ref.split(":", 2) : [undefined, ref];
|
|
157
|
+
const found = snapshots.flatMap((snapshot) =>
|
|
158
|
+
crew !== undefined && snapshot.crew !== crew
|
|
159
|
+
? []
|
|
160
|
+
: snapshot.instances.filter((r) => r.id === id && id !== "").map((record) => ({ snapshot, record })));
|
|
161
|
+
if (found.length === 1) return { ok: true, found: found[0] };
|
|
162
|
+
if (found.length === 0) return { ok: false, text: `no agent instance '${ref}': /tasks lists them` };
|
|
163
|
+
return {
|
|
164
|
+
ok: false,
|
|
165
|
+
text: `'${ref}' names an instance of ${found.map((f) => f.snapshot.crew).join(" and ")}: write ${found
|
|
166
|
+
.map((f) => `${f.snapshot.crew}:${id}`).join(" or ")}`,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const label = (l: Located): string => `${l.snapshot.crew}:${l.record.id}`;
|
|
171
|
+
|
|
172
|
+
/** Whether /tasks may ask the crew to stop the instance: only a running one, of a run still answering. */
|
|
173
|
+
export function stopVerdict(l: Located): { ok: true } | { ok: false; text: string } {
|
|
174
|
+
if (l.record.state !== "running") return { ok: false, text: `${label(l)} is ${l.record.state}: there is nothing to stop` };
|
|
175
|
+
if (!l.snapshot.serving) return { ok: false, text: `${label(l)}: its run no longer answers; it ends with the run` };
|
|
176
|
+
return { ok: true };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* What a send to the instance becomes: refused while it runs; once it has ended, a repair by a new
|
|
181
|
+
* run. A send in place (`crew.send` over the kept transcript) is not offered: the parent stops
|
|
182
|
+
* answering as soon as its child settles, so no command would ever reach the crew object in time.
|
|
183
|
+
*/
|
|
184
|
+
export function sendVerdict(l: Located): { kind: "refused"; text: string } | { kind: "repair" } {
|
|
185
|
+
if (l.record.state === "running") {
|
|
186
|
+
return { kind: "refused", text: `${label(l)} is running: a send is refused until it ends (/tasks stop ${l.record.id} ends it)` };
|
|
187
|
+
}
|
|
188
|
+
return { kind: "repair" };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const CUT_MARK = "[… the start is left out]\n";
|
|
192
|
+
|
|
193
|
+
/** The tail of `s` within `max` characters, the cut said in front. */
|
|
194
|
+
function tail(s: string, max: number): string {
|
|
195
|
+
if (s.length <= max) return s;
|
|
196
|
+
return max <= CUT_MARK.length ? s.slice(s.length - max) : CUT_MARK + s.slice(s.length - (max - CUT_MARK.length));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The brief of a repair by a new run: the operator's message, the previous report and the previous
|
|
201
|
+
* brief, within MAX_BRIEF_CHARS; the previous brief is cut first, from its start, then the report.
|
|
202
|
+
* The new run has no live context of the old one, and the brief says so.
|
|
203
|
+
*/
|
|
204
|
+
export function buildRepairBrief(record: InstanceRecord, message: string): string {
|
|
205
|
+
const head = [
|
|
206
|
+
`This is a new run of ${record.charter}, repairing instance ${record.id || "?"} of an ended run: you do not have its context,`,
|
|
207
|
+
"only what follows. Answer the operator's message below, then give the whole report again in the shape the previous brief asked for.",
|
|
208
|
+
"",
|
|
209
|
+
"## Operator's message",
|
|
210
|
+
message.trim(),
|
|
211
|
+
"",
|
|
212
|
+
"## Previous report",
|
|
213
|
+
"",
|
|
214
|
+
].join("\n");
|
|
215
|
+
const report = record.reply ?? `(none: the instance ${record.state}${record.error ? `: ${record.error}` : ""})`;
|
|
216
|
+
const briefHeading = "\n\n## Previous brief\n";
|
|
217
|
+
const forReport = MAX_BRIEF_CHARS - head.length - briefHeading.length;
|
|
218
|
+
const keptReport = tail(report, Math.max(0, forReport));
|
|
219
|
+
const forBrief = MAX_BRIEF_CHARS - head.length - keptReport.length - briefHeading.length;
|
|
220
|
+
const out = head + keptReport + briefHeading + tail(record.brief, Math.max(0, forBrief));
|
|
221
|
+
return out.slice(0, MAX_BRIEF_CHARS);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** One row per instance, the open runs first, for the /tasks table. */
|
|
225
|
+
export function instanceRows(snapshots: readonly RunSnapshot[]): Array<Record<string, string>> {
|
|
226
|
+
const ordered = [...snapshots].sort((a, b) => Number(b.open) - Number(a.open) || b.startedAt.localeCompare(a.startedAt));
|
|
227
|
+
return ordered.flatMap((s) => s.instances.map((r) => ({
|
|
228
|
+
id: r.id || "?",
|
|
229
|
+
crew: s.crew,
|
|
230
|
+
agent: r.agent,
|
|
231
|
+
state: r.stopRequested && r.state === "running" ? "running (stop asked)" : r.state,
|
|
232
|
+
task: r.task,
|
|
233
|
+
run: s.serving ? "answering" : s.open ? "running, not answering" : "ended",
|
|
234
|
+
})));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** The lines `/tasks show <id>` prints. */
|
|
238
|
+
export function describeInstance(l: Located): string[] {
|
|
239
|
+
const { snapshot: s, record: r } = l;
|
|
240
|
+
const lines = [
|
|
241
|
+
`${label(l)} — ${r.agent} (${r.charter}), ${r.state}${r.stopRequested && r.state === "running" ? ", stop asked" : ""}`,
|
|
242
|
+
`task: ${r.task}`,
|
|
243
|
+
`started ${r.startedAt}${r.endedAt ? `, ended ${r.endedAt}` : ""}${r.effort ? `, effort ${r.effort}` : ""}`,
|
|
244
|
+
`run of ${s.crew} started ${s.startedAt}: ${s.serving ? "answering /tasks" : s.open ? "running, no longer answering" : "ended"}`,
|
|
245
|
+
];
|
|
246
|
+
if (r.error) lines.push(`error: ${r.error}`);
|
|
247
|
+
if (r.reply) lines.push("report:", r.reply);
|
|
248
|
+
return lines;
|
|
249
|
+
}
|