ofw-mcp 2.27.5 → 2.28.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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +4 -2
- package/dist/bundle.js +155 -49
- package/dist/cache/store.js +12 -3
- package/dist/read-days.js +31 -5
- package/dist/sync.js +34 -19
- package/dist/tools/messages.js +149 -47
- package/dist/tools/reply-source.js +4 -0
- package/dist/version.js +1 -1
- package/mint.yaml +2 -1
- package/package.json +1 -1
- package/server.json +4 -4
- package/skills/ofw/SKILL.md +1 -0
package/dist/read-days.js
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Some co-parenting arrangements (a court order, a parenting-plan clause, or
|
|
4
4
|
// just a personal rule) limit when OFW messages are read — e.g. "check OFW on
|
|
5
|
-
// Mondays and Thursdays only".
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
5
|
+
// Mondays and Thursdays only". A no-read day exists for ONE reason: to keep an
|
|
6
|
+
// unread INBOX message from being marked read, which stamps a co-parent-visible
|
|
7
|
+
// "First Viewed" time on the record that cannot be undone. So on those days an
|
|
8
|
+
// unread inbox message shows only that it arrived — sender, subject, time —
|
|
9
|
+
// with its body and attachments withheld, and nothing that could stamp it is
|
|
10
|
+
// requested. Everything else stays fully readable: every sent message, every
|
|
11
|
+
// inbox message already read, and drafts. Blocking those protects nothing.
|
|
9
12
|
//
|
|
10
13
|
// Two env vars, either or both:
|
|
11
14
|
// OFW_READ_DAYS allow list — reading is permitted ONLY on these days
|
|
@@ -25,6 +28,12 @@
|
|
|
25
28
|
// An unparseable token fails CLOSED (every day blocked) with a stderr warning:
|
|
26
29
|
// someone who wrote "Thrusday" meant to restrict reading, and silently
|
|
27
30
|
// ignoring the typo would keep reading on the day they meant to keep clear.
|
|
31
|
+
//
|
|
32
|
+
// `overrideNoReadDay` is the one way past this, per call, for when the user
|
|
33
|
+
// explicitly asks to read an unread message anyway. It lifts ONLY the day restriction: the
|
|
34
|
+
// mark-read gates (OFW_ALLOW_MARK_READ, OFW_CONFIRM_MARK_READ, sync's
|
|
35
|
+
// fetchUnreadBodies) apply exactly as on a reading day, and each use is logged
|
|
36
|
+
// through auditReadOverride.
|
|
28
37
|
import { readEnvVar } from '@chrischall/mcp-utils';
|
|
29
38
|
import { displayTimeZone } from './timestamps.js';
|
|
30
39
|
const WEEKDAYS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
|
|
@@ -93,6 +102,8 @@ function addDays(date, n) {
|
|
|
93
102
|
const dt = new Date(Date.UTC(y, m - 1, d + n));
|
|
94
103
|
return { date: dt.toISOString().slice(0, 10), weekday: dt.getUTCDay() };
|
|
95
104
|
}
|
|
105
|
+
/** Why a single message's body is absent on a no-read day. */
|
|
106
|
+
export const UNREAD_ON_NO_READ_DAY = 'UNREAD_ON_NO_READ_DAY';
|
|
96
107
|
/**
|
|
97
108
|
* Null when message content may be read today; otherwise a description of why
|
|
98
109
|
* not, suitable for embedding in a tool response.
|
|
@@ -121,7 +132,22 @@ export function readingBlockedToday(now = new Date()) {
|
|
|
121
132
|
today: today.date,
|
|
122
133
|
weekday: WEEKDAY_LABELS[today.weekday],
|
|
123
134
|
timeZone,
|
|
124
|
-
reason: `${reason}
|
|
135
|
+
reason: `${reason} A no-read day only protects UNREAD inbox messages: their sender, subject and time are shown, but their bodies and attachments are withheld and nothing may mark them read on OurFamilyWizard. Sent messages, inbox messages already read, and drafts stay fully readable. This is a deployment setting: respect it. Only if the user has explicitly asked to read an unread message anyway today, pass overrideNoReadDay:true to ofw_get_message, ofw_list_messages or ofw_sync_messages. Attachments of unread messages stay withheld either way.`,
|
|
125
136
|
nextReadableDay,
|
|
126
137
|
};
|
|
127
138
|
}
|
|
139
|
+
/** What a response that used the override says about itself. */
|
|
140
|
+
export const READ_OVERRIDE_NOTE = 'Read on a no-read day via override.';
|
|
141
|
+
/**
|
|
142
|
+
* Record one use of overrideNoReadDay. stderr is this server's only log — on a
|
|
143
|
+
* hosted deployment it is what `mcp-host logs` tails — so the audit line goes
|
|
144
|
+
* there, in one greppable, parseable shape. Ids only: never subjects or bodies.
|
|
145
|
+
*/
|
|
146
|
+
export function auditReadOverride(tool, messageIds, now = new Date()) {
|
|
147
|
+
console.error(`[ofw-mcp] AUDIT ${JSON.stringify({
|
|
148
|
+
event: 'no_read_day_override',
|
|
149
|
+
timestamp: now.toISOString(),
|
|
150
|
+
tool,
|
|
151
|
+
messageIds,
|
|
152
|
+
})}`);
|
|
153
|
+
}
|
package/dist/sync.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { clearHeldFiles, getHeldFiles, setHeldFiles } from './tools/held-attachments.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { ApiRecipientSchema, draftReplyTarget, hasRealView, mapRecipients, scrapeSaysRead } from './tools/_shared.js';
|
|
4
|
-
import { setReplyToSource } from './tools/reply-source.js';
|
|
4
|
+
import { clearReplyToSource, setReplyToSource } from './tools/reply-source.js';
|
|
5
5
|
import { senderOf } from './tools/project.js';
|
|
6
6
|
import { parseLenient } from '@chrischall/mcp-utils';
|
|
7
7
|
import { displayTimeZone, nowNaiveWallClock, parseTimestampValue } from './timestamps.js';
|
|
8
|
-
import { readingBlockedToday } from './read-days.js';
|
|
8
|
+
import { READ_OVERRIDE_NOTE, readingBlockedToday } from './read-days.js';
|
|
9
9
|
// Each OFW message detail returns `files: [fileId, ...]`. We fetch the metadata
|
|
10
10
|
// for each file id (cheap JSON call) so the model can see filenames/mime types
|
|
11
11
|
// without downloading bytes. Bytes are pulled lazily by ofw_download_attachment.
|
|
@@ -221,11 +221,13 @@ async function walkPages(client, folder, folderId, opts, store) {
|
|
|
221
221
|
const listRead = scrapeSaysRead(folder, item);
|
|
222
222
|
const isInboxUnread = folder === 'inbox' && !listRead;
|
|
223
223
|
if (existing) {
|
|
224
|
-
// Heal a row cached without its body — typically
|
|
225
|
-
//
|
|
226
|
-
// an inbox message OFW's list reports as
|
|
227
|
-
// stays the caller's explicit choice
|
|
228
|
-
|
|
224
|
+
// Heal a row cached without its body — typically an inbox message
|
|
225
|
+
// first seen unread and read since — once fetching it can stamp
|
|
226
|
+
// nothing: a sent message, or an inbox message OFW's list reports as
|
|
227
|
+
// read. An unread inbox body stays the caller's explicit choice
|
|
228
|
+
// (ofw_get_message), as before. A no-read day does not stop this: it
|
|
229
|
+
// protects only unread inbox messages (read-days.ts).
|
|
230
|
+
if (existing.body === null && !isInboxUnread) {
|
|
229
231
|
if (!budget.take()) {
|
|
230
232
|
pageBudgetHit = true;
|
|
231
233
|
break;
|
|
@@ -254,7 +256,7 @@ async function walkPages(client, folder, folderId, opts, store) {
|
|
|
254
256
|
// on the detail endpoint. So when a sent message has flipped to read
|
|
255
257
|
// and we don't yet hold a real viewed time, re-fetch detail to capture
|
|
256
258
|
// it (no body re-fetch — only the recipient view fields can change).
|
|
257
|
-
if (
|
|
259
|
+
if (folder === 'sent' && item.showNeverViewed === false && !hasRealView(existing.recipients)) {
|
|
258
260
|
if (!budget.take()) {
|
|
259
261
|
pageBudgetHit = true;
|
|
260
262
|
break;
|
|
@@ -266,7 +268,7 @@ async function walkPages(client, folder, folderId, opts, store) {
|
|
|
266
268
|
continue;
|
|
267
269
|
}
|
|
268
270
|
pageHadNewItem = true;
|
|
269
|
-
const shouldFetchBody =
|
|
271
|
+
const shouldFetchBody = !isInboxUnread || opts.fetchUnreadBodies;
|
|
270
272
|
let body = null;
|
|
271
273
|
let fetchedBodyAt = null;
|
|
272
274
|
let detailFileIds = [];
|
|
@@ -300,6 +302,8 @@ async function walkPages(client, folder, folderId, opts, store) {
|
|
|
300
302
|
}
|
|
301
303
|
// Reached for an unread inbox message only under fetchUnreadBodies.
|
|
302
304
|
const detail = await fetchDetail(item, { subject: row.subject, sentAt: row.sentAt, from }, 'GET /pub/v3/messages/{id} (sync)', isInboxUnread);
|
|
305
|
+
if (isInboxUnread)
|
|
306
|
+
opts.onUnreadBodyFetched?.(item.id);
|
|
303
307
|
body = detail.body ?? '';
|
|
304
308
|
fetchedBodyAt = new Date().toISOString();
|
|
305
309
|
detailRecipients = detail.recipients;
|
|
@@ -370,7 +374,6 @@ async function walkPages(client, folder, folderId, opts, store) {
|
|
|
370
374
|
* waited months can wait one more call.
|
|
371
375
|
*/
|
|
372
376
|
export async function syncMessageFolder(client, folder, folderId, opts, store) {
|
|
373
|
-
const fetchBodies = opts.fetchBodies ?? true;
|
|
374
377
|
// No budget → unbounded (local stdio): every take() succeeds, so an ordinary
|
|
375
378
|
// sync is byte-for-byte the original unbounded walk (forward pass only).
|
|
376
379
|
const budget = opts.budget ?? makeBudget(Number.POSITIVE_INFINITY);
|
|
@@ -380,7 +383,7 @@ export async function syncMessageFolder(client, folder, folderId, opts, store) {
|
|
|
380
383
|
startPage: 1,
|
|
381
384
|
stopAtCachedPage: true,
|
|
382
385
|
fetchUnreadBodies: opts.fetchUnreadBodies,
|
|
383
|
-
|
|
386
|
+
onUnreadBodyFetched: opts.onUnreadBodyFetched,
|
|
384
387
|
budget,
|
|
385
388
|
}, store);
|
|
386
389
|
let synced = fwd.synced;
|
|
@@ -433,7 +436,7 @@ export async function syncMessageFolder(client, folder, folderId, opts, store) {
|
|
|
433
436
|
startPage: savedResume ?? fwd.nextPage,
|
|
434
437
|
stopAtCachedPage: false,
|
|
435
438
|
fetchUnreadBodies: opts.fetchUnreadBodies,
|
|
436
|
-
|
|
439
|
+
onUnreadBodyFetched: opts.onUnreadBodyFetched,
|
|
437
440
|
budget,
|
|
438
441
|
}, store);
|
|
439
442
|
synced += bf.synced;
|
|
@@ -652,8 +655,10 @@ export async function syncDrafts(client, draftsFolderId, store, budget) {
|
|
|
652
655
|
const seenIds = new Set(ids);
|
|
653
656
|
const vanished = (await store.listDraftIds()).filter((id) => !seenIds.has(id));
|
|
654
657
|
await inferReplacedDraftLineage(store, vanished, rows.filter((r) => !existingById.has(r.id)));
|
|
655
|
-
for (const id of vanished)
|
|
658
|
+
for (const id of vanished) {
|
|
656
659
|
await store.deleteDraft(id);
|
|
660
|
+
await clearReplyToSource(store, id);
|
|
661
|
+
}
|
|
657
662
|
// The complete walk fetched every draft's DETAIL and reconciled deletions, so
|
|
658
663
|
// the cache is now known-equal to the server. Only here is `synced: 0`
|
|
659
664
|
// truthful as "verified no changes" — and only here may reads report the
|
|
@@ -749,7 +754,13 @@ export async function syncAll(client, opts, store) {
|
|
|
749
754
|
const budget = makeBudget(opts.maxRequests ?? Number.POSITIVE_INFINITY);
|
|
750
755
|
// Decided HERE, not by each caller, so every path into a sync — the tool,
|
|
751
756
|
// a read's autoRefresh, ofw_status — honours a no-read day (read-days.ts).
|
|
752
|
-
|
|
757
|
+
// The day protects only unread inbox messages: it refuses fetchUnreadBodies
|
|
758
|
+
// and nothing else, so sent and already-read bodies sync as on any day.
|
|
759
|
+
const noReadDay = readingBlockedToday() !== null;
|
|
760
|
+
const overriding = noReadDay && opts.overrideNoReadDay === true;
|
|
761
|
+
const readingBlocked = noReadDay && !overriding;
|
|
762
|
+
const openedUnreadIds = [];
|
|
763
|
+
const onUnreadBodyFetched = (id) => { openedUnreadIds.push(id); };
|
|
753
764
|
// resolveFolderIds always makes exactly one request; the tool guarantees
|
|
754
765
|
// maxRequests >= 1, so this unit is always available (result intentionally
|
|
755
766
|
// ignored — we account for it without a branch that can't be reached).
|
|
@@ -780,7 +791,7 @@ export async function syncAll(client, opts, store) {
|
|
|
780
791
|
if (folder === 'inbox') {
|
|
781
792
|
const r = await syncMessageFolder(client, 'inbox', ids.inbox, {
|
|
782
793
|
fetchUnreadBodies: !readingBlocked && (opts.fetchUnreadBodies ?? false),
|
|
783
|
-
|
|
794
|
+
onUnreadBodyFetched,
|
|
784
795
|
deep: opts.deep ?? false,
|
|
785
796
|
budget,
|
|
786
797
|
}, store);
|
|
@@ -794,7 +805,6 @@ export async function syncAll(client, opts, store) {
|
|
|
794
805
|
else if (folder === 'sent') {
|
|
795
806
|
const r = await syncMessageFolder(client, 'sent', ids.sent, {
|
|
796
807
|
fetchUnreadBodies: false,
|
|
797
|
-
fetchBodies: !readingBlocked,
|
|
798
808
|
deep: opts.deep ?? false,
|
|
799
809
|
budget,
|
|
800
810
|
}, store);
|
|
@@ -818,8 +828,8 @@ export async function syncAll(client, opts, store) {
|
|
|
818
828
|
}
|
|
819
829
|
}
|
|
820
830
|
const notes = [];
|
|
821
|
-
if (readingBlocked) {
|
|
822
|
-
notes.push('Today is a no-read day (OFW_READ_DAYS / OFW_NO_READ_DAYS):
|
|
831
|
+
if (readingBlocked && opts.fetchUnreadBodies === true) {
|
|
832
|
+
notes.push('Today is a no-read day (OFW_READ_DAYS / OFW_NO_READ_DAYS), so fetchUnreadBodies was not honoured: unread inbox messages were cached from the list only — sender, date and subject — and none was marked read. Sent and already-read messages synced as usual.');
|
|
823
833
|
}
|
|
824
834
|
if (draftsUnverified) {
|
|
825
835
|
notes.push('The drafts folder was NOT checked against OurFamilyWizard on this call (the request budget ran out first), so no drafts count is reported and the cached drafts are marked "unverified". Cached draft bodies may be behind the server. Call ofw_sync_messages again — or ofw_sync_messages with folders:["drafts"] — before editing or deleting a draft.');
|
|
@@ -846,7 +856,12 @@ export async function syncAll(client, opts, store) {
|
|
|
846
856
|
syncComplete: done,
|
|
847
857
|
refreshed,
|
|
848
858
|
notRefreshed,
|
|
849
|
-
|
|
859
|
+
// Claimed only when the override released something: like ofw_get_message
|
|
860
|
+
// and ofw_list_messages, a sync whose read/sent bodies needed no override
|
|
861
|
+
// reports none and leaves nothing to audit.
|
|
862
|
+
...(overriding && openedUnreadIds.length > 0
|
|
863
|
+
? { readOverride: true, readOverrideNote: READ_OVERRIDE_NOTE, readOverrideMessageIds: openedUnreadIds }
|
|
864
|
+
: {}),
|
|
850
865
|
note,
|
|
851
866
|
markedRead,
|
|
852
867
|
newMessages: newMessages.slice(0, NEW_MESSAGES_CAP),
|