ofw-mcp 2.23.0 → 2.25.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.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +3 -2
- package/dist/bundle.js +1083 -328
- package/dist/config.js +29 -0
- package/dist/sync.js +10 -1
- package/dist/tools/messages.js +192 -17
- package/dist/tools/project.js +1 -1
- package/dist/version.js +1 -1
- package/mint.yaml +7 -0
- package/package.json +1 -1
- package/server.json +8 -2
- package/skills/ofw/SKILL.md +2 -2
package/dist/config.js
CHANGED
|
@@ -167,6 +167,35 @@ export function getAllowMarkRead() {
|
|
|
167
167
|
console.error(`[ofw-mcp] Unrecognized OFW_ALLOW_MARK_READ "${raw.trim()}" — failing closed to "false" (no tool may mark a message read on OFW). Valid values: true, false.`);
|
|
168
168
|
return false;
|
|
169
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Ask before a read stamps the record.
|
|
172
|
+
*
|
|
173
|
+
* With OFW_CONFIRM_MARK_READ=true, `ofw_get_message` no longer opens an unread
|
|
174
|
+
* inbox message silently: it shows the subject, sender and sent time and asks
|
|
175
|
+
* the user to confirm — through the same gate as a send (an elicitation prompt
|
|
176
|
+
* where the client supports one, otherwise the two-phase confirmToken flow).
|
|
177
|
+
* `ofw_sync_messages fetchUnreadBodies` asks too: it syncs without stamping,
|
|
178
|
+
* then lists the cached unread messages it would open and waits for a yes.
|
|
179
|
+
* The `allowMarkRead` probes of `ofw_check_freshness` / `ofw_status` have no
|
|
180
|
+
* message to show before the request that stamps, so they are switched off.
|
|
181
|
+
*
|
|
182
|
+
* Default FALSE: unset is exactly the shipped behaviour. An unrecognized value
|
|
183
|
+
* fails CLOSED to true, with a warning: someone who typed "ture" meant to turn
|
|
184
|
+
* the prompt on, and honouring the typo as "off" would stamp without asking.
|
|
185
|
+
* OFW_ALLOW_MARK_READ=false still wins — confirmation cannot raise that ceiling.
|
|
186
|
+
*/
|
|
187
|
+
export function getConfirmMarkRead() {
|
|
188
|
+
const raw = process.env.OFW_CONFIRM_MARK_READ;
|
|
189
|
+
if (typeof raw !== 'string' || raw.trim().length === 0)
|
|
190
|
+
return false;
|
|
191
|
+
const value = raw.trim().toLowerCase();
|
|
192
|
+
if (['1', 'true', 'yes', 'on'].includes(value))
|
|
193
|
+
return true;
|
|
194
|
+
if (['0', 'false', 'no', 'off'].includes(value))
|
|
195
|
+
return false;
|
|
196
|
+
console.error(`[ofw-mcp] Unrecognized OFW_CONFIRM_MARK_READ "${raw.trim()}" — failing closed to "true" (opening an unread message asks for confirmation first). Valid values: true, false.`);
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
170
199
|
/**
|
|
171
200
|
* Default for ofw_sync_messages' `fetchUnreadBodies` arg. False (the shipped
|
|
172
201
|
* default) so an ordinary sync never stamps unread inbox messages; set
|
package/dist/sync.js
CHANGED
|
@@ -528,6 +528,15 @@ export async function syncDrafts(client, draftsFolderId, store, budget) {
|
|
|
528
528
|
await markFolderVerified(store, 'drafts', now);
|
|
529
529
|
return { synced, done: true };
|
|
530
530
|
}
|
|
531
|
+
/**
|
|
532
|
+
* The sync note for unread inbox messages cached without bodies. Exported so
|
|
533
|
+
* ofw_sync_messages can rewrite it after a confirmed open of some of them —
|
|
534
|
+
* a note still counting messages the same call opened would contradict
|
|
535
|
+
* `unreadInbox` in one payload.
|
|
536
|
+
*/
|
|
537
|
+
export function unreadInboxNote(count) {
|
|
538
|
+
return `${count} unread inbox messages cached without bodies. Call ofw_get_message(id) to read them — this will mark them as read on OFW.`;
|
|
539
|
+
}
|
|
531
540
|
export async function syncAll(client, opts, store) {
|
|
532
541
|
const requested = opts.folders ?? ['inbox', 'sent', 'drafts'];
|
|
533
542
|
// Drafts go FIRST. They are the only folder a destructive tool
|
|
@@ -616,7 +625,7 @@ export async function syncAll(client, opts, store) {
|
|
|
616
625
|
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.');
|
|
617
626
|
}
|
|
618
627
|
if (unreadInbox.length > 0) {
|
|
619
|
-
notes.push(
|
|
628
|
+
notes.push(unreadInboxNote(unreadInbox.length));
|
|
620
629
|
}
|
|
621
630
|
if (notRefreshed.length > 0) {
|
|
622
631
|
notes.push(`NOT checked against OurFamilyWizard on this call: ${notRefreshed.join(', ')}. No count is reported for ${notRefreshed.length > 1 ? 'those folders' : 'that folder'} — absence of a count means "not looked at", not "no changes". Cached contents may be behind the server; call ofw_sync_messages again to finish, or ofw_check_freshness for a cheap live confirmation.`);
|
package/dist/tools/messages.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { syncAll, fetchAttachmentMeta, fetchAttachmentMetaForMessage, getDraftsCacheStatus } from '../sync.js';
|
|
2
|
+
import { syncAll, unreadInboxNote, fetchAttachmentMeta, fetchAttachmentMetaForMessage, getDraftsCacheStatus } from '../sync.js';
|
|
3
3
|
import { buildFreshness } from './freshness.js';
|
|
4
4
|
import { checkDraftFreshness, draftRevision, fetchServerDraft, staleDraftPayload, } from './draft-freshness.js';
|
|
5
5
|
import { FOLDER_TYPE, newDraftKey, persistFolderIds, probeIds, resolveDraftKey } from './lifecycle.js';
|
|
@@ -7,14 +7,14 @@ import { CONFIRM_NOTE, confirmTokenParam, confirmWrite } from './_confirm.js';
|
|
|
7
7
|
import { getFolderVerifiedAt } from '../sync.js';
|
|
8
8
|
import { buildInlineDelivery, tryExtract } from './delivery.js';
|
|
9
9
|
import { resolveDownloadMime, resolveSaveDest } from './attachments.js';
|
|
10
|
-
import { getAllowMarkRead, getAttachmentsDir, getAutoRefreshStaleReads, getDefaultInlineAttachments, getFetchUnreadBodies, getSyncMaxRequests, getWriteMode, } from '../config.js';
|
|
10
|
+
import { getAllowMarkRead, getConfirmMarkRead, getAttachmentsDir, getAutoRefreshStaleReads, getDefaultInlineAttachments, getFetchUnreadBodies, getSyncMaxRequests, getWriteMode, } from '../config.js';
|
|
11
11
|
import { basename, resolve } from 'node:path';
|
|
12
12
|
import { ApiRecipientSchema, deriveRead, hasRealView, jsonErrorResponse, jsonResponse, jsonText, mapRecipients, notedJsonResponse, postMessageAndRefetch, reportsThreaded, UnconfirmedWriteError, reportsUnthreaded, threadedReplyTo, verifyWriteLanded, withReadState } from './_shared.js';
|
|
13
13
|
import { parseLenient } from '@chrischall/mcp-utils';
|
|
14
14
|
import { pageState } from './pagination.js';
|
|
15
|
-
import { MESSAGE_VIEWS, viewDrafts, viewMessages, viewOne } from './project.js';
|
|
15
|
+
import { MESSAGE_VIEWS, senderOf, viewDrafts, viewMessages, viewOne } from './project.js';
|
|
16
16
|
import { resolveView, viewParam } from '@chrischall/mcp-utils';
|
|
17
|
-
import { nowNaiveWallClock, toNaiveWallClock } from '../timestamps.js';
|
|
17
|
+
import { normalizeTimestampsInValue, nowNaiveWallClock, toNaiveWallClock } from '../timestamps.js';
|
|
18
18
|
import { readingBlockedToday } from '../read-days.js';
|
|
19
19
|
// Schemas for the load-bearing fields of each /pub/v3 response this file
|
|
20
20
|
// reads (issue #83). Loose: unknown keys pass through into cached listData.
|
|
@@ -205,12 +205,116 @@ function unverifiedEmptyResponse(input) {
|
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
/**
|
|
208
|
-
* Whether
|
|
209
|
-
*
|
|
210
|
-
*
|
|
208
|
+
* Whether a BULK path may mark messages read right now without asking (the
|
|
209
|
+
* allowMarkRead probes; sync asks instead — see ofw_sync_messages): the OFW_ALLOW_MARK_READ
|
|
210
|
+
* ceiling, today being a reading day (OFW_READ_DAYS / OFW_NO_READ_DAYS), and
|
|
211
|
+
* OFW_CONFIRM_MARK_READ being off — those paths stamp many messages without
|
|
212
|
+
* looking at any of them, so they have nothing to put in front of the user.
|
|
213
|
+
* With confirmation on, ofw_get_message (which asks) is the one way in. All
|
|
214
|
+
* are deployment settings a per-call argument cannot raise.
|
|
211
215
|
*/
|
|
212
216
|
function markReadPermitted() {
|
|
213
|
-
return getAllowMarkRead() && readingBlockedToday() === null;
|
|
217
|
+
return getAllowMarkRead() && readingBlockedToday() === null && !getConfirmMarkRead();
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Which deployment CEILING (not the confirmation prompt) refuses marking
|
|
221
|
+
* anything read right now, or null when none does. Unlike
|
|
222
|
+
* markReadPermitted(), OFW_CONFIRM_MARK_READ is not a refusal here — it is a
|
|
223
|
+
* question the caller can put to the user.
|
|
224
|
+
*/
|
|
225
|
+
function markReadCeiling() {
|
|
226
|
+
if (!getAllowMarkRead()) {
|
|
227
|
+
return {
|
|
228
|
+
gate: 'OFW_ALLOW_MARK_READ',
|
|
229
|
+
reason: 'This server is configured with OFW_ALLOW_MARK_READ=false, so no tool may mark a message read on OurFamilyWizard. Unread inbox bodies were NOT fetched, and no per-call argument can change that.',
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
const blocked = readingBlockedToday();
|
|
233
|
+
if (blocked !== null) {
|
|
234
|
+
return {
|
|
235
|
+
gate: 'OFW_READ_DAYS',
|
|
236
|
+
reason: 'Today is a no-read day (OFW_READ_DAYS / OFW_NO_READ_DAYS), so no message body was fetched. readingBlocked says when reading resumes.',
|
|
237
|
+
readingBlocked: blocked,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
/** How many unread messages one confirmed sync opens — the prompt must stay readable. */
|
|
243
|
+
export const MAX_SYNC_OPEN_UNREAD = 25;
|
|
244
|
+
/**
|
|
245
|
+
* The cached unread INBOX messages a confirmed sync would open, newest first:
|
|
246
|
+
* no body yet, and `deriveRead` cannot rule out unread — exactly the rows whose
|
|
247
|
+
* detail GET stamps "First Viewed". Read from the cache rather than from the
|
|
248
|
+
* sync's own "new this walk" list, because the confirming call re-runs the sync
|
|
249
|
+
* and finds nothing new — the set must be the same on both phases for the
|
|
250
|
+
* approval to bind to it.
|
|
251
|
+
*/
|
|
252
|
+
async function unreadCandidates(cache) {
|
|
253
|
+
const all = (await cache.listMessages({ folder: 'inbox', page: 1, size: 1000 }))
|
|
254
|
+
.filter((row) => row.body === null && !deriveRead(row));
|
|
255
|
+
return { rows: all.slice(0, MAX_SYNC_OPEN_UNREAD), remaining: Math.max(0, all.length - MAX_SYNC_OPEN_UNREAD) };
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Fetch one unread inbox body and cache it — the request that marks it read.
|
|
259
|
+
* Only ever called after the confirmation gate approved this exact message.
|
|
260
|
+
*/
|
|
261
|
+
async function openUnreadBody(client, cache, cached) {
|
|
262
|
+
const detail = parseLenient(MessageDetailSchema, await client.request('GET', `/pub/v3/messages/${cached.id}`), { label: 'ofw-mcp', context: 'GET /pub/v3/messages/{id} (sync, confirmed mark-read)' });
|
|
263
|
+
await cache.upsertMessage({
|
|
264
|
+
...cached,
|
|
265
|
+
recipients: detail.recipients ? mapRecipients(detail.recipients) : cached.recipients,
|
|
266
|
+
body: detail.body ?? '',
|
|
267
|
+
fetchedBodyAt: new Date().toISOString(),
|
|
268
|
+
});
|
|
269
|
+
if (Array.isArray(detail.files) && detail.files.length > 0) {
|
|
270
|
+
await fetchAttachmentMetaForMessage(client, cached.id, detail.files, cache);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* OFW_CONFIRM_MARK_READ: before `ofw_get_message` fetches a body that would
|
|
275
|
+
* mark an unread inbox message read, show the user which message it is and
|
|
276
|
+
* ask. Called only after markReadVerdict let the fetch through, so the
|
|
277
|
+
* OFW_ALLOW_MARK_READ ceiling and allowMarkRead:false have already refused.
|
|
278
|
+
*
|
|
279
|
+
* Returns undefined to proceed with the fetch, otherwise the result to return.
|
|
280
|
+
*/
|
|
281
|
+
async function confirmMarkRead(ctx, cached, args) {
|
|
282
|
+
if (!getConfirmMarkRead())
|
|
283
|
+
return undefined;
|
|
284
|
+
// Same "would this stamp?" rule as markReadVerdict: a sent or already-read
|
|
285
|
+
// message changes nothing on OFW, so there is nothing to ask about.
|
|
286
|
+
if (cached !== null && !(cached.folder === 'inbox' && !deriveRead(cached)))
|
|
287
|
+
return undefined;
|
|
288
|
+
if (cached === null) {
|
|
289
|
+
// Nothing to show: the subject and time live only behind the request that
|
|
290
|
+
// would stamp it. A prompt reading "open message 123?" is not a choice.
|
|
291
|
+
return jsonErrorResponse({
|
|
292
|
+
error: 'MARK_READ_CONFIRMATION_UNAVAILABLE',
|
|
293
|
+
messageId: Number(args.messageId),
|
|
294
|
+
reason: 'This server asks before opening an unread message (OFW_CONFIRM_MARK_READ), but this id is not in the cache, so there is no subject or time to show — and fetching them is the request that would mark it read.',
|
|
295
|
+
hint: 'Run ofw_sync_messages first: it walks list pages, not bodies, so it learns the subject and sent time without marking anything read. Then call ofw_get_message again.',
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
// The preview never passes through jsonResponse, so normalize here: sentAt
|
|
299
|
+
// gains its explicit offset and a weekday-first sentAtDisplay.
|
|
300
|
+
const when = normalizeTimestampsInValue({ sentAt: cached.sentAt });
|
|
301
|
+
return confirmWrite(ctx, {
|
|
302
|
+
args,
|
|
303
|
+
tool: 'ofw_get_message',
|
|
304
|
+
action: 'ofw.message.mark_read',
|
|
305
|
+
message: `Open this unread OurFamilyWizard message and mark it read? "${cached.subject}" — ${when.sentAtDisplay ?? cached.sentAt}. Opening it stamps a "First Viewed" time your co-parent can see; that cannot be undone.`,
|
|
306
|
+
target: `message:${cached.id}`,
|
|
307
|
+
payload: { messageId: cached.id, markRead: true },
|
|
308
|
+
preview: {
|
|
309
|
+
action: 'Open unread OurFamilyWizard message (marks it READ)',
|
|
310
|
+
warning: 'Opening this message marks it read on OurFamilyWizard and stamps a "First Viewed" time your co-parent can see. It is part of the record and cannot be undone.',
|
|
311
|
+
messageId: cached.id,
|
|
312
|
+
subject: cached.subject,
|
|
313
|
+
from: senderOf(cached),
|
|
314
|
+
...when,
|
|
315
|
+
},
|
|
316
|
+
confirmToken: args.confirmToken,
|
|
317
|
+
});
|
|
214
318
|
}
|
|
215
319
|
/**
|
|
216
320
|
* A message row with its content removed, for a no-read day. The body goes,
|
|
@@ -469,7 +573,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
469
573
|
return jsonResponse(payload);
|
|
470
574
|
});
|
|
471
575
|
server.registerTool('ofw_get_message', {
|
|
472
|
-
description: 'Get a single OurFamilyWizard message OR draft by ID. Reads from local cache when available; otherwise fetches from OFW — and for an UNREAD INBOX message that fetch marks it read and stamps a "First Viewed" time the co-parent can see, which is part of the record and cannot be undone. Pass allowMarkRead:false to refuse such a fetch instead (cached bodies, sent messages and already-read messages are unaffected, because none of them stamp anything). For ids that match a draft (in the drafts cache), the response carries folder="drafts" and the body/subject/recipients reflect the drafts cache (which ofw_sync_messages keeps fresh) — drafts have no `fromUser`, and `sentAt`/`fetchedBodyAt` mirror the draft\'s `modifiedAt`. For inbox/sent messages, folder is "inbox" or "sent" as before. On a server-configured no-read day (OFW_READ_DAYS / OFW_NO_READ_DAYS) inbox/sent bodies are withheld (body:null, bodyWithheld:true, readingBlocked says when reading resumes) and OFW is never contacted.',
|
|
576
|
+
description: 'Get a single OurFamilyWizard message OR draft by ID. Reads from local cache when available; otherwise fetches from OFW — and for an UNREAD INBOX message that fetch marks it read and stamps a "First Viewed" time the co-parent can see, which is part of the record and cannot be undone. Pass allowMarkRead:false to refuse such a fetch instead (cached bodies, sent messages and already-read messages are unaffected, because none of them stamp anything). For ids that match a draft (in the drafts cache), the response carries folder="drafts" and the body/subject/recipients reflect the drafts cache (which ofw_sync_messages keeps fresh) — drafts have no `fromUser`, and `sentAt`/`fetchedBodyAt` mirror the draft\'s `modifiedAt`. For inbox/sent messages, folder is "inbox" or "sent" as before. On a server-configured no-read day (OFW_READ_DAYS / OFW_NO_READ_DAYS) inbox/sent bodies are withheld (body:null, bodyWithheld:true, readingBlocked says when reading resumes) and OFW is never contacted. When the server runs with OFW_CONFIRM_MARK_READ=true, opening an unread inbox message first shows its subject, sender and sent time and asks the user to confirm marking it read: a confirmation prompt where the client supports one; otherwise the first call fetches NOTHING and returns that preview plus a confirmToken, and only a repeat call with that token opens the message (see MCP_CONFIRM_MODE). Show the user the preview and wait for their yes before repeating the call.',
|
|
473
577
|
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
474
578
|
inputSchema: z.object({
|
|
475
579
|
messageId: z.string().describe('Message ID (also accepts draft IDs — drafts are routed via the drafts cache)'),
|
|
@@ -477,8 +581,9 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
477
581
|
view: viewParam(MESSAGE_VIEWS, {
|
|
478
582
|
note: 'compact omits OurFamilyWizard\'s raw `listData` echo, which duplicates this record\'s own id, subject, sentAt, recipients and read flag; the sender is promoted to `from`, and `files`/`replied` are kept. Pass "full" for the echo.',
|
|
479
583
|
}),
|
|
584
|
+
confirmToken: confirmTokenParam,
|
|
480
585
|
}),
|
|
481
|
-
}, async (args) => {
|
|
586
|
+
}, async (args, ctx) => {
|
|
482
587
|
const id = Number(args.messageId);
|
|
483
588
|
const view = resolveView(args.view, MESSAGE_VIEWS);
|
|
484
589
|
const cache = cacheProvider();
|
|
@@ -615,6 +720,9 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
615
720
|
const markReadCheck = markReadVerdict(cached, args.allowMarkRead);
|
|
616
721
|
if (markReadCheck !== null)
|
|
617
722
|
return markReadCheck;
|
|
723
|
+
const confirmGate = await confirmMarkRead(ctx, cached, args);
|
|
724
|
+
if (confirmGate)
|
|
725
|
+
return confirmGate;
|
|
618
726
|
const detail = parseLenient(MessageDetailSchema, await client.request('GET', `/pub/v3/messages/${encodeURIComponent(args.messageId)}`), { label: 'ofw-mcp', context: 'GET /pub/v3/messages/{id} (ofw_get_message)' });
|
|
619
727
|
// Derive the folder for a live-fetched message. A cached row (reached here
|
|
620
728
|
// only when its body was NULL) already knows its folder, so keep it.
|
|
@@ -1716,28 +1824,95 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1716
1824
|
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
1717
1825
|
inputSchema: z.object({
|
|
1718
1826
|
folders: z.array(z.enum(['inbox', 'sent', 'drafts'])).min(1).describe('Folders to sync (default: all three). Must be non-empty if given — an empty list would sync nothing while reporting success.').optional(),
|
|
1719
|
-
fetchUnreadBodies: z.boolean().describe('If true, also fetch bodies for unread inbox messages — which marks each one READ on OurFamilyWizard and stamps a co-parent-visible "First Viewed" time that cannot be undone. Defaults to the OFW_FETCH_UNREAD_BODIES env var (false unless set)
|
|
1827
|
+
fetchUnreadBodies: z.boolean().describe('If true, also fetch bodies for unread inbox messages — which marks each one READ on OurFamilyWizard and stamps a co-parent-visible "First Viewed" time that cannot be undone. Defaults to the OFW_FETCH_UNREAD_BODIES env var (false unless set). Applies only when the inbox is among the folders synced. Refused outright when OFW_ALLOW_MARK_READ=false or on a no-read day (the response\'s unreadBodies says which). When the server runs with OFW_CONFIRM_MARK_READ=true, the sync runs WITHOUT marking anything read and then asks the user to confirm opening the listed unread messages (newest ' + MAX_SYNC_OPEN_UNREAD + ' per call): a confirmation prompt where the client supports one; otherwise it returns that list plus a confirmToken, and only a repeat call with that token opens them. Show the user the list and wait for their yes.').optional(),
|
|
1720
1828
|
deep: z.boolean().describe('If true, walk every OFW page until empty regardless of cache state. Use to backfill gaps. Default false.').optional(),
|
|
1721
1829
|
maxRequests: z.number().int().min(1).describe('Maximum OFW requests this single call may make before pausing. When hit, the response reports done:false — call again with the same arguments to continue. Omit to use the server default (OFW_SYNC_MAX_REQUESTS, or unbounded on local installs).').optional(),
|
|
1830
|
+
confirmToken: confirmTokenParam,
|
|
1722
1831
|
}),
|
|
1723
|
-
}, async (args) => {
|
|
1832
|
+
}, async (args, ctx) => {
|
|
1724
1833
|
const cache = cacheProvider();
|
|
1834
|
+
// Default from OFW_FETCH_UNREAD_BODIES (false unless set). Fetching those
|
|
1835
|
+
// bodies is exactly what stamps a First Viewed time on every unread
|
|
1836
|
+
// message it touches, so two gates stand in front of it:
|
|
1837
|
+
// 1. the CEILINGS — OFW_ALLOW_MARK_READ=false and a no-read day — refuse
|
|
1838
|
+
// outright, and the response says which one refused;
|
|
1839
|
+
// 2. OFW_CONFIRM_MARK_READ asks the user, naming every message it would
|
|
1840
|
+
// open, before a single one is fetched.
|
|
1841
|
+
// Only an INBOX sync can have unread bodies to fetch — sent messages carry
|
|
1842
|
+
// no read state of ours. A sent/drafts-only call has nothing to ask about,
|
|
1843
|
+
// and a prompt to open inbox messages there is one the caller never invited.
|
|
1844
|
+
const syncsInbox = (args.folders ?? ['inbox']).includes('inbox');
|
|
1845
|
+
const requested = syncsInbox && (args.fetchUnreadBodies ?? getFetchUnreadBodies());
|
|
1846
|
+
const ceiling = requested ? markReadCeiling() : null;
|
|
1847
|
+
const askFirst = requested && ceiling === null && getConfirmMarkRead();
|
|
1725
1848
|
const result = await syncAll(client, {
|
|
1726
1849
|
folders: args.folders,
|
|
1727
|
-
//
|
|
1728
|
-
// the
|
|
1729
|
-
|
|
1730
|
-
fetchUnreadBodies: markReadPermitted() && (args.fetchUnreadBodies ?? getFetchUnreadBodies()),
|
|
1850
|
+
// Under confirmation the sync itself never stamps: it walks list pages
|
|
1851
|
+
// only, and the approved bodies are opened below, one by one.
|
|
1852
|
+
fetchUnreadBodies: requested && ceiling === null && !askFirst,
|
|
1731
1853
|
deep: args.deep,
|
|
1732
1854
|
maxRequests: args.maxRequests ?? getSyncMaxRequests(),
|
|
1733
1855
|
}, cache);
|
|
1856
|
+
let unreadBodies;
|
|
1857
|
+
if (ceiling !== null) {
|
|
1858
|
+
unreadBodies = { requested: true, fetched: false, ...ceiling };
|
|
1859
|
+
}
|
|
1860
|
+
else if (askFirst) {
|
|
1861
|
+
const { rows, remaining } = await unreadCandidates(cache);
|
|
1862
|
+
if (rows.length > 0) {
|
|
1863
|
+
const messages = rows.map((row) => ({
|
|
1864
|
+
messageId: row.id,
|
|
1865
|
+
subject: row.subject,
|
|
1866
|
+
from: senderOf(row),
|
|
1867
|
+
// The preview never passes through jsonResponse, so normalize here.
|
|
1868
|
+
...normalizeTimestampsInValue({ sentAt: row.sentAt }),
|
|
1869
|
+
}));
|
|
1870
|
+
const lines = messages.map((m) => `"${m.subject}" — ${String(m.sentAtDisplay ?? m.sentAt)}`);
|
|
1871
|
+
const gate = await confirmWrite(ctx, {
|
|
1872
|
+
args,
|
|
1873
|
+
tool: 'ofw_sync_messages',
|
|
1874
|
+
action: 'ofw.message.mark_read',
|
|
1875
|
+
message: `Open ${rows.length} unread OurFamilyWizard message${rows.length === 1 ? '' : 's'} and mark ${rows.length === 1 ? 'it' : 'them'} read? ${lines.join('; ')}.${remaining > 0 ? ` (Older unread messages not listed here: ${remaining}; they wait for the next sync.)` : ''} Opening stamps a "First Viewed" time your co-parent can see; that cannot be undone.`,
|
|
1876
|
+
target: 'messages:unread-inbox',
|
|
1877
|
+
// The approval binds to THIS set: a message arriving (or being read
|
|
1878
|
+
// elsewhere) between the preview and the confirming call changes
|
|
1879
|
+
// the revision, and the stale approval is refused.
|
|
1880
|
+
revision: rows.map((row) => row.id).join(','),
|
|
1881
|
+
payload: { messageIds: rows.map((row) => row.id), markRead: true },
|
|
1882
|
+
preview: {
|
|
1883
|
+
action: `Open ${rows.length} unread OurFamilyWizard message${rows.length === 1 ? '' : 's'} (marks ${rows.length === 1 ? 'it' : 'them'} READ)`,
|
|
1884
|
+
warning: 'Opening these messages marks each one read on OurFamilyWizard and stamps a "First Viewed" time your co-parent can see. It is part of the record and cannot be undone. The sync itself already ran and marked nothing read.',
|
|
1885
|
+
messages,
|
|
1886
|
+
...(remaining > 0 ? { remaining } : {}),
|
|
1887
|
+
},
|
|
1888
|
+
confirmToken: args.confirmToken,
|
|
1889
|
+
});
|
|
1890
|
+
if (gate)
|
|
1891
|
+
return gate;
|
|
1892
|
+
for (const row of rows)
|
|
1893
|
+
await openUnreadBody(client, cache, row);
|
|
1894
|
+
}
|
|
1895
|
+
const opened = new Set(rows.map((row) => row.id));
|
|
1896
|
+
const before = result.unreadInbox.length;
|
|
1897
|
+
result.unreadInbox = result.unreadInbox.filter((hint) => !opened.has(hint.id));
|
|
1898
|
+
if (result.unreadInbox.length !== before) {
|
|
1899
|
+
// Keep the note in step with unreadInbox: one payload, one count.
|
|
1900
|
+
// syncAll always writes a note when it reports unread hints, and the
|
|
1901
|
+
// count only moved because there were some, so the note is present.
|
|
1902
|
+
const notes = result.note.split('\n\n').filter((n) => n !== unreadInboxNote(before));
|
|
1903
|
+
if (result.unreadInbox.length > 0)
|
|
1904
|
+
notes.push(unreadInboxNote(result.unreadInbox.length));
|
|
1905
|
+
result.note = notes.length > 0 ? notes.join('\n\n') : undefined;
|
|
1906
|
+
}
|
|
1907
|
+
unreadBodies = { requested: true, fetched: true, opened: [...opened], ...(remaining > 0 ? { remaining } : {}) };
|
|
1908
|
+
}
|
|
1734
1909
|
// Freshness of the cache AS OF this sync completing — so a paused call
|
|
1735
1910
|
// that skipped a folder says so here too, not just in `notRefreshed`.
|
|
1736
1911
|
const freshness = await buildFreshness(cache, {
|
|
1737
1912
|
source: 'cache',
|
|
1738
1913
|
folders: args.folders ?? ['inbox', 'sent', 'drafts'],
|
|
1739
1914
|
});
|
|
1740
|
-
return jsonResponse({ ...result, freshness });
|
|
1915
|
+
return jsonResponse({ ...result, ...(unreadBodies ? { unreadBodies } : {}), freshness });
|
|
1741
1916
|
});
|
|
1742
1917
|
server.registerTool('ofw_check_freshness', {
|
|
1743
1918
|
// Not read-only, and destructive: allowMarkRead:true probes unread inbox
|
package/dist/tools/project.js
CHANGED
|
@@ -45,7 +45,7 @@ function asRecord(value) {
|
|
|
45
45
|
* it would have taken the sender's name off every message, and compact is
|
|
46
46
|
* where a field that has never worked starts working.
|
|
47
47
|
*/
|
|
48
|
-
function senderOf(row) {
|
|
48
|
+
export function senderOf(row) {
|
|
49
49
|
if (typeof row.fromUser === 'string' && row.fromUser !== '')
|
|
50
50
|
return row.fromUser;
|
|
51
51
|
const author = asRecord(asRecord(row.listData)?.author);
|
package/dist/version.js
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
// package.json drift. Importing these instead of package.json keeps the whole
|
|
5
5
|
// manifest — npm scripts included — out of dist/bundle.js.
|
|
6
6
|
export const SERVER_NAME = 'ofw-mcp';
|
|
7
|
-
export const VERSION = '2.
|
|
7
|
+
export const VERSION = '2.25.0'; // x-release-please-version
|
package/mint.yaml
CHANGED
|
@@ -78,6 +78,13 @@ env:
|
|
|
78
78
|
on OurFamilyWizard - reading a body for the first time stamps a
|
|
79
79
|
co-parent-visible "First Viewed" time that cannot be undone. A ceiling: no
|
|
80
80
|
per-call argument can raise it.
|
|
81
|
+
- name: OFW_CONFIRM_MARK_READ
|
|
82
|
+
required: false
|
|
83
|
+
help: >-
|
|
84
|
+
Default "false". Set "true" to show an unread message's subject, sender
|
|
85
|
+
and sent time and ask for confirmation before opening it marks it read on
|
|
86
|
+
OurFamilyWizard. Also disables the bulk mark-read paths (sync
|
|
87
|
+
fetchUnreadBodies, allowMarkRead probes), which cannot ask per message.
|
|
81
88
|
- name: OFW_FETCH_UNREAD_BODIES
|
|
82
89
|
required: false
|
|
83
90
|
help: >-
|
package/package.json
CHANGED
package/server.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"url": "https://github.com/chrischall/ofw-mcp",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "2.
|
|
9
|
+
"version": "2.25.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "ofw-mcp",
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.25.0",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|
|
@@ -47,6 +47,12 @@
|
|
|
47
47
|
"isRequired": false,
|
|
48
48
|
"format": "string"
|
|
49
49
|
},
|
|
50
|
+
{
|
|
51
|
+
"name": "OFW_CONFIRM_MARK_READ",
|
|
52
|
+
"description": "Default \"false\". Set \"true\" to show an unread message's subject, sender and sent time and ask for confirmation before opening it marks it read. Sync fetchUnreadBodies asks too; allowMarkRead probes are disabled.",
|
|
53
|
+
"isRequired": false,
|
|
54
|
+
"format": "string"
|
|
55
|
+
},
|
|
50
56
|
{
|
|
51
57
|
"name": "OFW_FETCH_UNREAD_BODIES",
|
|
52
58
|
"description": "Default \"false\". Whether ofw_sync_messages fetches unread inbox bodies by default (each fetch stamps a First Viewed time). Capped by OFW_ALLOW_MARK_READ.",
|
package/skills/ofw/SKILL.md
CHANGED
|
@@ -90,10 +90,10 @@ Always pass `--config ~/.mcporter/mcporter.json` unless a local `config/mcporter
|
|
|
90
90
|
### Messages
|
|
91
91
|
| Tool | Notes |
|
|
92
92
|
|------|-------|
|
|
93
|
-
| `ofw_sync_messages(folders?, deep?, fetchUnreadBodies?)` | Sync OFW → local cache. **Call first if the cache might be stale.** Returns unread inbox hints (bodies not fetched, to avoid mark-as-read). |
|
|
93
|
+
| `ofw_sync_messages(folders?, deep?, fetchUnreadBodies?)` | Sync OFW → local cache. **Call first if the cache might be stale.** Returns unread inbox hints (bodies not fetched, to avoid mark-as-read). With `fetchUnreadBodies` it may instead return a confirmation preview listing the unread messages it would open (server `OFW_CONFIRM_MARK_READ`): show the user that list and repeat with the `confirmToken` only on their yes. `unreadBodies.gate` names a server ceiling that refused. |
|
|
94
94
|
| `ofw_list_message_folders` | List OFW folders with unread counts. Most reads use the cache; this is mainly for folder IDs and live unread counts. |
|
|
95
95
|
| `ofw_list_messages(folderId?, since?, until?, q?, sort?, page?, size?, autoRefresh?, view?)` | Cache-backed list. Supports folder ("inbox"/"sent"/"both"), date range, and substring search. `sort:"oldest"` starts at the old end of a range instead of paging to it (default `"newest"`). Returns `complete` for the RESULT SET plus **`nextPage`** (null when done) — and the paging keys come FIRST in the JSON, before `messages`. `returned` carries the record count as a scalar, beside `total`. An **empty** result from a non-fresh cache is refused (`UNVERIFIED_EMPTY`) — pass `autoRefresh:true` to sync and answer instead. |
|
|
96
|
-
| `ofw_get_message(messageId, allowMarkRead?, view?)` | Read a message OR draft body. Cache-first. Ids in the drafts cache return `folder: "drafts"`. ⚠️ Falls through to OFW for unread inbox messages, which marks them read AND stamps a "First Viewed" time the co-parent can see — irreversible. Pass `allowMarkRead:false` to refuse that fetch instead; cached, sent and already-read messages are unaffected. On a server-configured no-read day (`readingBlocked` / `READING_BLOCKED` in the response) the body is withheld (`bodyWithheld: true`) — report the sender, date and subject, say when `nextReadableDay` is, and do not try to work around it. |
|
|
96
|
+
| `ofw_get_message(messageId, allowMarkRead?, view?)` | Read a message OR draft body. Cache-first. Ids in the drafts cache return `folder: "drafts"`. ⚠️ Falls through to OFW for unread inbox messages, which marks them read AND stamps a "First Viewed" time the co-parent can see — irreversible. Pass `allowMarkRead:false` to refuse that fetch instead; cached, sent and already-read messages are unaffected. If the server runs with `OFW_CONFIRM_MARK_READ`, the first call returns a preview (subject, sender, sent time) instead of the body: show it to the user and repeat the call with its `confirmToken` only after they say yes. On a server-configured no-read day (`readingBlocked` / `READING_BLOCKED` in the response) the body is withheld (`bodyWithheld: true`) — report the sender, date and subject, say when `nextReadableDay` is, and do not try to work around it. |
|
|
97
97
|
| `ofw_send_message(draftId?, subject?, body?, recipientIds?, replyToId?, expectedRevision?, deleteDraftOnSuccess?, myFileIDs?, force?)` | Send a message — **the one irreversible operation**. Preferred path: pass `draftId` (+ `expectedRevision`) to send an existing draft **as it exists on the server** — the tool re-reads it from OFW first and refuses if it changed since you read it (or was already sent/deleted); `subject`/`body` become optional overrides. `recipientIds` is usually still required: OFW does not store recipients on drafts. After a **confirmed** send the draft is auto-deleted (`deleteDraftOnSuccess:false` to keep it); on any failure or ambiguity it is retained and the response says why (`draftRetained`). Response leads with `sentMessageId`, `draftKey`, `threaded`, `draftDeleted`. Compose from scratch by passing `subject`/`body`/`recipientIds` with no `draftId`. |
|
|
98
98
|
| `ofw_get_unread_sent(page?, size?, autoRefresh?)` | Sent messages your co-parent hasn't read yet (from cache). Leads with `complete`/`hasMore`/`nextPage`, then `scanned`/`total`, then `unread`; an empty sent cache that is not fresh is refused rather than reported as "nothing sent". |
|
|
99
99
|
| `ofw_list_drafts(page?, size?, verify?, autoRefresh?, view?)` | Leads with `complete`/`hasMore`/`nextPage`; `drafts` comes last. List saved drafts, **auto-verified**: when the cache is not verified-fresh a cheap drafts sync runs first (default `verify:true`), so one call answers server-confirmed. `verify:false` serves straight from cache. Each draft carries `serverConfirmed`, `revision` and `draftKey`. Returns `complete` — **check it before saying "you have N drafts"**. See [Freshness](#freshness). |
|