fix: band-level windowed refine_layout + programmatic map_fields to prevent 91.5% content loss

Root cause: LLM receiving full 34k-char JRXML would regenerate from scratch
instead of modifying coordinates in-place, shrinking output to ~3k chars.

Solution (programmatic node control, not prompt engineering):

- New agent/jrxml_windower.py: decompose JRXML into header (never sent to
  LLM) + individual bands. Split bands >4000 chars at element boundaries.
  Reassemble with element count validation (>10% change = rollback).

- Rewrite refine_layout: per-band windowed LLM processing (~2-4k chars
  each). LLM cannot "reimagine" the entire report.

- Rewrite map_fields: 100% programmatic regex $F{field_N} -> real name
  replacement. Zero LLM calls, zero content loss.

- _sanitize_field_name: non-ASCII chars escaped to _uXXXX_ format for
  valid JRXML identifiers.

- Tests: 48 new unit tests (windower 28 + map_fields 20). All passing.
  Full suite 385 tests, zero regressions.
This commit is contained in:
2026-05-24 08:55:38 +08:00
parent bb6cc6e241
commit bd5bfbac2d
80 changed files with 39463 additions and 108 deletions
+19 -13
View File
@@ -1,17 +1,23 @@
你是一位资深 JasperReports 工程师。当前有一个骨架 JRXML,需要根据精确的像素坐标调整每个元素的位置
你是一位 JRXML 坐标调整器。你的唯一任务是修改 <reportElement> 标签内的 x, y, width, height 属性值
关键规则:
- 只输出完整修改后的 JRXML 代码,不要解释,不要 markdown 标记。
- 根据提供的采样坐标,精确调整每个 textField/staticText 的 x, y, width, height。
- 表头行的坐标直接使用采样坐标中 header_row 对应列的 x, y, width, height。
- 数据行:根据 first_data_row 的坐标模式,向下插值生成剩余数据行(每行 y 递增行高)。
- 标题行(如有)和表尾行:保持其在骨架中的 y 位置大致不变,但调整 x 和 width 与列的采样坐标对齐。
- 不要修改字段名(保持 $F{{field_N}} 占位名不变)。
- 不要修改 band 结构。
- 确保 JRXML 兼容 JasperReports 7.0.6。
**这是 Band "{band_name}"(高度 {band_height}px)的第 {window_index}/{total_windows} 个窗口。你只看到该 band 的一个片段,不要尝试生成完整报表。**
当前骨架 JRXML
{current_jrxml}
严格规则
- 只修改 x, y, width, height。不改任何其他内容。
- 不添加、删除、重命名任何元素。
- 不修改文本内容(CDATA)、表达式(textFieldExpression)、样式属性。
- 只输出修改后的 XML 片段,不要解释,不要 markdown,不要代码块标记。
- 输出的字符数应与输入片段大致相同。
采样坐标(表头行 + 第一行数据行,像素位置)
坐标调整规则
- 表头行:直接使用 header_row 对应列的 x, y, width, height
- 数据行:根据 first_data_row 的坐标模式,向下插值(每行 y 递增行高)
- 标题行和表尾行:保持 y 位置大致不变,但调整 x 和 width 与列的采样坐标对齐
{template_context}
采样坐标参考:
{sampled_coordinates}
请调整以下片段的坐标:
{xml_fragment}