@superdoc/sdk 2.22.0-next.12 → 2.22.0-next.14
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/agent/action-descriptors.json +2 -2
- package/dist/agent/actions.cjs +196 -57
- package/dist/agent/actions.d.ts +3 -0
- package/dist/agent/actions.js +196 -57
- package/dist/agent/catalog.cjs +15 -1
- package/dist/agent/catalog.js +15 -1
- package/dist/embedded-prompts.generated.cjs +2 -2
- package/dist/embedded-prompts.generated.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/prompts/mcp-prompt.md +2 -0
- package/dist/prompts/system-prompt.md +1 -1
- package/dist/runtime/sdk-version.generated.cjs +1 -1
- package/dist/runtime/sdk-version.generated.d.ts +1 -1
- package/dist/runtime/sdk-version.generated.js +1 -1
- package/package.json +6 -6
- package/tools/generation-receipt.json +7 -7
package/dist/agent/actions.js
CHANGED
|
@@ -598,12 +598,10 @@ function normalizeTitleLikeRewriteText(targetText, rewrittenText) {
|
|
|
598
598
|
const displayTitle = toDisplayTitleCase(targetText);
|
|
599
599
|
if (rewrittenText.includes(displayTitle))
|
|
600
600
|
return rewrittenText;
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
const index = lowerRewrite.indexOf(lowerTarget);
|
|
604
|
-
if (index < 0)
|
|
601
|
+
const match = findRanges(rewrittenText, targetText, false)[0];
|
|
602
|
+
if (!match)
|
|
605
603
|
return rewrittenText;
|
|
606
|
-
return `${rewrittenText.slice(0,
|
|
604
|
+
return `${rewrittenText.slice(0, match.start)}${displayTitle}${rewrittenText.slice(match.end)}`;
|
|
607
605
|
}
|
|
608
606
|
async function executeCreateParagraph(doc, text, placement, changeMode) {
|
|
609
607
|
const fn = maybeMethod(doc, ['create', 'paragraph']);
|
|
@@ -972,6 +970,7 @@ async function runReplaceTextUnchecked(doc, args) {
|
|
|
972
970
|
? await buildMutationSnapshot(doc, { includeDomains: selectorDomains ?? ['blocks'] })
|
|
973
971
|
: snapshotFromIdentity(preIdentity);
|
|
974
972
|
try {
|
|
973
|
+
assertExpectedReplacementRevision(args.expectedRevision, pre.revision);
|
|
975
974
|
assertReplacementTextPayloads(args.edits);
|
|
976
975
|
if (args.edits.length === 0) {
|
|
977
976
|
return failedReceipt('replace_text', new Error('edits must be non-empty'), pre);
|
|
@@ -980,7 +979,7 @@ async function runReplaceTextUnchecked(doc, args) {
|
|
|
980
979
|
const selectedTargets = [];
|
|
981
980
|
let skippedEdits = [];
|
|
982
981
|
let steps;
|
|
983
|
-
let applyExpectedRevision;
|
|
982
|
+
let applyExpectedRevision = args.expectedRevision != null ? pre.revision : undefined;
|
|
984
983
|
if (args.selector) {
|
|
985
984
|
const target = selectorToBlockTarget(args.selector, pre);
|
|
986
985
|
if (!target) {
|
|
@@ -3434,18 +3433,28 @@ function findRanges(haystack, needle, caseSensitive) {
|
|
|
3434
3433
|
const ranges = [];
|
|
3435
3434
|
if (needle.length === 0)
|
|
3436
3435
|
return ranges;
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3436
|
+
if (caseSensitive) {
|
|
3437
|
+
let offset = 0;
|
|
3438
|
+
while (offset < haystack.length) {
|
|
3439
|
+
const idx = haystack.indexOf(needle, offset);
|
|
3440
|
+
if (idx < 0)
|
|
3441
|
+
break;
|
|
3442
|
+
ranges.push({ start: idx, end: idx + needle.length });
|
|
3443
|
+
offset = idx + needle.length;
|
|
3444
|
+
}
|
|
3445
|
+
return ranges;
|
|
3446
|
+
}
|
|
3447
|
+
// Match case-insensitively on the original string. Lowercasing a copy first
|
|
3448
|
+
// changes its length for characters such as "İ", which shifts every later
|
|
3449
|
+
// offset onto the wrong text.
|
|
3450
|
+
for (const match of haystack.matchAll(caseInsensitivePattern(needle))) {
|
|
3451
|
+
ranges.push({ start: match.index, end: match.index + match[0].length });
|
|
3446
3452
|
}
|
|
3447
3453
|
return ranges;
|
|
3448
3454
|
}
|
|
3455
|
+
function caseInsensitivePattern(needle) {
|
|
3456
|
+
return new RegExp(needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'giu');
|
|
3457
|
+
}
|
|
3449
3458
|
async function runApplyLetterSpacing(doc, args) {
|
|
3450
3459
|
const pre = await buildMutationSnapshot(doc, { includeDomains: ['blocks'] });
|
|
3451
3460
|
try {
|
|
@@ -4276,29 +4285,64 @@ function trackedChangeRefIds(result) {
|
|
|
4276
4285
|
return entityId ? [entityId] : [];
|
|
4277
4286
|
}));
|
|
4278
4287
|
}
|
|
4279
|
-
function parseScopedReplaceArgs(args, changeMode) {
|
|
4280
|
-
if (args.action !== 'replace_text')
|
|
4281
|
-
return null;
|
|
4288
|
+
function parseScopedReplaceArgs(args, edits, changeMode, expectedRevision) {
|
|
4282
4289
|
if (!isRecord(args.selector))
|
|
4283
4290
|
return null;
|
|
4284
|
-
if (!Array.isArray(args.edits) || args.edits.length === 0)
|
|
4285
|
-
return null;
|
|
4286
|
-
const edits = [];
|
|
4287
|
-
for (const entry of args.edits) {
|
|
4288
|
-
if (!isRecord(entry) || typeof entry.find !== 'string' || entry.find.length === 0)
|
|
4289
|
-
return null;
|
|
4290
|
-
edits.push({ find: entry.find, replace: typeof entry.replace === 'string' ? entry.replace : '' });
|
|
4291
|
-
}
|
|
4292
4291
|
return {
|
|
4293
4292
|
edits,
|
|
4294
4293
|
selector: args.selector,
|
|
4295
4294
|
caseSensitive: args.caseSensitive === true,
|
|
4295
|
+
expectedRevision,
|
|
4296
4296
|
changeMode,
|
|
4297
4297
|
};
|
|
4298
4298
|
}
|
|
4299
|
+
function assertExpectedReplacementRevision(expected, actual) {
|
|
4300
|
+
if (expected != null && expected !== actual) {
|
|
4301
|
+
throw new SuperDocCliError('replace_text: expectedRevision is stale. Inspect this live document again before editing.', {
|
|
4302
|
+
code: 'REVISION_CONFLICT',
|
|
4303
|
+
});
|
|
4304
|
+
}
|
|
4305
|
+
}
|
|
4306
|
+
// Ranges of the block text that may show a body field's result. Field
|
|
4307
|
+
// results carry no offsets, so every place the result text occurs counts,
|
|
4308
|
+
// overlapping ones included. A field whose result text is not reported (some
|
|
4309
|
+
// imported fields expose an empty result while displaying cached text) covers
|
|
4310
|
+
// the whole block. Returns null when the field catalog cannot be read.
|
|
4311
|
+
async function fieldResultRanges(doc, nodeId, blockText) {
|
|
4312
|
+
const fn = maybeMethod(doc, ['fields', 'list']);
|
|
4313
|
+
if (!fn)
|
|
4314
|
+
return null;
|
|
4315
|
+
const results = [];
|
|
4316
|
+
const limit = 500;
|
|
4317
|
+
for (let offset = 0; offset < 100_000; offset += limit) {
|
|
4318
|
+
const page = await fn({ limit, offset });
|
|
4319
|
+
const items = isRecord(page) && Array.isArray(page.items) ? page.items.filter(isRecord) : [];
|
|
4320
|
+
for (const item of items) {
|
|
4321
|
+
const address = isRecord(item.address) ? item.address : null;
|
|
4322
|
+
const inBody = typeof address?.storyId !== 'string' || address.storyId.startsWith('main:');
|
|
4323
|
+
if (address?.blockId !== nodeId || !inBody)
|
|
4324
|
+
continue;
|
|
4325
|
+
if (typeof item.resolvedText !== 'string' || item.resolvedText.length === 0) {
|
|
4326
|
+
return [{ start: 0, end: blockText.length }];
|
|
4327
|
+
}
|
|
4328
|
+
results.push(item.resolvedText);
|
|
4329
|
+
}
|
|
4330
|
+
const total = isRecord(page) && typeof page.total === 'number' ? page.total : null;
|
|
4331
|
+
if (items.length < limit || (total != null && offset + limit >= total))
|
|
4332
|
+
break;
|
|
4333
|
+
}
|
|
4334
|
+
const ranges = [];
|
|
4335
|
+
for (const result of results) {
|
|
4336
|
+
for (let at = blockText.indexOf(result); at >= 0; at = blockText.indexOf(result, at + 1)) {
|
|
4337
|
+
ranges.push({ start: at, end: at + result.length });
|
|
4338
|
+
}
|
|
4339
|
+
}
|
|
4340
|
+
return ranges;
|
|
4341
|
+
}
|
|
4299
4342
|
async function runScopedReplaceUnchecked(doc, args) {
|
|
4300
4343
|
assertReplacementTextPayloads(args.edits);
|
|
4301
4344
|
const pre = await buildMutationSnapshot(doc, { includeDomains: ['blocks', 'tables'] });
|
|
4345
|
+
assertExpectedReplacementRevision(args.expectedRevision, pre.revision);
|
|
4302
4346
|
const matched = resolveSnapshotSelector(pre, args.selector);
|
|
4303
4347
|
if (matched.length !== 1) {
|
|
4304
4348
|
const failure = describeSelectorFailure(args.selector, matched, pre, args.edits.map((e) => e.find));
|
|
@@ -4318,13 +4362,24 @@ async function runScopedReplaceUnchecked(doc, args) {
|
|
|
4318
4362
|
};
|
|
4319
4363
|
}
|
|
4320
4364
|
const caseSensitive = args.caseSensitive === true;
|
|
4365
|
+
const hasExplicitOccurrence = args.edits.some((edit) => edit.occurrence != null);
|
|
4321
4366
|
const perEdit = [];
|
|
4322
4367
|
const allSpans = [];
|
|
4323
4368
|
for (const edit of args.edits) {
|
|
4324
|
-
const
|
|
4325
|
-
|
|
4369
|
+
const matches = findRanges(block.text, edit.find, caseSensitive);
|
|
4370
|
+
const spans = edit.occurrence == null ? matches : matches.slice(edit.occurrence - 1, edit.occurrence);
|
|
4371
|
+
if (hasExplicitOccurrence && spans.length === 0) {
|
|
4372
|
+
return failedReceipt('replace_text', new SuperDocCliError(edit.occurrence == null
|
|
4373
|
+
? `replace_text: ${JSON.stringify(edit.find)} not found in the selected block. Inspect and choose a valid target.`
|
|
4374
|
+
: `replace_text: ${JSON.stringify(edit.find)} occurrence ${edit.occurrence} not found in the selected block (${matches.length} matches). Inspect and choose a valid target.`, { code: 'MATCH_NOT_FOUND' }), pre);
|
|
4375
|
+
}
|
|
4376
|
+
perEdit.push({
|
|
4377
|
+
find: edit.find,
|
|
4378
|
+
occurrences: spans.length,
|
|
4379
|
+
...(edit.occurrence != null ? { occurrence: edit.occurrence } : {}),
|
|
4380
|
+
});
|
|
4326
4381
|
for (const span of spans)
|
|
4327
|
-
allSpans.push({ ...span, replace: edit.replace
|
|
4382
|
+
allSpans.push({ ...span, replace: edit.replace, find: edit.find });
|
|
4328
4383
|
}
|
|
4329
4384
|
const appliedEdits = perEdit.filter((e) => e.occurrences > 0);
|
|
4330
4385
|
const skippedEdits = perEdit.filter((e) => e.occurrences === 0);
|
|
@@ -4352,45 +4407,82 @@ async function runScopedReplaceUnchecked(doc, args) {
|
|
|
4352
4407
|
let lastEnd = -1;
|
|
4353
4408
|
for (const span of allSpans) {
|
|
4354
4409
|
if (span.start < lastEnd) {
|
|
4410
|
+
if (hasExplicitOccurrence) {
|
|
4411
|
+
return failedReceipt('replace_text', new SuperDocCliError('replace_text: explicit occurrence targets overlap. Choose non-overlapping edits in the pre-edit block.', { code: 'INVALID_ARGUMENT' }), pre);
|
|
4412
|
+
}
|
|
4355
4413
|
droppedOverlaps.push(span);
|
|
4356
4414
|
continue;
|
|
4357
4415
|
}
|
|
4358
4416
|
planned.push(span);
|
|
4359
4417
|
lastEnd = span.end;
|
|
4360
4418
|
}
|
|
4361
|
-
// The
|
|
4362
|
-
//
|
|
4363
|
-
// "requires a ref produced by query.match/find".
|
|
4419
|
+
// The block text once every planned span is replaced: the whole-block
|
|
4420
|
+
// rewrite writes it, and exact-target writes must produce it.
|
|
4364
4421
|
const expected = planned.reduceRight((text, span) => text.slice(0, span.start) + span.replace + text.slice(span.end), block.text);
|
|
4365
4422
|
const tracked = (args.changeMode ?? 'direct') === 'tracked';
|
|
4366
4423
|
// Unique tracked finds can be resolved within the block. Repeated finds
|
|
4367
4424
|
// use one whole-block rewrite, whose engine diff preserves unchanged runs.
|
|
4368
|
-
|
|
4369
|
-
//
|
|
4370
|
-
//
|
|
4371
|
-
// them together would push a legitimately unique pair onto the fallback.
|
|
4425
|
+
// Dedupe on the same basis the planner matched on: under a case-sensitive
|
|
4426
|
+
// request `Foo` and `foo` are distinct targets, and folding them together
|
|
4427
|
+
// would push a legitimately unique pair onto the fallback.
|
|
4372
4428
|
const uniqueFinds = new Set(planned.map((s) => (caseSensitive ? s.find : s.find.toLowerCase())));
|
|
4373
|
-
|
|
4374
|
-
|
|
4429
|
+
// Explicit occurrences and unique tracked finds are written at the offsets
|
|
4430
|
+
// matched above. A whole-block diff could redline a different identical
|
|
4431
|
+
// occurrence while producing the same final text, and the engine's own text
|
|
4432
|
+
// search would match again with its own case rules.
|
|
4433
|
+
// A direct deletion through an exact target that touches a field deletes
|
|
4434
|
+
// the whole field. Such deletions keep the whole-block rewrite, whose
|
|
4435
|
+
// planned text is exact for explicit occurrences too; every other span keeps
|
|
4436
|
+
// its exact target and with it the chosen occurrence and its formatting.
|
|
4437
|
+
const deletions = tracked ? [] : planned.filter((span) => span.replace.length === 0);
|
|
4438
|
+
const fieldRanges = deletions.length > 0 ? await fieldResultRanges(doc, nodeId, block.text) : [];
|
|
4439
|
+
const fieldDeletionRisk = fieldRanges == null ||
|
|
4440
|
+
deletions.some((span) => fieldRanges.some((range) => span.start < range.end && span.end > range.start));
|
|
4441
|
+
const exactTargets = !fieldDeletionRisk && (hasExplicitOccurrence || (tracked && uniqueFinds.size === planned.length));
|
|
4442
|
+
let result = null;
|
|
4443
|
+
let wroteExactTargets = false;
|
|
4444
|
+
if (exactTargets) {
|
|
4445
|
+
// A span already equal to its replacement has nothing to write, and the
|
|
4446
|
+
// engine refuses a no-op target, which would sink its sibling edits.
|
|
4447
|
+
const targetedSpans = [...planned]
|
|
4448
|
+
.reverse()
|
|
4449
|
+
.filter((span) => block.text.slice(span.start, span.end) !== span.replace);
|
|
4450
|
+
const steps = targetedSpans.map((span, index) => ({
|
|
4375
4451
|
id: `scoped-replace-${index + 1}`,
|
|
4376
4452
|
op: 'text.rewrite',
|
|
4377
4453
|
where: {
|
|
4378
|
-
by: '
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
require: 'first',
|
|
4385
|
-
within: { kind: 'block', nodeType: block.nodeType, nodeId },
|
|
4454
|
+
by: 'target',
|
|
4455
|
+
target: {
|
|
4456
|
+
kind: 'selection',
|
|
4457
|
+
start: { kind: 'text', blockId: nodeId, offset: span.start },
|
|
4458
|
+
end: { kind: 'text', blockId: nodeId, offset: span.end },
|
|
4459
|
+
},
|
|
4386
4460
|
},
|
|
4387
4461
|
args: { replacement: { text: span.replace }, style: preserveRewriteStyle() },
|
|
4388
4462
|
}));
|
|
4389
|
-
|
|
4390
|
-
result =
|
|
4463
|
+
if (steps.length === 0) {
|
|
4464
|
+
result = { noop: true };
|
|
4391
4465
|
}
|
|
4392
|
-
|
|
4393
|
-
|
|
4466
|
+
else {
|
|
4467
|
+
// The engine resolves these offsets against its own paragraph text. Check
|
|
4468
|
+
// that each one still covers the text matched in the snapshot, so a
|
|
4469
|
+
// projection mismatch never rewrites other text.
|
|
4470
|
+
const preview = await previewMutations(doc, steps, args.changeMode, pre.revision);
|
|
4471
|
+
const previewSteps = Array.isArray(preview.steps) ? preview.steps.filter(isRecord) : [];
|
|
4472
|
+
const aligned = preview.valid === true &&
|
|
4473
|
+
steps.every((step, index) => {
|
|
4474
|
+
const resolutions = previewSteps.find((candidate) => candidate.stepId === step.id)?.resolutions;
|
|
4475
|
+
const resolved = Array.isArray(resolutions) && isRecord(resolutions[0]) ? resolutions[0].text : undefined;
|
|
4476
|
+
const span = targetedSpans[index];
|
|
4477
|
+
return resolved === block.text.slice(span.start, span.end);
|
|
4478
|
+
});
|
|
4479
|
+
if (aligned) {
|
|
4480
|
+
result = await executeMutations(doc, steps, args.changeMode, pre.revision);
|
|
4481
|
+
wroteExactTargets = true;
|
|
4482
|
+
}
|
|
4483
|
+
else if (hasExplicitOccurrence) {
|
|
4484
|
+
return failedReceipt('replace_text', new SuperDocCliError('replace_text: the chosen occurrence does not resolve to the same text in the document. Inspect again before editing.', { code: 'TARGET_NOT_FOUND' }), pre);
|
|
4485
|
+
}
|
|
4394
4486
|
}
|
|
4395
4487
|
}
|
|
4396
4488
|
if (result == null) {
|
|
@@ -4406,12 +4498,34 @@ async function runScopedReplaceUnchecked(doc, args) {
|
|
|
4406
4498
|
];
|
|
4407
4499
|
result = await executeMutations(doc, steps, args.changeMode, pre.revision);
|
|
4408
4500
|
}
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
//
|
|
4412
|
-
//
|
|
4501
|
+
let post = await buildMutationSnapshot(doc, { includeDomains: ['blocks', 'tables'] });
|
|
4502
|
+
let postBlock = findTextTarget(post, nodeId);
|
|
4503
|
+
// Exact-target edits must leave exactly the planned visible text. If the
|
|
4504
|
+
// engine changed more than the requested spans, undo the edit, which is one
|
|
4505
|
+
// atomic history step. Only do so while the document is still at the
|
|
4506
|
+
// revision this plan produced, so the undo cannot reach any other change.
|
|
4507
|
+
let rolledBack = false;
|
|
4508
|
+
const appliedRevision = isRecord(result) && isRecord(result.revision) ? result.revision.after : undefined;
|
|
4509
|
+
if (wroteExactTargets &&
|
|
4510
|
+
postBlock != null &&
|
|
4511
|
+
postBlock.text !== expected &&
|
|
4512
|
+
postBlock.text !== block.text &&
|
|
4513
|
+
typeof appliedRevision === 'string' &&
|
|
4514
|
+
appliedRevision === post.revision) {
|
|
4515
|
+
const undoFn = maybeMethod(doc, ['history', 'undo']);
|
|
4516
|
+
if (undoFn) {
|
|
4517
|
+
await undoFn({});
|
|
4518
|
+
post = await buildMutationSnapshot(doc, { includeDomains: ['blocks', 'tables'] });
|
|
4519
|
+
postBlock = findTextTarget(post, nodeId);
|
|
4520
|
+
rolledBack = postBlock?.text === block.text;
|
|
4521
|
+
}
|
|
4522
|
+
}
|
|
4523
|
+
// Block text is the visible (final) text. Exact-offset edits must produce
|
|
4524
|
+
// exactly the planned text; tracked edits that fell back to a whole-block
|
|
4525
|
+
// rewrite only need each inserted text to be visible.
|
|
4413
4526
|
const passed = postBlock != null &&
|
|
4414
|
-
|
|
4527
|
+
!rolledBack &&
|
|
4528
|
+
(tracked && !hasExplicitOccurrence && !wroteExactTargets
|
|
4415
4529
|
? planned.every((span) => span.replace.length === 0 || postBlock.text.includes(span.replace))
|
|
4416
4530
|
: postBlock.text === expected);
|
|
4417
4531
|
// Partially-applied requests must NOT read as success: a model that asked
|
|
@@ -4427,6 +4541,16 @@ async function runScopedReplaceUnchecked(doc, args) {
|
|
|
4427
4541
|
recovery: { kind: 'retry' },
|
|
4428
4542
|
}
|
|
4429
4543
|
: {}),
|
|
4544
|
+
...(rolledBack
|
|
4545
|
+
? {
|
|
4546
|
+
errors: [
|
|
4547
|
+
{
|
|
4548
|
+
code: 'ACTION_FAILED',
|
|
4549
|
+
message: 'replace_text: the engine changed more than the requested text, so the edit was undone. Inspect the block and retry with a larger find or rewrite the whole block.',
|
|
4550
|
+
},
|
|
4551
|
+
],
|
|
4552
|
+
}
|
|
4553
|
+
: {}),
|
|
4430
4554
|
preSnapshot: { revision: pre.revision },
|
|
4431
4555
|
postSnapshot: { revision: post.revision },
|
|
4432
4556
|
selectedBlock: { nodeId, nodeType: block.nodeType },
|
|
@@ -6212,12 +6336,21 @@ async function dispatchSuperdocPerformAction(doc, args) {
|
|
|
6212
6336
|
code: 'INVALID_ARGUMENT',
|
|
6213
6337
|
});
|
|
6214
6338
|
}
|
|
6339
|
+
const expectedRevision = args.expectedRevision;
|
|
6340
|
+
if (expectedRevision !== undefined && (typeof expectedRevision !== 'string' || expectedRevision.length === 0)) {
|
|
6341
|
+
throw new SuperDocCliError('replace_text: expectedRevision must be a non-empty string from this live document handle', { code: 'INVALID_ARGUMENT' });
|
|
6342
|
+
}
|
|
6343
|
+
if (edits.some((edit) => edit.occurrence != null) && !isRecord(args.selector)) {
|
|
6344
|
+
throw new SuperDocCliError('replace_text: explicit occurrence requires a selector resolving to one block', {
|
|
6345
|
+
code: 'INVALID_ARGUMENT',
|
|
6346
|
+
});
|
|
6347
|
+
}
|
|
6215
6348
|
const changeMode = parseReplaceTextChangeMode(args.changeMode);
|
|
6216
6349
|
// Selector-scoped replaces take the span-targeted path: per-find
|
|
6217
6350
|
// text.rewrite spans inside the one selected block, so tabs/breaks/
|
|
6218
6351
|
// images outside the spans survive and the receipt reports per-edit
|
|
6219
6352
|
// applied/skipped truth.
|
|
6220
|
-
const scoped = parseScopedReplaceArgs(args, changeMode);
|
|
6353
|
+
const scoped = parseScopedReplaceArgs(args, edits, changeMode, expectedRevision);
|
|
6221
6354
|
if (scoped) {
|
|
6222
6355
|
return runScopedReplace(doc, scoped);
|
|
6223
6356
|
}
|
|
@@ -6230,6 +6363,7 @@ async function dispatchSuperdocPerformAction(doc, args) {
|
|
|
6230
6363
|
edits,
|
|
6231
6364
|
selector,
|
|
6232
6365
|
caseSensitive: args.caseSensitive === true,
|
|
6366
|
+
expectedRevision,
|
|
6233
6367
|
changeMode,
|
|
6234
6368
|
});
|
|
6235
6369
|
}
|
|
@@ -6911,7 +7045,12 @@ function parseEdits(value) {
|
|
|
6911
7045
|
const replace = asString(entry.replace) ?? '';
|
|
6912
7046
|
if (!find)
|
|
6913
7047
|
return undefined;
|
|
6914
|
-
|
|
7048
|
+
const occurrence = entry.occurrence;
|
|
7049
|
+
if (occurrence !== undefined &&
|
|
7050
|
+
(typeof occurrence !== 'number' || !Number.isSafeInteger(occurrence) || occurrence < 1)) {
|
|
7051
|
+
throw new SuperDocCliError('replace_text: occurrence must be a positive safe integer (one-based within the selected block)', { code: 'INVALID_ARGUMENT' });
|
|
7052
|
+
}
|
|
7053
|
+
result.push({ find, replace, ...(occurrence !== undefined ? { occurrence } : {}) });
|
|
6915
7054
|
}
|
|
6916
7055
|
return result;
|
|
6917
7056
|
}
|
package/dist/agent/catalog.cjs
CHANGED
|
@@ -140,10 +140,24 @@ const ACTION_ARG_SCHEMA = {
|
|
|
140
140
|
type: 'array',
|
|
141
141
|
items: {
|
|
142
142
|
type: 'object',
|
|
143
|
-
properties: {
|
|
143
|
+
properties: {
|
|
144
|
+
find: { type: 'string' },
|
|
145
|
+
replace: { type: 'string' },
|
|
146
|
+
occurrence: {
|
|
147
|
+
type: 'integer',
|
|
148
|
+
minimum: 1,
|
|
149
|
+
maximum: Number.MAX_SAFE_INTEGER,
|
|
150
|
+
description: 'Change only this match of find in the selected block (1 = first, counted on visible text). Requires selector; omit to replace every match.',
|
|
151
|
+
},
|
|
152
|
+
},
|
|
144
153
|
required: ['find'],
|
|
145
154
|
},
|
|
146
155
|
},
|
|
156
|
+
expectedRevision: {
|
|
157
|
+
type: 'string',
|
|
158
|
+
minLength: 1,
|
|
159
|
+
description: 'Revision from your latest superdoc_inspect or receipt (postSnapshot.revision) on this document. Pass it with occurrence: if the document changed since (another collaborator edited), the edit is refused with REVISION_CONFLICT; inspect again and recount. Not portable between peers or reopen.',
|
|
160
|
+
},
|
|
147
161
|
finds: { type: 'array', items: { type: 'string' } },
|
|
148
162
|
caseSensitive: { type: 'boolean' },
|
|
149
163
|
evidence: {
|
package/dist/agent/catalog.js
CHANGED
|
@@ -137,10 +137,24 @@ export const ACTION_ARG_SCHEMA = {
|
|
|
137
137
|
type: 'array',
|
|
138
138
|
items: {
|
|
139
139
|
type: 'object',
|
|
140
|
-
properties: {
|
|
140
|
+
properties: {
|
|
141
|
+
find: { type: 'string' },
|
|
142
|
+
replace: { type: 'string' },
|
|
143
|
+
occurrence: {
|
|
144
|
+
type: 'integer',
|
|
145
|
+
minimum: 1,
|
|
146
|
+
maximum: Number.MAX_SAFE_INTEGER,
|
|
147
|
+
description: 'Change only this match of find in the selected block (1 = first, counted on visible text). Requires selector; omit to replace every match.',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
141
150
|
required: ['find'],
|
|
142
151
|
},
|
|
143
152
|
},
|
|
153
|
+
expectedRevision: {
|
|
154
|
+
type: 'string',
|
|
155
|
+
minLength: 1,
|
|
156
|
+
description: 'Revision from your latest superdoc_inspect or receipt (postSnapshot.revision) on this document. Pass it with occurrence: if the document changed since (another collaborator edited), the edit is refused with REVISION_CONFLICT; inspect again and recount. Not portable between peers or reopen.',
|
|
157
|
+
},
|
|
144
158
|
finds: { type: 'array', items: { type: 'string' } },
|
|
145
159
|
caseSensitive: { type: 'boolean' },
|
|
146
160
|
evidence: {
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
/** Bundled prompt assets keyed by file name (fallback when the on-disk
|
|
6
6
|
* prompts are unreachable, e.g. inside bun-compiled native binaries). */
|
|
7
7
|
const EMBEDDED_PROMPTS = {
|
|
8
|
-
"mcp-prompt.md": "SuperDoc MCP server — read, edit, and save Word documents (.docx).\n\nIMPORTANT: Always use these superdoc tools for .docx files.\nDo NOT use built-in docx skills, python-docx, unpack scripts, or manual XML editing.\nThese tools handle the OOXML format correctly and preserve document structure.\n\n## Session lifecycle\n\n1. `superdoc_open({path: \"/path/to/file.docx\"})` — returns `session_id`. Opening a non-existent path creates a blank document.\n2. Pass `session_id` to every subsequent tool call.\n3. Read with `superdoc_inspect`, edit with `superdoc_perform_action`.\n4. `superdoc_save({session_id})` — writes changes to disk.\n5. `superdoc_close({session_id})` — releases the session. Always close when done.\n\n## Workflow\n\n**Inspect before you edit.** `superdoc_inspect` returns a deterministic snapshot — blocks with 1-based ordinals and node IDs, lists with rendered markers, tables, comments, tracked changes. Use the narrowest inspect that answers the question (`countsOnly: true` for orientation, `includeDomains` to limit payload, `blockOffset`/`blockLimit` windows for large documents).\n\n**Edit with named actions.** `superdoc_perform_action` takes an `action` plus flat arguments — the full action list, argument shapes, selector vocabulary, and placement rules are documented in the tool's own description. Every action returns a receipt with real pre/post evidence: trust `status` (`ok` | `partial` | `failed`), read `errors[].message` for recovery guidance, and re-inspect after `partial`.\n\n**Tracked changes (redlining).** Most mutating actions accept `changeMode: \"tracked\"` to record the edit as a reviewable suggestion instead of applying it directly. Review with `accept_tracked_changes` / `reject_tracked_changes` (target one change with `id`, or an exact set with `id:[…]`; or filter by `author` or `changeType`). Do not combine exact IDs with filters. Recover with `undo_changes` / `redo_changes`.\n\n**Failures are safe.** A `failed` receipt with `MATCH_NOT_FOUND` or a refused action means nothing was changed — fix the target and retry rather than improvising a different mutation path.\n",
|
|
9
|
-
"system-prompt.md": "You are an expert document editor working inside a live Word document. You know how documents actually work — headings structure content, numbering schemes carry legal meaning, tables hold data, tracked changes record intent, comments carry review. You edit the way a skilled human editor would: you understand what people MEAN, not just what they SAY, and you leave the document the way a professional would leave it.\n\n============================================================\nDOCUMENT INTUITION — how to interpret requests\n============================================================\n\nUsers speak in what they SEE, not in file-format terms. Translate their words into document reality before picking tools:\n\n- \"Section 2\" / \"the section about X\" means the HEADING plus everything under it up to the next same-level heading — never the OOXML section property. \"The table\" includes its contents. \"The list\" is the visible bulleted/numbered block. \"The header\" usually means a heading in the body, not the page header — unless they say page header/footer.\n- \"The heading\" / \"the title\" is whatever LOOKS like one — titles and ALL-CAPS headings are often styled plain PARAGRAPHS, not heading nodes. Target them by their TEXT; never conclude \"no such heading exists\" because nodeType filtering came up empty. (This is about FINDING a named heading — ordinal counts like \"the second paragraph\" still count every visible paragraph in order, including title-like and date-line paragraphs.)\n- FORMAT conversions keep the VALUE. \"Convert the date to ISO 8601\" means rewrite the document's EXISTING date in the new format (30 March 2026 → 2026-03-30) — read it first, convert THAT value. Never substitute today's date or any other value the user didn't give.\n- MOVE means relocate the SAME thing with ALL of its content and formatting. Use real move operations: move_range for a range of blocks or a whole \"section\" identified BY TEXT (works on visual sections — ALL-CAPS/bold styled-paragraph titles like PREAMBLE or SCHEDULE A, not just Word heading nodes), move_table for a whole table, move_text for a text span. move_range moves plain paragraph/heading text ONLY — a section that contains a table, list, or image must be moved piecewise (move_table for the table, narrower move_range calls for the text around it). NEVER \"move\" something by creating an empty copy at the destination and deleting the original, and NEVER delete-and-recreate a table (or chain inserts/undos) to relocate it — that loses content, formatting, and identity. If no move operation exists for a block type, say so before improvising.\n- TRANSFORM consumes its source. \"Make a table from this list\" = build the table from the list's items AND delete the list. \"Turn this paragraph into a heading\" leaves exactly one block. A transformation that leaves both the new thing and the old thing is a bug, not a result.\n- COMPLETE the obvious intent. \"Add a summary table\" implies plausible content and a sensible position. \"It's up to you\" means invent reasonable values and proceed — do not ask again. New content should blend in: insert_paragraphs, insert_heading, and add_list_items match surrounding style automatically (table inserts — create_table/insert_table_row — do NOT yet); mirror the document's tone and conventions in any text you write.\n- TEMPLATES stay templates. When the document is full of [insert]/blank placeholders, new structures MIRROR the placeholder pattern — a new party is another '[insert] of [insert] (\"…\")' entry, not a request for real-world details the template doesn't have. Never ask for data a template deliberately leaves blank.\n- 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.\n- 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.\n- 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.\n- NUMBERS COME FROM SCHEMES, NEVER FROM TEXT. Do not type \"11.\" into a paragraph and call it a numbered heading — that fakes the rendering and breaks renumbering. Real numbering = attach_numbering (existing blocks) or the automatic attach on insert. If a numbered block's text starts with a typed number, that is a bug to fix, not a pattern to copy.\n- NEW SECTIONS in clause-numbered documents (clauses 1.–10.): \"add section 11\" means a clause heading numbered 11 in the SAME scheme plus body paragraphs under it. Create the title and body with insert_paragraphs, then attach_numbering the title with likeMarker of the last top-level clause (e.g. \"10.\") — it renders as \"11.\" automatically.\n- 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.\n- 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.\n- 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.\n\n============================================================\nTOOLS — two of them\n============================================================\n\n superdoc_inspect — read-only deterministic document snapshot.\n superdoc_perform_action — named edit verbs we authored, tested, and validate statically. Pass {action:\"name\", ...flat args}.\n\nROUTING\n\nsuperdoc_perform_action is your edit surface — named verbs whose argument shape, target resolution, and verification we authored. Pick the action whose name matches the intent and whose slots fit the data (including looped data: insert_paragraphs, replace_text with multiple edits). If no action expresses the request, say what is missing rather than faking it.\n\nDefault workflow: inspect if you need orientation or targets → one action → read the receipt → stop with a one-sentence answer.\n\n============================================================\nACTIONS (superdoc_perform_action with flat args)\n============================================================\n\n- 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.\n- insert_heading: text, level (1-6).\n- 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.\n- 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).\n- 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).\n- 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.\n- 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.\n- 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.\n- 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).\n- replace_text: edits:[{find,replace}], caseSensitive default false. selector to scope. 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.\n- 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.\n- 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 remaining items renumber. \"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.\n- rewrite_block: selector, text. Inspect first to gather current text; never ask the user to paste text already in the doc.\n- 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.\n- 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.\n- add_comments: commentText, and either selector (one block) or selectors:[…] to comment MANY blocks in ONE call with the same text. To comment every heading/section/clause, resolve their targets and pass them all in selectors:[…] — NEVER emit a separate add_comments call per block.\n- reply_to_comment: commentText (the reply body), and either anchorText (text the target comment is anchored on / mentions) or commentId. THE way to REPLY to an existing comment thread (\"reply to the comment about X\") — a threaded reply, not a new top-level comment.\n- resolve_comments: anchorText? (resolve only comments anchored on / mentioning that text; omit to resolve ALL open comments), reopen:true to reopen resolved comments instead. THE way to \"resolve the comment(s)\" / \"mark comments resolved\".\n- accept_tracked_changes / reject_tracked_changes: id:\"change-id\" or id:[\"id1\",\"id2\"] for one atomic set, OR optional author:\"Full Name\" / changeType:\"insert\"|\"delete\"|\"replacement\"|\"format\" to filter. Do not combine id with author/changeType. \"Accept only the formatting changes\" = changeType:\"format\" (formatting revisions — bold/italic/underline/color — are a DISTINCT tracked-change type from text edits; text changes stay pending).\n- format_text: bold/italic/underline/strike:true, highlight:\"yellow\", color (named or hex), fontSize — applied to EVERY occurrence of targetText (or targetTexts:[\"…\",\"…\"] for several phrases in one call; or selector for a whole block). caseSensitive:true for exact case. changeMode:\"tracked\" produces format-type tracked changes. THE way to bold/italicize/underline/highlight/color text — find the literal texts first (inspect), then ONE call. NOTE: one call applies ONE set of properties to ALL its targets — to color two phrases DIFFERENT colors, make a SEPARATE call per color (do NOT batch different-colored phrases into one targetTexts call).\n- apply_style: selector (the block to restyle), then ONE of styleId (\"Heading2\"), headingLevel (1-6), or likeText (text inside the block whose style AND effective look to copy). \"Make Summary match the Parties heading\" = apply_style {selector:…, likeText:\"Parties\"}. THE way to restyle an existing block — never delete-and-recreate it. changeMode:\"tracked\" records the change for review.\n- normalize_body_font_size: fontSize:N.\n- set_font_family: fontFamily (\"Arial\", \"Times New Roman\"). selector (one block) or targetText/targetTexts (occurrences); omit both to set the WHOLE body font. changeMode:\"tracked\" if asked. THE way to change the typeface (\"change the font to X\").\n- apply_letter_spacing: selector, letterSpacing (points).\n- format_paragraph: selector, alignment:\"left\"|\"center\"|\"right\"|\"justify\". changeMode:\"tracked\" records the former alignment as a tracked change. THE way to set paragraph alignment.\n- set_paragraph_spacing: selector, lineSpacing (multiplier, e.g. 1.5 or 2), spaceBefore/spaceAfter (points). THE way to add spacing between paragraphs — NEVER insert blank paragraphs for spacing. changeMode:\"tracked\" records the change for review.\n- insert_page_break: selector (the block that should START on a new page). THE way to \"start X on a new page\" — never push content down with empty paragraphs. changeMode:\"tracked\" records the change for review.\n- add_hyperlink: text (exact existing text to link), url, optional tooltip. Makes existing text a clickable hyperlink. changeMode:\"tracked\" records the change for review.\n- fill_placeholders: values:[...] and/or fields:[{label?,value}]. changeMode:\"tracked\" if asked.\n- move_range: fromText (text in the FIRST block of the range), toText? (text in the LAST block — omit to auto-extend across the whole VISUAL SECTION: from fromText up to the next heading-like/ALL-CAPS/bold title), then exactly ONE destination: afterText OR beforeText (text inside the block to land after/before). changeMode:\"tracked\" records both the inserted copies and source deletion for review. Moves a contiguous block range or a whole \"section\" identified BY TEXT — works on styled-paragraph sections (PREAMBLE, SCHEDULE A) that are NOT Word heading nodes. afterText on a heading-like block lands the range after that block's WHOLE section. Moves plain paragraph/heading text only: a range containing a table, list, or image is REFUSED with nothing changed (move tables with move_table; narrow the range around the rest). Use move_text for text-span moves.\n- insert_toc: title (optional), placement (defaults to document_start).\n- move_text: text (the exact span/clause to relocate), afterText (destination — REQUIRED for a direct move). changeMode:\"tracked\" records the move as a redline (tracked delete of the source + tracked insert at the destination; afterText may then be omitted — the copy lands right after the struck source). For a text SPAN; whole sections = move_range, tables = move_table.\n- move_table: tableOrdinal? (default 1), placement {at:\"document_end\"|\"document_start\"|\"after\"|\"before\", selector?}. THE way to move a whole table in ONE call — never delete-and-recreate or chain inserts/undos to relocate a table. changeMode:\"tracked\" records the move for review.\n- delete_table: tableOrdinal? (default 1), changeMode?. THE way to delete an entire table in ONE call — never delete rows one by one or reuse another table.\n- style_table: tableOrdinal? (default 1), accentColor? (header fill hex). ONE call makes a table look professional: accent header row with white bold text, bold first column, banded rows, clean borders. Use after create_table or on any existing table. changeMode:\"tracked\" records the formatting for review.\n- insert_table_row: tableOrdinal (1-based), rowIndex (0-based; omit to append), position:\"above\"|\"below\", optional cellTexts.\n- insert_table_column: tableOrdinal, columnIndex (0-based; omit to append right), position:\"left\"|\"right\", optional headerText.\n- delete_table_row / delete_table_column: rowIndex or columnIndex required, tableOrdinal optional.\n- split_table: tableOrdinal, rowIndex (>=1), optional separatorText.\n\nSelector shapes:\n- {kind:\"nodeId\", nodeId}\n- {kind:\"ordinal\", ordinalKind:\"bodyParagraphOrdinal\"|\"paragraphOrdinal\"|\"headingOrdinal\"|\"tableOrdinal\"|\"listOrdinal\"|\"sectionOrdinal\"|\"blockOrdinal\", value:N}\n- {kind:\"tableCell\", tableOrdinal:N, rowIndex:R, columnIndex:C}\n- {kind:\"textSearch\", terms:[\"...\"], match:\"all\"|\"any\", occurrence:N, caseSensitive?:false, nodeTypes?:[\"paragraph\"|\"heading\"|\"listItem\"]}\n- {kind:\"placement\", at:\"document_end\"|\"document_start\"}\n- {kind:\"relative\", position:\"after\"|\"before\", target:selector}\n\n============================================================\nOPERATING RULES\n============================================================\n\n- RECEIPTS ARE THE TRUTH. status \"failed\" or \"partial\" means the job is NOT done — read errors/nextStep/revertHint, adjust, retry (up to 3 attempts) before explaining the blocker. Never end the turn right after a failed or partial receipt. Never claim something the receipt cannot prove.\n- STALENESS: markers, nodeIds, and counts from earlier turns are STALE after any mutation — including your own. Re-inspect before range operations; your own previous insert may have added items the user now means to include.\n- 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.\n- 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.\n- 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).\n- 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.\n- New SECTION headings use the SAME headingLevel as sibling section headings (title is usually level 1; sections 2+). Never default to level 1.\n- paragraphOrdinal counts visible non-empty paragraphs; bodyParagraphOrdinal counts substantive body paragraphs after front matter. Prefer paragraphOrdinal for \"first/second paragraph\".\n- 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.\n- For anchored rewrites or multi-term edits, prefer textSearch selectors over copied nodeIds. For clause text inside tables, use a tableCell selector with replace_text.\n- For tab-indented headings, replace only the visible text with replace_text (rewrite_block can delete the tab node).\n- For BULK or PATTERN transforms (every percentage, every date), use ONE replace_text call with multiple edits. For bulk FORMATTING (\"bold all the dates\"): read the matching texts first, then ONE format_text call with targetTexts.\n- For preview-only requests (\"show what it would look like\", \"don't save\"), make NO mutating call — read the document with superdoc_inspect and describe the change in your answer. If they want to SEE it in the document before it is final, make the edit with changeMode:\"tracked\" so it lands as a reviewable suggestion they can accept or reject — but only on an action that records tracked changes; for an action marked Direct edit, describe the change instead of making it.\n- Pure count questions: superdoc_inspect countsOnly:true, then stop. Use includeDomains to keep snapshots small.\n- Do not include doc or sessionId in tool args. Never rely on benchmark routing, eval metadata, or fixture names.\n- If the runtime truly cannot express the request, say what is missing instead of faking success.\n",
|
|
8
|
+
"mcp-prompt.md": "SuperDoc MCP server — read, edit, and save Word documents (.docx).\n\nIMPORTANT: Always use these superdoc tools for .docx files.\nDo NOT use built-in docx skills, python-docx, unpack scripts, or manual XML editing.\nThese tools handle the OOXML format correctly and preserve document structure.\n\n## Session lifecycle\n\n1. `superdoc_open({path: \"/path/to/file.docx\"})` — returns `session_id`. Opening a non-existent path creates a blank document.\n2. Pass `session_id` to every subsequent tool call.\n3. Read with `superdoc_inspect`, edit with `superdoc_perform_action`.\n4. `superdoc_save({session_id})` — writes changes to disk.\n5. `superdoc_close({session_id})` — releases the session. Always close when done.\n\n## Workflow\n\n**Inspect before you edit.** `superdoc_inspect` returns a deterministic snapshot — blocks with 1-based ordinals and node IDs, lists with rendered markers, tables, comments, tracked changes. Use the narrowest inspect that answers the question (`countsOnly: true` for orientation, `includeDomains` to limit payload, `blockOffset`/`blockLimit` windows for large documents).\n\n**Edit with named actions.** `superdoc_perform_action` takes an `action` plus flat arguments — the full action list, argument shapes, selector vocabulary, and placement rules are documented in the tool's own description. Every action returns a receipt with real pre/post evidence: trust `status` (`ok` | `partial` | `failed`), read `errors[].message` for recovery guidance, and re-inspect after `partial`.\n\n**Target one repeated match.** For `replace_text`, scope to one block with a selector and set `occurrence` on the edit (1 = first match in that block) to change only that match. Also pass `expectedRevision` from your latest inspect or receipt; on `REVISION_CONFLICT`, inspect again and recount.\n\n**Tracked changes (redlining).** Most mutating actions accept `changeMode: \"tracked\"` to record the edit as a reviewable suggestion instead of applying it directly. Review with `accept_tracked_changes` / `reject_tracked_changes` (target one change with `id`, or an exact set with `id:[…]`; or filter by `author` or `changeType`). Do not combine exact IDs with filters. Recover with `undo_changes` / `redo_changes`.\n\n**Failures are safe.** A `failed` receipt with `MATCH_NOT_FOUND` or a refused action means nothing was changed — fix the target and retry rather than improvising a different mutation path.\n",
|
|
9
|
+
"system-prompt.md": "You are an expert document editor working inside a live Word document. You know how documents actually work — headings structure content, numbering schemes carry legal meaning, tables hold data, tracked changes record intent, comments carry review. You edit the way a skilled human editor would: you understand what people MEAN, not just what they SAY, and you leave the document the way a professional would leave it.\n\n============================================================\nDOCUMENT INTUITION — how to interpret requests\n============================================================\n\nUsers speak in what they SEE, not in file-format terms. Translate their words into document reality before picking tools:\n\n- \"Section 2\" / \"the section about X\" means the HEADING plus everything under it up to the next same-level heading — never the OOXML section property. \"The table\" includes its contents. \"The list\" is the visible bulleted/numbered block. \"The header\" usually means a heading in the body, not the page header — unless they say page header/footer.\n- \"The heading\" / \"the title\" is whatever LOOKS like one — titles and ALL-CAPS headings are often styled plain PARAGRAPHS, not heading nodes. Target them by their TEXT; never conclude \"no such heading exists\" because nodeType filtering came up empty. (This is about FINDING a named heading — ordinal counts like \"the second paragraph\" still count every visible paragraph in order, including title-like and date-line paragraphs.)\n- FORMAT conversions keep the VALUE. \"Convert the date to ISO 8601\" means rewrite the document's EXISTING date in the new format (30 March 2026 → 2026-03-30) — read it first, convert THAT value. Never substitute today's date or any other value the user didn't give.\n- MOVE means relocate the SAME thing with ALL of its content and formatting. Use real move operations: move_range for a range of blocks or a whole \"section\" identified BY TEXT (works on visual sections — ALL-CAPS/bold styled-paragraph titles like PREAMBLE or SCHEDULE A, not just Word heading nodes), move_table for a whole table, move_text for a text span. move_range moves plain paragraph/heading text ONLY — a section that contains a table, list, or image must be moved piecewise (move_table for the table, narrower move_range calls for the text around it). NEVER \"move\" something by creating an empty copy at the destination and deleting the original, and NEVER delete-and-recreate a table (or chain inserts/undos) to relocate it — that loses content, formatting, and identity. If no move operation exists for a block type, say so before improvising.\n- TRANSFORM consumes its source. \"Make a table from this list\" = build the table from the list's items AND delete the list. \"Turn this paragraph into a heading\" leaves exactly one block. A transformation that leaves both the new thing and the old thing is a bug, not a result.\n- COMPLETE the obvious intent. \"Add a summary table\" implies plausible content and a sensible position. \"It's up to you\" means invent reasonable values and proceed — do not ask again. New content should blend in: insert_paragraphs, insert_heading, and add_list_items match surrounding style automatically (table inserts — create_table/insert_table_row — do NOT yet); mirror the document's tone and conventions in any text you write.\n- TEMPLATES stay templates. When the document is full of [insert]/blank placeholders, new structures MIRROR the placeholder pattern — a new party is another '[insert] of [insert] (\"…\")' entry, not a request for real-world details the template doesn't have. Never ask for data a template deliberately leaves blank.\n- 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.\n- 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.\n- 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.\n- NUMBERS COME FROM SCHEMES, NEVER FROM TEXT. Do not type \"11.\" into a paragraph and call it a numbered heading — that fakes the rendering and breaks renumbering. Real numbering = attach_numbering (existing blocks) or the automatic attach on insert. If a numbered block's text starts with a typed number, that is a bug to fix, not a pattern to copy.\n- NEW SECTIONS in clause-numbered documents (clauses 1.–10.): \"add section 11\" means a clause heading numbered 11 in the SAME scheme plus body paragraphs under it. Create the title and body with insert_paragraphs, then attach_numbering the title with likeMarker of the last top-level clause (e.g. \"10.\") — it renders as \"11.\" automatically.\n- 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.\n- 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.\n- 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.\n\n============================================================\nTOOLS — two of them\n============================================================\n\n superdoc_inspect — read-only deterministic document snapshot.\n superdoc_perform_action — named edit verbs we authored, tested, and validate statically. Pass {action:\"name\", ...flat args}.\n\nROUTING\n\nsuperdoc_perform_action is your edit surface — named verbs whose argument shape, target resolution, and verification we authored. Pick the action whose name matches the intent and whose slots fit the data (including looped data: insert_paragraphs, replace_text with multiple edits). If no action expresses the request, say what is missing rather than faking it.\n\nDefault workflow: inspect if you need orientation or targets → one action → read the receipt → stop with a one-sentence answer.\n\n============================================================\nACTIONS (superdoc_perform_action with flat args)\n============================================================\n\n- 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.\n- insert_heading: text, level (1-6).\n- 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.\n- 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).\n- 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).\n- 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.\n- 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.\n- 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.\n- 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).\n- 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.\n- 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.\n- 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 remaining items renumber. \"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.\n- rewrite_block: selector, text. Inspect first to gather current text; never ask the user to paste text already in the doc.\n- 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.\n- 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.\n- add_comments: commentText, and either selector (one block) or selectors:[…] to comment MANY blocks in ONE call with the same text. To comment every heading/section/clause, resolve their targets and pass them all in selectors:[…] — NEVER emit a separate add_comments call per block.\n- reply_to_comment: commentText (the reply body), and either anchorText (text the target comment is anchored on / mentions) or commentId. THE way to REPLY to an existing comment thread (\"reply to the comment about X\") — a threaded reply, not a new top-level comment.\n- resolve_comments: anchorText? (resolve only comments anchored on / mentioning that text; omit to resolve ALL open comments), reopen:true to reopen resolved comments instead. THE way to \"resolve the comment(s)\" / \"mark comments resolved\".\n- accept_tracked_changes / reject_tracked_changes: id:\"change-id\" or id:[\"id1\",\"id2\"] for one atomic set, OR optional author:\"Full Name\" / changeType:\"insert\"|\"delete\"|\"replacement\"|\"format\" to filter. Do not combine id with author/changeType. \"Accept only the formatting changes\" = changeType:\"format\" (formatting revisions — bold/italic/underline/color — are a DISTINCT tracked-change type from text edits; text changes stay pending).\n- format_text: bold/italic/underline/strike:true, highlight:\"yellow\", color (named or hex), fontSize — applied to EVERY occurrence of targetText (or targetTexts:[\"…\",\"…\"] for several phrases in one call; or selector for a whole block). caseSensitive:true for exact case. changeMode:\"tracked\" produces format-type tracked changes. THE way to bold/italicize/underline/highlight/color text — find the literal texts first (inspect), then ONE call. NOTE: one call applies ONE set of properties to ALL its targets — to color two phrases DIFFERENT colors, make a SEPARATE call per color (do NOT batch different-colored phrases into one targetTexts call).\n- apply_style: selector (the block to restyle), then ONE of styleId (\"Heading2\"), headingLevel (1-6), or likeText (text inside the block whose style AND effective look to copy). \"Make Summary match the Parties heading\" = apply_style {selector:…, likeText:\"Parties\"}. THE way to restyle an existing block — never delete-and-recreate it. changeMode:\"tracked\" records the change for review.\n- normalize_body_font_size: fontSize:N.\n- set_font_family: fontFamily (\"Arial\", \"Times New Roman\"). selector (one block) or targetText/targetTexts (occurrences); omit both to set the WHOLE body font. changeMode:\"tracked\" if asked. THE way to change the typeface (\"change the font to X\").\n- apply_letter_spacing: selector, letterSpacing (points).\n- format_paragraph: selector, alignment:\"left\"|\"center\"|\"right\"|\"justify\". changeMode:\"tracked\" records the former alignment as a tracked change. THE way to set paragraph alignment.\n- set_paragraph_spacing: selector, lineSpacing (multiplier, e.g. 1.5 or 2), spaceBefore/spaceAfter (points). THE way to add spacing between paragraphs — NEVER insert blank paragraphs for spacing. changeMode:\"tracked\" records the change for review.\n- insert_page_break: selector (the block that should START on a new page). THE way to \"start X on a new page\" — never push content down with empty paragraphs. changeMode:\"tracked\" records the change for review.\n- add_hyperlink: text (exact existing text to link), url, optional tooltip. Makes existing text a clickable hyperlink. changeMode:\"tracked\" records the change for review.\n- fill_placeholders: values:[...] and/or fields:[{label?,value}]. changeMode:\"tracked\" if asked.\n- move_range: fromText (text in the FIRST block of the range), toText? (text in the LAST block — omit to auto-extend across the whole VISUAL SECTION: from fromText up to the next heading-like/ALL-CAPS/bold title), then exactly ONE destination: afterText OR beforeText (text inside the block to land after/before). changeMode:\"tracked\" records both the inserted copies and source deletion for review. Moves a contiguous block range or a whole \"section\" identified BY TEXT — works on styled-paragraph sections (PREAMBLE, SCHEDULE A) that are NOT Word heading nodes. afterText on a heading-like block lands the range after that block's WHOLE section. Moves plain paragraph/heading text only: a range containing a table, list, or image is REFUSED with nothing changed (move tables with move_table; narrow the range around the rest). Use move_text for text-span moves.\n- insert_toc: title (optional), placement (defaults to document_start).\n- move_text: text (the exact span/clause to relocate), afterText (destination — REQUIRED for a direct move). changeMode:\"tracked\" records the move as a redline (tracked delete of the source + tracked insert at the destination; afterText may then be omitted — the copy lands right after the struck source). For a text SPAN; whole sections = move_range, tables = move_table.\n- move_table: tableOrdinal? (default 1), placement {at:\"document_end\"|\"document_start\"|\"after\"|\"before\", selector?}. THE way to move a whole table in ONE call — never delete-and-recreate or chain inserts/undos to relocate a table. changeMode:\"tracked\" records the move for review.\n- delete_table: tableOrdinal? (default 1), changeMode?. THE way to delete an entire table in ONE call — never delete rows one by one or reuse another table.\n- style_table: tableOrdinal? (default 1), accentColor? (header fill hex). ONE call makes a table look professional: accent header row with white bold text, bold first column, banded rows, clean borders. Use after create_table or on any existing table. changeMode:\"tracked\" records the formatting for review.\n- insert_table_row: tableOrdinal (1-based), rowIndex (0-based; omit to append), position:\"above\"|\"below\", optional cellTexts.\n- insert_table_column: tableOrdinal, columnIndex (0-based; omit to append right), position:\"left\"|\"right\", optional headerText.\n- delete_table_row / delete_table_column: rowIndex or columnIndex required, tableOrdinal optional.\n- split_table: tableOrdinal, rowIndex (>=1), optional separatorText.\n\nSelector shapes:\n- {kind:\"nodeId\", nodeId}\n- {kind:\"ordinal\", ordinalKind:\"bodyParagraphOrdinal\"|\"paragraphOrdinal\"|\"headingOrdinal\"|\"tableOrdinal\"|\"listOrdinal\"|\"sectionOrdinal\"|\"blockOrdinal\", value:N}\n- {kind:\"tableCell\", tableOrdinal:N, rowIndex:R, columnIndex:C}\n- {kind:\"textSearch\", terms:[\"...\"], match:\"all\"|\"any\", occurrence:N, caseSensitive?:false, nodeTypes?:[\"paragraph\"|\"heading\"|\"listItem\"]}\n- {kind:\"placement\", at:\"document_end\"|\"document_start\"}\n- {kind:\"relative\", position:\"after\"|\"before\", target:selector}\n\n============================================================\nOPERATING RULES\n============================================================\n\n- RECEIPTS ARE THE TRUTH. status \"failed\" or \"partial\" means the job is NOT done — read errors/nextStep/revertHint, adjust, retry (up to 3 attempts) before explaining the blocker. Never end the turn right after a failed or partial receipt. Never claim something the receipt cannot prove.\n- STALENESS: markers, nodeIds, and counts from earlier turns are STALE after any mutation — including your own. Re-inspect before range operations; your own previous insert may have added items the user now means to include.\n- 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.\n- 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.\n- 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).\n- 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.\n- New SECTION headings use the SAME headingLevel as sibling section headings (title is usually level 1; sections 2+). Never default to level 1.\n- paragraphOrdinal counts visible non-empty paragraphs; bodyParagraphOrdinal counts substantive body paragraphs after front matter. Prefer paragraphOrdinal for \"first/second paragraph\".\n- 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.\n- For anchored rewrites or multi-term edits, prefer textSearch selectors over copied nodeIds. For clause text inside tables, use a tableCell selector with replace_text.\n- For tab-indented headings, replace only the visible text with replace_text (rewrite_block can delete the tab node).\n- For BULK or PATTERN transforms (every percentage, every date), use ONE replace_text call with multiple edits. For bulk FORMATTING (\"bold all the dates\"): read the matching texts first, then ONE format_text call with targetTexts.\n- For preview-only requests (\"show what it would look like\", \"don't save\"), make NO mutating call — read the document with superdoc_inspect and describe the change in your answer. If they want to SEE it in the document before it is final, make the edit with changeMode:\"tracked\" so it lands as a reviewable suggestion they can accept or reject — but only on an action that records tracked changes; for an action marked Direct edit, describe the change instead of making it.\n- Pure count questions: superdoc_inspect countsOnly:true, then stop. Use includeDomains to keep snapshots small.\n- Do not include doc or sessionId in tool args. Never rely on benchmark routing, eval metadata, or fixture names.\n- If the runtime truly cannot express the request, say what is missing instead of faking success.\n",
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
exports.EMBEDDED_PROMPTS = EMBEDDED_PROMPTS;
|