@psiclawops/hypermem 0.5.0 → 0.5.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.
- package/dist/background-indexer.d.ts +132 -0
- package/dist/background-indexer.d.ts.map +1 -0
- package/dist/background-indexer.js +1044 -0
- package/dist/cache.d.ts +110 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +495 -0
- package/dist/compaction-fence.d.ts +89 -0
- package/dist/compaction-fence.d.ts.map +1 -0
- package/dist/compaction-fence.js +153 -0
- package/dist/compositor.d.ts +226 -0
- package/dist/compositor.d.ts.map +1 -0
- package/dist/compositor.js +2558 -0
- package/dist/content-type-classifier.d.ts +41 -0
- package/dist/content-type-classifier.d.ts.map +1 -0
- package/dist/content-type-classifier.js +181 -0
- package/dist/cross-agent.d.ts +62 -0
- package/dist/cross-agent.d.ts.map +1 -0
- package/dist/cross-agent.js +259 -0
- package/dist/db.d.ts +131 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +402 -0
- package/dist/desired-state-store.d.ts +100 -0
- package/dist/desired-state-store.d.ts.map +1 -0
- package/dist/desired-state-store.js +222 -0
- package/dist/doc-chunk-store.d.ts +140 -0
- package/dist/doc-chunk-store.d.ts.map +1 -0
- package/dist/doc-chunk-store.js +391 -0
- package/dist/doc-chunker.d.ts +99 -0
- package/dist/doc-chunker.d.ts.map +1 -0
- package/dist/doc-chunker.js +324 -0
- package/dist/dreaming-promoter.d.ts +86 -0
- package/dist/dreaming-promoter.d.ts.map +1 -0
- package/dist/dreaming-promoter.js +381 -0
- package/dist/episode-store.d.ts +49 -0
- package/dist/episode-store.d.ts.map +1 -0
- package/dist/episode-store.js +135 -0
- package/dist/fact-store.d.ts +75 -0
- package/dist/fact-store.d.ts.map +1 -0
- package/dist/fact-store.js +236 -0
- package/dist/fleet-store.d.ts +144 -0
- package/dist/fleet-store.d.ts.map +1 -0
- package/dist/fleet-store.js +276 -0
- package/dist/fos-mod.d.ts +178 -0
- package/dist/fos-mod.d.ts.map +1 -0
- package/dist/fos-mod.js +416 -0
- package/dist/hybrid-retrieval.d.ts +64 -0
- package/dist/hybrid-retrieval.d.ts.map +1 -0
- package/dist/hybrid-retrieval.js +344 -0
- package/dist/image-eviction.d.ts +49 -0
- package/dist/image-eviction.d.ts.map +1 -0
- package/dist/image-eviction.js +251 -0
- package/dist/index.d.ts +650 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1072 -0
- package/dist/keystone-scorer.d.ts +51 -0
- package/dist/keystone-scorer.d.ts.map +1 -0
- package/dist/keystone-scorer.js +52 -0
- package/dist/knowledge-graph.d.ts +110 -0
- package/dist/knowledge-graph.d.ts.map +1 -0
- package/dist/knowledge-graph.js +305 -0
- package/dist/knowledge-lint.d.ts +29 -0
- package/dist/knowledge-lint.d.ts.map +1 -0
- package/dist/knowledge-lint.js +116 -0
- package/dist/knowledge-store.d.ts +72 -0
- package/dist/knowledge-store.d.ts.map +1 -0
- package/dist/knowledge-store.js +247 -0
- package/dist/library-schema.d.ts +22 -0
- package/dist/library-schema.d.ts.map +1 -0
- package/dist/library-schema.js +1038 -0
- package/dist/message-store.d.ts +89 -0
- package/dist/message-store.d.ts.map +1 -0
- package/dist/message-store.js +323 -0
- package/dist/metrics-dashboard.d.ts +114 -0
- package/dist/metrics-dashboard.d.ts.map +1 -0
- package/dist/metrics-dashboard.js +260 -0
- package/dist/obsidian-exporter.d.ts +57 -0
- package/dist/obsidian-exporter.d.ts.map +1 -0
- package/dist/obsidian-exporter.js +274 -0
- package/dist/obsidian-watcher.d.ts +147 -0
- package/dist/obsidian-watcher.d.ts.map +1 -0
- package/dist/obsidian-watcher.js +403 -0
- package/dist/open-domain.d.ts +46 -0
- package/dist/open-domain.d.ts.map +1 -0
- package/dist/open-domain.js +125 -0
- package/dist/preference-store.d.ts +54 -0
- package/dist/preference-store.d.ts.map +1 -0
- package/dist/preference-store.js +109 -0
- package/dist/preservation-gate.d.ts +82 -0
- package/dist/preservation-gate.d.ts.map +1 -0
- package/dist/preservation-gate.js +150 -0
- package/dist/proactive-pass.d.ts +63 -0
- package/dist/proactive-pass.d.ts.map +1 -0
- package/dist/proactive-pass.js +239 -0
- package/dist/profiles.d.ts +44 -0
- package/dist/profiles.d.ts.map +1 -0
- package/dist/profiles.js +227 -0
- package/dist/provider-translator.d.ts +50 -0
- package/dist/provider-translator.d.ts.map +1 -0
- package/dist/provider-translator.js +403 -0
- package/dist/rate-limiter.d.ts +76 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/rate-limiter.js +179 -0
- package/dist/repair-tool-pairs.d.ts +38 -0
- package/dist/repair-tool-pairs.d.ts.map +1 -0
- package/dist/repair-tool-pairs.js +138 -0
- package/dist/retrieval-policy.d.ts +51 -0
- package/dist/retrieval-policy.d.ts.map +1 -0
- package/dist/retrieval-policy.js +77 -0
- package/dist/schema.d.ts +15 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +229 -0
- package/dist/secret-scanner.d.ts +51 -0
- package/dist/secret-scanner.d.ts.map +1 -0
- package/dist/secret-scanner.js +248 -0
- package/dist/seed.d.ts +108 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +177 -0
- package/dist/session-flusher.d.ts +53 -0
- package/dist/session-flusher.d.ts.map +1 -0
- package/dist/session-flusher.js +69 -0
- package/dist/session-topic-map.d.ts +41 -0
- package/dist/session-topic-map.d.ts.map +1 -0
- package/dist/session-topic-map.js +77 -0
- package/dist/spawn-context.d.ts +54 -0
- package/dist/spawn-context.d.ts.map +1 -0
- package/dist/spawn-context.js +159 -0
- package/dist/system-store.d.ts +73 -0
- package/dist/system-store.d.ts.map +1 -0
- package/dist/system-store.js +182 -0
- package/dist/temporal-store.d.ts +80 -0
- package/dist/temporal-store.d.ts.map +1 -0
- package/dist/temporal-store.js +149 -0
- package/dist/topic-detector.d.ts +35 -0
- package/dist/topic-detector.d.ts.map +1 -0
- package/dist/topic-detector.js +249 -0
- package/dist/topic-store.d.ts +45 -0
- package/dist/topic-store.d.ts.map +1 -0
- package/dist/topic-store.js +136 -0
- package/dist/topic-synthesizer.d.ts +51 -0
- package/dist/topic-synthesizer.d.ts.map +1 -0
- package/dist/topic-synthesizer.js +315 -0
- package/dist/trigger-registry.d.ts +63 -0
- package/dist/trigger-registry.d.ts.map +1 -0
- package/dist/trigger-registry.js +163 -0
- package/dist/types.d.ts +533 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/vector-store.d.ts +170 -0
- package/dist/vector-store.d.ts.map +1 -0
- package/dist/vector-store.js +677 -0
- package/dist/version.d.ts +34 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +34 -0
- package/dist/wiki-page-emitter.d.ts +65 -0
- package/dist/wiki-page-emitter.d.ts.map +1 -0
- package/dist/wiki-page-emitter.js +258 -0
- package/dist/work-store.d.ts +112 -0
- package/dist/work-store.d.ts.map +1 -0
- package/dist/work-store.js +273 -0
- package/package.json +1 -1
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hypermem Document Chunker
|
|
3
|
+
*
|
|
4
|
+
* Splits markdown documents into semantically coherent chunks for L3 indexing.
|
|
5
|
+
*
|
|
6
|
+
* Design principles:
|
|
7
|
+
* - Chunk by logical section (## / ###), NOT by token count
|
|
8
|
+
* - Each chunk is a self-contained policy/operational unit
|
|
9
|
+
* - Preserve section hierarchy for context assembly
|
|
10
|
+
* - Track source file hash for atomic re-indexing
|
|
11
|
+
* - Idempotent: same source produces same chunks (deterministic IDs)
|
|
12
|
+
*
|
|
13
|
+
* Collections (as defined in ACA offload spec):
|
|
14
|
+
* governance/policy — POLICY.md, shared-fleet
|
|
15
|
+
* governance/charter — CHARTER.md, per-tier (council/director)
|
|
16
|
+
* governance/comms — COMMS.md, shared-fleet
|
|
17
|
+
* operations/agents — AGENTS.md, per-tier
|
|
18
|
+
* operations/tools — TOOLS.md, per-agent
|
|
19
|
+
* memory/decisions — MEMORY.md, per-agent
|
|
20
|
+
* memory/daily — memory/YYYY-MM-DD.md, per-agent
|
|
21
|
+
* identity/soul — SOUL.md, per-agent (always-loaded kernel, but still indexed)
|
|
22
|
+
* identity/job — JOB.md, per-agent (demand-loaded during deliberation)
|
|
23
|
+
*/
|
|
24
|
+
import { createHash } from 'node:crypto';
|
|
25
|
+
import { readFileSync } from 'node:fs';
|
|
26
|
+
// ─── Core chunker ───────────────────────────────────────────────
|
|
27
|
+
/**
|
|
28
|
+
* Hash a string with SHA-256.
|
|
29
|
+
*/
|
|
30
|
+
export function hashContent(content) {
|
|
31
|
+
return createHash('sha256').update(content).digest('hex');
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Estimate token count from character length.
|
|
35
|
+
* Rough heuristic: 1 token ≈ 4 chars for English prose.
|
|
36
|
+
*/
|
|
37
|
+
function estimateTokens(text) {
|
|
38
|
+
return Math.ceil(text.length / 4);
|
|
39
|
+
}
|
|
40
|
+
function parseMarkdownSections(markdown) {
|
|
41
|
+
const lines = markdown.split('\n');
|
|
42
|
+
const sections = [];
|
|
43
|
+
let currentLevel = 0;
|
|
44
|
+
let currentHeading = '';
|
|
45
|
+
let currentRaw = '';
|
|
46
|
+
let contentLines = [];
|
|
47
|
+
function flush() {
|
|
48
|
+
if (currentHeading || contentLines.length > 0) {
|
|
49
|
+
sections.push({
|
|
50
|
+
heading: currentHeading,
|
|
51
|
+
level: currentLevel,
|
|
52
|
+
content: contentLines.join('\n').trim(),
|
|
53
|
+
rawHeading: currentRaw,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (const line of lines) {
|
|
58
|
+
const h3Match = line.match(/^### (.+)$/);
|
|
59
|
+
const h2Match = line.match(/^## (.+)$/);
|
|
60
|
+
const h1Match = line.match(/^# (.+)$/);
|
|
61
|
+
if (h3Match || h2Match || h1Match) {
|
|
62
|
+
flush();
|
|
63
|
+
currentRaw = line;
|
|
64
|
+
if (h3Match) {
|
|
65
|
+
currentLevel = 3;
|
|
66
|
+
currentHeading = h3Match[1].trim();
|
|
67
|
+
}
|
|
68
|
+
else if (h2Match) {
|
|
69
|
+
currentLevel = 2;
|
|
70
|
+
currentHeading = h2Match[1].trim();
|
|
71
|
+
}
|
|
72
|
+
else if (h1Match) {
|
|
73
|
+
currentLevel = 1;
|
|
74
|
+
currentHeading = h1Match[1].trim();
|
|
75
|
+
}
|
|
76
|
+
contentLines = [];
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
contentLines.push(line);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
flush();
|
|
83
|
+
return sections;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build a hierarchical section path from the section stack.
|
|
87
|
+
* e.g., ["POLICY.md", "§3 Escalation", "Triggers"] → "POLICY.md > §3 Escalation > Triggers"
|
|
88
|
+
*/
|
|
89
|
+
function buildSectionPath(stack) {
|
|
90
|
+
return stack.filter(Boolean).join(' > ');
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Generate a deterministic chunk ID from its identifying properties.
|
|
94
|
+
* Includes sourcePath to prevent collisions when different files have
|
|
95
|
+
* identical content and section structure (e.g., POLICY.md in two workspaces).
|
|
96
|
+
*/
|
|
97
|
+
function chunkId(collection, sectionPath, sourceHash, sourcePath) {
|
|
98
|
+
const key = `${collection}::${sourcePath}::${sectionPath}::${sourceHash}`;
|
|
99
|
+
return createHash('sha256').update(key).digest('hex').slice(0, 16);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Chunk a markdown document into semantic sections.
|
|
103
|
+
*
|
|
104
|
+
* Approach:
|
|
105
|
+
* - Level 1 (#) headings become top-level section anchors
|
|
106
|
+
* - Level 2 (##) headings become primary chunks
|
|
107
|
+
* - Level 3 (###) headings become sub-chunks under their parent
|
|
108
|
+
* - Content before the first heading becomes a "preamble" chunk
|
|
109
|
+
* - Empty sections (heading only, no content) are skipped unless minContentLen=0
|
|
110
|
+
*
|
|
111
|
+
* For documents with deeply nested content, we group level-3 sections under
|
|
112
|
+
* their parent level-2 section. This keeps related policy sections together.
|
|
113
|
+
*/
|
|
114
|
+
export function chunkMarkdown(content, opts) {
|
|
115
|
+
const minLen = opts.minContentLen ?? 50;
|
|
116
|
+
const sourceHash = hashContent(content);
|
|
117
|
+
const sections = parseMarkdownSections(content);
|
|
118
|
+
const chunks = [];
|
|
119
|
+
// Track current section hierarchy for path building
|
|
120
|
+
let h1Heading = '';
|
|
121
|
+
let h2Heading = '';
|
|
122
|
+
const h2ContentLines = [];
|
|
123
|
+
let h2Active = false;
|
|
124
|
+
function flushH2() {
|
|
125
|
+
if (!h2Active)
|
|
126
|
+
return;
|
|
127
|
+
const body = h2ContentLines.join('\n').trim();
|
|
128
|
+
if (body.length < minLen && !opts.includeParentContext) {
|
|
129
|
+
h2Active = false;
|
|
130
|
+
h2ContentLines.length = 0;
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const sectionPath = buildSectionPath([h1Heading, h2Heading].filter(Boolean));
|
|
134
|
+
const chunkContent = [
|
|
135
|
+
h1Heading ? `# ${h1Heading}` : '',
|
|
136
|
+
`## ${h2Heading}`,
|
|
137
|
+
'',
|
|
138
|
+
body,
|
|
139
|
+
].filter(l => l !== '' || body).join('\n').trim();
|
|
140
|
+
if (chunkContent.length >= minLen) {
|
|
141
|
+
chunks.push({
|
|
142
|
+
id: chunkId(opts.collection, sectionPath, sourceHash, opts.sourcePath),
|
|
143
|
+
collection: opts.collection,
|
|
144
|
+
sectionPath,
|
|
145
|
+
depth: 2,
|
|
146
|
+
content: chunkContent,
|
|
147
|
+
tokenEstimate: estimateTokens(chunkContent),
|
|
148
|
+
sourceHash,
|
|
149
|
+
sourcePath: opts.sourcePath,
|
|
150
|
+
scope: opts.scope,
|
|
151
|
+
tier: opts.tier,
|
|
152
|
+
agentId: opts.agentId,
|
|
153
|
+
parentPath: h1Heading || undefined,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
h2Active = false;
|
|
157
|
+
h2ContentLines.length = 0;
|
|
158
|
+
}
|
|
159
|
+
// Preamble: text before first heading
|
|
160
|
+
let preamble = '';
|
|
161
|
+
for (const section of sections) {
|
|
162
|
+
if (section.level === 1) {
|
|
163
|
+
flushH2();
|
|
164
|
+
h1Heading = section.heading;
|
|
165
|
+
h2Heading = '';
|
|
166
|
+
// Level-1 headings with body content become a preamble chunk
|
|
167
|
+
if (section.content.length >= minLen) {
|
|
168
|
+
const sectionPath = buildSectionPath([h1Heading]);
|
|
169
|
+
const chunkContent = [`# ${h1Heading}`, '', section.content].join('\n').trim();
|
|
170
|
+
chunks.push({
|
|
171
|
+
id: chunkId(opts.collection, sectionPath + '::intro', sourceHash, opts.sourcePath),
|
|
172
|
+
collection: opts.collection,
|
|
173
|
+
sectionPath: sectionPath + ' (intro)',
|
|
174
|
+
depth: 1,
|
|
175
|
+
content: chunkContent,
|
|
176
|
+
tokenEstimate: estimateTokens(chunkContent),
|
|
177
|
+
sourceHash,
|
|
178
|
+
sourcePath: opts.sourcePath,
|
|
179
|
+
scope: opts.scope,
|
|
180
|
+
tier: opts.tier,
|
|
181
|
+
agentId: opts.agentId,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (section.level === 2) {
|
|
186
|
+
flushH2();
|
|
187
|
+
h2Heading = section.heading;
|
|
188
|
+
h2Active = true;
|
|
189
|
+
// Start accumulating: begin with this section's own content
|
|
190
|
+
h2ContentLines.length = 0;
|
|
191
|
+
if (section.content)
|
|
192
|
+
h2ContentLines.push(section.content);
|
|
193
|
+
}
|
|
194
|
+
else if (section.level === 3) {
|
|
195
|
+
// Append h3 sub-sections into the current h2 chunk
|
|
196
|
+
if (h2Active) {
|
|
197
|
+
h2ContentLines.push(`\n### ${section.heading}`);
|
|
198
|
+
if (section.content)
|
|
199
|
+
h2ContentLines.push(section.content);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
// h3 without a parent h2 — emit as standalone
|
|
203
|
+
const sectionPath = buildSectionPath([h1Heading, section.heading].filter(Boolean));
|
|
204
|
+
const chunkContent = [
|
|
205
|
+
h1Heading ? `# ${h1Heading}` : '',
|
|
206
|
+
`### ${section.heading}`,
|
|
207
|
+
'',
|
|
208
|
+
section.content,
|
|
209
|
+
].filter(l => l !== '' || section.content).join('\n').trim();
|
|
210
|
+
if (chunkContent.length >= minLen) {
|
|
211
|
+
chunks.push({
|
|
212
|
+
id: chunkId(opts.collection, sectionPath, sourceHash, opts.sourcePath),
|
|
213
|
+
collection: opts.collection,
|
|
214
|
+
sectionPath,
|
|
215
|
+
depth: 3,
|
|
216
|
+
content: chunkContent,
|
|
217
|
+
tokenEstimate: estimateTokens(chunkContent),
|
|
218
|
+
sourceHash,
|
|
219
|
+
sourcePath: opts.sourcePath,
|
|
220
|
+
scope: opts.scope,
|
|
221
|
+
tier: opts.tier,
|
|
222
|
+
agentId: opts.agentId,
|
|
223
|
+
parentPath: h1Heading || undefined,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else if (section.level === 0) {
|
|
229
|
+
// Pre-heading content
|
|
230
|
+
preamble = section.content.trim();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// Flush any remaining h2
|
|
234
|
+
flushH2();
|
|
235
|
+
// Emit preamble if substantial
|
|
236
|
+
if (preamble.length >= minLen) {
|
|
237
|
+
chunks.unshift({
|
|
238
|
+
id: chunkId(opts.collection, '(preamble)', sourceHash, opts.sourcePath),
|
|
239
|
+
collection: opts.collection,
|
|
240
|
+
sectionPath: '(preamble)',
|
|
241
|
+
depth: 0,
|
|
242
|
+
content: preamble,
|
|
243
|
+
tokenEstimate: estimateTokens(preamble),
|
|
244
|
+
sourceHash,
|
|
245
|
+
sourcePath: opts.sourcePath,
|
|
246
|
+
scope: opts.scope,
|
|
247
|
+
tier: opts.tier,
|
|
248
|
+
agentId: opts.agentId,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return chunks;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Chunk a file from disk.
|
|
255
|
+
*/
|
|
256
|
+
export function chunkFile(filePath, opts) {
|
|
257
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
258
|
+
return chunkMarkdown(content, { ...opts, sourcePath: filePath });
|
|
259
|
+
}
|
|
260
|
+
export const ACA_COLLECTIONS = {
|
|
261
|
+
'POLICY.md': {
|
|
262
|
+
collection: 'governance/policy',
|
|
263
|
+
scope: 'shared-fleet',
|
|
264
|
+
description: 'Governance policy: escalation triggers, decision states, council procedures, naming rules',
|
|
265
|
+
},
|
|
266
|
+
'CHARTER.md': {
|
|
267
|
+
collection: 'governance/charter',
|
|
268
|
+
scope: 'per-tier',
|
|
269
|
+
description: 'Org charter: mission, director structure, boundaries, escalation, work queue',
|
|
270
|
+
},
|
|
271
|
+
'COMMS.md': {
|
|
272
|
+
collection: 'governance/comms',
|
|
273
|
+
scope: 'shared-fleet',
|
|
274
|
+
description: 'Communications protocol: inter-agent tiers, delegation, platform formatting',
|
|
275
|
+
},
|
|
276
|
+
'AGENTS.md': {
|
|
277
|
+
collection: 'operations/agents',
|
|
278
|
+
scope: 'per-tier',
|
|
279
|
+
description: 'Agent operational guide: boot sequence, identity, memory, messaging, group chats',
|
|
280
|
+
},
|
|
281
|
+
'TOOLS.md': {
|
|
282
|
+
collection: 'operations/tools',
|
|
283
|
+
scope: 'per-agent',
|
|
284
|
+
description: 'Tool and runtime configuration: workspace path, model, key paths, quick commands',
|
|
285
|
+
},
|
|
286
|
+
'SOUL.md': {
|
|
287
|
+
collection: 'identity/soul',
|
|
288
|
+
scope: 'per-agent',
|
|
289
|
+
description: 'Agent soul: core principles, personality, tone, continuity',
|
|
290
|
+
},
|
|
291
|
+
'JOB.md': {
|
|
292
|
+
collection: 'identity/job',
|
|
293
|
+
scope: 'per-agent',
|
|
294
|
+
description: 'Job performance criteria: duties, response contract, council mode, output discipline',
|
|
295
|
+
},
|
|
296
|
+
'MOTIVATIONS.md': {
|
|
297
|
+
collection: 'identity/motivations',
|
|
298
|
+
scope: 'per-agent',
|
|
299
|
+
description: 'Agent motivations: drives, fears, tensions that shape perspective',
|
|
300
|
+
},
|
|
301
|
+
'MEMORY.md': {
|
|
302
|
+
collection: 'memory/decisions',
|
|
303
|
+
scope: 'per-agent',
|
|
304
|
+
description: 'Long-term curated memory: key decisions, lessons, context',
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Infer the collection definition for a file based on its name.
|
|
309
|
+
* Returns undefined if the file is not a known ACA file.
|
|
310
|
+
*/
|
|
311
|
+
export function inferCollection(fileName, agentId) {
|
|
312
|
+
// Strip path, get just the filename
|
|
313
|
+
const base = fileName.split('/').pop() ?? fileName;
|
|
314
|
+
// Daily memory files: memory/YYYY-MM-DD.md
|
|
315
|
+
if (/^\d{4}-\d{2}-\d{2}\.md$/.test(base)) {
|
|
316
|
+
return {
|
|
317
|
+
collection: 'memory/daily',
|
|
318
|
+
scope: 'per-agent',
|
|
319
|
+
description: `Daily memory log for ${agentId || 'agent'}`,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return ACA_COLLECTIONS[base];
|
|
323
|
+
}
|
|
324
|
+
//# sourceMappingURL=doc-chunker.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dreaming-promoter.ts
|
|
3
|
+
*
|
|
4
|
+
* hypermem-native dreaming promotion pass.
|
|
5
|
+
*
|
|
6
|
+
* Unlike the stock memory-core dreaming feature (which appends raw content to
|
|
7
|
+
* MEMORY.md), this promoter generates pointer-format entries that match the
|
|
8
|
+
* council's MEMORY.md convention:
|
|
9
|
+
*
|
|
10
|
+
* - **{domain} — {title}:** {summary}
|
|
11
|
+
* → `memory_search("{query}")`
|
|
12
|
+
*
|
|
13
|
+
* Scoring uses confidence, decay, recency, and domain cluster weight.
|
|
14
|
+
* Dedup prevents re-promoting topics already covered by existing pointers.
|
|
15
|
+
*
|
|
16
|
+
* Dry-run mode returns what would be written without modifying any files.
|
|
17
|
+
*/
|
|
18
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
19
|
+
export interface DreamerConfig {
|
|
20
|
+
/** Enable the promotion pass. Default: false */
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
/** Minimum composite score for promotion. Default: 0.70 */
|
|
23
|
+
minScore: number;
|
|
24
|
+
/** Minimum confidence threshold (pre-scoring). Default: 0.70 */
|
|
25
|
+
minConfidence: number;
|
|
26
|
+
/** Max new pointer entries to write per agent per run. Default: 5 */
|
|
27
|
+
maxPromotionsPerRun: number;
|
|
28
|
+
/** How often to run: every N indexer ticks. Default: 12 (~1hr at 5min interval) */
|
|
29
|
+
tickInterval: number;
|
|
30
|
+
/** Preview what would be promoted without writing. Default: false */
|
|
31
|
+
dryRun: boolean;
|
|
32
|
+
/** Recency half-life in days (score decays to 0.5 at this age). Default: 14 */
|
|
33
|
+
recencyHalfLifeDays: number;
|
|
34
|
+
/** Max age in days to consider a fact. Default: 90 */
|
|
35
|
+
maxAgeDays: number;
|
|
36
|
+
}
|
|
37
|
+
export declare const DEFAULT_DREAMER_CONFIG: DreamerConfig;
|
|
38
|
+
export interface FactCandidate {
|
|
39
|
+
id: number;
|
|
40
|
+
agentId: string;
|
|
41
|
+
domain: string;
|
|
42
|
+
content: string;
|
|
43
|
+
confidence: number;
|
|
44
|
+
decayScore: number;
|
|
45
|
+
ageDays: number;
|
|
46
|
+
score: number;
|
|
47
|
+
}
|
|
48
|
+
export interface PromotionEntry {
|
|
49
|
+
factId: number;
|
|
50
|
+
domain: string;
|
|
51
|
+
pointer: string;
|
|
52
|
+
title: string;
|
|
53
|
+
summary: string;
|
|
54
|
+
query: string;
|
|
55
|
+
score: number;
|
|
56
|
+
dryRun: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface DreamerResult {
|
|
59
|
+
agentId: string;
|
|
60
|
+
candidates: number;
|
|
61
|
+
promoted: number;
|
|
62
|
+
skippedDuplicate: number;
|
|
63
|
+
skippedThreshold: number;
|
|
64
|
+
entries: PromotionEntry[];
|
|
65
|
+
memoryPath: string | null;
|
|
66
|
+
dryRun: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve the workspace directory for an agent.
|
|
70
|
+
* Council agents live at ~/.openclaw/workspace-council/{agentId}/
|
|
71
|
+
* Other agents at ~/.openclaw/workspace/{agentId}/
|
|
72
|
+
*/
|
|
73
|
+
export declare function resolveAgentWorkspacePath(agentId: string): Promise<string | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Run the dreaming promotion pass for a single agent.
|
|
76
|
+
*
|
|
77
|
+
* Reads qualified facts from library.db, scores them, deduplicates against
|
|
78
|
+
* existing MEMORY.md pointers, and writes new pointer entries.
|
|
79
|
+
*/
|
|
80
|
+
export declare function runDreamingPromoter(agentId: string, libraryDb: DatabaseSync, config?: Partial<DreamerConfig>): Promise<DreamerResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Run the dreaming promotion pass for all agents in a fleet.
|
|
83
|
+
* Called from the BackgroundIndexer on every N ticks.
|
|
84
|
+
*/
|
|
85
|
+
export declare function runDreamingPassForFleet(agentIds: string[], libraryDb: DatabaseSync, config?: Partial<DreamerConfig>): Promise<DreamerResult[]>;
|
|
86
|
+
//# sourceMappingURL=dreaming-promoter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dreaming-promoter.d.ts","sourceRoot":"","sources":["../src/dreaming-promoter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;IACjB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,aAAa,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mFAAmF;IACnF,YAAY,EAAE,MAAM,CAAC;IACrB,qEAAqE;IACrE,MAAM,EAAE,OAAO,CAAC;IAChB,+EAA+E;IAC/E,mBAAmB,EAAE,MAAM,CAAC;IAC5B,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,sBAAsB,EAAE,aASpC,CAAC;AAIF,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,OAAO,CAAC;CACjB;AAID;;;;GAIG;AACH,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgBvF;AA2ND;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,YAAY,EACvB,MAAM,GAAE,OAAO,CAAC,aAAa,CAAM,GAClC,OAAO,CAAC,aAAa,CAAC,CAgJxB;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,EAAE,EAClB,SAAS,EAAE,YAAY,EACvB,MAAM,GAAE,OAAO,CAAC,aAAa,CAAM,GAClC,OAAO,CAAC,aAAa,EAAE,CAAC,CAa1B"}
|