@pecot/visual-mcp 2.0.0 → 3.0.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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +2 -2
- package/assets/slidev/package.json +1 -1
- package/assets/slidev/scripts/eslint/slidev-pages-lint/package.json +1 -1
- package/assets/slidev/scripts/eslint/text-constraints/package.json +1 -1
- package/cli/dist/domain/_shared/failure-kind.d.ts +1 -1
- package/cli/dist/domain/_shared/failure-kind.js +1 -1
- package/cli/dist/mcp/dev-server-registry.d.ts +4 -0
- package/cli/dist/mcp/dev-server-registry.js +4 -1
- package/cli/dist/mcp/result.d.ts +34 -73
- package/cli/dist/mcp/result.js +72 -76
- package/cli/dist/mcp/tools/_shared.d.ts +36 -35
- package/cli/dist/mcp/tools/_shared.js +57 -70
- package/cli/dist/mcp/tools/drawio.js +44 -63
- package/cli/dist/mcp/tools/evidence.js +9 -18
- package/cli/dist/mcp/tools/setup.js +14 -36
- package/cli/dist/mcp/tools/slide-dev.js +13 -35
- package/cli/dist/mcp/tools/slide-page.js +16 -24
- package/cli/dist/mcp/tools/slide-theme.js +3 -13
- package/cli/dist/mcp/tools/slide.d.ts +2 -2
- package/cli/dist/mcp/tools/slide.js +27 -71
- package/cli/dist/mcp/warnings.d.ts +24 -0
- package/cli/dist/mcp/warnings.js +101 -0
- package/cli/dist/mcp/windows-path.js +1 -1
- package/npm-shrinkwrap.json +3 -3
- package/package.json +2 -2
- package/vendor/text-rules/dist/source-hash +1 -1
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
// 11 ツール共通の outputSchema
|
|
2
|
-
//
|
|
3
|
-
// outputSchema は ToolResult (src/mcp/result.ts) と同形の zod object で、全ツールが共有する。
|
|
4
|
-
// contract.test.ts は、required が artifacts・data・exitCode・message・ok の sorted であることを pin している。
|
|
5
|
-
// stdout / stderr は任意として pin しているため、フィールドの必須性はここでのみ管理する。
|
|
6
|
-
//
|
|
7
|
-
// 出力捕捉・エラー整形・パス引数の説明文は、11 ツールで同一の振る舞いが要る。
|
|
8
|
-
// とくに stdout / stderr は「捕捉したなら空でもキーを残す」が契約なので、実装はここに 1 本だけ置く。
|
|
9
|
-
//
|
|
10
|
-
// 引数の narrowing も、4 ファイル共通の方式に揃える。
|
|
11
|
-
// SDK は inputSchema で検証済みの引数を渡してくる。ただしハンドラの引数型は Record<string, unknown> のまま。
|
|
12
|
-
// そこで inputSchema と同じ z.object で parse し直して型を得る。
|
|
13
|
-
// これは `as` キャスト禁止の下で型を得る手段で、検証済みの引数に対しては既定値の適用も冪等になる。
|
|
1
|
+
// 11 ツール共通の outputSchema・出力捕捉・エラー整形・実行時ガード。
|
|
2
|
+
// ハンドラは inputSchema と同じ z.object で引数を parse し直して型を得る (`as` を使わないため)。
|
|
14
3
|
import path from 'node:path';
|
|
15
4
|
import { z } from 'zod';
|
|
16
5
|
import { areRuntimeDependenciesInstalled, DEPENDENCY_RECOVERY_HINT, runtimeDependencyRoot, } from '../../infra/_shared/dependency-root.js';
|
|
@@ -18,7 +7,8 @@ import { LOCK_CONFLICT_EXIT_CODE, LOCK_WAIT_SECONDS } from '../../infra/_shared/
|
|
|
18
7
|
import { resolvePluginRoot } from '../../infra/_shared/plugin-root.js';
|
|
19
8
|
import { installRuntimeDependencies, runtimeInstallStamp, RUNTIME_MANIFEST_DIRECTORY } from '../../infra/_shared/runtime-install.js';
|
|
20
9
|
import { AUTO_INSTALL_ENV, browsersRoot, installChromium, isAutoInstallEnabled, isChromiumInstalled, } from '../../infra/playwright/chromium.js';
|
|
21
|
-
import { createOutputCapture,
|
|
10
|
+
import { createOutputCapture, joinCapturedText, toCallToolResult } from '../result.js';
|
|
11
|
+
import { warningsOf } from '../warnings.js';
|
|
22
12
|
import { toPosixPath } from '../windows-path.js';
|
|
23
13
|
/**
|
|
24
14
|
パス型パラメータの description 末尾に足す 1 文 (直前の文は句点で閉じてから連結する)。
|
|
@@ -30,22 +20,37 @@ import { toPosixPath } from '../windows-path.js';
|
|
|
30
20
|
*/
|
|
31
21
|
export const WINDOWS_PATH_NOTE = String.raw `Windows-style paths (C:\... / \\wsl.localhost\<distro>\...) are accepted and `
|
|
32
22
|
+ 'converted to an absolute path under /mnt/<drive>/ or inside WSL.';
|
|
23
|
+
const WARNINGS_SCHEMA = z.array(z.string()).optional().describe('Warnings raised during the run (omitted when there are none). '
|
|
24
|
+
+ 'Beyond 100 warnings or 64KB, the last item tells how many were omitted');
|
|
33
25
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
data はツールごとに形が異なる (対応 CLI の --json 出力と同形) ため、共通スキーマでは
|
|
37
|
-
record として受け、同形性の検証は contract / parity テスト側で行う。
|
|
26
|
+
全ツール共通の outputSchema。ツールごとの項目は形が違うため開いた object にし、共通の 4 項目だけ名前を持たせる。
|
|
38
27
|
*/
|
|
39
|
-
export const TOOL_OUTPUT_SCHEMA = z.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
data: z.record(z.string(), z.unknown()).describe('Object with the details of the run'),
|
|
45
|
-
message: z.string().describe('One-line summary for the calling agent'),
|
|
46
|
-
stdout: z.string().optional().describe('Captured stdout (omitted when nothing was captured)'),
|
|
47
|
-
stderr: z.string().optional().describe('Captured stderr (omitted when nothing was captured)'),
|
|
28
|
+
export const TOOL_OUTPUT_SCHEMA = z.looseObject({
|
|
29
|
+
kind: z.string().optional().describe('Failure kind (failure only)'),
|
|
30
|
+
detail: z.string().optional().describe('Full text of the failure and how to recover (failure only)'),
|
|
31
|
+
log: z.string().optional().describe('Raw output of the command or child process (failure only). Over 64KB, the end is kept and the first line notes the truncation'),
|
|
32
|
+
warnings: WARNINGS_SCHEMA,
|
|
48
33
|
});
|
|
34
|
+
function stringArrayOf(value) {
|
|
35
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
捕捉した出力を ToolResult の data へ移す。warning の文は warnings へ (既にある文と重ねて重複を除く)、
|
|
39
|
+
失敗のときは出力の全体を log へ入れる。
|
|
40
|
+
*/
|
|
41
|
+
export function withCapturedOutput(result, captured) {
|
|
42
|
+
const existing = stringArrayOf(result.data['warnings']);
|
|
43
|
+
const warnings = [...new Set([...existing, ...(captured.warnings ?? warningsOf(captured.stderr))])];
|
|
44
|
+
const log = result.ok ? '' : joinCapturedText([captured.stdout, captured.stderr]);
|
|
45
|
+
return {
|
|
46
|
+
...result,
|
|
47
|
+
data: {
|
|
48
|
+
...result.data,
|
|
49
|
+
...((warnings.length > 0 || 'warnings' in result.data) && { warnings }),
|
|
50
|
+
...(log !== '' && { log }),
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
49
54
|
/**
|
|
50
55
|
MCP サーバの process.stdout は JSON-RPC 専有なので、コマンドの出力は必ずここへ逃がす。
|
|
51
56
|
*/
|
|
@@ -55,35 +60,38 @@ export function captureCommandOutput() {
|
|
|
55
60
|
return {
|
|
56
61
|
stdout: stdout.stream,
|
|
57
62
|
stderr: stderr.stream,
|
|
58
|
-
|
|
63
|
+
finish: result => toCallToolResult(withCapturedOutput(result, { stdout: stdout.text(), stderr: stderr.text(), warnings: stderr.warnings() })),
|
|
64
|
+
warnings: () => stderr.warnings(),
|
|
59
65
|
};
|
|
60
66
|
}
|
|
61
67
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
Writable を通さない出力にも、captureCommandOutput と同じ上限をかけるための関数。
|
|
65
|
-
空でもキーを残すのは CommandOutput.part() と同じ契約。
|
|
68
|
+
子プロセスの出力を result の data へ移す。warning は切り詰める前の stderr の全体から取る。
|
|
66
69
|
*/
|
|
67
|
-
export function
|
|
68
|
-
return {
|
|
69
|
-
stdout: truncateCapturedText(result.stdout),
|
|
70
|
-
stderr: truncateCapturedText(result.stderr),
|
|
71
|
-
};
|
|
70
|
+
export function withSpawnOutput(result, spawned) {
|
|
71
|
+
return withCapturedOutput(result, { stdout: spawned.stdout, stderr: spawned.stderr });
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
|
|
74
|
+
ツールの失敗の detail に載せる 1 行の理由。
|
|
75
75
|
*/
|
|
76
76
|
export function formatError(error) {
|
|
77
77
|
/* c8 ignore next -- 非 Error 例外は本実装範囲では未発生、false 分岐は防御網のみ */
|
|
78
78
|
return error instanceof Error ? error.message : String(error);
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
|
|
81
|
+
文面の違反で生成を止めたときの直し方。drawio_create と evidence_create で同じ文言にする。
|
|
82
82
|
*/
|
|
83
83
|
export function textViolationMessage(count) {
|
|
84
84
|
return `${count.toString()} text violations; fix the text without loosening the rules, then run again`;
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
|
+
失敗の detail。文面の違反なら、違反の一覧に直し方の 1 行を足す。
|
|
88
|
+
*/
|
|
89
|
+
export function failureDetailOf(error, data) {
|
|
90
|
+
const violationCount = violationCountOf(data);
|
|
91
|
+
const detail = formatError(error);
|
|
92
|
+
return violationCount === undefined ? detail : `${detail}\n${textViolationMessage(violationCount)}`;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
87
95
|
errorData の data から、文面の違反の件数を取る。違反を持たない失敗は undefined。
|
|
88
96
|
*/
|
|
89
97
|
export function violationCountOf(data) {
|
|
@@ -91,14 +99,6 @@ export function violationCountOf(data) {
|
|
|
91
99
|
return Array.isArray(violations) ? violations.length : undefined;
|
|
92
100
|
}
|
|
93
101
|
/**
|
|
94
|
-
chromium 不在 / 取得失敗で実処理を諦めたときの exit code (各コマンドの RuntimeError と同じ 1)。
|
|
95
|
-
*/
|
|
96
|
-
export const CHROMIUM_UNAVAILABLE_EXIT_CODE = 1;
|
|
97
|
-
/**
|
|
98
|
-
実行時依存 (永続層) 不在 / 取得失敗で実処理を諦めたときの exit code。
|
|
99
|
-
*/
|
|
100
|
-
export const RUNTIME_UNAVAILABLE_EXIT_CODE = 1;
|
|
101
|
-
/**
|
|
102
102
|
永続層の場所を特定できないときに利用者向けの応答へ載せる既定の表記。
|
|
103
103
|
*/
|
|
104
104
|
export const RUNTIME_ROOT_PLACEHOLDER = '<data-dir>/mcp-dist';
|
|
@@ -179,7 +179,7 @@ function chromiumFailureReason(result) {
|
|
|
179
179
|
return `download timed out${NETWORK_HINT}`;
|
|
180
180
|
if (result.exitCode === null) {
|
|
181
181
|
return result.signal === null
|
|
182
|
-
? 'could not start the download command (see
|
|
182
|
+
? 'could not start the download command (see log for the reason); rebuild node_modules (pnpm install), then run again'
|
|
183
183
|
: `download command was interrupted by ${result.signal}; the download was cut off externally`;
|
|
184
184
|
}
|
|
185
185
|
return `download command exited with ${String(result.exitCode)}${NETWORK_HINT}`;
|
|
@@ -205,18 +205,14 @@ signal) {
|
|
|
205
205
|
if (!dependencies.isAutoInstallEnabled()) {
|
|
206
206
|
return {
|
|
207
207
|
ok: false,
|
|
208
|
-
exitCode: CHROMIUM_UNAVAILABLE_EXIT_CODE,
|
|
209
|
-
artifacts: [],
|
|
210
208
|
kind: 'chromium-not-installed',
|
|
209
|
+
detail: `cannot run ${label}: Playwright Chromium is not installed in ${expectedLocation(dependencies)}`
|
|
210
|
+
+ '; call the `runtime_setup` tool to download it (about 120MB)'
|
|
211
|
+
+ `; to automate the download, set ${AUTO_INSTALL_ENV}=1`,
|
|
211
212
|
data: {
|
|
212
213
|
event: 'chromium.unavailable',
|
|
213
|
-
reason: 'chromium-not-installed',
|
|
214
|
-
detail: `${label} needs Playwright Chromium, but it is not found in ${expectedLocation(dependencies)}`
|
|
215
|
-
+ '; call the `runtime_setup` tool to download it (about 120MB)'
|
|
216
|
-
+ `; to automate the download, set ${AUTO_INSTALL_ENV}=1`,
|
|
217
214
|
expectedAt: expectedLocation(dependencies),
|
|
218
215
|
},
|
|
219
|
-
message: `cannot run ${label}: Playwright Chromium is not installed; call the \`runtime_setup\` tool`,
|
|
220
216
|
};
|
|
221
217
|
}
|
|
222
218
|
const result = await dependencies.install(signal);
|
|
@@ -227,21 +223,16 @@ signal) {
|
|
|
227
223
|
const detail = result.exitCode === 0
|
|
228
224
|
? `download command succeeded, but chromium is not in ${expectedLocation(dependencies)}`
|
|
229
225
|
: chromiumInstallFailureDetail(result);
|
|
230
|
-
|
|
226
|
+
// playwright install は失敗原因を stdout に書くこともあるため、両方を log に入れる。
|
|
227
|
+
return withSpawnOutput({
|
|
231
228
|
ok: false,
|
|
232
|
-
exitCode: CHROMIUM_UNAVAILABLE_EXIT_CODE,
|
|
233
|
-
artifacts: [],
|
|
234
229
|
kind: 'chromium-install-failed',
|
|
230
|
+
detail: `cannot run ${label}: downloading chromium with ${AUTO_INSTALL_ENV}=1 failed: ${detail}`,
|
|
235
231
|
data: {
|
|
236
232
|
event: 'chromium.unavailable',
|
|
237
|
-
reason: 'chromium-install-failed',
|
|
238
|
-
detail: `downloading chromium with ${AUTO_INSTALL_ENV}=1 for ${label} failed: ${detail}`,
|
|
239
233
|
expectedAt: expectedLocation(dependencies),
|
|
240
234
|
},
|
|
241
|
-
|
|
242
|
-
// 失敗原因が stdout 側にあることもある (playwright install は進捗・取得先を stdout へ書く)。
|
|
243
|
-
...spawnOutputPart(result),
|
|
244
|
-
};
|
|
235
|
+
}, result);
|
|
245
236
|
}
|
|
246
237
|
export function runtimeDefaultDependencies() {
|
|
247
238
|
const manifestPath = path.join(resolvePluginRoot(), RUNTIME_MANIFEST_DIRECTORY, 'package.json');
|
|
@@ -282,17 +273,13 @@ export function ensureRuntimeDependencies(label, dependencies = runtimeDefaultDe
|
|
|
282
273
|
const expectedAt = dependencies.root() ?? RUNTIME_ROOT_PLACEHOLDER;
|
|
283
274
|
return {
|
|
284
275
|
ok: false,
|
|
285
|
-
exitCode: RUNTIME_UNAVAILABLE_EXIT_CODE,
|
|
286
|
-
artifacts: [],
|
|
287
276
|
kind: 'runtime-dependencies-not-installed',
|
|
277
|
+
detail: `cannot run ${label}: runtime dependencies are not installed`
|
|
278
|
+
+ ` (@slidev/cli / dom-to-pptx / @slidev/parser cannot be resolved); ${DEPENDENCY_RECOVERY_HINT}`,
|
|
288
279
|
data: {
|
|
289
280
|
event: 'runtime-dependencies.unavailable',
|
|
290
|
-
reason: 'runtime-dependencies-not-installed',
|
|
291
|
-
detail: `${label} needs @slidev/cli / dom-to-pptx / @slidev/parser, which cannot be resolved; `
|
|
292
|
-
+ DEPENDENCY_RECOVERY_HINT,
|
|
293
281
|
expectedAt,
|
|
294
282
|
},
|
|
295
|
-
message: `cannot run ${label}: runtime dependencies are not installed; call the \`runtime_setup\` tool`,
|
|
296
283
|
};
|
|
297
284
|
}
|
|
298
285
|
/**
|
|
@@ -7,18 +7,18 @@
|
|
|
7
7
|
// deps はハンドラ内で毎回組み立てる。既定 deps ファクトリは CLAUDE_PLUGIN_ROOT 未設定で throw する。
|
|
8
8
|
// module top-level で評価すると、サーバ起動と tools/list がまとめて落ちる。
|
|
9
9
|
import { z } from 'zod';
|
|
10
|
-
import { assertOutputExtension as assertDrawioExportOutputExtension, drawioExportDefaultDependencies, errorToReason as drawioExportErrorToReason, executeDrawioExport,
|
|
11
|
-
import { drawioUrlDefaultDependencies, errorData as drawioUrlErrorData, errorToReason as drawioUrlErrorToReason, executeDrawioUrl,
|
|
10
|
+
import { assertOutputExtension as assertDrawioExportOutputExtension, drawioExportDefaultDependencies, errorToReason as drawioExportErrorToReason, executeDrawioExport, } from '../../commands/drawio/export.js';
|
|
11
|
+
import { drawioUrlDefaultDependencies, errorData as drawioUrlErrorData, errorToReason as drawioUrlErrorToReason, executeDrawioUrl, } from '../../commands/drawio/url.js';
|
|
12
12
|
import { createDiagnostics } from '../../diagnostics.js';
|
|
13
13
|
import { failureKindOf } from '../../domain/_shared/failure-kind.js';
|
|
14
14
|
import { resolvePluginRoot } from '../../infra/_shared/plugin-root.js';
|
|
15
15
|
import { defaultIconRoot } from '../../infra/drawio/icons.js';
|
|
16
|
-
import { parsePathArguments, toCallToolResult } from '../result.js';
|
|
17
|
-
import { captureCommandOutput, chromiumDefaultDependencies, ensureChromium,
|
|
16
|
+
import { parsePathArguments, toCallToolResult, withoutCommonFailureFields } from '../result.js';
|
|
17
|
+
import { captureCommandOutput, chromiumDefaultDependencies, ensureChromium, failureDetailOf, formatError, normalizeThemeArgument, TOOL_OUTPUT_SCHEMA, WINDOWS_PATH_NOTE, } from './_shared.js';
|
|
18
18
|
const drawioCreateInput = z.object({
|
|
19
19
|
input_path: z.string().describe('Absolute path of the input .drawio file. ' + WINDOWS_PATH_NOTE),
|
|
20
20
|
mode: z.enum(['view', 'edit']).describe('Purpose of the generated URL (view / edit). The generated URL is the same for both').default('view'),
|
|
21
|
-
out_path: z.string().describe('Absolute path of the .html file to write the viewer HTML to (opening it redirects to draw.io). If omitted, only the URL is returned in
|
|
21
|
+
out_path: z.string().describe('Absolute path of the .html file to write the viewer HTML to (opening it redirects to draw.io). If omitted, only the URL is returned in url. ' + WINDOWS_PATH_NOTE).optional(),
|
|
22
22
|
theme: z.string()
|
|
23
23
|
.describe('Theme used to check the font and font size: `git+https://<host>/<owner>/<repo>.git#<tag>`, `file:<absolute path>`, '
|
|
24
24
|
+ 'or the absolute path of a talk-dir or a theme root. If omitted, the theme of the talk-dir is used when the diagram is under its `public/`; '
|
|
@@ -35,14 +35,17 @@ const drawioExportInput = z.object({
|
|
|
35
35
|
pdf: z.boolean().describe('Whether to also write a PDF as a sibling file (<out_path with the extension replaced by .pdf>) alongside the SVG').default(true),
|
|
36
36
|
});
|
|
37
37
|
/**
|
|
38
|
-
PNG を出せなかったときの exit code。CLI の「警告あり」と同じ 3 に揃える。
|
|
39
|
-
*/
|
|
40
|
-
const PNG_SKIPPED_EXIT_CODE = 3;
|
|
41
|
-
/**
|
|
42
38
|
message 末尾の警告件数サフィックス。drawio_create / drawio_export で表記を揃える。
|
|
43
39
|
*/
|
|
44
40
|
function warningSuffix(warningCount) {
|
|
45
|
-
return warningCount > 0 ? ` (${String(warningCount)} warnings;
|
|
41
|
+
return warningCount > 0 ? ` (${String(warningCount)} warnings; see warnings)` : '';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
CLI の `--json` の `warnings` は件数。MCP では warnings を捕捉した文の配列にするため、件数を外す (件数は配列の長さで分かる)。
|
|
45
|
+
*/
|
|
46
|
+
function withoutWarningCount(data) {
|
|
47
|
+
const { warnings: _count, ...rest } = data;
|
|
48
|
+
return rest;
|
|
46
49
|
}
|
|
47
50
|
function drawioCreateMessage(outputFile, warningCount) {
|
|
48
51
|
const warnings = warningSuffix(warningCount);
|
|
@@ -54,22 +57,20 @@ function drawioCreateMessage(outputFile, warningCount) {
|
|
|
54
57
|
chromium 不在で PNG を諦めたときの結果を、CLI の degrade と同形に寄せる (SC-002)。
|
|
55
58
|
|
|
56
59
|
CLI (`pecotv drawio url`) は PNG 生成の失敗を warning に格下げする。
|
|
57
|
-
表示用 HTML は書いたうえで、`png: null` / `pngFailed: true` /
|
|
60
|
+
表示用 HTML は書いたうえで、`png: null` / `pngFailed: true` / warning 1 件を返す。
|
|
58
61
|
MCP だけが実処理の前に hard-fail すると、CLI と結果が食い違う。
|
|
59
62
|
degrade できる条件はこれだけ。drawio_export と slide_convert は、chromium が無いと成果物を 1 つも作れない。
|
|
60
|
-
|
|
63
|
+
項目は CLI の PNG 失敗時と同一にし、`runtime_setup` の誘導は message へ載せる。
|
|
61
64
|
*/
|
|
62
|
-
function degradeToPngSkipped(execution, unavailable) {
|
|
65
|
+
function degradeToPngSkipped(execution, unavailable, warningCount) {
|
|
63
66
|
return {
|
|
64
|
-
exitCode: PNG_SKIPPED_EXIT_CODE,
|
|
65
67
|
data: {
|
|
66
|
-
...execution.data,
|
|
68
|
+
...withoutWarningCount(execution.data),
|
|
67
69
|
// eslint-disable-next-line unicorn/no-null -- PNG 失敗時に png: null を返すことが CLI との契約
|
|
68
70
|
png: null,
|
|
69
71
|
pngFailed: true,
|
|
70
|
-
warnings: execution.warningCount + 1,
|
|
71
72
|
},
|
|
72
|
-
message: `${drawioCreateMessage(execution.outputFile,
|
|
73
|
+
message: `${drawioCreateMessage(execution.outputFile, warningCount)}: ${unavailable.detail}`,
|
|
73
74
|
};
|
|
74
75
|
}
|
|
75
76
|
const handleDrawioCreate = async (arguments_,
|
|
@@ -85,11 +86,9 @@ call) => {
|
|
|
85
86
|
const detail = normalized.detail;
|
|
86
87
|
return toCallToolResult({
|
|
87
88
|
ok: false,
|
|
88
|
-
exitCode: 2,
|
|
89
89
|
kind: 'invalid-option',
|
|
90
|
-
|
|
91
|
-
data: { event: 'drawio.url.error'
|
|
92
|
-
message: `pecotv drawio url: ${detail}`,
|
|
90
|
+
detail: `pecotv drawio url: ${detail}`,
|
|
91
|
+
data: { event: 'drawio.url.error' },
|
|
93
92
|
});
|
|
94
93
|
}
|
|
95
94
|
// PNG を書くときだけ chromium が要る。out_path 省略時と png: false は URL 生成だけで完結する。
|
|
@@ -97,39 +96,29 @@ call) => {
|
|
|
97
96
|
? await ensureChromium('drawio_create PNG output', chromiumDefaultDependencies(), call.signal)
|
|
98
97
|
: undefined;
|
|
99
98
|
const output = captureCommandOutput();
|
|
100
|
-
// CLI
|
|
101
|
-
// 同じ行を残して、「警告 N 件、詳細は stderr」という message を CLI と MCP で同じ意味にする。
|
|
99
|
+
// CLI と同じく PNG の失敗を warning の行に書き、warnings に入れる。
|
|
102
100
|
if (unavailable !== undefined)
|
|
103
|
-
createDiagnostics(output.stderr).warning(`PNG export failed: ${unavailable.
|
|
101
|
+
createDiagnostics(output.stderr).warning(`PNG export failed: ${unavailable.detail}`);
|
|
104
102
|
try {
|
|
105
103
|
const execution = await executeDrawioUrl(input.input_path,
|
|
106
104
|
// chromium が無いときは PNG を要求せずに実行する (表示用 HTML の生成は成立する)。
|
|
107
105
|
{ mode: input.mode, png: input.png && unavailable === undefined, theme: normalized?.theme, output: input.out_path }, { ...drawioUrlDefaultDependencies(), stdout: output.stdout, stderr: output.stderr, signal: call.signal });
|
|
108
|
-
// 警告あり (
|
|
109
|
-
|
|
106
|
+
// 警告あり (CLI の exit 3) でも URL の生成そのものは完了しているので成功で返す。file・png の項目が CLI の artifacts と同じパスを持つ。
|
|
107
|
+
return output.finish({
|
|
110
108
|
ok: true,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
...(unavailable !== undefined && degradeToPngSkipped(execution, unavailable)),
|
|
116
|
-
...output.part(),
|
|
117
|
-
};
|
|
118
|
-
return toCallToolResult(result);
|
|
109
|
+
data: withoutWarningCount(execution.data),
|
|
110
|
+
message: drawioCreateMessage(execution.outputFile, output.warnings().length),
|
|
111
|
+
...(unavailable !== undefined && degradeToPngSkipped(execution, unavailable, output.warnings().length)),
|
|
112
|
+
});
|
|
119
113
|
}
|
|
120
114
|
catch (error) {
|
|
121
115
|
const data = drawioUrlErrorData(error);
|
|
122
|
-
|
|
123
|
-
const result = {
|
|
116
|
+
return output.finish({
|
|
124
117
|
ok: false,
|
|
125
|
-
exitCode: drawioUrlToExitCode(error),
|
|
126
118
|
kind: failureKindOf(drawioUrlErrorToReason(error)),
|
|
127
|
-
|
|
128
|
-
data,
|
|
129
|
-
|
|
130
|
-
...output.part(),
|
|
131
|
-
};
|
|
132
|
-
return toCallToolResult(result);
|
|
119
|
+
detail: `pecotv drawio url: ${failureDetailOf(error, data)}`,
|
|
120
|
+
data: withoutCommonFailureFields(data),
|
|
121
|
+
});
|
|
133
122
|
}
|
|
134
123
|
};
|
|
135
124
|
const handleDrawioExport = async (arguments_,
|
|
@@ -159,41 +148,33 @@ call) => {
|
|
|
159
148
|
const output = captureCommandOutput();
|
|
160
149
|
try {
|
|
161
150
|
const execution = await executeDrawioExport(input.input_path, { icons: iconsRoot, output: input.out_path, printHash: input.print_hash, pdf: input.pdf }, { ...drawioExportDefaultDependencies(), stdout: output.stdout, stderr: output.stderr });
|
|
162
|
-
// 警告あり (
|
|
163
|
-
|
|
151
|
+
// 警告あり (CLI の exit 3。PDF 生成失敗) でも SVG の書き出しは完了しているので成功で返す。file・pdf の項目が CLI の artifacts と同じパスを持つ。
|
|
152
|
+
return output.finish({
|
|
164
153
|
ok: true,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
message: drawioExportMessage(execution),
|
|
169
|
-
...output.part(),
|
|
170
|
-
};
|
|
171
|
-
return toCallToolResult(result);
|
|
154
|
+
data: withoutWarningCount(execution.data),
|
|
155
|
+
message: drawioExportMessage(execution, output.warnings().length),
|
|
156
|
+
});
|
|
172
157
|
}
|
|
173
158
|
catch (error) {
|
|
174
|
-
return
|
|
159
|
+
return output.finish(drawioExportFailure(error));
|
|
175
160
|
}
|
|
176
161
|
};
|
|
177
162
|
/**
|
|
178
163
|
drawio_export の失敗を CLI の `--json` エラーと同形の ToolResult に写す。
|
|
179
164
|
*/
|
|
180
165
|
function drawioExportFailure(error) {
|
|
181
|
-
const detail = formatError(error);
|
|
182
|
-
const reason = drawioExportErrorToReason(error);
|
|
183
166
|
return {
|
|
184
167
|
ok: false,
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
data: { event: 'drawio.export.error', reason, detail },
|
|
189
|
-
message: `pecotv drawio export: ${detail}`,
|
|
168
|
+
kind: failureKindOf(drawioExportErrorToReason(error)),
|
|
169
|
+
detail: `pecotv drawio export: ${formatError(error)}`,
|
|
170
|
+
data: { event: 'drawio.export.error' },
|
|
190
171
|
};
|
|
191
172
|
}
|
|
192
|
-
function drawioExportMessage(execution) {
|
|
173
|
+
function drawioExportMessage(execution, warningCount) {
|
|
193
174
|
if (execution.outputFile === undefined)
|
|
194
175
|
return `computed composite hash: ${execution.sourceSha256}`;
|
|
195
176
|
const pdf = execution.pdfFile === undefined ? '' : ` (PDF: ${execution.pdfFile})`;
|
|
196
|
-
return `wrote SVG to ${execution.outputFile}${pdf}${warningSuffix(
|
|
177
|
+
return `wrote SVG to ${execution.outputFile}${pdf}${warningSuffix(warningCount)}`;
|
|
197
178
|
}
|
|
198
179
|
// annotations は SDK 既定 (readOnlyHint: false / openWorldHint: true) と一致するため付けない。
|
|
199
180
|
// どちらのツールもファイルを書き、PNG 生成では viewer.diagrams.net、SVG 生成では embed.diagrams.net へ到達する。
|
|
@@ -201,7 +182,7 @@ export const drawioCreateTool = {
|
|
|
201
182
|
name: 'drawio_create',
|
|
202
183
|
config: {
|
|
203
184
|
title: 'Output a drawio diagram as a deliverable',
|
|
204
|
-
description: 'Turns drawio XML into a deliverable that opens directly in a browser. Writes viewer HTML (.html; opening it redirects to draw.io) to out_path and, by default, also writes a rendered PNG (useful for checking the rendering). icon:// references are resolved to data URIs and embedded. Before generating, it checks the diagram labels against the text rules and generates nothing if there is a violation. The font and font size are checked against the theme declaration (theme, or the theme of the talk-dir that is an ancestor of the diagram), and the result is returned in
|
|
185
|
+
description: 'Turns drawio XML into a deliverable that opens directly in a browser. Writes viewer HTML (.html; opening it redirects to draw.io) to out_path and, by default, also writes a rendered PNG (useful for checking the rendering). icon:// references are resolved to data URIs and embedded. Before generating, it checks the diagram labels against the text rules and generates nothing if there is a violation. The font and font size are checked against the theme declaration (theme, or the theme of the talk-dir that is an ancestor of the diagram), and the result is returned in theme.',
|
|
205
186
|
inputSchema: drawioCreateInput,
|
|
206
187
|
outputSchema: TOOL_OUTPUT_SCHEMA,
|
|
207
188
|
},
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
// evidence 系の MCP ツール定義 (evidence_create)。
|
|
2
2
|
//
|
|
3
|
-
// ハンドラは既存 CLI と同じ executeEvidenceCreate
|
|
4
|
-
// オブジェクトをそのまま ToolResult.data に載せるため、CLI と MCP の結果は同形になる。
|
|
3
|
+
// ハンドラは既存 CLI と同じ executeEvidenceCreate を呼び、CLI の `--json` が出すオブジェクトをそのまま項目として返す。
|
|
5
4
|
import path from 'node:path';
|
|
6
5
|
import { z } from 'zod';
|
|
7
|
-
import { errorData, errorToReason,
|
|
6
|
+
import { errorData, errorToReason, evidenceCreateDefaultDependencies, executeEvidenceCreate, } from '../../commands/evidence-xlsx/create.js';
|
|
8
7
|
import { failureKindOf } from '../../domain/_shared/failure-kind.js';
|
|
9
|
-
import { parsePathArguments, toCallToolResult } from '../result.js';
|
|
10
|
-
import { captureCommandOutput,
|
|
8
|
+
import { parsePathArguments, toCallToolResult, withoutCommonFailureFields } from '../result.js';
|
|
9
|
+
import { captureCommandOutput, failureDetailOf, TOOL_OUTPUT_SCHEMA, WINDOWS_PATH_NOTE } from './_shared.js';
|
|
11
10
|
const evidenceCreateInput = z.object({
|
|
12
11
|
input_path: z.string().describe('Absolute path of the EvidenceSpec JSON. ' + WINDOWS_PATH_NOTE),
|
|
13
12
|
out_path: z.string().optional().describe('Absolute path of the xlsx to write. If omitted, evidence.xlsx in the same directory as input_path. ' + WINDOWS_PATH_NOTE),
|
|
@@ -37,28 +36,20 @@ async function handleEvidenceCreate(arguments_) {
|
|
|
37
36
|
};
|
|
38
37
|
const data = await executeEvidenceCreate({ input: input.input_path, out: input.out_path ?? defaultOutPath(input.input_path) }, dependencies);
|
|
39
38
|
const counts = `${String(data.items)} items; ${String(data.annotations)} annotations; ${String(data.skipped.length)} skipped`;
|
|
40
|
-
|
|
39
|
+
// 書いた xlsx のパスは outPath の項目で返す。
|
|
40
|
+
return output.finish({
|
|
41
41
|
ok: true,
|
|
42
|
-
exitCode: 0,
|
|
43
|
-
artifacts: [data.outPath],
|
|
44
42
|
data: { ...data },
|
|
45
43
|
message: `generated evidence xlsx: ${data.outPath} (${counts})`,
|
|
46
|
-
...output.part(),
|
|
47
44
|
});
|
|
48
45
|
}
|
|
49
46
|
catch (error) {
|
|
50
47
|
const data = errorData(error);
|
|
51
|
-
|
|
52
|
-
return toCallToolResult({
|
|
48
|
+
return output.finish({
|
|
53
49
|
ok: false,
|
|
54
|
-
// usage エラー (exit 2) は commander の引数検証にしか無い。MCP では
|
|
55
|
-
// inputSchema と parsePathArguments が先に弾くため、ここは実行失敗の 1 のみ。
|
|
56
|
-
exitCode: EVIDENCE_CREATE_FAILURE_EXIT_CODE,
|
|
57
50
|
kind: failureKindOf(errorToReason(error)),
|
|
58
|
-
|
|
59
|
-
data,
|
|
60
|
-
message: violationCount === undefined ? formatError(error) : textViolationMessage(violationCount),
|
|
61
|
-
...output.part(),
|
|
51
|
+
detail: failureDetailOf(error, data),
|
|
52
|
+
data: withoutCommonFailureFields(data),
|
|
62
53
|
});
|
|
63
54
|
}
|
|
64
55
|
}
|
|
@@ -30,7 +30,7 @@ import { z } from 'zod';
|
|
|
30
30
|
import { LOCK_CONFLICT_EXIT_CODE, LOCK_WAIT_SECONDS } from '../../infra/_shared/flock.js';
|
|
31
31
|
import { ensureChromiumHostDependencies, hostDependenciesDefaultDependencies, } from '../../infra/playwright/host-dependencies.js';
|
|
32
32
|
import { toCallToolResult } from '../result.js';
|
|
33
|
-
import {
|
|
33
|
+
import { chromiumDefaultDependencies, chromiumInstallFailureDetail, runtimeDefaultDependencies, tlsCertificateHint, TOOL_OUTPUT_SCHEMA, withSpawnOutput, } from './_shared.js';
|
|
34
34
|
/**
|
|
35
35
|
実行時依存を取得する。
|
|
36
36
|
|
|
@@ -79,10 +79,10 @@ function runtimeFailureReason(result) {
|
|
|
79
79
|
}
|
|
80
80
|
if (result.exitCode === null) {
|
|
81
81
|
return result.signal === null
|
|
82
|
-
? 'could not start npm (see
|
|
82
|
+
? 'could not start npm (see log for the reason)'
|
|
83
83
|
: `download command was interrupted by ${result.signal}; the download was cut off externally`;
|
|
84
84
|
}
|
|
85
|
-
return `npm install exited with ${String(result.exitCode)} (see
|
|
85
|
+
return `npm install exited with ${String(result.exitCode)} (see log for the reason)`;
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
88
|
Chromium を取得する。取得済みでも Playwright 側が冪等に skip するため常に実行する。
|
|
@@ -157,15 +157,6 @@ function stageData(outcome) {
|
|
|
157
157
|
...(outcome.detail !== undefined && { detail: outcome.detail }),
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
|
-
/**
|
|
161
|
-
取得した実体の置き場所だけを artifacts に載せる。何も取得していなければ空。
|
|
162
|
-
*/
|
|
163
|
-
function artifactsOf(stages) {
|
|
164
|
-
return stages
|
|
165
|
-
.filter(stage => stage.downloaded)
|
|
166
|
-
.map(stage => stage.location)
|
|
167
|
-
.filter((location) => location !== undefined);
|
|
168
|
-
}
|
|
169
160
|
function successMessage(runtime, chromium, hostDependencies) {
|
|
170
161
|
const parts = [
|
|
171
162
|
runtime.downloaded
|
|
@@ -204,29 +195,24 @@ export function setupTool(buildDependencies = chromiumDefaultDependencies, build
|
|
|
204
195
|
const chromium = await runChromiumStage(buildDependencies(), call.signal);
|
|
205
196
|
// OS のライブラリは実行ファイルが揃ってからでないと起動で確かめられない。
|
|
206
197
|
const hostDependencies = chromium.installed ? await runHostDependenciesStage(buildHostDependencies(), call.signal) : undefined;
|
|
207
|
-
|
|
198
|
+
// 取得した実体の置き場所は runtime.location・chromium.location の項目で返す。
|
|
208
199
|
const data = {
|
|
209
200
|
runtime: stageData(runtime),
|
|
210
201
|
chromium: stageData(chromium),
|
|
211
202
|
...(hostDependencies !== undefined && { hostDeps: stageData(hostDependencies) }),
|
|
212
203
|
};
|
|
213
204
|
if (runtime.installed && chromium.installed && hostDependencies?.installed === true) {
|
|
214
|
-
|
|
205
|
+
return toCallToolResult(withSpawnOutput({
|
|
215
206
|
ok: true,
|
|
216
|
-
exitCode: 0,
|
|
217
|
-
// ダウンロードした実体の置き場所を成果物として返す。取得済みなら何も置いていない。
|
|
218
|
-
artifacts,
|
|
219
207
|
data: {
|
|
220
208
|
event: runtime.downloaded || chromium.downloaded || hostDependencies.downloaded ? 'setup.done' : 'setup.skipped',
|
|
221
209
|
...data,
|
|
222
210
|
},
|
|
223
211
|
message: successMessage(runtime, chromium, hostDependencies),
|
|
224
|
-
|
|
225
|
-
};
|
|
226
|
-
return toCallToolResult(result);
|
|
212
|
+
}, chromium.spawned ?? emptySpawn()));
|
|
227
213
|
}
|
|
228
214
|
// 両系統が失敗することもある (ネットワーク断・プロキシ誤設定では両方が落ちる)。
|
|
229
|
-
// 片方だけを見ると、もう片方の理由が
|
|
215
|
+
// 片方だけを見ると、もう片方の理由が <系統>.detail にしか残らず detail から
|
|
230
216
|
// 消えるため、失敗した系統を全て畳んで載せる。
|
|
231
217
|
const failures = [
|
|
232
218
|
...(runtime.installed ? [] : [{ label: 'runtime dependencies', reason: 'runtime-install-failed', stage: runtime }]),
|
|
@@ -235,33 +221,28 @@ export function setupTool(buildDependencies = chromiumDefaultDependencies, build
|
|
|
235
221
|
? []
|
|
236
222
|
: [{ label: 'Chromium OS libraries', reason: 'chromium-host-deps-missing', stage: hostDependencies }]),
|
|
237
223
|
];
|
|
238
|
-
const detail = failures.map(failure => `${failure.label}: ${failure.stage.detail ?? ''}`).join(' / ');
|
|
239
224
|
// OS ライブラリの失敗は「取得」ではなく「足りない」ことを案内するため、取得の失敗と分ける。
|
|
240
225
|
// その detail は足りないライブラリと入れるコマンドまで書いた文なので、前置きを付けずに載せる。
|
|
241
226
|
const acquisitionFailures = failures.filter(failure => failure.reason !== 'chromium-host-deps-missing');
|
|
242
227
|
const hostDependenciesDetail = failures.find(failure => failure.reason === 'chromium-host-deps-missing')?.stage.detail;
|
|
243
|
-
const
|
|
228
|
+
const detail = [
|
|
244
229
|
...(acquisitionFailures.length === 0
|
|
245
230
|
? []
|
|
246
231
|
: [`download failed for ${acquisitionFailures.map(failure => failure.label).join(' / ')}: `
|
|
247
232
|
+ acquisitionFailures.map(failure => `${failure.label}: ${failure.stage.detail ?? ''}`).join(' / ')]),
|
|
248
233
|
...(hostDependenciesDetail === undefined ? [] : [hostDependenciesDetail]),
|
|
249
234
|
].join(' / ');
|
|
250
|
-
const result = {
|
|
235
|
+
const result = withSpawnOutput({
|
|
251
236
|
ok: false,
|
|
252
|
-
|
|
253
|
-
// data.reason は失敗した段をカンマでつなぐ。kind には最初に失敗した段の名前を入れる。
|
|
237
|
+
// reason (runtime_setup の項目) は失敗した段をカンマでつなぐ。kind には最初に失敗した段の名前を入れる。
|
|
254
238
|
kind: failures[0]?.reason ?? 'unknown',
|
|
255
|
-
|
|
239
|
+
detail,
|
|
256
240
|
data: {
|
|
257
241
|
event: 'setup.error',
|
|
258
242
|
reason: failures.map(failure => failure.reason).join(','),
|
|
259
|
-
detail,
|
|
260
243
|
...data,
|
|
261
244
|
},
|
|
262
|
-
|
|
263
|
-
...spawnOutputPart(mergeSpawned(failures.map(failure => failure.stage.spawned))),
|
|
264
|
-
};
|
|
245
|
+
}, mergeSpawned(failures.map(failure => failure.stage.spawned)));
|
|
265
246
|
return toCallToolResult(result);
|
|
266
247
|
};
|
|
267
248
|
return {
|
|
@@ -288,17 +269,14 @@ export function setupTool(buildDependencies = chromiumDefaultDependencies, build
|
|
|
288
269
|
};
|
|
289
270
|
}
|
|
290
271
|
/**
|
|
291
|
-
取得を飛ばした系統には子プロセスが無い。
|
|
272
|
+
取得を飛ばした系統には子プロセスが無い。
|
|
292
273
|
*/
|
|
293
274
|
function emptySpawn() {
|
|
294
275
|
// eslint-disable-next-line unicorn/no-null -- SpawnResult は起動なしを exitCode: null で表す
|
|
295
276
|
return { exitCode: null, signal: null, stdout: '', stderr: '', timedOut: false };
|
|
296
277
|
}
|
|
297
278
|
/**
|
|
298
|
-
失敗した系統の出力を 1
|
|
299
|
-
|
|
300
|
-
ToolResult の stdout / stderr は 1 組しか持てないため、両系統が失敗したときは
|
|
301
|
-
どちらの出力も落とさずに連結する (原因が stdout 側にあることもある)。
|
|
279
|
+
失敗した系統の出力を 1 つに畳む。両系統が失敗しても、どちらの出力も log に残す。
|
|
302
280
|
*/
|
|
303
281
|
function mergeSpawned(spawned) {
|
|
304
282
|
const present = spawned.filter((result) => result !== undefined);
|