clementine-agent 1.0.2 → 1.0.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/README.md +7 -0
- package/dist/cli/chat.js +27 -9
- package/dist/config.d.ts +2 -2
- package/dist/config.js +2 -2
- package/dist/index.js +29 -0
- package/dist/memory/maintenance.d.ts +20 -0
- package/dist/memory/maintenance.js +121 -0
- package/dist/memory/store.js +14 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,6 +85,8 @@ bash install.sh
|
|
|
85
85
|
|
|
86
86
|
The install script handles everything: system dependencies (redis, libomp, build tools), npm packages, TypeScript build, global CLI install, and launches the setup wizard. Safe to re-run — skips anything already installed.
|
|
87
87
|
|
|
88
|
+
The setup wizard auto-generates a Discord bot invite URL from your token and offers to open it in your browser — no need to visit the Developer Portal manually.
|
|
89
|
+
|
|
88
90
|
After setup:
|
|
89
91
|
|
|
90
92
|
```bash
|
|
@@ -324,6 +326,11 @@ clementine tools List available MCP tools, plugins, and channels
|
|
|
324
326
|
clementine config setup Interactive configuration wizard
|
|
325
327
|
clementine config set KEY VAL Set a single config value
|
|
326
328
|
clementine config get KEY Read a config value
|
|
329
|
+
clementine config edit Open .env in your editor ($EDITOR)
|
|
330
|
+
clementine memory search <q> Search memory from the terminal (FTS5)
|
|
331
|
+
clementine projects list Show all linked projects
|
|
332
|
+
clementine projects add <path> Link a project directory (-d desc, -k keywords)
|
|
333
|
+
clementine projects remove <p> Unlink a project directory
|
|
327
334
|
clementine cron list List all cron jobs and last run status
|
|
328
335
|
clementine cron run <job> Run a specific cron job
|
|
329
336
|
clementine cron run-due Run all due jobs (for OS scheduler)
|
package/dist/cli/chat.js
CHANGED
|
@@ -198,17 +198,35 @@ export async function cmdChat(opts) {
|
|
|
198
198
|
}
|
|
199
199
|
// ── Send message ──────────────────────────────────────────
|
|
200
200
|
process.stdout.write(`\n${DIM}thinking...${RESET}\r`);
|
|
201
|
+
let firstToken = true;
|
|
202
|
+
let streamedLen = 0;
|
|
201
203
|
try {
|
|
202
|
-
const response = await gateway.handleMessage(sessionKey, effectiveText,
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
204
|
+
const response = await gateway.handleMessage(sessionKey, effectiveText, async (token) => {
|
|
205
|
+
if (firstToken) {
|
|
206
|
+
// Clear "thinking..." and show project context on first real token
|
|
207
|
+
process.stdout.write('\x1b[2K\r');
|
|
208
|
+
const matched = gateway.getLastMatchedProject(sessionKey);
|
|
209
|
+
if (matched) {
|
|
210
|
+
process.stdout.write(`${DIM}[project: ${path.basename(matched.path)}]${RESET}\n`);
|
|
211
|
+
}
|
|
212
|
+
firstToken = false;
|
|
213
|
+
}
|
|
214
|
+
process.stdout.write(token);
|
|
215
|
+
streamedLen += token.length;
|
|
216
|
+
}, oneOffModel);
|
|
217
|
+
// If we streamed, just add a newline. Otherwise fall back to full render.
|
|
218
|
+
if (streamedLen > 0) {
|
|
219
|
+
process.stdout.write('\n\n');
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
process.stdout.write('\x1b[2K\r');
|
|
223
|
+
const matched = gateway.getLastMatchedProject(sessionKey);
|
|
224
|
+
if (matched) {
|
|
225
|
+
console.log(`${DIM}[project: ${path.basename(matched.path)}]${RESET}`);
|
|
226
|
+
}
|
|
227
|
+
console.log(renderMarkdown(response));
|
|
228
|
+
console.log();
|
|
209
229
|
}
|
|
210
|
-
console.log(renderMarkdown(response));
|
|
211
|
-
console.log();
|
|
212
230
|
}
|
|
213
231
|
catch (err) {
|
|
214
232
|
process.stdout.write('\x1b[2K\r');
|
package/dist/config.d.ts
CHANGED
|
@@ -117,8 +117,8 @@ export declare const LINK_EXTRACT_MAX_URLS = 3;
|
|
|
117
117
|
export declare const LINK_EXTRACT_MAX_CHARS = 4000;
|
|
118
118
|
export declare const MEMORY_DB_PATH: string;
|
|
119
119
|
export declare const GRAPH_DB_DIR: string;
|
|
120
|
-
export declare const SEARCH_CONTEXT_LIMIT =
|
|
121
|
-
export declare const SEARCH_RECENCY_LIMIT =
|
|
120
|
+
export declare const SEARCH_CONTEXT_LIMIT = 6;
|
|
121
|
+
export declare const SEARCH_RECENCY_LIMIT = 4;
|
|
122
122
|
export declare const SYSTEM_PROMPT_MAX_CONTEXT_CHARS = 12000;
|
|
123
123
|
export declare const SESSION_EXCHANGE_HISTORY_SIZE = 10;
|
|
124
124
|
export declare const SESSION_EXCHANGE_MAX_CHARS = 2000;
|
package/dist/config.js
CHANGED
|
@@ -239,8 +239,8 @@ export const LINK_EXTRACT_MAX_CHARS = 4000;
|
|
|
239
239
|
// ── Memory / Search ──────────────────────────────────────────────────
|
|
240
240
|
export const MEMORY_DB_PATH = path.join(VAULT_DIR, '.memory.db');
|
|
241
241
|
export const GRAPH_DB_DIR = path.join(BASE_DIR, '.graph.db');
|
|
242
|
-
export const SEARCH_CONTEXT_LIMIT =
|
|
243
|
-
export const SEARCH_RECENCY_LIMIT =
|
|
242
|
+
export const SEARCH_CONTEXT_LIMIT = 6;
|
|
243
|
+
export const SEARCH_RECENCY_LIMIT = 4;
|
|
244
244
|
export const SYSTEM_PROMPT_MAX_CONTEXT_CHARS = 12000;
|
|
245
245
|
// ── Session Persistence ──────────────────────────────────────────────
|
|
246
246
|
export const SESSION_EXCHANGE_HISTORY_SIZE = 10;
|
package/dist/index.js
CHANGED
|
@@ -545,6 +545,33 @@ async function asyncMain() {
|
|
|
545
545
|
// Agent layer
|
|
546
546
|
const { PersonalAssistant } = await import('./agent/assistant.js');
|
|
547
547
|
const assistant = new PersonalAssistant();
|
|
548
|
+
// Memory maintenance — startup + periodic (non-blocking)
|
|
549
|
+
let maintenanceInterval;
|
|
550
|
+
{
|
|
551
|
+
const memStore = assistant.getMemoryStore();
|
|
552
|
+
if (memStore) {
|
|
553
|
+
const { runStartupMaintenance, startPeriodicMaintenance } = await import('./memory/maintenance.js');
|
|
554
|
+
// Fire-and-forget startup maintenance
|
|
555
|
+
runStartupMaintenance(memStore).catch(() => { });
|
|
556
|
+
// Periodic maintenance every 6 hours (consolidation needs an LLM caller)
|
|
557
|
+
const { query } = await import('@anthropic-ai/claude-agent-sdk');
|
|
558
|
+
const llmCall = async (prompt) => {
|
|
559
|
+
try {
|
|
560
|
+
let result = '';
|
|
561
|
+
const stream = query({ prompt, options: { model: 'claude-haiku-4-5-20251001', maxTurns: 1, systemPrompt: 'You are a memory consolidation assistant. Be concise.' } });
|
|
562
|
+
for await (const msg of stream) {
|
|
563
|
+
if (msg.type === 'result')
|
|
564
|
+
result = msg.result ?? '';
|
|
565
|
+
}
|
|
566
|
+
return result;
|
|
567
|
+
}
|
|
568
|
+
catch {
|
|
569
|
+
return '';
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
maintenanceInterval = startPeriodicMaintenance(memStore, llmCall);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
548
575
|
// Gateway layer
|
|
549
576
|
const { Gateway } = await import('./gateway/router.js');
|
|
550
577
|
const gateway = new Gateway(assistant);
|
|
@@ -833,6 +860,8 @@ async function asyncMain() {
|
|
|
833
860
|
clearInterval(timerInterval);
|
|
834
861
|
clearInterval(teamDeliveryInterval);
|
|
835
862
|
clearInterval(sourceEditInterval);
|
|
863
|
+
if (maintenanceInterval)
|
|
864
|
+
clearInterval(maintenanceInterval);
|
|
836
865
|
// Close graph store FIRST — FalkorDBLite's cleanup.js registers an
|
|
837
866
|
// uncaughtException handler that re-throws errors. If a Redis socket
|
|
838
867
|
// drops during the drain wait, that handler crashes the process.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clementine TypeScript — Automatic Memory Maintenance.
|
|
3
|
+
*
|
|
4
|
+
* Runs startup and periodic maintenance so the memory store stays healthy
|
|
5
|
+
* without manual intervention. New users get this out of the box.
|
|
6
|
+
*
|
|
7
|
+
* Startup: decay salience, prune stale data, backfill embeddings
|
|
8
|
+
* Periodic (every 6h): full consolidation cycle + embedding rebuild
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Run one-time maintenance at daemon startup.
|
|
12
|
+
* Non-blocking — errors are logged but never thrown.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runStartupMaintenance(store: any): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Start periodic maintenance on a 6-hour interval.
|
|
17
|
+
* Returns the interval handle for cleanup on shutdown.
|
|
18
|
+
*/
|
|
19
|
+
export declare function startPeriodicMaintenance(store: any, llmCall?: (prompt: string) => Promise<string>): ReturnType<typeof setInterval>;
|
|
20
|
+
//# sourceMappingURL=maintenance.d.ts.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clementine TypeScript — Automatic Memory Maintenance.
|
|
3
|
+
*
|
|
4
|
+
* Runs startup and periodic maintenance so the memory store stays healthy
|
|
5
|
+
* without manual intervention. New users get this out of the box.
|
|
6
|
+
*
|
|
7
|
+
* Startup: decay salience, prune stale data, backfill embeddings
|
|
8
|
+
* Periodic (every 6h): full consolidation cycle + embedding rebuild
|
|
9
|
+
*/
|
|
10
|
+
import pino from 'pino';
|
|
11
|
+
const logger = pino({ name: 'clementine.maintenance' });
|
|
12
|
+
const PERIODIC_INTERVAL_MS = 6 * 60 * 60 * 1000; // 6 hours
|
|
13
|
+
/**
|
|
14
|
+
* Run one-time maintenance at daemon startup.
|
|
15
|
+
* Non-blocking — errors are logged but never thrown.
|
|
16
|
+
*/
|
|
17
|
+
export async function runStartupMaintenance(store) {
|
|
18
|
+
const start = Date.now();
|
|
19
|
+
logger.info('Starting memory maintenance (startup)');
|
|
20
|
+
try {
|
|
21
|
+
const decayed = store.decaySalience?.();
|
|
22
|
+
if (decayed)
|
|
23
|
+
logger.info({ decayed }, 'Salience decay applied');
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
logger.warn({ err }, 'Salience decay failed');
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const pruned = store.pruneStaleData?.();
|
|
30
|
+
if (pruned)
|
|
31
|
+
logger.info(pruned, 'Stale data pruned');
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
logger.warn({ err }, 'Stale data pruning failed');
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const embedded = store.buildEmbeddings?.();
|
|
38
|
+
if (embedded)
|
|
39
|
+
logger.info(embedded, 'Embeddings built/backfilled');
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
logger.warn({ err }, 'Embedding backfill failed');
|
|
43
|
+
}
|
|
44
|
+
// Prune old extraction logs (keep active extractions regardless of age)
|
|
45
|
+
try {
|
|
46
|
+
const conn = store.conn;
|
|
47
|
+
if (conn) {
|
|
48
|
+
const result = conn.prepare(`DELETE FROM memory_extractions
|
|
49
|
+
WHERE extracted_at < datetime('now', '-90 days')
|
|
50
|
+
AND status != 'active'`).run();
|
|
51
|
+
if (result.changes > 0) {
|
|
52
|
+
logger.info({ pruned: result.changes }, 'Old extraction logs pruned');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Table may not exist yet — non-fatal
|
|
58
|
+
}
|
|
59
|
+
logger.info({ durationMs: Date.now() - start }, 'Startup maintenance complete');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Start periodic maintenance on a 6-hour interval.
|
|
63
|
+
* Returns the interval handle for cleanup on shutdown.
|
|
64
|
+
*/
|
|
65
|
+
export function startPeriodicMaintenance(store, llmCall) {
|
|
66
|
+
const runCycle = async () => {
|
|
67
|
+
const start = Date.now();
|
|
68
|
+
logger.info('Starting periodic memory maintenance');
|
|
69
|
+
// 1. Decay + prune
|
|
70
|
+
try {
|
|
71
|
+
store.decaySalience?.();
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
logger.warn({ err }, 'Periodic decay failed');
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
store.pruneStaleData?.();
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
logger.warn({ err }, 'Periodic prune failed');
|
|
81
|
+
}
|
|
82
|
+
// 2. Rebuild vocab + backfill embeddings
|
|
83
|
+
try {
|
|
84
|
+
store.buildEmbeddings?.();
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
logger.warn({ err }, 'Periodic embedding build failed');
|
|
88
|
+
}
|
|
89
|
+
// 3. Consolidation (dedup, summarize, extract principles)
|
|
90
|
+
if (llmCall) {
|
|
91
|
+
try {
|
|
92
|
+
const { runConsolidation } = await import('./consolidation.js');
|
|
93
|
+
const result = await runConsolidation(store, llmCall);
|
|
94
|
+
logger.info(result, 'Consolidation cycle complete');
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
logger.warn({ err }, 'Consolidation failed');
|
|
98
|
+
}
|
|
99
|
+
// 4. Re-backfill embeddings for any new summary chunks from consolidation
|
|
100
|
+
try {
|
|
101
|
+
store.buildEmbeddings?.();
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
logger.warn({ err }, 'Post-consolidation embedding build failed');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// 5. Extraction log pruning
|
|
108
|
+
try {
|
|
109
|
+
const conn = store.conn;
|
|
110
|
+
if (conn) {
|
|
111
|
+
conn.prepare(`DELETE FROM memory_extractions
|
|
112
|
+
WHERE extracted_at < datetime('now', '-90 days')
|
|
113
|
+
AND status != 'active'`).run();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch { /* non-fatal */ }
|
|
117
|
+
logger.info({ durationMs: Date.now() - start }, 'Periodic maintenance complete');
|
|
118
|
+
};
|
|
119
|
+
return setInterval(runCycle, PERIODIC_INTERVAL_MS);
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=maintenance.js.map
|
package/dist/memory/store.js
CHANGED
|
@@ -748,9 +748,7 @@ export class MemoryStore {
|
|
|
748
748
|
const rows = this.conn
|
|
749
749
|
.prepare(`SELECT id, source_file, section, content, chunk_type, embedding, salience, agent_slug, updated_at, category, topic
|
|
750
750
|
FROM chunks
|
|
751
|
-
WHERE embedding IS NOT NULL
|
|
752
|
-
ORDER BY updated_at DESC
|
|
753
|
-
LIMIT 500`)
|
|
751
|
+
WHERE embedding IS NOT NULL`)
|
|
754
752
|
.all();
|
|
755
753
|
const scored = [];
|
|
756
754
|
for (const row of rows) {
|
|
@@ -1616,10 +1614,18 @@ export class MemoryStore {
|
|
|
1616
1614
|
*/
|
|
1617
1615
|
insertSummaryChunk(sourceFile, section, content) {
|
|
1618
1616
|
const hash = createHash('sha256').update(content).digest('hex').slice(0, 16);
|
|
1619
|
-
this.conn
|
|
1617
|
+
const result = this.conn
|
|
1620
1618
|
.prepare(`INSERT INTO chunks (source_file, section, content, chunk_type, content_hash, salience, consolidated)
|
|
1621
1619
|
VALUES (?, ?, ?, 'summary', ?, 0.8, 0)`)
|
|
1622
1620
|
.run(sourceFile, section, content, hash);
|
|
1621
|
+
// Immediately compute embedding so the summary is vector-searchable right away
|
|
1622
|
+
if (embeddingsModule.isReady()) {
|
|
1623
|
+
const vec = embeddingsModule.embed(content);
|
|
1624
|
+
if (vec) {
|
|
1625
|
+
this.conn.prepare('UPDATE chunks SET embedding = ? WHERE id = ?')
|
|
1626
|
+
.run(embeddingsModule.serializeEmbedding(vec), result.lastInsertRowid);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1623
1629
|
}
|
|
1624
1630
|
// ── SDR Operational Data ─────────────────────────────────────────
|
|
1625
1631
|
// -- Leads --
|
|
@@ -1912,17 +1918,17 @@ export class MemoryStore {
|
|
|
1912
1918
|
buildEmbeddings() {
|
|
1913
1919
|
// Gather all chunk contents for vocabulary building
|
|
1914
1920
|
const rows = this.conn
|
|
1915
|
-
.prepare('SELECT id, content FROM chunks
|
|
1921
|
+
.prepare('SELECT id, content FROM chunks')
|
|
1916
1922
|
.all();
|
|
1917
1923
|
if (rows.length === 0)
|
|
1918
1924
|
return { vocabSize: 0, backfilled: 0 };
|
|
1919
|
-
// Build vocabulary from corpus
|
|
1925
|
+
// Build vocabulary from entire corpus (including consolidated summaries)
|
|
1920
1926
|
embeddingsModule.buildVocab(rows.map((r) => r.content));
|
|
1921
1927
|
if (!embeddingsModule.isReady())
|
|
1922
1928
|
return { vocabSize: 0, backfilled: 0 };
|
|
1923
|
-
// Backfill embeddings for chunks that don't have one
|
|
1929
|
+
// Backfill embeddings for all chunks that don't have one
|
|
1924
1930
|
const missing = this.conn
|
|
1925
|
-
.prepare('SELECT id, content FROM chunks WHERE embedding IS NULL
|
|
1931
|
+
.prepare('SELECT id, content FROM chunks WHERE embedding IS NULL')
|
|
1926
1932
|
.all();
|
|
1927
1933
|
const updateStmt = this.conn.prepare('UPDATE chunks SET embedding = ? WHERE id = ?');
|
|
1928
1934
|
let backfilled = 0;
|