Skip to content

Commit 9aa655b

Browse files
committed
docs(sdk): update tool descriptions to show alignment inside format.apply step
1 parent 69f45cf commit 9aa655b

3 files changed

Lines changed: 61 additions & 38 deletions

File tree

packages/document-api/src/contract/operation-definitions.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,38 +144,44 @@ export const INTENT_GROUP_META: Record<string, IntentGroupMeta> = {
144144
edit: {
145145
toolName: 'superdoc_edit',
146146
description:
147+
'The primary tool for inserting content into documents. ' +
148+
'ALWAYS use action "insert" with type "markdown" to create headings, paragraphs, or any block content — this is faster and creates proper document structure in one call. Do NOT use superdoc_create for headings or paragraphs. ' +
149+
'The markdown parser creates headings from # markers (# = Heading1, ## = Heading2), bold from **text**, italic from *text*, and numbered/bullet lists. ' +
150+
'Position markdown inserts with "target" (a BlockNodeAddress like {kind:"block", nodeType, nodeId}) and "placement" (before, after, insideStart, insideEnd). Without a target, content appends at the end of the document. ' +
151+
'IMPORTANT: After a markdown insert, follow up with ONE superdoc_mutations call using format.apply steps to match the document style. ' +
152+
'Each format.apply step accepts "inline" (fontFamily, fontSize, bold, underline, color) AND "alignment" ("left","center","right","justify") in the same step — combine both in one step per block. ' +
153+
'Look at nearby headings and paragraphs in the get_content response and copy their exact formatting. Do NOT invent values — match what is already in the document. ' +
154+
'Also supports replace, delete, and undo/redo. For replace and delete, pass a "ref" from superdoc_search or superdoc_get_content blocks. ' +
155+
'A search ref covers only the matched substring; a block ref covers the entire block text, so use block refs when rewriting or shortening whole paragraphs. ' +
147156
'Refs expire after any mutation; always re-search before the next edit. ' +
148-
'Modify document text: insert new content, replace existing text, delete a range, or undo/redo. ' +
149-
'Use this for single text modifications. For 2+ edits that must succeed or fail atomically, use superdoc_mutations instead. ' +
150-
'For replace and delete, pass a "ref" from superdoc_search or superdoc_get_content blocks. A search ref covers only the matched substring; a block ref covers the entire block text, so use block refs when rewriting or shortening whole paragraphs. ' +
151-
'Insert supports plain text (default), markdown, or html via the "type" parameter. ' +
152-
'To create a document with multiple headings and paragraphs, use action "insert" with type "markdown" and placement "end". ' +
153-
'The markdown parser creates proper Heading styles from # markers (# = Heading1, ## = Heading2), bold from **text**, italic from *text*, and numbered/bullet lists. ' +
154-
'This is the most efficient way to build document structure: one call creates all sections. Follow up with superdoc_mutations format.apply steps to apply formatting (color, font, alignment) that markdown cannot express. ' +
155-
'Use "placement" (before, after, insideStart, insideEnd) to control position relative to the target. ' +
157+
'For 2+ edits that must succeed or fail atomically, use superdoc_mutations instead. ' +
156158
'Supports "dryRun" to preview changes and "changeMode: tracked" to record edits as tracked changes (not supported for markdown/html inserts). ' +
157159
'Do NOT build "target" objects manually when a ref is available; prefer "ref" for simpler, more reliable targeting.',
158160
inputExamples: [
159-
{ action: 'replace', ref: '<handle.ref>', text: 'new text here' },
160-
{ action: 'insert', value: 'Appended paragraph.', placement: 'insideEnd' },
161-
{ action: 'insert', ref: '<block.ref>', value: 'Inserted before.', placement: 'before' },
162161
{
163162
action: 'insert',
164163
type: 'markdown',
165-
placement: 'end',
164+
target: { kind: 'block', nodeType: 'paragraph', nodeId: '<nodeId>' },
165+
placement: 'before',
166+
value: '# Executive Summary\n\nThis agreement sets forth the principal terms...',
167+
},
168+
{
169+
action: 'insert',
170+
type: 'markdown',
166171
value:
167172
'# Section Title\n\nParagraph content here.\n\n# Another Section\n\nMore content with **bold** and *italic*.',
168173
},
174+
{ action: 'replace', ref: '<handle.ref>', text: 'new text here' },
169175
{ action: 'delete', ref: '<handle.ref>' },
170176
{ action: 'undo' },
171177
],
172178
},
173179
create: {
174180
toolName: 'superdoc_create',
175181
description:
176-
'Create a single paragraph, heading, or table. Returns nodeId and ref for the created block. ' +
177-
'For creating multiple headings and paragraphs at once, prefer superdoc_edit with type "markdown" (one call for all structure) instead of calling superdoc_create repeatedly. ' +
178-
'Use superdoc_create when you need to add one block at a specific position relative to another block. ' +
182+
'IMPORTANT: For headings and paragraphs, use superdoc_edit with type "markdown" instead — it is faster, creates proper styles, and handles positioning via target + placement. ' +
183+
'Only use superdoc_create for tables or when markdown cannot express the content. ' +
184+
'Creates a single paragraph, heading, or table. Returns nodeId and ref for the created block. ' +
179185
'After creating, the returned ref is valid for ONE immediate superdoc_format call. For subsequent operations, re-fetch blocks with superdoc_get_content to get fresh refs (refs expire after any mutation). ' +
180186
'When the user asks for a "heading", use action "heading" with a level (default 1). Use action "paragraph" for regular body text. ' +
181187
'Position with "at": {kind:"documentEnd"} (default), {kind:"documentStart"}, or {kind:"after"/"before", target:{kind:"block", nodeType, nodeId}} for relative placement. ' +

packages/sdk/tools/prompt-templates/system-prompt-core.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,29 +128,37 @@ Use preset "disc" for bullets, "decimal" for numbered. WARNING: the range conver
128128

129129
3. To change a bullet list to numbered: `superdoc_list({action: "set_type", target: {kind: "block", nodeType: "listItem", nodeId: "<anyItemId>"}, kind: "ordered"})`
130130

131-
### Create a multi-section document efficiently
131+
### Insert content into a document (new or existing)
132132

133-
**Step 1: Create all structure in one call using markdown insert:**
133+
Markdown insert creates block structure but uses default formatting. You MUST follow up with formatting to match the document's existing style.
134+
135+
**Step 1: Read existing formatting** from the initial get_content blocks response. Pay special attention to:
136+
- **Nearby headings/titles**: look at their fontFamily, fontSize, bold, underline, alignment (especially center vs justify vs left). Your new headings must match these exactly.
137+
- **Body paragraphs**: note fontFamily, fontSize, color, alignment. Your new paragraphs must match.
138+
- Match the style of the nearest similar element, not arbitrary values.
139+
140+
**Step 2: Insert content with markdown:**
134141

135142
```
136-
superdoc_edit({action: "insert", type: "markdown", placement: "end",
137-
value: "# Definitions\n\n\"Confidential Information\" means any non-public information...\n\n# Obligations\n\nThe Receiving Party agrees to maintain confidentiality...\n\n# Governing Law\n\nThis Agreement shall be governed by the laws of..."})
143+
superdoc_edit({action: "insert", type: "markdown",
144+
target: {kind: "block", nodeType: "paragraph", nodeId: "<first-block-nodeId>"},
145+
placement: "before",
146+
value: "# Executive Summary\n\nThis agreement sets forth the principal terms..."})
138147
```
139148

140-
This creates headings with proper Heading1 style, paragraphs, bold (**text**), italic (*text*), lists, and tables in one call. Markdown cannot express color, font-size, or alignment — those require step 2.
141-
142-
**Step 2: Apply formatting in one batch:**
149+
**Step 3: Apply ALL formatting in a SINGLE superdoc_mutations call.** Each format.apply step accepts both `inline` (text styles) AND `alignment` (paragraph alignment) — one step per block.
143150

151+
Example: if the document has centered, underlined, 12pt headings and justified 12pt body text:
144152
```
145-
superdoc_mutations({action: "apply", steps: [
146-
{id: "f1", op: "format.apply", where: {by: "select", select: {type: "node", nodeType: "heading"}, require: "all"}, args: {inline: {color: "#FF0000"}}},
147-
{id: "f2", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "Confidential Information"}, require: "all"}, args: {inline: {bold: true}}}
153+
superdoc_mutations({action: "apply", atomic: true, steps: [
154+
{id: "f1", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "Executive Summary"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12, underline: true}, alignment: "center"}},
155+
{id: "f2", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "This agreement sets forth"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12, color: "#000000"}, alignment: "justify"}}
148156
]})
149157
```
150158

151-
Use `require: "all"` with a node selector to format every heading at once instead of formatting one at a time.
159+
CRITICAL: Do NOT guess formatting values. Copy them from the existing document blocks you read in step 1. Use ONE format.apply step per block with both `inline` and `alignment` combined.
152160

153-
Total: 4 calls (open, insert, format batch, save) instead of 40+.
161+
Total: 3 calls (read + insert + format-all-in-one-batch). Never more.
154162

155163
### Batch multiple text edits atomically
156164

packages/sdk/tools/prompt-templates/system-prompt-mcp-header.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,36 @@ These tools handle the OOXML format correctly and preserve document structure.
1414

1515
## Efficient patterns (use these instead of calling tools one at a time)
1616

17-
**Creating multiple headings and paragraphs — use markdown insert (one call):**
17+
**Creating headings and paragraphs — ALWAYS use markdown insert (one call):**
1818
```
19-
superdoc_edit({action: "insert", type: "markdown", placement: "end",
19+
superdoc_edit({action: "insert", type: "markdown",
2020
value: "# Section Title\n\nParagraph content.\n\n# Another Section\n\nMore content with **bold**."})
2121
```
2222
This creates proper Heading styles from # markers. One call replaces many superdoc_create calls.
2323

24-
**Formatting multiple items at once — use mutations batch (one call):**
24+
**Inserting at a specific position — use target + placement:**
2525
```
26-
superdoc_mutations({action: "apply", steps: [
27-
{id: "f1", op: "format.apply", where: {by: "select", select: {type: "node", nodeType: "heading"}, require: "all"}, args: {inline: {color: "#FF0000"}}},
28-
{id: "f2", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "important term"}, require: "all"}, args: {inline: {bold: true}}}
26+
superdoc_edit({action: "insert", type: "markdown",
27+
target: {kind: "block", nodeType: "paragraph", nodeId: "<nodeId>"},
28+
placement: "before",
29+
value: "# Executive Summary\n\nThis agreement sets forth the principal terms..."})
30+
```
31+
Valid placements: "before", "after", "insideStart", "insideEnd". Without target, content appends at document end.
32+
33+
**Formatting — each format.apply step accepts both `inline` AND `alignment`:**
34+
```
35+
superdoc_mutations({action: "apply", atomic: true, steps: [
36+
{id: "f1", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "Executive Summary"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12, underline: true}, alignment: "center"}},
37+
{id: "f2", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "body paragraph text"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12}, alignment: "justify"}}
2938
]})
3039
```
31-
Use require "all" to format every match at once. Selectors resolve before execution, so format targets must exist in the document before the batch runs.
40+
One format.apply step per block. Combine `inline` (text styles) and `alignment` (paragraph alignment) in the same step. Do NOT use separate superdoc_format calls.
3241

3342
**When to use which tool:**
34-
- Creating multiple blocks `superdoc_edit` with type "markdown"
35-
- Creating one block at a specific position`superdoc_create`
36-
- Formatting multiple items `superdoc_mutations` with format.apply steps
37-
- Formatting one item`superdoc_format`
43+
- Creating headings, paragraphs, or any block content `superdoc_edit` with type "markdown" (preferred, even for a single heading + paragraph)
44+
- Creating one block only when markdown is insufficient`superdoc_create`
45+
- ALL formatting after insert `superdoc_mutations` with format.apply (inline + alignment in one step per block)
46+
- Single quick format (no insert before it)`superdoc_format`
3847
- Multiple text edits → `superdoc_mutations`
3948
- Single text edit → `superdoc_edit`
4049

0 commit comments

Comments
 (0)