@animus-labs/cortex 0.2.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 (293) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -0
  3. package/dist/budget-guard.d.ts +75 -0
  4. package/dist/budget-guard.d.ts.map +1 -0
  5. package/dist/budget-guard.js +142 -0
  6. package/dist/budget-guard.js.map +1 -0
  7. package/dist/compaction/compaction.d.ts +99 -0
  8. package/dist/compaction/compaction.d.ts.map +1 -0
  9. package/dist/compaction/compaction.js +302 -0
  10. package/dist/compaction/compaction.js.map +1 -0
  11. package/dist/compaction/failsafe.d.ts +57 -0
  12. package/dist/compaction/failsafe.d.ts.map +1 -0
  13. package/dist/compaction/failsafe.js +135 -0
  14. package/dist/compaction/failsafe.js.map +1 -0
  15. package/dist/compaction/index.d.ts +381 -0
  16. package/dist/compaction/index.d.ts.map +1 -0
  17. package/dist/compaction/index.js +979 -0
  18. package/dist/compaction/index.js.map +1 -0
  19. package/dist/compaction/microcompaction.d.ts +219 -0
  20. package/dist/compaction/microcompaction.d.ts.map +1 -0
  21. package/dist/compaction/microcompaction.js +536 -0
  22. package/dist/compaction/microcompaction.js.map +1 -0
  23. package/dist/compaction/observational/buffering.d.ts +225 -0
  24. package/dist/compaction/observational/buffering.d.ts.map +1 -0
  25. package/dist/compaction/observational/buffering.js +354 -0
  26. package/dist/compaction/observational/buffering.js.map +1 -0
  27. package/dist/compaction/observational/constants.d.ts +70 -0
  28. package/dist/compaction/observational/constants.d.ts.map +1 -0
  29. package/dist/compaction/observational/constants.js +507 -0
  30. package/dist/compaction/observational/constants.js.map +1 -0
  31. package/dist/compaction/observational/index.d.ts +219 -0
  32. package/dist/compaction/observational/index.d.ts.map +1 -0
  33. package/dist/compaction/observational/index.js +641 -0
  34. package/dist/compaction/observational/index.js.map +1 -0
  35. package/dist/compaction/observational/observer.d.ts +97 -0
  36. package/dist/compaction/observational/observer.d.ts.map +1 -0
  37. package/dist/compaction/observational/observer.js +424 -0
  38. package/dist/compaction/observational/observer.js.map +1 -0
  39. package/dist/compaction/observational/recall-tool.d.ts +27 -0
  40. package/dist/compaction/observational/recall-tool.d.ts.map +1 -0
  41. package/dist/compaction/observational/recall-tool.js +93 -0
  42. package/dist/compaction/observational/recall-tool.js.map +1 -0
  43. package/dist/compaction/observational/reflector.d.ts +94 -0
  44. package/dist/compaction/observational/reflector.d.ts.map +1 -0
  45. package/dist/compaction/observational/reflector.js +167 -0
  46. package/dist/compaction/observational/reflector.js.map +1 -0
  47. package/dist/compaction/observational/types.d.ts +271 -0
  48. package/dist/compaction/observational/types.d.ts.map +1 -0
  49. package/dist/compaction/observational/types.js +15 -0
  50. package/dist/compaction/observational/types.js.map +1 -0
  51. package/dist/context-manager.d.ts +134 -0
  52. package/dist/context-manager.d.ts.map +1 -0
  53. package/dist/context-manager.js +170 -0
  54. package/dist/context-manager.js.map +1 -0
  55. package/dist/cortex-agent.d.ts +1020 -0
  56. package/dist/cortex-agent.d.ts.map +1 -0
  57. package/dist/cortex-agent.js +3589 -0
  58. package/dist/cortex-agent.js.map +1 -0
  59. package/dist/error-classifier.d.ts +48 -0
  60. package/dist/error-classifier.d.ts.map +1 -0
  61. package/dist/error-classifier.js +152 -0
  62. package/dist/error-classifier.js.map +1 -0
  63. package/dist/event-bridge.d.ts +166 -0
  64. package/dist/event-bridge.d.ts.map +1 -0
  65. package/dist/event-bridge.js +381 -0
  66. package/dist/event-bridge.js.map +1 -0
  67. package/dist/index.d.ts +55 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +57 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/mcp-client.d.ts +119 -0
  72. package/dist/mcp-client.d.ts.map +1 -0
  73. package/dist/mcp-client.js +474 -0
  74. package/dist/mcp-client.js.map +1 -0
  75. package/dist/model-wrapper.d.ts +58 -0
  76. package/dist/model-wrapper.d.ts.map +1 -0
  77. package/dist/model-wrapper.js +86 -0
  78. package/dist/model-wrapper.js.map +1 -0
  79. package/dist/noop-logger.d.ts +4 -0
  80. package/dist/noop-logger.d.ts.map +1 -0
  81. package/dist/noop-logger.js +8 -0
  82. package/dist/noop-logger.js.map +1 -0
  83. package/dist/prompt-diagnostics.d.ts +47 -0
  84. package/dist/prompt-diagnostics.d.ts.map +1 -0
  85. package/dist/prompt-diagnostics.js +230 -0
  86. package/dist/prompt-diagnostics.js.map +1 -0
  87. package/dist/provider-manager.d.ts +224 -0
  88. package/dist/provider-manager.d.ts.map +1 -0
  89. package/dist/provider-manager.js +563 -0
  90. package/dist/provider-manager.js.map +1 -0
  91. package/dist/provider-registry.d.ts +115 -0
  92. package/dist/provider-registry.d.ts.map +1 -0
  93. package/dist/provider-registry.js +305 -0
  94. package/dist/provider-registry.js.map +1 -0
  95. package/dist/schema-converter.d.ts +20 -0
  96. package/dist/schema-converter.d.ts.map +1 -0
  97. package/dist/schema-converter.js +48 -0
  98. package/dist/schema-converter.js.map +1 -0
  99. package/dist/skill-preprocessor.d.ts +46 -0
  100. package/dist/skill-preprocessor.d.ts.map +1 -0
  101. package/dist/skill-preprocessor.js +237 -0
  102. package/dist/skill-preprocessor.js.map +1 -0
  103. package/dist/skill-registry.d.ts +107 -0
  104. package/dist/skill-registry.d.ts.map +1 -0
  105. package/dist/skill-registry.js +330 -0
  106. package/dist/skill-registry.js.map +1 -0
  107. package/dist/skill-tool.d.ts +54 -0
  108. package/dist/skill-tool.d.ts.map +1 -0
  109. package/dist/skill-tool.js +88 -0
  110. package/dist/skill-tool.js.map +1 -0
  111. package/dist/sub-agent-manager.d.ts +90 -0
  112. package/dist/sub-agent-manager.d.ts.map +1 -0
  113. package/dist/sub-agent-manager.js +192 -0
  114. package/dist/sub-agent-manager.js.map +1 -0
  115. package/dist/token-estimator.d.ts +23 -0
  116. package/dist/token-estimator.d.ts.map +1 -0
  117. package/dist/token-estimator.js +27 -0
  118. package/dist/token-estimator.js.map +1 -0
  119. package/dist/tool-contract.d.ts +68 -0
  120. package/dist/tool-contract.d.ts.map +1 -0
  121. package/dist/tool-contract.js +35 -0
  122. package/dist/tool-contract.js.map +1 -0
  123. package/dist/tool-result-persistence.d.ts +89 -0
  124. package/dist/tool-result-persistence.d.ts.map +1 -0
  125. package/dist/tool-result-persistence.js +152 -0
  126. package/dist/tool-result-persistence.js.map +1 -0
  127. package/dist/tools/bash/index.d.ts +71 -0
  128. package/dist/tools/bash/index.d.ts.map +1 -0
  129. package/dist/tools/bash/index.js +485 -0
  130. package/dist/tools/bash/index.js.map +1 -0
  131. package/dist/tools/bash/interactive.d.ts +47 -0
  132. package/dist/tools/bash/interactive.d.ts.map +1 -0
  133. package/dist/tools/bash/interactive.js +262 -0
  134. package/dist/tools/bash/interactive.js.map +1 -0
  135. package/dist/tools/bash/safety.d.ts +149 -0
  136. package/dist/tools/bash/safety.d.ts.map +1 -0
  137. package/dist/tools/bash/safety.js +1116 -0
  138. package/dist/tools/bash/safety.js.map +1 -0
  139. package/dist/tools/edit.d.ts +57 -0
  140. package/dist/tools/edit.d.ts.map +1 -0
  141. package/dist/tools/edit.js +310 -0
  142. package/dist/tools/edit.js.map +1 -0
  143. package/dist/tools/glob.d.ts +34 -0
  144. package/dist/tools/glob.d.ts.map +1 -0
  145. package/dist/tools/glob.js +268 -0
  146. package/dist/tools/glob.js.map +1 -0
  147. package/dist/tools/grep.d.ts +53 -0
  148. package/dist/tools/grep.d.ts.map +1 -0
  149. package/dist/tools/grep.js +673 -0
  150. package/dist/tools/grep.js.map +1 -0
  151. package/dist/tools/index.d.ts +62 -0
  152. package/dist/tools/index.d.ts.map +1 -0
  153. package/dist/tools/index.js +52 -0
  154. package/dist/tools/index.js.map +1 -0
  155. package/dist/tools/read.d.ts +43 -0
  156. package/dist/tools/read.d.ts.map +1 -0
  157. package/dist/tools/read.js +459 -0
  158. package/dist/tools/read.js.map +1 -0
  159. package/dist/tools/runtime.d.ts +62 -0
  160. package/dist/tools/runtime.d.ts.map +1 -0
  161. package/dist/tools/runtime.js +116 -0
  162. package/dist/tools/runtime.js.map +1 -0
  163. package/dist/tools/shared/cwd-tracker.d.ts +32 -0
  164. package/dist/tools/shared/cwd-tracker.d.ts.map +1 -0
  165. package/dist/tools/shared/cwd-tracker.js +44 -0
  166. package/dist/tools/shared/cwd-tracker.js.map +1 -0
  167. package/dist/tools/shared/edit-history.d.ts +55 -0
  168. package/dist/tools/shared/edit-history.d.ts.map +1 -0
  169. package/dist/tools/shared/edit-history.js +72 -0
  170. package/dist/tools/shared/edit-history.js.map +1 -0
  171. package/dist/tools/shared/edit-matcher.d.ts +83 -0
  172. package/dist/tools/shared/edit-matcher.d.ts.map +1 -0
  173. package/dist/tools/shared/edit-matcher.js +359 -0
  174. package/dist/tools/shared/edit-matcher.js.map +1 -0
  175. package/dist/tools/shared/file-mutation-lock.d.ts +22 -0
  176. package/dist/tools/shared/file-mutation-lock.d.ts.map +1 -0
  177. package/dist/tools/shared/file-mutation-lock.js +35 -0
  178. package/dist/tools/shared/file-mutation-lock.js.map +1 -0
  179. package/dist/tools/shared/gitignore.d.ts +17 -0
  180. package/dist/tools/shared/gitignore.d.ts.map +1 -0
  181. package/dist/tools/shared/gitignore.js +59 -0
  182. package/dist/tools/shared/gitignore.js.map +1 -0
  183. package/dist/tools/shared/pdf-extractor.d.ts +96 -0
  184. package/dist/tools/shared/pdf-extractor.d.ts.map +1 -0
  185. package/dist/tools/shared/pdf-extractor.js +196 -0
  186. package/dist/tools/shared/pdf-extractor.js.map +1 -0
  187. package/dist/tools/shared/read-registry.d.ts +66 -0
  188. package/dist/tools/shared/read-registry.d.ts.map +1 -0
  189. package/dist/tools/shared/read-registry.js +65 -0
  190. package/dist/tools/shared/read-registry.js.map +1 -0
  191. package/dist/tools/shared/safe-env.d.ts +18 -0
  192. package/dist/tools/shared/safe-env.d.ts.map +1 -0
  193. package/dist/tools/shared/safe-env.js +70 -0
  194. package/dist/tools/shared/safe-env.js.map +1 -0
  195. package/dist/tools/sub-agent.d.ts +91 -0
  196. package/dist/tools/sub-agent.d.ts.map +1 -0
  197. package/dist/tools/sub-agent.js +89 -0
  198. package/dist/tools/sub-agent.js.map +1 -0
  199. package/dist/tools/task-output.d.ts +38 -0
  200. package/dist/tools/task-output.d.ts.map +1 -0
  201. package/dist/tools/task-output.js +186 -0
  202. package/dist/tools/task-output.js.map +1 -0
  203. package/dist/tools/tool-search/index.d.ts +40 -0
  204. package/dist/tools/tool-search/index.d.ts.map +1 -0
  205. package/dist/tools/tool-search/index.js +110 -0
  206. package/dist/tools/tool-search/index.js.map +1 -0
  207. package/dist/tools/tool-search/registry.d.ts +82 -0
  208. package/dist/tools/tool-search/registry.d.ts.map +1 -0
  209. package/dist/tools/tool-search/registry.js +238 -0
  210. package/dist/tools/tool-search/registry.js.map +1 -0
  211. package/dist/tools/undo-edit.d.ts +51 -0
  212. package/dist/tools/undo-edit.d.ts.map +1 -0
  213. package/dist/tools/undo-edit.js +231 -0
  214. package/dist/tools/undo-edit.js.map +1 -0
  215. package/dist/tools/web-fetch/cache.d.ts +49 -0
  216. package/dist/tools/web-fetch/cache.d.ts.map +1 -0
  217. package/dist/tools/web-fetch/cache.js +89 -0
  218. package/dist/tools/web-fetch/cache.js.map +1 -0
  219. package/dist/tools/web-fetch/index.d.ts +53 -0
  220. package/dist/tools/web-fetch/index.d.ts.map +1 -0
  221. package/dist/tools/web-fetch/index.js +513 -0
  222. package/dist/tools/web-fetch/index.js.map +1 -0
  223. package/dist/tools/write.d.ts +59 -0
  224. package/dist/tools/write.d.ts.map +1 -0
  225. package/dist/tools/write.js +316 -0
  226. package/dist/tools/write.js.map +1 -0
  227. package/dist/types.d.ts +881 -0
  228. package/dist/types.d.ts.map +1 -0
  229. package/dist/types.js +16 -0
  230. package/dist/types.js.map +1 -0
  231. package/dist/working-tags.d.ts +44 -0
  232. package/dist/working-tags.d.ts.map +1 -0
  233. package/dist/working-tags.js +103 -0
  234. package/dist/working-tags.js.map +1 -0
  235. package/package.json +87 -0
  236. package/src/budget-guard.ts +170 -0
  237. package/src/compaction/compaction.ts +386 -0
  238. package/src/compaction/failsafe.ts +185 -0
  239. package/src/compaction/index.ts +1199 -0
  240. package/src/compaction/microcompaction.ts +709 -0
  241. package/src/compaction/observational/buffering.ts +430 -0
  242. package/src/compaction/observational/constants.ts +532 -0
  243. package/src/compaction/observational/index.ts +837 -0
  244. package/src/compaction/observational/observer.ts +510 -0
  245. package/src/compaction/observational/recall-tool.ts +130 -0
  246. package/src/compaction/observational/reflector.ts +221 -0
  247. package/src/compaction/observational/types.ts +343 -0
  248. package/src/context-manager.ts +237 -0
  249. package/src/cortex-agent.ts +4297 -0
  250. package/src/error-classifier.ts +199 -0
  251. package/src/event-bridge.ts +508 -0
  252. package/src/index.ts +292 -0
  253. package/src/mcp-client.ts +582 -0
  254. package/src/model-wrapper.ts +128 -0
  255. package/src/noop-logger.ts +9 -0
  256. package/src/prompt-diagnostics.ts +296 -0
  257. package/src/provider-manager.ts +823 -0
  258. package/src/provider-registry.ts +386 -0
  259. package/src/schema-converter.ts +51 -0
  260. package/src/skill-preprocessor.ts +314 -0
  261. package/src/skill-registry.ts +378 -0
  262. package/src/skill-tool.ts +130 -0
  263. package/src/sub-agent-manager.ts +236 -0
  264. package/src/token-estimator.ts +26 -0
  265. package/src/tool-contract.ts +113 -0
  266. package/src/tool-result-persistence.ts +197 -0
  267. package/src/tools/bash/index.ts +633 -0
  268. package/src/tools/bash/interactive.ts +302 -0
  269. package/src/tools/bash/safety.ts +1297 -0
  270. package/src/tools/edit.ts +422 -0
  271. package/src/tools/glob.ts +330 -0
  272. package/src/tools/grep.ts +819 -0
  273. package/src/tools/index.ts +110 -0
  274. package/src/tools/read.ts +580 -0
  275. package/src/tools/runtime.ts +173 -0
  276. package/src/tools/shared/cwd-tracker.ts +50 -0
  277. package/src/tools/shared/edit-history.ts +96 -0
  278. package/src/tools/shared/edit-matcher.ts +457 -0
  279. package/src/tools/shared/file-mutation-lock.ts +40 -0
  280. package/src/tools/shared/gitignore.ts +61 -0
  281. package/src/tools/shared/pdf-extractor.ts +290 -0
  282. package/src/tools/shared/read-registry.ts +93 -0
  283. package/src/tools/shared/safe-env.ts +82 -0
  284. package/src/tools/sub-agent.ts +171 -0
  285. package/src/tools/task-output.ts +236 -0
  286. package/src/tools/tool-search/index.ts +167 -0
  287. package/src/tools/tool-search/registry.ts +278 -0
  288. package/src/tools/undo-edit.ts +314 -0
  289. package/src/tools/web-fetch/cache.ts +112 -0
  290. package/src/tools/web-fetch/index.ts +604 -0
  291. package/src/tools/write.ts +385 -0
  292. package/src/types.ts +1057 -0
  293. package/src/working-tags.ts +118 -0
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Buffering coordinator for the observational memory system.
3
+ *
4
+ * Manages the async lifecycle of observer and reflector operations,
5
+ * ensuring at-most-one-in-flight per operation type, computing dynamic
6
+ * buffer intervals, and handling abort/cleanup.
7
+ *
8
+ * The coordinator does not own the observation slot or conversation
9
+ * history. It produces observation chunks and buffered reflections that
10
+ * the ObservationalMemoryEngine consumes during activation.
11
+ *
12
+ * References:
13
+ * - observational-memory-architecture.md (Observer System, Reflector System)
14
+ * - observer.ts (runObserver)
15
+ * - reflector.ts (runReflector)
16
+ */
17
+ import type { CompleteFn } from '../compaction.js';
18
+ import type { AgentMessage } from '../../context-manager.js';
19
+ import type { ObservationChunk } from './types.js';
20
+ /**
21
+ * Coordinates async observer and reflector operations for the
22
+ * observational memory system.
23
+ *
24
+ * Ensures at-most-one observer and at-most-one reflector call are
25
+ * in-flight at any time. Completed observer results are stored as
26
+ * {@link ObservationChunk}s until the engine activates them. Completed
27
+ * reflector results are stored until the engine swaps them in.
28
+ *
29
+ * All in-flight operations are fire-and-forget from the caller's
30
+ * perspective. The coordinator attaches `.then()` / `.catch()` handlers
31
+ * internally and never surfaces unhandled rejections.
32
+ */
33
+ export declare class BufferingCoordinator {
34
+ private chunks;
35
+ private bufferWatermark;
36
+ private inFlightObserver;
37
+ private inFlightObserverEndIndex;
38
+ private inFlightReflector;
39
+ private bufferedReflection;
40
+ private bufferedReflectionCompressionLevel;
41
+ private aborted;
42
+ /**
43
+ * Activation epoch. Incremented each time activation consumes chunks or
44
+ * a sync observer trims messages. In-flight observers capture the epoch
45
+ * at launch and discard their result if the epoch has changed by the time
46
+ * they complete. This prevents stale chunks from landing after sync
47
+ * activation has already processed those messages.
48
+ */
49
+ private activationEpoch;
50
+ /**
51
+ * Compute the dynamic buffer interval based on current context state.
52
+ *
53
+ * The interval targets `bufferTargetCycles` observer calls between the
54
+ * current utilization and the activation threshold. It is clamped between
55
+ * `bufferMinTokens` and `effectiveBufferCap` (the lesser of
56
+ * `bufferTokenCap` and 60% of the utility model's context window).
57
+ *
58
+ * @param tokensUntilActivation - tokens remaining before activation threshold
59
+ * @param config - buffer interval configuration
60
+ * @returns the buffer interval in tokens
61
+ */
62
+ computeBufferInterval(tokensUntilActivation: number, config: {
63
+ bufferTargetCycles: number;
64
+ bufferTokenCap: number;
65
+ bufferMinTokens: number;
66
+ utilityModelContextWindow: number;
67
+ }): number;
68
+ /**
69
+ * Check if a buffer observation should be triggered based on
70
+ * unobserved tokens.
71
+ *
72
+ * Returns true when the unobserved token count meets or exceeds the
73
+ * buffer interval, no observer call is currently in flight, and the
74
+ * coordinator has not been aborted.
75
+ *
76
+ * @param unobservedTokens - estimated tokens of messages after the buffer watermark
77
+ * @param bufferInterval - computed from {@link computeBufferInterval}
78
+ * @returns true if a buffer observation should launch
79
+ */
80
+ shouldBuffer(unobservedTokens: number, bufferInterval: number): boolean;
81
+ /**
82
+ * Launch an async observer call. Does NOT await it.
83
+ *
84
+ * Stores the in-flight promise and tracks the end index of messages
85
+ * being processed. When the observer completes, its output is converted
86
+ * to an {@link ObservationChunk} and appended to the internal chunk
87
+ * list. If the coordinator has been aborted before the observer
88
+ * completes, the result is discarded.
89
+ *
90
+ * @param complete - the LLM completion function
91
+ * @param messages - the unobserved messages to process (snapshot)
92
+ * @param endIndex - the index in conversation history where these messages end
93
+ * @param previousObservations - current observation text for context
94
+ * @param config - observer config
95
+ * @param logger - optional logger for error reporting
96
+ */
97
+ launchObserver(complete: CompleteFn, messages: AgentMessage[], endIndex: number, previousObservations: string | null, config: {
98
+ previousObserverTokens: number;
99
+ observerInstruction?: string;
100
+ }, logger?: {
101
+ warn: (msg: string) => void;
102
+ }): void;
103
+ /**
104
+ * Check if there are completed buffer chunks ready for activation.
105
+ */
106
+ hasCompletedChunks(): boolean;
107
+ /**
108
+ * Get all completed chunks and the watermark up to which messages
109
+ * are covered.
110
+ *
111
+ * Does NOT clear state. Call {@link commitActivation} after
112
+ * successfully activating.
113
+ */
114
+ getCompletedChunks(): {
115
+ chunks: ObservationChunk[];
116
+ watermark: number;
117
+ };
118
+ /**
119
+ * Called after successful activation to reset buffer state.
120
+ *
121
+ * Clears accumulated chunks and resets the watermark to 0 since the
122
+ * messages it pointed to have been removed from the conversation
123
+ * history.
124
+ */
125
+ commitActivation(): void;
126
+ /**
127
+ * Check if reflection should be triggered based on observation token count.
128
+ *
129
+ * Returns:
130
+ * - `'sync'` when observation tokens are at or above the effective threshold
131
+ * (the caller decides whether to use a buffered reflection or force a sync call)
132
+ * - `'async'` when observation tokens are between the buffer activation point
133
+ * and the threshold, and no reflector is currently in flight
134
+ * - `'none'` otherwise
135
+ *
136
+ * @param observationTokens - current observation slot token count
137
+ * @param effectiveThreshold - from computeEffectiveReflectionThreshold
138
+ * @param reflectionBufferActivation - fraction at which to start async reflection
139
+ * @returns action indicator
140
+ */
141
+ shouldReflect(observationTokens: number, effectiveThreshold: number, reflectionBufferActivation: number): 'none' | 'async' | 'sync';
142
+ /**
143
+ * Launch an async reflector call. Does NOT await it.
144
+ *
145
+ * When the reflector completes, its result is stored in
146
+ * `bufferedReflection` for later consumption via
147
+ * {@link consumeBufferedReflection}. If the coordinator has been
148
+ * aborted before the reflector completes, the result is discarded.
149
+ *
150
+ * @param complete - the LLM completion function
151
+ * @param observations - the current observation text to consolidate
152
+ * @param config - reflector config
153
+ * @param logger - optional logger for error reporting
154
+ */
155
+ launchReflector(complete: CompleteFn, observations: string, config: {
156
+ reflectionThreshold: number;
157
+ reflectorInstruction?: string;
158
+ }, logger?: {
159
+ warn: (msg: string) => void;
160
+ }): void;
161
+ /**
162
+ * Check if a buffered reflection is ready to swap in.
163
+ */
164
+ hasBufferedReflection(): boolean;
165
+ /**
166
+ * Get the buffered reflection and clear it.
167
+ *
168
+ * Returns the consolidated observations and the compression level that
169
+ * was applied, or null if no buffered reflection is available.
170
+ */
171
+ consumeBufferedReflection(): {
172
+ observations: string;
173
+ compressionLevel: number;
174
+ } | null;
175
+ /**
176
+ * Get the current state for session persistence.
177
+ *
178
+ * In-flight operations are NOT included (they are lost on session
179
+ * save). Only completed chunks and the watermark are persisted.
180
+ */
181
+ getState(): {
182
+ chunks: ObservationChunk[];
183
+ watermark: number;
184
+ };
185
+ /**
186
+ * Restore state from a previous session.
187
+ */
188
+ restoreState(state: {
189
+ chunks: ObservationChunk[];
190
+ watermark: number;
191
+ }): void;
192
+ /**
193
+ * Abort all in-flight operations. Called on agent destruction.
194
+ *
195
+ * Sets the aborted flag so that any in-flight promise handlers
196
+ * discard their results when they eventually resolve.
197
+ */
198
+ abort(): void;
199
+ /**
200
+ * Whether an observer call is currently in flight.
201
+ */
202
+ isObserverInFlight(): boolean;
203
+ /**
204
+ * Whether a reflector call is currently in flight.
205
+ */
206
+ isReflectorInFlight(): boolean;
207
+ /**
208
+ * Get the buffer watermark (index into conversation history marking
209
+ * where the last completed observation ended).
210
+ */
211
+ getWatermark(): number;
212
+ /**
213
+ * Set the watermark. Used during initialization or after manual
214
+ * adjustments to the conversation history.
215
+ */
216
+ setWatermark(index: number): void;
217
+ /**
218
+ * Advance the activation epoch. Called when a sync activation trims
219
+ * messages outside of the normal commitActivation() flow (e.g., the
220
+ * engine's Step 2 sync observer path). This invalidates any in-flight
221
+ * observers that were launched before the sync activation.
222
+ */
223
+ advanceEpoch(): void;
224
+ }
225
+ //# sourceMappingURL=buffering.d.ts.map
@@ -0,0 +1 @@
1
+ {"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AAO;IAI9B;;;OAGG;IACH,YAAY,IAAI,MAAM;IAItB;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjC;;;;;OAKG;IACH,YAAY,IAAI,IAAI;CAGrB"}
@@ -0,0 +1,354 @@
1
+ /**
2
+ * Buffering coordinator for the observational memory system.
3
+ *
4
+ * Manages the async lifecycle of observer and reflector operations,
5
+ * ensuring at-most-one-in-flight per operation type, computing dynamic
6
+ * buffer intervals, and handling abort/cleanup.
7
+ *
8
+ * The coordinator does not own the observation slot or conversation
9
+ * history. It produces observation chunks and buffered reflections that
10
+ * the ObservationalMemoryEngine consumes during activation.
11
+ *
12
+ * References:
13
+ * - observational-memory-architecture.md (Observer System, Reflector System)
14
+ * - observer.ts (runObserver)
15
+ * - reflector.ts (runReflector)
16
+ */
17
+ import { runObserver } from './observer.js';
18
+ import { runReflector } from './reflector.js';
19
+ import { estimateTokens } from '../../token-estimator.js';
20
+ // ---------------------------------------------------------------------------
21
+ // BufferingCoordinator
22
+ // ---------------------------------------------------------------------------
23
+ /**
24
+ * Coordinates async observer and reflector operations for the
25
+ * observational memory system.
26
+ *
27
+ * Ensures at-most-one observer and at-most-one reflector call are
28
+ * in-flight at any time. Completed observer results are stored as
29
+ * {@link ObservationChunk}s until the engine activates them. Completed
30
+ * reflector results are stored until the engine swaps them in.
31
+ *
32
+ * All in-flight operations are fire-and-forget from the caller's
33
+ * perspective. The coordinator attaches `.then()` / `.catch()` handlers
34
+ * internally and never surfaces unhandled rejections.
35
+ */
36
+ export class BufferingCoordinator {
37
+ // --- Internal state ---
38
+ chunks = [];
39
+ bufferWatermark = 0;
40
+ inFlightObserver = null;
41
+ inFlightObserverEndIndex = null;
42
+ inFlightReflector = null;
43
+ bufferedReflection = null;
44
+ bufferedReflectionCompressionLevel = 0;
45
+ aborted = false;
46
+ /**
47
+ * Activation epoch. Incremented each time activation consumes chunks or
48
+ * a sync observer trims messages. In-flight observers capture the epoch
49
+ * at launch and discard their result if the epoch has changed by the time
50
+ * they complete. This prevents stale chunks from landing after sync
51
+ * activation has already processed those messages.
52
+ */
53
+ activationEpoch = 0;
54
+ // -------------------------------------------------------------------------
55
+ // Buffer Interval Calculation
56
+ // -------------------------------------------------------------------------
57
+ /**
58
+ * Compute the dynamic buffer interval based on current context state.
59
+ *
60
+ * The interval targets `bufferTargetCycles` observer calls between the
61
+ * current utilization and the activation threshold. It is clamped between
62
+ * `bufferMinTokens` and `effectiveBufferCap` (the lesser of
63
+ * `bufferTokenCap` and 60% of the utility model's context window).
64
+ *
65
+ * @param tokensUntilActivation - tokens remaining before activation threshold
66
+ * @param config - buffer interval configuration
67
+ * @returns the buffer interval in tokens
68
+ */
69
+ computeBufferInterval(tokensUntilActivation, config) {
70
+ const effectiveBufferCap = Math.min(config.bufferTokenCap, config.utilityModelContextWindow * 0.6);
71
+ const dynamicInterval = tokensUntilActivation / config.bufferTargetCycles;
72
+ return Math.max(Math.min(dynamicInterval, effectiveBufferCap), config.bufferMinTokens);
73
+ }
74
+ // -------------------------------------------------------------------------
75
+ // Observer Buffering
76
+ // -------------------------------------------------------------------------
77
+ /**
78
+ * Check if a buffer observation should be triggered based on
79
+ * unobserved tokens.
80
+ *
81
+ * Returns true when the unobserved token count meets or exceeds the
82
+ * buffer interval, no observer call is currently in flight, and the
83
+ * coordinator has not been aborted.
84
+ *
85
+ * @param unobservedTokens - estimated tokens of messages after the buffer watermark
86
+ * @param bufferInterval - computed from {@link computeBufferInterval}
87
+ * @returns true if a buffer observation should launch
88
+ */
89
+ shouldBuffer(unobservedTokens, bufferInterval) {
90
+ return (unobservedTokens >= bufferInterval &&
91
+ !this.isObserverInFlight() &&
92
+ !this.aborted);
93
+ }
94
+ /**
95
+ * Launch an async observer call. Does NOT await it.
96
+ *
97
+ * Stores the in-flight promise and tracks the end index of messages
98
+ * being processed. When the observer completes, its output is converted
99
+ * to an {@link ObservationChunk} and appended to the internal chunk
100
+ * list. If the coordinator has been aborted before the observer
101
+ * completes, the result is discarded.
102
+ *
103
+ * @param complete - the LLM completion function
104
+ * @param messages - the unobserved messages to process (snapshot)
105
+ * @param endIndex - the index in conversation history where these messages end
106
+ * @param previousObservations - current observation text for context
107
+ * @param config - observer config
108
+ * @param logger - optional logger for error reporting
109
+ */
110
+ launchObserver(complete, messages, endIndex, previousObservations, config, logger) {
111
+ if (this.aborted)
112
+ return;
113
+ // Estimate tokens from the message snapshot for the chunk metadata
114
+ const messageTokensObserved = messages.reduce((sum, msg) => {
115
+ if (typeof msg.content === 'string') {
116
+ return sum + estimateTokens(msg.content);
117
+ }
118
+ if (Array.isArray(msg.content)) {
119
+ const text = msg.content
120
+ .map((part) => {
121
+ if (typeof part.text === 'string')
122
+ return part.text;
123
+ return JSON.stringify(part);
124
+ })
125
+ .join(' ');
126
+ return sum + estimateTokens(text);
127
+ }
128
+ return sum;
129
+ }, 0);
130
+ const promise = runObserver(complete, messages, previousObservations, config);
131
+ this.inFlightObserver = promise;
132
+ this.inFlightObserverEndIndex = endIndex;
133
+ // Capture the activation epoch at launch. If activation fires (sync or
134
+ // chunk-based) before this observer completes, the epoch will have
135
+ // advanced and the result is stale (those messages were already observed).
136
+ const launchEpoch = this.activationEpoch;
137
+ promise
138
+ .then((output) => {
139
+ if (this.aborted)
140
+ return;
141
+ // Discard if activation already processed these messages
142
+ if (this.activationEpoch !== launchEpoch) {
143
+ this.inFlightObserver = null;
144
+ this.inFlightObserverEndIndex = null;
145
+ return;
146
+ }
147
+ const chunk = {
148
+ observations: output.observations,
149
+ messageTokensObserved,
150
+ createdAt: new Date(),
151
+ };
152
+ if (output.currentTask) {
153
+ chunk.currentTask = output.currentTask;
154
+ }
155
+ if (output.suggestedResponse) {
156
+ chunk.suggestedResponse = output.suggestedResponse;
157
+ }
158
+ this.chunks.push(chunk);
159
+ this.bufferWatermark = this.inFlightObserverEndIndex ?? endIndex;
160
+ this.inFlightObserver = null;
161
+ this.inFlightObserverEndIndex = null;
162
+ })
163
+ .catch((err) => {
164
+ const message = err instanceof Error ? err.message : String(err);
165
+ if (logger) {
166
+ logger.warn(`Observer buffer call failed: ${message}`);
167
+ }
168
+ this.inFlightObserver = null;
169
+ this.inFlightObserverEndIndex = null;
170
+ });
171
+ }
172
+ /**
173
+ * Check if there are completed buffer chunks ready for activation.
174
+ */
175
+ hasCompletedChunks() {
176
+ return this.chunks.length > 0;
177
+ }
178
+ /**
179
+ * Get all completed chunks and the watermark up to which messages
180
+ * are covered.
181
+ *
182
+ * Does NOT clear state. Call {@link commitActivation} after
183
+ * successfully activating.
184
+ */
185
+ getCompletedChunks() {
186
+ return { chunks: [...this.chunks], watermark: this.bufferWatermark };
187
+ }
188
+ /**
189
+ * Called after successful activation to reset buffer state.
190
+ *
191
+ * Clears accumulated chunks and resets the watermark to 0 since the
192
+ * messages it pointed to have been removed from the conversation
193
+ * history.
194
+ */
195
+ commitActivation() {
196
+ this.chunks = [];
197
+ this.bufferWatermark = 0;
198
+ this.activationEpoch++;
199
+ }
200
+ // -------------------------------------------------------------------------
201
+ // Reflector Buffering
202
+ // -------------------------------------------------------------------------
203
+ /**
204
+ * Check if reflection should be triggered based on observation token count.
205
+ *
206
+ * Returns:
207
+ * - `'sync'` when observation tokens are at or above the effective threshold
208
+ * (the caller decides whether to use a buffered reflection or force a sync call)
209
+ * - `'async'` when observation tokens are between the buffer activation point
210
+ * and the threshold, and no reflector is currently in flight
211
+ * - `'none'` otherwise
212
+ *
213
+ * @param observationTokens - current observation slot token count
214
+ * @param effectiveThreshold - from computeEffectiveReflectionThreshold
215
+ * @param reflectionBufferActivation - fraction at which to start async reflection
216
+ * @returns action indicator
217
+ */
218
+ shouldReflect(observationTokens, effectiveThreshold, reflectionBufferActivation) {
219
+ if (observationTokens >= effectiveThreshold) {
220
+ return 'sync';
221
+ }
222
+ const asyncTrigger = effectiveThreshold * reflectionBufferActivation;
223
+ if (observationTokens >= asyncTrigger &&
224
+ !this.isReflectorInFlight() &&
225
+ !this.aborted) {
226
+ return 'async';
227
+ }
228
+ return 'none';
229
+ }
230
+ /**
231
+ * Launch an async reflector call. Does NOT await it.
232
+ *
233
+ * When the reflector completes, its result is stored in
234
+ * `bufferedReflection` for later consumption via
235
+ * {@link consumeBufferedReflection}. If the coordinator has been
236
+ * aborted before the reflector completes, the result is discarded.
237
+ *
238
+ * @param complete - the LLM completion function
239
+ * @param observations - the current observation text to consolidate
240
+ * @param config - reflector config
241
+ * @param logger - optional logger for error reporting
242
+ */
243
+ launchReflector(complete, observations, config, logger) {
244
+ if (this.aborted)
245
+ return;
246
+ const promise = runReflector(complete, observations, config);
247
+ this.inFlightReflector = promise;
248
+ promise
249
+ .then((output) => {
250
+ if (this.aborted)
251
+ return;
252
+ this.bufferedReflection = output.observations;
253
+ this.bufferedReflectionCompressionLevel = output.compressionLevel;
254
+ this.inFlightReflector = null;
255
+ })
256
+ .catch((err) => {
257
+ const message = err instanceof Error ? err.message : String(err);
258
+ if (logger) {
259
+ logger.warn(`Reflector buffer call failed: ${message}`);
260
+ }
261
+ this.inFlightReflector = null;
262
+ });
263
+ }
264
+ /**
265
+ * Check if a buffered reflection is ready to swap in.
266
+ */
267
+ hasBufferedReflection() {
268
+ return this.bufferedReflection !== null;
269
+ }
270
+ /**
271
+ * Get the buffered reflection and clear it.
272
+ *
273
+ * Returns the consolidated observations and the compression level that
274
+ * was applied, or null if no buffered reflection is available.
275
+ */
276
+ consumeBufferedReflection() {
277
+ if (this.bufferedReflection === null)
278
+ return null;
279
+ const result = {
280
+ observations: this.bufferedReflection,
281
+ compressionLevel: this.bufferedReflectionCompressionLevel,
282
+ };
283
+ this.bufferedReflection = null;
284
+ this.bufferedReflectionCompressionLevel = 0;
285
+ return result;
286
+ }
287
+ // -------------------------------------------------------------------------
288
+ // Lifecycle
289
+ // -------------------------------------------------------------------------
290
+ /**
291
+ * Get the current state for session persistence.
292
+ *
293
+ * In-flight operations are NOT included (they are lost on session
294
+ * save). Only completed chunks and the watermark are persisted.
295
+ */
296
+ getState() {
297
+ return { chunks: [...this.chunks], watermark: this.bufferWatermark };
298
+ }
299
+ /**
300
+ * Restore state from a previous session.
301
+ */
302
+ restoreState(state) {
303
+ this.chunks = [...state.chunks];
304
+ this.bufferWatermark = state.watermark;
305
+ }
306
+ /**
307
+ * Abort all in-flight operations. Called on agent destruction.
308
+ *
309
+ * Sets the aborted flag so that any in-flight promise handlers
310
+ * discard their results when they eventually resolve.
311
+ */
312
+ abort() {
313
+ this.aborted = true;
314
+ this.inFlightObserver = null;
315
+ this.inFlightObserverEndIndex = null;
316
+ this.inFlightReflector = null;
317
+ }
318
+ /**
319
+ * Whether an observer call is currently in flight.
320
+ */
321
+ isObserverInFlight() {
322
+ return this.inFlightObserver !== null;
323
+ }
324
+ /**
325
+ * Whether a reflector call is currently in flight.
326
+ */
327
+ isReflectorInFlight() {
328
+ return this.inFlightReflector !== null;
329
+ }
330
+ /**
331
+ * Get the buffer watermark (index into conversation history marking
332
+ * where the last completed observation ended).
333
+ */
334
+ getWatermark() {
335
+ return this.bufferWatermark;
336
+ }
337
+ /**
338
+ * Set the watermark. Used during initialization or after manual
339
+ * adjustments to the conversation history.
340
+ */
341
+ setWatermark(index) {
342
+ this.bufferWatermark = index;
343
+ }
344
+ /**
345
+ * Advance the activation epoch. Called when a sync activation trims
346
+ * messages outside of the normal commitActivation() flow (e.g., the
347
+ * engine's Step 2 sync observer path). This invalidates any in-flight
348
+ * observers that were launched before the sync activation.
349
+ */
350
+ advanceEpoch() {
351
+ this.activationEpoch++;
352
+ }
353
+ }
354
+ //# sourceMappingURL=buffering.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffering.js","sourceRoot":"","sources":["../../../src/compaction/observational/buffering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,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