@chainlesschain/personal-data-hub 0.4.29 → 0.4.30

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 (198) hide show
  1. package/lib/prompt-builder.js +15 -1
  2. package/package.json +4 -1
  3. package/__tests__/adapter-guide.test.js +0 -47
  4. package/__tests__/adapter-spec.test.js +0 -78
  5. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
  6. package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
  7. package/__tests__/adapters/ai-chat-history.test.js +0 -396
  8. package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
  9. package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
  10. package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
  11. package/__tests__/adapters/apple-health.test.js +0 -95
  12. package/__tests__/adapters/bank-family.test.js +0 -125
  13. package/__tests__/adapters/biz-tianyancha.test.js +0 -159
  14. package/__tests__/adapters/browser-history-chrome.test.js +0 -377
  15. package/__tests__/adapters/browser-history-edge.test.js +0 -159
  16. package/__tests__/adapters/car-mercedesme.test.js +0 -74
  17. package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
  18. package/__tests__/adapters/doc-camscanner.test.js +0 -147
  19. package/__tests__/adapters/doc-platforms.test.js +0 -177
  20. package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
  21. package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
  22. package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
  23. package/__tests__/adapters/email-adapter.test.js +0 -742
  24. package/__tests__/adapters/email-classifier.test.js +0 -347
  25. package/__tests__/adapters/email-imap-session.test.js +0 -334
  26. package/__tests__/adapters/email-parser.test.js +0 -244
  27. package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
  28. package/__tests__/adapters/email-providers.test.js +0 -84
  29. package/__tests__/adapters/email-retry-progress.test.js +0 -294
  30. package/__tests__/adapters/email-templates.test.js +0 -822
  31. package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
  32. package/__tests__/adapters/finance-alipay-live.test.js +0 -258
  33. package/__tests__/adapters/finance-dcep.test.js +0 -74
  34. package/__tests__/adapters/fitness-joyrun.test.js +0 -82
  35. package/__tests__/adapters/game-genshin-live.test.js +0 -238
  36. package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
  37. package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
  38. package/__tests__/adapters/git-activity.test.js +0 -222
  39. package/__tests__/adapters/gov-12123.test.js +0 -103
  40. package/__tests__/adapters/gov-ixiamen.test.js +0 -150
  41. package/__tests__/adapters/gov-tax.test.js +0 -135
  42. package/__tests__/adapters/health-meiyou.test.js +0 -125
  43. package/__tests__/adapters/local-files.test.js +0 -264
  44. package/__tests__/adapters/local-im-pc.test.js +0 -154
  45. package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
  46. package/__tests__/adapters/music-kugou.test.js +0 -187
  47. package/__tests__/adapters/music-qq.test.js +0 -112
  48. package/__tests__/adapters/netease-music-live.test.js +0 -244
  49. package/__tests__/adapters/netease-music.test.js +0 -74
  50. package/__tests__/adapters/pc-local-discovery.test.js +0 -141
  51. package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
  52. package/__tests__/adapters/reading-family.test.js +0 -108
  53. package/__tests__/adapters/recruit-boss.test.js +0 -180
  54. package/__tests__/adapters/shell-history.test.js +0 -180
  55. package/__tests__/adapters/shopping-base.test.js +0 -179
  56. package/__tests__/adapters/shopping-dianping.test.js +0 -239
  57. package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
  58. package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
  59. package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
  60. package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
  61. package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
  62. package/__tests__/adapters/social-csdn.test.js +0 -175
  63. package/__tests__/adapters/social-dongchedi.test.js +0 -165
  64. package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
  65. package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
  66. package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
  67. package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
  68. package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
  69. package/__tests__/adapters/social-douyin-adb-usage-profile.test.js +0 -229
  70. package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -269
  71. package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
  72. package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
  73. package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
  74. package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
  75. package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
  76. package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
  77. package/__tests__/adapters/social-toutiao-adb-article.test.js +0 -155
  78. package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
  79. package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
  80. package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
  81. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
  82. package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
  83. package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
  84. package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
  85. package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
  86. package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
  87. package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
  88. package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
  89. package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
  90. package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
  91. package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
  92. package/__tests__/adapters/social-zhihu.test.js +0 -246
  93. package/__tests__/adapters/system-data-adapter.test.js +0 -443
  94. package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
  95. package/__tests__/adapters/system-data-android.test.js +0 -519
  96. package/__tests__/adapters/system-data-disclosure.test.js +0 -153
  97. package/__tests__/adapters/travel-12306.test.js +0 -512
  98. package/__tests__/adapters/travel-amap.test.js +0 -219
  99. package/__tests__/adapters/travel-baidu-map.test.js +0 -305
  100. package/__tests__/adapters/travel-base.test.js +0 -205
  101. package/__tests__/adapters/travel-ctrip.test.js +0 -377
  102. package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
  103. package/__tests__/adapters/travel-didi.test.js +0 -204
  104. package/__tests__/adapters/travel-tencent-map.test.js +0 -207
  105. package/__tests__/adapters/travel-tongcheng.test.js +0 -289
  106. package/__tests__/adapters/video-platforms.test.js +0 -152
  107. package/__tests__/adapters/video-xigua.test.js +0 -106
  108. package/__tests__/adapters/vscode.test.js +0 -299
  109. package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
  110. package/__tests__/adapters/wechat-env-probe.test.js +0 -162
  111. package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
  112. package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
  113. package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
  114. package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
  115. package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
  116. package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
  117. package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
  118. package/__tests__/adapters/weread.test.js +0 -123
  119. package/__tests__/adapters/wework-pc.test.js +0 -124
  120. package/__tests__/adapters/win-recent.test.js +0 -192
  121. package/__tests__/analysis-skills.test.js +0 -754
  122. package/__tests__/analysis.test.js +0 -1845
  123. package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
  124. package/__tests__/batch.test.js +0 -133
  125. package/__tests__/bridges-cc-kg.test.js +0 -231
  126. package/__tests__/bridges-cc-llm.test.js +0 -191
  127. package/__tests__/bridges-cc-rag.test.js +0 -162
  128. package/__tests__/categories.test.js +0 -92
  129. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
  130. package/__tests__/e2e/full-user-journey.test.js +0 -188
  131. package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
  132. package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
  133. package/__tests__/entity-resolver-stages.test.js +0 -411
  134. package/__tests__/entity-resolver-vault.test.js +0 -249
  135. package/__tests__/entity-resolver.test.js +0 -526
  136. package/__tests__/fitness-keep-snapshot.test.js +0 -224
  137. package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
  138. package/__tests__/ids.test.js +0 -45
  139. package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
  140. package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
  141. package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
  142. package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
  143. package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
  144. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
  145. package/__tests__/key-providers.test.js +0 -126
  146. package/__tests__/kg-derive.test.js +0 -219
  147. package/__tests__/llm-client.test.js +0 -122
  148. package/__tests__/longtail-adapters.test.js +0 -281
  149. package/__tests__/messaging-qq-snapshot.test.js +0 -294
  150. package/__tests__/mobile-extractor-encrypted.test.js +0 -460
  151. package/__tests__/mobile-extractor.test.js +0 -288
  152. package/__tests__/mock-adapter.test.js +0 -93
  153. package/__tests__/prompt-builder.test.js +0 -249
  154. package/__tests__/query-parser.test.js +0 -365
  155. package/__tests__/rag-derive.test.js +0 -169
  156. package/__tests__/registry-readiness.test.js +0 -292
  157. package/__tests__/registry.test.js +0 -420
  158. package/__tests__/salvage-ingest.test.js +0 -97
  159. package/__tests__/schemas.test.js +0 -331
  160. package/__tests__/shopping-adapters.test.js +0 -392
  161. package/__tests__/shopping-eleme-snapshot.test.js +0 -454
  162. package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
  163. package/__tests__/shopping-snapshot.test.js +0 -438
  164. package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
  165. package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
  166. package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
  167. package/__tests__/sidecar-supervisor.test.js +0 -128
  168. package/__tests__/sign-providers.test.js +0 -62
  169. package/__tests__/social-adapters.test.js +0 -280
  170. package/__tests__/social-bilibili-snapshot.test.js +0 -278
  171. package/__tests__/social-douban-snapshot.test.js +0 -351
  172. package/__tests__/social-douyin-im-direct-read.test.js +0 -377
  173. package/__tests__/social-douyin-salvage-collector.test.js +0 -98
  174. package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
  175. package/__tests__/social-douyin-snapshot.test.js +0 -256
  176. package/__tests__/social-kuaishou-snapshot.test.js +0 -362
  177. package/__tests__/social-toutiao-snapshot.test.js +0 -366
  178. package/__tests__/social-weibo-snapshot.test.js +0 -234
  179. package/__tests__/social-weibo-sqlite-device.test.js +0 -174
  180. package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
  181. package/__tests__/sqlite-leaf-salvage.test.js +0 -97
  182. package/__tests__/travel-adapters.test.js +0 -483
  183. package/__tests__/travel-maps-snapshot.test.js +0 -426
  184. package/__tests__/vault-driver-error.test.js +0 -74
  185. package/__tests__/vault-search-helpers.test.js +0 -104
  186. package/__tests__/vault-search.test.js +0 -423
  187. package/__tests__/vault.test.js +0 -767
  188. package/__tests__/wechat-adapter.test.js +0 -594
  189. package/__tests__/whatsapp-adapter.test.js +0 -138
  190. package/scripts/_make-fixture-all.js +0 -126
  191. package/scripts/_make-fixture-contacts.js +0 -84
  192. package/scripts/evaluate-entity-resolver.js +0 -213
  193. package/scripts/run-native-tests-sandbox.sh +0 -55
  194. package/scripts/smoke-phase-5-5.js +0 -196
  195. package/scripts/smoke-phase-5-7.js +0 -181
  196. package/scripts/smoke-system-data-contacts.js +0 -309
  197. package/scripts/smoke-system-data.js +0 -312
  198. package/vitest.config.js +0 -88
@@ -1,138 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
-
5
- const fs = require("node:fs");
6
- const path = require("node:path");
7
- const os = require("node:os");
8
-
9
- const { WhatsAppAdapter } = require("../lib");
10
- const { assertAdapter } = require("../lib/adapter-spec");
11
- const { validateBatch } = require("../lib/batch");
12
-
13
- function makeMockDriver(scriptedRows) {
14
- return function () {
15
- return {
16
- prepare(sql) {
17
- return {
18
- all() {
19
- for (const [matchSubstr, rows] of scriptedRows) {
20
- if (sql.includes(matchSubstr)) return rows;
21
- }
22
- throw new Error("no such table");
23
- },
24
- };
25
- },
26
- close() {},
27
- };
28
- };
29
- }
30
-
31
- function tmpDb() {
32
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "wa-"));
33
- const dbPath = path.join(dir, "msgstore.db");
34
- fs.writeFileSync(dbPath, "fake");
35
- return { dir, dbPath };
36
- }
37
-
38
- describe("WhatsAppAdapter", () => {
39
- it("contract conformance", () => {
40
- const a = new WhatsAppAdapter({ account: { phone: "13800001111" } });
41
- expect(assertAdapter(a).ok).toBe(true);
42
- expect(a.extractMode).toBe("device-pull");
43
- expect(a.dataDisclosure.legalGate).toBe(true);
44
- });
45
-
46
- it("no-arg ctor passes contract (2026-05-25 v0.6 — account.phone OPTIONAL for snapshot mode)", () => {
47
- const a = new WhatsAppAdapter();
48
- expect(assertAdapter(a).ok).toBe(true);
49
- expect(a.capabilities).toContain("sync:snapshot");
50
- expect(a.capabilities).toContain("sync:sqlite");
51
- });
52
-
53
- it("authenticate fails without DB", async () => {
54
- const a = new WhatsAppAdapter({ account: { phone: "1" } });
55
- const r = await a.authenticate();
56
- expect(r.ok).toBe(false);
57
- expect(r.reason).toBe("DB_NOT_PULLED");
58
- });
59
-
60
- it("sync yields contact + chat + message + call", async () => {
61
- const { dir, dbPath } = tmpDb();
62
- try {
63
- const mockDriver = makeMockDriver([
64
- ["FROM jid", [
65
- { _id: 1, user: "13800001111", display_name: "Alice", raw_string: "13800001111@s.whatsapp.net" },
66
- { _id: 2, user: "group", display_name: "Group A", raw_string: "123456@g.us" },
67
- ]],
68
- ["FROM chat", [{ _id: 1, subject: "Chat 1" }]],
69
- ["FROM message", [
70
- { _id: 1, key_remote_jid: "1", text_data: "Hi", timestamp: 1700000000, from_me: 0 },
71
- ]],
72
- ["FROM messages", []],
73
- ["FROM call_log", [
74
- { _id: 1, jid_row_id: 1, video_call: 0, duration: 60, from_me: 1, timestamp: 1700001000, call_result: "completed" },
75
- ]],
76
- ]);
77
- const a = new WhatsAppAdapter({
78
- account: { phone: "13800001111" },
79
- dbPath,
80
- dbDriverFactory: () => mockDriver,
81
- });
82
- const raws = [];
83
- for await (const r of a.sync()) raws.push(r);
84
- // 2 jid contacts + 1 chat + 1 message + 1 call = 5
85
- expect(raws.length).toBe(5);
86
- const contacts = raws.filter((r) => r.payload.kind === "contact");
87
- const calls = raws.filter((r) => r.payload.kind === "call");
88
- expect(contacts).toHaveLength(2);
89
- expect(calls).toHaveLength(1);
90
-
91
- // Normalize all + validate
92
- for (const r of raws) {
93
- const batch = a.normalize(r);
94
- expect(validateBatch(batch).valid).toBe(true);
95
- }
96
- } finally {
97
- fs.rmSync(dir, { recursive: true, force: true });
98
- }
99
- });
100
-
101
- it("group jid → Topic not Person", async () => {
102
- const a = new WhatsAppAdapter({ account: { phone: "1" } });
103
- const batch = a.normalize({
104
- adapter: "messaging-whatsapp",
105
- originalId: "jid-2",
106
- capturedAt: Date.now(),
107
- payload: { kind: "contact", row: { _id: 2, raw_string: "123456@g.us", display_name: "Group A" } },
108
- });
109
- expect(batch.topics).toHaveLength(1);
110
- expect(batch.persons).toHaveLength(0);
111
- });
112
-
113
- it("individual jid → Person with phone identifier", async () => {
114
- const a = new WhatsAppAdapter({ account: { phone: "1" } });
115
- const batch = a.normalize({
116
- adapter: "messaging-whatsapp",
117
- originalId: "jid-1",
118
- capturedAt: Date.now(),
119
- payload: { kind: "contact", row: { _id: 1, user: "13800001111", display_name: "Alice", raw_string: "13800001111@s.whatsapp.net" } },
120
- });
121
- expect(batch.persons).toHaveLength(1);
122
- expect(batch.persons[0].identifiers.phone).toEqual(["13800001111"]);
123
- });
124
-
125
- it("call event captures duration + video flag", async () => {
126
- const a = new WhatsAppAdapter({ account: { phone: "1" } });
127
- const batch = a.normalize({
128
- adapter: "messaging-whatsapp",
129
- originalId: "call-1",
130
- capturedAt: Date.now(),
131
- payload: { kind: "call", row: { _id: 1, jid_row_id: 1, video_call: 1, duration: 300, from_me: 1, timestamp: 1700001000 } },
132
- });
133
- expect(batch.events[0].subtype).toBe("call");
134
- expect(batch.events[0].extra.duration).toBe(300);
135
- expect(batch.events[0].extra.isVideo).toBe(true);
136
- expect(batch.events[0].extra.fromMe).toBe(true);
137
- });
138
- });
@@ -1,126 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Build a complete fixture directory with all 4 system-data sources:
4
- *
5
- * <out>/
6
- * contacts2.db (raw_contacts + data + mimetypes)
7
- * mmssms.db (sms)
8
- * wifi/
9
- * WifiConfigStore.xml
10
- *
11
- * Usage:
12
- * node scripts/_make-fixture-all.js ./fixtures
13
- */
14
-
15
- "use strict";
16
-
17
- const fs = require("node:fs");
18
- const path = require("node:path");
19
- const Database = require("better-sqlite3-multiple-ciphers");
20
-
21
- const outDir = path.resolve(process.argv[2] || "./fixtures");
22
- fs.mkdirSync(path.join(outDir, "wifi"), { recursive: true });
23
-
24
- // ── contacts2.db ──────────────────────────────────────────────────────────
25
- const contactsPath = path.join(outDir, "contacts2.db");
26
- if (fs.existsSync(contactsPath)) fs.unlinkSync(contactsPath);
27
- const contacts = new Database(contactsPath);
28
- contacts.exec(`
29
- CREATE TABLE raw_contacts (
30
- _id INTEGER PRIMARY KEY, display_name TEXT, starred INTEGER DEFAULT 0, deleted INTEGER DEFAULT 0
31
- );
32
- CREATE TABLE mimetypes (_id INTEGER PRIMARY KEY, mimetype TEXT NOT NULL UNIQUE);
33
- CREATE TABLE data (
34
- _id INTEGER PRIMARY KEY, raw_contact_id INTEGER NOT NULL, mimetype_id INTEGER NOT NULL, data1 TEXT
35
- );
36
- CREATE TABLE calls (
37
- _id INTEGER PRIMARY KEY, number TEXT, type INTEGER, duration INTEGER, date INTEGER, name TEXT, is_read INTEGER DEFAULT 1
38
- );
39
- `);
40
- const MT = { phone: 5, email: 1, org: 4, note: 10, photo: 14 };
41
- const mi = contacts.prepare("INSERT INTO mimetypes (_id, mimetype) VALUES (?, ?)");
42
- mi.run(MT.phone, "vnd.android.cursor.item/phone_v2");
43
- mi.run(MT.email, "vnd.android.cursor.item/email_v2");
44
- mi.run(MT.org, "vnd.android.cursor.item/organization");
45
- mi.run(MT.note, "vnd.android.cursor.item/note");
46
- mi.run(MT.photo, "vnd.android.cursor.item/photo");
47
- const ci = contacts.prepare(
48
- "INSERT INTO raw_contacts (_id, display_name, starred, deleted) VALUES (?, ?, ?, 0)",
49
- );
50
- ci.run(1, "妈妈", 1);
51
- ci.run(2, "张三", 0);
52
- ci.run(3, "李四 Manager", 0);
53
- ci.run(5, "工商银行客服", 0);
54
- const di = contacts.prepare(
55
- "INSERT INTO data (raw_contact_id, mimetype_id, data1) VALUES (?, ?, ?)",
56
- );
57
- di.run(1, MT.phone, "13800001111");
58
- di.run(1, MT.phone, "13900002222");
59
- di.run(1, MT.email, "mom@example.com");
60
- di.run(1, MT.note, "亲妈,过年回家");
61
- di.run(2, MT.phone, "13711112222");
62
- di.run(3, MT.phone, "13822223333");
63
- di.run(3, MT.email, "lisi@corp.example.com");
64
- di.run(3, MT.org, "Example Corp");
65
- di.run(5, MT.phone, "95588");
66
- // Calls table inside contacts2.db (pre-Android-11 location)
67
- const li = contacts.prepare(
68
- "INSERT INTO calls (_id, number, type, duration, date, name, is_read) VALUES (?, ?, ?, ?, ?, ?, ?)",
69
- );
70
- li.run(1, "13800001111", 1, 120, 1737000000000, "妈妈", 1);
71
- li.run(2, "13800001111", 2, 45, 1737010000000, "妈妈", 1);
72
- li.run(3, "13999998888", 3, 0, 1737020000000, "", 0);
73
- li.run(4, "10086", 1, 8, 1737030000000, "中国移动", 1);
74
- contacts.close();
75
- console.log("wrote:", contactsPath);
76
-
77
- // ── mmssms.db ─────────────────────────────────────────────────────────────
78
- const smsPath = path.join(outDir, "mmssms.db");
79
- if (fs.existsSync(smsPath)) fs.unlinkSync(smsPath);
80
- const sms = new Database(smsPath);
81
- sms.exec(`
82
- CREATE TABLE sms (
83
- _id INTEGER PRIMARY KEY, thread_id INTEGER, address TEXT, body TEXT,
84
- type INTEGER, date INTEGER, read INTEGER
85
- );
86
- `);
87
- const si = sms.prepare(
88
- "INSERT INTO sms (_id, thread_id, address, body, type, date, read) VALUES (?, ?, ?, ?, ?, ?, ?)",
89
- );
90
- si.run(1, 100, "13800001111", "妈妈我到家了", 2, 1737000000000, 1);
91
- si.run(2, 100, "13800001111", "好的,注意安全", 1, 1737000010000, 1);
92
- si.run(3, 200, "10086", "【中国移动】您的话费余额为 ¥36.50", 1, 1737000020000, 1);
93
- si.run(4, 300, "95588", "【工商银行】您的验证码为 123456,3 分钟内有效", 1, 1737000030000, 0);
94
- sms.close();
95
- console.log("wrote:", smsPath);
96
-
97
- // ── wifi/WifiConfigStore.xml ──────────────────────────────────────────────
98
- const wifiXml = path.join(outDir, "wifi", "WifiConfigStore.xml");
99
- fs.writeFileSync(
100
- wifiXml,
101
- `<?xml version='1.0' encoding='UTF-8'?>
102
- <WifiConfigStoreData>
103
- <NetworkList>
104
- <Network>
105
- <WifiConfiguration>
106
- <string name="SSID">"Home_5G"</string>
107
- <string name="PreSharedKey">"secret"</string>
108
- <string name="KeyMgmt">WPA-PSK</string>
109
- <boolean name="HiddenSSID">false</boolean>
110
- </WifiConfiguration>
111
- </Network>
112
- <Network>
113
- <WifiConfiguration>
114
- <string name="SSID">"Starbucks Free"</string>
115
- <string name="KeyMgmt">NONE</string>
116
- <boolean name="HiddenSSID">false</boolean>
117
- </WifiConfiguration>
118
- </Network>
119
- </NetworkList>
120
- </WifiConfigStoreData>
121
- `,
122
- "utf-8",
123
- );
124
- console.log("wrote:", wifiXml);
125
-
126
- console.log("\nAll fixtures ready under:", outDir);
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Build a synthetic Android contacts2.db at the given path.
4
- *
5
- * Only used by the smoke runner / docs walkthrough — production code never
6
- * relies on this. Mirrors the fixture from
7
- * packages/personal-data-hub-bridge/tests/test_parsers_system_contacts.py.
8
- *
9
- * Usage:
10
- * node scripts/_make-fixture-contacts.js ./fixtures/contacts2.db
11
- */
12
-
13
- "use strict";
14
-
15
- const fs = require("node:fs");
16
- const path = require("node:path");
17
- const Database = require("better-sqlite3-multiple-ciphers");
18
-
19
- const target = path.resolve(process.argv[2] || "./fixtures/contacts2.db");
20
- fs.mkdirSync(path.dirname(target), { recursive: true });
21
- if (fs.existsSync(target)) fs.unlinkSync(target);
22
-
23
- const db = new Database(target);
24
- try {
25
- db.exec(`
26
- CREATE TABLE raw_contacts (
27
- _id INTEGER PRIMARY KEY,
28
- display_name TEXT,
29
- starred INTEGER DEFAULT 0,
30
- deleted INTEGER DEFAULT 0
31
- );
32
- CREATE TABLE mimetypes (
33
- _id INTEGER PRIMARY KEY,
34
- mimetype TEXT NOT NULL UNIQUE
35
- );
36
- CREATE TABLE data (
37
- _id INTEGER PRIMARY KEY,
38
- raw_contact_id INTEGER NOT NULL,
39
- mimetype_id INTEGER NOT NULL,
40
- data1 TEXT
41
- );
42
- `);
43
-
44
- const MT = {
45
- phone: 5,
46
- email: 1,
47
- org: 4,
48
- note: 10,
49
- photo: 14,
50
- };
51
- const insertMime = db.prepare(
52
- "INSERT INTO mimetypes (_id, mimetype) VALUES (?, ?)",
53
- );
54
- insertMime.run(MT.phone, "vnd.android.cursor.item/phone_v2");
55
- insertMime.run(MT.email, "vnd.android.cursor.item/email_v2");
56
- insertMime.run(MT.org, "vnd.android.cursor.item/organization");
57
- insertMime.run(MT.note, "vnd.android.cursor.item/note");
58
- insertMime.run(MT.photo, "vnd.android.cursor.item/photo");
59
-
60
- const insertC = db.prepare(
61
- "INSERT INTO raw_contacts (_id, display_name, starred, deleted) VALUES (?, ?, ?, 0)",
62
- );
63
- insertC.run(1, "妈妈", 1);
64
- insertC.run(2, "张三", 0);
65
- insertC.run(3, "李四 Manager", 0);
66
- insertC.run(4, "", 0); // nameless — skipped by parser
67
- insertC.run(5, "工商银行客服", 0);
68
-
69
- const insertD = db.prepare(
70
- "INSERT INTO data (raw_contact_id, mimetype_id, data1) VALUES (?, ?, ?)",
71
- );
72
- insertD.run(1, MT.phone, "13800001111");
73
- insertD.run(1, MT.phone, "13900002222");
74
- insertD.run(1, MT.email, "mom@example.com");
75
- insertD.run(1, MT.note, "亲妈,过年回家");
76
- insertD.run(2, MT.phone, "13711112222");
77
- insertD.run(3, MT.phone, "13822223333");
78
- insertD.run(3, MT.email, "lisi@corp.example.com");
79
- insertD.run(3, MT.org, "Example Corp");
80
- insertD.run(5, MT.phone, "95588");
81
- } finally {
82
- db.close();
83
- }
84
- console.log("fixture written:", target);
@@ -1,213 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Phase 8.8 — EntityResolver evaluation runner.
4
- *
5
- * Reads a labeled pair fixture, runs each pair through the configured
6
- * stages, computes recall / accuracy / per-stage breakdown, and exits
7
- * non-zero if the CI gate (recall ≥ 80%, accuracy ≥ 90%) fails.
8
- *
9
- * Usage:
10
- * node scripts/evaluate-entity-resolver.js \
11
- * [--fixture <path>] [--use-embedding] [--use-llm] [--require-pass]
12
- *
13
- * Defaults:
14
- * - fixture: __tests__/fixtures/entity-resolver-200-mock.json
15
- * - --use-embedding: skipped unless flag set (needs Ollama running)
16
- * - --use-llm: skipped unless flag set (needs Ollama + chat model)
17
- * - --require-pass: exit 1 when gate fails (use in CI; otherwise warn-only)
18
- */
19
-
20
- "use strict";
21
-
22
- const fs = require("node:fs");
23
- const path = require("node:path");
24
-
25
- const {
26
- entityResolverRuleStage: ruleStage,
27
- } = require("../lib/entity-resolver");
28
-
29
- const args = parseArgs(process.argv.slice(2));
30
- const fixturePath = args.fixture || path.join(
31
- __dirname, "..", "__tests__", "fixtures", "entity-resolver-200-mock.json"
32
- );
33
- const useEmbedding = !!args["use-embedding"];
34
- const useLlm = !!args["use-llm"];
35
- const requirePass = !!args["require-pass"];
36
-
37
- const RECALL_GATE = 0.80;
38
- const ACCURACY_GATE = 0.90;
39
-
40
- async function main() {
41
- console.log("== EntityResolver evaluation ==");
42
- console.log("fixture:", fixturePath);
43
- if (!fs.existsSync(fixturePath)) {
44
- console.error("\nFAIL: fixture not found");
45
- process.exit(2);
46
- }
47
- const data = JSON.parse(fs.readFileSync(fixturePath, "utf-8"));
48
- if (!Array.isArray(data.pairs) || data.pairs.length === 0) {
49
- console.error("\nFAIL: fixture has no pairs");
50
- process.exit(2);
51
- }
52
-
53
- const stages = { embedding: null, llm: null };
54
- if (useEmbedding) {
55
- const { EntityResolverEmbeddingStage } = require("../lib/entity-resolver");
56
- stages.embedding = new EntityResolverEmbeddingStage({}).asStageFn();
57
- console.log("embedding stage: Ollama nomic-embed-text @ localhost:11434");
58
- }
59
- if (useLlm) {
60
- const { EntityResolverLLMStage } = require("../lib/entity-resolver");
61
- const { OllamaClient } = require("../lib/llm-client");
62
- const llm = new OllamaClient({ baseUrl: "http://localhost:11434", model: "qwen2.5:7b-instruct" });
63
- stages.llm = new EntityResolverLLMStage({ llm }).asStageFn();
64
- console.log("llm stage: Ollama qwen2.5:7b-instruct");
65
- }
66
-
67
- // Per-stage counters
68
- const counts = {
69
- ruleSame: 0, ruleDifferent: 0, ruleUncertain: 0,
70
- embeddingSame: 0, embeddingDifferent: 0, embeddingUncertain: 0,
71
- llmSame: 0, llmDifferent: 0, llmMaybe: 0,
72
- };
73
-
74
- // Confusion matrix
75
- const confusion = { tp: 0, fp: 0, fn: 0, tn: 0, unresolved: 0 };
76
-
77
- // Per-pair breakdown
78
- const results = [];
79
-
80
- for (const pair of data.pairs) {
81
- const truth = pair.groundTruth; // "same" | "different"
82
- const ruleVerdict = ruleStage(pair.a, pair.b).verdict;
83
- let finalVerdict = ruleVerdict;
84
- let stage = "rule";
85
-
86
- if (ruleVerdict === "same") counts.ruleSame += 1;
87
- else if (ruleVerdict === "different") counts.ruleDifferent += 1;
88
- else counts.ruleUncertain += 1;
89
-
90
- if (ruleVerdict === "uncertain" && stages.embedding) {
91
- const e = await stages.embedding(pair.a, pair.b);
92
- if (e.sim >= 0.85) {
93
- finalVerdict = "same";
94
- counts.embeddingSame += 1;
95
- stage = "embedding";
96
- } else if (e.sim < 0.55) {
97
- finalVerdict = "different";
98
- counts.embeddingDifferent += 1;
99
- stage = "embedding";
100
- } else {
101
- counts.embeddingUncertain += 1;
102
- if (stages.llm) {
103
- const v = await stages.llm(pair.a, pair.b);
104
- if (v.verdict === "yes" && v.confidence >= 0.7) {
105
- finalVerdict = "same";
106
- counts.llmSame += 1;
107
- stage = "llm";
108
- } else if (v.verdict === "no" && v.confidence >= 0.7) {
109
- finalVerdict = "different";
110
- counts.llmDifferent += 1;
111
- stage = "llm";
112
- } else {
113
- finalVerdict = "review";
114
- counts.llmMaybe += 1;
115
- stage = "llm-review";
116
- }
117
- }
118
- }
119
- }
120
-
121
- // Tally confusion (only counting decided verdicts)
122
- if (finalVerdict === "same" && truth === "same") confusion.tp += 1;
123
- else if (finalVerdict === "same" && truth === "different") confusion.fp += 1;
124
- else if (finalVerdict === "different" && truth === "same") confusion.fn += 1;
125
- else if (finalVerdict === "different" && truth === "different") confusion.tn += 1;
126
- else confusion.unresolved += 1;
127
-
128
- results.push({ id: pair.id, truth, finalVerdict, stage, category: pair.category });
129
- }
130
-
131
- const total = data.pairs.length;
132
- const resolved = total - confusion.unresolved;
133
- const accuracy = resolved > 0 ? (confusion.tp + confusion.tn) / resolved : 0;
134
- const recall = (confusion.tp + confusion.fn) > 0
135
- ? confusion.tp / (confusion.tp + confusion.fn)
136
- : 1;
137
- const precision = (confusion.tp + confusion.fp) > 0
138
- ? confusion.tp / (confusion.tp + confusion.fp)
139
- : 1;
140
- const resolveRate = resolved / total;
141
-
142
- // ── Report ──
143
- console.log("\nPair counts:", { total, resolved, unresolved: confusion.unresolved });
144
- console.log("\nPipeline stages:");
145
- console.log(` Rule: same=${counts.ruleSame} different=${counts.ruleDifferent} uncertain=${counts.ruleUncertain}`);
146
- if (stages.embedding) console.log(` Embedding: same=${counts.embeddingSame} different=${counts.embeddingDifferent} uncertain=${counts.embeddingUncertain}`);
147
- if (stages.llm) console.log(` LLM: same=${counts.llmSame} different=${counts.llmDifferent} maybe=${counts.llmMaybe}`);
148
-
149
- console.log("\nConfusion (decided only):");
150
- console.log(` TP=${confusion.tp} FP=${confusion.fp} FN=${confusion.fn} TN=${confusion.tn}`);
151
- console.log(` unresolved=${confusion.unresolved} (rule "uncertain" with no embedding/llm wired)`);
152
-
153
- console.log("\nMetrics:");
154
- const recallStr = (recall * 100).toFixed(1) + "%";
155
- const accStr = (accuracy * 100).toFixed(1) + "%";
156
- const precStr = (precision * 100).toFixed(1) + "%";
157
- const resolveStr = (resolveRate * 100).toFixed(1) + "%";
158
- console.log(` Recall: ${recallStr} (target ≥ ${(RECALL_GATE * 100).toFixed(0)}%) ${recall >= RECALL_GATE ? "✓" : "✗"}`);
159
- console.log(` Accuracy: ${accStr} (target ≥ ${(ACCURACY_GATE * 100).toFixed(0)}%) ${accuracy >= ACCURACY_GATE ? "✓" : "✗"}`);
160
- console.log(` Precision: ${precStr}`);
161
- console.log(` Resolve rate: ${resolveStr}`);
162
-
163
- // Per-category breakdown (useful for spotting weak spots)
164
- const byCategory = {};
165
- for (const r of results) {
166
- const cat = r.category || "(uncat)";
167
- if (!byCategory[cat]) byCategory[cat] = { total: 0, correct: 0, unresolved: 0 };
168
- byCategory[cat].total += 1;
169
- if (r.finalVerdict === "review" || r.finalVerdict === "uncertain") {
170
- byCategory[cat].unresolved += 1;
171
- } else if (r.finalVerdict === r.truth) {
172
- byCategory[cat].correct += 1;
173
- }
174
- }
175
- console.log("\nPer-category:");
176
- for (const cat of Object.keys(byCategory)) {
177
- const s = byCategory[cat];
178
- const accStr = s.total - s.unresolved > 0
179
- ? ((s.correct / (s.total - s.unresolved)) * 100).toFixed(0) + "%"
180
- : "N/A";
181
- console.log(` ${cat}: ${s.correct}/${s.total - s.unresolved} correct (${accStr}); ${s.unresolved} unresolved`);
182
- }
183
-
184
- // Gate decision
185
- const passed = recall >= RECALL_GATE && accuracy >= ACCURACY_GATE;
186
- console.log(`\n${passed ? "✓ PASS" : "✗ FAIL"} — recall ${recallStr} / accuracy ${accStr}`);
187
-
188
- if (!passed && requirePass) {
189
- process.exit(1);
190
- }
191
- }
192
-
193
- function parseArgs(argv) {
194
- const out = {};
195
- for (let i = 0; i < argv.length; i += 1) {
196
- const a = argv[i];
197
- if (a.startsWith("--")) {
198
- const k = a.slice(2);
199
- if (argv[i + 1] && !argv[i + 1].startsWith("--")) {
200
- out[k] = argv[i + 1];
201
- i += 1;
202
- } else {
203
- out[k] = true;
204
- }
205
- }
206
- }
207
- return out;
208
- }
209
-
210
- main().catch((err) => {
211
- console.error("\nFATAL:", err && err.message ? err.message : err);
212
- process.exit(2);
213
- });
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Run vault-search.test.js (FTS5 native integration) in an isolated sandbox.
3
- #
4
- # Background: the root node_modules bs3mc binding is built for Electron 39
5
- # (NODE_MODULE_VERSION 140) which doesn't match ANY Node.js version
6
- # (Node 24 = ABI 137, Node 25 = ABI 141). Plain `npm test` fails locally with
7
- # ABI mismatch. CI is unaffected because its node_modules is built fresh.
8
- #
9
- # This script:
10
- # 1. Copies lib/ + the target test into a temp sandbox
11
- # 2. Installs a separate bs3mc compiled for the CURRENT host Node ABI
12
- # 3. Runs vitest against it
13
- #
14
- # Idempotent; rerun any time. Sandbox lives under $TMPDIR/pdh-fts5-sandbox
15
- # so it survives between runs (faster re-install).
16
- #
17
- # Usage: bash packages/personal-data-hub/scripts/run-native-tests-sandbox.sh
18
-
19
- set -euo pipefail
20
-
21
- ROOT="$(cd "$(dirname "$0")/.." && pwd)"
22
- SANDBOX="${TMPDIR:-/tmp}/pdh-fts5-sandbox"
23
-
24
- echo "==> Sandbox: $SANDBOX"
25
- mkdir -p "$SANDBOX/lib" "$SANDBOX/__tests__"
26
-
27
- # Sync sources every run (lib/ may have evolved since last sandbox build)
28
- cp -r "$ROOT/lib/." "$SANDBOX/lib/"
29
- cp "$ROOT/__tests__/vault-search.test.js" "$SANDBOX/__tests__/"
30
- # vault.test.js exercises native SQL (incl. sumEventAmount, intent=sum-amount Phase 2)
31
- cp "$ROOT/__tests__/vault.test.js" "$SANDBOX/__tests__/"
32
-
33
- # Minimal package.json — only the deps the target test needs.
34
- cat > "$SANDBOX/package.json" <<'EOF'
35
- {
36
- "name": "pdh-fts5-sandbox",
37
- "version": "0.0.0",
38
- "private": true,
39
- "type": "commonjs",
40
- "scripts": { "test": "vitest run" },
41
- "dependencies": { "better-sqlite3-multiple-ciphers": "^12.5.0" },
42
- "devDependencies": { "vitest": "^4.1.5" }
43
- }
44
- EOF
45
-
46
- if [ ! -d "$SANDBOX/node_modules/better-sqlite3-multiple-ciphers/build" ]; then
47
- echo "==> Installing deps (one-time, ~30-60s)"
48
- (cd "$SANDBOX" && npm install --no-audit --no-fund --loglevel=warn)
49
- else
50
- echo "==> Deps already installed (skipping npm install)"
51
- fi
52
-
53
- echo "==> Running tests"
54
- cd "$SANDBOX"
55
- exec node ./node_modules/vitest/vitest.mjs run