@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,641 @@
1
+ /**
2
+ * ObservationalMemoryEngine: core orchestrator for the observational memory
3
+ * system.
4
+ *
5
+ * Ties together the observer, reflector, and buffering coordinator. Manages
6
+ * the observation slot, handles activation and reflection, and exposes the
7
+ * state management API.
8
+ *
9
+ * The engine runs inside CompactionManager's transformContext hook. It does
10
+ * NOT directly call ContextManager.setSlot(); instead, it manages the slot
11
+ * content string and the integration layer handles writing it to the slot.
12
+ *
13
+ * References:
14
+ * - observational-memory-architecture.md
15
+ * - compaction-strategy.md
16
+ * - context-manager.md
17
+ */
18
+ import { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_PREAMBLE, OBSERVATION_RECALL_INSTRUCTIONS, } from './constants.js';
19
+ import { runObserver } from './observer.js';
20
+ import { runReflector, computeEffectiveReflectionThreshold } from './reflector.js';
21
+ import { BufferingCoordinator } from './buffering.js';
22
+ import { estimateTokens } from '../../token-estimator.js';
23
+ // ---------------------------------------------------------------------------
24
+ // Re-exports
25
+ // ---------------------------------------------------------------------------
26
+ export { BufferingCoordinator } from './buffering.js';
27
+ export { runObserver } from './observer.js';
28
+ export { runReflector, computeEffectiveReflectionThreshold } from './reflector.js';
29
+ export { createRecallTool } from './recall-tool.js';
30
+ // ---------------------------------------------------------------------------
31
+ // ObservationalMemoryEngine
32
+ // ---------------------------------------------------------------------------
33
+ /**
34
+ * Core orchestrator for the observational memory system.
35
+ *
36
+ * Coordinates the observer, reflector, and buffering coordinator to maintain
37
+ * a compressed observation log of the conversation. Called from
38
+ * CompactionManager during transformContext.
39
+ */
40
+ export class ObservationalMemoryEngine {
41
+ config;
42
+ buffering;
43
+ completeFn = null;
44
+ observations = '';
45
+ continuationHint = null;
46
+ observationTokenCount = 0;
47
+ generationCount = 0;
48
+ contextWindow = 0;
49
+ utilityModelContextWindow = 0;
50
+ slotIndex;
51
+ logger = null;
52
+ // Event handler arrays (method-level registration, multiple handlers)
53
+ observationHandlers = [];
54
+ reflectionHandlers = [];
55
+ constructor(config, slotIndex) {
56
+ this.slotIndex = slotIndex;
57
+ this.buffering = new BufferingCoordinator();
58
+ // Merge with defaults. Optional fields (observerInstruction,
59
+ // reflectorInstruction, recall) are only included when provided.
60
+ this.config = {
61
+ ...OBSERVATIONAL_MEMORY_DEFAULTS,
62
+ ...config,
63
+ };
64
+ }
65
+ // -------------------------------------------------------------------------
66
+ // Configuration
67
+ // -------------------------------------------------------------------------
68
+ /**
69
+ * Set the LLM completion function (wired to utilityComplete on CortexAgent).
70
+ */
71
+ setCompleteFn(fn) {
72
+ this.completeFn = fn;
73
+ }
74
+ /**
75
+ * Update the context window size.
76
+ */
77
+ setContextWindow(contextWindow) {
78
+ this.contextWindow = contextWindow;
79
+ }
80
+ /**
81
+ * Update the utility model context window (for clamps).
82
+ */
83
+ setUtilityModelContextWindow(utilityModelContextWindow) {
84
+ this.utilityModelContextWindow = utilityModelContextWindow;
85
+ }
86
+ /**
87
+ * Set the logger.
88
+ */
89
+ setLogger(logger) {
90
+ this.logger = logger;
91
+ }
92
+ // -------------------------------------------------------------------------
93
+ // Event Registration
94
+ // -------------------------------------------------------------------------
95
+ /**
96
+ * Register an observation event handler.
97
+ */
98
+ onObservation(handler) {
99
+ this.observationHandlers.push(handler);
100
+ }
101
+ /**
102
+ * Register a reflection event handler.
103
+ */
104
+ onReflection(handler) {
105
+ this.reflectionHandlers.push(handler);
106
+ }
107
+ // -------------------------------------------------------------------------
108
+ // Core: applyInTransformContext
109
+ // -------------------------------------------------------------------------
110
+ /**
111
+ * Core method called from CompactionManager during transformContext.
112
+ *
113
+ * Handles observation activation and reflection when context utilization
114
+ * exceeds the activation threshold. Updates the observation slot and
115
+ * trims observed messages from history.
116
+ *
117
+ * @param context - The AgentContext from transformContext
118
+ * @param utilization - Current total context utilization (0-1)
119
+ * @param slotCount - Number of slot messages at the start of the array
120
+ * @param getHistory - Get conversation history from the context (post-slot)
121
+ * @param setHistory - Set conversation history in the context (post-slot)
122
+ * @param getSourceHistory - Get the original transcript history (agent.state.messages post-slot)
123
+ * @param setSourceHistory - Replace the original transcript history
124
+ * @returns Modified context with updated observations and trimmed history
125
+ */
126
+ async applyInTransformContext(context, utilization, slotCount, getHistory, setHistory, getSourceHistory, setSourceHistory) {
127
+ if (utilization < this.config.activationThreshold) {
128
+ return context;
129
+ }
130
+ // --- Activation ---
131
+ const sourceHistory = getSourceHistory();
132
+ const watermark = this.buffering.getWatermark();
133
+ let compactedMessages = [];
134
+ let newObservationText = '';
135
+ let activatedSync = false;
136
+ // Step 1: Activate completed buffer chunks
137
+ if (this.buffering.hasCompletedChunks()) {
138
+ const { chunks, watermark: chunkWatermark } = this.buffering.getCompletedChunks();
139
+ const merged = this.mergeChunks(chunks);
140
+ newObservationText = merged.observations;
141
+ if (merged.hint) {
142
+ this.continuationHint = merged.hint;
143
+ }
144
+ // Messages covered by completed chunks (from start of source to watermark)
145
+ compactedMessages = sourceHistory.slice(0, chunkWatermark);
146
+ // Remove observed messages from source, keep unbuffered tail
147
+ setSourceHistory(sourceHistory.slice(chunkWatermark));
148
+ this.buffering.commitActivation();
149
+ }
150
+ // Step 2: Check if still over threshold after chunk activation
151
+ // Recompute utilization after trimming. Account for the full slot
152
+ // overhead (preamble, XML wrappers, continuation hints) rather than
153
+ // just the raw observation text, since the slot is always larger.
154
+ const postChunkSource = getSourceHistory();
155
+ const trimmedMessageTokens = estimateTokens(compactedMessages.map(m => typeof m.content === 'string' ? m.content : JSON.stringify(m.content)).join('\n'));
156
+ // Estimate the actual slot size including overhead, not just the raw
157
+ // observation text. buildSlotContent() wraps observations in the
158
+ // preamble, <observations> tags, and optional continuation hints.
159
+ const slotOverheadTokens = newObservationText
160
+ ? estimateTokens(this.buildSlotContentForEstimate(newObservationText))
161
+ : 0;
162
+ // Net change: removed messages, added observation slot content
163
+ const netTokenReduction = trimmedMessageTokens - slotOverheadTokens;
164
+ const postChunkUtilization = utilization - (this.contextWindow > 0 ? netTokenReduction / this.contextWindow : 0);
165
+ if (postChunkUtilization >= this.config.activationThreshold && this.completeFn) {
166
+ // Force sync observer on remaining unbuffered messages
167
+ const unbufferedMessages = postChunkSource;
168
+ if (unbufferedMessages.length > 0) {
169
+ activatedSync = true;
170
+ const output = await runObserver(this.completeFn, unbufferedMessages, this.observations || null, this.buildObserverConfig());
171
+ // Append sync observations
172
+ if (newObservationText) {
173
+ newObservationText += '\n\n' + output.observations;
174
+ }
175
+ else {
176
+ newObservationText = output.observations;
177
+ }
178
+ if (output.currentTask || output.suggestedResponse) {
179
+ this.continuationHint = {
180
+ currentTask: output.currentTask ?? '',
181
+ suggestedResponse: output.suggestedResponse ?? '',
182
+ };
183
+ }
184
+ // All unbuffered messages are now observed
185
+ compactedMessages = [...compactedMessages, ...unbufferedMessages];
186
+ setSourceHistory([]);
187
+ this.buffering.setWatermark(0);
188
+ // Invalidate any in-flight observers that were processing messages
189
+ // we just observed synchronously
190
+ this.buffering.advanceEpoch();
191
+ }
192
+ }
193
+ // Step 3: Merge new observations into existing
194
+ if (newObservationText) {
195
+ if (this.observations) {
196
+ this.observations += '\n\n' + newObservationText;
197
+ }
198
+ else {
199
+ this.observations = newObservationText;
200
+ }
201
+ this.observationTokenCount = estimateTokens(this.observations);
202
+ }
203
+ // Step 4: Fire observation event
204
+ if (compactedMessages.length > 0) {
205
+ this.fireObservationEvent({
206
+ compactedMessages,
207
+ observations: this.observations,
208
+ contextUtilization: utilization,
209
+ sync: activatedSync,
210
+ timestamp: new Date(),
211
+ });
212
+ }
213
+ // Step 5: Handle reflection (may replace this.observations with condensed version)
214
+ await this.handleReflection();
215
+ // Step 6: Build slot content AFTER reflection so it contains post-reflection
216
+ // observations. Previously this was captured before reflection, requiring
217
+ // an external patch in cortex-agent.ts to correct stale content.
218
+ const slotContent = this.buildSlotContent();
219
+ // Step 7: Rebuild context with updated observations and trimmed history
220
+ const updatedSourceHistory = getSourceHistory();
221
+ // Build new message array: slot region + observation slot + remaining source messages
222
+ const slotRegion = context.messages.slice(0, this.slotIndex);
223
+ const observationSlotMessage = {
224
+ role: 'user',
225
+ content: slotContent,
226
+ timestamp: Date.now(),
227
+ };
228
+ // Messages after the slot region that are not part of the observation slot
229
+ const postSlotMessages = updatedSourceHistory;
230
+ const newMessages = [
231
+ ...slotRegion,
232
+ observationSlotMessage,
233
+ ...context.messages.slice(this.slotIndex + 1, slotCount),
234
+ ...postSlotMessages,
235
+ ];
236
+ return setHistory({ ...context, messages: newMessages }, postSlotMessages);
237
+ }
238
+ // -------------------------------------------------------------------------
239
+ // Turn-end handler
240
+ // -------------------------------------------------------------------------
241
+ /**
242
+ * Called at each turn_end event. Handles async buffer triggering.
243
+ *
244
+ * Computes the dynamic buffer interval and launches an async observer
245
+ * if enough unobserved tokens have accumulated.
246
+ *
247
+ * @param totalTokens - Total tokens from the last LLM response
248
+ * @param contextWindow - Current context window size
249
+ * @param messages - Current conversation messages (post-slot)
250
+ * @param slotCount - Number of slot messages
251
+ */
252
+ onTurnEnd(totalTokens, contextWindow, messages, slotCount) {
253
+ if (!this.completeFn || contextWindow <= 0)
254
+ return;
255
+ const currentUtilization = totalTokens / contextWindow;
256
+ const tokensUntilActivation = (this.config.activationThreshold - currentUtilization) * contextWindow;
257
+ // Already past threshold, activation will handle it in transformContext
258
+ if (tokensUntilActivation <= 0)
259
+ return;
260
+ const bufferInterval = this.buffering.computeBufferInterval(tokensUntilActivation, {
261
+ bufferTargetCycles: this.config.bufferTargetCycles,
262
+ bufferTokenCap: this.config.bufferTokenCap,
263
+ bufferMinTokens: this.config.bufferMinTokens,
264
+ utilityModelContextWindow: this.utilityModelContextWindow,
265
+ });
266
+ // Skip slot messages to avoid processing them as conversation content
267
+ const history = messages.slice(slotCount);
268
+ // Compute unobserved tokens (messages after buffer watermark)
269
+ const watermark = this.buffering.getWatermark();
270
+ const unobservedMessages = history.slice(watermark);
271
+ const unobservedTokens = unobservedMessages.reduce((sum, msg) => {
272
+ const content = typeof msg.content === 'string'
273
+ ? msg.content
274
+ : JSON.stringify(msg.content);
275
+ return sum + estimateTokens(content);
276
+ }, 0);
277
+ if (this.buffering.shouldBuffer(unobservedTokens, bufferInterval)) {
278
+ // Snapshot the unobserved messages
279
+ const snapshot = [...unobservedMessages];
280
+ const endIndex = watermark + unobservedMessages.length;
281
+ this.buffering.launchObserver(this.completeFn, snapshot, endIndex, this.observations || null, this.buildObserverConfig(), this.logger ?? undefined);
282
+ }
283
+ }
284
+ // -------------------------------------------------------------------------
285
+ // Slot content
286
+ // -------------------------------------------------------------------------
287
+ /**
288
+ * Build the full observation slot content.
289
+ *
290
+ * Assembles the preamble, optional recall instructions, observation block,
291
+ * and optional continuation hints into a single string.
292
+ */
293
+ buildSlotContent() {
294
+ let content = OBSERVATION_CONTEXT_PREAMBLE;
295
+ if (this.config.recall) {
296
+ content += OBSERVATION_RECALL_INSTRUCTIONS;
297
+ }
298
+ content += '\n\n<observations>\n' + this.observations + '\n</observations>';
299
+ if (this.continuationHint) {
300
+ content += '\n\n<current-task>\n' + this.continuationHint.currentTask + '\n</current-task>';
301
+ content += '\n\n<suggested-response>\n' + this.continuationHint.suggestedResponse + '\n</suggested-response>';
302
+ }
303
+ return content;
304
+ }
305
+ /**
306
+ * Estimate the full slot content size for a given observation text.
307
+ *
308
+ * Used by the post-chunk utilization estimate to account for slot
309
+ * overhead (preamble, XML wrappers, continuation hints) rather than
310
+ * just the raw observation text.
311
+ */
312
+ buildSlotContentForEstimate(observationText) {
313
+ let content = OBSERVATION_CONTEXT_PREAMBLE;
314
+ if (this.config.recall) {
315
+ content += OBSERVATION_RECALL_INSTRUCTIONS;
316
+ }
317
+ content += '\n\n<observations>\n' + observationText + '\n</observations>';
318
+ if (this.continuationHint) {
319
+ content += '\n\n<current-task>\n' + this.continuationHint.currentTask + '\n</current-task>';
320
+ content += '\n\n<suggested-response>\n' + this.continuationHint.suggestedResponse + '\n</suggested-response>';
321
+ }
322
+ return content;
323
+ }
324
+ // -------------------------------------------------------------------------
325
+ // Manual trigger
326
+ // -------------------------------------------------------------------------
327
+ /**
328
+ * Force a synchronous observation cycle.
329
+ *
330
+ * Used by consumers after critical corrections to ensure the observation
331
+ * log captures the correction immediately.
332
+ *
333
+ * @param messages - The full message array (may include slot messages)
334
+ * @param slotCount - Number of slot messages to skip
335
+ */
336
+ async triggerObservation(messages, slotCount) {
337
+ const history = messages.slice(slotCount);
338
+ if (!this.completeFn || history.length === 0)
339
+ return;
340
+ const output = await runObserver(this.completeFn, history, this.observations || null, this.buildObserverConfig());
341
+ // Merge observations
342
+ if (this.observations) {
343
+ this.observations += '\n\n' + output.observations;
344
+ }
345
+ else {
346
+ this.observations = output.observations;
347
+ }
348
+ if (output.currentTask || output.suggestedResponse) {
349
+ this.continuationHint = {
350
+ currentTask: output.currentTask ?? '',
351
+ suggestedResponse: output.suggestedResponse ?? '',
352
+ };
353
+ }
354
+ this.observationTokenCount = estimateTokens(this.observations);
355
+ // Fire observation event
356
+ this.fireObservationEvent({
357
+ compactedMessages: history,
358
+ observations: this.observations,
359
+ contextUtilization: 0, // manual trigger, utilization unknown
360
+ sync: true,
361
+ timestamp: new Date(),
362
+ });
363
+ }
364
+ // -------------------------------------------------------------------------
365
+ // Kickstart buffer (session resumption)
366
+ // -------------------------------------------------------------------------
367
+ /**
368
+ * Kick off an initial async buffer on unobserved messages.
369
+ * Called during session resumption for a head start before the first prompt().
370
+ */
371
+ kickstartBuffer(messages, slotCount) {
372
+ if (!this.completeFn)
373
+ return;
374
+ const history = messages.slice(slotCount);
375
+ if (history.length === 0)
376
+ return;
377
+ const watermark = this.buffering.getWatermark();
378
+ const unobserved = history.slice(watermark);
379
+ if (unobserved.length === 0)
380
+ return;
381
+ const unobservedTokens = unobserved.reduce((sum, m) => sum + estimateTokens(typeof m.content === 'string' ? m.content : JSON.stringify(m.content)), 0);
382
+ if (unobservedTokens < this.config.bufferMinTokens)
383
+ return;
384
+ // Launch async observer on the unobserved messages (non-blocking)
385
+ this.buffering.launchObserver(this.completeFn, unobserved, watermark + unobserved.length, this.observations || null, this.buildObserverConfig(), this.logger ?? undefined);
386
+ }
387
+ // -------------------------------------------------------------------------
388
+ // State management
389
+ // -------------------------------------------------------------------------
390
+ /**
391
+ * Returns the current state for session persistence.
392
+ */
393
+ getState() {
394
+ return {
395
+ observations: this.observations,
396
+ continuationHint: this.continuationHint,
397
+ observationTokenCount: this.observationTokenCount,
398
+ generationCount: this.generationCount,
399
+ bufferedChunks: this.buffering.getState().chunks,
400
+ };
401
+ }
402
+ /**
403
+ * Restore state from a previous session.
404
+ *
405
+ * Sets observations, continuation hint, token count, and generation count.
406
+ * Restores buffering state. If a completeFn is available and observations
407
+ * exist, updates the slot content. Kicks off an initial async buffer on
408
+ * unobserved messages as a non-blocking head start.
409
+ */
410
+ restoreState(state) {
411
+ this.observations = state.observations;
412
+ this.continuationHint = state.continuationHint;
413
+ this.observationTokenCount = state.observationTokenCount;
414
+ this.generationCount = state.generationCount;
415
+ // Discard buffered chunks from the previous session. Chunks represent
416
+ // observations that completed async but were never activated (merged
417
+ // into this.observations + messages trimmed). Restoring them with
418
+ // watermark=0 would merge their observations without trimming any
419
+ // messages, duplicating context. The observer will re-observe
420
+ // unobserved messages naturally on the next buffer cycle.
421
+ this.buffering.restoreState({
422
+ chunks: [],
423
+ watermark: 0,
424
+ });
425
+ }
426
+ /**
427
+ * Returns the current slot content string.
428
+ */
429
+ getSlotContent() {
430
+ return this.buildSlotContent();
431
+ }
432
+ /**
433
+ * Returns just the observation text.
434
+ */
435
+ getObservations() {
436
+ return this.observations;
437
+ }
438
+ /**
439
+ * Token count of activated observations only.
440
+ */
441
+ getObservationTokenCount() {
442
+ return this.observationTokenCount;
443
+ }
444
+ /**
445
+ * Whether the observer or reflector is currently running in the background.
446
+ */
447
+ isProcessing() {
448
+ return this.buffering.isObserverInFlight() || this.buffering.isReflectorInFlight();
449
+ }
450
+ /**
451
+ * Whether the observer specifically is in-flight.
452
+ */
453
+ isObserverInFlight() {
454
+ return this.buffering.isObserverInFlight();
455
+ }
456
+ /**
457
+ * Whether the reflector specifically is in-flight.
458
+ */
459
+ isReflectorInFlight() {
460
+ return this.buffering.isReflectorInFlight();
461
+ }
462
+ /**
463
+ * Abort all in-flight operations. Delegates to buffering.abort().
464
+ */
465
+ abort() {
466
+ this.buffering.abort();
467
+ }
468
+ /**
469
+ * Whether recall is configured.
470
+ */
471
+ hasRecall() {
472
+ return this.config.recall !== undefined;
473
+ }
474
+ /**
475
+ * Get the recall config if provided.
476
+ */
477
+ getRecallConfig() {
478
+ return this.config.recall;
479
+ }
480
+ // -------------------------------------------------------------------------
481
+ // Private: Reflection handling
482
+ // -------------------------------------------------------------------------
483
+ /**
484
+ * Check and handle reflection after observation activation.
485
+ *
486
+ * Determines whether reflection should run (sync, async, or none) based
487
+ * on the current observation token count relative to the effective
488
+ * reflection threshold.
489
+ */
490
+ async handleReflection() {
491
+ if (!this.completeFn)
492
+ return;
493
+ const effectiveThreshold = computeEffectiveReflectionThreshold(this.contextWindow, this.config.reflectionThreshold, this.utilityModelContextWindow);
494
+ const reflectionAction = this.buffering.shouldReflect(this.observationTokenCount, effectiveThreshold, this.config.reflectionBufferActivation);
495
+ if (reflectionAction === 'none')
496
+ return;
497
+ if (reflectionAction === 'sync') {
498
+ const previousObservations = this.observations;
499
+ // Check for a ready buffered reflection first
500
+ if (this.buffering.hasBufferedReflection()) {
501
+ const buffered = this.buffering.consumeBufferedReflection();
502
+ if (buffered) {
503
+ this.observations = buffered.observations;
504
+ this.observationTokenCount = estimateTokens(this.observations);
505
+ this.generationCount++;
506
+ this.fireReflectionEvent({
507
+ previousObservations,
508
+ newObservations: this.observations,
509
+ generationCount: this.generationCount,
510
+ compressionLevel: buffered.compressionLevel,
511
+ timestamp: new Date(),
512
+ });
513
+ return;
514
+ }
515
+ }
516
+ // No buffered reflection, run synchronously
517
+ const output = await runReflector(this.completeFn, this.observations, this.buildReflectorConfig(effectiveThreshold));
518
+ this.observations = output.observations;
519
+ this.observationTokenCount = estimateTokens(this.observations);
520
+ this.generationCount++;
521
+ this.fireReflectionEvent({
522
+ previousObservations,
523
+ newObservations: this.observations,
524
+ generationCount: this.generationCount,
525
+ compressionLevel: output.compressionLevel,
526
+ timestamp: new Date(),
527
+ });
528
+ return;
529
+ }
530
+ if (reflectionAction === 'async') {
531
+ // Launch async reflector
532
+ const effectiveThresholdForReflector = computeEffectiveReflectionThreshold(this.contextWindow, this.config.reflectionThreshold, this.utilityModelContextWindow);
533
+ this.buffering.launchReflector(this.completeFn, this.observations, this.buildReflectorConfig(effectiveThresholdForReflector), this.logger ?? undefined);
534
+ }
535
+ }
536
+ // -------------------------------------------------------------------------
537
+ // Private: Config builders (exactOptionalPropertyTypes safe)
538
+ // -------------------------------------------------------------------------
539
+ /**
540
+ * Build the observer config object without assigning undefined to optional
541
+ * properties (exactOptionalPropertyTypes is enabled).
542
+ */
543
+ buildObserverConfig() {
544
+ const config = {
545
+ previousObserverTokens: this.config.previousObserverTokens,
546
+ };
547
+ if (this.config.observerInstruction !== undefined) {
548
+ config.observerInstruction = this.config.observerInstruction;
549
+ }
550
+ return config;
551
+ }
552
+ /**
553
+ * Build the reflector config object without assigning undefined to optional
554
+ * properties (exactOptionalPropertyTypes is enabled).
555
+ */
556
+ buildReflectorConfig(threshold) {
557
+ const config = {
558
+ reflectionThreshold: threshold,
559
+ };
560
+ if (this.config.reflectorInstruction !== undefined) {
561
+ config.reflectorInstruction = this.config.reflectorInstruction;
562
+ }
563
+ return config;
564
+ }
565
+ // -------------------------------------------------------------------------
566
+ // Private: Chunk merging
567
+ // -------------------------------------------------------------------------
568
+ /**
569
+ * Merge buffered observation chunks into a single observation text.
570
+ *
571
+ * Concatenates all chunk observation texts with double newlines. Uses
572
+ * the latest chunk's currentTask and suggestedResponse (latest wins).
573
+ */
574
+ mergeChunks(chunks) {
575
+ const observationParts = [];
576
+ // Find the latest chunk that produced at least one meaningful hint field.
577
+ // Each observer only sees its own batch of messages, so the latest chunk
578
+ // reflects the most recent state of the conversation. We do NOT mix fields
579
+ // across chunks: that would risk injecting a stale currentTask from an
580
+ // earlier chunk when the conversation has since moved on to something else.
581
+ //
582
+ // The parser already rejects placeholder-only content, so an observer that
583
+ // echoed the prompt template without filling it in will have undefined
584
+ // hint fields (not empty strings).
585
+ let latestHintChunk = null;
586
+ for (const chunk of chunks) {
587
+ observationParts.push(chunk.observations);
588
+ if (chunk.currentTask || chunk.suggestedResponse) {
589
+ latestHintChunk = chunk;
590
+ }
591
+ }
592
+ // If no chunk produced hints, preserve the existing hint from prior
593
+ // activation cycles. That hint is still more relevant than nothing, since
594
+ // it came from the observer that ran at the end of the previous cycle
595
+ // (itself more recent than anything older in this cycle).
596
+ const hint = latestHintChunk
597
+ ? {
598
+ currentTask: latestHintChunk.currentTask ?? '',
599
+ suggestedResponse: latestHintChunk.suggestedResponse ?? '',
600
+ }
601
+ : this.continuationHint;
602
+ return {
603
+ observations: observationParts.join('\n\n'),
604
+ hint,
605
+ };
606
+ }
607
+ // -------------------------------------------------------------------------
608
+ // Private: Event firing
609
+ // -------------------------------------------------------------------------
610
+ /**
611
+ * Fire all observation handlers. Each handler is individually try/catch
612
+ * wrapped to prevent one handler from breaking others.
613
+ */
614
+ fireObservationEvent(event) {
615
+ for (const handler of this.observationHandlers) {
616
+ try {
617
+ handler(event);
618
+ }
619
+ catch (err) {
620
+ const message = err instanceof Error ? err.message : String(err);
621
+ this.logger?.warn(`Observation handler threw: ${message}`);
622
+ }
623
+ }
624
+ }
625
+ /**
626
+ * Fire all reflection handlers. Each handler is individually try/catch
627
+ * wrapped to prevent one handler from breaking others.
628
+ */
629
+ fireReflectionEvent(event) {
630
+ for (const handler of this.reflectionHandlers) {
631
+ try {
632
+ handler(event);
633
+ }
634
+ catch (err) {
635
+ const message = err instanceof Error ? err.message : String(err);
636
+ this.logger?.warn(`Reflection handler threw: ${message}`);
637
+ }
638
+ }
639
+ }
640
+ }
641
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/compaction/observational/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAaH,OAAO,EACL,6BAA6B,EAC7B,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,mCAAmC,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,mCAAmC,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAgBpD,8EAA8E;AAC9E,4BAA4B;AAC5B,8EAA8E;AAE9E;;;;;;GAMG;AACH,MAAM,OAAO,yBAAyB;IAC5B,MAAM,CAIZ;IACM,SAAS,CAAuB;IAChC,UAAU,GAAsB,IAAI,CAAC;IACrC,YAAY,GAAW,EAAE,CAAC;IAC1B,gBAAgB,GAA4B,IAAI,CAAC;IACjD,qBAAqB,GAAW,CAAC,CAAC;IAClC,e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