ofw-mcp 2.27.4 → 2.27.5
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/dist/bundle.js +697 -615
- package/dist/sync.js +26 -7
- package/dist/tools/_shared.js +29 -0
- package/dist/tools/draft-freshness.js +11 -5
- package/dist/tools/lifecycle.js +4 -1
- package/dist/tools/messages.js +51 -15
- package/dist/tools/project.js +40 -0
- package/dist/tools/reply-source.js +28 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/ofw/SKILL.md +15 -0
package/dist/sync.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { clearHeldFiles, getHeldFiles, setHeldFiles } from './tools/held-attachments.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { ApiRecipientSchema, hasRealView, mapRecipients, scrapeSaysRead
|
|
3
|
+
import { ApiRecipientSchema, draftReplyTarget, hasRealView, mapRecipients, scrapeSaysRead } from './tools/_shared.js';
|
|
4
|
+
import { setReplyToSource } from './tools/reply-source.js';
|
|
4
5
|
import { senderOf } from './tools/project.js';
|
|
5
6
|
import { parseLenient } from '@chrischall/mcp-utils';
|
|
6
7
|
import { displayTimeZone, nowNaiveWallClock, parseTimestampValue } from './timestamps.js';
|
|
@@ -470,6 +471,14 @@ const DraftListResponseSchema = z.looseObject({ data: z.array(DraftListItemSchem
|
|
|
470
471
|
const DraftDetailSchema = z.looseObject({
|
|
471
472
|
body: z.string().optional(),
|
|
472
473
|
subject: z.string().optional(),
|
|
474
|
+
// The reply linkage and recipients are read from the DETAIL, not the list
|
|
475
|
+
// item: the drafts list carries no replyToId/inReplyTo/showContext key at all
|
|
476
|
+
// (verified live 2026-11-08), so a row built from it hashed to a different
|
|
477
|
+
// revision than the save echo and lost the reply target.
|
|
478
|
+
replyToId: z.number().nullable().optional(),
|
|
479
|
+
inReplyTo: z.number().nullable().optional(),
|
|
480
|
+
showContext: z.boolean().optional(),
|
|
481
|
+
recipients: z.array(ApiRecipientSchema).optional(),
|
|
473
482
|
});
|
|
474
483
|
/**
|
|
475
484
|
* Meta key holding whether the drafts cache has been compared against OFW.
|
|
@@ -594,26 +603,36 @@ export async function syncDrafts(client, draftsFolderId, store, budget) {
|
|
|
594
603
|
// Fetch every draft's detail up front, still buffered. OFW's list
|
|
595
604
|
// `date.dateTime` is NOT a reliable modification timestamp for drafts —
|
|
596
605
|
// direct UI edits don't bump it — so we can't skip the detail fetch.
|
|
606
|
+
//
|
|
607
|
+
// Pre-sync state (S1 batch read) — for the synced-count comparison below,
|
|
608
|
+
// and as the reply-target fallback when a payload does not echo the linkage.
|
|
609
|
+
const ids = items.map((it) => it.id);
|
|
610
|
+
const existingById = new Map((await store.getDrafts(ids)).map((d) => [d.id, d]));
|
|
597
611
|
const rows = [];
|
|
612
|
+
const replySources = [];
|
|
598
613
|
for (const item of items) {
|
|
599
614
|
if (!b.take())
|
|
600
615
|
return defer();
|
|
601
616
|
const detail = parseLenient(DraftDetailSchema, await client.request('GET', `/pub/v3/messages/${item.id}`), { label: 'ofw-mcp', context: 'GET /pub/v3/messages/{id} (drafts sync)' });
|
|
617
|
+
// The same rule ofw_save_draft and the freshness snapshot apply
|
|
618
|
+
// (draftReplyTarget), so the revision a read reports matches the one the
|
|
619
|
+
// save returned for the same server state.
|
|
620
|
+
const reply = draftReplyTarget([detail, item], existingById.get(item.id)?.replyToId ?? null);
|
|
602
621
|
rows.push({
|
|
603
622
|
id: item.id,
|
|
604
623
|
subject: detail.subject ?? item.subject ?? '(no subject)',
|
|
605
624
|
body: detail.body ?? '',
|
|
606
|
-
recipients: mapRecipients(item.recipients),
|
|
607
|
-
replyToId:
|
|
625
|
+
recipients: mapRecipients(detail.recipients ?? item.recipients),
|
|
626
|
+
replyToId: reply.replyToId,
|
|
608
627
|
modifiedAt: item.date?.dateTime ?? nowNaiveWallClock(),
|
|
609
628
|
listData: item,
|
|
610
629
|
});
|
|
630
|
+
replySources.push(reply.replyToSource);
|
|
611
631
|
}
|
|
612
|
-
// Budget funded the whole walk — apply atomically.
|
|
613
|
-
// pre-upsert state for the synced-count comparison and stale-row eviction.
|
|
614
|
-
const ids = items.map((it) => it.id);
|
|
615
|
-
const existingById = new Map((await store.getDrafts(ids)).map((d) => [d.id, d]));
|
|
632
|
+
// Budget funded the whole walk — apply atomically.
|
|
616
633
|
await store.upsertDrafts(rows);
|
|
634
|
+
for (const [i, row] of rows.entries())
|
|
635
|
+
await setReplyToSource(store, row.id, replySources[i]);
|
|
617
636
|
// If a stale `messages` row exists for a draft id (cached by a prior
|
|
618
637
|
// ofw_get_message call before the drafts table knew about this id), evict it.
|
|
619
638
|
// The drafts table is the source of truth for drafts.
|
package/dist/tools/_shared.js
CHANGED
|
@@ -102,6 +102,35 @@ export function hasRealView(recipients) {
|
|
|
102
102
|
export function threadedReplyTo(detail) {
|
|
103
103
|
return detail.replyToId ?? detail.inReplyTo ?? null;
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* The ONE rule for a draft's reply target, used by every path that builds a
|
|
107
|
+
* draft's content (save echo, drafts sync, the freshness snapshot, the
|
|
108
|
+
* destructive-draft guard), so the revision hashed from it cannot depend on
|
|
109
|
+
* which path produced it.
|
|
110
|
+
*
|
|
111
|
+
* The first echo that names a target wins (`server`). When none does, the
|
|
112
|
+
* `fallback` (the cached row's target, or the one just posted) is kept as
|
|
113
|
+
* `cache` — unless an echo POSITIVELY reports the draft unthreaded
|
|
114
|
+
* ({@link reportsUnthreaded}), in which case OFW's answer stands and nothing
|
|
115
|
+
* is resurrected.
|
|
116
|
+
*
|
|
117
|
+
* Why the fallback exists: the drafts LIST payload carries no `replyToId`,
|
|
118
|
+
* `inReplyTo` or `showContext` key at all (verified live 2026-11-08), so a
|
|
119
|
+
* cached row built from it read `replyToId: null` for a draft whose detail said
|
|
120
|
+
* `inReplyTo: 574607114` — and its revision disagreed with the one the save
|
|
121
|
+
* returned. Silence about the linkage is not evidence it is gone.
|
|
122
|
+
*/
|
|
123
|
+
export function draftReplyTarget(echoes, fallback) {
|
|
124
|
+
for (const echo of echoes) {
|
|
125
|
+
const target = threadedReplyTo(echo);
|
|
126
|
+
if (target !== null)
|
|
127
|
+
return { replyToId: target, replyToSource: 'server' };
|
|
128
|
+
}
|
|
129
|
+
if (fallback !== null && !echoes.some(reportsUnthreaded)) {
|
|
130
|
+
return { replyToId: fallback, replyToSource: 'cache' };
|
|
131
|
+
}
|
|
132
|
+
return { replyToId: null, replyToSource: null };
|
|
133
|
+
}
|
|
105
134
|
/** True when the payload positively reports the message as threaded. */
|
|
106
135
|
export function reportsThreaded(detail) {
|
|
107
136
|
return threadedReplyTo(detail) !== null || detail.showContext === true;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { parseLenient } from '@chrischall/mcp-utils';
|
|
3
|
-
import { ApiRecipientSchema,
|
|
3
|
+
import { ApiRecipientSchema, draftReplyTarget, mapRecipients } from './_shared.js';
|
|
4
4
|
/** Thrown when the freshness check itself could not be completed. */
|
|
5
5
|
export class DraftFreshnessError extends Error {
|
|
6
6
|
}
|
|
@@ -52,6 +52,7 @@ const ServerDraftSchema = z.looseObject({
|
|
|
52
52
|
// that disagreed about the same draft.
|
|
53
53
|
replyToId: z.number().nullable().optional(),
|
|
54
54
|
inReplyTo: z.number().nullable().optional(),
|
|
55
|
+
showContext: z.boolean().optional(),
|
|
55
56
|
recipients: z.array(ApiRecipientSchema).optional(),
|
|
56
57
|
// Attachment fileIds — read so send-by-draft carries the draft's
|
|
57
58
|
// attachments onto the sent message (see DraftContent.files).
|
|
@@ -89,7 +90,7 @@ function isNotFound(e) {
|
|
|
89
90
|
* the narrower type (the catch blocks read only `.message`, which every Error
|
|
90
91
|
* carries).
|
|
91
92
|
*/
|
|
92
|
-
export async function fetchMessageSnapshot(client, id) {
|
|
93
|
+
export async function fetchMessageSnapshot(client, id, fallbackReplyTo = null) {
|
|
93
94
|
let raw;
|
|
94
95
|
try {
|
|
95
96
|
raw = await client.request('GET', `/pub/v3/messages/${id}`);
|
|
@@ -109,17 +110,22 @@ export async function fetchMessageSnapshot(client, id) {
|
|
|
109
110
|
context: 'GET /pub/v3/messages/{id} (draft freshness check)',
|
|
110
111
|
mode: 'strict',
|
|
111
112
|
});
|
|
113
|
+
// The same reply-target rule as the save echo and the drafts sync
|
|
114
|
+
// (draftReplyTarget), with the cached target as the fallback, so a detail
|
|
115
|
+
// that does not echo the linkage hashes exactly like the cached row.
|
|
116
|
+
const reply = draftReplyTarget([detail], fallbackReplyTo);
|
|
112
117
|
return {
|
|
113
118
|
content: {
|
|
114
119
|
subject: detail.subject ?? '',
|
|
115
120
|
body: detail.body ?? '',
|
|
116
|
-
replyToId:
|
|
121
|
+
replyToId: reply.replyToId,
|
|
117
122
|
recipients: mapRecipients(detail.recipients),
|
|
118
123
|
...(detail.files !== undefined ? { files: detail.files } : {}),
|
|
119
124
|
},
|
|
120
125
|
folderId: detail.folder?.id === undefined ? null : String(detail.folder.id),
|
|
121
126
|
folderName: detail.folder?.name ?? null,
|
|
122
127
|
dateTime: detail.date?.dateTime ?? null,
|
|
128
|
+
replyToSource: reply.replyToSource,
|
|
123
129
|
};
|
|
124
130
|
}
|
|
125
131
|
/**
|
|
@@ -130,8 +136,8 @@ export async function fetchMessageSnapshot(client, id) {
|
|
|
130
136
|
* the callers in messages.ts abort on ALL of them: a freshness check that could
|
|
131
137
|
* not run must never wave the write through.
|
|
132
138
|
*/
|
|
133
|
-
export async function fetchServerDraft(client, id) {
|
|
134
|
-
return (await fetchMessageSnapshot(client, id))?.content ?? null;
|
|
139
|
+
export async function fetchServerDraft(client, id, fallbackReplyTo = null) {
|
|
140
|
+
return (await fetchMessageSnapshot(client, id, fallbackReplyTo))?.content ?? null;
|
|
135
141
|
}
|
|
136
142
|
/**
|
|
137
143
|
* The fields whose divergence constitutes a REAL conflict — the actual message
|
package/dist/tools/lifecycle.js
CHANGED
|
@@ -210,7 +210,10 @@ async function probeOne(client, prepared, map, draftKey, heldFiles) {
|
|
|
210
210
|
const { id, cachedDraft } = prepared;
|
|
211
211
|
let snapshot;
|
|
212
212
|
try {
|
|
213
|
-
|
|
213
|
+
// The cached target is the fallback for a detail that does not echo the
|
|
214
|
+
// linkage, the same rule the drafts sync applies, so an unchanged draft
|
|
215
|
+
// reports cacheRevision === serverRevision.
|
|
216
|
+
snapshot = await fetchMessageSnapshot(client, id, cachedDraft?.replyToId ?? null);
|
|
214
217
|
}
|
|
215
218
|
catch (e) {
|
|
216
219
|
return {
|
package/dist/tools/messages.js
CHANGED
|
@@ -10,15 +10,20 @@ import { MAX_UPLOAD_BYTES } from './attachments.js';
|
|
|
10
10
|
import { blobStoreFromEnv } from '@chrischall/mcp-utils/export';
|
|
11
11
|
import { blobKeysParam, blobObjectToUpload, checkFileCount, describePending, fileNameFromBlobKey, inlineAttachmentsParam, inlineFileSchema, MAX_FILES_PER_CALL, mintUploadSlot, planAttachments, requireBlobStore, resolveInlineUpload, sha256Hex, uploadPending, uploadSlotRequestSchema, uploadToMyFiles, } from './uploads.js';
|
|
12
12
|
import { clearHeldFiles, getHeldFiles, heldFilesFor, HELD_NOTE, setHeldFiles, uniqueIds } from './held-attachments.js';
|
|
13
|
+
import { replyToSourceField, setReplyToSource } from './reply-source.js';
|
|
13
14
|
import { buildInlineDelivery, MAX_INLINE_BYTES, tryExtract } from './delivery.js';
|
|
14
15
|
import { resolveDownloadMime, resolveSaveDest } from './attachments.js';
|
|
15
16
|
import { getAllowMarkRead, getConfirmMarkRead, getAttachmentsDir, getAutoRefreshStaleReads, getDefaultInlineAttachments, getFetchUnreadBodies, getSyncMaxRequests, getWriteMode, } from '../config.js';
|
|
16
17
|
import { basename, resolve } from 'node:path';
|
|
17
18
|
import { randomUUID } from 'node:crypto';
|
|
18
|
-
import { ApiRecipientSchema, deriveRead, hasRealView, jsonErrorResponse, jsonResponse, jsonText, mapRecipients, notedJsonResponse, postMessageAndRefetch, reportsThreaded, UnconfirmedWriteError, reportsUnthreaded, threadedReplyTo, verifyWriteLanded, withReadState } from './_shared.js';
|
|
19
|
+
import { ApiRecipientSchema, deriveRead, draftReplyTarget, hasRealView, jsonErrorResponse, jsonResponse, jsonText, mapRecipients, notedJsonResponse, postMessageAndRefetch, reportsThreaded, UnconfirmedWriteError, reportsUnthreaded, threadedReplyTo, verifyWriteLanded, withReadState } from './_shared.js';
|
|
19
20
|
import { parseLenient } from '@chrischall/mcp-utils';
|
|
20
21
|
import { pageState } from './pagination.js';
|
|
21
|
-
import { MESSAGE_VIEWS, senderOf, viewDrafts, viewMessages, viewOne } from './project.js';
|
|
22
|
+
import { compactSentMessage, compactWrittenDraft, MESSAGE_VIEWS, senderOf, viewDrafts, viewMessages, viewOne } from './project.js';
|
|
23
|
+
// The `view` note on the two write tools. Their echo is what the caller just
|
|
24
|
+
// wrote, so compact replaces the body with its length + hash rather than
|
|
25
|
+
// repeating it, and drops OFW's raw `listData` echo.
|
|
26
|
+
const WRITE_VIEW_NOTE = 'compact omits OurFamilyWizard\'s raw `listData` echo (which repeats the body, subject, recipients and a date block) and replaces the body you just wrote with `bodyLength` + `bodySha256` (the first 16 hex characters of its SHA-256) to confirm what landed. Pass "full" for both.';
|
|
22
27
|
import { resolveView, viewParam } from '@chrischall/mcp-utils';
|
|
23
28
|
import { displayTimeZone, formatInstant, normalizeTimestampsInValue, nowNaiveWallClock, toNaiveWallClock } from '../timestamps.js';
|
|
24
29
|
import { readingBlockedToday } from '../read-days.js';
|
|
@@ -690,6 +695,9 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
690
695
|
// ofw_delete_draft / ofw_send_message to assert you are acting on
|
|
691
696
|
// THIS version.
|
|
692
697
|
revision: draftRevision(draftRow, held),
|
|
698
|
+
// Whether the reply target is OFW's own echo or this server's record of
|
|
699
|
+
// it (OFW's payload omitted the linkage) — see reply-source.ts.
|
|
700
|
+
...(await replyToSourceField(cache, draftRow.id, draftRow.replyToId)),
|
|
693
701
|
cacheStatus,
|
|
694
702
|
// False = this draft's existence and unsent status are remembered from
|
|
695
703
|
// a cache, not confirmed on OFW. Call ofw_check_freshness before
|
|
@@ -839,6 +847,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
839
847
|
inlineAttachments: inlineAttachmentsParam,
|
|
840
848
|
blobKeys: blobKeysParam,
|
|
841
849
|
confirmToken: confirmTokenParam,
|
|
850
|
+
view: viewParam(MESSAGE_VIEWS, { note: WRITE_VIEW_NOTE }),
|
|
842
851
|
}),
|
|
843
852
|
}, async (args, ctx) => {
|
|
844
853
|
if (args.messageId !== undefined && args.draftId !== undefined && args.messageId !== args.draftId) {
|
|
@@ -1206,7 +1215,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1206
1215
|
previousId: draftRef,
|
|
1207
1216
|
}
|
|
1208
1217
|
: {}),
|
|
1209
|
-
...persisted,
|
|
1218
|
+
...(resolveView(args.view, MESSAGE_VIEWS) === 'full' ? persisted : compactSentMessage(persisted)),
|
|
1210
1219
|
...(attachmentCheck !== null ? { attachments: attachmentCheck } : {}),
|
|
1211
1220
|
...(newFiles.length > 0 ? { attachmentsUploaded: newFiles } : {}),
|
|
1212
1221
|
...(uploadWarnings.length > 0 ? { warnings: uploadWarnings } : {}),
|
|
@@ -1225,7 +1234,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1225
1234
|
};
|
|
1226
1235
|
let server;
|
|
1227
1236
|
try {
|
|
1228
|
-
server = await fetchServerDraft(client, draftId);
|
|
1237
|
+
server = await fetchServerDraft(client, draftId, cachedRow?.replyToId ?? null);
|
|
1229
1238
|
}
|
|
1230
1239
|
catch (e) {
|
|
1231
1240
|
// Anything landing here means the check could not RUN. Most failures
|
|
@@ -1344,8 +1353,9 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1344
1353
|
// compared this cache against OFW.
|
|
1345
1354
|
const held = await heldFilesFor(cache, rows.map((d) => d.id));
|
|
1346
1355
|
const inferred = await inferredDraftKeys(cache, rows.map((d) => d.id));
|
|
1347
|
-
const drafts = rows.map((d) => ({
|
|
1356
|
+
const drafts = await Promise.all(rows.map(async (d) => ({
|
|
1348
1357
|
...d,
|
|
1358
|
+
...(await replyToSourceField(cache, d.id, d.replyToId)),
|
|
1349
1359
|
revision: draftRevision(d, held.get(d.id)),
|
|
1350
1360
|
...(held.get(d.id).length > 0 ? { heldFiles: held.get(d.id) } : {}),
|
|
1351
1361
|
draftKey: keyById.get(d.id) ?? null,
|
|
@@ -1353,7 +1363,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1353
1363
|
cacheStatus,
|
|
1354
1364
|
serverConfirmed,
|
|
1355
1365
|
asOf: freshness.asOf,
|
|
1356
|
-
}));
|
|
1366
|
+
})));
|
|
1357
1367
|
return { drafts, total, freshness, serverConfirmed };
|
|
1358
1368
|
},
|
|
1359
1369
|
});
|
|
@@ -1410,7 +1420,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1410
1420
|
if (allowDrafts)
|
|
1411
1421
|
server.registerTool('ofw_save_draft', {
|
|
1412
1422
|
_meta: familyMeta('change'),
|
|
1413
|
-
description: 'Save a message as a draft in OurFamilyWizard. RECIPIENTS: OurFamilyWizard has not reliably kept recipients on drafts (when the saved draft comes back with none it is noted once, not warned about) — supply recipientIds at send time as well. ATTACHMENTS: OurFamilyWizard does not store files on drafts, so myFileIDs / inlineAttachments / blobKeys are HELD with the draft by this server (carried across edits, de-duplicated; removeFileIDs drops one), shown under attachments.held, folded into `revision`, and attached when the draft is sent with ofw_send_message(draftId). They are not visible on the draft in the OurFamilyWizard web app. IDENTITY: the response leads with `draftKey`, the stable identity that survives editing — key off it, because the `id` changes on EVERY edit (replacing a draft creates a NEW draft and deletes the old one; OFW\'s update-in-place endpoint silently no-ops, so we never use it). Pass messageId to replace an existing draft; the response.id will be the NEW id, and a transparency NOTE documents the swap and which fields were carried over. THREADING: if replyToId is provided, the cache may rewrite it to the latest reply in the thread (note included). The threading verdict is read from OFW\'s full echo (replyToId/inReplyTo/showContext) — a warning appears ONLY when the reply linkage was genuinely dropped or re-targeted, and the
|
|
1423
|
+
description: 'Save a message as a draft in OurFamilyWizard. RECIPIENTS: OurFamilyWizard has not reliably kept recipients on drafts (when the saved draft comes back with none it is noted once, not warned about) — supply recipientIds at send time as well. ATTACHMENTS: OurFamilyWizard does not store files on drafts, so myFileIDs / inlineAttachments / blobKeys are HELD with the draft by this server (carried across edits, de-duplicated; removeFileIDs drops one), shown under attachments.held, folded into `revision`, and attached when the draft is sent with ofw_send_message(draftId). They are not visible on the draft in the OurFamilyWizard web app. IDENTITY: the response leads with `draftKey`, the stable identity that survives editing — key off it, because the `id` changes on EVERY edit (replacing a draft creates a NEW draft and deletes the old one; OFW\'s update-in-place endpoint silently no-ops, so we never use it). Pass messageId to replace an existing draft; the response.id will be the NEW id, and a transparency NOTE documents the swap and which fields were carried over. THREADING: if replyToId is provided, the cache may rewrite it to the latest reply in the thread (note included). The threading verdict is read from OFW\'s full echo (replyToId/inReplyTo/showContext) — a warning appears ONLY when the reply linkage was genuinely dropped or re-targeted. When OFW\'s echo omits the linkage entirely, the posted target is kept and marked replyToSource:"cache". Replacing a draft (messageId) without replyToId keeps the draft\'s own reply target. RESPONSE: compact by default — no listData echo, and the body you wrote is returned as bodyLength + bodySha256; view:"full" returns both. After saving, the tool re-fetches the draft from OFW, and the returned `revision` reflects that authoritative state (so it will match on your next edit). SAFETY: because replacing DESTROYS the old draft rather than merging, passing messageId first re-reads that draft from OFW and REFUSES the write if its subject/body/recipients changed since you read it (drafts edited in the OFW web app do not bump any timestamp, so the local cache can be silently behind). A pure replyToId normalization by OFW is NOT treated as a conflict. The refusal returns the current server body under serverBody — merge your edit into it and retry with expectedRevision.',
|
|
1414
1424
|
// Destructive: with messageId, saving REPLACES the draft by creating a new
|
|
1415
1425
|
// one and deleting the old (OFW has no draft update), so the old draft's
|
|
1416
1426
|
// server content is gone. Not idempotent: every call mints a new draft id.
|
|
@@ -1427,9 +1437,11 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1427
1437
|
blobKeys: blobKeysParam,
|
|
1428
1438
|
expectedRevision: z.string().describe('With messageId: the `revision` you got from ofw_list_drafts/ofw_get_message for that draft. Asserts you are replacing THAT version. If the draft changed on OFW since, the write is refused and the current server body is returned. Omit and the tool compares the server against the local cache instead — omitting never means "overwrite anyway".').optional(),
|
|
1429
1439
|
force: z.boolean().describe('Default false. Overwrite even when the draft changed on OurFamilyWizard since you read it. The discarded server version is echoed back in the response. Only use after showing the user the conflict.').optional(),
|
|
1440
|
+
view: viewParam(MESSAGE_VIEWS, { note: WRITE_VIEW_NOTE }),
|
|
1430
1441
|
}),
|
|
1431
1442
|
}, async (args) => {
|
|
1432
1443
|
const cache = cacheProvider();
|
|
1444
|
+
const view = resolveView(args.view, MESSAGE_VIEWS);
|
|
1433
1445
|
// New attachments are validated before ANYTHING happens, so a bad entry
|
|
1434
1446
|
// fails the call with nothing uploaded and nothing saved.
|
|
1435
1447
|
const blobStore = args.blobKeys?.length ? blobStoreFromEnv() : undefined;
|
|
@@ -1440,6 +1452,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1440
1452
|
let serverFiles;
|
|
1441
1453
|
let priorHeld = [];
|
|
1442
1454
|
let serverRecipientIds;
|
|
1455
|
+
let serverReplyTo = null;
|
|
1443
1456
|
if (args.messageId !== undefined) {
|
|
1444
1457
|
const guard = await guardDestructiveDraftOp({
|
|
1445
1458
|
cache,
|
|
@@ -1458,8 +1471,12 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1458
1471
|
const kept = (guard.server?.recipients ?? []).map((r) => r.userId).filter((id) => id !== 0);
|
|
1459
1472
|
if (kept.length > 0)
|
|
1460
1473
|
serverRecipientIds = [...new Set(kept)];
|
|
1474
|
+
// Likewise the reply target: a replace that names no replyToId keeps the
|
|
1475
|
+
// draft's own thread. Posting without one turned an edit of a reply into
|
|
1476
|
+
// a new top-level conversation.
|
|
1477
|
+
serverReplyTo = guard.server?.replyToId ?? null;
|
|
1461
1478
|
}
|
|
1462
|
-
const requestedReplyTo = args.replyToId ??
|
|
1479
|
+
const requestedReplyTo = args.replyToId ?? serverReplyTo;
|
|
1463
1480
|
let resolvedReplyTo = requestedReplyTo;
|
|
1464
1481
|
let rewriteNote = null;
|
|
1465
1482
|
if (requestedReplyTo !== null) {
|
|
@@ -1502,6 +1519,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1502
1519
|
let verifyNote = null;
|
|
1503
1520
|
let recipientsNote = null;
|
|
1504
1521
|
let newRevision = null;
|
|
1522
|
+
let replyToSource = null;
|
|
1505
1523
|
let onDraft = [];
|
|
1506
1524
|
let held = [];
|
|
1507
1525
|
let draftKey = null;
|
|
@@ -1520,7 +1538,15 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1520
1538
|
// null — reading only `replyToId` fired a false "did not thread" warning
|
|
1521
1539
|
// on nearly every threaded save while the same response's listData
|
|
1522
1540
|
// showed inReplyTo populated.
|
|
1523
|
-
|
|
1541
|
+
//
|
|
1542
|
+
// The shared rule (draftReplyTarget) keeps the posted target when the
|
|
1543
|
+
// detail does not echo the linkage at all, exactly as the drafts sync and
|
|
1544
|
+
// the freshness snapshot do — so the revision returned here is the one
|
|
1545
|
+
// every later read reports. A POSITIVELY unthreaded echo still stores
|
|
1546
|
+
// null (the drop is not masked) and is warned about below.
|
|
1547
|
+
const reply = draftReplyTarget([detail], resolvedReplyTo);
|
|
1548
|
+
const effectiveReplyTo = reply.replyToId;
|
|
1549
|
+
replyToSource = reply.replyToSource;
|
|
1524
1550
|
const storedRecipients = mapRecipients(detail.recipients);
|
|
1525
1551
|
persisted = {
|
|
1526
1552
|
id: newId,
|
|
@@ -1532,6 +1558,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1532
1558
|
listData: detail,
|
|
1533
1559
|
};
|
|
1534
1560
|
await cache.upsertDraft(persisted);
|
|
1561
|
+
await setReplyToSource(cache, newId, replyToSource);
|
|
1535
1562
|
// What OFW actually kept on the draft (in practice none), and what is
|
|
1536
1563
|
// therefore held here for the send.
|
|
1537
1564
|
onDraft = Array.isArray(detail.files) ? detail.files : [];
|
|
@@ -1577,9 +1604,11 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1577
1604
|
// trained callers to skim warnings. The "dropped" warning demands
|
|
1578
1605
|
// POSITIVE evidence (reportsUnthreaded): a bare `replyToId: null` or a
|
|
1579
1606
|
// detail omitting every echo field is "not echoed", never "dropped".
|
|
1580
|
-
// The stored replyToId is
|
|
1581
|
-
//
|
|
1582
|
-
//
|
|
1607
|
+
// The stored replyToId is the server echo, or the posted target when OFW
|
|
1608
|
+
// echoed no linkage at all (replyToSource "cache"). Masking a POSITIVE
|
|
1609
|
+
// drop with intent was Defect 1; filling silence is not, because the
|
|
1610
|
+
// drafts sync and the freshness snapshot apply the same fallback, so the
|
|
1611
|
+
// revision still hashes what the next read reports.
|
|
1583
1612
|
if (resolvedReplyTo !== null && effectiveReplyTo !== resolvedReplyTo && reportsUnthreaded(detail)) {
|
|
1584
1613
|
const rewrittenFrom = requestedReplyTo !== resolvedReplyTo ? ` (rewritten from ${requestedReplyTo})` : '';
|
|
1585
1614
|
warnings.push(`replyToId was requested as ${resolvedReplyTo}${rewrittenFrom} but the saved draft came back with replyToId null — OurFamilyWizard did not thread this draft (its inReplyTo/showContext are empty). The subject and body were saved; only the reply linkage was dropped. If threading matters, verify on ourfamilywizard.com.`);
|
|
@@ -1632,12 +1661,18 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1632
1661
|
// `revision` concurrency token; the volatile `id` is carried further down
|
|
1633
1662
|
// as an implementation detail. `inReplyTo` echoes the effective threading,
|
|
1634
1663
|
// and `warnings` names any requested field that did not land.
|
|
1664
|
+
//
|
|
1665
|
+
// compact (the default) drops the OFW echo (`listData`, which repeats the
|
|
1666
|
+
// body, subject, recipients and an eleven-rendering date block) and the
|
|
1667
|
+
// body itself — the caller just wrote it — leaving its length and hash to
|
|
1668
|
+
// confirm what landed. `view: "full"` keeps both.
|
|
1635
1669
|
const responseObj = persisted !== null
|
|
1636
1670
|
? {
|
|
1637
1671
|
draftKey,
|
|
1638
1672
|
revision: newRevision,
|
|
1639
|
-
...persisted,
|
|
1673
|
+
...(view === 'full' ? persisted : compactWrittenDraft(persisted)),
|
|
1640
1674
|
inReplyTo: persisted.replyToId,
|
|
1675
|
+
...(replyToSource !== null ? { replyToSource } : {}),
|
|
1641
1676
|
previousId: args.messageId ?? null,
|
|
1642
1677
|
cacheStatus: 'fresh',
|
|
1643
1678
|
serverConfirmed: true,
|
|
@@ -2354,7 +2389,7 @@ Up to ${MAX_FILES_PER_CALL} files per call; each must be non-empty and at most 2
|
|
|
2354
2389
|
const keyById = new Map((await cache.getDraftLineageByIds(rows.map((d) => d.id))).map((l) => [l.id, l.draftKey]));
|
|
2355
2390
|
const held = await heldFilesFor(cache, rows.map((d) => d.id));
|
|
2356
2391
|
const inferred = await inferredDraftKeys(cache, rows.map((d) => d.id));
|
|
2357
|
-
drafts = rows.map((d) => ({
|
|
2392
|
+
drafts = await Promise.all(rows.map(async (d) => ({
|
|
2358
2393
|
id: d.id,
|
|
2359
2394
|
draftKey: keyById.get(d.id) ?? null,
|
|
2360
2395
|
...(inferred.has(d.id) ? { draftKeyInferred: true } : {}),
|
|
@@ -2364,8 +2399,9 @@ Up to ${MAX_FILES_PER_CALL} files per call; each must be non-empty and at most 2
|
|
|
2364
2399
|
modifiedAt: d.modifiedAt,
|
|
2365
2400
|
recipients: d.recipients,
|
|
2366
2401
|
replyToId: d.replyToId,
|
|
2402
|
+
...(await replyToSourceField(cache, d.id, d.replyToId)),
|
|
2367
2403
|
cacheStatus,
|
|
2368
|
-
}));
|
|
2404
|
+
})));
|
|
2369
2405
|
if (!inventoryComplete) {
|
|
2370
2406
|
incomplete.push('the drafts folder was not fully verified against OurFamilyWizard on this call (the request budget paused the walk), so this inventory may be missing or misreporting drafts');
|
|
2371
2407
|
}
|
package/dist/tools/project.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { projectOrRaw, pruneUndefined } from '@chrischall/mcp-utils';
|
|
2
3
|
/**
|
|
3
4
|
* The compact projection (`docs` — fleet convention "Response shape", and
|
|
@@ -155,6 +156,45 @@ export function compactDraft(row) {
|
|
|
155
156
|
...omitKnown(rest, DRAFT_ROW_KEYS),
|
|
156
157
|
});
|
|
157
158
|
}
|
|
159
|
+
export function bodyDigest(body) {
|
|
160
|
+
if (body === null)
|
|
161
|
+
return { bodyLength: null, bodySha256: null };
|
|
162
|
+
return { bodyLength: body.length, bodySha256: createHash('sha256').update(body).digest('hex').slice(0, 16) };
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The compact echo of a draft `ofw_save_draft` just wrote. Unlike
|
|
166
|
+
* {@link compactDraft} (a READ, where the body is the payload), the caller
|
|
167
|
+
* already holds this body, so it is replaced by {@link bodyDigest} — and the
|
|
168
|
+
* OFW `listData` echo, which repeats body, subject, recipients and an
|
|
169
|
+
* eleven-rendering date block, is dropped.
|
|
170
|
+
*/
|
|
171
|
+
export function compactWrittenDraft(row) {
|
|
172
|
+
return {
|
|
173
|
+
id: row.id,
|
|
174
|
+
subject: row.subject,
|
|
175
|
+
...bodyDigest(row.body),
|
|
176
|
+
recipients: row.recipients,
|
|
177
|
+
replyToId: row.replyToId,
|
|
178
|
+
modifiedAt: row.modifiedAt,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The compact echo of a message `ofw_send_message` just sent: the body becomes
|
|
183
|
+
* {@link bodyDigest}, and `listData`, `fromUser` (the account holder) and
|
|
184
|
+
* `fetchedBodyAt` (the moment of this very call) are dropped.
|
|
185
|
+
*/
|
|
186
|
+
export function compactSentMessage(row) {
|
|
187
|
+
return {
|
|
188
|
+
id: row.id,
|
|
189
|
+
folder: row.folder,
|
|
190
|
+
subject: row.subject,
|
|
191
|
+
...bodyDigest(row.body),
|
|
192
|
+
sentAt: row.sentAt,
|
|
193
|
+
recipients: row.recipients,
|
|
194
|
+
replyToId: row.replyToId,
|
|
195
|
+
chainRootId: row.chainRootId,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
158
198
|
/**
|
|
159
199
|
* Project a page of messages, or hand it back whole.
|
|
160
200
|
*
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Where each cached draft's reply target came from.
|
|
2
|
+
//
|
|
3
|
+
// The drafts table holds the target itself; this records whether it is
|
|
4
|
+
// OurFamilyWizard's own echo (`server`) or this server's record of it, kept
|
|
5
|
+
// because OFW's payload did not report the linkage (`cache` — see
|
|
6
|
+
// draftReplyTarget in _shared.ts). It lives in the cache's `meta` table, keyed
|
|
7
|
+
// by draft id like the held files, so it needed no schema migration. A row
|
|
8
|
+
// written before this existed has no entry and reads as `server`: every such
|
|
9
|
+
// row's target was taken from an OFW payload.
|
|
10
|
+
const key = (draftId) => `draft_reply_source:${draftId}`;
|
|
11
|
+
/** Record how a draft's reply target was established (null: it has none). */
|
|
12
|
+
export async function setReplyToSource(cache, draftId, source) {
|
|
13
|
+
await cache.setMeta(key(draftId), source ?? '');
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The source of a draft's reply target, or null when it has no target.
|
|
17
|
+
* Anything but an explicit `cache` reads as `server` (see the header).
|
|
18
|
+
*/
|
|
19
|
+
export async function getReplyToSource(cache, draftId, replyToId) {
|
|
20
|
+
if (replyToId === null)
|
|
21
|
+
return null;
|
|
22
|
+
return (await cache.getMeta(key(draftId))) === 'cache' ? 'cache' : 'server';
|
|
23
|
+
}
|
|
24
|
+
/** `{ replyToSource }` for a draft with a reply target, `{}` otherwise. */
|
|
25
|
+
export async function replyToSourceField(cache, draftId, replyToId) {
|
|
26
|
+
const source = await getReplyToSource(cache, draftId, replyToId);
|
|
27
|
+
return source === null ? {} : { replyToSource: source };
|
|
28
|
+
}
|
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.27.
|
|
7
|
+
export const VERSION = '2.27.5'; // x-release-please-version
|
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.27.
|
|
9
|
+
"version": "2.27.5",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "ofw-mcp",
|
|
14
|
-
"version": "2.27.
|
|
14
|
+
"version": "2.27.5",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|
package/skills/ofw/SKILL.md
CHANGED
|
@@ -177,6 +177,21 @@ eight fields per recipient beside the three the row already normalised, and a
|
|
|
177
177
|
- **On a draft, `ofw_get_message` returns `from: null`** — a draft is unsent, so
|
|
178
178
|
there is no sender, and `""` would read as one we failed to find.
|
|
179
179
|
|
|
180
|
+
**The two write tools default to compact too.** `ofw_save_draft` and
|
|
181
|
+
`ofw_send_message` drop the `listData` echo and replace the body you just wrote
|
|
182
|
+
with `bodyLength` + `bodySha256` (the first 16 hex characters of its SHA-256),
|
|
183
|
+
which is enough to confirm what landed. They keep `draftKey`, `id`, `revision`,
|
|
184
|
+
`replyToId`, `recipients`, the attachments block, `modifiedAt`/`sentAt`, notes
|
|
185
|
+
and warnings. `view: "full"` returns the body and the echo.
|
|
186
|
+
|
|
187
|
+
**`replyToSource` says where a draft's reply target came from.** `"server"`
|
|
188
|
+
means OFW reported it. `"cache"` means OFW's payload left the linkage out, so
|
|
189
|
+
the target this server recorded was kept (a payload that *positively* reports
|
|
190
|
+
the draft as unthreaded is never overridden). The target, and the `revision`
|
|
191
|
+
built from it, are the same on every path — save, list, get and
|
|
192
|
+
`ofw_check_freshness` — so a revision from any of them works as
|
|
193
|
+
`expectedRevision`, and sending by `draftId` threads to it.
|
|
194
|
+
|
|
180
195
|
Pass `view: "full"` when you need a field compact dropped — `listData` and
|
|
181
196
|
everything in it. There is deliberately **no `raw` rung**: a message here is
|
|
182
197
|
assembled from a list item, a detail GET and derived fields, so there is no
|