operon-agents-core 0.1.0-alpha.0
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/LICENSE +55 -0
- package/README.md +7 -0
- package/dist/agent/agent.d.ts +65 -0
- package/dist/agent/agent.js +39 -0
- package/dist/agent/compose-hooks.d.ts +13 -0
- package/dist/agent/compose-hooks.js +197 -0
- package/dist/agent/concurrency.d.ts +22 -0
- package/dist/agent/concurrency.js +70 -0
- package/dist/agent/context-report.d.ts +60 -0
- package/dist/agent/context-report.js +45 -0
- package/dist/agent/graph.d.ts +48 -0
- package/dist/agent/graph.js +129 -0
- package/dist/agent/guardrail.d.ts +105 -0
- package/dist/agent/guardrail.js +314 -0
- package/dist/agent/handoff-executor.d.ts +21 -0
- package/dist/agent/handoff-executor.js +95 -0
- package/dist/agent/handoff.d.ts +42 -0
- package/dist/agent/handoff.js +70 -0
- package/dist/agent/index.d.ts +25 -0
- package/dist/agent/index.js +19 -0
- package/dist/agent/instruction-context.d.ts +33 -0
- package/dist/agent/instruction-context.js +100 -0
- package/dist/agent/pause.d.ts +12 -0
- package/dist/agent/pause.js +82 -0
- package/dist/agent/profile-builtins.d.ts +8 -0
- package/dist/agent/profile-builtins.js +130 -0
- package/dist/agent/profiles.d.ts +94 -0
- package/dist/agent/profiles.js +264 -0
- package/dist/agent/recovery.d.ts +10 -0
- package/dist/agent/recovery.js +151 -0
- package/dist/agent/run-support.d.ts +79 -0
- package/dist/agent/run-support.js +211 -0
- package/dist/agent/runner.d.ts +246 -0
- package/dist/agent/runner.js +786 -0
- package/dist/agent/session.d.ts +363 -0
- package/dist/agent/session.js +937 -0
- package/dist/agent/subagent-tools.d.ts +18 -0
- package/dist/agent/subagent-tools.js +650 -0
- package/dist/agent/subagent.d.ts +56 -0
- package/dist/agent/subagent.js +50 -0
- package/dist/agent/toolset.d.ts +24 -0
- package/dist/agent/toolset.js +112 -0
- package/dist/agent/workflow/index.d.ts +9 -0
- package/dist/agent/workflow/index.js +8 -0
- package/dist/agent/workflow/journal.d.ts +180 -0
- package/dist/agent/workflow/journal.js +224 -0
- package/dist/agent/workflow/manager.d.ts +27 -0
- package/dist/agent/workflow/manager.js +33 -0
- package/dist/agent/workflow/parse.d.ts +17 -0
- package/dist/agent/workflow/parse.js +174 -0
- package/dist/agent/workflow/prompt.d.ts +8 -0
- package/dist/agent/workflow/prompt.js +84 -0
- package/dist/agent/workflow/runtime.d.ts +64 -0
- package/dist/agent/workflow/runtime.js +380 -0
- package/dist/agent/workflow/sandbox.d.ts +35 -0
- package/dist/agent/workflow/sandbox.js +90 -0
- package/dist/agent/workflow/snapshot.d.ts +36 -0
- package/dist/agent/workflow/snapshot.js +9 -0
- package/dist/agent/workflow/structured.d.ts +35 -0
- package/dist/agent/workflow/structured.js +79 -0
- package/dist/agent/workflow/tool.d.ts +14 -0
- package/dist/agent/workflow/tool.js +569 -0
- package/dist/agent/workflow/types.d.ts +100 -0
- package/dist/agent/workflow/types.js +17 -0
- package/dist/agent/worktree.d.ts +38 -0
- package/dist/agent/worktree.js +56 -0
- package/dist/capabilities/assembler.d.ts +39 -0
- package/dist/capabilities/assembler.js +171 -0
- package/dist/capabilities/background/agent-task.d.ts +51 -0
- package/dist/capabilities/background/agent-task.js +101 -0
- package/dist/capabilities/background/command-task.d.ts +43 -0
- package/dist/capabilities/background/command-task.js +86 -0
- package/dist/capabilities/background/index.d.ts +20 -0
- package/dist/capabilities/background/index.js +57 -0
- package/dist/capabilities/background/manager.d.ts +194 -0
- package/dist/capabilities/background/manager.js +1131 -0
- package/dist/capabilities/background/persist-disk.d.ts +17 -0
- package/dist/capabilities/background/persist-disk.js +66 -0
- package/dist/capabilities/background/persist.d.ts +61 -0
- package/dist/capabilities/background/persist.js +117 -0
- package/dist/capabilities/background/question-task.d.ts +32 -0
- package/dist/capabilities/background/question-task.js +56 -0
- package/dist/capabilities/background/registrar.d.ts +12 -0
- package/dist/capabilities/background/registrar.js +9 -0
- package/dist/capabilities/background/swappable-sink.d.ts +20 -0
- package/dist/capabilities/background/swappable-sink.js +20 -0
- package/dist/capabilities/background/task.d.ts +114 -0
- package/dist/capabilities/background/task.js +20 -0
- package/dist/capabilities/background/tools.d.ts +6 -0
- package/dist/capabilities/background/tools.js +190 -0
- package/dist/capabilities/background/workflow-task.d.ts +48 -0
- package/dist/capabilities/background/workflow-task.js +91 -0
- package/dist/capabilities/capability-state.d.ts +13 -0
- package/dist/capabilities/capability-state.js +37 -0
- package/dist/capabilities/capability.d.ts +145 -0
- package/dist/capabilities/capability.js +2 -0
- package/dist/capabilities/compaction/full.d.ts +27 -0
- package/dist/capabilities/compaction/full.js +155 -0
- package/dist/capabilities/compaction/index.d.ts +17 -0
- package/dist/capabilities/compaction/index.js +145 -0
- package/dist/capabilities/compaction/instruction.d.ts +2 -0
- package/dist/capabilities/compaction/instruction.js +31 -0
- package/dist/capabilities/compaction/micro.d.ts +17 -0
- package/dist/capabilities/compaction/micro.js +57 -0
- package/dist/capabilities/compaction/service.d.ts +28 -0
- package/dist/capabilities/compaction/service.js +52 -0
- package/dist/capabilities/compaction/strategy.d.ts +43 -0
- package/dist/capabilities/compaction/strategy.js +116 -0
- package/dist/capabilities/compaction/tokens.d.ts +5 -0
- package/dist/capabilities/compaction/tokens.js +28 -0
- package/dist/capabilities/goal/goal-store.d.ts +69 -0
- package/dist/capabilities/goal/goal-store.js +172 -0
- package/dist/capabilities/goal/index.d.ts +6 -0
- package/dist/capabilities/goal/index.js +31 -0
- package/dist/capabilities/goal/injector.d.ts +9 -0
- package/dist/capabilities/goal/injector.js +79 -0
- package/dist/capabilities/goal/tools.d.ts +6 -0
- package/dist/capabilities/goal/tools.js +86 -0
- package/dist/capabilities/index.d.ts +25 -0
- package/dist/capabilities/index.js +22 -0
- package/dist/capabilities/injection.d.ts +44 -0
- package/dist/capabilities/injection.js +112 -0
- package/dist/capabilities/plan/index.d.ts +6 -0
- package/dist/capabilities/plan/index.js +25 -0
- package/dist/capabilities/plan/injector.d.ts +13 -0
- package/dist/capabilities/plan/injector.js +83 -0
- package/dist/capabilities/plan/plan-mode.d.ts +38 -0
- package/dist/capabilities/plan/plan-mode.js +113 -0
- package/dist/capabilities/plan/policies.d.ts +6 -0
- package/dist/capabilities/plan/policies.js +89 -0
- package/dist/capabilities/plan/tools.d.ts +15 -0
- package/dist/capabilities/plan/tools.js +87 -0
- package/dist/capabilities/skills/flow-provider.d.ts +6 -0
- package/dist/capabilities/skills/flow-provider.js +50 -0
- package/dist/capabilities/skills/index.d.ts +43 -0
- package/dist/capabilities/skills/index.js +48 -0
- package/dist/capabilities/skills/injector.d.ts +11 -0
- package/dist/capabilities/skills/injector.js +27 -0
- package/dist/capabilities/skills/parser.d.ts +36 -0
- package/dist/capabilities/skills/parser.js +334 -0
- package/dist/capabilities/skills/registry.d.ts +33 -0
- package/dist/capabilities/skills/registry.js +118 -0
- package/dist/capabilities/skills/scanner.d.ts +26 -0
- package/dist/capabilities/skills/scanner.js +154 -0
- package/dist/capabilities/skills/service.d.ts +39 -0
- package/dist/capabilities/skills/service.js +68 -0
- package/dist/capabilities/skills/skill-tool.d.ts +13 -0
- package/dist/capabilities/skills/skill-tool.js +72 -0
- package/dist/capabilities/skills/types.d.ts +62 -0
- package/dist/capabilities/skills/types.js +26 -0
- package/dist/capabilities/task/index.d.ts +23 -0
- package/dist/capabilities/task/index.js +38 -0
- package/dist/capabilities/task/injector.d.ts +9 -0
- package/dist/capabilities/task/injector.js +62 -0
- package/dist/capabilities/task/persist-disk.d.ts +19 -0
- package/dist/capabilities/task/persist-disk.js +84 -0
- package/dist/capabilities/task/persist.d.ts +52 -0
- package/dist/capabilities/task/persist.js +84 -0
- package/dist/capabilities/task/task-store.d.ts +44 -0
- package/dist/capabilities/task/task-store.js +106 -0
- package/dist/capabilities/task/tools.d.ts +12 -0
- package/dist/capabilities/task/tools.js +164 -0
- package/dist/capabilities/todo/index.d.ts +8 -0
- package/dist/capabilities/todo/index.js +21 -0
- package/dist/capabilities/todo/injector.d.ts +9 -0
- package/dist/capabilities/todo/injector.js +68 -0
- package/dist/capabilities/todo/todo-store.d.ts +19 -0
- package/dist/capabilities/todo/todo-store.js +36 -0
- package/dist/capabilities/todo/tools.d.ts +6 -0
- package/dist/capabilities/todo/tools.js +70 -0
- package/dist/capabilities/tool-provider.d.ts +12 -0
- package/dist/capabilities/tool-provider.js +20 -0
- package/dist/capabilities/user-hooks/engine.d.ts +22 -0
- package/dist/capabilities/user-hooks/engine.js +105 -0
- package/dist/capabilities/user-hooks/index.d.ts +13 -0
- package/dist/capabilities/user-hooks/index.js +126 -0
- package/dist/capabilities/user-hooks/types.d.ts +26 -0
- package/dist/capabilities/user-hooks/types.js +19 -0
- package/dist/capabilities/workflow/index.d.ts +16 -0
- package/dist/capabilities/workflow/index.js +15 -0
- package/dist/commands/index.d.ts +31 -0
- package/dist/commands/index.js +318 -0
- package/dist/config/config-store.d.ts +29 -0
- package/dist/config/config-store.js +103 -0
- package/dist/config/file-source.d.ts +40 -0
- package/dist/config/file-source.js +78 -0
- package/dist/config/flags.d.ts +13 -0
- package/dist/config/flags.js +25 -0
- package/dist/config/index.d.ts +17 -0
- package/dist/config/index.js +10 -0
- package/dist/config/merge.d.ts +5 -0
- package/dist/config/merge.js +57 -0
- package/dist/config/model-catalog.d.ts +17 -0
- package/dist/config/model-catalog.js +37 -0
- package/dist/config/paths.d.ts +31 -0
- package/dist/config/paths.js +28 -0
- package/dist/config/provider-manager.d.ts +57 -0
- package/dist/config/provider-manager.js +344 -0
- package/dist/config/resolver.d.ts +40 -0
- package/dist/config/resolver.js +52 -0
- package/dist/config/schema.d.ts +389 -0
- package/dist/config/schema.js +132 -0
- package/dist/events/events.d.ts +348 -0
- package/dist/events/events.js +146 -0
- package/dist/events/index.d.ts +10 -0
- package/dist/events/index.js +5 -0
- package/dist/events/projection.d.ts +207 -0
- package/dist/events/projection.js +438 -0
- package/dist/events/publisher.d.ts +48 -0
- package/dist/events/publisher.js +404 -0
- package/dist/events/redacting-sink.d.ts +11 -0
- package/dist/events/redacting-sink.js +31 -0
- package/dist/home.d.ts +16 -0
- package/dist/home.js +20 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/internal.d.ts +33 -0
- package/dist/internal.js +29 -0
- package/dist/llm/auth.d.ts +22 -0
- package/dist/llm/auth.js +112 -0
- package/dist/llm/capability.d.ts +13 -0
- package/dist/llm/capability.js +45 -0
- package/dist/llm/define-model.d.ts +110 -0
- package/dist/llm/define-model.js +252 -0
- package/dist/llm/errors.d.ts +33 -0
- package/dist/llm/errors.js +154 -0
- package/dist/llm/index.d.ts +14 -0
- package/dist/llm/index.js +8 -0
- package/dist/llm/model.d.ts +43 -0
- package/dist/llm/model.js +9 -0
- package/dist/llm/retry.d.ts +35 -0
- package/dist/llm/retry.js +160 -0
- package/dist/llm/runtime.d.ts +25 -0
- package/dist/llm/runtime.js +38 -0
- package/dist/logging/diagnostics.d.ts +21 -0
- package/dist/logging/diagnostics.js +46 -0
- package/dist/logging/index.d.ts +11 -0
- package/dist/logging/index.js +7 -0
- package/dist/logging/logger.d.ts +25 -0
- package/dist/logging/logger.js +54 -0
- package/dist/logging/paths.d.ts +11 -0
- package/dist/logging/paths.js +20 -0
- package/dist/logging/policy.d.ts +5 -0
- package/dist/logging/policy.js +19 -0
- package/dist/logging/redact.d.ts +10 -0
- package/dist/logging/redact.js +95 -0
- package/dist/logging/sinks.d.ts +67 -0
- package/dist/logging/sinks.js +117 -0
- package/dist/loop/context.d.ts +69 -0
- package/dist/loop/context.js +129 -0
- package/dist/loop/errors.d.ts +8 -0
- package/dist/loop/errors.js +27 -0
- package/dist/loop/events.d.ts +14 -0
- package/dist/loop/events.js +2 -0
- package/dist/loop/index.d.ts +10 -0
- package/dist/loop/index.js +7 -0
- package/dist/loop/interruption.d.ts +118 -0
- package/dist/loop/interruption.js +191 -0
- package/dist/loop/run-turn.d.ts +54 -0
- package/dist/loop/run-turn.js +203 -0
- package/dist/loop/scheduler.d.ts +18 -0
- package/dist/loop/scheduler.js +71 -0
- package/dist/loop/steer.d.ts +122 -0
- package/dist/loop/steer.js +209 -0
- package/dist/loop/tool-call.d.ts +41 -0
- package/dist/loop/tool-call.js +326 -0
- package/dist/loop/turn-step.d.ts +57 -0
- package/dist/loop/turn-step.js +298 -0
- package/dist/loop/types.d.ts +217 -0
- package/dist/loop/types.js +2 -0
- package/dist/loop/usage.d.ts +6 -0
- package/dist/loop/usage.js +44 -0
- package/dist/mcp/auth-tool.d.ts +12 -0
- package/dist/mcp/auth-tool.js +92 -0
- package/dist/mcp/capability.d.ts +7 -0
- package/dist/mcp/capability.js +91 -0
- package/dist/mcp/config-loader.d.ts +28 -0
- package/dist/mcp/config-loader.js +115 -0
- package/dist/mcp/filter.d.ts +18 -0
- package/dist/mcp/filter.js +35 -0
- package/dist/mcp/index.d.ts +23 -0
- package/dist/mcp/index.js +13 -0
- package/dist/mcp/manager.d.ts +51 -0
- package/dist/mcp/manager.js +412 -0
- package/dist/mcp/mock-transport.d.ts +40 -0
- package/dist/mcp/mock-transport.js +68 -0
- package/dist/mcp/oauth/callback-server.d.ts +14 -0
- package/dist/mcp/oauth/callback-server.js +122 -0
- package/dist/mcp/oauth/index.d.ts +9 -0
- package/dist/mcp/oauth/index.js +5 -0
- package/dist/mcp/oauth/provider.d.ts +39 -0
- package/dist/mcp/oauth/provider.js +121 -0
- package/dist/mcp/oauth/service.d.ts +34 -0
- package/dist/mcp/oauth/service.js +130 -0
- package/dist/mcp/oauth/store.d.ts +40 -0
- package/dist/mcp/oauth/store.js +134 -0
- package/dist/mcp/output.d.ts +12 -0
- package/dist/mcp/output.js +110 -0
- package/dist/mcp/provider.d.ts +7 -0
- package/dist/mcp/provider.js +56 -0
- package/dist/mcp/sdk-transport.d.ts +25 -0
- package/dist/mcp/sdk-transport.js +228 -0
- package/dist/mcp/server.d.ts +77 -0
- package/dist/mcp/server.js +120 -0
- package/dist/mcp/tool-naming.d.ts +4 -0
- package/dist/mcp/tool-naming.js +26 -0
- package/dist/mcp/types.d.ts +75 -0
- package/dist/mcp/types.js +2 -0
- package/dist/net/index.d.ts +3 -0
- package/dist/net/index.js +2 -0
- package/dist/net/proxy.d.ts +16 -0
- package/dist/net/proxy.js +42 -0
- package/dist/permission/auto-approver/index.d.ts +3 -0
- package/dist/permission/auto-approver/index.js +3 -0
- package/dist/permission/auto-approver/llm-auto-approver.d.ts +53 -0
- package/dist/permission/auto-approver/llm-auto-approver.js +122 -0
- package/dist/permission/auto-approver/prompts-data.d.ts +9 -0
- package/dist/permission/auto-approver/prompts-data.js +155 -0
- package/dist/permission/auto-approver/prompts.d.ts +18 -0
- package/dist/permission/auto-approver/prompts.js +40 -0
- package/dist/permission/auto-approver/transcript.d.ts +22 -0
- package/dist/permission/auto-approver/transcript.js +75 -0
- package/dist/permission/auto-approver/xml.d.ts +5 -0
- package/dist/permission/auto-approver/xml.js +25 -0
- package/dist/permission/index.d.ts +7 -0
- package/dist/permission/index.js +5 -0
- package/dist/permission/manager.d.ts +74 -0
- package/dist/permission/manager.js +162 -0
- package/dist/permission/matches-rule.d.ts +27 -0
- package/dist/permission/matches-rule.js +54 -0
- package/dist/permission/policies.d.ts +14 -0
- package/dist/permission/policies.js +233 -0
- package/dist/permission/types.d.ts +84 -0
- package/dist/permission/types.js +2 -0
- package/dist/plugins/archive.d.ts +3 -0
- package/dist/plugins/archive.js +58 -0
- package/dist/plugins/github-resolver.d.ts +13 -0
- package/dist/plugins/github-resolver.js +20 -0
- package/dist/plugins/hooks.d.ts +28 -0
- package/dist/plugins/hooks.js +296 -0
- package/dist/plugins/index.d.ts +23 -0
- package/dist/plugins/index.js +23 -0
- package/dist/plugins/injector.d.ts +11 -0
- package/dist/plugins/injector.js +32 -0
- package/dist/plugins/manager.d.ts +37 -0
- package/dist/plugins/manager.js +330 -0
- package/dist/plugins/manifest.d.ts +9 -0
- package/dist/plugins/manifest.js +234 -0
- package/dist/plugins/marketplace.d.ts +85 -0
- package/dist/plugins/marketplace.js +205 -0
- package/dist/plugins/source.d.ts +23 -0
- package/dist/plugins/source.js +87 -0
- package/dist/plugins/store.d.ts +20 -0
- package/dist/plugins/store.js +30 -0
- package/dist/plugins/types.d.ts +118 -0
- package/dist/plugins/types.js +5 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.js +2 -0
- package/dist/protocol/tool-schema.d.ts +6 -0
- package/dist/protocol/tool-schema.js +2 -0
- package/dist/store/blob-store.d.ts +45 -0
- package/dist/store/blob-store.js +120 -0
- package/dist/store/catalog-store.d.ts +32 -0
- package/dist/store/catalog-store.js +73 -0
- package/dist/store/disk-store.d.ts +58 -0
- package/dist/store/disk-store.js +369 -0
- package/dist/store/index.d.ts +23 -0
- package/dist/store/index.js +15 -0
- package/dist/store/lock.d.ts +86 -0
- package/dist/store/lock.js +104 -0
- package/dist/store/log-store.d.ts +89 -0
- package/dist/store/log-store.js +296 -0
- package/dist/store/migrate.d.ts +26 -0
- package/dist/store/migrate.js +32 -0
- package/dist/store/origin.d.ts +89 -0
- package/dist/store/origin.js +16 -0
- package/dist/store/pg.d.ts +90 -0
- package/dist/store/pg.js +344 -0
- package/dist/store/redacting-store.d.ts +21 -0
- package/dist/store/redacting-store.js +46 -0
- package/dist/store/redis.d.ts +89 -0
- package/dist/store/redis.js +370 -0
- package/dist/store/repository.d.ts +150 -0
- package/dist/store/repository.js +508 -0
- package/dist/store/session-catalog.d.ts +32 -0
- package/dist/store/session-catalog.js +117 -0
- package/dist/store/storage.d.ts +27 -0
- package/dist/store/storage.js +54 -0
- package/dist/store/store.d.ts +262 -0
- package/dist/store/store.js +129 -0
- package/dist/store/workdir-key.d.ts +4 -0
- package/dist/store/workdir-key.js +28 -0
- package/dist/tool/access.d.ts +37 -0
- package/dist/tool/access.js +79 -0
- package/dist/tool/ask.d.ts +22 -0
- package/dist/tool/ask.js +38 -0
- package/dist/tool/background.d.ts +109 -0
- package/dist/tool/background.js +39 -0
- package/dist/tool/builtin/ask-user-question.d.ts +2 -0
- package/dist/tool/builtin/ask-user-question.js +175 -0
- package/dist/tool/builtin/bash.d.ts +2 -0
- package/dist/tool/builtin/bash.js +407 -0
- package/dist/tool/builtin/edit.d.ts +2 -0
- package/dist/tool/builtin/edit.js +202 -0
- package/dist/tool/builtin/glob.d.ts +3 -0
- package/dist/tool/builtin/glob.js +260 -0
- package/dist/tool/builtin/grep.d.ts +2 -0
- package/dist/tool/builtin/grep.js +574 -0
- package/dist/tool/builtin/line-endings.d.ts +10 -0
- package/dist/tool/builtin/line-endings.js +41 -0
- package/dist/tool/builtin/read.d.ts +28 -0
- package/dist/tool/builtin/read.js +498 -0
- package/dist/tool/builtin/write.d.ts +2 -0
- package/dist/tool/builtin/write.js +179 -0
- package/dist/tool/define.d.ts +46 -0
- package/dist/tool/define.js +45 -0
- package/dist/tool/file-freshness.d.ts +81 -0
- package/dist/tool/file-freshness.js +67 -0
- package/dist/tool/filesystem-tools.d.ts +16 -0
- package/dist/tool/filesystem-tools.js +19 -0
- package/dist/tool/git-context.d.ts +20 -0
- package/dist/tool/git-context.js +114 -0
- package/dist/tool/index.d.ts +37 -0
- package/dist/tool/index.js +34 -0
- package/dist/tool/machine-base.d.ts +138 -0
- package/dist/tool/machine-base.js +388 -0
- package/dist/tool/machine-local.d.ts +35 -0
- package/dist/tool/machine-local.js +316 -0
- package/dist/tool/machine-null.d.ts +36 -0
- package/dist/tool/machine-null.js +64 -0
- package/dist/tool/machine-ssh.d.ts +86 -0
- package/dist/tool/machine-ssh.js +576 -0
- package/dist/tool/machine.d.ts +333 -0
- package/dist/tool/machine.js +15 -0
- package/dist/tool/policies/path-access.d.ts +48 -0
- package/dist/tool/policies/path-access.js +186 -0
- package/dist/tool/policies/sensitive.d.ts +3 -0
- package/dist/tool/policies/sensitive.js +60 -0
- package/dist/tool/questions.d.ts +40 -0
- package/dist/tool/questions.js +8 -0
- package/dist/tool/search/activation.d.ts +13 -0
- package/dist/tool/search/activation.js +31 -0
- package/dist/tool/search/deferral.d.ts +37 -0
- package/dist/tool/search/deferral.js +128 -0
- package/dist/tool/search/search-tool.d.ts +9 -0
- package/dist/tool/search/search-tool.js +62 -0
- package/dist/tool/shell-env.d.ts +9 -0
- package/dist/tool/shell-env.js +34 -0
- package/dist/tool/support/bash-destructive.d.ts +24 -0
- package/dist/tool/support/bash-destructive.js +63 -0
- package/dist/tool/support/bash-paths.d.ts +7 -0
- package/dist/tool/support/bash-paths.js +247 -0
- package/dist/tool/support/bash-read-only.d.ts +8 -0
- package/dist/tool/support/bash-read-only.js +165 -0
- package/dist/tool/support/bash-rule-match.d.ts +20 -0
- package/dist/tool/support/bash-rule-match.js +191 -0
- package/dist/tool/support/file-type.d.ts +10 -0
- package/dist/tool/support/file-type.js +149 -0
- package/dist/tool/support/git-worktree.d.ts +10 -0
- package/dist/tool/support/git-worktree.js +63 -0
- package/dist/tool/support/image-compress.d.ts +69 -0
- package/dist/tool/support/image-compress.js +265 -0
- package/dist/tool/support/machine-ops.d.ts +34 -0
- package/dist/tool/support/machine-ops.js +34 -0
- package/dist/tool/support/path-glob-match.d.ts +12 -0
- package/dist/tool/support/path-glob-match.js +84 -0
- package/dist/tool/support/result-builder.d.ts +27 -0
- package/dist/tool/support/result-builder.js +108 -0
- package/dist/tool/support/rg-locator.d.ts +20 -0
- package/dist/tool/support/rg-locator.js +42 -0
- package/dist/tool/support/ripgrep-run.d.ts +65 -0
- package/dist/tool/support/ripgrep-run.js +40 -0
- package/dist/tool/support/rule-match.d.ts +6 -0
- package/dist/tool/support/rule-match.js +23 -0
- package/dist/tool/support/tool-path.d.ts +8 -0
- package/dist/tool/support/tool-path.js +28 -0
- package/dist/tool/support/workspace.d.ts +5 -0
- package/dist/tool/support/workspace.js +2 -0
- package/dist/tool/types.d.ts +131 -0
- package/dist/tool/types.js +2 -0
- package/dist/tool/web/fetch-url.d.ts +4 -0
- package/dist/tool/web/fetch-url.js +61 -0
- package/dist/tool/web/index.d.ts +11 -0
- package/dist/tool/web/index.js +7 -0
- package/dist/tool/web/providers/direct-fetch.d.ts +33 -0
- package/dist/tool/web/providers/direct-fetch.js +198 -0
- package/dist/tool/web/providers/firecrawl.d.ts +16 -0
- package/dist/tool/web/providers/firecrawl.js +59 -0
- package/dist/tool/web/providers/tavily.d.ts +14 -0
- package/dist/tool/web/providers/tavily.js +43 -0
- package/dist/tool/web/types.d.ts +41 -0
- package/dist/tool/web/types.js +7 -0
- package/dist/tool/web/web-search.d.ts +4 -0
- package/dist/tool/web/web-search.js +68 -0
- package/dist/tool/workspace-spec.d.ts +74 -0
- package/dist/tool/workspace-spec.js +177 -0
- package/dist/tracing/bridge.d.ts +7 -0
- package/dist/tracing/bridge.js +171 -0
- package/dist/tracing/index.d.ts +9 -0
- package/dist/tracing/index.js +5 -0
- package/dist/tracing/otel.d.ts +38 -0
- package/dist/tracing/otel.js +221 -0
- package/dist/tracing/processor.d.ts +47 -0
- package/dist/tracing/processor.js +94 -0
- package/dist/tracing/spans.d.ts +94 -0
- package/dist/tracing/spans.js +56 -0
- package/dist/ui/ai-sdk.d.ts +114 -0
- package/dist/ui/ai-sdk.js +175 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.js +2 -0
- package/package.json +101 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { logDataPolicy, noopLogger } from "../../logging/index.js";
|
|
2
|
+
import { summaryMessage } from "../../loop/context.js";
|
|
3
|
+
import { systemReminder } from "../injection.js";
|
|
4
|
+
import { compactionInstruction } from "./instruction.js";
|
|
5
|
+
import { estimateTokens, estimateTokensForMessages } from "./tokens.js";
|
|
6
|
+
export const MAX_COMPACTION_RETRY_ATTEMPTS = 5;
|
|
7
|
+
export async function runFullCompaction(deps) {
|
|
8
|
+
const { messages, strategy } = deps;
|
|
9
|
+
const logger = deps.logger ?? noopLogger;
|
|
10
|
+
const initialCount = strategy.computeCompactCount(messages);
|
|
11
|
+
if (initialCount === 0)
|
|
12
|
+
return 0;
|
|
13
|
+
// Ask before acting. Compaction is self-initiated, so this is the only chance another
|
|
14
|
+
// capability gets to veto it or to supply the summary itself.
|
|
15
|
+
const verdict = await consultGates(deps, initialCount);
|
|
16
|
+
if (verdict?.cancel === true) {
|
|
17
|
+
logger.log("debug", "compaction cancelled by a capability gate", { count: initialCount });
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
const tokensBefore = estimateTokensForMessages(messages);
|
|
21
|
+
const trigger = deps.trigger ?? "auto";
|
|
22
|
+
logger.log("debug", "compaction start", { trigger, count: initialCount, tokensBefore });
|
|
23
|
+
deps.emit?.({ type: "compaction.started", trigger, instruction: deps.customInstruction });
|
|
24
|
+
const { summary, count } = verdict?.replacement
|
|
25
|
+
? { summary: verdict.replacement.summary, count: clampCount(verdict.replacement.count ?? initialCount, messages.length) }
|
|
26
|
+
: await summarize(deps, initialCount);
|
|
27
|
+
// Token estimate of the post-splice list (summary + kept tail), before mutating.
|
|
28
|
+
const tokensAfter = estimateTokensForMessages([summaryMessage(summary), ...messages.slice(count)]);
|
|
29
|
+
// Replace the oldest `count` messages with one summary AND append the compaction entry, in order —
|
|
30
|
+
// one journaled operation, mirrored by replay's applyCompaction.
|
|
31
|
+
deps.context.applyCompaction({ summary, compactedCount: count, tokensBefore, tokensAfter });
|
|
32
|
+
// Rebuild reminders whose prior append-only copies were removed by compaction.
|
|
33
|
+
deps.injection?.onContextCompacted(count);
|
|
34
|
+
if (deps.injection) {
|
|
35
|
+
deps.injection.runAtTurnBoundary({
|
|
36
|
+
history: messages,
|
|
37
|
+
sessionId: deps.sessionId,
|
|
38
|
+
address: deps.address,
|
|
39
|
+
originOf: (message) => deps.context.originOf(message),
|
|
40
|
+
}, (result, injectorId) => {
|
|
41
|
+
const message = {
|
|
42
|
+
role: "user",
|
|
43
|
+
content: [{ type: "text", text: systemReminder(result.text) }],
|
|
44
|
+
timestamp: Date.now(),
|
|
45
|
+
};
|
|
46
|
+
deps.context.appendMessage(message, {
|
|
47
|
+
kind: "injection",
|
|
48
|
+
injectorId,
|
|
49
|
+
variant: result.variant ?? injectorId,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
logger.log("debug", "compaction done", { trigger, tokensBefore, tokensAfter, compactedCount: count });
|
|
54
|
+
deps.emit?.({ type: "compaction.completed", tokensBefore, tokensAfter, compactedCount: count });
|
|
55
|
+
return count;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Run every registered compaction gate in order. First `cancel` wins and stops the pass; first
|
|
59
|
+
* `replacement` wins and is used verbatim. A gate that throws is skipped — a broken arbiter must
|
|
60
|
+
* not be able to wedge compaction shut, or the context would grow until the window blows.
|
|
61
|
+
*/
|
|
62
|
+
async function consultGates(deps, compactCount) {
|
|
63
|
+
const gates = deps.gates ?? [];
|
|
64
|
+
if (gates.length === 0)
|
|
65
|
+
return undefined;
|
|
66
|
+
const logger = deps.logger ?? noopLogger;
|
|
67
|
+
let replacement;
|
|
68
|
+
for (const gate of gates) {
|
|
69
|
+
let result;
|
|
70
|
+
try {
|
|
71
|
+
result = await gate({
|
|
72
|
+
reason: deps.trigger === "manual" ? "manual" : "auto",
|
|
73
|
+
messages: deps.messages,
|
|
74
|
+
compactCount,
|
|
75
|
+
signal: deps.signal,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
logger.log("warn", "compaction gate failed; ignored", {
|
|
80
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
81
|
+
});
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (result?.cancel === true)
|
|
85
|
+
return { cancel: true };
|
|
86
|
+
if (result?.replacement !== undefined && replacement === undefined)
|
|
87
|
+
replacement = result.replacement;
|
|
88
|
+
}
|
|
89
|
+
return replacement ? { replacement } : undefined;
|
|
90
|
+
}
|
|
91
|
+
/** A gate-supplied count must still be a valid splice point, or `applyCompaction` corrupts history. */
|
|
92
|
+
function clampCount(count, total) {
|
|
93
|
+
if (!Number.isInteger(count) || count < 1)
|
|
94
|
+
return 1;
|
|
95
|
+
return Math.min(count, total);
|
|
96
|
+
}
|
|
97
|
+
async function summarize(deps, initialCount) {
|
|
98
|
+
const logger = deps.logger ?? noopLogger;
|
|
99
|
+
const instruction = compactionInstruction(deps.customInstruction);
|
|
100
|
+
let count = initialCount;
|
|
101
|
+
let attempt = 0;
|
|
102
|
+
while (true) {
|
|
103
|
+
deps.signal.throwIfAborted();
|
|
104
|
+
const prefix = deps.messages.slice(0, count);
|
|
105
|
+
const request = {
|
|
106
|
+
system: deps.system,
|
|
107
|
+
messages: [...prefix, instructionUserMessage(instruction)],
|
|
108
|
+
tools: undefined,
|
|
109
|
+
};
|
|
110
|
+
logger.log("debug", "compaction llm request", logDataPolicy.dontLogModelData
|
|
111
|
+
? { model: deps.model.id, attempt, count, messages: request.messages.length }
|
|
112
|
+
: { model: deps.model.id, attempt, count, system: request.system, messages: request.messages });
|
|
113
|
+
let summaryText = "";
|
|
114
|
+
let truncatedOrError = false;
|
|
115
|
+
try {
|
|
116
|
+
const message = await deps.model.complete(request, { signal: deps.signal });
|
|
117
|
+
if (message.stopReason === "error")
|
|
118
|
+
throw new Error(message.errorMessage ?? "compaction stream error");
|
|
119
|
+
summaryText = textOf(message);
|
|
120
|
+
if (message.stopReason === "length" || summaryText.trim().length === 0)
|
|
121
|
+
truncatedOrError = true;
|
|
122
|
+
logger.log("debug", "compaction llm response", logDataPolicy.dontLogModelData
|
|
123
|
+
? { model: deps.model.id, attempt, stopReason: message.stopReason, truncatedOrError, usage: message.usage }
|
|
124
|
+
: { model: deps.model.id, attempt, stopReason: message.stopReason, truncatedOrError, summary: summaryText, usage: message.usage });
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (deps.signal.aborted)
|
|
128
|
+
throw error;
|
|
129
|
+
truncatedOrError = true;
|
|
130
|
+
logger.log("warn", "compaction llm error", { model: deps.model.id, attempt, reason: error instanceof Error ? error.message : String(error) });
|
|
131
|
+
}
|
|
132
|
+
if (!truncatedOrError)
|
|
133
|
+
return { summary: summaryText, count };
|
|
134
|
+
attempt += 1;
|
|
135
|
+
if (attempt >= MAX_COMPACTION_RETRY_ATTEMPTS) {
|
|
136
|
+
throw new Error("Compaction failed to produce a complete summary after retries.");
|
|
137
|
+
}
|
|
138
|
+
// Truncated/overflowed → compact a bit more and retry (compact-and-retry, not #8).
|
|
139
|
+
const nextCount = deps.strategy.reduceCompactOnOverflow(deps.messages.slice(0, count));
|
|
140
|
+
logger.log("warn", "compaction retry", { attempt, maxAttempts: MAX_COMPACTION_RETRY_ATTEMPTS, count, nextCount });
|
|
141
|
+
count = nextCount;
|
|
142
|
+
if (count === 0)
|
|
143
|
+
throw new Error("Compaction could not reduce the prefix further.");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function instructionUserMessage(text) {
|
|
147
|
+
return { role: "user", content: [{ type: "text", text }], timestamp: Date.now() };
|
|
148
|
+
}
|
|
149
|
+
function textOf(message) {
|
|
150
|
+
return message.content
|
|
151
|
+
.filter((p) => p.type === "text")
|
|
152
|
+
.map((p) => p.text)
|
|
153
|
+
.join("");
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=full.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Capability } from "../capability.ts";
|
|
2
|
+
import { type CompactionConfig } from "./strategy.ts";
|
|
3
|
+
import { type MicroCompactionConfig } from "./micro.ts";
|
|
4
|
+
export { CompactionStrategy, DEFAULT_COMPACTION_CONFIG } from "./strategy.ts";
|
|
5
|
+
export type { CompactionConfig } from "./strategy.ts";
|
|
6
|
+
export { MicroCompaction } from "./micro.ts";
|
|
7
|
+
export { estimateTokens, estimateTokensForMessages } from "./tokens.ts";
|
|
8
|
+
export { CompactionService } from "./service.ts";
|
|
9
|
+
export type { CompactRequestOptions, PendingCompaction } from "./service.ts";
|
|
10
|
+
export interface CompactionOptions {
|
|
11
|
+
readonly maxContextTokens: number;
|
|
12
|
+
readonly config?: Partial<CompactionConfig>;
|
|
13
|
+
readonly micro?: boolean | Partial<MicroCompactionConfig>;
|
|
14
|
+
readonly customInstruction?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function compactionCapability(options: CompactionOptions): Capability;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { APIContextOverflowError } from "../../llm/errors.js";
|
|
2
|
+
import { noopLogger } from "../../logging/index.js";
|
|
3
|
+
import { CompactionStrategy, DEFAULT_COMPACTION_CONFIG } from "./strategy.js";
|
|
4
|
+
import { MicroCompaction } from "./micro.js";
|
|
5
|
+
import { runFullCompaction } from "./full.js";
|
|
6
|
+
import { estimateTokensForMessages } from "./tokens.js";
|
|
7
|
+
import { CompactionService } from "./service.js";
|
|
8
|
+
export { CompactionStrategy, DEFAULT_COMPACTION_CONFIG } from "./strategy.js";
|
|
9
|
+
export { MicroCompaction } from "./micro.js";
|
|
10
|
+
export { estimateTokens, estimateTokensForMessages } from "./tokens.js";
|
|
11
|
+
export { CompactionService } from "./service.js";
|
|
12
|
+
/** Consecutive auto-compaction failures before we stop trying for the rest of the session. A
|
|
13
|
+
* context that is irrecoverably over the limit otherwise re-attempts a doomed summary on every
|
|
14
|
+
* single step, burning a model call each time and never making progress. */
|
|
15
|
+
const MAX_CONSECUTIVE_FAILURES = 3;
|
|
16
|
+
export function compactionCapability(options) {
|
|
17
|
+
const mergedConfig = {
|
|
18
|
+
...DEFAULT_COMPACTION_CONFIG,
|
|
19
|
+
...options.config,
|
|
20
|
+
};
|
|
21
|
+
// The active model — hence its output limit — is only known once a step runs, so the strategy
|
|
22
|
+
// reads it through a provider that each hook refreshes.
|
|
23
|
+
let maxOutputTokens = 0;
|
|
24
|
+
const strategy = new CompactionStrategy(() => options.maxContextTokens, () => maxOutputTokens, mergedConfig);
|
|
25
|
+
const micro = options.micro
|
|
26
|
+
? new MicroCompaction(typeof options.micro === "object" ? options.micro : {})
|
|
27
|
+
: null;
|
|
28
|
+
const service = new CompactionService(() => strategy.reservedTokens);
|
|
29
|
+
let injection;
|
|
30
|
+
// Live reference from the assembler: reading it at compact() time (not at start()) means gates
|
|
31
|
+
// from capabilities ordered after this one are still seen.
|
|
32
|
+
let gates;
|
|
33
|
+
let events;
|
|
34
|
+
let logger = noopLogger;
|
|
35
|
+
let sessionId = "";
|
|
36
|
+
let lastAssistantAtMs = Date.now();
|
|
37
|
+
let consecutiveFailures = 0;
|
|
38
|
+
const compact = async (ctx, request) => {
|
|
39
|
+
const address = ctx.context.address;
|
|
40
|
+
const isManual = request !== undefined;
|
|
41
|
+
// Circuit breaker applies to automatic compaction only — an explicit /compact is the user
|
|
42
|
+
// asking again on purpose, and it gets a real attempt (and a real error) every time.
|
|
43
|
+
if (!isManual && consecutiveFailures >= MAX_CONSECUTIVE_FAILURES)
|
|
44
|
+
return 0;
|
|
45
|
+
try {
|
|
46
|
+
const count = await runFullCompaction({
|
|
47
|
+
messages: ctx.messages,
|
|
48
|
+
context: ctx.context,
|
|
49
|
+
model: ctx.model,
|
|
50
|
+
system: ctx.system,
|
|
51
|
+
signal: ctx.signal,
|
|
52
|
+
strategy,
|
|
53
|
+
customInstruction: request?.instruction ?? options.customInstruction,
|
|
54
|
+
trigger: isManual ? "manual" : "auto",
|
|
55
|
+
sessionId,
|
|
56
|
+
injection,
|
|
57
|
+
address,
|
|
58
|
+
gates,
|
|
59
|
+
emit: (body) => {
|
|
60
|
+
events?.emit({ ...body, address, sessionId });
|
|
61
|
+
},
|
|
62
|
+
logger,
|
|
63
|
+
});
|
|
64
|
+
if (count > 0)
|
|
65
|
+
service.recordCompleted();
|
|
66
|
+
consecutiveFailures = 0;
|
|
67
|
+
return count;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
// An abort is the user stopping the turn, not a compaction that can't succeed: propagate
|
|
71
|
+
// it untouched and don't count it against the breaker.
|
|
72
|
+
if (ctx.signal.aborted)
|
|
73
|
+
throw error;
|
|
74
|
+
// A manual request must surface its failure — swallowing it makes /compact look like a
|
|
75
|
+
// no-op. Automatic compaction degrades instead: the step proceeds uncompacted.
|
|
76
|
+
if (isManual)
|
|
77
|
+
throw error;
|
|
78
|
+
consecutiveFailures += 1;
|
|
79
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
80
|
+
logger.log("warn", "compaction failed", { reason, consecutiveFailures });
|
|
81
|
+
if (consecutiveFailures >= MAX_CONSECUTIVE_FAILURES) {
|
|
82
|
+
logger.log("warn", "compaction circuit breaker tripped — skipping automatic compaction for this session", {
|
|
83
|
+
consecutiveFailures,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
name: "compaction",
|
|
91
|
+
service,
|
|
92
|
+
hooks: {
|
|
93
|
+
beforeStep: async (ctx) => {
|
|
94
|
+
maxOutputTokens = ctx.model.maxOutputTokens;
|
|
95
|
+
const manual = service.consume();
|
|
96
|
+
if (manual !== null)
|
|
97
|
+
await compact(ctx, manual);
|
|
98
|
+
if (micro) {
|
|
99
|
+
// Truncate on a copy and commit through the journaled mutator. The previous
|
|
100
|
+
// in-place edit of the live array bypassed the journal, so a replay would
|
|
101
|
+
// resurrect every tool result micro-compaction had cleared.
|
|
102
|
+
const trimmed = [...ctx.messages];
|
|
103
|
+
if (micro.detectAndApply(trimmed, lastAssistantAtMs, options.maxContextTokens) > 0) {
|
|
104
|
+
ctx.context.replaceHistory(trimmed);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (strategy.shouldBlock(estimateTokensForMessages(ctx.messages))) {
|
|
108
|
+
await compact(ctx);
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
},
|
|
112
|
+
afterStep: async (ctx) => {
|
|
113
|
+
maxOutputTokens = ctx.model.maxOutputTokens;
|
|
114
|
+
lastAssistantAtMs = Date.now();
|
|
115
|
+
if (strategy.checkAfterStep && strategy.shouldCompact(estimateTokensForMessages(ctx.messages))) {
|
|
116
|
+
await compact(ctx);
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
},
|
|
120
|
+
// Reactive overflow recovery: the API rejected the request as too large, so the
|
|
121
|
+
// threshold check is skipped — the provider is ground truth and the estimate simply
|
|
122
|
+
// under-counted. The circuit breaker still applies (compact() returns 0 when tripped),
|
|
123
|
+
// and a compaction that made no progress does NOT claim: the turn then fails exactly
|
|
124
|
+
// as it would have without this hook.
|
|
125
|
+
recoverStepError: async (ctx) => {
|
|
126
|
+
if (!(ctx.error instanceof APIContextOverflowError))
|
|
127
|
+
return undefined;
|
|
128
|
+
maxOutputTokens = ctx.model.maxOutputTokens;
|
|
129
|
+
const compacted = await compact(ctx);
|
|
130
|
+
if (compacted <= 0)
|
|
131
|
+
return undefined;
|
|
132
|
+
return { recovered: true };
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
start: (ctx) => {
|
|
136
|
+
injection = ctx.injection;
|
|
137
|
+
gates = ctx.gates?.compaction;
|
|
138
|
+
events = ctx.events;
|
|
139
|
+
logger = ctx.logger ?? noopLogger;
|
|
140
|
+
sessionId = ctx.sessionId;
|
|
141
|
+
lastAssistantAtMs = Date.now();
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function compactionInstruction(customInstruction = "") {
|
|
2
|
+
const base = `Your context is being compacted. Summarize the conversation ABOVE into a single, self-contained briefing so work can continue from it without losing essential state. Be concrete and faithful; do not invent. Write the briefing in the same language the conversation has been using — do not switch to English just because these instructions are in English. Use these sections (omit a section only if truly empty):
|
|
3
|
+
|
|
4
|
+
## Current Focus & Forward Plan
|
|
5
|
+
The task in progress right now, then the plan the next turn will follow — and this is the moment to invest in it. Right now you hold more context on this task than you ever will again; the next turn resumes with less, so the plan you commit here is the one it will follow. Give the exact next command or tool call, but don't stop at the next step: set out the remaining sequence to finish, the decisions you have already made for those upcoming steps (so the next turn doesn't reopen them), the obstacles or edge cases you can already foresee and how you mean to handle them, and any work you can commit to now — the exact patch, query, or shape of the final answer you already know you will produce. Include any required format for the final answer.
|
|
6
|
+
|
|
7
|
+
## Environment
|
|
8
|
+
Working directory, key paths, tools/commands, versions, and config that matter.
|
|
9
|
+
|
|
10
|
+
## Completed Tasks
|
|
11
|
+
What has already been done, at high fidelity: the exact commands run, the exact file paths touched, and whether each succeeded or failed — with the concrete results themselves (values returned, key lines or error text, the schema or signature a lookup revealed), not just the commands, since re-running to recover them may be slow or impossible. Keep only the final working version of any code; drop intermediate attempts and already-resolved errors.
|
|
12
|
+
|
|
13
|
+
## Active Issues
|
|
14
|
+
Open problems, errors seen, and anything still failing or unverified. Be honest about uncertainty: if an earlier step claimed something was done but was never verified (tests "passing", a fix "working", a file "created"), say so plainly and treat it as unverified rather than fact.
|
|
15
|
+
|
|
16
|
+
## Unknowns
|
|
17
|
+
Context the next step depends on that this conversation never established — files or paths referenced but not yet read, schemas or APIs assumed but unseen, questions the user has not answered. Name these gaps so the next turn goes and checks them instead of assuming.
|
|
18
|
+
|
|
19
|
+
## Code State
|
|
20
|
+
Files created/modified and their current state — for each critical file, its path and what it now contains or how it changed.
|
|
21
|
+
|
|
22
|
+
## Important Context
|
|
23
|
+
Decisions made and their rationale, constraints, user preferences, and anything non-obvious needed to continue.
|
|
24
|
+
|
|
25
|
+
## All User Messages
|
|
26
|
+
A faithful list of every distinct request/instruction the user gave, in order, so no user intent is lost.
|
|
27
|
+
|
|
28
|
+
Output ONLY the summary in the sections above. Do not call any tools.`;
|
|
29
|
+
return customInstruction.trim().length > 0 ? `${base}\n\nAdditional instruction: ${customInstruction.trim()}` : base;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=instruction.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Message } from "../../protocol/index.ts";
|
|
2
|
+
export interface MicroCompactionConfig {
|
|
3
|
+
readonly keepRecentMessages: number;
|
|
4
|
+
readonly minContentTokens: number;
|
|
5
|
+
readonly cacheMissedThresholdMs: number;
|
|
6
|
+
readonly truncatedMarker: string;
|
|
7
|
+
readonly minContextUsageRatio: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const DEFAULT_MICRO_CONFIG: MicroCompactionConfig;
|
|
10
|
+
export declare class MicroCompaction {
|
|
11
|
+
private cutoff;
|
|
12
|
+
readonly config: MicroCompactionConfig;
|
|
13
|
+
constructor(config?: Partial<MicroCompactionConfig>);
|
|
14
|
+
detectAndApply(messages: Message[], lastAssistantAtMs: number, maxContextTokens: number): number;
|
|
15
|
+
private clearOld;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=micro.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export const DEFAULT_MICRO_CONFIG = {
|
|
2
|
+
keepRecentMessages: 20,
|
|
3
|
+
minContentTokens: 100,
|
|
4
|
+
cacheMissedThresholdMs: 60 * 60 * 1000,
|
|
5
|
+
truncatedMarker: "[Old tool result content cleared]",
|
|
6
|
+
minContextUsageRatio: 0.5,
|
|
7
|
+
};
|
|
8
|
+
function contentTokens(message) {
|
|
9
|
+
let chars = 0;
|
|
10
|
+
for (const part of message.content) {
|
|
11
|
+
if (typeof part === "string")
|
|
12
|
+
chars += part.length;
|
|
13
|
+
else if (part.type === "text")
|
|
14
|
+
chars += part.text.length;
|
|
15
|
+
}
|
|
16
|
+
return Math.ceil(chars / 4);
|
|
17
|
+
}
|
|
18
|
+
function isMarkerOnly(message, marker) {
|
|
19
|
+
if (message.content.length !== 1)
|
|
20
|
+
return false;
|
|
21
|
+
const part = message.content[0];
|
|
22
|
+
if (typeof part === "string")
|
|
23
|
+
return part === marker;
|
|
24
|
+
return part?.type === "text" && part.text === marker;
|
|
25
|
+
}
|
|
26
|
+
export class MicroCompaction {
|
|
27
|
+
cutoff = 0;
|
|
28
|
+
config;
|
|
29
|
+
constructor(config = {}) {
|
|
30
|
+
this.config = { ...DEFAULT_MICRO_CONFIG, ...config };
|
|
31
|
+
}
|
|
32
|
+
detectAndApply(messages, lastAssistantAtMs, maxContextTokens) {
|
|
33
|
+
const cacheAgeMs = Date.now() - lastAssistantAtMs;
|
|
34
|
+
if (cacheAgeMs < this.config.cacheMissedThresholdMs)
|
|
35
|
+
return 0; // cache still hot → never touch
|
|
36
|
+
const used = messages.reduce((sum, m) => sum + contentTokens(m), 0);
|
|
37
|
+
const ratio = maxContextTokens > 0 ? used / maxContextTokens : 1;
|
|
38
|
+
if (ratio < this.config.minContextUsageRatio)
|
|
39
|
+
return 0;
|
|
40
|
+
this.cutoff = Math.max(this.cutoff, Math.max(0, messages.length - this.config.keepRecentMessages));
|
|
41
|
+
return this.clearOld(messages);
|
|
42
|
+
}
|
|
43
|
+
clearOld(messages) {
|
|
44
|
+
let cleared = 0;
|
|
45
|
+
for (let i = 0; i < this.cutoff && i < messages.length; i++) {
|
|
46
|
+
const m = messages[i];
|
|
47
|
+
if (m.role === "toolResult" &&
|
|
48
|
+
contentTokens(m) >= this.config.minContentTokens &&
|
|
49
|
+
!isMarkerOnly(m, this.config.truncatedMarker)) {
|
|
50
|
+
messages[i] = { ...m, content: [{ type: "text", text: this.config.truncatedMarker }] };
|
|
51
|
+
cleared += 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return cleared;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=micro.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface CompactRequestOptions {
|
|
2
|
+
readonly instruction?: string;
|
|
3
|
+
}
|
|
4
|
+
export interface PendingCompaction {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly requestedAt: number;
|
|
7
|
+
readonly instruction?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class CompactionService {
|
|
10
|
+
private pendingRequest;
|
|
11
|
+
private completedRevision;
|
|
12
|
+
private readonly reserveProvider;
|
|
13
|
+
/** Context tokens the strategy holds back before the window fills — surfaced here (the
|
|
14
|
+
* session-visible service) so the context breakdown can report the real value instead of
|
|
15
|
+
* guessing the default. Read through a provider, not stored: the reserve depends on the
|
|
16
|
+
* active model's output limit, which isn't known when the capability is constructed. */
|
|
17
|
+
get reservedContextTokens(): number;
|
|
18
|
+
constructor(reserveProvider?: (() => number) | number);
|
|
19
|
+
/** Monotonic, in-memory signal that a full compaction committed in this live Session. */
|
|
20
|
+
get revision(): number;
|
|
21
|
+
/** Capability-internal commit notification; micro-compaction deliberately does not call it. */
|
|
22
|
+
recordCompleted(): void;
|
|
23
|
+
request(options?: CompactRequestOptions): PendingCompaction;
|
|
24
|
+
pending(): PendingCompaction | null;
|
|
25
|
+
cancel(): PendingCompaction | null;
|
|
26
|
+
consume(): PendingCompaction | null;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
let requestCounter = 0;
|
|
2
|
+
function nextRequestId() {
|
|
3
|
+
requestCounter += 1;
|
|
4
|
+
return `compact-${Date.now().toString(36)}-${requestCounter.toString(36)}`;
|
|
5
|
+
}
|
|
6
|
+
export class CompactionService {
|
|
7
|
+
pendingRequest = null;
|
|
8
|
+
completedRevision = 0;
|
|
9
|
+
reserveProvider;
|
|
10
|
+
/** Context tokens the strategy holds back before the window fills — surfaced here (the
|
|
11
|
+
* session-visible service) so the context breakdown can report the real value instead of
|
|
12
|
+
* guessing the default. Read through a provider, not stored: the reserve depends on the
|
|
13
|
+
* active model's output limit, which isn't known when the capability is constructed. */
|
|
14
|
+
get reservedContextTokens() {
|
|
15
|
+
return this.reserveProvider();
|
|
16
|
+
}
|
|
17
|
+
constructor(reserveProvider = 0) {
|
|
18
|
+
this.reserveProvider = typeof reserveProvider === "number" ? () => reserveProvider : reserveProvider;
|
|
19
|
+
}
|
|
20
|
+
/** Monotonic, in-memory signal that a full compaction committed in this live Session. */
|
|
21
|
+
get revision() {
|
|
22
|
+
return this.completedRevision;
|
|
23
|
+
}
|
|
24
|
+
/** Capability-internal commit notification; micro-compaction deliberately does not call it. */
|
|
25
|
+
recordCompleted() {
|
|
26
|
+
this.completedRevision += 1;
|
|
27
|
+
}
|
|
28
|
+
request(options = {}) {
|
|
29
|
+
const instruction = options.instruction?.trim();
|
|
30
|
+
const request = {
|
|
31
|
+
id: nextRequestId(),
|
|
32
|
+
requestedAt: Date.now(),
|
|
33
|
+
...(instruction !== undefined && instruction.length > 0 ? { instruction } : {}),
|
|
34
|
+
};
|
|
35
|
+
this.pendingRequest = request;
|
|
36
|
+
return request;
|
|
37
|
+
}
|
|
38
|
+
pending() {
|
|
39
|
+
return this.pendingRequest;
|
|
40
|
+
}
|
|
41
|
+
cancel() {
|
|
42
|
+
const pending = this.pendingRequest;
|
|
43
|
+
this.pendingRequest = null;
|
|
44
|
+
return pending;
|
|
45
|
+
}
|
|
46
|
+
consume() {
|
|
47
|
+
const pending = this.pendingRequest;
|
|
48
|
+
this.pendingRequest = null;
|
|
49
|
+
return pending;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Message } from "../../protocol/index.ts";
|
|
2
|
+
export interface CompactionConfig {
|
|
3
|
+
/** Room the compaction summary's own LLM call needs for its output. Applied as
|
|
4
|
+
* `min(model.maxOutputTokens, this)` — a model that cannot emit this much never needs this
|
|
5
|
+
* much held back. The default covers the summary's p99.99 with headroom. */
|
|
6
|
+
readonly summaryOutputReserve: number;
|
|
7
|
+
/** Head start for auto-compaction: how far ahead of the effective window we begin
|
|
8
|
+
* summarizing, so the turn still in flight has somewhere to land while the summary runs. */
|
|
9
|
+
readonly compactBufferTokens: number;
|
|
10
|
+
/** Hard floor — past this the next request must not go out uncompacted. Deliberately much
|
|
11
|
+
* smaller than `compactBufferTokens`: this is the true safety margin, not a head start. */
|
|
12
|
+
readonly blockBufferTokens: number;
|
|
13
|
+
readonly maxRecentMessages: number;
|
|
14
|
+
readonly maxRecentSizeRatio: number;
|
|
15
|
+
readonly minOverflowReductionRatio: number;
|
|
16
|
+
}
|
|
17
|
+
export declare const DEFAULT_COMPACTION_CONFIG: CompactionConfig;
|
|
18
|
+
export declare class CompactionStrategy {
|
|
19
|
+
private readonly maxSizeProvider;
|
|
20
|
+
private readonly maxOutputProvider;
|
|
21
|
+
private readonly config;
|
|
22
|
+
constructor(maxSizeProvider: () => number, maxOutputProvider?: () => number, config?: CompactionConfig);
|
|
23
|
+
private get maxSize();
|
|
24
|
+
/** The window actually available to the conversation: the model's window minus the room the
|
|
25
|
+
* summary call will need. An unknown output limit (0) reserves the full configured amount
|
|
26
|
+
* rather than guessing low. */
|
|
27
|
+
get effectiveWindow(): number;
|
|
28
|
+
get compactThreshold(): number;
|
|
29
|
+
get blockThreshold(): number;
|
|
30
|
+
/** Total tokens withheld from the conversation — summary reserve plus compaction head start.
|
|
31
|
+
* This is the number the context breakdown reports as the compaction buffer. */
|
|
32
|
+
get reservedTokens(): number;
|
|
33
|
+
private threshold;
|
|
34
|
+
/** Whether the compact line sits earlier than the block line. When it does, an afterStep check
|
|
35
|
+
* can start compaction at the head start instead of waiting for beforeStep to hit the floor. */
|
|
36
|
+
get checkAfterStep(): boolean;
|
|
37
|
+
shouldCompact(usedSize: number): boolean;
|
|
38
|
+
shouldBlock(usedSize: number): boolean;
|
|
39
|
+
computeCompactCount(messages: readonly Message[]): number;
|
|
40
|
+
reduceCompactOnOverflow(messages: readonly Message[]): number;
|
|
41
|
+
}
|
|
42
|
+
export declare function canSplitAfter(messages: readonly Message[], index: number): boolean;
|
|
43
|
+
//# sourceMappingURL=strategy.d.ts.map
|