ofw-mcp 2.28.1 → 2.29.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/dist/bundle.js +257 -29
- package/dist/sync.js +14 -9
- package/dist/timestamps.js +4 -0
- package/dist/tools/_shared.js +71 -15
- package/dist/tools/messages.js +37 -17
- package/dist/tools/plain-text.js +211 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/ofw/SKILL.md +5 -3
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
},
|
|
7
7
|
"metadata": {
|
|
8
8
|
"description": "OurFamilyWizard tools for Claude Code",
|
|
9
|
-
"version": "2.
|
|
9
|
+
"version": "2.29.1"
|
|
10
10
|
},
|
|
11
11
|
"plugins": [
|
|
12
12
|
{
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"displayName": "OurFamilyWizard",
|
|
15
15
|
"source": "./",
|
|
16
16
|
"description": "OurFamilyWizard co-parenting tools for Claude — messages, calendar, expenses, and journal via MCP",
|
|
17
|
-
"version": "2.
|
|
17
|
+
"version": "2.29.1",
|
|
18
18
|
"author": {
|
|
19
19
|
"name": "Chris Chall"
|
|
20
20
|
},
|
package/dist/bundle.js
CHANGED
|
@@ -47852,7 +47852,7 @@ function describeTokenlessLogin(record2) {
|
|
|
47852
47852
|
|
|
47853
47853
|
// src/version.ts
|
|
47854
47854
|
var SERVER_NAME = "ofw-mcp";
|
|
47855
|
-
var VERSION = "2.
|
|
47855
|
+
var VERSION = "2.29.1";
|
|
47856
47856
|
|
|
47857
47857
|
// src/auth.ts
|
|
47858
47858
|
function fetchproxyDisabled() {
|
|
@@ -48325,6 +48325,10 @@ var TIMESTAMP_KEYS = /* @__PURE__ */ new Set([
|
|
|
48325
48325
|
// OFW: UTC instants we stamp ourselves.
|
|
48326
48326
|
"fetchedBodyAt",
|
|
48327
48327
|
"fetchedAt",
|
|
48328
|
+
// When the detail behind a recipient's `viewedAt` was read (issue #448).
|
|
48329
|
+
// NOT `viewedPlaceholder`: that is OFW's raw epoch-zero placeholder, kept
|
|
48330
|
+
// verbatim precisely so it can never be rendered as a real time.
|
|
48331
|
+
"viewedAtCheckedAt",
|
|
48328
48332
|
"syncedAt",
|
|
48329
48333
|
"downloadedAt",
|
|
48330
48334
|
"recordedAt",
|
|
@@ -48477,12 +48481,52 @@ var ApiRecipientSchema = external_exports.looseObject({
|
|
|
48477
48481
|
}).optional(),
|
|
48478
48482
|
viewed: external_exports.looseObject({ dateTime: external_exports.string() }).nullable().optional()
|
|
48479
48483
|
});
|
|
48480
|
-
function mapRecipients(items) {
|
|
48484
|
+
function mapRecipients(items, origin) {
|
|
48481
48485
|
return (items ?? []).map((r) => {
|
|
48482
48486
|
const dt = r.viewed?.dateTime;
|
|
48483
|
-
const
|
|
48484
|
-
|
|
48487
|
+
const placeholder = typeof dt === "string" && dt.startsWith("1970-01-01");
|
|
48488
|
+
const viewedAt = typeof dt === "string" && !placeholder ? dt : null;
|
|
48489
|
+
const out = { userId: r.user?.userId ?? r.user?.id ?? 0, name: r.user?.name ?? "", viewedAt };
|
|
48490
|
+
if (origin) {
|
|
48491
|
+
out.viewedAtSource = origin.source;
|
|
48492
|
+
if (origin.source === "detail" && origin.checkedAt !== void 0) out.viewedAtCheckedAt = origin.checkedAt;
|
|
48493
|
+
if (placeholder) out.viewedPlaceholder = dt;
|
|
48494
|
+
}
|
|
48495
|
+
return out;
|
|
48496
|
+
});
|
|
48497
|
+
}
|
|
48498
|
+
function detailRecipients(items, checkedAt) {
|
|
48499
|
+
return items && items.length > 0 ? mapRecipients(items, { source: "detail", checkedAt }) : null;
|
|
48500
|
+
}
|
|
48501
|
+
function sameRecipient(a, b) {
|
|
48502
|
+
if (a.userId !== 0 && b.userId !== 0) return a.userId === b.userId;
|
|
48503
|
+
return a.name !== "" && a.name === b.name;
|
|
48504
|
+
}
|
|
48505
|
+
function mergeRecipients(prior, fresh) {
|
|
48506
|
+
if (fresh === null || fresh.length === 0) return prior ?? [];
|
|
48507
|
+
const priorList = prior ?? [];
|
|
48508
|
+
return fresh.map((r) => {
|
|
48509
|
+
if (hasRealView([r])) return r;
|
|
48510
|
+
const match = priorList.find((p) => sameRecipient(p, r) && hasRealView([p]));
|
|
48511
|
+
if (!match) return r;
|
|
48512
|
+
const carried = { userId: r.userId, name: r.name, viewedAt: match.viewedAt };
|
|
48513
|
+
if (match.viewedAtSource !== void 0) carried.viewedAtSource = match.viewedAtSource;
|
|
48514
|
+
if (match.viewedAtCheckedAt !== void 0) carried.viewedAtCheckedAt = match.viewedAtCheckedAt;
|
|
48515
|
+
return carried;
|
|
48516
|
+
});
|
|
48517
|
+
}
|
|
48518
|
+
function withViewOrigin(row, callStartedAtMs) {
|
|
48519
|
+
const recipients = row.recipients.map((r) => {
|
|
48520
|
+
let viewedAtOrigin;
|
|
48521
|
+
if (r.viewedAtSource === "detail") {
|
|
48522
|
+
const at = r.viewedAtCheckedAt === void 0 ? NaN : Date.parse(r.viewedAtCheckedAt);
|
|
48523
|
+
viewedAtOrigin = at >= callStartedAtMs ? "detail-this-call" : "detail-cached";
|
|
48524
|
+
} else {
|
|
48525
|
+
viewedAtOrigin = r.viewedAtSource ?? "unrecorded";
|
|
48526
|
+
}
|
|
48527
|
+
return { ...r, viewedAtOrigin };
|
|
48485
48528
|
});
|
|
48529
|
+
return { ...row, recipients };
|
|
48486
48530
|
}
|
|
48487
48531
|
function hasRealView(recipients) {
|
|
48488
48532
|
return recipients.some((r) => r.viewedAt !== null && !r.viewedAt.startsWith("1970-01-01"));
|
|
@@ -49129,11 +49173,15 @@ async function walkPages(client2, folder, folderId, opts, store) {
|
|
|
49129
49173
|
"GET /pub/v3/messages/{id} (body backfill)",
|
|
49130
49174
|
false
|
|
49131
49175
|
);
|
|
49176
|
+
const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
49132
49177
|
toUpsert.push({
|
|
49133
49178
|
...existing,
|
|
49134
49179
|
body: detail.body ?? "",
|
|
49135
|
-
fetchedBodyAt:
|
|
49136
|
-
|
|
49180
|
+
fetchedBodyAt: checkedAt,
|
|
49181
|
+
// A detail that omits recipients (or a view time) must not erase
|
|
49182
|
+
// what the cache already recorded — and the LIST's recipients
|
|
49183
|
+
// carry only a placeholder, so they are never a substitute.
|
|
49184
|
+
recipients: mergeRecipients(existing.recipients, detailRecipients(detail.recipients, checkedAt)),
|
|
49137
49185
|
listData: item
|
|
49138
49186
|
});
|
|
49139
49187
|
synced++;
|
|
@@ -49153,7 +49201,8 @@ async function walkPages(client2, folder, folderId, opts, store) {
|
|
|
49153
49201
|
await client2.request("GET", `/pub/v3/messages/${item.id}`),
|
|
49154
49202
|
{ label: "ofw-mcp", context: "GET /pub/v3/messages/{id} (view-status refresh)" }
|
|
49155
49203
|
);
|
|
49156
|
-
|
|
49204
|
+
const recipients = mergeRecipients(existing.recipients, detailRecipients(detail.recipients, (/* @__PURE__ */ new Date()).toISOString()));
|
|
49205
|
+
toUpsert.push({ ...existing, recipients, listData: item });
|
|
49157
49206
|
synced++;
|
|
49158
49207
|
}
|
|
49159
49208
|
continue;
|
|
@@ -49163,14 +49212,14 @@ async function walkPages(client2, folder, folderId, opts, store) {
|
|
|
49163
49212
|
let body = null;
|
|
49164
49213
|
let fetchedBodyAt = null;
|
|
49165
49214
|
let detailFileIds = [];
|
|
49166
|
-
let
|
|
49215
|
+
let detailRecipientsRaw;
|
|
49167
49216
|
const row = {
|
|
49168
49217
|
id: item.id,
|
|
49169
49218
|
folder,
|
|
49170
49219
|
subject: item.subject ?? "(no subject)",
|
|
49171
49220
|
fromUser: item.from?.name ?? "",
|
|
49172
49221
|
sentAt: item.date?.dateTime ?? nowNaiveWallClock(),
|
|
49173
|
-
recipients: mapRecipients(item.recipients),
|
|
49222
|
+
recipients: mapRecipients(item.recipients, { source: "list" }),
|
|
49174
49223
|
body: null,
|
|
49175
49224
|
fetchedBodyAt: null,
|
|
49176
49225
|
replyToId: null,
|
|
@@ -49187,7 +49236,7 @@ async function walkPages(client2, folder, folderId, opts, store) {
|
|
|
49187
49236
|
if (isInboxUnread) opts.onUnreadBodyFetched?.(item.id);
|
|
49188
49237
|
body = detail.body ?? "";
|
|
49189
49238
|
fetchedBodyAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
49190
|
-
|
|
49239
|
+
detailRecipientsRaw = detail.recipients;
|
|
49191
49240
|
if (Array.isArray(detail.files) && detail.files.length > 0) {
|
|
49192
49241
|
detailFileIds = detail.files;
|
|
49193
49242
|
}
|
|
@@ -49212,7 +49261,7 @@ async function walkPages(client2, folder, folderId, opts, store) {
|
|
|
49212
49261
|
});
|
|
49213
49262
|
row.body = body;
|
|
49214
49263
|
row.fetchedBodyAt = fetchedBodyAt;
|
|
49215
|
-
if (
|
|
49264
|
+
if (detailRecipientsRaw) row.recipients = mergeRecipients(row.recipients, detailRecipients(detailRecipientsRaw, fetchedBodyAt));
|
|
49216
49265
|
toUpsert.push(row);
|
|
49217
49266
|
synced++;
|
|
49218
49267
|
if (detailFileIds.length > 0) {
|
|
@@ -51821,6 +51870,174 @@ function withPaginationFirst(input2) {
|
|
|
51821
51870
|
return { ...head, ...body, ...head };
|
|
51822
51871
|
}
|
|
51823
51872
|
|
|
51873
|
+
// src/tools/plain-text.ts
|
|
51874
|
+
var CHANGE_ORDER = [
|
|
51875
|
+
"headings",
|
|
51876
|
+
"bold/italic",
|
|
51877
|
+
"links",
|
|
51878
|
+
"list markers",
|
|
51879
|
+
"list numbering",
|
|
51880
|
+
"list indentation"
|
|
51881
|
+
];
|
|
51882
|
+
var PH_OPEN = "\uE000";
|
|
51883
|
+
var PH_CLOSE = "\uE001";
|
|
51884
|
+
var PLACEHOLDER = /(\d+)/g;
|
|
51885
|
+
function convertInline(line, changes) {
|
|
51886
|
+
if (line.includes(PH_OPEN) || line.includes(PH_CLOSE)) return line;
|
|
51887
|
+
const kept = [];
|
|
51888
|
+
const protect = (s2) => `${PH_OPEN}${kept.push(s2) - 1}${PH_CLOSE}`;
|
|
51889
|
+
let s = line.replace(/(`+)[^`]+?\1(?!`)/g, protect);
|
|
51890
|
+
const beforeLinks = s;
|
|
51891
|
+
s = s.replace(/<(https?:\/\/[^\s<>]+)>/g, (_m, url2) => protect(url2));
|
|
51892
|
+
s = s.replace(/!?\[([^\]\n]+)\]\(([^)\s]+)\)/g, (_m, text, url2) => {
|
|
51893
|
+
const bare = (u) => u.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
51894
|
+
return bare(text) === bare(url2) ? protect(url2) : `${text} (${protect(url2)})`;
|
|
51895
|
+
});
|
|
51896
|
+
if (s !== beforeLinks) changes.add("links");
|
|
51897
|
+
s = s.replace(/https?:\/\/\S+/g, protect);
|
|
51898
|
+
const beforeEmphasis = s;
|
|
51899
|
+
s = s.replace(/\*\*(?=\S)(.+?)(?<=\S)\*\*/g, "$1");
|
|
51900
|
+
s = s.replace(/(?<![\w_])__(?=\S)(.+?)(?<=\S)__(?![\w_])/g, "$1");
|
|
51901
|
+
s = s.replace(/(?<![\w*])\*(?![\s*])(.+?)(?<![\s*])\*(?![\w*])/g, "$1");
|
|
51902
|
+
s = s.replace(/(?<![\w_])_(?![\s_])(.+?)(?<![\s_])_(?![\w_])/g, "$1");
|
|
51903
|
+
if (s !== beforeEmphasis) changes.add("bold/italic");
|
|
51904
|
+
while (s.includes(PH_OPEN)) {
|
|
51905
|
+
s = s.replace(PLACEHOLDER, (_m, i) => kept[Number(i)]);
|
|
51906
|
+
}
|
|
51907
|
+
return s;
|
|
51908
|
+
}
|
|
51909
|
+
var HEADING = /^ {0,3}#{1,6}[ \t]+(.*?)(?:[ \t]+#+)?[ \t]*$/;
|
|
51910
|
+
var FENCE = /^ {0,3}(`{3,}|~{3,})/;
|
|
51911
|
+
var ITEM = /^([ \t]*)([-*+]|\d{1,9}[.)]|[a-z]{1,2}[.)])([ \t]+)(\S.*)$/;
|
|
51912
|
+
function indentWidth(ws) {
|
|
51913
|
+
let n = 0;
|
|
51914
|
+
for (const ch of ws) n += ch === " " ? 4 : 1;
|
|
51915
|
+
return n;
|
|
51916
|
+
}
|
|
51917
|
+
function alphaIndex(token) {
|
|
51918
|
+
let n = 0;
|
|
51919
|
+
for (const ch of token) n = n * 26 + (ch.charCodeAt(0) - 96);
|
|
51920
|
+
return n;
|
|
51921
|
+
}
|
|
51922
|
+
function toAlpha(n) {
|
|
51923
|
+
let s = "";
|
|
51924
|
+
for (let k = Math.max(1, n); k > 0; k = Math.floor((k - 1) / 26)) {
|
|
51925
|
+
s = String.fromCharCode(97 + (k - 1) % 26) + s;
|
|
51926
|
+
}
|
|
51927
|
+
return s;
|
|
51928
|
+
}
|
|
51929
|
+
function markdownToPlainText(input2) {
|
|
51930
|
+
const eol = input2.includes("\r\n") ? "\r\n" : "\n";
|
|
51931
|
+
const lines = input2.split(/\r?\n/);
|
|
51932
|
+
const out = [...lines];
|
|
51933
|
+
const changes = /* @__PURE__ */ new Set();
|
|
51934
|
+
const runs = [];
|
|
51935
|
+
let fence = null;
|
|
51936
|
+
let stack = [];
|
|
51937
|
+
let prevBlank = true;
|
|
51938
|
+
const endList = () => {
|
|
51939
|
+
stack = [];
|
|
51940
|
+
};
|
|
51941
|
+
lines.forEach((line, i) => {
|
|
51942
|
+
if (fence !== null) {
|
|
51943
|
+
if (line.trimStart().startsWith(fence)) fence = null;
|
|
51944
|
+
return;
|
|
51945
|
+
}
|
|
51946
|
+
const fenceOpen = FENCE.exec(line);
|
|
51947
|
+
if (fenceOpen) {
|
|
51948
|
+
fence = fenceOpen[1];
|
|
51949
|
+
endList();
|
|
51950
|
+
prevBlank = false;
|
|
51951
|
+
return;
|
|
51952
|
+
}
|
|
51953
|
+
if (line.trim() === "") {
|
|
51954
|
+
prevBlank = true;
|
|
51955
|
+
return;
|
|
51956
|
+
}
|
|
51957
|
+
const m = ITEM.exec(line);
|
|
51958
|
+
if (m) {
|
|
51959
|
+
const [, ws, marker, sep3, content] = m;
|
|
51960
|
+
const indent = indentWidth(ws);
|
|
51961
|
+
const bullet = /^[-*+]$/.test(marker);
|
|
51962
|
+
const letter = /^[a-z]/.test(marker);
|
|
51963
|
+
const token = bullet ? "" : marker.slice(0, -1);
|
|
51964
|
+
const accepted = letter ? stack.length > 0 && indent >= stack[0].indent + 2 : stack.length > 0 || prevBlank || bullet || token === "1";
|
|
51965
|
+
if (accepted) {
|
|
51966
|
+
const kind = bullet ? "bullet" : "ordered";
|
|
51967
|
+
const start = bullet ? 0 : letter ? alphaIndex(token) : Number(token);
|
|
51968
|
+
const item = { line: i, indent: ws, marker, sep: sep3, content };
|
|
51969
|
+
const newRun = (level) => {
|
|
51970
|
+
const run = { kind, level, start, items: [item] };
|
|
51971
|
+
runs.push(run);
|
|
51972
|
+
return run;
|
|
51973
|
+
};
|
|
51974
|
+
if (stack.length === 0) {
|
|
51975
|
+
stack.push({ indent, run: newRun(0) });
|
|
51976
|
+
} else {
|
|
51977
|
+
while (stack.length > 1 && indent <= stack[stack.length - 1].indent - 2) stack.pop();
|
|
51978
|
+
const top = stack[stack.length - 1];
|
|
51979
|
+
if (indent >= top.indent + 2) {
|
|
51980
|
+
stack.push({ indent, run: newRun(stack.length) });
|
|
51981
|
+
} else if (top.run.kind !== kind) {
|
|
51982
|
+
top.run = newRun(stack.length - 1);
|
|
51983
|
+
} else {
|
|
51984
|
+
top.run.items.push(item);
|
|
51985
|
+
}
|
|
51986
|
+
}
|
|
51987
|
+
prevBlank = false;
|
|
51988
|
+
return;
|
|
51989
|
+
}
|
|
51990
|
+
}
|
|
51991
|
+
if (stack.length > 0 && /^[ \t]/.test(line)) {
|
|
51992
|
+
out[i] = convertInline(line, changes);
|
|
51993
|
+
prevBlank = false;
|
|
51994
|
+
return;
|
|
51995
|
+
}
|
|
51996
|
+
endList();
|
|
51997
|
+
const heading = HEADING.exec(line);
|
|
51998
|
+
if (heading) {
|
|
51999
|
+
out[i] = convertInline(heading[1], changes);
|
|
52000
|
+
changes.add("headings");
|
|
52001
|
+
} else {
|
|
52002
|
+
out[i] = convertInline(line, changes);
|
|
52003
|
+
}
|
|
52004
|
+
prevBlank = false;
|
|
52005
|
+
});
|
|
52006
|
+
for (const run of runs) {
|
|
52007
|
+
const lettered = run.kind === "ordered" && run.level % 2 === 1;
|
|
52008
|
+
const markers = run.items.map((_, k) => {
|
|
52009
|
+
if (run.kind === "bullet") return "-";
|
|
52010
|
+
return `${lettered ? toAlpha(run.start + k) : run.start + k}.`;
|
|
52011
|
+
});
|
|
52012
|
+
const width = Math.max(...markers.map((mk) => mk.length));
|
|
52013
|
+
run.items.forEach((item, k) => {
|
|
52014
|
+
const indent = " ".repeat(4 * run.level);
|
|
52015
|
+
const sep3 = " ".repeat(width - markers[k].length + 1);
|
|
52016
|
+
if (indent !== item.indent) changes.add("list indentation");
|
|
52017
|
+
const origToken = item.marker.replace(/[.)]$/, "");
|
|
52018
|
+
const newToken = markers[k].replace(/\.$/, "");
|
|
52019
|
+
if (run.kind === "bullet" ? item.marker !== "-" : item.marker.endsWith(")")) changes.add("list markers");
|
|
52020
|
+
if (run.kind === "ordered" && origToken !== newToken) changes.add("list numbering");
|
|
52021
|
+
if (sep3 !== item.sep) changes.add(run.kind === "ordered" && width > 2 ? "list numbering" : "list markers");
|
|
52022
|
+
out[item.line] = `${indent}${markers[k]}${sep3}${convertInline(item.content, changes)}`;
|
|
52023
|
+
});
|
|
52024
|
+
}
|
|
52025
|
+
if (changes.size === 0) return { text: input2, changes: [] };
|
|
52026
|
+
return { text: out.join(eol), changes: CHANGE_ORDER.filter((c) => changes.has(c)) };
|
|
52027
|
+
}
|
|
52028
|
+
var BODY_FORMAT_DESCRIPTION = 'How to treat `body`. OurFamilyWizard shows message bodies as PLAIN TEXT \u2014 Markdown is never rendered, so **bold** would reach the co-parent with its asterisks. Default "markdown": Markdown is converted to plain text before anything is saved or sent (bold/italic markers and # heading markers dropped; [text](url) \u2192 "text (url)"; lists normalized to "-" bullets and renumbered 1., 2., \u2026 with a., b. for the second level, 4 spaces per nesting level; code, URLs and ~~strikethrough~~ left as written), and the response reports what changed under bodyConversion. "plain": send the body byte-for-byte. Line breaks, blank lines and leading spaces always survive; full https:// URLs, email addresses and phone numbers become links for the reader.';
|
|
52029
|
+
function prepareBody(body, format) {
|
|
52030
|
+
if (format === "plain") return { body, conversion: null, noteLine: null };
|
|
52031
|
+
const { text, changes } = markdownToPlainText(body);
|
|
52032
|
+
if (changes.length === 0) return { body, conversion: null, noteLine: null };
|
|
52033
|
+
const note = `OurFamilyWizard shows bodies as plain text, so Markdown was converted (${changes.join(", ")}). What was saved/sent is the converted text; pass bodyFormat:"plain" to send a body exactly as written.`;
|
|
52034
|
+
return {
|
|
52035
|
+
body: text,
|
|
52036
|
+
conversion: { changes, note },
|
|
52037
|
+
noteLine: `NOTE: the body was converted from Markdown to plain text (${changes.join(", ")}).`
|
|
52038
|
+
};
|
|
52039
|
+
}
|
|
52040
|
+
|
|
51824
52041
|
// src/tools/messages.ts
|
|
51825
52042
|
var 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.';
|
|
51826
52043
|
var DRAFT_KEY_NULL_REASON = "No draftKey: this draft was not saved through this server's cache \u2014 it may have been created in the OurFamilyWizard web app or replaced from another session \u2014 so its lineage is unknown. The next ofw_save_draft on it starts a new key.";
|
|
@@ -51986,11 +52203,12 @@ async function openUnreadBody(client2, cache, cached2) {
|
|
|
51986
52203
|
await client2.request("GET", `/pub/v3/messages/${cached2.id}`),
|
|
51987
52204
|
{ label: "ofw-mcp", context: "GET /pub/v3/messages/{id} (sync, confirmed mark-read)" }
|
|
51988
52205
|
);
|
|
52206
|
+
const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
51989
52207
|
await cache.upsertMessage({
|
|
51990
52208
|
...cached2,
|
|
51991
|
-
recipients:
|
|
52209
|
+
recipients: mergeRecipients(cached2.recipients, detailRecipients(detail.recipients, checkedAt)),
|
|
51992
52210
|
body: detail.body ?? "",
|
|
51993
|
-
fetchedBodyAt:
|
|
52211
|
+
fetchedBodyAt: checkedAt
|
|
51994
52212
|
});
|
|
51995
52213
|
if (Array.isArray(detail.files) && detail.files.length > 0) {
|
|
51996
52214
|
await fetchAttachmentMetaForMessage(client2, cached2.id, detail.files, cache);
|
|
@@ -52121,6 +52339,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52121
52339
|
view: LIST_MESSAGES_VIEW
|
|
52122
52340
|
})
|
|
52123
52341
|
}, async (args) => {
|
|
52342
|
+
const callStartedAt = Date.now();
|
|
52124
52343
|
const page = args.page ?? 1;
|
|
52125
52344
|
const size = args.size ?? 50;
|
|
52126
52345
|
const sort = args.sort ?? "newest";
|
|
@@ -52170,7 +52389,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52170
52389
|
isEmpty: (v) => v.total === 0,
|
|
52171
52390
|
read: async () => {
|
|
52172
52391
|
const total2 = await cache.countMessages(filter);
|
|
52173
|
-
const messages2 = (await cache.listMessages({ ...filter, page, size, sort })).map((m) => withReadState(m));
|
|
52392
|
+
const messages2 = (await cache.listMessages({ ...filter, page, size, sort })).map((m) => withViewOrigin(withReadState(m), callStartedAt));
|
|
52174
52393
|
const freshness2 = await buildFreshness(cache, { source: "cache", folders });
|
|
52175
52394
|
return { messages: messages2, total: total2, freshness: freshness2 };
|
|
52176
52395
|
}
|
|
@@ -52251,7 +52470,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52251
52470
|
});
|
|
52252
52471
|
server.registerTool("ofw_get_message", {
|
|
52253
52472
|
_meta: familyMeta("lookup"),
|
|
52254
|
-
description: 'Get a single OurFamilyWizard message OR draft by ID. Reads from local cache when available; otherwise fetches from OFW \u2014 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) \u2014 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) only an UNREAD inbox message is protected: its body is withheld (body:null, bodyWithheld:true, withheldReason:"UNREAD_ON_NO_READ_DAY", readingBlocked says when reading resumes) and OFW is never contacted for it; an id not in the cache is refused, since fetching it could mark it read. Sent messages and inbox messages already read are returned exactly as on a reading day. 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.' + OVERRIDE_DESCRIPTION,
|
|
52473
|
+
description: 'Get a single OurFamilyWizard message OR draft by ID. Reads from local cache when available; otherwise fetches from OFW \u2014 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) \u2014 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) only an UNREAD inbox message is protected: its body is withheld (body:null, bodyWithheld:true, withheldReason:"UNREAD_ON_NO_READ_DAY", readingBlocked says when reading resumes) and OFW is never contacted for it; an id not in the cache is refused, since fetching it could mark it read. Sent messages and inbox messages already read are returned exactly as on a reading day. 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. Each recipient\'s `viewedAt` carries its provenance: `viewedAtOrigin` is "detail-this-call" (read from OurFamilyWizard during this call), "detail-cached" (from an earlier read \u2014 see `viewedAtCheckedAt`), "list" (only the list was seen, so a null `viewedAt` means UNKNOWN, not unviewed) or "unrecorded". `viewedPlaceholder` is OurFamilyWizard\'s raw 1970 placeholder, kept as source data \u2014 it is never a view time.' + OVERRIDE_DESCRIPTION,
|
|
52255
52474
|
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
52256
52475
|
inputSchema: external_exports.object({
|
|
52257
52476
|
messageId: external_exports.string().describe("Message ID (also accepts draft IDs \u2014 drafts are routed via the drafts cache)"),
|
|
@@ -52263,6 +52482,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52263
52482
|
confirmToken: confirmTokenParam
|
|
52264
52483
|
})
|
|
52265
52484
|
}, async (args, ctx) => {
|
|
52485
|
+
const callStartedAt = Date.now();
|
|
52266
52486
|
const id2 = Number(args.messageId);
|
|
52267
52487
|
const view = resolveView(args.view, MESSAGE_VIEWS);
|
|
52268
52488
|
const cache = cacheProvider();
|
|
@@ -52335,7 +52555,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52335
52555
|
const freshness2 = await buildFreshness(cache, { source: "cache", folders: [cached2.folder] });
|
|
52336
52556
|
return jsonResponse({
|
|
52337
52557
|
readingBlocked: blocked,
|
|
52338
|
-
...viewOne(view, withholdBody(withReadState(cached2))),
|
|
52558
|
+
...viewOne(view, withholdBody(withViewOrigin(withReadState(cached2), callStartedAt))),
|
|
52339
52559
|
attachments: attachments2,
|
|
52340
52560
|
freshness: freshness2
|
|
52341
52561
|
});
|
|
@@ -52349,7 +52569,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52349
52569
|
await client2.request("GET", `/pub/v3/messages/${id2}`),
|
|
52350
52570
|
{ label: "ofw-mcp", context: "GET /pub/v3/messages/{id} (view-status refresh)" }
|
|
52351
52571
|
);
|
|
52352
|
-
const recipients =
|
|
52572
|
+
const recipients = mergeRecipients(cached2.recipients, detailRecipients(detail2.recipients, (/* @__PURE__ */ new Date()).toISOString()));
|
|
52353
52573
|
row2 = {
|
|
52354
52574
|
...cached2,
|
|
52355
52575
|
recipients,
|
|
@@ -52377,7 +52597,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52377
52597
|
const freshness2 = await buildFreshness(cache, { source: "cache", folders: [row2.folder] });
|
|
52378
52598
|
return jsonResponse({
|
|
52379
52599
|
...overriding ? readOverrideFields("ofw_get_message", [row2.id]) : {},
|
|
52380
|
-
...viewOne(view, withReadState(row2)),
|
|
52600
|
+
...viewOne(view, withViewOrigin(withReadState(row2), callStartedAt)),
|
|
52381
52601
|
attachments: attachments2,
|
|
52382
52602
|
freshness: freshness2
|
|
52383
52603
|
});
|
|
@@ -52398,15 +52618,16 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52398
52618
|
folder = "sent";
|
|
52399
52619
|
}
|
|
52400
52620
|
}
|
|
52621
|
+
const fetchedBodyAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
52401
52622
|
const row = {
|
|
52402
52623
|
id: detail.id,
|
|
52403
52624
|
folder,
|
|
52404
52625
|
subject: detail.subject,
|
|
52405
52626
|
fromUser: detail.from?.name ?? "",
|
|
52406
52627
|
sentAt: detail.date?.dateTime ?? nowNaiveWallClock(),
|
|
52407
|
-
recipients:
|
|
52628
|
+
recipients: mergeRecipients(cached2?.recipients, detailRecipients(detail.recipients, fetchedBodyAt)),
|
|
52408
52629
|
body: detail.body ?? "",
|
|
52409
|
-
fetchedBodyAt
|
|
52630
|
+
fetchedBodyAt,
|
|
52410
52631
|
replyToId: cached2?.replyToId ?? null,
|
|
52411
52632
|
chainRootId: cached2?.chainRootId ?? null,
|
|
52412
52633
|
listData: cached2?.listData ?? detail
|
|
@@ -52419,7 +52640,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52419
52640
|
const freshness = await buildFreshness(cache, { source: "live", folders: [folder] });
|
|
52420
52641
|
return jsonResponse({
|
|
52421
52642
|
...overriding ? readOverrideFields("ofw_get_message", [row.id]) : {},
|
|
52422
|
-
...viewOne(view, withReadState(row)),
|
|
52643
|
+
...viewOne(view, withViewOrigin(withReadState(row), callStartedAt)),
|
|
52423
52644
|
attachments,
|
|
52424
52645
|
freshness
|
|
52425
52646
|
});
|
|
@@ -52431,6 +52652,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52431
52652
|
inputSchema: external_exports.object({
|
|
52432
52653
|
subject: external_exports.string().describe("Message subject. Required unless draftId/messageId is given (then it overrides the server draft's subject).").optional(),
|
|
52433
52654
|
body: external_exports.string().describe("Message body text. Required unless draftId/messageId is given (then it overrides the server draft's body \u2014 omit it to send exactly what is on OurFamilyWizard).").optional(),
|
|
52655
|
+
bodyFormat: external_exports.enum(["markdown", "plain"]).describe(`${BODY_FORMAT_DESCRIPTION} Applies only to a body passed here: a draft sent by id goes out exactly as it is on OurFamilyWizard.`).optional(),
|
|
52434
52656
|
recipientIds: external_exports.array(external_exports.number()).describe("Array of recipient user IDs (get from ofw_get_profile). Usually required even when sending a draft: OurFamilyWizard does not persist recipients on drafts.").optional(),
|
|
52435
52657
|
replyToId: external_exports.number().describe("ID of the message being replied to. Defaults to the draft's stored reply target when sending by draftId.").optional(),
|
|
52436
52658
|
draftId: external_exports.number().describe("ID of an existing draft to send. The draft is re-read from OurFamilyWizard and its SERVER content is sent; missing subject/body default from it. Guarded: a draft that changed since you read it, or that was already sent/deleted, refuses rather than sending blind.").optional(),
|
|
@@ -52457,7 +52679,8 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52457
52679
|
{ store: blobStore, readBlobs: true }
|
|
52458
52680
|
);
|
|
52459
52681
|
let subject = args.subject;
|
|
52460
|
-
|
|
52682
|
+
const prepared = args.body === void 0 ? null : prepareBody(args.body, args.bodyFormat);
|
|
52683
|
+
let body = prepared?.body;
|
|
52461
52684
|
let recipientIds = args.recipientIds;
|
|
52462
52685
|
let draftReplyToId = null;
|
|
52463
52686
|
let guardNote = null;
|
|
@@ -52534,6 +52757,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52534
52757
|
...unresolved.length > 0 ? { recipientNote: `No name on file for user id(s) ${unresolved.join(", ")} \u2014 verify the recipient before approving.` } : {},
|
|
52535
52758
|
subject,
|
|
52536
52759
|
body,
|
|
52760
|
+
...prepared?.conversion ? { bodyConversion: prepared.conversion } : {},
|
|
52537
52761
|
replyTo: resolvedReplyTo === null ? null : { messageId: resolvedReplyTo, subject: replyParent?.subject ?? null, from: replyParent?.fromUser || null },
|
|
52538
52762
|
attachments,
|
|
52539
52763
|
...pending.length > 0 ? { newAttachments: describePending(pending) } : {},
|
|
@@ -52632,7 +52856,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52632
52856
|
} else {
|
|
52633
52857
|
threaded = true;
|
|
52634
52858
|
}
|
|
52635
|
-
const storedRecipients = mapRecipients(detail.recipients);
|
|
52859
|
+
const storedRecipients = mapRecipients(detail.recipients, { source: "detail", checkedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
52636
52860
|
if (Array.isArray(detail.recipients) && detail.recipients.length > 0) {
|
|
52637
52861
|
const landed = new Set(storedRecipients.map((r) => r.userId));
|
|
52638
52862
|
const missingRecipients = recipientIds.filter((rid) => !landed.has(rid));
|
|
@@ -52722,10 +52946,11 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
52722
52946
|
...resolveView(args.view, MESSAGE_VIEWS) === "full" ? persisted : compactSentMessage(persisted),
|
|
52723
52947
|
...attachmentCheck !== null ? { attachments: attachmentCheck } : {},
|
|
52724
52948
|
...newFiles.length > 0 ? { attachmentsUploaded: newFiles } : {},
|
|
52725
|
-
...uploadWarnings.length > 0 ? { warnings: uploadWarnings } : {}
|
|
52949
|
+
...uploadWarnings.length > 0 ? { warnings: uploadWarnings } : {},
|
|
52950
|
+
...prepared?.conversion ? { bodyConversion: prepared.conversion } : {}
|
|
52726
52951
|
};
|
|
52727
52952
|
return notedJsonResponse(
|
|
52728
|
-
[guardNote, rewriteNote, verifyNote, threadNote, attachmentNote, unconfirmedNote, retainNote],
|
|
52953
|
+
[guardNote, rewriteNote, prepared?.noteLine ?? null, verifyNote, threadNote, attachmentNote, unconfirmedNote, retainNote],
|
|
52729
52954
|
responseObj,
|
|
52730
52955
|
"Message sent successfully."
|
|
52731
52956
|
);
|
|
@@ -52903,6 +53128,7 @@ ${jsonText(
|
|
|
52903
53128
|
inputSchema: external_exports.object({
|
|
52904
53129
|
subject: external_exports.string().describe("Message subject"),
|
|
52905
53130
|
body: external_exports.string().describe("Message body text"),
|
|
53131
|
+
bodyFormat: external_exports.enum(["markdown", "plain"]).describe(BODY_FORMAT_DESCRIPTION).optional(),
|
|
52906
53132
|
recipientIds: external_exports.array(external_exports.number()).describe("Array of recipient user IDs (optional for drafts)").optional(),
|
|
52907
53133
|
messageId: external_exports.number().describe("ID of an existing draft to replace (the new draft will have a new id; the old is deleted)").optional(),
|
|
52908
53134
|
replyToId: external_exports.number().nullable().describe("ID of the message this draft replies to. When replacing a draft (messageId), omit it to keep the draft's own reply target, or pass null to make the draft a new top-level message.").optional(),
|
|
@@ -52917,6 +53143,7 @@ ${jsonText(
|
|
|
52917
53143
|
}, async (args) => {
|
|
52918
53144
|
const cache = cacheProvider();
|
|
52919
53145
|
const view = resolveView(args.view, MESSAGE_VIEWS);
|
|
53146
|
+
const prepared = prepareBody(args.body, args.bodyFormat);
|
|
52920
53147
|
const blobStore = args.blobKeys?.length ? blobStoreFromEnv() : void 0;
|
|
52921
53148
|
const pending = await planAttachments(
|
|
52922
53149
|
{ inline: args.inlineAttachments, blobKeys: args.blobKeys },
|
|
@@ -52968,7 +53195,7 @@ ${jsonText(
|
|
|
52968
53195
|
]).filter((id2) => !removed.has(id2));
|
|
52969
53196
|
const payload = {
|
|
52970
53197
|
subject: args.subject,
|
|
52971
|
-
body:
|
|
53198
|
+
body: prepared.body,
|
|
52972
53199
|
recipientIds: args.recipientIds ?? serverRecipientIds ?? [],
|
|
52973
53200
|
attachments: { myFileIDs },
|
|
52974
53201
|
draft: true,
|
|
@@ -52992,7 +53219,7 @@ ${jsonText(
|
|
|
52992
53219
|
let draftKey = null;
|
|
52993
53220
|
const warnings = [...uploadWarnings];
|
|
52994
53221
|
if (newId !== null) {
|
|
52995
|
-
verifyNote = verifyWriteLanded("draft", { subject: args.subject, body:
|
|
53222
|
+
verifyNote = verifyWriteLanded("draft", { subject: args.subject, body: prepared.body }, detail);
|
|
52996
53223
|
const reply = draftReplyTarget([detail], resolvedReplyTo);
|
|
52997
53224
|
const effectiveReplyTo = reply.replyToId;
|
|
52998
53225
|
replyToSource = reply.replyToSource;
|
|
@@ -53085,11 +53312,12 @@ ${jsonText(
|
|
|
53085
53312
|
},
|
|
53086
53313
|
...newFiles.length > 0 ? { attachmentsUploaded: newFiles } : {},
|
|
53087
53314
|
...warnings.length > 0 ? { warnings } : {},
|
|
53088
|
-
...recipientsNote !== null ? { recipientsNote } : {}
|
|
53315
|
+
...recipientsNote !== null ? { recipientsNote } : {},
|
|
53316
|
+
...prepared.conversion !== null ? { bodyConversion: prepared.conversion } : {}
|
|
53089
53317
|
} : raw;
|
|
53090
53318
|
const warnNote = warnings.length > 0 ? `WARNING: ${warnings.join("\n\n")}` : null;
|
|
53091
53319
|
return notedJsonResponse(
|
|
53092
|
-
[forceNote, rewriteNote, verifyNote, warnNote, recipientsNote, replaceNote],
|
|
53320
|
+
[forceNote, rewriteNote, prepared.noteLine, verifyNote, warnNote, recipientsNote, replaceNote],
|
|
53093
53321
|
responseObj,
|
|
53094
53322
|
"Draft saved."
|
|
53095
53323
|
);
|
package/dist/sync.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { clearHeldFiles, getHeldFiles, setHeldFiles } from './tools/held-attachments.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { ApiRecipientSchema, draftReplyTarget, hasRealView, mapRecipients, scrapeSaysRead } from './tools/_shared.js';
|
|
3
|
+
import { ApiRecipientSchema, detailRecipients, draftReplyTarget, hasRealView, mapRecipients, mergeRecipients, scrapeSaysRead } from './tools/_shared.js';
|
|
4
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';
|
|
@@ -233,11 +233,15 @@ async function walkPages(client, folder, folderId, opts, store) {
|
|
|
233
233
|
break;
|
|
234
234
|
}
|
|
235
235
|
const detail = await fetchDetail(item, { subject: existing.subject, sentAt: existing.sentAt, from: senderOf(existing) }, 'GET /pub/v3/messages/{id} (body backfill)', false);
|
|
236
|
+
const checkedAt = new Date().toISOString();
|
|
236
237
|
toUpsert.push({
|
|
237
238
|
...existing,
|
|
238
239
|
body: detail.body ?? '',
|
|
239
|
-
fetchedBodyAt:
|
|
240
|
-
|
|
240
|
+
fetchedBodyAt: checkedAt,
|
|
241
|
+
// A detail that omits recipients (or a view time) must not erase
|
|
242
|
+
// what the cache already recorded — and the LIST's recipients
|
|
243
|
+
// carry only a placeholder, so they are never a substitute.
|
|
244
|
+
recipients: mergeRecipients(existing.recipients, detailRecipients(detail.recipients, checkedAt)),
|
|
241
245
|
listData: item,
|
|
242
246
|
});
|
|
243
247
|
synced++;
|
|
@@ -262,7 +266,8 @@ async function walkPages(client, folder, folderId, opts, store) {
|
|
|
262
266
|
break;
|
|
263
267
|
}
|
|
264
268
|
const detail = parseLenient(DetailResponseSchema, await client.request('GET', `/pub/v3/messages/${item.id}`), { label: 'ofw-mcp', context: 'GET /pub/v3/messages/{id} (view-status refresh)' });
|
|
265
|
-
|
|
269
|
+
const recipients = mergeRecipients(existing.recipients, detailRecipients(detail.recipients, new Date().toISOString()));
|
|
270
|
+
toUpsert.push({ ...existing, recipients, listData: item });
|
|
266
271
|
synced++;
|
|
267
272
|
}
|
|
268
273
|
continue;
|
|
@@ -278,7 +283,7 @@ async function walkPages(client, folder, folderId, opts, store) {
|
|
|
278
283
|
// the row from the list would cache viewedAt:null for a message that was
|
|
279
284
|
// already read by the time we first saw it — reporting "never viewed" for
|
|
280
285
|
// a message OFW shows as read, until a later sync's refresh healed it.
|
|
281
|
-
let
|
|
286
|
+
let detailRecipientsRaw;
|
|
282
287
|
// The row as the list describes it; the detail (if fetched) fills in
|
|
283
288
|
// body and real view times below.
|
|
284
289
|
const row = {
|
|
@@ -287,7 +292,7 @@ async function walkPages(client, folder, folderId, opts, store) {
|
|
|
287
292
|
subject: item.subject ?? '(no subject)',
|
|
288
293
|
fromUser: item.from?.name ?? '',
|
|
289
294
|
sentAt: item.date?.dateTime ?? nowNaiveWallClock(),
|
|
290
|
-
recipients: mapRecipients(item.recipients),
|
|
295
|
+
recipients: mapRecipients(item.recipients, { source: 'list' }),
|
|
291
296
|
body: null,
|
|
292
297
|
fetchedBodyAt: null,
|
|
293
298
|
replyToId: null,
|
|
@@ -306,7 +311,7 @@ async function walkPages(client, folder, folderId, opts, store) {
|
|
|
306
311
|
opts.onUnreadBodyFetched?.(item.id);
|
|
307
312
|
body = detail.body ?? '';
|
|
308
313
|
fetchedBodyAt = new Date().toISOString();
|
|
309
|
-
|
|
314
|
+
detailRecipientsRaw = detail.recipients;
|
|
310
315
|
if (Array.isArray(detail.files) && detail.files.length > 0) {
|
|
311
316
|
detailFileIds = detail.files;
|
|
312
317
|
}
|
|
@@ -327,8 +332,8 @@ async function walkPages(client, folder, folderId, opts, store) {
|
|
|
327
332
|
});
|
|
328
333
|
row.body = body;
|
|
329
334
|
row.fetchedBodyAt = fetchedBodyAt;
|
|
330
|
-
if (
|
|
331
|
-
row.recipients =
|
|
335
|
+
if (detailRecipientsRaw)
|
|
336
|
+
row.recipients = mergeRecipients(row.recipients, detailRecipients(detailRecipientsRaw, fetchedBodyAt));
|
|
332
337
|
toUpsert.push(row);
|
|
333
338
|
synced++;
|
|
334
339
|
if (detailFileIds.length > 0) {
|
package/dist/timestamps.js
CHANGED
|
@@ -173,6 +173,10 @@ const TIMESTAMP_KEYS = new Set([
|
|
|
173
173
|
// OFW: UTC instants we stamp ourselves.
|
|
174
174
|
'fetchedBodyAt',
|
|
175
175
|
'fetchedAt',
|
|
176
|
+
// When the detail behind a recipient's `viewedAt` was read (issue #448).
|
|
177
|
+
// NOT `viewedPlaceholder`: that is OFW's raw epoch-zero placeholder, kept
|
|
178
|
+
// verbatim precisely so it can never be rendered as a real time.
|
|
179
|
+
'viewedAtCheckedAt',
|
|
176
180
|
'syncedAt',
|
|
177
181
|
'downloadedAt',
|
|
178
182
|
'recordedAt',
|
package/dist/tools/_shared.js
CHANGED
|
@@ -70,24 +70,80 @@ export const ApiRecipientSchema = z.looseObject({
|
|
|
70
70
|
}).optional(),
|
|
71
71
|
viewed: z.looseObject({ dateTime: z.string() }).nullable().optional(),
|
|
72
72
|
});
|
|
73
|
-
|
|
74
|
-
// Used wherever we surface or persist recipients (sync, get_message, send,
|
|
75
|
-
// save_draft).
|
|
76
|
-
//
|
|
77
|
-
// `viewedAt` is the recipient's true "First Viewed" time, or null if not yet
|
|
78
|
-
// viewed. Only the DETAIL endpoint (/pub/v3/messages/{id}) carries a real
|
|
79
|
-
// timestamp; the LIST endpoint returns an epoch-zero PLACEHOLDER
|
|
80
|
-
// ("1970-01-01T00:00:00") in the SAME field even for read messages (on the
|
|
81
|
-
// list, read status lives in the flags — `read` for inbox, `showNeverViewed`
|
|
82
|
-
// for sent; see scrapeSaysRead — not the timestamp). So treat
|
|
83
|
-
// the epoch placeholder as "no real view time" — otherwise a list-sourced row
|
|
84
|
-
// reports a bogus 1970 read time. A detail re-fetch is what fills in the truth.
|
|
85
|
-
export function mapRecipients(items) {
|
|
73
|
+
export function mapRecipients(items, origin) {
|
|
86
74
|
return (items ?? []).map((r) => {
|
|
87
75
|
const dt = r.viewed?.dateTime;
|
|
88
|
-
const
|
|
89
|
-
|
|
76
|
+
const placeholder = typeof dt === 'string' && dt.startsWith('1970-01-01');
|
|
77
|
+
const viewedAt = typeof dt === 'string' && !placeholder ? dt : null;
|
|
78
|
+
const out = { userId: r.user?.userId ?? r.user?.id ?? 0, name: r.user?.name ?? '', viewedAt };
|
|
79
|
+
if (origin) {
|
|
80
|
+
out.viewedAtSource = origin.source;
|
|
81
|
+
if (origin.source === 'detail' && origin.checkedAt !== undefined)
|
|
82
|
+
out.viewedAtCheckedAt = origin.checkedAt;
|
|
83
|
+
if (placeholder)
|
|
84
|
+
out.viewedPlaceholder = dt;
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A detail payload's recipients, labelled as read from the detail at
|
|
91
|
+
* `checkedAt` — or null when the payload reported none (absent or empty), so
|
|
92
|
+
* {@link mergeRecipients} keeps what the cache already knew.
|
|
93
|
+
*/
|
|
94
|
+
export function detailRecipients(items, checkedAt) {
|
|
95
|
+
return items && items.length > 0 ? mapRecipients(items, { source: 'detail', checkedAt }) : null;
|
|
96
|
+
}
|
|
97
|
+
function sameRecipient(a, b) {
|
|
98
|
+
if (a.userId !== 0 && b.userId !== 0)
|
|
99
|
+
return a.userId === b.userId;
|
|
100
|
+
return a.name !== '' && a.name === b.name;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Combine freshly fetched recipients with what the cache already held, so an
|
|
104
|
+
* INCOMPLETE OFW response can never erase evidence (issue #448).
|
|
105
|
+
*
|
|
106
|
+
* - No recipients reported (absent or `[]`) → the cached set stands; a message
|
|
107
|
+
* always has recipients, so an empty array is "not echoed", not "none".
|
|
108
|
+
* - A recipient the fresh payload gives no real view time, where the cache
|
|
109
|
+
* holds one → the cached time is carried forward WITH its original
|
|
110
|
+
* provenance (`viewedAtSource`/`viewedAtCheckedAt`), so a reader can tell it
|
|
111
|
+
* was not re-observed by this fetch. "First Viewed" cannot be withdrawn, so
|
|
112
|
+
* a payload that omits it is incomplete, not a correction.
|
|
113
|
+
*
|
|
114
|
+
* Membership otherwise follows the fresh payload.
|
|
115
|
+
*/
|
|
116
|
+
export function mergeRecipients(prior, fresh) {
|
|
117
|
+
if (fresh === null || fresh.length === 0)
|
|
118
|
+
return prior ?? [];
|
|
119
|
+
const priorList = prior ?? [];
|
|
120
|
+
return fresh.map((r) => {
|
|
121
|
+
if (hasRealView([r]))
|
|
122
|
+
return r;
|
|
123
|
+
const match = priorList.find((p) => sameRecipient(p, r) && hasRealView([p]));
|
|
124
|
+
if (!match)
|
|
125
|
+
return r;
|
|
126
|
+
const carried = { userId: r.userId, name: r.name, viewedAt: match.viewedAt };
|
|
127
|
+
if (match.viewedAtSource !== undefined)
|
|
128
|
+
carried.viewedAtSource = match.viewedAtSource;
|
|
129
|
+
if (match.viewedAtCheckedAt !== undefined)
|
|
130
|
+
carried.viewedAtCheckedAt = match.viewedAtCheckedAt;
|
|
131
|
+
return carried;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
export function withViewOrigin(row, callStartedAtMs) {
|
|
135
|
+
const recipients = row.recipients.map((r) => {
|
|
136
|
+
let viewedAtOrigin;
|
|
137
|
+
if (r.viewedAtSource === 'detail') {
|
|
138
|
+
const at = r.viewedAtCheckedAt === undefined ? NaN : Date.parse(r.viewedAtCheckedAt);
|
|
139
|
+
viewedAtOrigin = at >= callStartedAtMs ? 'detail-this-call' : 'detail-cached';
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
viewedAtOrigin = r.viewedAtSource ?? 'unrecorded';
|
|
143
|
+
}
|
|
144
|
+
return { ...r, viewedAtOrigin };
|
|
90
145
|
});
|
|
146
|
+
return { ...row, recipients };
|
|
91
147
|
}
|
|
92
148
|
// True if any recipient has a *real* "First Viewed" time — i.e. present and
|
|
93
149
|
// not the epoch-zero placeholder. After mapRecipients a fresh `viewedAt` is
|
package/dist/tools/messages.js
CHANGED
|
@@ -16,7 +16,7 @@ import { resolveDownloadMime, resolveSaveDest } from './attachments.js';
|
|
|
16
16
|
import { getAllowMarkRead, getConfirmMarkRead, getAttachmentsDir, getAutoRefreshStaleReads, getDefaultInlineAttachments, getFetchUnreadBodies, getSyncMaxRequests, getWriteMode, } from '../config.js';
|
|
17
17
|
import { basename, resolve } from 'node:path';
|
|
18
18
|
import { randomUUID } from 'node:crypto';
|
|
19
|
-
import { ApiRecipientSchema, deriveRead, draftReplyTarget, hasRealView, jsonErrorResponse, jsonResponse, jsonText, mapRecipients, notedJsonResponse, postMessageAndRefetch, reportsThreaded, UnconfirmedWriteError, reportsUnthreaded, threadedReplyTo, verifyWriteLanded, withReadState } from './_shared.js';
|
|
19
|
+
import { ApiRecipientSchema, deriveRead, detailRecipients, mergeRecipients, withViewOrigin, draftReplyTarget, hasRealView, jsonErrorResponse, jsonResponse, jsonText, mapRecipients, notedJsonResponse, postMessageAndRefetch, reportsThreaded, UnconfirmedWriteError, reportsUnthreaded, threadedReplyTo, verifyWriteLanded, withReadState } from './_shared.js';
|
|
20
20
|
import { parseLenient } from '@chrischall/mcp-utils';
|
|
21
21
|
import { pageState } from './pagination.js';
|
|
22
22
|
import { compactSentMessage, compactWrittenDraft, MESSAGE_VIEWS, senderOf, viewDrafts, viewMessages, viewOne } from './project.js';
|
|
@@ -27,6 +27,7 @@ const WRITE_VIEW_NOTE = 'compact omits OurFamilyWizard\'s raw `listData` echo (w
|
|
|
27
27
|
import { resolveView, viewParam } from '@chrischall/mcp-utils';
|
|
28
28
|
import { displayTimeZone, formatInstant, normalizeTimestampsInValue, nowNaiveWallClock, toNaiveWallClock } from '../timestamps.js';
|
|
29
29
|
import { READ_OVERRIDE_NOTE, UNREAD_ON_NO_READ_DAY, auditReadOverride, readingBlockedToday } from '../read-days.js';
|
|
30
|
+
import { BODY_FORMAT_DESCRIPTION, prepareBody } from './plain-text.js';
|
|
30
31
|
/** Why a draft has no draftKey — said instead of a bare null. */
|
|
31
32
|
export const DRAFT_KEY_NULL_REASON = 'No draftKey: this draft was not saved through this server\'s cache — it may have been created in the OurFamilyWizard web app or replaced from another session — so its lineage is unknown. The next ofw_save_draft on it starts a new key.';
|
|
32
33
|
/** `{draftKey, draftKeyInferred?}` or `{draftKey: null, draftKeyReason}` for one draft. */
|
|
@@ -303,11 +304,12 @@ async function unreadCandidates(cache) {
|
|
|
303
304
|
*/
|
|
304
305
|
async function openUnreadBody(client, cache, cached) {
|
|
305
306
|
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)' });
|
|
307
|
+
const checkedAt = new Date().toISOString();
|
|
306
308
|
await cache.upsertMessage({
|
|
307
309
|
...cached,
|
|
308
|
-
recipients:
|
|
310
|
+
recipients: mergeRecipients(cached.recipients, detailRecipients(detail.recipients, checkedAt)),
|
|
309
311
|
body: detail.body ?? '',
|
|
310
|
-
fetchedBodyAt:
|
|
312
|
+
fetchedBodyAt: checkedAt,
|
|
311
313
|
});
|
|
312
314
|
if (Array.isArray(detail.files) && detail.files.length > 0) {
|
|
313
315
|
await fetchAttachmentMetaForMessage(client, cached.id, detail.files, cache);
|
|
@@ -508,6 +510,10 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
508
510
|
view: LIST_MESSAGES_VIEW,
|
|
509
511
|
}),
|
|
510
512
|
}, async (args) => {
|
|
513
|
+
// The instant this call began: a recipient view time read from OFW's detail
|
|
514
|
+
// at or after it is labelled `detail-this-call`, anything older came from
|
|
515
|
+
// the cache (withViewOrigin, issue #448).
|
|
516
|
+
const callStartedAt = Date.now();
|
|
511
517
|
const page = args.page ?? 1;
|
|
512
518
|
const size = args.size ?? 50;
|
|
513
519
|
const sort = args.sort ?? 'newest';
|
|
@@ -577,7 +583,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
577
583
|
// can be stale (a message read after it was first scraped), so `read`
|
|
578
584
|
// is derived from the record's own `viewedAt`/`fetchedBodyAt` and
|
|
579
585
|
// `listData` is forced to agree — see withReadState.
|
|
580
|
-
const messages = (await cache.listMessages({ ...filter, page, size, sort })).map((m) => withReadState(m));
|
|
586
|
+
const messages = (await cache.listMessages({ ...filter, page, size, sort })).map((m) => withViewOrigin(withReadState(m), callStartedAt));
|
|
581
587
|
// Served from the local cache, so the result must say how old it is and
|
|
582
588
|
// whether anything vouches for it — a caller cannot state current state
|
|
583
589
|
// from this payload without either re-reading or surfacing the caveat.
|
|
@@ -683,7 +689,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
683
689
|
});
|
|
684
690
|
server.registerTool('ofw_get_message', {
|
|
685
691
|
_meta: familyMeta('lookup'),
|
|
686
|
-
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) only an UNREAD inbox message is protected: its body is withheld (body:null, bodyWithheld:true, withheldReason:"UNREAD_ON_NO_READ_DAY", readingBlocked says when reading resumes) and OFW is never contacted for it; an id not in the cache is refused, since fetching it could mark it read. Sent messages and inbox messages already read are returned exactly as on a reading day. 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.' + OVERRIDE_DESCRIPTION,
|
|
692
|
+
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) only an UNREAD inbox message is protected: its body is withheld (body:null, bodyWithheld:true, withheldReason:"UNREAD_ON_NO_READ_DAY", readingBlocked says when reading resumes) and OFW is never contacted for it; an id not in the cache is refused, since fetching it could mark it read. Sent messages and inbox messages already read are returned exactly as on a reading day. 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. Each recipient\'s `viewedAt` carries its provenance: `viewedAtOrigin` is "detail-this-call" (read from OurFamilyWizard during this call), "detail-cached" (from an earlier read — see `viewedAtCheckedAt`), "list" (only the list was seen, so a null `viewedAt` means UNKNOWN, not unviewed) or "unrecorded". `viewedPlaceholder` is OurFamilyWizard\'s raw 1970 placeholder, kept as source data — it is never a view time.' + OVERRIDE_DESCRIPTION,
|
|
687
693
|
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
688
694
|
inputSchema: z.object({
|
|
689
695
|
messageId: z.string().describe('Message ID (also accepts draft IDs — drafts are routed via the drafts cache)'),
|
|
@@ -695,6 +701,10 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
695
701
|
confirmToken: confirmTokenParam,
|
|
696
702
|
}),
|
|
697
703
|
}, async (args, ctx) => {
|
|
704
|
+
// The instant this call began: a recipient view time read from OFW's detail
|
|
705
|
+
// at or after it is labelled `detail-this-call`, anything older came from
|
|
706
|
+
// the cache (withViewOrigin, issue #448).
|
|
707
|
+
const callStartedAt = Date.now();
|
|
698
708
|
const id = Number(args.messageId);
|
|
699
709
|
const view = resolveView(args.view, MESSAGE_VIEWS);
|
|
700
710
|
const cache = cacheProvider();
|
|
@@ -779,7 +789,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
779
789
|
const freshness = await buildFreshness(cache, { source: 'cache', folders: [cached.folder] });
|
|
780
790
|
return jsonResponse({
|
|
781
791
|
readingBlocked: blocked,
|
|
782
|
-
...viewOne(view, withholdBody(withReadState(cached))),
|
|
792
|
+
...viewOne(view, withholdBody(withViewOrigin(withReadState(cached), callStartedAt))),
|
|
783
793
|
attachments,
|
|
784
794
|
freshness,
|
|
785
795
|
});
|
|
@@ -796,7 +806,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
796
806
|
if (cached.folder === 'sent' && !hasRealView(cached.recipients)) {
|
|
797
807
|
try {
|
|
798
808
|
const detail = parseLenient(MessageDetailSchema, await client.request('GET', `/pub/v3/messages/${id}`), { label: 'ofw-mcp', context: 'GET /pub/v3/messages/{id} (view-status refresh)' });
|
|
799
|
-
const recipients =
|
|
809
|
+
const recipients = mergeRecipients(cached.recipients, detailRecipients(detail.recipients, new Date().toISOString()));
|
|
800
810
|
// Keep the raw listData read-flag in step with the refreshed
|
|
801
811
|
// recipients so `showNeverViewed` can't contradict `viewedAt`.
|
|
802
812
|
// (Spreading a null/absent listData is a no-op, so no guard needed.)
|
|
@@ -837,7 +847,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
837
847
|
const freshness = await buildFreshness(cache, { source: 'cache', folders: [row.folder] });
|
|
838
848
|
return jsonResponse({
|
|
839
849
|
...(overriding ? readOverrideFields('ofw_get_message', [row.id]) : {}),
|
|
840
|
-
...viewOne(view, withReadState(row)),
|
|
850
|
+
...viewOne(view, withViewOrigin(withReadState(row), callStartedAt)),
|
|
841
851
|
attachments,
|
|
842
852
|
freshness,
|
|
843
853
|
});
|
|
@@ -868,15 +878,16 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
868
878
|
folder = 'sent';
|
|
869
879
|
}
|
|
870
880
|
}
|
|
881
|
+
const fetchedBodyAt = new Date().toISOString();
|
|
871
882
|
const row = {
|
|
872
883
|
id: detail.id,
|
|
873
884
|
folder,
|
|
874
885
|
subject: detail.subject,
|
|
875
886
|
fromUser: detail.from?.name ?? '',
|
|
876
887
|
sentAt: detail.date?.dateTime ?? nowNaiveWallClock(),
|
|
877
|
-
recipients:
|
|
888
|
+
recipients: mergeRecipients(cached?.recipients, detailRecipients(detail.recipients, fetchedBodyAt)),
|
|
878
889
|
body: detail.body ?? '',
|
|
879
|
-
fetchedBodyAt
|
|
890
|
+
fetchedBodyAt,
|
|
880
891
|
replyToId: cached?.replyToId ?? null,
|
|
881
892
|
chainRootId: cached?.chainRootId ?? null,
|
|
882
893
|
listData: cached?.listData ?? detail,
|
|
@@ -890,7 +901,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
890
901
|
const freshness = await buildFreshness(cache, { source: 'live', folders: [folder] });
|
|
891
902
|
return jsonResponse({
|
|
892
903
|
...(overriding ? readOverrideFields('ofw_get_message', [row.id]) : {}),
|
|
893
|
-
...viewOne(view, withReadState(row)),
|
|
904
|
+
...viewOne(view, withViewOrigin(withReadState(row), callStartedAt)),
|
|
894
905
|
attachments,
|
|
895
906
|
freshness,
|
|
896
907
|
});
|
|
@@ -903,6 +914,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
903
914
|
inputSchema: z.object({
|
|
904
915
|
subject: z.string().describe('Message subject. Required unless draftId/messageId is given (then it overrides the server draft\'s subject).').optional(),
|
|
905
916
|
body: z.string().describe('Message body text. Required unless draftId/messageId is given (then it overrides the server draft\'s body — omit it to send exactly what is on OurFamilyWizard).').optional(),
|
|
917
|
+
bodyFormat: z.enum(['markdown', 'plain']).describe(`${BODY_FORMAT_DESCRIPTION} Applies only to a body passed here: a draft sent by id goes out exactly as it is on OurFamilyWizard.`).optional(),
|
|
906
918
|
recipientIds: z.array(z.number()).describe('Array of recipient user IDs (get from ofw_get_profile). Usually required even when sending a draft: OurFamilyWizard does not persist recipients on drafts.').optional(),
|
|
907
919
|
replyToId: z.number().describe('ID of the message being replied to. Defaults to the draft\'s stored reply target when sending by draftId.').optional(),
|
|
908
920
|
draftId: z.number().describe('ID of an existing draft to send. The draft is re-read from OurFamilyWizard and its SERVER content is sent; missing subject/body default from it. Guarded: a draft that changed since you read it, or that was already sent/deleted, refuses rather than sending blind.').optional(),
|
|
@@ -929,7 +941,10 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
929
941
|
const blobStore = args.blobKeys?.length ? blobStoreFromEnv() : undefined;
|
|
930
942
|
const pending = await planAttachments({ inline: args.inlineAttachments, blobKeys: args.blobKeys }, { store: blobStore, readBlobs: true });
|
|
931
943
|
let subject = args.subject;
|
|
932
|
-
|
|
944
|
+
// Only a body the CALLER supplies is converted. A draft sent by id goes
|
|
945
|
+
// out as it is on OFW — the artifact sent is the artifact on the server.
|
|
946
|
+
const prepared = args.body === undefined ? null : prepareBody(args.body, args.bodyFormat);
|
|
947
|
+
let body = prepared?.body;
|
|
933
948
|
let recipientIds = args.recipientIds;
|
|
934
949
|
let draftReplyToId = null;
|
|
935
950
|
let guardNote = null;
|
|
@@ -1044,6 +1059,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1044
1059
|
: {}),
|
|
1045
1060
|
subject,
|
|
1046
1061
|
body,
|
|
1062
|
+
...(prepared?.conversion ? { bodyConversion: prepared.conversion } : {}),
|
|
1047
1063
|
replyTo: resolvedReplyTo === null
|
|
1048
1064
|
? null
|
|
1049
1065
|
: { messageId: resolvedReplyTo, subject: replyParent?.subject ?? null, from: replyParent?.fromUser || null },
|
|
@@ -1168,7 +1184,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1168
1184
|
// omitted or empty recipients array is "not echoed" (OFW routinely
|
|
1169
1185
|
// echoes [] the way it does on drafts), and crying wolf on it would
|
|
1170
1186
|
// retain the draft after every ordinary send.
|
|
1171
|
-
const storedRecipients = mapRecipients(detail.recipients);
|
|
1187
|
+
const storedRecipients = mapRecipients(detail.recipients, { source: 'detail', checkedAt: new Date().toISOString() });
|
|
1172
1188
|
if (Array.isArray(detail.recipients) && detail.recipients.length > 0) {
|
|
1173
1189
|
const landed = new Set(storedRecipients.map((r) => r.userId));
|
|
1174
1190
|
const missingRecipients = recipientIds.filter((rid) => !landed.has(rid));
|
|
@@ -1288,8 +1304,9 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1288
1304
|
...(attachmentCheck !== null ? { attachments: attachmentCheck } : {}),
|
|
1289
1305
|
...(newFiles.length > 0 ? { attachmentsUploaded: newFiles } : {}),
|
|
1290
1306
|
...(uploadWarnings.length > 0 ? { warnings: uploadWarnings } : {}),
|
|
1307
|
+
...(prepared?.conversion ? { bodyConversion: prepared.conversion } : {}),
|
|
1291
1308
|
};
|
|
1292
|
-
return notedJsonResponse([guardNote, rewriteNote, verifyNote, threadNote, attachmentNote, unconfirmedNote, retainNote], responseObj, 'Message sent successfully.');
|
|
1309
|
+
return notedJsonResponse([guardNote, rewriteNote, prepared?.noteLine ?? null, verifyNote, threadNote, attachmentNote, unconfirmedNote, retainNote], responseObj, 'Message sent successfully.');
|
|
1293
1310
|
});
|
|
1294
1311
|
async function guardDestructiveDraftOp(input) {
|
|
1295
1312
|
const { cache, draftId, expectedRevision, force, action } = input;
|
|
@@ -1497,6 +1514,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1497
1514
|
inputSchema: z.object({
|
|
1498
1515
|
subject: z.string().describe('Message subject'),
|
|
1499
1516
|
body: z.string().describe('Message body text'),
|
|
1517
|
+
bodyFormat: z.enum(['markdown', 'plain']).describe(BODY_FORMAT_DESCRIPTION).optional(),
|
|
1500
1518
|
recipientIds: z.array(z.number()).describe('Array of recipient user IDs (optional for drafts)').optional(),
|
|
1501
1519
|
messageId: z.number().describe('ID of an existing draft to replace (the new draft will have a new id; the old is deleted)').optional(),
|
|
1502
1520
|
replyToId: z.number().nullable().describe('ID of the message this draft replies to. When replacing a draft (messageId), omit it to keep the draft\'s own reply target, or pass null to make the draft a new top-level message.').optional(),
|
|
@@ -1511,6 +1529,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1511
1529
|
}, async (args) => {
|
|
1512
1530
|
const cache = cacheProvider();
|
|
1513
1531
|
const view = resolveView(args.view, MESSAGE_VIEWS);
|
|
1532
|
+
const prepared = prepareBody(args.body, args.bodyFormat);
|
|
1514
1533
|
// New attachments are validated before ANYTHING happens, so a bad entry
|
|
1515
1534
|
// fails the call with nothing uploaded and nothing saved.
|
|
1516
1535
|
const blobStore = args.blobKeys?.length ? blobStoreFromEnv() : undefined;
|
|
@@ -1576,7 +1595,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1576
1595
|
// messageId, we delete the old draft afterward (the "replace" path).
|
|
1577
1596
|
const payload = {
|
|
1578
1597
|
subject: args.subject,
|
|
1579
|
-
body:
|
|
1598
|
+
body: prepared.body,
|
|
1580
1599
|
recipientIds: args.recipientIds ?? serverRecipientIds ?? [],
|
|
1581
1600
|
attachments: { myFileIDs },
|
|
1582
1601
|
draft: true,
|
|
@@ -1597,7 +1616,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1597
1616
|
// loss must be reported. Never a silent drop (Defect 3).
|
|
1598
1617
|
const warnings = [...uploadWarnings];
|
|
1599
1618
|
if (newId !== null) {
|
|
1600
|
-
verifyNote = verifyWriteLanded('draft', { subject: args.subject, body:
|
|
1619
|
+
verifyNote = verifyWriteLanded('draft', { subject: args.subject, body: prepared.body }, detail);
|
|
1601
1620
|
// Trust the re-fetched server detail as the source of truth for the stored
|
|
1602
1621
|
// replyToId — NOT `resolvedReplyTo` (what we intended to post). OFW
|
|
1603
1622
|
// normalizes/drops threading after a save, and masking that with our own
|
|
@@ -1755,12 +1774,13 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1755
1774
|
...(newFiles.length > 0 ? { attachmentsUploaded: newFiles } : {}),
|
|
1756
1775
|
...(warnings.length > 0 ? { warnings } : {}),
|
|
1757
1776
|
...(recipientsNote !== null ? { recipientsNote } : {}),
|
|
1777
|
+
...(prepared.conversion !== null ? { bodyConversion: prepared.conversion } : {}),
|
|
1758
1778
|
}
|
|
1759
1779
|
: raw;
|
|
1760
1780
|
const warnNote = warnings.length > 0
|
|
1761
1781
|
? `WARNING: ${warnings.join('\n\n')}`
|
|
1762
1782
|
: null;
|
|
1763
|
-
return notedJsonResponse([forceNote, rewriteNote, verifyNote, warnNote, recipientsNote, replaceNote], responseObj, 'Draft saved.');
|
|
1783
|
+
return notedJsonResponse([forceNote, rewriteNote, prepared.noteLine, verifyNote, warnNote, recipientsNote, replaceNote], responseObj, 'Draft saved.');
|
|
1764
1784
|
});
|
|
1765
1785
|
if (allowDrafts)
|
|
1766
1786
|
server.registerTool('ofw_delete_draft', {
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown → plain text for OurFamilyWizard message bodies.
|
|
3
|
+
*
|
|
4
|
+
* OFW renders a body as plain text: verified in the web app 2026-11-11, the
|
|
5
|
+
* read view HTML-escapes the body (a `&` arrives as `&`), auto-links
|
|
6
|
+
* https URLs, emails and phone numbers, and shows it in a `white-space:
|
|
7
|
+
* pre-wrap` span. Markdown is never rendered, so `**urgent**` reaches the
|
|
8
|
+
* co-parent — and the court-visible record — with its asterisks. Models write
|
|
9
|
+
* Markdown by habit, so the write tools run the body through this first.
|
|
10
|
+
*
|
|
11
|
+
* Rules, all deliberately conservative (when in doubt, leave the text alone):
|
|
12
|
+
* - bold/italic markers are stripped; word-internal `_`/`*` (snake_case,
|
|
13
|
+
* a*b) and spaced `*` (3 * 4) are not emphasis
|
|
14
|
+
* - `[text](url)` → `text (url)` (OFW auto-links the url); `<url>` → url
|
|
15
|
+
* - `# Heading` → `Heading`
|
|
16
|
+
* - lists: `*`/`+` → `-`; 4 spaces per nesting level; numbered lists are
|
|
17
|
+
* renumbered from their first number (Markdown's `1. 1. 1.` means 1, 2, 3),
|
|
18
|
+
* the second level is lettered (a., b.), and markers are padded so item
|
|
19
|
+
* text lines up past 9
|
|
20
|
+
* - code spans, fenced blocks, URLs and ~~strikethrough~~ (stripping it would
|
|
21
|
+
* invert its meaning) are left exactly as written
|
|
22
|
+
*
|
|
23
|
+
* Idempotent: converting the output again changes nothing, so a draft that
|
|
24
|
+
* is re-saved does not drift. When nothing changes the input is returned
|
|
25
|
+
* byte-for-byte (line endings included).
|
|
26
|
+
*/
|
|
27
|
+
const CHANGE_ORDER = [
|
|
28
|
+
'headings', 'bold/italic', 'links', 'list markers', 'list numbering', 'list indentation',
|
|
29
|
+
];
|
|
30
|
+
const PH_OPEN = '';
|
|
31
|
+
const PH_CLOSE = '';
|
|
32
|
+
const PLACEHOLDER = /(\d+)/g;
|
|
33
|
+
function convertInline(line, changes) {
|
|
34
|
+
// A body that already holds our private-use markers is left alone rather
|
|
35
|
+
// than risk restoring the wrong span into it.
|
|
36
|
+
if (line.includes(PH_OPEN) || line.includes(PH_CLOSE))
|
|
37
|
+
return line;
|
|
38
|
+
const kept = [];
|
|
39
|
+
const protect = (s) => `${PH_OPEN}${kept.push(s) - 1}${PH_CLOSE}`;
|
|
40
|
+
let s = line.replace(/(`+)[^`]+?\1(?!`)/g, protect);
|
|
41
|
+
const beforeLinks = s;
|
|
42
|
+
s = s.replace(/<(https?:\/\/[^\s<>]+)>/g, (_m, url) => protect(url));
|
|
43
|
+
s = s.replace(/!?\[([^\]\n]+)\]\(([^)\s]+)\)/g, (_m, text, url) => {
|
|
44
|
+
const bare = (u) => u.replace(/^https?:\/\//, '').replace(/\/$/, '');
|
|
45
|
+
return bare(text) === bare(url) ? protect(url) : `${text} (${protect(url)})`;
|
|
46
|
+
});
|
|
47
|
+
if (s !== beforeLinks)
|
|
48
|
+
changes.add('links');
|
|
49
|
+
s = s.replace(/https?:\/\/\S+/g, protect);
|
|
50
|
+
const beforeEmphasis = s;
|
|
51
|
+
s = s.replace(/\*\*(?=\S)(.+?)(?<=\S)\*\*/g, '$1');
|
|
52
|
+
s = s.replace(/(?<![\w_])__(?=\S)(.+?)(?<=\S)__(?![\w_])/g, '$1');
|
|
53
|
+
s = s.replace(/(?<![\w*])\*(?![\s*])(.+?)(?<![\s*])\*(?![\w*])/g, '$1');
|
|
54
|
+
s = s.replace(/(?<![\w_])_(?![\s_])(.+?)(?<![\s_])_(?![\w_])/g, '$1');
|
|
55
|
+
if (s !== beforeEmphasis)
|
|
56
|
+
changes.add('bold/italic');
|
|
57
|
+
while (s.includes(PH_OPEN)) {
|
|
58
|
+
s = s.replace(PLACEHOLDER, (_m, i) => kept[Number(i)]);
|
|
59
|
+
}
|
|
60
|
+
return s;
|
|
61
|
+
}
|
|
62
|
+
const HEADING = /^ {0,3}#{1,6}[ \t]+(.*?)(?:[ \t]+#+)?[ \t]*$/;
|
|
63
|
+
const FENCE = /^ {0,3}(`{3,}|~{3,})/;
|
|
64
|
+
const ITEM = /^([ \t]*)([-*+]|\d{1,9}[.)]|[a-z]{1,2}[.)])([ \t]+)(\S.*)$/;
|
|
65
|
+
function indentWidth(ws) {
|
|
66
|
+
let n = 0;
|
|
67
|
+
for (const ch of ws)
|
|
68
|
+
n += ch === '\t' ? 4 : 1;
|
|
69
|
+
return n;
|
|
70
|
+
}
|
|
71
|
+
/** a=1 … z=26, aa=27 … */
|
|
72
|
+
function alphaIndex(token) {
|
|
73
|
+
let n = 0;
|
|
74
|
+
for (const ch of token)
|
|
75
|
+
n = n * 26 + (ch.charCodeAt(0) - 96);
|
|
76
|
+
return n;
|
|
77
|
+
}
|
|
78
|
+
function toAlpha(n) {
|
|
79
|
+
let s = '';
|
|
80
|
+
for (let k = Math.max(1, n); k > 0; k = Math.floor((k - 1) / 26)) {
|
|
81
|
+
s = String.fromCharCode(97 + ((k - 1) % 26)) + s;
|
|
82
|
+
}
|
|
83
|
+
return s;
|
|
84
|
+
}
|
|
85
|
+
export function markdownToPlainText(input) {
|
|
86
|
+
const eol = input.includes('\r\n') ? '\r\n' : '\n';
|
|
87
|
+
const lines = input.split(/\r?\n/);
|
|
88
|
+
const out = [...lines];
|
|
89
|
+
const changes = new Set();
|
|
90
|
+
const runs = [];
|
|
91
|
+
let fence = null;
|
|
92
|
+
let stack = [];
|
|
93
|
+
let prevBlank = true;
|
|
94
|
+
const endList = () => { stack = []; };
|
|
95
|
+
lines.forEach((line, i) => {
|
|
96
|
+
if (fence !== null) {
|
|
97
|
+
if (line.trimStart().startsWith(fence))
|
|
98
|
+
fence = null;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const fenceOpen = FENCE.exec(line);
|
|
102
|
+
if (fenceOpen) {
|
|
103
|
+
fence = fenceOpen[1];
|
|
104
|
+
endList();
|
|
105
|
+
prevBlank = false;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (line.trim() === '') {
|
|
109
|
+
prevBlank = true;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const m = ITEM.exec(line);
|
|
113
|
+
if (m) {
|
|
114
|
+
const [, ws, marker, sep, content] = m;
|
|
115
|
+
const indent = indentWidth(ws);
|
|
116
|
+
const bullet = /^[-*+]$/.test(marker);
|
|
117
|
+
const letter = /^[a-z]/.test(marker);
|
|
118
|
+
const token = bullet ? '' : marker.slice(0, -1);
|
|
119
|
+
const accepted = letter
|
|
120
|
+
? stack.length > 0 && indent >= stack[0].indent + 2
|
|
121
|
+
: stack.length > 0 || prevBlank || bullet || token === '1';
|
|
122
|
+
if (accepted) {
|
|
123
|
+
const kind = bullet ? 'bullet' : 'ordered';
|
|
124
|
+
const start = bullet ? 0 : letter ? alphaIndex(token) : Number(token);
|
|
125
|
+
const item = { line: i, indent: ws, marker, sep, content };
|
|
126
|
+
const newRun = (level) => {
|
|
127
|
+
const run = { kind, level, start, items: [item] };
|
|
128
|
+
runs.push(run);
|
|
129
|
+
return run;
|
|
130
|
+
};
|
|
131
|
+
if (stack.length === 0) {
|
|
132
|
+
stack.push({ indent, run: newRun(0) });
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
while (stack.length > 1 && indent <= stack[stack.length - 1].indent - 2)
|
|
136
|
+
stack.pop();
|
|
137
|
+
const top = stack[stack.length - 1];
|
|
138
|
+
if (indent >= top.indent + 2) {
|
|
139
|
+
stack.push({ indent, run: newRun(stack.length) });
|
|
140
|
+
}
|
|
141
|
+
else if (top.run.kind !== kind) {
|
|
142
|
+
top.run = newRun(stack.length - 1);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
top.run.items.push(item);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
prevBlank = false;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (stack.length > 0 && /^[ \t]/.test(line)) {
|
|
153
|
+
// An indented line inside a list continues the item above it.
|
|
154
|
+
out[i] = convertInline(line, changes);
|
|
155
|
+
prevBlank = false;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
endList();
|
|
159
|
+
const heading = HEADING.exec(line);
|
|
160
|
+
if (heading) {
|
|
161
|
+
out[i] = convertInline(heading[1], changes);
|
|
162
|
+
changes.add('headings');
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
out[i] = convertInline(line, changes);
|
|
166
|
+
}
|
|
167
|
+
prevBlank = false;
|
|
168
|
+
});
|
|
169
|
+
for (const run of runs) {
|
|
170
|
+
const lettered = run.kind === 'ordered' && run.level % 2 === 1;
|
|
171
|
+
const markers = run.items.map((_, k) => {
|
|
172
|
+
if (run.kind === 'bullet')
|
|
173
|
+
return '-';
|
|
174
|
+
return `${lettered ? toAlpha(run.start + k) : run.start + k}.`;
|
|
175
|
+
});
|
|
176
|
+
const width = Math.max(...markers.map((mk) => mk.length));
|
|
177
|
+
run.items.forEach((item, k) => {
|
|
178
|
+
const indent = ' '.repeat(4 * run.level);
|
|
179
|
+
const sep = ' '.repeat(width - markers[k].length + 1);
|
|
180
|
+
if (indent !== item.indent)
|
|
181
|
+
changes.add('list indentation');
|
|
182
|
+
const origToken = item.marker.replace(/[.)]$/, '');
|
|
183
|
+
const newToken = markers[k].replace(/\.$/, '');
|
|
184
|
+
if (run.kind === 'bullet' ? item.marker !== '-' : item.marker.endsWith(')'))
|
|
185
|
+
changes.add('list markers');
|
|
186
|
+
if (run.kind === 'ordered' && origToken !== newToken)
|
|
187
|
+
changes.add('list numbering');
|
|
188
|
+
if (sep !== item.sep)
|
|
189
|
+
changes.add(run.kind === 'ordered' && width > 2 ? 'list numbering' : 'list markers');
|
|
190
|
+
out[item.line] = `${indent}${markers[k]}${sep}${convertInline(item.content, changes)}`;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (changes.size === 0)
|
|
194
|
+
return { text: input, changes: [] };
|
|
195
|
+
return { text: out.join(eol), changes: CHANGE_ORDER.filter((c) => changes.has(c)) };
|
|
196
|
+
}
|
|
197
|
+
export const BODY_FORMAT_DESCRIPTION = 'How to treat `body`. OurFamilyWizard shows message bodies as PLAIN TEXT — Markdown is never rendered, so **bold** would reach the co-parent with its asterisks. Default "markdown": Markdown is converted to plain text before anything is saved or sent (bold/italic markers and # heading markers dropped; [text](url) → "text (url)"; lists normalized to "-" bullets and renumbered 1., 2., … with a., b. for the second level, 4 spaces per nesting level; code, URLs and ~~strikethrough~~ left as written), and the response reports what changed under bodyConversion. "plain": send the body byte-for-byte. Line breaks, blank lines and leading spaces always survive; full https:// URLs, email addresses and phone numbers become links for the reader.';
|
|
198
|
+
/** Apply the write tools' `bodyFormat` to a caller-supplied body. */
|
|
199
|
+
export function prepareBody(body, format) {
|
|
200
|
+
if (format === 'plain')
|
|
201
|
+
return { body, conversion: null, noteLine: null };
|
|
202
|
+
const { text, changes } = markdownToPlainText(body);
|
|
203
|
+
if (changes.length === 0)
|
|
204
|
+
return { body, conversion: null, noteLine: null };
|
|
205
|
+
const note = `OurFamilyWizard shows bodies as plain text, so Markdown was converted (${changes.join(', ')}). What was saved/sent is the converted text; pass bodyFormat:"plain" to send a body exactly as written.`;
|
|
206
|
+
return {
|
|
207
|
+
body: text,
|
|
208
|
+
conversion: { changes, note },
|
|
209
|
+
noteLine: `NOTE: the body was converted from Markdown to plain text (${changes.join(', ')}).`,
|
|
210
|
+
};
|
|
211
|
+
}
|
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.29.1'; // 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.
|
|
9
|
+
"version": "2.29.1",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "ofw-mcp",
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.29.1",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|
package/skills/ofw/SKILL.md
CHANGED
|
@@ -93,11 +93,11 @@ Always pass `--config ~/.mcporter/mcporter.json` unless a local `config/mcporter
|
|
|
93
93
|
| `ofw_sync_messages(folders?, deep?, fetchUnreadBodies?)` | Sync OFW → local cache. **Call first if the cache might be stale.** Never marks anything read unless `fetchUnreadBodies` is set. `newMessages` lists every message this call cached for the first time (newest first, with `read` and `bodyFetched`; `newMessagesTotal`/`newMessagesTruncated` when more than 50 arrived), so tell the user what arrived from that list. `unreadInbox` lists the new inbox messages that were unread when the sync began (`bodyFetched:false` = still unread). If the response leads with a `warning` and a `markedRead` list, the sync marked those messages read on OFW; tell the user, and stress any with `reason: "unexpected"`. 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. 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
|
-
| `ofw_send_message(draftId?, subject?, body?, recipientIds?, replyToId?, expectedRevision?, deleteDraftOnSuccess?, myFileIDs?, inlineAttachments?, blobKeys?, 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`. Sending a draft attaches its held files as they are (PRIVATE files attach fine); new files upload PRIVATE only after approval, and the response's `attachments.verified`/`missing` says what OFW actually attached. A replace without `recipientIds` keeps the draft's recipients. A draft with no `draftKey` says why (`draftKeyReason`). |
|
|
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. When citing a "First Viewed" time, check the recipient's `viewedAtOrigin`: `detail-this-call` was read from OFW just now, `detail-cached` is carried forward from an earlier read (`viewedAtCheckedAt`), `list` means unknown. Never cite `viewedPlaceholder` (OFW's 1970 placeholder) as a view time. |
|
|
97
|
+
| `ofw_send_message(draftId?, subject?, body?, bodyFormat?, recipientIds?, replyToId?, expectedRevision?, deleteDraftOnSuccess?, myFileIDs?, inlineAttachments?, blobKeys?, 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`. Sending a draft attaches its held files as they are (PRIVATE files attach fine); new files upload PRIVATE only after approval, and the response's `attachments.verified`/`missing` says what OFW actually attached. A replace without `recipientIds` keeps the draft's recipients. A draft with no `draftKey` says why (`draftKeyReason`). |
|
|
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). |
|
|
100
|
-
| `ofw_save_draft(subject, body, recipientIds?, messageId?, replyToId?, myFileIDs?, removeFileIDs?, inlineAttachments?, blobKeys?, expectedRevision?, force?)` | Create a new draft. Pass `messageId` to **replace** an existing draft: the tool creates a fresh draft and deletes the old one (OFW's update-in-place endpoint silently no-ops). The returned `id` is the NEW id; the response leads with `draftKey`, which stays the same across every edit — **track that, not the id**. Note: OFW does **not** store recipients on drafts — `recipientIds` are accepted but come back empty (a one-line NOTE says so; supply them at send time instead). Threading warnings fire only on genuine drops — a draft echoing `inReplyTo`/`showContext` IS threaded. **OFW drafts can't hold files**: attachments are HELD by the server (`attachments.held`), kept across edits (`removeFileIDs` drops one), and attached when the draft is sent. They don't appear on the draft in the OFW web app; that's expected. `inlineAttachments`/`blobKeys` upload and add new files in the same call. |
|
|
100
|
+
| `ofw_save_draft(subject, body, bodyFormat?, recipientIds?, messageId?, replyToId?, myFileIDs?, removeFileIDs?, inlineAttachments?, blobKeys?, expectedRevision?, force?)` | Create a new draft. Pass `messageId` to **replace** an existing draft: the tool creates a fresh draft and deletes the old one (OFW's update-in-place endpoint silently no-ops). The returned `id` is the NEW id; the response leads with `draftKey`, which stays the same across every edit — **track that, not the id**. Note: OFW does **not** store recipients on drafts — `recipientIds` are accepted but come back empty (a one-line NOTE says so; supply them at send time instead). Threading warnings fire only on genuine drops — a draft echoing `inReplyTo`/`showContext` IS threaded. **OFW drafts can't hold files**: attachments are HELD by the server (`attachments.held`), kept across edits (`removeFileIDs` drops one), and attached when the draft is sent. They don't appear on the draft in the OFW web app; that's expected. `inlineAttachments`/`blobKeys` upload and add new files in the same call. |
|
|
101
101
|
| `ofw_delete_draft(messageId)` | Delete a draft. |
|
|
102
102
|
| `ofw_upload_attachment(path \| inline \| uploadSlots \| blobKeys, shareClass?, label?, description?)` | Upload to My Files; returns fileIds for `myFileIDs`. Exactly one source. **Hosted connector (claude.ai): `path` cannot work.** For real files (photos), call `uploadSlots:[{filename}]`, run each slot's `curl` with the file, then call again with `blobKeys`; for a small file pass `inline:{filename, contentBase64}`. Local installs: `path` inside the upload directory (`OFW_UPLOAD_DIR`). Up to 10 files per call, 25 MiB each; a batch reports per-file `results`. `shareClass:"SHARED"` is one file, confirm-gated, mode `all`. |
|
|
103
103
|
| `ofw_download_attachment(fileId, inline?, saveTo?, force?, extract?, maxChars?, parts?, link?, linkMinutes?)` | Download an attachment. Inline delivery returns the first rung that works: image → `ImageContent`; .xlsx/.csv/.pdf/.docx/.pptx/text → **extracted content** under `extracted` (per-sheet CSV, per-page/slide text); anything else → raw bytes. Default writes to `~/Downloads/ofw-mcp/` (add `extract:true` for content too). Use `parts:"1-2"` / a sheet name and `maxChars` on large files. Images and raw bytes over 10 MiB are not returned inline (tool error) — use disk mode or open the file in OFW. On a hosted connector, `inline:false`/`link:true` returns a private expiring download link instead, and an over-10-MiB inline image falls back to one. |
|
|
@@ -270,6 +270,8 @@ Editing a draft mints a **new OFW id every time** — `ofw_save_draft` replaces
|
|
|
270
270
|
2. `ofw_list_messages(folderId)` → list messages
|
|
271
271
|
3. `ofw_get_message(messageId)` → read a specific message
|
|
272
272
|
|
|
273
|
+
**Writing a message body:** OFW shows bodies as plain text — Markdown is never rendered. Write plain text: blank lines between paragraphs, `-` bullets, `1.` numbered lists, full `https://` links (those, emails and phone numbers become clickable). Any Markdown that slips in is converted before saving/sending (`bodyConversion` in the response says what changed; the send preview shows the converted text). `bodyFormat: "plain"` sends a body byte-for-byte.
|
|
274
|
+
|
|
273
275
|
**Send a message:**
|
|
274
276
|
1. `ofw_get_profile` → get co-parent's user ID
|
|
275
277
|
2. `ofw_send_message(subject, body, [coParentId])`
|