wps-multitool-mcp 1.0.3 → 1.0.5

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.
Files changed (208) hide show
  1. package/README.md +2 -2
  2. package/dist/bridge/cancellable.d.ts.map +1 -1
  3. package/dist/bridge/cancellable.js +2 -0
  4. package/dist/bridge/cancellable.js.map +1 -1
  5. package/dist/bridge/index.js +36 -1
  6. package/dist/bridge/index.js.map +1 -1
  7. package/dist/client/action-routes.generated.d.ts +2 -2
  8. package/dist/client/action-routes.generated.d.ts.map +1 -1
  9. package/dist/client/action-routes.generated.js +8 -2
  10. package/dist/client/action-routes.generated.js.map +1 -1
  11. package/dist/server/auto-snapshot.d.ts.map +1 -1
  12. package/dist/server/auto-snapshot.js +12 -1
  13. package/dist/server/auto-snapshot.js.map +1 -1
  14. package/dist/server/collab-guard.d.ts +13 -0
  15. package/dist/server/collab-guard.d.ts.map +1 -0
  16. package/dist/server/collab-guard.js +112 -0
  17. package/dist/server/collab-guard.js.map +1 -0
  18. package/dist/server/intent-miss-log.d.ts +28 -0
  19. package/dist/server/intent-miss-log.d.ts.map +1 -0
  20. package/dist/server/intent-miss-log.js +143 -0
  21. package/dist/server/intent-miss-log.js.map +1 -0
  22. package/dist/server/mcp-server.d.ts +9 -0
  23. package/dist/server/mcp-server.d.ts.map +1 -1
  24. package/dist/server/mcp-server.js +168 -4
  25. package/dist/server/mcp-server.js.map +1 -1
  26. package/dist/server/progress-context.d.ts +6 -0
  27. package/dist/server/progress-context.d.ts.map +1 -0
  28. package/dist/server/progress-context.js +35 -0
  29. package/dist/server/progress-context.js.map +1 -0
  30. package/dist/server/task-engine.d.ts +112 -0
  31. package/dist/server/task-engine.d.ts.map +1 -0
  32. package/dist/server/task-engine.js +305 -0
  33. package/dist/server/task-engine.js.map +1 -0
  34. package/dist/server/tool-aliases.generated.d.ts +1 -1
  35. package/dist/server/tool-aliases.generated.d.ts.map +1 -1
  36. package/dist/server/tool-aliases.generated.js +15 -2
  37. package/dist/server/tool-aliases.generated.js.map +1 -1
  38. package/dist/server/tool-annotations.d.ts.map +1 -1
  39. package/dist/server/tool-annotations.generated.d.ts.map +1 -1
  40. package/dist/server/tool-annotations.generated.js +7 -8
  41. package/dist/server/tool-annotations.generated.js.map +1 -1
  42. package/dist/server/tool-annotations.js +18 -0
  43. package/dist/server/tool-annotations.js.map +1 -1
  44. package/dist/server/tool-metadata.d.ts.map +1 -1
  45. package/dist/server/tool-metadata.js +21 -9
  46. package/dist/server/tool-metadata.js.map +1 -1
  47. package/dist/server/tool-registry.d.ts.map +1 -1
  48. package/dist/server/tool-registry.js +26 -1
  49. package/dist/server/tool-registry.js.map +1 -1
  50. package/dist/server/tool-tiers.d.ts +2 -2
  51. package/dist/server/tool-tiers.js +2 -2
  52. package/dist/server/tool-verification.d.ts +5 -5
  53. package/dist/server/tool-verification.generated.d.ts +4 -4
  54. package/dist/server/tool-verification.generated.d.ts.map +1 -1
  55. package/dist/server/tool-verification.generated.js +78 -79
  56. package/dist/server/tool-verification.generated.js.map +1 -1
  57. package/dist/server/tool-verification.js +2 -2
  58. package/dist/tools/common/batch.d.ts.map +1 -1
  59. package/dist/tools/common/batch.js +5 -0
  60. package/dist/tools/common/batch.js.map +1 -1
  61. package/dist/tools/common/convert.js +34 -34
  62. package/dist/tools/common/general.d.ts.map +1 -1
  63. package/dist/tools/common/general.js +81 -79
  64. package/dist/tools/common/general.js.map +1 -1
  65. package/dist/tools/common/index.d.ts +1 -0
  66. package/dist/tools/common/index.d.ts.map +1 -1
  67. package/dist/tools/common/index.js +3 -0
  68. package/dist/tools/common/index.js.map +1 -1
  69. package/dist/tools/common/intent.d.ts +42 -0
  70. package/dist/tools/common/intent.d.ts.map +1 -1
  71. package/dist/tools/common/intent.js +307 -19
  72. package/dist/tools/common/intent.js.map +1 -1
  73. package/dist/tools/common/snapshot.d.ts.map +1 -1
  74. package/dist/tools/common/snapshot.js +27 -19
  75. package/dist/tools/common/snapshot.js.map +1 -1
  76. package/dist/tools/common/taskrunner.d.ts +25 -0
  77. package/dist/tools/common/taskrunner.d.ts.map +1 -0
  78. package/dist/tools/common/taskrunner.js +100 -0
  79. package/dist/tools/common/taskrunner.js.map +1 -0
  80. package/dist/tools/common/toolgroups.js +36 -36
  81. package/dist/tools/excel/chart.d.ts.map +1 -1
  82. package/dist/tools/excel/chart.js +109 -86
  83. package/dist/tools/excel/chart.js.map +1 -1
  84. package/dist/tools/excel/comment-protect.js +2 -2
  85. package/dist/tools/excel/comment-protect.js.map +1 -1
  86. package/dist/tools/excel/data.d.ts.map +1 -1
  87. package/dist/tools/excel/data.js +32 -21
  88. package/dist/tools/excel/data.js.map +1 -1
  89. package/dist/tools/excel/format.js +9 -9
  90. package/dist/tools/excel/formula.js +46 -46
  91. package/dist/tools/excel/pivot.js +34 -34
  92. package/dist/tools/excel/sheet.d.ts +4 -0
  93. package/dist/tools/excel/sheet.d.ts.map +1 -1
  94. package/dist/tools/excel/sheet.js +103 -1
  95. package/dist/tools/excel/sheet.js.map +1 -1
  96. package/dist/tools/ppt/animation.d.ts +2 -2
  97. package/dist/tools/ppt/animation.d.ts.map +1 -1
  98. package/dist/tools/ppt/animation.js +35 -97
  99. package/dist/tools/ppt/animation.js.map +1 -1
  100. package/dist/tools/ppt/beautify-advanced.d.ts +3 -16
  101. package/dist/tools/ppt/beautify-advanced.d.ts.map +1 -1
  102. package/dist/tools/ppt/beautify-advanced.js +65 -355
  103. package/dist/tools/ppt/beautify-advanced.js.map +1 -1
  104. package/dist/tools/ppt/chart-flow.d.ts.map +1 -1
  105. package/dist/tools/ppt/chart-flow.js +113 -278
  106. package/dist/tools/ppt/chart-flow.js.map +1 -1
  107. package/dist/tools/ppt/data-viz.d.ts.map +1 -1
  108. package/dist/tools/ppt/data-viz.js +78 -276
  109. package/dist/tools/ppt/data-viz.js.map +1 -1
  110. package/dist/tools/ppt/deckkit.d.ts +209 -0
  111. package/dist/tools/ppt/deckkit.d.ts.map +1 -0
  112. package/dist/tools/ppt/deckkit.js +635 -0
  113. package/dist/tools/ppt/deckkit.js.map +1 -0
  114. package/dist/tools/ppt/helpers.d.ts +38 -0
  115. package/dist/tools/ppt/helpers.d.ts.map +1 -0
  116. package/dist/tools/ppt/helpers.js +60 -0
  117. package/dist/tools/ppt/helpers.js.map +1 -0
  118. package/dist/tools/ppt/image.d.ts +6 -4
  119. package/dist/tools/ppt/image.d.ts.map +1 -1
  120. package/dist/tools/ppt/image.js +148 -244
  121. package/dist/tools/ppt/image.js.map +1 -1
  122. package/dist/tools/ppt/index.d.ts +43 -29
  123. package/dist/tools/ppt/index.d.ts.map +1 -1
  124. package/dist/tools/ppt/index.js +106 -95
  125. package/dist/tools/ppt/index.js.map +1 -1
  126. package/dist/tools/ppt/misc.d.ts +1 -2
  127. package/dist/tools/ppt/misc.d.ts.map +1 -1
  128. package/dist/tools/ppt/misc.js +70 -385
  129. package/dist/tools/ppt/misc.js.map +1 -1
  130. package/dist/tools/ppt/page-effects.d.ts +28 -0
  131. package/dist/tools/ppt/page-effects.d.ts.map +1 -0
  132. package/dist/tools/ppt/page-effects.js +505 -0
  133. package/dist/tools/ppt/page-effects.js.map +1 -0
  134. package/dist/tools/ppt/{background.d.ts → page-info.d.ts} +11 -13
  135. package/dist/tools/ppt/page-info.d.ts.map +1 -0
  136. package/dist/tools/ppt/page-info.js +258 -0
  137. package/dist/tools/ppt/page-info.js.map +1 -0
  138. package/dist/tools/ppt/presentation.d.ts +3 -6
  139. package/dist/tools/ppt/presentation.d.ts.map +1 -1
  140. package/dist/tools/ppt/presentation.js +136 -437
  141. package/dist/tools/ppt/presentation.js.map +1 -1
  142. package/dist/tools/ppt/shape-basic.d.ts +22 -3
  143. package/dist/tools/ppt/shape-basic.d.ts.map +1 -1
  144. package/dist/tools/ppt/shape-basic.js +518 -421
  145. package/dist/tools/ppt/shape-basic.js.map +1 -1
  146. package/dist/tools/ppt/slide-ops.d.ts +6 -42
  147. package/dist/tools/ppt/slide-ops.d.ts.map +1 -1
  148. package/dist/tools/ppt/slide-ops.js +93 -1485
  149. package/dist/tools/ppt/slide-ops.js.map +1 -1
  150. package/dist/tools/ppt/slide.d.ts +1 -7
  151. package/dist/tools/ppt/slide.d.ts.map +1 -1
  152. package/dist/tools/ppt/slide.js +196 -328
  153. package/dist/tools/ppt/slide.js.map +1 -1
  154. package/dist/tools/ppt/table.d.ts.map +1 -1
  155. package/dist/tools/ppt/table.js +94 -264
  156. package/dist/tools/ppt/table.js.map +1 -1
  157. package/dist/tools/ppt/textbox.d.ts +1 -22
  158. package/dist/tools/ppt/textbox.d.ts.map +1 -1
  159. package/dist/tools/ppt/textbox.js +87 -107
  160. package/dist/tools/ppt/textbox.js.map +1 -1
  161. package/dist/tools/word/academic.d.ts +2 -0
  162. package/dist/tools/word/academic.d.ts.map +1 -1
  163. package/dist/tools/word/academic.js +77 -111
  164. package/dist/tools/word/academic.js.map +1 -1
  165. package/dist/tools/word/content.d.ts +7 -12
  166. package/dist/tools/word/content.d.ts.map +1 -1
  167. package/dist/tools/word/content.js +134 -452
  168. package/dist/tools/word/content.js.map +1 -1
  169. package/dist/tools/word/document.d.ts +1 -3
  170. package/dist/tools/word/document.d.ts.map +1 -1
  171. package/dist/tools/word/document.js +71 -328
  172. package/dist/tools/word/document.js.map +1 -1
  173. package/dist/tools/word/format.d.ts.map +1 -1
  174. package/dist/tools/word/format.js +59 -211
  175. package/dist/tools/word/format.js.map +1 -1
  176. package/dist/tools/word/helpers.d.ts +33 -0
  177. package/dist/tools/word/helpers.d.ts.map +1 -0
  178. package/dist/tools/word/helpers.js +50 -0
  179. package/dist/tools/word/helpers.js.map +1 -0
  180. package/dist/tools/word/index.d.ts +1 -1
  181. package/dist/tools/word/index.d.ts.map +1 -1
  182. package/dist/tools/word/index.js +2 -6
  183. package/dist/tools/word/index.js.map +1 -1
  184. package/dist/tools/word/professional.d.ts +4 -0
  185. package/dist/tools/word/professional.d.ts.map +1 -1
  186. package/dist/tools/word/professional.js +80 -4
  187. package/dist/tools/word/professional.js.map +1 -1
  188. package/dist/tools/word/proofread.d.ts.map +1 -1
  189. package/dist/tools/word/proofread.js +44 -184
  190. package/dist/tools/word/proofread.js.map +1 -1
  191. package/dist/types/tools.d.ts +6 -0
  192. package/dist/types/tools.d.ts.map +1 -1
  193. package/dist/utils/image-inline.d.ts +3 -0
  194. package/dist/utils/image-inline.d.ts.map +1 -0
  195. package/dist/utils/image-inline.js +61 -0
  196. package/dist/utils/image-inline.js.map +1 -0
  197. package/dist/version.js +1 -1
  198. package/package.json +1 -1
  199. package/scripts/wps-com.ps1 +509 -28
  200. package/skills/wps-multitool/SKILL.md +17 -4
  201. package/skills/wps-multitool/references/dsh.md +1 -1
  202. package/skills/wps-multitool/references/recipes.md +20 -4
  203. package/skills/wps-multitool/references/routing.md +13 -0
  204. package/dist/client/mac-poll-server.d.ts.map +0 -1
  205. package/dist/client/mac-poll-server.js.map +0 -1
  206. package/dist/tools/ppt/background.d.ts.map +0 -1
  207. package/dist/tools/ppt/background.js +0 -389
  208. package/dist/tools/ppt/background.js.map +0 -1
@@ -159,6 +159,27 @@ function Remove-OwnCreatedProcs {
159
159
  return $n
160
160
  }
161
161
 
162
+ # ==================== AI 撤销分组(逐步撤销,对标 per-action undo) ====================
163
+ # AI 的每个破坏性动作包进一个自定义撤销记录:用户 Ctrl+Z 一次退回一整个动作,
164
+ # 而不是跟自己的编辑混在一起。仅 Word 侧有 UndoRecord;拿不到时静默返回 $null——
165
+ # 没有分组只是撤销粒度变粗,不是功能失败。
166
+ function Start-AiUndoRecord {
167
+ param($Doc, [string]$Label)
168
+ try {
169
+ $app = $Doc.Application
170
+ if ($null -ne $app -and $null -ne $app.UndoRecord) {
171
+ $ur = $app.UndoRecord
172
+ $ur.StartCustomRecord("AI: " + $Label)
173
+ return $ur
174
+ }
175
+ } catch { }
176
+ return $null
177
+ }
178
+ function Stop-AiUndoRecord {
179
+ param($UndoRecord)
180
+ if ($null -ne $UndoRecord) { try { $UndoRecord.StopCustomRecord() } catch { } }
181
+ }
182
+
162
183
  # ==================== COM Object Getters ====================
163
184
 
164
185
  function Get-WpsExcel {
@@ -305,14 +326,69 @@ function Get-WpsExePath {
305
326
  return $null
306
327
  }
307
328
 
329
+ # 演示文稿健康检查(微轮 · PPT 定位去 Active 化 2026-11-05):Name 非空 且 Slides.Count 可读。
330
+ # 对应 word 侧的 Test-DocHealthy——Active* 是弱引用(依赖 UI 焦点,自动化场景不可靠),
331
+ # 冷启动/焦点落在首页时会给出 null/空壳,必须过健康检查才能当"解析成功"。
332
+ function Test-PresHealthy($pres) {
333
+ if ($null -eq $pres) { return $false }
334
+ try {
335
+ $n = [string]$pres.Name
336
+ if ([string]::IsNullOrWhiteSpace($n)) { return $false }
337
+ } catch { return $false }
338
+ try { $null = $pres.Slides.Count } catch { return $false }
339
+ return $true
340
+ }
341
+
342
+ # 按名字找演示文稿:先按 FullName 全等,再按 Name 全等,最后按"文件名(无扩展名)"全等。
343
+ function Find-PresByName($ppt, [string]$want) {
344
+ if ($null -eq $ppt -or [string]::IsNullOrWhiteSpace($want)) { return $null }
345
+ $items = @()
346
+ try { $items = @($ppt.Presentations) } catch { return $null }
347
+ foreach ($c in $items) {
348
+ try { if ([string]$c.FullName -eq $want) { return $c } } catch {}
349
+ }
350
+ foreach ($c in $items) {
351
+ try { if ([string]$c.Name -eq $want) { return $c } } catch {}
352
+ }
353
+ $stem = [System.IO.Path]::GetFileNameWithoutExtension($want)
354
+ if (-not [string]::IsNullOrWhiteSpace($stem)) {
355
+ foreach ($c in $items) {
356
+ try { if ([string]$c.Name -eq $stem) { return $c } } catch {}
357
+ try { if ([System.IO.Path]::GetFileNameWithoutExtension([string]$c.Name) -eq $stem) { return $c } } catch {}
358
+ }
359
+ }
360
+ return $null
361
+ }
362
+
363
+ # 解析目标演示文稿(微轮 · PPT 定位去 Active 化,照 Resolve-Doc 形制):
364
+ # 1) presentationName 精确定位(找不到返回 $null,不静默回退——否则用户以为在改 A 结果改的是 B);
365
+ # 2) ActivePresentation 必须过 Test-PresHealthy(弱引用/幽灵窗口在恶劣状态下给出 null/空壳);
366
+ # 3) 空壳 → 遍历 Presentations 取第一个健康的;
367
+ # 4) 全空返回 $null,由调用方报明确错误。
368
+ function Resolve-Pres($ppt, $p) {
369
+ if ($null -eq $ppt) { return $null }
370
+ if ($p -and $p.presentationName) {
371
+ $d = Find-PresByName $ppt ([string]$p.presentationName)
372
+ if ($d) { return $d }
373
+ return $null
374
+ }
375
+ try { $act = $ppt.ActivePresentation } catch { $act = $null }
376
+ if (Test-PresHealthy $act) { return $act }
377
+ try {
378
+ foreach ($c in @($ppt.Presentations)) {
379
+ if (Test-PresHealthy $c) { return $c }
380
+ }
381
+ } catch {}
382
+ return $null
383
+ }
384
+
308
385
  # 解析目标演示文稿:优先按 presentationName 精确定位(避免多文稿打开时 ActivePresentation 漂移),
309
386
  # 未提供则回退到当前活动文稿;提供了但找不到则返回 $null(让调用方报明确错误,而不是误改其它文稿)。
387
+ # 微轮(2026-11-05):实现体收敛到 Resolve-Pres(Active 过健康检查 + 空壳遍历)——
388
+ # 全组用 Get-TargetPres 的 PPT 工具自动获得去 Active 化后的解析。
310
389
  function Get-TargetPres($ppt, $p) {
311
390
  if ($null -eq $ppt) { return $null }
312
- if ($p.presentationName) {
313
- try { return $ppt.Presentations.Item([string]$p.presentationName) } catch { return $null }
314
- }
315
- return $ppt.ActivePresentation
391
+ return Resolve-Pres $ppt $p
316
392
  }
317
393
 
318
394
  # 取整型参数并带默认值。写成函数而不是内联 $(if ...):内联 if 在 [int] 转换里
@@ -1049,7 +1125,12 @@ switch ($Action) {
1049
1125
  $dir = ""; try { $dir = [string]$book.Path } catch {}
1050
1126
  $saved = $true; try { $saved = [bool]$book.Saved } catch {}
1051
1127
  $ro = $false; try { $ro = [bool]$book.ReadOnly } catch {}
1052
- $cand += @{ app = "excel"; name = [string]$book.Name; fullName = $full; dir = $dir; saved = $saved; readOnly = $ro; hasPath = (-not [string]::IsNullOrEmpty($dir)) }
1128
+ # editProbe:协作安全网的文档指纹(2026-10-29)。excel 用 UsedRange 的
1129
+ # 地址+行列数 —— 只有结构性增删会动它,改单元格值不会(诚实局限:
1130
+ # 值级人工编辑在此探测不到)。取不到就 $null,守卫侧按降级处理。
1131
+ $probe = $null
1132
+ try { $ur = $book.ActiveSheet.UsedRange; $probe = "$($ur.Address)|$($ur.Rows.Count)x$($ur.Columns.Count)" } catch {}
1133
+ $cand += @{ app = "excel"; name = [string]$book.Name; fullName = $full; dir = $dir; saved = $saved; readOnly = $ro; hasPath = (-not [string]::IsNullOrEmpty($dir)); editProbe = $probe }
1053
1134
  }
1054
1135
  } catch {}
1055
1136
  }
@@ -1065,7 +1146,11 @@ switch ($Action) {
1065
1146
  $dir = ""; try { $dir = [string]$doc.Path } catch {}
1066
1147
  $saved = $true; try { $saved = [bool]$doc.Saved } catch {}
1067
1148
  $ro = $false; try { $ro = [bool]$doc.ReadOnly } catch {}
1068
- $cand += @{ app = "word"; name = [string]$doc.Name; fullName = $full; dir = $dir; saved = $saved; readOnly = $ro; hasPath = (-not [string]::IsNullOrEmpty($dir)) }
1149
+ # editProbe:word 用正文流末位(Content.End,O(1))——插入/删除会移动它,
1150
+ # 纯格式调整不会(诚实局限:排版级人工编辑探测不到)。
1151
+ $probe = $null
1152
+ try { $probe = [string]$doc.Content.End } catch {}
1153
+ $cand += @{ app = "word"; name = [string]$doc.Name; fullName = $full; dir = $dir; saved = $saved; readOnly = $ro; hasPath = (-not [string]::IsNullOrEmpty($dir)); editProbe = $probe }
1069
1154
  }
1070
1155
  } catch {}
1071
1156
  }
@@ -1081,7 +1166,10 @@ switch ($Action) {
1081
1166
  $dir = ""; try { $dir = [string]$pres.Path } catch {}
1082
1167
  $saved = $true; try { $saved = [bool]$pres.Saved } catch {}
1083
1168
  $ro = $false; try { $ro = [bool]$pres.ReadOnly } catch {}
1084
- $cand += @{ app = "ppt"; name = [string]$pres.Name; fullName = $full; dir = $dir; saved = $saved; readOnly = $ro; hasPath = (-not [string]::IsNullOrEmpty($dir)) }
1169
+ # editProbe:ppt 用页数 —— 增删页会动它,改页内文字不会(诚实局限)。
1170
+ $probe = $null
1171
+ try { $probe = [string]$pres.Slides.Count } catch {}
1172
+ $cand += @{ app = "ppt"; name = [string]$pres.Name; fullName = $full; dir = $dir; saved = $saved; readOnly = $ro; hasPath = (-not [string]::IsNullOrEmpty($dir)); editProbe = $probe }
1085
1173
  }
1086
1174
  } catch {}
1087
1175
  }
@@ -1658,22 +1746,37 @@ switch ($Action) {
1658
1746
  }
1659
1747
 
1660
1748
  "save" {
1749
+ # 落盘校验(七坑 #6 收尾 2026-10-28):Save() 之后读回文档路径,存在性 + 大小>0。
1750
+ # 从未保存过的文档没有 FullName(Save 会弹另存框)——校验只对"有路径"的场景生效,
1751
+ # 无路径时如实回 note,不假装校验过。
1752
+ function Test-SavedOnDisk($obj) {
1753
+ try {
1754
+ $fp = [string]$obj.FullName
1755
+ if (-not $fp -or -not (Test-Path $fp)) { return @{ saved = $true; verified = $false; note = "文档无磁盘路径(从未保存过),无法校验落盘" } }
1756
+ $fi = Get-Item $fp
1757
+ if ($fi.Length -gt 0) { return @{ saved = $true; verified = $true; path = $fp; size = $fi.Length } }
1758
+ return @{ saved = $true; verified = $false; path = $fp; note = "落盘文件大小为 0" }
1759
+ } catch { return @{ saved = $true; verified = $false; note = "落盘校验失败: " + $_.Exception.Message } }
1760
+ }
1661
1761
  $excel = Get-WpsExcel
1662
1762
  if ($null -ne $excel -and $null -ne $(Resolve-Book $excel $p)) {
1663
- $(Resolve-Book $excel $p).Save()
1664
- Output-Json @{ success = $true; app = "excel" }
1763
+ $bk = $(Resolve-Book $excel $p)
1764
+ $bk.Save()
1765
+ Output-Json @{ success = $true; app = "excel"; data = (Test-SavedOnDisk $bk) }
1665
1766
  return
1666
1767
  }
1667
1768
  $word = Get-WpsWord
1668
1769
  if ($null -ne $word -and $null -ne $(Resolve-Doc $word $p)) {
1669
- $(Resolve-Doc $word $p).Save()
1670
- Output-Json @{ success = $true; app = "word" }
1770
+ $dc = $(Resolve-Doc $word $p)
1771
+ $dc.Save()
1772
+ Output-Json @{ success = $true; app = "word"; data = (Test-SavedOnDisk $dc) }
1671
1773
  return
1672
1774
  }
1673
1775
  $ppt = Get-WpsPpt
1674
1776
  if ($null -ne $ppt -and $null -ne $ppt.ActivePresentation) {
1675
- $ppt.ActivePresentation.Save()
1676
- Output-Json @{ success = $true; app = "ppt" }
1777
+ $pr = $ppt.ActivePresentation
1778
+ $pr.Save()
1779
+ Output-Json @{ success = $true; app = "ppt"; data = (Test-SavedOnDisk $pr) }
1677
1780
  return
1678
1781
  }
1679
1782
  Output-Json @{ success = $false; error = "No active document" }
@@ -1700,7 +1803,13 @@ switch ($Action) {
1700
1803
  }
1701
1804
  $same = $false
1702
1805
  try { $same = ([IO.Path]::GetFullPath($actual) -ieq [IO.Path]::GetFullPath($requested)) } catch {} # 吞错有据:比较失败按未验证处理,不静默判成一致
1703
- return @{ path = $actual; requestedPath = $requested; verified = $same }
1806
+ # 七坑 #6 收尾(2026-10-28):verified 之外补大小校验(存在 + >0)
1807
+ $size = $null; $sizeNote = $null
1808
+ try {
1809
+ if (Test-Path $actual) { $size = (Get-Item $actual).Length; if ($size -le 0) { $sizeNote = "落盘文件大小为 0" } }
1810
+ else { $sizeNote = "落盘路径不存在" }
1811
+ } catch { $sizeNote = "大小校验失败: " + $_.Exception.Message }
1812
+ return @{ path = $actual; requestedPath = $requested; verified = $same; size = $size; sizeNote = $sizeNote }
1704
1813
  }
1705
1814
 
1706
1815
  if ($appType -eq 'excel') {
@@ -1810,11 +1919,20 @@ switch ($Action) {
1810
1919
  $ppt = Get-WpsPpt
1811
1920
  if ($null -eq $ppt) { Output-Json @{ success = $false; error = "WPS PPT not running" }; return }
1812
1921
  $pres = $ppt.Presentations.Add()
1922
+ # 微轮 · PPT 定位去 Active 化(2026-11-05):Add() 不带窗口不物化——0 页幽灵演示文稿
1923
+ # 会毒化 ActivePresentation 焦点(后续 Slides.Add 报"对 Null 调方法")。Add 后立即
1924
+ # Activate 物化窗口,从源头杀幽灵;Activate 失败进 warnings 不阻断。
1925
+ $actWarn = $null
1926
+ try { $pres.Activate() } catch { $actWarn = "新演示文稿窗口物化失败(Activate):" + $_.Exception.Message }
1813
1927
  # 必须回 data:Node 侧的 handler 判的是 success && data,
1814
1928
  # 只回 success 会被当成失败("新建演示文稿失败: undefined" —— 实测踩过)
1815
1929
  $nm = ""
1816
1930
  try { $nm = [string]$pres.Name } catch {}
1817
- Output-Json @{ success = $true; data = @{ name = $nm; count = $ppt.Presentations.Count } }
1931
+ if ($actWarn) {
1932
+ Output-Json @{ success = $true; data = @{ name = $nm; count = $ppt.Presentations.Count }; warnings = @(@{ step = 'createPresentation'; message = $actWarn }) }
1933
+ } else {
1934
+ Output-Json @{ success = $true; data = @{ name = $nm; count = $ppt.Presentations.Count } }
1935
+ }
1818
1936
  }
1819
1937
 
1820
1938
  "convertToPDF" {
@@ -4189,12 +4307,16 @@ switch ($Action) {
4189
4307
  } else {
4190
4308
  Output-Json @{ success = $false; error = "需要 index(序号)或 text(批注内容片段)之一" }; return
4191
4309
  }
4310
+ # 逐步撤销:删除批注包进一个撤销记录,用户一次 Ctrl+Z 退回
4311
+ $ur = Start-AiUndoRecord $doc "删除批注"
4312
+ try {
4192
4313
  $before = ""
4193
4314
  try { $before = [string]$target.Range.Text } catch {} # 吞错有据:展示用的删除前文本,读不到不影响删除本身
4194
4315
  $target.Delete()
4195
4316
  $n1 = 0
4196
4317
  try { $n1 = [int]$doc.Comments.Count } catch {} # 吞错有据:剩余计数读不到按 0 展示
4197
4318
  Output-Json @{ success = $true; data = @{ deleted = $before; remaining = $n1 } }
4319
+ } finally { Stop-AiUndoRecord $ur }
4198
4320
  }
4199
4321
 
4200
4322
  "getBookmarks" {
@@ -4346,6 +4468,14 @@ switch ($Action) {
4346
4468
  Output-Json @{ success = $false; error = "探测失败:临时文档未就绪(Documents.Add 返回空壳,等待 3 秒仍不可用)" }
4347
4469
  return
4348
4470
  }
4471
+
4472
+ # 空壳对象判定(BACKLOG 顺手项 2026-10-27 补):Documents.Add 可能返回
4473
+ # 非 null 但不健康的空壳(B3 线门禁"Documents.Count 0→0"的根因)——
4474
+ # 只判 null 捕不住它,这里升级为健康判定,同样显式失败。
4475
+ if (-not (Test-DocHealthy $doc)) {
4476
+ Output-Json @{ success = $false; error = "探测失败:临时文档为空壳(非 null 但不健康),等待 3 秒仍不可用" }
4477
+ return
4478
+ }
4349
4479
  # 铺探测素材:一段文字 + 一张 2x2 表 + 一个书签
4350
4480
  try { $null = $doc.Content.InsertAfter("__probe__ 内容") } catch {}
4351
4481
  try { $null = $doc.Tables.Add($doc.Range($doc.Content.End - 1, $doc.Content.End - 1), 2, 2) } catch {}
@@ -5137,14 +5267,12 @@ switch ($Action) {
5137
5267
  Output-Json @{ success = $false; error = "[勿重试·先改参数] 宽高必须是正数(收到 width=$($p.width) height=$($p.height))" }
5138
5268
  return
5139
5269
  }
5140
- # 单位换算:TS 的 schema 承诺的是【像素】,而 WPS 的 PageSetup 要的是【磅】。
5141
- # 1 px = 0.75 pt(96 DPI)。不换算的话 960×720 会被当成 960×720 磅 = 13.3×10 英寸,
5142
- # 页面上所有元素都跑到角落里去 —— 用户看到的是"设完尺寸版面全乱了"。
5143
- $wPt = $w * 0.75
5144
- $hPt = $h * 0.75
5145
- $pres.PageSetup.SlideWidth = $wPt
5146
- $pres.PageSetup.SlideHeight = $hPt
5147
- Output-Json @{ success = $true; data = @{ width = $w; height = $h; widthPt = $wPt; heightPt = $hPt; slideCount = $pres.Slides.Count } }
5270
+ # 单位裁定(2026-11-03 所有者授权决策者定):全组统一【磅】——COM/VBA/Office JS 原生单位,
5271
+ # 一套闭环最广。v1.0.5 起本动作收到的 width/height 直接就是磅,不再做 px→pt 的 ×0.75 换算
5272
+ # (旧口径曾按 96 DPI 折算:960×720"像素"进来变 720×540 磅出去;迁移提示写在 TS schema 里)。
5273
+ $pres.PageSetup.SlideWidth = $w
5274
+ $pres.PageSetup.SlideHeight = $h
5275
+ Output-Json @{ success = $true; data = @{ width = $w; height = $h; widthPt = $w; heightPt = $h; slideCount = $pres.Slides.Count } }
5148
5276
  }
5149
5277
 
5150
5278
  "setSlideTheme" {
@@ -5283,7 +5411,14 @@ switch ($Action) {
5283
5411
  if ($shape.HasTextFrame) {
5284
5412
  $text = ""
5285
5413
  try { $text = $shape.TextFrame.TextRange.Text } catch {}
5286
- $textBoxes += @{ name = $shape.Name; index = $i; text = $text; left = $shape.Left; top = $shape.Top; width = $shape.Width; height = $shape.Height }
5414
+ # E3 增补(deckkit 生成后溢出检查的读回依据,引擎探针 seg2 证过 BoundHeight 可判溢出):
5415
+ # boundWidth/boundHeight = 文字实际包围盒(超框判据),fontSize = 当前字号(缩字档位基准)。
5416
+ # 取不到时回 null——调用方按字段缺失降级,勿当硬失败。老桥没有这几行。
5417
+ $bw = $null; $bh = $null; $fs = $null
5418
+ try { $bw = [math]::Round($shape.BoundWidth, 2) } catch {}
5419
+ try { $bh = [math]::Round($shape.BoundHeight, 2) } catch {}
5420
+ try { $fs = $shape.TextFrame.TextRange.Font.Size } catch {}
5421
+ $textBoxes += @{ name = $shape.Name; index = $i; text = $text; left = $shape.Left; top = $shape.Top; width = $shape.Width; height = $shape.Height; boundWidth = $bw; boundHeight = $bh; fontSize = $fs }
5287
5422
  }
5288
5423
  }
5289
5424
  Output-Json @{ success = $true; data = @{ slideIndex = $slideIndex; textBoxes = $textBoxes; count = $textBoxes.Count } }
@@ -6090,10 +6225,11 @@ switch ($Action) {
6090
6225
  $pres = Get-TargetPres $ppt $p
6091
6226
  $slideIndex = if ($p.slideIndex) { $p.slideIndex } else { 1 }
6092
6227
  $slide = $pres.Slides.Item($slideIndex)
6093
- $left = if ($p.left) { $p.left } else { 100 }
6094
- $top = if ($p.top) { $p.top } else { 100 }
6095
- $width = if ($p.width) { $p.width } else { 400 }
6096
- $height = if ($p.height) { $p.height } else { 300 }
6228
+ # 坐标/尺寸用 $null -ne 判断,不用真值判断:0 是合法坐标(与 TS 侧 add_shape 的 ?? 修复同批,审计三.1)
6229
+ $left = if ($null -ne $p.left) { $p.left } else { 100 }
6230
+ $top = if ($null -ne $p.top) { $p.top } else { 100 }
6231
+ $width = if ($null -ne $p.width) { $p.width } else { 400 }
6232
+ $height = if ($null -ne $p.height) { $p.height } else { 300 }
6097
6233
  # AddChart 的第一个参数是 xlChartType 枚举(数字),不是类型名字符串。
6098
6234
  # 之前这里直接把 $p.type 丢进去:TS 传 chartType 时它是 $null(靠 COM 兜默认值蒙混过去),
6099
6235
  # 入口归一化把 chartType 映射成 type 之后,"bar" 这个字符串就撞上来了 ——
@@ -7933,6 +8069,21 @@ switch ($Action) {
7933
8069
  # 实测本机 WPS 12.1 的 Range/Selection.InsertCaption 都会抛"值不在预期的范围内"
7934
8070
  # (CaptionLabels 集合也不可用),所以必须有这条兜底,否则这个功能直接废掉。
7935
8071
  # 代价:序号是写死的文本,不是活编号域 —— 图表目录收集不到,已在返回值里如实标注。
8072
+ # ①b SEQ 活域兜底(2026-10-28 主线 ps1 增补轮):__probeCaptionSeq 真机实测
8073
+ # Fields.Add(rng, -1, "SEQ <label> \* ARABIC", false) 插入成功且编号为活域,
8074
+ # TablesOfFigures.Add(…, label) 更新后实际收集 1 条(探针 collectedEntries=1)——
8075
+ # 任务卡判定标准:读回 TOF 实际收集条目数 ≥1 → 链条通。
8076
+ # 这层插的是真编号域,图表目录能自动收集;仍失败才落到纯文本。
8077
+ if ($null -eq $mode) {
8078
+ try {
8079
+ $rng = $word.Selection.Range
8080
+ $rng.Collapse(0)
8081
+ $f = $doc.Fields.Add($rng, -1, "SEQ $label \* ARABIC", $false)
8082
+ if ($null -eq $f) { throw "Fields.Add 返回 null" }
8083
+ $mode = "seq"
8084
+ $captionText = "$label "
8085
+ } catch { $seqErr = $_.Exception.Message }
8086
+ }
7936
8087
  if ($null -eq $mode) {
7937
8088
  try {
7938
8089
  $n = 0
@@ -8157,6 +8308,244 @@ switch ($Action) {
8157
8308
  Output-Json @{ success = $true; data = @{ received = $p; keys = $keys; ptype = $p.GetType().FullName } }
8158
8309
  }
8159
8310
 
8311
+ # 【B5-T3 主线 · 目标 A+B1】题注 SEQ 端到端 + Bibliography 探针(word 宿主,临时文档探完即关)。
8312
+ # 链路判定标准(任务卡):TOF 实际收集条目数 ≥1 = 链通(不许只看调用成功)。
8313
+ # SEQ 域参考 ps1 既有范式:Fields.Add(rng, -1, 域代码, false)(PAGE/STYLEREF/REF 同款)。
8314
+ "__probeCaptionSeq" {
8315
+ $out = @{}
8316
+ $word = $null; $doc = $null
8317
+ try { $word = Get-WpsWord } catch { $out.hostErr = $_.Exception.Message }
8318
+ if ($null -eq $word) { Output-Json @{ success = $false; error = "WPS Word not running"; data = $out }; return }
8319
+ try {
8320
+ $doc = $word.Documents.Add()
8321
+ for ($i = 0; $i -lt 20; $i++) {
8322
+ Start-Sleep -Milliseconds 150
8323
+ try { $cur = $word.Documents.Item($word.Documents.Count); if (Test-DocHealthy $cur) { $doc = $cur; break } } catch {}
8324
+ }
8325
+ if (-not (Test-DocHealthy $doc)) { Output-Json @{ success = $false; error = "探测失败:临时文档为空壳"; data = $out }; return }
8326
+
8327
+ # 正文一段 + 伪图(占位段落)
8328
+ try { $null = $doc.Content.InsertAfter("探针正文第一段。`r"); } catch { $out.bodyErr = $_.Exception.Message }
8329
+
8330
+ # ---- SEQ 域三形态(哪种能插成功且显示"图 1")----
8331
+ $seq = @{}
8332
+ try {
8333
+ $rng = $doc.Content; $rng.Collapse(0)
8334
+ $f = $doc.Fields.Add($rng, -1, "SEQ 图 \* ARABIC", $false)
8335
+ if ($null -eq $f) { throw "Fields.Add 返回 null" }
8336
+ $seq.formA_code = "ok"
8337
+ try { $seq.formA_result = [string]$f.Result.Text } catch { $seq.formAResultErr = $_.Exception.Message }
8338
+ try { $seq.formA_codeText = [string]$f.Code.Text } catch {}
8339
+ } catch { $seq.formA_err = $_.Exception.Message }
8340
+ try {
8341
+ $rng = $doc.Content; $rng.Collapse(0)
8342
+ $f = $doc.Fields.Add($rng, 34, "图", $false)
8343
+ if ($null -eq $f) { throw "Fields.Add 返回 null" }
8344
+ $seq.formB_type34 = "ok"
8345
+ try { $seq.formB_result = [string]$f.Result.Text } catch { $seq.formBResultErr = $_.Exception.Message }
8346
+ } catch { $seq.formB_err = $_.Exception.Message }
8347
+ $out.seqField = $seq
8348
+
8349
+ # ---- TOF 收集(链路判定核心):带标签"图"的图表目录,更新后读回收集条目 ----
8350
+ try {
8351
+ $rng2 = $doc.Content; $rng2.Collapse(0)
8352
+ $tof = $doc.TablesOfFigures.Add($rng2, "图")
8353
+ try { $tof.Update() } catch { $out.tofUpdateErr = $_.Exception.Message }
8354
+ $tofInfo = @{}
8355
+ try { $tofInfo.tofCount = [int]$doc.TablesOfFigures.Count } catch {}
8356
+ try {
8357
+ $tofText = [string]$doc.TablesOfFigures.Item(1).Range.Text
8358
+ $tofInfo.tofText = $tofText
8359
+ # 收集条目数:目录文本里 "图 N" 的出现次数(SEQ 编号至少应有"图 1")
8360
+ $m = [regex]::Matches($tofText, "图\s*\d+")
8361
+ $tofInfo.collectedEntries = $m.Count
8362
+ } catch { $tofInfo.readErr = $_.Exception.Message }
8363
+ $out.tof = $tofInfo
8364
+ } catch { $out.tof = @{ ok = $false; error = $_.Exception.Message } }
8365
+
8366
+ # ---- Bibliography(目标 B1):存在性 + 书目域可用性 ----
8367
+ try {
8368
+ $bib = @{}
8369
+ try { $bib.hasBibliography = ($null -ne $doc.Bibliography) } catch { $bib.bibliographyErr = $_.Exception.Message }
8370
+ try { if ($null -ne $doc.Bibliography) { $bib.bibSourceCount = [string]$doc.Bibliography.Sources.Count } catch {} } catch { $bib.sourcesErr = $_.Exception.Message }
8371
+ try {
8372
+ $rng3 = $doc.Content; $rng3.Collapse(0)
8373
+ $f = $doc.Fields.Add($rng3, -1, "BIBLIOGRAPHY", $false)
8374
+ if ($null -eq $f) { throw "Fields.Add 返回 null" }
8375
+ $bib.bibFieldAdd = "ok"
8376
+ } catch { $bib.bibFieldErr = $_.Exception.Message }
8377
+ $out.bibliography = $bib
8378
+ } catch { $out.bibliography = @{ ok = $false; error = $_.Exception.Message } }
8379
+
8380
+ # ---- 清理:临时文档放弃保存关闭(自带收尾,红线教训)----
8381
+ try { $doc.Close(0) } catch { $out.closeErr = $_.Exception.Message }
8382
+ } catch { $out.fatal = $_.Exception.Message }
8383
+ Output-Json @{ success = $true; data = $out }
8384
+ }
8385
+
8386
+ # 【B5 引擎探针 · deckkit 第一步】BORROW-PLAN §4.3 的 COM 调用面 + 七坑真机复核(对账卡目标 A/B)。
8387
+ # 一次调用跑完全部分段(每段独立 try/catch,一段炸不影响其余),分段 JSON 原样回传——
8388
+ # 判定归决策者,探针只交证据。临时演示/文档探完即关(不保存);产物落 %TEMP%\wps-deckkit\。
8389
+ # 火力分配(任务卡):渐变(素材路线生死)最高优先;溢出可测性;行高标定;UserPicture+SaveAs32;
8390
+ # SVG;Bibliography/Fields(word 侧);七坑 #1/#2/#3/#5/#6 真机段。
8391
+ "__probeDeckkit" {
8392
+ $out = @{}
8393
+ $dir = Join-Path $env:TEMP 'wps-deckkit'
8394
+ try { New-Item -ItemType Directory -Path $dir -Force | Out-Null } catch {}
8395
+ $out.workDir = $dir
8396
+
8397
+ # ---- PPT 段宿主:优先活动演示,没有就新建临时演示(探完关闭)----
8398
+ $ppt = $null; $pres = $null; $tmpPres = $false
8399
+ try { $ppt = Get-WpsPpt } catch { $out.pptHostErr = $_.Exception.Message; $ppt = $null }
8400
+ if ($null -ne $ppt) {
8401
+ try { $pres = $ppt.ActivePresentation } catch { $pres = $null }
8402
+ if ($null -eq $pres) {
8403
+ try { $pres = $ppt.Presentations.Add(); $pres.Slides.Add(1, 2) | Out-Null; $tmpPres = $true } catch { $out.newPresErr = $_.Exception.Message; $pres = $null }
8404
+ }
8405
+ }
8406
+ if ($null -eq $pres) { $out.fatal = "no ppt host"; Output-Json @{ success = $false; error = "WPS PPT not running"; data = $out }; return }
8407
+ $slide = $null
8408
+ try { $slide = $pres.Slides.Item(1) } catch { $slide = $null }
8409
+ if ($null -eq $slide) {
8410
+ try { $slide = $pres.Slides.Add(1, 12) } catch { $out.slideErr = $_.Exception.Message }
8411
+ }
8412
+
8413
+ # ---- seg1 形状渐变填充(素材路线生死判定)----
8414
+ try {
8415
+ $g = @{}
8416
+ $sh = $slide.Shapes.AddShape(1, 10, 10, 200, 60)
8417
+ try {
8418
+ $sh.Fill.TwoColorGradient(1, 1)
8419
+ $g.twoColorGradient = "ok"
8420
+ try { $g.foreColorAfter = [string]$sh.Fill.ForeColor.RGB } catch { $g.foreErr = $_.Exception.Message }
8421
+ try { $g.backColor = [string]$sh.Fill.BackColor.RGB } catch { $g.backErr = $_.Exception.Message }
8422
+ } catch { $g.twoColorGradientErr = $_.Exception.Message }
8423
+ try { $g.gradientStops = [string]$sh.Fill.GradientStops.Count } catch { $g.stopsErr = $_.Exception.Message }
8424
+ try { $g.gradientAngle = [string]$sh.Fill.GradientAngle } catch { $g.angleErr = $_.Exception.Message }
8425
+ try { $sh.Delete() } catch {}
8426
+ $out.seg1_gradient = $g
8427
+ } catch { $out.seg1_gradient = @{ ok = $false; error = $_.Exception.Message } }
8428
+
8429
+ # ---- seg2 文本溢出可测性(BoundWidth/BoundHeight vs 框宽;WordWrap 读写)----
8430
+ try {
8431
+ $t = @{}
8432
+ $tb = $slide.Shapes.AddTextbox(1, 10, 120, 200, 60)
8433
+ try { $tb.TextFrame.WordWrap = $true; $t.wordWrapSet = "ok" } catch { $t.wordWrapErr = $_.Exception.Message }
8434
+ try { $t.wordWrapRead = [string]$tb.TextFrame.WordWrap } catch { $t.wordWrapReadErr = $_.Exception.Message }
8435
+ try { $tb.TextFrame.TextRange.Text = "探针长文本" * 30; $t.longTextSet = "ok" } catch { $t.textErr = $_.Exception.Message }
8436
+ try { $t.boundWidth = [string]$tb.TextFrame.TextRange.BoundWidth } catch { $t.bwErr = $_.Exception.Message }
8437
+ try { $t.boundHeight = [string]$tb.TextFrame.TextRange.BoundHeight } catch { $t.bhErr = $_.Exception.Message }
8438
+ try { $t.frameWidth = [string]$tb.Width } catch {}
8439
+ try { $t.overflowProperty = [string]$tb.TextFrame.Overflowing } catch { $t.overflowErr = $_.Exception.Message }
8440
+ try { $tb.Delete() } catch {}
8441
+ $out.seg2_overflow = $t
8442
+ } catch { $out.seg2_overflow = @{ ok = $false; error = $_.Exception.Message } }
8443
+
8444
+ # ---- seg3 多行文本行高标定(2 行 vs 3 行同字号,标定我们自己的行高系数)----
8445
+ try {
8446
+ $h = @{}
8447
+ $tb = $slide.Shapes.AddTextbox(1, 10, 200, 300, 200)
8448
+ try { $tb.TextFrame.TextRange.Font.Size = 24 } catch {}
8449
+ try { $tb.TextFrame.TextRange.Text = "第一行`n第二行"; $h.twoLinesBound = [string]$tb.TextFrame.TextRange.BoundHeight } catch { $h.twoErr = $_.Exception.Message }
8450
+ try { $tb.TextFrame.TextRange.Text = "第一行`n第二行`n第三行"; $h.threeLinesBound = [string]$tb.TextFrame.TextRange.BoundHeight } catch { $h.threeErr = $_.Exception.Message }
8451
+ try {
8452
+ $d2 = [double]$h.twoLinesBound; $d3 = [double]$h.threeLinesBound
8453
+ if ($d2 -gt 0 -and $d3 -gt $d2) { $h.lineHeightAt24 = [string][math]::Round($d3 - $d2, 2) }
8454
+ } catch { $h.calcErr = $_.Exception.Message }
8455
+ try { $tb.Delete() } catch {}
8456
+ $out.seg3_lineHeight = $h
8457
+ } catch { $out.seg3_lineHeight = @{ ok = $false; error = $_.Exception.Message } }
8458
+
8459
+ # ---- seg4 页底图填充 + SaveAs 第二参 32 导 PDF ----
8460
+ try {
8461
+ $u = @{}
8462
+ try { $slide.Export((Join-Path $dir 'probe-slide.png'), 'PNG', 1280, 720); $u.exportPng = (Test-Path (Join-Path $dir 'probe-slide.png')) } catch { $u.exportErr = $_.Exception.Message }
8463
+ try {
8464
+ $slide.FollowMasterBackground = $false
8465
+ $slide.Background.Fill.UserPicture((Join-Path $dir 'probe-slide.png'))
8466
+ $u.userPicture = "ok"
8467
+ } catch { $u.userPictureErr = $_.Exception.Message }
8468
+ try {
8469
+ $pdfPath = Join-Path $dir 'probe.pdf'
8470
+ $pres.SaveAs($pdfPath, 32)
8471
+ Start-Sleep -Milliseconds 400
8472
+ $u.pdfExists = (Test-Path $pdfPath)
8473
+ if ($u.pdfExists) { $u.pdfSize = (Get-Item $pdfPath).Length }
8474
+ } catch { $u.saveAsPdfErr = $_.Exception.Message }
8475
+ $out.seg4_background_pdf = $u
8476
+ } catch { $out.seg4_background_pdf = @{ ok = $false; error = $_.Exception.Message } }
8477
+
8478
+ # ---- seg5 SVG 插入兼容性 ----
8479
+ try {
8480
+ $v = @{}
8481
+ $svgPath = Join-Path $dir 'probe.svg'
8482
+ [IO.File]::WriteAllText($svgPath, '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="60"><rect width="100" height="60" fill="#336699"/></svg>')
8483
+ try {
8484
+ $pic = $slide.Shapes.AddPicture($svgPath, 0, 1, 300, 10, 100, 60)
8485
+ $v.addSvg = "ok"; $v.svgShapeType = [string]$pic.Type
8486
+ try { $pic.Delete() } catch {}
8487
+ } catch { $v.addSvgErr = $_.Exception.Message }
8488
+ $out.seg5_svg = $v
8489
+ } catch { $out.seg5_svg = @{ ok = $false; error = $_.Exception.Message } }
8490
+
8491
+ # ---- seg7 七坑真机段:#1 Adjustments / #2 Bold=False / #3 WordWrap+居中 / #5 AddTable 边框 / #6 SaveAs 校验 ----
8492
+ try {
8493
+ $s7 = @{}
8494
+ # 坑1 Adjustments.Item(1) = 赋值(PowerShell 语法实测——B3 预判:pywin32 专属坑,ps1 天然安全)
8495
+ try {
8496
+ $sh = $slide.Shapes.AddShape(1, 10, 300, 120, 80)
8497
+ try { $sh.Adjustments.Item(1) = 0.3; $s7.pit1_adjustments = "ok, value=" + [string]$sh.Adjustments.Item(1) } catch { $s7.pit1_adjustmentsErr = $_.Exception.Message }
8498
+ try { $sh.Delete() } catch {}
8499
+ # B5-T3 主线目标 B2:圆角矩(AutoShapeType=5)复测——矩形(1)写 0.3 读回 1,疑"矩形无调节点"
8500
+ try {
8501
+ $r5 = $slide.Shapes.AddShape(5, 150, 300, 120, 80)
8502
+ try { $r5.Adjustments.Item(1) = 0.3; $s7.pit1_roundRect = "ok, readback=" + [string]$r5.Adjustments.Item(1) } catch { $s7.pit1_roundRectErr = $_.Exception.Message }
8503
+ try { $r5.Delete() } catch {}
8504
+ } catch { $s7.pit1_roundErr = $_.Exception.Message }
8505
+ } catch { $s7.pit1_err = $_.Exception.Message }
8506
+ # 坑2 Bold = $false 直接赋(对方文档:抛异常)
8507
+ try {
8508
+ $tb = $slide.Shapes.AddTextbox(1, 10, 400, 200, 40)
8509
+ $tb.TextFrame.TextRange.Font.Bold = $true
8510
+ try { $tb.TextFrame.TextRange.Font.Bold = $false; $s7.pit2_boldFalse = "ok, readback=" + [string]$tb.TextFrame.TextRange.Font.Bold } catch { $s7.pit2_boldFalseErr = $_.Exception.Message }
8511
+ try { $tb.Delete() } catch {}
8512
+ } catch { $s7.pit2_err = $_.Exception.Message }
8513
+ # 坑3 WordWrap=$false + 居中 + 长文本(对方文档:文字出页)
8514
+ try {
8515
+ $tb = $slide.Shapes.AddTextbox(1, 300, 400, 150, 40)
8516
+ try { $tb.TextFrame.WordWrap = $false } catch {}
8517
+ try { $tb.TextFrame.TextRange.ParagraphFormat.Alignment = 2 } catch {}
8518
+ try { $tb.TextFrame.TextRange.Text = "这是一段故意很长的中文文本用来复现 WordWrap 关闭加居中的出页问题" } catch {}
8519
+ try { $s7.pit3_boundLeft = [string]$tb.TextFrame.TextRange.BoundLeft; $s7.pit3_boundWidth = [string]$tb.TextFrame.TextRange.BoundWidth; $s7.pit3_frameLeft = [string]$tb.Left; $s7.pit3_frameWidth = [string]$tb.Width } catch { $s7.pit3_readErr = $_.Exception.Message }
8520
+ try { $tb.Delete() } catch {}
8521
+ } catch { $s7.pit3_err = $_.Exception.Message }
8522
+ # 坑5 AddTable 边框读写(对方文档:边框 API 不稳)
8523
+ try {
8524
+ $tbl = $slide.Shapes.AddTable(2, 2, 10, 460, 300, 100)
8525
+ try {
8526
+ $c = $tbl.Table.Cell(1, 1)
8527
+ try { $c.Borders.Item(1).LineStyle = 1; $s7.pit5_lineStyleSet = "ok, readback=" + [string]$c.Borders.Item(1).LineStyle } catch { $s7.pit5_styleErr = $_.Exception.Message }
8528
+ try { $s7.pit5_bordersCount = [string]$c.Borders.Count } catch { $s7.pit5_countErr = $_.Exception.Message }
8529
+ } catch { $s7.pit5_cellErr = $_.Exception.Message }
8530
+ try { $tbl.Delete() } catch {}
8531
+ } catch { $s7.pit5_err = $_.Exception.Message }
8532
+ # 坑6 SaveAs 落盘校验(pptx:存在性 + 大小)
8533
+ try {
8534
+ $pp = Join-Path $dir 'probe-out.pptx'
8535
+ $pres.SaveAs($pp)
8536
+ Start-Sleep -Milliseconds 400
8537
+ $s7.pit6_saveAsExists = (Test-Path $pp)
8538
+ if ($s7.pit6_saveAsExists) { $s7.pit6_saveAsSize = (Get-Item $pp).Length }
8539
+ } catch { $s7.pit6_err = $_.Exception.Message }
8540
+ $out.seg7_sevenPits = $s7
8541
+ } catch { $out.seg7_sevenPits = @{ ok = $false; error = $_.Exception.Message } }
8542
+
8543
+ # ---- 清理:临时演示关闭不保存;产物目录保留(供人工复核)----
8544
+ try { if ($tmpPres -and $null -ne $pres) { $pres.Close() } } catch { $out.closeErr = $_.Exception.Message }
8545
+
8546
+ Output-Json @{ success = $true; data = $out }
8547
+ }
8548
+
8160
8549
  # 【临时诊断】查 WPS 文字的 COM 状态(进程/文档数/ActiveDocument 是否可用)
8161
8550
  "__probeDoc" {
8162
8551
  $info = @{}
@@ -8332,6 +8721,9 @@ switch ($Action) {
8332
8721
  if ($null -eq $word) { Output-Json @{ success = $false; error = "WPS Word not running" }; return }
8333
8722
  $doc = Resolve-Doc $word $p
8334
8723
  if ($null -eq $doc) { Output-Json @{ success = $false; error = "No active document" }; return }
8724
+ # 逐步撤销:整段修订处理包进一个自定义撤销记录,用户一次 Ctrl+Z 全退
8725
+ $ur = Start-AiUndoRecord $doc "处理修订"
8726
+ try {
8335
8727
  $mode = [string]$p.mode
8336
8728
  $before = 0
8337
8729
  try { $before = [int]$doc.Revisions.Count } catch {} # 吞错有据:读不到按 0 处理,走"没有修订"路径(不会误删)
@@ -8358,6 +8750,7 @@ switch ($Action) {
8358
8750
  } catch {
8359
8751
  Output-Json @{ success = $false; error = "处理修订失败: $(Get-CallError $_)" }
8360
8752
  }
8753
+ } finally { Stop-AiUndoRecord $ur }
8361
8754
  }
8362
8755
 
8363
8756
  # 列出修订(谁改的、改成什么)—— 处理之前得先看得见
@@ -8781,6 +9174,12 @@ switch ($Action) {
8781
9174
  try {
8782
9175
  $marked = 0
8783
9176
  try { $marked = [int]$doc.Indexes.MarkEntries.Count } catch {}
9177
+ # countOnly:只读计数,不插入(2026-10-30 word-audit:TS 的 op=count 查个数
9178
+ # 此前会真的在光标处插一个空索引——查询带副作用的副作用 bug)
9179
+ if ($p.countOnly) {
9180
+ Output-Json @{ success = $true; data = @{ markedEntries = $marked } }
9181
+ return
9182
+ }
8784
9183
  $rng = $word.Selection.Range
8785
9184
  $rng.Collapse(0)
8786
9185
  $ix = $doc.Indexes.Add($rng)
@@ -8850,6 +9249,88 @@ switch ($Action) {
8850
9249
  }
8851
9250
  }
8852
9251
 
9252
+ # 修订模式开关(对标 word-mcp-live 的 native tracked changes):
9253
+ # 开启后 AI 的所有写入自动带修订留痕,用户逐条审阅、可接受可拒绝。会话级状态。
9254
+ "reviewMode" {
9255
+ $word = Get-WpsWord
9256
+ if ($null -eq $word) { Output-Json @{ success = $false; error = "WPS Word not running" }; return }
9257
+ $doc = Resolve-Doc $word $p
9258
+ if ($null -eq $doc) { Output-Json @{ success = $false; error = "No active document" }; return }
9259
+ $enabled = $false
9260
+ try { $enabled = [bool]$doc.TrackRevisions } catch { }
9261
+ if ($null -ne $p.enabled) {
9262
+ $want = [bool]$p.enabled
9263
+ try {
9264
+ $doc.TrackRevisions = $want
9265
+ $enabled = $want
9266
+ } catch {
9267
+ Output-Json @{ success = $false; error = "设置修订模式失败: $(Get-CallError $_)" }
9268
+ return
9269
+ }
9270
+ }
9271
+ Output-Json @{ success = $true; data = @{ reviewMode = $enabled; doc = [string]$doc.Name } }
9272
+ }
9273
+
9274
+ # 逐步撤销(对标 per-action undo):按步撤销最近的编辑。
9275
+ # 配合 Start/Stop-AiUndoRecord 的分组,AI 的一个动作 = 用户的一次 Ctrl+Z。
9276
+ "undoSteps" {
9277
+ $word = Get-WpsWord
9278
+ if ($null -eq $word) { Output-Json @{ success = $false; error = "WPS Word not running" }; return }
9279
+ $doc = Resolve-Doc $word $p
9280
+ if ($null -eq $doc) { Output-Json @{ success = $false; error = "No active document" }; return }
9281
+ $steps = 1
9282
+ if ($null -ne $p.steps) { $steps = [Math]::Max(1, [Math]::Min(100, [int]$p.steps)) }
9283
+ $undone = 0
9284
+ try { $undone = [int]$doc.Undo($steps) } catch { Output-Json @{ success = $false; error = "撤销失败: $(Get-CallError $_)" }; return }
9285
+ Output-Json @{ success = $true; data = @{ requested = $steps; undone = $undone; doc = [string]$doc.Name } }
9286
+ }
9287
+
9288
+ # Excel 表格(ListObjects):结构化引用区,与"插入网格表格"是两种东西。
9289
+ # 探针实测(2026-10-26):ListObjects.Add 可用,真建出命名表格。
9290
+ "createExcelTable" {
9291
+ $excel = Get-WpsExcel
9292
+ if ($null -eq $excel) { Output-Json @{ success = $false; error = "WPS Excel not running" }; return }
9293
+ $ws = Resolve-Sheet $excel $p
9294
+ if ($null -eq $ws) { Output-Json @{ success = $false; error = "No active worksheet" }; return }
9295
+ $range = [string]$p.range
9296
+ if (-not $range) { Output-Json @{ success = $false; error = "[勿重试·先改参数] 缺少 range(如 A1:C10,含表头行)" }; return }
9297
+ $tableName = [string]$p.tableName
9298
+ if (-not $tableName) { $tableName = "AI表" + (Get-Date -Format "HHmmss") }
9299
+ try {
9300
+ $lo = $ws.ListObjects.Add(1, $ws.Range($range), $null, 1)
9301
+ if ($null -eq $lo) { Output-Json @{ success = $false; error = "ListObjects.Add 返回空" }; return }
9302
+ try { $lo.Name = $tableName } catch { }
9303
+ Output-Json @{ success = $true; data = @{ name = [string]$lo.Name; range = [string]$lo.Range.Address($false, $false) } }
9304
+ } catch {
9305
+ Output-Json @{ success = $false; error = "创建表格失败: $(Get-CallError $_)" }
9306
+ }
9307
+ }
9308
+
9309
+ # 切片器(SlicerCaches.Add):探针实测(2026-10-26)SlicerCaches/Slicers.Add 可用,真建出切片器。
9310
+ "addSlicer" {
9311
+ $excel = Get-WpsExcel
9312
+ if ($null -eq $excel) { Output-Json @{ success = $false; error = "WPS Excel not running" }; return }
9313
+ $ws = Resolve-Sheet $excel $p
9314
+ if ($null -eq $ws) { Output-Json @{ success = $false; error = "No active worksheet" }; return }
9315
+ $tableName = [string]$p.tableName
9316
+ $field = [string]$p.field
9317
+ if (-not $field) { Output-Json @{ success = $false; error = "[勿重试·先改参数] 缺少 field(切片器对应的列名)" }; return }
9318
+ $lo = $null
9319
+ if ($tableName) { try { $lo = $ws.ListObjects.Item($tableName) } catch { } }
9320
+ if ($null -eq $lo) { try { $lo = $ws.ListObjects.Item(1) } catch { } }
9321
+ if ($null -eq $lo) { Output-Json @{ success = $false; error = "找不到表格:传 tableName,或先 createExcelTable" }; return }
9322
+ $wb = $ws.Parent
9323
+ try {
9324
+ $sc = $wb.SlicerCaches.Add($lo, $field)
9325
+ $slicerName = [string]$p.name
9326
+ if (-not $slicerName) { $slicerName = "切片_" + $field }
9327
+ $sl = $sc.Slicers.Add($slicerName, "", $field, "", 180, 120)
9328
+ Output-Json @{ success = $true; data = @{ slicer = [string]$sl.Name; table = [string]$lo.Name; field = $field } }
9329
+ } catch {
9330
+ Output-Json @{ success = $false; error = "添加切片器失败: $(Get-CallError $_)" }
9331
+ }
9332
+ }
9333
+
8853
9334
  default {
8854
9335
  Output-Json @{ success = $false; error = "Unknown action: $Action" }
8855
9336
  }