aegiscode 7.0.26 → 7.0.28

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.
Files changed (118) hide show
  1. package/SOURCE-OFFER.txt +9 -0
  2. package/package.json +4 -7
  3. package/scripts/check.mjs +1 -52
  4. package/scripts/demo.mjs +1 -94
  5. package/scripts/predist.mjs +1 -75
  6. package/scripts/runtests.mjs +1 -56
  7. package/scripts/seal-gate.mjs +1 -74
  8. package/src/agents.js +1 -139
  9. package/src/app.js +1 -2957
  10. package/src/art.js +1 -289
  11. package/src/chatflow.js +1 -3023
  12. package/src/checkpoint.js +1 -90
  13. package/src/clipboard.js +1 -424
  14. package/src/cloudsync.js +1 -528
  15. package/src/commands.js +1 -4089
  16. package/src/config.js +1 -581
  17. package/src/connect.js +1 -349
  18. package/src/credentials.js +1 -33
  19. package/src/deps.js +1 -232
  20. package/src/devrun.js +1 -187
  21. package/src/diff.js +1 -333
  22. package/src/diffview.js +1 -296
  23. package/src/engine.js +1 -297
  24. package/src/entitlement.js +1 -355
  25. package/src/events.js +1 -707
  26. package/src/export.js +1 -67
  27. package/src/filepreview.js +1 -153
  28. package/src/fingerprint.js +1 -592
  29. package/src/format.js +1 -259
  30. package/src/fuzzy.js +1 -119
  31. package/src/history.js +1 -423
  32. package/src/init.js +1 -175
  33. package/src/input.js +1 -139
  34. package/src/keys.js +1 -183
  35. package/src/markdown.js +1 -306
  36. package/src/models.js +1 -507
  37. package/src/naming.js +1 -57
  38. package/src/overlays.js +1 -462
  39. package/src/panels.js +1 -1418
  40. package/src/ping.js +1 -226
  41. package/src/presence.js +1 -238
  42. package/src/render.js +1 -516
  43. package/src/screen.js +1 -518
  44. package/src/screens.js +1 -896
  45. package/src/secret.js +1 -59
  46. package/src/securefs.js +1 -359
  47. package/src/settings.js +1 -155
  48. package/src/shared.js +1 -52
  49. package/src/sharedpaths.js +1 -53
  50. package/src/signup.js +1 -156
  51. package/src/summarize.js +1 -95
  52. package/src/sysdiag.js +1 -585
  53. package/src/system.js +1 -40
  54. package/src/theme.js +1 -570
  55. package/src/title.js +1 -220
  56. package/src/todos.js +1 -115
  57. package/src/tokens.js +1 -263
  58. package/src/topup.js +1 -210
  59. package/src/update.js +1 -191
  60. package/vendor/client/aegis.js +1 -2441
  61. package/vendor/client/attest.js +1 -518
  62. package/vendor/client/authorship-key.js +1 -410
  63. package/vendor/client/auto-provision.js +1 -134
  64. package/vendor/client/brain-catalog.js +1 -268
  65. package/vendor/client/byok-catalog.js +1 -199
  66. package/vendor/client/catalog-client.js +1 -487
  67. package/vendor/client/conversation-export.js +1 -177
  68. package/vendor/client/credentials.js +1 -494
  69. package/vendor/client/device-fingerprint.js +1 -141
  70. package/vendor/client/drive-connect.js +1 -110
  71. package/vendor/client/drive-upload.js +1 -234
  72. package/vendor/client/env-file.js +1 -1273
  73. package/vendor/client/fingerprint.js +1 -1064
  74. package/vendor/client/foreign-memory.js +1 -669
  75. package/vendor/client/google-signin.js +1 -133
  76. package/vendor/client/hooks.js +1 -430
  77. package/vendor/client/model-discovery.js +1 -373
  78. package/vendor/client/naming.js +1 -283
  79. package/vendor/client/platform.js +1 -937
  80. package/vendor/client/prefs.js +1 -351
  81. package/vendor/client/presence-constants.js +1 -107
  82. package/vendor/client/presence.js +1 -438
  83. package/vendor/client/record-vault.js +3 -1055
  84. package/vendor/client/session-store.js +1 -575
  85. package/vendor/client/topup.js +1 -297
  86. package/vendor/client/touch.js +1 -458
  87. package/vendor/client/update.js +1 -763
  88. package/vendor/client/user-models.js +1 -381
  89. package/vendor/desktop/lib/local/agents.js +1 -105
  90. package/vendor/desktop/lib/local/attachments.js +1 -276
  91. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  92. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  93. package/vendor/desktop/lib/local/context.js +1 -125
  94. package/vendor/desktop/lib/local/engine.js +1 -3666
  95. package/vendor/desktop/lib/local/entitlement.js +1 -660
  96. package/vendor/desktop/lib/local/exec-plan.js +1 -269
  97. package/vendor/desktop/lib/local/git-scope.js +1 -228
  98. package/vendor/desktop/lib/local/integrity.js +1 -163
  99. package/vendor/desktop/lib/local/local.js +1 -2145
  100. package/vendor/desktop/lib/local/prompt.js +1 -280
  101. package/vendor/desktop/lib/local/queue.js +1 -560
  102. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  103. package/vendor/desktop/lib/local/shell.js +1 -712
  104. package/vendor/desktop/lib/local/spill.js +1 -75
  105. package/vendor/desktop/lib/local/tools.js +1 -1328
  106. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  107. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  108. package/vendor/desktop/lib/settings.js +1 -890
  109. package/vendor/desktop/main.js +1 -4890
  110. package/vendor/desktop/renderer/usage.js +1 -1239
  111. package/vendor/hosts/install.js +1 -638
  112. package/vendor/hosts/openai-shim.js +1 -515
  113. package/vendor/hosts/spec.js +1 -164
  114. package/vendor/hosts/targets.js +1 -346
  115. package/vendor/mcp/server.js +1 -221
  116. package/vendor/mcp/tools.js +1 -408
  117. package/vendor/one/src/child.js +1 -285
  118. package/vendor/one/src/permissions.js +1 -383
@@ -1,671 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
- // Conveying a modified copy, or running one as a network service, owes the
5
- // corresponding source under this licence (§5/§13) — see LICENSING.md.
6
- 'use strict';
7
-
8
- /**
9
- * foreign-memory.js — scan the local memory/transcript stores that *other* AI
10
- * coding tools leave on disk, and normalise them into AEGIS cloud memory
11
- * entries (the shape `POST /api/memory/save {entries}` accepts).
12
- *
13
- * Why this file exists: AEGIS memory is only as useful as what's in it. A user
14
- * arriving from Claude Code (or Codex, Cursor, Gemini CLI, …) already has
15
- * months of durable context sitting in a proprietary directory that AEGIS
16
- * cannot see. This module is the read-only importer for that.
17
- *
18
- * Design rules (all of them load-bearing):
19
- *
20
- * 1. Zero runtime deps, pure Node — like client/aegis.js it is shared verbatim
21
- * between the CLI/MCP server (requires ../client/…) and AEGIS Desktop
22
- * (vendored to desktop/vendor/ by scripts/predist.mjs, because
23
- * electron-builder cannot reach outside the app dir).
24
- *
25
- * 2. READ-ONLY. Nothing here writes, moves, or deletes inside a foreign
26
- * tool's directory. Ever.
27
- *
28
- * 3. Probe-and-skip, never assume. Every source declares its candidate roots
29
- * and is simply absent if those paths don't exist. A missing source is a
30
- * normal result (`present: false`), not an error — the whole point is that
31
- * we cannot know which of these tools a given machine has.
32
- *
33
- * 4. Deterministic ids. `/api/memory/save` upserts on (user_id, id), so an id
34
- * derived from the *content* makes a re-scan idempotent instead of
35
- * duplicating every entry on every run.
36
- *
37
- * 5. Bounded session fan-out. aegis1's free tier meters distinct
38
- * memory_entries.session values via _memory_sync_access(). If we minted one
39
- * session per foreign transcript, a single import would blow the free
40
- * session limit and 402 the entire batch. So every entry from a source
41
- * collapses into ONE session, `import:<source>`. Importing from ten tools
42
- * costs at most ten sessions, and re-runs cost zero (upsert).
43
- *
44
- * Local-only and offline: this module never opens a socket. Scanning and
45
- * uploading are separate steps (see mcp/server.js `aegis_memory_import`),
46
- * precisely so `scan()` can be dry-run and unit-tested with no network.
47
- */
48
-
49
- const fs = require('node:fs');
50
- const path = require('node:path');
51
- const os = require('node:os');
52
- const crypto = require('node:crypto');
53
-
54
- // --- bounds ---------------------------------------------------------------
55
- // A memory store is not a transcript dump. These keep one import from turning
56
- // into a 100k-entry upload that helps nobody.
57
- const DEFAULTS = {
58
- minChars: 24, // skip "ok", "yes", "continue" — fragments carry no memory value
59
- maxChars: 2000, // truncate long agent replies
60
- maxEntriesPerSource: 500,
61
- maxFilesPerSource: 400,
62
- maxFileBytes: 8 * 1024 * 1024, // don't read a multi-GB transcript into RAM
63
- };
64
-
65
- // Noise that shows up in these stores and is never worth remembering.
66
- const NOISE = [
67
- /^<command-name>/i,
68
- /^<local-command-stdout>/i,
69
- /^\[Request interrupted by user/i,
70
- /^Caveat: The messages below were generated by the user while running local commands/i,
71
- /^(ok|okay|yes|no|yep|nope|sure|thanks|thank you|continue|proceed|go on|done)[.!]?$/i,
72
- ];
73
-
74
- function isNoise(text) {
75
- return NOISE.some((re) => re.test(text));
76
- }
77
-
78
- function homeDir(home) {
79
- return home || os.homedir();
80
- }
81
-
82
- // --- per-platform root layout ---------------------------------------------
83
- // Every source below declares its roots through these helpers instead of
84
- // hardcoding `path.join(home, '.config', name)`. That hardcoding was a
85
- // cross-platform bug, not a style choice: `~/.config` is the XDG convention on
86
- // Linux only. On Windows the equivalent trees are `%APPDATA%` (Roaming) and
87
- // `%LOCALAPPDATA%` (Local), and several of these tools use
88
- // `~/Library/Application Support` on macOS. Resolving only `~/.config` meant
89
- // the entire scan silently reported `present: false` for every source on a
90
- // Windows install — the app packaged and ran fine, it simply found nothing to
91
- // import, with no error to explain why.
92
- //
93
- // `platform` is a parameter (not a bare `process.platform` read) so the
94
- // Windows and macOS layouts stay unit-testable from Linux CI.
95
-
96
- function platformOf(platform) {
97
- return platform || process.platform;
98
- }
99
-
100
- /** Roaming app data (`%APPDATA%`), or null off Windows. */
101
- function roamingDir(home, plat) {
102
- if (plat !== 'win32') return null;
103
- // A redirected profile can move %APPDATA% off the home dir, so prefer the
104
- // real env var — but only when scanning the real home. A caller-supplied
105
- // home (tests, overrides) is the source of truth.
106
- if (home === os.homedir() && process.env.APPDATA) return process.env.APPDATA;
107
- return path.join(home, 'AppData', 'Roaming');
108
- }
109
-
110
- /** Local app data / cache (`%LOCALAPPDATA%`), or null off Windows. */
111
- function localDir(home, plat) {
112
- if (plat !== 'win32') return null;
113
- if (home === os.homedir() && process.env.LOCALAPPDATA) return process.env.LOCALAPPDATA;
114
- return path.join(home, 'AppData', 'Local');
115
- }
116
-
117
- /** macOS `~/Library/Application Support`, or null elsewhere. */
118
- function macSupportDir(home, plat) {
119
- return plat === 'darwin' ? path.join(home, 'Library', 'Application Support') : null;
120
- }
121
-
122
- /**
123
- * Candidate roots for one app, across all three platform layouts.
124
- *
125
- * Deliberately additive: the POSIX paths are always included, so a source can
126
- * never *lose* a root it used to match, and the Windows/macOS alternates are
127
- * appended only when they apply. `present` is still a probe of existing
128
- * directories, so extra candidates that don't exist change nothing.
129
- *
130
- * @param {boolean} [opts.config] include `<config>/<name>` layouts
131
- * @param {boolean} [opts.data] include `<data>/<name>` (XDG share) layouts
132
- * @param {boolean} [opts.macSupport] include `~/Library/Application Support/<name>`
133
- */
134
- function appRoots(home, plat, name, { config = true, data = false, macSupport = false } = {}) {
135
- const roots = [];
136
- if (config) roots.push(path.join(home, '.config', name)); // linux (and XDG-following mac apps)
137
- if (data) roots.push(path.join(home, '.local', 'share', name)); // linux XDG data
138
- const roaming = roamingDir(home, plat);
139
- if (roaming && config) roots.push(path.join(roaming, name)); // windows %APPDATA%
140
- const local = localDir(home, plat);
141
- if (local) roots.push(path.join(local, name)); // windows %LOCALAPPDATA%
142
- if (macSupport) {
143
- const support = macSupportDir(home, plat);
144
- if (support) roots.push(path.join(support, name)); // macOS
145
- }
146
- return roots;
147
- }
148
-
149
- /** Collapse whitespace, strip control chars, trim. */
150
- function cleanText(value) {
151
- if (typeof value !== 'string') return '';
152
- // eslint-disable-next-line no-control-regex
153
- return value.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g, ' ').replace(/\s+/g, ' ').trim();
154
- }
155
-
156
- /** Content-addressed id: same text from the same place always maps to one row. */
157
- function stableId(...parts) {
158
- return `import-${crypto.createHash('sha1').update(parts.join('|')).digest('hex').slice(0, 32)}`;
159
- }
160
-
161
- function readJsonl(file) {
162
- const out = [];
163
- let raw;
164
- try {
165
- raw = fs.readFileSync(file, 'utf8');
166
- } catch {
167
- return out;
168
- }
169
- for (const line of raw.split('\n')) {
170
- const trimmed = line.trim();
171
- if (!trimmed) continue;
172
- try {
173
- out.push(JSON.parse(trimmed));
174
- } catch {
175
- /* torn/partial line — skip, never throw on foreign data */
176
- }
177
- }
178
- return out;
179
- }
180
-
181
- /**
182
- * Depth-first file walk, bounded. Skips node_modules/.git and any directory
183
- * the source marks as off-limits. Never follows symlinks (a foreign store is
184
- * untrusted input; a symlink loop must not hang the importer).
185
- */
186
- function walkFiles(root, { ext, limit }) {
187
- const found = [];
188
- const stack = [root];
189
- while (stack.length && found.length < limit) {
190
- const dir = stack.pop();
191
- let items;
192
- try {
193
- items = fs.readdirSync(dir, { withFileTypes: true });
194
- } catch {
195
- continue;
196
- }
197
- for (const item of items) {
198
- if (found.length >= limit) break;
199
- if (item.isSymbolicLink()) continue;
200
- const full = path.join(dir, item.name);
201
- if (item.isDirectory()) {
202
- if (item.name === 'node_modules' || item.name === '.git') continue;
203
- stack.push(full);
204
- } else if (item.isFile()) {
205
- if (ext && !ext.some((e) => item.name.endsWith(e))) continue;
206
- found.push(full);
207
- }
208
- }
209
- }
210
- return found;
211
- }
212
-
213
- function fileSize(file) {
214
- try {
215
- return fs.statSync(file).size;
216
- } catch {
217
- return 0;
218
- }
219
- }
220
-
221
- function isFile(p) {
222
- try {
223
- return fs.statSync(p).isFile();
224
- } catch {
225
- return false;
226
- }
227
- }
228
-
229
- function isDir(p) {
230
- try {
231
- return fs.statSync(p).isDirectory();
232
- } catch {
233
- return false;
234
- }
235
- }
236
-
237
- // --- extractors -----------------------------------------------------------
238
-
239
- /**
240
- * Claude Code / Claude Desktop style transcript line:
241
- * {type:'user', message:{content: 'string' | [{type:'text',text}]}}
242
- * {type:'assistant', message:{content:[{type:'text'|'tool_use'|'thinking'}]}}
243
- * Only human text and assistant *text* blocks are memory-worthy; tool calls,
244
- * results and hidden reasoning are not (and would flood the store).
245
- */
246
- function textFromClaudeMessage(message) {
247
- if (!message) return '';
248
- const content = message.content;
249
- if (typeof content === 'string') return cleanText(content);
250
- if (!Array.isArray(content)) return '';
251
- return content
252
- .filter((block) => block && block.type === 'text' && typeof block.text === 'string')
253
- .map((block) => block.text)
254
- .join('\n');
255
- }
256
-
257
- function extractClaudeJsonl(file, ctx) {
258
- const out = [];
259
- const rel = ctx.rel(file);
260
- for (const [index, row] of readJsonl(file).entries()) {
261
- const type = row && row.type;
262
- const role = type === 'user' ? 'user' : type === 'assistant' ? 'assistant' : null;
263
- if (!role) continue;
264
- if (row.isSidechain) continue; // subagent chatter, not user context
265
- const text = cleanText(textFromClaudeMessage(row.message));
266
- if (!text) continue;
267
- out.push({ role, text, timestamp: row.timestamp || '', where: `${rel}#${index}` });
268
- }
269
- return out;
270
- }
271
-
272
- /**
273
- * Best-effort generic `{role, content}` JSONL — the shape most OpenAI-compatible
274
- * CLIs (and several agent frameworks) persist. We only claim what we can prove:
275
- * a row must carry a recognisable role AND string content.
276
- */
277
- function extractGenericJsonl(file, ctx) {
278
- const out = [];
279
- const rel = ctx.rel(file);
280
- for (const [index, row] of readJsonl(file).entries()) {
281
- if (!row || typeof row !== 'object') continue;
282
- const role = row.role || (row.message && row.message.role);
283
- if (role !== 'user' && role !== 'assistant') continue;
284
- const content = row.content != null ? row.content : row.message && row.message.content;
285
- const text = cleanText(typeof content === 'string' ? content : textFromClaudeMessage({ content }));
286
- if (!text) continue;
287
- out.push({ role, text, timestamp: row.timestamp || row.created_at || '', where: `${rel}#${index}` });
288
- }
289
- return out;
290
- }
291
-
292
- /** A markdown/text note file is itself one memory entry. */
293
- function extractMarkdown(file, ctx) {
294
- if (fileSize(file) > DEFAULTS.maxFileBytes) return [];
295
- let raw;
296
- try {
297
- raw = fs.readFileSync(file, 'utf8');
298
- } catch {
299
- return [];
300
- }
301
- const text = cleanText(raw);
302
- if (!text) return [];
303
- return [{ role: 'user', text, timestamp: '', where: ctx.rel(file) }];
304
- }
305
-
306
- /** A JSON memory file: array of entries, or {entries|memories|memory: [...]}. */
307
- function extractJsonMemory(file, ctx) {
308
- if (fileSize(file) > DEFAULTS.maxFileBytes) return [];
309
- let data;
310
- try {
311
- data = JSON.parse(fs.readFileSync(file, 'utf8'));
312
- } catch {
313
- return [];
314
- }
315
- const list = Array.isArray(data)
316
- ? data
317
- : data && Array.isArray(data.entries)
318
- ? data.entries
319
- : data && Array.isArray(data.memories)
320
- ? data.memories
321
- : data && Array.isArray(data.memory)
322
- ? data.memory
323
- : [];
324
- const rel = ctx.rel(file);
325
- return list
326
- .map((item, index) => {
327
- if (typeof item === 'string') {
328
- return { role: 'user', text: cleanText(item), timestamp: '', where: `${rel}#${index}` };
329
- }
330
- const text = cleanText(item && (item.content || item.text || item.value || item.fact));
331
- return { role: 'user', text, timestamp: (item && (item.timestamp || item.createdAt)) || '', where: `${rel}#${index}` };
332
- })
333
- .filter((e) => e.text);
334
- }
335
-
336
- // --- source registry ------------------------------------------------------
337
-
338
- /**
339
- * Every known foreign store. `roots` are candidates — a source is present only
340
- * if at least one root exists, and only the roots that exist are walked.
341
- *
342
- * `verified` marks how much trust the extractor has earned:
343
- * verified: true — format confirmed against real files on this machine (or
344
- * in a test fixture), schema-pinned.
345
- * verified: false — best-effort probe over a documented/observed layout.
346
- * Counts from these should be treated as a lower bound.
347
- */
348
- const SOURCES = [
349
- {
350
- id: 'claude-code',
351
- label: 'Claude Code',
352
- verified: true,
353
- // ~/.claude/projects/<slug>/<session-uuid>.jsonl is the canonical store.
354
- roots: (home) => [path.join(home, '.claude', 'projects')],
355
- files: (home) => [path.join(home, '.claude', 'history.jsonl')],
356
- extract: { '**/*.jsonl': extractClaudeJsonl, '*.jsonl': extractClaudeJsonl },
357
- },
358
- {
359
- id: 'claude-memory',
360
- label: 'Claude memory files',
361
- verified: true,
362
- roots: (home) => [path.join(home, '.claude', 'memory')],
363
- files: (home) => [path.join(home, '.claude', 'memory.json')],
364
- extract: { '.json': extractJsonMemory, '.md': extractMarkdown, '.txt': extractMarkdown },
365
- },
366
- {
367
- id: 'aegiscodex',
368
- label: 'AEGIS Codex engine',
369
- verified: true,
370
- roots: (home) => [path.join(home, '.aegiscodex', 'memory')],
371
- files: () => [],
372
- extract: { '.json': extractJsonMemory, '.jsonl': extractGenericJsonl, '.md': extractMarkdown },
373
- },
374
- {
375
- id: 'codex',
376
- label: 'OpenAI Codex CLI',
377
- verified: false,
378
- roots: (home) => [path.join(home, '.codex')],
379
- files: () => [],
380
- extract: { '.jsonl': extractGenericJsonl, '.json': extractJsonMemory, '.md': extractMarkdown },
381
- },
382
- {
383
- id: 'gemini-cli',
384
- label: 'Gemini CLI',
385
- verified: false,
386
- roots: (home) => [path.join(home, '.gemini')],
387
- files: () => [],
388
- extract: { '.json': extractJsonMemory, '.jsonl': extractGenericJsonl, '.md': extractMarkdown },
389
- },
390
- {
391
- id: 'cursor',
392
- label: 'Cursor',
393
- verified: false,
394
- roots: (home) => [path.join(home, '.cursor')],
395
- files: () => [],
396
- extract: { '.json': extractJsonMemory, '.jsonl': extractGenericJsonl, '.md': extractMarkdown },
397
- },
398
- {
399
- id: 'continue',
400
- label: 'Continue',
401
- verified: false,
402
- roots: (home) => [path.join(home, '.continue')],
403
- files: () => [],
404
- extract: { '.json': extractJsonMemory, '.jsonl': extractGenericJsonl, '.md': extractMarkdown },
405
- },
406
- {
407
- id: 'goose',
408
- label: 'Goose',
409
- verified: false,
410
- roots: (home, plat) => appRoots(home, plat, 'goose', { data: true }),
411
- files: () => [],
412
- extract: { '.jsonl': extractGenericJsonl, '.json': extractJsonMemory, '.md': extractMarkdown },
413
- },
414
- {
415
- id: 'opencode',
416
- label: 'opencode',
417
- verified: false,
418
- roots: (home, plat) => appRoots(home, plat, 'opencode', { data: true }),
419
- files: () => [],
420
- extract: { '.json': extractJsonMemory, '.jsonl': extractGenericJsonl, '.md': extractMarkdown },
421
- },
422
- {
423
- id: 'windsurf',
424
- label: 'Windsurf / Codeium',
425
- verified: false,
426
- // Home-relative dot-dirs on every platform; macOS additionally stores the
427
- // app under Application Support.
428
- roots: (home, plat) => [
429
- path.join(home, '.windsurf'),
430
- path.join(home, '.codeium'),
431
- ...appRoots(home, plat, 'Windsurf', { config: false, macSupport: true }),
432
- ...appRoots(home, plat, 'Codeium', { config: false, macSupport: true }),
433
- ],
434
- files: () => [],
435
- extract: { '.json': extractJsonMemory, '.jsonl': extractGenericJsonl, '.md': extractMarkdown },
436
- },
437
- {
438
- id: 'zed',
439
- label: 'Zed',
440
- verified: false,
441
- // Zed follows XDG on Linux, uses %APPDATA% on Windows, and keeps
442
- // ~/.config/zed on macOS too — `config: true` covers all three.
443
- roots: (home, plat) => appRoots(home, plat, 'zed'),
444
- files: () => [],
445
- extract: { '.json': extractJsonMemory, '.jsonl': extractGenericJsonl },
446
- },
447
- {
448
- id: 'claude-desktop',
449
- label: 'Claude Desktop app',
450
- verified: false,
451
- roots: (home, plat) => appRoots(home, plat, 'Claude', { macSupport: true }),
452
- files: () => [],
453
- extract: { '.json': extractJsonMemory, '.jsonl': extractClaudeJsonl, '.md': extractMarkdown },
454
- },
455
- ];
456
-
457
- /**
458
- * Reduce an extractor pattern to its literal trailing filename suffix.
459
- * '**\/*.jsonl' -> '.jsonl' '*.jsonl' -> '.jsonl' '.json' -> '.json'
460
- * Everything before the last `*` is a glob, not part of the literal suffix.
461
- */
462
- function suffixOf(pattern) {
463
- const star = pattern.lastIndexOf('*');
464
- return star === -1 ? pattern : pattern.slice(star + 1);
465
- }
466
-
467
- /** Pick the extractor whose suffix matches the file; first match wins. */
468
- function extractorFor(extract, file) {
469
- for (const [pattern, fn] of Object.entries(extract)) {
470
- if (file.endsWith(suffixOf(pattern))) return fn;
471
- }
472
- return null;
473
- }
474
-
475
- function sourceById(id) {
476
- return SOURCES.find((s) => s.id === id) || null;
477
- }
478
-
479
- /**
480
- * Which sources exist on this machine. Cheap (stat only) — safe to call from a
481
- * UI before the user commits to an import.
482
- */
483
- function listSources(home, platform) {
484
- const h = homeDir(home);
485
- const plat = platformOf(platform);
486
- return SOURCES.map((source) => {
487
- const roots = source.roots(h, plat).filter(isDir);
488
- const files = (source.files ? source.files(h) : []).filter(isFile);
489
- return {
490
- id: source.id,
491
- label: source.label,
492
- verified: source.verified,
493
- roots: roots.concat(files),
494
- present: roots.length > 0 || files.length > 0,
495
- };
496
- });
497
- }
498
-
499
- /**
500
- * Scan foreign stores into normalised AEGIS memory entries.
501
- *
502
- * @param {object} [opts]
503
- * @param {string} [opts.home] override home dir (tests)
504
- * @param {string[]} [opts.sources] restrict to these source ids
505
- * @param {number} [opts.limit] max entries returned overall
506
- * @param {number} [opts.minChars] drop entries shorter than this
507
- * @param {number} [opts.maxChars] truncate entries longer than this
508
- * @param {number} [opts.maxEntriesPerSource]
509
- * @param {string} [opts.platform] override platform (tests); defaults to process.platform
510
- * @returns {{entries: Array, sources: Array, totals: object, scannedAt: string}}
511
- */
512
- function scan(opts = {}) {
513
- const home = homeDir(opts.home);
514
- const plat = platformOf(opts.platform);
515
- const minChars = opts.minChars != null ? opts.minChars : DEFAULTS.minChars;
516
- const maxChars = opts.maxChars != null ? opts.maxChars : DEFAULTS.maxChars;
517
- const perSource = opts.maxEntriesPerSource != null ? opts.maxEntriesPerSource : DEFAULTS.maxEntriesPerSource;
518
- const overall = opts.limit != null ? opts.limit : Infinity;
519
- const wanted = opts.sources && opts.sources.length ? new Set(opts.sources) : null;
520
-
521
- const results = [];
522
- const entries = [];
523
- const seen = new Set(); // dedupe identical text within one scan
524
-
525
- for (const source of SOURCES) {
526
- if (wanted && !wanted.has(source.id)) continue;
527
-
528
- const roots = source.roots(home, plat).filter(isDir);
529
- const looseFiles = (source.files ? source.files(home) : []).filter(isFile);
530
- const present = roots.length > 0 || looseFiles.length > 0;
531
-
532
- const record = {
533
- id: source.id,
534
- label: source.label,
535
- verified: source.verified,
536
- present,
537
- files: 0,
538
- scanned: 0,
539
- count: 0,
540
- skipped: 0,
541
- roots,
542
- session: `import:${source.id}`,
543
- };
544
-
545
- if (!present) {
546
- results.push(record);
547
- continue;
548
- }
549
-
550
- const candidates = looseFiles.slice();
551
- for (const root of roots) {
552
- // Literal suffixes only — a glob like '**/*.jsonl' is not a filename
553
- // suffix, and passing it to endsWith() silently matched nothing.
554
- const suffixes = Object.keys(source.extract).map(suffixOf);
555
- candidates.push(...walkFiles(root, { ext: suffixes, limit: DEFAULTS.maxFilesPerSource }));
556
- }
557
-
558
- const ctx = { rel: (f) => path.relative(home, f) };
559
-
560
- for (const file of candidates) {
561
- if (record.count >= perSource || entries.length >= overall) break;
562
- if (fileSize(file) > DEFAULTS.maxFileBytes) {
563
- record.skipped += 1;
564
- continue;
565
- }
566
- const extractor = extractorFor(source.extract, file);
567
- if (!extractor) continue;
568
- record.files += 1;
569
-
570
- let found;
571
- try {
572
- found = extractor(file, ctx);
573
- } catch {
574
- continue; // foreign data is untrusted: a bad file must not kill the scan
575
- }
576
-
577
- for (const item of found) {
578
- if (record.count >= perSource || entries.length >= overall) break;
579
- record.scanned += 1;
580
- let text = item.text;
581
- if (text.length > maxChars) text = `${text.slice(0, maxChars)}…`;
582
- if (text.length < minChars || isNoise(text)) {
583
- record.skipped += 1;
584
- continue;
585
- }
586
- // Include role in the id so a prompt and an identical reply stay distinct.
587
- const id = stableId(source.id, item.where, item.role, text);
588
- if (seen.has(id)) continue;
589
- seen.add(id);
590
-
591
- entries.push({
592
- id,
593
- content: text,
594
- role: item.role,
595
- source: source.id,
596
- session: record.session, // bounded fan-out: one session per source
597
- tags: ['imported', source.id],
598
- importance: 5,
599
- timestamp: item.timestamp || new Date().toISOString(),
600
- });
601
- record.count += 1;
602
- }
603
- }
604
-
605
- results.push(record);
606
- }
607
-
608
- return {
609
- entries,
610
- sources: results,
611
- totals: {
612
- entries: entries.length,
613
- sourcesPresent: results.filter((r) => r.present).length,
614
- sourcesWithEntries: results.filter((r) => r.count > 0).length,
615
- scanned: results.reduce((n, r) => n + r.scanned, 0),
616
- skipped: results.reduce((n, r) => n + r.skipped, 0),
617
- },
618
- scannedAt: new Date().toISOString(),
619
- };
620
- }
621
-
622
- /** Split entries into upload-sized chunks (server takes a batch per request). */
623
- function chunk(entries, size = 200) {
624
- const out = [];
625
- for (let i = 0; i < entries.length; i += size) out.push(entries.slice(i, i + size));
626
- return out;
627
- }
628
-
629
- /** One-line human summary — shared by the MCP tool and the desktop UI. */
630
- function describe(report) {
631
- const present = report.sources.filter((s) => s.present);
632
- if (!present.length) {
633
- return 'No other AI tool memory found on this machine.';
634
- }
635
- const lines = present.map((s) => {
636
- const tag = s.verified ? '' : ' (best-effort layout)';
637
- return ` ${s.label}${tag}: ${s.count} entries from ${s.files} file(s), ${s.skipped} skipped`;
638
- });
639
- const header = `Found ${report.totals.entries} importable entries across ${report.totals.sourcesWithEntries} source(s):`;
640
- return [header, ...lines].join('\n');
641
- }
642
-
643
- module.exports = {
644
- DEFAULTS,
645
- SOURCES,
646
- scan,
647
- listSources,
648
- describe,
649
- chunk,
650
- stableId,
651
- sourceById,
652
- // exported for tests
653
- _internal: {
654
- walkFiles,
655
- extractClaudeJsonl,
656
- extractGenericJsonl,
657
- extractJsonMemory,
658
- extractMarkdown,
659
- cleanText,
660
- isNoise,
661
- suffixOf,
662
- // Platform-layout resolution: exported so the Windows/macOS branch can be
663
- // exercised from a Linux CI runner (the roots themselves are probed with
664
- // isDir, so they are unobservable on the host that lacks them).
665
- platformOf,
666
- roamingDir,
667
- localDir,
668
- macSupportDir,
669
- appRoots,
670
- },
671
- };
3
+ "use strict";const fs=require("node:fs"),path=require("node:path"),os=require("node:os"),crypto=require("node:crypto"),DEFAULTS={minChars:24,maxChars:2e3,maxEntriesPerSource:500,maxFilesPerSource:400,maxFileBytes:8388608},NOISE=[/^<command-name>/i,/^<local-command-stdout>/i,/^\[Request interrupted by user/i,/^Caveat: The messages below were generated by the user while running local commands/i,/^(ok|okay|yes|no|yep|nope|sure|thanks|thank you|continue|proceed|go on|done)[.!]?$/i];function isNoise(e){return NOISE.some((t=>t.test(e)))}function homeDir(e){return e||os.homedir()}function platformOf(e){return e||process.platform}function roamingDir(e,t){return"win32"!==t?null:e===os.homedir()&&process.env.APPDATA?process.env.APPDATA:path.join(e,"AppData","Roaming")}function localDir(e,t){return"win32"!==t?null:e===os.homedir()&&process.env.LOCALAPPDATA?process.env.LOCALAPPDATA:path.join(e,"AppData","Local")}function macSupportDir(e,t){return"darwin"===t?path.join(e,"Library","Application Support"):null}function appRoots(e,t,r,{config:o=!0,data:n=!1,macSupport:s=!1}={}){const i=[];o&&i.push(path.join(e,".config",r)),n&&i.push(path.join(e,".local","share",r));const a=roamingDir(e,t);a&&o&&i.push(path.join(a,r));const c=localDir(e,t);if(c&&i.push(path.join(c,r)),s){const o=macSupportDir(e,t);o&&i.push(path.join(o,r))}return i}function cleanText(e){return"string"!=typeof e?"":e.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g," ").replace(/\s+/g," ").trim()}function stableId(...e){return`import-${crypto.createHash("sha1").update(e.join("|")).digest("hex").slice(0,32)}`}function readJsonl(e){const t=[];let r;try{r=fs.readFileSync(e,"utf8")}catch{return t}for(const e of r.split("\n")){const r=e.trim();if(r)try{t.push(JSON.parse(r))}catch{}}return t}function walkFiles(e,{ext:t,limit:r}){const o=[],n=[e];for(;n.length&&o.length<r;){const e=n.pop();let s;try{s=fs.readdirSync(e,{withFileTypes:!0})}catch{continue}for(const i of s){if(o.length>=r)break;if(i.isSymbolicLink())continue;const s=path.join(e,i.name);if(i.isDirectory()){if("node_modules"===i.name||".git"===i.name)continue;n.push(s)}else if(i.isFile()){if(t&&!t.some((e=>i.name.endsWith(e))))continue;o.push(s)}}}return o}function fileSize(e){try{return fs.statSync(e).size}catch{return 0}}function isFile(e){try{return fs.statSync(e).isFile()}catch{return!1}}function isDir(e){try{return fs.statSync(e).isDirectory()}catch{return!1}}function textFromClaudeMessage(e){if(!e)return"";const t=e.content;return"string"==typeof t?cleanText(t):Array.isArray(t)?t.filter((e=>e&&"text"===e.type&&"string"==typeof e.text)).map((e=>e.text)).join("\n"):""}function extractClaudeJsonl(e,t){const r=[],o=t.rel(e);for(const[t,n]of readJsonl(e).entries()){const e=n&&n.type,s="user"===e?"user":"assistant"===e?"assistant":null;if(!s)continue;if(n.isSidechain)continue;const i=cleanText(textFromClaudeMessage(n.message));i&&r.push({role:s,text:i,timestamp:n.timestamp||"",where:`${o}#${t}`})}return r}function extractGenericJsonl(e,t){const r=[],o=t.rel(e);for(const[t,n]of readJsonl(e).entries()){if(!n||"object"!=typeof n)continue;const e=n.role||n.message&&n.message.role;if("user"!==e&&"assistant"!==e)continue;const s=null!=n.content?n.content:n.message&&n.message.content,i=cleanText("string"==typeof s?s:textFromClaudeMessage({content:s}));i&&r.push({role:e,text:i,timestamp:n.timestamp||n.created_at||"",where:`${o}#${t}`})}return r}function extractMarkdown(e,t){if(fileSize(e)>DEFAULTS.maxFileBytes)return[];let r;try{r=fs.readFileSync(e,"utf8")}catch{return[]}const o=cleanText(r);return o?[{role:"user",text:o,timestamp:"",where:t.rel(e)}]:[]}function extractJsonMemory(e,t){if(fileSize(e)>DEFAULTS.maxFileBytes)return[];let r;try{r=JSON.parse(fs.readFileSync(e,"utf8"))}catch{return[]}const o=Array.isArray(r)?r:r&&Array.isArray(r.entries)?r.entries:r&&Array.isArray(r.memories)?r.memories:r&&Array.isArray(r.memory)?r.memory:[],n=t.rel(e);return o.map(((e,t)=>"string"==typeof e?{role:"user",text:cleanText(e),timestamp:"",where:`${n}#${t}`}:{role:"user",text:cleanText(e&&(e.content||e.text||e.value||e.fact)),timestamp:e&&(e.timestamp||e.createdAt)||"",where:`${n}#${t}`})).filter((e=>e.text))}const SOURCES=[{id:"claude-code",label:"Claude Code",verified:!0,roots:e=>[path.join(e,".claude","projects")],files:e=>[path.join(e,".claude","history.jsonl")],extract:{"**/*.jsonl":extractClaudeJsonl,"*.jsonl":extractClaudeJsonl}},{id:"claude-memory",label:"Claude memory files",verified:!0,roots:e=>[path.join(e,".claude","memory")],files:e=>[path.join(e,".claude","memory.json")],extract:{".json":extractJsonMemory,".md":extractMarkdown,".txt":extractMarkdown}},{id:"aegiscodex",label:"AEGIS Codex engine",verified:!0,roots:e=>[path.join(e,".aegiscodex","memory")],files:()=>[],extract:{".json":extractJsonMemory,".jsonl":extractGenericJsonl,".md":extractMarkdown}},{id:"codex",label:"OpenAI Codex CLI",verified:!1,roots:e=>[path.join(e,".codex")],files:()=>[],extract:{".jsonl":extractGenericJsonl,".json":extractJsonMemory,".md":extractMarkdown}},{id:"gemini-cli",label:"Gemini CLI",verified:!1,roots:e=>[path.join(e,".gemini")],files:()=>[],extract:{".json":extractJsonMemory,".jsonl":extractGenericJsonl,".md":extractMarkdown}},{id:"cursor",label:"Cursor",verified:!1,roots:e=>[path.join(e,".cursor")],files:()=>[],extract:{".json":extractJsonMemory,".jsonl":extractGenericJsonl,".md":extractMarkdown}},{id:"continue",label:"Continue",verified:!1,roots:e=>[path.join(e,".continue")],files:()=>[],extract:{".json":extractJsonMemory,".jsonl":extractGenericJsonl,".md":extractMarkdown}},{id:"goose",label:"Goose",verified:!1,roots:(e,t)=>appRoots(e,t,"goose",{data:!0}),files:()=>[],extract:{".jsonl":extractGenericJsonl,".json":extractJsonMemory,".md":extractMarkdown}},{id:"opencode",label:"opencode",verified:!1,roots:(e,t)=>appRoots(e,t,"opencode",{data:!0}),files:()=>[],extract:{".json":extractJsonMemory,".jsonl":extractGenericJsonl,".md":extractMarkdown}},{id:"windsurf",label:"Windsurf / Codeium",verified:!1,roots:(e,t)=>[path.join(e,".windsurf"),path.join(e,".codeium"),...appRoots(e,t,"Windsurf",{config:!1,macSupport:!0}),...appRoots(e,t,"Codeium",{config:!1,macSupport:!0})],files:()=>[],extract:{".json":extractJsonMemory,".jsonl":extractGenericJsonl,".md":extractMarkdown}},{id:"zed",label:"Zed",verified:!1,roots:(e,t)=>appRoots(e,t,"zed"),files:()=>[],extract:{".json":extractJsonMemory,".jsonl":extractGenericJsonl}},{id:"claude-desktop",label:"Claude Desktop app",verified:!1,roots:(e,t)=>appRoots(e,t,"Claude",{macSupport:!0}),files:()=>[],extract:{".json":extractJsonMemory,".jsonl":extractClaudeJsonl,".md":extractMarkdown}}];function suffixOf(e){const t=e.lastIndexOf("*");return-1===t?e:e.slice(t+1)}function extractorFor(e,t){for(const[r,o]of Object.entries(e))if(t.endsWith(suffixOf(r)))return o;return null}function sourceById(e){return SOURCES.find((t=>t.id===e))||null}function listSources(e,t){const r=homeDir(e),o=platformOf(t);return SOURCES.map((e=>{const t=e.roots(r,o).filter(isDir),n=(e.files?e.files(r):[]).filter(isFile);return{id:e.id,label:e.label,verified:e.verified,roots:t.concat(n),present:t.length>0||n.length>0}}))}function scan(e={}){const t=homeDir(e.home),r=platformOf(e.platform),o=null!=e.minChars?e.minChars:DEFAULTS.minChars,n=null!=e.maxChars?e.maxChars:DEFAULTS.maxChars,s=null!=e.maxEntriesPerSource?e.maxEntriesPerSource:DEFAULTS.maxEntriesPerSource,i=null!=e.limit?e.limit:1/0,a=e.sources&&e.sources.length?new Set(e.sources):null,c=[],l=[],u=new Set;for(const e of SOURCES){if(a&&!a.has(e.id))continue;const f=e.roots(t,r).filter(isDir),d=(e.files?e.files(t):[]).filter(isFile),p=f.length>0||d.length>0,m={id:e.id,label:e.label,verified:e.verified,present:p,files:0,scanned:0,count:0,skipped:0,roots:f,session:`import:${e.id}`};if(!p){c.push(m);continue}const x=d.slice();for(const t of f){const r=Object.keys(e.extract).map(suffixOf);x.push(...walkFiles(t,{ext:r,limit:DEFAULTS.maxFilesPerSource}))}const h={rel:e=>path.relative(t,e)};for(const t of x){if(m.count>=s||l.length>=i)break;if(fileSize(t)>DEFAULTS.maxFileBytes){m.skipped+=1;continue}const r=extractorFor(e.extract,t);if(!r)continue;let a;m.files+=1;try{a=r(t,h)}catch{continue}for(const t of a){if(m.count>=s||l.length>=i)break;m.scanned+=1;let r=t.text;if(r.length>n&&(r=`${r.slice(0,n)}…`),r.length<o||isNoise(r)){m.skipped+=1;continue}const a=stableId(e.id,t.where,t.role,r);u.has(a)||(u.add(a),l.push({id:a,content:r,role:t.role,source:e.id,session:m.session,tags:["imported",e.id],importance:5,timestamp:t.timestamp||(new Date).toISOString()}),m.count+=1)}}c.push(m)}return{entries:l,sources:c,totals:{entries:l.length,sourcesPresent:c.filter((e=>e.present)).length,sourcesWithEntries:c.filter((e=>e.count>0)).length,scanned:c.reduce(((e,t)=>e+t.scanned),0),skipped:c.reduce(((e,t)=>e+t.skipped),0)},scannedAt:(new Date).toISOString()}}function chunk(e,t=200){const r=[];for(let o=0;o<e.length;o+=t)r.push(e.slice(o,o+t));return r}function describe(e){const t=e.sources.filter((e=>e.present));if(!t.length)return"No other AI tool memory found on this machine.";const r=t.map((e=>{const t=e.verified?"":" (best-effort layout)";return` ${e.label}${t}: ${e.count} entries from ${e.files} file(s), ${e.skipped} skipped`}));return[`Found ${e.totals.entries} importable entries across ${e.totals.sourcesWithEntries} source(s):`,...r].join("\n")}module.exports={DEFAULTS:DEFAULTS,SOURCES:SOURCES,scan:scan,listSources:listSources,describe:describe,chunk:chunk,stableId:stableId,sourceById:sourceById,_internal:{walkFiles:walkFiles,extractClaudeJsonl:extractClaudeJsonl,extractGenericJsonl:extractGenericJsonl,extractJsonMemory:extractJsonMemory,extractMarkdown:extractMarkdown,cleanText:cleanText,isNoise:isNoise,suffixOf:suffixOf,platformOf:platformOf,roamingDir:roamingDir,localDir:localDir,macSupportDir:macSupportDir,appRoots:appRoots}};