humemory 0.2.1 → 0.2.3
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/AGENTS.md +9 -5
- package/CHANGELOG.md +12 -0
- package/README.md +94 -7
- package/dist/agent/claude-hook.d.ts +13 -0
- package/dist/agent/claude-hook.js +48 -5
- package/dist/agent/learning-extractor.d.ts +2 -0
- package/dist/agent/learning-extractor.js +41 -12
- package/dist/agent/maintenance-queue.d.ts +47 -0
- package/dist/agent/maintenance-queue.js +246 -0
- package/dist/agent/session-context.js +15 -4
- package/dist/agent/source-registry.d.ts +34 -0
- package/dist/agent/source-registry.js +89 -0
- package/dist/api/server.js +46 -3
- package/dist/cli/index.js +20 -1
- package/dist/core/llm-generator.d.ts +2 -1
- package/dist/core/llm-generator.js +35 -34
- package/dist/index.d.ts +6 -2
- package/dist/index.js +4 -2
- package/dist/mcp/server.js +13 -3
- package/dist/store/sqlite.js +1 -0
- package/docs/TESTING.md +3 -2
- package/package.json +7 -5
- package/public/app/{galaxy-f42190mq.js → galaxy-cgbkc6e1.js} +1 -1
- package/public/app/index-5kwkpwkp.js +2 -0
- package/public/app/index-kv9v6ty0.css +1 -0
- package/public/app/{index-f9h80bzq.js → index-nqr7bd0a.js} +9 -9
- package/public/app/index.html +1 -1
- package/public/app/{promenade-cnzzpm73.js → promenade-fa0tb6jx.js} +1 -1
- package/public/app/river-01hs4f06.js +5 -0
- package/scripts/hook-session.ts +11 -10
- package/scripts/maintenance-worker.ts +37 -0
- package/public/app/index-2cf31xxn.css +0 -1
- package/public/app/index-kvhc17mz.js +0 -2
- package/public/app/river-tyawhh8w.js +0 -13
package/AGENTS.md
CHANGED
|
@@ -42,6 +42,7 @@ pnpm cli <cmd> # run CLI directly
|
|
|
42
42
|
pnpm test # bun test, single pass
|
|
43
43
|
pnpm test:watch # bun test --watch
|
|
44
44
|
pnpm consolidate # manual decay pass (cron-friendly)
|
|
45
|
+
pnpm maintenance # process queued sessions (network-free by default)
|
|
45
46
|
```
|
|
46
47
|
|
|
47
48
|
Single test file: `bun test tests/humemory.test.ts`
|
|
@@ -56,13 +57,15 @@ src/
|
|
|
56
57
|
│ ├── types.ts # Memory, DecayLevel, SearchQuery, MemoryStore iface
|
|
57
58
|
│ ├── decay.ts # degradation curve + thresholds
|
|
58
59
|
│ ├── search.ts # inverse search (BM25, degraded-first)
|
|
59
|
-
│ └── llm-generator.ts #
|
|
60
|
+
│ └── llm-generator.ts # deterministic L1/L2/L3; optional injected LLM
|
|
60
61
|
├── store/
|
|
61
62
|
│ └── sqlite.ts # bun:sqlite store (WAL), findSimilar/merge/setPhotographic
|
|
62
63
|
├── agent/
|
|
63
64
|
│ ├── session-parser.ts # parse Claude Code session transcripts
|
|
65
|
+
│ ├── source-registry.ts # discover local AI runtimes without reading sessions
|
|
64
66
|
│ ├── learning-extractor.ts # extract decisions/bugs/solutions
|
|
65
|
-
│ ├──
|
|
67
|
+
│ ├── maintenance-queue.ts # durable async inbox, session checkpoints, dead-letter
|
|
68
|
+
│ ├── claude-hook.ts # worker-side session learning encoder
|
|
66
69
|
│ └── session-context.ts # SessionStart → markdown block (open loops + traces)
|
|
67
70
|
├── core/
|
|
68
71
|
│ ├── clock.ts # Clock seam (systemClock / FakeClock)
|
|
@@ -73,8 +76,9 @@ src/
|
|
|
73
76
|
├── cli/index.ts # commander CLI
|
|
74
77
|
└── index.ts # library exports
|
|
75
78
|
web/ # React front (bun bundler → public/app, served at /app)
|
|
76
|
-
scripts/hook-session.ts # Claude Code Stop hook →
|
|
79
|
+
scripts/hook-session.ts # Claude Code Stop hook → queue raw session only
|
|
77
80
|
scripts/hook-session-start.ts # Claude Code SessionStart hook → inject context
|
|
81
|
+
scripts/maintenance-worker.ts # async extraction/storage; deterministic by default
|
|
78
82
|
tests/ # bun test (hermetic; helpers/ + fixtures/)
|
|
79
83
|
data/humemory.db # shared DB (created on first run)
|
|
80
84
|
```
|
|
@@ -149,9 +153,9 @@ clock- and event-driven and cannot be trusted without it.
|
|
|
149
153
|
- Core decay + inverse search; `bun:sqlite` store (WAL, write-queue serialization)
|
|
150
154
|
- CLI + Hono API + web dashboard ("palais de mémoire")
|
|
151
155
|
- Nightly cron consolidation (`0 3 * * *`)
|
|
152
|
-
-
|
|
156
|
+
- Deterministic L1/L2/L3 generation; optional injected LLM enhancement
|
|
153
157
|
- Similar-detection + merge (L4); enriched search (type/period/saillance/recalls)
|
|
154
|
-
- Photographic mode; Claude Code `Stop` hook →
|
|
158
|
+
- Photographic mode; Claude Code `Stop` hook → durable async maintenance queue
|
|
155
159
|
|
|
156
160
|
### 🎯 Phase 5 — Prospective memory (the destiny)
|
|
157
161
|
> Detailed corrected plan in **[PHASE5_PLAN.md](./PHASE5_PLAN.md)**. Summary below.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.3] - 2026-08-17
|
|
4
|
+
**Features:**
|
|
5
|
+
- add Streamable HTTP transport and security hardening
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## [0.2.2] - 2026-08-15
|
|
10
|
+
**Features:**
|
|
11
|
+
- add async multi-agent session capture
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
## [0.2.1] - 2026-08-09
|
|
4
16
|
**Features:**
|
|
5
17
|
- correction kills the script — contradictions target scripts too
|
package/README.md
CHANGED
|
@@ -37,7 +37,8 @@ the curve. A **photographic** flag pins critical traces so they never fade.
|
|
|
37
37
|
escalates toward full content only on a match — the human recall pattern, fast by
|
|
38
38
|
construction.
|
|
39
39
|
|
|
40
|
-
A Claude Code `Stop` hook
|
|
40
|
+
A Claude Code `Stop` hook can queue each completed session instantly; maintenance
|
|
41
|
+
extracts and stores its learnings afterward, outside the agent's critical path.
|
|
41
42
|
|
|
42
43
|
### 2. Prospective memory — *what to resurface* 🎯 the destiny
|
|
43
44
|
|
|
@@ -63,9 +64,37 @@ pnpm install
|
|
|
63
64
|
pnpm build:web # bundle the React front (bun's own bundler, no extra tooling)
|
|
64
65
|
pnpm start:api # API + dashboards → http://localhost:3456
|
|
65
66
|
pnpm cli status # state of the memory palace
|
|
67
|
+
pnpm cli sources discover # discover local AI runtimes; reads no sessions
|
|
66
68
|
pnpm test # bun test — backend and React components, one runner
|
|
67
69
|
```
|
|
68
70
|
|
|
71
|
+
### Local AI sources — a non-exhaustive registry
|
|
72
|
+
|
|
73
|
+
humemory keeps acquisition outside the cognitive core: the registry discovers
|
|
74
|
+
local producers, while humemory decides what becomes a trace, how it decays, and
|
|
75
|
+
when it resurfaces. Discovery only checks commands and known data roots; importing
|
|
76
|
+
historical sessions remains an explicit, opt-in step.
|
|
77
|
+
|
|
78
|
+
The non-exhaustive catalog currently recognizes:
|
|
79
|
+
|
|
80
|
+
| Runtime | Vendor | Discovery hints |
|
|
81
|
+
| --- | --- | --- |
|
|
82
|
+
| Claude Code | Anthropic | `claude`, `~/.claude` |
|
|
83
|
+
| Codex | OpenAI | `codex`, `~/.codex` |
|
|
84
|
+
| Kimi Code / Kimi Desktop | Moonshot AI | `kimi`, `~/.kimi-code`, desktop data roots |
|
|
85
|
+
| Mistral Vibe | **Mistral AI** | `vibe`, `$VIBE_HOME`, `~/.vibe` |
|
|
86
|
+
| OpenCode | SST | `opencode`, `~/.opencode` |
|
|
87
|
+
| Qwen Code | Alibaba Cloud | `qwen`, `$QWEN_RUNTIME_DIR`, `$QWEN_HOME`, `~/.qwen` |
|
|
88
|
+
| Gemini CLI | Google | `gemini`, `$GEMINI_CLI_HOME`, `~/.gemini` |
|
|
89
|
+
| GitHub Copilot CLI | GitHub | `copilot`, `~/.copilot` |
|
|
90
|
+
| Aider | Aider-AI | `aider`, `~/.aider.conf.yml` |
|
|
91
|
+
| Cursor | Anysphere | `cursor`, desktop data roots |
|
|
92
|
+
| Windsurf | Cognition | `windsurf`, desktop data roots |
|
|
93
|
+
|
|
94
|
+
An entry means **ready to be discovered**, not that its evolving private session
|
|
95
|
+
format is already parsed. Run `pnpm cli sources discover --installed-only` for a
|
|
96
|
+
local inventory without exposing conversation content.
|
|
97
|
+
|
|
69
98
|
The React app is served at **`/`** (and `/app`). The original vanilla dashboard
|
|
70
99
|
has been removed — the React front reached parity first, and git keeps the old
|
|
71
100
|
one if it is ever needed.
|
|
@@ -133,7 +162,8 @@ more than leaving one open.
|
|
|
133
162
|
|
|
134
163
|
### Wiring the Claude Code hooks
|
|
135
164
|
|
|
136
|
-
Two hooks, both optional and both fail-open
|
|
165
|
+
Two hooks, both optional and both fail-open. `Stop` only writes the raw session to
|
|
166
|
+
a durable local queue; it never waits for a model or a network request:
|
|
137
167
|
|
|
138
168
|
```jsonc
|
|
139
169
|
// ~/.claude/settings.json
|
|
@@ -143,7 +173,7 @@ Two hooks, both optional and both fail-open — neither will ever block a sessio
|
|
|
143
173
|
"SessionStart": [{ "matcher": "", "hooks": [
|
|
144
174
|
{ "type": "command", "command": "bun /path/to/humemory/scripts/hook-session-start.ts" }
|
|
145
175
|
]}],
|
|
146
|
-
// end of session:
|
|
176
|
+
// end of session: queues the transcript for asynchronous maintenance
|
|
147
177
|
"Stop": [{ "matcher": "", "hooks": [
|
|
148
178
|
{ "type": "command", "command": "bun /path/to/humemory/scripts/hook-session.ts" }
|
|
149
179
|
]}]
|
|
@@ -155,9 +185,34 @@ Two hooks, both optional and both fail-open — neither will ever block a sessio
|
|
|
155
185
|
fires any due time cues, and writes a markdown block on stdout — which Claude Code
|
|
156
186
|
injects into the session. Nothing relevant means nothing written.
|
|
157
187
|
|
|
188
|
+
Process queued sessions independently from the agent flow:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
pnpm maintenance
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The default maintenance path is deterministic and network-free. To opt into
|
|
195
|
+
Claude as an asynchronous quality enhancement, set
|
|
196
|
+
`HUMEMORY_MAINTENANCE_LLM=anthropic` and `ANTHROPIC_API_KEY`; quota errors and
|
|
197
|
+
timeouts fall back to the deterministic extractor. A queue item is deleted only
|
|
198
|
+
after its extracted memories are committed successfully.
|
|
199
|
+
|
|
200
|
+
The queue directory is the whole contract, and it is inspectable at any time:
|
|
201
|
+
|
|
202
|
+
| Entry | Meaning |
|
|
203
|
+
| --- | --- |
|
|
204
|
+
| `<id>.json` | a session waiting to be encoded, keyed on session — not on transcript content, since `Stop` resends a longer transcript every turn |
|
|
205
|
+
| `<id>.json.processing` | claimed by the running worker; a newer transcript may land on the free `<id>.json` slot meanwhile, and survives |
|
|
206
|
+
| `checkpoints/<id>.json` | how many messages of that session are already encoded, so a resent transcript only contributes its delta |
|
|
207
|
+
| `<id>.dead.json` | gave up after `maxAttempts` (5), or unparseable on disk; never retried, never deleted |
|
|
208
|
+
| `.worker.lock` | single-worker token; a lock left by a dead worker is reclaimed atomically after 5 min |
|
|
209
|
+
|
|
158
210
|
| Env var | Default | Effect |
|
|
159
211
|
| --- | --- | --- |
|
|
160
212
|
| `HUMEMORY_DB` | `data/humemory.db` | database path |
|
|
213
|
+
| `HUMEMORY_QUEUE` | `data/maintenance-queue` | durable raw-session inbox |
|
|
214
|
+
| `HUMEMORY_MAINTENANCE_LLM` | `none` | optional enhancement (`anthropic`) |
|
|
215
|
+
| `HUMEMORY_MAINTENANCE_TIMEOUT_MS` | `8000` | model timeout; never affects the agent hook |
|
|
161
216
|
| `HUMEMORY_DIR` | `cwd` | mental place to scope loops and traces to |
|
|
162
217
|
| `HUMEMORY_SESSION_BUDGET` | `10` | max items listed per section |
|
|
163
218
|
| `HUMEMORY_SAILLANCE_MIN` | `60` | salience floor for recalling a decayed trace |
|
|
@@ -171,10 +226,42 @@ A log remembers everything and reminds you of nothing. A human memory forgets mo
|
|
|
171
226
|
of it and hands you the one thing that matters, at the moment it matters. humemory
|
|
172
227
|
is an attempt to give an AI agent the second kind.
|
|
173
228
|
|
|
229
|
+
## A memory engine, not an integration bundle
|
|
230
|
+
|
|
231
|
+
humemory has a narrow job: decide what deserves to become a memory, how that
|
|
232
|
+
trace changes with time, and when it should return. Everything that brings data
|
|
233
|
+
in sits outside the cognitive core.
|
|
234
|
+
|
|
235
|
+
- **Connectors live in a registry.** Discovery and future import adapters identify
|
|
236
|
+
Claude Code, Codex, Kimi, Qwen, Mistral and other local producers; they don't
|
|
237
|
+
become memory primitives. Adding a source doesn't change decay, recall, trust
|
|
238
|
+
or cue logic.
|
|
239
|
+
- **SQLite owns the truth.** Provenance, decay levels, intentions, scripts and
|
|
240
|
+
review decisions remain queryable and recoverable. Vector embeddings form a
|
|
241
|
+
second, disposable search lane: humemory can rebuild them, change the embedding
|
|
242
|
+
model or disable semantic search without putting the memory store at risk.
|
|
243
|
+
- **Several agents can share one brain.** MCP and source attribution let Claude,
|
|
244
|
+
Codex, Kimi, OpenCode and future clients use the same store. Every write keeps
|
|
245
|
+
its agent and device provenance instead of inheriting one vendor's session model.
|
|
246
|
+
- **Maintenance stays out of the agent's path.** Hooks queue a raw session locally,
|
|
247
|
+
then exit. A separate worker filters, consolidates and stores it; a slow GPU,
|
|
248
|
+
a network outage or an exhausted quota doesn't make the agent wait.
|
|
249
|
+
- **LLMs are optional, not governors.** Decay, salience, recall, cues, scripts,
|
|
250
|
+
trust and deterministic consolidation work without an API key. A configured
|
|
251
|
+
model may improve the generated text, but failure always returns to the local
|
|
252
|
+
deterministic path.
|
|
253
|
+
- **Automation stops before judgment.** The dreamer files proposals, agent-authored
|
|
254
|
+
scripts begin as drafts, and contradictions stay inspectable. A model doesn't
|
|
255
|
+
silently turn a guess into permanent memory.
|
|
256
|
+
|
|
257
|
+
Historical absorption stays opt-in. `sources discover` checks commands and known
|
|
258
|
+
paths without reading conversations. Each runtime still needs a parser before
|
|
259
|
+
humemory can import its sessions, and discovery never pretends otherwise.
|
|
260
|
+
|
|
174
261
|
## Stack
|
|
175
262
|
|
|
176
263
|
TypeScript · `bun:sqlite` (WAL) · `flexsearch` (BM25) · `hono` (API) ·
|
|
177
|
-
`commander` (CLI) · `@anthropic-ai/sdk` (
|
|
264
|
+
`commander` (CLI) · `@anthropic-ai/sdk` (optional maintenance adapter).
|
|
178
265
|
|
|
179
266
|
---
|
|
180
267
|
|
|
@@ -202,7 +289,7 @@ The CLI provides several commands to interact with humemory:
|
|
|
202
289
|
- `-l2, --level2 <essential>`: Essential for consolidation N2
|
|
203
290
|
- `-l3, --level3 <keywords>`: Trace for fast search N3
|
|
204
291
|
- `-t, --type <type>`: Memory type (episodic/semantic/procedural)
|
|
205
|
-
- `--auto`: Auto-generate N1/N2/N3
|
|
292
|
+
- `--auto`: Auto-generate N1/N2/N3 locally; an injected LLM may enhance them
|
|
206
293
|
- `--photographic`: Photographic mode — disable degradation
|
|
207
294
|
|
|
208
295
|
- **Search for memory traces**:
|
|
@@ -446,9 +533,9 @@ keywords >5. `photographic: true` disables decay entirely.
|
|
|
446
533
|
- Core decay + inverse search; `bun:sqlite` store (WAL, write-queue serialization)
|
|
447
534
|
- CLI + Hono API + web dashboard ("palais de mémoire")
|
|
448
535
|
- Nightly cron consolidation (`0 3 * * *`)
|
|
449
|
-
-
|
|
536
|
+
- Deterministic L1/L2/L3 generation; optional injected LLM enhancement
|
|
450
537
|
- Similar-detection + merge (L4); enriched search (type/period/saillance/recalls)
|
|
451
|
-
- Photographic mode; Claude Code `Stop` hook →
|
|
538
|
+
- Photographic mode; Claude Code `Stop` hook → durable async maintenance queue
|
|
452
539
|
|
|
453
540
|
### 🎯 Phase 5 — Prospective memory (the destiny)
|
|
454
541
|
> Corrected plan in **[PHASE5_PLAN.md](./PHASE5_PLAN.md)**. Summary:
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import type { LLMClient } from '../core/llm-generator.js';
|
|
2
|
+
import type { TraceSource } from '../core/types.js';
|
|
2
3
|
export interface HookOptions {
|
|
3
4
|
dbPath: string;
|
|
4
5
|
directory?: string;
|
|
5
6
|
maxLearnings?: number;
|
|
6
7
|
client?: LLMClient;
|
|
8
|
+
llmTimeoutMs?: number;
|
|
9
|
+
source?: TraceSource;
|
|
10
|
+
agent?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Number of leading transcript messages already encoded for this session.
|
|
13
|
+
* `Stop` fires once per turn and resends the whole transcript, so without a
|
|
14
|
+
* checkpoint every pass would re-encode the entire history as new memories.
|
|
15
|
+
*/
|
|
16
|
+
sinceMessage?: number;
|
|
7
17
|
verbose?: boolean;
|
|
8
18
|
}
|
|
9
19
|
export interface HookResult {
|
|
@@ -11,5 +21,8 @@ export interface HookResult {
|
|
|
11
21
|
directory: string;
|
|
12
22
|
memoriesStored: number;
|
|
13
23
|
learnings: string[];
|
|
24
|
+
extractionMode: 'llm' | 'deterministic';
|
|
25
|
+
/** Total messages in the transcript — the checkpoint to persist after success. */
|
|
26
|
+
messagesSeen: number;
|
|
14
27
|
}
|
|
15
28
|
export declare function processSession(rawTranscript: string, options: HookOptions): Promise<HookResult>;
|
|
@@ -1,14 +1,53 @@
|
|
|
1
1
|
import { SQLiteStore } from '../store/sqlite.js';
|
|
2
2
|
import { parseClaudeHookPayload } from './session-parser.js';
|
|
3
|
-
import { extractLearnings } from './learning-extractor.js';
|
|
4
|
-
|
|
3
|
+
import { extractLearnings, extractLearningsDeterministic } from './learning-extractor.js';
|
|
4
|
+
async function withTimeout(promise, timeoutMs) {
|
|
5
|
+
let timer;
|
|
6
|
+
try {
|
|
7
|
+
return await Promise.race([
|
|
8
|
+
promise,
|
|
9
|
+
new Promise((_, reject) => {
|
|
10
|
+
timer = setTimeout(() => reject(new Error(`maintenance model timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
11
|
+
}),
|
|
12
|
+
]);
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
if (timer)
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
5
19
|
export async function processSession(rawTranscript, options) {
|
|
6
20
|
const directory = options.directory ?? process.cwd();
|
|
7
|
-
const client = options.client ?? new Anthropic();
|
|
8
21
|
const session = parseClaudeHookPayload(rawTranscript, directory);
|
|
9
|
-
const
|
|
22
|
+
const maxLearnings = options.maxLearnings ?? 5;
|
|
23
|
+
const messagesSeen = session.messages.length;
|
|
24
|
+
// Only the messages added since the last successful pass are candidates.
|
|
25
|
+
const since = Math.max(0, Math.min(options.sinceMessage ?? 0, messagesSeen));
|
|
26
|
+
const pending = session.messages.slice(since);
|
|
27
|
+
if (pending.length === 0) {
|
|
28
|
+
return {
|
|
29
|
+
sessionId: session.sessionId, directory: session.directory,
|
|
30
|
+
memoriesStored: 0, learnings: [], extractionMode: 'deterministic', messagesSeen,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const scoped = {
|
|
34
|
+
...session,
|
|
35
|
+
messages: pending,
|
|
36
|
+
rawText: pending.map((m) => `${m.role}: ${m.content}`).join('\n\n'),
|
|
37
|
+
};
|
|
38
|
+
let extractionMode = 'deterministic';
|
|
39
|
+
let learnings = extractLearningsDeterministic(scoped, maxLearnings);
|
|
40
|
+
if (options.client) {
|
|
41
|
+
try {
|
|
42
|
+
learnings = await withTimeout(extractLearnings(scoped, options.client, maxLearnings), options.llmTimeoutMs ?? 8_000);
|
|
43
|
+
extractionMode = 'llm';
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// Quota, network, timeout: the deterministic path already produced a result.
|
|
47
|
+
}
|
|
48
|
+
}
|
|
10
49
|
if (learnings.length === 0) {
|
|
11
|
-
return { sessionId: session.sessionId, directory: session.directory, memoriesStored: 0, learnings: [] };
|
|
50
|
+
return { sessionId: session.sessionId, directory: session.directory, memoriesStored: 0, learnings: [], extractionMode, messagesSeen };
|
|
12
51
|
}
|
|
13
52
|
const store = new SQLiteStore(options.dbPath);
|
|
14
53
|
const stored = [];
|
|
@@ -22,6 +61,8 @@ export async function processSession(rawTranscript, options) {
|
|
|
22
61
|
sessionId: session.sessionId,
|
|
23
62
|
memoryType: learning.memoryType,
|
|
24
63
|
level3Keywords: learning.level3Keywords,
|
|
64
|
+
source: options.source ?? 'agent',
|
|
65
|
+
agent: options.agent ?? 'unknown',
|
|
25
66
|
});
|
|
26
67
|
stored.push(learning.content.slice(0, 80));
|
|
27
68
|
}
|
|
@@ -34,5 +75,7 @@ export async function processSession(rawTranscript, options) {
|
|
|
34
75
|
directory: session.directory,
|
|
35
76
|
memoriesStored: stored.length,
|
|
36
77
|
learnings: stored,
|
|
78
|
+
extractionMode,
|
|
79
|
+
messagesSeen,
|
|
37
80
|
};
|
|
38
81
|
}
|
|
@@ -7,4 +7,6 @@ export interface ExtractedLearning {
|
|
|
7
7
|
keywords: string[];
|
|
8
8
|
level3Keywords: string;
|
|
9
9
|
}
|
|
10
|
+
/** Fast, network-free baseline used whenever no maintenance model is available. */
|
|
11
|
+
export declare function extractLearningsDeterministic(session: ParsedSession, maxLearnings?: number): ExtractedLearning[];
|
|
10
12
|
export declare function extractLearnings(session: ParsedSession, client: LLMClient, maxLearnings?: number): Promise<ExtractedLearning[]>;
|
|
@@ -1,3 +1,42 @@
|
|
|
1
|
+
const STOP_WORDS = new Set([
|
|
2
|
+
'about', 'after', 'again', 'avec', 'cette', 'dans', 'elle', 'from', 'have', 'mais',
|
|
3
|
+
'pour', 'that', 'this', 'tout', 'une', 'with', 'your', 'être', 'plus', 'then', 'when',
|
|
4
|
+
]);
|
|
5
|
+
function deterministicKeywords(content) {
|
|
6
|
+
const words = content
|
|
7
|
+
.toLocaleLowerCase()
|
|
8
|
+
.normalize('NFD')
|
|
9
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
10
|
+
.match(/[a-z0-9_-]{4,}/g) ?? [];
|
|
11
|
+
return [...new Set(words.filter((word) => !STOP_WORDS.has(word)))].slice(0, 8);
|
|
12
|
+
}
|
|
13
|
+
/** Fast, network-free baseline used whenever no maintenance model is available. */
|
|
14
|
+
export function extractLearningsDeterministic(session, maxLearnings = 5) {
|
|
15
|
+
const unique = new Set();
|
|
16
|
+
const candidates = session.messages
|
|
17
|
+
.filter((message) => message.role === 'assistant')
|
|
18
|
+
.map((message) => message.content.trim())
|
|
19
|
+
.filter((content) => content.length >= 40)
|
|
20
|
+
.filter((content) => {
|
|
21
|
+
const key = content.replace(/\s+/g, ' ').toLocaleLowerCase();
|
|
22
|
+
if (unique.has(key))
|
|
23
|
+
return false;
|
|
24
|
+
unique.add(key);
|
|
25
|
+
return true;
|
|
26
|
+
})
|
|
27
|
+
.slice(-maxLearnings);
|
|
28
|
+
return candidates.map((content) => {
|
|
29
|
+
const clipped = content.slice(0, 1_000);
|
|
30
|
+
const keywords = deterministicKeywords(clipped);
|
|
31
|
+
const procedural = /\b(fix(?:ed)?|implement(?:ed)?|add(?:ed)?|use|run|step|corrig|ajout|remplac|configur)/i.test(clipped);
|
|
32
|
+
return {
|
|
33
|
+
content: clipped,
|
|
34
|
+
memoryType: procedural ? 'procedural' : 'episodic',
|
|
35
|
+
keywords,
|
|
36
|
+
level3Keywords: keywords.join(' '),
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
1
40
|
const SYSTEM_PROMPT = `You are a system that extracts mnemonic learnings.
|
|
2
41
|
Analyse the session and extract the key learnings worth remembering.
|
|
3
42
|
Write them in the same language as the session itself.
|
|
@@ -59,17 +98,7 @@ Format JSON requis:
|
|
|
59
98
|
.slice(0, maxLearnings);
|
|
60
99
|
}
|
|
61
100
|
catch {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!lastAssistant)
|
|
65
|
-
return [];
|
|
66
|
-
return [
|
|
67
|
-
{
|
|
68
|
-
content: lastAssistant.content.slice(0, 500),
|
|
69
|
-
memoryType: 'episodic',
|
|
70
|
-
keywords: [],
|
|
71
|
-
level3Keywords: '',
|
|
72
|
-
},
|
|
73
|
-
];
|
|
101
|
+
return extractLearningsDeterministic(session, 1)
|
|
102
|
+
.map((learning) => ({ ...learning, memoryType: 'episodic' }));
|
|
74
103
|
}
|
|
75
104
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { LLMClient } from '../core/llm-generator.js';
|
|
2
|
+
export interface MaintenanceJob {
|
|
3
|
+
version: 1;
|
|
4
|
+
id: string;
|
|
5
|
+
source: string;
|
|
6
|
+
agent: string;
|
|
7
|
+
sessionId: string;
|
|
8
|
+
directory: string;
|
|
9
|
+
rawTranscript: string;
|
|
10
|
+
maxLearnings: number;
|
|
11
|
+
queuedAt: string;
|
|
12
|
+
attempts: number;
|
|
13
|
+
lastError?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface EnqueueOptions {
|
|
16
|
+
queueDir: string;
|
|
17
|
+
directory?: string;
|
|
18
|
+
source?: string;
|
|
19
|
+
agent?: string;
|
|
20
|
+
maxLearnings?: number;
|
|
21
|
+
now?: () => Date;
|
|
22
|
+
}
|
|
23
|
+
export interface QueueResult {
|
|
24
|
+
job: MaintenanceJob;
|
|
25
|
+
created: boolean;
|
|
26
|
+
path: string;
|
|
27
|
+
}
|
|
28
|
+
export interface WorkerOptions {
|
|
29
|
+
queueDir: string;
|
|
30
|
+
dbPath: string;
|
|
31
|
+
client?: LLMClient;
|
|
32
|
+
llmTimeoutMs?: number;
|
|
33
|
+
maxJobs?: number;
|
|
34
|
+
lockStaleMs?: number;
|
|
35
|
+
maxAttempts?: number;
|
|
36
|
+
now?: () => Date;
|
|
37
|
+
}
|
|
38
|
+
export interface WorkerResult {
|
|
39
|
+
discovered: number;
|
|
40
|
+
processed: number;
|
|
41
|
+
failed: number;
|
|
42
|
+
deadLettered: number;
|
|
43
|
+
memoriesStored: number;
|
|
44
|
+
busy: boolean;
|
|
45
|
+
}
|
|
46
|
+
export declare function enqueueSession(rawTranscript: string, options: EnqueueOptions): Promise<QueueResult>;
|
|
47
|
+
export declare function processMaintenanceQueue(options: WorkerOptions): Promise<WorkerResult>;
|