@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,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical JSON contract that the SDK posts to TheoCloud at
|
|
3
|
+
* `POST /v1/agents/{id}/runs`. PaaS reads this to reconstruct the agent's
|
|
4
|
+
* tool catalog server-side (skills, plugins, hooks rules, MCP HTTP servers,
|
|
5
|
+
* subagents, providers, memory, context).
|
|
6
|
+
*
|
|
7
|
+
* Locked at `schemaVersion: "1.0"`. Adding fields is forward-compatible;
|
|
8
|
+
* removing or renaming requires a v2 ADR (see ADR D15).
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export interface CloudPayloadCloud {
|
|
13
|
+
repos: ReadonlyArray<{
|
|
14
|
+
url: string;
|
|
15
|
+
startingRef?: string;
|
|
16
|
+
}>;
|
|
17
|
+
autoCreatePR?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface HookRule {
|
|
20
|
+
event: string;
|
|
21
|
+
command?: string;
|
|
22
|
+
reject?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface McpHttpRedacted {
|
|
25
|
+
type: "http";
|
|
26
|
+
url: string;
|
|
27
|
+
}
|
|
28
|
+
export interface McpStdioRedacted {
|
|
29
|
+
type: "stdio";
|
|
30
|
+
command: string;
|
|
31
|
+
args?: ReadonlyArray<string>;
|
|
32
|
+
}
|
|
33
|
+
export interface SubagentRef {
|
|
34
|
+
description?: string;
|
|
35
|
+
systemPrompt?: string;
|
|
36
|
+
model?: {
|
|
37
|
+
id: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface ProvidersRedacted {
|
|
41
|
+
routes?: ReadonlyArray<{
|
|
42
|
+
provider: string;
|
|
43
|
+
model?: string;
|
|
44
|
+
}>;
|
|
45
|
+
fallback?: ReadonlyArray<string>;
|
|
46
|
+
}
|
|
47
|
+
export interface MemoryPayload {
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
index?: {
|
|
50
|
+
backend: "sqlite-vec" | "lance";
|
|
51
|
+
embedding?: {
|
|
52
|
+
provider: string;
|
|
53
|
+
model?: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aggregate context cap (T4.1, ADR D155).
|
|
3
|
+
*
|
|
4
|
+
* After per-file truncation, applies a second-level cap on the TOTAL
|
|
5
|
+
* size across all sources. Lower-priority sources are dropped when the
|
|
6
|
+
* sum would exceed `maxBytesTotal`. The last partially-fitting source
|
|
7
|
+
* is truncated to fit exactly into the remaining budget.
|
|
8
|
+
*
|
|
9
|
+
* EC-J: same-priority sources tie-break by absolute source path
|
|
10
|
+
* lex-ascending for deterministic ordering (prompt-cache stability).
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
/** Default aggregate cap (120k chars across all context files). D155. */
|
|
15
|
+
export declare const DEFAULT_MAX_BYTES_TOTAL = 120000;
|
|
16
|
+
export interface AggregatorSource {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly source: string;
|
|
19
|
+
readonly content: string;
|
|
20
|
+
readonly priority: number;
|
|
21
|
+
readonly truncated: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface AggregateResult {
|
|
24
|
+
readonly kept: AggregatorSource[];
|
|
25
|
+
readonly dropped: AggregatorSource[];
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-format context discovery runner (T5.1, ADRs D150-D156).
|
|
3
|
+
*
|
|
4
|
+
* Walks `DEFAULT_DISCOVERY_SPECS` (or caller override), loads each
|
|
5
|
+
* spec via the appropriate parser, applies `@import` resolution where
|
|
6
|
+
* declared, and returns a flat list of `AggregatorSource[]` ready for
|
|
7
|
+
* the aggregate cap.
|
|
8
|
+
*
|
|
9
|
+
* **EC-E privacy fix:** source disambiguation uses
|
|
10
|
+
* `relative(gitRoot ?? cwd, ...)` — NEVER absolute paths in
|
|
11
|
+
* `<source name="">`.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
import { type DiscoverySpec } from "./context-discovery.js";
|
|
16
|
+
export interface DiscoveryRunnerOptions {
|
|
17
|
+
/** Workspace root passed to all discovery scopes. */
|
|
18
|
+
readonly cwd: string;
|
|
19
|
+
/** Per-file truncation cap (D155). */
|
|
20
|
+
readonly maxBytesPerFile: number;
|
|
21
|
+
/** Optional override of the default registry. */
|
|
22
|
+
readonly specs?: ReadonlyArray<DiscoverySpec>;
|
|
23
|
+
/** Cursor MDC: file paths the LLM has touched this turn (EC-I: empty at send-time). */
|
|
24
|
+
readonly touchedFiles?: ReadonlyArray<string>;
|
|
25
|
+
/** When true, skip `theokit-context` spec — caller already handles the legacy path. */
|
|
26
|
+
readonly skipLegacyTheokitContext?: boolean;
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context file discovery (T1.1, ADRs D150 / D151).
|
|
3
|
+
*
|
|
4
|
+
* Discovers context files via three scopes:
|
|
5
|
+
* - `cwd-only` — single dir, single path lookup
|
|
6
|
+
* - `git-root-walk` — walk cwd → git-root, collect every directory's match
|
|
7
|
+
* (nearest-first ordering)
|
|
8
|
+
* - `globbed` — glob pattern relative to cwd (e.g. `.cursor/rules/*.mdc`)
|
|
9
|
+
*
|
|
10
|
+
* Pure `existsSync` checks — **no `.gitignore` parsing** (EC-A, KISS) and
|
|
11
|
+
* **no invented `.theokitignore`** (EC-B). Paths normalized via
|
|
12
|
+
* `realpath` to dedup symlink chains pointing to the same physical file
|
|
13
|
+
* (EC-F). Git worktrees work transparently because `.git` exists as a
|
|
14
|
+
* file in that case (EC-N).
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
/** Single filename ("AGENTS.md") or relative glob (".cursor/rules/*.mdc"). */
|
|
19
|
+
export type DiscoveryScope = "cwd-only" | "git-root-walk" | "globbed";
|
|
20
|
+
/** Parser to apply once file is read. */
|
|
21
|
+
export type DiscoveryParser = "plain-markdown" | "mdc" | "frontmatter-zod";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context source frontmatter schema (ADR D76 — mirrors D10 / hooks-frontmatter).
|
|
3
|
+
*
|
|
4
|
+
* Used by the markdown context loader (`context/<name>.md`). Each .md file
|
|
5
|
+
* represents one context source with structured frontmatter + optional
|
|
6
|
+
* prose body explaining why this source is part of the agent's context.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const ContextSourceFrontmatterSchema: z.ZodObject<{
|
|
11
|
+
name: z.ZodOptional<z.ZodString>;
|
|
12
|
+
path: z.ZodString;
|
|
13
|
+
enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
14
|
+
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export type ContextSourceFrontmatter = z.infer<typeof ContextSourceFrontmatterSchema>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@path/to/file` import resolver (T2.1, ADR D156).
|
|
3
|
+
*
|
|
4
|
+
* Anthropic/Gemini convention: lines that are EXACTLY `@path` get
|
|
5
|
+
* replaced with the imported file's content, recursively (5-hop cap),
|
|
6
|
+
* with cycle detection. Inline `see @x.md, also @y.md` references are
|
|
7
|
+
* NOT resolved (EC-Q — own-line only, mirrors Anthropic's actual
|
|
8
|
+
* behavior).
|
|
9
|
+
*
|
|
10
|
+
* EC-D fix: every imported file is itself capped at `maxBytesPerFile`
|
|
11
|
+
* via `loadPlainMarkdown` BEFORE concatenation. Prevents a CLAUDE.md
|
|
12
|
+
* with 5 imports of 30k each from ballooning to 150k of imported
|
|
13
|
+
* content before the outer cap fires.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export interface ResolveImportsOptions {
|
|
18
|
+
/** Absolute paths already resolved (cycle detection). */
|
|
19
|
+
readonly visited: Set<string>;
|
|
20
|
+
/** Current recursion depth — caps at MAX_HOPS. */
|
|
21
|
+
readonly depth: number;
|
|
22
|
+
/** Per-import file cap (EC-D). Forwarded to loadPlainMarkdown. */
|
|
23
|
+
readonly maxBytesPerFile: number;
|
|
24
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context file loaders + truncation (T1.2, ADRs D154 / D155 / D159).
|
|
3
|
+
*
|
|
4
|
+
* Reads context source files from disk, applies the per-file size cap
|
|
5
|
+
* with 70%/20% head/tail truncation, and emits the
|
|
6
|
+
* `context_files_truncated` telemetry counter when the cap fires.
|
|
7
|
+
* Pure (no I/O) for `truncateWithMarker` — testable in isolation.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
/** Default per-file cap (40k chars ≈ 10k tokens). D155. */
|
|
12
|
+
export declare const DEFAULT_MAX_BYTES_PER_FILE = 40000;
|
|
13
|
+
export interface LoadedSource {
|
|
14
|
+
/** Absolute path the content came from. */
|
|
15
|
+
readonly source: string;
|
|
16
|
+
readonly content: string;
|
|
17
|
+
readonly originalBytes: number;
|
|
18
|
+
readonly truncated: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface TruncateResult {
|
|
21
|
+
readonly truncated: boolean;
|
|
22
|
+
readonly finalContent: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Cap `content` at `max` characters with 70%/20% head/tail truncation
|
|
26
|
+
* and an explicit marker. Pure — no I/O, no telemetry.
|
|
27
|
+
*
|
|
28
|
+
* EC-C: when `max <= MARKER.length`, skip the marker entirely and
|
|
29
|
+
* return a head-only slice. Without this guard, `budget = max -
|
|
30
|
+
* MARKER.length` would go negative and `content.slice(-tailBytes)`
|
|
31
|
+
* would slice from the END of the string rather than truncating.
|
|
32
|
+
*
|
|
33
|
+
* EC-H: codepoint integrity — `String.slice()` operates on UTF-16
|
|
34
|
+
* code units, which can split surrogate pairs. We accept that
|
|
35
|
+
* trailing/leading replacement chars (U+FFFD) may appear at boundaries.
|
|
36
|
+
* Modern LLMs tolerate them; byte-exact safety would require Buffer
|
|
37
|
+
* slicing + TextDecoder with `fatal: true` retry, which adds complexity
|
|
38
|
+
* without value.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare function truncateWithMarker(content: string, max: number): TruncateResult;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ContextSettings, ContextSnapshot, SDKContextManager } from "../../types/context.js";
|
|
2
|
+
export declare class FileContextManager implements SDKContextManager {
|
|
3
|
+
private readonly cwd;
|
|
4
|
+
private readonly settings;
|
|
5
|
+
private readonly settingSourcesIncludeProject;
|
|
6
|
+
private state;
|
|
7
|
+
constructor(cwd: string, settings: ContextSettings, settingSourcesIncludeProject: boolean);
|
|
8
|
+
initialize(): Promise<void>;
|
|
9
|
+
refresh(): Promise<void>;
|
|
10
|
+
snapshot(): Promise<ContextSnapshot>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MDC (Markdown Cursor) parser for `.cursor/rules/*.mdc` (T3.1, ADR D154).
|
|
3
|
+
*
|
|
4
|
+
* Parses YAML frontmatter with `description` / `globs` / `alwaysApply`
|
|
5
|
+
* fields. Honors activation per Cursor's docs:
|
|
6
|
+
* - `alwaysApply: true` → activates unconditionally.
|
|
7
|
+
* - `alwaysApply: false` + matching glob in `touchedFiles` → activates.
|
|
8
|
+
* - `alwaysApply: false` + no glob match → skipped.
|
|
9
|
+
*
|
|
10
|
+
* **EC-I (v1 semantic):** at `agent.send()` time, `touchedFiles` is
|
|
11
|
+
* empty. Only `alwaysApply: true` rules activate. Per-glob activation
|
|
12
|
+
* arrives in v2 when we hook the file-read pipeline. Description-based
|
|
13
|
+
* "agent requested" classification is out of scope.
|
|
14
|
+
*
|
|
15
|
+
* Glob matching uses a tiny in-house `*` → `.*` regex (no new dep)
|
|
16
|
+
* sufficient for the patterns Cursor itself recommends.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export type McdFrontmatter = z.infer<typeof McdFrontmatterSchema>;
|
|
21
|
+
export interface McdParseResult {
|
|
22
|
+
readonly frontmatter: McdFrontmatter;
|
|
23
|
+
readonly body: string;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SDKAssistantMessage, SDKRequestMessage, SDKStatusMessage, SDKSystemMessage, SDKTaskMessage, SDKThinkingMessage, SDKToolUseMessage, SDKUserMessageEvent } from "../../types/messages.js";
|
|
2
|
+
import type { FixtureRequest } from "./fixture-types.js";
|
|
3
|
+
export declare function systemEvent(request: FixtureRequest, tools: string[]): SDKSystemMessage;
|
|
4
|
+
export declare function userEvent(request: FixtureRequest): SDKUserMessageEvent;
|
|
5
|
+
export declare function assistantText(request: FixtureRequest, text: string): SDKAssistantMessage;
|
|
6
|
+
export declare function thinkingEvent(request: FixtureRequest, text: string): SDKThinkingMessage;
|
|
7
|
+
export declare function toolCallRunning(request: FixtureRequest, callId: string, name: string): SDKToolUseMessage;
|
|
8
|
+
export declare function toolCallCompleted(request: FixtureRequest, callId: string, name: string): SDKToolUseMessage;
|
|
9
|
+
export declare function cloudStatus(request: FixtureRequest, status: SDKStatusMessage["status"]): SDKStatusMessage;
|
|
10
|
+
export declare function taskEvent(request: FixtureRequest, status: string): SDKTaskMessage;
|
|
11
|
+
export declare function requestEvent(request: FixtureRequest): SDKRequestMessage;
|
|
12
|
+
export declare function defaultLocalTools(request: FixtureRequest): string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ModelSelection } from "../../types/agent.js";
|
|
2
|
+
import type { ConversationTurn } from "../../types/conversation.js";
|
|
3
|
+
import type { SDKMessage } from "../../types/messages.js";
|
|
4
|
+
import type { Run, RunOperation, RunResult, RunStatus } from "../../types/run.js";
|
|
5
|
+
import type { FixtureScript } from "./fixture-types.js";
|
|
6
|
+
export declare abstract class FixtureRunBase implements Run {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly agentId: string;
|
|
9
|
+
status: RunStatus;
|
|
10
|
+
result?: string;
|
|
11
|
+
model?: ModelSelection;
|
|
12
|
+
durationMs?: number;
|
|
13
|
+
createdAt?: number;
|
|
14
|
+
protected readonly script: FixtureScript;
|
|
15
|
+
protected readonly startTime: number;
|
|
16
|
+
protected readonly supportedOps: Set<RunOperation>;
|
|
17
|
+
protected readonly listeners: Set<(status: RunStatus) => void>;
|
|
18
|
+
protected readonly terminationPromise: Promise<RunResult>;
|
|
19
|
+
protected resolveTermination: (value: RunResult) => void;
|
|
20
|
+
protected terminated: boolean;
|
|
21
|
+
private eventNotifier;
|
|
22
|
+
constructor(options: FixtureRunBaseOptions);
|
|
23
|
+
abstract bootstrap(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Subclasses driving real (non-fixture) runtimes should call this after
|
|
26
|
+
* pushing a new event into `this.script.events` so that already-awaiting
|
|
27
|
+
* consumers of `stream()` wake up and yield it.
|
|
28
|
+
*/
|
|
29
|
+
protected notifyNewEvents(): void;
|
|
30
|
+
stream(): AsyncGenerator<SDKMessage, void>;
|
|
31
|
+
wait(): Promise<RunResult>;
|
|
32
|
+
cancel(): Promise<void>;
|
|
33
|
+
conversation(): Promise<ConversationTurn[]>;
|
|
34
|
+
supports(op: RunOperation): boolean;
|
|
35
|
+
unsupportedReason(op: RunOperation): string | undefined;
|
|
36
|
+
onDidChangeStatus(listener: (status: RunStatus) => void): () => void;
|
|
37
|
+
protected transitionTo(nextStatus: RunStatus): void;
|
|
38
|
+
protected buildResult(status: RunStatus): RunResult;
|
|
39
|
+
/** Subclasses override to attach runtime-specific fields (e.g. cloud git info). */
|
|
40
|
+
protected extendRunResult(result: RunResult): RunResult;
|
|
41
|
+
/** Whether `onDidChangeStatus` should fire immediately with the current status. */
|
|
42
|
+
protected notifyImmediately(): boolean;
|
|
43
|
+
private notifyListener;
|
|
44
|
+
private notifyAllListeners;
|
|
45
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FixtureRequest, FixtureScript } from "./fixture-types.js";
|
|
2
|
+
export { extractMemoryFact, isMemoryWritePrompt } from "./memory-store.js";
|
|
3
|
+
export declare function isMemoryRecallPrompt(message: string, request: FixtureRequest): boolean;
|
|
4
|
+
export declare function memoryWriteScript(request: FixtureRequest): FixtureScript;
|
|
5
|
+
export declare function memoryRecallScript(request: FixtureRequest): FixtureScript;
|
|
6
|
+
export declare function returnAnswerScript(request: FixtureRequest, answer: string): FixtureScript;
|
|
7
|
+
export declare function buildCloudScript(request: FixtureRequest): FixtureScript;
|
|
8
|
+
export declare function slowRunScript(request: FixtureRequest): FixtureScript;
|
|
9
|
+
export declare function errorRunScript(request: FixtureRequest): FixtureScript;
|
|
10
|
+
export declare function returnOnlyScript(request: FixtureRequest): FixtureScript;
|
|
11
|
+
export declare function shellWithApprovalScript(request: FixtureRequest): FixtureScript;
|
|
12
|
+
export declare function twoShellCommandsScript(request: FixtureRequest): FixtureScript;
|
|
13
|
+
export declare function shellExplainScript(request: FixtureRequest): FixtureScript;
|
|
14
|
+
export declare function spawnSubagentsScript(request: FixtureRequest): FixtureScript;
|
|
15
|
+
export declare function listMcpToolsScript(request: FixtureRequest): FixtureScript;
|
|
16
|
+
export declare function webSearchScript(request: FixtureRequest): FixtureScript;
|
|
17
|
+
export declare function providerFallbackScript(request: FixtureRequest): FixtureScript;
|
|
18
|
+
export declare function printEnvScript(request: FixtureRequest): FixtureScript;
|
|
19
|
+
export declare function useSkillScript(request: FixtureRequest, skillName: string): FixtureScript;
|
|
20
|
+
export declare function contextAwareScript(request: FixtureRequest): FixtureScript;
|
|
21
|
+
export declare function defaultFinishedScript(request: FixtureRequest): FixtureScript;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fork agent primitive (T1.2, ADRs D110-D114).
|
|
3
|
+
*
|
|
4
|
+
* `forkAgentImpl(parent, options, deps)` creates a short-lived auxiliary
|
|
5
|
+
* agent that inherits the parent's credentials and **byte-identical**
|
|
6
|
+
* system prompt (D112 — cache hit) but runs with a reduced tool
|
|
7
|
+
* whitelist enforced via `AsyncLocalStorage` (D111). Memory plugins
|
|
8
|
+
* (`kind: "memory"`) are preserved so memory writes carry provenance
|
|
9
|
+
* (D114 + EC-B fix); general/model-provider plugins are dropped because
|
|
10
|
+
* the fork has its own `PluginManager.initialize` and double-registering
|
|
11
|
+
* is redundant.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface HookCommand {
|
|
2
|
+
command: string;
|
|
3
|
+
/** Optional matcher restricting the hook to specific tools (regex). */
|
|
4
|
+
matcher?: string;
|
|
5
|
+
/** Optional timeout in ms; defaults to 30s. */
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface HookDecision {
|
|
9
|
+
decision: "allow" | "deny" | "feedback";
|
|
10
|
+
reason?: string;
|
|
11
|
+
feedback?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface HookPayload {
|
|
14
|
+
event: HookEvent;
|
|
15
|
+
tool?: string;
|
|
16
|
+
input?: Record<string, unknown>;
|
|
17
|
+
output?: Record<string, unknown>;
|
|
18
|
+
agentId?: string;
|
|
19
|
+
runId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface HookExecutionResult {
|
|
22
|
+
decisions: HookDecision[];
|
|
23
|
+
blocked: boolean;
|
|
24
|
+
reason?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare class HooksExecutor {
|
|
27
|
+
private readonly cwd;
|
|
28
|
+
private config;
|
|
29
|
+
constructor(cwd: string);
|
|
30
|
+
initialize(settingSourcesIncludeProject: boolean): Promise<void>;
|
|
31
|
+
/** Fire every hook registered for `event` and aggregate the decisions. */
|
|
32
|
+
run(payload: HookPayload): Promise<HookExecutionResult>;
|
|
33
|
+
private commandsFor;
|
|
34
|
+
private executeOne;
|
|
35
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook frontmatter schema (ADR D76 — mirrors D10 SkillFrontmatter pattern).
|
|
3
|
+
*
|
|
4
|
+
* Used by the markdown hooks loader (`hooks/<name>.md`). Each .md file
|
|
5
|
+
* represents one hook entry with structured frontmatter + optional prose
|
|
6
|
+
* body explaining rationale.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
/** Hook events supported by the SDK runtime. Mirrors HookEvent in hooks-executor.ts. */
|
|
11
|
+
export declare const HOOK_EVENTS: readonly ["preRun", "postRun", "preToolUse", "postToolUse", "stop"];
|
|
12
|
+
export declare const HookFrontmatterSchema: z.ZodObject<{
|
|
13
|
+
event: z.ZodEnum<{
|
|
14
|
+
stop: "stop";
|
|
15
|
+
preRun: "preRun";
|
|
16
|
+
postRun: "postRun";
|
|
17
|
+
preToolUse: "preToolUse";
|
|
18
|
+
postToolUse: "postToolUse";
|
|
19
|
+
}>;
|
|
20
|
+
matcher: z.ZodString;
|
|
21
|
+
command: z.ZodString;
|
|
22
|
+
enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
23
|
+
priority: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
24
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
export type HookFrontmatter = z.infer<typeof HookFrontmatterSchema>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for loading the hooks config (T1.2, ADR D77).
|
|
3
|
+
*
|
|
4
|
+
* Detection order:
|
|
5
|
+
* 1. `.theokit/hooks/*.md` (markdown, frontmatter-validated) — canonical.
|
|
6
|
+
* 2. `.theokit/hooks.json` — legacy. Emits one-time deprecation warn.
|
|
7
|
+
* 3. Neither → empty config (no hooks).
|
|
8
|
+
*
|
|
9
|
+
* Consumed by `hooks-loader.ts` (boot-time validation) and
|
|
10
|
+
* `hooks-executor.ts` (runtime dispatch).
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export type HookEvent = "preRun" | "postRun" | "preToolUse" | "postToolUse" | "stop";
|
|
15
|
+
export interface HookCommand {
|
|
16
|
+
command: string;
|
|
17
|
+
matcher?: string;
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface HookConfig {
|
|
21
|
+
hooks?: Partial<Record<HookEvent, HookCommand[]>>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live-agent cache for production deploys (Production-Readiness #2, ADRs D307-D310).
|
|
3
|
+
*
|
|
4
|
+
* Caches `SDKAgent` instances by id with LRU eviction (when `size > maxAgents`)
|
|
5
|
+
* and an idle-timeout sweep (configurable interval, default 60s). Solves the
|
|
6
|
+
* "OOM at some point" failure mode of long-running Node servers that keep
|
|
7
|
+
* spawning fresh agents per conversation.
|
|
8
|
+
*
|
|
9
|
+
* **Distinct from `agent-registry.ts`** (the metadata registry that persists
|
|
10
|
+
* `RegisteredAgent` to `registry.json` per cwd). That module is the "address
|
|
11
|
+
* book"; this module is the "live cache". Conflating them violates SRP — see
|
|
12
|
+
* ADR D307.
|
|
13
|
+
*
|
|
14
|
+
* Defaults (ADR D308): `maxAgents: 100`, `idleTimeoutMs: 30 min`, sweep `60s`.
|
|
15
|
+
* Calibrated for indie/small-team Node deploys; high-traffic SaaS should
|
|
16
|
+
* `configure({ maxAgents: 1000 })`.
|
|
17
|
+
*
|
|
18
|
+
* @public (singleton exposed via `Agent.registry`)
|
|
19
|
+
*/
|
|
20
|
+
import type { SDKAgent } from "../../types/agent.js";
|
|
21
|
+
export type EvictReason = "lru" | "idle" | "explicit";
|
|
22
|
+
export interface AgentRegistryOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Maximum number of agents kept alive simultaneously. LRU eviction when
|
|
25
|
+
* exceeded. Default: 100.
|
|
26
|
+
*
|
|
27
|
+
* Setting `0` disables the cache entirely — every `Agent.getOrCreate`
|
|
28
|
+
* re-initializes (high cost, but predictable memory).
|
|
29
|
+
*/
|
|
30
|
+
maxAgents?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Idle timeout in milliseconds. Agents not used for this duration are
|
|
33
|
+
* evicted on the next sweep tick. Default: 1_800_000 (30 minutes).
|
|
34
|
+
* Set `0` to disable idle eviction.
|
|
35
|
+
*/
|
|
36
|
+
idleTimeoutMs?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Sweep interval in milliseconds. Default: 60_000 (60s).
|
|
39
|
+
* Lower = more responsive eviction but more CPU. Higher = staler entries.
|
|
40
|
+
*/
|
|
41
|
+
sweepIntervalMs?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Called whenever an agent is evicted. Listener errors are swallowed
|
|
44
|
+
* with a one-shot stderr warn (do not crash the eviction loop).
|
|
45
|
+
*/
|
|
46
|
+
onEvict?: (id: string, reason: EvictReason) => void;
|
|
47
|
+
}
|
|
48
|
+
export declare class LiveAgentRegistry {
|
|
49
|
+
#private;
|
|
50
|
+
/**
|
|
51
|
+
* Reconfigure registry behavior. Process-wide singleton (D310) — last
|
|
52
|
+
* configure call wins for all subsequent operations.
|
|
53
|
+
*/
|
|
54
|
+
configure(opts: AgentRegistryOptions): void;
|
|
55
|
+
/**
|
|
56
|
+
* Lookup a cached agent. `get` is a use — refreshes `lastUsedAt` so the
|
|
57
|
+
* entry survives LRU eviction.
|
|
58
|
+
*/
|
|
59
|
+
get(id: string): SDKAgent | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Insert or overwrite an agent in the cache. Triggers fire-and-forget LRU
|
|
62
|
+
* eviction when `size > maxAgents`.
|
|
63
|
+
*
|
|
64
|
+
* EC-4: when `id` already maps to a DIFFERENT agent instance, dispose the
|
|
65
|
+
* old one before overwriting (race protection against two `getOrCreate`
|
|
66
|
+
* calls creating two agents but only the second being cached — the first
|
|
67
|
+
* would leak file handles + lifecycle controllers).
|
|
68
|
+
*/
|
|
69
|
+
set(id: string, agent: SDKAgent): void;
|
|
70
|
+
/**
|
|
71
|
+
* Explicitly evict an agent by id. Returns `true` when the entry was
|
|
72
|
+
* present (false = already gone). Calls `agent.dispose()` + `onEvict`
|
|
73
|
+
* with reason `"explicit"`.
|
|
74
|
+
*/
|
|
75
|
+
evict(id: string): Promise<boolean>;
|
|
76
|
+
/**
|
|
77
|
+
* Evict every cached agent. Used by graceful shutdown (`process.on('SIGTERM')`)
|
|
78
|
+
* or end-of-test cleanup.
|
|
79
|
+
*/
|
|
80
|
+
evictAll(): Promise<void>;
|
|
81
|
+
/** Number of currently cached agents. */
|
|
82
|
+
size(): number;
|
|
83
|
+
/** Ids of cached agents, newest first (by lastUsedAt). */
|
|
84
|
+
ids(): readonly string[];
|
|
85
|
+
}
|
|
86
|
+
/** Process-wide singleton (ADR D310). */
|
|
87
|
+
export declare const liveAgentRegistry: LiveAgentRegistry;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `LocalAgent` constructor bootstrap helpers (extracted for G8 ≤400 LoC).
|
|
3
|
+
*
|
|
4
|
+
* Each helper builds one optional submanager from `AgentOptions` and
|
|
5
|
+
* the resolved workspace cwd. The constructor itself stays focused on
|
|
6
|
+
* the agentId / model wiring; submanager bootstrap is delegated here.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
import { FileContextManager } from "./context-manager.js";
|
|
11
|
+
import { type PluginMetadata, PluginsManager } from "./plugins-manager.js";
|
|
12
|
+
import { ProvidersManagerImpl } from "./providers-manager.js";
|
|
13
|
+
import { type SkillMetadata, SkillsManager } from "./skills-manager.js";
|
|
14
|
+
export declare function registerLocalAgent(args: {
|
|
15
|
+
agentId: string;
|
|
16
|
+
model: ModelSelection | undefined;
|
|
17
|
+
options: AgentOptions;
|
|
18
|
+
workspaceCwd: string;
|
|
19
|
+
}): void;
|
|
20
|
+
export interface BootstrappedSubmanagers {
|
|
21
|
+
context?: FileContextManager;
|
|
22
|
+
providers?: ProvidersManagerImpl;
|
|
23
|
+
skillsManager?: SkillsManager;
|
|
24
|
+
skills?: {
|
|
25
|
+
list: () => Promise<SkillMetadata[]>;
|
|
26
|
+
};
|
|
27
|
+
pluginsManager?: PluginsManager;
|
|
28
|
+
plugins?: {
|
|
29
|
+
list: () => Promise<PluginMetadata[]>;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export declare function bootstrapSubmanagers(args: {
|
|
33
|
+
options: AgentOptions;
|
|
34
|
+
workspaceCwd: string;
|
|
35
|
+
settingSourcesIncludeProject: boolean;
|
|
36
|
+
settingSourcesIncludePlugins: boolean;
|
|
37
|
+
}): BootstrappedSubmanagers;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatch helpers extracted from `LocalAgent` to keep its file under
|
|
3
|
+
* G8 (≤400 LoC). Builds the args for real-LLM and fixture run paths.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentDefinition, AgentOptions, ModelSelection } from "../../types/agent.js";
|
|
8
|
+
import type { Run, SDKUserMessage, SendOptions } from "../../types/run.js";
|
|
9
|
+
import type { MemoryToolSpec } from "../agent-loop/loop-types.js";
|
|
10
|
+
import type { PersonalityPreset } from "../personality/types.js";
|
|
11
|
+
import type { PluginManager } from "../plugins/manager.js";
|
|
12
|
+
import type { HooksExecutor } from "./hooks-executor.js";
|
|
13
|
+
import type { MemoryFact } from "./memory-store.js";
|
|
14
|
+
import { createRealLocalRun } from "./real-local-run.js";
|
|
15
|
+
export interface DispatchInputs {
|
|
16
|
+
agentId: string;
|
|
17
|
+
model: ModelSelection | undefined;
|
|
18
|
+
options: AgentOptions;
|
|
19
|
+
workspaceCwd: string;
|
|
20
|
+
hooksExecutor: HooksExecutor;
|
|
21
|
+
pluginManager: PluginManager;
|
|
22
|
+
resolvedSubagents: Record<string, AgentDefinition>;
|
|
23
|
+
settingSourcesIncludeProject: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare function buildRealRunOptions(args: {
|
|
26
|
+
inputs: DispatchInputs;
|
|
27
|
+
message: string | SDKUserMessage;
|
|
28
|
+
options: SendOptions;
|
|
29
|
+
systemPrompt: string | undefined;
|
|
30
|
+
priorMessages: ReadonlyArray<{
|
|
31
|
+
role: "user" | "assistant";
|
|
32
|
+
text: string;
|
|
33
|
+
}>;
|
|
34
|
+
memoryTools: ReadonlyArray<MemoryToolSpec> | undefined;
|
|
35
|
+
personalityToolWhitelist?: ReadonlyArray<string>;
|
|
36
|
+
personalityName?: string;
|
|
37
|
+
}): Parameters<typeof createRealLocalRun>[0];
|
|
38
|
+
export declare function createFixtureRunHelper(args: {
|
|
39
|
+
inputs: DispatchInputs;
|
|
40
|
+
message: string | SDKUserMessage;
|
|
41
|
+
options: SendOptions;
|
|
42
|
+
systemPrompt: string | undefined;
|
|
43
|
+
memoryFacts: ReadonlyArray<MemoryFact>;
|
|
44
|
+
}): Promise<Run>;
|
|
45
|
+
export declare function dispatchLocalRun(args: {
|
|
46
|
+
inputs: DispatchInputs;
|
|
47
|
+
message: string | SDKUserMessage;
|
|
48
|
+
sendOptions: SendOptions;
|
|
49
|
+
systemPrompt: string | undefined;
|
|
50
|
+
memoryFacts: ReadonlyArray<MemoryFact>;
|
|
51
|
+
priorMessages: ReadonlyArray<{
|
|
52
|
+
role: "user" | "assistant";
|
|
53
|
+
text: string;
|
|
54
|
+
}>;
|
|
55
|
+
memoryTools: ReadonlyArray<MemoryToolSpec> | undefined;
|
|
56
|
+
activePreset: PersonalityPreset | undefined;
|
|
57
|
+
}): Promise<Run>;
|