@theokit/sdk 1.6.2 → 1.8.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.
Files changed (371) hide show
  1. package/CHANGELOG.md +193 -0
  2. package/bin/init-claude.mjs +34 -0
  3. package/claude-template/AGENTS.md +139 -0
  4. package/claude-template/CLAUDE.md +51 -0
  5. package/claude-template/dot-claude/rules/theokit-conventions.md +33 -0
  6. package/claude-template/dot-claude/settings.json +16 -0
  7. package/claude-template/dot-claude/skills/theokit-agent-core/SKILL.md +209 -0
  8. package/claude-template/dot-claude/skills/theokit-budget/SKILL.md +176 -0
  9. package/claude-template/dot-claude/skills/theokit-config/SKILL.md +139 -0
  10. package/claude-template/dot-claude/skills/theokit-cron/SKILL.md +148 -0
  11. package/claude-template/dot-claude/skills/theokit-di/SKILL.md +233 -0
  12. package/claude-template/dot-claude/skills/theokit-di-agent/SKILL.md +294 -0
  13. package/claude-template/dot-claude/skills/theokit-errors/SKILL.md +172 -0
  14. package/claude-template/dot-claude/skills/theokit-eval/SKILL.md +144 -0
  15. package/claude-template/dot-claude/skills/theokit-gateways/SKILL.md +209 -0
  16. package/claude-template/dot-claude/skills/theokit-memory/SKILL.md +176 -0
  17. package/claude-template/dot-claude/skills/theokit-rag/SKILL.md +226 -0
  18. package/claude-template/dot-claude/skills/theokit-streaming/SKILL.md +156 -0
  19. package/claude-template/dot-claude/skills/theokit-subscriptions/SKILL.md +148 -0
  20. package/claude-template/dot-claude/skills/theokit-tools/SKILL.md +170 -0
  21. package/claude-template/dot-claude/skills/theokit-workflows/SKILL.md +218 -0
  22. package/dist/a2a/agent-mailbox.d.cts +27 -0
  23. package/dist/a2a/agent-mailbox.d.ts +27 -0
  24. package/dist/a2a/index.cjs +16850 -0
  25. package/dist/a2a/index.cjs.map +1 -0
  26. package/dist/a2a/index.d.cts +9 -0
  27. package/dist/a2a/index.d.ts +9 -0
  28. package/dist/a2a/index.js +16844 -0
  29. package/dist/a2a/index.js.map +1 -0
  30. package/dist/a2a/message-bus.d.cts +27 -0
  31. package/dist/a2a/message-bus.d.ts +27 -0
  32. package/dist/a2a/subagent.d.cts +25 -0
  33. package/dist/a2a/subagent.d.ts +25 -0
  34. package/dist/a2a/types.d.cts +12 -0
  35. package/dist/a2a/types.d.ts +12 -0
  36. package/dist/agent.d.ts +1 -1
  37. package/dist/client/index.cjs +73 -0
  38. package/dist/client/index.cjs.map +1 -0
  39. package/dist/client/index.d.cts +7 -0
  40. package/dist/client/index.d.ts +7 -0
  41. package/dist/client/index.js +71 -0
  42. package/dist/client/index.js.map +1 -0
  43. package/dist/client/theokit-client.d.cts +18 -0
  44. package/dist/client/theokit-client.d.ts +18 -0
  45. package/dist/client/types.d.cts +19 -0
  46. package/dist/client/types.d.ts +19 -0
  47. package/dist/{run-DkCD5DeO.d.cts → cron-BnywDYLq.d.cts} +496 -910
  48. package/dist/{run-DkCD5DeO.d.ts → cron-CtZvJD9J.d.ts} +496 -910
  49. package/dist/cron.cjs +4285 -2893
  50. package/dist/cron.cjs.map +1 -1
  51. package/dist/cron.d.cts +2 -3
  52. package/dist/cron.d.ts +2 -71
  53. package/dist/cron.js +4289 -2897
  54. package/dist/cron.js.map +1 -1
  55. package/dist/{errors-CvAeEWgE.d.ts → errors-ChqOmFH1.d.cts} +52 -6
  56. package/dist/{errors-CK8brCJ1.d.cts → errors-DV9e0rcp.d.ts} +52 -6
  57. package/dist/errors.cjs +218 -3
  58. package/dist/errors.cjs.map +1 -1
  59. package/dist/errors.d.cts +2 -3
  60. package/dist/errors.d.ts +50 -4
  61. package/dist/errors.js +217 -4
  62. package/dist/errors.js.map +1 -1
  63. package/dist/eval.cjs +4285 -2893
  64. package/dist/eval.cjs.map +1 -1
  65. package/dist/eval.d.cts +35 -0
  66. package/dist/eval.js +4289 -2897
  67. package/dist/eval.js.map +1 -1
  68. package/dist/event-bus.d.ts +23 -0
  69. package/dist/index.cjs +5132 -4200
  70. package/dist/index.cjs.map +1 -1
  71. package/dist/index.d.cts +298 -278
  72. package/dist/index.d.ts +1898 -24
  73. package/dist/index.js +6441 -5509
  74. package/dist/index.js.map +1 -1
  75. package/dist/internal/agent-loop/loop-context-init.d.ts +2 -0
  76. package/dist/internal/agent-loop/tool-dispatch.d.ts +22 -1
  77. package/dist/internal/auth/api-key-validator.d.ts +46 -0
  78. package/dist/internal/llm/anthropic-shared.d.ts +8 -1
  79. package/dist/internal/llm/retry.d.ts +22 -0
  80. package/dist/internal/llm/types.d.ts +47 -1
  81. package/dist/internal/memory/active-memory-cache.d.ts +3 -3
  82. package/dist/internal/memory/active-memory-types.d.ts +8 -0
  83. package/dist/internal/memory/active-memory.d.ts +24 -20
  84. package/dist/internal/memory/adapters/azure-openai-embedding.d.ts +2 -0
  85. package/dist/internal/memory/adapters/cohere-embedding.d.ts +2 -0
  86. package/dist/internal/memory/adapters/gemini-embedding.d.ts +2 -0
  87. package/dist/internal/memory/adapters/jina-embedding.d.ts +2 -0
  88. package/dist/internal/memory/index-manager-contract.d.ts +26 -0
  89. package/dist/internal/memory/index-manager-dispatch.d.ts +1 -1
  90. package/dist/internal/memory/index-manager.d.ts +8 -26
  91. package/dist/internal/memory/{chunk-markdown.d.ts → storage/chunk-markdown.d.ts} +1 -1
  92. package/dist/internal/memory/{markdown-store.d.ts → storage/markdown-store.d.ts} +1 -1
  93. package/dist/internal/memory/{reader.d.ts → storage/reader.d.ts} +1 -1
  94. package/dist/internal/observability/context.d.cts +23 -0
  95. package/dist/internal/observability/context.d.ts +23 -0
  96. package/dist/internal/observability/index.cjs +38 -0
  97. package/dist/internal/observability/index.cjs.map +1 -0
  98. package/dist/internal/observability/index.d.cts +8 -0
  99. package/dist/internal/observability/index.d.ts +8 -0
  100. package/dist/internal/observability/index.js +33 -0
  101. package/dist/internal/observability/index.js.map +1 -0
  102. package/dist/internal/observability/tracer-loader.d.cts +20 -0
  103. package/dist/internal/persistence/conversation-storage-fs.d.cts +37 -0
  104. package/dist/internal/persistence/conversation-storage-memory.d.cts +24 -0
  105. package/dist/internal/persistence/credential-pool-store.d.cts +32 -0
  106. package/dist/internal/persistence/credential-pool-store.d.ts +32 -0
  107. package/dist/internal/persistence/cwd-mutex.d.cts +1 -0
  108. package/dist/internal/persistence/exclusive-create.d.cts +22 -0
  109. package/dist/internal/persistence/exclusive-create.d.ts +22 -0
  110. package/dist/internal/persistence/file-lock.d.cts +14 -0
  111. package/dist/internal/persistence/fts5-sanitize.d.cts +16 -0
  112. package/dist/internal/persistence/index.cjs +359 -0
  113. package/dist/internal/persistence/index.cjs.map +1 -0
  114. package/dist/internal/persistence/index.d.cts +20 -0
  115. package/dist/internal/persistence/index.d.ts +20 -0
  116. package/dist/internal/persistence/index.js +341 -0
  117. package/dist/internal/persistence/index.js.map +1 -0
  118. package/dist/internal/persistence/markdown-config-loader.d.cts +35 -0
  119. package/dist/internal/persistence/paths.d.cts +19 -0
  120. package/dist/internal/persistence/persistence-schema.d.cts +21 -0
  121. package/dist/internal/persistence/persistence-schema.d.ts +4 -0
  122. package/dist/internal/persistence/schema-version.d.cts +13 -0
  123. package/dist/internal/persistence/sqlite-cas.d.cts +25 -0
  124. package/dist/internal/persistence/sqlite-cas.d.ts +25 -0
  125. package/dist/internal/persistence/sqlite-wal.d.cts +10 -0
  126. package/dist/internal/plugins/context.d.cts +31 -0
  127. package/dist/internal/plugins/index.cjs +228 -0
  128. package/dist/internal/plugins/index.cjs.map +1 -0
  129. package/dist/internal/plugins/index.d.cts +8 -0
  130. package/dist/internal/plugins/index.d.ts +8 -0
  131. package/dist/internal/plugins/index.js +222 -0
  132. package/dist/internal/plugins/index.js.map +1 -0
  133. package/dist/internal/plugins/lifecycle.d.cts +14 -0
  134. package/dist/internal/plugins/lifecycle.d.ts +14 -0
  135. package/dist/internal/plugins/manager.d.cts +37 -0
  136. package/dist/internal/plugins/types.d.cts +102 -0
  137. package/dist/internal/providers/catalog-loader.d.ts +39 -0
  138. package/dist/internal/runtime/agent-session-store.d.ts +1 -1
  139. package/dist/internal/runtime/agent-session.d.ts +1 -0
  140. package/dist/internal/runtime/budget-tracker.d.ts +73 -0
  141. package/dist/internal/runtime/{context-manager.d.ts → context/context-manager.d.ts} +1 -1
  142. package/dist/internal/runtime/{fixture-events.d.ts → fixtures/fixture-events.d.ts} +1 -1
  143. package/dist/internal/runtime/{fixture-run-base.d.ts → fixtures/fixture-run-base.d.ts} +4 -4
  144. package/dist/internal/runtime/{fixture-scripts.d.ts → fixtures/fixture-scripts.d.ts} +1 -1
  145. package/dist/internal/runtime/local-agent-bootstrap.d.ts +2 -2
  146. package/dist/internal/runtime/local-agent-memory-provider.d.ts +57 -0
  147. package/dist/internal/runtime/memory-path-selector.d.ts +73 -0
  148. package/dist/internal/runtime/memory-provider.d.ts +165 -0
  149. package/dist/internal/runtime/{agent-registry.d.ts → registry/agent-registry-contract.d.ts} +15 -9
  150. package/dist/internal/runtime/registry/agent-registry.d.ts +7 -0
  151. package/dist/internal/runtime/{live-agent-registry.d.ts → registry/live-agent-registry.d.ts} +1 -1
  152. package/dist/internal/runtime/{run-registry.d.ts → registry/run-registry.d.ts} +1 -1
  153. package/dist/internal/runtime/session-types.d.ts +35 -0
  154. package/dist/internal/runtime/system-prompt/sources/skills-provider.d.ts +1 -0
  155. package/dist/internal/runtime/validate-response.d.ts +18 -0
  156. package/dist/internal/security/index.cjs +361 -0
  157. package/dist/internal/security/index.cjs.map +1 -0
  158. package/dist/internal/security/index.d.cts +11 -0
  159. package/dist/internal/security/index.js +350 -0
  160. package/dist/internal/security/index.js.map +1 -0
  161. package/dist/internal/security/path-guard.d.cts +59 -0
  162. package/dist/internal/security/path-guard.d.ts +3 -0
  163. package/dist/internal/security/redact.d.cts +21 -0
  164. package/dist/internal/security/secret-redactor.d.cts +1 -0
  165. package/dist/internal/security/secret-redactor.d.ts +1 -0
  166. package/dist/internal/security/test-reset.d.cts +10 -0
  167. package/dist/internal/security/test-reset.d.ts +10 -0
  168. package/dist/internal/telemetry/adapters/arize.d.ts +2 -0
  169. package/dist/internal/telemetry/adapters/braintrust.d.ts +2 -0
  170. package/dist/internal/telemetry/adapters/datadog.d.ts +2 -0
  171. package/dist/internal/telemetry/adapters/langsmith.d.ts +2 -0
  172. package/dist/internal/telemetry/span-names.d.ts +6 -0
  173. package/dist/internal/telemetry/tracer.d.ts +1 -0
  174. package/dist/internal/workflow/evented-executor.d.ts +42 -0
  175. package/dist/internal/workflow/scheduler.d.ts +23 -0
  176. package/dist/internal/zod/to-json-schema.d.ts +5 -15
  177. package/dist/job-queue.d.ts +28 -0
  178. package/dist/path-safety.cjs +67 -6
  179. package/dist/path-safety.cjs.map +1 -1
  180. package/dist/path-safety.d.cts +15 -0
  181. package/dist/path-safety.d.ts +1 -1
  182. package/dist/path-safety.js +67 -7
  183. package/dist/path-safety.js.map +1 -1
  184. package/dist/permission-engine.d.ts +21 -0
  185. package/dist/provider-catalog.json +702 -0
  186. package/dist/rag/index.cjs +136 -0
  187. package/dist/rag/index.cjs.map +1 -0
  188. package/dist/rag/index.d.cts +11 -0
  189. package/dist/rag/index.d.ts +11 -0
  190. package/dist/rag/index.js +129 -0
  191. package/dist/rag/index.js.map +1 -0
  192. package/dist/rag/reranker.d.cts +26 -0
  193. package/dist/rag/reranker.d.ts +26 -0
  194. package/dist/rag/retriever.d.cts +25 -0
  195. package/dist/rag/retriever.d.ts +25 -0
  196. package/dist/rag/text-splitter.d.cts +12 -0
  197. package/dist/rag/text-splitter.d.ts +12 -0
  198. package/dist/rag/types.d.cts +37 -0
  199. package/dist/rag/types.d.ts +37 -0
  200. package/dist/run-DrwUpFxZ.d.cts +823 -0
  201. package/dist/run-DrwUpFxZ.d.ts +823 -0
  202. package/dist/sandbox/index.cjs +133 -0
  203. package/dist/sandbox/index.cjs.map +1 -0
  204. package/dist/sandbox/index.d.cts +2 -0
  205. package/dist/sandbox/index.d.ts +2 -0
  206. package/dist/sandbox/index.js +128 -0
  207. package/dist/sandbox/index.js.map +1 -0
  208. package/dist/sandbox/local-sandbox.d.cts +17 -0
  209. package/dist/sandbox/local-sandbox.d.ts +17 -0
  210. package/dist/sandbox/types.d.cts +44 -0
  211. package/dist/sandbox/types.d.ts +44 -0
  212. package/dist/server/adapter/express.d.cts +9 -0
  213. package/dist/server/adapter/express.d.ts +9 -0
  214. package/dist/server/adapter/fastify.d.cts +9 -0
  215. package/dist/server/adapter/fastify.d.ts +9 -0
  216. package/dist/server/adapter/hono.d.cts +9 -0
  217. package/dist/server/adapter/hono.d.ts +9 -0
  218. package/dist/server/adapter/index.d.cts +8 -0
  219. package/dist/server/adapter/index.d.ts +8 -0
  220. package/dist/server/adapter/shared-handler.d.cts +9 -0
  221. package/dist/server/adapter/shared-handler.d.ts +9 -0
  222. package/dist/server/adapter/types.d.cts +33 -0
  223. package/dist/server/adapter/types.d.ts +33 -0
  224. package/dist/server/auth/errors.d.cts +53 -0
  225. package/dist/server/auth/errors.d.ts +53 -0
  226. package/dist/server/auth/index.cjs +38 -41
  227. package/dist/server/auth/index.cjs.map +1 -1
  228. package/dist/server/auth/index.d.cts +11 -172
  229. package/dist/server/auth/index.d.ts +11 -172
  230. package/dist/server/auth/index.js +39 -42
  231. package/dist/server/auth/index.js.map +1 -1
  232. package/dist/server/auth/oauth-transaction-store.d.cts +39 -0
  233. package/dist/server/auth/oauth-transaction-store.d.ts +39 -0
  234. package/dist/server/auth/orchestrator.d.cts +8 -0
  235. package/dist/server/auth/orchestrator.d.ts +8 -0
  236. package/dist/server/auth/types.d.cts +91 -0
  237. package/dist/server/auth/types.d.ts +91 -0
  238. package/dist/server/auth/validate-return-to.d.cts +17 -0
  239. package/dist/server/auth/validate-return-to.d.ts +17 -0
  240. package/dist/server/errors-envelope.cjs +409 -0
  241. package/dist/server/errors-envelope.cjs.map +1 -0
  242. package/dist/server/errors-envelope.d.cts +61 -0
  243. package/dist/server/errors-envelope.d.ts +61 -0
  244. package/dist/server/errors-envelope.js +405 -0
  245. package/dist/server/errors-envelope.js.map +1 -0
  246. package/dist/subscription/define-subscription.d.cts +63 -0
  247. package/dist/subscription/define-subscription.d.ts +63 -0
  248. package/dist/subscription/index.cjs +402 -0
  249. package/dist/subscription/index.cjs.map +1 -0
  250. package/dist/subscription/index.d.cts +18 -0
  251. package/dist/subscription/index.d.ts +18 -0
  252. package/dist/subscription/index.js +394 -0
  253. package/dist/subscription/index.js.map +1 -0
  254. package/dist/subscription/internal/adapter-types.d.cts +11 -0
  255. package/dist/subscription/internal/adapter-types.d.ts +11 -0
  256. package/dist/subscription/internal/backpressure.d.cts +24 -0
  257. package/dist/subscription/internal/backpressure.d.ts +24 -0
  258. package/dist/subscription/internal/server-integration.d.cts +17 -0
  259. package/dist/subscription/internal/server-integration.d.ts +17 -0
  260. package/dist/subscription/internal/sse-encoder.d.cts +13 -0
  261. package/dist/subscription/internal/sse-encoder.d.ts +13 -0
  262. package/dist/subscription/internal/sse-parser.d.cts +15 -0
  263. package/dist/subscription/internal/sse-parser.d.ts +15 -0
  264. package/dist/subscription/internal/subscription-runtime.d.cts +9 -0
  265. package/dist/subscription/internal/subscription-runtime.d.ts +9 -0
  266. package/dist/subscription/internal/ws-adapter-node.d.cts +10 -0
  267. package/dist/subscription/internal/ws-adapter-node.d.ts +10 -0
  268. package/dist/subscription/theokit-subscribe.d.cts +41 -0
  269. package/dist/subscription/theokit-subscribe.d.ts +41 -0
  270. package/dist/subscription/types.d.cts +140 -0
  271. package/dist/subscription/types.d.ts +140 -0
  272. package/dist/task-store.cjs +30 -2
  273. package/dist/task-store.cjs.map +1 -1
  274. package/dist/task-store.d.cts +8 -0
  275. package/dist/task-store.js +31 -3
  276. package/dist/task-store.js.map +1 -1
  277. package/dist/types/agent-prims.d.ts +61 -0
  278. package/dist/types/agent.d.ts +48 -53
  279. package/dist/types/conversation.d.ts +20 -8
  280. package/dist/types/index.d.ts +0 -2
  281. package/dist/types/messages-base.d.ts +20 -0
  282. package/dist/types/messages.d.ts +1 -1
  283. package/dist/types/run.d.ts +1 -1
  284. package/dist/types/updates.d.ts +1 -1
  285. package/dist/voice/index.d.ts +7 -0
  286. package/dist/voice/openai-realtime.d.ts +21 -0
  287. package/dist/voice/types.d.ts +35 -0
  288. package/dist/workflow.cjs +179 -88
  289. package/dist/workflow.cjs.map +1 -1
  290. package/dist/workflow.d.cts +97 -0
  291. package/dist/workflow.js +180 -89
  292. package/dist/workflow.js.map +1 -1
  293. package/package.json +128 -25
  294. package/dist/budget.d.ts +0 -48
  295. package/dist/cache.d.ts +0 -74
  296. package/dist/cron-1yxL3K2S.d.cts +0 -221
  297. package/dist/cron-BYVdYzob.d.ts +0 -221
  298. package/dist/handoff.d.ts +0 -55
  299. package/dist/internal/budget/calendar-window.d.ts +0 -19
  300. package/dist/internal/budget/enforcement.d.ts +0 -32
  301. package/dist/internal/budget/ledger.d.ts +0 -25
  302. package/dist/internal/budget/normalize-usage.d.ts +0 -27
  303. package/dist/internal/budget/registry.d.ts +0 -16
  304. package/dist/internal/cache/cosine.d.ts +0 -14
  305. package/dist/internal/cache/embed-helper.d.ts +0 -15
  306. package/dist/internal/cache/key.d.ts +0 -15
  307. package/dist/internal/cache/lookup.d.ts +0 -28
  308. package/dist/internal/cache/store-handler.d.ts +0 -24
  309. package/dist/internal/cache/store-json.d.ts +0 -48
  310. package/dist/internal/cache/store.d.ts +0 -54
  311. package/dist/internal/cache/telemetry.d.ts +0 -20
  312. package/dist/internal/cache/ttl.d.ts +0 -11
  313. package/dist/internal/catalog/fixtures.d.ts +0 -16
  314. package/dist/internal/catalog/local-models.d.ts +0 -24
  315. package/dist/internal/handoff/dispatcher.d.ts +0 -29
  316. package/dist/internal/handoff/registry.d.ts +0 -23
  317. package/dist/internal/handoff/telemetry.d.ts +0 -18
  318. package/dist/internal/handoff/tool-injector.d.ts +0 -34
  319. package/dist/internal/memory/atomic-write.d.ts +0 -7
  320. package/dist/internal/memory/dreaming/diary.d.ts +0 -4
  321. package/dist/internal/memory/dreaming/phases.d.ts +0 -15
  322. package/dist/internal/memory/dreaming/run.d.ts +0 -10
  323. package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +0 -15
  324. package/dist/memory-adapter-helpers.d.ts +0 -28
  325. package/dist/memory.d.ts +0 -123
  326. package/dist/migrate.d.ts +0 -33
  327. package/dist/security.d.ts +0 -67
  328. package/dist/task.d.ts +0 -87
  329. package/dist/theokit.d.ts +0 -84
  330. package/dist/tools/_path-scope.d.ts +0 -8
  331. package/dist/tools/_subprocess.d.ts +0 -28
  332. package/dist/tools/git-diff.d.ts +0 -22
  333. package/dist/tools/index.d.ts +0 -29
  334. package/dist/tools/list-dir.d.ts +0 -26
  335. package/dist/tools/read-file.d.ts +0 -31
  336. package/dist/tools/run-vitest.d.ts +0 -46
  337. package/dist/tools/search-text.d.ts +0 -32
  338. package/dist/tools.cjs +0 -690
  339. package/dist/tools.cjs.map +0 -1
  340. package/dist/tools.js +0 -683
  341. package/dist/tools.js.map +0 -1
  342. package/dist/trajectory-helpers.d.ts +0 -31
  343. package/dist/types/cache.d.ts +0 -76
  344. package/dist/types/handoff.d.ts +0 -135
  345. /package/dist/{internal/cron/run-job.d.ts → agent-helpers.d.ts} +0 -0
  346. /package/dist/internal/{cron/scheduler.d.ts → agent-loop/loop-llm-stream.d.ts} +0 -0
  347. /package/dist/internal/{cron/store.d.ts → agent-loop/tool-executors.d.ts} +0 -0
  348. /package/dist/internal/{cron/validate.d.ts → memory/index-manager-helpers.d.ts} +0 -0
  349. /package/dist/internal/memory/{session-loader.d.ts → storage/session-loader.d.ts} +0 -0
  350. /package/dist/internal/memory/{session-summary-writer.d.ts → storage/session-summary-writer.d.ts} +0 -0
  351. /package/dist/internal/memory/{transcript-store.d.ts → storage/transcript-store.d.ts} +0 -0
  352. /package/dist/internal/memory/{wiki-loader.d.ts → storage/wiki-loader.d.ts} +0 -0
  353. /package/dist/internal/{memory/cwd-mutex.d.ts → persistence/atomic-write.d.cts} +0 -0
  354. /package/dist/internal/runtime/{context-aggregator.d.ts → context/context-aggregator.d.ts} +0 -0
  355. /package/dist/internal/runtime/{context-discovery-runner.d.ts → context/context-discovery-runner.d.ts} +0 -0
  356. /package/dist/internal/runtime/{context-discovery.d.ts → context/context-discovery.d.ts} +0 -0
  357. /package/dist/internal/runtime/{context-frontmatter.d.ts → context/context-frontmatter.d.ts} +0 -0
  358. /package/dist/internal/runtime/{context-import-resolver.d.ts → context/context-import-resolver.d.ts} +0 -0
  359. /package/dist/internal/runtime/{context-loaders.d.ts → context/context-loaders.d.ts} +0 -0
  360. /package/dist/internal/runtime/{context-mdc-parser.d.ts → context/context-mdc-parser.d.ts} +0 -0
  361. /package/dist/internal/runtime/{fixture-responder.d.ts → fixtures/fixture-responder.d.ts} +0 -0
  362. /package/dist/internal/runtime/{fixture-types.d.ts → fixtures/fixture-types.d.ts} +0 -0
  363. /package/dist/internal/runtime/{plugins-manager.d.ts → local-agent-send.d.ts} +0 -0
  364. /package/dist/internal/runtime/{plugin-frontmatter.d.ts → plugins/plugin-frontmatter.d.ts} +0 -0
  365. /package/dist/internal/runtime/{system-prompt/providers/active-memory-provider.d.ts → plugins/plugins-manager.d.ts} +0 -0
  366. /package/dist/internal/runtime/{agent-factory-registry.d.ts → registry/agent-factory-registry.d.ts} +0 -0
  367. /package/dist/internal/runtime/{agent-registry-store.d.ts → registry/agent-registry-store.d.ts} +0 -0
  368. /package/dist/internal/runtime/system-prompt/{providers/base-provider.d.ts → sources/active-memory-provider.d.ts} +0 -0
  369. /package/dist/internal/runtime/system-prompt/{providers/context-provider.d.ts → sources/base-provider.d.ts} +0 -0
  370. /package/dist/internal/runtime/system-prompt/{providers/memory-provider.d.ts → sources/context-provider.d.ts} +0 -0
  371. /package/dist/internal/runtime/system-prompt/{providers/skills-provider.d.ts → sources/memory-provider.d.ts} +0 -0
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Plugin contract types (T1.1, ADRs D97-D101).
3
+ *
4
+ * Discriminated union by `kind`:
5
+ * - `"general"` — registers tools/hooks/commands via `register(ctx)`.
6
+ * - `"model-provider"` — declares a `ProviderProfile` consumed by router.
7
+ * - `"memory"` — supplies a memory provider factory.
8
+ *
9
+ * Hooks are a fixed enum (D100) to prevent sprawl; `pre_tool_call` supports
10
+ * veto via `{ block: true, message }` (D101) so plugins can implement safety
11
+ * guards without crashing the agent loop.
12
+ *
13
+ * @public
14
+ */
15
+ import type { CustomTool } from "../../types/agent.js";
16
+ import type { ProviderProfile } from "../providers/types.js";
17
+ export type HookName = "pre_tool_call" | "post_tool_call" | "pre_llm_call" | "post_llm_call" | "on_session_start" | "on_session_end" | "transform_tool_result" | "transform_llm_output" | "pre_user_send" | "post_assistant_reply";
18
+ export interface PreToolCallContext {
19
+ name: string;
20
+ args: Record<string, unknown>;
21
+ agentId: string;
22
+ runId: string;
23
+ }
24
+ export interface PreToolCallDecision {
25
+ block: true;
26
+ message: string;
27
+ }
28
+ /**
29
+ * Context passed to `pre_user_send` hook handlers (ADR D145).
30
+ *
31
+ * @public
32
+ */
33
+ export interface PreUserSendContext {
34
+ prompt: string;
35
+ agentId: string;
36
+ runId: string;
37
+ /** Caller-supplied memory context, flowing through from `AgentOptions.memoryContext`. */
38
+ memoryContext?: import("../../types/memory-adapter.js").MemoryContext;
39
+ /** Forwarded `AbortSignal` so adapter recall HTTP can be cancelled mid-flight (EC-H). */
40
+ signal?: AbortSignal;
41
+ }
42
+ /**
43
+ * Optional result returned by `pre_user_send` handlers. The agent loop
44
+ * concatenates `recalledContext` from all handlers and injects it as a
45
+ * `<memory-context>...</memory-context>` block before the user prompt.
46
+ *
47
+ * @public
48
+ */
49
+ export interface PreUserSendResult {
50
+ recalledContext?: string;
51
+ }
52
+ /**
53
+ * Context passed to `post_assistant_reply` hook handlers (ADR D145).
54
+ * Fire-and-forget — exceptions are caught and surfaced to stderr; the
55
+ * caller's `wait()` never blocks on this dispatch.
56
+ *
57
+ * @public
58
+ */
59
+ export interface PostAssistantReplyContext {
60
+ prompt: string;
61
+ reply: string;
62
+ agentId: string;
63
+ runId: string;
64
+ memoryContext?: import("../../types/memory-adapter.js").MemoryContext;
65
+ }
66
+ export type HookHandler = (ctx: unknown) => unknown | Promise<unknown>;
67
+ export type CommandHandler = (args: Record<string, unknown>) => Promise<string> | string;
68
+ export interface CommandOptions {
69
+ description?: string;
70
+ }
71
+ export interface PluginContext {
72
+ /** Register a custom tool. Equivalent to passing in `AgentOptions.tools`. */
73
+ registerTool(tool: CustomTool): void;
74
+ /** Register a slash-command-style handler. Consumed by CLI/bot wrappers; NOT used by the agent loop. */
75
+ registerCommand(name: string, handler: CommandHandler, opts?: CommandOptions): void;
76
+ /** Attach a hook handler. `pre_tool_call` supports veto via `PreToolCallDecision`. */
77
+ on(hook: HookName, handler: HookHandler): void;
78
+ /** Inject a user/system message into the next agent turn. v1 supports only `on_session_start` context. */
79
+ injectMessage(content: string, role?: "user" | "system"): void;
80
+ }
81
+ interface BasePlugin {
82
+ name: string;
83
+ version: string;
84
+ }
85
+ export type Plugin = (BasePlugin & {
86
+ kind: "general";
87
+ register: (ctx: PluginContext) => void | Promise<void>;
88
+ }) | (BasePlugin & {
89
+ kind: "model-provider";
90
+ profile: ProviderProfile;
91
+ }) | (BasePlugin & {
92
+ kind: "memory";
93
+ createProvider: MemoryProviderFactory;
94
+ });
95
+ /**
96
+ * Identity helper for plugin authors. TS-only convenience — preserves
97
+ * inferred type without forcing manual `Plugin` annotation.
98
+ *
99
+ * @public
100
+ */
101
+ export declare function definePlugin<P extends Plugin>(p: P): P;
102
+ export {};
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Dynamic provider catalog loader (T10.1, ADR D447).
3
+ *
4
+ * Loads provider metadata from `provider-catalog.json` at runtime.
5
+ * Malformed entries are skipped with WARN (EC-1) — never crash.
6
+ *
7
+ * @internal
8
+ */
9
+ import type { ApiMode, AuthType } from "./types.js";
10
+ export interface ProviderCapabilities {
11
+ supportsToolUse: boolean;
12
+ supportsVision: boolean;
13
+ supportsStructuredOutput: boolean;
14
+ supportsStreaming: boolean;
15
+ supportsCacheControl: boolean;
16
+ maxContextTokens?: number;
17
+ maxOutputTokens?: number;
18
+ }
19
+ export interface CatalogEntry {
20
+ id: string;
21
+ displayName: string;
22
+ apiMode: ApiMode;
23
+ authType: AuthType;
24
+ baseUrl: string;
25
+ envVars: string[];
26
+ fallbackModels: string[];
27
+ capabilities: ProviderCapabilities;
28
+ aliases?: string[];
29
+ modelsUrl?: string;
30
+ hostname?: string;
31
+ extraHeaders?: Record<string, string>;
32
+ }
33
+ interface LoadOptions {
34
+ _testInjectMalformed?: boolean;
35
+ }
36
+ export declare function loadProviderCatalog(opts?: LoadOptions): Record<string, CatalogEntry>;
37
+ export declare function getCatalogCapabilities(providerId: string): ProviderCapabilities | undefined;
38
+ export declare function registerCatalogProviders(opts?: LoadOptions): void;
39
+ export {};
@@ -1,3 +1,3 @@
1
- import type { SessionMessage } from "./agent-session.js";
1
+ import type { SessionMessage } from "./session-types.js";
2
2
  export declare function sessionFilePath(cwd: string, agentId: string): string;
3
3
  export declare function readSessionFile(cwd: string, agentId: string): Promise<SessionMessage[]>;
@@ -1,2 +1,3 @@
1
+ import type { SessionMessage } from "./session-types.js";
1
2
  export declare function getSessionMessages(agentId: string): SessionMessage[];
2
3
  export declare function clearSession(agentId: string): void;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * `BudgetTracker` — runtime contract for budget/usage tracking in the
3
+ * agent loop (SDK 2.0 Phase 2 / T2.1 — ADR D1 interface inversion).
4
+ *
5
+ * This interface is the FOUNDATION for the eventual extraction of the
6
+ * Budget subsystem to `@theokit/sdk-budget`. The kernel depends on this
7
+ * contract (not on `UsageAccumulator` / `IterationBudget` concrete classes)
8
+ * so the implementation can move to a separate package without circular
9
+ * imports.
10
+ *
11
+ * Until Phase 2 completes, the legacy `UsageAccumulator` + `IterationBudget`
12
+ * remain wired in `internal/agent-loop/loop.ts` as the default impl. Future
13
+ * iterations:
14
+ * - Refactor `Agent.create` to accept `budgetTracker?: BudgetTracker`.
15
+ * - When provided, agent-loop uses it; when absent, falls back to the
16
+ * internal default for back-compat.
17
+ * - Move the default impl to `@theokit/sdk-budget` (extracted package).
18
+ * - Phase 6 cohort: drop the internal default, require explicit tracker.
19
+ *
20
+ * @public — surface-level interface; impl is internal-but-replaceable.
21
+ */
22
+ /** Single usage event recorded during one LLM call. */
23
+ export interface BudgetUsageEvent {
24
+ /** Token count for this event. */
25
+ readonly tokens: number;
26
+ /** Provider/model identifier (e.g., `"openai/gpt-4o-mini"`). */
27
+ readonly model: string;
28
+ /** Whether this is an input (prompt) or output (completion) measurement. */
29
+ readonly type: "input" | "output";
30
+ /** Optional ISO 8601 timestamp; defaults to now() if omitted. */
31
+ readonly at?: string;
32
+ }
33
+ /** Decision the tracker returns on each iteration / pre-flight check. */
34
+ export interface BudgetCheck {
35
+ /** Whether the agent loop is allowed to proceed. */
36
+ readonly allowed: boolean;
37
+ /**
38
+ * When `allowed` is false, names the reason in a stable, codemod-friendly
39
+ * form. Consumers map this to retry / surface to user / abort behavior.
40
+ */
41
+ readonly reason?: "budget_exceeded" | "iteration_limit" | "cost_limit" | "token_limit" | "custom";
42
+ /** Free-form details for logs / diagnostics. */
43
+ readonly detail?: string;
44
+ }
45
+ /** Aggregate snapshot of usage so far. */
46
+ export interface BudgetTotal {
47
+ /** Sum of all input + output tokens. */
48
+ readonly tokens: number;
49
+ /** USD cost when pricing data is available; `undefined` otherwise. */
50
+ readonly costUsd?: number;
51
+ /** Iteration count if the impl tracks it. */
52
+ readonly iterations?: number;
53
+ }
54
+ /**
55
+ * The kernel-facing contract. Implementations live OUTSIDE the agent loop
56
+ * (in `@theokit/sdk-budget` after Phase 2 / in `internal/budget/` until then).
57
+ *
58
+ * Implementations MUST be:
59
+ * - **Synchronous** — every method returns a value, never a Promise.
60
+ * `track()` is on the hot path (called on every iteration); async would
61
+ * bloat the loop with floating promises and force every call site to
62
+ * await.
63
+ * - **Non-throwing in track()** — record-only semantics. Validation
64
+ * failures bubble up via `check()` instead.
65
+ */
66
+ export interface BudgetTracker {
67
+ /** Record a single usage event. MUST be synchronous and non-throwing. */
68
+ track(event: BudgetUsageEvent): void;
69
+ /** Pre-flight check before the next iteration. */
70
+ check(): BudgetCheck;
71
+ /** Snapshot of accumulated totals (for telemetry / final reporting). */
72
+ getTotal(): BudgetTotal;
73
+ }
@@ -1,4 +1,4 @@
1
- import type { ContextSettings, ContextSnapshot, SDKContextManager } from "../../types/context.js";
1
+ import type { ContextSettings, ContextSnapshot, SDKContextManager } from "../../../types/context.js";
2
2
  export declare class FileContextManager implements SDKContextManager {
3
3
  private readonly cwd;
4
4
  private readonly settings;
@@ -1,4 +1,4 @@
1
- import type { SDKAssistantMessage, SDKRequestMessage, SDKStatusMessage, SDKSystemMessage, SDKTaskMessage, SDKThinkingMessage, SDKToolUseMessage, SDKUserMessageEvent } from "../../types/messages.js";
1
+ import type { SDKAssistantMessage, SDKRequestMessage, SDKStatusMessage, SDKSystemMessage, SDKTaskMessage, SDKThinkingMessage, SDKToolUseMessage, SDKUserMessageEvent } from "../../../types/messages.js";
2
2
  import type { FixtureRequest } from "./fixture-types.js";
3
3
  export declare function systemEvent(request: FixtureRequest, tools: string[]): SDKSystemMessage;
4
4
  export declare function userEvent(request: FixtureRequest): SDKUserMessageEvent;
@@ -1,7 +1,7 @@
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";
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
5
  import type { FixtureScript } from "./fixture-types.js";
6
6
  export declare abstract class FixtureRunBase implements Run {
7
7
  readonly id: string;
@@ -1,5 +1,5 @@
1
1
  import type { FixtureRequest, FixtureScript } from "./fixture-types.js";
2
- export { extractMemoryFact, isMemoryWritePrompt } from "./memory-store.js";
2
+ export { extractMemoryFact, isMemoryWritePrompt } from "../memory-store.js";
3
3
  export declare function isMemoryRecallPrompt(message: string, request: FixtureRequest): boolean;
4
4
  export declare function memoryWriteScript(request: FixtureRequest): FixtureScript;
5
5
  export declare function memoryRecallScript(request: FixtureRequest): FixtureScript;
@@ -7,8 +7,8 @@
7
7
  *
8
8
  * @internal
9
9
  */
10
- import { FileContextManager } from "./context-manager.js";
11
- import { type PluginMetadata, PluginsManager } from "./plugins-manager.js";
10
+ import { FileContextManager } from "./context/context-manager.js";
11
+ import { type PluginMetadata, PluginsManager } from "./plugins/plugins-manager.js";
12
12
  import { ProvidersManagerImpl } from "./providers-manager.js";
13
13
  import { type SkillMetadata, SkillsManager } from "./skills-manager.js";
14
14
  export declare function registerLocalAgent(args: {
@@ -0,0 +1,57 @@
1
+ /**
2
+ * `createLocalAgentMemoryProvider` — bridges the legacy LocalAgentMemory
3
+ * rich impl (sdk-core's internal/memory/* subsystem) to the
4
+ * MemoryProvider port (SDK 2.0 Phase 1 physical Stage 2a — iter 19+).
5
+ *
6
+ * Goal: ONE memory path inside the kernel. Today there are TWO:
7
+ * 1. Legacy via `LocalAgentMemory` (when consumer didn't pass memoryProvider)
8
+ * 2. Port via `MemoryProvider` (when consumer passed memoryProvider in T1.3)
9
+ *
10
+ * This adapter wraps path 1 as a MemoryProvider, so the kernel can use
11
+ * the port uniformly. Stage 2b will refactor LocalAgent.send() to use
12
+ * the port + this adapter as default. Stage 3 will move the internal/
13
+ * memory/* sources to sdk-memory + ship a richer LanceDB-backed
14
+ * provider replacing this adapter.
15
+ *
16
+ * Why a separate file (not modifying LocalAgentMemory):
17
+ * - Preserves LocalAgentMemory's existing public API for callers that
18
+ * haven't migrated to the port yet.
19
+ * - Adapter pattern: the rich logic stays where it is; the adapter
20
+ * translates between LocalAgentMemory's signature and the port's.
21
+ * - Allows incremental migration: kernel call sites move one at a
22
+ * time from `memoryGlue.X()` direct calls to `provider.X(handle)`
23
+ * calls.
24
+ *
25
+ * @internal — sdk-core's bridging glue. Replaced by sdk-memory rich impl
26
+ * in Stage 3.
27
+ */
28
+ import type { TelemetryHandle } from "../telemetry/tracer.js";
29
+ import type { MemoryProvider } from "./memory-provider.js";
30
+ /**
31
+ * Options for `createLocalAgentMemoryProvider`. Mirrors what
32
+ * `LocalAgentMemory`'s constructor needs.
33
+ */
34
+ export interface LocalAgentMemoryProviderOptions {
35
+ /** AgentOptions slice — required for memory subsystem config (cfg.memory). */
36
+ readonly agentOptions: AgentOptions;
37
+ /** Workspace cwd — used for `.theokit/memory/` paths. */
38
+ readonly workspaceCwd: string;
39
+ /** Agent id — required for per-agent cache + telemetry. */
40
+ readonly agentId: string;
41
+ /** Telemetry handle (optional) — forwarded to active-memory recall. */
42
+ readonly telemetry?: TelemetryHandle;
43
+ }
44
+ /**
45
+ * Build a `MemoryProvider` whose lifecycle methods delegate to an
46
+ * underlying `LocalAgentMemory` instance.
47
+ *
48
+ * Mapping:
49
+ * - `init()` → constructs LocalAgentMemory + warms tool cache via ensureTools()
50
+ * - `buildTools()` → wraps ensureTools() result, renaming `execute` to `handler`
51
+ * - `runActivePass()` → calls runActiveMemoryIfEnabled() with synthesized args;
52
+ * returns the summary as `systemPromptAdditions`
53
+ * - `sync()` → calls syncIfReady()
54
+ * - `dispose()` → no-op (LocalAgentMemory's caches are per-agent + GC'd
55
+ * when the agent is GC'd)
56
+ */
57
+ export declare function createLocalAgentMemoryProvider(opts: LocalAgentMemoryProviderOptions): MemoryProvider;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Memory path selector (SDK 2.0 Phase 1 physical Stage 2b — iter 22).
3
+ *
4
+ * Pure helpers the future kernel flip will use to choose between
5
+ * legacy direct-call path and new MemoryProvider port path. Shipped
6
+ * in isolation so the helpers are tested + frozen BEFORE the actual
7
+ * `LocalAgent.send()` refactor wires them.
8
+ *
9
+ * Gate semantics (option A from the progress doc):
10
+ * - Default: legacy path (zero behavior change).
11
+ * - `THEOKIT_PORT_MEMORY_PATH=1` (env var): port path active.
12
+ *
13
+ * Why env var (vs option flag):
14
+ * - Easy to flip on/off at runtime without rebuild.
15
+ * - No public API surface added (the env var is internal-only;
16
+ * consumers don't see it in their TypeScript types).
17
+ * - Future iter can remove the env var once port path is the
18
+ * unconditional default — no deprecation cycle on the public API.
19
+ *
20
+ * @internal
21
+ */
22
+ import type { MemoryToolSpec } from "../agent-loop/loop-types.js";
23
+ import type { MemoryProvider } from "./memory-provider.js";
24
+ /** Env var name — internal, not in public docs yet. */
25
+ export declare const PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
26
+ /**
27
+ * Returns true when the port-memory-path should be active for this send.
28
+ *
29
+ * Checks both `process.env` (Node) and `globalThis.process?.env`
30
+ * (defensive — some test environments stub process differently).
31
+ */
32
+ export declare function shouldUsePortMemoryPath(): boolean;
33
+ /**
34
+ * Pick which `MemoryProvider` (if any) gets passed to the agent loop.
35
+ *
36
+ * Semantics:
37
+ * - When consumer-supplied `options.memoryProvider` is set: ALWAYS
38
+ * honor it (regardless of env flag). The flag only affects the
39
+ * fall-back default.
40
+ * - When consumer didn't supply AND port path enabled: return the
41
+ * auto-installed `defaultMemoryProviderForLoop` (the adapter).
42
+ * - When consumer didn't supply AND port path disabled: return
43
+ * `undefined` (legacy path; agent-loop sees no provider).
44
+ */
45
+ export declare function resolveMemoryProviderForLoop(consumerSupplied: MemoryProvider | undefined, defaultAdapter: MemoryProvider, portPathEnabled: boolean): MemoryProvider | undefined;
46
+ /**
47
+ * Pick which `memoryTools` (if any) get passed to the agent loop's
48
+ * `inputs.memoryTools` field.
49
+ *
50
+ * Semantics:
51
+ * - When port path active: return `undefined` (tools surface via
52
+ * `provider.buildTools()` inside agent-loop instead — iter 18 T1.5.2).
53
+ * - When port path inactive: return the legacy tools (from
54
+ * `memoryGlue.ensureTools()`).
55
+ */
56
+ export declare function resolveMemoryToolsForLoop(legacyTools: ReadonlyArray<MemoryToolSpec> | undefined, portPathEnabled: boolean): ReadonlyArray<MemoryToolSpec> | undefined;
57
+ /**
58
+ * Pick the `activeMemorySummary` value to fold into the system-prompt
59
+ * assembly.
60
+ *
61
+ * Semantics:
62
+ * - When port path active: return `undefined` (additions surface via
63
+ * `provider.runActivePass()` inside agent-loop instead — iter 18 T1.5.3).
64
+ * - When port path inactive: return the legacy summary (from
65
+ * `memoryGlue.runActiveMemoryIfEnabled(...)`).
66
+ */
67
+ export declare function resolveActiveMemorySummaryForSend(legacySummary: string | undefined, portPathEnabled: boolean): string | undefined;
68
+ /**
69
+ * Type-only re-export for downstream consumers of the helpers.
70
+ * `CustomTool` is the port's tool shape; future iter may need it
71
+ * when assembling memoryTools via the port path.
72
+ */
73
+ export type { CustomTool };
@@ -0,0 +1,165 @@
1
+ /**
2
+ * `MemoryProvider` — kernel-facing port for the memory subsystem
3
+ * (SDK 2.0 Phase 1 / T1.1 — Hexagonal Architecture / Ports & Adapters,
4
+ * SOLID Dependency Inversion).
5
+ *
6
+ * The agent loop kernel depends on THIS CONTRACT — not on the concrete
7
+ * `internal/memory/*` modules. Default adapter ships with `@theokit/sdk`
8
+ * (no-op for back-compat); rich impl ships in `@theokit/sdk-memory`.
9
+ * Consumers opt-in via `Agent.create({ memoryProvider: ... })` (wiring
10
+ * lands in subsequent iteration).
11
+ *
12
+ * Design rationale (ADR-001 + ADR-003 in
13
+ * `sdk-2-0-phase-1-2-adr.md`):
14
+ * - Memory subsystem is deeply integrated with the agent loop (active
15
+ * memory pass, LLM tool injection, lifecycle ownership) — cannot
16
+ * extract via plugin-protocol alone like Cache / Handoff.
17
+ * - Interface inversion is the canonical FAANG-style answer: the kernel
18
+ * defines what it NEEDS; impls satisfy the contract; package boundary
19
+ * is the seam.
20
+ * - Mirrors the `BudgetTracker` interface inversion (iter 10-16): same
21
+ * pattern, different subsystem.
22
+ *
23
+ * Layered model (mirrors Budget):
24
+ * - `MemoryAdapter` (existing in `types/memory-adapter.ts`) — LOW-LEVEL
25
+ * data port: write / recall / delete primitives.
26
+ * - `MemoryProvider` (THIS FILE) — HIGH-LEVEL lifecycle port: init,
27
+ * tool factories, active memory pass, embedding runtime selection.
28
+ *
29
+ * @public — surface-level interface; impls are internal-but-replaceable.
30
+ */
31
+ import type { CustomTool, SDKAgent } from "../../types/agent.js";
32
+ import type { MemoryAdapter, MemoryFact } from "../../types/memory-adapter.js";
33
+ /** Result of `MemoryProvider.runActivePass(...)` — what the kernel injects into the LLM call. */
34
+ export interface ActiveMemoryPassResult {
35
+ /** Compressed memory facts to seed the LLM's context window for this turn. */
36
+ readonly facts: ReadonlyArray<MemoryFact>;
37
+ /** Optional system-prompt enrichment derived from the recalled facts. */
38
+ readonly systemPromptAdditions?: string;
39
+ /** Whether the active-memory circuit breaker tripped (degraded mode). */
40
+ readonly breakerTripped?: boolean;
41
+ }
42
+ /** Arguments for `MemoryProvider.runActivePass(...)`. */
43
+ export interface ActiveMemoryPassArgs {
44
+ /** The current user message — used as the recall query. */
45
+ readonly userMessage: string;
46
+ /** Conversation history (most recent first). */
47
+ readonly history: ReadonlyArray<{
48
+ role: "user" | "assistant";
49
+ content: string;
50
+ }>;
51
+ /** Agent identity for scope. */
52
+ readonly agentId: string;
53
+ }
54
+ /**
55
+ * Arguments for `MemoryProvider.recordSessionSummary(...)`
56
+ * (SDK 2.0 Phase 1 physical Stage 3 prep — iter 27).
57
+ *
58
+ * The "session summary" is the markdown that gets written to disk
59
+ * after a finished run + indexed under `corpus="sessions"`. This
60
+ * port method lets sdk-core's `post-run-lifecycle.ts` delegate the
61
+ * write to the provider instead of importing
62
+ * `internal/memory/storage/session-summary-writer.ts` directly.
63
+ *
64
+ * @public
65
+ */
66
+ export interface RecordSessionSummaryArgs {
67
+ /**
68
+ * Workspace cwd where on-disk artefacts live. Included on the args
69
+ * (not on a handle) because `recordSessionSummary` is STATELESS — it
70
+ * runs AFTER `runAgentLoop`'s `dispose()` releases the per-run handle.
71
+ * The kernel passes its own `workspaceCwd`; the impl uses it to
72
+ * compute the markdown file path.
73
+ */
74
+ readonly cwd: string;
75
+ /** Run id used as the filename key. */
76
+ readonly runId: string;
77
+ /** Agent identity for scope (foldering). */
78
+ readonly agentId: string;
79
+ /** Verbatim user message that started the run. */
80
+ readonly userText: string;
81
+ /** Final assistant text the run produced. */
82
+ readonly assistantText: string;
83
+ /** Final run status (only "finished" is recorded today). */
84
+ readonly status: "finished" | "error" | "cancelled";
85
+ /** Wall-clock ms at write time. */
86
+ readonly at: number;
87
+ }
88
+ /** Options for `MemoryProvider.init(...)`. */
89
+ export interface MemoryProviderInitOptions {
90
+ /** Workspace cwd where on-disk artefacts live (`.theokit/memory/...`). */
91
+ readonly cwd: string;
92
+ /** Embedding-provider id (`"openai" | "ollama" | ...`); when omitted the impl picks a default. */
93
+ readonly embeddingProviderId?: string;
94
+ }
95
+ /**
96
+ * Opaque handle returned by `init()`. Carried back into other methods so
97
+ * the impl can stash per-agent state (index, breaker, cache, …) without
98
+ * exposing it to the kernel.
99
+ */
100
+ export interface MemoryProviderHandle {
101
+ /** Adapter interface for direct read/write — matches existing `MemoryAdapter` shape. */
102
+ readonly adapter: MemoryAdapter;
103
+ /** Implementation-defined opaque field (private state pointer / index handle). */
104
+ readonly [implState: symbol]: unknown;
105
+ }
106
+ /**
107
+ * The kernel-facing contract. Implementations live OUTSIDE the agent loop
108
+ * (in `@theokit/sdk-memory` after Phase 1; in `internal/memory/` until then).
109
+ *
110
+ * Implementations MUST be:
111
+ * - **Lazy** — `init()` may be called once per agent; subsequent calls
112
+ * return the same handle (impl decides via cache). Heavy work
113
+ * (loading the index, opening SQLite) deferred until first use.
114
+ * - **Non-throwing on the hot path** — `runActivePass()` returns an
115
+ * empty `facts: []` on degradation rather than throwing. Errors
116
+ * surface via the breakerTripped flag + telemetry.
117
+ */
118
+ export interface MemoryProvider {
119
+ /** Construct or fetch the per-agent handle. Lazy + idempotent. */
120
+ init(opts: MemoryProviderInitOptions): Promise<MemoryProviderHandle>;
121
+ /** Build the LLM-facing tool catalog (memory_search, memory_get, …). */
122
+ buildTools(handle: MemoryProviderHandle, agent: SDKAgent): ReadonlyArray<CustomTool>;
123
+ /** Run the active-memory pre-LLM pass — recall + compress + format. */
124
+ runActivePass(handle: MemoryProviderHandle, args: ActiveMemoryPassArgs): Promise<ActiveMemoryPassResult>;
125
+ /**
126
+ * Optional post-run hook (SDK 2.0 Phase 1 physical Stage 1 — iter 19).
127
+ * Called by the agent loop AFTER a successful send so the impl can
128
+ * incorporate the session summary into its index (e.g., re-index the
129
+ * `sessions` corpus so the next recall sees it).
130
+ *
131
+ * Fire-and-forget at the call site; impl MUST be idempotent +
132
+ * non-throwing. Optional so existing impls (createNoopMemoryProvider,
133
+ * sdk-memory@0.1.0) keep working without modification.
134
+ *
135
+ * Mirrors the role of `LocalAgentMemory.syncIfReady()` in sdk-core's
136
+ * legacy memory path — exposing it via the port is the seam that
137
+ * unblocks moving LocalAgentMemory's logic out to sdk-memory.
138
+ */
139
+ sync?(handle: MemoryProviderHandle): Promise<void> | void;
140
+ /**
141
+ * Optional session-summary write hook (SDK 2.0 Phase 1 physical
142
+ * Stage 3 prep — iter 27, refined iter 28).
143
+ *
144
+ * Called by `post-run-lifecycle.ts` AFTER a finished run to persist
145
+ * the run's session-summary markdown under `corpus="sessions"`. When
146
+ * defined, the kernel delegates the write to the provider; when
147
+ * undefined, post-run-lifecycle falls back to the direct
148
+ * `writeSessionSummary` import (legacy path, until Stage 3 source
149
+ * move drops that import entirely).
150
+ *
151
+ * STATELESS — does NOT take a `MemoryProviderHandle` because post-run-
152
+ * lifecycle runs AFTER `runAgentLoop` disposed the per-run handle.
153
+ * `cwd` lives on `args` instead. Impls that need per-agent state can
154
+ * cache it via closure inside the provider factory.
155
+ *
156
+ * Impl MUST be non-throwing on the hot path. The kernel swallows
157
+ * any throw + emits a stderr warning.
158
+ *
159
+ * Optional so existing impls (createNoopMemoryProvider,
160
+ * createInMemoryMarkdownProvider) keep working without modification.
161
+ */
162
+ recordSessionSummary?(args: RecordSessionSummaryArgs): Promise<void> | void;
163
+ /** Release the handle (close index, flush caches). Idempotent + non-throwing. */
164
+ dispose(handle: MemoryProviderHandle): Promise<void> | void;
165
+ }
@@ -1,4 +1,14 @@
1
- import type { AgentOptions, ModelSelection } from "../../types/agent.js";
1
+ /**
2
+ * Whether an agent runs in the local or cloud runtime. Drives storage routing,
3
+ * fork semantics, and the cross-runtime UnsupportedRunOperationError contract
4
+ * (ADR D122).
5
+ */
6
+ export type AgentRuntime = "local" | "cloud";
7
+ /**
8
+ * In-memory agent registry record. Persisted via the
9
+ * `agent-registry-store.ts` serialization layer (which strips secrets per
10
+ * ADR D17 + D68 — see `stripSecretsFromOptions`).
11
+ */
2
12
  export interface RegisteredAgent {
3
13
  agentId: string;
4
14
  runtime: AgentRuntime;
@@ -9,8 +19,10 @@ export interface RegisteredAgent {
9
19
  lastModified: number;
10
20
  archived: boolean;
11
21
  options: AgentOptions;
12
- /** Local workspace cwd; only set when runtime is local. Also used as the
13
- * persistence routing key (cloud agents default to `process.cwd()`). */
22
+ /**
23
+ * Local workspace cwd; only set when runtime is local. Also used as the
24
+ * persistence routing key (cloud agents default to `process.cwd()`).
25
+ */
14
26
  cwd?: string;
15
27
  /** Cloud repo URLs; only set when runtime is cloud. */
16
28
  repos?: string[];
@@ -26,9 +38,3 @@ export interface RegisteredAgent {
26
38
  */
27
39
  requiresCustomStorage?: boolean;
28
40
  }
29
- export declare function registerAgent(agent: RegisteredAgent): void;
30
- export declare function getRegisteredAgent(agentId: string): RegisteredAgent | undefined;
31
- export declare function listRegisteredAgents(runtime?: AgentRuntime): RegisteredAgent[];
32
- export declare function updateRegisteredAgent(agentId: string, update: Partial<RegisteredAgent>): RegisteredAgent | undefined;
33
- export declare function removeRegisteredAgent(agentId: string): boolean;
34
- export declare function clearAgentRegistry(): void;
@@ -0,0 +1,7 @@
1
+ import type { AgentRuntime, RegisteredAgent } from "./agent-registry-contract.js";
2
+ export declare function registerAgent(agent: RegisteredAgent): void;
3
+ export declare function getRegisteredAgent(agentId: string): RegisteredAgent | undefined;
4
+ export declare function listRegisteredAgents(runtime?: AgentRuntime): RegisteredAgent[];
5
+ export declare function updateRegisteredAgent(agentId: string, update: Partial<RegisteredAgent>): RegisteredAgent | undefined;
6
+ export declare function removeRegisteredAgent(agentId: string): boolean;
7
+ export declare function clearAgentRegistry(): void;
@@ -17,7 +17,7 @@
17
17
  *
18
18
  * @public (singleton exposed via `Agent.registry`)
19
19
  */
20
- import type { SDKAgent } from "../../types/agent.js";
20
+ import type { SDKAgent } from "../../../types/agent.js";
21
21
  export type EvictReason = "lru" | "idle" | "explicit";
22
22
  export interface AgentRegistryOptions {
23
23
  /**
@@ -1,4 +1,4 @@
1
- import type { Run } from "../../types/run.js";
1
+ import type { Run } from "../../../types/run.js";
2
2
  export declare function registerRun(run: Run): void;
3
3
  export declare function getRun(runId: string): Run | undefined;
4
4
  export declare function listRunsByAgent(agentId: string): Run[];