dal-code 1.0.0 → 1.0.7
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.
- package/CHANGELOG.md +67 -1
- package/dist/core/auth-guidance.d.ts +1 -0
- package/dist/core/auth-guidance.d.ts.map +1 -1
- package/dist/core/auth-guidance.js +6 -0
- package/dist/core/auth-guidance.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +4 -7
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +13 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +47 -48
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +46 -43
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybindings.d.ts +10 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +13 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/tools/bash.d.ts +3 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +61 -8
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js +43 -6
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/dal/builtins.d.ts.map +1 -1
- package/dist/dal/builtins.js +1 -0
- package/dist/dal/builtins.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +6 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +12 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +22 -1
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +2 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +24 -7
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +39 -2
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +200 -29
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +35 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +177 -23
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -1
- package/dist/modes/interactive/theme/light.json +1 -1
- package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/tui-renderer.js +2 -2
- package/dist/modes/interactive/tui-renderer.js.map +1 -1
- package/dist/node_modules/@dalcode/dal-bridge/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-gateway/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-guard/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-halo/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-mcp/package.json +9 -6
- package/dist/node_modules/@dalcode/dal-mcp/src/add-wizard.ts +142 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/command-parser.ts +218 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/config-edit.ts +99 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/index.ts +161 -18
- package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.ts +8 -3
- package/dist/node_modules/@dalcode/dal-office/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-office/package.json +37 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/csv.ts +84 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/index.ts +111 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/ooxml.ts +109 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/pdf.ts +43 -0
- package/dist/node_modules/@dalcode/dal-office/src/index.ts +43 -0
- package/dist/node_modules/@dalcode/dal-office/src/paths.ts +107 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/chart.ts +111 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/docx.ts +155 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/pptx.ts +386 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.ts +99 -0
- package/dist/node_modules/@dalcode/dal-office/src/scenes.ts +197 -0
- package/dist/node_modules/@dalcode/dal-office/src/scratchpad.ts +49 -0
- package/dist/node_modules/@dalcode/dal-office/src/themes.ts +240 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/chart-generate.ts +122 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/doc-generate.ts +123 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/drawio-generate.ts +99 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/md-generate.ts +76 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.ts +106 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.ts +91 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/read-file.ts +71 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/shared.ts +54 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/sheet-generate.ts +101 -0
- package/dist/node_modules/@dalcode/dal-office/src/truncate.ts +27 -0
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.d.ts.map +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +233 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js.map +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.ts +322 -1
- package/dist/node_modules/@dalcode/dal-skills/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-skills/src/discover.ts +101 -0
- package/dist/node_modules/@dalcode/dal-skills/src/index.ts +71 -9
- package/dist/node_modules/@dalcode/dal-skills/src/install.ts +140 -0
- package/dist/node_modules/@dalcode/dal-skills/src/manage.ts +446 -0
- package/dist/node_modules/@dalcode/dal-skills/src/packages.ts +39 -1
- package/dist/node_modules/@dalcode/dal-subagent/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-subagent/src/index.ts +46 -4
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
- package/dist/node_modules/@dalcode/deepailab/package.json +4 -4
- package/dist/node_modules/@dalcode/deepailab/src/index.ts +7 -1
- package/dist/node_modules/@dalcode/deepailab/src/model-defaults.ts +42 -6
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +3 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js +3 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js +23 -22
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +4 -3
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +4 -2
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/dist/utils/changelog.d.ts +37 -4
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +80 -17
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +13 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/package.json +1 -1
- package/npm-shrinkwrap.json +1511 -25
- package/package.json +8 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text extraction from OOXML containers (docx/pptx).
|
|
3
|
+
*
|
|
4
|
+
* Office text XML is machine-generated and stable, so paragraph text is
|
|
5
|
+
* lifted with targeted matches instead of a full DOM walk: `<w:t>` runs
|
|
6
|
+
* inside `</w:p>`-delimited paragraphs for Word, `<a:t>` runs per slide for
|
|
7
|
+
* PowerPoint. Entities are decoded afterwards.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import JSZip from "jszip";
|
|
11
|
+
|
|
12
|
+
const NAMED_ENTITIES: Record<string, string> = {
|
|
13
|
+
"&": "&",
|
|
14
|
+
"<": "<",
|
|
15
|
+
">": ">",
|
|
16
|
+
""": '"',
|
|
17
|
+
"'": "'",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Decodes the five XML named entities plus numeric character references. */
|
|
21
|
+
export function decodeXmlEntities(text: string): string {
|
|
22
|
+
return text
|
|
23
|
+
.replace(/&#x([0-9a-fA-F]+);/g, (_, hex: string) => String.fromCodePoint(Number.parseInt(hex, 16)))
|
|
24
|
+
.replace(/&#(\d+);/g, (_, dec: string) => String.fromCodePoint(Number.parseInt(dec, 10)))
|
|
25
|
+
.replace(/&(amp|lt|gt|quot|apos);/g, (match) => NAMED_ENTITIES[match] ?? match);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface RunMatch {
|
|
29
|
+
text: string;
|
|
30
|
+
index: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Collects `<tag>` run texts in document order. */
|
|
34
|
+
function collectRuns(xml: string, tag: string): RunMatch[] {
|
|
35
|
+
const pattern = new RegExp(`<${tag}(?:\\s[^>]*)?>([\\s\\S]*?)</${tag}>`, "g");
|
|
36
|
+
const runs: RunMatch[] = [];
|
|
37
|
+
for (const match of xml.matchAll(pattern)) {
|
|
38
|
+
runs.push({ text: decodeXmlEntities(match[1]), index: match.index ?? 0 });
|
|
39
|
+
}
|
|
40
|
+
return runs;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Extracts paragraph-per-line text from a Word document body. */
|
|
44
|
+
export function extractDocxText(xml: string): string {
|
|
45
|
+
const paragraphs = xml.split(/<\/w:p>/);
|
|
46
|
+
const lines: string[] = [];
|
|
47
|
+
for (const paragraph of paragraphs) {
|
|
48
|
+
const runs = collectRuns(paragraph, "w:t");
|
|
49
|
+
if (runs.length === 0) continue;
|
|
50
|
+
const line = runs
|
|
51
|
+
.map((run) => run.text)
|
|
52
|
+
.join("")
|
|
53
|
+
.trim();
|
|
54
|
+
if (line.length > 0) lines.push(line);
|
|
55
|
+
}
|
|
56
|
+
return lines.join("\n");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Extracts per-slide text from PowerPoint slide XML (one `<a:t>` run per line). */
|
|
60
|
+
export function extractSlideTexts(xml: string): string[] {
|
|
61
|
+
const runs = collectRuns(xml, "a:t");
|
|
62
|
+
return runs.map((run) => run.text.trim()).filter((line) => line.length > 0);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Reads one entry from the zip as text; returns undefined when missing. */
|
|
66
|
+
export async function zipEntryText(zip: JSZip, path: string): Promise<string | undefined> {
|
|
67
|
+
const entry = zip.file(path);
|
|
68
|
+
return entry ? entry.async("string") : undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface OoxmlExtraction {
|
|
72
|
+
text: string;
|
|
73
|
+
meta: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** docx: one line per paragraph. */
|
|
77
|
+
export async function extractDocx(buffer: Buffer): Promise<OoxmlExtraction> {
|
|
78
|
+
const zip = await JSZip.loadAsync(buffer);
|
|
79
|
+
const xml = await zipEntryText(zip, "word/document.xml");
|
|
80
|
+
if (xml === undefined) {
|
|
81
|
+
throw new Error("invalid docx: missing word/document.xml");
|
|
82
|
+
}
|
|
83
|
+
const text = extractDocxText(xml);
|
|
84
|
+
const lines = text.split("\n").filter((line) => line.length > 0).length;
|
|
85
|
+
return { text, meta: `${lines} paragraphs` };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** pptx: slides in numeric order with separators. */
|
|
89
|
+
export async function extractPptx(buffer: Buffer): Promise<OoxmlExtraction> {
|
|
90
|
+
const zip = await JSZip.loadAsync(buffer);
|
|
91
|
+
const slidePaths = Object.keys(zip.files)
|
|
92
|
+
.filter((path) => /^ppt\/slides\/slide\d+\.xml$/.test(path))
|
|
93
|
+
.sort((a, b) => {
|
|
94
|
+
const numA = Number.parseInt(a.replace(/\D+/g, ""), 10);
|
|
95
|
+
const numB = Number.parseInt(b.replace(/\D+/g, ""), 10);
|
|
96
|
+
return numA - numB;
|
|
97
|
+
});
|
|
98
|
+
if (slidePaths.length === 0) {
|
|
99
|
+
throw new Error("invalid pptx: no slides found");
|
|
100
|
+
}
|
|
101
|
+
const chunks: string[] = [];
|
|
102
|
+
for (const [index, path] of slidePaths.entries()) {
|
|
103
|
+
const xml = await zipEntryText(zip, path);
|
|
104
|
+
if (!xml) continue;
|
|
105
|
+
chunks.push(`--- Page ${index + 1} ---`);
|
|
106
|
+
chunks.push(...extractSlideTexts(xml));
|
|
107
|
+
}
|
|
108
|
+
return { text: chunks.join("\n"), meta: `${slidePaths.length} slides` };
|
|
109
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF text extraction via pdfjs-dist.
|
|
3
|
+
*
|
|
4
|
+
* Runs fully in-process (fake worker, no canvas): each page's text items are
|
|
5
|
+
* joined, honoring end-of-line markers so paragraphs survive extraction.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
9
|
+
|
|
10
|
+
export interface PdfExtraction {
|
|
11
|
+
text: string;
|
|
12
|
+
meta: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function extractPdf(buffer: Buffer): Promise<PdfExtraction> {
|
|
16
|
+
const loadingTask = getDocument({ data: new Uint8Array(buffer) });
|
|
17
|
+
const doc = await loadingTask.promise;
|
|
18
|
+
try {
|
|
19
|
+
const chunks: string[] = [];
|
|
20
|
+
for (let pageNumber = 1; pageNumber <= doc.numPages; pageNumber++) {
|
|
21
|
+
const page = await doc.getPage(pageNumber);
|
|
22
|
+
const content = await page.getTextContent();
|
|
23
|
+
let pageText = "";
|
|
24
|
+
for (const item of content.items) {
|
|
25
|
+
if ("str" in item) {
|
|
26
|
+
pageText += item.str;
|
|
27
|
+
if (item.hasEOL) {
|
|
28
|
+
pageText += "\n";
|
|
29
|
+
}
|
|
30
|
+
} else if (typeof item === "string") {
|
|
31
|
+
pageText += item;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const trimmed = pageText.trim();
|
|
35
|
+
if (trimmed.length > 0) {
|
|
36
|
+
chunks.push(`--- Page ${pageNumber} ---\n${trimmed}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return { text: chunks.join("\n\n"), meta: `${doc.numPages} pages` };
|
|
40
|
+
} finally {
|
|
41
|
+
await loadingTask.destroy();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dal-office: daily-office toolkit for DAL Code.
|
|
3
|
+
*
|
|
4
|
+
* Registers eight office_* tools covering the full local document chain:
|
|
5
|
+
* a two-step PPT pipeline (office_ppt_plan -> office_ppt_generate with a
|
|
6
|
+
* session scratchpad handoff), Word/Markdown/Excel document generation,
|
|
7
|
+
* ECharts chart rendering, draw.io diagram writing, and text extraction
|
|
8
|
+
* from office files. Everything is local and deterministic — content comes
|
|
9
|
+
* from the session model as tool parameters; the tools validate, render,
|
|
10
|
+
* and write files under <cwd>/office-outputs/.
|
|
11
|
+
*
|
|
12
|
+
* Guard boundary: dal-guard's path rules only intercept bash/write/edit/mcp
|
|
13
|
+
* tool names, so these custom tools self-police instead — resolveOutputPath
|
|
14
|
+
* keeps every artifact inside the session cwd and never overwrites.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
18
|
+
import { clearPresentationPlan } from "./scratchpad.ts";
|
|
19
|
+
import { registerChartGenerate } from "./tools/chart-generate.ts";
|
|
20
|
+
import { registerDocGenerate } from "./tools/doc-generate.ts";
|
|
21
|
+
import { registerDrawioGenerate } from "./tools/drawio-generate.ts";
|
|
22
|
+
import { registerMdGenerate } from "./tools/md-generate.ts";
|
|
23
|
+
import { registerPptGenerate } from "./tools/ppt-generate.ts";
|
|
24
|
+
import { registerPptPlan } from "./tools/ppt-plan.ts";
|
|
25
|
+
import { registerReadFile } from "./tools/read-file.ts";
|
|
26
|
+
import { registerSheetGenerate } from "./tools/sheet-generate.ts";
|
|
27
|
+
|
|
28
|
+
export default function officeExtension(pi: ExtensionAPI): void {
|
|
29
|
+
registerPptPlan(pi);
|
|
30
|
+
registerPptGenerate(pi);
|
|
31
|
+
registerDocGenerate(pi);
|
|
32
|
+
registerMdGenerate(pi);
|
|
33
|
+
registerSheetGenerate(pi);
|
|
34
|
+
registerChartGenerate(pi);
|
|
35
|
+
registerDrawioGenerate(pi);
|
|
36
|
+
registerReadFile(pi);
|
|
37
|
+
|
|
38
|
+
// Drop the session's PPT outline when the session ends so a long-lived
|
|
39
|
+
// process never serves a stale plan to a future session.
|
|
40
|
+
pi.on("session_shutdown", async (_event, ctx: ExtensionContext) => {
|
|
41
|
+
clearPresentationPlan(ctx.sessionManager.getSessionId());
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output path resolution for dal-office artifacts.
|
|
3
|
+
*
|
|
4
|
+
* Custom tools are not covered by dal-guard's path rules (those match only
|
|
5
|
+
* bash/write/edit/mcp tool names), so every writing tool funnels its output
|
|
6
|
+
* through this module: requested paths must stay inside the session cwd,
|
|
7
|
+
* generated filenames are Windows-safe, and existing files are never
|
|
8
|
+
* overwritten — a `-2`/`-3` suffix is appended instead.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
12
|
+
import { dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
|
|
13
|
+
import { t } from "@dalcode/dal-pi-kit";
|
|
14
|
+
|
|
15
|
+
export const OFFICE_OUTPUT_DIR = "office-outputs";
|
|
16
|
+
|
|
17
|
+
/** Windows-reserved device names that cannot stand alone as a filename. */
|
|
18
|
+
const RESERVED_BASENAMES = new Set([
|
|
19
|
+
"CON",
|
|
20
|
+
"PRN",
|
|
21
|
+
"AUX",
|
|
22
|
+
"NUL",
|
|
23
|
+
"COM1",
|
|
24
|
+
"COM2",
|
|
25
|
+
"COM3",
|
|
26
|
+
"COM4",
|
|
27
|
+
"COM5",
|
|
28
|
+
"COM6",
|
|
29
|
+
"COM7",
|
|
30
|
+
"COM8",
|
|
31
|
+
"COM9",
|
|
32
|
+
"LPT1",
|
|
33
|
+
"LPT2",
|
|
34
|
+
"LPT3",
|
|
35
|
+
"LPT4",
|
|
36
|
+
"LPT5",
|
|
37
|
+
"LPT6",
|
|
38
|
+
"LPT7",
|
|
39
|
+
"LPT8",
|
|
40
|
+
"LPT9",
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Strips control/format characters and Windows-forbidden characters; keeps a
|
|
45
|
+
* usable basename. `\p{C}` covers control codes plus zero-width marks that
|
|
46
|
+
* would otherwise hide in pasted titles.
|
|
47
|
+
*/
|
|
48
|
+
const UNSAFE_FILENAME_CHARS = /\p{C}|[\\/:*?"<>|]/gu;
|
|
49
|
+
|
|
50
|
+
/** Turns an arbitrary artifact title into a safe file basename. */
|
|
51
|
+
export function sanitizeFilename(title: string, fallback: string): string {
|
|
52
|
+
const cleaned = title
|
|
53
|
+
.replace(UNSAFE_FILENAME_CHARS, "-")
|
|
54
|
+
.replace(/\s+/g, " ")
|
|
55
|
+
.replace(/^[.\s-]+/, "")
|
|
56
|
+
.replace(/[.\s-]+$/, "")
|
|
57
|
+
.slice(0, 60)
|
|
58
|
+
.trim();
|
|
59
|
+
const guarded = RESERVED_BASENAMES.has(cleaned.toUpperCase()) ? `_${cleaned}` : cleaned;
|
|
60
|
+
return guarded.length > 0 ? guarded : fallback;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function timestamp(): string {
|
|
64
|
+
const now = new Date();
|
|
65
|
+
const pad = (value: number): string => String(value).padStart(2, "0");
|
|
66
|
+
const date = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}`;
|
|
67
|
+
const time = `${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
68
|
+
return `${date}-${time}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Returns the path with a numeric suffix appended (before the extension) until it does not exist. */
|
|
72
|
+
function ensureUnique(target: string): string {
|
|
73
|
+
if (!existsSync(target)) return target;
|
|
74
|
+
const ext = extname(target);
|
|
75
|
+
const stem = target.slice(0, target.length - ext.length);
|
|
76
|
+
for (let attempt = 2; attempt < 1000; attempt++) {
|
|
77
|
+
const candidate = `${stem}-${attempt}${ext}`;
|
|
78
|
+
if (!existsSync(candidate)) return candidate;
|
|
79
|
+
}
|
|
80
|
+
// Practically unreachable; fall back to a timestamped name rather than overwrite.
|
|
81
|
+
return `${stem}-${Date.now()}${ext}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Resolves the output path for one artifact.
|
|
86
|
+
*
|
|
87
|
+
* Without `requested`, artifacts land in `<cwd>/office-outputs/` under a
|
|
88
|
+
* sanitized, timestamped name. A `requested` path (relative to cwd) is
|
|
89
|
+
* honored but must not escape the cwd, and an existing file is never
|
|
90
|
+
* overwritten.
|
|
91
|
+
*/
|
|
92
|
+
export function resolveOutputPath(cwd: string, requested: string | undefined, title: string, ext: string): string {
|
|
93
|
+
if (requested === undefined || requested.trim() === "") {
|
|
94
|
+
const dir = join(cwd, OFFICE_OUTPUT_DIR);
|
|
95
|
+
mkdirSync(dir, { recursive: true });
|
|
96
|
+
return ensureUnique(join(dir, `${sanitizeFilename(title, "output")}-${timestamp()}.${ext}`));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let target = isAbsolute(requested) ? resolve(requested) : resolve(cwd, requested);
|
|
100
|
+
const rel = relative(cwd, target);
|
|
101
|
+
if (rel.startsWith("..") || isAbsolute(rel)) {
|
|
102
|
+
throw new Error(`${t("输出路径必须位于当前工作目录内:")}${requested}`);
|
|
103
|
+
}
|
|
104
|
+
if (extname(target) === "") target = `${target}.${ext}`;
|
|
105
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
106
|
+
return ensureUnique(target);
|
|
107
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart renderer: builds an ECharts option from plain labels/values and
|
|
3
|
+
* renders it server-side to a standalone SVG.
|
|
4
|
+
*
|
|
5
|
+
* Three artifacts come out of one call: the .svg (drop into any doc/browser),
|
|
6
|
+
* an .html wrapper, and the raw option .json for later editing.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as echarts from "echarts";
|
|
10
|
+
|
|
11
|
+
export type ChartType = "line" | "bar" | "pie" | "gauge" | "funnel" | "scatter";
|
|
12
|
+
|
|
13
|
+
export interface ChartInput {
|
|
14
|
+
title: string;
|
|
15
|
+
chartType: ChartType;
|
|
16
|
+
labels: string[];
|
|
17
|
+
values: number[];
|
|
18
|
+
seriesName?: string;
|
|
19
|
+
summary?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const CHART_WIDTH = 960;
|
|
23
|
+
const CHART_HEIGHT = 600;
|
|
24
|
+
|
|
25
|
+
/** Zips labels with values into ECharts `{name, value}` datum (pie/funnel). */
|
|
26
|
+
function nameValueData(labels: string[], values: number[]): Array<{ name: string; value: number }> {
|
|
27
|
+
return labels.map((label, index) => ({ name: label, value: values[index] }));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function buildChartOption(chart: ChartInput): Record<string, unknown> {
|
|
31
|
+
const seriesName = chart.seriesName ?? "";
|
|
32
|
+
const base: Record<string, unknown> = {
|
|
33
|
+
title: { text: chart.title, left: "center" },
|
|
34
|
+
animation: false,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
switch (chart.chartType) {
|
|
38
|
+
case "pie":
|
|
39
|
+
return {
|
|
40
|
+
...base,
|
|
41
|
+
tooltip: { trigger: "item" },
|
|
42
|
+
legend: { bottom: 0 },
|
|
43
|
+
series: [{ type: "pie", radius: "62%", name: seriesName, data: nameValueData(chart.labels, chart.values) }],
|
|
44
|
+
};
|
|
45
|
+
case "funnel":
|
|
46
|
+
return {
|
|
47
|
+
...base,
|
|
48
|
+
tooltip: { trigger: "item" },
|
|
49
|
+
series: [{ type: "funnel", name: seriesName, data: nameValueData(chart.labels, chart.values) }],
|
|
50
|
+
};
|
|
51
|
+
case "gauge":
|
|
52
|
+
return {
|
|
53
|
+
...base,
|
|
54
|
+
series: [
|
|
55
|
+
{
|
|
56
|
+
type: "gauge",
|
|
57
|
+
data: [{ value: chart.values[0], name: seriesName || chart.labels[0] || "" }],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
default:
|
|
62
|
+
// line / bar / scatter share the category-axis shape.
|
|
63
|
+
return {
|
|
64
|
+
...base,
|
|
65
|
+
tooltip: { trigger: "axis" },
|
|
66
|
+
xAxis: { type: "category", data: chart.labels },
|
|
67
|
+
yAxis: { type: "value" },
|
|
68
|
+
series: [
|
|
69
|
+
{
|
|
70
|
+
type: chart.chartType,
|
|
71
|
+
name: seriesName,
|
|
72
|
+
data: chart.values,
|
|
73
|
+
smooth: chart.chartType === "line",
|
|
74
|
+
symbolSize: chart.chartType === "scatter" ? 12 : undefined,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function renderChartSvg(option: Record<string, unknown>): string {
|
|
82
|
+
const chart = echarts.init(null, null, {
|
|
83
|
+
ssr: true,
|
|
84
|
+
renderer: "svg",
|
|
85
|
+
width: CHART_WIDTH,
|
|
86
|
+
height: CHART_HEIGHT,
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
chart.setOption(option);
|
|
90
|
+
return chart.renderToSVGString();
|
|
91
|
+
} finally {
|
|
92
|
+
chart.dispose();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function chartHtml(svg: string, title: string): string {
|
|
97
|
+
return [
|
|
98
|
+
"<!DOCTYPE html>",
|
|
99
|
+
'<html lang="zh-CN">',
|
|
100
|
+
"<head>",
|
|
101
|
+
'<meta charset="utf-8">',
|
|
102
|
+
`<title>${title}</title>`,
|
|
103
|
+
"<style>body{margin:0;display:flex;align-items:center;justify-content:center;min-height:100vh;background:#f8fafc;}",
|
|
104
|
+
"svg{max-width:96vw;height:auto;}</style>",
|
|
105
|
+
"</head>",
|
|
106
|
+
"<body>",
|
|
107
|
+
svg,
|
|
108
|
+
"</body>",
|
|
109
|
+
"</html>",
|
|
110
|
+
].join("\n");
|
|
111
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOCX renderer: turns structured sections into a Word document.
|
|
3
|
+
*
|
|
4
|
+
* Typography is fixed (28pt title, 18/15/13pt headings, 11pt body) so every
|
|
5
|
+
* generated document shares one house style. Inline `**bold**` and `*italic*`
|
|
6
|
+
* markers coming from the model are converted to real Word formatting.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
BorderStyle,
|
|
11
|
+
Document,
|
|
12
|
+
type IParagraphOptions,
|
|
13
|
+
Packer,
|
|
14
|
+
Paragraph,
|
|
15
|
+
ShadingType,
|
|
16
|
+
Table,
|
|
17
|
+
TableCell,
|
|
18
|
+
TableRow,
|
|
19
|
+
TextRun,
|
|
20
|
+
WidthType,
|
|
21
|
+
} from "docx";
|
|
22
|
+
|
|
23
|
+
export interface DocTableInput {
|
|
24
|
+
headers: string[];
|
|
25
|
+
rows: string[][];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DocSectionInput {
|
|
29
|
+
heading: string;
|
|
30
|
+
headingLevel?: number;
|
|
31
|
+
paragraphs?: string[];
|
|
32
|
+
bullets?: string[];
|
|
33
|
+
table?: DocTableInput;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface DocOutputInput {
|
|
37
|
+
title: string;
|
|
38
|
+
sections: DocSectionInput[];
|
|
39
|
+
summary?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const TITLE_SIZE = 56; // half-points: 28pt
|
|
43
|
+
const HEADING_SIZES: Record<number, number> = { 1: 36, 2: 30, 3: 26 }; // 18/15/13pt
|
|
44
|
+
const BODY_SIZE = 22; // 11pt
|
|
45
|
+
const TABLE_SIZE = 20; // 10pt
|
|
46
|
+
const BORDER_COLOR = "BFBFBF";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Splits text on `**bold**` and `*italic*` markers into styled runs.
|
|
50
|
+
* Unmatched markers survive as literal text.
|
|
51
|
+
*/
|
|
52
|
+
export function parseInlineRuns(text: string, size: number): TextRun[] {
|
|
53
|
+
const runs: TextRun[] = [];
|
|
54
|
+
for (const part of text.split(/(\*\*[^*]+\*\*|\*[^*]+\*)/g)) {
|
|
55
|
+
if (part.length === 0) continue;
|
|
56
|
+
if (part.startsWith("**") && part.endsWith("**") && part.length > 4) {
|
|
57
|
+
runs.push(new TextRun({ text: part.slice(2, -2), bold: true, size }));
|
|
58
|
+
} else if (part.startsWith("*") && part.endsWith("*") && part.length > 2) {
|
|
59
|
+
runs.push(new TextRun({ text: part.slice(1, -1), italics: true, size }));
|
|
60
|
+
} else {
|
|
61
|
+
runs.push(new TextRun({ text: part, size }));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return runs;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function headingParagraph(section: DocSectionInput): Paragraph {
|
|
68
|
+
const level = Math.min(Math.max(section.headingLevel ?? 1, 1), 3);
|
|
69
|
+
return new Paragraph({
|
|
70
|
+
children: [new TextRun({ text: section.heading, bold: true, size: HEADING_SIZES[level] })],
|
|
71
|
+
spacing: { before: 240, after: 120 },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function tableBorders() {
|
|
76
|
+
const border = { style: BorderStyle.SINGLE, size: 4, color: BORDER_COLOR };
|
|
77
|
+
return {
|
|
78
|
+
top: border,
|
|
79
|
+
bottom: border,
|
|
80
|
+
left: border,
|
|
81
|
+
right: border,
|
|
82
|
+
insideHorizontal: border,
|
|
83
|
+
insideVertical: border,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function buildTable(table: DocTableInput): Table {
|
|
88
|
+
const headerRow = new TableRow({
|
|
89
|
+
tableHeader: true,
|
|
90
|
+
children: table.headers.map(
|
|
91
|
+
(header) =>
|
|
92
|
+
new TableCell({
|
|
93
|
+
shading: { type: ShadingType.CLEAR, fill: "F2F2F2" },
|
|
94
|
+
children: [new Paragraph({ children: [new TextRun({ text: header, bold: true, size: TABLE_SIZE })] })],
|
|
95
|
+
}),
|
|
96
|
+
),
|
|
97
|
+
});
|
|
98
|
+
const bodyRows = table.rows.map(
|
|
99
|
+
(row) =>
|
|
100
|
+
new TableRow({
|
|
101
|
+
children: row.map(
|
|
102
|
+
(cell) =>
|
|
103
|
+
new TableCell({
|
|
104
|
+
children: [new Paragraph({ children: [new TextRun({ text: cell, size: TABLE_SIZE })] })],
|
|
105
|
+
}),
|
|
106
|
+
),
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
return new Table({
|
|
110
|
+
width: { size: 100, type: WidthType.PERCENTAGE },
|
|
111
|
+
borders: tableBorders(),
|
|
112
|
+
rows: [headerRow, ...bodyRows],
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function renderDocx(doc: DocOutputInput): Promise<Buffer> {
|
|
117
|
+
const children: Array<Paragraph | Table> = [
|
|
118
|
+
new Paragraph({
|
|
119
|
+
children: [new TextRun({ text: doc.title, bold: true, size: TITLE_SIZE })],
|
|
120
|
+
spacing: { after: 240 },
|
|
121
|
+
}),
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
for (const section of doc.sections) {
|
|
125
|
+
children.push(headingParagraph(section));
|
|
126
|
+
for (const paragraph of section.paragraphs ?? []) {
|
|
127
|
+
children.push(new Paragraph({ children: parseInlineRuns(paragraph, BODY_SIZE), spacing: { after: 120 } }));
|
|
128
|
+
}
|
|
129
|
+
for (const bullet of section.bullets ?? []) {
|
|
130
|
+
const options: IParagraphOptions = {
|
|
131
|
+
children: parseInlineRuns(bullet, BODY_SIZE),
|
|
132
|
+
bullet: { level: 0 },
|
|
133
|
+
spacing: { after: 60 },
|
|
134
|
+
};
|
|
135
|
+
children.push(new Paragraph(options));
|
|
136
|
+
}
|
|
137
|
+
if (section.table && section.table.headers.length > 0) {
|
|
138
|
+
children.push(buildTable(section.table));
|
|
139
|
+
children.push(new Paragraph({ children: [], spacing: { after: 120 } }));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const document = new Document({
|
|
144
|
+
styles: {
|
|
145
|
+
default: {
|
|
146
|
+
document: {
|
|
147
|
+
run: { font: "Calibri", size: BODY_SIZE },
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
sections: [{ children }],
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return Packer.toBuffer(document);
|
|
155
|
+
}
|