@theokit/sdk 1.5.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/CHANGELOG.md +1571 -0
- package/LICENSE +201 -0
- package/README.md +80 -0
- package/bin/theokit-migrate-config.mjs +269 -0
- package/bin/theokit-migrate-memory.mjs +116 -0
- package/dist/agent-builder.d.ts +52 -0
- package/dist/agent-factory.d.ts +39 -0
- package/dist/agent.d.ts +175 -0
- package/dist/batch.d.ts +11 -0
- package/dist/budget.d.ts +48 -0
- package/dist/cache.d.ts +74 -0
- package/dist/cron-1yxL3K2S.d.cts +221 -0
- package/dist/cron-BYVdYzob.d.ts +221 -0
- package/dist/cron.cjs +14655 -0
- package/dist/cron.cjs.map +1 -0
- package/dist/cron.d.cts +3 -0
- package/dist/cron.d.ts +71 -0
- package/dist/cron.js +14652 -0
- package/dist/cron.js.map +1 -0
- package/dist/define-tool.d.ts +35 -0
- package/dist/errors-CK8brCJ1.d.cts +448 -0
- package/dist/errors-CvAeEWgE.d.ts +448 -0
- package/dist/errors.cjs +255 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +3 -0
- package/dist/errors.d.ts +356 -0
- package/dist/errors.js +238 -0
- package/dist/errors.js.map +1 -0
- package/dist/eval.cjs +14826 -0
- package/dist/eval.cjs.map +1 -0
- package/dist/eval.d.cts +35 -0
- package/dist/eval.d.ts +35 -0
- package/dist/eval.js +14821 -0
- package/dist/eval.js.map +1 -0
- package/dist/generate-object.d.ts +67 -0
- package/dist/handoff.d.ts +55 -0
- package/dist/index.cjs +17127 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1878 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +17095 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/agent-loop/loop-types.d.ts +29 -0
- package/dist/internal/agent-loop/loop.d.ts +2 -0
- package/dist/internal/agent-loop/message-builders.d.ts +6 -0
- package/dist/internal/agent-loop/tool-dispatch.d.ts +4 -0
- package/dist/internal/agent-loop/usage-and-cost.d.ts +25 -0
- package/dist/internal/budget/calendar-window.d.ts +19 -0
- package/dist/internal/budget/compute-cost.d.ts +28 -0
- package/dist/internal/budget/enforcement.d.ts +32 -0
- package/dist/internal/budget/ledger.d.ts +25 -0
- package/dist/internal/budget/normalize-usage.d.ts +27 -0
- package/dist/internal/budget/pricing-registry.d.ts +36 -0
- package/dist/internal/budget/registry.d.ts +16 -0
- package/dist/internal/budget/usage-accumulator.d.ts +31 -0
- package/dist/internal/cache/cosine.d.ts +14 -0
- package/dist/internal/cache/embed-helper.d.ts +15 -0
- package/dist/internal/cache/key.d.ts +15 -0
- package/dist/internal/cache/lookup.d.ts +28 -0
- package/dist/internal/cache/store-handler.d.ts +24 -0
- package/dist/internal/cache/store-json.d.ts +48 -0
- package/dist/internal/cache/store.d.ts +54 -0
- package/dist/internal/cache/telemetry.d.ts +20 -0
- package/dist/internal/cache/ttl.d.ts +11 -0
- package/dist/internal/catalog/fixtures.d.ts +16 -0
- package/dist/internal/catalog/local-models.d.ts +24 -0
- package/dist/internal/cron/run-job.d.ts +1 -0
- package/dist/internal/cron/scheduler.d.ts +1 -0
- package/dist/internal/cron/store.d.ts +1 -0
- package/dist/internal/cron/validate.d.ts +1 -0
- package/dist/internal/env.d.ts +1 -0
- package/dist/internal/errors/mappers/anthropic.d.ts +30 -0
- package/dist/internal/errors/mappers/bedrock.d.ts +16 -0
- package/dist/internal/errors/mappers/ollama.d.ts +41 -0
- package/dist/internal/errors/mappers/openai-compatible.d.ts +25 -0
- package/dist/internal/errors/mappers/shared.d.ts +10 -0
- package/dist/internal/errors/mappers/vertex.d.ts +15 -0
- package/dist/internal/eval/aggregate.d.ts +9 -0
- package/dist/internal/eval/dataset-iter.d.ts +9 -0
- package/dist/internal/eval/runner.d.ts +9 -0
- package/dist/internal/eval/single-flight.d.ts +16 -0
- package/dist/internal/eval/telemetry.d.ts +23 -0
- package/dist/internal/fixture-mode.d.ts +16 -0
- package/dist/internal/handoff/dispatcher.d.ts +29 -0
- package/dist/internal/handoff/registry.d.ts +23 -0
- package/dist/internal/handoff/telemetry.d.ts +18 -0
- package/dist/internal/handoff/tool-injector.d.ts +34 -0
- package/dist/internal/http.d.ts +1 -0
- package/dist/internal/ids.d.ts +1 -0
- package/dist/internal/judge/judge-call.d.ts +35 -0
- package/dist/internal/judge/parse-verdict.d.ts +11 -0
- package/dist/internal/judge/types.d.ts +17 -0
- package/dist/internal/llm/anthropic-shared.d.ts +89 -0
- package/dist/internal/llm/anthropic.d.ts +9 -0
- package/dist/internal/llm/bedrock-anthropic.d.ts +36 -0
- package/dist/internal/llm/bedrock-token-cache.d.ts +18 -0
- package/dist/internal/llm/credential-pool-context.d.ts +11 -0
- package/dist/internal/llm/credential-pool-types.d.ts +22 -0
- package/dist/internal/llm/credential-pool.d.ts +18 -0
- package/dist/internal/llm/fallback-client.d.ts +1 -0
- package/dist/internal/llm/fault-injection.d.ts +50 -0
- package/dist/internal/llm/finish.d.ts +1 -0
- package/dist/internal/llm/model-identifier.d.ts +24 -0
- package/dist/internal/llm/ollama-native.d.ts +27 -0
- package/dist/internal/llm/openai.d.ts +9 -0
- package/dist/internal/llm/pool-aware-client.d.ts +16 -0
- package/dist/internal/llm/router.d.ts +17 -0
- package/dist/internal/llm/sse.d.ts +9 -0
- package/dist/internal/llm/stream-relay.d.ts +17 -0
- package/dist/internal/llm/types.d.ts +70 -0
- package/dist/internal/llm/vertex-anthropic.d.ts +40 -0
- package/dist/internal/llm/vertex-auth.d.ts +30 -0
- package/dist/internal/llm/vertex-gemini.d.ts +28 -0
- package/dist/internal/llm/vertex-router.d.ts +21 -0
- package/dist/internal/mcp/client.d.ts +16 -0
- package/dist/internal/memory/active-memory-cache.d.ts +10 -0
- package/dist/internal/memory/active-memory.d.ts +45 -0
- package/dist/internal/memory/adapters/catalog.d.ts +1 -0
- package/dist/internal/memory/adapters/deepinfra-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/mistral-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/ollama-embedding.d.ts +34 -0
- package/dist/internal/memory/adapters/openai-compatible.d.ts +23 -0
- package/dist/internal/memory/adapters/openai-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/openrouter-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/voyage-embedding.d.ts +2 -0
- package/dist/internal/memory/atomic-write.d.ts +7 -0
- package/dist/internal/memory/chunk-markdown.d.ts +2 -0
- package/dist/internal/memory/circuit-breaker.d.ts +22 -0
- package/dist/internal/memory/cwd-mutex.d.ts +1 -0
- package/dist/internal/memory/dreaming/diary.d.ts +4 -0
- package/dist/internal/memory/dreaming/phases.d.ts +15 -0
- package/dist/internal/memory/dreaming/run.d.ts +10 -0
- package/dist/internal/memory/embedding-adapter.d.ts +42 -0
- package/dist/internal/memory/embedding-cache.d.ts +1 -0
- package/dist/internal/memory/index-db.d.ts +10 -0
- package/dist/internal/memory/index-manager-dispatch.d.ts +23 -0
- package/dist/internal/memory/index-manager.d.ts +68 -0
- package/dist/internal/memory/index-schema.d.ts +21 -0
- package/dist/internal/memory/lance-index.d.ts +32 -0
- package/dist/internal/memory/lance-memory-adapter.d.ts +43 -0
- package/dist/internal/memory/markdown-store.d.ts +16 -0
- package/dist/internal/memory/memory-index.d.ts +52 -0
- package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +15 -0
- package/dist/internal/memory/migration.d.ts +9 -0
- package/dist/internal/memory/reader.d.ts +8 -0
- package/dist/internal/memory/session-loader.d.ts +1 -0
- package/dist/internal/memory/session-summary-writer.d.ts +2 -0
- package/dist/internal/memory/sqlite-vec-loader.d.ts +3 -0
- package/dist/internal/memory/tools.d.ts +14 -0
- package/dist/internal/memory/transcript-store.d.ts +1 -0
- package/dist/internal/memory/types.d.ts +17 -0
- package/dist/internal/memory/vec-index.d.ts +28 -0
- package/dist/internal/memory/wiki-loader.d.ts +2 -0
- package/dist/internal/observability/tracer-loader.d.ts +20 -0
- package/dist/internal/persistence/atomic-write.d.ts +1 -0
- package/dist/internal/persistence/conversation-storage-fs.d.ts +37 -0
- package/dist/internal/persistence/conversation-storage-memory.d.ts +24 -0
- package/dist/internal/persistence/cwd-mutex.d.ts +1 -0
- package/dist/internal/persistence/file-lock.d.ts +14 -0
- package/dist/internal/persistence/fts5-sanitize.d.ts +16 -0
- package/dist/internal/persistence/markdown-config-loader.d.ts +35 -0
- package/dist/internal/persistence/paths.d.ts +19 -0
- package/dist/internal/persistence/persistence-schema.d.ts +17 -0
- package/dist/internal/persistence/schema-version.d.ts +13 -0
- package/dist/internal/persistence/sqlite-wal.d.ts +10 -0
- package/dist/internal/personality/context.d.ts +17 -0
- package/dist/internal/personality/registry.d.ts +17 -0
- package/dist/internal/personality/store.d.ts +27 -0
- package/dist/internal/personality/switch.d.ts +36 -0
- package/dist/internal/personality/types.d.ts +18 -0
- package/dist/internal/plugins/context.d.ts +31 -0
- package/dist/internal/plugins/manager.d.ts +37 -0
- package/dist/internal/plugins/types.d.ts +102 -0
- package/dist/internal/providers/builtin/anthropic.d.ts +2 -0
- package/dist/internal/providers/builtin/bedrock.d.ts +25 -0
- package/dist/internal/providers/builtin/gemini.d.ts +10 -0
- package/dist/internal/providers/builtin/index.d.ts +19 -0
- package/dist/internal/providers/builtin/llamacpp.d.ts +1 -0
- package/dist/internal/providers/builtin/lmstudio.d.ts +1 -0
- package/dist/internal/providers/builtin/ollama.d.ts +17 -0
- package/dist/internal/providers/builtin/openai.d.ts +2 -0
- package/dist/internal/providers/builtin/openrouter.d.ts +2 -0
- package/dist/internal/providers/builtin/vertex.d.ts +27 -0
- package/dist/internal/providers/discovery.d.ts +14 -0
- package/dist/internal/providers/index.d.ts +8 -0
- package/dist/internal/providers/registry.d.ts +12 -0
- package/dist/internal/providers/types.d.ts +27 -0
- package/dist/internal/runtime/abort-utils.d.ts +21 -0
- package/dist/internal/runtime/agent-factory-registry.d.ts +16 -0
- package/dist/internal/runtime/agent-registry-store.d.ts +61 -0
- package/dist/internal/runtime/agent-registry.d.ts +34 -0
- package/dist/internal/runtime/agent-session-store.d.ts +3 -0
- package/dist/internal/runtime/agent-session.d.ts +2 -0
- package/dist/internal/runtime/async-local-storage.d.ts +20 -0
- package/dist/internal/runtime/async-semaphore.d.ts +24 -0
- package/dist/internal/runtime/budget.d.ts +36 -0
- package/dist/internal/runtime/cloud-agent.d.ts +1 -0
- package/dist/internal/runtime/cloud-config-serializer.d.ts +3 -0
- package/dist/internal/runtime/cloud-payload-types.d.ts +56 -0
- package/dist/internal/runtime/cloud-run.d.ts +1 -0
- package/dist/internal/runtime/cloud-tool-parity.d.ts +1 -0
- package/dist/internal/runtime/context-aggregator.d.ts +26 -0
- package/dist/internal/runtime/context-discovery-runner.d.ts +27 -0
- package/dist/internal/runtime/context-discovery.d.ts +21 -0
- package/dist/internal/runtime/context-frontmatter.d.ts +16 -0
- package/dist/internal/runtime/context-import-resolver.d.ts +24 -0
- package/dist/internal/runtime/context-loaders.d.ts +42 -0
- package/dist/internal/runtime/context-manager.d.ts +11 -0
- package/dist/internal/runtime/context-mdc-parser.d.ts +24 -0
- package/dist/internal/runtime/default-model.d.ts +1 -0
- package/dist/internal/runtime/fixture-events.d.ts +12 -0
- package/dist/internal/runtime/fixture-responder.d.ts +1 -0
- package/dist/internal/runtime/fixture-run-base.d.ts +45 -0
- package/dist/internal/runtime/fixture-scripts.d.ts +21 -0
- package/dist/internal/runtime/fixture-types.d.ts +1 -0
- package/dist/internal/runtime/fork-agent.d.ts +15 -0
- package/dist/internal/runtime/hooks-executor.d.ts +35 -0
- package/dist/internal/runtime/hooks-frontmatter.d.ts +26 -0
- package/dist/internal/runtime/hooks-source.d.ts +22 -0
- package/dist/internal/runtime/live-agent-registry.d.ts +87 -0
- package/dist/internal/runtime/local-agent-bootstrap.d.ts +37 -0
- package/dist/internal/runtime/local-agent-dispatch.d.ts +57 -0
- package/dist/internal/runtime/local-agent-invalidate.d.ts +8 -0
- package/dist/internal/runtime/local-agent-memory-direct.d.ts +12 -0
- package/dist/internal/runtime/local-agent-memory-hooks.d.ts +41 -0
- package/dist/internal/runtime/local-agent-memory.d.ts +1 -0
- package/dist/internal/runtime/local-agent-personality-extensions.d.ts +19 -0
- package/dist/internal/runtime/local-agent-plugins.d.ts +13 -0
- package/dist/internal/runtime/local-agent-runtime-extensions.d.ts +13 -0
- package/dist/internal/runtime/local-agent-task-wrap.d.ts +11 -0
- package/dist/internal/runtime/local-agent.d.ts +1 -0
- package/dist/internal/runtime/local-run.d.ts +1 -0
- package/dist/internal/runtime/memory-store.d.ts +4 -0
- package/dist/internal/runtime/plugin-frontmatter.d.ts +17 -0
- package/dist/internal/runtime/plugins-manager.d.ts +1 -0
- package/dist/internal/runtime/post-run-lifecycle.d.ts +1 -0
- package/dist/internal/runtime/providers-manager.d.ts +1 -0
- package/dist/internal/runtime/real-cloud-run.d.ts +2 -0
- package/dist/internal/runtime/real-local-run.d.ts +2 -0
- package/dist/internal/runtime/run-registry.d.ts +5 -0
- package/dist/internal/runtime/run-until.d.ts +22 -0
- package/dist/internal/runtime/shell-tool.d.ts +7 -0
- package/dist/internal/runtime/skill-frontmatter.d.ts +1 -0
- package/dist/internal/runtime/skills-manager.d.ts +1 -0
- package/dist/internal/runtime/spawn-collect.d.ts +8 -0
- package/dist/internal/runtime/subagents-loader.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/escape.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/local-assembly.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/pipeline.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/active-memory-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/base-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/context-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/memory-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/skills-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/safe-call.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/types.d.ts +5 -0
- package/dist/internal/runtime/system-prompt.d.ts +1 -0
- package/dist/internal/runtime/validate-agent-options.d.ts +1 -0
- package/dist/internal/runtime/workspace-dir.d.ts +9 -0
- package/dist/internal/runtime/yaml-frontmatter.d.ts +20 -0
- package/dist/internal/scorers/llm-judge.d.ts +24 -0
- package/dist/internal/security/index.d.ts +11 -0
- package/dist/internal/security/path-guard.d.ts +56 -0
- package/dist/internal/security/redact.d.ts +21 -0
- package/dist/internal/structured-output-helpers.d.ts +54 -0
- package/dist/internal/task/registry.d.ts +61 -0
- package/dist/internal/task/ring-buffer.d.ts +10 -0
- package/dist/internal/task/store.d.ts +59 -0
- package/dist/internal/task/subscribe.d.ts +15 -0
- package/dist/internal/task/telemetry.d.ts +27 -0
- package/dist/internal/telemetry/adapter-registry.d.ts +2 -0
- package/dist/internal/telemetry/adapters/langfuse.d.ts +2 -0
- package/dist/internal/telemetry/adapters/posthog.d.ts +2 -0
- package/dist/internal/telemetry/adapters/sentry.d.ts +2 -0
- package/dist/internal/telemetry/safe-require.d.ts +1 -0
- package/dist/internal/telemetry/tracer.d.ts +18 -0
- package/dist/internal/tool-dispatch/repair-middleware.d.ts +34 -0
- package/dist/internal/tool-dispatch/strip-think.d.ts +22 -0
- package/dist/internal/tool-registry/personality-filter.d.ts +37 -0
- package/dist/internal/workflow/ctx.d.ts +19 -0
- package/dist/internal/workflow/error-shape.d.ts +7 -0
- package/dist/internal/workflow/executor.d.ts +15 -0
- package/dist/internal/workflow/index.d.ts +12 -0
- package/dist/internal/workflow/retry-policy.d.ts +14 -0
- package/dist/internal/workflow/run-id.d.ts +9 -0
- package/dist/internal/workflow/single-flight.d.ts +18 -0
- package/dist/internal/workflow/snapshot-store.d.ts +23 -0
- package/dist/internal/workflow/step-agent.d.ts +12 -0
- package/dist/internal/workflow/step-branch.d.ts +10 -0
- package/dist/internal/workflow/step-dowhile.d.ts +8 -0
- package/dist/internal/workflow/step-fn.d.ts +10 -0
- package/dist/internal/workflow/step-foreach.d.ts +11 -0
- package/dist/internal/workflow/step-parallel.d.ts +17 -0
- package/dist/internal/workflow/step-sleep.d.ts +7 -0
- package/dist/internal/workflow/telemetry.d.ts +23 -0
- package/dist/internal/zod/to-json-schema.d.ts +21 -0
- package/dist/memory-adapter-helpers.d.ts +28 -0
- package/dist/memory.d.ts +123 -0
- package/dist/migrate.d.ts +33 -0
- package/dist/path-safety.cjs +126 -0
- package/dist/path-safety.cjs.map +1 -0
- package/dist/path-safety.d.cts +15 -0
- package/dist/path-safety.d.ts +15 -0
- package/dist/path-safety.js +120 -0
- package/dist/path-safety.js.map +1 -0
- package/dist/run-DkCD5DeO.d.cts +2181 -0
- package/dist/run-DkCD5DeO.d.ts +2181 -0
- package/dist/scorers.d.ts +75 -0
- package/dist/security.d.ts +67 -0
- package/dist/stream-object.d.ts +74 -0
- package/dist/task-store.cjs +237 -0
- package/dist/task-store.cjs.map +1 -0
- package/dist/task-store.d.cts +8 -0
- package/dist/task-store.d.ts +8 -0
- package/dist/task-store.js +233 -0
- package/dist/task-store.js.map +1 -0
- package/dist/task.d.ts +87 -0
- package/dist/theokit.d.ts +84 -0
- package/dist/tools/_path-scope.d.cts +8 -0
- package/dist/tools/_path-scope.d.ts +8 -0
- package/dist/tools/_subprocess.d.cts +28 -0
- package/dist/tools/_subprocess.d.ts +28 -0
- package/dist/tools/git-diff.d.cts +22 -0
- package/dist/tools/git-diff.d.ts +22 -0
- package/dist/tools/index.d.cts +29 -0
- package/dist/tools/index.d.ts +29 -0
- package/dist/tools/list-dir.d.cts +26 -0
- package/dist/tools/list-dir.d.ts +26 -0
- package/dist/tools/read-file.d.cts +31 -0
- package/dist/tools/read-file.d.ts +31 -0
- package/dist/tools/run-vitest.d.cts +46 -0
- package/dist/tools/run-vitest.d.ts +46 -0
- package/dist/tools/search-text.d.cts +32 -0
- package/dist/tools/search-text.d.ts +32 -0
- package/dist/tools.cjs +690 -0
- package/dist/tools.cjs.map +1 -0
- package/dist/tools.js +683 -0
- package/dist/tools.js.map +1 -0
- package/dist/trajectory-helpers.d.ts +31 -0
- package/dist/types/agent.d.ts +771 -0
- package/dist/types/batch.d.ts +112 -0
- package/dist/types/budget.d.ts +88 -0
- package/dist/types/cache.d.ts +76 -0
- package/dist/types/context.d.ts +93 -0
- package/dist/types/conversation-storage.d.ts +76 -0
- package/dist/types/conversation.d.ts +90 -0
- package/dist/types/cron.d.ts +150 -0
- package/dist/types/eval.d.ts +132 -0
- package/dist/types/goal-events.d.ts +95 -0
- package/dist/types/handoff.d.ts +135 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/mcp.d.ts +64 -0
- package/dist/types/memory-adapter.d.ts +175 -0
- package/dist/types/messages.d.ts +154 -0
- package/dist/types/providers.d.ts +102 -0
- package/dist/types/run.d.ts +215 -0
- package/dist/types/task.d.ts +131 -0
- package/dist/types/theokit.d.ts +61 -0
- package/dist/types/trajectory.d.ts +49 -0
- package/dist/types/updates.d.ts +148 -0
- package/dist/types/usage.d.ts +61 -0
- package/dist/types/workflow.d.ts +217 -0
- package/dist/workflow.cjs +2405 -0
- package/dist/workflow.cjs.map +1 -0
- package/dist/workflow.d.cts +97 -0
- package/dist/workflow.d.ts +97 -0
- package/dist/workflow.js +2398 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +183 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `agent.memory` direct API implementation (T2.2, ADR D141 / D142).
|
|
3
|
+
*
|
|
4
|
+
* Builds an `AgentMemory` impl over whichever third-party adapters
|
|
5
|
+
* the `PluginManager` aggregated. Lazy-resolves the adapter list on
|
|
6
|
+
* first access (EC-I: `initialize()` fires exactly once on first
|
|
7
|
+
* write/recall). Multi-adapter fan-out for writes; merge + dedupe by
|
|
8
|
+
* content for recalls.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory hook wiring for `LocalAgent.sendLocked` (T2.1, ADRs D141 / D145).
|
|
3
|
+
*
|
|
4
|
+
* Two helpers extracted to keep `local-agent.ts` under G8 (≤400 LoC):
|
|
5
|
+
* - `applyPreUserSendHook` — fires `pre_user_send`, caps recalled context
|
|
6
|
+
* at `maxRecallContextBytes` (EC-A), injects `<memory-context>` fence.
|
|
7
|
+
* - `wrapRunWithPostReplyHook` — Proxy-wraps the Run so
|
|
8
|
+
* `post_assistant_reply` fires once after `wait()` (fire-and-forget,
|
|
9
|
+
* errors → stderr per EC-O).
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
import type { Run, SDKUserMessage, SendOptions } from "../../types/run.js";
|
|
14
|
+
import type { PluginManager } from "../plugins/manager.js";
|
|
15
|
+
/**
|
|
16
|
+
* EC-A + EC-G + EC-H: fire `pre_user_send` hooks, cap recalled context,
|
|
17
|
+
* and prepend it as a `<memory-context>` fence around the original
|
|
18
|
+
* user text. Returns the (possibly wrapped) message preserving the
|
|
19
|
+
* `string | SDKUserMessage` shape the caller passed in.
|
|
20
|
+
*/
|
|
21
|
+
export declare function applyPreUserSendHook(args: {
|
|
22
|
+
pluginManager: PluginManager;
|
|
23
|
+
agentId: string;
|
|
24
|
+
options: AgentOptions;
|
|
25
|
+
original: string | SDKUserMessage;
|
|
26
|
+
userText: string;
|
|
27
|
+
sendOptions: SendOptions;
|
|
28
|
+
}): Promise<string | SDKUserMessage>;
|
|
29
|
+
/**
|
|
30
|
+
* Wrap a `Run` so `post_assistant_reply` fires once after `wait()`.
|
|
31
|
+
* Fire-and-forget — errors are surfaced to stderr (EC-O) so the caller
|
|
32
|
+
* never blocks on memory sync. Returns a Proxy preserving all other
|
|
33
|
+
* Run methods (stream, cancel, conversation).
|
|
34
|
+
*/
|
|
35
|
+
export declare function wrapRunWithPostReplyHook(args: {
|
|
36
|
+
pluginManager: PluginManager;
|
|
37
|
+
agentId: string;
|
|
38
|
+
options: AgentOptions;
|
|
39
|
+
run: Run;
|
|
40
|
+
userText: string;
|
|
41
|
+
}): Run;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personality-preset runtime extensions for {@link LocalAgent}.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `local-agent.ts` to keep that file under the 400-LoC
|
|
5
|
+
* guard (G8). The functions here implement the personality-related
|
|
6
|
+
* behaviour declared by ADRs D160-D168:
|
|
7
|
+
*
|
|
8
|
+
* - `resolveActivePersonalityPreset` — read the active preset honoring
|
|
9
|
+
* the fork ALS snapshot (D168 / EC-A).
|
|
10
|
+
* - `ensurePersonalityRegistryIfNeeded` — lazy-load registry when ANY
|
|
11
|
+
* slug is active.
|
|
12
|
+
* - `applyPersonalityOverlay` — overlay preset body on the base prompt.
|
|
13
|
+
* - `localAgentUsePersonality` — the full `Agent.usePersonality` flow:
|
|
14
|
+
* fork-scope no-op, registry lazy-load, then delegate to
|
|
15
|
+
* `performPersonalitySwitch` under the per-agent send mutex (EC-E).
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EC-1 (edge-case review): runtime discrimination between legacy plugin
|
|
3
|
+
* metadata `{ enabled: string[] }` (v1.2 shape) and the new code Plugin
|
|
4
|
+
* objects (v1.3+ Plugin discriminated union).
|
|
5
|
+
*
|
|
6
|
+
* Telegram-pro + 7 examples pass `plugins: { enabled: ["openrouter"] }`
|
|
7
|
+
* — an OBJECT, not an array. The new Plugin[] is an ARRAY. We discriminate
|
|
8
|
+
* by `Array.isArray` first, then by shape per-kind.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function isCodePlugin(p: unknown): p is Plugin;
|
|
13
|
+
export declare function extractCodePlugins(value: unknown): Plugin[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background-work runtime extensions for {@link LocalAgent} (T4.2 + T4.3).
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `local-agent.ts` to keep that file under the 400-LoC
|
|
5
|
+
* guard (G8). The two helpers below implement
|
|
6
|
+
* `LocalAgent.runUntil(goal, options)` and `LocalAgent.fork(options)`
|
|
7
|
+
* by lazy-importing the implementation modules and resolving
|
|
8
|
+
* `Agent.create` through the DI registry (see
|
|
9
|
+
* `agent-factory-registry.ts` for the cycle-avoidance rationale).
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T3.2 — register a `Run` from `LocalAgent.send({ task: ... })` as a
|
|
3
|
+
* Task in the observable registry. Extracted from `local-agent.ts`
|
|
4
|
+
* to keep that file under the 400-LoC quality gate (G8).
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare function registerRunAsTask(run: Run, agentId: string, taskOpt: true | {
|
|
9
|
+
id?: string;
|
|
10
|
+
meta?: Record<string, unknown>;
|
|
11
|
+
}, userText: string): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type MemoryConfig, type MemoryFact, redactSecrets } from "../memory/types.js";
|
|
2
|
+
export { redactSecrets };
|
|
3
|
+
export declare function readMemoryFacts(cwd: string, config: MemoryConfig): Promise<MemoryFact[]>;
|
|
4
|
+
export declare function appendMemoryFact(cwd: string, config: MemoryConfig, fact: MemoryFact): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin manifest frontmatter schema (ADR D76).
|
|
3
|
+
*
|
|
4
|
+
* Used by the markdown plugin loader (`plugins/<name>/PLUGIN.md`). Matches
|
|
5
|
+
* the legacy `plugin.json` shape consumed by `plugins-manager.ts`:
|
|
6
|
+
* `{ name, version, capabilities, entry }`. Frontmatter is flat — no
|
|
7
|
+
* nested provider object (parseSimpleYaml doesn't support nesting).
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare const PluginFrontmatterSchema: z.ZodObject<{
|
|
12
|
+
name: z.ZodOptional<z.ZodString>;
|
|
13
|
+
version: z.ZodOptional<z.ZodString>;
|
|
14
|
+
capabilities: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
15
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export type PluginFrontmatter = z.infer<typeof PluginFrontmatterSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Run } from "../../types/run.js";
|
|
2
|
+
export declare function registerRun(run: Run): void;
|
|
3
|
+
export declare function getRun(runId: string): Run | undefined;
|
|
4
|
+
export declare function listRunsByAgent(agentId: string): Run[];
|
|
5
|
+
export declare function clearRunRegistry(): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal-driven Ralph loop (T3.2, ADRs D115-D121).
|
|
3
|
+
*
|
|
4
|
+
* `runUntilImpl` is an `AsyncGenerator<GoalEvent, GoalResult, void>`:
|
|
5
|
+
* yields events as the loop progresses, returns the final result when
|
|
6
|
+
* the goal completes, fails, or is paused. The auxiliary judge model is
|
|
7
|
+
* injected via `deps.judge` so the generator stays free of the `Agent`
|
|
8
|
+
* façade import.
|
|
9
|
+
*
|
|
10
|
+
* EC-C fix: pre-aborted signals emit only `[paused]`, not `[active, paused]`.
|
|
11
|
+
* EC-D: `maxTurns: 0` is supported (vacuous yield active → failed).
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
import type { GoalEvent, GoalOptions, GoalResult } from "../../types/goal-events.js";
|
|
16
|
+
import type { JudgeContext, JudgeOptions } from "../judge/judge-call.js";
|
|
17
|
+
import type { JudgeResult } from "../judge/types.js";
|
|
18
|
+
/** DI contract: the judge is the only external touchpoint. */
|
|
19
|
+
export interface RunUntilDeps {
|
|
20
|
+
judge: (ctx: JudgeContext, opts?: JudgeOptions) => Promise<JudgeResult>;
|
|
21
|
+
}
|
|
22
|
+
export declare function runUntilImpl(agent: SDKAgent, goal: string, options: GoalOptions | undefined, deps: RunUntilDeps): AsyncGenerator<GoalEvent, GoalResult, void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SkillFrontmatterErrorCode = "missing_frontmatter" | "schema_invalid";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiny YAML-frontmatter parser shared by the file-based loaders (skills,
|
|
3
|
+
* subagents, hooks, context, plugins). Supports four scalar shapes:
|
|
4
|
+
*
|
|
5
|
+
* key: bar → "bar" (string)
|
|
6
|
+
* key: 42 → 42 (number)
|
|
7
|
+
* key: true → true (boolean)
|
|
8
|
+
* key: [a, b, c] → ["a","b","c"](string[])
|
|
9
|
+
* key: → undefined (caller's Zod default kicks in)
|
|
10
|
+
*
|
|
11
|
+
* Limitations (intentional — keep parser tiny, no dep):
|
|
12
|
+
* - No nested objects (use flat keys like `providerId` not `provider.id`).
|
|
13
|
+
* - No quoted strings — `match: "1"` becomes the literal 3-char string `"1"`.
|
|
14
|
+
* - List values cannot contain a literal comma inside an element; the
|
|
15
|
+
* `tags: [a,b, c]` splitter is greedy on `,`. Use multi-line lists or
|
|
16
|
+
* reword if you need this.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseSimpleYaml(text: string): Record<string, FrontmatterValue | undefined>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM-as-judge scorer implementation (ADR D205).
|
|
3
|
+
*
|
|
4
|
+
* Builds a transient agent with the judge model + apiKey, calls
|
|
5
|
+
* `Agent.prompt` with a structured judge prompt, parses score from
|
|
6
|
+
* the response. Returns 0 (with diagnostic reason) on any parse failure.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
import type { ModelSelection } from "../../types/agent.js";
|
|
11
|
+
import type { Score } from "../../types/eval.js";
|
|
12
|
+
import type { ProviderRoutingSettings } from "../../types/providers.js";
|
|
13
|
+
export interface LlmJudgeOptions {
|
|
14
|
+
readonly model: ModelSelection;
|
|
15
|
+
readonly apiKey: string;
|
|
16
|
+
readonly criteria: string;
|
|
17
|
+
/** "continuous" → [0, 1] real number. "discrete" → 0 or 1 only. Default: continuous. */
|
|
18
|
+
readonly rubric?: "continuous" | "discrete";
|
|
19
|
+
readonly providers?: ProviderRoutingSettings;
|
|
20
|
+
}
|
|
21
|
+
export declare function llmJudgeScore(options: LlmJudgeOptions & {
|
|
22
|
+
output: string;
|
|
23
|
+
expected?: unknown;
|
|
24
|
+
}): Promise<Score>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel for the canonical secret-redaction module (ADRs D68-D73).
|
|
3
|
+
*
|
|
4
|
+
* Consumers across the SDK output boundaries import from here:
|
|
5
|
+
* `internal/errors/mappers/shared.ts`, `internal/telemetry/tracer.ts`,
|
|
6
|
+
* `internal/runtime/agent-session-store.ts`,
|
|
7
|
+
* `internal/memory/migrate-sqlite-to-lance.ts`.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export { addPattern, maskToken, redactSecrets } from "./redact.js";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical path-guard module (ADRs D79-D81).
|
|
3
|
+
*
|
|
4
|
+
* Three primitives + one typed error:
|
|
5
|
+
* - `safePathJoin(base, ...parts)` — resolve THEN prefix-check (ADR D80).
|
|
6
|
+
* - `assertNoSymlinkEscape(path, base)` — `realpathSync` resolves entire
|
|
7
|
+
* symlink chain (EC-1 fix; Hermes v0.2 #386, #61).
|
|
8
|
+
* - `sanitizeIdentifier(input, { maxLen })` — strict grammar
|
|
9
|
+
* `^[a-z0-9][a-z0-9-_]*$` (ADR D81; case-insensitive on input,
|
|
10
|
+
* lowercase on output).
|
|
11
|
+
* - `PathTraversalError` — extends ConfigurationError with code
|
|
12
|
+
* `path_traversal` (ADR D65: no new hierarchy).
|
|
13
|
+
*
|
|
14
|
+
* Wire at all sites where user input becomes a path. CI lint gate
|
|
15
|
+
* `tests/lint/no-unguarded-path-input.test.ts` prevents regression
|
|
16
|
+
* (ADR D85).
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
import { ConfigurationError } from "../../errors.js";
|
|
21
|
+
/**
|
|
22
|
+
* Thrown when an agent tool is asked to read or write a sensitive path
|
|
23
|
+
* that the blocklist forbids (`.env`, `.git/`, `node_modules/`, `.theo/`,
|
|
24
|
+
* lock files). Distinct from `PathTraversalError` because the path is
|
|
25
|
+
* lexically inside the project — it is just sensitive.
|
|
26
|
+
*
|
|
27
|
+
* Extends `ConfigurationError` (no new error hierarchy per ADR D65).
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare class ForbiddenPathError extends ConfigurationError {
|
|
32
|
+
readonly name: string;
|
|
33
|
+
constructor(path: string);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Decide whether a project-relative path points to a known-sensitive file
|
|
37
|
+
* that a coding agent must not read or write.
|
|
38
|
+
*
|
|
39
|
+
* Universal blocklist (works for any agent operating on a project tree):
|
|
40
|
+
*
|
|
41
|
+
* - `.env`, `.env.<anything>` — except `.env.example` (template safe to read)
|
|
42
|
+
* - `.git/` — version control internals
|
|
43
|
+
* - `node_modules/` — dependency cache (changes don't belong to the user)
|
|
44
|
+
* - `.theo/` — TheoKit build artefacts / state
|
|
45
|
+
* - Lock files at any depth: `pnpm-lock.yaml`, `package-lock.json`,
|
|
46
|
+
* `yarn.lock`, `bun.lockb`
|
|
47
|
+
*
|
|
48
|
+
* Operates on path segments (forward-slash normalized). Cross-platform safe.
|
|
49
|
+
*
|
|
50
|
+
* Use together with `safePathJoin` + `assertNoSymlinkEscape`: the former two
|
|
51
|
+
* defeat traversal, this one defeats reading a file that is lexically inside
|
|
52
|
+
* the project but should not be agent-visible.
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export declare function isForbiddenPath(input: string): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical secret redaction module (ADRs D68-D73).
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for credential pattern masking across the SDK.
|
|
5
|
+
* Wired at output boundaries: `ErrorMetadata.raw` (mappers/shared.ts),
|
|
6
|
+
* telemetry span attributes (telemetry/tracer.ts), transcript JSONL
|
|
7
|
+
* appends (agent-session-store.ts), migration logger output
|
|
8
|
+
* (memory/migrate-sqlite-to-lance.ts).
|
|
9
|
+
*
|
|
10
|
+
* - D68: central module, single source of truth (replaces 2 duplicates)
|
|
11
|
+
* - D69: env snapshot at module init (prompt-injection defense)
|
|
12
|
+
* - D70: ON by default, warn on opt-out
|
|
13
|
+
* - D71: two-bucket masking — short fully masked, long preserves prefix+suffix
|
|
14
|
+
* - D72: `codeFile` opt-out for legitimate prefix-shaped content
|
|
15
|
+
* - D73: redact at OUTPUT boundaries, not at storage
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare function redactSecrets(text: unknown, opts?: {
|
|
20
|
+
codeFile?: boolean;
|
|
21
|
+
}): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { z as ZodNamespace, ZodType } from "zod";
|
|
2
|
+
import type { AgentOptions, CustomTool, LocalOptions, ModelSelection } from "../types/agent.js";
|
|
3
|
+
import type { ProviderRoutingSettings } from "../types/providers.js";
|
|
4
|
+
/**
|
|
5
|
+
* Load Zod via createRequire (it's an optional peer dep). Throws a typed
|
|
6
|
+
* ConfigurationError if Zod isn't installed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function requireZod(): typeof ZodNamespace;
|
|
9
|
+
/**
|
|
10
|
+
* Build the synthetic `output` tool used by both `generateObject` and
|
|
11
|
+
* `streamObject`. The handler captures the raw input on first call only
|
|
12
|
+
* (EC-D10 / EC-6: parallel tool use in Claude 3.5+ may invoke `output`
|
|
13
|
+
* twice; later calls are ignored).
|
|
14
|
+
*/
|
|
15
|
+
export declare function makeOutputTool(jsonSchema: Record<string, unknown>, onCapture: (input: unknown) => string | Promise<string> | undefined): CustomTool;
|
|
16
|
+
/**
|
|
17
|
+
* Assemble the AgentOptions for the transient agent. Shared shape:
|
|
18
|
+
* model + local + tools[output] + systemPrompt + apiKey.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildTransientAgentOptions(params: {
|
|
21
|
+
model: ModelSelection;
|
|
22
|
+
local: LocalOptions;
|
|
23
|
+
outputTool: CustomTool;
|
|
24
|
+
systemPrompt?: string;
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
providers?: ProviderRoutingSettings;
|
|
27
|
+
}): AgentOptions;
|
|
28
|
+
/**
|
|
29
|
+
* Best-effort extraction of token usage from a run result. Local runtimes
|
|
30
|
+
* may not expose it; default to zeros.
|
|
31
|
+
*/
|
|
32
|
+
export declare function extractUsage(result: unknown): {
|
|
33
|
+
inputTokens: number;
|
|
34
|
+
outputTokens: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Build the user-message prompt that instructs the model to call the
|
|
38
|
+
* `output` tool with a schema-matched structured answer.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildToolPrompt(prompt: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* One-shot setup shared by both `generateObject` and `streamObject`. Loads
|
|
43
|
+
* Zod, computes the JSON schema, primes the captured-raw / usage / retry
|
|
44
|
+
* state. Returns the values needed by the caller's loop.
|
|
45
|
+
*/
|
|
46
|
+
export declare function setupStructuredOutput<T extends ZodType>(schema: T, maxRetries: number | undefined): {
|
|
47
|
+
z: typeof ZodNamespace;
|
|
48
|
+
jsonSchema: Record<string, unknown>;
|
|
49
|
+
maxRetries: number;
|
|
50
|
+
initialUsage: {
|
|
51
|
+
inputTokens: number;
|
|
52
|
+
outputTokens: number;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `TaskRegistry` — the singleton coordinating Task submit/list/get/cancel/
|
|
3
|
+
* subscribe. Wraps the pluggable `TaskStore` (D364), the `AsyncSemaphore`
|
|
4
|
+
* (D135 / D369) and a per-task `RingBuffer<TaskEvent>` (D372) for
|
|
5
|
+
* late-attach replay.
|
|
6
|
+
*
|
|
7
|
+
* Edge cases absorbed:
|
|
8
|
+
* - EC-3: work-fn invocation goes through `Promise.resolve().then(...)`
|
|
9
|
+
* so synchronous throws become rejected promises.
|
|
10
|
+
* - EC-4: pre-aborted signal short-circuits to `cancelled` without
|
|
11
|
+
* acquiring a semaphore slot.
|
|
12
|
+
* - EC-7: cross-process cancel via the `cancelRequested` flag on
|
|
13
|
+
* `TaskHandle`. Registry polls at start + each progress event.
|
|
14
|
+
* - EC-9: store-update failures are caught + logged; the event is
|
|
15
|
+
* still emitted so subscribers always observe a terminal event.
|
|
16
|
+
* - EC-10: subscribe iterator implements `return()` for leak-free
|
|
17
|
+
* cleanup.
|
|
18
|
+
* - EC-11: reentrant submit (work-fn calling `Task.submit`) uses an
|
|
19
|
+
* ALS marker to bypass the semaphore queue, avoiding deadlock under
|
|
20
|
+
* low concurrency caps.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
import { type TaskCancelResult, type TaskEvent, type TaskFilter, type TaskHandle, type TaskKind, type TaskStoreOptions } from "../../types/task.js";
|
|
25
|
+
export interface TaskRegistryOptions {
|
|
26
|
+
readonly store?: TaskStoreOptions;
|
|
27
|
+
readonly maxConcurrent?: number;
|
|
28
|
+
readonly retentionMs?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface TaskWorkContext {
|
|
31
|
+
readonly signal: AbortSignal;
|
|
32
|
+
emit(payload: unknown): void;
|
|
33
|
+
}
|
|
34
|
+
type WorkFn<T> = (ctx: TaskWorkContext) => Promise<T> | T;
|
|
35
|
+
export declare function __resetTaskRegistryForTests(): void;
|
|
36
|
+
export declare function __getSubscribersCountForTests(taskId: string): number;
|
|
37
|
+
export declare function __getCancelRequestedForTests(_taskId: string): boolean | undefined;
|
|
38
|
+
export declare function configure(opts: TaskRegistryOptions): void;
|
|
39
|
+
interface SubmitInternal<T> {
|
|
40
|
+
readonly kind: TaskKind;
|
|
41
|
+
readonly work: WorkFn<T>;
|
|
42
|
+
readonly id?: string;
|
|
43
|
+
readonly meta?: Record<string, unknown>;
|
|
44
|
+
readonly signal?: AbortSignal;
|
|
45
|
+
/** When true (adapter-internal), the validator allows reserved prefixes. */
|
|
46
|
+
readonly allowReservedPrefix?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Submit a task. Validates id (D368, EC-5 via allowReservedPrefix),
|
|
50
|
+
* handles pre-aborted signals (EC-4), enforces single-flight by id
|
|
51
|
+
* (D367), runs work under semaphore (D369/EC-11 reentrant bypass),
|
|
52
|
+
* and produces the canonical event stream (D366).
|
|
53
|
+
*/
|
|
54
|
+
export declare function submit<T>(internal: SubmitInternal<T>): Promise<TaskHandle>;
|
|
55
|
+
export declare function list(filter?: TaskFilter): Promise<TaskHandle[]>;
|
|
56
|
+
export declare function get(id: string): Promise<TaskHandle | undefined>;
|
|
57
|
+
export declare function cancel(id: string, reason?: string): Promise<TaskCancelResult>;
|
|
58
|
+
export declare const subscribe: (id: string) => AsyncIterable<TaskEvent>;
|
|
59
|
+
/** Manual trigger for tests. */
|
|
60
|
+
export declare function evictNow(now?: number): Promise<number>;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded FIFO ring buffer for late-attach replay (ADR D372).
|
|
3
|
+
*
|
|
4
|
+
* Push always succeeds; when the buffer is at capacity the oldest
|
|
5
|
+
* entry is dropped and the `truncated` flag flips to `true`. Drain
|
|
6
|
+
* returns a snapshot + the current truncated flag.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `TaskStore` interface + 2 implementations (ADR D364).
|
|
3
|
+
*
|
|
4
|
+
* - `InMemoryTaskStore` — default, transient, single-process.
|
|
5
|
+
* - `JsonFileTaskStore` — opt-in, one JSON file per task under a
|
|
6
|
+
* dedicated dir; single-process invariant (EC-15 documented).
|
|
7
|
+
*
|
|
8
|
+
* Edge cases absorbed:
|
|
9
|
+
* - EC-1: constructor auto-creates dir (mkdirSync recursive idempotent).
|
|
10
|
+
* - EC-2: every method validates the task id against the public
|
|
11
|
+
* grammar (D368) BEFORE doing any path I/O — path-traversal defense.
|
|
12
|
+
* - EC-6: `list()` returns `[]` on ENOENT (fresh install path).
|
|
13
|
+
* - EC-8: `list()` skips `.tmp.*` orphan files left by interrupted
|
|
14
|
+
* atomic writes.
|
|
15
|
+
* - EC-14 (DOCUMENT): `list()` JSDoc documents the 256-row hard cap
|
|
16
|
+
* and the `submittedBefore` paging idiom.
|
|
17
|
+
* - EC-15 (DOCUMENT): `JsonFileTaskStore` JSDoc documents the
|
|
18
|
+
* single-process invariant; v0.2 SQLite covers cross-process.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
import { type TaskFilter, type TaskHandle, type TaskStoreOptions } from "../../types/task.js";
|
|
23
|
+
/** Storage interface used by `TaskRegistry`. */
|
|
24
|
+
export interface TaskStore {
|
|
25
|
+
insert(handle: TaskHandle): Promise<void>;
|
|
26
|
+
update(id: string, mutate: (h: TaskHandle) => TaskHandle): Promise<TaskHandle | undefined>;
|
|
27
|
+
get(id: string): Promise<TaskHandle | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Returns at most `filter.limit ?? 100` matching handles. JsonFile
|
|
30
|
+
* backend hard-caps loaded entries at 256 — callers needing larger
|
|
31
|
+
* pages must use `submittedBefore` to walk the timeline.
|
|
32
|
+
*/
|
|
33
|
+
list(filter: TaskFilter): Promise<TaskHandle[]>;
|
|
34
|
+
delete(id: string): Promise<boolean>;
|
|
35
|
+
/** Removes terminal handles whose terminal-timestamp is older than `epochMs`. */
|
|
36
|
+
evictTerminalOlderThan(epochMs: number): Promise<number>;
|
|
37
|
+
}
|
|
38
|
+
export declare class InMemoryTaskStore implements TaskStore {
|
|
39
|
+
private readonly map;
|
|
40
|
+
insert(handle: TaskHandle): Promise<void>;
|
|
41
|
+
update(id: string, mutate: (h: TaskHandle) => TaskHandle): Promise<TaskHandle | undefined>;
|
|
42
|
+
get(id: string): Promise<TaskHandle | undefined>;
|
|
43
|
+
list(filter: TaskFilter): Promise<TaskHandle[]>;
|
|
44
|
+
delete(id: string): Promise<boolean>;
|
|
45
|
+
evictTerminalOlderThan(epochMs: number): Promise<number>;
|
|
46
|
+
}
|
|
47
|
+
export declare class JsonFileTaskStore implements TaskStore {
|
|
48
|
+
private readonly dir;
|
|
49
|
+
constructor(dir: string);
|
|
50
|
+
private filePath;
|
|
51
|
+
insert(handle: TaskHandle): Promise<void>;
|
|
52
|
+
update(id: string, mutate: (h: TaskHandle) => TaskHandle): Promise<TaskHandle | undefined>;
|
|
53
|
+
get(id: string): Promise<TaskHandle | undefined>;
|
|
54
|
+
list(filter: TaskFilter): Promise<TaskHandle[]>;
|
|
55
|
+
delete(id: string): Promise<boolean>;
|
|
56
|
+
evictTerminalOlderThan(epochMs: number): Promise<number>;
|
|
57
|
+
}
|
|
58
|
+
/** Factory used by `TaskRegistry.configure` (D364). */
|
|
59
|
+
export declare function getTaskStoreFor(options: TaskStoreOptions): TaskStore;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `subscribe(id)` — emits the per-task event stream (D372 ring buffer
|
|
3
|
+
* + live tail). The returned AsyncIterable implements `return()` for
|
|
4
|
+
* leak-free cleanup (EC-10).
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
import { type TaskEvent } from "../../types/task.js";
|
|
9
|
+
import type { RingBuffer } from "./ring-buffer.js";
|
|
10
|
+
export interface SubscribeDeps {
|
|
11
|
+
getBuffer(id: string): RingBuffer<TaskEvent> | undefined;
|
|
12
|
+
getOrCreateSubscriberSet(id: string): Set<(e: TaskEvent) => void>;
|
|
13
|
+
removeSubscriber(id: string, cb: (e: TaskEvent) => void): void;
|
|
14
|
+
}
|
|
15
|
+
export declare function buildSubscribe(deps: SubscribeDeps): (id: string) => AsyncIterable<TaskEvent>;
|