@superdoc/mcp 1.10.0-next.12 → 1.10.0-next.13
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/dist/index.js +442 -20
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -31630,7 +31630,7 @@ var init_host = __esm(() => {
|
|
|
31630
31630
|
});
|
|
31631
31631
|
|
|
31632
31632
|
// ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
|
|
31633
|
-
var SDK_VERSION = "2.23.0-next.
|
|
31633
|
+
var SDK_VERSION = "2.23.0-next.13";
|
|
31634
31634
|
|
|
31635
31635
|
// ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
|
|
31636
31636
|
import { accessSync, chmodSync, constants, existsSync, statSync } from "node:fs";
|
|
@@ -93757,7 +93757,7 @@ async function runInsertParagraphs(doc2, args, formatArgs) {
|
|
|
93757
93757
|
kind: "placement",
|
|
93758
93758
|
at: placement.kind === "documentStart" ? "document_start" : "document_end"
|
|
93759
93759
|
});
|
|
93760
|
-
|
|
93760
|
+
let preRows = pre.complete ? await listBlockRows(doc2) : anchor ? [anchor] : [];
|
|
93761
93761
|
let currentPlacement = placement;
|
|
93762
93762
|
const nodeIds = [];
|
|
93763
93763
|
const specs = [];
|
|
@@ -93795,6 +93795,16 @@ async function runInsertParagraphs(doc2, args, formatArgs) {
|
|
|
93795
93795
|
if (!pre.complete) {
|
|
93796
93796
|
const created = await post.page({ nodeIds, limit: Math.max(nodeIds.length, 1) });
|
|
93797
93797
|
localRows = [...anchor ? [anchor] : [], ...created].sort((a, b) => a.ordinal - b.ordinal);
|
|
93798
|
+
const placed = anchor && texts.some((text) => typedMarkerPrefixOf(text)) ? await post.block(anchor.nodeId) : null;
|
|
93799
|
+
if (placed) {
|
|
93800
|
+
const span = TYPED_SIBLING_WINDOW + nodeIds.length;
|
|
93801
|
+
const window2 = await post.page({ offset: Math.max(0, placed.ordinal - 1 - span), limit: 2 * span + 1 });
|
|
93802
|
+
const createdIds = new Set(nodeIds);
|
|
93803
|
+
if (nodeIds.every((id) => window2.some((row) => row.nodeId === id))) {
|
|
93804
|
+
preRows = window2.filter((row) => !createdIds.has(row.nodeId));
|
|
93805
|
+
localRows = window2;
|
|
93806
|
+
}
|
|
93807
|
+
}
|
|
93798
93808
|
}
|
|
93799
93809
|
const count = context.executedOperations.length;
|
|
93800
93810
|
formatted = await matchInsertedBlockFormatting(context.document, preRows, context.receipt("insert_paragraphs", []), formatArgs, localRows);
|
|
@@ -94122,6 +94132,164 @@ async function runDeleteText(doc2, args) {
|
|
|
94122
94132
|
return failedReceipt("delete_text", err, pre);
|
|
94123
94133
|
}
|
|
94124
94134
|
}
|
|
94135
|
+
function enumerationSlotOf(block) {
|
|
94136
|
+
const numbering = blockNumbering(block);
|
|
94137
|
+
const path5 = numbering?.path;
|
|
94138
|
+
if (Array.isArray(path5) && path5.length > 0) {
|
|
94139
|
+
return { key: `scheme:${path5.slice(0, -1).join(".")}:${path5.length}`, depth: path5.length, typed: null };
|
|
94140
|
+
}
|
|
94141
|
+
const markerShape = numbering?.marker ? markerShapeOf(numbering.marker) : null;
|
|
94142
|
+
if (markerShape)
|
|
94143
|
+
return { key: `scheme-marker:${markerShape.wrapper}:${markerShape.kind}`, depth: null, typed: null };
|
|
94144
|
+
const text = block.text || block.textPreview || "";
|
|
94145
|
+
const typedMarker = typedMarkerPrefixOf(text)?.marker;
|
|
94146
|
+
const typedShape = typedMarker ? markerShapeOf(text) : null;
|
|
94147
|
+
if (!typedMarker || !typedShape)
|
|
94148
|
+
return null;
|
|
94149
|
+
const parent = typedShape.kind === "digit" ? typedDigitParentOf(typedMarker) : "";
|
|
94150
|
+
return { key: `typed:${typedShape.wrapper}:${typedShape.kind}:${parent}`, depth: null, typed: typedShape };
|
|
94151
|
+
}
|
|
94152
|
+
function typedDigitParentOf(marker) {
|
|
94153
|
+
const segments = marker.replace(/^\(/, "").replace(/[.)]$/, "").split(".");
|
|
94154
|
+
return `${segments.length}:${segments.slice(0, -1).join(".")}`;
|
|
94155
|
+
}
|
|
94156
|
+
function markerValueOf(token, shape) {
|
|
94157
|
+
const core2 = token.replace(/^\(/, "").replace(/[.)]$/, "").toLowerCase();
|
|
94158
|
+
if (shape.kind === "digit")
|
|
94159
|
+
return Number(core2.split(".").pop());
|
|
94160
|
+
if (shape.kind === "lower-roman" || shape.kind === "upper-roman") {
|
|
94161
|
+
let total = 0;
|
|
94162
|
+
for (let i = 0;i < core2.length; i += 1) {
|
|
94163
|
+
const value = ROMAN_DIGITS[core2[i]] ?? 0;
|
|
94164
|
+
total += value < (ROMAN_DIGITS[core2[i + 1] ?? ""] ?? 0) ? -value : value;
|
|
94165
|
+
}
|
|
94166
|
+
return total;
|
|
94167
|
+
}
|
|
94168
|
+
const letter = core2.charCodeAt(0) - 96;
|
|
94169
|
+
return core2.length === 1 ? letter : 26 * (core2.length - 1) + letter;
|
|
94170
|
+
}
|
|
94171
|
+
function enumerationRunOf(blocks, index, slot, textOf) {
|
|
94172
|
+
const typed = slot.typed;
|
|
94173
|
+
const valueOf = (block) => {
|
|
94174
|
+
if (!typed) {
|
|
94175
|
+
const path5 = blockNumbering(block)?.path;
|
|
94176
|
+
return Array.isArray(path5) && path5.length > 0 ? Number(path5[path5.length - 1]) : null;
|
|
94177
|
+
}
|
|
94178
|
+
const token = typed ? typedMarkerPrefixOf(textOf(block))?.marker : null;
|
|
94179
|
+
return token && typed ? markerValueOf(token, typed) : null;
|
|
94180
|
+
};
|
|
94181
|
+
const walk = (step) => {
|
|
94182
|
+
const found = [];
|
|
94183
|
+
let edge = valueOf(blocks[index]);
|
|
94184
|
+
let crossed = false;
|
|
94185
|
+
for (let i = index + step;i >= 0 && i < blocks.length; i += step) {
|
|
94186
|
+
const block = blocks[i];
|
|
94187
|
+
if (textOf(block).length === 0)
|
|
94188
|
+
continue;
|
|
94189
|
+
const other = enumerationSlotOf(block);
|
|
94190
|
+
const continuesAsLetter = typed != null && other?.typed != null && markerShapeFits(typed, other.typed) && edge != null && valueOf(block) === edge + step;
|
|
94191
|
+
if (other?.key === slot.key || continuesAsLetter) {
|
|
94192
|
+
const value = valueOf(block);
|
|
94193
|
+
if (value != null && edge != null) {
|
|
94194
|
+
const advance = (value - edge) * step;
|
|
94195
|
+
if (advance <= 0 || (crossed || !typed) && advance !== 1)
|
|
94196
|
+
break;
|
|
94197
|
+
}
|
|
94198
|
+
found.push(block);
|
|
94199
|
+
edge = value;
|
|
94200
|
+
crossed = false;
|
|
94201
|
+
continue;
|
|
94202
|
+
}
|
|
94203
|
+
if (typed && other?.typed) {
|
|
94204
|
+
if (step === -1 && edge != null) {
|
|
94205
|
+
const prefix = typedMarkerPrefixOf(textOf(block)).prefix;
|
|
94206
|
+
const inline = new RegExp(String.raw`(?:^|\s)(${TYPED_MARKER_TOKEN}) `).exec(textOf(block).slice(prefix.length));
|
|
94207
|
+
const inlineShape = inline ? markerShapeOf(inline[1]) : null;
|
|
94208
|
+
if (inline && sameMarkerShape(inlineShape, typed) && markerValueOf(inline[1], typed) === edge - 1) {
|
|
94209
|
+
found.push(block);
|
|
94210
|
+
break;
|
|
94211
|
+
}
|
|
94212
|
+
}
|
|
94213
|
+
crossed = true;
|
|
94214
|
+
continue;
|
|
94215
|
+
}
|
|
94216
|
+
if (slot.depth != null && other?.depth != null && other.depth > slot.depth)
|
|
94217
|
+
continue;
|
|
94218
|
+
break;
|
|
94219
|
+
}
|
|
94220
|
+
return found;
|
|
94221
|
+
};
|
|
94222
|
+
return [...walk(-1).reverse(), blocks[index], ...walk(1)];
|
|
94223
|
+
}
|
|
94224
|
+
function listPunctuationAfterDelete(blocks, deletedIds) {
|
|
94225
|
+
const textOf = (block) => (block.text || (block.textPreview ?? "").replace(/…\s*$/, "")).trimEnd();
|
|
94226
|
+
const endingOf = (block) => {
|
|
94227
|
+
const text = textOf(block);
|
|
94228
|
+
const closers = ITEM_CLOSERS.exec(text)?.[0] ?? "";
|
|
94229
|
+
const body = text.slice(0, text.length - closers.length).trimEnd();
|
|
94230
|
+
const ending = ITEM_ENDING.exec(body);
|
|
94231
|
+
return {
|
|
94232
|
+
core: ending?.[0].trim() ?? "",
|
|
94233
|
+
real: ending ? `${ending[0].trim()}${closers}` : closers,
|
|
94234
|
+
closers,
|
|
94235
|
+
conjunction: CONJUNCTION_TAIL.exec(body)?.[0].trim() ?? null
|
|
94236
|
+
};
|
|
94237
|
+
};
|
|
94238
|
+
const quote = (block) => {
|
|
94239
|
+
const text = textOf(block);
|
|
94240
|
+
return JSON.stringify(text.length > 40 ? `...${text.slice(-40)}` : text);
|
|
94241
|
+
};
|
|
94242
|
+
const change = (block, to) => {
|
|
94243
|
+
const ending = endingOf(block);
|
|
94244
|
+
return `change the ending of ${quote(block)} (nodeId ${block.nodeId}) from "${ending.real}" to "${to}${ending.closers}"`;
|
|
94245
|
+
};
|
|
94246
|
+
const entries = [];
|
|
94247
|
+
const covered = new Set;
|
|
94248
|
+
blocks.forEach((block, index) => {
|
|
94249
|
+
if (!deletedIds.has(block.nodeId) || covered.has(block.nodeId))
|
|
94250
|
+
return;
|
|
94251
|
+
const slot = enumerationSlotOf(block);
|
|
94252
|
+
if (!slot)
|
|
94253
|
+
return;
|
|
94254
|
+
const run = enumerationRunOf(blocks, index, slot, textOf);
|
|
94255
|
+
for (const item of run)
|
|
94256
|
+
covered.add(item.nodeId);
|
|
94257
|
+
const survivors = run.filter((item) => !deletedIds.has(item.nodeId));
|
|
94258
|
+
if (survivors.length === 0)
|
|
94259
|
+
return;
|
|
94260
|
+
const last = survivors[survivors.length - 1];
|
|
94261
|
+
const penultimate = survivors.length >= 2 ? survivors[survivors.length - 2] : undefined;
|
|
94262
|
+
const originalPenultimate = run[run.length - 2];
|
|
94263
|
+
if (run.some((item) => item !== originalPenultimate && endingOf(item).conjunction))
|
|
94264
|
+
return;
|
|
94265
|
+
const runEnd = run[run.length - 1];
|
|
94266
|
+
if (!deletedIds.has(runEnd.nodeId))
|
|
94267
|
+
return;
|
|
94268
|
+
const tail = originalPenultimate ? endingOf(originalPenultimate).conjunction : null;
|
|
94269
|
+
const separator = tail ? tail.charAt(0) : ";";
|
|
94270
|
+
const closing = endingOf(runEnd).core || ".";
|
|
94271
|
+
const lastEnding = endingOf(last);
|
|
94272
|
+
if (lastEnding.core === ":")
|
|
94273
|
+
return;
|
|
94274
|
+
const needsClose = lastEnding.core !== closing && (lastEnding.conjunction != null || lastEnding.core === separator);
|
|
94275
|
+
const needsTail = penultimate != null && tail != null && endingOf(penultimate).core !== ":" && !endingOf(penultimate).conjunction;
|
|
94276
|
+
if (!needsClose && !(needsTail && lastEnding.core !== closing))
|
|
94277
|
+
return;
|
|
94278
|
+
const edits = [
|
|
94279
|
+
`end ${quote(last)} (nodeId ${last.nodeId}) with "${closing}${lastEnding.closers}" instead of "${lastEnding.real}"`
|
|
94280
|
+
];
|
|
94281
|
+
if (needsTail)
|
|
94282
|
+
edits.push(change(penultimate, tail));
|
|
94283
|
+
entries.push({
|
|
94284
|
+
deleted: runEnd.nodeId,
|
|
94285
|
+
lastItem: last.nodeId,
|
|
94286
|
+
lastItemEnds: lastEnding.real,
|
|
94287
|
+
...penultimate ? { penultimate: penultimate.nodeId, penultimateEnds: endingOf(penultimate).real } : {},
|
|
94288
|
+
suggestion: `The run now ends at ${quote(last)}: ${edits.join(", and ")}, using replace_text.`
|
|
94289
|
+
});
|
|
94290
|
+
});
|
|
94291
|
+
return entries;
|
|
94292
|
+
}
|
|
94125
94293
|
async function runDeleteBlocks(doc2, args) {
|
|
94126
94294
|
const domains = new Set(["blocks", "trackedChanges"]);
|
|
94127
94295
|
for (const selector of args.selectors) {
|
|
@@ -94235,6 +94403,10 @@ async function runDeleteBlocks(doc2, args) {
|
|
|
94235
94403
|
}
|
|
94236
94404
|
const allApplied = deleted.length === targets.length && errors4.length === 0;
|
|
94237
94405
|
const verified = verification.every((v) => v.passed);
|
|
94406
|
+
let listPunctuation = [];
|
|
94407
|
+
try {
|
|
94408
|
+
listPunctuation = listPunctuationAfterDelete(pre.blocks, new Set(deleted.map((entry) => entry.nodeId)));
|
|
94409
|
+
} catch {}
|
|
94238
94410
|
return {
|
|
94239
94411
|
status: !verified || deleted.length === 0 ? "failed" : allApplied ? "ok" : "partial",
|
|
94240
94412
|
intent: `delete_blocks: ${deleted.length} block(s)`,
|
|
@@ -94244,6 +94416,7 @@ async function runDeleteBlocks(doc2, args) {
|
|
|
94244
94416
|
executedOperations,
|
|
94245
94417
|
verification,
|
|
94246
94418
|
deletedBlocks: deleted,
|
|
94419
|
+
...listPunctuation.length > 0 ? { listPunctuation } : {},
|
|
94247
94420
|
...errors4.length ? { errors: errors4 } : {},
|
|
94248
94421
|
...errors4.length ? { nextStep: "Re-inspect the document and retry the selectors that did not resolve to one block." } : {}
|
|
94249
94422
|
};
|
|
@@ -96706,8 +96879,9 @@ async function runScopedReplaceUnchecked(doc2, args) {
|
|
|
96706
96879
|
occurrences: spans.length,
|
|
96707
96880
|
...edit.occurrence != null ? { occurrence: edit.occurrence } : {}
|
|
96708
96881
|
});
|
|
96709
|
-
for (const span of spans)
|
|
96710
|
-
allSpans.push({ ...span, replace: edit.replace, find: edit.find });
|
|
96882
|
+
for (const span of spans) {
|
|
96883
|
+
allSpans.push({ ...span, replace: edit.replace, find: edit.find, editIndex: perEdit.length - 1 });
|
|
96884
|
+
}
|
|
96711
96885
|
}
|
|
96712
96886
|
const appliedEdits = perEdit.filter((e) => e.occurrences > 0);
|
|
96713
96887
|
const skippedEdits = perEdit.filter((e) => e.occurrences === 0);
|
|
@@ -96741,6 +96915,23 @@ async function runScopedReplaceUnchecked(doc2, args) {
|
|
|
96741
96915
|
planned.push(span);
|
|
96742
96916
|
lastEnd = span.end;
|
|
96743
96917
|
}
|
|
96918
|
+
planned.forEach((span, at) => {
|
|
96919
|
+
if (span.replace.trim().length > 0)
|
|
96920
|
+
return;
|
|
96921
|
+
const text = block.text;
|
|
96922
|
+
if (text.charAt(span.start - 1) !== " " || text.charAt(span.end) !== " ")
|
|
96923
|
+
return;
|
|
96924
|
+
if (text.charAt(span.start - 2) === " " || text.charAt(span.end + 1) === " ")
|
|
96925
|
+
return;
|
|
96926
|
+
if (/[.!?]["'\u201d\u2019)\]]*$/.test(text.slice(0, span.start - 1)))
|
|
96927
|
+
return;
|
|
96928
|
+
if ((planned[at + 1]?.start ?? Infinity) <= span.end || (planned[at - 1]?.end ?? -1) >= span.start - 1)
|
|
96929
|
+
return;
|
|
96930
|
+
if (span.replace.length > 0)
|
|
96931
|
+
span.start -= 1;
|
|
96932
|
+
span.end += 1;
|
|
96933
|
+
perEdit[span.editIndex].collapsedSpace = true;
|
|
96934
|
+
});
|
|
96744
96935
|
const expected = planned.reduceRight((text, span) => text.slice(0, span.start) + span.replace + text.slice(span.end), block.text);
|
|
96745
96936
|
const tracked = (args.changeMode ?? "direct") === "tracked";
|
|
96746
96937
|
const uniqueFinds = new Set(planned.map((s) => caseSensitive ? s.find : s.find.toLowerCase()));
|
|
@@ -96913,6 +97104,8 @@ function leadInShapeOf(blockText, labelText, quote) {
|
|
|
96913
97104
|
return null;
|
|
96914
97105
|
}
|
|
96915
97106
|
function leadInSpanOf(text, shape) {
|
|
97107
|
+
if (shape.kind === "typed")
|
|
97108
|
+
return typedCaptionSpanOf(text, shape.delimiter);
|
|
96916
97109
|
if (shape.kind === "word") {
|
|
96917
97110
|
const next = text.charAt(shape.label.length);
|
|
96918
97111
|
return text.startsWith(shape.label) && (next === "" || /\s/.test(next)) ? { start: 0, end: shape.label.length } : null;
|
|
@@ -96940,6 +97133,71 @@ function leadInSpanOf(text, shape) {
|
|
|
96940
97133
|
const end = leadInEndOf(text, shape.delimiter);
|
|
96941
97134
|
return end == null ? null : { start: 0, end };
|
|
96942
97135
|
}
|
|
97136
|
+
function typedMarkerPrefixOf(text) {
|
|
97137
|
+
const match = TYPED_MARKER_PREFIX.exec(text);
|
|
97138
|
+
return match ? { prefix: match[0], marker: match[1] } : null;
|
|
97139
|
+
}
|
|
97140
|
+
function markerShapeOf(text) {
|
|
97141
|
+
const match = LEADING_MARKER_TOKEN.exec(text);
|
|
97142
|
+
if (!match)
|
|
97143
|
+
return null;
|
|
97144
|
+
const token = match[1];
|
|
97145
|
+
const wrapper = token.startsWith("(") ? "paren" : token.endsWith(".") ? "period" : "close";
|
|
97146
|
+
const core2 = token.replace(/^\(/, "").replace(/[.)]$/, "");
|
|
97147
|
+
let kind;
|
|
97148
|
+
if (/^\d/.test(core2))
|
|
97149
|
+
kind = "digit";
|
|
97150
|
+
else if (/^[ivx]+$/.test(core2))
|
|
97151
|
+
kind = "lower-roman";
|
|
97152
|
+
else if (/^[IVX]+$/.test(core2))
|
|
97153
|
+
kind = "upper-roman";
|
|
97154
|
+
else if (/^[a-z]+$/.test(core2))
|
|
97155
|
+
kind = "lower-alpha";
|
|
97156
|
+
else if (/^[A-Z]+$/.test(core2))
|
|
97157
|
+
kind = "upper-alpha";
|
|
97158
|
+
else
|
|
97159
|
+
return null;
|
|
97160
|
+
return { wrapper, kind };
|
|
97161
|
+
}
|
|
97162
|
+
function sameMarkerShape(a, b) {
|
|
97163
|
+
return a != null && b != null && a.wrapper === b.wrapper && a.kind === b.kind;
|
|
97164
|
+
}
|
|
97165
|
+
function markerShapeFits(reference, created) {
|
|
97166
|
+
if (!reference || reference.wrapper !== created.wrapper)
|
|
97167
|
+
return false;
|
|
97168
|
+
if (reference.kind === created.kind)
|
|
97169
|
+
return true;
|
|
97170
|
+
return created.kind === "lower-roman" && reference.kind === "lower-alpha" || created.kind === "upper-roman" && reference.kind === "upper-alpha";
|
|
97171
|
+
}
|
|
97172
|
+
function continuesAlphabet(referenceText, createdText, referenceBefore) {
|
|
97173
|
+
const letterOf = (text) => /^[a-zA-Z]$/.exec(LEADING_MARKER_TOKEN.exec(text)?.[1]?.replace(/[().]/g, "") ?? "")?.[0];
|
|
97174
|
+
const reference = letterOf(referenceText);
|
|
97175
|
+
const created = letterOf(createdText);
|
|
97176
|
+
return reference != null && created != null && created.charCodeAt(0) - reference.charCodeAt(0) === (referenceBefore ? 1 : -1);
|
|
97177
|
+
}
|
|
97178
|
+
function isTitleLike(caption) {
|
|
97179
|
+
const words = caption.match(/\p{L}+/gu) ?? [];
|
|
97180
|
+
const capitalised = words.filter((word) => /^\p{Lu}/u.test(word)).length;
|
|
97181
|
+
return words.length > 0 && words.every((word) => word.length < 4 || /^\p{Lu}/u.test(word)) && capitalised * 2 >= words.length;
|
|
97182
|
+
}
|
|
97183
|
+
function typedCaptionSpanOf(text, delimiter = ".") {
|
|
97184
|
+
const typed = typedMarkerPrefixOf(text);
|
|
97185
|
+
const mark = delimiter.trim();
|
|
97186
|
+
if (!typed || !mark)
|
|
97187
|
+
return null;
|
|
97188
|
+
const start = typed.prefix.length;
|
|
97189
|
+
for (let at = text.indexOf(mark, start);at >= 0; at = text.indexOf(mark, at + 1)) {
|
|
97190
|
+
const end = at + mark.length;
|
|
97191
|
+
if (end - start > TYPED_CAPTION_MAX_CHARS)
|
|
97192
|
+
return null;
|
|
97193
|
+
if (at === start || !/\s/.test(text.charAt(end)))
|
|
97194
|
+
continue;
|
|
97195
|
+
if (!isTitleLike(text.slice(start, at)))
|
|
97196
|
+
return null;
|
|
97197
|
+
return text.slice(end).trim().length > 0 ? { start, end } : null;
|
|
97198
|
+
}
|
|
97199
|
+
return null;
|
|
97200
|
+
}
|
|
96943
97201
|
function sliceWholeChars(text, end) {
|
|
96944
97202
|
if (end >= text.length)
|
|
96945
97203
|
return text;
|
|
@@ -96980,7 +97238,10 @@ async function listItemRunPattern(doc2, text, blockId) {
|
|
|
96980
97238
|
if (!queryFn || !text.trim())
|
|
96981
97239
|
return null;
|
|
96982
97240
|
const delimiterAt = leadInEndOf(text);
|
|
96983
|
-
|
|
97241
|
+
let windowEnd = delimiterAt != null ? delimiterAt + LEAD_IN_BODY_SAMPLE_CHARS : LEAD_IN_BODY_SAMPLE_CHARS;
|
|
97242
|
+
const typedCaption = typedCaptionSpanOf(text);
|
|
97243
|
+
if (typedCaption)
|
|
97244
|
+
windowEnd = Math.max(windowEnd, typedCaption.end + LEAD_IN_BODY_SAMPLE_CHARS);
|
|
96984
97245
|
const pattern = sliceWholeChars(text, windowEnd);
|
|
96985
97246
|
const result = asRecord2(await queryFn({ select: { type: "text", pattern } }));
|
|
96986
97247
|
const items = Array.isArray(result?.items) ? result.items : [];
|
|
@@ -96994,6 +97255,9 @@ async function listItemRunPattern(doc2, text, blockId) {
|
|
|
96994
97255
|
const runs = (Array.isArray(rec?.runs) ? rec.runs : []).filter((r) => runTextOf(r).length > 0);
|
|
96995
97256
|
if (runs.length === 0)
|
|
96996
97257
|
continue;
|
|
97258
|
+
const typedLead = typedPrefixLabelOf(runs, runTextOf);
|
|
97259
|
+
if (typedLead)
|
|
97260
|
+
return typedLead;
|
|
96997
97261
|
const blockText = asString2(rec?.text, "") ?? "";
|
|
96998
97262
|
const opener = runTextOf(runs[0]).trim();
|
|
96999
97263
|
const quote = LEAD_IN_QUOTES.find((q) => opener === q);
|
|
@@ -97017,6 +97281,59 @@ async function listItemRunPattern(doc2, text, blockId) {
|
|
|
97017
97281
|
}
|
|
97018
97282
|
return null;
|
|
97019
97283
|
}
|
|
97284
|
+
function typedPrefixLabelOf(runs, runTextOf) {
|
|
97285
|
+
const typed = typedMarkerPrefixOf(runs.map(runTextOf).join(""));
|
|
97286
|
+
if (!typed)
|
|
97287
|
+
return null;
|
|
97288
|
+
const markerEnd = typed.prefix.indexOf(typed.marker) + typed.marker.length;
|
|
97289
|
+
let covered = 0;
|
|
97290
|
+
let labelIndex = 0;
|
|
97291
|
+
while (labelIndex < runs.length && covered + runTextOf(runs[labelIndex]).length <= typed.prefix.length) {
|
|
97292
|
+
covered += runTextOf(runs[labelIndex]).length;
|
|
97293
|
+
labelIndex += 1;
|
|
97294
|
+
}
|
|
97295
|
+
if (covered < markerEnd || labelIndex + 1 >= runs.length)
|
|
97296
|
+
return null;
|
|
97297
|
+
const underlined = (run) => asRecord2(asRecord2(asRecord2(run)?.styles)?.effective)?.underline === true;
|
|
97298
|
+
const emphasisOf = (run) => {
|
|
97299
|
+
const style = matchRunStyle(run);
|
|
97300
|
+
return `${style.bold}/${style.italic}/${underlined(run)}`;
|
|
97301
|
+
};
|
|
97302
|
+
const label = runs[labelIndex];
|
|
97303
|
+
if (emphasisOf(label) === "false/false/false")
|
|
97304
|
+
return null;
|
|
97305
|
+
const isBlank = (run) => runTextOf(run).trim().length === 0;
|
|
97306
|
+
const continuesLabel = (index) => {
|
|
97307
|
+
if (emphasisOf(runs[index]) === emphasisOf(label))
|
|
97308
|
+
return true;
|
|
97309
|
+
let next = index;
|
|
97310
|
+
while (next < runs.length && isBlank(runs[next]))
|
|
97311
|
+
next += 1;
|
|
97312
|
+
return next > index && next < runs.length && emphasisOf(runs[next]) === emphasisOf(label);
|
|
97313
|
+
};
|
|
97314
|
+
let bodyIndex = labelIndex + 1;
|
|
97315
|
+
while (bodyIndex < runs.length && continuesLabel(bodyIndex))
|
|
97316
|
+
bodyIndex += 1;
|
|
97317
|
+
while (bodyIndex < runs.length - 1 && isBlank(runs[bodyIndex]))
|
|
97318
|
+
bodyIndex += 1;
|
|
97319
|
+
if (bodyIndex >= runs.length)
|
|
97320
|
+
return null;
|
|
97321
|
+
const labelText = runs.slice(labelIndex, bodyIndex).map(runTextOf).join("").trim();
|
|
97322
|
+
if (labelText.length === 0 || labelText.length > LEAD_IN_MAX_CHARS)
|
|
97323
|
+
return null;
|
|
97324
|
+
const delimiter = [".", ...LEAD_IN_DELIMITERS.map((d) => d.trim())].find((d) => labelText.endsWith(d) && labelText.length > d.length);
|
|
97325
|
+
if (!delimiter)
|
|
97326
|
+
return null;
|
|
97327
|
+
const body = runs[bodyIndex];
|
|
97328
|
+
const leadStyle = matchRunStyle(label);
|
|
97329
|
+
const bodyStyle = matchRunStyle(body);
|
|
97330
|
+
const leadUnderline = underlined(label);
|
|
97331
|
+
const bodyUnderline = underlined(body);
|
|
97332
|
+
const look = inlineFromMatchStyle(leadStyle, bodyStyle);
|
|
97333
|
+
if (leadUnderline || bodyUnderline)
|
|
97334
|
+
look.underline = leadUnderline;
|
|
97335
|
+
return { body: inlineFromMatchStyle(bodyStyle), lead: { look, shape: { kind: "typed", delimiter } } };
|
|
97336
|
+
}
|
|
97020
97337
|
function paragraphIndentOf(payload) {
|
|
97021
97338
|
const node = isRecord(payload) ? payload.node : null;
|
|
97022
97339
|
if (!isRecord(node))
|
|
@@ -97707,6 +98024,7 @@ async function matchOneBlock(doc2, postBlocks, preIds, created, createdIndex, an
|
|
|
97707
98024
|
}
|
|
97708
98025
|
if (!reference)
|
|
97709
98026
|
return null;
|
|
98027
|
+
reference = typedShapeReference(postBlocks, preIds, created, createdIndex, createdText, reference, compatibleHeading);
|
|
97710
98028
|
const applied = {};
|
|
97711
98029
|
const refNumbering = blockNumbering(reference);
|
|
97712
98030
|
if (allowNumberingAttach && refNumbering && !blockNumbering(created)) {
|
|
@@ -97726,7 +98044,8 @@ async function matchOneBlock(doc2, postBlocks, preIds, created, createdIndex, an
|
|
|
97726
98044
|
}
|
|
97727
98045
|
}
|
|
97728
98046
|
if (reference.styleId && reference.styleId !== created.styleId) {
|
|
97729
|
-
const
|
|
98047
|
+
const keepRunMarks = !allowLeadPattern;
|
|
98048
|
+
const setStyleFn = (keepRunMarks ? maybeMethod2(doc2, ["styles", "paragraph", "setStyleRef"]) : null) ?? maybeMethod2(doc2, ["styles", "paragraph", "setStyle"]);
|
|
97730
98049
|
if (setStyleFn) {
|
|
97731
98050
|
const target = { kind: "block", nodeType: created.nodeType, nodeId: created.nodeId };
|
|
97732
98051
|
let canCopyStyle = true;
|
|
@@ -97801,6 +98120,38 @@ async function matchOneBlock(doc2, postBlocks, preIds, created, createdIndex, an
|
|
|
97801
98120
|
return { matchedSibling: null, skipped: reasonOf(err) };
|
|
97802
98121
|
}
|
|
97803
98122
|
}
|
|
98123
|
+
function typedShapeReference(postBlocks, preIds, created, createdIndex, createdText, reference, compatible) {
|
|
98124
|
+
const typed = createdText ? typedMarkerPrefixOf(createdText) : null;
|
|
98125
|
+
if (!typed || createdText.slice(typed.prefix.length).trim().length === 0)
|
|
98126
|
+
return reference;
|
|
98127
|
+
const shape = markerShapeOf(createdText);
|
|
98128
|
+
const referenceShape = markerShapeOf(reference.textPreview ?? "");
|
|
98129
|
+
if (!shape || sameMarkerShape(referenceShape, shape))
|
|
98130
|
+
return reference;
|
|
98131
|
+
const usable = (row) => !!row && preIds.has(row.nodeId) && row.nodeType === created.nodeType && !row.isEmpty && compatible(row);
|
|
98132
|
+
const before = postBlocks.slice(0, createdIndex).reverse().find(usable);
|
|
98133
|
+
const after = postBlocks.slice(createdIndex + 1).find(usable);
|
|
98134
|
+
const continued = [reference, before, after].find((row) => !!row && markerShapeFits(markerShapeOf(row.textPreview ?? ""), shape) && continuesAlphabet(row.textPreview ?? "", createdText, postBlocks.findIndex((b) => b.nodeId === row.nodeId) < createdIndex));
|
|
98135
|
+
if (continued)
|
|
98136
|
+
return continued;
|
|
98137
|
+
const candidate = (row) => {
|
|
98138
|
+
if (!usable(row))
|
|
98139
|
+
return null;
|
|
98140
|
+
const preview = row.textPreview ?? "";
|
|
98141
|
+
return typedMarkerPrefixOf(preview) ? markerShapeOf(preview) : null;
|
|
98142
|
+
};
|
|
98143
|
+
const nearest = (accepts) => {
|
|
98144
|
+
for (let distance = 1;distance < postBlocks.length; distance += 1) {
|
|
98145
|
+
for (const index of [createdIndex - distance, createdIndex + distance]) {
|
|
98146
|
+
const row = postBlocks[index];
|
|
98147
|
+
if (index >= 0 && accepts(candidate(row)))
|
|
98148
|
+
return row;
|
|
98149
|
+
}
|
|
98150
|
+
}
|
|
98151
|
+
return null;
|
|
98152
|
+
};
|
|
98153
|
+
return nearest((rowShape) => sameMarkerShape(rowShape, shape)) ?? nearest((rowShape) => markerShapeFits(rowShape, shape)) ?? reference;
|
|
98154
|
+
}
|
|
97804
98155
|
async function matchLeadMarkerPattern(doc2, reference, created, createdText) {
|
|
97805
98156
|
const createdPreview = created.textPreview ?? "";
|
|
97806
98157
|
if (!reference.nodeId || !created.nodeId || !createdPreview)
|
|
@@ -97878,7 +98229,7 @@ async function matchBlockRunPattern(doc2, reference, created, createdText) {
|
|
|
97878
98229
|
}
|
|
97879
98230
|
if (pattern.lead) {
|
|
97880
98231
|
const span = leadInSpanOf(fullText, pattern.lead.shape);
|
|
97881
|
-
const range = span ?? (Object.keys(pattern.body).length === 0 ? { start: 0, end } : null);
|
|
98232
|
+
const range = span ?? (Object.keys(pattern.body).length === 0 && pattern.lead.shape.kind !== "typed" ? { start: 0, end } : null);
|
|
97882
98233
|
if (range && await applyInlineQuiet(formatFn, { blockId: created.nodeId, ...range, inline: pattern.lead.look })) {
|
|
97883
98234
|
applied.lead = { ...pattern.lead.look, range: [range.start, range.end] };
|
|
97884
98235
|
}
|
|
@@ -97898,7 +98249,7 @@ async function matchInsertedBlockFormatting(doc2, preBlocks, receipt, args, avai
|
|
|
97898
98249
|
const anchorSelector = placement && isRecord(placement.selector) ? placement.selector : null;
|
|
97899
98250
|
const anchorId = anchorSelector && typeof anchorSelector.nodeId === "string" ? anchorSelector.nodeId : null;
|
|
97900
98251
|
const anchorRow = anchorId ? postBlocks.find((b) => b.nodeId === anchorId) ?? null : null;
|
|
97901
|
-
const rawTexts = Array.isArray(args?.texts) ? args.texts : [];
|
|
98252
|
+
const rawTexts = Array.isArray(args?.texts) ? args.texts : args?.text != null ? [args.text] : [];
|
|
97902
98253
|
const hasExplicitStyling = rawTexts.some((entry) => isRecord(entry) && (Array.isArray(entry.runs) || entry.marks != null));
|
|
97903
98254
|
const insertedTexts = rawTexts.map((entry) => {
|
|
97904
98255
|
if (typeof entry === "string")
|
|
@@ -98056,7 +98407,7 @@ async function runAttachNumbering(doc2, args) {
|
|
|
98056
98407
|
errors: [
|
|
98057
98408
|
{
|
|
98058
98409
|
code: "TARGET_NOT_FOUND",
|
|
98059
|
-
message: `no block renders marker ${JSON.stringify(likeMarker)}. Available: ${available.join(" ")}
|
|
98410
|
+
message: available.length > 0 ? `no block renders marker ${JSON.stringify(likeMarker)}. Available: ${available.join(" ")}` : rows.some((r) => typedMarkerPrefixOf(r.textPreview ?? "") != null) ? `no block renders marker ${JSON.stringify(likeMarker)}: this document has no numbering scheme; its clause numbers are typed text. ` + `Copy the sibling's typed prefix (tab, next number, tab) into the paragraph text with insert_paragraphs or replace_text, ` + `then renumber the following typed markers with replace_text.` : `no block renders marker ${JSON.stringify(likeMarker)}: no block in this document carries numbering. ` + `To add a paragraph that matches its neighbours use insert_paragraphs next to them; ` + `to start a numbered list use append_list or convert_list.`,
|
|
98060
98411
|
recovery: { kind: "reinspect" }
|
|
98061
98412
|
}
|
|
98062
98413
|
]
|
|
@@ -98983,7 +99334,7 @@ function parseSelector(value) {
|
|
|
98983
99334
|
}
|
|
98984
99335
|
return;
|
|
98985
99336
|
}
|
|
98986
|
-
var ACTION_DEFINITIONS, ACTION_NAMES, ACTION_HINTS, ACTION_ARGS, ACTION_DISPOSITIONS, ACTION_GROUP_LABELS, ACTION_GROUPS, DELETABLE_BLOCK_NODE_TYPES, RUN_BOOL_MARKS, NAMED_COLORS, HEX_COLOR_PATTERN, TWIPS_PER_POINT = 20, LEAD_IN_DELIMITERS, LEAD_IN_MAX_CHARS = 90, LEAD_IN_BODY_SAMPLE_CHARS = 40, LEAD_IN_QUOTES, LEAD_IN_TAIL_DELIMITERS, normMarker = (m) => m.trim().replace(/\.$/, ""), LEAD_MARKER_PATTERN, ACTION_NAMES_LIST;
|
|
99337
|
+
var ACTION_DEFINITIONS, ACTION_NAMES, ACTION_HINTS, ACTION_ARGS, ACTION_DISPOSITIONS, ACTION_GROUP_LABELS, ACTION_GROUPS, TYPED_SIBLING_WINDOW = 20, CONJUNCTION_TAIL, ITEM_ENDING, ITEM_CLOSERS, ROMAN_DIGITS, DELETABLE_BLOCK_NODE_TYPES, RUN_BOOL_MARKS, NAMED_COLORS, HEX_COLOR_PATTERN, TWIPS_PER_POINT = 20, LEAD_IN_DELIMITERS, LEAD_IN_MAX_CHARS = 90, LEAD_IN_BODY_SAMPLE_CHARS = 40, LEAD_IN_QUOTES, LEAD_IN_TAIL_DELIMITERS, TYPED_MARKER_CORE, TYPED_MARKER_TOKEN, TYPED_MARKER_PREFIX, LEADING_MARKER_TOKEN, TYPED_CAPTION_MAX_CHARS = 60, normMarker = (m) => m.trim().replace(/\.$/, ""), LEAD_MARKER_PATTERN, ACTION_NAMES_LIST;
|
|
98987
99338
|
var init_actions = __esm(() => {
|
|
98988
99339
|
init_action_descriptors();
|
|
98989
99340
|
init_execution_context();
|
|
@@ -99016,6 +99367,10 @@ var init_actions = __esm(() => {
|
|
|
99016
99367
|
label,
|
|
99017
99368
|
actions: ACTION_NAMES.filter((name) => ACTION_DEFINITIONS[name].group === label).sort((left, right) => ACTION_DEFINITIONS[left].groupOrder - ACTION_DEFINITIONS[right].groupOrder)
|
|
99018
99369
|
}));
|
|
99370
|
+
CONJUNCTION_TAIL = /[;,]\s*(and|or)\s*$/i;
|
|
99371
|
+
ITEM_ENDING = /(?:[;,]\s*(?:and|or)|[.;,:])\s*$/i;
|
|
99372
|
+
ITEM_CLOSERS = /["'”’)\]]+$/;
|
|
99373
|
+
ROMAN_DIGITS = { i: 1, v: 5, x: 10 };
|
|
99019
99374
|
DELETABLE_BLOCK_NODE_TYPES = new Set(["paragraph", "heading", "listItem"]);
|
|
99020
99375
|
RUN_BOOL_MARKS = ["bold", "italic", "underline", "strike"];
|
|
99021
99376
|
NAMED_COLORS = {
|
|
@@ -99036,6 +99391,10 @@ var init_actions = __esm(() => {
|
|
|
99036
99391
|
LEAD_IN_DELIMITERS = [":", " — ", " – ", " - ", "—", "–"];
|
|
99037
99392
|
LEAD_IN_QUOTES = ['"', "“", "‘", "'"];
|
|
99038
99393
|
LEAD_IN_TAIL_DELIMITERS = [". ", ": ", ...LEAD_IN_DELIMITERS];
|
|
99394
|
+
TYPED_MARKER_CORE = String.raw`(?:\d{1,3}(?:\.\d{1,3})*|[ivx]{1,6}|[IVX]{1,6}|[a-z]{1,2}|[A-Z])`;
|
|
99395
|
+
TYPED_MARKER_TOKEN = String.raw`(?:\(${TYPED_MARKER_CORE}\)|${TYPED_MARKER_CORE}[.)])`;
|
|
99396
|
+
TYPED_MARKER_PREFIX = new RegExp(String.raw`^[ \t]*(${TYPED_MARKER_TOKEN})\t[\t ]*`);
|
|
99397
|
+
LEADING_MARKER_TOKEN = new RegExp(String.raw`^\s*(${TYPED_MARKER_TOKEN})(?=\s|$)`);
|
|
99039
99398
|
LEAD_MARKER_PATTERN = /^\(?(?:[a-zA-Z]{1,3}|\d{1,3})[).:\]]/;
|
|
99040
99399
|
ACTION_NAMES_LIST = ACTION_NAMES;
|
|
99041
99400
|
});
|
|
@@ -100224,8 +100583,8 @@ Users speak in what they SEE, not in file-format terms. Translate their words in
|
|
|
100224
100583
|
- PLACEMENT: when the user names a position, honor it exactly. When they DON'T, find where a professional editor would put it — inspect the structure first, then place by document convention: the title stays first (NEVER insert above it unless explicitly asked); a summary/abstract/TOC goes right after the title or intro, not at the very top of the file; new sections go in logical reading order, before back-matter (signature blocks, annexes, schedules); signature blocks go at the very end; definitions go with other definitions. Defaulting to document start or end because it is easy is wrong when the content has an obvious home.
|
|
100225
100584
|
- LEGAL DOCUMENTS ARE CROSS-REFERENCED. Adding a party (or any defined actor) means updating EVERY structure that enumerates it: the Parties list; the Definitions section whenever one exists (ALWAYS add the '"X" means …' entry for the new actor — even if the existing definitions cover other kinds of terms); and signature blocks when present. Same for removals. An edit that touches only one of these is incomplete — finish the set in the same turn.
|
|
100226
100585
|
- CLEANUP is part of the job. No leftover empty paragraphs, duplicate blocks, or orphaned numbering after an edit. If your edit creates debris, remove it in the same turn.
|
|
100227
|
-
- NUMBERS
|
|
100228
|
-
-
|
|
100586
|
+
- CLAUSE NUMBERS follow the siblings. SCHEME numbering (inspect shows numbering.marker on the blocks): never type a number into the text; a new clause = insert_paragraphs, then attach_numbering with likeMarker of the last sibling (e.g. "10.") and the rest renumbers itself. TYPED numbering (counts.lists is 0 and the siblings' text starts with the number: "\\t4.\\t", "\\t(b)\\t", "\\t(i)\\t"): copy that exact shape into the inserted text (leading tab, next number, tab, caption, two spaces), style a sub-item like an existing sub-item (apply_style likeText), never attach_numbering or append_list there, and renumber what follows yourself in ONE replace_text call: the later markers of the SAME sequence (a new top-level clause shifts the top-level clauses after it, not their (a)/(i) sub-runs, not an attachment's own clauses) AND every "Section N" cross-reference to a moved clause (a clause's reference to itself takes its new number). Schedule, Exhibit, Annex and Appendix labels are not clause numbers: leave them alone. A typed number is the document's convention, not a bug to fix.
|
|
100587
|
+
- REMOVING an item from a lettered or numbered run ("(a) …, (b) … and (c) …", sub-clauses ending "; and") reletters the items that follow and moves the closing conjunction to the new penultimate item, so the last one ends the way the list ends: deleting (iv) from "(ii) …; (iii) …; and (iv) …." takes TWO edits, (ii) "…;" becomes "…; and" and (iii) "…; and" becomes "…." (read (ii) first; it is in the paragraph above). Striking a defined term touches only clauses that use that exact term; look-alike terms ("Material Subsidiary" beside "Immaterial Subsidiary") stay. Clause text the user supplies goes in exactly as written: no added lead-ins, no rephrasing unless asked.
|
|
100229
100588
|
- NEVER END THE TURN WITH THE DOCUMENT WORSE THAN YOU FOUND IT. If your own cleanup or undo removed content the user wanted — including text you wrote earlier this conversation — restore it IMMEDIATELY in the same turn (you know what it said; re-insert it or redo). Do not ask permission to repair damage you caused.
|
|
100230
100589
|
- REVIEW means READING. "Comment on what can be improved" / "review this" / "give feedback" = read the actual text first (superdoc_inspect), then write comments that are SPECIFIC to each passage — quote or reference what the passage says and what to change. Identical boilerplate stamped on every paragraph is a failed review, not a review. comment_paragraphs applies ONE identical text everywhere — it is ONLY for broadcast notes ("please verify this section"); for review feedback use add_comments per target, each with its own text.
|
|
100231
100590
|
- ACT when intent is plain; ask only when the request is genuinely ambiguous AND the wrong guess would be destructive. One clarifying question maximum, with your best-guess default stated.
|
|
@@ -100250,15 +100609,15 @@ ACTIONS (superdoc_perform_action with flat args)
|
|
|
100250
100609
|
- insert_paragraphs: texts (in final order) — or a single text for one paragraph. headingLevel makes the first item a heading (1-6). changeMode:"tracked" if asked. Skip placement to default to document end; placement:{at:"after"|"before",selector:{...}} to position. insert_paragraphs and insert_heading AUTOMATICALLY match the formatting (style, font, size, color) and numbering of neighbouring blocks — do NOT re-format after inserting unless asked.
|
|
100251
100610
|
- insert_heading: text, level (1-6).
|
|
100252
100611
|
- append_list: items (string array), kind:"ordered"|"bullet". headingText/headingLevel only if asked for a heading above. placement:{at:"after"|"before",selector:{...}} builds the list at that block instead of document end — when the list belongs inside a section, ALWAYS pass placement. The receipt's placement-honored check is the truth.
|
|
100253
|
-
- add_list_items: entries:[{text, level?}] (level relative to the anchor: 0 = same level, 1 = nested sub-item) — or items:[…] plain strings at the list level. Locate the list by anchorText (text inside one of its items) or listOrdinal (1-based). THE way to ADD items into an EXISTING list — reuses its numbering + markers, matches the anchor item's font/size/bold/colour automatically (receipt.formattingMatched — do NOT re-format after adding unless asked), joins imported list-looking paragraphs in place, and is tracked-safe. NOT append_list (which starts a brand-new list).
|
|
100612
|
+
- add_list_items: entries:[{text, level?}] (level relative to the anchor: 0 = same level, 1 = nested sub-item) — or items:[…] plain strings at the list level. Locate the list by anchorText (text inside one of its items) or listOrdinal (1-based). THE way to ADD items into an EXISTING list or scheme-numbered sequence (never a typed one) — reuses its numbering + markers, matches the anchor item's font/size/bold/colour automatically (receipt.formattingMatched — do NOT re-format after adding unless asked), joins imported list-looking paragraphs in place, and is tracked-safe. NOT append_list (which starts a brand-new list).
|
|
100254
100613
|
- convert_list: kind:"ordered"|"bullet", with listOrdinal or anchorText for real lists, OR fromMarker+toMarker (rendered clause numbers from inspect, e.g. "2.1.", "2.3.") for NUMBERED-CLAUSE ranges — including heading-styled clauses, OR fromText+toText (exact text inside the FIRST and LAST of consecutive plain paragraphs) to convert existing paragraphs into a list IN PLACE. Sub-clauses in range included automatically. THE way to convert numbering<->bullets AND the way to make existing paragraphs a list; never rewrite text to fake it, never recreate-the-content-then-delete-the-originals (two chances to lose text — convert_list fromText/toText is one lossless call).
|
|
100255
100614
|
- split_list: anchorText (text inside the item that should START the second list), restartNumbering? (default true). Splits ONE list into two at that item — the new list restarts at 1, nested sub-items stay with their parent. THE way to "split the list starting at item N into a new list with reset numbering"; never fake it with convert_list/attach_numbering. changeMode:"tracked" records the change for review.
|
|
100256
100615
|
- undo_changes: untilMarker (rendered marker from the original state, e.g. "2.1.") or steps (1-25). Deterministic revert — steps history back until the marker reappears; the receipt proves it. NEVER use steps > 1 blindly: prefer untilMarker, and after ANY undo verify (superdoc_inspect) that content you meant to KEEP still exists — if you overshot, redo_changes {steps:N} steps forward again to recover it.
|
|
100257
100616
|
- redo_changes: steps (1-25, default 1). Steps history FORWARD to re-apply edits a prior undo removed — THE recovery for an undo overshoot. Only reaches the forward branch until a NEW edit is made.
|
|
100258
|
-
- attach_numbering: anchorText (text of the block) or nodeId, likeMarker (rendered marker of a sibling clause, e.g. "10."). Makes an EXISTING block a numbered clause at the same scheme/level — "make this the section 11 heading" in a clause-numbered document is exactly this (it will render as the next number).
|
|
100617
|
+
- attach_numbering: anchorText (text of the block) or nodeId, likeMarker (rendered marker of a sibling clause, e.g. "10."). Scheme numbering only (it fails where the numbers are typed text). Makes an EXISTING block a numbered clause at the same scheme/level — "make this the section 11 heading" in a clause-numbered document is exactly this (it will render as the next number).
|
|
100259
100618
|
- replace_text: edits:[{find,replace,occurrence?}], caseSensitive default false. selector to scope. Keep find/replace spans MINIMAL. If the find appears more than once in the selected block and only one should change, give that edit occurrence (1 = first match in the block; needs selector; not selector.occurrence). With occurrence, also pass expectedRevision from your latest inspect or receipt; on REVISION_CONFLICT inspect again and recount. changeMode:"tracked" if asked. The receipt reports editsApplied and editsSkipped per find — READ IT: a skipped find is not in the selected block; re-target instead of assuming success.
|
|
100260
100619
|
- delete_text: finds:[string]. selector to scope deletions to ONE block — REQUIRED for whitespace-only finds (unscoped whitespace matches document-wide and is refused). changeMode:"tracked" if asked. Deletes TEXT ONLY: the block survives, so a list item keeps its bullet/number and an accepted tracked deletion leaves an empty numbered item behind. To remove the item itself use delete_blocks.
|
|
100261
|
-
- delete_blocks: selectors:[…], each resolving to ONE block (list item, paragraph or heading). changeMode:"tracked" if asked. THE way to DELETE a whole LIST ITEM, paragraph or heading — the bullet/number goes with it and the
|
|
100620
|
+
- delete_blocks: selectors:[…], each resolving to ONE block (list item, paragraph or heading). changeMode:"tracked" if asked. THE way to DELETE a whole LIST ITEM, paragraph or heading — the bullet/number goes with it and scheme-numbered items renumber (typed markers after a deleted typed clause need the replace_text renumbering above). "Delete the first item under Article II" / "remove that clause" is exactly this, NOT delete_text. Pass every target in ONE call. Use delete_table for a whole table. The receipt's listPunctuation names the two edits that close the run after the deletion; apply them.
|
|
100262
100621
|
- rewrite_block: selector, text. Inspect first to gather current text; never ask the user to paste text already in the doc.
|
|
100263
100622
|
- create_table: rows, columns, optional cellTexts (2D array). rows counts ALL rows INCLUDING the header — header plus one data row is rows:2. placement defaults to document end. changeMode:"tracked" if asked ("track-changes table") — the insertion itself becomes a tracked change.
|
|
100264
100623
|
- comment_paragraphs: commentText. excludeBlockQuotes:true to skip block quotes. Applies the SAME text to every BODY paragraph (it does NOT comment the title/heading) — broadcast notes only, never review feedback (see REVIEW rule). To comment a heading too, add_comments on it explicitly.
|
|
@@ -100304,7 +100663,7 @@ OPERATING RULES
|
|
|
100304
100663
|
- REVERTS: "undo / revert / make it back" = superdoc_perform_action undo_changes with untilMarker from the original state (a convert receipt's revertHint contains the exact call) — NEVER re-convert or re-edit to approximate the old state.
|
|
100305
100664
|
- If the request names a target descriptively ("the indented heading", "the second clause"), inspect FIRST and use the block's actual text or nodeId — never invent find text.
|
|
100306
100665
|
- Numbered legal clauses ("2.3.") usually live on numbered HEADINGS, not lists: if counts.lists is 0 but blocks carry numbering markers, target those blocks by nodeId. "Add item 2.4" = insert_paragraphs (one text) after the "2.3." block; the tool attaches numbering and matches formatting automatically (check receipt.contextualFormatting).
|
|
100307
|
-
- ADDING SEVERAL items to an existing list or numbered sequence = ONE add_list_items call (it joins the sequence and is tracked-safe — it works even when the "list" is clause numbering and counts.lists is 0). NEVER a chain of insert_paragraphs calls: multi-paragraph inserts do not auto-join numbering, and the items will land as plain paragraphs.
|
|
100666
|
+
- ADDING SEVERAL items to an existing list or scheme-numbered sequence = ONE add_list_items call (it joins the sequence and is tracked-safe — it works even when the "list" is clause numbering with markers and counts.lists is 0). NEVER a chain of insert_paragraphs calls there: multi-paragraph inserts do not auto-join numbering, and the items will land as plain paragraphs. TYPED sequences are the exception: ONE insert_paragraphs call whose texts carry the typed markers.
|
|
100308
100667
|
- New SECTION headings use the SAME headingLevel as sibling section headings (title is usually level 1; sections 2+). Never default to level 1.
|
|
100309
100668
|
- paragraphOrdinal counts visible non-empty paragraphs; bodyParagraphOrdinal counts substantive body paragraphs after front matter. Prefer paragraphOrdinal for "first/second paragraph".
|
|
100310
100669
|
- For literal ordinal rewrites, do not switch paragraphs because the matched one looks title-like or short. If a rewrite is a no-op, keep the target and change the rewrite.
|
|
@@ -327464,7 +327823,8 @@ function insertXmlAtCollapsedTopLevelWrapperBoundary(paragraphXml, offset, inser
|
|
|
327464
327823
|
const childTextEnd = childTextStart + visibleTextLength3(childXml);
|
|
327465
327824
|
textCursor = childTextEnd;
|
|
327466
327825
|
cursor = childEnd;
|
|
327467
|
-
|
|
327826
|
+
const boundaryChild = COLLAPSED_INSERTION_BOUNDARY_WRAPPERS.has(localName2) || localName2 === "r" && !parsePlainRun2(childXml, childTextStart, childStart, childEnd).ok;
|
|
327827
|
+
if (!boundaryChild || childTextStart === childTextEnd) {
|
|
327468
327828
|
continue;
|
|
327469
327829
|
}
|
|
327470
327830
|
if (offset === childTextStart) {
|
|
@@ -327596,7 +327956,9 @@ function insertXmlAtRangeStartInSimpleFieldResultInParagraphXml(input) {
|
|
|
327596
327956
|
return { ok: true, xml };
|
|
327597
327957
|
}
|
|
327598
327958
|
function projectMatchRuns(input) {
|
|
327599
|
-
const collected = collectPlainTextRuns2(input.paragraphXml, input.rangeStart, input.rangeEnd
|
|
327959
|
+
const collected = collectPlainTextRuns2(input.paragraphXml, input.rangeStart, input.rangeEnd, {
|
|
327960
|
+
splitMixedRuns: true
|
|
327961
|
+
});
|
|
327600
327962
|
if (!collected.ok) {
|
|
327601
327963
|
input.onProjectionUnavailable?.();
|
|
327602
327964
|
return [
|
|
@@ -327682,7 +328044,7 @@ function collectPlainTextRuns2(paragraphXml, rangeStart, rangeEnd, options = {})
|
|
|
327682
328044
|
const markers = scanComplexFieldMarkers2(childXml);
|
|
327683
328045
|
complexFieldDepth = Math.max(0, complexFieldDepth + markers.begins - markers.ends);
|
|
327684
328046
|
complexFieldResultDepth = Math.max(0, complexFieldResultDepth + markers.separates - markers.ends);
|
|
327685
|
-
const parsed = parsePlainRun2(childXml, childTextStart, cursor - childXml.length, cursor);
|
|
328047
|
+
const parsed = options.splitMixedRuns ? parsePlainRunLeaves(childXml, childTextStart, cursor - childXml.length, cursor) : parsePlainRun2(childXml, childTextStart, cursor - childXml.length, cursor);
|
|
327686
328048
|
if (!parsed.ok) {
|
|
327687
328049
|
if (intersects) {
|
|
327688
328050
|
return { ok: false, reason: parsed.reason };
|
|
@@ -327698,7 +328060,10 @@ function collectPlainTextRuns2(paragraphXml, rangeStart, rangeEnd, options = {})
|
|
|
327698
328060
|
if (fieldDepthBefore > 0 && fieldResultDepthBefore > 0 && !options.allowFieldResultContent && rangesOverlap7(childTextStart, childTextEnd, rangeStart, rangeEnd)) {
|
|
327699
328061
|
return { ok: false, reason: "text-range-in-field" };
|
|
327700
328062
|
}
|
|
327701
|
-
runs
|
|
328063
|
+
if ("runs" in parsed)
|
|
328064
|
+
runs.push(...parsed.runs);
|
|
328065
|
+
else
|
|
328066
|
+
runs.push(parsed.run);
|
|
327702
328067
|
continue;
|
|
327703
328068
|
}
|
|
327704
328069
|
if (localName2 === "ins" || localName2 === "del" || localName2 === "moveFrom" || localName2 === "moveTo") {
|
|
@@ -327791,6 +328156,63 @@ function parsePlainRun2(runXml, textStart, xmlStart, xmlEnd) {
|
|
|
327791
328156
|
}
|
|
327792
328157
|
};
|
|
327793
328158
|
}
|
|
328159
|
+
function parsePlainRunLeaves(runXml, textStart, xmlStart, xmlEnd) {
|
|
328160
|
+
const single = parsePlainRun2(runXml, textStart, xmlStart, xmlEnd);
|
|
328161
|
+
if (single.ok)
|
|
328162
|
+
return { ok: true, runs: [single.run] };
|
|
328163
|
+
if (single.reason !== "invalid-range")
|
|
328164
|
+
return single;
|
|
328165
|
+
const run = parseContainerXml(runXml, "r");
|
|
328166
|
+
if (!run)
|
|
328167
|
+
return single;
|
|
328168
|
+
const children2 = parseTopLevelChildren(run.inner);
|
|
328169
|
+
const rPr = getChildXml(children2, "rPr") ?? "";
|
|
328170
|
+
const runs = [];
|
|
328171
|
+
let cursor = textStart;
|
|
328172
|
+
for (const child of children2) {
|
|
328173
|
+
if (child.localName === "rPr")
|
|
328174
|
+
continue;
|
|
328175
|
+
let text;
|
|
328176
|
+
let kind;
|
|
328177
|
+
if (child.localName === "t") {
|
|
328178
|
+
text = decodeXmlText8(child.xml.replace(/^<[\w.-]+:t\b[^>]*>|<\/[\w.-]+:t>$/g, ""));
|
|
328179
|
+
kind = "text";
|
|
328180
|
+
} else if (child.localName === "tab") {
|
|
328181
|
+
text = "\t";
|
|
328182
|
+
kind = "tab";
|
|
328183
|
+
} else if (child.localName === "br" || child.localName === "cr") {
|
|
328184
|
+
const breakType = child.localName === "br" ? readAttr2(child.xml, "type") : null;
|
|
328185
|
+
if (child.localName === "br" && breakType && breakType !== "textWrapping") {
|
|
328186
|
+
return { ok: false, reason: "unsupported-context" };
|
|
328187
|
+
}
|
|
328188
|
+
text = `
|
|
328189
|
+
`;
|
|
328190
|
+
kind = child.localName;
|
|
328191
|
+
} else {
|
|
328192
|
+
const marker = child.localName === "bookmarkStart" || child.localName === "bookmarkEnd" || child.localName === "commentRangeStart" || child.localName === "commentRangeEnd" || child.localName === "commentReference";
|
|
328193
|
+
if (marker)
|
|
328194
|
+
continue;
|
|
328195
|
+
return single;
|
|
328196
|
+
}
|
|
328197
|
+
runs.push({
|
|
328198
|
+
kind,
|
|
328199
|
+
xmlStart,
|
|
328200
|
+
xmlEnd,
|
|
328201
|
+
xml: runXml,
|
|
328202
|
+
open: run.open,
|
|
328203
|
+
prefix: run.prefix,
|
|
328204
|
+
textStart: cursor,
|
|
328205
|
+
textEnd: cursor + text.length,
|
|
328206
|
+
text,
|
|
328207
|
+
rPr,
|
|
328208
|
+
leafXml: kind === "text" ? null : child.xml
|
|
328209
|
+
});
|
|
328210
|
+
cursor += text.length;
|
|
328211
|
+
}
|
|
328212
|
+
if (runs.length === 0 || cursor - textStart !== visibleTextLength3(runXml))
|
|
328213
|
+
return single;
|
|
328214
|
+
return { ok: true, runs };
|
|
328215
|
+
}
|
|
327794
328216
|
function buildRunSpan2(runs, rangeStart, rangeEnd) {
|
|
327795
328217
|
if (rangeEnd <= rangeStart)
|
|
327796
328218
|
return { ok: false, reason: "invalid-range" };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdoc/mcp",
|
|
3
|
-
"version": "1.10.0-next.
|
|
3
|
+
"version": "1.10.0-next.13",
|
|
4
4
|
"description": "Model Context Protocol server for SuperDoc, giving an AI agent tools to read and edit .docx files.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
27
|
-
"@superdoc/sdk": "2.23.0-next.
|
|
27
|
+
"@superdoc/sdk": "2.23.0-next.13",
|
|
28
28
|
"debug": "^4.4.3",
|
|
29
29
|
"zod": "^4.3.6"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"superdoc": "2.26.0-next.
|
|
33
|
-
"@superdoc/docx-engine": "0.25.0-next.
|
|
32
|
+
"superdoc": "2.26.0-next.13",
|
|
33
|
+
"@superdoc/docx-engine": "0.25.0-next.13",
|
|
34
34
|
"@superdoc/document-api": "0.1.0-alpha.0",
|
|
35
35
|
"@types/bun": "^1.3.8",
|
|
36
36
|
"@types/node": "22.19.2",
|