advisers 0.1.0-preview.4 → 0.2.0

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 (53) hide show
  1. package/LICENSE +131 -21
  2. package/NOTICE +34 -0
  3. package/README-zh.md +40 -9
  4. package/README.md +53 -10
  5. package/THIRD-PARTY-NOTICES.md +277 -0
  6. package/bin/advisers.js +4230 -122
  7. package/index.js +1 -1
  8. package/lib/agent.js +414 -0
  9. package/lib/attachments.js +283 -0
  10. package/lib/capture.js +168 -0
  11. package/lib/context-window.js +123 -0
  12. package/lib/digest.js +27 -0
  13. package/lib/doc-review.js +30 -0
  14. package/lib/egress.js +27 -0
  15. package/lib/evidence.js +1995 -0
  16. package/lib/ical.js +542 -0
  17. package/lib/imap.js +181 -0
  18. package/lib/importers.js +1001 -0
  19. package/lib/learning.js +46 -0
  20. package/lib/mcp-server.js +869 -0
  21. package/lib/model.js +307 -0
  22. package/lib/notify.js +189 -0
  23. package/lib/nudge.js +10 -0
  24. package/lib/ocr.js +47 -0
  25. package/lib/pdf.js +105 -0
  26. package/lib/pet-brief-store.js +51 -0
  27. package/lib/pet-brief.js +644 -0
  28. package/lib/receipt-verify.js +624 -0
  29. package/lib/relative-date.js +393 -0
  30. package/lib/remind.js +690 -0
  31. package/lib/research.js +193 -0
  32. package/lib/review.js +88 -0
  33. package/lib/routine.js +22 -0
  34. package/lib/safety/classifier.js +392 -0
  35. package/lib/safety/explain.js +157 -0
  36. package/lib/safety/index.js +333 -0
  37. package/lib/safety/redact.js +212 -0
  38. package/lib/safety/rules.js +824 -0
  39. package/lib/scheduler.js +399 -0
  40. package/lib/source.js +294 -0
  41. package/lib/sqlite.js +1022 -0
  42. package/lib/sync.js +129 -0
  43. package/lib/timestamp.js +45 -0
  44. package/lib/tos/index.js +332 -0
  45. package/lib/tos/manifest.json +32 -0
  46. package/lib/tos/privacy.zh-CN.md +136 -0
  47. package/lib/tos/safety.zh-CN.md +101 -0
  48. package/lib/tos/summary.zh-CN.md +12 -0
  49. package/lib/tos/terms.zh-CN.md +439 -0
  50. package/lib/ui.js +49 -0
  51. package/lib/undo.js +83 -0
  52. package/lib/vault.js +51 -0
  53. package/package.json +26 -4
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Read-only ledger snapshot loader for `advisers pet-brief`.
3
+ *
4
+ * Unlike `loadLedger()` in the CLI, this never creates, migrates, or writes
5
+ * the store: it opens SQLite with `readOnly: true`, or reads `state.json`
6
+ * as-is. Used only by the Pet Brief producer path.
7
+ */
8
+ import { existsSync, readFileSync } from 'node:fs'
9
+ import { SqliteStore } from './sqlite.js'
10
+
11
+ export class PetBriefStoreError extends Error {
12
+ constructor(code, message) {
13
+ super(message)
14
+ this.name = 'PetBriefStoreError'
15
+ this.code = code
16
+ }
17
+ }
18
+
19
+ /**
20
+ * @param {object} options
21
+ * @param {'sqlite'|'json'} [options.store] store backend (ADVISERS_STORE)
22
+ * @param {string} options.dbPath SQLite database path
23
+ * @param {string} options.statePath JSON ledger path
24
+ * @returns {object} LedgerSnapshot v1 (plain JSON object)
25
+ */
26
+ export function readLedgerSnapshotReadOnly({ store = 'sqlite', dbPath, statePath } = {}) {
27
+ if (store === 'json') {
28
+ if (!statePath || !existsSync(statePath)) {
29
+ throw new PetBriefStoreError('E_STORE', `store not found: ${statePath ?? '(no state path)'}; run \`advisers init\``)
30
+ }
31
+ try {
32
+ return JSON.parse(readFileSync(statePath, 'utf8'))
33
+ } catch (error) {
34
+ throw new PetBriefStoreError('E_STORE', `cannot read JSON ledger ${statePath}: ${error.message}`)
35
+ }
36
+ }
37
+ if (!dbPath || !existsSync(dbPath)) {
38
+ throw new PetBriefStoreError('E_STORE', `store not found: ${dbPath ?? '(no database path)'}; run \`advisers init\``)
39
+ }
40
+ let database
41
+ try {
42
+ database = new SqliteStore(dbPath, { readOnly: true })
43
+ return database.load()
44
+ } catch (error) {
45
+ throw new PetBriefStoreError('E_STORE', `cannot read SQLite store ${dbPath} read-only: ${error.message}`)
46
+ } finally {
47
+ if (database) {
48
+ try { database.close() } catch {}
49
+ }
50
+ }
51
+ }