dal-code 1.0.0 → 1.0.8

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 (166) hide show
  1. package/CHANGELOG.md +73 -1
  2. package/dist/core/auth-guidance.d.ts +1 -0
  3. package/dist/core/auth-guidance.d.ts.map +1 -1
  4. package/dist/core/auth-guidance.js +6 -0
  5. package/dist/core/auth-guidance.js.map +1 -1
  6. package/dist/core/compaction/compaction.d.ts.map +1 -1
  7. package/dist/core/compaction/compaction.js +4 -7
  8. package/dist/core/compaction/compaction.js.map +1 -1
  9. package/dist/core/extensions/index.d.ts +1 -1
  10. package/dist/core/extensions/index.d.ts.map +1 -1
  11. package/dist/core/extensions/index.js.map +1 -1
  12. package/dist/core/extensions/loader.d.ts.map +1 -1
  13. package/dist/core/extensions/loader.js +13 -1
  14. package/dist/core/extensions/loader.js.map +1 -1
  15. package/dist/core/extensions/runner.d.ts.map +1 -1
  16. package/dist/core/extensions/runner.js +47 -48
  17. package/dist/core/extensions/runner.js.map +1 -1
  18. package/dist/core/extensions/types.d.ts +46 -43
  19. package/dist/core/extensions/types.d.ts.map +1 -1
  20. package/dist/core/extensions/types.js.map +1 -1
  21. package/dist/core/keybindings.d.ts +10 -0
  22. package/dist/core/keybindings.d.ts.map +1 -1
  23. package/dist/core/keybindings.js +13 -0
  24. package/dist/core/keybindings.js.map +1 -1
  25. package/dist/core/tools/bash.d.ts +3 -1
  26. package/dist/core/tools/bash.d.ts.map +1 -1
  27. package/dist/core/tools/bash.js +61 -8
  28. package/dist/core/tools/bash.js.map +1 -1
  29. package/dist/core/tools/renderers/bash.d.ts.map +1 -1
  30. package/dist/core/tools/renderers/bash.js +43 -6
  31. package/dist/core/tools/renderers/bash.js.map +1 -1
  32. package/dist/dal/builtins.d.ts.map +1 -1
  33. package/dist/dal/builtins.js +1 -0
  34. package/dist/dal/builtins.js.map +1 -1
  35. package/dist/index.d.ts +1 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/main.d.ts.map +1 -1
  39. package/dist/main.js +6 -0
  40. package/dist/main.js.map +1 -1
  41. package/dist/modes/interactive/components/assistant-message.d.ts +12 -0
  42. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  43. package/dist/modes/interactive/components/assistant-message.js +22 -1
  44. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  45. package/dist/modes/interactive/components/footer.d.ts +2 -0
  46. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  47. package/dist/modes/interactive/components/footer.js +24 -7
  48. package/dist/modes/interactive/components/footer.js.map +1 -1
  49. package/dist/modes/interactive/components/tool-execution.d.ts +39 -2
  50. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  51. package/dist/modes/interactive/components/tool-execution.js +200 -29
  52. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  53. package/dist/modes/interactive/interactive-mode.d.ts +35 -0
  54. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  55. package/dist/modes/interactive/interactive-mode.js +177 -23
  56. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  57. package/dist/modes/interactive/theme/dark.json +1 -1
  58. package/dist/modes/interactive/theme/light.json +1 -1
  59. package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
  60. package/dist/modes/interactive/tui-renderer.js +2 -2
  61. package/dist/modes/interactive/tui-renderer.js.map +1 -1
  62. package/dist/node_modules/@dalcode/dal-bridge/package.json +3 -3
  63. package/dist/node_modules/@dalcode/dal-gateway/package.json +3 -3
  64. package/dist/node_modules/@dalcode/dal-guard/package.json +5 -5
  65. package/dist/node_modules/@dalcode/dal-halo/package.json +2 -2
  66. package/dist/node_modules/@dalcode/dal-lang/package.json +4 -4
  67. package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
  68. package/dist/node_modules/@dalcode/dal-mcp/package.json +9 -6
  69. package/dist/node_modules/@dalcode/dal-mcp/src/add-wizard.ts +142 -0
  70. package/dist/node_modules/@dalcode/dal-mcp/src/command-parser.ts +218 -0
  71. package/dist/node_modules/@dalcode/dal-mcp/src/config-edit.ts +99 -0
  72. package/dist/node_modules/@dalcode/dal-mcp/src/index.ts +161 -18
  73. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.ts +8 -3
  74. package/dist/node_modules/@dalcode/dal-office/LICENSE +21 -0
  75. package/dist/node_modules/@dalcode/dal-office/package.json +37 -0
  76. package/dist/node_modules/@dalcode/dal-office/src/extract/csv.ts +84 -0
  77. package/dist/node_modules/@dalcode/dal-office/src/extract/index.ts +111 -0
  78. package/dist/node_modules/@dalcode/dal-office/src/extract/ooxml.ts +109 -0
  79. package/dist/node_modules/@dalcode/dal-office/src/extract/pdf.ts +43 -0
  80. package/dist/node_modules/@dalcode/dal-office/src/index.ts +43 -0
  81. package/dist/node_modules/@dalcode/dal-office/src/paths.ts +107 -0
  82. package/dist/node_modules/@dalcode/dal-office/src/render/chart.ts +111 -0
  83. package/dist/node_modules/@dalcode/dal-office/src/render/docx.ts +155 -0
  84. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.ts +386 -0
  85. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.ts +99 -0
  86. package/dist/node_modules/@dalcode/dal-office/src/scenes.ts +197 -0
  87. package/dist/node_modules/@dalcode/dal-office/src/scratchpad.ts +49 -0
  88. package/dist/node_modules/@dalcode/dal-office/src/themes.ts +240 -0
  89. package/dist/node_modules/@dalcode/dal-office/src/tools/chart-generate.ts +122 -0
  90. package/dist/node_modules/@dalcode/dal-office/src/tools/doc-generate.ts +123 -0
  91. package/dist/node_modules/@dalcode/dal-office/src/tools/drawio-generate.ts +99 -0
  92. package/dist/node_modules/@dalcode/dal-office/src/tools/md-generate.ts +76 -0
  93. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.ts +106 -0
  94. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.ts +91 -0
  95. package/dist/node_modules/@dalcode/dal-office/src/tools/read-file.ts +71 -0
  96. package/dist/node_modules/@dalcode/dal-office/src/tools/shared.ts +54 -0
  97. package/dist/node_modules/@dalcode/dal-office/src/tools/sheet-generate.ts +101 -0
  98. package/dist/node_modules/@dalcode/dal-office/src/truncate.ts +27 -0
  99. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.d.ts.map +1 -1
  100. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +233 -1
  101. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js.map +1 -1
  102. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  103. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.ts +322 -1
  104. package/dist/node_modules/@dalcode/dal-skills/package.json +4 -4
  105. package/dist/node_modules/@dalcode/dal-skills/src/discover.ts +101 -0
  106. package/dist/node_modules/@dalcode/dal-skills/src/index.ts +71 -9
  107. package/dist/node_modules/@dalcode/dal-skills/src/install.ts +140 -0
  108. package/dist/node_modules/@dalcode/dal-skills/src/manage.ts +446 -0
  109. package/dist/node_modules/@dalcode/dal-skills/src/packages.ts +39 -1
  110. package/dist/node_modules/@dalcode/dal-subagent/package.json +6 -6
  111. package/dist/node_modules/@dalcode/dal-subagent/src/index.ts +46 -4
  112. package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
  113. package/dist/node_modules/@dalcode/deepailab/package.json +4 -4
  114. package/dist/node_modules/@dalcode/deepailab/src/index.ts +7 -1
  115. package/dist/node_modules/@dalcode/deepailab/src/model-defaults.ts +42 -6
  116. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  117. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  118. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  119. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  120. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  121. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
  122. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
  123. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  124. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  125. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  126. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  127. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  128. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  129. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
  130. package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
  131. package/dist/node_modules/@earendil-works/pi-client/package.json +2 -2
  132. package/dist/node_modules/@earendil-works/pi-protocol/package.json +1 -1
  133. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  134. package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts.map +1 -1
  135. package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +3 -1
  136. package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js.map +1 -1
  137. package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts.map +1 -1
  138. package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js +3 -1
  139. package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js.map +1 -1
  140. package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts.map +1 -1
  141. package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js +23 -22
  142. package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js.map +1 -1
  143. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +4 -3
  144. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts.map +1 -1
  145. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +4 -2
  146. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js.map +1 -1
  147. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  148. package/dist/utils/changelog.d.ts +37 -4
  149. package/dist/utils/changelog.d.ts.map +1 -1
  150. package/dist/utils/changelog.js +80 -17
  151. package/dist/utils/changelog.js.map +1 -1
  152. package/dist/utils/clipboard.d.ts.map +1 -1
  153. package/dist/utils/clipboard.js +13 -1
  154. package/dist/utils/clipboard.js.map +1 -1
  155. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  156. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  157. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  158. package/examples/extensions/gondolin/package-lock.json +2 -2
  159. package/examples/extensions/gondolin/package.json +1 -1
  160. package/examples/extensions/sandbox/package-lock.json +2 -2
  161. package/examples/extensions/sandbox/package.json +1 -1
  162. package/examples/extensions/with-deps/package-lock.json +2 -2
  163. package/examples/extensions/with-deps/package.json +1 -1
  164. package/examples/plugins/pi-example-plugin/package.json +1 -1
  165. package/npm-shrinkwrap.json +1511 -25
  166. package/package.json +8 -2
@@ -0,0 +1,76 @@
1
+ /**
2
+ * office_md_generate — Markdown document writer.
3
+ *
4
+ * The model drafts the full document as the `content` parameter; the tool
5
+ * only validates, sanitizes the filename and writes the .md file. Style
6
+ * guidance lives in promptGuidelines, not in code.
7
+ */
8
+
9
+ import { writeFileSync } from "node:fs";
10
+ import { t } from "@dalcode/dal-pi-kit";
11
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
12
+ import { Type } from "typebox";
13
+ import { resolveOutputPath } from "../paths.ts";
14
+ import { inferMarkdownScene } from "../scenes.ts";
15
+ import { displayPath, formatTemplate, type OfficeToolDetails, officeFailure, officeResult } from "./shared.ts";
16
+
17
+ const mdGenerateSchema = Type.Object({
18
+ title: Type.String({ description: t("文档标题(同时用作文件名)") }),
19
+ style: Type.Optional(
20
+ Type.Union(
21
+ [
22
+ Type.Literal("knowledge_base"),
23
+ Type.Literal("readme"),
24
+ Type.Literal("guide"),
25
+ Type.Literal("notes"),
26
+ Type.Literal("research"),
27
+ ],
28
+ { description: t("文档风格:knowledge_base 知识库 / readme / guide 指南 / notes 纪要 / research 调研") },
29
+ ),
30
+ ),
31
+ audience: Type.Optional(Type.String({ description: t("目标读者(可选),写入场景判断") })),
32
+ content: Type.String({ description: t("完整 Markdown 正文(不是提纲),从一级标题开始") }),
33
+ path: Type.Optional(Type.String({ description: t("输出文件路径(可选,相对当前目录,默认写入 office-outputs/)") })),
34
+ });
35
+
36
+ export function registerMdGenerate(pi: ExtensionAPI): void {
37
+ pi.registerTool<typeof mdGenerateSchema, OfficeToolDetails>({
38
+ name: "office_md_generate",
39
+ label: t("生成 Markdown 文档"),
40
+ description: t(
41
+ "生成 Markdown 文档(.md):适合知识库、README、说明文档、会议纪要、调研整理、操作手册等纯文本结构化内容。",
42
+ ),
43
+ promptSnippet: t("office_md_generate - 生成 Markdown 文档(README/知识库/纪要/调研/操作手册)"),
44
+ promptGuidelines: [
45
+ t(
46
+ "Markdown/README/知识库/说明文档/会议纪要/调研整理类需求用本工具,content 必须是完整正文:结构清楚、示例充分,便于阅读与沉淀。当用户说「先写提示词 / 出提示词 / 帮我构思」时属于文本输出意图:直接回复文本或用本工具产出提示词文档。",
47
+ ),
48
+ ],
49
+ parameters: mdGenerateSchema,
50
+ execute: async (_toolCallId, params, _signal, _onUpdate, ctx) => {
51
+ const title = params.title.trim();
52
+ if (title.length === 0) {
53
+ return officeFailure(t("title 不能为空"), "md");
54
+ }
55
+ if (params.content.trim().length === 0) {
56
+ return officeFailure(t("content 不能为空"), "md");
57
+ }
58
+ const scene = inferMarkdownScene(`${title} ${params.audience ?? ""}`);
59
+ let target: string;
60
+ try {
61
+ target = resolveOutputPath(ctx.cwd, params.path, title, "md");
62
+ } catch (error) {
63
+ return officeFailure(error instanceof Error ? error.message : String(error), "md");
64
+ }
65
+ writeFileSync(target, params.content, "utf8");
66
+
67
+ const text = formatTemplate(t("已生成 Markdown 文档《{title}》({chars} 字)。\n文件:{file}\n{scene}"), {
68
+ title,
69
+ chars: params.content.length,
70
+ file: displayPath(ctx.cwd, target),
71
+ scene,
72
+ });
73
+ return officeResult(text, { ok: true, kind: "md", file: displayPath(ctx.cwd, target) });
74
+ },
75
+ });
76
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * office_ppt_generate — second step of the two-step PPT pipeline.
3
+ *
4
+ * Slide plan sources, in priority order: the outline office_ppt_plan stored
5
+ * in the session scratchpad, slides passed inline in the parameters, or a
6
+ * minimal three-slide fallback. Rendering is deterministic (themes.ts +
7
+ * render/pptx.ts); this tool only picks the plan, renders, and writes the
8
+ * .pptx under the session cwd.
9
+ */
10
+
11
+ import { writeFileSync } from "node:fs";
12
+ import { t } from "@dalcode/dal-pi-kit";
13
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
14
+ import { Type } from "typebox";
15
+ import { resolveOutputPath } from "../paths.ts";
16
+ import { fallbackPlan, renderPptx } from "../render/pptx.ts";
17
+ import { type OfficePresentationPlan, takePresentationPlan } from "../scratchpad.ts";
18
+ import type { ThemeName } from "../themes.ts";
19
+ import { slidePlanSchema } from "./ppt-plan.ts";
20
+ import { displayPath, formatTemplate, type OfficeToolDetails, officeFailure, officeResult } from "./shared.ts";
21
+
22
+ const pptGenerateSchema = Type.Object({
23
+ title: Type.String({ description: t("PPT 标题,需与 office_ppt_plan 的大纲标题一致") }),
24
+ topic: Type.Optional(Type.String({ description: t("用户原始需求(没有大纲也没有内联 slides 时用于兜底)") })),
25
+ theme: Type.Optional(
26
+ Type.Union(
27
+ [
28
+ Type.Literal("default"),
29
+ Type.Literal("business"),
30
+ Type.Literal("tech"),
31
+ Type.Literal("warm"),
32
+ Type.Literal("minimal"),
33
+ ],
34
+ { description: t("主题风格:default 多彩 / business 商务 / tech 深色科技 / warm 暖色 / minimal 极简") },
35
+ ),
36
+ ),
37
+ slides: Type.Optional(
38
+ Type.Array(slidePlanSchema, {
39
+ minItems: 1,
40
+ maxItems: 15,
41
+ description: t("内联大纲;本会话已调用 office_ppt_plan 时可省略"),
42
+ }),
43
+ ),
44
+ path: Type.Optional(Type.String({ description: t("输出文件路径(可选,相对当前目录,默认写入 office-outputs/)") })),
45
+ });
46
+
47
+ export function registerPptGenerate(pi: ExtensionAPI): void {
48
+ pi.registerTool<typeof pptGenerateSchema, OfficeToolDetails>({
49
+ name: "office_ppt_generate",
50
+ label: t("生成 PPT 文件"),
51
+ description: t(
52
+ "生成 .pptx 演示文稿(两步流程第二步):使用 office_ppt_plan 规划的大纲渲染幻灯片(含主题配色与版式设计),写入文件供直接使用。",
53
+ ),
54
+ promptSnippet: t("office_ppt_generate - 生成 .pptx 文件(生成 PPT 的第二步,需要先有 office_ppt_plan 大纲)"),
55
+ promptGuidelines: [
56
+ t(
57
+ "生成 PPT 文件前必须已有大纲:优先依赖本会话 office_ppt_plan 的大纲;会话恢复后大纲已失效时,先重新调用 office_ppt_plan 再生成本工具。生成完成后向用户说明文件位置与页数。",
58
+ ),
59
+ ],
60
+ parameters: pptGenerateSchema,
61
+ execute: async (_toolCallId, params, _signal, _onUpdate, ctx) => {
62
+ const title = params.title.trim();
63
+ if (title.length === 0) {
64
+ return officeFailure(t("title 不能为空"), "pptx");
65
+ }
66
+ const sessionId = ctx.sessionManager.getSessionId();
67
+ const stored = takePresentationPlan(sessionId);
68
+ let plan: OfficePresentationPlan;
69
+ if (stored) {
70
+ plan = stored;
71
+ } else if (params.slides && params.slides.length > 0) {
72
+ plan = { title, slides: params.slides };
73
+ } else {
74
+ plan = fallbackPlan(title, params.topic ?? title);
75
+ }
76
+
77
+ const theme: ThemeName = params.theme ?? "default";
78
+ const buffer = await renderPptx(plan, theme);
79
+ let target: string;
80
+ try {
81
+ target = resolveOutputPath(ctx.cwd, params.path, title, "pptx");
82
+ } catch (error) {
83
+ return officeFailure(error instanceof Error ? error.message : String(error), "pptx");
84
+ }
85
+ writeFileSync(target, buffer);
86
+
87
+ const text = formatTemplate(
88
+ t(
89
+ "已生成 PPT《{title}》,共 {count} 页(theme:{theme})。\n文件:{file}\n可直接用 PowerPoint / WPS 打开继续编辑。",
90
+ ),
91
+ {
92
+ title: plan.title,
93
+ count: plan.slides.length,
94
+ theme,
95
+ file: displayPath(ctx.cwd, target),
96
+ },
97
+ );
98
+ return officeResult(text, {
99
+ ok: true,
100
+ kind: "pptx",
101
+ file: displayPath(ctx.cwd, target),
102
+ slideCount: plan.slides.length,
103
+ });
104
+ },
105
+ });
106
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * office_ppt_plan — first step of the two-step PPT pipeline.
3
+ *
4
+ * The model drafts the outline itself and passes it in as parameters; this
5
+ * tool infers the business scene, stores the plan in the session scratchpad
6
+ * for office_ppt_generate, and tells the model how to proceed. Read-only:
7
+ * nothing is written to disk.
8
+ */
9
+
10
+ import { t } from "@dalcode/dal-pi-kit";
11
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
12
+ import { type Static, Type } from "typebox";
13
+ import { inferPptScene } from "../scenes.ts";
14
+ import { type OfficeSlidePlan, savePresentationPlan } from "../scratchpad.ts";
15
+ import { formatTemplate, type OfficeToolDetails, officeFailure, officeResult } from "./shared.ts";
16
+
17
+ export const slidePlanSchema = Type.Object({
18
+ title: Type.String({ description: t("本页标题,要具体,避免空泛") }),
19
+ layout: Type.Optional(
20
+ Type.Union(
21
+ [Type.Literal("title"), Type.Literal("content"), Type.Literal("two-column"), Type.Literal("section")],
22
+ {
23
+ description: t("版式:title 封面 / content 内容页 / section 章节页 / two-column 双栏"),
24
+ },
25
+ ),
26
+ ),
27
+ goal: Type.Optional(Type.String({ description: t("本页目标,会写入演讲者备注") })),
28
+ visual: Type.Optional(Type.String({ description: t("视觉建议,如:数据卡片、流程箭头、双栏对比、时间轴") })),
29
+ points: Type.Optional(
30
+ Type.Array(Type.String(), { maxItems: 4, description: t("本页要点,2-4 条,每条一句话,适合直接上屏") }),
31
+ ),
32
+ });
33
+
34
+ const pptPlanSchema = Type.Object({
35
+ topic: Type.String({ description: t("PPT 主题/用户需求") }),
36
+ title: Type.Optional(Type.String({ description: t("PPT 标题(可选,默认取主题)") })),
37
+ audience: Type.Optional(Type.String({ description: t("目标听众(可选)") })),
38
+ slides: Type.Array(slidePlanSchema, {
39
+ minItems: 3,
40
+ maxItems: 15,
41
+ description: t("完整页面大纲,5-10 页为宜:首页做封面、中间形成叙事链、末页做结论/建议/下一步"),
42
+ }),
43
+ });
44
+
45
+ export type PptPlanInput = Static<typeof pptPlanSchema>;
46
+
47
+ export function registerPptPlan(pi: ExtensionAPI): void {
48
+ pi.registerTool<typeof pptPlanSchema, OfficeToolDetails>({
49
+ name: "office_ppt_plan",
50
+ label: t("规划 PPT 大纲"),
51
+ description: t(
52
+ "规划 PPT 大纲(两步流程第一步):整理出每一页的标题、版式、要点,存入会话供 office_ppt_generate 生成文件。只产出规划,不生成幻灯片。",
53
+ ),
54
+ promptSnippet: t("office_ppt_plan - 规划 PPT 大纲(生成 PPT 的第一步,之后必须调用 office_ppt_generate)"),
55
+ promptGuidelines: [
56
+ t(
57
+ "PPT 任务必须两步:先用 office_ppt_plan 规划大纲,再用 office_ppt_generate 生成 .pptx 文件,两步缺一不可。大纲要形成叙事链(背景/目标 → 分析/拆解 → 方案/价值 → 落地/结论),首页做封面、末页做结论或下一步行动。",
58
+ ),
59
+ t(
60
+ "用户同时要多个交付物时(如 PPT + 流程图 + 文档),按顺序分别调用对应工具完整交付;除 PPT 占两步外,单次任务工具总数尽量控制在 5 个以内。需求缺少受众、页数、风格等信息时做合理默认假设继续执行,不要反问。",
61
+ ),
62
+ ],
63
+ parameters: pptPlanSchema,
64
+ execute: async (_toolCallId, params: PptPlanInput, _signal, _onUpdate, ctx) => {
65
+ const topic = params.topic.trim();
66
+ if (topic.length === 0) {
67
+ return officeFailure(t("topic 不能为空"), "ppt_plan");
68
+ }
69
+ const title = (params.title ?? topic).trim() || topic;
70
+ const slides: OfficeSlidePlan[] = params.slides.map((slide) => ({
71
+ title: slide.title,
72
+ ...(slide.layout !== undefined ? { layout: slide.layout } : {}),
73
+ ...(slide.goal !== undefined ? { goal: slide.goal } : {}),
74
+ ...(slide.visual !== undefined ? { visual: slide.visual } : {}),
75
+ ...(slide.points !== undefined ? { points: slide.points } : {}),
76
+ }));
77
+
78
+ savePresentationPlan(ctx.sessionManager.getSessionId(), { title, slides });
79
+ const scene = inferPptScene(`${topic} ${params.audience ?? ""}`);
80
+ const text = [
81
+ formatTemplate(t("已规划 PPT《{title}》,共 {count} 页大纲,已存入本会话。"), {
82
+ title,
83
+ count: slides.length,
84
+ }),
85
+ `${t("场景判断:")}${scene}`,
86
+ t("下一步:调用 office_ppt_generate(title 保持一致)生成 .pptx 文件。"),
87
+ ].join("\n");
88
+ return officeResult(text, { ok: true, kind: "ppt_plan", slideCount: slides.length });
89
+ },
90
+ });
91
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * office_read_file — text extraction for office documents.
3
+ *
4
+ * Read-only counterpart to the generation tools: pulls plain text out of
5
+ * .docx/.pptx/.xlsx/.pdf/.csv so the model can work with files it receives
6
+ * from users or produced earlier in the session.
7
+ */
8
+
9
+ import { existsSync, statSync } from "node:fs";
10
+ import { isAbsolute, resolve } from "node:path";
11
+ import { t } from "@dalcode/dal-pi-kit";
12
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
13
+ import { Type } from "typebox";
14
+ import { extractOfficeText, type OfficeTextExtraction } from "../extract/index.ts";
15
+ import { truncateHeadTail } from "../truncate.ts";
16
+ import { formatTemplate, type OfficeToolDetails, officeFailure, officeResult } from "./shared.ts";
17
+
18
+ const readFileSchema = Type.Object({
19
+ path: Type.String({ description: t("要读取的文件路径(.docx/.pptx/.xlsx/.pdf/.csv/.tsv/.txt/.md)") }),
20
+ });
21
+
22
+ export function registerReadFile(pi: ExtensionAPI): void {
23
+ pi.registerTool<typeof readFileSchema, OfficeToolDetails>({
24
+ name: "office_read_file",
25
+ label: t("读取 office 文件"),
26
+ description: t(
27
+ "读取 office 文件的文本内容:.docx(按段落)、.pptx(按页)、.xlsx(按工作表)、.pdf(按页)、.csv/.tsv(对齐表格)与纯文本。只读,不修改文件。",
28
+ ),
29
+ promptSnippet: t("office_read_file - 读取 docx/pptx/xlsx/pdf/csv 等 office 文件的文本内容"),
30
+ promptGuidelines: [
31
+ t(
32
+ "用户给出 .docx/.pptx/.xlsx/.pdf/.csv 文件路径,或要求基于某个 office 文件继续加工时,先用本工具读取内容作为上下文,再继续任务。",
33
+ ),
34
+ ],
35
+ parameters: readFileSchema,
36
+ executionMode: "parallel",
37
+ execute: async (_toolCallId, params, _signal, _onUpdate, ctx) => {
38
+ const requested = params.path.trim();
39
+ if (requested.length === 0) {
40
+ return officeFailure(t("path 不能为空"), "read");
41
+ }
42
+ const target = isAbsolute(requested) ? resolve(requested) : resolve(ctx.cwd, requested);
43
+ if (!existsSync(target) || !statSync(target).isFile()) {
44
+ return officeFailure(formatTemplate(t("文件不存在或不是普通文件:{path}"), { path: requested }), "read");
45
+ }
46
+
47
+ let extraction: OfficeTextExtraction;
48
+ try {
49
+ extraction = await extractOfficeText(target);
50
+ } catch (error) {
51
+ return officeFailure(
52
+ formatTemplate(t("文件解析失败:{error}"), {
53
+ error: error instanceof Error ? error.message : String(error),
54
+ }),
55
+ "read",
56
+ );
57
+ }
58
+ const text = formatTemplate(t("已读取 {parser} 文件({meta}),正文如下:\n\n{text}"), {
59
+ parser: extraction.parser,
60
+ meta: extraction.meta,
61
+ text: truncateHeadTail(extraction.text),
62
+ });
63
+ return officeResult(text, {
64
+ ok: true,
65
+ kind: "read",
66
+ parser: extraction.parser,
67
+ meta: extraction.meta,
68
+ });
69
+ },
70
+ });
71
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Shared helpers for dal-office tool implementations.
3
+ */
4
+
5
+ import { relative } from "node:path";
6
+
7
+ /** Details payload every dal-office tool attaches for the TUI. */
8
+ export interface OfficeToolDetails {
9
+ ok: boolean;
10
+ kind: string;
11
+ file?: string;
12
+ [key: string]: unknown;
13
+ }
14
+
15
+ /** Builds the standard tool result: short text observation + structured details. */
16
+ export function officeResult<T extends OfficeToolDetails>(
17
+ text: string,
18
+ details: T,
19
+ ): {
20
+ content: Array<{ type: "text"; text: string }>;
21
+ details: T;
22
+ } {
23
+ return {
24
+ content: [{ type: "text", text }],
25
+ details,
26
+ };
27
+ }
28
+
29
+ /** Builds a failed (but LLM-visible, retryable) result — validation problems are messages, not throws. */
30
+ export function officeFailure(
31
+ message: string,
32
+ kind: string,
33
+ ): {
34
+ content: Array<{ type: "text"; text: string }>;
35
+ details: OfficeToolDetails;
36
+ } {
37
+ return officeResult(message, { ok: false, kind });
38
+ }
39
+
40
+ /** Substitutes `{key}` placeholders so translations can reorder around values. */
41
+ export function formatTemplate(template: string, vars: Record<string, string | number>): string {
42
+ let out = template;
43
+ for (const [key, value] of Object.entries(vars)) {
44
+ out = out.replaceAll(`{${key}}`, String(value));
45
+ }
46
+ return out;
47
+ }
48
+
49
+ /** Displays a path relative to the session cwd when possible, with forward slashes for readability. */
50
+ export function displayPath(cwd: string, absolute: string): string {
51
+ const rel = relative(cwd, absolute);
52
+ const normalized = (rel.startsWith("..") ? absolute : rel).split("\\").join("/");
53
+ return normalized;
54
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * office_sheet_generate — Excel workbook renderer.
3
+ *
4
+ * Tables arrive fully drafted as parameters (one worksheet per table);
5
+ * quality expectations for headers/rows live in promptGuidelines while the
6
+ * tool enforces the hard size caps in the schema.
7
+ */
8
+
9
+ import { writeFileSync } from "node:fs";
10
+ import { t } from "@dalcode/dal-pi-kit";
11
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
12
+ import { Type } from "typebox";
13
+ import { resolveOutputPath } from "../paths.ts";
14
+ import { renderXlsx } from "../render/xlsx.ts";
15
+ import { inferSheetScene } from "../scenes.ts";
16
+ import { displayPath, formatTemplate, type OfficeToolDetails, officeFailure, officeResult } from "./shared.ts";
17
+
18
+ const MAX_TABLES = 10;
19
+ const MAX_ROWS = 500;
20
+
21
+ const sheetGenerateSchema = Type.Object({
22
+ title: Type.String({ description: t("表格组标题(同时用作文件名)") }),
23
+ summary: Type.Optional(Type.String({ description: t("整体说明:这套表格适合怎样使用或分析") })),
24
+ tables: Type.Array(
25
+ Type.Object({
26
+ title: Type.String({ description: t("本表标题(用作工作表名)") }),
27
+ headers: Type.Array(Type.String(), {
28
+ minItems: 2,
29
+ maxItems: 30,
30
+ description: t("列名,要专业可执行:负责人、阶段、金额、转化率、开始/结束日期等"),
31
+ }),
32
+ rows: Type.Array(Type.Array(Type.String()), {
33
+ minItems: 1,
34
+ maxItems: MAX_ROWS,
35
+ description: t("数据行,要具体真实有意义,不要占位符"),
36
+ }),
37
+ summary: Type.Optional(Type.String({ description: t("本表说明(写入 A1 批注)") })),
38
+ }),
39
+ {
40
+ minItems: 1,
41
+ maxItems: MAX_TABLES,
42
+ description: t("表格列表;适合多表时拆分为「明细表 + 汇总表」「计划表 + 风险表」等"),
43
+ },
44
+ ),
45
+ path: Type.Optional(Type.String({ description: t("输出文件路径(可选,相对当前目录,默认写入 office-outputs/)") })),
46
+ });
47
+
48
+ export function registerSheetGenerate(pi: ExtensionAPI): void {
49
+ pi.registerTool<typeof sheetGenerateSchema, OfficeToolDetails>({
50
+ name: "office_sheet_generate",
51
+ label: t("生成 Excel 表格"),
52
+ description: t(
53
+ "生成结构化 Excel 工作簿(.xlsx),可含多个工作表:tables 里给出每张表的列名与数据行,工具负责渲染(冻结表头、列宽、数字单元格)。",
54
+ ),
55
+ promptSnippet: t("office_sheet_generate - 生成结构化 Excel 表格(分析/排期/预算/台账)"),
56
+ promptGuidelines: [
57
+ t(
58
+ "excel/表格/排期/预算/数据分析/台账类需求用本工具。表头要专业可执行,数据要具体真实:不要整列「示例1/示例2」式占位;缺少真实数据时按主题补出贴合业务场景的合理数据,并保持同表口径一致。",
59
+ ),
60
+ ],
61
+ parameters: sheetGenerateSchema,
62
+ execute: async (_toolCallId, params, _signal, _onUpdate, ctx) => {
63
+ const title = params.title.trim();
64
+ if (title.length === 0) {
65
+ return officeFailure(t("title 不能为空"), "xlsx");
66
+ }
67
+ const scene = inferSheetScene(title);
68
+ let target: string;
69
+ try {
70
+ target = resolveOutputPath(ctx.cwd, params.path, title, "xlsx");
71
+ } catch (error) {
72
+ return officeFailure(error instanceof Error ? error.message : String(error), "xlsx");
73
+ }
74
+ const buffer = await renderXlsx({
75
+ title,
76
+ tables: params.tables,
77
+ ...(params.summary !== undefined ? { summary: params.summary } : {}),
78
+ });
79
+ writeFileSync(target, buffer);
80
+
81
+ const rowCount = params.tables.reduce((sum, table) => sum + table.rows.length, 0);
82
+ const text = formatTemplate(
83
+ t("已生成 Excel《{title}》,共 {tables} 个工作表、{rows} 行数据。\n文件:{file}\n{scene}"),
84
+ {
85
+ title,
86
+ tables: params.tables.length,
87
+ rows: rowCount,
88
+ file: displayPath(ctx.cwd, target),
89
+ scene,
90
+ },
91
+ );
92
+ return officeResult(text, {
93
+ ok: true,
94
+ kind: "xlsx",
95
+ file: displayPath(ctx.cwd, target),
96
+ tableCount: params.tables.length,
97
+ rowCount,
98
+ });
99
+ },
100
+ });
101
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Shared truncation limits for dal-office tool observations.
3
+ *
4
+ * Tool results feed straight back into the model context; an unbounded
5
+ * document dump would blow the window, so every observation is capped here.
6
+ */
7
+
8
+ /** Hard cap for any tool's text observation (chars). */
9
+ export const MAX_OBSERVATION_CHARS = 4_000;
10
+
11
+ /** Cap for extracted office-file text (chars); kept head + tail when exceeded. */
12
+ export const MAX_EXTRACTED_CHARS = 200_000;
13
+
14
+ /** Head-only truncation for tool observations. */
15
+ export function truncateObservation(text: string, max: number = MAX_OBSERVATION_CHARS): string {
16
+ if (text.length <= max) return text;
17
+ return `${text.slice(0, max)}\n…(内容过长,已截断)`;
18
+ }
19
+
20
+ /** Head+tail truncation for extracted file text, so both the start and the summary survive. */
21
+ export function truncateHeadTail(text: string, max: number = MAX_EXTRACTED_CHARS): string {
22
+ if (text.length <= max) return text;
23
+ const head = Math.floor(max * 0.7);
24
+ const tail = max - head;
25
+ const omitted = text.length - head - tail;
26
+ return `${text.slice(0, head)}\n\n…(中间省略 ${omitted} 字符)…\n\n${text.slice(text.length - tail)}`;
27
+ }