@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,68 @@
|
|
|
1
|
+
import type { EmbeddingRuntime } from "./embedding-adapter.js";
|
|
2
|
+
import { type MemoryIndex } from "./memory-index.js";
|
|
3
|
+
export interface IndexStatus {
|
|
4
|
+
backend: "fts-only" | "hybrid";
|
|
5
|
+
filesIndexed: number;
|
|
6
|
+
chunksIndexed: number;
|
|
7
|
+
lastSyncMs?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface SearchOptions {
|
|
10
|
+
maxResults?: number;
|
|
11
|
+
minScore?: number;
|
|
12
|
+
sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
|
|
13
|
+
/** 0..1 — vector vs text weight in hybrid scoring (D4). Default 0.6. */
|
|
14
|
+
vectorWeight?: number;
|
|
15
|
+
/** 0..1 — text weight in hybrid scoring. Default 0.4. */
|
|
16
|
+
textWeight?: number;
|
|
17
|
+
}
|
|
18
|
+
/** Vector backend selector. SQLite default; Lance opt-in (ADR D43). */
|
|
19
|
+
export type MemoryBackend = "sqlite-vec" | "lance";
|
|
20
|
+
export interface OpenIndexOptions {
|
|
21
|
+
cwd: string;
|
|
22
|
+
filePath?: string;
|
|
23
|
+
/** When provided, vector index is enabled in hybrid mode. */
|
|
24
|
+
embedding?: EmbeddingRuntime;
|
|
25
|
+
/** Vector backend. Default and only value today: `"sqlite-vec"`. */
|
|
26
|
+
backend?: MemoryBackend;
|
|
27
|
+
}
|
|
28
|
+
export declare class IndexManager implements MemoryIndex {
|
|
29
|
+
private readonly cwd;
|
|
30
|
+
private readonly db;
|
|
31
|
+
private readonly embedding;
|
|
32
|
+
private lastSyncMs;
|
|
33
|
+
private vectorReady;
|
|
34
|
+
private constructor();
|
|
35
|
+
/**
|
|
36
|
+
* Open a memory index. Dispatches to SQLite (default) or Lance (opt-in
|
|
37
|
+
* via `backend: "lance"`). See `openLanceInternal` for Lance-specific
|
|
38
|
+
* preconditions + typed errors.
|
|
39
|
+
*/
|
|
40
|
+
static open(opts: OpenIndexOptions & {
|
|
41
|
+
backend: "lance";
|
|
42
|
+
}): Promise<MemoryIndex>;
|
|
43
|
+
static open(opts: Omit<OpenIndexOptions, "backend"> | (OpenIndexOptions & {
|
|
44
|
+
backend?: "sqlite-vec";
|
|
45
|
+
})): Promise<IndexManager>;
|
|
46
|
+
/** Internal SQLite-path open. Renamed from previous public `open`. */
|
|
47
|
+
private static openSqliteInternal;
|
|
48
|
+
private initVectorBackend;
|
|
49
|
+
/** Walk the memory corpus + (re)index changed files. */
|
|
50
|
+
sync(): Promise<{
|
|
51
|
+
filesScanned: number;
|
|
52
|
+
filesUpdated: number;
|
|
53
|
+
chunksWritten: number;
|
|
54
|
+
chunksEmbedded: number;
|
|
55
|
+
}>;
|
|
56
|
+
search(query: string, options?: SearchOptions): Promise<MemorySearchHit[]>;
|
|
57
|
+
status(): IndexStatus;
|
|
58
|
+
private ftsSearch;
|
|
59
|
+
private vectorSearchById;
|
|
60
|
+
private combineHybridScores;
|
|
61
|
+
private mergeHits;
|
|
62
|
+
private fetchChunksByIds;
|
|
63
|
+
private loadFilesIndex;
|
|
64
|
+
private upsertFile;
|
|
65
|
+
private deleteChunksForFile;
|
|
66
|
+
private insertChunk;
|
|
67
|
+
close(): void;
|
|
68
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite schema for the memory index.
|
|
3
|
+
*
|
|
4
|
+
* Tables:
|
|
5
|
+
* - files — one row per indexed markdown file (path, mtime, hash).
|
|
6
|
+
* - chunks — one row per chunk produced by `chunkMarkdown`.
|
|
7
|
+
* - chunks_fts — FTS5 virtual table mirroring chunks.text for BM25 search.
|
|
8
|
+
* - meta — key/value store; persists the active embedding identity
|
|
9
|
+
* (provider id, model, dimension) so we detect when the
|
|
10
|
+
* index was built against a different embedding setup.
|
|
11
|
+
* - embeddings — sqlite-vec virtual table holding the chunk vectors
|
|
12
|
+
* (created on demand by `vec-index.ts`).
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Non-WAL pragmas. WAL is applied separately via
|
|
18
|
+
* `applyWalWithFallback` (T4.2, ADR D63) so NFS/SMB users get a graceful
|
|
19
|
+
* DELETE fallback instead of crashing.
|
|
20
|
+
*/
|
|
21
|
+
export declare const PRAGMA_STATEMENTS: ReadonlyArray<string>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { EmbeddingRuntime } from "./embedding-adapter.js";
|
|
2
|
+
export interface LanceFactRecord {
|
|
3
|
+
id: string;
|
|
4
|
+
text: string;
|
|
5
|
+
source: "memory" | "sessions" | "wiki";
|
|
6
|
+
embedding: ReadonlyArray<number>;
|
|
7
|
+
namespace: string;
|
|
8
|
+
scope: string;
|
|
9
|
+
user_id: string;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}
|
|
12
|
+
export interface OpenLanceOptions {
|
|
13
|
+
cwd: string;
|
|
14
|
+
embedding: EmbeddingRuntime;
|
|
15
|
+
/** Override storage location. Default: `<cwd>/.theokit/memory/lance/`. */
|
|
16
|
+
storagePath?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface LanceSearchOptions {
|
|
19
|
+
namespace: string;
|
|
20
|
+
scope?: string;
|
|
21
|
+
limit?: number;
|
|
22
|
+
sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
|
|
23
|
+
}
|
|
24
|
+
export interface LanceSearchHit {
|
|
25
|
+
id: string;
|
|
26
|
+
text: string;
|
|
27
|
+
source: "memory" | "sessions" | "wiki";
|
|
28
|
+
namespace: string;
|
|
29
|
+
scope: string;
|
|
30
|
+
userId: string;
|
|
31
|
+
score: number;
|
|
32
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `LanceMemoryAdapter` — wraps `LanceIndex` to expose the common
|
|
3
|
+
* `MemoryIndex` interface (sync/search/status/close) so consumers of
|
|
4
|
+
* `IndexManager.open({ backend: "lance" })` get a drop-in replacement
|
|
5
|
+
* for the SQLite-backed `IndexManager`.
|
|
6
|
+
*
|
|
7
|
+
* Semantic deltas vs SQLite (documented so callers know what to expect):
|
|
8
|
+
*
|
|
9
|
+
* - `sync()` is a NO-OP. Lance is a pure vector store — there is no
|
|
10
|
+
* markdown corpus to crawl. Returns zero counts. Consumers writing
|
|
11
|
+
* facts use `LanceIndex.addFacts` directly (exposed via the index
|
|
12
|
+
* object returned to advanced callers).
|
|
13
|
+
* - `search()` performs vector-only retrieval. `MemorySearchHit.textScore`
|
|
14
|
+
* is undefined (no FTS5 layer); `vectorScore === score`.
|
|
15
|
+
* - `status()` reports `backend: "hybrid"` only when an embedding runtime
|
|
16
|
+
* is wired (always the case for Lance — embedding is required at open).
|
|
17
|
+
* `chunksIndexed` reflects total Lance row count; `filesIndexed` is 0
|
|
18
|
+
* because Lance does not track file provenance per-row.
|
|
19
|
+
*
|
|
20
|
+
* Ships with the lancedb-backend-ship-v1-1 plan (close D12, supersede via
|
|
21
|
+
* D43). v1.4.0 of `@theokit/sdk`.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
import type { LanceIndex } from "./lance-index.js";
|
|
26
|
+
import { type MemoryIndex, type SyncResult } from "./memory-index.js";
|
|
27
|
+
export declare class LanceMemoryAdapter implements MemoryIndex {
|
|
28
|
+
private readonly inner;
|
|
29
|
+
constructor(inner: LanceIndex);
|
|
30
|
+
/**
|
|
31
|
+
* No-op for Lance — see file header. Returns zero counts so callers'
|
|
32
|
+
* existing logging (`filesScanned: X`) does not break.
|
|
33
|
+
*/
|
|
34
|
+
sync(): Promise<SyncResult>;
|
|
35
|
+
search(query: string, options?: SearchOptions): Promise<MemorySearchHit[]>;
|
|
36
|
+
status(): IndexStatus;
|
|
37
|
+
close(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Escape hatch for advanced callers (migration tool, benchmark script)
|
|
40
|
+
* that need direct access to addFacts/countFacts/removeFacts.
|
|
41
|
+
*/
|
|
42
|
+
unwrap(): LanceIndex;
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type MemoryConfig, type MemoryFact } from "./types.js";
|
|
2
|
+
export declare function memoryDir(cwd: string): string;
|
|
3
|
+
export declare function memoryMdPath(cwd: string): string;
|
|
4
|
+
export declare function notesDir(cwd: string): string;
|
|
5
|
+
/** Read facts from `MEMORY.md`'s `## Facts` section. Returns `[]` when missing. */
|
|
6
|
+
export declare function readFactsFromMarkdown(cwd: string): Promise<MemoryFact[]>;
|
|
7
|
+
/** Append a fact to `MEMORY.md ## Facts`. Creates the section if missing. Atomic + serialized. */
|
|
8
|
+
export declare function appendFactToMarkdown(cwd: string, fact: MemoryFact): Promise<void>;
|
|
9
|
+
export interface NoteFile {
|
|
10
|
+
slug: string;
|
|
11
|
+
path: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function listNotes(cwd: string): Promise<NoteFile[]>;
|
|
14
|
+
/** Configuration-aware accessors honoring the existing MemoryConfig contract. */
|
|
15
|
+
export declare function readFacts(cwd: string, config: MemoryConfig): Promise<MemoryFact[]>;
|
|
16
|
+
export declare function appendFact(cwd: string, config: MemoryConfig, fact: MemoryFact): Promise<void>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common `MemoryIndex` interface shared between the SQLite-backed
|
|
3
|
+
* `IndexManager` (default) and the Lance-backed adapter (ADR D43, shipped
|
|
4
|
+
* v1.4.0 via lancedb-backend-ship-v1-1 plan).
|
|
5
|
+
*
|
|
6
|
+
* Consumers (`local-agent-memory.ts`, `active-memory.ts`, `tools.ts`,
|
|
7
|
+
* `runActiveMemory`) only ever call `sync()`, `search()`, `status()`,
|
|
8
|
+
* `close()` — the union of those four methods is the portable surface.
|
|
9
|
+
*
|
|
10
|
+
* Why a separate file (vs declaring inline in `index-manager.ts`)? D43
|
|
11
|
+
* promised "extrair interface abstrata `MemoryIndex` em
|
|
12
|
+
* `internal/memory/index-interface.ts`". Keeping the contract physically
|
|
13
|
+
* separated from one of its implementations preserves OCP — future
|
|
14
|
+
* backends (Qdrant, PGVector) can land without touching IndexManager.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export type { IndexStatus, MemorySearchHit, SearchOptions };
|
|
19
|
+
export interface SyncResult {
|
|
20
|
+
filesScanned: number;
|
|
21
|
+
filesUpdated: number;
|
|
22
|
+
chunksWritten: number;
|
|
23
|
+
chunksEmbedded: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Common search-options parser used by both `IndexManager.search` and
|
|
27
|
+
* `LanceMemoryAdapter.search`. Returns the normalized cap + minimum-score
|
|
28
|
+
* floor — eliminates jscpd duplication while keeping per-backend search
|
|
29
|
+
* logic distinct.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseSearchOptions(options?: SearchOptions): {
|
|
32
|
+
maxResults: number;
|
|
33
|
+
minScore: number;
|
|
34
|
+
};
|
|
35
|
+
export interface MemoryIndex {
|
|
36
|
+
/**
|
|
37
|
+
* Walk the memory corpus + reindex changed files. Lance backend has no
|
|
38
|
+
* markdown corpus to walk — its adapter returns zero counts (no-op) and
|
|
39
|
+
* relies on explicit `addFact` calls instead.
|
|
40
|
+
*/
|
|
41
|
+
sync(): Promise<SyncResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Semantic + textual search over the indexed corpus. Both backends
|
|
44
|
+
* return the same `MemorySearchHit[]` shape; Lance leaves `textScore`
|
|
45
|
+
* undefined (vector-only — no FTS5 layer).
|
|
46
|
+
*/
|
|
47
|
+
search(query: string, options?: SearchOptions): Promise<MemorySearchHit[]>;
|
|
48
|
+
/** Snapshot of the index health (backend type + counts). */
|
|
49
|
+
status(): IndexStatus;
|
|
50
|
+
/** Release native handles. Idempotent. */
|
|
51
|
+
close(): Promise<void> | void;
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface MigrateResult {
|
|
2
|
+
countSqlite: number;
|
|
3
|
+
countLance: number;
|
|
4
|
+
/** Set when validation succeeded (or dryRun); false on validation failure. */
|
|
5
|
+
validated: boolean;
|
|
6
|
+
/** Per-fact compare results (size = sample count, up to 10). */
|
|
7
|
+
sampleComparisons: ReadonlyArray<{
|
|
8
|
+
id: string;
|
|
9
|
+
match: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
/** Lance storage location (final, after migration). */
|
|
12
|
+
lancePath: string;
|
|
13
|
+
/** Was the migration committed (false for dry-run). */
|
|
14
|
+
committed: boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type MemoryConfig } from "./types.js";
|
|
2
|
+
export interface MigrationResult {
|
|
3
|
+
migrated: boolean;
|
|
4
|
+
factCount: number;
|
|
5
|
+
reason?: "already-migrated" | "no-legacy-json" | "markdown-exists" | "readonly-fs";
|
|
6
|
+
}
|
|
7
|
+
export declare function migrateLegacyJson(cwd: string, config: MemoryConfig): Promise<MigrationResult>;
|
|
8
|
+
/** Test-only — reset the in-process migration flag map. */
|
|
9
|
+
export declare function resetMigrationStateForTests(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function discoverSessionFiles(cwd: string): Promise<SessionFile[]>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MemoryIndex } from "./memory-index.js";
|
|
2
|
+
export interface MemoryTool extends MemoryToolJson {
|
|
3
|
+
execute(input: Record<string, unknown>): Promise<string>;
|
|
4
|
+
}
|
|
5
|
+
export interface MemorySearchToolOptions {
|
|
6
|
+
index: MemoryIndex;
|
|
7
|
+
/** Cap on the JSON response size (EC-10 of edge-case review). Default 16384. */
|
|
8
|
+
maxTotalChars?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function createMemorySearchTool(opts: MemorySearchToolOptions): MemoryTool;
|
|
11
|
+
export interface MemoryGetToolOptions {
|
|
12
|
+
cwd: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function createMemoryGetTool(opts: MemoryGetToolOptions): MemoryTool;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function persistActiveMemoryTranscript(cwd: string, transcript: ActiveMemoryTranscript): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface MemoryConfig {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
namespace?: string;
|
|
4
|
+
userId?: string;
|
|
5
|
+
scope?: "agent" | "user" | "team";
|
|
6
|
+
storePath?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface MemoryFact {
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
export { redactSecrets } from "../security/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the legacy JSON memory path used pre-ADR-D8 (kept for migration
|
|
14
|
+
* helpers + tests). Centralized here so `migration.ts` and the legacy-aware
|
|
15
|
+
* `runtime/memory-store.ts` don't duplicate the path logic (jscpd cleanup).
|
|
16
|
+
*/
|
|
17
|
+
export declare function legacyMemoryJsonPath(cwd: string, config: MemoryConfig): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { EmbeddingRuntime } from "./embedding-adapter.js";
|
|
2
|
+
import type { MemoryDb } from "./index-db.js";
|
|
3
|
+
export declare const META_KEY_MODEL = "embedding.model";
|
|
4
|
+
export declare const META_KEY_DIMENSION = "embedding.dimension";
|
|
5
|
+
export interface EmbeddingIdentity {
|
|
6
|
+
providerId: string;
|
|
7
|
+
model: string;
|
|
8
|
+
dimension: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function readEmbeddingIdentity(db: MemoryDb): EmbeddingIdentity | undefined;
|
|
11
|
+
export declare function writeEmbeddingIdentity(db: MemoryDb, identity: EmbeddingIdentity): void;
|
|
12
|
+
export declare function identityMatches(a: EmbeddingIdentity, b: EmbeddingIdentity): boolean;
|
|
13
|
+
export declare function dropVectorIndex(db: MemoryDb): void;
|
|
14
|
+
export declare function createVectorIndex(db: MemoryDb, dimension: number): void;
|
|
15
|
+
/** Pack a Float32Array into a Buffer suitable for sqlite-vec BLOB binding. */
|
|
16
|
+
export declare function packVector(vec: ReadonlyArray<number>): Buffer;
|
|
17
|
+
export declare function upsertEmbedding(db: MemoryDb, chunkId: number, vec: ReadonlyArray<number>): void;
|
|
18
|
+
export interface VectorHitRow {
|
|
19
|
+
chunk_id: number;
|
|
20
|
+
distance: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function vectorSearch(db: MemoryDb, query: ReadonlyArray<number>, k: number): VectorHitRow[];
|
|
23
|
+
export interface EmbedAllArgs {
|
|
24
|
+
db: MemoryDb;
|
|
25
|
+
runtime: EmbeddingRuntime;
|
|
26
|
+
}
|
|
27
|
+
/** Embed every chunk that doesn't yet have a vector. */
|
|
28
|
+
export declare function embedMissingChunks(args: EmbedAllArgs): Promise<number>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared OTel tracer loader (extracted to eliminate cross-module clones —
|
|
3
|
+
* was previously inlined in cache/, workflow/, eval/, handoff/ telemetry
|
|
4
|
+
* modules). Lazy-loads `@opentelemetry/api` via `createRequire`; users
|
|
5
|
+
* without OTel installed pay zero cost.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface SpanLike {
|
|
10
|
+
setAttribute(key: string, value: string | number | boolean): SpanLike;
|
|
11
|
+
end(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare const noopSpan: SpanLike;
|
|
14
|
+
export interface TracerLike {
|
|
15
|
+
startSpan(name: string, options?: {
|
|
16
|
+
attributes?: Record<string, string | number | boolean>;
|
|
17
|
+
}): SpanLike;
|
|
18
|
+
}
|
|
19
|
+
export declare function getTracer(name: string, version?: string): TracerLike | undefined;
|
|
20
|
+
export declare function resetTracerCacheForTests(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filesystem-backed implementation of {@link ConversationStorageAdapter}
|
|
3
|
+
* (Production-Readiness #1, ADR D304).
|
|
4
|
+
*
|
|
5
|
+
* Default adapter when `AgentOptions.conversationStorage` is not provided.
|
|
6
|
+
* Writes append-only JSONL to `<root>/.theokit/agents/<safeId>/messages.jsonl`,
|
|
7
|
+
* preserving the pre-D303 byte-identical behavior (redaction D68 + JSONL
|
|
8
|
+
* line granularity).
|
|
9
|
+
*
|
|
10
|
+
* Path safety: every conversationId flows through `sanitizeIdentifier` +
|
|
11
|
+
* `safePathJoin` before touching disk. `deleteConversation` re-applies the
|
|
12
|
+
* guard (EC-1) — without this the new `rm -rf` would escape via traversal.
|
|
13
|
+
*
|
|
14
|
+
* Listing: `listConversationIds` catches ENOENT (EC-2) so first-run deploys
|
|
15
|
+
* without any `.theokit/agents/` directory return `[]` instead of crashing.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
import type { ConversationStorageAdapter, StoredMessage } from "../../types/conversation-storage.js";
|
|
20
|
+
export interface FileSystemConversationStorageOptions {
|
|
21
|
+
/** Root directory under which `.theokit/agents/<id>/` lives. Defaults to `process.cwd()`. */
|
|
22
|
+
root?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class FileSystemConversationStorage implements ConversationStorageAdapter {
|
|
25
|
+
#private;
|
|
26
|
+
constructor(opts?: FileSystemConversationStorageOptions);
|
|
27
|
+
/** Exposed for tests + diagnostics. The path is sanitized at use sites. */
|
|
28
|
+
get root(): string;
|
|
29
|
+
getMessages(conversationId: string): Promise<readonly StoredMessage[]>;
|
|
30
|
+
appendMessage(conversationId: string, message: StoredMessage): Promise<void>;
|
|
31
|
+
deleteConversation(conversationId: string): Promise<void>;
|
|
32
|
+
listConversationIds(opts?: {
|
|
33
|
+
limit?: number;
|
|
34
|
+
}): Promise<readonly string[]>;
|
|
35
|
+
compact(conversationId: string, maxTurns: number): Promise<void>;
|
|
36
|
+
dispose(): Promise<void>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory implementation of {@link ConversationStorageAdapter} (Production-Readiness #1, ADR D304).
|
|
3
|
+
*
|
|
4
|
+
* Intended for tests + ephemeral single-process dev/CLI usage. Holds messages
|
|
5
|
+
* in a `Map<conversationId, StoredMessage[]>`. JavaScript's single-threaded
|
|
6
|
+
* runtime makes per-conversation appends naturally atomic; no external mutex
|
|
7
|
+
* needed.
|
|
8
|
+
*
|
|
9
|
+
* The adapter returns defensive copies from `getMessages` so callers cannot
|
|
10
|
+
* mutate internal state by holding a reference to the returned array.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
import type { ConversationStorageAdapter, StoredMessage } from "../../types/conversation-storage.js";
|
|
15
|
+
export declare class InMemoryConversationStorage implements ConversationStorageAdapter {
|
|
16
|
+
#private;
|
|
17
|
+
getMessages(conversationId: string): Promise<readonly StoredMessage[]>;
|
|
18
|
+
appendMessage(conversationId: string, message: StoredMessage): Promise<void>;
|
|
19
|
+
deleteConversation(conversationId: string): Promise<void>;
|
|
20
|
+
listConversationIds(opts?: {
|
|
21
|
+
limit?: number;
|
|
22
|
+
}): Promise<readonly string[]>;
|
|
23
|
+
dispose(): Promise<void>;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function withCwdMutex<T>(key: string, fn: () => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-process file lock helper (ADR D61).
|
|
3
|
+
*
|
|
4
|
+
* Uses `proper-lockfile` (optional peer dep) for cross-process locks. When
|
|
5
|
+
* the peer dep is absent, falls back to `withCwdMutex` (in-process only)
|
|
6
|
+
* with a one-shot stderr warning.
|
|
7
|
+
*
|
|
8
|
+
* EC-1 fix: uses a companion `<path>.lock` file with `realpath: false` so
|
|
9
|
+
* `withFileLock` works even when the target `path` does not exist yet.
|
|
10
|
+
* Without this, fresh installs that lock-then-create would crash with ENOENT.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FTS5 query sanitization + CJK detection (ADR D64).
|
|
3
|
+
*
|
|
4
|
+
* Port of Hermes' 6-step sanitizer (`hermes_state.py:1797-1847`). Prevents
|
|
5
|
+
* crashes on user inputs with hyphens, dots, underscores, and unmatched
|
|
6
|
+
* specials. Auto-quotes identifier-shaped tokens so `error-code` finds
|
|
7
|
+
* literal `error-code` instead of `error AND code`.
|
|
8
|
+
*
|
|
9
|
+
* CJK detection returns true for inputs containing characters in the main
|
|
10
|
+
* CJK Unicode ranges (Chinese, Japanese, Korean). CJK trigram routing is
|
|
11
|
+
* deferred to v1.4 — callers receiving `containsCjk === true` should
|
|
12
|
+
* short-circuit to an empty result or LIKE fallback for v1.3.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared loader for `.theokit/<dir>/<name>.md` (or `.theokit/<dir>/<name>/PLUGIN.md`)
|
|
3
|
+
* config files. Mirrors the SKILL.md pattern: YAML frontmatter delimited by
|
|
4
|
+
* `---` blocks + optional markdown body for prose / rationale.
|
|
5
|
+
*
|
|
6
|
+
* Consumed by hooks-loader (T1.2), context-manager (T2.2), and
|
|
7
|
+
* plugins-manager (T3.2) — DRY across all 3 user-edited config surfaces.
|
|
8
|
+
*
|
|
9
|
+
* ADRs: D74 (markdown format), D75 (1 file = 1 entity), D76 (Zod schema).
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
import type { z } from "zod";
|
|
14
|
+
export interface MarkdownEntity<T> {
|
|
15
|
+
/** Slug from filename (without `.md`) for flat pattern, or subdir name for nested. */
|
|
16
|
+
slug: string;
|
|
17
|
+
/** Validated frontmatter. */
|
|
18
|
+
frontmatter: T;
|
|
19
|
+
/** Markdown body (everything after the closing `---`). May be empty. */
|
|
20
|
+
body: string;
|
|
21
|
+
/** Absolute source path for audit / error context. */
|
|
22
|
+
source: string;
|
|
23
|
+
}
|
|
24
|
+
export interface LoadOptions<T> {
|
|
25
|
+
/** Absolute path to the directory containing `*.md` files (flat) or
|
|
26
|
+
* subdirs with `PLUGIN.md` (nested). */
|
|
27
|
+
dir: string;
|
|
28
|
+
/** Zod schema validating the frontmatter shape. */
|
|
29
|
+
schema: z.ZodType<T>;
|
|
30
|
+
/** `"flat"` = top-level `<slug>.md` files; `"nested"` = subdirs each with
|
|
31
|
+
* `PLUGIN.md`. Default: `"flat"`. */
|
|
32
|
+
pattern?: "flat" | "nested";
|
|
33
|
+
/** Error code prefix (e.g., `"hook"` → `"hook_frontmatter_invalid"`). */
|
|
34
|
+
errorCodePrefix: string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path resolution for SDK state files (ADR D60).
|
|
3
|
+
*
|
|
4
|
+
* Theokit anchors state at `<cwd>/.theokit/` by default (per-cwd). An
|
|
5
|
+
* optional `THEOKIT_HOME` environment variable overrides this, enabling
|
|
6
|
+
* test isolation, profile switching, and multi-tenant deployments.
|
|
7
|
+
*
|
|
8
|
+
* Rules:
|
|
9
|
+
* - `getTheokitHome(cwd)` is the ONLY canonical resolver. Never hardcode
|
|
10
|
+
* `path.join(cwd, ".theokit")` in callers — use this function so tests
|
|
11
|
+
* and overrides stay consistent.
|
|
12
|
+
* - `getProfilesRoot()` is intentionally home-anchored (not affected by
|
|
13
|
+
* `THEOKIT_HOME`) so `theokit profile list` discovers all profiles
|
|
14
|
+
* regardless of which is active.
|
|
15
|
+
* - `displayTheokitHome(cwd)` returns a human-readable path for logs.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Zod schema for the `{ backend: "memory" | "json", dir? }` options
|
|
3
|
+
* used by both `Workflow` snapshots and `Cache` semantic store persistence.
|
|
4
|
+
* Extracted to remove the cross-module clone flagged by jscpd.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* `persistence?` opt-in JSON disk backend with `dir` required when chosen.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PersistenceSchema: z.ZodOptional<z.ZodObject<{
|
|
12
|
+
backend: z.ZodEnum<{
|
|
13
|
+
memory: "memory";
|
|
14
|
+
json: "json";
|
|
15
|
+
}>;
|
|
16
|
+
dir: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, z.core.$strip>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema versioning helpers (ADR D62).
|
|
3
|
+
*
|
|
4
|
+
* Two parallel APIs:
|
|
5
|
+
* - `migrateSchema` — SQLite via `PRAGMA user_version` + ordered forward-only migrations.
|
|
6
|
+
* - `readVersionedJson` / `writeVersionedJson` — JSON files with `_schemaVersion` field.
|
|
7
|
+
*
|
|
8
|
+
* Forward-only: never deletes data, never downgrades. Migration callbacks
|
|
9
|
+
* own the transformation; this module owns the bookkeeping.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite WAL mode helper with NFS/SMB/FUSE fallback to DELETE (ADR D63).
|
|
3
|
+
*
|
|
4
|
+
* WAL is faster (concurrent readers + one writer) but unsupported on some
|
|
5
|
+
* network/FUSE filesystems. Try WAL; if the pragma returns something else
|
|
6
|
+
* or throws, fall back to DELETE journal mode. Warn one time per label.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personality fork-context (ADR D168 + EC-A snapshot semantic).
|
|
3
|
+
*
|
|
4
|
+
* Uses Node's `AsyncLocalStorage` so a fork's execution chain can know
|
|
5
|
+
* that it is running inside a fork AND can see the slug that was active
|
|
6
|
+
* on the parent **at fork-construction time**.
|
|
7
|
+
*
|
|
8
|
+
* **EC-A:** The slug stored here is captured ONCE at the wrap site
|
|
9
|
+
* (`localAgentFork`) — passing `parentStore.active(parentAgentId)`
|
|
10
|
+
* returns a primitive `string | undefined`, which is then frozen
|
|
11
|
+
* inside the ALS context object. Subsequent `usePersonality` calls on
|
|
12
|
+
* the parent do NOT mutate the fork's view, because the fork reads from
|
|
13
|
+
* its own ALS frame, not from the parent's store.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PersonalityRegistry — loads `.theokit/personalities/*.md` from project
|
|
3
|
+
* + user dirs (T1.1, ADRs D161 / D162).
|
|
4
|
+
*
|
|
5
|
+
* Project entries win on slug collision (matches `.theokit/` family
|
|
6
|
+
* convention). Reserved slugs (`none`, `default`, `neutral`) cannot be
|
|
7
|
+
* registered — they map to "clear active preset".
|
|
8
|
+
*
|
|
9
|
+
* **EC-C:** name regex enforced lowercase-only by the Zod schema in
|
|
10
|
+
* `types.ts`. Filenames are independent of the frontmatter `name`.
|
|
11
|
+
*
|
|
12
|
+
* **EC-M (documented):** body content is NOT sanitized against
|
|
13
|
+
* prompt-injection — users own their preset content.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PersonalityStore — session-default + persistent JSON state of the
|
|
3
|
+
* currently-active personality slug per agentId (T2.1, ADR D163).
|
|
4
|
+
*
|
|
5
|
+
* Storage layout (`$THEOKIT_HOME/personality.json`):
|
|
6
|
+
*
|
|
7
|
+
* ```json
|
|
8
|
+
* { "version": 1, "agents": { "agent-xyz": "coder" } }
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* **EC-B (MUST FIX):** `setActive(agentId, undefined, { save: true })`
|
|
12
|
+
* **DELETES** the key from the `agents` map. Never writes `null`.
|
|
13
|
+
* "Key absent === no active personality" is the single canonical
|
|
14
|
+
* representation. Hydration only reads present keys.
|
|
15
|
+
*
|
|
16
|
+
* **EC-N (DOCUMENT):** Brief memory/disk divergence on persist failure is
|
|
17
|
+
* tolerated — session state always wins; next successful call recovers.
|
|
18
|
+
* Disk write failures log a one-shot warn (via redactSecrets) and do NOT
|
|
19
|
+
* throw to the caller (mirrors credential-pool EC-A pattern).
|
|
20
|
+
*
|
|
21
|
+
* Cross-process safety: writes go through `withFileLock` (D61) and use
|
|
22
|
+
* `atomicWriteJson` (atomic rename). Reads always re-load from disk
|
|
23
|
+
* inside the lock so concurrent writers don't lose updates (EC-6).
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export {};
|