@documonster/mcp 0.10.0-canary.sha.2c2ccf7b → 0.10.0
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/README.md +51 -170
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +0 -28
- package/dist/capabilities.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -10
- package/dist/config.js.map +1 -1
- package/dist/tools/doc-convert.d.ts.map +1 -1
- package/dist/tools/doc-convert.js +4 -26
- package/dist/tools/doc-convert.js.map +1 -1
- package/dist/tools/doc-read.d.ts.map +1 -1
- package/dist/tools/doc-read.js +4 -32
- package/dist/tools/doc-read.js.map +1 -1
- package/dist/tools/doc-write.d.ts.map +1 -1
- package/dist/tools/doc-write.js +3 -21
- package/dist/tools/doc-write.js.map +1 -1
- package/dist/tools/document.d.ts +1 -1
- package/dist/tools/document.d.ts.map +1 -1
- package/dist/tools/document.js +1 -13
- package/dist/tools/document.js.map +1 -1
- package/dist/tools/help.d.ts +15 -263
- package/dist/tools/help.d.ts.map +1 -1
- package/dist/tools/help.js +15 -263
- package/dist/tools/help.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +0 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/inspect.d.ts.map +1 -1
- package/dist/tools/inspect.js +6 -98
- package/dist/tools/inspect.js.map +1 -1
- package/dist/tools/pdf-edit.d.ts +6 -13
- package/dist/tools/pdf-edit.d.ts.map +1 -1
- package/dist/tools/pdf-edit.js +8 -93
- package/dist/tools/pdf-edit.js.map +1 -1
- package/dist/tools/sheet-edit.d.ts.map +1 -1
- package/dist/tools/sheet-edit.js +2 -37
- package/dist/tools/sheet-edit.js.map +1 -1
- package/dist/tools/sheet-read.d.ts.map +1 -1
- package/dist/tools/sheet-read.js +1 -18
- package/dist/tools/sheet-read.js.map +1 -1
- package/dist/tools/sheet-write.d.ts.map +1 -1
- package/dist/tools/sheet-write.js +4 -41
- package/dist/tools/sheet-write.js.map +1 -1
- package/dist/tools/template.d.ts +0 -19
- package/dist/tools/template.d.ts.map +1 -1
- package/dist/tools/template.js +11 -436
- package/dist/tools/template.js.map +1 -1
- package/package.json +3 -3
- package/dist/tools/diagram-inspect.d.ts +0 -20
- package/dist/tools/diagram-inspect.d.ts.map +0 -1
- package/dist/tools/diagram-inspect.js +0 -91
- package/dist/tools/diagram-inspect.js.map +0 -1
- package/dist/tools/diagram-markdown.d.ts +0 -45
- package/dist/tools/diagram-markdown.d.ts.map +0 -1
- package/dist/tools/diagram-markdown.js +0 -127
- package/dist/tools/diagram-markdown.js.map +0 -1
- package/dist/tools/diagram-render.d.ts +0 -14
- package/dist/tools/diagram-render.d.ts.map +0 -1
- package/dist/tools/diagram-render.js +0 -117
- package/dist/tools/diagram-render.js.map +0 -1
- package/dist/tools/diagram.d.ts +0 -217
- package/dist/tools/diagram.d.ts.map +0 -1
- package/dist/tools/diagram.js +0 -760
- package/dist/tools/diagram.js.map +0 -1
- package/dist/tools/image.d.ts +0 -147
- package/dist/tools/image.d.ts.map +0 -1
- package/dist/tools/image.js +0 -749
- package/dist/tools/image.js.map +0 -1
- package/dist/tools/sheet-image.d.ts +0 -58
- package/dist/tools/sheet-image.d.ts.map +0 -1
- package/dist/tools/sheet-image.js +0 -156
- package/dist/tools/sheet-image.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
[Model Context Protocol](https://modelcontextprotocol.io) server for
|
|
4
4
|
[documonster](https://github.com/documonster/documonster). Gives an AI assistant
|
|
5
|
-
the ability to read, write and convert Excel, Word, PDF, CSV and ZIP documents
|
|
6
|
-
|
|
5
|
+
the ability to read, write and convert Excel, Word, PDF, CSV and ZIP documents
|
|
6
|
+
on the local filesystem.
|
|
7
7
|
|
|
8
|
-
> **Status: usable.**
|
|
9
|
-
> archives
|
|
10
|
-
>
|
|
11
|
-
> scope boundaries.
|
|
8
|
+
> **Status: usable.** Nineteen tools cover spreadsheets, Word, PDF, templates and
|
|
9
|
+
> archives — reading, writing, editing, searching and converting. See
|
|
10
|
+
> [Roadmap](#roadmap) for what is deliberately absent.
|
|
12
11
|
|
|
13
12
|
## Install
|
|
14
13
|
|
|
@@ -62,15 +61,15 @@ No install needed — point your MCP client at `npx`.
|
|
|
62
61
|
|
|
63
62
|
## Options
|
|
64
63
|
|
|
65
|
-
| Flag | Default | Meaning
|
|
66
|
-
| ------------------------- | ------------ |
|
|
67
|
-
| `--root <dir>` | cwd | Sandbox root. Every path a tool touches must resolve inside it.
|
|
68
|
-
| `--output-root <dir>` | private temp | Separate writable root. Outputs are returned as `@output/<path>` for later calls.
|
|
69
|
-
| `--allow-in-place` | off | Permit edits below `--root`; disabled by default because it weakens isolation.
|
|
70
|
-
| `--readonly` | off | Withhold every mutating tool from the model's tool list.
|
|
71
|
-
| `--enable <groups>` | all | Comma-separated tool groups: `core`, `excel`, `word`, `pdf`, `forms`, `archive
|
|
72
|
-
| `--max-file-size <bytes>` | 67108864 | Reject larger input documents.
|
|
73
|
-
| `--max-output-chars <n>` | 40000 | Truncate tool output — a token budget in disguise.
|
|
64
|
+
| Flag | Default | Meaning |
|
|
65
|
+
| ------------------------- | ------------ | ----------------------------------------------------------------------------------------------------- |
|
|
66
|
+
| `--root <dir>` | cwd | Sandbox root. Every path a tool touches must resolve inside it. |
|
|
67
|
+
| `--output-root <dir>` | private temp | Separate writable root. Outputs are returned as `@output/<path>` for later calls. |
|
|
68
|
+
| `--allow-in-place` | off | Permit edits below `--root`; disabled by default because it weakens isolation. |
|
|
69
|
+
| `--readonly` | off | Withhold every mutating tool from the model's tool list. |
|
|
70
|
+
| `--enable <groups>` | all | Comma-separated tool groups: `core`, `excel`, `word`, `pdf`, `forms`, `archive`. `core` is always on. |
|
|
71
|
+
| `--max-file-size <bytes>` | 67108864 | Reject larger input documents. |
|
|
72
|
+
| `--max-output-chars <n>` | 40000 | Truncate tool output — a token budget in disguise. |
|
|
74
73
|
|
|
75
74
|
## Security
|
|
76
75
|
|
|
@@ -115,34 +114,31 @@ server root with an untrusted local account or process while the server runs.
|
|
|
115
114
|
|
|
116
115
|
## Tools
|
|
117
116
|
|
|
118
|
-
| Tool | Purpose
|
|
119
|
-
| ----------------------- |
|
|
120
|
-
| **Orientation** |
|
|
121
|
-
| `documonster_help` | Conventions, path rules, and formula/document/editing notes kept out of tool schemas to save context.
|
|
122
|
-
| `doc_inspect` | Identify a file (type, size, sheet list, CSV dialect, extension mismatches) or list a directory. Always first.
|
|
123
|
-
| **Spreadsheets** |
|
|
124
|
-
| `sheet_read` | Read a bounded window as a Markdown table with column letters and row numbers. Paginates; reports what it omitted.
|
|
125
|
-
| `sheet_write` | Create an `.xlsx` from a declarative spec. `fromCsv` pulls source data in server-side
|
|
126
|
-
| `sheet_edit` | Patch an existing `.xlsx` — cells, ranges, formulas, rows, styles, sheets
|
|
127
|
-
| `formula_evaluate` | Evaluate a formula against supplied values using the real engine (~450 functions). Touches no files.
|
|
128
|
-
| **Documents** |
|
|
129
|
-
| `doc_read` | Read `.docx` / `.pdf` / `.md` / `.txt
|
|
130
|
-
| `doc_write` | Create a `.docx` or `.pdf` from Markdown.
|
|
131
|
-
| `doc_edit` | Find and replace text in a `.docx`, including matches Word split across runs. Formatting preserved.
|
|
132
|
-
| `doc_search` | Find text, or find text **by its formatting** — "which text is red", "what is highlighted".
|
|
133
|
-
| `doc_paginate` | Real page count and per-heading page numbers without Word installed; optionally refresh fields and the TOC.
|
|
134
|
-
| `doc_convert` | `docx`→`md`/`html`/`pdf`/`txt`, `md`→`docx`/`pdf`, `xlsx`→`csv`/`pdf`, `csv`→`xlsx`. Lossy conversions state their loss.
|
|
135
|
-
| `pdf_edit` | Watermark, page numbers, stamps,
|
|
136
|
-
| **Forms and templates** |
|
|
137
|
-
| `template_inspect` | List a template's placeholders and print the JSON shape needed to fill it.
|
|
138
|
-
| `template_fill` | Fill a Word template from JSON
|
|
139
|
-
| `form_fill` | List or fill Word form fields and PDF AcroForms. PDF values are verified by re-reading the saved file.
|
|
140
|
-
| **
|
|
141
|
-
| `
|
|
142
|
-
| `
|
|
143
|
-
| **Archives** | |
|
|
144
|
-
| `archive_read` | List or extract a `.zip`/`.tar`. Guards traversal, decompression bombs and symlink entries. |
|
|
145
|
-
| `archive_write` | Package files and directories into a `.zip`/`.tar`, verified by reading it back. |
|
|
117
|
+
| Tool | Purpose |
|
|
118
|
+
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
119
|
+
| **Orientation** | |
|
|
120
|
+
| `documonster_help` | Conventions, path rules, and formula/document/editing notes kept out of tool schemas to save context. |
|
|
121
|
+
| `doc_inspect` | Identify a file (type, size, sheet list, CSV dialect, extension mismatches) or list a directory. Always first. |
|
|
122
|
+
| **Spreadsheets** | |
|
|
123
|
+
| `sheet_read` | Read a bounded window as a Markdown table with column letters and row numbers. Paginates; reports what it omitted. |
|
|
124
|
+
| `sheet_write` | Create an `.xlsx` from a declarative spec. `fromCsv` pulls source data in server-side. |
|
|
125
|
+
| `sheet_edit` | Patch an existing `.xlsx` — cells, ranges, formulas, rows, styles, sheets. Atomic, backed up, `dryRun` available. |
|
|
126
|
+
| `formula_evaluate` | Evaluate a formula against supplied values using the real engine (~450 functions). Touches no files. |
|
|
127
|
+
| **Documents** | |
|
|
128
|
+
| `doc_read` | Read `.docx` / `.pdf` / `.md` / `.txt`. Word returns Markdown; PDFs are reported page by page. |
|
|
129
|
+
| `doc_write` | Create a `.docx` or `.pdf` from Markdown. |
|
|
130
|
+
| `doc_edit` | Find and replace text in a `.docx`, including matches Word split across runs. Formatting preserved. |
|
|
131
|
+
| `doc_search` | Find text, or find text **by its formatting** — "which text is red", "what is highlighted". |
|
|
132
|
+
| `doc_paginate` | Real page count and per-heading page numbers without Word installed; optionally refresh fields and the TOC. |
|
|
133
|
+
| `doc_convert` | `docx`→`md`/`html`/`pdf`/`txt`, `md`→`docx`/`pdf`, `xlsx`→`csv`/`pdf`, `csv`→`xlsx`. Lossy conversions state their loss. |
|
|
134
|
+
| `pdf_edit` | Watermark, page numbers, stamps, rotate, delete/keep pages, append another PDF. Overlays never rewrite the original content. |
|
|
135
|
+
| **Forms and templates** | |
|
|
136
|
+
| `template_inspect` | List a template's placeholders and print the JSON shape needed to fill it. |
|
|
137
|
+
| `template_fill` | Fill a Word template from JSON. A missing field fails loudly rather than shipping a blank. |
|
|
138
|
+
| `form_fill` | List or fill Word form fields and PDF AcroForms. PDF values are verified by re-reading the saved file. |
|
|
139
|
+
| **Archives** | |
|
|
140
|
+
| `archive_read` | List or extract a `.zip`/`.tar`. Guards traversal, decompression bombs and symlink entries. |
|
|
141
|
+
| `archive_write` | Package files and directories into a `.zip`/`.tar`, verified by reading it back. |
|
|
146
142
|
|
|
147
143
|
### Two worked examples
|
|
148
144
|
|
|
@@ -176,124 +172,13 @@ Note what does **not** happen in either: no document bytes and no bulk rows pass
|
|
|
176
172
|
through the model's context. `fromCsv`, the `entries` filter and template data
|
|
177
173
|
keep the payload on the server.
|
|
178
174
|
|
|
179
|
-
### Diagrams
|
|
180
|
-
|
|
181
|
-
`diagram_render` takes Mermaid text and draws `flowchart`, `sequenceDiagram`,
|
|
182
|
-
`classDiagram`, `stateDiagram`, `erDiagram`, `gantt`, `gitGraph`, `mindmap`,
|
|
183
|
-
`timeline`, `journey`, `kanban`, `quadrantChart`, `xychart`, `radar`, `sankey`,
|
|
184
|
-
`packet`, `block`, `pie`, `C4`, `requirementDiagram` and `architecture` — the same
|
|
185
|
-
twenty-one the core library draws, since this is a thin consumer of its public API.
|
|
186
|
-
|
|
187
|
-
```jsonc
|
|
188
|
-
diagram_inspect { "source": "flowchart TD\n A[Read] --> B{Valid?}\n B -->|no| A" }
|
|
189
|
-
diagram_render { "source": "…", "to": "arch.svg", "theme": "dark" }
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
**The result reports the parsed structure, and that is the point.** This is the one
|
|
193
|
-
place in the server where reading the output back is impossible — nothing can look
|
|
194
|
-
at a picture. So both tools answer with what the parser recognised: `3 node(s),
|
|
195
|
-
3 edge(s)`, `A (Read)`, `B -[no]-> A`. The parser implements a subset of Mermaid and
|
|
196
|
-
a subset fails by _silently dropping_ what it did not understand, so a missing edge
|
|
197
|
-
in that list is the only symptom there will ever be.
|
|
198
|
-
|
|
199
|
-
SVG, PNG and PDF come from the **same display list** rather than three renderers, so
|
|
200
|
-
they are the same picture and not three that might disagree. `theme` picks a colour
|
|
201
|
-
set (`default` is Mermaid's own base theme token for token; `dark` and `neutral` are
|
|
202
|
-
this server's), `themeOverrides` sets individual tokens, and `background` defaults to
|
|
203
|
-
white — a transparent PNG is invisible in a dark viewer, which is a failure the model
|
|
204
|
-
would never see.
|
|
205
|
-
|
|
206
|
-
A ` ```mermaid ` fence in the Markdown you give `doc_write` (or in a `.md` file you
|
|
207
|
-
pass to `doc_convert`) becomes a real embedded image, scaled to fit the text column:
|
|
208
|
-
Word does not shrink an oversized inline image, it runs it off the page. A fence that
|
|
209
|
-
fails to parse is left as a code block and reported, so one bad diagram never costs
|
|
210
|
-
you the document. `diagrams: false` opts out.
|
|
211
|
-
|
|
212
|
-
**Onto a PDF that already exists**, `pdf_edit` takes `{ op: "diagram", source, pages }`
|
|
213
|
-
and draws **vectors** onto the page — sharp at any zoom, saved as an incremental
|
|
214
|
-
update so bookmarks, form fields and signature bytes survive. Two defaults invert
|
|
215
|
-
because it draws _over_ existing content: `background` is transparent, and omitting
|
|
216
|
-
the position centres the diagram at its natural size shrunk to fit, so the simplest
|
|
217
|
-
call lands on the page rather than off the edge of it.
|
|
218
|
-
|
|
219
|
-
**Reading** is the one direction that stays textual, deliberately: `doc_read` cannot
|
|
220
|
-
show you a picture, so it returns a `.mmd` file's source and _indexes_ a Markdown
|
|
221
|
-
file's fences instead. The footer names `diagram_render({ from, index, to })` — the
|
|
222
|
-
point being that the model never has to copy a diagram's source out through its own
|
|
223
|
-
reply in order to draw it.
|
|
224
|
-
|
|
225
|
-
### Images
|
|
226
|
-
|
|
227
|
-
A diagram is not a separate kind of thing from a picture, so it is not a separate
|
|
228
|
-
argument. Four destinations take an image, and all four take the **same source
|
|
229
|
-
shape**, routed by extension rather than by a format flag:
|
|
230
|
-
|
|
231
|
-
````jsonc
|
|
232
|
-
{ "from": "logo.png" } // .png / .jpg / .gif — embedded as-is
|
|
233
|
-
{ "from": "flow.mmd" } // a diagram file — drawn server-side
|
|
234
|
-
{ "from": "design.md", "index": 2 } // a ```mermaid fence out of Markdown
|
|
235
|
-
{ "source": "flowchart LR\n A --> B" } // Mermaid text
|
|
236
|
-
````
|
|
237
|
-
|
|
238
|
-
| Destination | How |
|
|
239
|
-
| ----------------------------- | ------------------------------------------------------------ |
|
|
240
|
-
| a worksheet | `images` in `sheet_write`, `op: "add_image"` in `sheet_edit` |
|
|
241
|
-
| a Word template's `{{%name}}` | `images` in `template_fill` |
|
|
242
|
-
| a page of an existing PDF | `op: "diagram"` in `pdf_edit` |
|
|
243
|
-
| a document you write | a ` ```mermaid ` fence in `doc_write`'s Markdown |
|
|
244
|
-
|
|
245
|
-
```jsonc
|
|
246
|
-
sheet_write { "path": "out/report.xlsx", "sheets": [{ "name": "June",
|
|
247
|
-
"images": [{ "at": "F2", "from": "logo.png" },
|
|
248
|
-
{ "at": "A10:H30", "source": "flowchart LR\n A --> B" }] }] }
|
|
249
|
-
template_fill { "template": "invoice.docx", "out": "out/INV.docx",
|
|
250
|
-
"data": { "client": "Acme" },
|
|
251
|
-
"images": { "logo": { "from": "logo.png" } } }
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
Four details are worth knowing, because each was a real defect before it was a rule.
|
|
255
|
-
**A worksheet anchor means two different things**: a single cell (`"F2"`) hangs the
|
|
256
|
-
picture at its own size, a range (`"A10:H30"`) binds it to those cells so it moves
|
|
257
|
-
_and resizes_ with them — offering only one silently answers half the requests
|
|
258
|
-
wrongly. **One dimension implies the other**, keeping the aspect ratio, because an
|
|
259
|
-
image squashed to a ratio nobody asked for is a defect the model cannot see. **A
|
|
260
|
-
declared resolution is honoured** — a PNG's `pHYs`, a JPEG's JFIF density — because
|
|
261
|
-
Word and Excel honour it, so ignoring it placed a 300-dpi photograph at three times
|
|
262
|
-
its intended size. And **a header that will not parse is an error**, not a 1×1
|
|
263
|
-
placement: the library's own reader answers 1×1 for an unreadable file, which is right
|
|
264
|
-
for a renderer that must draw something and wrong here, where the result would be
|
|
265
|
-
invisible and unreportable.
|
|
266
|
-
|
|
267
|
-
Sizes are in points. A single call may place 20 pictures, 64 MiB of source and 80
|
|
268
|
-
million decoded pixels; the budget is aggregate, because twenty images each just under
|
|
269
|
-
a per-file limit cost the same memory as one enormous one.
|
|
270
|
-
|
|
271
175
|
### Deliberately absent
|
|
272
176
|
|
|
273
177
|
Not implemented, and the server tells the model to say so rather than improvise:
|
|
274
178
|
password-protected files, PDF→Word (no faithful conversion exists), OCR, legacy
|
|
275
|
-
binary `.doc`/`.xls`, and pivot
|
|
276
|
-
tool does yet.
|
|
277
|
-
|
|
278
|
-
A Word template's `{{%name}}` must sit in **a paragraph of its own** — in the body, a
|
|
279
|
-
table cell, or a header or footer, nesting included. One placement is genuinely
|
|
280
|
-
impossible: scoped to a `{{#each}}` item, because images are substituted before loops
|
|
281
|
-
expand, so one picture per row is not expressible. `template_fill` refuses that up
|
|
282
|
-
front and `template_inspect` marks it rather than inventing a key for it.
|
|
283
|
-
|
|
284
|
-
Every image is also checked for **integrity**, not just for a readable header: PNG
|
|
285
|
-
chunk CRCs and an inflate that yields exactly the declared scanlines, a JPEG's
|
|
286
|
-
end-of-image marker, a GIF's trailer. Truncation is how images really arrive broken,
|
|
287
|
-
and a header check cannot see it — the first bytes of a cut-off PNG are identical to a
|
|
288
|
-
whole one's.
|
|
289
|
-
|
|
290
|
-
Because that same pass runs before conditionals are evaluated, a picture inside a
|
|
291
|
-
`{{#if}}` that turns out false is substituted and then removed with its block. The
|
|
292
|
-
fill still succeeds, so `template_fill` reports it as **not in the output** and drops
|
|
293
|
-
its bytes from the package — a document that withholds a picture must not leak it to
|
|
294
|
-
anyone who unzips the file. Every placed picture is then verified by re-opening the
|
|
295
|
-
written `.docx`, because the document handed to the writer is not evidence about the
|
|
296
|
-
file it produced.
|
|
179
|
+
binary `.doc`/`.xls`, and image/pivot-table insertion — the library supports
|
|
180
|
+
those, no tool does yet. Spreadsheet charts are supported by `sheet_write` and
|
|
181
|
+
`sheet_edit`.
|
|
297
182
|
|
|
298
183
|
### Editing existing files
|
|
299
184
|
|
|
@@ -321,10 +206,10 @@ Besides tools, the server publishes:
|
|
|
321
206
|
|
|
322
207
|
- **Resources** — every help topic at `documonster://help/{topic}`, so a client can
|
|
323
208
|
display them and a model can read one without spending a tool call.
|
|
324
|
-
- **Prompts** —
|
|
325
|
-
`fill-document`, `review-changes`, `convert-document
|
|
326
|
-
|
|
327
|
-
|
|
209
|
+
- **Prompts** — five workflow templates (`summarise-spreadsheet`, `build-report`,
|
|
210
|
+
`fill-document`, `review-changes`, `convert-document`). Each encodes the working
|
|
211
|
+
order that matters — inspect, read narrowly, verify — and tells the model never
|
|
212
|
+
to invent a value it was not given.
|
|
328
213
|
|
|
329
214
|
## Programmatic use
|
|
330
215
|
|
|
@@ -354,15 +239,11 @@ ever imports `@excel/*`, `@utils/*` or reaches into `../../src`.
|
|
|
354
239
|
|
|
355
240
|
### Testing layers
|
|
356
241
|
|
|
357
|
-
| Layer | File | Catches
|
|
358
|
-
| ---------- | ------------------------------------------------------- |
|
|
359
|
-
| Unit | `config` / `sandbox` / `result` / `errors` / `registry` | Argument parsing, path containment, output budget, error text, tool filtering
|
|
360
|
-
|
|
|
361
|
-
|
|
|
362
|
-
| Package | `image.test.ts` | Media integrity in the produced OOXML: unique parts, resolvable relationships, and no bytes left behind by a false `{{#if}}` |
|
|
363
|
-
| Budget | `schema-budget.test.ts` | The permanent context cost of `tools/list`, which nothing else makes visible as it grows |
|
|
364
|
-
| Protocol | `server.test.ts` | Handshake, `tools/list`, JSON Schema generation, `tools/call`, in-memory transport |
|
|
365
|
-
| Executable | `stdio.e2e.test.ts` | Real spawned process: `bin` entry, shebang, exit codes, manifest version, and that stdout carries nothing but JSON-RPC |
|
|
242
|
+
| Layer | File | Catches |
|
|
243
|
+
| ---------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
244
|
+
| Unit | `config` / `sandbox` / `result` / `errors` / `registry` | Argument parsing, path containment, output budget, error text, tool filtering |
|
|
245
|
+
| Protocol | `server.test.ts` | Handshake, `tools/list`, JSON Schema generation, `tools/call`, in-memory transport |
|
|
246
|
+
| Executable | `stdio.e2e.test.ts` | Real spawned process: `bin` entry, shebang, exit codes, manifest version, and that stdout carries nothing but JSON-RPC |
|
|
366
247
|
|
|
367
248
|
The e2e suite compiles the package itself in `beforeAll`, so it never
|
|
368
249
|
silently skips when `dist/` is absent.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMhD,4CAA4C;AAC5C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAezD;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMhD,4CAA4C;AAC5C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAezD;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAgL7E"}
|
package/dist/capabilities.js
CHANGED
|
@@ -160,34 +160,6 @@ Work in this order:
|
|
|
160
160
|
]
|
|
161
161
|
}));
|
|
162
162
|
}
|
|
163
|
-
if (has("diagram") && !config.readonly) {
|
|
164
|
-
server.registerPrompt("draw-diagram", {
|
|
165
|
-
title: "Draw a diagram",
|
|
166
|
-
description: "Turn a description of a system or process into a rendered Mermaid diagram.",
|
|
167
|
-
argsSchema: {
|
|
168
|
-
subject: z.string().describe("What the diagram should show."),
|
|
169
|
-
out: z.string().describe("Output path; the extension picks .svg, .png or .pdf.")
|
|
170
|
-
}
|
|
171
|
-
}, ({ subject, out }) => ({
|
|
172
|
-
messages: [
|
|
173
|
-
{
|
|
174
|
-
role: "user",
|
|
175
|
-
content: {
|
|
176
|
-
type: "text",
|
|
177
|
-
text: `Draw ${out} showing: ${subject}
|
|
178
|
-
|
|
179
|
-
Work in this order:
|
|
180
|
-
1. Choose the diagram type that matches the *relationship*, not the one you know best — a flow is a flowchart, an interaction over time is a sequenceDiagram, a lifecycle is a stateDiagram, a data model is an erDiagram, a schedule is a gantt.
|
|
181
|
-
2. Call diagram_inspect with the Mermaid source before rendering. Read the structure it reports back and check every node and edge you intended is there — the parser drops what it does not recognise **silently**, and this is the only place that shows.
|
|
182
|
-
3. Then diagram_render to ${out}.
|
|
183
|
-
4. Tell me the diagram's type and its node/edge counts. You cannot see the picture, so do not claim it "looks good" — report what the parser found.
|
|
184
|
-
|
|
185
|
-
If a label is long, prefer shortening it over widening the diagram. If ${out} is a page inside an existing PDF instead of a new file, use pdf_edit with op: "diagram".`
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
]
|
|
189
|
-
}));
|
|
190
|
-
}
|
|
191
163
|
if ((has("word") || has("pdf") || has("excel")) && !config.readonly) {
|
|
192
164
|
server.registerPrompt("convert-document", {
|
|
193
165
|
title: "Convert a document",
|
package/dist/capabilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,kCAAkC;AAClC,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAE9C,4CAA4C;AAC5C,MAAM,UAAU,iBAAiB,CAAC,MAAiB;IACjD,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QACxD,MAAM,CAAC,gBAAgB,CACrB,QAAQ,IAAI,EAAE,EACd,GAAG,eAAe,GAAG,IAAI,EAAE,EAC3B;YACE,KAAK,EAAE,gBAAgB,IAAI,EAAE;YAC7B,WAAW,EAAE,KAAK,CAAC,OAAO;YAC1B,QAAQ,EAAE,eAAe;SAC1B,EACD,GAAG,CAAC,EAAE,CAAC,CAAC;YACN,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;SAC3E,CAAC,CACH,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,MAAiB,EAAE,MAAoB;IACrE,MAAM,GAAG,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;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AC,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpE,MAAM,CAAC,cAAc,CACnB,kBAAkB,EAClB;YACE,KAAK,EAAE,oBAAoB;YAC3B,WAAW,EAAE,gEAAgE;YAC7E,UAAU,EAAE;gBACV,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC;gBACzC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mDAAmD,CAAC;aAC7E;SACF,EACD,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YACjB,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACP,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,WAAW,IAAI,OAAO,EAAE;;;;2DAIe;qBAC9C;iBACF;aACF;SACF,CAAC,CACH,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* `core` (`documonster_help`, `doc_inspect`) is always enabled — it is how a
|
|
15
15
|
* model orients itself before doing anything else.
|
|
16
16
|
*/
|
|
17
|
-
export declare const TOOL_GROUPS: readonly ["core", "excel", "word", "pdf", "forms", "archive"
|
|
17
|
+
export declare const TOOL_GROUPS: readonly ["core", "excel", "word", "pdf", "forms", "archive"];
|
|
18
18
|
export type ToolGroup = (typeof TOOL_GROUPS)[number];
|
|
19
19
|
export interface ServerConfig {
|
|
20
20
|
/**
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW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,EAAE,OAAO,CAAA;CAAE,CAK1F;AA2CD,+BAA+B;AAC/B,wBAAgB,KAAK,IAAI,MAAM,CAkC9B"}
|
package/dist/config.js
CHANGED
|
@@ -18,17 +18,9 @@ import { parseArgs } from "node:util";
|
|
|
18
18
|
* `core` (`documonster_help`, `doc_inspect`) is always enabled — it is how a
|
|
19
19
|
* model orients itself before doing anything else.
|
|
20
20
|
*/
|
|
21
|
-
export const TOOL_GROUPS = ["core", "excel", "word", "pdf", "forms", "archive"
|
|
21
|
+
export const TOOL_GROUPS = ["core", "excel", "word", "pdf", "forms", "archive"];
|
|
22
22
|
/** Groups enabled when `--enable` is omitted. */
|
|
23
|
-
const DEFAULT_GROUPS = [
|
|
24
|
-
"core",
|
|
25
|
-
"excel",
|
|
26
|
-
"word",
|
|
27
|
-
"pdf",
|
|
28
|
-
"forms",
|
|
29
|
-
"archive",
|
|
30
|
-
"diagram"
|
|
31
|
-
];
|
|
23
|
+
const DEFAULT_GROUPS = ["core", "excel", "word", "pdf", "forms", "archive"];
|
|
32
24
|
/** Default ceiling for a single input document, in bytes (64 MiB). */
|
|
33
25
|
const DEFAULT_MAX_FILE_SIZE = 64 * 1024 * 1024;
|
|
34
26
|
/**
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,
|
|
1
|
+
{"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EAAE,CAAC;YACxB,MAAM,IAAI,WAAW,CACnB,4BAA4B,KAAK,aAAa,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACxE,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,OAAQ,WAAiC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,cAAc,CAAC,GAAuB,EAAE,IAAY,EAAE,QAAgB;IAC7E,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,WAAW,CAAC,GAAG,IAAI,qCAAqC,GAAG,GAAG,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,+BAA+B;AAC/B,MAAM,UAAU,KAAK;IACnB,OAAO;;;;;;;;;;;;;;;uCAe8B,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;wEAEW,qBAAqB;+DAC9B,wBAAwB;;;;;;;;;;;;;;CActF,CAAC;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc-convert.d.ts","sourceRoot":"","sources":["../../src/tools/doc-convert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"doc-convert.d.ts","sourceRoot":"","sources":["../../src/tools/doc-convert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAyCH,eAAO,MAAM,cAAc,wCAqEzB,CAAC"}
|
|
@@ -20,7 +20,6 @@ import { markdownToDocx, renderToMarkdown } from "documonster/word/markdown";
|
|
|
20
20
|
import { z } from "zod";
|
|
21
21
|
import { toolError } from "../errors.js";
|
|
22
22
|
import { assertWritable, outputDisplay, resolveInRoot, resolveOutputPath } from "../sandbox.js";
|
|
23
|
-
import { prepareMarkdownDiagrams } from "./diagram-markdown.js";
|
|
24
23
|
import { assertNonMacroOutput, requireFormat } from "./document.js";
|
|
25
24
|
import { assertReadableSize, replaceAtomically, writeFileAtomic, writeWithPolicy } from "./fs-helpers.js";
|
|
26
25
|
import { formatBytes, textResult } from "./result.js";
|
|
@@ -55,10 +54,6 @@ export const docConvertTool = defineTool({
|
|
|
55
54
|
.union([z.string(), z.number().int().positive()])
|
|
56
55
|
.optional()
|
|
57
56
|
.describe("xlsx→csv only: which sheet to export. Defaults to the first."),
|
|
58
|
-
diagrams: z
|
|
59
|
-
.boolean()
|
|
60
|
-
.optional()
|
|
61
|
-
.describe("md→docx/pdf only: render ```mermaid fences as embedded diagrams. Defaults to true when the diagram tool group is enabled."),
|
|
62
57
|
overwrite: z
|
|
63
58
|
.boolean()
|
|
64
59
|
.optional()
|
|
@@ -82,23 +77,13 @@ export const docConvertTool = defineTool({
|
|
|
82
77
|
assertNonMacroOutput(args.to);
|
|
83
78
|
const allowed = ROUTES[fromFormat];
|
|
84
79
|
if (allowed === undefined || !allowed.includes(toFormat)) {
|
|
85
|
-
// A diagram is drawn, not converted, and saying "nothing converts from
|
|
86
|
-
// mermaid" would be true of this tool and false of the server.
|
|
87
|
-
if (fromFormat === "mermaid" || toFormat === "mermaid") {
|
|
88
|
-
throw toolError.unsupported(`doc_convert does not handle Mermaid diagrams`, fromFormat === "mermaid"
|
|
89
|
-
? "Use diagram_render to draw a .mmd file as .svg / .png / .pdf."
|
|
90
|
-
: "Nothing produces a .mmd file — a diagram is written, not derived from a document.");
|
|
91
|
-
}
|
|
92
80
|
throw toolError.unsupported(`cannot convert ${fromFormat} to ${toFormat}`, allowed === undefined
|
|
93
81
|
? `Nothing converts from ${fromFormat}. Supported sources: ${Object.keys(ROUTES).join(", ")}.`
|
|
94
82
|
: `From ${fromFormat} you can produce: ${allowed.join(", ")}.`);
|
|
95
83
|
}
|
|
96
84
|
let note = [];
|
|
97
85
|
await writeWithPolicy(target, args.overwrite === true, async (temporary) => {
|
|
98
|
-
note = await convert(fromFormat, toFormat, source, temporary,
|
|
99
|
-
...args,
|
|
100
|
-
renderDiagrams: args.diagrams ?? config.groups.has("diagram")
|
|
101
|
-
});
|
|
86
|
+
note = await convert(fromFormat, toFormat, source, temporary, args);
|
|
102
87
|
});
|
|
103
88
|
const size = (await stat(target)).size;
|
|
104
89
|
return textResult(config, [
|
|
@@ -166,21 +151,14 @@ async function convert(from, to, source, target, args) {
|
|
|
166
151
|
}
|
|
167
152
|
if (from === "md") {
|
|
168
153
|
const markdown = await readFile(source, "utf8");
|
|
169
|
-
const
|
|
170
|
-
? await prepareMarkdownDiagrams(markdown)
|
|
171
|
-
: { markdown, count: 0, notes: [] };
|
|
172
|
-
const doc = await markdownToDocx(prepared.markdown, {
|
|
173
|
-
...("resolveImage" in prepared && prepared.resolveImage !== undefined
|
|
174
|
-
? { resolveImage: prepared.resolveImage }
|
|
175
|
-
: {})
|
|
176
|
-
});
|
|
154
|
+
const doc = await markdownToDocx(markdown);
|
|
177
155
|
if (to === "docx") {
|
|
178
156
|
await replaceAtomically(target, temporary => Io.writeFile(doc, temporary));
|
|
179
|
-
return ["- Markdown structure mapped to Word styles"
|
|
157
|
+
return ["- Markdown structure mapped to Word styles"];
|
|
180
158
|
}
|
|
181
159
|
if (to === "pdf") {
|
|
182
160
|
await writeFileAtomic(target, await Pdf.fromDocx(doc));
|
|
183
|
-
return ["- rendered via Word layout, so pagination is real"
|
|
161
|
+
return ["- rendered via Word layout, so pagination is real"];
|
|
184
162
|
}
|
|
185
163
|
throw unreachable(from, to);
|
|
186
164
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc-convert.js","sourceRoot":"","sources":["../../src/tools/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AK,CAAC,CAAC,KAAc,EAAE,EAAE;QACxD,MAAM,SAAS,CAAC,WAAW,CACzB,8CAA8C,EAC9C,4GAA4G,EAC5G,EAAE,KAAK,EAAE,CACV,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,6EAA6E;AAC7E,SAAS,WAAW,CAAC,IAAe,EAAE,EAAa;IACjD,OAAO,SAAS,CAAC,WAAW,CAC1B,cAAc,IAAI,MAAM,EAAE,6CAA6C,EACvE,kCAAkC,CACnC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc-read.d.ts","sourceRoot":"","sources":["../../src/tools/doc-read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"doc-read.d.ts","sourceRoot":"","sources":["../../src/tools/doc-read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAmBH,eAAO,MAAM,WAAW,wCA0DtB,CAAC"}
|
package/dist/tools/doc-read.js
CHANGED
|
@@ -17,7 +17,6 @@ import { renderToMarkdown } from "documonster/word/markdown";
|
|
|
17
17
|
import { z } from "zod";
|
|
18
18
|
import { toolError } from "../errors.js";
|
|
19
19
|
import { resolveInRoot } from "../sandbox.js";
|
|
20
|
-
import { describeFences } from "./diagram.js";
|
|
21
20
|
import { continuationNote, parsePages, requireFormat, takeLines } from "./document.js";
|
|
22
21
|
import { assertReadableSize } from "./fs-helpers.js";
|
|
23
22
|
import { formatBytes, textResult } from "./result.js";
|
|
@@ -28,7 +27,7 @@ export const docReadTool = defineTool({
|
|
|
28
27
|
name: "doc_read",
|
|
29
28
|
group: ["word", "pdf"],
|
|
30
29
|
title: "Read a document's text",
|
|
31
|
-
description: "Read the text of a .docx, .pdf, .md
|
|
30
|
+
description: "Read the text of a .docx, .pdf, .md or .txt file. Word documents come back as Markdown so headings, lists and tables survive; PDFs are reported page by page. Reads a bounded number of lines and always says what it omitted. Call doc_inspect first to learn the file's real type.",
|
|
32
31
|
inputSchema: {
|
|
33
32
|
path: z.string().min(1).describe("Document path, relative to the server root."),
|
|
34
33
|
pages: z
|
|
@@ -68,12 +67,11 @@ export const docReadTool = defineTool({
|
|
|
68
67
|
case "md":
|
|
69
68
|
case "txt":
|
|
70
69
|
case "html":
|
|
71
|
-
case "mermaid":
|
|
72
70
|
return textResult(config, await readPlainText(resolved, args, format));
|
|
73
71
|
default:
|
|
74
72
|
throw toolError.unsupported(`doc_read cannot read .${format} files`, format === "xlsx" || format === "csv"
|
|
75
73
|
? "Use sheet_read for spreadsheets and CSV files."
|
|
76
|
-
: "Supported: .docx, .pdf, .md, .txt, .html
|
|
74
|
+
: "Supported: .docx, .pdf, .md, .txt, .html");
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
77
|
});
|
|
@@ -162,42 +160,16 @@ async function readPdf(resolved, args) {
|
|
|
162
160
|
header.push(...continuationNote(window));
|
|
163
161
|
return [...header, window.text].join("\n");
|
|
164
162
|
}
|
|
165
|
-
/**
|
|
166
|
-
* Read a text file, and route anything in it that is not really text.
|
|
167
|
-
*
|
|
168
|
-
* A Markdown file's mermaid fences arrive here as source code, and a `.mmd` file
|
|
169
|
-
* is nothing but a diagram. Both are shown verbatim — this tool's output is text,
|
|
170
|
-
* and a model cannot see a picture — but the footer names the tool that can draw
|
|
171
|
-
* it, so the model does not resort to copying the source back out through its own
|
|
172
|
-
* reply in order to render it.
|
|
173
|
-
*/
|
|
174
163
|
async function readPlainText(resolved, args, format) {
|
|
175
164
|
const raw = await readFile(resolved, "utf8");
|
|
176
165
|
const window = takeLines(raw, args.startLine ?? 1, args.maxLines ?? DEFAULT_MAX_LINES);
|
|
177
166
|
return [
|
|
178
|
-
`# ${args.path} (${format
|
|
167
|
+
`# ${args.path} (${format})`,
|
|
179
168
|
"",
|
|
180
169
|
`- showing lines ${window.startLine}–${window.endLine} of ${window.totalLines}`,
|
|
181
170
|
...continuationNote(window),
|
|
182
171
|
"",
|
|
183
|
-
window.text
|
|
184
|
-
...(format === "mermaid"
|
|
185
|
-
? [
|
|
186
|
-
"",
|
|
187
|
-
"This whole file is one diagram. Draw it with",
|
|
188
|
-
`\`diagram_render({ from: ${JSON.stringify(args.path)}, to: "diagram.svg" })\`, or read its`,
|
|
189
|
-
"structure with `diagram_inspect`. Do not paste the source above back as `source`.",
|
|
190
|
-
"",
|
|
191
|
-
"There is no conversion **to** a .mmd file: a diagram is written, not derived."
|
|
192
|
-
]
|
|
193
|
-
: // The whole file is scanned, not just the returned window, so the indices
|
|
194
|
-
// are stable no matter which lines this call happened to show.
|
|
195
|
-
appendFenceNote(raw))
|
|
172
|
+
window.text
|
|
196
173
|
].join("\n");
|
|
197
174
|
}
|
|
198
|
-
/** The fence index, separated from the body by a blank line when there is one. */
|
|
199
|
-
function appendFenceNote(raw) {
|
|
200
|
-
const fences = describeFences(raw);
|
|
201
|
-
return fences.length === 0 ? [] : ["", ...fences];
|
|
202
|
-
}
|
|
203
175
|
//# sourceMappingURL=doc-read.js.map
|