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,120 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
const BLOBREF_PREFIX = "blobref:";
|
|
5
|
+
const DEFAULT_THRESHOLD = 4096;
|
|
6
|
+
const DEFAULT_MAX_CACHE_BYTES = 50 * 1024 * 1024;
|
|
7
|
+
export function isBlobRef(value) {
|
|
8
|
+
return value.startsWith(BLOBREF_PREFIX);
|
|
9
|
+
}
|
|
10
|
+
/** Filesystem {@link BlobIO}: content-addressed `<blobsDir>/<sha>.bin`, crash-safe via tmp+rename. */
|
|
11
|
+
export function diskBlobIO(blobsDir) {
|
|
12
|
+
return {
|
|
13
|
+
async read(sha) {
|
|
14
|
+
try {
|
|
15
|
+
return await readFile(join(blobsDir, `${sha}.bin`));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
async write(sha, bytes) {
|
|
22
|
+
await mkdir(blobsDir, { recursive: true, mode: 0o700 });
|
|
23
|
+
const target = join(blobsDir, `${sha}.bin`);
|
|
24
|
+
// Content-addressed: identical bytes → identical file. tmp+rename so a crash can't leave a torn blob.
|
|
25
|
+
const tmp = `${target}.tmp.${process.pid}.${sha.slice(0, 8)}`;
|
|
26
|
+
await writeFile(tmp, bytes, { mode: 0o600 });
|
|
27
|
+
await rename(tmp, target);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Content-addressed sidecar store for large inline content (images). Oversized base64 `data` is
|
|
33
|
+
* written to a {@link BlobIO} (filesystem, Postgres, Redis…) under its sha256 and the inline value
|
|
34
|
+
* is replaced with a `blobref:<sha256>` marker. Same bytes → same key (dedup). A bounded LRU keeps
|
|
35
|
+
* hot blobs in memory.
|
|
36
|
+
*/
|
|
37
|
+
export class BlobStore {
|
|
38
|
+
io;
|
|
39
|
+
threshold;
|
|
40
|
+
maxCacheBytes;
|
|
41
|
+
cache = new Map();
|
|
42
|
+
cacheBytes = 0;
|
|
43
|
+
constructor(options) {
|
|
44
|
+
this.io = options.io ?? diskBlobIO(options.blobsDir);
|
|
45
|
+
this.threshold = options.threshold ?? DEFAULT_THRESHOLD;
|
|
46
|
+
this.maxCacheBytes = options.maxCacheBytes ?? DEFAULT_MAX_CACHE_BYTES;
|
|
47
|
+
}
|
|
48
|
+
/** base64 `data` → `blobref:<sha>` if oversized; pass-through otherwise (incl. already-ref). */
|
|
49
|
+
async offload(data) {
|
|
50
|
+
if (isBlobRef(data) || data.length <= this.threshold)
|
|
51
|
+
return data;
|
|
52
|
+
const bytes = Buffer.from(data, "base64");
|
|
53
|
+
const sha = createHash("sha256").update(bytes).digest("hex");
|
|
54
|
+
await this.io.write(sha, bytes);
|
|
55
|
+
this.cachePut(sha, bytes);
|
|
56
|
+
return `${BLOBREF_PREFIX}${sha}`;
|
|
57
|
+
}
|
|
58
|
+
/** `blobref:<sha>` → base64 `data`; pass-through for inline values. */
|
|
59
|
+
async load(data) {
|
|
60
|
+
if (!isBlobRef(data))
|
|
61
|
+
return data;
|
|
62
|
+
const sha = data.slice(BLOBREF_PREFIX.length);
|
|
63
|
+
const cached = this.cache.get(sha);
|
|
64
|
+
if (cached !== undefined)
|
|
65
|
+
return cached.toString("base64");
|
|
66
|
+
const bytes = await this.io.read(sha);
|
|
67
|
+
if (bytes === undefined)
|
|
68
|
+
throw new Error(`blob "${sha}" not found`);
|
|
69
|
+
this.cachePut(sha, bytes);
|
|
70
|
+
return bytes.toString("base64");
|
|
71
|
+
}
|
|
72
|
+
cachePut(sha, bytes) {
|
|
73
|
+
if (bytes.length > this.maxCacheBytes)
|
|
74
|
+
return;
|
|
75
|
+
if (this.cache.has(sha)) {
|
|
76
|
+
this.cache.delete(sha);
|
|
77
|
+
this.cacheBytes -= bytes.length;
|
|
78
|
+
}
|
|
79
|
+
this.cache.set(sha, bytes);
|
|
80
|
+
this.cacheBytes += bytes.length;
|
|
81
|
+
// Evict oldest (insertion-ordered Map) until under budget.
|
|
82
|
+
while (this.cacheBytes > this.maxCacheBytes) {
|
|
83
|
+
const oldest = this.cache.keys().next().value;
|
|
84
|
+
if (oldest === undefined)
|
|
85
|
+
break;
|
|
86
|
+
this.cacheBytes -= this.cache.get(oldest).length;
|
|
87
|
+
this.cache.delete(oldest);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** Deep-walk a record, transforming every `{type:'image', data, mimeType}` node's `data`.
|
|
92
|
+
* Non-mutating: returns a fresh structure so the caller's record is never altered. */
|
|
93
|
+
async function transformImages(value, fn) {
|
|
94
|
+
if (Array.isArray(value)) {
|
|
95
|
+
const out = [];
|
|
96
|
+
for (const item of value)
|
|
97
|
+
out.push(await transformImages(item, fn));
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
if (value !== null && typeof value === "object") {
|
|
101
|
+
const obj = value;
|
|
102
|
+
if (obj.type === "image" && typeof obj.data === "string" && typeof obj.mimeType === "string") {
|
|
103
|
+
return { ...obj, data: await fn(obj.data, obj.mimeType) };
|
|
104
|
+
}
|
|
105
|
+
const out = {};
|
|
106
|
+
for (const key of Object.keys(obj))
|
|
107
|
+
out[key] = await transformImages(obj[key], fn);
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
/** Replace oversized inline image data with blob refs (write side). */
|
|
113
|
+
export async function offloadRecord(record, blobs) {
|
|
114
|
+
return (await transformImages(record, (data) => blobs.offload(data)));
|
|
115
|
+
}
|
|
116
|
+
/** Replace blob refs with inline image data (read side). */
|
|
117
|
+
export async function rehydrateRecord(record, blobs) {
|
|
118
|
+
return (await transformImages(record, (data) => blobs.load(data)));
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=blob-store.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AgentRecord, ReadRecordPageOptions, ReadRecordsFilter, RecordPage, SessionStore, StateKey } from "./store.ts";
|
|
2
|
+
export type DurableSessionState = "idle" | "interrupted";
|
|
3
|
+
export interface SessionCatalogObserver {
|
|
4
|
+
activity(at: number, source: "log" | "state"): void | Promise<void>;
|
|
5
|
+
durableState(state: DurableSessionState, at: number): void | Promise<void>;
|
|
6
|
+
metadata?(value: unknown, at: number): void | Promise<void>;
|
|
7
|
+
flush?(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Decorates a repository-owned store with catalog maintenance. The session KV/log remains
|
|
11
|
+
* authoritative: callbacks run only after the corresponding write succeeds, and a broken
|
|
12
|
+
* derived catalog never turns that durable write into a reported failure. Repository startup
|
|
13
|
+
* reconciliation repairs the resulting stale summary.
|
|
14
|
+
*/
|
|
15
|
+
export declare class CatalogSessionStore implements SessionStore {
|
|
16
|
+
private readonly inner;
|
|
17
|
+
private readonly observer;
|
|
18
|
+
readonly listStateKeys?: () => Promise<readonly StateKey[]>;
|
|
19
|
+
readonly storageDir?: () => string | undefined;
|
|
20
|
+
constructor(inner: SessionStore, observer: SessionCatalogObserver);
|
|
21
|
+
appendRecord(record: AgentRecord): Promise<string>;
|
|
22
|
+
readRecords(filter?: ReadRecordsFilter): AsyncIterable<AgentRecord>;
|
|
23
|
+
readRecordPage(options: ReadRecordPageOptions): Promise<RecordPage>;
|
|
24
|
+
putState(key: StateKey, value: unknown): Promise<void>;
|
|
25
|
+
getState(key: StateKey): Promise<unknown | null>;
|
|
26
|
+
deleteState(key: StateKey): Promise<void>;
|
|
27
|
+
flush(): Promise<void>;
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
rewrite(address?: string): Promise<void>;
|
|
30
|
+
private notify;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=catalog-store.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decorates a repository-owned store with catalog maintenance. The session KV/log remains
|
|
3
|
+
* authoritative: callbacks run only after the corresponding write succeeds, and a broken
|
|
4
|
+
* derived catalog never turns that durable write into a reported failure. Repository startup
|
|
5
|
+
* reconciliation repairs the resulting stale summary.
|
|
6
|
+
*/
|
|
7
|
+
export class CatalogSessionStore {
|
|
8
|
+
inner;
|
|
9
|
+
observer;
|
|
10
|
+
listStateKeys;
|
|
11
|
+
storageDir;
|
|
12
|
+
constructor(inner, observer) {
|
|
13
|
+
this.inner = inner;
|
|
14
|
+
this.observer = observer;
|
|
15
|
+
if (inner.listStateKeys !== undefined)
|
|
16
|
+
this.listStateKeys = () => inner.listStateKeys();
|
|
17
|
+
if (inner.storageDir !== undefined)
|
|
18
|
+
this.storageDir = () => inner.storageDir();
|
|
19
|
+
}
|
|
20
|
+
async appendRecord(record) {
|
|
21
|
+
const sequence = await this.inner.appendRecord(record);
|
|
22
|
+
await this.notify(() => this.observer.activity(Date.now(), "log"));
|
|
23
|
+
return sequence;
|
|
24
|
+
}
|
|
25
|
+
readRecords(filter) {
|
|
26
|
+
return this.inner.readRecords(filter);
|
|
27
|
+
}
|
|
28
|
+
readRecordPage(options) {
|
|
29
|
+
return this.inner.readRecordPage(options);
|
|
30
|
+
}
|
|
31
|
+
async putState(key, value) {
|
|
32
|
+
await this.inner.putState(key, value);
|
|
33
|
+
const at = Date.now();
|
|
34
|
+
await this.notify(() => {
|
|
35
|
+
if (key === "interrupt")
|
|
36
|
+
return this.observer.durableState("interrupted", at);
|
|
37
|
+
if (key === "meta" && this.observer.metadata !== undefined)
|
|
38
|
+
return this.observer.metadata(value, at);
|
|
39
|
+
return this.observer.activity(at, "state");
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getState(key) {
|
|
43
|
+
return this.inner.getState(key);
|
|
44
|
+
}
|
|
45
|
+
async deleteState(key) {
|
|
46
|
+
await this.inner.deleteState(key);
|
|
47
|
+
const at = Date.now();
|
|
48
|
+
await this.notify(() => key === "interrupt"
|
|
49
|
+
? this.observer.durableState("idle", at)
|
|
50
|
+
: this.observer.activity(at, "state"));
|
|
51
|
+
}
|
|
52
|
+
async flush() {
|
|
53
|
+
await this.inner.flush?.();
|
|
54
|
+
await this.observer.flush?.();
|
|
55
|
+
}
|
|
56
|
+
async close() {
|
|
57
|
+
await this.inner.close?.();
|
|
58
|
+
await this.observer.flush?.();
|
|
59
|
+
}
|
|
60
|
+
async rewrite(address) {
|
|
61
|
+
await this.inner.rewrite?.(address);
|
|
62
|
+
await this.notify(() => this.observer.activity(Date.now(), "log"));
|
|
63
|
+
}
|
|
64
|
+
async notify(callback) {
|
|
65
|
+
try {
|
|
66
|
+
await callback();
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Catalog is a rebuildable read model. The authoritative write above already committed.
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=catalog-store.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type AgentRecord, type ReadRecordPageOptions, type ReadRecordsFilter, type RecordPage, type SessionStore, type StateKey } from "./store.ts";
|
|
2
|
+
export interface DiskSessionStoreOptions {
|
|
3
|
+
/** Inline image data (base64) longer than this is offloaded to a blob. Default 4096. */
|
|
4
|
+
readonly blobThreshold?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class DiskSessionStore implements SessionStore {
|
|
7
|
+
private readonly sessionDir;
|
|
8
|
+
private readonly blobStore;
|
|
9
|
+
private versionCache;
|
|
10
|
+
private upgraded;
|
|
11
|
+
private readonly metadataChecked;
|
|
12
|
+
private stateWrite;
|
|
13
|
+
private logWrite;
|
|
14
|
+
private lastSequence;
|
|
15
|
+
constructor(sessionDir: string, options?: DiskSessionStoreOptions);
|
|
16
|
+
storageDir(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Best-effort "last written" time: the newest mtime among state.json and the shard logs,
|
|
19
|
+
* which appendRecord/putState touch. Advances with activity — unlike the meta's stored
|
|
20
|
+
* updatedAt, stamped once at create. The repository's list() uses this for "most recently
|
|
21
|
+
* active" ordering. 0 if nothing is on disk yet.
|
|
22
|
+
*/
|
|
23
|
+
lastActivityMs(): Promise<number>;
|
|
24
|
+
appendRecord(record: AgentRecord): Promise<string>;
|
|
25
|
+
readRecords(filter?: ReadRecordsFilter): AsyncIterable<AgentRecord>;
|
|
26
|
+
readRecordPage(options: ReadRecordPageOptions): Promise<RecordPage>;
|
|
27
|
+
putState(key: StateKey, value: unknown): Promise<void>;
|
|
28
|
+
getState(key: StateKey): Promise<unknown | null>;
|
|
29
|
+
deleteState(key: StateKey): Promise<void>;
|
|
30
|
+
listStateKeys(): Promise<readonly StateKey[]>;
|
|
31
|
+
private withStateLock;
|
|
32
|
+
/** Force shard logs and state to disk. */
|
|
33
|
+
flush(): Promise<void>;
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
/** Re-emit shard logs compactly: migrated to the current wire version, blob-offloaded, and
|
|
36
|
+
* free of any torn trailing line. Records dropped by migration are removed; each shard is
|
|
37
|
+
* kept opening with a `metadata` record. */
|
|
38
|
+
rewrite(address?: string): Promise<void>;
|
|
39
|
+
/** Read a shard's raw lines and bring each record up to the current wire version + rehydrate
|
|
40
|
+
* any offloaded blobs. Records dropped by a migration are skipped. */
|
|
41
|
+
private readShardDecoded;
|
|
42
|
+
private readStored;
|
|
43
|
+
/** Ensure the shard's log opens with a `metadata` record. */
|
|
44
|
+
private ensureMetadata;
|
|
45
|
+
/** The version this log was written at; an absent stamp defaults to 0. */
|
|
46
|
+
private version;
|
|
47
|
+
/** On the first write of the process, reconcile a stale log to the current version. */
|
|
48
|
+
private ensureCurrentVersion;
|
|
49
|
+
private stampVersion;
|
|
50
|
+
private rewriteShard;
|
|
51
|
+
private listShards;
|
|
52
|
+
private readState;
|
|
53
|
+
private writeState;
|
|
54
|
+
private withLogLock;
|
|
55
|
+
private appendStored;
|
|
56
|
+
private nextSequence;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=disk-store.d.ts.map
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
import { appendFile, mkdir, open, readFile, readdir, rename, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { BlobStore, offloadRecord, rehydrateRecord } from "./blob-store.js";
|
|
5
|
+
import { compareSequence, pageRecords } from "./log-store.js";
|
|
6
|
+
import { migrateRecord, WIRE_PROTOCOL_VERSION, WIRE_VERSION_KEY } from "./migrate.js";
|
|
7
|
+
import { DEFAULT_ADDRESS, } from "./store.js";
|
|
8
|
+
const AGENTS_DIR = "agents";
|
|
9
|
+
const BLOBS_DIR = "blobs";
|
|
10
|
+
const LOG_FILE = "log.jsonl";
|
|
11
|
+
const STATE_FILE = "state.json";
|
|
12
|
+
export class DiskSessionStore {
|
|
13
|
+
sessionDir;
|
|
14
|
+
blobStore;
|
|
15
|
+
// The wire version this log was written at; cached after first read.
|
|
16
|
+
versionCache;
|
|
17
|
+
// Whether we've reconciled the log to the current wire version this process.
|
|
18
|
+
upgraded = false;
|
|
19
|
+
// Addresses whose shard has been checked for the leading `metadata` record this process.
|
|
20
|
+
metadataChecked = new Set();
|
|
21
|
+
// Serializes state.json read-modify-write across concurrent putState/deleteState calls.
|
|
22
|
+
stateWrite = Promise.resolve();
|
|
23
|
+
// One sequence space spans every shard. Keeping allocation + append in this chain makes
|
|
24
|
+
// the sequence order identical to durable append order within this store instance.
|
|
25
|
+
logWrite = Promise.resolve();
|
|
26
|
+
lastSequence;
|
|
27
|
+
constructor(sessionDir, options = {}) {
|
|
28
|
+
this.sessionDir = sessionDir;
|
|
29
|
+
this.blobStore = new BlobStore({ blobsDir: join(sessionDir, BLOBS_DIR), threshold: options.blobThreshold });
|
|
30
|
+
}
|
|
31
|
+
storageDir() {
|
|
32
|
+
return this.sessionDir;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Best-effort "last written" time: the newest mtime among state.json and the shard logs,
|
|
36
|
+
* which appendRecord/putState touch. Advances with activity — unlike the meta's stored
|
|
37
|
+
* updatedAt, stamped once at create. The repository's list() uses this for "most recently
|
|
38
|
+
* active" ordering. 0 if nothing is on disk yet.
|
|
39
|
+
*/
|
|
40
|
+
async lastActivityMs() {
|
|
41
|
+
let latest = 0;
|
|
42
|
+
const consider = async (p) => {
|
|
43
|
+
try {
|
|
44
|
+
const s = await stat(p);
|
|
45
|
+
if (s.mtimeMs > latest)
|
|
46
|
+
latest = s.mtimeMs;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
/* missing — ignore */
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
await consider(join(this.sessionDir, STATE_FILE));
|
|
53
|
+
try {
|
|
54
|
+
const shards = await readdir(join(this.sessionDir, AGENTS_DIR), { withFileTypes: true });
|
|
55
|
+
for (const entry of shards) {
|
|
56
|
+
if (entry.isDirectory())
|
|
57
|
+
await consider(join(this.sessionDir, AGENTS_DIR, entry.name, LOG_FILE));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
/* no shards yet — ignore */
|
|
62
|
+
}
|
|
63
|
+
return latest;
|
|
64
|
+
}
|
|
65
|
+
appendRecord(record) {
|
|
66
|
+
return this.withLogLock(async () => {
|
|
67
|
+
await this.ensureCurrentVersion();
|
|
68
|
+
const address = record.address ?? DEFAULT_ADDRESS;
|
|
69
|
+
const dir = join(this.sessionDir, AGENTS_DIR, shardName(address));
|
|
70
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
71
|
+
if (record.type === "metadata")
|
|
72
|
+
this.metadataChecked.add(address);
|
|
73
|
+
else
|
|
74
|
+
await this.ensureMetadata(address, dir);
|
|
75
|
+
const stamped = record.time !== undefined ? record : { ...record, time: Date.now() };
|
|
76
|
+
const stored = await offloadRecord(stamped, this.blobStore);
|
|
77
|
+
return this.appendStored(dir, stored);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async *readRecords(filter) {
|
|
81
|
+
const shards = filter?.address !== undefined ? [shardName(filter.address)] : await this.listShards();
|
|
82
|
+
for (const item of await this.readStored(shards))
|
|
83
|
+
yield item.record;
|
|
84
|
+
}
|
|
85
|
+
async readRecordPage(options) {
|
|
86
|
+
const shards = options.address !== undefined ? [shardName(options.address)] : await this.listShards();
|
|
87
|
+
return pageRecords(await this.readStored(shards), options);
|
|
88
|
+
}
|
|
89
|
+
async putState(key, value) {
|
|
90
|
+
// Serialize the read-modify-write on state.json so concurrent writes to different keys
|
|
91
|
+
// (e.g. the wire-version stamp and the subagent registry) don't clobber each other.
|
|
92
|
+
await this.withStateLock(async () => {
|
|
93
|
+
const state = await this.readState();
|
|
94
|
+
state[key] = value;
|
|
95
|
+
await this.writeState(state);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
async getState(key) {
|
|
99
|
+
const state = await this.readState();
|
|
100
|
+
return key in state ? (state[key] ?? null) : null;
|
|
101
|
+
}
|
|
102
|
+
async deleteState(key) {
|
|
103
|
+
await this.withStateLock(async () => {
|
|
104
|
+
const state = await this.readState();
|
|
105
|
+
if (!(key in state))
|
|
106
|
+
return;
|
|
107
|
+
delete state[key];
|
|
108
|
+
await this.writeState(state);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async listStateKeys() {
|
|
112
|
+
return Object.keys(await this.readState());
|
|
113
|
+
}
|
|
114
|
+
async withStateLock(fn) {
|
|
115
|
+
const run = this.stateWrite.then(fn, fn);
|
|
116
|
+
this.stateWrite = run.then(() => undefined, () => undefined);
|
|
117
|
+
return run;
|
|
118
|
+
}
|
|
119
|
+
/** Force shard logs and state to disk. */
|
|
120
|
+
async flush() {
|
|
121
|
+
await Promise.all([this.logWrite, this.stateWrite]);
|
|
122
|
+
for (const shard of await this.listShards()) {
|
|
123
|
+
await fsyncFile(join(this.sessionDir, AGENTS_DIR, shard, LOG_FILE));
|
|
124
|
+
}
|
|
125
|
+
await fsyncFile(join(this.sessionDir, STATE_FILE));
|
|
126
|
+
}
|
|
127
|
+
async close() {
|
|
128
|
+
await this.flush();
|
|
129
|
+
}
|
|
130
|
+
/** Re-emit shard logs compactly: migrated to the current wire version, blob-offloaded, and
|
|
131
|
+
* free of any torn trailing line. Records dropped by migration are removed; each shard is
|
|
132
|
+
* kept opening with a `metadata` record. */
|
|
133
|
+
async rewrite(address) {
|
|
134
|
+
await this.withLogLock(async () => {
|
|
135
|
+
const shards = address !== undefined ? [shardName(address)] : await this.listShards();
|
|
136
|
+
const fromVersion = await this.version();
|
|
137
|
+
for (const shard of shards)
|
|
138
|
+
await this.rewriteShard(shard, fromVersion);
|
|
139
|
+
await this.stampVersion();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
// ── internals ──
|
|
143
|
+
/** Read a shard's raw lines and bring each record up to the current wire version + rehydrate
|
|
144
|
+
* any offloaded blobs. Records dropped by a migration are skipped. */
|
|
145
|
+
async *readShardDecoded(shard) {
|
|
146
|
+
const version = await this.version();
|
|
147
|
+
for await (const stored of readRawLines(join(this.sessionDir, AGENTS_DIR, shard, LOG_FILE))) {
|
|
148
|
+
const migrated = migrateRecord(stored.record, version);
|
|
149
|
+
if (migrated !== null) {
|
|
150
|
+
yield { sequence: stored.sequence, record: await rehydrateRecord(migrated, this.blobStore) };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async readStored(shards) {
|
|
155
|
+
const all = [];
|
|
156
|
+
for (const shard of shards)
|
|
157
|
+
for await (const item of this.readShardDecoded(shard))
|
|
158
|
+
all.push(item);
|
|
159
|
+
all.sort((a, b) => compareSequence(a.sequence, b.sequence));
|
|
160
|
+
return all;
|
|
161
|
+
}
|
|
162
|
+
/** Ensure the shard's log opens with a `metadata` record. */
|
|
163
|
+
async ensureMetadata(address, dir) {
|
|
164
|
+
if (this.metadataChecked.has(address))
|
|
165
|
+
return;
|
|
166
|
+
this.metadataChecked.add(address);
|
|
167
|
+
for await (const _ of readRawLines(join(dir, LOG_FILE)))
|
|
168
|
+
return; // shard already has ≥1 line
|
|
169
|
+
await this.appendStored(dir, metadataRecord(address));
|
|
170
|
+
}
|
|
171
|
+
/** The version this log was written at; an absent stamp defaults to 0. */
|
|
172
|
+
async version() {
|
|
173
|
+
if (this.versionCache !== undefined)
|
|
174
|
+
return this.versionCache;
|
|
175
|
+
const stored = await this.getState(WIRE_VERSION_KEY);
|
|
176
|
+
this.versionCache = typeof stored === "number" ? stored : 0;
|
|
177
|
+
return this.versionCache;
|
|
178
|
+
}
|
|
179
|
+
/** On the first write of the process, reconcile a stale log to the current version. */
|
|
180
|
+
async ensureCurrentVersion() {
|
|
181
|
+
if (this.upgraded)
|
|
182
|
+
return;
|
|
183
|
+
this.upgraded = true;
|
|
184
|
+
const hasLog = (await this.listShards()).length > 0;
|
|
185
|
+
if (!hasLog) {
|
|
186
|
+
// Brand-new session: stamp current; nothing to migrate.
|
|
187
|
+
await this.stampVersion();
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const version = await this.version();
|
|
191
|
+
if (version < WIRE_PROTOCOL_VERSION) {
|
|
192
|
+
// Legacy/stale log: migrate every record and re-emit before appending current-shape ones,
|
|
193
|
+
// so the log never mixes versions.
|
|
194
|
+
for (const shard of await this.listShards())
|
|
195
|
+
await this.rewriteShard(shard, version);
|
|
196
|
+
await this.stampVersion();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async stampVersion() {
|
|
200
|
+
await this.putState(WIRE_VERSION_KEY, WIRE_PROTOCOL_VERSION);
|
|
201
|
+
this.versionCache = WIRE_PROTOCOL_VERSION;
|
|
202
|
+
}
|
|
203
|
+
async rewriteShard(shard, fromVersion) {
|
|
204
|
+
const dir = join(this.sessionDir, AGENTS_DIR, shard);
|
|
205
|
+
const target = join(dir, LOG_FILE);
|
|
206
|
+
const lines = [];
|
|
207
|
+
for await (const stored of readRawLines(target)) {
|
|
208
|
+
// Migrate to current, then offload (without rehydrating — existing blob refs pass through).
|
|
209
|
+
const migrated = migrateRecord(stored.record, fromVersion);
|
|
210
|
+
if (migrated === null)
|
|
211
|
+
continue; // a migration may drop a record
|
|
212
|
+
const offloaded = await offloadRecord(migrated, this.blobStore);
|
|
213
|
+
lines.push({ sequence: stored.sequence, record: offloaded });
|
|
214
|
+
}
|
|
215
|
+
const withMeta = withLeadingMetadata(lines, shardAddress(shard));
|
|
216
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
217
|
+
const tmp = `${target}.tmp.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
218
|
+
await writeFile(tmp, withMeta.length > 0 ? `${withMeta.map((line) => JSON.stringify(line)).join("\n")}\n` : "", { encoding: "utf-8", mode: 0o600 });
|
|
219
|
+
await rename(tmp, target);
|
|
220
|
+
this.metadataChecked.add(shardAddress(shard));
|
|
221
|
+
}
|
|
222
|
+
async listShards() {
|
|
223
|
+
try {
|
|
224
|
+
const dirents = await readdir(join(this.sessionDir, AGENTS_DIR), { withFileTypes: true });
|
|
225
|
+
return dirents.filter((d) => d.isDirectory()).map((d) => d.name);
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async readState() {
|
|
232
|
+
let raw;
|
|
233
|
+
try {
|
|
234
|
+
raw = await readFile(join(this.sessionDir, STATE_FILE), "utf-8");
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
return {};
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
const parsed = JSON.parse(raw);
|
|
241
|
+
return typeof parsed === "object" && parsed !== null ? parsed : {};
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
return {};
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async writeState(state) {
|
|
248
|
+
await mkdir(this.sessionDir, { recursive: true, mode: 0o700 });
|
|
249
|
+
const target = join(this.sessionDir, STATE_FILE);
|
|
250
|
+
const tmp = `${target}.tmp.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
251
|
+
await writeFile(tmp, `${JSON.stringify(state, null, 2)}\n`, { encoding: "utf-8", mode: 0o600 });
|
|
252
|
+
await rename(tmp, target);
|
|
253
|
+
}
|
|
254
|
+
async withLogLock(fn) {
|
|
255
|
+
const run = this.logWrite.then(fn, fn);
|
|
256
|
+
this.logWrite = run.then(() => undefined, () => undefined);
|
|
257
|
+
return run;
|
|
258
|
+
}
|
|
259
|
+
async appendStored(dir, record) {
|
|
260
|
+
const sequence = String(await this.nextSequence());
|
|
261
|
+
await appendFile(join(dir, LOG_FILE), `${JSON.stringify({ sequence, record })}\n`, "utf-8");
|
|
262
|
+
return sequence;
|
|
263
|
+
}
|
|
264
|
+
// The counter lives only in memory: every log line embeds its sequence, so the last
|
|
265
|
+
// allocated value is recoverable from the shard tails (allocation is globally monotonic,
|
|
266
|
+
// hence each shard's final line is its max, and rewrites never renumber).
|
|
267
|
+
async nextSequence() {
|
|
268
|
+
if (this.lastSequence === undefined) {
|
|
269
|
+
let last = 0n;
|
|
270
|
+
for (const shard of await this.listShards()) {
|
|
271
|
+
let tail;
|
|
272
|
+
for await (const stored of readRawLines(join(this.sessionDir, AGENTS_DIR, shard, LOG_FILE)))
|
|
273
|
+
tail = stored.sequence;
|
|
274
|
+
if (tail !== undefined && BigInt(tail) > last)
|
|
275
|
+
last = BigInt(tail);
|
|
276
|
+
}
|
|
277
|
+
this.lastSequence = last;
|
|
278
|
+
}
|
|
279
|
+
this.lastSequence += 1n;
|
|
280
|
+
return this.lastSequence;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/** The leading `metadata` record stamped at the head of a shard's log. */
|
|
284
|
+
function metadataRecord(address) {
|
|
285
|
+
return { type: "metadata", protocol_version: WIRE_PROTOCOL_VERSION, created_at: Date.now(), time: Date.now(), address };
|
|
286
|
+
}
|
|
287
|
+
/** Keep an existing leading metadata record and correct its informational address in place. */
|
|
288
|
+
function withLeadingMetadata(lines, address) {
|
|
289
|
+
const first = lines[0];
|
|
290
|
+
if (first !== undefined) {
|
|
291
|
+
try {
|
|
292
|
+
if (first.record["type"] === "metadata") {
|
|
293
|
+
return first.record["address"] === address
|
|
294
|
+
? [...lines]
|
|
295
|
+
: [{ sequence: first.sequence, record: { ...first.record, address } }, ...lines.slice(1)];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
/* malformed records are handled by the reader before rewrite */
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return [...lines];
|
|
303
|
+
}
|
|
304
|
+
function shardName(address) {
|
|
305
|
+
const addr = address ?? DEFAULT_ADDRESS;
|
|
306
|
+
const safe = addr.replaceAll(/[^a-zA-Z0-9_-]+/g, "_").replaceAll(/^_+|_+$/g, "");
|
|
307
|
+
if (safe.length === 0)
|
|
308
|
+
return DEFAULT_ADDRESS;
|
|
309
|
+
// Guard against collisions after sanitization by suffixing a short hash when the address
|
|
310
|
+
// contained stripped characters (so "a/b" and "a_b" don't share a shard).
|
|
311
|
+
if (safe === addr)
|
|
312
|
+
return safe;
|
|
313
|
+
const hash = createHash("sha256").update(addr).digest("hex").slice(0, 6);
|
|
314
|
+
return `${safe}_${hash}`;
|
|
315
|
+
}
|
|
316
|
+
/** Best-effort inverse of `shardName` for metadata stamping. Sanitized shards keep their name
|
|
317
|
+
* (address == shard); hash-suffixed shards can't be inverted, so the metadata `address` field is
|
|
318
|
+
* approximate — it is informational only (reduceHistory never reads it). */
|
|
319
|
+
function shardAddress(shard) {
|
|
320
|
+
return shard;
|
|
321
|
+
}
|
|
322
|
+
/** Yield each well-formed JSON record of a log file (a torn trailing line is tolerated). */
|
|
323
|
+
async function* readRawLines(filePath) {
|
|
324
|
+
let raw;
|
|
325
|
+
try {
|
|
326
|
+
raw = await readFile(filePath, "utf-8");
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const lines = raw.split("\n");
|
|
332
|
+
for (let i = 0; i < lines.length; i++) {
|
|
333
|
+
const line = lines[i].replace(/\r$/, "");
|
|
334
|
+
if (line === "")
|
|
335
|
+
continue;
|
|
336
|
+
try {
|
|
337
|
+
const parsed = JSON.parse(line);
|
|
338
|
+
if (typeof parsed.sequence !== "string" || !/^[1-9]\d*$/.test(parsed.sequence) || !isRecord(parsed.record)) {
|
|
339
|
+
throw new Error(`invalid stored record envelope`);
|
|
340
|
+
}
|
|
341
|
+
yield { sequence: parsed.sequence, record: parsed.record };
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
// The very last line may be a half-flushed write at crash time — tolerate it.
|
|
345
|
+
if (i === lines.length - 1)
|
|
346
|
+
return;
|
|
347
|
+
throw new Error(`log.jsonl: corrupted line ${i + 1} in ${filePath}: ${String(error)}`, { cause: error });
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function isRecord(value) {
|
|
352
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
353
|
+
}
|
|
354
|
+
async function fsyncFile(filePath) {
|
|
355
|
+
let handle;
|
|
356
|
+
try {
|
|
357
|
+
handle = await open(filePath, "r+");
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
return; // file doesn't exist yet — nothing to sync
|
|
361
|
+
}
|
|
362
|
+
try {
|
|
363
|
+
await handle.sync();
|
|
364
|
+
}
|
|
365
|
+
finally {
|
|
366
|
+
await handle.close();
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
//# sourceMappingURL=disk-store.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type { AgentRecord, AgentRecordBody, SessionStore, StateKey, ReadRecordsFilter, StoredAgentRecord, RecordOrder, ReadRecordPageOptions, RecordPage, WatchRecordsOptions, } from "./store.ts";
|
|
2
|
+
export { DEFAULT_ADDRESS, reduceHistory, summaryMessage, customMessage, watchRecordsByPolling } from "./store.ts";
|
|
3
|
+
export { MemorySessionLock, SessionBusyError } from "./lock.ts";
|
|
4
|
+
export type { SessionLock, SessionLease, AcquireLeaseOptions } from "./lock.ts";
|
|
5
|
+
export { LogSessionStore, MemoryStore } from "./log-store.ts";
|
|
6
|
+
export type { LogStoreOptions, ReadLinesPageOptions, StoredLogLine } from "./log-store.ts";
|
|
7
|
+
export { DiskSessionStore } from "./disk-store.ts";
|
|
8
|
+
export type { DiskSessionStoreOptions } from "./disk-store.ts";
|
|
9
|
+
export { PgSessionStore, PgSessionRepository, pgStorage } from "./pg.ts";
|
|
10
|
+
export type { PgPool, PgExecutor, PgClient, PgStorageOptions, PgTransaction } from "./pg.ts";
|
|
11
|
+
export { RedisSessionStore, RedisSessionRepository, redisStorage } from "./redis.ts";
|
|
12
|
+
export type { RedisClient, RedisStorageOptions } from "./redis.ts";
|
|
13
|
+
export { storageOver, memoryStorage, diskStorage } from "./storage.ts";
|
|
14
|
+
export type { SessionStorage } from "./storage.ts";
|
|
15
|
+
export { RedactingSessionStore } from "./redacting-store.ts";
|
|
16
|
+
export type { RedactingStoreOptions } from "./redacting-store.ts";
|
|
17
|
+
export { USER_PROMPT_ORIGIN } from "./origin.ts";
|
|
18
|
+
export type { PromptOrigin, UserPromptOrigin, UserFollowUpPromptOrigin, InjectionOrigin, BackgroundTaskOrigin, CronJobOrigin, CronMissedOrigin, CompactionSummaryOrigin, HandoffSeedOrigin, ExternalPromptOrigin, ExternalOriginMetadataValue, } from "./origin.ts";
|
|
19
|
+
export { MemorySessionRepository, DiskSessionRepository, generateSessionId, } from "./repository.ts";
|
|
20
|
+
export { SessionRepositoryConflictError, SessionRepositoryNotFoundError, } from "./repository.ts";
|
|
21
|
+
export type { SessionRepository, SessionHandle, SessionSummary, SessionMeta, CreateSessionInput, ForkSessionInput, ListSessionsFilter, OpenSessionOptions, DeleteSessionOptions, } from "./repository.ts";
|
|
22
|
+
export type { DurableSessionState } from "./catalog-store.ts";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|