compact-agent 1.9.0 → 1.10.1

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.
@@ -0,0 +1,332 @@
1
+ /**
2
+ * MemPalace storage layer.
3
+ *
4
+ * Each store is a single JSON file written atomically (tmp file + rename)
5
+ * so a crashed write can't corrupt the existing state. The choice of JSON-
6
+ * over-SQLite is deliberate for v1: zero native dependencies, trivial to
7
+ * inspect by hand, no migration story needed for npm-published CLI.
8
+ *
9
+ * The Store interface is the swappable seam — when we outgrow JSON (>~10k
10
+ * drawers, slow search) we replace the implementation with SQLite/FTS5 or
11
+ * a vector store without touching callers.
12
+ */
13
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, renameSync, unlinkSync } from 'node:fs';
14
+ import { join, dirname } from 'node:path';
15
+ import { homedir } from 'node:os';
16
+ import { randomBytes } from 'node:crypto';
17
+ import { SCHEMA_VERSION } from './types.js';
18
+ import { searchDrawers } from './search.js';
19
+ // ── Paths ─────────────────────────────────────────────────
20
+ /** ~/.crowcoder/memory/store.json — cross-project knowledge */
21
+ export function globalStorePath() {
22
+ return join(homedir(), '.crowcoder', 'memory', 'store.json');
23
+ }
24
+ /** <cwd>/.crowcoder/memory/store.json — per-repo knowledge */
25
+ export function projectStorePath(cwd) {
26
+ return join(cwd, '.crowcoder', 'memory', 'store.json');
27
+ }
28
+ // ── ID generation ─────────────────────────────────────────
29
+ /**
30
+ * Time-ordered ID: hex timestamp + 8 random hex chars. Sorts naturally by
31
+ * creation time, no UUID library needed. ~96 bits of entropy total which
32
+ * is overkill for a single-user store but keeps collision chances at
33
+ * effective zero even across machines.
34
+ */
35
+ export function newId(prefix) {
36
+ const ts = Date.now().toString(16).padStart(11, '0');
37
+ const rand = randomBytes(4).toString('hex');
38
+ return `${prefix}_${ts}${rand}`;
39
+ }
40
+ // ── Atomic JSON read/write ────────────────────────────────
41
+ function readState(path) {
42
+ if (!existsSync(path)) {
43
+ return { schemaVersion: SCHEMA_VERSION, drawers: [], tunnels: [], triples: [] };
44
+ }
45
+ try {
46
+ const raw = readFileSync(path, 'utf-8');
47
+ const parsed = JSON.parse(raw);
48
+ // Defensive: future schema migrations would dispatch on parsed.schemaVersion here
49
+ return {
50
+ schemaVersion: parsed.schemaVersion ?? SCHEMA_VERSION,
51
+ drawers: parsed.drawers ?? [],
52
+ tunnels: parsed.tunnels ?? [],
53
+ triples: parsed.triples ?? [],
54
+ };
55
+ }
56
+ catch {
57
+ // Corrupted store — log and return empty so we don't crash the agent.
58
+ // The bad file is preserved alongside as .corrupt for forensic recovery.
59
+ try {
60
+ renameSync(path, path + '.corrupt-' + Date.now());
61
+ }
62
+ catch { /* noop */ }
63
+ return { schemaVersion: SCHEMA_VERSION, drawers: [], tunnels: [], triples: [] };
64
+ }
65
+ }
66
+ function writeState(path, state) {
67
+ mkdirSync(dirname(path), { recursive: true });
68
+ const tmp = path + '.tmp-' + process.pid;
69
+ writeFileSync(tmp, JSON.stringify(state, null, 2), 'utf-8');
70
+ try {
71
+ renameSync(tmp, path);
72
+ }
73
+ catch (e) {
74
+ // On some Windows filesystems renaming over an existing file can fail.
75
+ // Fall back to unlink + rename.
76
+ try {
77
+ unlinkSync(path);
78
+ }
79
+ catch { /* noop */ }
80
+ renameSync(tmp, path);
81
+ }
82
+ }
83
+ // ── Store class ───────────────────────────────────────────
84
+ /**
85
+ * A single-file MemPalace store backed by JSON. Mutations are immediately
86
+ * persisted to disk — there's no in-memory cache to flush. Trades a small
87
+ * amount of throughput for crash safety, which matters more for a memory
88
+ * system.
89
+ */
90
+ export class JsonStore {
91
+ path;
92
+ scope;
93
+ constructor(path, scope) {
94
+ this.path = path;
95
+ this.scope = scope;
96
+ }
97
+ read() { return readState(this.path); }
98
+ write(s) { writeState(this.path, s); }
99
+ // ── Drawers ───────────────────────────────────────────
100
+ addDrawer(input) {
101
+ const now = new Date().toISOString();
102
+ const drawer = {
103
+ id: newId('drw'),
104
+ createdAt: now,
105
+ updatedAt: now,
106
+ scope: this.scope,
107
+ ...input,
108
+ // Defensive normalization
109
+ tags: (input.tags || []).map((t) => t.toLowerCase().trim()).filter(Boolean),
110
+ importance: clamp01(input.importance ?? 0.5),
111
+ wing: input.wing.toLowerCase().trim(),
112
+ room: input.room.toLowerCase().trim(),
113
+ };
114
+ const state = this.read();
115
+ state.drawers.push(drawer);
116
+ this.write(state);
117
+ return drawer;
118
+ }
119
+ getDrawer(id) {
120
+ return this.read().drawers.find((d) => d.id === id) || null;
121
+ }
122
+ updateDrawer(id, patch) {
123
+ const state = this.read();
124
+ const idx = state.drawers.findIndex((d) => d.id === id);
125
+ if (idx < 0)
126
+ return null;
127
+ const updated = {
128
+ ...state.drawers[idx],
129
+ ...patch,
130
+ updatedAt: new Date().toISOString(),
131
+ tags: patch.tags
132
+ ? patch.tags.map((t) => t.toLowerCase().trim()).filter(Boolean)
133
+ : state.drawers[idx].tags,
134
+ importance: patch.importance !== undefined ? clamp01(patch.importance) : state.drawers[idx].importance,
135
+ };
136
+ state.drawers[idx] = updated;
137
+ this.write(state);
138
+ return updated;
139
+ }
140
+ deleteDrawer(id) {
141
+ const state = this.read();
142
+ const before = state.drawers.length;
143
+ state.drawers = state.drawers.filter((d) => d.id !== id);
144
+ // Cascade: drop tunnels touching this drawer + triples sourced from it
145
+ state.tunnels = state.tunnels.filter((t) => t.fromDrawerId !== id && t.toDrawerId !== id);
146
+ state.triples = state.triples.filter((t) => t.sourceDrawerId !== id);
147
+ const removed = state.drawers.length < before;
148
+ if (removed)
149
+ this.write(state);
150
+ return removed;
151
+ }
152
+ listDrawers(filter = {}) {
153
+ let drawers = this.read().drawers;
154
+ if (filter.wing)
155
+ drawers = drawers.filter((d) => d.wing === filter.wing.toLowerCase());
156
+ if (filter.room)
157
+ drawers = drawers.filter((d) => d.room === filter.room.toLowerCase());
158
+ if (filter.tag)
159
+ drawers = drawers.filter((d) => d.tags.includes(filter.tag.toLowerCase()));
160
+ return drawers;
161
+ }
162
+ // ── Wings + Rooms (derived views) ─────────────────────
163
+ listWings() {
164
+ const drawers = this.read().drawers;
165
+ const byWing = new Map();
166
+ for (const d of drawers) {
167
+ const entry = byWing.get(d.wing) ?? { rooms: new Set(), count: 0 };
168
+ entry.rooms.add(d.room);
169
+ entry.count++;
170
+ byWing.set(d.wing, entry);
171
+ }
172
+ return [...byWing.entries()]
173
+ .map(([name, v]) => ({ name, rooms: [...v.rooms].sort(), drawerCount: v.count }))
174
+ .sort((a, b) => a.name.localeCompare(b.name));
175
+ }
176
+ listRooms(wing) {
177
+ const drawers = this.read().drawers;
178
+ const filtered = wing ? drawers.filter((d) => d.wing === wing.toLowerCase()) : drawers;
179
+ const byRoom = new Map();
180
+ for (const d of filtered) {
181
+ const key = `${d.wing}/${d.room}`;
182
+ const entry = byRoom.get(key) ?? { wing: d.wing, count: 0, lastTouched: d.updatedAt };
183
+ entry.count++;
184
+ if (d.updatedAt > entry.lastTouched)
185
+ entry.lastTouched = d.updatedAt;
186
+ byRoom.set(key, entry);
187
+ }
188
+ return [...byRoom.entries()]
189
+ .map(([key, v]) => ({
190
+ wing: v.wing,
191
+ name: key.split('/')[1],
192
+ drawerCount: v.count,
193
+ lastTouched: v.lastTouched,
194
+ }))
195
+ .sort((a, b) => b.lastTouched.localeCompare(a.lastTouched));
196
+ }
197
+ // ── Tunnels (drawer relationships) ────────────────────
198
+ addTunnel(fromDrawerId, toDrawerId, relation) {
199
+ const tunnel = {
200
+ id: newId('tun'),
201
+ fromDrawerId,
202
+ toDrawerId,
203
+ relation: relation.toLowerCase().trim(),
204
+ createdAt: new Date().toISOString(),
205
+ scope: this.scope,
206
+ };
207
+ const state = this.read();
208
+ state.tunnels.push(tunnel);
209
+ this.write(state);
210
+ return tunnel;
211
+ }
212
+ /**
213
+ * Find all tunnels touching a drawer, in either direction. Useful for
214
+ * "what is this drawer related to?" queries.
215
+ */
216
+ findTunnels(drawerId) {
217
+ const tunnels = this.read().tunnels;
218
+ return {
219
+ outgoing: tunnels.filter((t) => t.fromDrawerId === drawerId),
220
+ incoming: tunnels.filter((t) => t.toDrawerId === drawerId),
221
+ };
222
+ }
223
+ /**
224
+ * Walk outgoing tunnels from a start drawer for up to maxDepth hops,
225
+ * returning every drawer reached and the path that got us there.
226
+ * Bounded by visited-set so cycles don't loop forever.
227
+ */
228
+ traverse(startId, maxDepth = 3) {
229
+ const state = this.read();
230
+ const drawerById = new Map(state.drawers.map((d) => [d.id, d]));
231
+ const tunnelsByFrom = new Map();
232
+ for (const t of state.tunnels) {
233
+ const arr = tunnelsByFrom.get(t.fromDrawerId) ?? [];
234
+ arr.push(t);
235
+ tunnelsByFrom.set(t.fromDrawerId, arr);
236
+ }
237
+ const visited = new Set();
238
+ const results = [];
239
+ const queue = [{ id: startId, depth: 0, via: [] }];
240
+ while (queue.length > 0) {
241
+ const cur = queue.shift();
242
+ if (visited.has(cur.id))
243
+ continue;
244
+ visited.add(cur.id);
245
+ const drawer = drawerById.get(cur.id);
246
+ if (drawer && cur.depth > 0) {
247
+ results.push({ drawer, depth: cur.depth, via: cur.via });
248
+ }
249
+ if (cur.depth >= maxDepth)
250
+ continue;
251
+ const outgoing = tunnelsByFrom.get(cur.id) ?? [];
252
+ for (const t of outgoing) {
253
+ if (!visited.has(t.toDrawerId)) {
254
+ queue.push({ id: t.toDrawerId, depth: cur.depth + 1, via: [...cur.via, t.relation] });
255
+ }
256
+ }
257
+ }
258
+ return results;
259
+ }
260
+ deleteTunnel(id) {
261
+ const state = this.read();
262
+ const before = state.tunnels.length;
263
+ state.tunnels = state.tunnels.filter((t) => t.id !== id);
264
+ const removed = state.tunnels.length < before;
265
+ if (removed)
266
+ this.write(state);
267
+ return removed;
268
+ }
269
+ // ── Knowledge graph triples ───────────────────────────
270
+ addTriple(t) {
271
+ const triple = {
272
+ ...t,
273
+ id: newId('kg'),
274
+ createdAt: new Date().toISOString(),
275
+ scope: this.scope,
276
+ confidence: clamp01(t.confidence ?? 1.0),
277
+ };
278
+ const state = this.read();
279
+ state.triples.push(triple);
280
+ this.write(state);
281
+ return triple;
282
+ }
283
+ /**
284
+ * Query triples with optional s/p/o filters. Any field left undefined
285
+ * acts as a wildcard. Matching is case-insensitive equality on each
286
+ * specified field.
287
+ */
288
+ queryTriples(q) {
289
+ const triples = this.read().triples;
290
+ const lc = (s) => s?.toLowerCase();
291
+ const s = lc(q.subject);
292
+ const p = lc(q.predicate);
293
+ const o = lc(q.object);
294
+ return triples.filter((t) => (s === undefined || t.subject.toLowerCase() === s) &&
295
+ (p === undefined || t.predicate.toLowerCase() === p) &&
296
+ (o === undefined || t.object.toLowerCase() === o));
297
+ }
298
+ /** Most-recent triples first. For "what have I been learning?" views. */
299
+ recentTriples(limit = 20) {
300
+ return [...this.read().triples]
301
+ .sort((a, b) => b.createdAt.localeCompare(a.createdAt))
302
+ .slice(0, limit);
303
+ }
304
+ // ── Search ────────────────────────────────────────────
305
+ search(query, opts = {}) {
306
+ const drawers = this.read().drawers;
307
+ return searchDrawers(drawers, query, opts);
308
+ }
309
+ // ── Stats ─────────────────────────────────────────────
310
+ stats() {
311
+ const state = this.read();
312
+ const wings = new Set(state.drawers.map((d) => d.wing));
313
+ const rooms = new Set(state.drawers.map((d) => `${d.wing}/${d.room}`));
314
+ return {
315
+ drawers: state.drawers.length,
316
+ tunnels: state.tunnels.length,
317
+ triples: state.triples.length,
318
+ wings: wings.size,
319
+ rooms: rooms.size,
320
+ };
321
+ }
322
+ }
323
+ function clamp01(n) {
324
+ if (Number.isNaN(n))
325
+ return 0.5;
326
+ if (n < 0)
327
+ return 0;
328
+ if (n > 1)
329
+ return 1;
330
+ return n;
331
+ }
332
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/mempalace/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACr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EAAE;QAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC;QACpC,OAAO,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,yDAAyD;IACzD,KAAK;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACxD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACvE,OAAO;YACL,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;YAC7B,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;YAC7B,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;YAC7B,KAAK,EAAE,KAAK,CAAC,IAAI;YACjB,KAAK,EAAE,KAAK,CAAC,IAAI;SAClB,CAAC;IACJ,CAAC;CACF;AAED,SAAS,OAAO,CAAC,CAAS;IACxB,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IAChC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * MemPalace data model — TypeScript port of the core MemPalace concepts.
3
+ *
4
+ * Mental model:
5
+ *
6
+ * Wing ─ a top-level domain ("projects", "people", "code", "wisdom")
7
+ * Room ─ a category inside a wing ("crowcoder", "abc-reborn", ...)
8
+ * Drawer ─ an individual memory item: a chunk of text + tags + metadata
9
+ * Tunnel ─ a directed link between two drawers, typed by relation
10
+ * Triple ─ a knowledge-graph fact: (subject, predicate, object)
11
+ *
12
+ * Drawers are the atomic unit of memory. Wings + rooms give them addressable
13
+ * structure. Tunnels and KG triples give them relational structure.
14
+ *
15
+ * Two stores live side-by-side:
16
+ * GLOBAL ~/.crowcoder/memory/ cross-project knowledge (user prefs,
17
+ * recurring patterns, skills)
18
+ * PROJECT <cwd>/.crowcoder/memory/ this-codebase-specific (e.g. "build
19
+ * is broken because X", "the queue lives
20
+ * in services/queue/...")
21
+ *
22
+ * The agent picks which store to query based on the request. User-modeling
23
+ * queries hit global; codebase queries hit project. Search APIs accept a
24
+ * Scope hint or 'both' to search across.
25
+ */
26
+ /**
27
+ * Which memory store an operation targets.
28
+ *
29
+ * 'global' — ~/.crowcoder/memory/ (cross-project)
30
+ * 'project' — <cwd>/.crowcoder/memory/ (per-repo)
31
+ * 'both' — search both; writes pick based on content (global for user
32
+ * preferences, project for codebase facts)
33
+ */
34
+ export type Scope = 'global' | 'project' | 'both';
35
+ /**
36
+ * A drawer is one memory item — a chunk of text living at wing/room. Tags
37
+ * are free-form lowercase strings used for filtering. Importance is a 0–1
38
+ * heuristic the agent or user can set to bias search ordering.
39
+ */
40
+ export interface Drawer {
41
+ id: string;
42
+ wing: string;
43
+ room: string;
44
+ content: string;
45
+ tags: string[];
46
+ importance: number;
47
+ createdAt: string;
48
+ updatedAt: string;
49
+ scope: Scope;
50
+ sourceSessionId?: string;
51
+ }
52
+ /**
53
+ * Convenience metadata about a wing — populated by `listWings` for UI/
54
+ * status output. Not stored separately; derived from drawer counts.
55
+ */
56
+ export interface WingMeta {
57
+ name: string;
58
+ rooms: string[];
59
+ drawerCount: number;
60
+ }
61
+ /**
62
+ * Same for rooms.
63
+ */
64
+ export interface RoomMeta {
65
+ wing: string;
66
+ name: string;
67
+ drawerCount: number;
68
+ lastTouched: string;
69
+ }
70
+ /**
71
+ * A tunnel is a directed link from one drawer to another with a labelled
72
+ * relation. Use cases:
73
+ * - "drawer A inspired drawer B" (relation: "inspired")
74
+ * - "drawer A supersedes drawer B" (relation: "supersedes")
75
+ * - "drawer A is part of drawer B's project" (relation: "in-project")
76
+ *
77
+ * Bidirectional traversal is supported by following tunnels in reverse.
78
+ */
79
+ export interface Tunnel {
80
+ id: string;
81
+ fromDrawerId: string;
82
+ toDrawerId: string;
83
+ relation: string;
84
+ createdAt: string;
85
+ scope: Scope;
86
+ }
87
+ /**
88
+ * A knowledge-graph triple — semantic-web style. Stored separately from
89
+ * drawers because triples express *facts* (small, atomic, queryable in
90
+ * aggregate) whereas drawers express *content* (larger, narrative).
91
+ *
92
+ * Example: ("rsfit", "owns", "Crowcoder") or ("compact-agent", "uses",
93
+ * "OpenRouter").
94
+ */
95
+ export interface KGTriple {
96
+ id: string;
97
+ subject: string;
98
+ predicate: string;
99
+ object: string;
100
+ confidence: number;
101
+ sourceDrawerId?: string;
102
+ sourceSessionId?: string;
103
+ createdAt: string;
104
+ scope: Scope;
105
+ }
106
+ /**
107
+ * Internal disk schema. One JSON file per store containing all drawers,
108
+ * tunnels, and triples. Simple, atomic-write-via-rename safe.
109
+ *
110
+ * For very large stores (>10k drawers) this approach will get slow; the
111
+ * intent is to swap to SQLite/FTS5 later behind the same Store interface.
112
+ */
113
+ export interface StoreState {
114
+ schemaVersion: number;
115
+ drawers: Drawer[];
116
+ tunnels: Tunnel[];
117
+ triples: KGTriple[];
118
+ }
119
+ export declare const SCHEMA_VERSION = 1;
120
+ /**
121
+ * Search options shared across query APIs.
122
+ */
123
+ export interface SearchOptions {
124
+ scope?: Scope;
125
+ wing?: string;
126
+ room?: string;
127
+ tags?: string[];
128
+ limit?: number;
129
+ minImportance?: number;
130
+ }
131
+ /**
132
+ * A scored search hit — the drawer plus the relevance score the search
133
+ * function computed. Higher = more relevant. Score is unitless; only
134
+ * meaningful for ordering, not absolute comparison.
135
+ */
136
+ export interface SearchHit {
137
+ drawer: Drawer;
138
+ score: number;
139
+ matchedFields: ('content' | 'tags' | 'wing' | 'room')[];
140
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * MemPalace data model — TypeScript port of the core MemPalace concepts.
3
+ *
4
+ * Mental model:
5
+ *
6
+ * Wing ─ a top-level domain ("projects", "people", "code", "wisdom")
7
+ * Room ─ a category inside a wing ("crowcoder", "abc-reborn", ...)
8
+ * Drawer ─ an individual memory item: a chunk of text + tags + metadata
9
+ * Tunnel ─ a directed link between two drawers, typed by relation
10
+ * Triple ─ a knowledge-graph fact: (subject, predicate, object)
11
+ *
12
+ * Drawers are the atomic unit of memory. Wings + rooms give them addressable
13
+ * structure. Tunnels and KG triples give them relational structure.
14
+ *
15
+ * Two stores live side-by-side:
16
+ * GLOBAL ~/.crowcoder/memory/ cross-project knowledge (user prefs,
17
+ * recurring patterns, skills)
18
+ * PROJECT <cwd>/.crowcoder/memory/ this-codebase-specific (e.g. "build
19
+ * is broken because X", "the queue lives
20
+ * in services/queue/...")
21
+ *
22
+ * The agent picks which store to query based on the request. User-modeling
23
+ * queries hit global; codebase queries hit project. Search APIs accept a
24
+ * Scope hint or 'both' to search across.
25
+ */
26
+ export const SCHEMA_VERSION = 1;
27
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/mempalace/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AA6GH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC"}
@@ -96,6 +96,34 @@ ${fileList ? `- Files in cwd: ${fileList}` : ''}
96
96
  # Available Tools (these and ONLY these — do not invent tool names)
97
97
  ${buildToolList()}
98
98
 
99
+ ${config.memory?.enabled !== false ? `# Memory (MemPalace) — when to use the memory_* tools
100
+
101
+ This agent has a persistent memory subsystem with two scopes:
102
+ - **global** memory at ~/.crowcoder/memory/ — cross-project: user preferences,
103
+ style choices, recurring patterns, identity
104
+ - **project** memory at <cwd>/.crowcoder/memory/ — this-codebase-specific:
105
+ landmarks ("auth lives in src/auth"), gotchas, decisions
106
+
107
+ You have these memory tools available:
108
+ - **memory_search** — ALWAYS check before proposing something the user may
109
+ have told you before. If a search hits, recall + use the existing fact
110
+ instead of asking again.
111
+ - **memory_recall** — fetch a specific drawer's full content by id
112
+ - **memory_add** — save a NEW drawer when the user states a durable fact:
113
+ a preference ("I always use vitest"), a codebase landmark ("the queue
114
+ lives in services/queue/"), or a lesson worth keeping across sessions.
115
+ Use scope:"auto" by default — the system infers global vs project from
116
+ content signals.
117
+ - **memory_link** — connect related drawers (sparingly; only when the
118
+ relationship will be useful for later traversal)
119
+ - **memory_list** — orient yourself: what wings/rooms exist
120
+ - **memory_fact_add / memory_fact_query** — for atomic (subject, predicate,
121
+ object) facts you want to query in aggregate later
122
+
123
+ Be conservative — don't write a drawer for every passing comment. Write
124
+ when the user makes a STATEMENT OF FACT or PREFERENCE that you'd benefit
125
+ from knowing in a future session. Quality > quantity.` : ''}
126
+
99
127
  # Turn semantics — read carefully
100
128
  Each user message is an INDEPENDENT request. Conversation history is a record
101
129
  of past requests that are ALREADY DONE. Specifically:
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../src/system-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAErD,OAAO,EAAE,qBAAqB,EAAa,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,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;UACT,IAAI;EACZ,QAAQ,CAAC,CAAC,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE;;;EAG7C,aAAa,EAAE;;EAEf,MAAM,CAAC,MAAM,EAAE,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;sDA0BiB,CAAC,CAAC,CAAC,EAAE;;;;;;;;;;;;;;;;;;;;;;;+VAuBoS,KAAK;;;;;0BAK1U,KAAK;;;;;;;;;;;;;;EAc7B,YAAY,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,aAAa,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,YAAY;CAC1G,CAAC;AACF,CAAC"}
@@ -9,11 +9,19 @@ import { WebSearchTool } from './web-search.js';
9
9
  import { ListDirTool } from './list-dir.js';
10
10
  import { StitchTool } from './stitch.js';
11
11
  import { stitchConfigured } from '../stitch.js';
12
+ import { MEMORY_TOOLS } from './memory.js';
13
+ import { isMemoryEnabled } from '../mempalace/index.js';
12
14
  // Stitch is only listed in the tool registry when configured — otherwise
13
15
  // free models hallucinate calls to it and waste turns on auth errors.
14
16
  const OPTIONAL_TOOLS = [];
15
17
  if (stitchConfigured())
16
18
  OPTIONAL_TOOLS.push(StitchTool);
19
+ // MemPalace memory tools — only registered when the user enabled the
20
+ // feature (default true). Disabling it during the setup wizard or via
21
+ // /memory disable removes them from the registry entirely so the model
22
+ // doesn't see them at all (no wasted tokens advertising tools it can't
23
+ // use, no risk of the model hallucinating memory calls).
24
+ const MEMORY_TOOLS_IF_ENABLED = isMemoryEnabled() ? MEMORY_TOOLS : [];
17
25
  export const ALL_TOOLS = [
18
26
  BashTool,
19
27
  ReadTool,
@@ -24,6 +32,7 @@ export const ALL_TOOLS = [
24
32
  ListDirTool,
25
33
  WebFetchTool,
26
34
  WebSearchTool,
35
+ ...MEMORY_TOOLS_IF_ENABLED,
27
36
  ...OPTIONAL_TOOLS,
28
37
  ];
29
38
  export function getToolNames() {
@@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,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * MemPalace-backed memory tools the agent can call.
3
+ *
4
+ * Surface (kept small, action-oriented):
5
+ * memory_search read full-text search across global + project stores
6
+ * memory_recall read fetch a specific drawer by id, plus its tunnels
7
+ * memory_add write create a new drawer (or save a fact via KG)
8
+ * memory_link write tunnel between two drawers
9
+ * memory_list read inventory: wings/rooms/recent drawers
10
+ *
11
+ * The agent should reach for these whenever the user mentions facts that
12
+ * are worth keeping across sessions ("I always use vitest, never jest"),
13
+ * codebase landmarks ("the auth flow lives in src/auth/oauth.ts"), or
14
+ * lessons learned during this turn that future sessions would benefit
15
+ * from. The system prompt nudges this — see src/system-prompt.ts.
16
+ *
17
+ * All write tools are marked isDestructive: false because they only
18
+ * append to a local file — no network, no external state. They still
19
+ * require permission in `ask` mode by default but don't trigger the
20
+ * destructive-action verbal-confirm path.
21
+ */
22
+ import type { Tool } from './types.js';
23
+ export declare const MemoryAddTool: Tool;
24
+ export declare const MemorySearchTool: Tool;
25
+ export declare const MemoryRecallTool: Tool;
26
+ export declare const MemoryLinkTool: Tool;
27
+ export declare const MemoryListTool: Tool;
28
+ export declare const MemoryFactAddTool: Tool;
29
+ export declare const MemoryFactQueryTool: Tool;
30
+ export declare const MEMORY_TOOLS: Tool[];