aegisone 1.0.34 → 1.0.35

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 (226) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -976
  9. package/src/child.js +1 -285
  10. package/src/dispatch.js +1 -269
  11. package/src/doctor.js +1 -639
  12. package/src/host.js +1 -111
  13. package/src/permissions.js +1 -383
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/package.json +3 -7
  17. package/vendor/cli/scripts/check.mjs +1 -52
  18. package/vendor/cli/scripts/demo.mjs +1 -94
  19. package/vendor/cli/scripts/predist.mjs +1 -75
  20. package/vendor/cli/scripts/runtests.mjs +1 -56
  21. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  22. package/vendor/cli/src/agents.js +1 -139
  23. package/vendor/cli/src/app.js +1 -2957
  24. package/vendor/cli/src/art.js +1 -289
  25. package/vendor/cli/src/chatflow.js +1 -3023
  26. package/vendor/cli/src/checkpoint.js +1 -90
  27. package/vendor/cli/src/clipboard.js +1 -424
  28. package/vendor/cli/src/cloudsync.js +1 -528
  29. package/vendor/cli/src/commands.js +1 -4089
  30. package/vendor/cli/src/config.js +1 -581
  31. package/vendor/cli/src/connect.js +1 -349
  32. package/vendor/cli/src/credentials.js +1 -33
  33. package/vendor/cli/src/deps.js +1 -232
  34. package/vendor/cli/src/devrun.js +1 -187
  35. package/vendor/cli/src/diff.js +1 -333
  36. package/vendor/cli/src/diffview.js +1 -296
  37. package/vendor/cli/src/engine.js +1 -297
  38. package/vendor/cli/src/entitlement.js +1 -355
  39. package/vendor/cli/src/events.js +1 -707
  40. package/vendor/cli/src/export.js +1 -67
  41. package/vendor/cli/src/filepreview.js +1 -153
  42. package/vendor/cli/src/fingerprint.js +1 -592
  43. package/vendor/cli/src/format.js +1 -259
  44. package/vendor/cli/src/fuzzy.js +1 -119
  45. package/vendor/cli/src/history.js +1 -423
  46. package/vendor/cli/src/init.js +1 -175
  47. package/vendor/cli/src/input.js +1 -139
  48. package/vendor/cli/src/keys.js +1 -183
  49. package/vendor/cli/src/markdown.js +1 -306
  50. package/vendor/cli/src/models.js +1 -507
  51. package/vendor/cli/src/naming.js +1 -57
  52. package/vendor/cli/src/overlays.js +1 -462
  53. package/vendor/cli/src/panels.js +1 -1418
  54. package/vendor/cli/src/ping.js +1 -226
  55. package/vendor/cli/src/presence.js +1 -238
  56. package/vendor/cli/src/render.js +1 -516
  57. package/vendor/cli/src/screen.js +1 -518
  58. package/vendor/cli/src/screens.js +1 -896
  59. package/vendor/cli/src/secret.js +1 -59
  60. package/vendor/cli/src/securefs.js +1 -359
  61. package/vendor/cli/src/settings.js +1 -155
  62. package/vendor/cli/src/shared.js +1 -52
  63. package/vendor/cli/src/sharedpaths.js +1 -53
  64. package/vendor/cli/src/signup.js +1 -156
  65. package/vendor/cli/src/summarize.js +1 -95
  66. package/vendor/cli/src/sysdiag.js +1 -585
  67. package/vendor/cli/src/system.js +1 -40
  68. package/vendor/cli/src/theme.js +1 -570
  69. package/vendor/cli/src/title.js +1 -220
  70. package/vendor/cli/src/todos.js +1 -115
  71. package/vendor/cli/src/tokens.js +1 -263
  72. package/vendor/cli/src/topup.js +1 -210
  73. package/vendor/cli/src/update.js +1 -191
  74. package/vendor/cli/vendor/client/aegis.js +1 -2441
  75. package/vendor/cli/vendor/client/attest.js +1 -518
  76. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  77. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  78. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  79. package/vendor/cli/vendor/client/byok-catalog.js +1 -199
  80. package/vendor/cli/vendor/client/catalog-client.js +1 -487
  81. package/vendor/cli/vendor/client/conversation-export.js +1 -177
  82. package/vendor/cli/vendor/client/credentials.js +1 -494
  83. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  84. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  85. package/vendor/cli/vendor/client/drive-upload.js +1 -234
  86. package/vendor/cli/vendor/client/env-file.js +1 -1273
  87. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  88. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  89. package/vendor/cli/vendor/client/google-signin.js +1 -133
  90. package/vendor/cli/vendor/client/hooks.js +1 -430
  91. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  92. package/vendor/cli/vendor/client/naming.js +1 -283
  93. package/vendor/cli/vendor/client/platform.js +1 -937
  94. package/vendor/cli/vendor/client/prefs.js +1 -351
  95. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  96. package/vendor/cli/vendor/client/presence.js +1 -438
  97. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  98. package/vendor/cli/vendor/client/session-store.js +1 -575
  99. package/vendor/cli/vendor/client/topup.js +1 -297
  100. package/vendor/cli/vendor/client/touch.js +1 -458
  101. package/vendor/cli/vendor/client/update.js +1 -763
  102. package/vendor/cli/vendor/client/user-models.js +1 -381
  103. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  104. package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
  105. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  106. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
  107. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
  108. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
  109. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  110. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  111. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
  112. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
  113. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  114. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
  115. package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
  116. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  117. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  118. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  119. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  120. package/vendor/cli/vendor/hosts/install.js +1 -638
  121. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  122. package/vendor/cli/vendor/hosts/spec.js +1 -164
  123. package/vendor/cli/vendor/hosts/targets.js +1 -346
  124. package/vendor/cli/vendor/mcp/server.js +1 -221
  125. package/vendor/cli/vendor/mcp/tools.js +1 -408
  126. package/vendor/cli/vendor/one/src/child.js +1 -285
  127. package/vendor/cli/vendor/one/src/permissions.js +1 -383
  128. package/vendor/desktop/bin/aegis.js +1 -32
  129. package/vendor/desktop/lib/account-key.js +1 -56
  130. package/vendor/desktop/lib/auto.js +1 -461
  131. package/vendor/desktop/lib/avatar/companion.js +1 -698
  132. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  133. package/vendor/desktop/lib/avatar/events.js +1 -344
  134. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  135. package/vendor/desktop/lib/avatar/holders.js +1 -612
  136. package/vendor/desktop/lib/avatar/identity.js +1 -641
  137. package/vendor/desktop/lib/avatar/level.js +1 -368
  138. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  139. package/vendor/desktop/lib/avatar/persona.js +1 -388
  140. package/vendor/desktop/lib/avatar/profile.js +1 -977
  141. package/vendor/desktop/lib/avatar/register.js +1 -307
  142. package/vendor/desktop/lib/avatar/store.js +1 -472
  143. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  144. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  145. package/vendor/desktop/lib/avatar/turn.js +1 -216
  146. package/vendor/desktop/lib/avatar/voice.js +1 -328
  147. package/vendor/desktop/lib/avatar/xp.js +1 -404
  148. package/vendor/desktop/lib/deep-link.js +1 -120
  149. package/vendor/desktop/lib/fingerprint.js +2 -347
  150. package/vendor/desktop/lib/google-connect.js +1 -323
  151. package/vendor/desktop/lib/local/agents.js +1 -105
  152. package/vendor/desktop/lib/local/attachments.js +1 -276
  153. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  154. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  155. package/vendor/desktop/lib/local/context.js +1 -125
  156. package/vendor/desktop/lib/local/engine.js +1 -3666
  157. package/vendor/desktop/lib/local/entitlement.js +1 -660
  158. package/vendor/desktop/lib/local/git-scope.js +1 -228
  159. package/vendor/desktop/lib/local/local.js +1 -2145
  160. package/vendor/desktop/lib/local/prompt.js +1 -280
  161. package/vendor/desktop/lib/local/queue.js +1 -560
  162. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  163. package/vendor/desktop/lib/local/spill.js +1 -75
  164. package/vendor/desktop/lib/local/telemetry.js +1 -470
  165. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  166. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  167. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  168. package/vendor/desktop/lib/quick-launcher.js +1 -84
  169. package/vendor/desktop/lib/settings.js +1 -890
  170. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  171. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  172. package/vendor/desktop/lib/sync/sessions.js +1 -106
  173. package/vendor/desktop/lib/window-state.js +1 -66
  174. package/vendor/desktop/package.json +2 -4
  175. package/vendor/desktop/preload.js +1 -679
  176. package/vendor/desktop/renderer/app.js +1 -7250
  177. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  178. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  179. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  180. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  181. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  182. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  183. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  184. package/vendor/desktop/renderer/budget.js +1 -172
  185. package/vendor/desktop/renderer/companion.js +1 -223
  186. package/vendor/desktop/renderer/diff.js +1 -359
  187. package/vendor/desktop/renderer/diffview.js +1 -336
  188. package/vendor/desktop/renderer/filepreview.js +1 -211
  189. package/vendor/desktop/renderer/fingerprint.js +3 -789
  190. package/vendor/desktop/renderer/markdown.js +1 -168
  191. package/vendor/desktop/renderer/provider-mark.js +1 -311
  192. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  193. package/vendor/desktop/renderer/providers.js +1 -259
  194. package/vendor/desktop/renderer/quick.js +1 -285
  195. package/vendor/desktop/renderer/stream-policy.js +1 -387
  196. package/vendor/desktop/renderer/transcript-view.js +1 -323
  197. package/vendor/desktop/renderer/usage.js +1 -1239
  198. package/vendor/desktop/vendor/aegis.js +1 -2441
  199. package/vendor/desktop/vendor/attest.js +1 -518
  200. package/vendor/desktop/vendor/authorship-key.js +1 -410
  201. package/vendor/desktop/vendor/auto-provision.js +1 -134
  202. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  203. package/vendor/desktop/vendor/byok-catalog.js +1 -199
  204. package/vendor/desktop/vendor/catalog-client.js +1 -487
  205. package/vendor/desktop/vendor/conversation-export.js +1 -177
  206. package/vendor/desktop/vendor/credentials.js +1 -494
  207. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  208. package/vendor/desktop/vendor/drive-connect.js +1 -110
  209. package/vendor/desktop/vendor/drive-upload.js +1 -234
  210. package/vendor/desktop/vendor/env-file.js +1 -1273
  211. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  212. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  213. package/vendor/desktop/vendor/google-signin.js +1 -133
  214. package/vendor/desktop/vendor/hooks.js +1 -430
  215. package/vendor/desktop/vendor/model-discovery.js +1 -373
  216. package/vendor/desktop/vendor/naming.js +1 -283
  217. package/vendor/desktop/vendor/platform.js +1 -937
  218. package/vendor/desktop/vendor/prefs.js +1 -351
  219. package/vendor/desktop/vendor/presence-constants.js +1 -107
  220. package/vendor/desktop/vendor/presence.js +1 -438
  221. package/vendor/desktop/vendor/record-vault.js +3 -1055
  222. package/vendor/desktop/vendor/session-store.js +1 -575
  223. package/vendor/desktop/vendor/topup.js +1 -297
  224. package/vendor/desktop/vendor/touch.js +1 -458
  225. package/vendor/desktop/vendor/update.js +1 -763
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -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}};