pi-web-ui 0.110.0 → 0.112.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.
Files changed (110) hide show
  1. package/CHANGELOG.md +55 -2
  2. package/bin/frp-manager.mjs +92 -7
  3. package/dist/server/agent-formatters.js +10 -6
  4. package/dist/server/agent-service-daemon.js +27 -9
  5. package/dist/server/agent-service.js +1442 -489
  6. package/dist/server/approval-audit.js +119 -0
  7. package/dist/server/approval-default-rules.js +4 -4
  8. package/dist/server/approval-rules.js +42 -17
  9. package/dist/server/attachment-store.js +8 -8
  10. package/dist/server/attachments.js +114 -31
  11. package/dist/server/canvas/canvas-agent-tool.js +593 -0
  12. package/dist/server/canvas/canvas-cards.js +144 -0
  13. package/dist/server/canvas/canvas-dispatch.js +155 -0
  14. package/dist/server/canvas/canvas-orchestrator.js +1094 -0
  15. package/dist/server/canvas/canvas-store.js +260 -0
  16. package/dist/server/client-id-utils.js +2 -2
  17. package/dist/server/client-state.js +52 -0
  18. package/dist/server/context-budget.js +6 -3
  19. package/dist/server/delegate-mode.js +6 -3
  20. package/dist/server/delegate-task.js +18 -3
  21. package/dist/server/dispatch-domain-handlers.js +3 -0
  22. package/dist/server/dsh/dsh-agent-service.js +357 -20
  23. package/dist/server/dsh/dsh-client.js +10 -1
  24. package/dist/server/dsh/dsh-serialize.js +1 -1
  25. package/dist/server/dsh/runtime/goal-rpc.mjs +128 -3
  26. package/dist/server/dsh/runtime/launcher.mjs +59 -5
  27. package/dist/server/dsh/runtime/runtime-root.mjs +353 -40
  28. package/dist/server/durable/durable-agent-service.js +3 -0
  29. package/dist/server/durable/durable-driver.js +75 -9
  30. package/dist/server/durable/durable-loader.js +1 -14
  31. package/dist/server/durable/durable-models.js +107 -0
  32. package/dist/server/durable/index.js +0 -4
  33. package/dist/server/engine-probe.js +76 -37
  34. package/dist/server/eval-tool.js +28 -3
  35. package/dist/server/file-transfer-routes.js +8 -2
  36. package/dist/server/files-service.js +10 -2
  37. package/dist/server/goal-service.js +7 -0
  38. package/dist/server/index.js +480 -59
  39. package/dist/server/json-utils.js +57 -0
  40. package/dist/server/marker-service.js +11 -1
  41. package/dist/server/markers/marker.js +45 -4
  42. package/dist/server/markers/registry.js +31 -0
  43. package/dist/server/message-window.js +44 -8
  44. package/dist/server/model-admin.js +68 -106
  45. package/dist/server/model-resolver.js +66 -44
  46. package/dist/server/office-parse.js +394 -7
  47. package/dist/server/plan-manager.js +3 -6
  48. package/dist/server/plugin-api-catalog.js +7 -0
  49. package/dist/server/plugin-assets.js +238 -0
  50. package/dist/server/plugin-facilities.js +22 -0
  51. package/dist/server/plugin-ui-slots.js +1 -0
  52. package/dist/server/plugins.js +296 -25
  53. package/dist/server/preset-fields.js +60 -2
  54. package/dist/server/preset-share.js +8 -2
  55. package/dist/server/prompt-assembler.js +9 -2
  56. package/dist/server/prompt-composer.js +84 -44
  57. package/dist/server/protocol-version.js +1 -1
  58. package/dist/server/queue-utils.js +156 -0
  59. package/dist/server/remote-ssh-service.js +16 -4
  60. package/dist/server/sdk-builtin-extensions.js +85 -0
  61. package/dist/server/server-config.js +66 -0
  62. package/dist/server/session-parser.js +49 -13
  63. package/dist/server/session-search.js +4 -3
  64. package/dist/server/settings-service.js +56 -7
  65. package/dist/server/soft-cap.js +8 -6
  66. package/dist/server/subagent-helpers.js +22 -1
  67. package/dist/server/subagent-notify.js +93 -0
  68. package/dist/server/subagent-security-gate.js +282 -0
  69. package/dist/server/subagent-templates.js +8 -0
  70. package/dist/server/subagents.js +144 -17
  71. package/dist/server/terminals.js +196 -8
  72. package/dist/server/text-quote.js +61 -0
  73. package/dist/server/tool-approval.js +63 -4
  74. package/dist/server/tool-guards.js +208 -0
  75. package/dist/server/tool-host-factories.js +46 -10
  76. package/dist/server/tool-manager.js +30 -0
  77. package/dist/server/tool-overrides.js +21 -11
  78. package/dist/server/univer-service.js +448 -0
  79. package/dist/server/universal/driver-base.js +8 -0
  80. package/dist/server/universal/drivers/claude-code.js +39 -5
  81. package/dist/server/universal/drivers/dsh-driver.js +3 -0
  82. package/dist/server/universal/index.js +0 -1
  83. package/dist/server/universal/universal-attachments.js +5 -0
  84. package/dist/server/universal/universal-service.js +5 -0
  85. package/dist/server/universal/universal-session.js +114 -21
  86. package/dist/server/update-check.js +90 -5
  87. package/dist/server/workspace-snapshot.js +33 -2
  88. package/dist/server/worktree-service.js +189 -1
  89. package/docs/dsh-engine.md +493 -0
  90. package/package.json +5 -4
  91. package/plugin-sdk/client-utils.mjs +192 -5
  92. package/plugin-sdk/index.d.ts +80 -1
  93. package/plugin-sdk/index.mjs +99 -0
  94. package/plugin-sdk/package.json +5 -1
  95. package/plugins/catalog.json +33 -0
  96. package/themes/aetheris.css +114 -0
  97. package/themes/bases/obsidian-base.css +216 -0
  98. package/themes/md-preview.css +113 -0
  99. package/themes/wallpaper-flow.css +182 -0
  100. package/web/dist/assets/{TerminalPanel-BHjM6pzY.js → TerminalPanel-Dqr1dK28.js} +2 -2
  101. package/web/dist/assets/index-Dh8BX-lP.js +720 -0
  102. package/web/dist/assets/index-DqrC1I_a.css +1 -0
  103. package/web/dist/assets/{markdown-DXwnfD9T.js → markdown-BJZlfvdP.js} +24 -24
  104. package/web/dist/assets/markdown-DSNUiDzp.css +1 -0
  105. package/web/dist/index.html +13 -4
  106. package/web/dist/sw.js +1 -1
  107. package/web/dist/assets/es-DIDZppIF.js +0 -2
  108. package/web/dist/assets/index-DwInT7-a.css +0 -1
  109. package/web/dist/assets/index-GfVFIgIL.js +0 -693
  110. package/web/dist/assets/markdown-CCeVCbci.css +0 -1
@@ -4,15 +4,12 @@
4
4
  * 给「随处可看」用的:文件预览(files-service readFile)、附件等走 file_content
5
5
  * 下发 Markdown 文本,前端 FilePreview 按 Markdown 渲染表格/段落,无需改协议。
6
6
  *
7
- * 零依赖:docx / xlsx 本质是 zip 包,这里用 node:zlib + 手写 zip 中央目录解析
7
+ * 零依赖:docx / xlsx / pptx 本质是 zip 包,这里用 node:zlib + 手写 zip 中央目录解析
8
8
  * 做最小解包(只支持 stored / deflate,Office 写出的文件都是这两种)。
9
- *
10
- * 注意:plugins/office-preview/index.mjs 里有一份同逻辑的 JS 拷贝(插件必须
11
- * 自包含、不能 import 服务端 TS,见架构文档插件章)。两边改解析时请同步另一份。
12
9
  */
13
10
  import { inflateRawSync } from "node:zlib";
14
- const OFFICE_EXTS = new Set([".docx", ".xlsx", ".xlsm"]);
15
- /** 单个文件上限(与 office-preview 插件一致)。 */
11
+ const OFFICE_EXTS = new Set([".docx", ".xlsx", ".xlsm", ".pptx", ".pptm", ".ppsx", ".potx"]);
12
+ /** 单个文件上限(15MB)。 */
16
13
  export const OFFICE_MAX_FILE_BYTES = 15 * 1024 * 1024;
17
14
  /** 解包后总量上限(防 zip 炸弹:小包解出巨量内容)。 */
18
15
  export const OFFICE_MAX_UNCOMPRESSED_BYTES = 64 * 1024 * 1024;
@@ -111,6 +108,25 @@ export function unzipFiles(buf, wanted) {
111
108
  }
112
109
  return out;
113
110
  }
111
+ /** 列出 zip 中央目录里的全部条目名(不解压内容,快速探测)。 */
112
+ export function listZipEntries(buf) {
113
+ const eocd = findEocd(buf);
114
+ const cdCount = buf.readUInt16LE(eocd + 10);
115
+ const cdOffset = buf.readUInt32LE(eocd + 16);
116
+ const names = [];
117
+ let p = cdOffset;
118
+ for (let i = 0; i < cdCount; i++) {
119
+ if (buf.readUInt32LE(p) !== 0x02014b50)
120
+ throw new Error("zip 中央目录损坏");
121
+ const nameLen = buf.readUInt16LE(p + 28);
122
+ const extraLen = buf.readUInt16LE(p + 30);
123
+ const commentLen = buf.readUInt16LE(p + 32);
124
+ const name = buf.toString("utf8", p + 46, p + 46 + nameLen);
125
+ names.push(name);
126
+ p += 46 + nameLen + extraLen + commentLen;
127
+ }
128
+ return names;
129
+ }
114
130
  const NAMED_ENTITIES = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
115
131
  /**
116
132
  * 单轮解码命名实体与十/十六进制数字实体(一次扫描同时匹配三类)。
@@ -324,6 +340,371 @@ function colName(i) {
324
340
  } while (n >= 0);
325
341
  return s;
326
342
  }
343
+ /* ---------------- PPTX 幻灯片解析 ---------------- */
344
+ export const PPTX_MAX_SLIDES = 500;
345
+ function extractShapePlainText(spXml) {
346
+ const parts = [];
347
+ for (const m of spXml.matchAll(/<a:(t|tab|br)\b[^>]*\/?>([^<]*)(?:<\/a:t>)?/g)) {
348
+ if (m[1] === "tab")
349
+ parts.push("\t");
350
+ else if (m[1] === "br")
351
+ parts.push(" ");
352
+ else
353
+ parts.push(decodeEntities(m[2]));
354
+ }
355
+ return parts.join("").trim();
356
+ }
357
+ function extractShapeParagraphs(spXml, isBodyPlaceholder = false) {
358
+ const out = [];
359
+ for (const pMatch of spXml.matchAll(/<a:p\b[\s\S]*?<\/a:p>/g)) {
360
+ const pXml = pMatch[0];
361
+ const pPr = /<a:pPr\b([^>]*)>([\s\S]*?)<\/a:pPr>|<a:pPr\b([^>]*)\/>/.exec(pXml);
362
+ let lvl = 0;
363
+ let hasBuNone = false;
364
+ let hasBuChar = false;
365
+ let hasBuAutoNum = false;
366
+ if (pPr) {
367
+ const attrs = pPr[1] ?? pPr[3] ?? "";
368
+ const inner = pPr[2] ?? "";
369
+ const lvlMatch = /\blvl=["'](\d+)["']/.exec(attrs);
370
+ if (lvlMatch)
371
+ lvl = Number(lvlMatch[1]);
372
+ hasBuNone = /<a:buNone\b/.test(inner);
373
+ hasBuChar = /<a:buChar\b/.test(inner);
374
+ hasBuAutoNum = /<a:buAutoNum\b/.test(inner);
375
+ }
376
+ const isBullet = !hasBuNone && (hasBuChar || hasBuAutoNum || lvl > 0 || isBodyPlaceholder);
377
+ let text = "";
378
+ for (const m of pXml.matchAll(/<a:(t|tab|br)\b[^>]*\/?>([^<]*)(?:<\/a:t>)?/g)) {
379
+ if (m[1] === "tab")
380
+ text += "\t";
381
+ else if (m[1] === "br")
382
+ text += "\n";
383
+ else
384
+ text += decodeEntities(m[2]);
385
+ }
386
+ text = text.trim();
387
+ if (text) {
388
+ out.push({ text, lvl, isBullet });
389
+ }
390
+ }
391
+ return out;
392
+ }
393
+ function parseTable(tblXml) {
394
+ const rows = [];
395
+ for (const trMatch of tblXml.matchAll(/<a:tr\b[^>]*>([\s\S]*?)<\/a:tr>/g)) {
396
+ const rowXml = trMatch[1];
397
+ const row = [];
398
+ for (const tcMatch of rowXml.matchAll(/<a:tc\b[^>]*>([\s\S]*?)<\/a:tc>/g)) {
399
+ const cellXml = tcMatch[1];
400
+ const cellText = [];
401
+ for (const m of cellXml.matchAll(/<a:(t|tab|br)\b[^>]*\/?>([^<]*)(?:<\/a:t>)?/g)) {
402
+ if (m[1] === "tab")
403
+ cellText.push("\t");
404
+ else if (m[1] === "br")
405
+ cellText.push(" ");
406
+ else
407
+ cellText.push(decodeEntities(m[2]));
408
+ }
409
+ row.push(cellText.join("").trim());
410
+ }
411
+ if (row.length > 0)
412
+ rows.push(row);
413
+ }
414
+ return rows;
415
+ }
416
+ function tableToMarkdown(rows) {
417
+ if (rows.length === 0)
418
+ return "";
419
+ const colCount = Math.max(...rows.map((r) => r.length));
420
+ if (colCount === 0)
421
+ return "";
422
+ const pad = (r) => {
423
+ const row = r.slice(0, colCount);
424
+ while (row.length < colCount)
425
+ row.push("");
426
+ return row;
427
+ };
428
+ const headerRow = pad(rows[0]);
429
+ const separatorRow = Array(colCount).fill("---");
430
+ const dataRows = rows.slice(1).map(pad);
431
+ const lines = [headerRow, separatorRow, ...dataRows].map((r) => `| ${r.map(mdCell).join(" | ")} |`);
432
+ return lines.join("\n");
433
+ }
434
+ function slideToMarkdown(slide) {
435
+ const titlePart = slide.title ? `:${slide.title}` : "";
436
+ const head = `## 幻灯片 ${slide.index}${titlePart}`;
437
+ const bodyParts = [];
438
+ if (slide.subtitle) {
439
+ bodyParts.push(`*${slide.subtitle}*`);
440
+ }
441
+ if (slide.images && slide.images.length > 0) {
442
+ for (const img of slide.images) {
443
+ bodyParts.push(`🖼️ **图片**:${img.descr || img.media}`);
444
+ }
445
+ }
446
+ if (slide.paragraphs.length > 0) {
447
+ bodyParts.push(slide.paragraphs.join("\n"));
448
+ }
449
+ if (slide.tables && slide.tables.length > 0) {
450
+ for (const tbl of slide.tables) {
451
+ const mdTbl = tableToMarkdown(tbl);
452
+ if (mdTbl)
453
+ bodyParts.push(mdTbl);
454
+ }
455
+ }
456
+ if (slide.notes) {
457
+ bodyParts.push(`> 💡 **备注**:${slide.notes}`);
458
+ }
459
+ if (bodyParts.length === 0) {
460
+ return `${head}\n\n(空幻灯片)`;
461
+ }
462
+ return `${head}\n\n${bodyParts.join("\n\n")}`;
463
+ }
464
+ /** pptx/pptm/ppsx/potx → 幻灯片数组。 */
465
+ export function parsePptxSlides(buf) {
466
+ const allEntries = new Set(listZipEntries(buf));
467
+ const probeTargets = ["ppt/presentation.xml", "ppt/_rels/presentation.xml.rels"].filter((n) => allEntries.has(n));
468
+ const probe = unzipFiles(buf, probeTargets);
469
+ const presXml = probe.get("ppt/presentation.xml")?.toString("utf8") ?? "";
470
+ const relsXml = probe.get("ppt/_rels/presentation.xml.rels")?.toString("utf8") ?? "";
471
+ const relTarget = new Map();
472
+ for (const m of relsXml.matchAll(/<Relationship\b[^>]*>/gi)) {
473
+ const id = /\bId=["']([^"']+)["']/i.exec(m[0])?.[1];
474
+ const target = /\bTarget=["']([^"']+)["']/i.exec(m[0])?.[1];
475
+ if (id && target) {
476
+ const clean = target
477
+ .replace(/\\/g, "/")
478
+ .replace(/^\/+/, "")
479
+ .replace(/^ppt\//, "");
480
+ relTarget.set(id, clean);
481
+ }
482
+ }
483
+ const slideRids = [];
484
+ for (const m of presXml.matchAll(/<[a-zA-Z0-9:]*sldId\b[^>]*\br:id=["']([^"']+)["']/gi)) {
485
+ slideRids.push(m[1]);
486
+ }
487
+ let slideTargets = slideRids
488
+ .map((rid) => relTarget.get(rid))
489
+ .filter((t) => Boolean(t))
490
+ .map((t) => (t.startsWith("ppt/") ? t : `ppt/${t}`));
491
+ // Fallback 1: presentation.xml.rels 中声明的 slide 关系
492
+ if (slideTargets.length === 0) {
493
+ for (const m of relsXml.matchAll(/<Relationship\b[^>]*>/gi)) {
494
+ const type = /\bType=["']([^"']+)["']/i.exec(m[0])?.[1] ?? "";
495
+ const target = /\bTarget=["']([^"']+)["']/i.exec(m[0])?.[1] ?? "";
496
+ if (type.endsWith("/slide") || target.includes("slides/slide")) {
497
+ const clean = target
498
+ .replace(/\\/g, "/")
499
+ .replace(/^\/+/, "")
500
+ .replace(/^ppt\//, "");
501
+ slideTargets.push(clean.startsWith("ppt/") ? clean : `ppt/${clean}`);
502
+ }
503
+ }
504
+ slideTargets.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
505
+ }
506
+ // Fallback 2: 中央目录扫描 ppt/slides/slideN.xml
507
+ if (slideTargets.length === 0) {
508
+ slideTargets = Array.from(allEntries)
509
+ .filter((name) => /^ppt\/slides\/slide\d+\.xml$/i.test(name))
510
+ .sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
511
+ }
512
+ if (slideTargets.length === 0) {
513
+ throw new Error("PPTX 文件中未找到幻灯片内容");
514
+ }
515
+ const cappedSlideTargets = slideTargets.slice(0, PPTX_MAX_SLIDES);
516
+ // 扫描各幻灯片的 .rels 关系(查找图片与演讲者备注)
517
+ const slideRelsMap = new Map();
518
+ const slideToNotes = new Map();
519
+ const slideRelsToFetch = [];
520
+ for (const st of cappedSlideTargets) {
521
+ const base = st.split("/").pop();
522
+ const relsName = `ppt/slides/_rels/${base}.rels`;
523
+ if (allEntries.has(relsName))
524
+ slideRelsToFetch.push(relsName);
525
+ }
526
+ if (slideRelsToFetch.length > 0) {
527
+ const slideRelsData = unzipFiles(buf, slideRelsToFetch);
528
+ for (const [relsPath, relsBuf] of slideRelsData) {
529
+ const xml = relsBuf.toString("utf8");
530
+ const rMap = new Map();
531
+ const base = relsPath
532
+ .split("/")
533
+ .pop()
534
+ ?.replace(/\.rels$/, "");
535
+ const slideTarget = cappedSlideTargets.find((st) => st.endsWith(`/${base}`));
536
+ for (const m of xml.matchAll(/<Relationship\b[^>]*>/gi)) {
537
+ const id = /\bId=["']([^"']+)["']/i.exec(m[0])?.[1];
538
+ const target = /\bTarget=["']([^"']+)["']/i.exec(m[0])?.[1];
539
+ const type = /\bType=["']([^"']+)["']/i.exec(m[0])?.[1] ?? "";
540
+ if (id && target) {
541
+ rMap.set(id, target);
542
+ }
543
+ if ((type.endsWith("/notesSlide") || target?.includes("notesSlide")) && target && slideTarget) {
544
+ const clean = target
545
+ .replace(/\\/g, "/")
546
+ .replace(/^\.\.\//, "")
547
+ .replace(/^ppt\//, "");
548
+ const fullNotesPath = clean.startsWith("ppt/") ? clean : `ppt/${clean}`;
549
+ if (allEntries.has(fullNotesPath)) {
550
+ slideToNotes.set(slideTarget, fullNotesPath);
551
+ }
552
+ }
553
+ }
554
+ if (slideTarget)
555
+ slideRelsMap.set(slideTarget, rMap);
556
+ }
557
+ }
558
+ const filesToUnzip = [...cappedSlideTargets, ...Array.from(new Set(slideToNotes.values()))];
559
+ const unzipped = unzipFiles(buf, filesToUnzip);
560
+ const slides = [];
561
+ for (let i = 0; i < cappedSlideTargets.length; i++) {
562
+ const target = cappedSlideTargets[i];
563
+ const slideXml = unzipped.get(target)?.toString("utf8") ?? "";
564
+ if (!slideXml)
565
+ continue;
566
+ if (slideXml.length > DOCX_MAX_XML_BYTES) {
567
+ throw new Error(`幻灯片内容过大(解压后 ${(slideXml.length / 1048576).toFixed(1)} MB,上限 20 MB),拒绝预览`);
568
+ }
569
+ let title = "";
570
+ let titleShapeXml = null;
571
+ let subtitle;
572
+ // 查找标题与副标题占位符
573
+ for (const spMatch of slideXml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>/g)) {
574
+ const sp = spMatch[0];
575
+ if (!title && /<p:ph\b[^>]*\btype=["'](?:title|ctrTitle)["']/i.test(sp)) {
576
+ const text = extractShapePlainText(sp);
577
+ if (text) {
578
+ title = text;
579
+ titleShapeXml = sp;
580
+ }
581
+ }
582
+ else if (!subtitle && /<p:ph\b[^>]*\btype=["']subTitle["']/i.test(sp)) {
583
+ const text = extractShapePlainText(sp);
584
+ if (text) {
585
+ subtitle = text;
586
+ }
587
+ }
588
+ }
589
+ if (!title) {
590
+ for (const spMatch of slideXml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>/g)) {
591
+ const sp = spMatch[0];
592
+ const isTitle = /<p:ph\b(?![^>]*type=)(?:[^>]*idx=["']0["'])?/i.test(sp) ||
593
+ /<p:cNvPr\b[^>]*name=["'][^"']*(?:Title|标题)/i.test(sp);
594
+ if (isTitle) {
595
+ const text = extractShapePlainText(sp);
596
+ if (text && text.length <= 120) {
597
+ title = text;
598
+ titleShapeXml = sp;
599
+ break;
600
+ }
601
+ }
602
+ }
603
+ }
604
+ if (!title) {
605
+ for (const spMatch of slideXml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>/g)) {
606
+ const sp = spMatch[0];
607
+ if (/<p:ph\b[^>]*type=["'](?:sldNum|dt|ftr)["']/i.test(sp))
608
+ continue;
609
+ const paras = extractShapeParagraphs(sp);
610
+ if (paras.length === 1 && paras[0].text.length <= 60 && !paras[0].isBullet) {
611
+ title = paras[0].text;
612
+ titleShapeXml = sp;
613
+ break;
614
+ }
615
+ if (paras.length > 0)
616
+ break;
617
+ }
618
+ }
619
+ const paragraphs = [];
620
+ const tables = [];
621
+ const images = [];
622
+ const rMap = slideRelsMap.get(target);
623
+ // 提取图片(<p:pic>)
624
+ for (const picMatch of slideXml.matchAll(/<p:pic\b[\s\S]*?<\/p:pic>/gi)) {
625
+ const pic = picMatch[0];
626
+ const rEmbed = /<a:blip\b[^>]*r:embed=["']([^"']+)["']/i.exec(pic)?.[1];
627
+ const imgTarget = rEmbed && rMap ? rMap.get(rEmbed) : null;
628
+ if (imgTarget) {
629
+ const media = imgTarget.replace(/\\/g, "/").split("/").pop() ?? "";
630
+ if (media && /^image\d+\./i.test(media)) {
631
+ const descr = /<p:cNvPr\b[^>]*descr=["']([^"']*)["']/i.exec(pic)?.[1] ||
632
+ /<p:cNvPr\b[^>]*name=["']([^"']*)["']/i.exec(pic)?.[1];
633
+ images.push({ media, descr: descr?.trim() || undefined });
634
+ }
635
+ }
636
+ }
637
+ // 提取背景色
638
+ let bg;
639
+ const bgPrMatch = /<p:bgPr\b[\s\S]*?<a:srgbClr\b[^>]*val=["']([0-9a-fA-F]{6})["']/i.exec(slideXml);
640
+ if (bgPrMatch) {
641
+ bg = `#${bgPrMatch[1]}`;
642
+ }
643
+ else {
644
+ const fullSp = /<p:sp\b[\s\S]*?<a:ext\b[^>]*cx=["'](?:12\d{6}|9\d{6})["'][\s\S]*?<a:srgbClr\b[^>]*val=["']([0-9a-fA-F]{6})["']/i.exec(slideXml);
645
+ if (fullSp) {
646
+ bg = `#${fullSp[1]}`;
647
+ }
648
+ }
649
+ for (const elemMatch of slideXml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>|<a:tbl\b[\s\S]*?<\/a:tbl>/g)) {
650
+ const elem = elemMatch[0];
651
+ if (elem.startsWith("<p:sp")) {
652
+ if (elem === titleShapeXml)
653
+ continue;
654
+ if (/<p:ph\b[^>]*type=["'](?:sldNum|dt|ftr)["']/i.test(elem))
655
+ continue;
656
+ const isBodyPlaceholder = /<p:ph\b[^>]*type=["']body["']/i.test(elem);
657
+ const paras = extractShapeParagraphs(elem, isBodyPlaceholder);
658
+ for (const p of paras) {
659
+ if (p.isBullet) {
660
+ const clean = p.text.replace(/^[\s•·\-*]+\s*/, "");
661
+ paragraphs.push(`${" ".repeat(p.lvl)}- ${clean}`);
662
+ }
663
+ else {
664
+ paragraphs.push(p.text);
665
+ }
666
+ }
667
+ }
668
+ else if (elem.startsWith("<a:tbl")) {
669
+ const tbl = parseTable(elem);
670
+ if (tbl.length > 0)
671
+ tables.push(tbl);
672
+ }
673
+ }
674
+ let notes;
675
+ const notesPath = slideToNotes.get(target);
676
+ if (notesPath) {
677
+ const notesXml = unzipped.get(notesPath)?.toString("utf8");
678
+ if (notesXml) {
679
+ for (const spMatch of notesXml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>/g)) {
680
+ const sp = spMatch[0];
681
+ if (/<p:ph\b[^>]*type=["']body["']/i.test(sp)) {
682
+ const paras = extractShapeParagraphs(sp, false);
683
+ const noteText = paras
684
+ .map((p) => p.text)
685
+ .join("\n")
686
+ .trim();
687
+ if (noteText) {
688
+ notes = noteText;
689
+ break;
690
+ }
691
+ }
692
+ }
693
+ }
694
+ }
695
+ slides.push({
696
+ index: i + 1,
697
+ title,
698
+ subtitle,
699
+ paragraphs,
700
+ tables: tables.length > 0 ? tables : undefined,
701
+ images: images.length > 0 ? images : undefined,
702
+ notes,
703
+ bg,
704
+ });
705
+ }
706
+ return slides;
707
+ }
327
708
  /**
328
709
  * 表头固定用 A/B/C…(与 Excel 列标一致),而不拿第一行数据冒充表头——
329
710
  * 很多表的第一行是通知/标题文字,染成紫色表头又怪又误导。
@@ -359,11 +740,17 @@ export function extractOfficeText(filename, buf) {
359
740
  }
360
741
  let text;
361
742
  let truncated = false;
743
+ let slides;
362
744
  if (ext === ".docx") {
363
745
  const paras = parseDocxParagraphs(buf);
364
746
  text = paras.join("\n");
365
747
  truncated = text.length > OFFICE_MAX_TEXT_CHARS;
366
748
  }
749
+ else if (ext === ".pptx" || ext === ".pptm" || ext === ".ppsx" || ext === ".potx") {
750
+ slides = parsePptxSlides(buf);
751
+ text = slides.map(slideToMarkdown).join("\n\n---\n\n");
752
+ truncated = text.length > OFFICE_MAX_TEXT_CHARS || slides.length >= PPTX_MAX_SLIDES;
753
+ }
367
754
  else {
368
755
  const sheets = parseXlsxSheets(buf);
369
756
  text = sheets.map(sheetToMarkdown).join("\n\n");
@@ -371,5 +758,5 @@ export function extractOfficeText(filename, buf) {
371
758
  }
372
759
  if (text.length > OFFICE_MAX_TEXT_CHARS)
373
760
  text = text.slice(0, OFFICE_MAX_TEXT_CHARS);
374
- return { text, truncated };
761
+ return { text, truncated, slides };
375
762
  }
@@ -17,8 +17,8 @@
17
17
  * - 运行时缓存(plansByConv):以会话槽位 conversationId 为主键,仅存活于进程内存,绝不落盘。
18
18
  * - 历史文件清洗:严格过滤形如 /^c\d+$/ 的易变短 ID,防止服务重启后新会话被上一个会话的任务附体。
19
19
  */
20
- import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
21
- import { dirname } from "node:path";
20
+ import { readFileSync } from "node:fs";
21
+ import { writeJsonAtomicSync } from "./atomic-file.js";
22
22
  const VALID_STATUSES = new Set(["pending", "in_progress", "done", "failed"]);
23
23
  /** 判断是否为易变的临时 conversationId(如 c1, c2, c99 等)。此类短 ID 绝不入持久化文件。 */
24
24
  function isEphemeralConvId(id) {
@@ -61,7 +61,6 @@ export class PlanManager {
61
61
  if (!this.filePath)
62
62
  return;
63
63
  try {
64
- mkdirSync(dirname(this.filePath), { recursive: true });
65
64
  const obj = {};
66
65
  for (const [k, v] of this.plansBySession.entries()) {
67
66
  // 双重防护:临时 conversationId 绝不落盘
@@ -69,9 +68,7 @@ export class PlanManager {
69
68
  continue;
70
69
  obj[k] = v;
71
70
  }
72
- const tmp = `${this.filePath}.tmp.${Date.now()}`;
73
- writeFileSync(tmp, JSON.stringify(obj, null, 2), "utf8");
74
- renameSync(tmp, this.filePath);
71
+ writeJsonAtomicSync(this.filePath, obj);
75
72
  }
76
73
  catch {
77
74
  // 持久化失败绝不阻断主流程
@@ -14,6 +14,7 @@ export const SLOT_EXAMPLES = {
14
14
  "contextmenu.project": `{ "ui": { "contextmenu.project": [{ "id": "m", "label": "项目菜单", "kind": "action", "action": "my:m" }] } }`,
15
15
  "contextmenu.file": `{ "contextmenu.file": [{ "id": "mail", "label": "发到邮箱", "kind": "action", "action": "my:send" }] }`,
16
16
  "contextmenu.toolcall": `{ "ui": { "contextmenu.toolcall": [{ "id": "m", "label": "工具菜单", "kind": "action", "action": "my:m" }] } }`,
17
+ "tool.card.footer": `{ "ui": { "tool.card.footer": [{ "id": "m", "label": "工具卡底部", "kind": "action", "action": "my:m" }] } }`,
17
18
  "settings.pages": `{ "settings": [{ "id": "conf", "label": "邮箱设置", "kind": "page" }] }`,
18
19
  "tasks.panel": `{ "ui": { "tasks.panel": [{ "id": "pm2", "label": "pm2 托管的应用", "kind": "view" }] } }`,
19
20
  "leftpanel.projects.actions": `{ "ui": { "leftpanel.projects.actions": [{ "id": "m", "label": "项目标题按钮", "kind": "action", "action": "my:m" }] } }`,
@@ -92,6 +93,12 @@ export const HOST_METHODS = [
92
93
  summary: "给 AI 注册工具(插件给模型加能力,与 AI 写插件方向相反)",
93
94
  example: `host.registerAgentTool({ name: "mail", description: "…", execute: async () => ({}) })`,
94
95
  },
96
+ {
97
+ name: "registerMarker",
98
+ needs: "tools",
99
+ summary: "注册内联状态标记(如 [[name:op:...]];模型直接输出触发副作用,正文自动剥离)",
100
+ example: `host.registerMarker({ name: "flag", guidance: ["[[flag:mark:<id>]] mark item"], apply: (token, ctx) => ({ applied: true }) })`,
101
+ },
95
102
  {
96
103
  name: "onToolPre",
97
104
  needs: "tools",