advisers 0.2.3 → 0.3.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.
- package/LICENSE +0 -0
- package/NOTICE +0 -0
- package/README-zh.md +15 -6
- package/README.md +22 -6
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/bin/advisers.js +3323 -222
- package/index.js +1 -1
- package/lib/agent.js +0 -0
- package/lib/attachments.js +0 -0
- package/lib/audit-anchor.js +683 -0
- package/lib/backup.js +1345 -0
- package/lib/capture.js +0 -0
- package/lib/context-window.js +0 -0
- package/lib/digest.js +0 -0
- package/lib/doc-review.js +0 -0
- package/lib/egress.js +0 -0
- package/lib/error-codes.js +1373 -0
- package/lib/evidence.js +202 -26
- package/lib/fs-safe.js +70 -7
- package/lib/ical.js +0 -0
- package/lib/imap.js +6 -2
- package/lib/importers.js +0 -0
- package/lib/learning.js +0 -0
- package/lib/ledger-read.js +608 -0
- package/lib/mcp-server.js +294 -38
- package/lib/model.js +0 -0
- package/lib/node-warning-filter.js +15 -0
- package/lib/notify.js +13 -3
- package/lib/nudge.js +0 -0
- package/lib/ocr.js +0 -0
- package/lib/pdf.js +0 -0
- package/lib/pet-brief-store.js +0 -0
- package/lib/pet-brief.js +102 -39
- package/lib/receipt-verify.js +213 -15
- package/lib/relative-date.js +0 -0
- package/lib/remind.js +91 -36
- package/lib/research.js +0 -0
- package/lib/review.js +0 -0
- package/lib/routine.js +0 -0
- package/lib/safety/classifier.js +0 -0
- package/lib/safety/explain.js +0 -0
- package/lib/safety/index.js +0 -0
- package/lib/safety/redact.js +0 -0
- package/lib/safety/rules.js +0 -0
- package/lib/scheduler.js +0 -0
- package/lib/source.js +0 -0
- package/lib/sqlite.js +1214 -24
- package/lib/sync.js +0 -0
- package/lib/text-safe.js +229 -0
- package/lib/timestamp.js +0 -0
- package/lib/tos/index.js +1 -1
- package/lib/tos/manifest.json +6 -6
- package/lib/tos/privacy.zh-CN.md +12 -9
- package/lib/tos/safety.zh-CN.md +4 -3
- package/lib/tos/summary.zh-CN.md +3 -3
- package/lib/tos/terms.zh-CN.md +8 -6
- package/lib/tui/color.js +164 -0
- package/lib/tui/index.js +33 -0
- package/lib/tui/json.js +124 -0
- package/lib/tui/labels.js +50 -0
- package/lib/tui/policy.js +108 -0
- package/lib/tui/render.js +371 -0
- package/lib/tui/sanitize.js +142 -0
- package/lib/tui/text-file.js +116 -0
- package/lib/tui/width.js +577 -0
- package/lib/ui.js +0 -0
- package/lib/undo.js +0 -0
- package/lib/untrusted.js +0 -0
- package/lib/vault.js +0 -0
- package/package.json +6 -5
package/lib/remind.js
CHANGED
|
@@ -19,12 +19,6 @@ export const DEFAULT_HORIZON_DAYS = 7
|
|
|
19
19
|
const BUCKETS = new Set(['overdue', 'due-today', 'due-1d', 'upcoming'])
|
|
20
20
|
const LEVELS = new Set(['L1', 'L2', 'L3'])
|
|
21
21
|
|
|
22
|
-
const DAY_FORMAT = new Intl.DateTimeFormat('en-US', {
|
|
23
|
-
timeZone: TIME_ZONE,
|
|
24
|
-
year: 'numeric',
|
|
25
|
-
month: '2-digit',
|
|
26
|
-
day: '2-digit',
|
|
27
|
-
})
|
|
28
22
|
const TIME_FORMAT = new Intl.DateTimeFormat('en-US', {
|
|
29
23
|
timeZone: TIME_ZONE,
|
|
30
24
|
hour: '2-digit',
|
|
@@ -88,18 +82,34 @@ function requireNow(value) {
|
|
|
88
82
|
return requireDate(value, 'now')
|
|
89
83
|
}
|
|
90
84
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Local calendar day in Asia/Shanghai, as `YYYY-MM-DD`.
|
|
87
|
+
*
|
|
88
|
+
* 0.3.0 P0-T2: computed with UTC+8 arithmetic instead of
|
|
89
|
+
* Intl.DateTimeFormat.formatToParts. Shanghai has been a fixed UTC+8 offset
|
|
90
|
+
* without DST since 1991, so the two agree for every date the ledger stores;
|
|
91
|
+
* the arithmetic form is ~20x faster, which matters because the reminder and
|
|
92
|
+
* pet-brief views resolve one local day per due row (66k rows at a 200k
|
|
93
|
+
* ledger).
|
|
94
|
+
*/
|
|
98
95
|
export function localDay(value) {
|
|
99
96
|
const date = toDate(value)
|
|
100
97
|
if (!date) return null
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
return localDayOf(date)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Local calendar day string for an already-parsed instant. */
|
|
102
|
+
function localDayOf(date) {
|
|
103
|
+
const wall = new Date(date.getTime() + SHANGHAI_OFFSET_MS)
|
|
104
|
+
const year = wall.getUTCFullYear()
|
|
105
|
+
const month = wall.getUTCMonth() + 1
|
|
106
|
+
const day = wall.getUTCDate()
|
|
107
|
+
return `${String(year).padStart(4, '0')}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Day-of-epoch number of the Asia/Shanghai calendar day for an instant. */
|
|
111
|
+
function localDayIndexFromMs(ms) {
|
|
112
|
+
return Math.floor((ms + SHANGHAI_OFFSET_MS) / DAY_MS)
|
|
103
113
|
}
|
|
104
114
|
|
|
105
115
|
/** Minutes since local midnight in Asia/Shanghai (0–1439). */
|
|
@@ -260,6 +270,9 @@ function resolveReminderOffsets(value) {
|
|
|
260
270
|
return resolved
|
|
261
271
|
}
|
|
262
272
|
|
|
273
|
+
/** Shared empty result for the reminder-planning fast path (never mutated). */
|
|
274
|
+
const EMPTY_REMINDER_OFFSETS = Object.freeze([])
|
|
275
|
+
|
|
263
276
|
/** Human label used inside a VALARM DESCRIPTION. */
|
|
264
277
|
export function describeReminderOffset(value) {
|
|
265
278
|
const parsed = parseReminderOffset(value)
|
|
@@ -527,23 +540,61 @@ export function buildReminders(ledger, options = {}) {
|
|
|
527
540
|
const seen = new Set()
|
|
528
541
|
const reminders = []
|
|
529
542
|
|
|
543
|
+
// 0.3.0 P0-T2: per-call caches. Reminder planning needs one parsed due
|
|
544
|
+
// instant and one local day per row, but a real ledger has only a few
|
|
545
|
+
// hundred distinct dueAt strings at 200k rows; caching the parse turns ~60k
|
|
546
|
+
// regex + Date.parse + Intl lookups into a few hundred and keeps remind/tui
|
|
547
|
+
// inside the 0.3.0 read budget.
|
|
548
|
+
const dueCache = new Map()
|
|
549
|
+
const dueInfo = (value) => {
|
|
550
|
+
const key = typeof value === 'string' ? value : value instanceof Date ? `date:${value.getTime()}` : `ms:${String(value)}`
|
|
551
|
+
let info = dueCache.get(key)
|
|
552
|
+
if (info === undefined) {
|
|
553
|
+
const date = toDate(value)
|
|
554
|
+
info = date ? { date, dayIndex: localDayIndexFromMs(date.getTime()), dueDay: localDayOf(date) } : null
|
|
555
|
+
dueCache.set(key, info)
|
|
556
|
+
}
|
|
557
|
+
return info
|
|
558
|
+
}
|
|
559
|
+
// readSnoozeUntil()/readReminderOffsets() can only find state that was
|
|
560
|
+
// injected, set on the row, or exposed by a duck-typed ledger hook. The
|
|
561
|
+
// common CLI path has none of that, so skip the per-row lookup instead of
|
|
562
|
+
// allocating a candidate array for every commitment.
|
|
563
|
+
const injectedSnooze = opts.snoozedUntil
|
|
564
|
+
const snoozeStatePossible = typeof injectedSnooze === 'function' ||
|
|
565
|
+
(injectedSnooze instanceof Map && injectedSnooze.size > 0) ||
|
|
566
|
+
(Boolean(injectedSnooze) && typeof injectedSnooze === 'object' && !(injectedSnooze instanceof Map) && Object.keys(injectedSnooze).length > 0) ||
|
|
567
|
+
typeof ledger.getMeta === 'function'
|
|
568
|
+
const injectedOffsets = opts.reminderOffsets
|
|
569
|
+
const offsetStatePossible = typeof injectedOffsets === 'function' ||
|
|
570
|
+
(injectedOffsets instanceof Map && injectedOffsets.size > 0) ||
|
|
571
|
+
(Boolean(injectedOffsets) && typeof injectedOffsets === 'object' && !(injectedOffsets instanceof Map) && Object.keys(injectedOffsets).length > 0) ||
|
|
572
|
+
opts.defaultReminderOffsets !== undefined ||
|
|
573
|
+
typeof ledger.getMeta === 'function'
|
|
574
|
+
|
|
530
575
|
for (const commitment of commitments) {
|
|
531
576
|
if (!commitment || typeof commitment !== 'object') continue
|
|
532
577
|
if (!commitment.id) continue
|
|
533
578
|
if (commitment.status === 'done' || commitment.status === 'dropped') continue
|
|
534
579
|
if (commitment.dueAt == null || commitment.dueAt === '') continue
|
|
535
|
-
const
|
|
536
|
-
if (!
|
|
537
|
-
|
|
538
|
-
|
|
580
|
+
const info = dueInfo(commitment.dueAt)
|
|
581
|
+
if (!info) continue
|
|
582
|
+
const due = info.date
|
|
583
|
+
|
|
584
|
+
const snoozeUntil = snoozeStatePossible || commitment.snoozedUntil !== undefined || commitment.snoozeUntil !== undefined ||
|
|
585
|
+
commitment.snoozeAt !== undefined || commitment.meta !== undefined
|
|
586
|
+
? readSnoozeUntil(commitment, opts, ledger)
|
|
587
|
+
: null
|
|
539
588
|
// An active snooze hides the commitment; once it expires the commitment
|
|
540
589
|
// becomes visible again and the snooze-wake rule fires.
|
|
541
590
|
if (snoozeUntil && snoozeUntil.getTime() > now.getTime()) continue
|
|
542
591
|
const snoozeExpired = Boolean(snoozeUntil)
|
|
543
|
-
const reminderOffsets =
|
|
592
|
+
const reminderOffsets = offsetStatePossible || commitment.reminderOffsets !== undefined || commitment.meta !== undefined
|
|
593
|
+
? readReminderOffsets(commitment, opts, ledger)
|
|
594
|
+
: EMPTY_REMINDER_OFFSETS
|
|
544
595
|
|
|
545
|
-
const dueDay =
|
|
546
|
-
const dayOffset =
|
|
596
|
+
const dueDay = info.dueDay
|
|
597
|
+
const dayOffset = info.dayIndex - todayIndex
|
|
547
598
|
if (dayOffset > horizonDays) continue
|
|
548
599
|
|
|
549
600
|
const bucket = bucketFor(dayOffset)
|
|
@@ -569,27 +620,31 @@ export function buildReminders(ledger, options = {}) {
|
|
|
569
620
|
if (seen.has(key)) continue
|
|
570
621
|
seen.add(key)
|
|
571
622
|
reminders.push({
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
623
|
+
// Kept out of the output object: the final sort needs the instant,
|
|
624
|
+
// and toDate() per comparator call was the 0.2.x sort's hot spot.
|
|
625
|
+
dueMs: due.getTime(),
|
|
626
|
+
reminder: {
|
|
627
|
+
commitmentId: commitment.id,
|
|
628
|
+
action: commitment.action ?? '',
|
|
629
|
+
dueAt: outputDueAt(commitment.dueAt),
|
|
630
|
+
bucket: result.bucket,
|
|
631
|
+
level: result.level,
|
|
632
|
+
ruleId: result.ruleId,
|
|
633
|
+
// Only present when customised: pre-0.2.0 reminder objects keep their
|
|
634
|
+
// exact shape and toIcs falls back to the legacy relative alarms.
|
|
635
|
+
...(reminderOffsets.length ? { reminderOffsets } : {}),
|
|
636
|
+
},
|
|
581
637
|
})
|
|
582
638
|
}
|
|
583
639
|
}
|
|
584
640
|
|
|
585
|
-
const dueTime = (reminder) => toDate(reminder.dueAt)?.getTime() ?? 0
|
|
586
641
|
reminders.sort(
|
|
587
642
|
(left, right) =>
|
|
588
|
-
|
|
589
|
-
left.commitmentId.localeCompare(right.commitmentId) ||
|
|
590
|
-
left.ruleId.localeCompare(right.ruleId),
|
|
643
|
+
left.dueMs - right.dueMs ||
|
|
644
|
+
left.reminder.commitmentId.localeCompare(right.reminder.commitmentId) ||
|
|
645
|
+
left.reminder.ruleId.localeCompare(right.reminder.ruleId),
|
|
591
646
|
)
|
|
592
|
-
return reminders
|
|
647
|
+
return reminders.map((entry) => entry.reminder)
|
|
593
648
|
}
|
|
594
649
|
|
|
595
650
|
/**
|
package/lib/research.js
CHANGED
|
File without changes
|
package/lib/review.js
CHANGED
|
File without changes
|
package/lib/routine.js
CHANGED
|
File without changes
|
package/lib/safety/classifier.js
CHANGED
|
File without changes
|
package/lib/safety/explain.js
CHANGED
|
File without changes
|
package/lib/safety/index.js
CHANGED
|
File without changes
|
package/lib/safety/redact.js
CHANGED
|
File without changes
|
package/lib/safety/rules.js
CHANGED
|
File without changes
|
package/lib/scheduler.js
CHANGED
|
File without changes
|
package/lib/source.js
CHANGED
|
File without changes
|