@framers/agentos 0.13.64 → 0.13.65
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/cognition/memory/AgentMemory.d.ts +4 -2
- package/dist/cognition/memory/AgentMemory.d.ts.map +1 -1
- package/dist/cognition/memory/AgentMemory.js +3 -1
- package/dist/cognition/memory/AgentMemory.js.map +1 -1
- package/dist/cognition/memory/core/types.d.ts +1 -1
- package/dist/cognition/memory/core/types.d.ts.map +1 -1
- package/dist/cognition/memory/index.d.ts +1 -1
- package/dist/cognition/memory/index.d.ts.map +1 -1
- package/dist/cognition/memory/index.js.map +1 -1
- package/dist/cognition/memory/io/MarkdownExporter.d.ts +42 -8
- package/dist/cognition/memory/io/MarkdownExporter.d.ts.map +1 -1
- package/dist/cognition/memory/io/MarkdownExporter.js +196 -16
- package/dist/cognition/memory/io/MarkdownExporter.js.map +1 -1
- package/dist/cognition/memory/io/ObsidianExporter.d.ts +6 -4
- package/dist/cognition/memory/io/ObsidianExporter.d.ts.map +1 -1
- package/dist/cognition/memory/io/ObsidianExporter.js +5 -3
- package/dist/cognition/memory/io/ObsidianExporter.js.map +1 -1
- package/dist/cognition/memory/io/facade/Memory.d.ts +14 -3
- package/dist/cognition/memory/io/facade/Memory.d.ts.map +1 -1
- package/dist/cognition/memory/io/facade/Memory.js +19 -8
- package/dist/cognition/memory/io/facade/Memory.js.map +1 -1
- package/dist/cognition/memory/io/facade/index.d.ts +1 -1
- package/dist/cognition/memory/io/facade/index.d.ts.map +1 -1
- package/dist/cognition/memory/io/facade/types.d.ts +37 -0
- package/dist/cognition/memory/io/facade/types.d.ts.map +1 -1
- package/dist/cognition/memory/io/tools/MemoryAddTool.d.ts +4 -0
- package/dist/cognition/memory/io/tools/MemoryAddTool.d.ts.map +1 -1
- package/dist/cognition/memory/io/tools/MemoryAddTool.js +18 -4
- package/dist/cognition/memory/io/tools/MemoryAddTool.js.map +1 -1
- package/dist/cognition/substrate/memory/wiki/WikiCompiler.d.ts +5 -1
- package/dist/cognition/substrate/memory/wiki/WikiCompiler.d.ts.map +1 -1
- package/dist/cognition/substrate/memory/wiki/WikiCompiler.js +35 -10
- package/dist/cognition/substrate/memory/wiki/WikiCompiler.js.map +1 -1
- package/dist/cognition/substrate/memory/wiki/WikiMemoryStore.d.ts +23 -4
- package/dist/cognition/substrate/memory/wiki/WikiMemoryStore.d.ts.map +1 -1
- package/dist/cognition/substrate/memory/wiki/WikiMemoryStore.js +66 -35
- package/dist/cognition/substrate/memory/wiki/WikiMemoryStore.js.map +1 -1
- package/dist/cognition/substrate/memory/wiki/WikiPageId.d.ts +9 -7
- package/dist/cognition/substrate/memory/wiki/WikiPageId.d.ts.map +1 -1
- package/dist/cognition/substrate/memory/wiki/WikiPageId.js +19 -23
- package/dist/cognition/substrate/memory/wiki/WikiPageId.js.map +1 -1
- package/dist/core/utils/pathName.d.ts +59 -0
- package/dist/core/utils/pathName.d.ts.map +1 -0
- package/dist/core/utils/pathName.js +78 -0
- package/dist/core/utils/pathName.js.map +1 -0
- package/package.json +1 -1
|
@@ -9,6 +9,16 @@
|
|
|
9
9
|
* The `gray-matter` library is used to serialise the front-matter block so
|
|
10
10
|
* that the same library can later round-trip back via `MarkdownImporter`.
|
|
11
11
|
*
|
|
12
|
+
* A trace's scope, type and id name its folders and its file, so each is held
|
|
13
|
+
* to the name rule in `core/utils/pathName` before anything is written, and the
|
|
14
|
+
* file's resolved path must lie inside the export folder. Below the export
|
|
15
|
+
* folder no folder or file is made or written through a link, symbolic or
|
|
16
|
+
* hard, and two traces whose files would be one where names ignore case are
|
|
17
|
+
* not both written. A trace that fails any of these is left out and reported
|
|
18
|
+
* in the export's result. The checks run as each folder is made and each file
|
|
19
|
+
* opened; Node has no `openat`, so a process that swaps a folder below the
|
|
20
|
+
* export folder for a link while the export runs is outside what they stop.
|
|
21
|
+
*
|
|
12
22
|
* ## Folder layout
|
|
13
23
|
* ```
|
|
14
24
|
* {outputDir}/
|
|
@@ -26,8 +36,29 @@
|
|
|
26
36
|
* @module memory/io/MarkdownExporter
|
|
27
37
|
*/
|
|
28
38
|
import fs from 'node:fs/promises';
|
|
39
|
+
import { constants as fsConstants } from 'node:fs';
|
|
29
40
|
import path from 'node:path';
|
|
30
41
|
import { writeFrontMatter } from '../../../core/utils/frontMatter.js';
|
|
42
|
+
import { pathNameProblem, resolveInsideFolder } from '../../../core/utils/pathName.js';
|
|
43
|
+
/**
|
|
44
|
+
* The flags a trace's file is opened with: for writing, made when missing, and, where the platform has the flag
|
|
45
|
+
* (`O_NOFOLLOW`, which Windows lacks), never through a symbolic link in the file's own place. The file is emptied
|
|
46
|
+
* only once the open file shows it has no second name.
|
|
47
|
+
*/
|
|
48
|
+
const OPEN_FLAGS = fsConstants.O_WRONLY |
|
|
49
|
+
fsConstants.O_CREAT |
|
|
50
|
+
(fsConstants.O_NOFOLLOW !== undefined ? fsConstants.O_NOFOLLOW : 0);
|
|
51
|
+
/** The codes an open with `O_NOFOLLOW` fails with when a symbolic link holds the file's place (EMLINK on FreeBSD). */
|
|
52
|
+
const LINK_OPEN_CODES = new Set(['ELOOP', 'EMLINK']);
|
|
53
|
+
/** Thrown by `traceRelativePath` for a trace whose scope, type or id is not a safe name; the export reports it. */
|
|
54
|
+
class RefusedTraceName extends Error {
|
|
55
|
+
constructor(field, problem) {
|
|
56
|
+
super(`the trace's ${field} is not a safe file or folder name (${problem})`);
|
|
57
|
+
this.field = field;
|
|
58
|
+
this.problem = problem;
|
|
59
|
+
this.name = 'RefusedTraceName';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
31
62
|
// ---------------------------------------------------------------------------
|
|
32
63
|
// MarkdownExporter
|
|
33
64
|
// ---------------------------------------------------------------------------
|
|
@@ -53,15 +84,66 @@ export class MarkdownExporter {
|
|
|
53
84
|
/**
|
|
54
85
|
* Export all memory traces as `.md` files into `outputDir`.
|
|
55
86
|
*
|
|
56
|
-
* Directories are created on demand
|
|
87
|
+
* Directories are created on demand, one name at a time. A trace is not
|
|
88
|
+
* written, and is reported in the result, when its scope, type or id is not
|
|
89
|
+
* a safe file or folder name, when its file would lie outside `outputDir`,
|
|
90
|
+
* when a folder or file in its place under `outputDir` is a symbolic link or
|
|
91
|
+
* its file has a second name (a hard link), or when an older trace's file is
|
|
92
|
+
* the same file where names ignore case. Every other trace is written.
|
|
57
93
|
*
|
|
58
94
|
* @param outputDir - Root directory to write the Markdown vault into.
|
|
59
95
|
* @param _options - Optional export configuration (currently unused but
|
|
60
96
|
* accepted for API consistency with other exporters).
|
|
97
|
+
* @returns The traces left out, with the reason for each.
|
|
61
98
|
*/
|
|
62
99
|
async export(outputDir, _options) {
|
|
63
|
-
|
|
64
|
-
|
|
100
|
+
// Oldest first, so of two traces whose files would be one, the older is written.
|
|
101
|
+
const traces = await this.brain.all('SELECT id, type, scope, content, strength, created_at, tags FROM memory_traces WHERE deleted = 0 ORDER BY created_at, id');
|
|
102
|
+
// Every trace is placed before any folder is made or file written.
|
|
103
|
+
const refused = [];
|
|
104
|
+
const placed = [];
|
|
105
|
+
const taken = new Set();
|
|
106
|
+
for (const trace of traces) {
|
|
107
|
+
const place = this._placeTrace(outputDir, trace);
|
|
108
|
+
if (typeof place !== 'string') {
|
|
109
|
+
refused.push(place);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
// Paths that differ only in case or in Unicode form name one file where names ignore case (macOS, Windows).
|
|
113
|
+
const key = place.normalize('NFC').toLowerCase();
|
|
114
|
+
if (taken.has(key)) {
|
|
115
|
+
refused.push({ id: String(trace.id), field: 'path', problem: 'collision' });
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
taken.add(key);
|
|
119
|
+
placed.push({ file: place, trace });
|
|
120
|
+
}
|
|
121
|
+
// The export folder is the caller's: it is made when missing and used as it is, even when it is a link. Below
|
|
122
|
+
// it, every folder is made one name at a time, and no folder or file is written through a link.
|
|
123
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
124
|
+
const root = path.resolve(outputDir);
|
|
125
|
+
const linkFree = new Map();
|
|
126
|
+
const writable = [];
|
|
127
|
+
for (const entry of placed) {
|
|
128
|
+
const folder = path.dirname(entry.file);
|
|
129
|
+
let free = linkFree.get(folder);
|
|
130
|
+
if (free === undefined) {
|
|
131
|
+
free = await makeFoldersOutsideLinks(root, path.relative(root, folder));
|
|
132
|
+
linkFree.set(folder, free);
|
|
133
|
+
}
|
|
134
|
+
if (free) {
|
|
135
|
+
writable.push(entry);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
refused.push({ id: String(entry.trace.id), field: 'path', problem: 'link' });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const written = await Promise.all(writable.map(({ file, trace }) => this._writeTrace(file, trace)));
|
|
142
|
+
for (const refusal of written) {
|
|
143
|
+
if (refusal)
|
|
144
|
+
refused.push(refusal);
|
|
145
|
+
}
|
|
146
|
+
return { refused };
|
|
65
147
|
}
|
|
66
148
|
// -------------------------------------------------------------------------
|
|
67
149
|
// Protected helpers (overridden by ObsidianExporter)
|
|
@@ -97,32 +179,130 @@ export class MarkdownExporter {
|
|
|
97
179
|
/**
|
|
98
180
|
* Determine the relative file path for a trace within the output directory.
|
|
99
181
|
*
|
|
100
|
-
* Default: `{scope}/{type}/{id}.md
|
|
182
|
+
* Default: `{scope}/{type}/{id}.md`. Each of the three must be a safe file
|
|
183
|
+
* or folder name (see `pathNameProblem`), or the trace is refused. Whatever
|
|
184
|
+
* a subclass returns, the export writes the file only when its resolved
|
|
185
|
+
* path lies inside the output directory.
|
|
101
186
|
*
|
|
102
187
|
* @param trace - The trace row.
|
|
103
188
|
* @returns Relative path string (no leading slash).
|
|
189
|
+
* @throws When the trace's scope, type or id is not a safe name; the export
|
|
190
|
+
* reports such a trace in its result instead of writing it.
|
|
104
191
|
*/
|
|
105
192
|
traceRelativePath(trace) {
|
|
106
|
-
return path.join(trace
|
|
193
|
+
return path.join(traceName(trace, 'scope'), traceName(trace, 'type'), `${traceName(trace, 'id')}.md`);
|
|
107
194
|
}
|
|
108
195
|
// -------------------------------------------------------------------------
|
|
109
196
|
// Private helpers
|
|
110
197
|
// -------------------------------------------------------------------------
|
|
111
198
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
199
|
+
* The absolute path of a trace's file inside `outputDir`, or the reason the
|
|
200
|
+
* trace is refused: a scope, type or id that is not a safe name, or a path
|
|
201
|
+
* outside `outputDir`.
|
|
115
202
|
*
|
|
116
203
|
* @param outputDir - Root output directory.
|
|
117
|
-
* @param trace -
|
|
204
|
+
* @param trace - The trace row.
|
|
118
205
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
206
|
+
_placeTrace(outputDir, trace) {
|
|
207
|
+
let relPath;
|
|
208
|
+
try {
|
|
209
|
+
relPath = this.traceRelativePath(trace);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
if (!(err instanceof RefusedTraceName))
|
|
213
|
+
throw err;
|
|
214
|
+
return { id: String(trace.id), field: err.field, problem: err.problem };
|
|
215
|
+
}
|
|
216
|
+
return resolveInsideFolder(outputDir, [relPath]) ?? { id: String(trace.id), field: 'path', problem: 'outside' };
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Write a single trace to disk, into a folder already made, and never
|
|
220
|
+
* through a link. A symbolic link in the file's place is refused before the
|
|
221
|
+
* open, and where the platform has `O_NOFOLLOW` the open refuses one put
|
|
222
|
+
* there since. A file with a second name (a hard link) is the same file as
|
|
223
|
+
* that name, which may be outside the export folder, so the open file is
|
|
224
|
+
* refused before it is emptied.
|
|
225
|
+
*
|
|
226
|
+
* @param file - Absolute path of the trace's file, inside the output directory.
|
|
227
|
+
* @param trace - Trace row to serialise.
|
|
228
|
+
* @returns The refusal when a link holds the file's place, or null once the file is written.
|
|
229
|
+
*/
|
|
230
|
+
async _writeTrace(file, trace) {
|
|
231
|
+
const linked = { id: String(trace.id), field: 'path', problem: 'link' };
|
|
232
|
+
if ((await lstatOrNull(file))?.isSymbolicLink())
|
|
233
|
+
return linked;
|
|
234
|
+
const handle = await fs.open(file, OPEN_FLAGS).catch((err) => {
|
|
235
|
+
if (LINK_OPEN_CODES.has(String(err.code)))
|
|
236
|
+
return null;
|
|
237
|
+
throw err;
|
|
238
|
+
});
|
|
239
|
+
if (handle === null)
|
|
240
|
+
return linked;
|
|
241
|
+
try {
|
|
242
|
+
if ((await handle.stat()).nlink > 1)
|
|
243
|
+
return linked;
|
|
244
|
+
await handle.truncate(0);
|
|
245
|
+
await handle.writeFile(this.buildFileContent(trace), 'utf8');
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
await handle.close();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/** The entry at `file` itself, a link not followed, or null when there is none. */
|
|
254
|
+
async function lstatOrNull(file) {
|
|
255
|
+
try {
|
|
256
|
+
return await fs.lstat(file);
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
if (err.code === 'ENOENT')
|
|
260
|
+
return null;
|
|
261
|
+
throw err;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Make the folders `relative` names under `root`, one name at a time, and stop at a link. A folder this makes is
|
|
266
|
+
* never a link, so a file written into it stays under `root`.
|
|
267
|
+
*
|
|
268
|
+
* @param root - The export folder.
|
|
269
|
+
* @param relative - The folder's path under `root`.
|
|
270
|
+
* @returns True when every folder is in place and none of them is a link.
|
|
271
|
+
*/
|
|
272
|
+
async function makeFoldersOutsideLinks(root, relative) {
|
|
273
|
+
let dir = root;
|
|
274
|
+
for (const name of relative.split(path.sep).filter((part) => part.length > 0)) {
|
|
275
|
+
dir = path.join(dir, name);
|
|
276
|
+
const entry = await lstatOrNull(dir);
|
|
277
|
+
if (entry) {
|
|
278
|
+
if (entry.isSymbolicLink())
|
|
279
|
+
return false;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
await fs.mkdir(dir);
|
|
284
|
+
}
|
|
285
|
+
catch (err) {
|
|
286
|
+
if (err.code !== 'EEXIST')
|
|
287
|
+
throw err;
|
|
288
|
+
// Something was put there since the look: look again.
|
|
289
|
+
if ((await fs.lstat(dir)).isSymbolicLink())
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
126
292
|
}
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The trace's `field` as one file or folder name: its value as text, once the
|
|
297
|
+
* name rule accepts it.
|
|
298
|
+
*
|
|
299
|
+
* @throws RefusedTraceName when the value is not a safe name.
|
|
300
|
+
*/
|
|
301
|
+
function traceName(trace, field) {
|
|
302
|
+
const name = String(trace[field]);
|
|
303
|
+
const problem = pathNameProblem(name);
|
|
304
|
+
if (problem)
|
|
305
|
+
throw new RefusedTraceName(field, problem);
|
|
306
|
+
return name;
|
|
127
307
|
}
|
|
128
308
|
//# sourceMappingURL=MarkdownExporter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownExporter.js","sourceRoot":"","sources":["../../../../src/cognition/memory/io/MarkdownExporter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"MarkdownExporter.js","sourceRoot":"","sources":["../../../../src/cognition/memory/io/MarkdownExporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,SAAS,IAAI,WAAW,EAAc,MAAM,SAAS,CAAC;AAC/D,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAwB,MAAM,iCAAiC,CAAC;AAoB7G;;;;GAIG;AAC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,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;QAC9E,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC3B,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,KAAK,CAAC,cAAc,EAAE;gBAAE,OAAO,KAAK,CAAC;YACzC,SAAS;QACX,CAAC;QACD,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAK,GAA6B,CAAC,IAAI,KAAK,QAAQ;gBAAE,MAAM,GAAG,CAAC;YAChE,sDAAsD;YACtD,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc,EAAE;gBAAE,OAAO,KAAK,CAAC;QAC3D,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,SAAS,SAAS,CAAC,KAAe,EAAE,KAAqB;IACvD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,OAAO;QAAE,MAAM,IAAI,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACxD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
*
|
|
22
22
|
* @module memory/io/ObsidianExporter
|
|
23
23
|
*/
|
|
24
|
-
import type { ExportOptions } from './facade/types.js';
|
|
24
|
+
import type { ExportOptions, ExportResult } from './facade/types.js';
|
|
25
25
|
import { MarkdownExporter } from './MarkdownExporter.js';
|
|
26
26
|
/** Raw row shape from the `memory_traces` table (subset used here). */
|
|
27
27
|
interface TraceRow {
|
|
@@ -54,13 +54,15 @@ export declare class ObsidianExporter extends MarkdownExporter {
|
|
|
54
54
|
* Export all memory traces as Obsidian-flavoured `.md` files.
|
|
55
55
|
*
|
|
56
56
|
* Pre-fetches all knowledge-edge relationships into an in-memory cache,
|
|
57
|
-
* then delegates to the parent `export()` method. Directory creation
|
|
58
|
-
* file writing are handled there; only
|
|
57
|
+
* then delegates to the parent `export()` method. Directory creation,
|
|
58
|
+
* file writing and the checks on each trace's path are handled there; only
|
|
59
|
+
* `buildFileContent` is overridden.
|
|
59
60
|
*
|
|
60
61
|
* @param outputDir - Root directory to write the Obsidian vault into.
|
|
61
62
|
* @param options - Optional export configuration.
|
|
63
|
+
* @returns The traces left out, with the reason for each.
|
|
62
64
|
*/
|
|
63
|
-
export(outputDir: string, options?: ExportOptions): Promise<
|
|
65
|
+
export(outputDir: string, options?: ExportOptions): Promise<ExportResult>;
|
|
64
66
|
/**
|
|
65
67
|
* Build Obsidian-flavoured Markdown for a trace.
|
|
66
68
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObsidianExporter.d.ts","sourceRoot":"","sources":["../../../../src/cognition/memory/io/ObsidianExporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"ObsidianExporter.d.ts","sourceRoot":"","sources":["../../../../src/cognition/memory/io/ObsidianExporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAOzD,uEAAuE;AACvE,UAAU,QAAQ;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAYD;;;;;;;;GAQG;AACH,qBAAa,gBAAiB,SAAQ,gBAAgB;IACpD;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB,CAA+B;IAMzD;;;;;;;;;;;OAWG;IACY,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAUxF;;;;;;;;;;OAUG;cACgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM;IAwC5D;;;;;OAKG;YACW,qBAAqB;CA4BpC"}
|
|
@@ -53,16 +53,18 @@ export class ObsidianExporter extends MarkdownExporter {
|
|
|
53
53
|
* Export all memory traces as Obsidian-flavoured `.md` files.
|
|
54
54
|
*
|
|
55
55
|
* Pre-fetches all knowledge-edge relationships into an in-memory cache,
|
|
56
|
-
* then delegates to the parent `export()` method. Directory creation
|
|
57
|
-
* file writing are handled there; only
|
|
56
|
+
* then delegates to the parent `export()` method. Directory creation,
|
|
57
|
+
* file writing and the checks on each trace's path are handled there; only
|
|
58
|
+
* `buildFileContent` is overridden.
|
|
58
59
|
*
|
|
59
60
|
* @param outputDir - Root directory to write the Obsidian vault into.
|
|
60
61
|
* @param options - Optional export configuration.
|
|
62
|
+
* @returns The traces left out, with the reason for each.
|
|
61
63
|
*/
|
|
62
64
|
async export(outputDir, options) {
|
|
63
65
|
// Pre-fetch all related nodes so buildFileContent can use them synchronously.
|
|
64
66
|
await this._prefetchRelatedNodes();
|
|
65
|
-
|
|
67
|
+
return super.export(outputDir, options);
|
|
66
68
|
}
|
|
67
69
|
// -------------------------------------------------------------------------
|
|
68
70
|
// Overridden helpers
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObsidianExporter.js","sourceRoot":"","sources":["../../../../src/cognition/memory/io/ObsidianExporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAuBtE,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,MAAM,OAAO,gBAAiB,SAAQ,gBAAgB;IAAtD;;QACE;;;;;WAKG;QACK,uBAAkB,GAAG,IAAI,GAAG,EAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"ObsidianExporter.js","sourceRoot":"","sources":["../../../../src/cognition/memory/io/ObsidianExporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAuBtE,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,MAAM,OAAO,gBAAiB,SAAQ,gBAAgB;IAAtD;;QACE;;;;;WAKG;QACK,uBAAkB,GAAG,IAAI,GAAG,EAAoB,CAAC;IAiH3D,CAAC;IA/GC,4EAA4E;IAC5E,aAAa;IACb,4EAA4E;IAE5E;;;;;;;;;;;OAWG;IACM,KAAK,CAAC,MAAM,CAAC,SAAiB,EAAE,OAAuB;QAC9D,8EAA8E;QAC9E,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,4EAA4E;IAC5E,qBAAqB;IACrB,4EAA4E;IAE5E;;;;;;;;;;OAUG;IACgB,gBAAgB,CAAC,KAAe;QACjD,IAAI,IAAI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qBAAqB;QACjC,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAEhC,IAAI,CAAC;YACH,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YACxC,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CACpC,OAAO,CAAC,WAAW,CAAC,gBAAgB,EAAE,YAAY,CAAC,EACnD,cAAc,CACf,CAAC;YACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAC/B,UAAU,eAAe;;;yDAGwB,CAClD,CAAC;YAEF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAC3D,IAAI,QAAQ,EAAE,CAAC;oBACb,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAC3B,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;gBACzD,CAAC;YACH,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,iEAAiE;QACnE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import type { MemoryTrace } from '../../core/types.js';
|
|
21
21
|
import type { CompileResult } from '../../../substrate/memory/wiki/types.js';
|
|
22
22
|
import type { ITool } from '../../../../core/tools/ITool.js';
|
|
23
|
-
import type { MemoryConfig, RememberOptions, RecallOptions, IngestOptions, IngestResult, ExportOptions, ImportOptions, ImportResult, ConsolidationResult, MemoryHealth } from './types.js';
|
|
23
|
+
import type { MemoryConfig, RememberOptions, RecallOptions, IngestOptions, IngestResult, ExportOptions, ExportResult, ImportOptions, ImportResult, ConsolidationResult, MemoryHealth } from './types.js';
|
|
24
24
|
import type { IKnowledgeGraph, KnowledgeEntity, KnowledgeRelation } from '../../retrieval/graph/knowledge/IKnowledgeGraph.js';
|
|
25
25
|
import type { RetrievalFeedback } from '../../retrieval/feedback/RetrievalFeedbackSignal.js';
|
|
26
26
|
/**
|
|
@@ -212,7 +212,10 @@ export declare class Memory {
|
|
|
212
212
|
/**
|
|
213
213
|
* Compile recent (non-wiki) traces into the markdown wiki, then re-index.
|
|
214
214
|
* Reads the wiki's watermark, folds every trace created since into pages, and
|
|
215
|
-
* advances the watermark. No-op when no wiki is attached.
|
|
215
|
+
* advances the watermark. No-op when no wiki is attached. A batch whose
|
|
216
|
+
* compile rejects, such as on a page write that fails for want of disk space
|
|
217
|
+
* or permission, leaves the watermark where it was, so the next compile
|
|
218
|
+
* starts from that batch again.
|
|
216
219
|
*
|
|
217
220
|
* @param opts.reason - What triggered this compile (telemetry + compiler hint).
|
|
218
221
|
*/
|
|
@@ -300,10 +303,18 @@ export declare class Memory {
|
|
|
300
303
|
* - `.sqlite` / `.db` -> SQLite file copy
|
|
301
304
|
* - directory path -> Markdown or Obsidian (based on `options.format`)
|
|
302
305
|
*
|
|
306
|
+
* A Markdown or Obsidian export writes one file per trace, in folders named
|
|
307
|
+
* after the trace's scope and type, and leaves out a trace whose scope, type
|
|
308
|
+
* or id is not a safe file or folder name, whose place in the export folder
|
|
309
|
+
* holds a link, symbolic or hard, or whose file would be an older trace's
|
|
310
|
+
* where names ignore case; the result lists each one left out. No file is
|
|
311
|
+
* written outside the export folder.
|
|
312
|
+
*
|
|
303
313
|
* @param outputPath - Path to write the export to.
|
|
304
314
|
* @param options - Optional format and content controls.
|
|
315
|
+
* @returns The traces the export left out, with the reason for each.
|
|
305
316
|
*/
|
|
306
|
-
export(outputPath: string, options?: ExportOptions): Promise<
|
|
317
|
+
export(outputPath: string, options?: ExportOptions): Promise<ExportResult>;
|
|
307
318
|
/**
|
|
308
319
|
* Import memory data from a file or directory.
|
|
309
320
|
*
|
|
@@ -1 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 export class Memory {
|
|
|
641
641
|
/**
|
|
642
642
|
* Compile recent (non-wiki) traces into the markdown wiki, then re-index.
|
|
643
643
|
* Reads the wiki's watermark, folds every trace created since into pages, and
|
|
644
|
-
* advances the watermark. No-op when no wiki is attached.
|
|
644
|
+
* advances the watermark. No-op when no wiki is attached. A batch whose
|
|
645
|
+
* compile rejects, such as on a page write that fails for want of disk space
|
|
646
|
+
* or permission, leaves the watermark where it was, so the next compile
|
|
647
|
+
* starts from that batch again.
|
|
645
648
|
*
|
|
646
649
|
* @param opts.reason - What triggered this compile (telemetry + compiler hint).
|
|
647
650
|
*/
|
|
@@ -672,7 +675,9 @@ export class Memory {
|
|
|
672
675
|
if (traces.length < BATCH)
|
|
673
676
|
break;
|
|
674
677
|
}
|
|
675
|
-
|
|
678
|
+
// A page reported in conflicts may still be on disk (its file written before the catalog failed), so the
|
|
679
|
+
// index runs after any compile that wrote or reported a page; it re-embeds only pages whose text changed.
|
|
680
|
+
if (aggregate.pagesWritten.length > 0 || aggregate.conflicts.length > 0) {
|
|
676
681
|
await this._wiki.store.index();
|
|
677
682
|
}
|
|
678
683
|
return aggregate;
|
|
@@ -979,8 +984,16 @@ export class Memory {
|
|
|
979
984
|
* - `.sqlite` / `.db` -> SQLite file copy
|
|
980
985
|
* - directory path -> Markdown or Obsidian (based on `options.format`)
|
|
981
986
|
*
|
|
987
|
+
* A Markdown or Obsidian export writes one file per trace, in folders named
|
|
988
|
+
* after the trace's scope and type, and leaves out a trace whose scope, type
|
|
989
|
+
* or id is not a safe file or folder name, whose place in the export folder
|
|
990
|
+
* holds a link, symbolic or hard, or whose file would be an older trace's
|
|
991
|
+
* where names ignore case; the result lists each one left out. No file is
|
|
992
|
+
* written outside the export folder.
|
|
993
|
+
*
|
|
982
994
|
* @param outputPath - Path to write the export to.
|
|
983
995
|
* @param options - Optional format and content controls.
|
|
996
|
+
* @returns The traces the export left out, with the reason for each.
|
|
984
997
|
*/
|
|
985
998
|
async export(outputPath, options) {
|
|
986
999
|
await this._initPromise;
|
|
@@ -990,25 +1003,23 @@ export class Memory {
|
|
|
990
1003
|
const { JsonExporter } = await import('../JsonExporter.js');
|
|
991
1004
|
const exporter = new JsonExporter(this._brain);
|
|
992
1005
|
await exporter.export(outputPath, options);
|
|
993
|
-
|
|
1006
|
+
return { refused: [] };
|
|
994
1007
|
}
|
|
995
1008
|
case 'markdown': {
|
|
996
1009
|
const { MarkdownExporter } = await import('../MarkdownExporter.js');
|
|
997
1010
|
const exporter = new MarkdownExporter(this._brain);
|
|
998
|
-
|
|
999
|
-
break;
|
|
1011
|
+
return exporter.export(outputPath, options);
|
|
1000
1012
|
}
|
|
1001
1013
|
case 'obsidian': {
|
|
1002
1014
|
const { ObsidianExporter } = await import('../ObsidianExporter.js');
|
|
1003
1015
|
const exporter = new ObsidianExporter(this._brain);
|
|
1004
|
-
|
|
1005
|
-
break;
|
|
1016
|
+
return exporter.export(outputPath, options);
|
|
1006
1017
|
}
|
|
1007
1018
|
case 'sqlite': {
|
|
1008
1019
|
const { SqliteExporter } = await import('../SqliteExporter.js');
|
|
1009
1020
|
const exporter = new SqliteExporter(this._brain);
|
|
1010
1021
|
await exporter.export(outputPath, options);
|
|
1011
|
-
|
|
1022
|
+
return { refused: [] };
|
|
1012
1023
|
}
|
|
1013
1024
|
default: {
|
|
1014
1025
|
throw new Error(`Memory.export(): unsupported format "${format}".`);
|