@x-otto/memory 0.0.1-alpha.2 → 0.0.1-alpha.4
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/README.md +28 -19
- package/dist/index.d.ts +501 -53
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +54 -92
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @x-otto/memory
|
|
2
2
|
|
|
3
|
-
Agent working memory pipeline: LLM-driven compaction, LLM-free pruning,
|
|
3
|
+
Agent working memory pipeline: LLM-driven compaction, LLM-free pruning, multi-source AGENTS.md memory, writable cross-session auto-memory, operational learning, and workspace file-state snapshots.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -15,9 +15,8 @@ import { MemoryManager, OperationalLearningStore, FileStateManager } from '@x-ot
|
|
|
15
15
|
|
|
16
16
|
// Pipeline: prune → compaction → archive
|
|
17
17
|
const memory = new MemoryManager({
|
|
18
|
-
|
|
19
|
-
model:
|
|
20
|
-
provider: myProvider,
|
|
18
|
+
summarize: async (prompt, opts) => myLLM.complete(prompt, opts),
|
|
19
|
+
model: { contextWindow: 200_000, maxOutput: 8_192 },
|
|
21
20
|
})
|
|
22
21
|
const result = await memory.process(messages, sessionId)
|
|
23
22
|
// Returns { messages, summary, archivePath, pruned, compacted }
|
|
@@ -33,7 +32,7 @@ await lessons.save({ tags: ['testing'], trigger: 'flaky test', insight: 'reset s
|
|
|
33
32
|
// File state snapshot
|
|
34
33
|
const fsm = new FileStateManager()
|
|
35
34
|
const snapshot = await fsm.capture({ workspaceDir: '.' })
|
|
36
|
-
// snapshot → {
|
|
35
|
+
// snapshot → { directoryTree, modifiedFiles: { created, modified, deleted }, findings }
|
|
37
36
|
```
|
|
38
37
|
|
|
39
38
|
## Pipeline: prune → compaction → archive
|
|
@@ -43,23 +42,24 @@ const snapshot = await fsm.capture({ workspaceDir: '.' })
|
|
|
43
42
|
- Triggered when estimated tokens exceed `prune.trigger` threshold
|
|
44
43
|
- Protection window: last N messages (by token count) are always kept
|
|
45
44
|
- `tool_result` content outside protection → `[output pruned — N tokens]`
|
|
46
|
-
- `tool_call` arguments for write tools (write/edit
|
|
45
|
+
- `tool_call` arguments for write tools (write/edit) truncated beyond `truncateMaxLength`
|
|
47
46
|
- Minimum gain gate: rolls back if net savings < `minimum` tokens
|
|
48
47
|
|
|
49
|
-
### 2. Compaction — LLM-driven summary (`compaction.ts`)
|
|
48
|
+
### 2. Compaction — LLM-driven summary (`compaction-backend.ts`)
|
|
50
49
|
|
|
51
50
|
- `findCutPoint`: keep recent tokens, align to user/assistant boundary, detect split-turn
|
|
52
51
|
- Separates messages-to-summarize / preserved / turn-prefix region
|
|
53
52
|
- Extracts file operations (read/modified paths) from tool_results
|
|
54
|
-
- Calls injected `summarize(
|
|
53
|
+
- Calls injected `summarize(prompt, opts)` with structured prompt (Goal / Constraints / Progress / Key Decisions / Next Steps / File Operations / Critical Context)
|
|
55
54
|
- Iterative: previous summary + new messages → `UPDATE_SUMMARIZATION_PROMPT`
|
|
56
55
|
- Split turn: generates additional turn-prefix summary via `TURN_PREFIX_SUMMARIZATION_PROMPT`
|
|
57
56
|
|
|
58
|
-
### 3. Archive —
|
|
57
|
+
### 3. Archive — session-derived view (`archive-source.ts`)
|
|
59
58
|
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
59
|
+
- Archive is a session-derived view (compaction boundaries reconstructed from session entries on demand), not independent persistence
|
|
60
|
+
- `InMemoryArchiveStorage` retained as V-form (headless, no session tree) fallback
|
|
61
|
+
- `ArchiveSource` interface unifies both implementations; `MemoryManager` has no form-branching
|
|
62
|
+
- Backend: `InMemoryArchiveStorage` (default; the former `PersistenceBackedArchiveStorage` / `createArchiveStorage` file/HTTP stack was deleted — archive is now a session-derived view, not independent persistence)
|
|
63
63
|
|
|
64
64
|
## Persistent Memory (`persistent-memory.ts`)
|
|
65
65
|
|
|
@@ -97,7 +97,7 @@ CJK-aware classification heuristic (not `length/4`):
|
|
|
97
97
|
- CJK: 1 token/char, ASCII/symbols: 0.25–0.5/char → conservatively high (triggers early rather than overflow)
|
|
98
98
|
- `estimateMessageTokens`: content blocks (text/thinking/tool_call), images ~2000 tokens constant, + role overhead
|
|
99
99
|
- `estimateContextTokens`: hybrid — last assistant's usage as baseline, estimate only trailing tail
|
|
100
|
-
- Exports `messageToText`
|
|
100
|
+
- Exports `messageToText`
|
|
101
101
|
|
|
102
102
|
## Operational Learning (`operational-learning.ts`)
|
|
103
103
|
|
|
@@ -125,28 +125,37 @@ Read-only workspace snapshot for agent context:
|
|
|
125
125
|
```
|
|
126
126
|
src/
|
|
127
127
|
types.ts # Config types, MemoryStore, ArchiveStorage, ManagerConfig
|
|
128
|
-
memory-manager.ts # Pipeline coordinator + persistent memory facade
|
|
128
|
+
memory-manager.ts # Pipeline coordinator + persistent memory facade + trigger orchestration
|
|
129
129
|
prune.ts # No-LLM pruning (window, tool_result truncation, gain gate)
|
|
130
|
-
compaction.ts #
|
|
131
|
-
|
|
130
|
+
compaction.ts # Pure functions: findCutPoint / isSummaryMessage / extractFileOps / formatFileOps
|
|
131
|
+
compaction-backend.ts # CompactionBackend: compact/prepare/isEligible (strategy-execution separation)
|
|
132
|
+
trigger-policies.ts # TriggerPolicy interface + TokenPressure/RealInput/Residency/Prune policies
|
|
133
|
+
coverage-governor.ts # Per-session coverage boost state (instance-owned)
|
|
134
|
+
archive-source.ts # ArchiveSource interface + SessionEntries/InMemory implementations
|
|
135
|
+
compaction-truncation.ts # Summary-input formatting & truncation primitives
|
|
136
|
+
memory-injection.ts # <agent_memory> injection: budget accounting + index folding
|
|
137
|
+
archive.ts # InMemoryArchiveStorage + formatArchive
|
|
132
138
|
persistent-memory.ts # AGENTS.md multi-source + FileSystemMemoryStore / InMemoryMemoryStore
|
|
133
139
|
http-memory-store.ts # Remote HTTP memory store
|
|
134
140
|
auto-memory.ts # Cross-session progressive-disclosure memory
|
|
135
141
|
auto-extract.ts # Auto-memory candidate extraction
|
|
136
142
|
agents-discovery.ts # AGENTS.md path discovery
|
|
137
143
|
memory-extractor.ts # Derive persistable memory entries from session
|
|
144
|
+
evolution-signal-store.ts # Evolution-observation unified signal exit (append-only)
|
|
145
|
+
signal-log.ts # SignalLog persistence (AppendLog JSONL domain wrapper)
|
|
146
|
+
overlay-memory-store.ts # Shadow-mode MemoryStore overlay (reads-through, writes in-memory)
|
|
138
147
|
token-estimator.ts # CJK-aware token estimation + usage-hybrid context
|
|
139
148
|
defaults.ts # computeMemoryDefaults / resolveContextSize
|
|
140
149
|
operational-learning.ts # Lessons store (CRUD + weighted search + atomic persistence)
|
|
141
150
|
file-state-snapshot.ts # Workspace read-only snapshot
|
|
142
|
-
prompts.ts # Summary prompts +
|
|
143
|
-
constants.ts # Thresholds, paths
|
|
151
|
+
prompts.ts # Summary prompts + archive reference builders
|
|
152
|
+
constants.ts # Thresholds, paths, conflict ring size
|
|
144
153
|
index.ts # Barrel exports
|
|
145
154
|
```
|
|
146
155
|
|
|
147
156
|
## Dependencies
|
|
148
157
|
|
|
149
|
-
- Internal: `@x-otto/
|
|
158
|
+
- Internal: `@x-otto/interchange` (Message types), `@x-otto/persistence`, `@x-otto/shared`, `@x-otto/env` (thresholds, tool name constants)
|
|
150
159
|
- External: `js-tiktoken`
|
|
151
160
|
- LLM access: via injected `summarize` callback (not direct)
|
|
152
161
|
|