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,83 @@
|
|
|
1
|
+
// The project manifests: the configuration files that state a project's commands and rules (build, test,
|
|
2
|
+
// lint, format, task runners, contribution guide), which /init and /init-verifiers read. Pure, no IO: the
|
|
3
|
+
// reads live in ../application/project-manifests.ts.
|
|
4
|
+
//
|
|
5
|
+
// Order rule: the material is bounded, so the files that state commands come first (the manifests with
|
|
6
|
+
// scripts or targets, then the CI workflows), the files that state rules after (lint and format
|
|
7
|
+
// configurations, `.editorconfig`), `CONTRIBUTING.md` last.
|
|
8
|
+
//
|
|
9
|
+
// An entry starting with `*` (`*.csproj`) names no file: it matches the top-level entries ending with the
|
|
10
|
+
// rest (`App.csproj`), which only a listing of the workspace root shows, since Files.read takes a path.
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The manifests that state commands (scripts, targets, tasks), relative to the workspace root, in read
|
|
14
|
+
* order: the most useful first, since the material is bounded (MAX_MANIFESTS_MATERIAL_CHARS) and what does
|
|
15
|
+
* not fit is left out from the end. The task runners and the build manifests of each ecosystem: Node,
|
|
16
|
+
* Python, make, just, Task, Rust, Go, then the JVM and .NET.
|
|
17
|
+
*/
|
|
18
|
+
export const COMMAND_MANIFESTS: readonly string[] = [
|
|
19
|
+
"package.json",
|
|
20
|
+
"pyproject.toml",
|
|
21
|
+
"Makefile",
|
|
22
|
+
"justfile",
|
|
23
|
+
"Taskfile.yml",
|
|
24
|
+
"Cargo.toml",
|
|
25
|
+
"go.mod",
|
|
26
|
+
"pom.xml",
|
|
27
|
+
"build.gradle",
|
|
28
|
+
"build.gradle.kts",
|
|
29
|
+
"*.sln",
|
|
30
|
+
"*.csproj",
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
/** The configurations that state rules rather than commands, read after the CI workflows: the compiler,
|
|
34
|
+
* lint and format configurations, then `.editorconfig`, the contribution guide last. */
|
|
35
|
+
export const RULE_CONFIGS: readonly string[] = [
|
|
36
|
+
"tsconfig.json",
|
|
37
|
+
".eslintrc.json",
|
|
38
|
+
".eslintrc.js",
|
|
39
|
+
"eslint.config.js",
|
|
40
|
+
"eslint.config.mjs",
|
|
41
|
+
"biome.json",
|
|
42
|
+
"ruff.toml",
|
|
43
|
+
".editorconfig",
|
|
44
|
+
"CONTRIBUTING.md",
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
/** Every manifest read, in read order: COMMAND_MANIFESTS, then RULE_CONFIGS (the CI workflows go between). */
|
|
48
|
+
export const CONFIG_CANDIDATES: readonly string[] = [...COMMAND_MANIFESTS, ...RULE_CONFIGS];
|
|
49
|
+
|
|
50
|
+
/** Characters read of each manifest. */
|
|
51
|
+
export const MAX_CONFIG_FILE_CHARS = 4_000;
|
|
52
|
+
|
|
53
|
+
/** Characters of the manifests material as a whole: whole files are kept in read order while they fit. */
|
|
54
|
+
export const MAX_MANIFESTS_MATERIAL_CHARS = 24_000;
|
|
55
|
+
|
|
56
|
+
/** The line that closes the visible part of a manifest (or a section) cut at its bound. */
|
|
57
|
+
export function cutLine(omitted: number, what = "this file"): string {
|
|
58
|
+
return `[… cut: ${omitted} characters of ${what} not shown …]`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The line that ends the manifests material when files were left out of it, naming them. */
|
|
62
|
+
export function leftOutLine(paths: readonly string[], max = MAX_MANIFESTS_MATERIAL_CHARS): string {
|
|
63
|
+
return `[… cut: ${paths.length} file(s) left out, over ${max} characters: ${paths.join(", ")} …]`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The folder of the CI workflows, relative to the workspace root. */
|
|
67
|
+
export const CI_WORKFLOWS_DIR = ".github/workflows";
|
|
68
|
+
|
|
69
|
+
/** A candidate matched by suffix against the top-level entries rather than read by name. */
|
|
70
|
+
export function isSuffixCandidate(candidate: string): boolean {
|
|
71
|
+
return candidate.startsWith("*");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The paths to read for `candidates`: a named one as it is, a suffix one replaced by the `topLevel`
|
|
75
|
+
* entries it matches, in their listing order; each path once. */
|
|
76
|
+
export function expandCandidates(candidates: readonly string[], topLevel: readonly string[]): string[] {
|
|
77
|
+
const paths: string[] = [];
|
|
78
|
+
for (const c of candidates) {
|
|
79
|
+
const matches = isSuffixCandidate(c) ? topLevel.filter((name) => name.endsWith(c.slice(1))) : [c];
|
|
80
|
+
for (const path of matches) if (!paths.includes(path)) paths.push(path);
|
|
81
|
+
}
|
|
82
|
+
return paths;
|
|
83
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Which search surface covers which file — pure, no IO.
|
|
2
|
+
//
|
|
3
|
+
// The two indexes cover DISJOINT ground, and neither reports the other's blind
|
|
4
|
+
// side: the RaggableTree parses exactly the Tree-sitter adapters' extensions and
|
|
5
|
+
// silently skips everything else (a `.md` never enters `codebase_search`'s world),
|
|
6
|
+
// while the RAG document store only holds what was explicitly `rag_ingest`ed. A
|
|
7
|
+
// model told "search the codebase" with no routing rule picks one tool, gets an
|
|
8
|
+
// empty answer on the other half, and concludes the content does not exist.
|
|
9
|
+
//
|
|
10
|
+
// So the rule is DETERMINISTIC, by extension:
|
|
11
|
+
// code (tree) → codebase_search / symbol_source / flow_trace
|
|
12
|
+
// documents (rag) → rag_search on the workspace-docs collection
|
|
13
|
+
// unknown → rag (the tree cannot parse it by construction; the RAG's
|
|
14
|
+
// text loader reads any UTF-8 body, so it is the side with
|
|
15
|
+
// a chance — and rag_ingest fails loudly instead of lying)
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Extensions the RaggableTree parses — the union of the thirteen Tree-sitter
|
|
19
|
+
* adapters' `FileExtensions` (TypeScript/C#/Python/Go/Rust, and since Orkeon #195
|
|
20
|
+
* JavaScript/Java/C/C++/PHP/Ruby/Bash), read from
|
|
21
|
+
* `src/analysis/Orkeon.Analysis/Adapters/*.cs`. A new adapter framework-side
|
|
22
|
+
* must be mirrored here; the probe's partition step is the tripwire. The
|
|
23
|
+
* parse-only grammars (CSS, HTML, JSON…) serve the structural tools but enter
|
|
24
|
+
* no index: they stay on the rag side.
|
|
25
|
+
*/
|
|
26
|
+
export const TREE_CODE_EXTENSIONS: readonly string[] = [
|
|
27
|
+
".ts", ".tsx", ".cs", ".py", ".go", ".rs",
|
|
28
|
+
".js", ".jsx", ".mjs", ".cjs", ".java", ".c",
|
|
29
|
+
".cpp", ".cc", ".cxx", ".hpp", ".hh", ".hxx", ".h",
|
|
30
|
+
".php", ".rb", ".sh", ".bash",
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Extensions the RAG document loaders accept, per loader (read from
|
|
35
|
+
* `src/rag/Orkeon.Rag/Loaders/*.cs`): text/markdown, CSV, HTML, PDF.
|
|
36
|
+
*/
|
|
37
|
+
export const RAG_DOCUMENT_EXTENSIONS: readonly string[] = [
|
|
38
|
+
".txt", ".md", ".markdown", ".text", ".log",
|
|
39
|
+
".csv", ".html", ".htm", ".pdf",
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
/** The collection where the workspace's non-code files get ingested. */
|
|
43
|
+
export const WORKSPACE_DOCS_COLLECTION = "workspace-docs";
|
|
44
|
+
|
|
45
|
+
export type SearchSurface = "tree" | "rag";
|
|
46
|
+
|
|
47
|
+
/** Lowercased extension of a path, "" when there is none. */
|
|
48
|
+
export function extensionOf(path: string): string {
|
|
49
|
+
const name = String(path ?? "").split("/").pop() ?? "";
|
|
50
|
+
const dot = name.lastIndexOf(".");
|
|
51
|
+
return dot > 0 ? name.slice(dot).toLowerCase() : "";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The surface that covers a path. Everything the tree does not parse routes to
|
|
56
|
+
* the RAG — including unknown extensions: the tree CANNOT hold them (its
|
|
57
|
+
* discovery filters by adapter extension), so sending the query there would
|
|
58
|
+
* manufacture a guaranteed-empty answer that reads as "not found".
|
|
59
|
+
*/
|
|
60
|
+
export function routeForPath(path: string): SearchSurface {
|
|
61
|
+
return TREE_CODE_EXTENSIONS.includes(extensionOf(path)) ? "tree" : "rag";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** True when a RAG loader is DECLARED for this extension (ingestion will parse it). */
|
|
65
|
+
export function hasRagLoader(path: string): boolean {
|
|
66
|
+
return RAG_DOCUMENT_EXTENSIONS.includes(extensionOf(path));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The playbook's routing paragraph — kept here so the prompt text and the rule
|
|
71
|
+
* cannot drift apart (the prompt renders THIS, tests pin THIS).
|
|
72
|
+
*/
|
|
73
|
+
export function describeSearchRouting(tools: readonly string[]): string {
|
|
74
|
+
const ingest = tools.includes("rag_ingest")
|
|
75
|
+
? " The collection holds nothing until ingested: when it returns nothing for files you KNOW exist, " +
|
|
76
|
+
"`rag_ingest {collection: \"" + WORKSPACE_DOCS_COLLECTION + "\", sources: [globs of those files, such as " +
|
|
77
|
+
"\"/workspace/docs/**/*.md\"]}`, then search again."
|
|
78
|
+
: " The collection holds only what a writing session ingested: an empty answer there is no proof of absence.";
|
|
79
|
+
return (
|
|
80
|
+
"- Code files: `codebase_search`, then `symbol_source`/`flow_trace` on the hits.\n" +
|
|
81
|
+
"- Any other file (configuration, data, documents, other languages): a name, a key or an exact text with " +
|
|
82
|
+
"`grep` (a `glob` narrows), then `file_read`; a question of meaning over prose with `rag_search` " +
|
|
83
|
+
"(`question`, `collection: \"" + WORKSPACE_DOCS_COLLECTION + "\"`)." + ingest
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Secret detection, pure: the file names that usually hold a secret (used by /commit
|
|
2
|
+
// before it stages anything) and the content patterns a stored text must never carry.
|
|
3
|
+
|
|
4
|
+
/** File names that usually hold a secret, and the safe variants of them. */
|
|
5
|
+
const SECRET_EXTENSIONS = [".pem", ".key", ".p12", ".pfx", ".jks", ".keystore"];
|
|
6
|
+
const SECRET_KEY_FILES = /^id_(rsa|dsa|ecdsa|ed25519)(\.|$)/;
|
|
7
|
+
const SAFE_ENV_SUFFIXES = [".example", ".sample", ".template", ".dist"];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The paths that usually hold a secret: an env file (but not its example), a key
|
|
11
|
+
* or certificate store, an SSH private key, a credentials file. Committing one by
|
|
12
|
+
* accident is the one mistake `git add -A` makes easy and history keeps forever,
|
|
13
|
+
* so /commit stops before any model call and lets the user decide.
|
|
14
|
+
*/
|
|
15
|
+
export function secretLikePaths(paths: readonly string[]): string[] {
|
|
16
|
+
return paths.filter((path) => {
|
|
17
|
+
const name = path.split("/").pop() ?? "";
|
|
18
|
+
const lower = name.toLowerCase();
|
|
19
|
+
if (lower === ".env" || (lower.startsWith(".env.") && !SAFE_ENV_SUFFIXES.some((s) => lower.endsWith(s)))) return true;
|
|
20
|
+
if (SECRET_EXTENSIONS.some((ext) => lower.endsWith(ext))) return true;
|
|
21
|
+
if (SECRET_KEY_FILES.test(lower) && !lower.endsWith(".pub")) return true;
|
|
22
|
+
return lower === "credentials" || lower === "credentials.json";
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface SecretPattern { name: string; re: RegExp }
|
|
27
|
+
|
|
28
|
+
/** Content patterns: a text that matches one is refused, and the match itself is never echoed. */
|
|
29
|
+
export const SECRET_PATTERNS: readonly SecretPattern[] = [
|
|
30
|
+
{ name: "private key block", re: /-----BEGIN (?:[A-Z]+ )*PRIVATE KEY-----/ },
|
|
31
|
+
{ name: "AWS access key id", re: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/ },
|
|
32
|
+
{ name: "GitHub token", re: /\bgh[pousr]_[A-Za-z0-9]{36,}|\bgithub_pat_[A-Za-z0-9_]{22,}/ },
|
|
33
|
+
{ name: "Slack token", re: /\bxox[abposr]-[A-Za-z0-9-]{10,}/ },
|
|
34
|
+
{ name: "Google API key", re: /\bAIza[0-9A-Za-z_-]{35}/ },
|
|
35
|
+
{ name: "secret key", re: /\bsk-[A-Za-z0-9_-]{20,}/ },
|
|
36
|
+
{ name: "JSON web token", re: /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/ },
|
|
37
|
+
{ name: "credential in a URL", re: /:\/\/[^\/:@\s]+:[^\/:@\s]+@/ },
|
|
38
|
+
{ name: "assigned secret", re: /(?:api[_-]?key|secret|password|passwd|token)["']?\s*[:=]\s*["']?[^\s"']{8,}/i },
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
/** The names of the patterns the text matches, in SECRET_PATTERNS order, each once. */
|
|
42
|
+
export function secretPatternsIn(text: string): string[] {
|
|
43
|
+
const value = String(text ?? "");
|
|
44
|
+
return SECRET_PATTERNS.filter((pattern) => pattern.re.test(value)).map((pattern) => pattern.name);
|
|
45
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Session state-bag keys, in ONE place — pure, no IO. Every key of the bag is
|
|
2
|
+
// declared here, and session-keys.test.ts pins its string value: the value is
|
|
3
|
+
// what a stored session and the runtime (`default_permission_mode`) read, so a
|
|
4
|
+
// renamed value silently orphans the state.
|
|
5
|
+
//
|
|
6
|
+
// Most of these are written by a command and read somewhere else: `/skills` writes
|
|
7
|
+
// the registry that the main-loop prompt assembly and the post-compaction restore
|
|
8
|
+
// both read; `/hooks` writes what the prompt renders; `/output-style` writes what
|
|
9
|
+
// the preferences block renders. Until B-7 every one of them was a string literal
|
|
10
|
+
// duplicated at each site (three copies of "skills_attached", two of
|
|
11
|
+
// "hooks_registry"), so renaming one would have left the writer and the reader
|
|
12
|
+
// pointing at different keys — and the symptom is silence: the command reports
|
|
13
|
+
// success, the prompt never changes.
|
|
14
|
+
|
|
15
|
+
/** `/output-style` — the session's answer style (B-7). */
|
|
16
|
+
export const OUTPUT_STYLE_STATE_KEY = "output_style";
|
|
17
|
+
|
|
18
|
+
/** `/hooks` — the declarative registry; the engine awaits framework G-6. */
|
|
19
|
+
export const HOOKS_STATE_KEY = "hooks_registry";
|
|
20
|
+
|
|
21
|
+
/** `/skills` — attached playbook paths (B-13 consumes them in the prompt). */
|
|
22
|
+
export const SKILLS_STATE_KEY = "skills_attached";
|
|
23
|
+
|
|
24
|
+
// ── B-9 / B-10: the behavior flags, now that something reads them ────────
|
|
25
|
+
//
|
|
26
|
+
// These five keys existed since E-1 but were written and never read — the
|
|
27
|
+
// commands said "consumed by future main-loop wiring". B-9 is that wiring, so
|
|
28
|
+
// the keys move here for the same reason the three above did: the writer is a
|
|
29
|
+
// command, the reader is the loop, and a literal duplicated across the two is
|
|
30
|
+
// how a rename silently stops working.
|
|
31
|
+
|
|
32
|
+
/** `/effort` — low|medium|high|xhigh|max; picks the act() iteration ladder (B-9). */
|
|
33
|
+
export const EFFORT_STATE_KEY = "reasoning_effort";
|
|
34
|
+
|
|
35
|
+
/** `/passes` — 1-5; the number of review rounds /review runs (B-9). */
|
|
36
|
+
export const PASSES_STATE_KEY = "reasoning_passes";
|
|
37
|
+
|
|
38
|
+
/** The history file `/resume <n|id>` loaded this session from (Orkeon #227): written into the loaded session's own
|
|
39
|
+
* state bag, so the listing can name it. */
|
|
40
|
+
export const LOADED_SESSION_STATE_KEY = "resume_loaded_from";
|
|
41
|
+
|
|
42
|
+
/** `/fast` — drops the advisory prompt blocks to buy latency (B-9). */
|
|
43
|
+
export const FAST_MODE_STATE_KEY = "fast_mode";
|
|
44
|
+
|
|
45
|
+
/** `/proactive` — appends the follow-up-suggestion clause to the task (B-9). */
|
|
46
|
+
export const PROACTIVE_STATE_KEY = "proactive_suggestions";
|
|
47
|
+
|
|
48
|
+
/** `/model` — per-turn model override applied to act() (B-10). */
|
|
49
|
+
export const MODEL_PREFERENCE_STATE_KEY = "model_preference";
|
|
50
|
+
|
|
51
|
+
// ── Permissions, configuration, tasks and the compaction breaker ──────────
|
|
52
|
+
|
|
53
|
+
/** `/mode` — the session-default permission mode (cleared by /clear). A
|
|
54
|
+
* contract with the host: Orkeon's `SessionStateKeys.DefaultPermissionMode`,
|
|
55
|
+
* which the REPL console shows and cycles. */
|
|
56
|
+
export const DEFAULT_MODE_STATE_KEY = "default_permission_mode";
|
|
57
|
+
|
|
58
|
+
/** `/permissions` — the rule list: one JSON array of rule lines
|
|
59
|
+
* (`allow shell_command command=npm test*`; the older `deny:file_write` still reads). */
|
|
60
|
+
export const PERMISSION_RULES_STATE_KEY = "permission_rules";
|
|
61
|
+
|
|
62
|
+
/** `/config` — the session override map, over the settings file (B-6). */
|
|
63
|
+
export const CONFIG_MAP_STATE_KEY = "config_map";
|
|
64
|
+
|
|
65
|
+
/** `/tasks` — the session task list, one JSON array. */
|
|
66
|
+
export const TASKS_STATE_KEY = "task_list";
|
|
67
|
+
|
|
68
|
+
/** The main-loop auto-compaction circuit breaker: consecutive failures (F3 v2). */
|
|
69
|
+
export const AUTOCOMPACT_BREAKER_STATE_KEY = "autocompact_consecutive_failures";
|
|
70
|
+
|
|
71
|
+
/** The dev batch in progress, `{"code": …, "phase": "F<n>"}`: written by the shape of /dev-batches
|
|
72
|
+
* that starts on a batch (`F<n>`, its audit), read by the state file written before a compaction. */
|
|
73
|
+
export const WORKFLOW_ACTIVE_STATE_KEY = "workflow_active";
|
|
74
|
+
|
|
75
|
+
/** The chain the last launch of /dev-batches started (`run`, `batch` or `audit`): its `completed` reads it to tell
|
|
76
|
+
* a plan's run from one batch, whose answers come from the same crews. */
|
|
77
|
+
export const DEV_BATCHES_CHAIN_STATE_KEY = "dev_batches_chain";
|
|
78
|
+
|
|
79
|
+
/** The agent instances of a crew's run, `agent_instances:<crew>` (A-3): written by the crew while its children run,
|
|
80
|
+
* read by /tasks. One key per crew, so two crews never write the same one. */
|
|
81
|
+
export const AGENT_INSTANCES_STATE_PREFIX = "agent_instances:";
|
|
82
|
+
|
|
83
|
+
/** A request of /tasks to one instance, `agent_request:<crew>:<id>` (A-3): written by /tasks, read and cleared by the
|
|
84
|
+
* crew that holds the instance. */
|
|
85
|
+
export const AGENT_REQUEST_STATE_PREFIX = "agent_request:";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// The block the runtime puts before the first free-text turn of a session: what the
|
|
2
|
+
// script named by Orkeon:Cli:Session:StartScript printed at the REPL's start, with its
|
|
3
|
+
// path and its source. Pure, no IO. The command reads it off its raw input (the
|
|
4
|
+
// command's tokens never hold it); the main loop renders its lines as context of that
|
|
5
|
+
// turn. The source is dropped: the model needs what the script found, not its code.
|
|
6
|
+
|
|
7
|
+
/** The start script's output, as the main loop receives it in its inputs. */
|
|
8
|
+
export interface StartOutput {
|
|
9
|
+
script: string;
|
|
10
|
+
lines: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** At most this many lines of the script's output reach the model, each cut to MAX_START_LINE_CHARS. */
|
|
14
|
+
export const MAX_START_LINES = 40;
|
|
15
|
+
export const MAX_START_LINE_CHARS = 240;
|
|
16
|
+
|
|
17
|
+
const HEADER = /^\[Session start script: ([^\]\n]+)\]\n/;
|
|
18
|
+
const SOURCE_MARKER = "\n[Script source]\n";
|
|
19
|
+
const END_MARKER = "\n[End of session start script]";
|
|
20
|
+
|
|
21
|
+
/** Cut a line to the bound, saying so. */
|
|
22
|
+
function bounded(line: string): string {
|
|
23
|
+
return line.length <= MAX_START_LINE_CHARS ? line : line.slice(0, MAX_START_LINE_CHARS - 1) + "…";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The output's non-blank lines, bounded, with a last line saying how many were left out. */
|
|
27
|
+
function boundedLines(stdout: string): string[] {
|
|
28
|
+
const lines = stdout.split(/\r?\n/).map((l) => l.trimEnd()).filter((l) => l.trim().length > 0);
|
|
29
|
+
if (lines.length <= MAX_START_LINES) return lines.map(bounded);
|
|
30
|
+
return [...lines.slice(0, MAX_START_LINES).map(bounded), `(${lines.length - MAX_START_LINES} more line(s) left out)`];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The start block at the head of a command's raw input, and the input without it;
|
|
35
|
+
* `start` is null when the input does not open with a whole block (the runtime's
|
|
36
|
+
* header, its source marker and its end marker, in that order).
|
|
37
|
+
*/
|
|
38
|
+
export function splitStartOutput(raw: string): { start: StartOutput | null; rest: string } {
|
|
39
|
+
const text = String(raw ?? "");
|
|
40
|
+
const header = HEADER.exec(text);
|
|
41
|
+
if (header === null) return { start: null, rest: text };
|
|
42
|
+
const sourceAt = text.indexOf(SOURCE_MARKER, header[0].length - 1);
|
|
43
|
+
if (sourceAt < 0) return { start: null, rest: text };
|
|
44
|
+
const endAt = text.indexOf(END_MARKER, sourceAt + SOURCE_MARKER.length - 1);
|
|
45
|
+
if (endAt < 0) return { start: null, rest: text };
|
|
46
|
+
const stdout = text.slice(header[0].length, sourceAt);
|
|
47
|
+
const lines = boundedLines(stdout);
|
|
48
|
+
const rest = text.slice(endAt + END_MARKER.length).replace(/^\s+/, "");
|
|
49
|
+
return { start: lines.length === 0 ? null : { script: header[1].trim(), lines }, rest };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The `sessionStart` input as the main loop reads it: null unless a script path and lines. */
|
|
53
|
+
export function readStartOutput(value: unknown): StartOutput | null {
|
|
54
|
+
if (value === null || typeof value !== "object") return null;
|
|
55
|
+
const v = value as { script?: unknown; lines?: unknown };
|
|
56
|
+
if (typeof v.script !== "string" || v.script.trim().length === 0 || !Array.isArray(v.lines)) return null;
|
|
57
|
+
const lines = v.lines.filter((l): l is string => typeof l === "string" && l.trim().length > 0);
|
|
58
|
+
if (lines.length === 0) return null;
|
|
59
|
+
return { script: v.script.trim(), lines: boundedLines(lines.join("\n")) };
|
|
60
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// The /summary request — pure. It runs through the main loop in plan mode, whose
|
|
2
|
+
// user body already carries the session's history: the request says what to make
|
|
3
|
+
// of it. Written from docs/architecture.md, "Crew prompts".
|
|
4
|
+
|
|
5
|
+
/** The request /summary sends to the main loop. */
|
|
6
|
+
export const SUMMARY_PROMPT =
|
|
7
|
+
"Summarise this session for the user from the conversation so far, which is complete: calling a tool " +
|
|
8
|
+
"would only spend this turn. Start with where things stand (done, in progress, blocked), then the " +
|
|
9
|
+
"decisions taken, the files touched (each path and what changed) and what is still open, as a few short " +
|
|
10
|
+
"bullets under each heading, leaving out a heading with nothing under it and adding no next-steps list " +
|
|
11
|
+
"of your own. A [compacted] message is either the summary of earlier turns, to cover too, or a note that turns " +
|
|
12
|
+
"were removed without one: report that gap, never fill it in. " +
|
|
13
|
+
"Report a test or a check only as it was last seen. Write in the language of the conversation.";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Finding severity ordering + dedup/rank — pure, no IO. Extracted verbatim in
|
|
2
|
+
// behaviour from code-review/crew.ork.ts:68-77 so it can be unit-tested
|
|
3
|
+
// without a live LLM run.
|
|
4
|
+
|
|
5
|
+
import type { Finding } from "./types.ts";
|
|
6
|
+
|
|
7
|
+
/** Canonical severity ladder, most→least severe. */
|
|
8
|
+
export const SEVERITY_ORDER: Record<string, number> = {
|
|
9
|
+
blocker: 0,
|
|
10
|
+
high: 1,
|
|
11
|
+
medium: 2,
|
|
12
|
+
low: 3,
|
|
13
|
+
nit: 4,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Rank a severity for sorting; unknown severities sort last (9). */
|
|
17
|
+
export function severityRank(severity: string | undefined): number {
|
|
18
|
+
return SEVERITY_ORDER[String(severity ?? "").toLowerCase()] ?? 9;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** How many characters of the claim the dedup key keeps. */
|
|
22
|
+
export const DEDUP_CLAIM_CHARS = 40;
|
|
23
|
+
|
|
24
|
+
/** Stable dedup key: file + line + category (lower-cased, empty when absent) + the
|
|
25
|
+
* start of the claim (the first {@link DEDUP_CLAIM_CHARS} characters of `finding`,
|
|
26
|
+
* trimmed and lower-cased). The claim opens a finding, so two faults of one lens on
|
|
27
|
+
* one line stay apart, while passes or lenses that give the same category and the
|
|
28
|
+
* same claim opening collapse; each lens names its own category, so two lenses
|
|
29
|
+
* rarely do. */
|
|
30
|
+
export function findingDedupKey(f: Finding): string {
|
|
31
|
+
const claim = String(f.finding ?? "").trim().toLowerCase().slice(0, DEDUP_CLAIM_CHARS);
|
|
32
|
+
return `${f.file}:${f.line}:${(f.category ?? "").toLowerCase()}:${claim}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether `a` outranks `b` on one key: the more severe, or at equal severity a
|
|
36
|
+
* `shown` over a finding that is not, so the report never calls plausible what a
|
|
37
|
+
* pass showed. */
|
|
38
|
+
function outranks(a: Finding, b: Finding): boolean {
|
|
39
|
+
const bySeverity = severityRank(a.severity) - severityRank(b.severity);
|
|
40
|
+
if (bySeverity !== 0) return bySeverity < 0;
|
|
41
|
+
return a.confidence === "shown" && b.confidence !== "shown";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Merge lens results, drop duplicates (by {@link findingDedupKey}), and sort by
|
|
46
|
+
* severity. On a collision the most severe finding is kept, at equal severity the
|
|
47
|
+
* `shown` one, else the first, so a blocker is never dropped behind a low on the
|
|
48
|
+
* same key. Each input group
|
|
49
|
+
* carries its lens so the kept finding records which lens surfaced it.
|
|
50
|
+
* Order-stable for equal severities (sort is stable in V8).
|
|
51
|
+
*/
|
|
52
|
+
export function dedupAndRank(
|
|
53
|
+
groups: ReadonlyArray<{ lens: string; findings: Finding[] }>,
|
|
54
|
+
): Finding[] {
|
|
55
|
+
const at = new Map<string, number>();
|
|
56
|
+
const all: Finding[] = [];
|
|
57
|
+
for (const g of groups) {
|
|
58
|
+
for (const f of g.findings) {
|
|
59
|
+
const key = findingDedupKey(f);
|
|
60
|
+
const kept = { ...f, lens: f.lens ?? g.lens };
|
|
61
|
+
const index = at.get(key);
|
|
62
|
+
if (index === undefined) {
|
|
63
|
+
at.set(key, all.length);
|
|
64
|
+
all.push(kept);
|
|
65
|
+
} else if (outranks(kept, all[index])) {
|
|
66
|
+
all[index] = kept;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
all.sort((a, b) => severityRank(a.severity) - severityRank(b.severity));
|
|
71
|
+
return all;
|
|
72
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// SHA-1 over the UTF-8 bytes of a string, in plain TypeScript: the REPL runtime has
|
|
2
|
+
// neither TextEncoder nor a hash module, and the learning ids must equal the ones the
|
|
3
|
+
// harness's script computes with Python's hashlib. Pure, no IO, never throws.
|
|
4
|
+
|
|
5
|
+
/** The UTF-8 bytes of a string; a lone surrogate encodes as U+FFFD (EF BF BD). */
|
|
6
|
+
export function utf8Bytes(text: string): number[] {
|
|
7
|
+
const out: number[] = [];
|
|
8
|
+
for (let i = 0; i < text.length; i++) {
|
|
9
|
+
let c = text.charCodeAt(i);
|
|
10
|
+
if (c >= 0xd800 && c <= 0xdbff) {
|
|
11
|
+
const next = i + 1 < text.length ? text.charCodeAt(i + 1) : 0;
|
|
12
|
+
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
13
|
+
c = 0x10000 + ((c - 0xd800) << 10) + (next - 0xdc00);
|
|
14
|
+
i++;
|
|
15
|
+
} else c = 0xfffd;
|
|
16
|
+
} else if (c >= 0xdc00 && c <= 0xdfff) c = 0xfffd;
|
|
17
|
+
if (c < 0x80) out.push(c);
|
|
18
|
+
else if (c < 0x800) out.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
|
|
19
|
+
else if (c < 0x10000) out.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
|
|
20
|
+
else out.push(0xf0 | (c >> 18), 0x80 | ((c >> 12) & 0x3f), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function rotl(x: number, n: number): number {
|
|
26
|
+
return ((x << n) | (x >>> (32 - n))) >>> 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** SHA-1 (FIPS 180-4) of the UTF-8 bytes of text, 40 lower-case hex digits. */
|
|
30
|
+
export function sha1Hex(text: string): string {
|
|
31
|
+
const bytes = utf8Bytes(text);
|
|
32
|
+
const bits = bytes.length * 8;
|
|
33
|
+
bytes.push(0x80);
|
|
34
|
+
while (bytes.length % 64 !== 56) bytes.push(0);
|
|
35
|
+
const high = Math.floor(bits / 2 ** 32);
|
|
36
|
+
const low = bits >>> 0;
|
|
37
|
+
bytes.push((high >>> 24) & 0xff, (high >>> 16) & 0xff, (high >>> 8) & 0xff, high & 0xff);
|
|
38
|
+
bytes.push((low >>> 24) & 0xff, (low >>> 16) & 0xff, (low >>> 8) & 0xff, low & 0xff);
|
|
39
|
+
|
|
40
|
+
let h0 = 0x67452301, h1 = 0xefcdab89, h2 = 0x98badcfe, h3 = 0x10325476, h4 = 0xc3d2e1f0;
|
|
41
|
+
const w = new Array<number>(80);
|
|
42
|
+
for (let off = 0; off < bytes.length; off += 64) {
|
|
43
|
+
for (let t = 0; t < 16; t++) {
|
|
44
|
+
const j = off + t * 4;
|
|
45
|
+
w[t] = ((bytes[j] << 24) | (bytes[j + 1] << 16) | (bytes[j + 2] << 8) | bytes[j + 3]) >>> 0;
|
|
46
|
+
}
|
|
47
|
+
for (let t = 16; t < 80; t++) w[t] = rotl(w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16], 1);
|
|
48
|
+
let a = h0, b = h1, c = h2, d = h3, e = h4;
|
|
49
|
+
for (let t = 0; t < 80; t++) {
|
|
50
|
+
let f: number, k: number;
|
|
51
|
+
if (t < 20) { f = (b & c) | (~b & d); k = 0x5a827999; }
|
|
52
|
+
else if (t < 40) { f = b ^ c ^ d; k = 0x6ed9eba1; }
|
|
53
|
+
else if (t < 60) { f = (b & c) | (b & d) | (c & d); k = 0x8f1bbcdc; }
|
|
54
|
+
else { f = b ^ c ^ d; k = 0xca62c1d6; }
|
|
55
|
+
const temp = (rotl(a, 5) + (f >>> 0) + e + k + w[t]) >>> 0;
|
|
56
|
+
e = d; d = c; c = rotl(b, 30); b = a; a = temp;
|
|
57
|
+
}
|
|
58
|
+
h0 = (h0 + a) >>> 0; h1 = (h1 + b) >>> 0; h2 = (h2 + c) >>> 0; h3 = (h3 + d) >>> 0; h4 = (h4 + e) >>> 0;
|
|
59
|
+
}
|
|
60
|
+
return [h0, h1, h2, h3, h4].map((h) => h.toString(16).padStart(8, "0")).join("");
|
|
61
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// The harness's agent memory read as shared-memory candidates (lot M-9, temp/05 § 8.2), pure: one
|
|
2
|
+
// top-level list item of a .claude/agent-memory/<agent>/MEMORY.md is one entry, its linked note (a
|
|
3
|
+
// .md file of the same folder) read when there is one. Every entry becomes a `method` candidate whose
|
|
4
|
+
// source is the import itself: /memory-admit still asks for each one.
|
|
5
|
+
|
|
6
|
+
import { MAX_BODY_CHARS, MAX_TITLE_CHARS, entryIdPrefix } from "./entry.ts";
|
|
7
|
+
import type { MemoryEntry } from "./entry.ts";
|
|
8
|
+
import { topicOf } from "./refused.ts";
|
|
9
|
+
|
|
10
|
+
/** The harness's agent memory, relative to the project. */
|
|
11
|
+
export const HARNESS_AGENT_MEMORY_DIR = ".claude/agent-memory";
|
|
12
|
+
export const AGENT_MEMORY_INDEX = "MEMORY.md";
|
|
13
|
+
/** How many characters of a linked note are read. */
|
|
14
|
+
export const MAX_NOTE_CHARS = 8_000;
|
|
15
|
+
|
|
16
|
+
export interface AgentMemoryItem {
|
|
17
|
+
/** 1-based line of the item in MEMORY.md. */
|
|
18
|
+
line: number;
|
|
19
|
+
title: string;
|
|
20
|
+
/** The text after the link (or the whole item when it has none). */
|
|
21
|
+
hook: string;
|
|
22
|
+
/** The linked note's file name, when it is a plain .md name of the agent's folder. */
|
|
23
|
+
note?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const ITEM = /^[-*]\s+(.*)$/;
|
|
27
|
+
const LINKED = /^\[([^\]]+)\]\(([^)\s]+)\)\s*(?:[—–:-]+\s*)?(.*)$/;
|
|
28
|
+
const NOTE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*\.md$/;
|
|
29
|
+
|
|
30
|
+
/** How many characters of a sentence (a hook, a Why, a How to apply) an entry keeps. */
|
|
31
|
+
export const MAX_SENTENCE_CHARS = 300;
|
|
32
|
+
|
|
33
|
+
const oneLine = (text: string): string => text.replace(/\s+/g, " ").trim();
|
|
34
|
+
const plain = (text: string): string => text.replace(/\*\*|__|`/g, "");
|
|
35
|
+
|
|
36
|
+
/** At most `max` characters, cut at a word. */
|
|
37
|
+
function cut(text: string, max: number): string {
|
|
38
|
+
const t = oneLine(text);
|
|
39
|
+
if (Array.from(t).length <= max) return t;
|
|
40
|
+
const head = Array.from(t).slice(0, max - 1).join("");
|
|
41
|
+
const at = head.lastIndexOf(" ");
|
|
42
|
+
return `${(at > max / 2 ? head.slice(0, at) : head).trimEnd()}…`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A title of at most MAX_TITLE_CHARS, cut at a word. */
|
|
46
|
+
export function shortTitle(text: string): string {
|
|
47
|
+
return cut(plain(text), MAX_TITLE_CHARS);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The entries of a MEMORY.md: its top-level list items, an indented line continuing the item above. */
|
|
51
|
+
export function parseAgentMemoryIndex(text: string): AgentMemoryItem[] {
|
|
52
|
+
const items: Array<{ line: number; text: string }> = [];
|
|
53
|
+
let fenced = false;
|
|
54
|
+
let current: { line: number; text: string } | null = null;
|
|
55
|
+
text.replace(/\r\n?/g, "\n").split("\n").forEach((raw, i) => {
|
|
56
|
+
if (/^\s*(```|~~~)/.test(raw)) { fenced = !fenced; current = null; return; }
|
|
57
|
+
if (fenced) return;
|
|
58
|
+
const m = ITEM.exec(raw);
|
|
59
|
+
if (m !== null) {
|
|
60
|
+
current = { line: i + 1, text: m[1] };
|
|
61
|
+
items.push(current);
|
|
62
|
+
} else if (current !== null && /^\s+\S/.test(raw)) {
|
|
63
|
+
current.text += ` ${raw.trim()}`;
|
|
64
|
+
} else {
|
|
65
|
+
current = null;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return items.flatMap(({ line, text: item }) => {
|
|
69
|
+
const body = oneLine(item);
|
|
70
|
+
// A thematic break (`* * *`, `- - -`) is not an entry.
|
|
71
|
+
if (body === "" || /^([-*_])(\s*\1)+$/.test(body)) return [];
|
|
72
|
+
const link = LINKED.exec(body);
|
|
73
|
+
if (link === null) return [{ line, title: shortTitle(body), hook: body }];
|
|
74
|
+
const title = shortTitle(link[1]);
|
|
75
|
+
const hook = oneLine(link[3]) || title;
|
|
76
|
+
return [NOTE_NAME.test(link[2]) ? { line, title, hook, note: link[2] } : { line, title, hook }];
|
|
77
|
+
}).filter((item) => /[A-Za-z0-9]/.test(item.title));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface AgentNote {
|
|
81
|
+
/** The note without its front matter. */
|
|
82
|
+
body: string;
|
|
83
|
+
why?: string;
|
|
84
|
+
howToApply?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A linked note: its front matter dropped, its `**Why:**` and `**How to apply:**` sentences picked. */
|
|
88
|
+
export function parseAgentNote(text: string): AgentNote {
|
|
89
|
+
let body = text.replace(/\r\n?/g, "\n");
|
|
90
|
+
const fm = /^---\n[\s\S]*?\n---\n?/.exec(body);
|
|
91
|
+
if (fm !== null) body = body.slice(fm[0].length);
|
|
92
|
+
body = body.trim();
|
|
93
|
+
// A label is a bold run ending in a colon (`**Why:**`); a sentence ends at the next label or a blank line.
|
|
94
|
+
const pick = (label: string): string | undefined => {
|
|
95
|
+
const m = new RegExp(`\\*\\*${label}:\\*\\*\\s*([\\s\\S]*?)(?=\\*\\*[A-Za-z][^*\\n]{0,30}:\\*\\*|\\n\\s*\\n|$)`, "i").exec(body);
|
|
96
|
+
const value = m === null ? "" : oneLine(m[1]);
|
|
97
|
+
return value === "" ? undefined : value;
|
|
98
|
+
};
|
|
99
|
+
const note: AgentNote = { body };
|
|
100
|
+
const why = pick("Why");
|
|
101
|
+
const how = pick("How to apply");
|
|
102
|
+
if (why !== undefined) note.why = why;
|
|
103
|
+
if (how !== undefined) note.howToApply = how;
|
|
104
|
+
return note;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface ImportContext {
|
|
108
|
+
agent: string;
|
|
109
|
+
project: string;
|
|
110
|
+
/** YYYY-MM-DD. */
|
|
111
|
+
date: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const TAG = /^[a-z0-9][a-z0-9.+#-]*$/;
|
|
115
|
+
|
|
116
|
+
/** The candidate an item becomes (its id not yet made unique; the domain's entryProblems still applies). */
|
|
117
|
+
export function importedEntry(item: AgentMemoryItem, note: AgentNote | null, ctx: ImportContext): MemoryEntry {
|
|
118
|
+
const index = `${HARNESS_AGENT_MEMORY_DIR}/${ctx.agent}/${AGENT_MEMORY_INDEX}`;
|
|
119
|
+
const topic = topicOf(item.title);
|
|
120
|
+
const evidence = [`- \`${index}:${item.line}\``];
|
|
121
|
+
if (note !== null && item.note !== undefined) evidence.push(`- \`${HARNESS_AGENT_MEMORY_DIR}/${ctx.agent}/${item.note}\``);
|
|
122
|
+
const hook = cut(item.hook, MAX_SENTENCE_CHARS);
|
|
123
|
+
const head = ["## Context", `Imported from the harness agent memory of ${ctx.agent} (${index}, line ${item.line}).`];
|
|
124
|
+
// Without a note the item itself is the content: it is not repeated here.
|
|
125
|
+
if (note !== null && item.hook !== item.title) head.push(hook);
|
|
126
|
+
const tail = ["", "## Evidence", ...evidence];
|
|
127
|
+
// A note's own headings are flattened: the entry's three sections stay the only ones.
|
|
128
|
+
let fenced = false;
|
|
129
|
+
const content = (note?.body ?? item.hook).split("\n").map((l) => {
|
|
130
|
+
if (/^\s*(```|~~~)/.test(l)) fenced = !fenced;
|
|
131
|
+
return fenced ? l : l.replace(/^#{1,6}\s+/, "");
|
|
132
|
+
}).join("\n").trim() || item.title;
|
|
133
|
+
const room = MAX_BODY_CHARS - (head.join("\n").length + tail.join("\n").length + "\n\n## Content\n\n".length + 1);
|
|
134
|
+
const shown = content.length <= room ? content : `${content.slice(0, Math.max(0, room - 1)).trimEnd()}…`;
|
|
135
|
+
return {
|
|
136
|
+
id: `${entryIdPrefix(ctx.project, "method", ctx.date)}${topic}`,
|
|
137
|
+
type: "method", title: item.title, project: ctx.project, date: ctx.date, topic,
|
|
138
|
+
appliesWhen: cut(note?.howToApply ?? hook, MAX_SENTENCE_CHARS), rationale: cut(note?.why ?? hook, MAX_SENTENCE_CHARS),
|
|
139
|
+
source: `human:${ctx.date} import ${index}`, status: "candidate", supersedes: [],
|
|
140
|
+
tags: ["agent-memory", ...(TAG.test(ctx.agent) ? [ctx.agent] : [])], stack: [],
|
|
141
|
+
body: [...head, "", "## Content", shown, ...tail].join("\n") + "\n",
|
|
142
|
+
};
|
|
143
|
+
}
|