@cereworker/hippocampus 0.2.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/LICENSE +21 -0
- package/dist/curator.d.ts +29 -0
- package/dist/curator.d.ts.map +1 -0
- package/dist/curator.js +185 -0
- package/dist/curator.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/store.d.ts +30 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +124 -0
- package/dist/store.js.map +1 -0
- package/dist/tools.d.ts +37 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +57 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Producible
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HippocampusStore } from './store.js';
|
|
2
|
+
import type { TrainingPair, CurationResult } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for generating text from the Cerebrum.
|
|
5
|
+
* Kept minimal so the curator doesn't depend on the full CerebrumProvider.
|
|
6
|
+
*/
|
|
7
|
+
export interface TextGenerator {
|
|
8
|
+
generate(prompt: string): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
export declare class HippocampusCurator {
|
|
11
|
+
private store;
|
|
12
|
+
private generator;
|
|
13
|
+
constructor(store: HippocampusStore, generator: TextGenerator);
|
|
14
|
+
/**
|
|
15
|
+
* Curate memories for fine-tuning.
|
|
16
|
+
* Reads uncurated content, sends to Cerebrum for review,
|
|
17
|
+
* and saves approved training pairs to pending.jsonl.
|
|
18
|
+
*/
|
|
19
|
+
curate(): Promise<CurationResult>;
|
|
20
|
+
/** Read pending training pairs that haven't been consumed by fine-tuning yet. */
|
|
21
|
+
getPendingPairs(): TrainingPair[];
|
|
22
|
+
/** Mark pending pairs as consumed (move to consumed/YYYY-MM-DD.jsonl). */
|
|
23
|
+
markConsumed(): void;
|
|
24
|
+
private parseResponse;
|
|
25
|
+
private appendPending;
|
|
26
|
+
private readMarker;
|
|
27
|
+
private writeMarker;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=curator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curator.d.ts","sourceRoot":"","sources":["../src/curator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAqC/D;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3C;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,SAAS,CAAgB;gBAErB,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,aAAa;IAK7D;;;;OAIG;IACG,MAAM,IAAI,OAAO,CAAC,cAAc,CAAC;IA0DvC,iFAAiF;IACjF,eAAe,IAAI,YAAY,EAAE;IAmBjC,0EAA0E;IAC1E,YAAY,IAAI,IAAI;IAoBpB,OAAO,CAAC,aAAa;IAqCrB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,WAAW;CAIpB"}
|
package/dist/curator.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const CURATED_MARKER = '.curated-marker';
|
|
4
|
+
const PENDING_FILE = 'pending.jsonl';
|
|
5
|
+
const CONSUMED_DIR = 'consumed';
|
|
6
|
+
const CURATION_PROMPT = `You are a memory curator for CereWorker, an AI agent. Your job is to review the agent's temporary memories and decide which contain **durable knowledge** worth permanently learning through fine-tuning.
|
|
7
|
+
|
|
8
|
+
## Instructions
|
|
9
|
+
|
|
10
|
+
Review the memories below. For each piece of knowledge that is:
|
|
11
|
+
- A user preference, decision, or established fact
|
|
12
|
+
- A technical pattern, convention, or architecture decision
|
|
13
|
+
- A recurring workflow or process
|
|
14
|
+
- Important context that would be useful across many future sessions
|
|
15
|
+
|
|
16
|
+
Create a training pair in instruction/response format. Skip anything that is:
|
|
17
|
+
- Ephemeral session details (timestamps, one-off tasks)
|
|
18
|
+
- Already obvious or common knowledge
|
|
19
|
+
- Too vague to be useful
|
|
20
|
+
- Contradicted by later memories
|
|
21
|
+
|
|
22
|
+
## Output Format
|
|
23
|
+
|
|
24
|
+
Respond with a JSON array of objects. Each object must have:
|
|
25
|
+
- "instruction": a question or prompt that would naturally elicit this knowledge
|
|
26
|
+
- "response": the factual answer based on the memory
|
|
27
|
+
- "source": the filename the knowledge came from
|
|
28
|
+
|
|
29
|
+
If no memories are worth fine-tuning, respond with an empty array: []
|
|
30
|
+
|
|
31
|
+
Respond ONLY with the JSON array, nothing else.
|
|
32
|
+
|
|
33
|
+
## Memories to Review
|
|
34
|
+
|
|
35
|
+
`;
|
|
36
|
+
export class HippocampusCurator {
|
|
37
|
+
store;
|
|
38
|
+
generator;
|
|
39
|
+
constructor(store, generator) {
|
|
40
|
+
this.store = store;
|
|
41
|
+
this.generator = generator;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Curate memories for fine-tuning.
|
|
45
|
+
* Reads uncurated content, sends to Cerebrum for review,
|
|
46
|
+
* and saves approved training pairs to pending.jsonl.
|
|
47
|
+
*/
|
|
48
|
+
async curate() {
|
|
49
|
+
const errors = [];
|
|
50
|
+
const lastCurated = this.readMarker();
|
|
51
|
+
const allFiles = this.store.listAll();
|
|
52
|
+
// Gather uncurated content
|
|
53
|
+
const uncurated = [];
|
|
54
|
+
for (const file of allFiles) {
|
|
55
|
+
const content = this.store.readFile(file);
|
|
56
|
+
if (!content)
|
|
57
|
+
continue;
|
|
58
|
+
// Skip if file hasn't changed since last curation
|
|
59
|
+
if (lastCurated && file !== 'MEMORY.md') {
|
|
60
|
+
const dateMatch = file.match(/^(\d{4}-\d{2}-\d{2})/);
|
|
61
|
+
if (dateMatch && dateMatch[1] <= lastCurated)
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
uncurated.push({ filename: file, content });
|
|
65
|
+
}
|
|
66
|
+
if (uncurated.length === 0) {
|
|
67
|
+
return { pairs: [], skipped: 0, errors: [] };
|
|
68
|
+
}
|
|
69
|
+
// Build prompt with memory content
|
|
70
|
+
const memoriesText = uncurated
|
|
71
|
+
.map((m) => `### ${m.filename}\n\n${m.content}`)
|
|
72
|
+
.join('\n\n---\n\n');
|
|
73
|
+
const prompt = CURATION_PROMPT + memoriesText;
|
|
74
|
+
// Call Cerebrum
|
|
75
|
+
let responseText;
|
|
76
|
+
try {
|
|
77
|
+
responseText = await this.generator.generate(prompt);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
errors.push(`Cerebrum call failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
81
|
+
return { pairs: [], skipped: uncurated.length, errors };
|
|
82
|
+
}
|
|
83
|
+
// Parse response
|
|
84
|
+
const pairs = this.parseResponse(responseText, errors);
|
|
85
|
+
// Save pending pairs
|
|
86
|
+
if (pairs.length > 0) {
|
|
87
|
+
this.appendPending(pairs);
|
|
88
|
+
}
|
|
89
|
+
// Update marker
|
|
90
|
+
this.writeMarker();
|
|
91
|
+
return {
|
|
92
|
+
pairs,
|
|
93
|
+
skipped: uncurated.length - pairs.length,
|
|
94
|
+
errors,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Read pending training pairs that haven't been consumed by fine-tuning yet. */
|
|
98
|
+
getPendingPairs() {
|
|
99
|
+
const path = join(this.store.finetuneDir, PENDING_FILE);
|
|
100
|
+
if (!existsSync(path))
|
|
101
|
+
return [];
|
|
102
|
+
const content = readFileSync(path, 'utf-8').trim();
|
|
103
|
+
if (!content)
|
|
104
|
+
return [];
|
|
105
|
+
return content
|
|
106
|
+
.split('\n')
|
|
107
|
+
.map((line) => {
|
|
108
|
+
try {
|
|
109
|
+
return JSON.parse(line);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
.filter((p) => p !== null);
|
|
116
|
+
}
|
|
117
|
+
/** Mark pending pairs as consumed (move to consumed/YYYY-MM-DD.jsonl). */
|
|
118
|
+
markConsumed() {
|
|
119
|
+
const pendingPath = join(this.store.finetuneDir, PENDING_FILE);
|
|
120
|
+
if (!existsSync(pendingPath))
|
|
121
|
+
return;
|
|
122
|
+
const consumedDir = join(this.store.finetuneDir, CONSUMED_DIR);
|
|
123
|
+
if (!existsSync(consumedDir)) {
|
|
124
|
+
mkdirSync(consumedDir, { recursive: true });
|
|
125
|
+
}
|
|
126
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
127
|
+
const consumedPath = join(consumedDir, `${date}.jsonl`);
|
|
128
|
+
// Append to consumed file (in case multiple curations happen in one day)
|
|
129
|
+
const content = readFileSync(pendingPath, 'utf-8');
|
|
130
|
+
writeFileSync(consumedPath, content, { flag: 'a' });
|
|
131
|
+
// Clear pending
|
|
132
|
+
writeFileSync(pendingPath, '', 'utf-8');
|
|
133
|
+
}
|
|
134
|
+
parseResponse(response, errors) {
|
|
135
|
+
let text = response.trim();
|
|
136
|
+
// Handle markdown code blocks
|
|
137
|
+
if (text.startsWith('```')) {
|
|
138
|
+
text = text.split('\n', 1)[0] ? text.split('\n').slice(1).join('\n') : text.slice(3);
|
|
139
|
+
if (text.endsWith('```')) {
|
|
140
|
+
text = text.slice(0, -3);
|
|
141
|
+
}
|
|
142
|
+
text = text.trim();
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const parsed = JSON.parse(text);
|
|
146
|
+
if (!Array.isArray(parsed)) {
|
|
147
|
+
errors.push('Cerebrum response is not an array');
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
const now = Date.now();
|
|
151
|
+
return parsed
|
|
152
|
+
.filter((item) => {
|
|
153
|
+
if (typeof item !== 'object' || !item)
|
|
154
|
+
return false;
|
|
155
|
+
return typeof item.instruction === 'string' && typeof item.response === 'string';
|
|
156
|
+
})
|
|
157
|
+
.map((item) => ({
|
|
158
|
+
instruction: item.instruction,
|
|
159
|
+
response: item.response,
|
|
160
|
+
source: item.source ?? 'unknown',
|
|
161
|
+
createdAt: now,
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
errors.push(`Failed to parse Cerebrum response: ${err instanceof Error ? err.message : String(err)}`);
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
appendPending(pairs) {
|
|
170
|
+
const path = join(this.store.finetuneDir, PENDING_FILE);
|
|
171
|
+
const lines = pairs.map((p) => JSON.stringify(p)).join('\n') + '\n';
|
|
172
|
+
writeFileSync(path, lines, { flag: 'a' });
|
|
173
|
+
}
|
|
174
|
+
readMarker() {
|
|
175
|
+
const path = join(this.store.directory, CURATED_MARKER);
|
|
176
|
+
if (!existsSync(path))
|
|
177
|
+
return null;
|
|
178
|
+
return readFileSync(path, 'utf-8').trim();
|
|
179
|
+
}
|
|
180
|
+
writeMarker() {
|
|
181
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
182
|
+
writeFileSync(join(this.store.directory, CURATED_MARKER), date, 'utf-8');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=curator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curator.js","sourceRoot":"","sources":["../src/curator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAc,SAAS,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,MAAM,cAAc,GAAG,iBAAiB,CAAC;AACzC,MAAM,YAAY,GAAG,eAAe,CAAC;AACrC,MAAM,YAAY,GAAG,UAAU,CAAC;AAEhC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BvB,CAAC;AAUF,MAAM,OAAO,kBAAkB;IACrB,KAAK,CAAmB;IACxB,SAAS,CAAgB;IAEjC,YAAY,KAAuB,EAAE,SAAwB;QAC3D,IAAI,CAAC,KAAK,GAA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HippocampusStore } from './store.js';
|
|
2
|
+
export { createMemoryTools, memoryReadParameters, memoryWriteParameters, memoryLogParameters, memorySearchParameters, } from './tools.js';
|
|
3
|
+
export { HippocampusCurator, type TextGenerator } from './curator.js';
|
|
4
|
+
export type { TrainingPair, CurationResult, MemoryEntry } from './types.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACtE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { HippocampusStore } from './store.js';
|
|
2
|
+
export { createMemoryTools, memoryReadParameters, memoryWriteParameters, memoryLogParameters, memorySearchParameters, } from './tools.js';
|
|
3
|
+
export { HippocampusCurator } from './curator.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAsB,MAAM,cAAc,CAAC"}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MemoryEntry } from './types.js';
|
|
2
|
+
export declare class HippocampusStore {
|
|
3
|
+
private readonly dir;
|
|
4
|
+
constructor(directory?: string);
|
|
5
|
+
private ensureDir;
|
|
6
|
+
private ensureSubdir;
|
|
7
|
+
get directory(): string;
|
|
8
|
+
/** Read the main MEMORY.md file. */
|
|
9
|
+
readMemory(): string;
|
|
10
|
+
/** Write/replace the main MEMORY.md file. */
|
|
11
|
+
writeMemory(content: string): void;
|
|
12
|
+
/** Append content to today's daily log (YYYY-MM-DD.md). */
|
|
13
|
+
appendDailyLog(content: string): void;
|
|
14
|
+
/** Read recent daily logs. */
|
|
15
|
+
readDailyLogs(days?: number): MemoryEntry[];
|
|
16
|
+
/** List all daily log files (date strings, sorted). */
|
|
17
|
+
listLogFiles(): string[];
|
|
18
|
+
/** List all files in the memory directory. */
|
|
19
|
+
listAll(): string[];
|
|
20
|
+
/** Read a specific file from the memory directory. */
|
|
21
|
+
readFile(filename: string): string | null;
|
|
22
|
+
/** Search across all memory files for a text pattern. */
|
|
23
|
+
search(query: string): MemoryEntry[];
|
|
24
|
+
/** Delete daily logs older than maxDays. */
|
|
25
|
+
pruneOldLogs(maxDays: number): number;
|
|
26
|
+
/** Get the finetune subdirectory path. */
|
|
27
|
+
get finetuneDir(): string;
|
|
28
|
+
private todayDate;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;gBAEjB,SAAS,CAAC,EAAE,MAAM;IAO9B,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,YAAY;IAOpB,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,oCAAoC;IACpC,UAAU,IAAI,MAAM;IAMpB,6CAA6C;IAC7C,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIlC,2DAA2D;IAC3D,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAOrC,8BAA8B;IAC9B,aAAa,CAAC,IAAI,GAAE,MAAU,GAAG,WAAW,EAAE;IAe9C,uDAAuD;IACvD,YAAY,IAAI,MAAM,EAAE;IAQxB,8CAA8C;IAC9C,OAAO,IAAI,MAAM,EAAE;IAKnB,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAOzC,yDAAyD;IACzD,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE;IAmBpC,4CAA4C;IAC5C,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAgBrC,0CAA0C;IAC1C,IAAI,WAAW,IAAI,MAAM,CAIxB;IAED,OAAO,CAAC,SAAS;CAGlB"}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, appendFileSync, existsSync, mkdirSync, readdirSync, unlinkSync, } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
const DEFAULT_MEMORY_DIR = join(homedir(), '.cereworker', 'memory');
|
|
5
|
+
const MEMORY_FILE = 'MEMORY.md';
|
|
6
|
+
export class HippocampusStore {
|
|
7
|
+
dir;
|
|
8
|
+
constructor(directory) {
|
|
9
|
+
this.dir = directory
|
|
10
|
+
? resolve(directory.replace(/^~/, homedir()))
|
|
11
|
+
: DEFAULT_MEMORY_DIR;
|
|
12
|
+
this.ensureDir();
|
|
13
|
+
}
|
|
14
|
+
ensureDir() {
|
|
15
|
+
if (!existsSync(this.dir)) {
|
|
16
|
+
mkdirSync(this.dir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
ensureSubdir(subdir) {
|
|
20
|
+
const path = join(this.dir, subdir);
|
|
21
|
+
if (!existsSync(path)) {
|
|
22
|
+
mkdirSync(path, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
get directory() {
|
|
26
|
+
return this.dir;
|
|
27
|
+
}
|
|
28
|
+
/** Read the main MEMORY.md file. */
|
|
29
|
+
readMemory() {
|
|
30
|
+
const path = join(this.dir, MEMORY_FILE);
|
|
31
|
+
if (!existsSync(path))
|
|
32
|
+
return '';
|
|
33
|
+
return readFileSync(path, 'utf-8');
|
|
34
|
+
}
|
|
35
|
+
/** Write/replace the main MEMORY.md file. */
|
|
36
|
+
writeMemory(content) {
|
|
37
|
+
writeFileSync(join(this.dir, MEMORY_FILE), content, 'utf-8');
|
|
38
|
+
}
|
|
39
|
+
/** Append content to today's daily log (YYYY-MM-DD.md). */
|
|
40
|
+
appendDailyLog(content) {
|
|
41
|
+
const filename = `${this.todayDate()}.md`;
|
|
42
|
+
const path = join(this.dir, filename);
|
|
43
|
+
const entry = `\n---\n_${new Date().toISOString()}_\n\n${content}\n`;
|
|
44
|
+
appendFileSync(path, entry, 'utf-8');
|
|
45
|
+
}
|
|
46
|
+
/** Read recent daily logs. */
|
|
47
|
+
readDailyLogs(days = 7) {
|
|
48
|
+
const files = this.listLogFiles();
|
|
49
|
+
const cutoff = new Date();
|
|
50
|
+
cutoff.setDate(cutoff.getDate() - days);
|
|
51
|
+
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
52
|
+
return files
|
|
53
|
+
.filter((f) => f >= cutoffStr)
|
|
54
|
+
.map((f) => ({
|
|
55
|
+
filename: `${f}.md`,
|
|
56
|
+
content: readFileSync(join(this.dir, `${f}.md`), 'utf-8'),
|
|
57
|
+
date: f,
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
/** List all daily log files (date strings, sorted). */
|
|
61
|
+
listLogFiles() {
|
|
62
|
+
if (!existsSync(this.dir))
|
|
63
|
+
return [];
|
|
64
|
+
return readdirSync(this.dir)
|
|
65
|
+
.filter((f) => /^\d{4}-\d{2}-\d{2}\.md$/.test(f))
|
|
66
|
+
.map((f) => f.replace('.md', ''))
|
|
67
|
+
.sort();
|
|
68
|
+
}
|
|
69
|
+
/** List all files in the memory directory. */
|
|
70
|
+
listAll() {
|
|
71
|
+
if (!existsSync(this.dir))
|
|
72
|
+
return [];
|
|
73
|
+
return readdirSync(this.dir).filter((f) => f.endsWith('.md'));
|
|
74
|
+
}
|
|
75
|
+
/** Read a specific file from the memory directory. */
|
|
76
|
+
readFile(filename) {
|
|
77
|
+
const safeName = filename.replace(/[/\\]/g, '');
|
|
78
|
+
const path = join(this.dir, safeName);
|
|
79
|
+
if (!existsSync(path))
|
|
80
|
+
return null;
|
|
81
|
+
return readFileSync(path, 'utf-8');
|
|
82
|
+
}
|
|
83
|
+
/** Search across all memory files for a text pattern. */
|
|
84
|
+
search(query) {
|
|
85
|
+
const results = [];
|
|
86
|
+
const lowerQuery = query.toLowerCase();
|
|
87
|
+
for (const file of this.listAll()) {
|
|
88
|
+
const content = readFileSync(join(this.dir, file), 'utf-8');
|
|
89
|
+
if (content.toLowerCase().includes(lowerQuery)) {
|
|
90
|
+
const dateMatch = file.match(/^(\d{4}-\d{2}-\d{2})/);
|
|
91
|
+
results.push({
|
|
92
|
+
filename: file,
|
|
93
|
+
content,
|
|
94
|
+
date: dateMatch?.[1] ?? '',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return results;
|
|
99
|
+
}
|
|
100
|
+
/** Delete daily logs older than maxDays. */
|
|
101
|
+
pruneOldLogs(maxDays) {
|
|
102
|
+
const cutoff = new Date();
|
|
103
|
+
cutoff.setDate(cutoff.getDate() - maxDays);
|
|
104
|
+
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
105
|
+
let pruned = 0;
|
|
106
|
+
for (const dateStr of this.listLogFiles()) {
|
|
107
|
+
if (dateStr < cutoffStr) {
|
|
108
|
+
unlinkSync(join(this.dir, `${dateStr}.md`));
|
|
109
|
+
pruned++;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return pruned;
|
|
113
|
+
}
|
|
114
|
+
/** Get the finetune subdirectory path. */
|
|
115
|
+
get finetuneDir() {
|
|
116
|
+
const dir = join(this.dir, 'finetune');
|
|
117
|
+
this.ensureSubdir('finetune');
|
|
118
|
+
return dir;
|
|
119
|
+
}
|
|
120
|
+
todayDate() {
|
|
121
|
+
return new Date().toISOString().slice(0, 10);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,GACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,MAAM,kBAAkB,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;AACpE,MAAM,WAAW,GAAG,WAAW,CAAC;AAEhC,MAAM,OAAO,gBAAgB;IACV,GAAG,CAAS;IAE7B,YAAY,SAAkB;QAC5B,IAAI,CAAC,GAAG,GAAG,SAAS;YAClB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YAC7C,CAAC,CAAC,kBAAkB,CAAC;QACvB,IAAI,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IAEO,SAAS;QACf,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;I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O,IAAI,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;YAC1C,IAAI,OAAO,GAAG,SAAS,EAAE,CAAC;gBACxB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC;gBAC5C,MAAM,EAAE,CAAC;YACX,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,0CAA0C;IAC1C,IAAI,WAAW;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QACvC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAC9B,OAAO,GAAG,CAAC;IACb,CAAC;IAEO,SAAS;QACf,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/C,CAAC;CACF"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { HippocampusStore } from './store.js';
|
|
3
|
+
export declare const memoryReadParameters: z.ZodObject<{
|
|
4
|
+
file: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
file: string;
|
|
7
|
+
}, {
|
|
8
|
+
file?: string | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const memoryWriteParameters: z.ZodObject<{
|
|
11
|
+
content: z.ZodString;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
content: string;
|
|
14
|
+
}, {
|
|
15
|
+
content: string;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const memoryLogParameters: z.ZodObject<{
|
|
18
|
+
content: z.ZodString;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
content: string;
|
|
21
|
+
}, {
|
|
22
|
+
content: string;
|
|
23
|
+
}>;
|
|
24
|
+
export declare const memorySearchParameters: z.ZodObject<{
|
|
25
|
+
query: z.ZodString;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
query: string;
|
|
28
|
+
}, {
|
|
29
|
+
query: string;
|
|
30
|
+
}>;
|
|
31
|
+
export declare function createMemoryTools(store: HippocampusStore): {
|
|
32
|
+
executeMemoryRead: (args: z.infer<typeof memoryReadParameters>) => Promise<string>;
|
|
33
|
+
executeMemoryWrite: (args: z.infer<typeof memoryWriteParameters>) => Promise<string>;
|
|
34
|
+
executeMemoryLog: (args: z.infer<typeof memoryLogParameters>) => Promise<string>;
|
|
35
|
+
executeMemorySearch: (args: z.infer<typeof memorySearchParameters>) => Promise<string>;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,oBAAoB;;;;;;EAM/B,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;EAEhC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;EAE9B,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;EAEjC,CAAC;AAEH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,gBAAgB;8BAErB,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,KAAG,OAAO,CAAC,MAAM,CAAC;+BAYrD,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,KAAG,OAAO,CAAC,MAAM,CAAC;6BAKzD,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,KAAG,OAAO,CAAC,MAAM,CAAC;gCAMlD,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,KAAG,OAAO,CAAC,MAAM,CAAC;EAiB7F"}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const memoryReadParameters = z.object({
|
|
3
|
+
file: z
|
|
4
|
+
.string()
|
|
5
|
+
.optional()
|
|
6
|
+
.default('MEMORY.md')
|
|
7
|
+
.describe('Memory file to read. Defaults to MEMORY.md. Use a date like "2026-03-08.md" for daily logs.'),
|
|
8
|
+
});
|
|
9
|
+
export const memoryWriteParameters = z.object({
|
|
10
|
+
content: z.string().describe('Content to write to MEMORY.md (replaces existing content)'),
|
|
11
|
+
});
|
|
12
|
+
export const memoryLogParameters = z.object({
|
|
13
|
+
content: z.string().describe("Content to append to today's daily log"),
|
|
14
|
+
});
|
|
15
|
+
export const memorySearchParameters = z.object({
|
|
16
|
+
query: z.string().describe('Text to search for across all memory files'),
|
|
17
|
+
});
|
|
18
|
+
export function createMemoryTools(store) {
|
|
19
|
+
return {
|
|
20
|
+
executeMemoryRead: async (args) => {
|
|
21
|
+
const content = store.readFile(args.file);
|
|
22
|
+
if (content === null) {
|
|
23
|
+
const files = store.listAll();
|
|
24
|
+
if (files.length === 0) {
|
|
25
|
+
return 'No memory files found. Use memory_write to create MEMORY.md or memory_log to start a daily log.';
|
|
26
|
+
}
|
|
27
|
+
return `File "${args.file}" not found. Available files: ${files.join(', ')}`;
|
|
28
|
+
}
|
|
29
|
+
return content || '(empty file)';
|
|
30
|
+
},
|
|
31
|
+
executeMemoryWrite: async (args) => {
|
|
32
|
+
store.writeMemory(args.content);
|
|
33
|
+
return 'MEMORY.md updated successfully.';
|
|
34
|
+
},
|
|
35
|
+
executeMemoryLog: async (args) => {
|
|
36
|
+
store.appendDailyLog(args.content);
|
|
37
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
38
|
+
return `Logged to ${today}.md`;
|
|
39
|
+
},
|
|
40
|
+
executeMemorySearch: async (args) => {
|
|
41
|
+
const results = store.search(args.query);
|
|
42
|
+
if (results.length === 0) {
|
|
43
|
+
return `No matches found for "${args.query}"`;
|
|
44
|
+
}
|
|
45
|
+
return results
|
|
46
|
+
.map((r) => {
|
|
47
|
+
const lines = r.content.split('\n');
|
|
48
|
+
const matchingLines = lines
|
|
49
|
+
.filter((l) => l.toLowerCase().includes(args.query.toLowerCase()))
|
|
50
|
+
.slice(0, 5);
|
|
51
|
+
return `## ${r.filename}\n${matchingLines.join('\n')}`;
|
|
52
|
+
})
|
|
53
|
+
.join('\n\n');
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,IAAI,EAAE,CAAC;SACJ,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,OAAO,CAAC,WAAW,CAAC;SACpB,QAAQ,CAAC,6FAA6F,CAAC;CAC3G,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2DAA2D,CAAC;CAC1F,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wCAAwC,CAAC;CACvE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;CACzE,CAAC,CAAC;AAEH,MAAM,UAAU,iB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E,EAAE;gBACT,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACpC,MAAM,aAAa,GAAG,KAAK;qBACxB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;qBACjE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBACf,OAAO,MAAM,CAAC,CAAC,QAAQ,KAAK,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACzD,CAAC,CAAC;iBACD,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface TrainingPair {
|
|
2
|
+
instruction: string;
|
|
3
|
+
response: string;
|
|
4
|
+
source: string;
|
|
5
|
+
createdAt: number;
|
|
6
|
+
}
|
|
7
|
+
export interface CurationResult {
|
|
8
|
+
pairs: TrainingPair[];
|
|
9
|
+
skipped: number;
|
|
10
|
+
errors: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface MemoryEntry {
|
|
13
|
+
filename: string;
|
|
14
|
+
content: string;
|
|
15
|
+
date: string;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cereworker/hippocampus",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/Producible/CereWorker.git",
|
|
16
|
+
"directory": "packages/hippocampus"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"zod": "^3.24.0",
|
|
20
|
+
"@cereworker/core": "0.2.0",
|
|
21
|
+
"@cereworker/config": "0.2.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.7.3"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"lint": "eslint src/",
|
|
30
|
+
"clean": "rm -rf dist"
|
|
31
|
+
}
|
|
32
|
+
}
|