@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
package/README.md
CHANGED
|
@@ -106,8 +106,8 @@ WSL 内の npx が非ログインシェルの PATH に無い場合は、次の
|
|
|
106
106
|
|
|
107
107
|
ツールのパス引数には `C:\...` と `\\wsl.localhost\<distro>\...` をそのまま渡せます。
|
|
108
108
|
変換の対象はツール引数のみです。spec ファイル等の中身に書かれたパスは変換しません。
|
|
109
|
-
|
|
110
|
-
WSL 内の絶対パス(例: `/home/alice/deck
|
|
109
|
+
応答のパスの項目(`file`・`outPath` など)は、WSL 内のパスで返ります。
|
|
110
|
+
ドライブレター形式なら `/mnt/<drive>/...`、UNC 形式なら WSL 内の絶対パス(例: `/home/alice/deck`)です。
|
|
111
111
|
`/etc/wsl.conf` の `[automount] root` を既定から変えている場合は、その値を環境変数
|
|
112
112
|
`PECOTV_WSL_MOUNT_ROOT` に設定してください。
|
|
113
113
|
|
|
@@ -2,7 +2,7 @@ export declare const FAILURE_KINDS: readonly ['broken-reference', 'cancelled', '
|
|
|
2
2
|
export type FailureKind = typeof FAILURE_KINDS[number];
|
|
3
3
|
export declare const CLI_ONLY_FAILURE_REASONS: readonly ['input-mutated', 'input-open-failed', 'invalid-mode', 'invalid-morph-option', 'invalid-transition-duration-ms', 'invalid-transition-type', 'missing-icons-root', 'missing-option', 'relative-dir', 'soffice-conversion-failed', 'soffice-not-found', 'soffice-timeout'];
|
|
4
4
|
/**
|
|
5
|
-
CLI の `--json`
|
|
5
|
+
CLI の `--json` の `reason` に載る失敗の名前。MCP は failureKindOf で kind に写して返す。
|
|
6
6
|
*/
|
|
7
7
|
export type FailureReason = FailureKind | typeof CLI_ONLY_FAILURE_REASONS[number];
|
|
8
8
|
export declare function isFailureKind(reason: string): reason is FailureKind;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// MCP ツールが失敗の結果の `kind
|
|
1
|
+
// MCP ツールが失敗の結果の `kind` で返しうる名前の一覧。
|
|
2
2
|
// 定義書の exit_status[].kind の集合との一致は、failure-kinds-definition.test.ts が確かめる。
|
|
3
3
|
// eslint-disable-next-line no-restricted-syntax -- 名前の一覧から型を作るため、要素をリテラルの型のまま残す
|
|
4
4
|
export const FAILURE_KINDS = [
|
|
@@ -76,6 +76,10 @@ export interface DevServerStartFailure {
|
|
|
76
76
|
readonly detail: string;
|
|
77
77
|
readonly stdout: string;
|
|
78
78
|
readonly stderr: string;
|
|
79
|
+
/**
|
|
80
|
+
子の stderr の warning の文。stderr の切り詰めと関係なく保つ。子を起こしていなければ省く。
|
|
81
|
+
*/
|
|
82
|
+
readonly warnings?: readonly string[];
|
|
79
83
|
}
|
|
80
84
|
export type DevServerStartResult = DevServerStarted | DevServerStartFailure;
|
|
81
85
|
export interface DevServerStopResult {
|
|
@@ -116,6 +116,7 @@ function trackChild(child, port, killEscalationMs) {
|
|
|
116
116
|
},
|
|
117
117
|
stdout: () => stdoutCapture.text(),
|
|
118
118
|
stderr: () => mergeStderr(stderrCapture.text(), spawnError),
|
|
119
|
+
warnings: () => stderrCapture.warnings(),
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
122
|
/**
|
|
@@ -205,6 +206,7 @@ export function createDevServerRegistry(dependencies = devServerDefaultDependenc
|
|
|
205
206
|
detail: failureDetailOf(outcome, handle.port, dependencies.readyTimeoutMs),
|
|
206
207
|
stdout: handle.stdout(),
|
|
207
208
|
stderr,
|
|
209
|
+
warnings: handle.warnings(),
|
|
208
210
|
},
|
|
209
211
|
};
|
|
210
212
|
};
|
|
@@ -306,6 +308,7 @@ function portInUseFailure(port, defaultPorts, raced) {
|
|
|
306
308
|
detail,
|
|
307
309
|
stdout: raced?.stdout ?? '',
|
|
308
310
|
stderr: raced?.stderr ?? '',
|
|
311
|
+
...(raced?.warnings !== undefined && { warnings: raced.warnings }),
|
|
309
312
|
};
|
|
310
313
|
}
|
|
311
314
|
/**
|
|
@@ -343,7 +346,7 @@ function failureReasonOf(outcome) {
|
|
|
343
346
|
function failureDetailOf(outcome, port, timeoutMs) {
|
|
344
347
|
switch (outcome) {
|
|
345
348
|
case 'exited': {
|
|
346
|
-
return `Slidev dev server on port ${String(port)} exited right after starting (see
|
|
349
|
+
return `Slidev dev server on port ${String(port)} exited right after starting (see log for the reason)`;
|
|
347
350
|
}
|
|
348
351
|
case 'timeout': {
|
|
349
352
|
return `Slidev dev server on port ${String(port)} did not become reachable within `
|
package/cli/dist/mcp/result.d.ts
CHANGED
|
@@ -2,64 +2,42 @@ import { Writable } from 'node:stream';
|
|
|
2
2
|
import type { CallToolResult } from '@modelcontextprotocol/server';
|
|
3
3
|
import type { z } from 'zod';
|
|
4
4
|
import type { FailureKind } from '../domain/_shared/failure-kind.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
readonly artifacts: readonly string[];
|
|
14
|
-
/**
|
|
15
|
-
ツール固有の構造化データ (URL・件数など)。
|
|
16
|
-
*/
|
|
5
|
+
/**
|
|
6
|
+
ツールの結果。toCallToolResult が MCP の CallToolResult に変える。
|
|
7
|
+
data はツールごとの項目で、structuredContent の最上位にそのまま並ぶ。共通の項目は tools/_shared.ts の TOOL_OUTPUT_SCHEMA。
|
|
8
|
+
*/
|
|
9
|
+
export type ToolResult = SucceededToolResult | FailedToolResult;
|
|
10
|
+
export interface SucceededToolResult {
|
|
11
|
+
readonly ok: true;
|
|
12
|
+
readonly kind?: never;
|
|
17
13
|
readonly data: Readonly<Record<string, unknown>>;
|
|
18
14
|
/**
|
|
19
|
-
|
|
15
|
+
content の 1 つ目の text に入る文。空なら JSON の text だけを返す。
|
|
20
16
|
*/
|
|
21
17
|
readonly message: string;
|
|
18
|
+
}
|
|
19
|
+
export interface FailedToolResult {
|
|
20
|
+
readonly ok: false;
|
|
21
|
+
readonly kind: FailureKind;
|
|
22
22
|
/**
|
|
23
|
-
|
|
23
|
+
失敗の全文と直し方。structuredContent の detail と、content の 1 つ目の text に入る。
|
|
24
24
|
*/
|
|
25
|
-
readonly
|
|
25
|
+
readonly detail: string;
|
|
26
26
|
/**
|
|
27
|
-
|
|
27
|
+
途中まで進んだ分の項目。kind・detail と同じ名前は共通の値で上書きされる。
|
|
28
28
|
*/
|
|
29
|
-
readonly
|
|
29
|
+
readonly data: Readonly<Record<string, unknown>>;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
|
|
32
|
+
content は文の text と、structuredContent と 1 字も違わない JSON の text (MCP の仕様の SHOULD)。
|
|
33
33
|
*/
|
|
34
|
-
export
|
|
35
|
-
export type SucceededToolResult = ToolResultFields & {
|
|
36
|
-
readonly ok: true;
|
|
37
|
-
readonly kind?: never;
|
|
38
|
-
};
|
|
39
|
-
export type FailedToolResult = ToolResultFields & {
|
|
40
|
-
readonly ok: false;
|
|
41
|
-
readonly kind: FailureKind;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
stdout / stderr を呼び出し側が付ける前の ToolResult。Omit<ToolResult> では ok と kind の対応が崩れる。
|
|
45
|
-
*/
|
|
46
|
-
export type ToolResultBody = Omit<SucceededToolResult, 'stdout' | 'stderr'> | Omit<FailedToolResult, 'stdout' | 'stderr'>;
|
|
34
|
+
export declare function toCallToolResult(result: Readonly<ToolResult>): CallToolResult;
|
|
47
35
|
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
content には structuredContent と同じ内容の JSON テキストを載せる。structuredContent を
|
|
51
|
-
読めないクライアントでもツール結果を解釈できるようにするための二重化で、
|
|
52
|
-
MCP 仕様が推奨する形。
|
|
53
|
-
|
|
54
|
-
引数は deep readonly だが、戻り値は SDK 側の mutable 型のまま返す。
|
|
55
|
-
SDK が readonly 型を公開していないため、この非対称は境界として許容する。
|
|
36
|
+
CLI の `--json` の失敗の payload から、共通の項目と重なる reason・detail を外す。原因の名前は kind、全文は detail で返すため。
|
|
56
37
|
*/
|
|
57
|
-
export declare function
|
|
38
|
+
export declare function withoutCommonFailureFields(data: Readonly<Record<string, unknown>>): Record<string, unknown>;
|
|
58
39
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
拒否用の ToolResult と検証済み引数を 1 つの戻り値に畳むのは、ハンドラ側で
|
|
62
|
-
「確認は通したが変換前の値を使う」という取り違えを型として起こせなくするため。
|
|
40
|
+
1 つの戻り値に畳み、確認を通した後に変換前の値を使う取り違えを型で防ぐ。
|
|
63
41
|
*/
|
|
64
42
|
export type PathArgumentsResult<Output> = {
|
|
65
43
|
readonly rejected: ToolResult;
|
|
@@ -69,33 +47,18 @@ export type PathArgumentsResult<Output> = {
|
|
|
69
47
|
readonly input: Output;
|
|
70
48
|
};
|
|
71
49
|
/**
|
|
72
|
-
引数の parse
|
|
73
|
-
|
|
74
|
-
受理したときは変換済みの値を載せた同型オブジェクトを返す。ハンドラ側に未変換の束縛を残さないための形にしている。
|
|
75
|
-
パスを下流へ渡すルートが 1 箇所でも取りこぼすと、Windows のクライアントには「変換されたりされなかったり」に見える。
|
|
76
|
-
そのため確認と変換を別々の関数に割らない。
|
|
77
|
-
|
|
78
|
-
拒否するのは (1) Windows 形式だが POSIX パスへ畳めないもの (他 distro の UNC 等) と
|
|
79
|
-
(2) 変換後も絶対パスにならないものの 2 つ。両方が同じ呼び出しに含まれるときは、
|
|
80
|
-
一方を返して他方を隠すと利用者が取りこぼすため invalidPaths に両方を列挙する。
|
|
81
|
-
message は解決不能側 (1) を主文にする。cwd 依存の曖昧さより「渡した値をそもそも
|
|
82
|
-
解釈できない」方が原因の特定に時間がかかるため。MCP クライアントの cwd はサーバ
|
|
83
|
-
プロセスの cwd と一致する保証が無いため、相対パスは解決せず即座に弾く。invalidPaths
|
|
84
|
-
には利用者が渡した元の値を載せる (変換後の値だけを見せると、渡した引数との対応が取れない)。
|
|
85
|
-
|
|
86
|
-
見るのは「cwd 非依存で一意に解決できるか」だけで、`/a/../etc/passwd` のような
|
|
87
|
-
`..` を含む絶対パスは通す。FR-011 は cwd の曖昧さを排除する規約で、
|
|
88
|
-
サンドボックス境界ではない。アクセス範囲の制限は本関数の責務ではない。
|
|
50
|
+
引数の parse と、パス引数の変換・絶対パスの確認 (FR-011) を 1 つで行う。分けると変換の取りこぼしが起きるため。
|
|
51
|
+
`..` を含む絶対パスは通す。FR-011 は cwd の曖昧さを除く決まりで、アクセス範囲の制限ではない。
|
|
89
52
|
*/
|
|
90
53
|
export declare function parsePathArguments<Output extends Readonly<Record<string, unknown>>>(schema: z.ZodType<Output>, arguments_: Readonly<Record<string, unknown>>, keys: readonly (keyof Output & string)[]): PathArgumentsResult<Output>;
|
|
91
54
|
/**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
子プロセスの結果 (SpawnResult) のように Writable を経由しない出力にも同じ上限を働かせる
|
|
95
|
-
ためのエントリ。上限を超える出力をそのまま ToolResult に載せると、エージェントのコンテキストを
|
|
96
|
-
際限なく食う (`playwright install` は非 TTY でも進捗を stdout へ書く)。
|
|
55
|
+
Writable を通さない出力 (SpawnResult) を、出力の捕捉と同じ上限・同じマーカーで切り詰める。
|
|
97
56
|
*/
|
|
98
57
|
export declare function truncateCapturedText(text: string): string;
|
|
58
|
+
/**
|
|
59
|
+
捕捉した出力をつないで上限で切り詰める。各部分の切り詰めのマーカーは外し、印を冒頭の 1 つにまとめる。
|
|
60
|
+
*/
|
|
61
|
+
export declare function joinCapturedText(parts: readonly string[]): string;
|
|
99
62
|
export interface OutputCapture {
|
|
100
63
|
/**
|
|
101
64
|
既存コマンドの DI (deps.stdout / deps.stderr) にそのまま渡せる書き込み先。
|
|
@@ -105,15 +68,13 @@ export interface OutputCapture {
|
|
|
105
68
|
ここまでに書き込まれた内容を連結して返す (上限超過時は末尾側だけを保持する)。
|
|
106
69
|
*/
|
|
107
70
|
text(): string;
|
|
71
|
+
/**
|
|
72
|
+
ここまでに書き込まれた `warning: ` の文。text() の切り詰めと関係なく、早く出たものから保つ。
|
|
73
|
+
*/
|
|
74
|
+
warnings(): string[];
|
|
108
75
|
}
|
|
109
76
|
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
MCP サーバのプロセス stdout は JSON-RPC 専有なので、既存コマンドの stdout / stderr は
|
|
113
|
-
これに差し替えて捕捉し、ToolResult へ転写する。
|
|
114
|
-
|
|
115
|
-
蓄積量は OUTPUT_CAPTURE_LIMIT_BYTES で頭打ちにし、超えた分は先頭から捨てる。
|
|
77
|
+
MCP サーバの stdout は JSON-RPC 専有なので、既存コマンドの stdout / stderr をこれに差し替えて捕捉する。
|
|
116
78
|
*/
|
|
117
79
|
export declare function createOutputCapture(): OutputCapture;
|
|
118
|
-
export {};
|
|
119
80
|
//# sourceMappingURL=result.d.ts.map
|
package/cli/dist/mcp/result.js
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
// MCP
|
|
2
|
-
//
|
|
3
|
-
// pecotv の各ツールは「既存 CLI コマンドの実処理を呼び、その成否・生成物・出力を一様な形で返す」構造になる。
|
|
4
|
-
// そのためコマンド固有の戻り値ではなく ToolResult に正規化してからプロトコル表現へ変換する。加えて parsePathArguments が、引数の parse とパス引数への
|
|
5
|
-
// Windows 形式パス変換 (windows-path.ts) をまとめて担う。
|
|
1
|
+
// MCP ツールの結果表現 (ToolResult) と、SDK の CallToolResult への変換。
|
|
6
2
|
import path from 'node:path';
|
|
7
3
|
import { Writable } from 'node:stream';
|
|
4
|
+
import { createWarningCollector, WARNING_LIMIT_BYTES } from './warnings.js';
|
|
8
5
|
import { toPosixPath } from './windows-path.js';
|
|
9
6
|
/**
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
const USAGE_ERROR_EXIT_CODE = 2;
|
|
13
|
-
/**
|
|
14
|
-
1 本の捕捉で保持する出力の上限 (バイト)。
|
|
15
|
-
|
|
16
|
-
捕捉した出力は ToolResult に載って MCP クライアントのコンテキストへ入る。
|
|
17
|
-
長時間ツール (slide_convert 等) の進捗ログが際限なく積み上がると、メモリとクライアント側コンテキストを圧迫する。超過分は「新しい方を残す」= 先頭を捨てる:
|
|
18
|
-
失敗の直接原因は末尾に出るため、切り詰めるなら古い側から捨てるのが妥当。
|
|
7
|
+
捕捉と log で保持する出力の上限 (バイト)。失敗の直接原因は末尾に出るため、超えたら先頭を捨てる。
|
|
19
8
|
*/
|
|
20
9
|
const OUTPUT_CAPTURE_LIMIT_BYTES = 64 * 1024;
|
|
21
10
|
/**
|
|
@@ -23,54 +12,34 @@ const OUTPUT_CAPTURE_LIMIT_BYTES = 64 * 1024;
|
|
|
23
12
|
*/
|
|
24
13
|
const TRUNCATION_MARKER = `[pecotv] output exceeded the ${String(OUTPUT_CAPTURE_LIMIT_BYTES)}-byte limit; the beginning was truncated\n`;
|
|
25
14
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
content には structuredContent と同じ内容の JSON テキストを載せる。structuredContent を
|
|
29
|
-
読めないクライアントでもツール結果を解釈できるようにするための二重化で、
|
|
30
|
-
MCP 仕様が推奨する形。
|
|
31
|
-
|
|
32
|
-
引数は deep readonly だが、戻り値は SDK 側の mutable 型のまま返す。
|
|
33
|
-
SDK が readonly 型を公開していないため、この非対称は境界として許容する。
|
|
15
|
+
content は文の text と、structuredContent と 1 字も違わない JSON の text (MCP の仕様の SHOULD)。
|
|
34
16
|
*/
|
|
35
17
|
export function toCallToolResult(result) {
|
|
36
|
-
const structuredContent =
|
|
18
|
+
const structuredContent = result.ok
|
|
19
|
+
? { ...result.data }
|
|
20
|
+
: { ...result.data, kind: result.kind, detail: result.detail };
|
|
21
|
+
const text = result.ok ? result.message : result.detail;
|
|
22
|
+
const sentence = text === '' ? [] : [{ type: 'text', text }];
|
|
37
23
|
return {
|
|
38
|
-
content: [
|
|
24
|
+
content: [
|
|
25
|
+
...sentence,
|
|
26
|
+
{ type: 'text', text: JSON.stringify(structuredContent) },
|
|
27
|
+
],
|
|
39
28
|
structuredContent,
|
|
40
29
|
// exactOptionalPropertyTypes 下で「成功時は isError キー自体を持たない」を表現する。
|
|
41
30
|
...(!result.ok && { isError: true }),
|
|
42
31
|
};
|
|
43
32
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
data: { ...result.data },
|
|
51
|
-
message: result.message,
|
|
52
|
-
...(result.stdout !== undefined && { stdout: result.stdout }),
|
|
53
|
-
...(result.stderr !== undefined && { stderr: result.stderr }),
|
|
54
|
-
};
|
|
33
|
+
/**
|
|
34
|
+
CLI の `--json` の失敗の payload から、共通の項目と重なる reason・detail を外す。原因の名前は kind、全文は detail で返すため。
|
|
35
|
+
*/
|
|
36
|
+
export function withoutCommonFailureFields(data) {
|
|
37
|
+
const { reason: _reason, detail: _detail, ...rest } = data;
|
|
38
|
+
return rest;
|
|
55
39
|
}
|
|
56
40
|
/**
|
|
57
|
-
引数の parse
|
|
58
|
-
|
|
59
|
-
受理したときは変換済みの値を載せた同型オブジェクトを返す。ハンドラ側に未変換の束縛を残さないための形にしている。
|
|
60
|
-
パスを下流へ渡すルートが 1 箇所でも取りこぼすと、Windows のクライアントには「変換されたりされなかったり」に見える。
|
|
61
|
-
そのため確認と変換を別々の関数に割らない。
|
|
62
|
-
|
|
63
|
-
拒否するのは (1) Windows 形式だが POSIX パスへ畳めないもの (他 distro の UNC 等) と
|
|
64
|
-
(2) 変換後も絶対パスにならないものの 2 つ。両方が同じ呼び出しに含まれるときは、
|
|
65
|
-
一方を返して他方を隠すと利用者が取りこぼすため invalidPaths に両方を列挙する。
|
|
66
|
-
message は解決不能側 (1) を主文にする。cwd 依存の曖昧さより「渡した値をそもそも
|
|
67
|
-
解釈できない」方が原因の特定に時間がかかるため。MCP クライアントの cwd はサーバ
|
|
68
|
-
プロセスの cwd と一致する保証が無いため、相対パスは解決せず即座に弾く。invalidPaths
|
|
69
|
-
には利用者が渡した元の値を載せる (変換後の値だけを見せると、渡した引数との対応が取れない)。
|
|
70
|
-
|
|
71
|
-
見るのは「cwd 非依存で一意に解決できるか」だけで、`/a/../etc/passwd` のような
|
|
72
|
-
`..` を含む絶対パスは通す。FR-011 は cwd の曖昧さを排除する規約で、
|
|
73
|
-
サンドボックス境界ではない。アクセス範囲の制限は本関数の責務ではない。
|
|
41
|
+
引数の parse と、パス引数の変換・絶対パスの確認 (FR-011) を 1 つで行う。分けると変換の取りこぼしが起きるため。
|
|
42
|
+
`..` を含む絶対パスは通す。FR-011 は cwd の曖昧さを除く決まりで、アクセス範囲の制限ではない。
|
|
74
43
|
*/
|
|
75
44
|
export function parsePathArguments(
|
|
76
45
|
// zod のスキーマはメソッドを持つクラス型で、readonly 化すると parse を呼べない。
|
|
@@ -117,50 +86,76 @@ schema, arguments_, keys) {
|
|
|
117
86
|
return {
|
|
118
87
|
rejected: {
|
|
119
88
|
ok: false,
|
|
120
|
-
exitCode: USAGE_ERROR_EXIT_CODE,
|
|
121
89
|
kind: 'invalid-path',
|
|
122
|
-
|
|
90
|
+
detail: messages.join('; '),
|
|
123
91
|
data: { invalidPaths, ...convertedPart },
|
|
124
|
-
message: messages.join('; '),
|
|
125
92
|
},
|
|
126
93
|
};
|
|
127
94
|
}
|
|
128
|
-
//
|
|
129
|
-
// draft は parsed のキー集合と型をそのまま保ち、パス引数の値だけを toPosixPath が返した
|
|
130
|
-
// 文字列へ差し替えている (schema の他フィールドには一切触れない)。差し替え後の値も
|
|
131
|
-
// string で schema 側の型と矛盾しないため、再 parse せず Output として返す。
|
|
95
|
+
// draft は parsed のパス引数の値を、string のまま差し替えただけなので、再 parse せず Output として返す。
|
|
132
96
|
// eslint-disable-next-line no-restricted-syntax -- 上記の理由により draft は Output と同型 (unknown 経由の narrowing)
|
|
133
97
|
return ({ input: Object.keys(converted).length === 0 ? parsed : draft });
|
|
134
98
|
}
|
|
135
99
|
/**
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
子プロセスの結果 (SpawnResult) のように Writable を経由しない出力にも同じ上限を働かせる
|
|
139
|
-
ためのエントリ。上限を超える出力をそのまま ToolResult に載せると、エージェントのコンテキストを
|
|
140
|
-
際限なく食う (`playwright install` は非 TTY でも進捗を stdout へ書く)。
|
|
100
|
+
Writable を通さない出力 (SpawnResult) を、出力の捕捉と同じ上限・同じマーカーで切り詰める。
|
|
141
101
|
*/
|
|
142
102
|
export function truncateCapturedText(text) {
|
|
143
103
|
const buffer = Buffer.from(text, 'utf8');
|
|
144
|
-
// createOutputCapture と同じく新しい方 (末尾) を残す。失敗の直接原因は末尾に出る。
|
|
145
104
|
return buffer.length <= OUTPUT_CAPTURE_LIMIT_BYTES
|
|
146
105
|
? text
|
|
147
106
|
: TRUNCATION_MARKER + buffer.subarray(buffer.length - OUTPUT_CAPTURE_LIMIT_BYTES).toString('utf8');
|
|
148
107
|
}
|
|
149
108
|
/**
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
109
|
+
捕捉した出力をつないで上限で切り詰める。各部分の切り詰めのマーカーは外し、印を冒頭の 1 つにまとめる。
|
|
110
|
+
*/
|
|
111
|
+
export function joinCapturedText(parts) {
|
|
112
|
+
const wasTruncated = parts.some(part => part.startsWith(TRUNCATION_MARKER));
|
|
113
|
+
const joined = parts
|
|
114
|
+
.map(part => (part.startsWith(TRUNCATION_MARKER) ? part.slice(TRUNCATION_MARKER.length) : part))
|
|
115
|
+
.filter(part => part !== '')
|
|
116
|
+
.join('\n');
|
|
117
|
+
const text = truncateCapturedText(joined);
|
|
118
|
+
return wasTruncated && text === joined ? TRUNCATION_MARKER + text : text;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
改行を待つ間に持つ 1 行の上限。warning の文の上限に、接頭辞 `warning: ` の分の余裕を足す。
|
|
122
|
+
*/
|
|
123
|
+
const PENDING_LINE_LIMIT_BYTES = WARNING_LIMIT_BYTES + 16;
|
|
124
|
+
/**
|
|
125
|
+
MCP サーバの stdout は JSON-RPC 専有なので、既存コマンドの stdout / stderr をこれに差し替えて捕捉する。
|
|
156
126
|
*/
|
|
157
127
|
export function createOutputCapture() {
|
|
158
|
-
// Buffer
|
|
159
|
-
// マルチバイト文字が chunk 境界で破損しうる。
|
|
160
|
-
// decodeStrings は既定 true なので、文字列を write しても _write には Buffer で届く。
|
|
128
|
+
// chunk 境界のマルチバイト文字を正しくデコードするため、Buffer のまま溜めて取り出すときにデコードする。
|
|
161
129
|
const chunks = [];
|
|
162
130
|
let retainedBytes = 0;
|
|
163
131
|
let isTruncated = false;
|
|
132
|
+
const collector = createWarningCollector();
|
|
133
|
+
let pending = [];
|
|
134
|
+
let pendingBytes = 0;
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- Buffer は可変の型
|
|
136
|
+
const keepPending = (part) => {
|
|
137
|
+
const room = PENDING_LINE_LIMIT_BYTES - pendingBytes;
|
|
138
|
+
if (room <= 0 || part.length === 0)
|
|
139
|
+
return;
|
|
140
|
+
const kept = part.length <= room ? part : part.subarray(0, room);
|
|
141
|
+
pending.push(kept);
|
|
142
|
+
pendingBytes += kept.length;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
改行 (0x0A) で行に分けて warning の収集へ渡す。UTF-8 では 0x0A がマルチバイト文字の途中に現れない。
|
|
146
|
+
*/
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- Buffer は可変の型
|
|
148
|
+
const feedLines = (buffered) => {
|
|
149
|
+
let start = 0;
|
|
150
|
+
for (let index = buffered.indexOf(0x0A); index !== -1; index = buffered.indexOf(0x0A, start)) {
|
|
151
|
+
keepPending(buffered.subarray(start, index));
|
|
152
|
+
collector.addLine(Buffer.concat(pending).toString('utf8'));
|
|
153
|
+
pending = [];
|
|
154
|
+
pendingBytes = 0;
|
|
155
|
+
start = index + 1;
|
|
156
|
+
}
|
|
157
|
+
keepPending(buffered.subarray(start));
|
|
158
|
+
};
|
|
164
159
|
/**
|
|
165
160
|
保持量が上限に収まるまで先頭から捨てる。境界にかかる chunk は途中から切り出す。
|
|
166
161
|
*/
|
|
@@ -187,6 +182,7 @@ export function createOutputCapture() {
|
|
|
187
182
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
188
183
|
write(chunk, _encoding, callback) {
|
|
189
184
|
const buffered = Buffer.from(chunk);
|
|
185
|
+
feedLines(buffered);
|
|
190
186
|
chunks.push(buffered);
|
|
191
187
|
retainedBytes += buffered.length;
|
|
192
188
|
dropOverflow();
|
|
@@ -195,9 +191,9 @@ export function createOutputCapture() {
|
|
|
195
191
|
});
|
|
196
192
|
return {
|
|
197
193
|
stream,
|
|
198
|
-
//
|
|
199
|
-
// U+FFFD になる)。バイト数で頭打ちにする以上避けられないので、マーカーで明示する。
|
|
194
|
+
// 切り詰めた先頭はマルチバイト文字の途中から始まりうる (その 1 文字が U+FFFD になる)。
|
|
200
195
|
text: () => (isTruncated ? TRUNCATION_MARKER : '') + Buffer.concat(chunks).toString('utf8'),
|
|
196
|
+
warnings: () => collector.list(pendingBytes === 0 ? undefined : Buffer.concat(pending).toString('utf8')),
|
|
201
197
|
};
|
|
202
198
|
}
|
|
203
199
|
//# sourceMappingURL=result.js.map
|
|
@@ -2,7 +2,8 @@ import type { Writable } from 'node:stream';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import type { SpawnResult } from '../../domain/_shared/spawn-result.js';
|
|
4
4
|
import { type RuntimeInstallResult } from '../../infra/_shared/runtime-install.js';
|
|
5
|
-
import {
|
|
5
|
+
import type { CallToolResult } from '@modelcontextprotocol/server';
|
|
6
|
+
import { type FailedToolResult, type ToolResult } from '../result.js';
|
|
6
7
|
/**
|
|
7
8
|
パス型パラメータの description 末尾に足す 1 文 (直前の文は句点で閉じてから連結する)。
|
|
8
9
|
|
|
@@ -13,21 +14,27 @@ import { type ToolResult } from '../result.js';
|
|
|
13
14
|
*/
|
|
14
15
|
export declare const WINDOWS_PATH_NOTE: string;
|
|
15
16
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
data はツールごとに形が異なる (対応 CLI の --json 出力と同形) ため、共通スキーマでは
|
|
19
|
-
record として受け、同形性の検証は contract / parity テスト側で行う。
|
|
17
|
+
全ツール共通の outputSchema。ツールごとの項目は形が違うため開いた object にし、共通の 4 項目だけ名前を持たせる。
|
|
20
18
|
*/
|
|
21
19
|
export declare const TOOL_OUTPUT_SCHEMA: z.ZodObject<{
|
|
22
|
-
ok: z.ZodBoolean;
|
|
23
|
-
exitCode: z.ZodNumber;
|
|
24
20
|
kind: z.ZodOptional<z.ZodString>;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
22
|
+
log: z.ZodOptional<z.ZodString>;
|
|
23
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
|
+
}, z.core.$loose>;
|
|
25
|
+
/**
|
|
26
|
+
捕捉した stdout / stderr の文字列。warnings を省くと stderr から取る。
|
|
27
|
+
*/
|
|
28
|
+
export interface CapturedText {
|
|
29
|
+
readonly stdout: string;
|
|
30
|
+
readonly stderr: string;
|
|
31
|
+
readonly warnings?: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
捕捉した出力を ToolResult の data へ移す。warning の文は warnings へ (既にある文と重ねて重複を除く)、
|
|
35
|
+
失敗のときは出力の全体を log へ入れる。
|
|
36
|
+
*/
|
|
37
|
+
export declare function withCapturedOutput<Result extends ToolResult>(result: Result, captured: Readonly<CapturedText>): Result;
|
|
31
38
|
export interface CommandOutput {
|
|
32
39
|
/**
|
|
33
40
|
既存コマンドの deps.stdout / deps.stderr にそのまま渡す。
|
|
@@ -35,44 +42,38 @@ export interface CommandOutput {
|
|
|
35
42
|
readonly stdout: Writable;
|
|
36
43
|
readonly stderr: Writable;
|
|
37
44
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
捕捉した出力を withCapturedOutput で result の data へ移し、CallToolResult にする。
|
|
46
|
+
*/
|
|
47
|
+
finish(result: Readonly<ToolResult>): CallToolResult;
|
|
48
|
+
/**
|
|
49
|
+
捕捉した stderr の warning の文。finish が warnings へ入れる配列と同じ。message の件数を作るときに使う。
|
|
42
50
|
*/
|
|
43
|
-
|
|
51
|
+
warnings(): string[];
|
|
44
52
|
}
|
|
45
53
|
/**
|
|
46
54
|
MCP サーバの process.stdout は JSON-RPC 専有なので、コマンドの出力は必ずここへ逃がす。
|
|
47
55
|
*/
|
|
48
56
|
export declare function captureCommandOutput(): CommandOutput;
|
|
49
57
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Writable を通さない出力にも、captureCommandOutput と同じ上限をかけるための関数。
|
|
53
|
-
空でもキーを残すのは CommandOutput.part() と同じ契約。
|
|
58
|
+
子プロセスの出力を result の data へ移す。warning は切り詰める前の stderr の全体から取る。
|
|
54
59
|
*/
|
|
55
|
-
export declare function
|
|
60
|
+
export declare function withSpawnOutput<Result extends ToolResult>(result: Result, spawned: Readonly<SpawnResult>): Result;
|
|
56
61
|
/**
|
|
57
|
-
|
|
62
|
+
ツールの失敗の detail に載せる 1 行の理由。
|
|
58
63
|
*/
|
|
59
64
|
export declare function formatError(error: unknown): string;
|
|
60
65
|
/**
|
|
61
|
-
|
|
66
|
+
文面の違反で生成を止めたときの直し方。drawio_create と evidence_create で同じ文言にする。
|
|
62
67
|
*/
|
|
63
68
|
export declare function textViolationMessage(count: number): string;
|
|
64
69
|
/**
|
|
65
|
-
|
|
70
|
+
失敗の detail。文面の違反なら、違反の一覧に直し方の 1 行を足す。
|
|
66
71
|
*/
|
|
67
|
-
export declare function
|
|
72
|
+
export declare function failureDetailOf(error: unknown, data: Readonly<Record<string, unknown>>): string;
|
|
68
73
|
/**
|
|
69
|
-
|
|
70
|
-
*/
|
|
71
|
-
export declare const CHROMIUM_UNAVAILABLE_EXIT_CODE = 1;
|
|
72
|
-
/**
|
|
73
|
-
実行時依存 (永続層) 不在 / 取得失敗で実処理を諦めたときの exit code。
|
|
74
|
+
errorData の data から、文面の違反の件数を取る。違反を持たない失敗は undefined。
|
|
74
75
|
*/
|
|
75
|
-
export declare
|
|
76
|
+
export declare function violationCountOf(data: Readonly<Record<string, unknown>>): number | undefined;
|
|
76
77
|
/**
|
|
77
78
|
永続層の場所を特定できないときに利用者向けの応答へ載せる既定の表記。
|
|
78
79
|
*/
|
|
@@ -114,7 +115,7 @@ PECOTV_AUTO_INSTALL_BROWSER=1 のときだけ、その場で取得してから
|
|
|
114
115
|
取得中も MCP の無音タイムアウトは進まない。progress ハートビートは createMcpServer が
|
|
115
116
|
全ツール一律で送っており (src/mcp/server.ts)、ツール側で送出する必要はない。
|
|
116
117
|
*/
|
|
117
|
-
export declare function ensureChromium(label: string, dependencies?: Readonly<ChromiumDependencies>, signal?: AbortSignal): Promise<
|
|
118
|
+
export declare function ensureChromium(label: string, dependencies?: Readonly<ChromiumDependencies>, signal?: AbortSignal): Promise<FailedToolResult | undefined>;
|
|
118
119
|
/**
|
|
119
120
|
実行時依存 (@slidev/cli / dom-to-pptx / @slidev/parser 等) の取得状態を扱う依存。
|
|
120
121
|
*/
|
|
@@ -140,7 +141,7 @@ slide_create / slide_convert / slide_sync / slide_dev の 4 ツールが引数
|
|
|
140
141
|
ensureChromium と違い、自動取得の抜け道は持たない。npm install は 600MB 級で、
|
|
141
142
|
モデルから呼ばれるツールが無断で始めてよい規模ではないため、必ず `runtime_setup` を経由させる。
|
|
142
143
|
*/
|
|
143
|
-
export declare function ensureRuntimeDependencies(label: string, dependencies?: Readonly<RuntimeDependencies>):
|
|
144
|
+
export declare function ensureRuntimeDependencies(label: string, dependencies?: Readonly<RuntimeDependencies>): FailedToolResult | undefined;
|
|
144
145
|
export type NormalizedThemeArgument = {
|
|
145
146
|
readonly ok: true;
|
|
146
147
|
readonly theme: string;
|