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,46 @@
1
+ const CORRECTION_START = /^(不是|不对|错了|应该|以后|记住|每次|改成|改一下)/
2
+ const MAX_STATEMENT = 160
3
+
4
+ /** Extract a correction/preference statement from a short user message. */
5
+ export function correctionStatement(text) {
6
+ const raw = typeof text === 'string' ? text.trim() : ''
7
+ if (!raw || raw.length > MAX_STATEMENT || !CORRECTION_START.test(raw)) return null
8
+ const contrast = raw.match(/^不是(.+?)[,,]\s*(?:而)?是(.+)$/)
9
+ if (contrast) return contrast[2].trim()
10
+ const rewrite = raw.match(/^(?:改成|改一下|应该)\s*(.+)$/)
11
+ if (rewrite) return rewrite[1].trim()
12
+ return raw
13
+ }
14
+
15
+ /** Exponential decay per 30 days; deprecated below 0.3. */
16
+ export function applyPreferenceDecay(preferences, now = new Date(), days = 30) {
17
+ const changed = []
18
+ for (const pref of preferences) {
19
+ if (pref.status === 'deprecated') continue
20
+ if (pref.priority === 'hard') continue
21
+ const last = new Date(pref.lastConfirmed ?? pref.validFrom).getTime()
22
+ const ageDays = (now.getTime() - last) / 86_400_000
23
+ if (!Number.isFinite(ageDays) || ageDays < days) continue
24
+ const periods = Math.floor(ageDays / days)
25
+ pref.confidence = Math.max(0, pref.confidence * Math.pow(0.8, periods))
26
+ if (pref.confidence < 0.3) pref.status = 'deprecated'
27
+ changed.push(pref)
28
+ }
29
+ return changed
30
+ }
31
+
32
+ /** A successful multi-tool task becomes a draft routine, never auto-active. */
33
+ export function buildRoutineCandidate({ text, toolLog = [], artifacts = [] }) {
34
+ const tools = [...new Set(toolLog.map((t) => t.name).filter(Boolean))]
35
+ if (tools.length < 3 || artifacts.length === 0) return null
36
+ return {
37
+ name: text.replace(/\s+/g, ' ').slice(0, 60),
38
+ description: '从一次多工具任务沉淀的流程草稿',
39
+ trigger: [],
40
+ steps: tools,
41
+ preferences: [],
42
+ pitfalls: [],
43
+ verification: artifacts.map((file) => `file:${file}`),
44
+ createdBy: 'agent',
45
+ }
46
+ }