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,15 @@
|
|
|
1
|
+
export { DEFAULT_ADDRESS, reduceHistory, summaryMessage, customMessage, watchRecordsByPolling } from "./store.js";
|
|
2
|
+
export { MemorySessionLock, SessionBusyError } from "./lock.js";
|
|
3
|
+
export { LogSessionStore, MemoryStore } from "./log-store.js";
|
|
4
|
+
export { DiskSessionStore } from "./disk-store.js";
|
|
5
|
+
export { PgSessionStore, PgSessionRepository, pgStorage } from "./pg.js";
|
|
6
|
+
export { RedisSessionStore, RedisSessionRepository, redisStorage } from "./redis.js";
|
|
7
|
+
export { storageOver, memoryStorage, diskStorage } from "./storage.js";
|
|
8
|
+
// The wire-version migration machinery (WIRE_PROTOCOL_VERSION / migrateRecord / RECORD_MIGRATIONS),
|
|
9
|
+
// content-addressed blob store, workdir-key encoding, and session-catalog helpers are store plumbing —
|
|
10
|
+
// on `operon-agents-core/internal`, not the public surface.
|
|
11
|
+
export { RedactingSessionStore } from "./redacting-store.js";
|
|
12
|
+
export { USER_PROMPT_ORIGIN } from "./origin.js";
|
|
13
|
+
export { MemorySessionRepository, DiskSessionRepository, generateSessionId, } from "./repository.js";
|
|
14
|
+
export { SessionRepositoryConflictError, SessionRepositoryNotFoundError, } from "./repository.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exclusive right to run a session.
|
|
3
|
+
*
|
|
4
|
+
* `Session.withRunLock` serializes runs sharing one `Session` OBJECT. That is the whole
|
|
5
|
+
* guarantee — two requests that each open their own Session for the same id run
|
|
6
|
+
* simultaneously, replay history from before each other's writes, and fork their views. Nothing
|
|
7
|
+
* is lost (both write to the log), but neither run sees the other's turn.
|
|
8
|
+
*
|
|
9
|
+
* This is the seam for the distributed counterpart: a lock keyed by session id rather than by
|
|
10
|
+
* object identity. The framework defines the contract and ships an in-process implementation;
|
|
11
|
+
* where the lease lives in a multi-node deployment (a table, a KV entry, a coordination service)
|
|
12
|
+
* is the host's decision, exactly as the session repository is.
|
|
13
|
+
*
|
|
14
|
+
* ## Losing a lease is not the same as releasing it
|
|
15
|
+
*
|
|
16
|
+
* A holder can lose its lease without knowing: a long GC pause or a clock skew is enough for the
|
|
17
|
+
* TTL to expire while the process is frozen, after which another node legitimately takes over.
|
|
18
|
+
* When the frozen process wakes it still believes it holds the lease. Two defenses, and only the
|
|
19
|
+
* second is a mechanism:
|
|
20
|
+
*
|
|
21
|
+
* - `signal` aborts when renewal fails, so a well-behaved holder stops on its own. Best-effort:
|
|
22
|
+
* a process that is frozen or wedged never observes it.
|
|
23
|
+
* - `fence` is a monotonically increasing token, bumped on every acquire. A backend that can
|
|
24
|
+
* compare-and-set on write rejects anything carrying a fence lower than the current one — the
|
|
25
|
+
* stale holder is stopped whether or not it cooperates. Backends that cannot enforce this
|
|
26
|
+
* (a plain append-only file) still surface the token; enforcement is a property of the store,
|
|
27
|
+
* not of the lock.
|
|
28
|
+
*/
|
|
29
|
+
/** Raised when the session is being run elsewhere. Retry after the holder finishes. */
|
|
30
|
+
export declare class SessionBusyError extends Error {
|
|
31
|
+
readonly sessionId: string;
|
|
32
|
+
constructor(sessionId: string);
|
|
33
|
+
}
|
|
34
|
+
export interface SessionLease {
|
|
35
|
+
readonly sessionId: string;
|
|
36
|
+
/**
|
|
37
|
+
* Monotonic fencing token for this holder, bumped on every successful acquire. Carry it on
|
|
38
|
+
* writes so a backend that can enforce it rejects a stale holder's writes.
|
|
39
|
+
*/
|
|
40
|
+
readonly fence: number;
|
|
41
|
+
/** Aborts when the lease is lost or released — runs should treat it as a cancel. */
|
|
42
|
+
readonly signal: AbortSignal;
|
|
43
|
+
/** Extend the lease. `false` means it is gone (taken over, or expired) — stop working. */
|
|
44
|
+
renew(): Promise<boolean>;
|
|
45
|
+
/** Give it up. Idempotent. */
|
|
46
|
+
release(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export interface AcquireLeaseOptions {
|
|
49
|
+
/** How long the lease stays valid without renewal. Backend default applies when omitted. */
|
|
50
|
+
readonly ttlMs?: number;
|
|
51
|
+
/** Abort waiting/acquiring. */
|
|
52
|
+
readonly signal?: AbortSignal;
|
|
53
|
+
}
|
|
54
|
+
export interface SessionLock {
|
|
55
|
+
/**
|
|
56
|
+
* Take the lease for `sessionId`, or return `undefined` when a live one is held elsewhere.
|
|
57
|
+
*
|
|
58
|
+
* Never blocks waiting for the current holder: an agent turn can run for many minutes, so
|
|
59
|
+
* queueing behind it inside a request is the wrong default. Callers decide whether to fail
|
|
60
|
+
* fast, retry, or route the work to whoever holds it.
|
|
61
|
+
*/
|
|
62
|
+
acquire(sessionId: string, options?: AcquireLeaseOptions): Promise<SessionLease | undefined>;
|
|
63
|
+
/**
|
|
64
|
+
* Is anyone holding this session right now? (optional)
|
|
65
|
+
*
|
|
66
|
+
* Read-only and advisory: the answer can be stale the instant it returns, so it must never
|
|
67
|
+
* gate correctness — that is `acquire`'s job. It exists for observability, where the useful
|
|
68
|
+
* question is "should something be running, and is it?" A session with unprocessed input and
|
|
69
|
+
* no holder is a session nobody is working on, and a client waiting on its stream deserves to
|
|
70
|
+
* be told that rather than watching an idle connection.
|
|
71
|
+
*/
|
|
72
|
+
peek?(sessionId: string): Promise<boolean>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Single-process lock: correct for one node, and the default so that the in-process path has the
|
|
76
|
+
* same shape as the distributed one. It is NOT a substitute for a real lease across processes —
|
|
77
|
+
* two Node processes over the same disk session each get their own instance and both succeed.
|
|
78
|
+
*/
|
|
79
|
+
export declare class MemorySessionLock implements SessionLock {
|
|
80
|
+
private readonly held;
|
|
81
|
+
private fences;
|
|
82
|
+
acquire(sessionId: string, options?: AcquireLeaseOptions): Promise<SessionLease | undefined>;
|
|
83
|
+
peek(sessionId: string): Promise<boolean>;
|
|
84
|
+
private lose;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=lock.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exclusive right to run a session.
|
|
3
|
+
*
|
|
4
|
+
* `Session.withRunLock` serializes runs sharing one `Session` OBJECT. That is the whole
|
|
5
|
+
* guarantee — two requests that each open their own Session for the same id run
|
|
6
|
+
* simultaneously, replay history from before each other's writes, and fork their views. Nothing
|
|
7
|
+
* is lost (both write to the log), but neither run sees the other's turn.
|
|
8
|
+
*
|
|
9
|
+
* This is the seam for the distributed counterpart: a lock keyed by session id rather than by
|
|
10
|
+
* object identity. The framework defines the contract and ships an in-process implementation;
|
|
11
|
+
* where the lease lives in a multi-node deployment (a table, a KV entry, a coordination service)
|
|
12
|
+
* is the host's decision, exactly as the session repository is.
|
|
13
|
+
*
|
|
14
|
+
* ## Losing a lease is not the same as releasing it
|
|
15
|
+
*
|
|
16
|
+
* A holder can lose its lease without knowing: a long GC pause or a clock skew is enough for the
|
|
17
|
+
* TTL to expire while the process is frozen, after which another node legitimately takes over.
|
|
18
|
+
* When the frozen process wakes it still believes it holds the lease. Two defenses, and only the
|
|
19
|
+
* second is a mechanism:
|
|
20
|
+
*
|
|
21
|
+
* - `signal` aborts when renewal fails, so a well-behaved holder stops on its own. Best-effort:
|
|
22
|
+
* a process that is frozen or wedged never observes it.
|
|
23
|
+
* - `fence` is a monotonically increasing token, bumped on every acquire. A backend that can
|
|
24
|
+
* compare-and-set on write rejects anything carrying a fence lower than the current one — the
|
|
25
|
+
* stale holder is stopped whether or not it cooperates. Backends that cannot enforce this
|
|
26
|
+
* (a plain append-only file) still surface the token; enforcement is a property of the store,
|
|
27
|
+
* not of the lock.
|
|
28
|
+
*/
|
|
29
|
+
/** Raised when the session is being run elsewhere. Retry after the holder finishes. */
|
|
30
|
+
export class SessionBusyError extends Error {
|
|
31
|
+
sessionId;
|
|
32
|
+
constructor(sessionId) {
|
|
33
|
+
super(`session "${sessionId}" is currently held by another runner`);
|
|
34
|
+
this.name = "SessionBusyError";
|
|
35
|
+
this.sessionId = sessionId;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const DEFAULT_TTL_MS = 30_000;
|
|
39
|
+
/**
|
|
40
|
+
* Single-process lock: correct for one node, and the default so that the in-process path has the
|
|
41
|
+
* same shape as the distributed one. It is NOT a substitute for a real lease across processes —
|
|
42
|
+
* two Node processes over the same disk session each get their own instance and both succeed.
|
|
43
|
+
*/
|
|
44
|
+
export class MemorySessionLock {
|
|
45
|
+
held = new Map();
|
|
46
|
+
fences = new Map();
|
|
47
|
+
async acquire(sessionId, options) {
|
|
48
|
+
const ttlMs = options?.ttlMs ?? DEFAULT_TTL_MS;
|
|
49
|
+
const now = Date.now();
|
|
50
|
+
const existing = this.held.get(sessionId);
|
|
51
|
+
// A holder that let its TTL lapse is treated as gone — same rule a distributed backend uses,
|
|
52
|
+
// so takeover behaves identically in tests and in production.
|
|
53
|
+
if (existing !== undefined && existing.expiresAt > now)
|
|
54
|
+
return undefined;
|
|
55
|
+
if (existing !== undefined)
|
|
56
|
+
this.lose(sessionId, existing);
|
|
57
|
+
const fence = (this.fences.get(sessionId) ?? 0) + 1;
|
|
58
|
+
this.fences.set(sessionId, fence);
|
|
59
|
+
const controller = new AbortController();
|
|
60
|
+
const entry = { controller, fence, expiresAt: now + ttlMs };
|
|
61
|
+
this.held.set(sessionId, entry);
|
|
62
|
+
let surrendered = false;
|
|
63
|
+
/** Give up this holder's claim without touching whoever holds the row now. */
|
|
64
|
+
const surrender = () => {
|
|
65
|
+
if (surrendered)
|
|
66
|
+
return;
|
|
67
|
+
surrendered = true;
|
|
68
|
+
if (this.held.get(sessionId) === entry)
|
|
69
|
+
this.held.delete(sessionId);
|
|
70
|
+
controller.abort();
|
|
71
|
+
};
|
|
72
|
+
const lease = {
|
|
73
|
+
sessionId,
|
|
74
|
+
fence,
|
|
75
|
+
signal: controller.signal,
|
|
76
|
+
renew: async () => {
|
|
77
|
+
if (surrendered)
|
|
78
|
+
return false;
|
|
79
|
+
const current = this.held.get(sessionId);
|
|
80
|
+
if (current !== entry) {
|
|
81
|
+
// Superseded while we were not looking. Abort, exactly as the durable implementations
|
|
82
|
+
// do — a lease that cannot be renewed has been taken, and the holder must stop. These
|
|
83
|
+
// two behaving differently would make the in-process path a misleading rehearsal for
|
|
84
|
+
// the distributed one.
|
|
85
|
+
surrender();
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
entry.expiresAt = Date.now() + ttlMs;
|
|
89
|
+
return true;
|
|
90
|
+
},
|
|
91
|
+
release: async () => surrender(),
|
|
92
|
+
};
|
|
93
|
+
return lease;
|
|
94
|
+
}
|
|
95
|
+
async peek(sessionId) {
|
|
96
|
+
const entry = this.held.get(sessionId);
|
|
97
|
+
return entry !== undefined && entry.expiresAt > Date.now();
|
|
98
|
+
}
|
|
99
|
+
lose(sessionId, entry) {
|
|
100
|
+
this.held.delete(sessionId);
|
|
101
|
+
entry.controller.abort();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=lock.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type AgentRecord, type ReadRecordPageOptions, type ReadRecordsFilter, type RecordPage, type SessionStore, type StateKey, type StoredAgentRecord } from "./store.ts";
|
|
2
|
+
export interface LogStoreOptions {
|
|
3
|
+
/** Inline image data (base64) longer than this is offloaded to a blob. Default 4096. */
|
|
4
|
+
readonly blobThreshold?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface StoredLogLine {
|
|
7
|
+
readonly sequence: string;
|
|
8
|
+
readonly line: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ReadLinesPageOptions {
|
|
11
|
+
/** Strictly past this sequence, in `order`. Omit to start from the end `order` begins at. */
|
|
12
|
+
readonly after?: string;
|
|
13
|
+
readonly limit: number;
|
|
14
|
+
readonly order: "asc" | "desc";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The **linear** session log implemented once over a tiny physical machine
|
|
18
|
+
* (raw line append/read/rewrite + key-value state + content-addressed blobs). A new backing
|
|
19
|
+
* (disk, Postgres, Redis, S3…) implements only those primitives; the flat append log, first-
|
|
20
|
+
* record `metadata` prepend, wire migration, and blob offload are written once here. Records are
|
|
21
|
+
* JSON lines in append order per address; a shard's conversation is those records reduced.
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class LogSessionStore implements SessionStore {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(options?: LogStoreOptions);
|
|
26
|
+
/** Append a raw line to an address's log. */
|
|
27
|
+
protected abstract appendLine(address: string, line: string): Promise<string>;
|
|
28
|
+
/** The address's log lines in append order. A torn trailing line (crash) is tolerated. */
|
|
29
|
+
protected abstract readLines(address: string): AsyncIterable<StoredLogLine>;
|
|
30
|
+
/**
|
|
31
|
+
* One page of an address's lines (optional). A backing that can seek — an indexed table —
|
|
32
|
+
* implements this so `readRecordPage` costs a range read instead of the whole shard; one that
|
|
33
|
+
* cannot (a flat file) leaves it out and pages in memory. Either way the result is the same.
|
|
34
|
+
*/
|
|
35
|
+
protected readLinesPage?(address: string, options: ReadLinesPageOptions): Promise<readonly StoredLogLine[]>;
|
|
36
|
+
/** Atomically replace an address's whole log. */
|
|
37
|
+
protected abstract rewriteLines(address: string, lines: readonly StoredLogLine[]): Promise<void>;
|
|
38
|
+
/** Every address that has a log. */
|
|
39
|
+
protected abstract listShardAddresses(): Promise<readonly string[]>;
|
|
40
|
+
/** Content-addressed blob bytes (`undefined` if absent). */
|
|
41
|
+
protected abstract readBlobBytes(sha: string): Promise<Buffer | undefined>;
|
|
42
|
+
protected abstract writeBlobBytes(sha: string, bytes: Buffer): Promise<void>;
|
|
43
|
+
abstract getState(key: StateKey): Promise<unknown | null>;
|
|
44
|
+
abstract putState(key: StateKey, value: unknown): Promise<void>;
|
|
45
|
+
abstract deleteState(key: StateKey): Promise<void>;
|
|
46
|
+
flush(): Promise<void>;
|
|
47
|
+
close(): Promise<void>;
|
|
48
|
+
appendRecord(record: AgentRecord): Promise<string>;
|
|
49
|
+
private appendRecordNow;
|
|
50
|
+
readRecords(filter?: ReadRecordsFilter): AsyncIterable<AgentRecord>;
|
|
51
|
+
readRecordPage(options: ReadRecordPageOptions): Promise<RecordPage>;
|
|
52
|
+
/** `readRecordPage` over a backing that can seek: read `limit + 1` lines to learn whether a
|
|
53
|
+
* next page exists, parse only those. Same validation and cursor semantics as `pageRecords`. */
|
|
54
|
+
private readRecordPageSeeking;
|
|
55
|
+
listAddresses(): Promise<readonly string[]>;
|
|
56
|
+
/** Re-emit a shard's log compactly: migrated to the current wire version + blob-offloaded. */
|
|
57
|
+
rewrite(address?: string): Promise<void>;
|
|
58
|
+
private rewriteNow;
|
|
59
|
+
/** Parsed + wire-migrated records for an address, in append order (NOT blob-rehydrated).
|
|
60
|
+
* Records dropped by a migration are skipped. */
|
|
61
|
+
private parsedRecords;
|
|
62
|
+
private storedRecords;
|
|
63
|
+
/** Ensure the shard's log opens with a `metadata` record. Cheap after first touch. */
|
|
64
|
+
private ensureMetadata;
|
|
65
|
+
private shardIsEmpty;
|
|
66
|
+
private version;
|
|
67
|
+
private ensureVersionStamped;
|
|
68
|
+
private stampVersion;
|
|
69
|
+
}
|
|
70
|
+
/** In-process session store: logs, state, and blobs in process memory (gone on restart). */
|
|
71
|
+
export declare class MemoryStore extends LogSessionStore {
|
|
72
|
+
private readonly logs;
|
|
73
|
+
private readonly kv;
|
|
74
|
+
private readonly blobBytes;
|
|
75
|
+
private sequence;
|
|
76
|
+
protected appendLine(address: string, line: string): Promise<string>;
|
|
77
|
+
protected readLines(address: string): AsyncIterable<StoredLogLine>;
|
|
78
|
+
protected rewriteLines(address: string, lines: readonly StoredLogLine[]): Promise<void>;
|
|
79
|
+
protected listShardAddresses(): Promise<readonly string[]>;
|
|
80
|
+
protected readBlobBytes(sha: string): Promise<Buffer | undefined>;
|
|
81
|
+
protected writeBlobBytes(sha: string, bytes: Buffer): Promise<void>;
|
|
82
|
+
getState(key: StateKey): Promise<unknown | null>;
|
|
83
|
+
putState(key: StateKey, value: unknown): Promise<void>;
|
|
84
|
+
deleteState(key: StateKey): Promise<void>;
|
|
85
|
+
listStateKeys(): Promise<readonly StateKey[]>;
|
|
86
|
+
}
|
|
87
|
+
export declare function compareSequence(a: string, b: string): number;
|
|
88
|
+
export declare function pageRecords(records: readonly StoredAgentRecord[], options: ReadRecordPageOptions): RecordPage;
|
|
89
|
+
//# sourceMappingURL=log-store.d.ts.map
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { BlobStore, offloadRecord, rehydrateRecord } from "./blob-store.js";
|
|
2
|
+
import { migrateRecord, WIRE_PROTOCOL_VERSION, WIRE_VERSION_KEY } from "./migrate.js";
|
|
3
|
+
import { DEFAULT_ADDRESS, } from "./store.js";
|
|
4
|
+
/**
|
|
5
|
+
* The **linear** session log implemented once over a tiny physical machine
|
|
6
|
+
* (raw line append/read/rewrite + key-value state + content-addressed blobs). A new backing
|
|
7
|
+
* (disk, Postgres, Redis, S3…) implements only those primitives; the flat append log, first-
|
|
8
|
+
* record `metadata` prepend, wire migration, and blob offload are written once here. Records are
|
|
9
|
+
* JSON lines in append order per address; a shard's conversation is those records reduced.
|
|
10
|
+
*/
|
|
11
|
+
export class LogSessionStore {
|
|
12
|
+
// ECMAScript-private so a subclass field can never clobber these.
|
|
13
|
+
#blobs;
|
|
14
|
+
#versionCache;
|
|
15
|
+
#versionStamped = false;
|
|
16
|
+
#appendWrite = Promise.resolve();
|
|
17
|
+
// Addresses whose shard has been checked for the leading `metadata` record this process.
|
|
18
|
+
#metadataChecked = new Set();
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
this.#blobs = new BlobStore({
|
|
21
|
+
io: { read: (sha) => this.readBlobBytes(sha), write: (sha, bytes) => this.writeBlobBytes(sha, bytes) },
|
|
22
|
+
...(options.blobThreshold !== undefined ? { threshold: options.blobThreshold } : {}),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
flush() {
|
|
26
|
+
return Promise.resolve();
|
|
27
|
+
}
|
|
28
|
+
close() {
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
}
|
|
31
|
+
// ── ① append log (flat, linear; first record of a shard is `metadata`) ──
|
|
32
|
+
appendRecord(record) {
|
|
33
|
+
const run = this.#appendWrite.then(() => this.appendRecordNow(record), () => this.appendRecordNow(record));
|
|
34
|
+
this.#appendWrite = run.then(() => undefined, () => undefined);
|
|
35
|
+
return run;
|
|
36
|
+
}
|
|
37
|
+
async appendRecordNow(record) {
|
|
38
|
+
await this.ensureVersionStamped();
|
|
39
|
+
const address = record.address ?? DEFAULT_ADDRESS;
|
|
40
|
+
if (record.type === "metadata")
|
|
41
|
+
this.#metadataChecked.add(address);
|
|
42
|
+
else
|
|
43
|
+
await this.ensureMetadata(address);
|
|
44
|
+
const stamped = record.time !== undefined ? record : { ...record, time: Date.now() };
|
|
45
|
+
const stored = await offloadRecord(stamped, this.#blobs);
|
|
46
|
+
return this.appendLine(address, JSON.stringify(stored));
|
|
47
|
+
}
|
|
48
|
+
async *readRecords(filter) {
|
|
49
|
+
for (const item of await this.storedRecords(filter?.address))
|
|
50
|
+
yield item.record;
|
|
51
|
+
}
|
|
52
|
+
async readRecordPage(options) {
|
|
53
|
+
if (options.address !== undefined && this.readLinesPage !== undefined) {
|
|
54
|
+
return this.readRecordPageSeeking(options.address, options);
|
|
55
|
+
}
|
|
56
|
+
return pageRecords(await this.storedRecords(options.address), options);
|
|
57
|
+
}
|
|
58
|
+
/** `readRecordPage` over a backing that can seek: read `limit + 1` lines to learn whether a
|
|
59
|
+
* next page exists, parse only those. Same validation and cursor semantics as `pageRecords`. */
|
|
60
|
+
async readRecordPageSeeking(address, options) {
|
|
61
|
+
assertPageLimit(options.limit);
|
|
62
|
+
if (options.after !== undefined)
|
|
63
|
+
parseSequence(options.after);
|
|
64
|
+
const lines = await this.readLinesPage(address, {
|
|
65
|
+
...(options.after !== undefined ? { after: options.after } : {}),
|
|
66
|
+
limit: options.limit + 1,
|
|
67
|
+
order: options.order ?? "asc",
|
|
68
|
+
});
|
|
69
|
+
const page = lines.slice(0, options.limit);
|
|
70
|
+
const version = await this.version();
|
|
71
|
+
const data = [];
|
|
72
|
+
for (const storedLine of page) {
|
|
73
|
+
const migrated = migrateRecord(JSON.parse(storedLine.line), version);
|
|
74
|
+
if (migrated === null)
|
|
75
|
+
continue;
|
|
76
|
+
data.push({ sequence: storedLine.sequence, record: await rehydrateRecord(migrated, this.#blobs) });
|
|
77
|
+
}
|
|
78
|
+
// The cursor is the last LINE read, not the last record returned: a line a migration dropped
|
|
79
|
+
// still has to be stepped over, or the next page would read it again.
|
|
80
|
+
const last = page[page.length - 1];
|
|
81
|
+
return {
|
|
82
|
+
data,
|
|
83
|
+
...(lines.length > page.length && last !== undefined ? { next: last.sequence } : {}),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
listAddresses() {
|
|
87
|
+
return this.listShardAddresses();
|
|
88
|
+
}
|
|
89
|
+
// ── ② KV state — provided by the backing (abstract above) ──
|
|
90
|
+
/** Re-emit a shard's log compactly: migrated to the current wire version + blob-offloaded. */
|
|
91
|
+
rewrite(address) {
|
|
92
|
+
const run = this.#appendWrite.then(() => this.rewriteNow(address), () => this.rewriteNow(address));
|
|
93
|
+
this.#appendWrite = run.then(() => undefined, () => undefined);
|
|
94
|
+
return run;
|
|
95
|
+
}
|
|
96
|
+
async rewriteNow(address) {
|
|
97
|
+
const addresses = address !== undefined ? [address] : [...(await this.listShardAddresses())];
|
|
98
|
+
const fromVersion = await this.version();
|
|
99
|
+
for (const addr of addresses) {
|
|
100
|
+
const lines = [];
|
|
101
|
+
for await (const storedLine of this.readLines(addr)) {
|
|
102
|
+
const migrated = migrateRecord(JSON.parse(storedLine.line), fromVersion);
|
|
103
|
+
if (migrated === null)
|
|
104
|
+
continue; // a migration may drop a record
|
|
105
|
+
lines.push({ sequence: storedLine.sequence, line: JSON.stringify(await offloadRecord(migrated, this.#blobs)) });
|
|
106
|
+
}
|
|
107
|
+
await this.rewriteLines(addr, withLeadingMetadata(lines, addr));
|
|
108
|
+
this.#metadataChecked.add(addr);
|
|
109
|
+
}
|
|
110
|
+
await this.stampVersion();
|
|
111
|
+
}
|
|
112
|
+
// ── internals ──
|
|
113
|
+
/** Parsed + wire-migrated records for an address, in append order (NOT blob-rehydrated).
|
|
114
|
+
* Records dropped by a migration are skipped. */
|
|
115
|
+
async parsedRecords(address) {
|
|
116
|
+
const version = await this.version();
|
|
117
|
+
const out = [];
|
|
118
|
+
for await (const storedLine of this.readLines(address)) {
|
|
119
|
+
const migrated = migrateRecord(JSON.parse(storedLine.line), version);
|
|
120
|
+
if (migrated !== null) {
|
|
121
|
+
out.push({ sequence: storedLine.sequence, record: await rehydrateRecord(migrated, this.#blobs) });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
async storedRecords(address) {
|
|
127
|
+
if (address !== undefined)
|
|
128
|
+
return this.parsedRecords(address);
|
|
129
|
+
const all = [];
|
|
130
|
+
for (const shard of await this.listShardAddresses())
|
|
131
|
+
all.push(...(await this.parsedRecords(shard)));
|
|
132
|
+
all.sort((a, b) => compareSequence(a.sequence, b.sequence));
|
|
133
|
+
return all;
|
|
134
|
+
}
|
|
135
|
+
/** Ensure the shard's log opens with a `metadata` record. Cheap after first touch. */
|
|
136
|
+
async ensureMetadata(address) {
|
|
137
|
+
if (this.#metadataChecked.has(address))
|
|
138
|
+
return;
|
|
139
|
+
this.#metadataChecked.add(address);
|
|
140
|
+
if (!(await this.shardIsEmpty(address)))
|
|
141
|
+
return;
|
|
142
|
+
await this.appendLine(address, JSON.stringify(metadataRecord(address)));
|
|
143
|
+
}
|
|
144
|
+
async shardIsEmpty(address) {
|
|
145
|
+
// A seeking backing answers with one row; a streaming one is stopped after its first line.
|
|
146
|
+
if (this.readLinesPage !== undefined) {
|
|
147
|
+
return (await this.readLinesPage(address, { limit: 1, order: "asc" })).length === 0;
|
|
148
|
+
}
|
|
149
|
+
for await (const _ of this.readLines(address))
|
|
150
|
+
return false;
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
async version() {
|
|
154
|
+
if (this.#versionCache !== undefined)
|
|
155
|
+
return this.#versionCache;
|
|
156
|
+
const stored = await this.getState(WIRE_VERSION_KEY);
|
|
157
|
+
this.#versionCache = typeof stored === "number" ? stored : WIRE_PROTOCOL_VERSION;
|
|
158
|
+
return this.#versionCache;
|
|
159
|
+
}
|
|
160
|
+
async ensureVersionStamped() {
|
|
161
|
+
if (this.#versionStamped)
|
|
162
|
+
return;
|
|
163
|
+
// Set synchronously so a second caller returns early instead of re-running the migration.
|
|
164
|
+
// Narrow window: that early return does NOT await the in-flight rewrite()/stampVersion()
|
|
165
|
+
// below, so a concurrent first-write during a version upgrade could append before the
|
|
166
|
+
// rewrite lands. In practice a single context's writes are serialized upstream by
|
|
167
|
+
// ConversationContext.writeChain, so this only bites on cross-context first-write races
|
|
168
|
+
// over a shared store mid-upgrade — low risk, noted rather than locked.
|
|
169
|
+
this.#versionStamped = true;
|
|
170
|
+
const stored = await this.getState(WIRE_VERSION_KEY);
|
|
171
|
+
if (stored === null) {
|
|
172
|
+
await this.stampVersion();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (typeof stored === "number" && stored < WIRE_PROTOCOL_VERSION) {
|
|
176
|
+
this.#versionCache = stored;
|
|
177
|
+
await this.rewriteNow();
|
|
178
|
+
await this.stampVersion();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async stampVersion() {
|
|
182
|
+
await this.putState(WIRE_VERSION_KEY, WIRE_PROTOCOL_VERSION);
|
|
183
|
+
this.#versionCache = WIRE_PROTOCOL_VERSION;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** The leading `metadata` record stamped at the head of a shard's log. */
|
|
187
|
+
function metadataRecord(address) {
|
|
188
|
+
return { type: "metadata", protocol_version: WIRE_PROTOCOL_VERSION, created_at: Date.now(), time: Date.now(), address };
|
|
189
|
+
}
|
|
190
|
+
/** Keep an existing leading metadata record and correct its informational address in place.
|
|
191
|
+
* New-format stores always create metadata before their first data record; rewrite therefore
|
|
192
|
+
* never needs to invent one (which would have no valid earlier sequence). */
|
|
193
|
+
function withLeadingMetadata(lines, address) {
|
|
194
|
+
const first = lines[0];
|
|
195
|
+
if (first !== undefined) {
|
|
196
|
+
try {
|
|
197
|
+
const parsed = JSON.parse(first.line);
|
|
198
|
+
if (parsed.type === "metadata") {
|
|
199
|
+
if (parsed.address === address)
|
|
200
|
+
return [...lines];
|
|
201
|
+
return [{ sequence: first.sequence, line: JSON.stringify({ ...parsed, address }) }, ...lines.slice(1)];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
/* malformed records are handled by the reader before rewrite */
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// Current stores always stamp metadata before the first real append. There is deliberately
|
|
209
|
+
// no legacy repair here: inventing a new leading record would require renumbering an existing
|
|
210
|
+
// record, violating sequence stability.
|
|
211
|
+
return [...lines];
|
|
212
|
+
}
|
|
213
|
+
function clone(value) {
|
|
214
|
+
if (value === undefined || value === null)
|
|
215
|
+
return value;
|
|
216
|
+
try {
|
|
217
|
+
return structuredClone(value);
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
return JSON.parse(JSON.stringify(value));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** In-process session store: logs, state, and blobs in process memory (gone on restart). */
|
|
224
|
+
export class MemoryStore extends LogSessionStore {
|
|
225
|
+
logs = new Map();
|
|
226
|
+
kv = new Map();
|
|
227
|
+
blobBytes = new Map();
|
|
228
|
+
sequence = 0n;
|
|
229
|
+
async appendLine(address, line) {
|
|
230
|
+
const sequence = String(++this.sequence);
|
|
231
|
+
const stored = { sequence, line };
|
|
232
|
+
const log = this.logs.get(address);
|
|
233
|
+
if (log === undefined)
|
|
234
|
+
this.logs.set(address, [stored]);
|
|
235
|
+
else
|
|
236
|
+
log.push(stored);
|
|
237
|
+
return sequence;
|
|
238
|
+
}
|
|
239
|
+
async *readLines(address) {
|
|
240
|
+
yield* this.logs.get(address) ?? [];
|
|
241
|
+
}
|
|
242
|
+
async rewriteLines(address, lines) {
|
|
243
|
+
this.logs.set(address, [...lines]);
|
|
244
|
+
}
|
|
245
|
+
async listShardAddresses() {
|
|
246
|
+
return [...this.logs.keys()];
|
|
247
|
+
}
|
|
248
|
+
async readBlobBytes(sha) {
|
|
249
|
+
return this.blobBytes.get(sha);
|
|
250
|
+
}
|
|
251
|
+
async writeBlobBytes(sha, bytes) {
|
|
252
|
+
this.blobBytes.set(sha, bytes);
|
|
253
|
+
}
|
|
254
|
+
async getState(key) {
|
|
255
|
+
return this.kv.has(key) ? clone(this.kv.get(key)) : null;
|
|
256
|
+
}
|
|
257
|
+
async putState(key, value) {
|
|
258
|
+
this.kv.set(key, clone(value));
|
|
259
|
+
}
|
|
260
|
+
async deleteState(key) {
|
|
261
|
+
this.kv.delete(key);
|
|
262
|
+
}
|
|
263
|
+
async listStateKeys() {
|
|
264
|
+
return [...this.kv.keys()];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
export function compareSequence(a, b) {
|
|
268
|
+
const left = parseSequence(a);
|
|
269
|
+
const right = parseSequence(b);
|
|
270
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
271
|
+
}
|
|
272
|
+
export function pageRecords(records, options) {
|
|
273
|
+
assertPageLimit(options.limit);
|
|
274
|
+
const order = options.order ?? "asc";
|
|
275
|
+
const cursor = options.after === undefined ? undefined : parseSequence(options.after);
|
|
276
|
+
const ordered = order === "asc" ? [...records] : [...records].reverse();
|
|
277
|
+
const eligible = cursor === undefined
|
|
278
|
+
? ordered
|
|
279
|
+
: ordered.filter(({ sequence }) => order === "asc" ? parseSequence(sequence) > cursor : parseSequence(sequence) < cursor);
|
|
280
|
+
const data = eligible.slice(0, options.limit);
|
|
281
|
+
return {
|
|
282
|
+
data,
|
|
283
|
+
...(eligible.length > data.length && data.length > 0 ? { next: data[data.length - 1].sequence } : {}),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function assertPageLimit(limit) {
|
|
287
|
+
if (!Number.isSafeInteger(limit) || limit < 1) {
|
|
288
|
+
throw new Error("record page limit must be a positive integer");
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function parseSequence(value) {
|
|
292
|
+
if (!/^[1-9]\d*$/.test(value))
|
|
293
|
+
throw new Error(`invalid record sequence "${value}"`);
|
|
294
|
+
return BigInt(value);
|
|
295
|
+
}
|
|
296
|
+
//# sourceMappingURL=log-store.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AgentRecord } from "./store.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Wire protocol version for the on-disk record log. Bump this whenever `AgentRecordBody`'s
|
|
4
|
+
* persisted shape changes, and register a migration for the previous version in
|
|
5
|
+
* `RECORD_MIGRATIONS` below.
|
|
6
|
+
*
|
|
7
|
+
* Version 1 introduced the linear `AgentRecord` format. Version 2 adds
|
|
8
|
+
* durable handoff linkage and seed provenance without invalidating version-1 records.
|
|
9
|
+
*/
|
|
10
|
+
export declare const WIRE_PROTOCOL_VERSION = 2;
|
|
11
|
+
/** KV state key under which a session stamps the version its log was written at. */
|
|
12
|
+
export declare const WIRE_VERSION_KEY = "wire_version";
|
|
13
|
+
/**
|
|
14
|
+
* Upgrades a raw record from version N to version N+1, keyed by the SOURCE version N.
|
|
15
|
+
* Returning `null` DROPS the record (for a record that has no place in the new format).
|
|
16
|
+
*/
|
|
17
|
+
export type RecordMigration = (raw: Record<string, unknown>) => Record<string, unknown> | null;
|
|
18
|
+
/** Version 2 adds durable handoff linkage/provenance; every version-1 record remains valid. */
|
|
19
|
+
export declare const RECORD_MIGRATIONS: Readonly<Record<number, RecordMigration>>;
|
|
20
|
+
/**
|
|
21
|
+
* Apply the migration chain to bring a raw record from `fromVersion` up to `toVersion`.
|
|
22
|
+
* Returns `null` if a migration dropped the record. `registry`/`toVersion` are injectable
|
|
23
|
+
* for tests.
|
|
24
|
+
*/
|
|
25
|
+
export declare function migrateRecord(raw: unknown, fromVersion: number, registry?: Record<number, RecordMigration>, toVersion?: number): AgentRecord | null;
|
|
26
|
+
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire protocol version for the on-disk record log. Bump this whenever `AgentRecordBody`'s
|
|
3
|
+
* persisted shape changes, and register a migration for the previous version in
|
|
4
|
+
* `RECORD_MIGRATIONS` below.
|
|
5
|
+
*
|
|
6
|
+
* Version 1 introduced the linear `AgentRecord` format. Version 2 adds
|
|
7
|
+
* durable handoff linkage and seed provenance without invalidating version-1 records.
|
|
8
|
+
*/
|
|
9
|
+
export const WIRE_PROTOCOL_VERSION = 2;
|
|
10
|
+
/** KV state key under which a session stamps the version its log was written at. */
|
|
11
|
+
export const WIRE_VERSION_KEY = "wire_version";
|
|
12
|
+
/** Version 2 adds durable handoff linkage/provenance; every version-1 record remains valid. */
|
|
13
|
+
export const RECORD_MIGRATIONS = {
|
|
14
|
+
1: (raw) => raw,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Apply the migration chain to bring a raw record from `fromVersion` up to `toVersion`.
|
|
18
|
+
* Returns `null` if a migration dropped the record. `registry`/`toVersion` are injectable
|
|
19
|
+
* for tests.
|
|
20
|
+
*/
|
|
21
|
+
export function migrateRecord(raw, fromVersion, registry = RECORD_MIGRATIONS, toVersion = WIRE_PROTOCOL_VERSION) {
|
|
22
|
+
let current = raw;
|
|
23
|
+
for (let v = fromVersion; v < toVersion; v++) {
|
|
24
|
+
if (current === null)
|
|
25
|
+
return null;
|
|
26
|
+
const migration = registry[v];
|
|
27
|
+
if (migration !== undefined)
|
|
28
|
+
current = migration(current);
|
|
29
|
+
}
|
|
30
|
+
return current;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=migrate.js.map
|