@retinue/agentkit 0.1.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 (405) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +310 -0
  3. package/dist/adapters/bullmq/consumer.d.ts +33 -0
  4. package/dist/adapters/bullmq/consumer.js +41 -0
  5. package/dist/adapters/bullmq/dispatcher.d.ts +74 -0
  6. package/dist/adapters/bullmq/dispatcher.js +160 -0
  7. package/dist/adapters/bullmq/export.d.ts +31 -0
  8. package/dist/adapters/bullmq/export.js +53 -0
  9. package/dist/adapters/bullmq/extraction.d.ts +42 -0
  10. package/dist/adapters/bullmq/extraction.js +63 -0
  11. package/dist/adapters/bullmq/index.d.ts +13 -0
  12. package/dist/adapters/bullmq/index.js +13 -0
  13. package/dist/adapters/bullmq/lock.d.ts +77 -0
  14. package/dist/adapters/bullmq/lock.js +126 -0
  15. package/dist/adapters/bullmq/queue.d.ts +50 -0
  16. package/dist/adapters/bullmq/queue.js +81 -0
  17. package/dist/adapters/memory/artifact-exports.d.ts +11 -0
  18. package/dist/adapters/memory/artifact-exports.js +102 -0
  19. package/dist/adapters/memory/artifacts.d.ts +15 -0
  20. package/dist/adapters/memory/artifacts.js +134 -0
  21. package/dist/adapters/memory/blobs.d.ts +7 -0
  22. package/dist/adapters/memory/blobs.js +27 -0
  23. package/dist/adapters/memory/evaluation.d.ts +18 -0
  24. package/dist/adapters/memory/evaluation.js +148 -0
  25. package/dist/adapters/memory/files.d.ts +27 -0
  26. package/dist/adapters/memory/files.js +0 -0
  27. package/dist/adapters/memory/flows.d.ts +16 -0
  28. package/dist/adapters/memory/flows.js +117 -0
  29. package/dist/adapters/memory/hitl.d.ts +9 -0
  30. package/dist/adapters/memory/hitl.js +130 -0
  31. package/dist/adapters/memory/idempotency.d.ts +13 -0
  32. package/dist/adapters/memory/idempotency.js +32 -0
  33. package/dist/adapters/memory/index.d.ts +39 -0
  34. package/dist/adapters/memory/index.js +107 -0
  35. package/dist/adapters/memory/knowledge.d.ts +43 -0
  36. package/dist/adapters/memory/knowledge.js +248 -0
  37. package/dist/adapters/memory/mcp.d.ts +9 -0
  38. package/dist/adapters/memory/mcp.js +37 -0
  39. package/dist/adapters/memory/message-store.d.ts +17 -0
  40. package/dist/adapters/memory/message-store.js +70 -0
  41. package/dist/adapters/memory/principal-memory.d.ts +7 -0
  42. package/dist/adapters/memory/principal-memory.js +83 -0
  43. package/dist/adapters/memory/runtime.d.ts +29 -0
  44. package/dist/adapters/memory/runtime.js +0 -0
  45. package/dist/adapters/memory/sessions.d.ts +29 -0
  46. package/dist/adapters/memory/sessions.js +0 -0
  47. package/dist/adapters/memory/skills.d.ts +10 -0
  48. package/dist/adapters/memory/skills.js +41 -0
  49. package/dist/adapters/memory/thread-summary.d.ts +7 -0
  50. package/dist/adapters/memory/thread-summary.js +29 -0
  51. package/dist/adapters/memory/usage-limits.d.ts +13 -0
  52. package/dist/adapters/memory/usage-limits.js +72 -0
  53. package/dist/adapters/memory/usage.d.ts +16 -0
  54. package/dist/adapters/memory/usage.js +279 -0
  55. package/dist/adapters/otel/index.d.ts +111 -0
  56. package/dist/adapters/otel/index.js +133 -0
  57. package/dist/adapters/postgres/artifact-exports.d.ts +12 -0
  58. package/dist/adapters/postgres/artifact-exports.js +117 -0
  59. package/dist/adapters/postgres/artifacts.d.ts +16 -0
  60. package/dist/adapters/postgres/artifacts.js +172 -0
  61. package/dist/adapters/postgres/checkpoint-store.d.ts +16 -0
  62. package/dist/adapters/postgres/checkpoint-store.js +34 -0
  63. package/dist/adapters/postgres/config.d.ts +15 -0
  64. package/dist/adapters/postgres/config.js +187 -0
  65. package/dist/adapters/postgres/conversation-store.d.ts +4 -0
  66. package/dist/adapters/postgres/conversation-store.js +82 -0
  67. package/dist/adapters/postgres/evaluation.d.ts +17 -0
  68. package/dist/adapters/postgres/evaluation.js +193 -0
  69. package/dist/adapters/postgres/file-content.d.ts +30 -0
  70. package/dist/adapters/postgres/file-content.js +111 -0
  71. package/dist/adapters/postgres/files.d.ts +19 -0
  72. package/dist/adapters/postgres/files.js +209 -0
  73. package/dist/adapters/postgres/flows.d.ts +20 -0
  74. package/dist/adapters/postgres/flows.js +206 -0
  75. package/dist/adapters/postgres/hitl.d.ts +5 -0
  76. package/dist/adapters/postgres/hitl.js +247 -0
  77. package/dist/adapters/postgres/index.d.ts +35 -0
  78. package/dist/adapters/postgres/index.js +35 -0
  79. package/dist/adapters/postgres/knowledge.d.ts +48 -0
  80. package/dist/adapters/postgres/knowledge.js +255 -0
  81. package/dist/adapters/postgres/memory.d.ts +14 -0
  82. package/dist/adapters/postgres/memory.js +194 -0
  83. package/dist/adapters/postgres/message-store.d.ts +11 -0
  84. package/dist/adapters/postgres/message-store.js +145 -0
  85. package/dist/adapters/postgres/migrations.d.ts +69 -0
  86. package/dist/adapters/postgres/migrations.js +1594 -0
  87. package/dist/adapters/postgres/pg-executor.d.ts +19 -0
  88. package/dist/adapters/postgres/pg-executor.js +32 -0
  89. package/dist/adapters/postgres/retention.d.ts +26 -0
  90. package/dist/adapters/postgres/retention.js +59 -0
  91. package/dist/adapters/postgres/rollups.d.ts +17 -0
  92. package/dist/adapters/postgres/rollups.js +267 -0
  93. package/dist/adapters/postgres/run-coordinator.d.ts +5 -0
  94. package/dist/adapters/postgres/run-coordinator.js +98 -0
  95. package/dist/adapters/postgres/run-event-log.d.ts +26 -0
  96. package/dist/adapters/postgres/run-event-log.js +30 -0
  97. package/dist/adapters/postgres/run-store.d.ts +4 -0
  98. package/dist/adapters/postgres/run-store.js +199 -0
  99. package/dist/adapters/postgres/schema.d.ts +39 -0
  100. package/dist/adapters/postgres/schema.js +70 -0
  101. package/dist/adapters/postgres/session-state.d.ts +7 -0
  102. package/dist/adapters/postgres/session-state.js +99 -0
  103. package/dist/adapters/postgres/sql.d.ts +8 -0
  104. package/dist/adapters/postgres/sql.js +2 -0
  105. package/dist/adapters/postgres/transaction.d.ts +37 -0
  106. package/dist/adapters/postgres/transaction.js +93 -0
  107. package/dist/adapters/postgres/unit-of-work.d.ts +18 -0
  108. package/dist/adapters/postgres/unit-of-work.js +8 -0
  109. package/dist/adapters/postgres/usage-limits.d.ts +15 -0
  110. package/dist/adapters/postgres/usage-limits.js +136 -0
  111. package/dist/adapters/postgres/usage.d.ts +15 -0
  112. package/dist/adapters/postgres/usage.js +226 -0
  113. package/dist/adapters/redis/index.d.ts +9 -0
  114. package/dist/adapters/redis/index.js +9 -0
  115. package/dist/adapters/redis/realtime.d.ts +74 -0
  116. package/dist/adapters/redis/realtime.js +112 -0
  117. package/dist/adapters/supabase/index.d.ts +88 -0
  118. package/dist/adapters/supabase/index.js +84 -0
  119. package/dist/adapters/supabase/realtime.d.ts +30 -0
  120. package/dist/adapters/supabase/realtime.js +53 -0
  121. package/dist/adapters/supabase/rls.d.ts +99 -0
  122. package/dist/adapters/supabase/rls.js +216 -0
  123. package/dist/adapters/supabase/storage.d.ts +50 -0
  124. package/dist/adapters/supabase/storage.js +207 -0
  125. package/dist/agents/agent.d.ts +66 -0
  126. package/dist/agents/agent.js +209 -0
  127. package/dist/agents/define.d.ts +21 -0
  128. package/dist/agents/define.js +63 -0
  129. package/dist/agents/engine.d.ts +98 -0
  130. package/dist/agents/engine.js +462 -0
  131. package/dist/agents/index.d.ts +50 -0
  132. package/dist/agents/index.js +17 -0
  133. package/dist/artifacts/index.d.ts +114 -0
  134. package/dist/artifacts/index.js +219 -0
  135. package/dist/authorization/index.d.ts +76 -0
  136. package/dist/authorization/index.js +76 -0
  137. package/dist/capabilities/index.d.ts +120 -0
  138. package/dist/capabilities/index.js +167 -0
  139. package/dist/capabilities/runtime.d.ts +89 -0
  140. package/dist/capabilities/runtime.js +84 -0
  141. package/dist/citations/index.d.ts +161 -0
  142. package/dist/citations/index.js +182 -0
  143. package/dist/context/assembler.d.ts +82 -0
  144. package/dist/context/assembler.js +129 -0
  145. package/dist/context/compaction.d.ts +45 -0
  146. package/dist/context/compaction.js +55 -0
  147. package/dist/context/index.d.ts +75 -0
  148. package/dist/context/index.js +17 -0
  149. package/dist/core/content-parts.d.ts +194 -0
  150. package/dist/core/content-parts.js +23 -0
  151. package/dist/core/context.d.ts +51 -0
  152. package/dist/core/context.js +9 -0
  153. package/dist/core/env.d.ts +25 -0
  154. package/dist/core/env.js +41 -0
  155. package/dist/core/errors.d.ts +30 -0
  156. package/dist/core/errors.js +65 -0
  157. package/dist/core/events.d.ts +139 -0
  158. package/dist/core/events.js +99 -0
  159. package/dist/core/ids.d.ts +52 -0
  160. package/dist/core/ids.js +13 -0
  161. package/dist/core/index.d.ts +9 -0
  162. package/dist/core/index.js +9 -0
  163. package/dist/core/tokens.d.ts +22 -0
  164. package/dist/core/tokens.js +22 -0
  165. package/dist/core/validation.d.ts +34 -0
  166. package/dist/core/validation.js +176 -0
  167. package/dist/documents/extraction.d.ts +121 -0
  168. package/dist/documents/extraction.js +293 -0
  169. package/dist/documents/index.d.ts +199 -0
  170. package/dist/documents/index.js +65 -0
  171. package/dist/documents/parsers/pdf.d.ts +47 -0
  172. package/dist/documents/parsers/pdf.js +508 -0
  173. package/dist/documents/parsers/text.d.ts +59 -0
  174. package/dist/documents/parsers/text.js +325 -0
  175. package/dist/documents/read-tool.d.ts +52 -0
  176. package/dist/documents/read-tool.js +109 -0
  177. package/dist/documents/render.d.ts +29 -0
  178. package/dist/documents/render.js +59 -0
  179. package/dist/documents/vision.d.ts +159 -0
  180. package/dist/documents/vision.js +214 -0
  181. package/dist/entries/adapters-bullmq.d.ts +8 -0
  182. package/dist/entries/adapters-bullmq.js +8 -0
  183. package/dist/entries/adapters-otel.d.ts +13 -0
  184. package/dist/entries/adapters-otel.js +13 -0
  185. package/dist/entries/adapters-postgres.d.ts +10 -0
  186. package/dist/entries/adapters-postgres.js +10 -0
  187. package/dist/entries/adapters-redis.d.ts +3 -0
  188. package/dist/entries/adapters-redis.js +3 -0
  189. package/dist/entries/context.d.ts +20 -0
  190. package/dist/entries/context.js +20 -0
  191. package/dist/entries/flows.d.ts +15 -0
  192. package/dist/entries/flows.js +15 -0
  193. package/dist/entries/hitl.d.ts +10 -0
  194. package/dist/entries/hitl.js +10 -0
  195. package/dist/entries/knowledge.d.ts +18 -0
  196. package/dist/entries/knowledge.js +19 -0
  197. package/dist/entries/mcp.d.ts +10 -0
  198. package/dist/entries/mcp.js +10 -0
  199. package/dist/entries/observability.d.ts +14 -0
  200. package/dist/entries/observability.js +16 -0
  201. package/dist/entries/persistence.d.ts +11 -0
  202. package/dist/entries/persistence.js +11 -0
  203. package/dist/entries/providers.d.ts +14 -0
  204. package/dist/entries/providers.js +14 -0
  205. package/dist/entries/runtime.d.ts +13 -0
  206. package/dist/entries/runtime.js +13 -0
  207. package/dist/entries/server.d.ts +24 -0
  208. package/dist/entries/server.js +24 -0
  209. package/dist/entries/tools.d.ts +21 -0
  210. package/dist/entries/tools.js +21 -0
  211. package/dist/entries/usage.d.ts +10 -0
  212. package/dist/entries/usage.js +10 -0
  213. package/dist/evaluation/gate.d.ts +168 -0
  214. package/dist/evaluation/gate.js +180 -0
  215. package/dist/evaluation/graders.d.ts +125 -0
  216. package/dist/evaluation/graders.js +203 -0
  217. package/dist/evaluation/index.d.ts +120 -0
  218. package/dist/evaluation/index.js +183 -0
  219. package/dist/evaluation/judge.d.ts +75 -0
  220. package/dist/evaluation/judge.js +111 -0
  221. package/dist/export/index.d.ts +162 -0
  222. package/dist/export/index.js +363 -0
  223. package/dist/export/markdown.d.ts +19 -0
  224. package/dist/export/markdown.js +29 -0
  225. package/dist/export/pdf.d.ts +73 -0
  226. package/dist/export/pdf.js +407 -0
  227. package/dist/files/context.d.ts +97 -0
  228. package/dist/files/context.js +185 -0
  229. package/dist/files/index.d.ts +210 -0
  230. package/dist/files/index.js +338 -0
  231. package/dist/files/read-tool.d.ts +81 -0
  232. package/dist/files/read-tool.js +163 -0
  233. package/dist/files/turn-parts.d.ts +96 -0
  234. package/dist/files/turn-parts.js +171 -0
  235. package/dist/flows/index.d.ts +270 -0
  236. package/dist/flows/index.js +62 -0
  237. package/dist/flows/interpreter.d.ts +146 -0
  238. package/dist/flows/interpreter.js +426 -0
  239. package/dist/flows/runner.d.ts +145 -0
  240. package/dist/flows/runner.js +270 -0
  241. package/dist/graphql/index.d.ts +8 -0
  242. package/dist/graphql/index.js +8 -0
  243. package/dist/graphql/resolvers.d.ts +237 -0
  244. package/dist/graphql/resolvers.js +253 -0
  245. package/dist/graphql/schema.d.ts +11 -0
  246. package/dist/graphql/schema.js +258 -0
  247. package/dist/graphql/sse.d.ts +77 -0
  248. package/dist/graphql/sse.js +100 -0
  249. package/dist/hitl/approved-execution.d.ts +127 -0
  250. package/dist/hitl/approved-execution.js +177 -0
  251. package/dist/hitl/index.d.ts +79 -0
  252. package/dist/hitl/index.js +12 -0
  253. package/dist/hitl/service.d.ts +221 -0
  254. package/dist/hitl/service.js +268 -0
  255. package/dist/idempotency/index.d.ts +70 -0
  256. package/dist/idempotency/index.js +59 -0
  257. package/dist/index.d.ts +103 -0
  258. package/dist/index.js +60 -0
  259. package/dist/knowledge/chunking.d.ts +57 -0
  260. package/dist/knowledge/chunking.js +158 -0
  261. package/dist/knowledge/index.d.ts +119 -0
  262. package/dist/knowledge/index.js +166 -0
  263. package/dist/knowledge/retrieval.d.ts +146 -0
  264. package/dist/knowledge/retrieval.js +170 -0
  265. package/dist/loadtest/harness.d.ts +168 -0
  266. package/dist/loadtest/harness.js +507 -0
  267. package/dist/loadtest/index.d.ts +13 -0
  268. package/dist/loadtest/index.js +13 -0
  269. package/dist/loadtest/injection.d.ts +89 -0
  270. package/dist/loadtest/injection.js +147 -0
  271. package/dist/loadtest/metrics.d.ts +197 -0
  272. package/dist/loadtest/metrics.js +160 -0
  273. package/dist/loadtest/runbooks.d.ts +28 -0
  274. package/dist/loadtest/runbooks.js +159 -0
  275. package/dist/loadtest/scenario.d.ts +104 -0
  276. package/dist/loadtest/scenario.js +208 -0
  277. package/dist/mcp/egress.d.ts +53 -0
  278. package/dist/mcp/egress.js +115 -0
  279. package/dist/mcp/index.d.ts +93 -0
  280. package/dist/mcp/index.js +33 -0
  281. package/dist/mcp/provider.d.ts +62 -0
  282. package/dist/mcp/provider.js +0 -0
  283. package/dist/models/index.d.ts +98 -0
  284. package/dist/models/index.js +74 -0
  285. package/dist/models/pricing.d.ts +24 -0
  286. package/dist/models/pricing.js +37 -0
  287. package/dist/models/provider-factory.d.ts +31 -0
  288. package/dist/models/provider-factory.js +67 -0
  289. package/dist/models/streaming.d.ts +145 -0
  290. package/dist/models/streaming.js +272 -0
  291. package/dist/models/vision.d.ts +38 -0
  292. package/dist/models/vision.js +62 -0
  293. package/dist/persistence/index.d.ts +1654 -0
  294. package/dist/persistence/index.js +226 -0
  295. package/dist/principal-memory/index.d.ts +106 -0
  296. package/dist/principal-memory/index.js +89 -0
  297. package/dist/retention/index.d.ts +89 -0
  298. package/dist/retention/index.js +70 -0
  299. package/dist/runtime/checkpoint.d.ts +37 -0
  300. package/dist/runtime/checkpoint.js +22 -0
  301. package/dist/runtime/index.d.ts +118 -0
  302. package/dist/runtime/index.js +69 -0
  303. package/dist/runtime/retry.d.ts +95 -0
  304. package/dist/runtime/retry.js +126 -0
  305. package/dist/runtime/serialization.d.ts +85 -0
  306. package/dist/runtime/serialization.js +95 -0
  307. package/dist/runtime/streaming.d.ts +54 -0
  308. package/dist/runtime/streaming.js +115 -0
  309. package/dist/runtime/worker.d.ts +130 -0
  310. package/dist/runtime/worker.js +405 -0
  311. package/dist/security/checklist.d.ts +53 -0
  312. package/dist/security/checklist.js +204 -0
  313. package/dist/security/findings.d.ts +56 -0
  314. package/dist/security/findings.js +168 -0
  315. package/dist/security/index.d.ts +14 -0
  316. package/dist/security/index.js +14 -0
  317. package/dist/security/prompt-safety.d.ts +100 -0
  318. package/dist/security/prompt-safety.js +133 -0
  319. package/dist/server/boot.d.ts +32 -0
  320. package/dist/server/boot.js +36 -0
  321. package/dist/server/cli-worker.d.ts +37 -0
  322. package/dist/server/cli-worker.js +151 -0
  323. package/dist/server/cli.d.ts +27 -0
  324. package/dist/server/cli.js +74 -0
  325. package/dist/server/config.d.ts +42 -0
  326. package/dist/server/config.js +127 -0
  327. package/dist/server/health.d.ts +59 -0
  328. package/dist/server/health.js +90 -0
  329. package/dist/server/host.d.ts +39 -0
  330. package/dist/server/host.js +124 -0
  331. package/dist/server/index.d.ts +15 -0
  332. package/dist/server/index.js +15 -0
  333. package/dist/server/main.d.ts +16 -0
  334. package/dist/server/main.js +31 -0
  335. package/dist/server/sse-route.d.ts +21 -0
  336. package/dist/server/sse-route.js +282 -0
  337. package/dist/skills/index.d.ts +67 -0
  338. package/dist/skills/index.js +31 -0
  339. package/dist/skills/resolver.d.ts +54 -0
  340. package/dist/skills/resolver.js +121 -0
  341. package/dist/teams/index.d.ts +93 -0
  342. package/dist/teams/index.js +207 -0
  343. package/dist/telemetry/index.d.ts +157 -0
  344. package/dist/telemetry/index.js +71 -0
  345. package/dist/telemetry/instrument.d.ts +108 -0
  346. package/dist/telemetry/instrument.js +232 -0
  347. package/dist/telemetry/log-events.d.ts +17 -0
  348. package/dist/telemetry/log-events.js +58 -0
  349. package/dist/telemetry/metrics.d.ts +123 -0
  350. package/dist/telemetry/metrics.js +135 -0
  351. package/dist/telemetry/noop.d.ts +39 -0
  352. package/dist/telemetry/noop.js +143 -0
  353. package/dist/telemetry/redaction.d.ts +64 -0
  354. package/dist/telemetry/redaction.js +153 -0
  355. package/dist/telemetry/spans.d.ts +56 -0
  356. package/dist/telemetry/spans.js +78 -0
  357. package/dist/telemetry/trace-context.d.ts +55 -0
  358. package/dist/telemetry/trace-context.js +60 -0
  359. package/dist/toolkit/compute.d.ts +53 -0
  360. package/dist/toolkit/compute.js +152 -0
  361. package/dist/toolkit/data.d.ts +98 -0
  362. package/dist/toolkit/data.js +235 -0
  363. package/dist/toolkit/http.d.ts +113 -0
  364. package/dist/toolkit/http.js +205 -0
  365. package/dist/toolkit/index.d.ts +21 -0
  366. package/dist/toolkit/index.js +17 -0
  367. package/dist/toolkit/web.d.ts +107 -0
  368. package/dist/toolkit/web.js +147 -0
  369. package/dist/tools/define.d.ts +25 -0
  370. package/dist/tools/define.js +45 -0
  371. package/dist/tools/delegating.d.ts +132 -0
  372. package/dist/tools/delegating.js +211 -0
  373. package/dist/tools/index.d.ts +129 -0
  374. package/dist/tools/index.js +33 -0
  375. package/dist/tools/library/compute.d.ts +11 -0
  376. package/dist/tools/library/compute.js +46 -0
  377. package/dist/tools/library/data.d.ts +16 -0
  378. package/dist/tools/library/data.js +92 -0
  379. package/dist/tools/library/http.d.ts +28 -0
  380. package/dist/tools/library/http.js +71 -0
  381. package/dist/tools/library/index.d.ts +97 -0
  382. package/dist/tools/library/index.js +134 -0
  383. package/dist/tools/library/knowledge.d.ts +39 -0
  384. package/dist/tools/library/knowledge.js +58 -0
  385. package/dist/tools/library/web.d.ts +19 -0
  386. package/dist/tools/library/web.js +65 -0
  387. package/dist/tools/meta-tools.d.ts +19 -0
  388. package/dist/tools/meta-tools.js +36 -0
  389. package/dist/tools/registry.d.ts +146 -0
  390. package/dist/tools/registry.js +291 -0
  391. package/dist/usage/index.d.ts +105 -0
  392. package/dist/usage/index.js +20 -0
  393. package/dist/usage/quota.d.ts +258 -0
  394. package/dist/usage/quota.js +510 -0
  395. package/dist/usage/recorder.d.ts +29 -0
  396. package/dist/usage/recorder.js +96 -0
  397. package/dist/usage/rollups.d.ts +121 -0
  398. package/dist/usage/rollups.js +157 -0
  399. package/dist/worker/export.d.ts +57 -0
  400. package/dist/worker/export.js +81 -0
  401. package/dist/worker/extraction.d.ts +57 -0
  402. package/dist/worker/extraction.js +84 -0
  403. package/dist/worker/main.d.ts +103 -0
  404. package/dist/worker/main.js +159 -0
  405. package/package.json +187 -0
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Citations and per-claim provenance — REQ-030 (#137).
3
+ *
4
+ * `research-and-citation` already says what should happen. This makes it structural, and the structure carries
5
+ * four decisions worth stating.
6
+ *
7
+ * **A citation is a snapshot, not a pointer.** `excerpt`, `title` and `retrievedAt` live on the part. AC-4
8
+ * requires an answer given months ago to stay auditable *after the source is gone* — a document deleted, a URL
9
+ * dead, a chunk re-indexed under a new id — and a citation that resolved by fetching would stop being evidence
10
+ * exactly when someone needs it. The duplication is the feature.
11
+ *
12
+ * **Groundedness is derived from the citation graph**, not flagged on the text. A text part is grounded exactly
13
+ * when some citation names it in `supports`. A boolean on the text part would be a second place for the same
14
+ * fact, and the two would drift the first time a citation was withheld — leaving a claim that says "grounded"
15
+ * with nothing behind it, which is worse than an honestly ungrounded one.
16
+ *
17
+ * **Permission is re-checked at citation time.** AC-5, and the reason is precise: retrieval and rendering are
18
+ * different moments, and a permission can change between them. A citation emitted on the strength of a
19
+ * retrieval check is a citation that can outlive the access that justified it.
20
+ *
21
+ * **One shape for retrieval and web research.** AC-6. Two part types would mean two renderers, two schemas and
22
+ * eventually two behaviours for "click the citation".
23
+ */
24
+ import { AgentPlatformError } from "../core/errors.js";
25
+ import { asId } from "../core/ids.js";
26
+ import { MAX_CITATION_EXCERPT } from "../core/validation.js";
27
+ /** The current citation payload version. Bumped from 1 by #137, which added origin, excerpt and supports. */
28
+ export const CITATION_SCHEMA_VERSION = 2;
29
+ /**
30
+ * Trim an excerpt to the cap without cutting a word in half.
31
+ *
32
+ * A citation ending mid-word reads as corrupt, and a reader cannot tell whether the source said something else.
33
+ * The ellipsis is explicit so a truncated excerpt is visibly truncated rather than silently shorter than what
34
+ * was read.
35
+ */
36
+ export const boundExcerpt = (text, max = MAX_CITATION_EXCERPT) => {
37
+ const collapsed = text.replace(/\s+/g, " ").trim();
38
+ if (collapsed.length <= max)
39
+ return collapsed;
40
+ const cut = collapsed.slice(0, max - 1);
41
+ const lastSpace = cut.lastIndexOf(" ");
42
+ return `${lastSpace > max * 0.6 ? cut.slice(0, lastSpace) : cut}…`;
43
+ };
44
+ /** A citation built from a retrieval hit. The passage fields come from the hit, so they cannot disagree. */
45
+ export const citationFromRetrieval = (input) => ({
46
+ origin: {
47
+ kind: "retrieval",
48
+ sourceType: input.hit.reference.sourceType,
49
+ sourceId: input.hit.reference.sourceId,
50
+ chunkId: input.hit.reference.chunkId,
51
+ chunkIndex: input.hit.reference.chunkIndex,
52
+ ...(input.hit.reference.locator === undefined ? {} : { locator: input.hit.reference.locator }),
53
+ },
54
+ // The chunk's own content, bounded. Not a re-read of the source: what was *used* is what must be cited.
55
+ excerpt: boundExcerpt(input.hit.chunk.content),
56
+ retrievedAt: input.retrievedAt,
57
+ supports: input.supports,
58
+ ...(input.charRange === undefined ? {} : { charRange: input.charRange }),
59
+ // The chunk's auth subject, so the emission check asks about the same thing retrieval filtered on.
60
+ authSubject: input.hit.chunk.authSubject,
61
+ });
62
+ /**
63
+ * A citation built from a web passage.
64
+ *
65
+ * Shaped to accept ShareFlow's `SourcePassage` without adaptation — `url`, `retrievedAt`, `excerpt` — because
66
+ * AC-6 is only true if the two paths really do produce one thing rather than two things that look alike.
67
+ */
68
+ export const citationFromWeb = (input) => ({
69
+ origin: {
70
+ kind: "web",
71
+ url: input.passage.url,
72
+ ...(input.title === undefined ? {} : { title: input.title }),
73
+ },
74
+ excerpt: boundExcerpt(input.passage.excerpt),
75
+ retrievedAt: input.passage.retrievedAt,
76
+ supports: input.supports,
77
+ });
78
+ export const createCitationEmitter = (deps) => {
79
+ const clock = deps.clock ?? (() => new Date().toISOString());
80
+ const newId = deps.partId ?? (() => `cite_${crypto.randomUUID()}`);
81
+ return {
82
+ /**
83
+ * Turn candidates into parts, dropping any the reader may not open.
84
+ *
85
+ * Checked here and not only at retrieval, because the two are different moments. A permission revoked in
86
+ * between is exactly the case the test steps name, and a citation emitted on a retrieval-time check would
87
+ * survive it.
88
+ */
89
+ async emit(context, candidates) {
90
+ const parts = [];
91
+ let withheld = 0;
92
+ for (const candidate of candidates) {
93
+ if (!(await this.mayCite(context, candidate))) {
94
+ withheld += 1;
95
+ continue;
96
+ }
97
+ parts.push({
98
+ id: asId(newId()),
99
+ type: "citation",
100
+ schemaVersion: CITATION_SCHEMA_VERSION,
101
+ createdAt: clock(),
102
+ origin: candidate.origin,
103
+ excerpt: candidate.excerpt,
104
+ retrievedAt: candidate.retrievedAt,
105
+ supports: candidate.supports,
106
+ ...(candidate.charRange === undefined ? {} : { charRange: candidate.charRange }),
107
+ });
108
+ }
109
+ return { parts, withheld };
110
+ },
111
+ /**
112
+ * Whether this reader may be shown this citation.
113
+ *
114
+ * A web citation needs no check: its URL is public by construction, and asking a policy about it would be
115
+ * asking about a resource the policy has never heard of — which most policies answer by denying, silently
116
+ * suppressing every web citation.
117
+ */
118
+ async mayCite(context, candidate) {
119
+ if (candidate.origin.kind === "web")
120
+ return true;
121
+ if (candidate.authSubject === undefined)
122
+ // A retrieval citation with no subject cannot be checked, so it is not emitted. Failing closed here is
123
+ // the only safe direction: the alternative emits an excerpt nobody authorised.
124
+ return false;
125
+ const decision = await deps.authorization.can(context, "read", {
126
+ type: "conversation",
127
+ id: candidate.authSubject,
128
+ });
129
+ return decision.allow;
130
+ },
131
+ };
132
+ };
133
+ /**
134
+ * The parts a message's citations ground — AC-3.
135
+ *
136
+ * Derived from the citation graph, so there is one source of truth. A caller renders a text part differently
137
+ * when its id is in this set; nothing has to inspect the prose.
138
+ */
139
+ export const groundedPartIds = (parts) => {
140
+ const grounded = new Set();
141
+ for (const part of parts) {
142
+ if (part.type !== "citation")
143
+ continue;
144
+ for (const supported of part.supports)
145
+ grounded.add(supported);
146
+ }
147
+ return grounded;
148
+ };
149
+ /** Citations that ground a given part, in the order they appear. For rendering markers next to a claim. */
150
+ export const citationsFor = (parts, partId) => parts.filter((p) => p.type === "citation" && p.supports.includes(partId));
151
+ /**
152
+ * A citation that grounds nothing.
153
+ *
154
+ * Worth finding, because it is the shape a bug takes: a producer that emitted citations without wiring them to
155
+ * the claims they support leaves an answer that *looks* cited — markers in a list at the bottom — while no
156
+ * individual statement is traceable, which is the failure REQ-030 exists to prevent.
157
+ */
158
+ export const danglingCitations = (parts) => {
159
+ const ids = new Set(parts.map((p) => p.id));
160
+ return parts.filter((p) => p.type === "citation" && (p.supports.length === 0 || !p.supports.some((s) => ids.has(s))));
161
+ };
162
+ export const resolveCitation = (part) => ({
163
+ excerpt: part.excerpt,
164
+ retrievedAt: part.retrievedAt,
165
+ label: part.origin.kind === "retrieval"
166
+ ? // The heading path when the chunker found one; otherwise the passage's position, which is still more
167
+ // specific than the document. A bare document name would be AC-2 unmet.
168
+ (part.origin.locator ?? `${part.origin.sourceId} — passage ${part.origin.chunkIndex + 1}`)
169
+ : (part.origin.title ?? part.origin.url),
170
+ target: part.origin.kind === "retrieval" ? part.origin.chunkId : part.origin.url,
171
+ kind: part.origin.kind,
172
+ });
173
+ /** Thrown when a producer tries to cite without an excerpt. A citation with no text is not evidence. */
174
+ export const assertCitable = (candidate) => {
175
+ if (candidate.excerpt.trim() === "")
176
+ throw new AgentPlatformError({
177
+ code: "invalid_input",
178
+ message: "a citation must carry the excerpt it is evidence for",
179
+ retryable: false,
180
+ });
181
+ };
182
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Prompt assembly & budgeting — `docs/03-intelligence-runtime.md` → Prompt assembly.
3
+ *
4
+ * Turns the sections gathered from context providers into a budgeted, previewable prompt. Each
5
+ * section draws from an explicit budget bucket (base policy, user/app context, tools, skills,
6
+ * knowledge, history) rather than one undifferentiated window. When the prompt exceeds the model's
7
+ * limit, sections are pruned in a fixed order — old reasoning, old tool detail, old knowledge, old
8
+ * turns — while recent semantic turns and open tool continuity (sections with no `pruneStage`) are
9
+ * preserved. Base policy is never pruned: if it cannot fit, assembly fails loudly rather than
10
+ * silently dropping critical instructions.
11
+ */
12
+ import type { ExecutionContext } from "../core/context.js";
13
+ import { PRUNE_ORDER } from "./index.js";
14
+ import { type ContextBudget, type ContextKind, type ContextProvider, type ContextSection, type PromptPreview } from "./index.js";
15
+ /** Gather sections from every provider, in provider order. Providers that fail are surfaced, not hidden. */
16
+ export declare const gatherSections: (context: ExecutionContext, providers: readonly ContextProvider[]) => Promise<readonly ContextSection[]>;
17
+ export type AssembledPrompt = {
18
+ /** Included sections, highest priority first within each bucket. */
19
+ readonly sections: readonly ContextSection[];
20
+ readonly preview: PromptPreview;
21
+ readonly totalTokens: number;
22
+ /**
23
+ * The model's hard input limit this prompt was assembled against — #168.
24
+ *
25
+ * Echoed back rather than left to the caller to remember. It is the denominator of every useful question about
26
+ * a prompt — how full is the window, how much is left, is this turn near the edge — and a caller holding the
27
+ * numerator while the limit lives somewhere else is a caller computing utilization against the wrong model the
28
+ * first time a policy resolves a different one.
29
+ */
30
+ readonly modelContextTokens: number;
31
+ /** Sections dropped, with why — for observability and the context inspector. */
32
+ readonly pruned: readonly {
33
+ readonly section: ContextSection;
34
+ readonly reason: "bucket-overflow" | PromptPruneStage;
35
+ }[];
36
+ };
37
+ type PromptPruneStage = (typeof PRUNE_ORDER)[number];
38
+ /**
39
+ * Assemble a budgeted prompt from already-gathered sections. Pure and deterministic, so composition
40
+ * is previewable: the returned `preview` lists every section with its token estimate and whether it
41
+ * was included. `modelContextTokens` is the hard input limit the assembled prompt must fit within.
42
+ */
43
+ export declare const assemblePrompt: (input: {
44
+ readonly sections: readonly ContextSection[];
45
+ readonly budget: ContextBudget;
46
+ readonly modelContextTokens: number;
47
+ }) => AssembledPrompt;
48
+ /** A section's inspector view — enough for the Context panel to explain what shaped a turn. */
49
+ export type InspectedSection = {
50
+ readonly title: string;
51
+ readonly providerId: string;
52
+ readonly kind: ContextKind;
53
+ readonly provenance: string;
54
+ readonly estimatedTokens: number;
55
+ readonly sensitivity: ContextSection["sensitivity"];
56
+ readonly included: boolean;
57
+ /** Set when the section was dropped: why. */
58
+ readonly prunedReason?: string;
59
+ };
60
+ export type ContextInspection = {
61
+ readonly sections: readonly InspectedSection[];
62
+ readonly totalTokens: number;
63
+ readonly budget: ContextBudget;
64
+ /** The model's hard input limit — the denominator for utilization (#168). */
65
+ readonly modelContextTokens: number;
66
+ /**
67
+ * What is left for history and the model's reply.
68
+ *
69
+ * Derived here rather than by each client, because `max(0, limit - used)` is the kind of arithmetic that gets
70
+ * written twice and clamped once. Never negative: the assembler refuses to overflow, so a negative remainder
71
+ * would be a bug reported as a number.
72
+ */
73
+ readonly remainingTokens: number;
74
+ };
75
+ /**
76
+ * Derive the context-inspector view from an assembled prompt: every section (included and pruned)
77
+ * with its bucket, provenance and token cost — so the UI can attribute which context (and which
78
+ * memory entries, via provenance) influenced a turn, and show what was dropped and why.
79
+ */
80
+ export declare const inspectAssembledPrompt: (assembled: AssembledPrompt) => ContextInspection;
81
+ export {};
82
+ //# sourceMappingURL=assembler.d.ts.map
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Prompt assembly & budgeting — `docs/03-intelligence-runtime.md` → Prompt assembly.
3
+ *
4
+ * Turns the sections gathered from context providers into a budgeted, previewable prompt. Each
5
+ * section draws from an explicit budget bucket (base policy, user/app context, tools, skills,
6
+ * knowledge, history) rather than one undifferentiated window. When the prompt exceeds the model's
7
+ * limit, sections are pruned in a fixed order — old reasoning, old tool detail, old knowledge, old
8
+ * turns — while recent semantic turns and open tool continuity (sections with no `pruneStage`) are
9
+ * preserved. Base policy is never pruned: if it cannot fit, assembly fails loudly rather than
10
+ * silently dropping critical instructions.
11
+ */
12
+ import { AgentPlatformError } from "../core/errors.js";
13
+ import { PRUNE_ORDER } from "./index.js";
14
+ import {} from "./index.js";
15
+ const BUCKET_FIELD = {
16
+ "base-policy": "basePolicyTokens",
17
+ "user-context": "userContextTokens",
18
+ tools: "toolTokens",
19
+ skills: "skillTokens",
20
+ knowledge: "knowledgeTokens",
21
+ history: "historyTokens",
22
+ };
23
+ const kindOf = (section) => section.kind ?? "user-context";
24
+ /** Gather sections from every provider, in provider order. Providers that fail are surfaced, not hidden. */
25
+ export const gatherSections = async (context, providers) => {
26
+ const sections = [];
27
+ for (const provider of providers)
28
+ sections.push(...(await provider.provide(context)));
29
+ return sections;
30
+ };
31
+ const overflow = (message) => new AgentPlatformError({ code: "context_overflow", message, retryable: false });
32
+ /**
33
+ * Assemble a budgeted prompt from already-gathered sections. Pure and deterministic, so composition
34
+ * is previewable: the returned `preview` lists every section with its token estimate and whether it
35
+ * was included. `modelContextTokens` is the hard input limit the assembled prompt must fit within.
36
+ */
37
+ export const assemblePrompt = (input) => {
38
+ const { budget, modelContextTokens } = input;
39
+ const pruned = [];
40
+ // 1. Per-bucket budgeting: within each bucket, keep the highest-priority sections that fit.
41
+ const byKind = new Map();
42
+ for (const section of input.sections) {
43
+ const list = byKind.get(kindOf(section)) ?? [];
44
+ list.push(section);
45
+ byKind.set(kindOf(section), list);
46
+ }
47
+ let included = [];
48
+ for (const [kind, sections] of byKind) {
49
+ const limit = budget[BUCKET_FIELD[kind]];
50
+ const ordered = [...sections].sort((a, b) => b.priority - a.priority);
51
+ let used = 0;
52
+ for (const section of ordered) {
53
+ if (used + section.estimatedTokens <= limit) {
54
+ used += section.estimatedTokens;
55
+ included.push(section);
56
+ }
57
+ else if (kind === "base-policy") {
58
+ // Critical instructions must fit their budget; refuse rather than truncate.
59
+ throw overflow(`Base policy needs more than its ${limit}-token budget`);
60
+ }
61
+ else {
62
+ pruned.push({ section, reason: "bucket-overflow" });
63
+ }
64
+ }
65
+ }
66
+ // 2. Global limit: if still over the model's window, prune in the fixed stage order.
67
+ let total = included.reduce((sum, s) => sum + s.estimatedTokens, 0);
68
+ for (const stage of PRUNE_ORDER) {
69
+ if (total <= modelContextTokens)
70
+ break;
71
+ // Drop lowest-priority sections tagged for this stage first. Base policy is never eligible,
72
+ // even if a section carried a pruneStage — critical instructions are never dropped.
73
+ const eligible = included
74
+ .filter((s) => s.pruneStage === stage && s.kind !== "base-policy")
75
+ .sort((a, b) => a.priority - b.priority);
76
+ for (const section of eligible) {
77
+ if (total <= modelContextTokens)
78
+ break;
79
+ included = included.filter((s) => s !== section);
80
+ pruned.push({ section, reason: stage });
81
+ total -= section.estimatedTokens;
82
+ }
83
+ }
84
+ if (total > modelContextTokens) {
85
+ throw overflow(`Prompt needs ${total} tokens but the model allows ${modelContextTokens}, and nothing further is prunable`);
86
+ }
87
+ const includedSet = new Set(included);
88
+ const preview = {
89
+ sections: input.sections.map((s) => ({
90
+ title: s.title,
91
+ estimatedTokens: s.estimatedTokens,
92
+ included: includedSet.has(s),
93
+ })),
94
+ totalTokens: total,
95
+ budget,
96
+ };
97
+ return { sections: included, preview, totalTokens: total, pruned, modelContextTokens };
98
+ };
99
+ /**
100
+ * Derive the context-inspector view from an assembled prompt: every section (included and pruned)
101
+ * with its bucket, provenance and token cost — so the UI can attribute which context (and which
102
+ * memory entries, via provenance) influenced a turn, and show what was dropped and why.
103
+ */
104
+ export const inspectAssembledPrompt = (assembled) => {
105
+ const prunedReason = new Map(assembled.pruned.map((p) => [p.section, p.reason]));
106
+ const view = (section, included) => ({
107
+ title: section.title,
108
+ providerId: section.providerId,
109
+ kind: section.kind ?? "user-context",
110
+ provenance: section.provenance,
111
+ estimatedTokens: section.estimatedTokens,
112
+ sensitivity: section.sensitivity,
113
+ included,
114
+ ...(prunedReason.has(section) ? { prunedReason: prunedReason.get(section) } : {}),
115
+ });
116
+ return {
117
+ sections: [
118
+ ...assembled.sections.map((s) => view(s, true)),
119
+ ...assembled.pruned.map((p) => view(p.section, false)),
120
+ ],
121
+ totalTokens: assembled.totalTokens,
122
+ budget: assembled.preview.budget,
123
+ modelContextTokens: assembled.modelContextTokens,
124
+ // Clamped at zero. The assembler refuses to overflow, so a negative remainder would be a bug reported as a
125
+ // number — and a UI drawing a negative bar is a UI nobody believes again.
126
+ remainingTokens: Math.max(0, assembled.modelContextTokens - assembled.totalTokens),
127
+ };
128
+ };
129
+ //# sourceMappingURL=assembler.js.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Long-thread compaction — `docs/13-sessions-and-threads.md` → Long-thread compaction.
3
+ *
4
+ * When a thread's history outgrows the context budget, older turns are compacted into a durable,
5
+ * versioned thread summary rather than dropped. Recent turns and open tool continuity are preserved
6
+ * verbatim; only the older prefix is summarized. Compaction emits the `context.compacted` transport
7
+ * event so a client can show that history was condensed. The summarizer itself is injected, so this
8
+ * stays provider-neutral.
9
+ */
10
+ import type { Message } from "../core/content-parts.js";
11
+ import type { ConversationId, TenantId } from "../core/ids.js";
12
+ import type { ThreadSummary, ThreadSummaryStore } from "../persistence/index.js";
13
+ import type { ContextCompactedEvent } from "../core/events.js";
14
+ /** Produces the condensed text for a batch of older messages, layering on any prior summary. */
15
+ export interface ThreadSummarizer {
16
+ summarize(input: {
17
+ priorSummary?: string;
18
+ messages: readonly Message[];
19
+ }): Promise<string>;
20
+ }
21
+ export type CompactionResult = {
22
+ readonly summary: ThreadSummary;
23
+ /** Recent turns kept verbatim — these plus the summary feed the next prompt. */
24
+ readonly kept: readonly Message[];
25
+ /** The transport event to publish (worker stamps runId/sequence/occurredAt). */
26
+ readonly event: Omit<ContextCompactedEvent, "runId" | "sequence" | "occurredAt">;
27
+ };
28
+ /**
29
+ * Compact a thread's history. Returns null when there is nothing worth compacting (history at or
30
+ * under `keepRecent`, or no older messages survive the tool-continuity split). Otherwise summarizes
31
+ * the older prefix, appends a versioned `ThreadSummary`, and reports what was reclaimed.
32
+ */
33
+ export declare const compactThread: (input: {
34
+ readonly tenantId: TenantId;
35
+ readonly conversationId: ConversationId;
36
+ /** Full history, oldest first. */
37
+ readonly messages: readonly Message[];
38
+ /** How many trailing messages to keep verbatim. */
39
+ readonly keepRecent: number;
40
+ readonly summaries: ThreadSummaryStore;
41
+ readonly summarizer: ThreadSummarizer;
42
+ /** Token estimate for a set of messages, used to report tokensReclaimed. */
43
+ readonly estimateTokens: (messages: readonly Message[]) => number;
44
+ }) => Promise<CompactionResult | null>;
45
+ //# sourceMappingURL=compaction.d.ts.map
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Long-thread compaction — `docs/13-sessions-and-threads.md` → Long-thread compaction.
3
+ *
4
+ * When a thread's history outgrows the context budget, older turns are compacted into a durable,
5
+ * versioned thread summary rather than dropped. Recent turns and open tool continuity are preserved
6
+ * verbatim; only the older prefix is summarized. Compaction emits the `context.compacted` transport
7
+ * event so a client can show that history was condensed. The summarizer itself is injected, so this
8
+ * stays provider-neutral.
9
+ */
10
+ import { estimateTokens } from "../core/tokens.js";
11
+ const partCount = (messages) => messages.reduce((sum, m) => sum + m.parts.length, 0);
12
+ /**
13
+ * Choose the split so the kept (recent) side never *starts* with a dangling tool result whose
14
+ * tool-call would be summarized away. Walk the boundary earlier while the first kept message is a
15
+ * tool message, preserving tool-call ↔ tool-result continuity.
16
+ */
17
+ const splitPreservingToolContinuity = (messages, keepRecent) => {
18
+ let boundary = Math.max(0, messages.length - keepRecent);
19
+ while (boundary > 0 && messages[boundary]?.role === "tool")
20
+ boundary -= 1;
21
+ return { older: messages.slice(0, boundary), recent: messages.slice(boundary) };
22
+ };
23
+ /**
24
+ * Compact a thread's history. Returns null when there is nothing worth compacting (history at or
25
+ * under `keepRecent`, or no older messages survive the tool-continuity split). Otherwise summarizes
26
+ * the older prefix, appends a versioned `ThreadSummary`, and reports what was reclaimed.
27
+ */
28
+ export const compactThread = async (input) => {
29
+ if (input.messages.length <= input.keepRecent)
30
+ return null;
31
+ const { older, recent } = splitPreservingToolContinuity(input.messages, input.keepRecent);
32
+ if (older.length === 0)
33
+ return null;
34
+ const prior = await input.summaries.latest({ tenantId: input.tenantId, conversationId: input.conversationId });
35
+ const text = await input.summarizer.summarize({
36
+ ...(prior ? { priorSummary: prior.summary } : {}),
37
+ messages: older,
38
+ });
39
+ const coversUpToMessageId = older[older.length - 1].id;
40
+ const summary = await input.summaries.append({
41
+ tenantId: input.tenantId,
42
+ conversationId: input.conversationId,
43
+ summary: text,
44
+ coversUpToMessageId,
45
+ });
46
+ // Tokens saved by replacing the older messages with the (smaller) summary text.
47
+ const summaryTokens = estimateTokens(text);
48
+ const tokensReclaimed = Math.max(0, input.estimateTokens(older) - summaryTokens);
49
+ return {
50
+ summary,
51
+ kept: recent,
52
+ event: { type: "context.compacted", droppedParts: partCount(older), tokensReclaimed },
53
+ };
54
+ };
55
+ //# sourceMappingURL=compaction.js.map
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Context providers and prompt budgeting — `docs/03-intelligence-runtime.md`.
3
+ */
4
+ import type { ExecutionContext } from "../core/context.js";
5
+ import type { ContextOrigin } from "../security/prompt-safety.js";
6
+ export type ContextSensitivity = "public" | "internal" | "confidential" | "restricted";
7
+ /** Budget bucket a section draws from. Mirrors the fields of `ContextBudget`. */
8
+ export type ContextKind = "base-policy" | "user-context" | "tools" | "skills" | "knowledge" | "history";
9
+ export type ContextSection = {
10
+ readonly providerId: string;
11
+ readonly title: string;
12
+ readonly body: string;
13
+ /** Higher priority survives pruning longer. */
14
+ readonly priority: number;
15
+ readonly estimatedTokens: number;
16
+ /** Where this came from, so a claim in the output can be traced back. */
17
+ readonly provenance: string;
18
+ readonly sensitivity: ContextSensitivity;
19
+ /**
20
+ * Whether this content may instruct the agent (#145, AC-4).
21
+ *
22
+ * **Required, with no default.** A provider has to decide, so "nobody thought about it" is a compile error
23
+ * rather than external content quietly reaching the system prompt as instruction.
24
+ *
25
+ * Not the same as `sensitivity`, and the difference matters in the worst direction. Sensitivity is
26
+ * *confidentiality* — who may see this. Origin is *provenance* — may this instruct. A page fetched off the
27
+ * public web is `public` sensitivity and the least trustworthy content in the system.
28
+ *
29
+ * `external` content is rendered inside a delimited envelope with delimiter forgery neutralised; see
30
+ * `security/prompt-safety.ts`. A `platform` section that *interpolates* untrusted values — a filename, a tool
31
+ * name, a user-supplied label — stays `platform` and neutralises those values itself, so the section's own
32
+ * instructions are not swallowed by an envelope that says nothing inside it is an instruction.
33
+ */
34
+ readonly origin: ContextOrigin;
35
+ readonly cacheable: boolean;
36
+ readonly expiresAt?: string;
37
+ /** Budget bucket. Defaults to `user-context` when a provider does not specify one. */
38
+ readonly kind?: ContextKind;
39
+ /** When set, this section is eligible for pruning in that stage. Unset ⇒ preserved (recent turns,
40
+ * open tool continuity, base policy). */
41
+ readonly pruneStage?: PruneStage;
42
+ };
43
+ export interface ContextProvider {
44
+ readonly id: string;
45
+ provide(context: ExecutionContext): Promise<readonly ContextSection[]>;
46
+ }
47
+ /** Explicit per-section budgets rather than one undifferentiated window. */
48
+ export type ContextBudget = {
49
+ readonly basePolicyTokens: number;
50
+ readonly userContextTokens: number;
51
+ readonly toolTokens: number;
52
+ readonly skillTokens: number;
53
+ readonly knowledgeTokens: number;
54
+ readonly historyTokens: number;
55
+ };
56
+ /**
57
+ * Pruning order. Old reasoning and tool detail go first; recent semantic turns and tool
58
+ * continuity are preserved. If the prompt still will not fit, assembly fails loudly
59
+ * rather than silently truncating critical instructions.
60
+ */
61
+ export declare const PRUNE_ORDER: readonly ["old-reasoning", "old-tool-detail", "old-knowledge", "old-turns"];
62
+ export type PruneStage = (typeof PRUNE_ORDER)[number];
63
+ /** Per-section token estimates, so prompt composition is previewable. */
64
+ export type PromptPreview = {
65
+ readonly sections: readonly {
66
+ readonly title: string;
67
+ readonly estimatedTokens: number;
68
+ readonly included: boolean;
69
+ }[];
70
+ readonly totalTokens: number;
71
+ readonly budget: ContextBudget;
72
+ };
73
+ export * from "./assembler.js";
74
+ export * from "./compaction.js";
75
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Context providers and prompt budgeting — `docs/03-intelligence-runtime.md`.
3
+ */
4
+ /**
5
+ * Pruning order. Old reasoning and tool detail go first; recent semantic turns and tool
6
+ * continuity are preserved. If the prompt still will not fit, assembly fails loudly
7
+ * rather than silently truncating critical instructions.
8
+ */
9
+ export const PRUNE_ORDER = [
10
+ "old-reasoning",
11
+ "old-tool-detail",
12
+ "old-knowledge",
13
+ "old-turns",
14
+ ];
15
+ export * from "./assembler.js";
16
+ export * from "./compaction.js";
17
+ //# sourceMappingURL=index.js.map