@animalabs/context-manager 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.
- package/dist/src/blob-manager.d.ts +37 -0
- package/dist/src/blob-manager.d.ts.map +1 -0
- package/dist/src/blob-manager.js +128 -0
- package/dist/src/blob-manager.js.map +1 -0
- package/dist/src/context-log.d.ts +99 -0
- package/dist/src/context-log.d.ts.map +1 -0
- package/dist/src/context-log.js +277 -0
- package/dist/src/context-log.js.map +1 -0
- package/dist/src/context-manager.d.ts +245 -0
- package/dist/src/context-manager.d.ts.map +1 -0
- package/dist/src/context-manager.js +553 -0
- package/dist/src/context-manager.js.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +12 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/message-store.d.ts +135 -0
- package/dist/src/message-store.d.ts.map +1 -0
- package/dist/src/message-store.js +372 -0
- package/dist/src/message-store.js.map +1 -0
- package/dist/src/strategies/autobiographical.d.ts +199 -0
- package/dist/src/strategies/autobiographical.d.ts.map +1 -0
- package/dist/src/strategies/autobiographical.js +1122 -0
- package/dist/src/strategies/autobiographical.js.map +1 -0
- package/dist/src/strategies/index.d.ts +3 -0
- package/dist/src/strategies/index.d.ts.map +1 -0
- package/dist/src/strategies/index.js +3 -0
- package/dist/src/strategies/index.js.map +1 -0
- package/dist/src/strategies/knowledge.d.ts +46 -0
- package/dist/src/strategies/knowledge.d.ts.map +1 -0
- package/dist/src/strategies/knowledge.js +270 -0
- package/dist/src/strategies/knowledge.js.map +1 -0
- package/dist/src/strategies/passthrough.d.ts +17 -0
- package/dist/src/strategies/passthrough.d.ts.map +1 -0
- package/dist/src/strategies/passthrough.js +69 -0
- package/dist/src/strategies/passthrough.js.map +1 -0
- package/dist/src/types/context.d.ts +108 -0
- package/dist/src/types/context.d.ts.map +1 -0
- package/dist/src/types/context.js +2 -0
- package/dist/src/types/context.js.map +1 -0
- package/dist/src/types/index.d.ts +5 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +2 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/message.d.ts +129 -0
- package/dist/src/types/message.d.ts.map +1 -0
- package/dist/src/types/message.js +2 -0
- package/dist/src/types/message.js.map +1 -0
- package/dist/src/types/strategy.d.ts +233 -0
- package/dist/src/types/strategy.d.ts.map +1 -0
- package/dist/src/types/strategy.js +32 -0
- package/dist/src/types/strategy.js.map +1 -0
- package/dist/test/autobiographical.test.d.ts +2 -0
- package/dist/test/autobiographical.test.d.ts.map +1 -0
- package/dist/test/autobiographical.test.js +46 -0
- package/dist/test/autobiographical.test.js.map +1 -0
- package/dist/test/head-window-reset.test.d.ts +17 -0
- package/dist/test/head-window-reset.test.d.ts.map +1 -0
- package/dist/test/head-window-reset.test.js +342 -0
- package/dist/test/head-window-reset.test.js.map +1 -0
- package/dist/test/integration.test.d.ts +2 -0
- package/dist/test/integration.test.d.ts.map +1 -0
- package/dist/test/integration.test.js +1341 -0
- package/dist/test/integration.test.js.map +1 -0
- package/dist/test/knowledge.test.d.ts +2 -0
- package/dist/test/knowledge.test.d.ts.map +1 -0
- package/dist/test/knowledge.test.js +617 -0
- package/dist/test/knowledge.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +48 -0
- package/src/blob-manager.ts +155 -0
- package/src/context-log.ts +342 -0
- package/src/context-manager.ts +726 -0
- package/src/index.ts +50 -0
- package/src/message-store.ts +479 -0
- package/src/strategies/autobiographical.ts +1355 -0
- package/src/strategies/index.ts +2 -0
- package/src/strategies/knowledge.ts +336 -0
- package/src/strategies/passthrough.ts +98 -0
- package/src/types/context.ts +119 -0
- package/src/types/index.ts +42 -0
- package/src/types/message.ts +140 -0
- package/src/types/strategy.ts +282 -0
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import { JsStore } from '@animalabs/chronicle';
|
|
2
|
+
import { isResettableStrategy } from './types/index.js';
|
|
3
|
+
import { MessageStore } from './message-store.js';
|
|
4
|
+
import { ContextLog } from './context-log.js';
|
|
5
|
+
import { PassthroughStrategy } from './strategies/passthrough.js';
|
|
6
|
+
/**
|
|
7
|
+
* Context Manager - the main interface for managing conversation context.
|
|
8
|
+
*
|
|
9
|
+
* Sits between the application/agent layer and Membrane, managing what goes
|
|
10
|
+
* into the context window. Uses Chronicle for persistent storage.
|
|
11
|
+
*/
|
|
12
|
+
export class ContextManager {
|
|
13
|
+
store;
|
|
14
|
+
messageStore;
|
|
15
|
+
contextLog;
|
|
16
|
+
strategy;
|
|
17
|
+
membrane;
|
|
18
|
+
initialized = false;
|
|
19
|
+
/** Whether we own the store (created it) vs app owns it (passed in) */
|
|
20
|
+
ownsStore;
|
|
21
|
+
debugLogContext;
|
|
22
|
+
constructor(store, messageStore, contextLog, strategy, ownsStore, membrane, debugLogContext = false) {
|
|
23
|
+
this.store = store;
|
|
24
|
+
this.messageStore = messageStore;
|
|
25
|
+
this.contextLog = contextLog;
|
|
26
|
+
this.strategy = strategy;
|
|
27
|
+
this.ownsStore = ownsStore;
|
|
28
|
+
this.membrane = membrane;
|
|
29
|
+
this.debugLogContext = debugLogContext;
|
|
30
|
+
// Set up edit propagation
|
|
31
|
+
this.messageStore.addListener((event) => this.handleMessageStoreEvent(event));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Open or create a context manager.
|
|
35
|
+
*
|
|
36
|
+
* Can be called with either:
|
|
37
|
+
* - `{ path: string }` - Creates and owns a new store
|
|
38
|
+
* - `{ store: JsStore }` - Uses an existing app-owned store
|
|
39
|
+
*
|
|
40
|
+
* When using an app-owned store, the app is responsible for closing it.
|
|
41
|
+
* The app can register additional states on the store before passing it.
|
|
42
|
+
*/
|
|
43
|
+
static async open(config) {
|
|
44
|
+
let store;
|
|
45
|
+
let ownsStore;
|
|
46
|
+
if ('store' in config && config.store) {
|
|
47
|
+
// App provides existing store - app owns it
|
|
48
|
+
store = config.store;
|
|
49
|
+
ownsStore = false;
|
|
50
|
+
}
|
|
51
|
+
else if ('path' in config && config.path) {
|
|
52
|
+
// Create new store - we own it
|
|
53
|
+
store = JsStore.openOrCreate({
|
|
54
|
+
path: config.path,
|
|
55
|
+
blobCacheSize: config.blobCacheSize ?? 1000,
|
|
56
|
+
});
|
|
57
|
+
ownsStore = true;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw new Error('ContextManagerConfig must have either "path" or "store"');
|
|
61
|
+
}
|
|
62
|
+
// Namespace for messages: only when `isolate` is true
|
|
63
|
+
if (config.isolate && !config.namespace) {
|
|
64
|
+
throw new Error('ContextManagerConfig: "isolate" requires "namespace" to be set');
|
|
65
|
+
}
|
|
66
|
+
const messageNamespace = config.isolate ? config.namespace : undefined;
|
|
67
|
+
// Register states if needed (idempotent)
|
|
68
|
+
try {
|
|
69
|
+
MessageStore.register(store, messageNamespace);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// State already registered
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
ContextLog.register(store, config.namespace);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// State already registered
|
|
79
|
+
}
|
|
80
|
+
const messageStore = new MessageStore(store, {
|
|
81
|
+
estimator: config.tokenEstimator,
|
|
82
|
+
namespace: messageNamespace,
|
|
83
|
+
});
|
|
84
|
+
const contextLog = new ContextLog(store, {
|
|
85
|
+
estimator: config.tokenEstimator,
|
|
86
|
+
namespace: config.namespace,
|
|
87
|
+
});
|
|
88
|
+
const strategy = config.strategy ?? new PassthroughStrategy();
|
|
89
|
+
const manager = new ContextManager(store, messageStore, contextLog, strategy, ownsStore, config.membrane, config.debugLogContext ?? false);
|
|
90
|
+
// Initialize strategy
|
|
91
|
+
await manager.initializeStrategy();
|
|
92
|
+
manager.initialized = true;
|
|
93
|
+
return manager;
|
|
94
|
+
}
|
|
95
|
+
// ==========================================================================
|
|
96
|
+
// Message Store Operations
|
|
97
|
+
// ==========================================================================
|
|
98
|
+
/**
|
|
99
|
+
* Add a message to the store.
|
|
100
|
+
*/
|
|
101
|
+
addMessage(participant, content, metadata, causedBy) {
|
|
102
|
+
const message = this.messageStore.append(participant, content, metadata, causedBy);
|
|
103
|
+
return message.id;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Edit a message in the store. Propagates to context log based on source relation.
|
|
107
|
+
*/
|
|
108
|
+
editMessage(messageId, content) {
|
|
109
|
+
this.messageStore.edit(messageId, content);
|
|
110
|
+
// Propagation handled by event listener
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Remove a message from the store. Propagates to context log.
|
|
114
|
+
*/
|
|
115
|
+
removeMessage(messageId) {
|
|
116
|
+
this.messageStore.remove(messageId);
|
|
117
|
+
// Propagation handled by event listener
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Remove a range of messages from the store.
|
|
121
|
+
*/
|
|
122
|
+
removeMessages(fromId, toId) {
|
|
123
|
+
this.messageStore.removeRange(fromId, toId);
|
|
124
|
+
// Propagation handled by event listener
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get a message by ID.
|
|
128
|
+
*/
|
|
129
|
+
getMessage(messageId) {
|
|
130
|
+
return this.messageStore.get(messageId);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get a message as it was at a specific sequence (time travel).
|
|
134
|
+
*/
|
|
135
|
+
getMessageAt(messageId, atSequence) {
|
|
136
|
+
return this.messageStore.getAt(messageId, atSequence);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get all messages in the store.
|
|
140
|
+
*/
|
|
141
|
+
getAllMessages() {
|
|
142
|
+
return this.messageStore.getAll();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Query messages by filter criteria.
|
|
146
|
+
* Useful for finding messages from external sources, by participant, etc.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* // Find all messages from Discord
|
|
150
|
+
* const { messages } = manager.queryMessages({ source: 'discord' });
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* // Find messages from a specific channel
|
|
154
|
+
* const { messages } = manager.queryMessages({
|
|
155
|
+
* source: 'discord',
|
|
156
|
+
* metadata: { 'external.channelId': '123456' }
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* // Find specific messages by external ID
|
|
161
|
+
* const { messages } = manager.queryMessages({
|
|
162
|
+
* source: 'discord',
|
|
163
|
+
* externalIds: ['msg1', 'msg2', 'msg3']
|
|
164
|
+
* });
|
|
165
|
+
*/
|
|
166
|
+
queryMessages(filter) {
|
|
167
|
+
return this.messageStore.query(filter);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Find a message by its external source and ID.
|
|
171
|
+
* Returns the internal message ID, or null if not found.
|
|
172
|
+
*/
|
|
173
|
+
findMessageByExternalId(source, externalId) {
|
|
174
|
+
const msg = this.messageStore.findByExternalId(source, externalId);
|
|
175
|
+
return msg?.id ?? null;
|
|
176
|
+
}
|
|
177
|
+
// ==========================================================================
|
|
178
|
+
// Branching
|
|
179
|
+
// ==========================================================================
|
|
180
|
+
/**
|
|
181
|
+
* Create a branch from a specific message.
|
|
182
|
+
* The new branch will have state as of that message's sequence (time-travel branching).
|
|
183
|
+
*/
|
|
184
|
+
branchAt(messageId, name) {
|
|
185
|
+
const message = this.messageStore.get(messageId);
|
|
186
|
+
if (!message) {
|
|
187
|
+
throw new Error(`Message not found: ${messageId}`);
|
|
188
|
+
}
|
|
189
|
+
// Create branch name if not provided
|
|
190
|
+
const branchName = name ?? `branch-${Date.now()}`;
|
|
191
|
+
// Get current branch name to branch from
|
|
192
|
+
const currentBranch = this.store.currentBranch();
|
|
193
|
+
// Use createBranchAt to branch at the message's sequence (time-travel)
|
|
194
|
+
const branch = this.store.createBranchAt(branchName, currentBranch.name, message.sequence);
|
|
195
|
+
return branch.id;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Switch to a different branch.
|
|
199
|
+
*/
|
|
200
|
+
switchBranch(branchId) {
|
|
201
|
+
this.store.switchBranch(branchId);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Get current branch.
|
|
205
|
+
*/
|
|
206
|
+
currentBranch() {
|
|
207
|
+
const branch = this.store.currentBranch();
|
|
208
|
+
return {
|
|
209
|
+
id: branch.id,
|
|
210
|
+
name: branch.name,
|
|
211
|
+
head: branch.head,
|
|
212
|
+
parentId: branch.parentId ?? undefined,
|
|
213
|
+
branchPoint: branch.branchPoint ?? undefined,
|
|
214
|
+
created: new Date(branch.created),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* List all branches.
|
|
219
|
+
*/
|
|
220
|
+
listBranches() {
|
|
221
|
+
return this.store.listBranches().map((b) => ({
|
|
222
|
+
id: b.id,
|
|
223
|
+
name: b.name,
|
|
224
|
+
head: b.head,
|
|
225
|
+
parentId: b.parentId ?? undefined,
|
|
226
|
+
branchPoint: b.branchPoint ?? undefined,
|
|
227
|
+
created: new Date(b.created),
|
|
228
|
+
}));
|
|
229
|
+
}
|
|
230
|
+
// ==========================================================================
|
|
231
|
+
// Context Compilation
|
|
232
|
+
// ==========================================================================
|
|
233
|
+
/**
|
|
234
|
+
* Check if compile() will block waiting for background work.
|
|
235
|
+
*/
|
|
236
|
+
isReady() {
|
|
237
|
+
return this.strategy.checkReadiness().ready;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Get info about pending background work.
|
|
241
|
+
*/
|
|
242
|
+
getPendingWork() {
|
|
243
|
+
const state = this.strategy.checkReadiness();
|
|
244
|
+
if (state.ready) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
description: state.description ?? 'Background work pending',
|
|
249
|
+
started: new Date(),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Compile context for Membrane.
|
|
254
|
+
*
|
|
255
|
+
* Accepts optional context injections (e.g., from MCPL servers) and merges
|
|
256
|
+
* them into the compiled output by position:
|
|
257
|
+
* - "system": returned separately in `systemInjections` (caller appends to system prompt)
|
|
258
|
+
* - "beforeUser": inserted before the last user message
|
|
259
|
+
* - "afterUser": inserted after the last user message
|
|
260
|
+
*
|
|
261
|
+
* May block if strategy has pending work.
|
|
262
|
+
*/
|
|
263
|
+
async compile(budget, injections) {
|
|
264
|
+
// Check readiness and wait if needed
|
|
265
|
+
const readiness = this.strategy.checkReadiness();
|
|
266
|
+
if (!readiness.ready && readiness.pendingWork) {
|
|
267
|
+
await readiness.pendingWork;
|
|
268
|
+
}
|
|
269
|
+
// Default budget
|
|
270
|
+
const effectiveBudget = budget ?? {
|
|
271
|
+
maxTokens: 100000,
|
|
272
|
+
reserveForResponse: 4000,
|
|
273
|
+
};
|
|
274
|
+
// Get selected entries from strategy
|
|
275
|
+
const entries = this.strategy.select(this.messageStore.createView(), this.contextLog.createView(), effectiveBudget);
|
|
276
|
+
// Convert to NormalizedMessage[]
|
|
277
|
+
const messages = entries.map((entry) => ({
|
|
278
|
+
participant: entry.participant,
|
|
279
|
+
content: entry.content,
|
|
280
|
+
}));
|
|
281
|
+
// If no injections, log and return early
|
|
282
|
+
if (!injections || injections.length === 0) {
|
|
283
|
+
const result = { messages, systemInjections: [] };
|
|
284
|
+
if (this.debugLogContext)
|
|
285
|
+
this.logCompiledContext(result);
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
288
|
+
// Separate injections by position
|
|
289
|
+
const systemInjections = [];
|
|
290
|
+
const beforeUser = [];
|
|
291
|
+
const afterUser = [];
|
|
292
|
+
for (const injection of injections) {
|
|
293
|
+
switch (injection.position) {
|
|
294
|
+
case 'system':
|
|
295
|
+
systemInjections.push(...injection.content);
|
|
296
|
+
break;
|
|
297
|
+
case 'beforeUser':
|
|
298
|
+
beforeUser.push(injection);
|
|
299
|
+
break;
|
|
300
|
+
case 'afterUser':
|
|
301
|
+
afterUser.push(injection);
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Find last user message index (participant is typically 'user' or 'User')
|
|
306
|
+
let lastUserIdx = -1;
|
|
307
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
308
|
+
if (messages[i].participant.toLowerCase() === 'user') {
|
|
309
|
+
lastUserIdx = i;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// Insert beforeUser injections before last user message
|
|
314
|
+
if (beforeUser.length > 0 && lastUserIdx >= 0) {
|
|
315
|
+
const injectedMessages = beforeUser.map((inj) => ({
|
|
316
|
+
participant: `injection:${inj.namespace}`,
|
|
317
|
+
content: inj.content,
|
|
318
|
+
}));
|
|
319
|
+
messages.splice(lastUserIdx, 0, ...injectedMessages);
|
|
320
|
+
// Adjust lastUserIdx to account for inserted messages
|
|
321
|
+
lastUserIdx += injectedMessages.length;
|
|
322
|
+
}
|
|
323
|
+
// Insert afterUser injections after last user message
|
|
324
|
+
if (afterUser.length > 0) {
|
|
325
|
+
const insertIdx = lastUserIdx >= 0 ? lastUserIdx + 1 : messages.length;
|
|
326
|
+
const injectedMessages = afterUser.map((inj) => ({
|
|
327
|
+
participant: `injection:${inj.namespace}`,
|
|
328
|
+
content: inj.content,
|
|
329
|
+
}));
|
|
330
|
+
messages.splice(insertIdx, 0, ...injectedMessages);
|
|
331
|
+
}
|
|
332
|
+
const result = { messages, systemInjections };
|
|
333
|
+
if (this.debugLogContext)
|
|
334
|
+
this.logCompiledContext(result);
|
|
335
|
+
return result;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Log the compiled context to stderr for debugging.
|
|
339
|
+
* Uses stderr so it doesn't pollute the context log (which strategies read).
|
|
340
|
+
*/
|
|
341
|
+
logCompiledContext(result) {
|
|
342
|
+
const renderedMessages = result.messages.map((m) => {
|
|
343
|
+
const text = m.content
|
|
344
|
+
.map((b) => {
|
|
345
|
+
switch (b.type) {
|
|
346
|
+
case 'text': return b.text;
|
|
347
|
+
case 'thinking': return `[thinking] ${b.thinking}`;
|
|
348
|
+
case 'tool_use': return `[tool_use:${b.name}] ${JSON.stringify(b.input)}`;
|
|
349
|
+
case 'tool_result': return `[tool_result:${b.toolUseId}] ${typeof b.content === 'string' ? b.content : JSON.stringify(b.content)}`;
|
|
350
|
+
default: return `[${b.type}]`;
|
|
351
|
+
}
|
|
352
|
+
})
|
|
353
|
+
.join('\n');
|
|
354
|
+
return { participant: m.participant, text };
|
|
355
|
+
});
|
|
356
|
+
const entry = {
|
|
357
|
+
timestamp: Date.now(),
|
|
358
|
+
type: 'compiled_context',
|
|
359
|
+
messageCount: result.messages.length,
|
|
360
|
+
systemInjectionCount: result.systemInjections.length,
|
|
361
|
+
messages: renderedMessages,
|
|
362
|
+
};
|
|
363
|
+
console.error('[debugLogContext]', JSON.stringify(entry));
|
|
364
|
+
}
|
|
365
|
+
// ==========================================================================
|
|
366
|
+
// Strategy
|
|
367
|
+
// ==========================================================================
|
|
368
|
+
/**
|
|
369
|
+
* Set the context management strategy.
|
|
370
|
+
*/
|
|
371
|
+
async setStrategy(strategy) {
|
|
372
|
+
this.strategy = strategy;
|
|
373
|
+
await this.initializeStrategy();
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Get the current strategy.
|
|
377
|
+
*/
|
|
378
|
+
getStrategy() {
|
|
379
|
+
return this.strategy;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Reset the head window to start from a new position.
|
|
383
|
+
* Old head window messages become compressible.
|
|
384
|
+
*
|
|
385
|
+
* If transitionText is provided, it's used as the transition summary.
|
|
386
|
+
* If omitted, an LLM call auto-generates a transition summary.
|
|
387
|
+
*
|
|
388
|
+
* Returns the transition summary text used.
|
|
389
|
+
*/
|
|
390
|
+
async resetHeadWindow(transitionText) {
|
|
391
|
+
if (!isResettableStrategy(this.strategy)) {
|
|
392
|
+
throw new Error('Active strategy does not support head window reset');
|
|
393
|
+
}
|
|
394
|
+
const ctx = this.createStrategyContext();
|
|
395
|
+
// Generate transition summary if not provided
|
|
396
|
+
const summary = transitionText ?? await this.strategy.generateTransitionSummary(ctx);
|
|
397
|
+
// Inject transition message
|
|
398
|
+
const msgId = this.addMessage('Context Manager', [
|
|
399
|
+
{ type: 'text', text: `[Topic Transition]\n\n${summary}` },
|
|
400
|
+
]);
|
|
401
|
+
// Reset head window to start from this message
|
|
402
|
+
this.strategy.resetHeadWindow(msgId);
|
|
403
|
+
return summary;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Trigger background maintenance work.
|
|
407
|
+
* Call this periodically to allow strategies to do compression, etc.
|
|
408
|
+
*/
|
|
409
|
+
async tick() {
|
|
410
|
+
if (this.strategy.tick) {
|
|
411
|
+
await this.strategy.tick(this.createStrategyContext());
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// ==========================================================================
|
|
415
|
+
// Internal
|
|
416
|
+
// ==========================================================================
|
|
417
|
+
async initializeStrategy() {
|
|
418
|
+
if (this.strategy.initialize) {
|
|
419
|
+
await this.strategy.initialize(this.createStrategyContext());
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
createStrategyContext() {
|
|
423
|
+
return {
|
|
424
|
+
messageStore: this.messageStore.createView(),
|
|
425
|
+
contextLog: this.contextLog.createView(),
|
|
426
|
+
membrane: this.membrane,
|
|
427
|
+
currentSequence: this.store.currentSequence(),
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Handle message store events for edit propagation.
|
|
432
|
+
*/
|
|
433
|
+
handleMessageStoreEvent(event) {
|
|
434
|
+
switch (event.type) {
|
|
435
|
+
case 'add':
|
|
436
|
+
this.handleMessageAdd(event.message);
|
|
437
|
+
break;
|
|
438
|
+
case 'edit':
|
|
439
|
+
this.handleMessageEdit(event.messageId, event.newContent);
|
|
440
|
+
break;
|
|
441
|
+
case 'remove':
|
|
442
|
+
this.handleMessageRemove(event.messageId);
|
|
443
|
+
break;
|
|
444
|
+
case 'removeRange':
|
|
445
|
+
// For range removes, we need to check all affected messages
|
|
446
|
+
// This is a simplification - in practice we'd need to track the IDs
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
handleMessageAdd(message) {
|
|
451
|
+
// Notify strategy of new message
|
|
452
|
+
if (this.strategy.onNewMessage) {
|
|
453
|
+
// Fire and forget - don't block on strategy processing
|
|
454
|
+
this.strategy.onNewMessage(message, this.createStrategyContext()).catch((err) => {
|
|
455
|
+
console.error('Strategy onNewMessage failed:', err);
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
handleMessageEdit(messageId, newContent) {
|
|
460
|
+
// Find context entries that reference this message
|
|
461
|
+
const entries = this.contextLog.findBySource(messageId);
|
|
462
|
+
for (const entry of entries) {
|
|
463
|
+
// Check source relation to decide whether to propagate
|
|
464
|
+
switch (entry.sourceRelation) {
|
|
465
|
+
case 'copy':
|
|
466
|
+
// Must propagate
|
|
467
|
+
this.contextLog.edit(entry.index, newContent);
|
|
468
|
+
break;
|
|
469
|
+
case 'derived':
|
|
470
|
+
// May ignore (stale is acceptable)
|
|
471
|
+
// Do nothing
|
|
472
|
+
break;
|
|
473
|
+
case 'referenced':
|
|
474
|
+
// Don't propagate
|
|
475
|
+
// Do nothing
|
|
476
|
+
break;
|
|
477
|
+
default:
|
|
478
|
+
// No relation specified, treat as copy for safety
|
|
479
|
+
this.contextLog.edit(entry.index, newContent);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
handleMessageRemove(messageId) {
|
|
484
|
+
// Find context entries that reference this message
|
|
485
|
+
const entries = this.contextLog.findBySource(messageId);
|
|
486
|
+
// Collect indices to remove (in reverse order to maintain indices)
|
|
487
|
+
const indicesToRemove = [];
|
|
488
|
+
for (const entry of entries) {
|
|
489
|
+
switch (entry.sourceRelation) {
|
|
490
|
+
case 'copy':
|
|
491
|
+
// Must remove
|
|
492
|
+
indicesToRemove.push(entry.index);
|
|
493
|
+
break;
|
|
494
|
+
case 'derived':
|
|
495
|
+
// Ignore (it's a snapshot)
|
|
496
|
+
break;
|
|
497
|
+
case 'referenced':
|
|
498
|
+
// Don't propagate
|
|
499
|
+
break;
|
|
500
|
+
default:
|
|
501
|
+
// No relation specified, treat as copy
|
|
502
|
+
indicesToRemove.push(entry.index);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
// Remove in reverse order to maintain indices
|
|
506
|
+
indicesToRemove.sort((a, b) => b - a);
|
|
507
|
+
for (const index of indicesToRemove) {
|
|
508
|
+
this.contextLog.remove(index);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Get the underlying Chronicle store.
|
|
513
|
+
* Useful for registering additional states or accessing store-level features.
|
|
514
|
+
*/
|
|
515
|
+
getStore() {
|
|
516
|
+
return this.store;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Sync to disk.
|
|
520
|
+
*/
|
|
521
|
+
sync() {
|
|
522
|
+
this.store.sync();
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Close the context manager.
|
|
526
|
+
*
|
|
527
|
+
* If the manager owns the store (created via path config), this closes the store.
|
|
528
|
+
* If the app owns the store (passed via store config), this is a no-op;
|
|
529
|
+
* the app is responsible for closing the store when done.
|
|
530
|
+
*/
|
|
531
|
+
close() {
|
|
532
|
+
if (this.ownsStore) {
|
|
533
|
+
this.store.close();
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Check if the store has been closed.
|
|
538
|
+
*/
|
|
539
|
+
isClosed() {
|
|
540
|
+
return this.store.isClosed();
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Get store stats.
|
|
544
|
+
*/
|
|
545
|
+
stats() {
|
|
546
|
+
return {
|
|
547
|
+
messageCount: this.messageStore.length(),
|
|
548
|
+
contextEntryCount: this.contextLog.length(),
|
|
549
|
+
branches: this.listBranches().length,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
//# sourceMappingURL=context-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-manager.js","sourceRoot":"","sources":["../../src/context-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAkB/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AA0DlE;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IACjB,KAAK,CAAU;IACf,YAAY,CAAe;IAC3B,UAAU,CAAa;IACvB,QAAQ,CAAkB;IAC1B,QAAQ,CAAY;IACpB,WAAW,GAAG,KAAK,CAAC;IAC5B,uEAAuE;IAC/D,SAAS,CAAU;IACnB,eAAe,CAAU;IAEjC,YACE,KAAc,EACd,YAA0B,EAC1B,UAAsB,EACtB,QAAyB,EACzB,SAAkB,EAClB,QAAmB,EACnB,eAAe,GAAG,KAAK;QAEvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QAEvC,0BAA0B;QAC1B,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CA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;;OAEG;IACH,IAAI;QACF,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACH,KAAK;QACH,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK;QAKH,OAAO;YACL,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;YACxC,iBAAiB,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YAC3C,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,MAAM;SACrC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { ContextManager } from './context-manager.js';
|
|
2
|
+
export type { ContextManagerConfig } from './context-manager.js';
|
|
3
|
+
export { MessageStore } from './message-store.js';
|
|
4
|
+
export type { MessageStoreEvent, MessageStoreListener } from './message-store.js';
|
|
5
|
+
export { ContextLog } from './context-log.js';
|
|
6
|
+
export { BlobManager } from './blob-manager.js';
|
|
7
|
+
export { PassthroughStrategy } from './strategies/passthrough.js';
|
|
8
|
+
export { AutobiographicalStrategy } from './strategies/autobiographical.js';
|
|
9
|
+
export { KnowledgeStrategy } from './strategies/knowledge.js';
|
|
10
|
+
export type { MessageId, Sequence, BranchId, MessageMetadata, StoredMessage, BlobReference, StoredContentBlock, MessageQuery, MessageQueryResult, SourceRelation, ContextEntry, TokenBudget, PendingWork, BranchInfo, ContextInjection, CompileResult, MessageStoreView, ContextLogView, StrategyContext, ReadinessState, ContextStrategy, AutobiographicalConfig, SummaryLevel, SummaryEntry, PhaseType, KnowledgeConfig, ResettableStrategy, } from './types/index.js';
|
|
11
|
+
export { DEFAULT_AUTOBIOGRAPHICAL_CONFIG, isResettableStrategy } from './types/index.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGjE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG9D,YAAY,EAEV,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAElB,cAAc,EACd,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,aAAa,EAEb,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,eAAe,EACf,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,+BAA+B,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Main class
|
|
2
|
+
export { ContextManager } from './context-manager.js';
|
|
3
|
+
// Storage
|
|
4
|
+
export { MessageStore } from './message-store.js';
|
|
5
|
+
export { ContextLog } from './context-log.js';
|
|
6
|
+
export { BlobManager } from './blob-manager.js';
|
|
7
|
+
// Strategies
|
|
8
|
+
export { PassthroughStrategy } from './strategies/passthrough.js';
|
|
9
|
+
export { AutobiographicalStrategy } from './strategies/autobiographical.js';
|
|
10
|
+
export { KnowledgeStrategy } from './strategies/knowledge.js';
|
|
11
|
+
export { DEFAULT_AUTOBIOGRAPHICAL_CONFIG, isResettableStrategy } from './types/index.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,UAAU;AACV,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,aAAa;AACb,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAoC9D,OAAO,EAAE,+BAA+B,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC"}
|