recallnest 2.6.1 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/CHANGELOG.md +292 -0
  2. package/README.md +280 -195
  3. package/README_CN.md +266 -199
  4. package/config.json.example +8 -1
  5. package/docs/api-reference.md +1 -1
  6. package/integrations/README.md +1 -1
  7. package/integrations/agy/README.md +73 -0
  8. package/integrations/agy/setup.sh +75 -0
  9. package/integrations/setup-all.sh +1 -1
  10. package/package.json +7 -5
  11. package/src/access-tracker.ts +10 -1
  12. package/src/activity-counter.ts +69 -11
  13. package/src/age-label.ts +29 -0
  14. package/src/audit-log.ts +35 -0
  15. package/src/auto-gc.ts +97 -30
  16. package/src/capture-engine.ts +26 -4
  17. package/src/cli.ts +224 -10
  18. package/src/consolidation-engine.ts +317 -123
  19. package/src/context-composer-stable.ts +5 -1
  20. package/src/data-checkup.ts +17 -3
  21. package/src/dream-pipeline.ts +90 -12
  22. package/src/embedder.ts +44 -5
  23. package/src/env-config.ts +71 -0
  24. package/src/forget-engine.ts +8 -2
  25. package/src/gateway-server.ts +272 -0
  26. package/src/ingest.ts +248 -22
  27. package/src/kg-extractor.ts +17 -0
  28. package/src/llm-client.ts +86 -25
  29. package/src/mcp-server.ts +2 -1
  30. package/src/mcp-tools-advanced.ts +7 -2
  31. package/src/mcp-tools-core.ts +11 -1
  32. package/src/mcp-tools-governance.ts +45 -3
  33. package/src/memory-evolution.ts +16 -0
  34. package/src/memory-output.ts +47 -8
  35. package/src/memory-promotion.ts +280 -0
  36. package/src/memory-store-port.ts +32 -3
  37. package/src/memory-utility.ts +314 -0
  38. package/src/pivot-apply.ts +52 -1
  39. package/src/pivot-evidence.ts +128 -0
  40. package/src/ppr-traversal.ts +25 -1
  41. package/src/recall-ledger.ts +76 -0
  42. package/src/retriever.ts +82 -9
  43. package/src/runtime-config.ts +9 -0
  44. package/src/scope-policy.ts +22 -1
  45. package/src/session-engine.ts +11 -4
  46. package/src/session-output.ts +13 -4
  47. package/src/session-store.ts +2 -3
  48. package/src/skill-promotion.ts +218 -1
  49. package/src/store.ts +231 -71
  50. package/src/synthesis-contract.ts +286 -0
  51. package/src/version-manager.ts +83 -0
  52. package/src/workflow-observation-schema.ts +26 -0
  53. package/integrations/gemini-cli/README.md +0 -57
  54. package/integrations/gemini-cli/setup.sh +0 -64
  55. package/src/__tests__/access-tracker-novelty.test.ts +0 -304
  56. package/src/__tests__/activity-counter.test.ts +0 -125
  57. package/src/__tests__/adaptive-fidelity.test.ts +0 -102
  58. package/src/__tests__/admission-control.test.ts +0 -206
  59. package/src/__tests__/anchor-generator.test.ts +0 -67
  60. package/src/__tests__/api-server-security.test.ts +0 -102
  61. package/src/__tests__/auto-consolidation.test.ts +0 -168
  62. package/src/__tests__/auto-recall.test.ts +0 -131
  63. package/src/__tests__/babel-integration.test.ts +0 -144
  64. package/src/__tests__/batch-dedup.test.ts +0 -65
  65. package/src/__tests__/belief-history.test.ts +0 -220
  66. package/src/__tests__/canary-eval.test.ts +0 -114
  67. package/src/__tests__/capture-engine.test.ts +0 -1328
  68. package/src/__tests__/capture-heuristic.test.ts +0 -171
  69. package/src/__tests__/cascade-forget.test.ts +0 -210
  70. package/src/__tests__/category-min-scores.test.ts +0 -116
  71. package/src/__tests__/cc8-cc1-essential-context.test.ts +0 -298
  72. package/src/__tests__/circuit-breaker.test.ts +0 -99
  73. package/src/__tests__/cluster-consolidation.test.ts +0 -945
  74. package/src/__tests__/confidence-metadata.test.ts +0 -125
  75. package/src/__tests__/confidence-tracker.test.ts +0 -261
  76. package/src/__tests__/conflict-advisor.test.ts +0 -206
  77. package/src/__tests__/conflict-escalation.test.ts +0 -149
  78. package/src/__tests__/conflict-lifecycle.test.ts +0 -83
  79. package/src/__tests__/conflict-output.test.ts +0 -85
  80. package/src/__tests__/conflict-store.test.ts +0 -418
  81. package/src/__tests__/connector-v1.test.ts +0 -181
  82. package/src/__tests__/consolidation-engine.test.ts +0 -430
  83. package/src/__tests__/constructive-retrieval.test.ts +0 -509
  84. package/src/__tests__/context-collapse-renderer.test.ts +0 -214
  85. package/src/__tests__/context-composer-pins.test.ts +0 -64
  86. package/src/__tests__/context-composer-task-selection.test.ts +0 -24
  87. package/src/__tests__/context-reconstructor.test.ts +0 -65
  88. package/src/__tests__/context-renderer.test.ts +0 -91
  89. package/src/__tests__/continuity-eval.test.ts +0 -275
  90. package/src/__tests__/continuity-schema.test.ts +0 -97
  91. package/src/__tests__/contracts.test.ts +0 -262
  92. package/src/__tests__/conversation-importer.test.ts +0 -692
  93. package/src/__tests__/core-recall-eval.test.ts +0 -235
  94. package/src/__tests__/core-summary.test.ts +0 -109
  95. package/src/__tests__/data-checkup.test.ts +0 -276
  96. package/src/__tests__/decay-exemption.test.ts +0 -129
  97. package/src/__tests__/dedup-actions.test.ts +0 -58
  98. package/src/__tests__/dedup-guard.test.ts +0 -39
  99. package/src/__tests__/deterministic-id.test.ts +0 -39
  100. package/src/__tests__/distill-lock.test.ts +0 -305
  101. package/src/__tests__/distill-session-argshape.test.ts +0 -79
  102. package/src/__tests__/doctor.test.ts +0 -319
  103. package/src/__tests__/dream-pipeline.test.ts +0 -780
  104. package/src/__tests__/drill-down.test.ts +0 -108
  105. package/src/__tests__/embedder.test.ts +0 -122
  106. package/src/__tests__/emotion-decay.test.ts +0 -46
  107. package/src/__tests__/emotion-detector.test.ts +0 -56
  108. package/src/__tests__/emotion-phase1-integration.test.ts +0 -153
  109. package/src/__tests__/emotion-retrieval.test.ts +0 -56
  110. package/src/__tests__/entity-resolver.test.ts +0 -58
  111. package/src/__tests__/env-config.test.ts +0 -151
  112. package/src/__tests__/error-signature-boost.test.ts +0 -87
  113. package/src/__tests__/error-signature.test.ts +0 -95
  114. package/src/__tests__/error-taxonomy.test.ts +0 -129
  115. package/src/__tests__/ethics-layer.test.ts +0 -476
  116. package/src/__tests__/event-segmenter.test.ts +0 -153
  117. package/src/__tests__/feature-flags-integration.test.ts +0 -54
  118. package/src/__tests__/frequency-tracker.test.ts +0 -113
  119. package/src/__tests__/freshness.test.ts +0 -186
  120. package/src/__tests__/graph-export.test.ts +0 -489
  121. package/src/__tests__/hotness-blend.test.ts +0 -283
  122. package/src/__tests__/ingest-chunking.test.ts +0 -44
  123. package/src/__tests__/ingest.test.ts +0 -360
  124. package/src/__tests__/interference-detector.test.ts +0 -203
  125. package/src/__tests__/kg-extractor.test.ts +0 -192
  126. package/src/__tests__/kg-store.test.ts +0 -300
  127. package/src/__tests__/llm-client-pivot.test.ts +0 -628
  128. package/src/__tests__/llm-consolidation.test.ts +0 -226
  129. package/src/__tests__/maintenance-locks.test.ts +0 -189
  130. package/src/__tests__/mcp-efficiency.test.ts +0 -288
  131. package/src/__tests__/mcp-related-scopes.test.ts +0 -151
  132. package/src/__tests__/memory-boundaries.test.ts +0 -282
  133. package/src/__tests__/memory-evolution-b2-b3-e1.test.ts +0 -345
  134. package/src/__tests__/memory-evolution.test.ts +0 -271
  135. package/src/__tests__/memory-health-rebalance.test.ts +0 -144
  136. package/src/__tests__/memory-lint.test.ts +0 -421
  137. package/src/__tests__/memory-output.test.ts +0 -215
  138. package/src/__tests__/memory-promotion.test.ts +0 -315
  139. package/src/__tests__/migrate-dedup-ids.test.ts +0 -65
  140. package/src/__tests__/multi-vector.test.ts +0 -242
  141. package/src/__tests__/narrative-architecture.test.ts +0 -456
  142. package/src/__tests__/noise-filter.test.ts +0 -205
  143. package/src/__tests__/noise-prototype-bank.test.ts +0 -280
  144. package/src/__tests__/obsidian-connector.test.ts +0 -363
  145. package/src/__tests__/omitted-reporting.test.ts +0 -98
  146. package/src/__tests__/pending-review.test.ts +0 -77
  147. package/src/__tests__/pii-redact.test.ts +0 -333
  148. package/src/__tests__/pivot-apply.test.ts +0 -373
  149. package/src/__tests__/pivot-distill-supervisor.test.ts +0 -457
  150. package/src/__tests__/pivot-distill.test.ts +0 -1178
  151. package/src/__tests__/post-retrieval-filter.test.ts +0 -178
  152. package/src/__tests__/ppr-traversal.test.ts +0 -256
  153. package/src/__tests__/prediction-engine.test.ts +0 -349
  154. package/src/__tests__/predictive-prospective-memory.test.ts +0 -416
  155. package/src/__tests__/preference-guard-smoke.test.ts +0 -211
  156. package/src/__tests__/preference-matcher.test.ts +0 -282
  157. package/src/__tests__/preference-slots.test.ts +0 -205
  158. package/src/__tests__/prospective-memory.test.ts +0 -283
  159. package/src/__tests__/pull-from-macbook-sync-only.test.ts +0 -679
  160. package/src/__tests__/query-entity-detector.test.ts +0 -171
  161. package/src/__tests__/query-expander-alias.test.ts +0 -146
  162. package/src/__tests__/query-expander.test.ts +0 -34
  163. package/src/__tests__/recall-gate.test.ts +0 -266
  164. package/src/__tests__/recall-governor.test.ts +0 -227
  165. package/src/__tests__/recall-mode.test.ts +0 -64
  166. package/src/__tests__/resolve-db-path.test.ts +0 -130
  167. package/src/__tests__/resolve-tier.test.ts +0 -64
  168. package/src/__tests__/result-synthesizer.test.ts +0 -198
  169. package/src/__tests__/resume-context.test.ts +0 -4898
  170. package/src/__tests__/retrieval-eval.test.ts +0 -163
  171. package/src/__tests__/retrieval-trace.test.ts +0 -213
  172. package/src/__tests__/retriever-boundary-weight.test.ts +0 -136
  173. package/src/__tests__/retriever-lazy-init-dispatch.test.ts +0 -123
  174. package/src/__tests__/retroactive-boost.test.ts +0 -223
  175. package/src/__tests__/salience-scoring.test.ts +0 -106
  176. package/src/__tests__/scope-inventory.test.ts +0 -200
  177. package/src/__tests__/scope-policy.test.ts +0 -69
  178. package/src/__tests__/scope-suggester.test.ts +0 -80
  179. package/src/__tests__/session-checkpoint.test.ts +0 -291
  180. package/src/__tests__/session-distiller.test.ts +0 -640
  181. package/src/__tests__/session-gc.test.ts +0 -215
  182. package/src/__tests__/skill-engine.test.ts +0 -552
  183. package/src/__tests__/skill-promotion.test.ts +0 -654
  184. package/src/__tests__/skill-verifier.test.ts +0 -122
  185. package/src/__tests__/source-heartbeat.test.ts +0 -250
  186. package/src/__tests__/stable-context-length-contract.test.ts +0 -62
  187. package/src/__tests__/store-patch-metadata.test.ts +0 -205
  188. package/src/__tests__/store-read-consistency.test.ts +0 -122
  189. package/src/__tests__/store-schema-migration.test.ts +0 -87
  190. package/src/__tests__/store-scope-audit.test.ts +0 -81
  191. package/src/__tests__/store-upsert.test.ts +0 -201
  192. package/src/__tests__/supersede-chain.test.ts +0 -154
  193. package/src/__tests__/temporal-parser.test.ts +0 -241
  194. package/src/__tests__/temporal-validity.test.ts +0 -160
  195. package/src/__tests__/term-registry-terminal-roster.test.ts +0 -127
  196. package/src/__tests__/term-registry.test.ts +0 -121
  197. package/src/__tests__/tool-error-surfacing.test.ts +0 -98
  198. package/src/__tests__/tool-output-compressor.test.ts +0 -160
  199. package/src/__tests__/topic-tag.test.ts +0 -113
  200. package/src/__tests__/trusted-memory.test.ts +0 -839
  201. package/src/__tests__/ui-server-security.test.ts +0 -93
  202. package/src/__tests__/usage-tracker.test.ts +0 -287
  203. package/src/__tests__/version-manager.test.ts +0 -213
  204. package/src/__tests__/workflow-observation-skill-outcome.test.ts +0 -352
  205. package/src/__tests__/workflow-observation.test.ts +0 -433
  206. package/src/__tests__/write-verifier.test.ts +0 -122
  207. /package/integrations/{gemini-cli/gemini-md-snippet.md → agy/agy-md-snippet.md} +0 -0
@@ -1,679 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
- import {
3
- chmodSync,
4
- existsSync,
5
- mkdirSync,
6
- mkdtempSync,
7
- readFileSync,
8
- renameSync,
9
- statSync,
10
- symlinkSync,
11
- writeFileSync,
12
- } from "node:fs";
13
- import { tmpdir } from "node:os";
14
- import { dirname, join, resolve } from "node:path";
15
- import { spawnSync } from "node:child_process";
16
-
17
- const REPO_ROOT = resolve(import.meta.dir, "../..");
18
- const SCRIPT = join(REPO_ROOT, "scripts", "pull-from-macbook.sh");
19
- const TEST_TIMEOUT_MS = 30_000;
20
-
21
- interface Harness {
22
- root: string;
23
- home: string;
24
- remoteHome: string;
25
- report: string;
26
- rsyncLog: string;
27
- sshLog: string;
28
- registrarMarker: string;
29
- ingestMarker: string;
30
- env: NodeJS.ProcessEnv;
31
- }
32
-
33
- interface RsyncCall {
34
- args: string[];
35
- sourceArg: string;
36
- targetArg: string;
37
- dryRun: boolean;
38
- ignoreTimes: boolean;
39
- }
40
-
41
- function executable(path: string, source: string): void {
42
- writeFileSync(path, source, { mode: 0o700 });
43
- chmodSync(path, 0o700);
44
- }
45
-
46
- function fixture(path: string, content: string): void {
47
- mkdirSync(dirname(path), { recursive: true });
48
- writeFileSync(path, content);
49
- }
50
-
51
- function fakeRsyncSource(): string {
52
- return [
53
- "#!/usr/bin/env bun",
54
- 'import { appendFileSync, copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, renameSync, statSync, symlinkSync, writeFileSync } from "node:fs";',
55
- 'import { basename, dirname, extname, join, relative, sep } from "node:path";',
56
- 'const args = process.argv.slice(2);',
57
- 'const sourceArg = args.at(-2) || "";',
58
- 'const targetArg = args.at(-1) || "";',
59
- 'const dryRun = args.includes("--dry-run");',
60
- 'const ignoreTimes = args.includes("--ignore-times");',
61
- 'const optionValues = new Set(["-e", "--exclude", "--include", "--out-format", "--rsync-path", "--timeout"]);',
62
- 'for (let index = 0; index < args.length - 2; index += 1) {',
63
- ' const arg = args[index];',
64
- ' if (optionValues.has(arg)) { if (index + 1 >= args.length - 2) process.exit(64); index += 1; continue; }',
65
- ' if (!arg.startsWith("-")) process.exit(64);',
66
- '}',
67
- 'appendFileSync(process.env.FAKE_RSYNC_LOG, JSON.stringify({ args: args.slice(0, -2), sourceArg, targetArg, dryRun, ignoreTimes }) + "\\n");',
68
- 'if (!dryRun && process.env.FAKE_CREATE_REPORT_DURING_SYNC && !existsSync(process.env.FAKE_CREATE_REPORT_DURING_SYNC)) writeFileSync(process.env.FAKE_CREATE_REPORT_DURING_SYNC, "racing-writer");',
69
- 'if (!dryRun && process.env.FAKE_BREAK_MAPPING_TMP) {',
70
- ' const report = process.env.FAKE_BREAK_MAPPING_TMP;',
71
- ' const prefix = basename(report) + ".tmp.";',
72
- ' const temporary = readdirSync(dirname(report))',
73
- ' .filter((name) => name.startsWith(prefix) && !name.endsWith(".saved"))',
74
- ' .map((name) => join(dirname(report), name))',
75
- ' .find((path) => statSync(path).isFile());',
76
- ' if (temporary) { renameSync(temporary, temporary + ".saved"); mkdirSync(temporary); }',
77
- '}',
78
- 'if (!sourceArg.startsWith("mac:")) process.exit(64);',
79
- 'const remoteHome = process.env.FAKE_REMOTE_HOME;',
80
- 'let remoteRaw = sourceArg.slice(4);',
81
- 'let sourcePath = remoteRaw;',
82
- 'if (remoteRaw === "~") sourcePath = remoteHome;',
83
- 'else if (remoteRaw.startsWith("~/")) sourcePath = join(remoteHome, remoteRaw.slice(2));',
84
- 'else if (!remoteRaw.startsWith("/")) sourcePath = join(remoteHome, remoteRaw);',
85
- 'if (!existsSync(sourcePath)) process.exit(23);',
86
- 'function walk(root) {',
87
- ' const files = [];',
88
- ' for (const entry of readdirSync(root, { withFileTypes: true })) {',
89
- ' const path = join(root, entry.name);',
90
- ' if (entry.isDirectory()) files.push(...walk(path));',
91
- ' else if (entry.isFile() || entry.isSymbolicLink()) files.push(path);',
92
- ' }',
93
- ' return files.sort();',
94
- '}',
95
- 'function included(path) {',
96
- ' const normalizedSource = sourcePath.split(sep).join("/");',
97
- ' const name = basename(path);',
98
- ' if (statSync(sourcePath).isFile()) return true;',
99
- ' if (normalizedSource.includes("/.gemini/tmp")) return name.startsWith("session-") && extname(name) === ".json";',
100
- ' if (normalizedSource.includes("/local-agent-mode-sessions")) return extname(name) === ".jsonl" && name !== "audit.jsonl";',
101
- ' if (normalizedSource.includes("/antigravity-cli/brain")) return name === "transcript_full.jsonl";',
102
- ' if (normalizedSource.includes("/antigravity-rescue/conversations")) return extname(name) === ".pb";',
103
- ' return extname(name) === ".jsonl";',
104
- '}',
105
- 'const sourceIsDirectory = statSync(sourcePath).isDirectory();',
106
- 'const files = (sourceIsDirectory ? walk(sourcePath) : [sourcePath]).filter(included);',
107
- 'if (dryRun && !ignoreTimes && process.env.FAKE_RSYNC_MUTATE_ON_VERIFY_SOURCE && sourceArg.includes(process.env.FAKE_RSYNC_MUTATE_ON_VERIFY_SOURCE) && files.length > 0) appendFileSync(files[0], "late-change");',
108
- 'const prefix = args.some((arg) => arg.includes("__RN_MAP__")) ? "__RN_MAP__" : "__RN_CHANGE__";',
109
- 'function copySource(source, destination) {',
110
- ' mkdirSync(dirname(destination), { recursive: true });',
111
- ' if (lstatSync(source).isSymbolicLink()) symlinkSync(readlinkSync(source), destination);',
112
- ' else copyFileSync(source, destination);',
113
- '}',
114
- 'const forcedFailure = Boolean(process.env.FAKE_RSYNC_FAIL_SOURCE && sourceArg.includes(process.env.FAKE_RSYNC_FAIL_SOURCE));',
115
- 'if (!dryRun && forcedFailure && files.length > 0) {',
116
- ' const source = files[0];',
117
- ' const rel = sourceIsDirectory ? relative(sourcePath, source).split(sep).join("/") : basename(source);',
118
- ' const destination = sourceIsDirectory ? join(targetArg, rel) : targetArg;',
119
- ' copySource(source, destination);',
120
- ' process.exit(23);',
121
- '}',
122
- 'for (const source of files) {',
123
- ' const rel = sourceIsDirectory ? relative(sourcePath, source).split(sep).join("/") : basename(source);',
124
- ' const destination = sourceIsDirectory ? join(targetArg, rel) : targetArg;',
125
- ' if (dryRun) {',
126
- ' const changed = !existsSync(destination) || !readFileSync(source).equals(readFileSync(destination));',
127
- ' const item = lstatSync(source).isSymbolicLink() ? "cL+++++++++" : ">f+++++++++";',
128
- ' if (ignoreTimes || changed) process.stdout.write(prefix + item + "|" + rel + "\\n");',
129
- ' continue;',
130
- ' }',
131
- ' copySource(source, destination);',
132
- '}',
133
- ].join("\n") + "\n";
134
- }
135
-
136
- function fakeSshSource(): string {
137
- return [
138
- "#!/usr/bin/env bun",
139
- 'import { appendFileSync, existsSync, statSync } from "node:fs";',
140
- 'import { join } from "node:path";',
141
- 'const args = process.argv.slice(2);',
142
- 'const command = args.join(" ");',
143
- 'appendFileSync(process.env.FAKE_SSH_LOG, command + "\\n");',
144
- 'if (process.env.FAKE_SSH_ONLINE !== "1") process.exit(255);',
145
- 'if (command.includes("echo online")) { console.log("online"); process.exit(0); }',
146
- 'if (process.env.FAKE_SSH_FAIL_PROBE && command.includes(process.env.FAKE_SSH_FAIL_PROBE)) process.exit(255);',
147
- 'if (command.includes("$HOME/.codex") && command.includes("session_index.jsonl")) { const path = join(process.env.FAKE_REMOTE_HOME, ".codex/session_index.jsonl"); process.exit(!existsSync(path) ? 2 : statSync(path).isFile() ? 0 : 3); }',
148
- 'if (command.includes("$HOME/.kimi-code") && command.includes("session_index.jsonl")) { const path = join(process.env.FAKE_REMOTE_HOME, ".kimi-code/session_index.jsonl"); process.exit(!existsSync(path) ? 2 : statSync(path).isFile() ? 0 : 3); }',
149
- 'if (command.includes("antigravity-rescue")) { const path = join(process.env.FAKE_REMOTE_HOME, "Downloads/antigravity-rescue/conversations"); process.exit(!existsSync(path) ? 2 : statSync(path).isDirectory() ? 0 : 3); }',
150
- 'process.exit(0);',
151
- ].join("\n") + "\n";
152
- }
153
-
154
- function makeHarness(): Harness {
155
- const root = mkdtempSync(join(tmpdir(), "pull-sync-only-"));
156
- const home = join(root, "home");
157
- const remoteHome = join(root, "remote-home");
158
- const fakeBin = join(root, "bin");
159
- const report = join(root, "mapping.tsv");
160
- const rsyncLog = join(root, "rsync.jsonl");
161
- const sshLog = join(root, "ssh.log");
162
- const registrarMarker = join(root, "registrar-called");
163
- const ingestMarker = join(root, "ingest-called");
164
-
165
- mkdirSync(fakeBin, { recursive: true });
166
- mkdirSync(join(home, "recallnest", "scripts"), { recursive: true });
167
- executable(join(fakeBin, "rsync"), fakeRsyncSource());
168
- executable(join(fakeBin, "ssh"), fakeSshSource());
169
- executable(
170
- join(home, "recallnest", "scripts", "codex-projectless-register.py"),
171
- [
172
- "#!/bin/bash",
173
- 'printf "called\\n" > "$FAKE_REGISTRAR_MARKER"',
174
- ].join("\n") + "\n",
175
- );
176
- executable(
177
- join(home, "recallnest", "scripts", "incremental-ingest.sh"),
178
- [
179
- "#!/bin/bash",
180
- 'printf "called\\n" > "$FAKE_INGEST_MARKER"',
181
- ].join("\n") + "\n",
182
- );
183
-
184
- fixture(join(remoteHome, ".claude", "projects", "p", "cc.jsonl"), "{\"source\":\"cc\"}\n");
185
- fixture(join(remoteHome, ".codex", "sessions", "2026", "codex.jsonl"), "{\"source\":\"codex\"}\n");
186
- fixture(join(remoteHome, ".codex", "archived_sessions", "archived.jsonl"), "{\"source\":\"archive\"}\n");
187
- fixture(
188
- join(remoteHome, ".codex", "session_index.jsonl"),
189
- "{\"id\":\"mac-codex\",\"updated_at\":\"2026-08-03T00:00:00Z\"}\n",
190
- );
191
- fixture(join(remoteHome, ".kimi-code", "sessions", "k1", "wire.jsonl"), "{\"source\":\"kimi\"}\n");
192
- fixture(join(remoteHome, ".kimi-code", "session_index.jsonl"), "{\"sessionId\":\"mac-kimi\"}\n");
193
- fixture(join(remoteHome, ".gemini", "tmp", "g1", "chats", "session-g.json"), "{\"source\":\"gemini\"}\n");
194
- fixture(
195
- join(
196
- remoteHome,
197
- "Library",
198
- "Application Support",
199
- "Claude",
200
- "local-agent-mode-sessions",
201
- "d1",
202
- ".claude",
203
- "projects",
204
- "p",
205
- "desktop-one.jsonl",
206
- ),
207
- "{\"source\":\"desktop\"}\n",
208
- );
209
- fixture(
210
- join(remoteHome, ".gemini", "antigravity-cli", "brain", "b1", "transcript_full.jsonl"),
211
- "{\"source\":\"agy-brain\"}\n",
212
- );
213
- fixture(
214
- join(remoteHome, "Downloads", "antigravity-rescue", "conversations", "legacy.pb"),
215
- "legacy-original",
216
- );
217
- fixture(
218
- join(remoteHome, ".gemini", "antigravity-cli", "conversations", "remote-cli.db"),
219
- "remote-cli-original",
220
- );
221
- fixture(
222
- join(remoteHome, ".gemini", "antigravity", "conversations", "remote-app.db"),
223
- "remote-app-original",
224
- );
225
-
226
- for (let index = 1; index <= 24; index += 1) {
227
- fixture(
228
- join(home, "machine-data", "macbook-agy", "conversations", "existing-" + index + ".db"),
229
- "mini-existing-" + index,
230
- );
231
- }
232
-
233
- const env: NodeJS.ProcessEnv = {
234
- ...process.env,
235
- LC_ALL: "C",
236
- PULL_FROM_MACBOOK_HOME: home,
237
- PULL_FROM_MACBOOK_RSYNC: join(fakeBin, "rsync"),
238
- PULL_FROM_MACBOOK_SSH: join(fakeBin, "ssh"),
239
- FAKE_REMOTE_HOME: remoteHome,
240
- FAKE_RSYNC_LOG: rsyncLog,
241
- FAKE_SSH_LOG: sshLog,
242
- FAKE_SSH_ONLINE: "1",
243
- FAKE_REGISTRAR_MARKER: registrarMarker,
244
- FAKE_INGEST_MARKER: ingestMarker,
245
- PULL_FROM_MACBOOK_LOG: join(root, "pull.log"),
246
- PULL_FROM_MACBOOK_LOG_DIR: join(root, "logs"),
247
- };
248
-
249
- return {
250
- root,
251
- home,
252
- remoteHome,
253
- report,
254
- rsyncLog,
255
- sshLog,
256
- registrarMarker,
257
- ingestMarker,
258
- env,
259
- };
260
- }
261
-
262
- function run(harness: Harness, args: string[], extraEnv: NodeJS.ProcessEnv = {}) {
263
- return spawnSync("/bin/bash", [SCRIPT, ...args], {
264
- env: { ...harness.env, ...extraEnv },
265
- encoding: "utf8",
266
- timeout: 30_000,
267
- });
268
- }
269
-
270
- function syncOnly(harness: Harness) {
271
- return run(harness, ["--sync-only", "--mapping-report", harness.report]);
272
- }
273
-
274
- function rsyncCalls(harness: Harness): RsyncCall[] {
275
- if (!existsSync(harness.rsyncLog)) return [];
276
- return readFileSync(harness.rsyncLog, "utf8")
277
- .trim()
278
- .split("\n")
279
- .filter(Boolean)
280
- .map((line) => JSON.parse(line) as RsyncCall);
281
- }
282
-
283
- function normalizedRsyncArgs(args: string[]): string[] {
284
- return args.filter(
285
- (arg) =>
286
- arg !== "--dry-run"
287
- && arg !== "--ignore-times"
288
- && arg !== "--itemize-changes"
289
- && !arg.startsWith("--out-format="),
290
- );
291
- }
292
-
293
- function unexpectedPositionalArgs(args: string[]): string[] {
294
- const valueOptions = new Set(["-e", "--exclude", "--include", "--out-format", "--rsync-path", "--timeout"]);
295
- const unexpected: string[] = [];
296
- for (let index = 0; index < args.length; index += 1) {
297
- const arg = args[index];
298
- if (valueOptions.has(arg)) {
299
- index += 1;
300
- continue;
301
- }
302
- if (!arg.startsWith("-")) unexpected.push(arg);
303
- }
304
- return unexpected;
305
- }
306
-
307
- function dbContents(directory: string): Record<string, string> {
308
- const result: Record<string, string> = {};
309
- for (let index = 1; index <= 24; index += 1) {
310
- const name = "existing-" + index + ".db";
311
- result[name] = readFileSync(join(directory, name), "utf8");
312
- }
313
- return result;
314
- }
315
-
316
- describe("pull-from-macbook --sync-only", () => {
317
- it("syncs allowed sources, verifies identical rsync arguments, and emits per-file mappings without ingest", () => {
318
- const harness = makeHarness();
319
- expect(harness.env.HOME).toBe(process.env.HOME);
320
- const localDbDir = join(harness.home, "machine-data", "macbook-agy", "conversations");
321
- const localDbBefore = dbContents(localDbDir);
322
- const remoteCliDb = join(harness.remoteHome, ".gemini", "antigravity-cli", "conversations", "remote-cli.db");
323
- const remoteAppDb = join(harness.remoteHome, ".gemini", "antigravity", "conversations", "remote-app.db");
324
- const remoteCliBefore = readFileSync(remoteCliDb, "utf8");
325
- const remoteAppBefore = readFileSync(remoteAppDb, "utf8");
326
-
327
- const result = syncOnly(harness);
328
-
329
- expect(result.status).toBe(0);
330
- expect(existsSync(harness.ingestMarker)).toBe(false);
331
- expect(existsSync(harness.registrarMarker)).toBe(false);
332
- expect(readFileSync(join(harness.home, ".claude", "projects", "p", "cc.jsonl"), "utf8")).toContain("cc");
333
- expect(
334
- readFileSync(
335
- join(harness.home, "recallnest", "data", "desktop-import", "desktop-one.jsonl"),
336
- "utf8",
337
- ),
338
- ).toContain("desktop");
339
- expect(readFileSync(join(harness.home, ".codex", "session_index.jsonl"), "utf8")).toContain("mac-codex");
340
- expect(readFileSync(join(harness.home, ".kimi-code", "session_index.jsonl"), "utf8")).toContain("mac-kimi");
341
-
342
- const mapping = readFileSync(harness.report, "utf8");
343
- expect(mapping.split("\n")[0]).toBe(
344
- "source_kind\tsource_file\tlocal_target\tderived_target\tstatus",
345
- );
346
- expect(mapping).toContain("claude-code\tmac:~/.claude/projects/p/cc.jsonl");
347
- expect(mapping).toContain(
348
- join(harness.home, "recallnest", "data", "desktop-import", "desktop-one.jsonl"),
349
- );
350
- expect(mapping).toContain("desktop-flat\t");
351
- expect(mapping).toContain("codex-index-merge\t");
352
- for (const line of mapping.trim().split("\n").slice(1)) {
353
- expect(line.split("\t")).toHaveLength(5);
354
- }
355
- const desktopTransportRows = mapping
356
- .trim()
357
- .split("\n")
358
- .slice(1)
359
- .map((line) => line.split("\t"))
360
- .filter(([sourceKind]) => sourceKind === "claude-desktop");
361
- expect(desktopTransportRows.length).toBeGreaterThan(0);
362
- expect(
363
- desktopTransportRows.every((fields) => fields[4] === "local-verified:derived-pending"),
364
- ).toBe(true);
365
- expect(statSync(harness.report).mode & 0o777).toBe(0o600);
366
- expect(existsSync(join(harness.home, ".codex", ".codex-global-state.json"))).toBe(false);
367
-
368
- const calls = rsyncCalls(harness);
369
- const grouped = new Map<string, RsyncCall[]>();
370
- for (const call of calls) {
371
- grouped.set(call.sourceArg, [...(grouped.get(call.sourceArg) || []), call]);
372
- }
373
- expect(grouped.size).toBe(10);
374
- for (const sourceCalls of grouped.values()) {
375
- expect(sourceCalls).toHaveLength(3);
376
- const real = sourceCalls.find((call) => !call.dryRun);
377
- const verify = sourceCalls.find((call) => call.dryRun && !call.ignoreTimes);
378
- const inventory = sourceCalls.find((call) => call.dryRun && call.ignoreTimes);
379
- expect(real).toBeDefined();
380
- expect(verify).toBeDefined();
381
- expect(inventory).toBeDefined();
382
- expect(normalizedRsyncArgs(verify!.args)).toEqual(real!.args);
383
- expect(normalizedRsyncArgs(inventory!.args)).toEqual(real!.args);
384
- expect(verify!.targetArg).toBe(real!.targetArg);
385
- expect(inventory!.targetArg).toBe(real!.targetArg);
386
- expect(unexpectedPositionalArgs(real!.args)).toEqual([]);
387
- }
388
- const desktopSource = "mac:Library/Application Support/Claude/local-agent-mode-sessions/";
389
- const desktopCalls = grouped.get(desktopSource);
390
- expect(desktopCalls).toHaveLength(3);
391
- expect(desktopCalls!.every((call) => call.args.includes("-s"))).toBe(true);
392
- expect(
393
- calls.some((call) =>
394
- call.sourceArg.includes("/.gemini/antigravity-cli/conversations/")
395
- || call.sourceArg.includes("/.gemini/antigravity/conversations/")
396
- ),
397
- ).toBe(false);
398
- const wrapperSource = readFileSync(SCRIPT, "utf8");
399
- expect(wrapperSource).not.toContain("mac:~/.gemini/antigravity-cli/conversations/");
400
- expect(wrapperSource).not.toContain("mac:~/.gemini/antigravity/conversations/");
401
-
402
- expect(dbContents(localDbDir)).toEqual(localDbBefore);
403
- expect(readFileSync(remoteCliDb, "utf8")).toBe(remoteCliBefore);
404
- expect(readFileSync(remoteAppDb, "utf8")).toBe(remoteAppBefore);
405
- const sshCalls = readFileSync(harness.sshLog, "utf8");
406
- expect(sshCalls).toContain("echo online");
407
- expect(sshCalls).toContain("$HOME/.codex");
408
- expect(sshCalls).toContain("$HOME/.kimi-code");
409
- expect(sshCalls).toContain("antigravity-rescue");
410
- }, TEST_TIMEOUT_MS);
411
-
412
- it("fails offline in sync-only mode but keeps the routine offline run successful", () => {
413
- const syncHarness = makeHarness();
414
- const syncResult = run(
415
- syncHarness,
416
- ["--sync-only", "--mapping-report", syncHarness.report],
417
- { FAKE_SSH_ONLINE: "0" },
418
- );
419
- expect(syncResult.status).not.toBe(0);
420
- expect(readFileSync(syncHarness.report, "utf8")).toContain("transport\tmac\t-\t-\toffline");
421
- expect(existsSync(syncHarness.registrarMarker)).toBe(false);
422
- expect(existsSync(syncHarness.ingestMarker)).toBe(false);
423
- expect(rsyncCalls(syncHarness)).toHaveLength(0);
424
-
425
- const routineHarness = makeHarness();
426
- const routineResult = run(routineHarness, [], { FAKE_SSH_ONLINE: "0" });
427
- expect(routineResult.status).toBe(0);
428
- expect(existsSync(routineHarness.registrarMarker)).toBe(true);
429
- expect(existsSync(routineHarness.ingestMarker)).toBe(false);
430
-
431
- const existingReportHarness = makeHarness();
432
- fixture(existingReportHarness.report, "keep-existing-report");
433
- const existingReportResult = syncOnly(existingReportHarness);
434
- expect(existingReportResult.status).not.toBe(0);
435
- expect(readFileSync(existingReportHarness.report, "utf8")).toBe("keep-existing-report");
436
- expect(existsSync(existingReportHarness.sshLog)).toBe(false);
437
-
438
- const racingReportHarness = makeHarness();
439
- const racingReportResult = run(
440
- racingReportHarness,
441
- ["--sync-only", "--mapping-report", racingReportHarness.report],
442
- { FAKE_CREATE_REPORT_DURING_SYNC: racingReportHarness.report },
443
- );
444
- expect(racingReportResult.status).not.toBe(0);
445
- expect(readFileSync(racingReportHarness.report, "utf8")).toBe("racing-writer");
446
- }, TEST_TIMEOUT_MS);
447
-
448
- it("fails before flattening when Desktop basenames collide", () => {
449
- const harness = makeHarness();
450
- fixture(
451
- join(
452
- harness.remoteHome,
453
- "Library",
454
- "Application Support",
455
- "Claude",
456
- "local-agent-mode-sessions",
457
- "d2",
458
- ".claude",
459
- "projects",
460
- "other",
461
- "Desktop-One.jsonl",
462
- ),
463
- "{\"source\":\"collision\"}\n",
464
- );
465
-
466
- const result = syncOnly(harness);
467
-
468
- expect(result.status).not.toBe(0);
469
- expect(readFileSync(harness.report, "utf8")).toContain("basename-collision");
470
- expect(
471
- existsSync(join(harness.home, "recallnest", "data", "desktop-import", "desktop-one.jsonl")),
472
- ).toBe(false);
473
- expect(existsSync(harness.ingestMarker)).toBe(false);
474
-
475
- const symlinkHarness = makeHarness();
476
- const linkedContent = join(symlinkHarness.remoteHome, "linked-content.jsonl");
477
- fixture(linkedContent, "{\"source\":\"must-not-follow\"}\n");
478
- const linkedSession = join(
479
- symlinkHarness.remoteHome,
480
- "Library",
481
- "Application Support",
482
- "Claude",
483
- "local-agent-mode-sessions",
484
- "d2",
485
- ".claude",
486
- "projects",
487
- "other",
488
- "linked.jsonl",
489
- );
490
- mkdirSync(dirname(linkedSession), { recursive: true });
491
- symlinkSync(linkedContent, linkedSession);
492
-
493
- const symlinkResult = syncOnly(symlinkHarness);
494
-
495
- expect(symlinkResult.status).not.toBe(0);
496
- expect(readFileSync(symlinkHarness.report, "utf8")).toContain("unsafe-symlink");
497
- expect(
498
- existsSync(join(symlinkHarness.home, "recallnest", "data", "desktop-import", "linked.jsonl")),
499
- ).toBe(false);
500
-
501
- const destinationHarness = makeHarness();
502
- const outsideTarget = join(destinationHarness.root, "outside-target.jsonl");
503
- fixture(outsideTarget, "outside-must-not-be-ingested");
504
- const destinationLink = join(
505
- destinationHarness.home,
506
- "recallnest",
507
- "data",
508
- "desktop-import",
509
- "desktop-one.jsonl",
510
- );
511
- mkdirSync(dirname(destinationLink), { recursive: true });
512
- symlinkSync(outsideTarget, destinationLink);
513
-
514
- const destinationResult = syncOnly(destinationHarness);
515
-
516
- expect(destinationResult.status).not.toBe(0);
517
- expect(readFileSync(destinationHarness.report, "utf8")).toContain(
518
- "unsafe-destination-symlink",
519
- );
520
- expect(readFileSync(outsideTarget, "utf8")).toBe("outside-must-not-be-ingested");
521
- }, TEST_TIMEOUT_MS);
522
-
523
- it("surfaces a Desktop copy failure and does not ingest", () => {
524
- const harness = makeHarness();
525
- mkdirSync(
526
- join(harness.home, "recallnest", "data", "desktop-import", "desktop-one.jsonl"),
527
- { recursive: true },
528
- );
529
-
530
- const result = syncOnly(harness);
531
-
532
- expect(result.status).not.toBe(0);
533
- expect(readFileSync(harness.report, "utf8")).toContain("copy-failed:IsADirectoryError");
534
- expect(existsSync(harness.ingestMarker)).toBe(false);
535
- }, TEST_TIMEOUT_MS);
536
-
537
- it("does not derive from a failed or partial source sync", () => {
538
- const desktopHarness = makeHarness();
539
- const desktopImport = join(
540
- desktopHarness.home,
541
- "recallnest",
542
- "data",
543
- "desktop-import",
544
- "desktop-one.jsonl",
545
- );
546
- fixture(desktopImport, "known-good-desktop");
547
-
548
- const desktopResult = run(
549
- desktopHarness,
550
- ["--sync-only", "--mapping-report", desktopHarness.report],
551
- { FAKE_RSYNC_FAIL_SOURCE: "local-agent-mode-sessions" },
552
- );
553
-
554
- expect(desktopResult.status).not.toBe(0);
555
- expect(readFileSync(desktopImport, "utf8")).toBe("known-good-desktop");
556
- expect(readFileSync(desktopHarness.report, "utf8")).toContain(
557
- "derived-skipped:source-sync-failed",
558
- );
559
-
560
- const indexHarness = makeHarness();
561
- const kimiIndex = join(indexHarness.home, ".kimi-code", "session_index.jsonl");
562
- fixture(kimiIndex, "{\"sessionId\":\"mini-only\"}\n");
563
-
564
- const indexResult = run(
565
- indexHarness,
566
- ["--sync-only", "--mapping-report", indexHarness.report],
567
- { FAKE_RSYNC_FAIL_SOURCE: ".kimi-code/session_index.jsonl" },
568
- );
569
-
570
- expect(indexResult.status).not.toBe(0);
571
- expect(readFileSync(kimiIndex, "utf8")).toContain("mini-only");
572
- expect(readFileSync(kimiIndex, "utf8")).not.toContain("mac-kimi");
573
- expect(readFileSync(indexHarness.report, "utf8")).toContain(
574
- "kimi-index-merge\t" + join(indexHarness.home, ".kimi-code", "session_index.macbook.jsonl"),
575
- );
576
- expect(readFileSync(indexHarness.report, "utf8")).toContain(
577
- "derived-skipped:source-sync-failed",
578
- );
579
- }, TEST_TIMEOUT_MS);
580
-
581
- it("distinguishes absent probes from partial, transport, and wrong-type failures", () => {
582
- const legacyHarness = makeHarness();
583
- const legacyResult = run(
584
- legacyHarness,
585
- ["--sync-only", "--mapping-report", legacyHarness.report],
586
- { FAKE_RSYNC_FAIL_SOURCE: "antigravity-rescue/conversations" },
587
- );
588
- const legacyMapping = readFileSync(legacyHarness.report, "utf8");
589
- expect(legacyResult.status).not.toBe(0);
590
- expect(legacyMapping).toContain("agy-legacy-pb\t");
591
- expect(legacyMapping).toContain("sync-failed:23");
592
- expect(legacyMapping).not.toContain(
593
- "agy-legacy-pb\tmac:~/Downloads/antigravity-rescue/conversations/\t"
594
- + join(legacyHarness.home, "machine-data", "macbook-agy", "legacy-pb")
595
- + "/\t"
596
- + join(legacyHarness.home, "machine-data", "macbook-agy", "legacy-pb")
597
- + "/\tsource-absent",
598
- );
599
-
600
- const probeHarness = makeHarness();
601
- const probeResult = run(
602
- probeHarness,
603
- ["--sync-only", "--mapping-report", probeHarness.report],
604
- { FAKE_SSH_FAIL_PROBE: "$HOME/.codex" },
605
- );
606
- expect(probeResult.status).not.toBe(0);
607
- expect(readFileSync(probeHarness.report, "utf8")).toContain("probe-failed:255");
608
- expect(
609
- rsyncCalls(probeHarness).some((call) =>
610
- call.sourceArg === "mac:~/.codex/session_index.jsonl"
611
- ),
612
- ).toBe(false);
613
-
614
- const wrongTypeHarness = makeHarness();
615
- const wrongTypeIndex = join(
616
- wrongTypeHarness.remoteHome,
617
- ".codex",
618
- "session_index.jsonl",
619
- );
620
- renameSync(wrongTypeIndex, wrongTypeIndex + ".saved");
621
- mkdirSync(wrongTypeIndex);
622
- const wrongTypeResult = syncOnly(wrongTypeHarness);
623
- const wrongTypeMapping = readFileSync(wrongTypeHarness.report, "utf8");
624
- expect(wrongTypeResult.status).not.toBe(0);
625
- expect(wrongTypeMapping).toContain("probe-failed:3");
626
- expect(wrongTypeMapping).not.toContain(
627
- "codex-session-index\tmac:~/.codex/session_index.jsonl\t"
628
- + join(wrongTypeHarness.home, ".codex", "session_index.macbook.jsonl")
629
- + "\t"
630
- + join(wrongTypeHarness.home, ".codex", "session_index.jsonl")
631
- + "\tsource-absent",
632
- );
633
-
634
- const absentHarness = makeHarness();
635
- const absentIndex = join(absentHarness.remoteHome, ".codex", "session_index.jsonl");
636
- renameSync(absentIndex, absentIndex + ".saved");
637
- const absentResult = syncOnly(absentHarness);
638
- expect(absentResult.status).toBe(0);
639
- expect(readFileSync(absentHarness.report, "utf8")).toContain(
640
- "codex-session-index\tmac:~/.codex/session_index.jsonl\t"
641
- + join(absentHarness.home, ".codex", "session_index.macbook.jsonl")
642
- + "\t"
643
- + join(absentHarness.home, ".codex", "session_index.jsonl")
644
- + "\tsource-absent",
645
- );
646
- }, TEST_TIMEOUT_MS);
647
-
648
- it("surfaces mapping append failures without installing a report or ingesting", () => {
649
- const harness = makeHarness();
650
- const result = run(
651
- harness,
652
- ["--sync-only", "--mapping-report", harness.report],
653
- { FAKE_BREAK_MAPPING_TMP: harness.report },
654
- );
655
-
656
- expect(result.status).not.toBe(0);
657
- expect(result.stdout + result.stderr).toContain("sync-only 映射报告追加失败");
658
- expect(existsSync(harness.report)).toBe(false);
659
- expect(existsSync(harness.ingestMarker)).toBe(false);
660
- }, TEST_TIMEOUT_MS);
661
-
662
- it("marks files pending when a live source changes after inventory", () => {
663
- const liveSourceHarness = makeHarness();
664
- const liveSourceResult = run(
665
- liveSourceHarness,
666
- ["--sync-only", "--mapping-report", liveSourceHarness.report],
667
- { FAKE_RSYNC_MUTATE_ON_VERIFY_SOURCE: ".claude/projects/" },
668
- );
669
- const liveSourceRows = readFileSync(liveSourceHarness.report, "utf8")
670
- .trim()
671
- .split("\n")
672
- .slice(1)
673
- .map((line) => line.split("\t"))
674
- .filter(([sourceKind]) => sourceKind === "claude-code");
675
- expect(liveSourceResult.status).not.toBe(0);
676
- expect(liveSourceRows.some((fields) => fields[4] === "pending:1")).toBe(true);
677
- expect(liveSourceRows.some((fields) => fields[4] === "verified")).toBe(false);
678
- }, TEST_TIMEOUT_MS);
679
- });