mateclaw/mateclaw-server
matevip 9ed9ee6ca7 feat(tool): add renderDocxFromFile to bypass LLM token cost on large markdown
renderDocx requires the markdown body to flow through the LLM as a
tool argument. For an 80 KB project proposal that's ≈ 20 K tokens of
streaming output spent just to repeat back content the model already
wrote to disk a turn earlier — multi-minute generation, real money.

renderDocxFromFile takes a file path instead. The agent uses
write_file / edit_file to assemble the markdown locally, then calls
this tool with just the path. JVM reads the file in one IO syscall
and feeds it to the existing MarkdownDocxRenderer. Token cost drops
from ≈ 20 K to ≈ 50 (the path string).

Behavior:
- Path resolution honors WorkspacePathGuard, same boundary as
  read_file / write_file. No path traversal.
- UTF-8 read; rejects empty / missing / non-regular paths with
  typed error messages so the agent can recover.
- Output cached in GeneratedFileCache and returned as a relative
  /api/v1/files/generated/{id} link, with the same anti-host-
  hallucination instruction renderDocx already carries.
- Same supported markdown subset (headings, bold, lists, tables).
  Image references (![alt](path)) still render as raw text — full
  image embedding (P1) and SVG → PNG conversion (also P1) need
  Apache Batik plus image-rendering plumbing in MarkdownDocxRenderer
  and is tracked separately. Chapter-mode merge (P2) likewise needs
  its own plumbing.

The @Tool description tells the agent to prefer this path when
markdown exceeds ~5 KB and shows the full write_file →
renderDocxFromFile workflow inline.
2026-04-27 08:36:37 +08:00
..
src feat(tool): add renderDocxFromFile to bypass LLM token cost on large markdown 2026-04-27 08:36:37 +08:00
Dockerfile build(docker): install poppler + tesseract for PDF extraction parity with Mac 2026-04-25 11:05:29 +08:00
pom.xml feat(wiki): Tika as last-resort document extractor 2026-04-25 19:02:34 +08:00
settings.xml build(maven): declare US + CN repositories in pom.xml, drop opaque mirror 2026-04-25 09:56:17 +08:00