@pecot/visual-mcp 1.3.1 → 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.
Files changed (61) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +12 -12
  3. package/assets/slidev/package.json +1 -1
  4. package/assets/slidev/scripts/eslint/slidev-pages-lint/package.json +1 -1
  5. package/assets/slidev/scripts/eslint/text-constraints/package.json +1 -1
  6. package/cli/dist/commands/drawio/errors.d.ts +5 -4
  7. package/cli/dist/commands/drawio/export.d.ts +6 -5
  8. package/cli/dist/commands/drawio/export.js +0 -2
  9. package/cli/dist/commands/drawio/url.d.ts +2 -1
  10. package/cli/dist/commands/drawio/url.js +0 -1
  11. package/cli/dist/commands/evidence-xlsx/create.d.ts +2 -1
  12. package/cli/dist/commands/evidence-xlsx/create.js +0 -1
  13. package/cli/dist/commands/pptx-ooxml/preview.d.ts +4 -3
  14. package/cli/dist/commands/pptx-ooxml/preview.js +0 -3
  15. package/cli/dist/commands/slidev-project/create.d.ts +2 -1
  16. package/cli/dist/commands/slidev-project/create.js +0 -1
  17. package/cli/dist/commands/slidev-project/lint.d.ts +2 -1
  18. package/cli/dist/commands/slidev-project/sync.d.ts +2 -1
  19. package/cli/dist/commands/slidev-project/sync.js +0 -1
  20. package/cli/dist/commands/slidev-project/theme.d.ts +2 -1
  21. package/cli/dist/commands/slidev-to-pptx/convert.d.ts +6 -5
  22. package/cli/dist/commands/slidev-to-pptx/convert.js +0 -4
  23. package/cli/dist/domain/_shared/failure-kind.d.ts +13 -0
  24. package/cli/dist/domain/_shared/failure-kind.js +103 -0
  25. package/cli/dist/domain/slidev-project/errors.d.ts +5 -4
  26. package/cli/dist/domain/slidev-theme/error-reason.d.ts +9 -5
  27. package/cli/dist/infra/_shared/dependency-root.d.ts +3 -3
  28. package/cli/dist/infra/_shared/dependency-root.js +5 -5
  29. package/cli/dist/infra/_shared/runtime-install.d.ts +1 -1
  30. package/cli/dist/infra/_shared/runtime-install.js +1 -1
  31. package/cli/dist/infra/_shared/slidev-bin.d.ts +1 -1
  32. package/cli/dist/infra/_shared/slidev-bin.js +1 -1
  33. package/cli/dist/infra/playwright/chromium.js +2 -2
  34. package/cli/dist/infra/playwright/host-dependencies.js +1 -1
  35. package/cli/dist/infra/playwright/launch.js +1 -1
  36. package/cli/dist/infra/slidev-to-pptx/pipeline.js +1 -1
  37. package/cli/dist/infra/slidev-to-pptx/runner.js +1 -1
  38. package/cli/dist/mcp/dev-server-registry.d.ts +6 -1
  39. package/cli/dist/mcp/dev-server-registry.js +4 -1
  40. package/cli/dist/mcp/result.d.ts +36 -61
  41. package/cli/dist/mcp/result.js +73 -75
  42. package/cli/dist/mcp/tool-names.d.ts +17 -0
  43. package/cli/dist/mcp/tool-names.js +26 -0
  44. package/cli/dist/mcp/tools/_shared.d.ts +40 -38
  45. package/cli/dist/mcp/tools/_shared.js +63 -72
  46. package/cli/dist/mcp/tools/drawio.js +47 -61
  47. package/cli/dist/mcp/tools/evidence.js +11 -18
  48. package/cli/dist/mcp/tools/setup.d.ts +1 -1
  49. package/cli/dist/mcp/tools/setup.js +18 -38
  50. package/cli/dist/mcp/tools/slide-dev.js +17 -36
  51. package/cli/dist/mcp/tools/slide-page.d.ts +2 -1
  52. package/cli/dist/mcp/tools/slide-page.js +20 -26
  53. package/cli/dist/mcp/tools/slide-theme.js +4 -11
  54. package/cli/dist/mcp/tools/slide.d.ts +2 -2
  55. package/cli/dist/mcp/tools/slide.js +31 -73
  56. package/cli/dist/mcp/warnings.d.ts +24 -0
  57. package/cli/dist/mcp/warnings.js +101 -0
  58. package/cli/dist/mcp/windows-path.js +1 -1
  59. package/npm-shrinkwrap.json +92 -33
  60. package/package.json +2 -2
  61. package/vendor/text-rules/dist/source-hash +1 -1
@@ -2,7 +2,7 @@ import { type HostDependencies } from '../../infra/playwright/host-dependencies.
2
2
  import type { ToolDefinition } from '../server.js';
3
3
  import { type ChromiumDependencies, type RuntimeDependencies } from './_shared.js';
4
4
  /**
5
- `setup` を公開する。
5
+ `runtime_setup` を公開する。
6
6
 
7
7
  引数は取らない。chromium 側は取得済みかを見て早期 return はしない。
8
8
  判定が「取得済み」になる状態でも、実体が欠けていることがある。
@@ -1,4 +1,4 @@
1
- // setup ツール。実行時依存 (永続層) と Playwright Chromium を明示的に取得する。
1
+ // runtime_setup ツール。実行時依存 (永続層) と Playwright Chromium を明示的に取得する。
2
2
  //
3
3
  // `pecotv mcp` は MCP クライアントの接続タイムアウト (Claude Code の MCP_TIMEOUT は既定
4
4
  // 30000ms) に収めるため、起動時に何も取得しない。また、モデルが呼ぶツールの側から 120MB 級の
@@ -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 { CHROMIUM_UNAVAILABLE_EXIT_CODE, chromiumDefaultDependencies, chromiumInstallFailureDetail, runtimeDefaultDependencies, RUNTIME_UNAVAILABLE_EXIT_CODE, spawnOutputPart, tlsCertificateHint, TOOL_OUTPUT_SCHEMA, } from './_shared.js';
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 stderr for the reason)'
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 stderr for the reason)`;
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
@@ -181,7 +172,7 @@ function successMessage(runtime, chromium, hostDependencies) {
181
172
  return parts.join(' / ');
182
173
  }
183
174
  /**
184
- `setup` を公開する。
175
+ `runtime_setup` を公開する。
185
176
 
186
177
  引数は取らない。chromium 側は取得済みかを見て早期 return はしない。
187
178
  判定が「取得済み」になる状態でも、実体が欠けていることがある。
@@ -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
- const artifacts = artifactsOf([runtime, chromium]);
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
- const result = {
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
- ...spawnOutputPart(chromium.spawned ?? emptySpawn()),
225
- };
226
- return toCallToolResult(result);
212
+ }, chromium.spawned ?? emptySpawn()));
227
213
  }
228
214
  // 両系統が失敗することもある (ネットワーク断・プロキシ誤設定では両方が落ちる)。
229
- // 片方だけを見ると、もう片方の理由が data.<系統>.detail にしか残らず message から
215
+ // 片方だけを見ると、もう片方の理由が <系統>.detail にしか残らず detail から
230
216
  // 消えるため、失敗した系統を全て畳んで載せる。
231
217
  const failures = [
232
218
  ...(runtime.installed ? [] : [{ label: 'runtime dependencies', reason: 'runtime-install-failed', stage: runtime }]),
@@ -235,35 +221,32 @@ 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 message = [
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
- exitCode: runtime.installed ? CHROMIUM_UNAVAILABLE_EXIT_CODE : RUNTIME_UNAVAILABLE_EXIT_CODE,
253
- artifacts,
237
+ // reason (runtime_setup の項目) は失敗した段をカンマでつなぐ。kind には最初に失敗した段の名前を入れる。
238
+ kind: failures[0]?.reason ?? 'unknown',
239
+ detail,
254
240
  data: {
255
241
  event: 'setup.error',
256
242
  reason: failures.map(failure => failure.reason).join(','),
257
- detail,
258
243
  ...data,
259
244
  },
260
- message,
261
- ...spawnOutputPart(mergeSpawned(failures.map(failure => failure.stage.spawned))),
262
- };
245
+ }, mergeSpawned(failures.map(failure => failure.stage.spawned)));
263
246
  return toCallToolResult(result);
264
247
  };
265
248
  return {
266
- name: 'setup',
249
+ name: 'runtime_setup',
267
250
  config: {
268
251
  title: 'Prepare the runtime (runtime dependencies / Chromium download and OS libraries)',
269
252
  description: 'Downloads the runtime dependencies pecotv uses (@slidev/cli / dom-to-pptx / @slidev/parser, etc.) and Playwright Chromium. '
@@ -286,17 +269,14 @@ export function setupTool(buildDependencies = chromiumDefaultDependencies, build
286
269
  };
287
270
  }
288
271
  /**
289
- 取得を飛ばした系統には子プロセスが無い。stdout / stderr のキーは契約どおり残す。
272
+ 取得を飛ばした系統には子プロセスが無い。
290
273
  */
291
274
  function emptySpawn() {
292
275
  // eslint-disable-next-line unicorn/no-null -- SpawnResult は起動なしを exitCode: null で表す
293
276
  return { exitCode: null, signal: null, stdout: '', stderr: '', timedOut: false };
294
277
  }
295
278
  /**
296
- 失敗した系統の出力を 1 つに畳む。
297
-
298
- ToolResult の stdout / stderr は 1 組しか持てないため、両系統が失敗したときは
299
- どちらの出力も落とさずに連結する (原因が stdout 側にあることもある)。
279
+ 失敗した系統の出力を 1 つに畳む。両系統が失敗しても、どちらの出力も log に残す。
300
280
  */
301
281
  function mergeSpawned(spawned) {
302
282
  const present = spawned.filter((result) => result !== undefined);
@@ -1,6 +1,6 @@
1
1
  // slide_dev ツール。talk-dir の Slidev dev サーバを起動し、ブラウザで開ける URL を返す。
2
2
  //
3
- // 対応する CLI サブコマンドは持たない (`setup` と同じ MCP 専用ツール)。dev サーバの寿命は
3
+ // 対応する CLI サブコマンドは持たない (`runtime_setup` と同じ MCP 専用ツール)。dev サーバの寿命は
4
4
  // MCP サーバプロセスに紐づくため、CLI から起動しても呼び出しの終了と同時に落ちるだけで
5
5
  // 意味を持たない。プレビュールートを MCP 一本に絞る #1023 の決定にも沿う。
6
6
  //
@@ -14,22 +14,12 @@ import path from 'node:path';
14
14
  import { z } from 'zod';
15
15
  import { errorToReason as slideCreateErrorToReason } from '../../commands/slidev-project/create.js';
16
16
  import { ensureTalkThemeLinked, linkedThemeDefaultDependencies, } from '../../commands/slidev-project/linked-theme.js';
17
+ import { failureKindOf } from '../../domain/_shared/failure-kind.js';
17
18
  import { pluginDependencyRoot } from '../../infra/_shared/dependency-root.js';
18
19
  import { resolvePluginRoot } from '../../infra/_shared/plugin-root.js';
19
20
  import { devServerRegistry } from '../dev-server-registry.js';
20
21
  import { parsePathArguments, toCallToolResult } from '../result.js';
21
- import { ensureRuntimeDependencies, runtimeDefaultDependencies, TOOL_OUTPUT_SCHEMA, WINDOWS_PATH_NOTE, } from './_shared.js';
22
- /**
23
- dev サーバを起動できなかったときの exit code (各コマンドの RuntimeError と同じ 1)。
24
- */
25
- const DEV_SERVER_EXIT_CODE = 1;
26
- /**
27
- 子プロセスを起こす前に諦めたルートの出力。
28
-
29
- ToolResult の stdout / stderr が省略されるのは「捕捉していない」ときで、捕捉した結果が
30
- 空であることとは意味が違う (tools/_shared.ts)。実行前ガードでも捕捉相当のキーは残す。
31
- */
32
- const NO_OUTPUT = { stdout: '', stderr: '' };
22
+ import { ensureRuntimeDependencies, runtimeDefaultDependencies, TOOL_OUTPUT_SCHEMA, WINDOWS_PATH_NOTE, withCapturedOutput, } from './_shared.js';
33
23
  // context に AbortSignal を持つため readonly にできない。
34
24
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
35
25
  function ensureThemeLinkedWithDefaults(directory, context) {
@@ -99,17 +89,13 @@ function inspectNodeModules(directory) {
99
89
  function guardFailure(defect, directory, warnings = []) {
100
90
  return {
101
91
  ok: false,
102
- exitCode: DEV_SERVER_EXIT_CODE,
103
- artifacts: [],
92
+ kind: failureKindOf(defect.reason),
93
+ detail: defect.detail,
104
94
  data: {
105
95
  event: 'slide.dev.error',
106
- reason: defect.reason,
107
- detail: defect.detail,
108
96
  dir: directory,
109
97
  ...(warnings.length > 0 && { warnings }),
110
98
  },
111
- message: defect.detail,
112
- ...NO_OUTPUT,
113
99
  };
114
100
  }
115
101
  /**
@@ -134,8 +120,6 @@ export function slideDevTool(buildRegistry = devServerRegistry, buildRuntimeDepe
134
120
  const stopped = buildRegistry().stop(input.dir);
135
121
  return toCallToolResult({
136
122
  ok: true,
137
- exitCode: 0,
138
- artifacts: [],
139
123
  data: {
140
124
  event: 'slide.dev.stopped',
141
125
  dir: input.dir,
@@ -146,7 +130,6 @@ export function slideDevTool(buildRegistry = devServerRegistry, buildRuntimeDepe
146
130
  message: stopped.stopped
147
131
  ? `slide dev: stopped (${input.dir})`
148
132
  : `slide dev: no running server (${input.dir})`,
149
- ...NO_OUTPUT,
150
133
  });
151
134
  }
152
135
  // 起動には @slidev/cli の bin が要る。未取得のときの失敗の型は
@@ -158,7 +141,7 @@ export function slideDevTool(buildRegistry = devServerRegistry, buildRuntimeDepe
158
141
  if (defect !== undefined)
159
142
  return toCallToolResult(guardFailure(defect, input.dir));
160
143
  // テーマを今の値で張る。取得済みなら stamp を比べるだけで、ネットワークには出ない。
161
- // 取得中の警告は応答の data.warnings に載せ、MCP のキャンセルは取得 (git) まで届ける。
144
+ // 取得中の警告は応答の warnings に載せ、MCP のキャンセルは取得 (git) まで届ける。
162
145
  const warnings = [];
163
146
  let ensured;
164
147
  const context = {
@@ -185,20 +168,19 @@ export function slideDevTool(buildRegistry = devServerRegistry, buildRuntimeDepe
185
168
  await buildRegistry().stopAndWait(input.dir);
186
169
  const started = await buildRegistry().start(input.dir, { port: input.port, signal: call.signal });
187
170
  if (!started.ok) {
188
- return toCallToolResult({
171
+ return toCallToolResult(withCapturedOutput({
189
172
  ok: false,
190
- exitCode: DEV_SERVER_EXIT_CODE,
191
- artifacts: [],
192
- data: { event: 'slide.dev.error', reason: started.reason, detail: started.detail, dir: input.dir },
193
- message: started.detail,
194
- stdout: started.stdout,
195
- stderr: started.stderr,
196
- });
173
+ kind: started.reason,
174
+ detail: started.detail,
175
+ data: {
176
+ event: 'slide.dev.error',
177
+ dir: input.dir,
178
+ ...(warnings.length > 0 && { warnings }),
179
+ },
180
+ }, started));
197
181
  }
198
182
  return toCallToolResult({
199
183
  ok: true,
200
- exitCode: 0,
201
- artifacts: [],
202
184
  data: {
203
185
  event: started.reused ? 'slide.dev.reused' : 'slide.dev.started',
204
186
  dir: input.dir,
@@ -212,16 +194,15 @@ export function slideDevTool(buildRegistry = devServerRegistry, buildRuntimeDepe
212
194
  message: started.reused
213
195
  ? `slide dev: reusing the running server ${started.url}`
214
196
  : `slide dev: started ${started.url}`,
215
- ...NO_OUTPUT,
216
197
  });
217
198
  };
218
199
  return {
219
200
  name: 'slide_dev',
220
201
  config: {
221
202
  title: 'Start a Slidev preview',
222
- description: 'Starts the Slidev dev server of a talk-dir and returns a URL that opens in a browser (data.url). '
203
+ description: 'Starts the Slidev dev server of a talk-dir and returns a URL that opens in a browser (url). '
223
204
  + 'The port can be set with port; if omitted, a free port from 3030 to 3034 is used. '
224
- + 'Calling again for the same talk-dir returns the running server as it is (data.reused: true). '
205
+ + 'Calling again for the same talk-dir returns the running server as it is (reused: true). '
225
206
  + 'Set stop: true to stop it. '
226
207
  + 'The server runs only while the MCP server process is alive; the preview ends with the session.',
227
208
  inputSchema: slideDevInput,
@@ -1,10 +1,11 @@
1
+ import { type FailureKind } from '../../domain/_shared/failure-kind.js';
1
2
  import type { ToolDefinition } from '../server.js';
2
3
  type PageFileName = {
3
4
  readonly ok: true;
4
5
  readonly filename: string;
5
6
  } | {
6
7
  readonly ok: false;
7
- readonly reason: string;
8
+ readonly reason: FailureKind;
8
9
  readonly detail: string;
9
10
  };
10
11
  /**
@@ -1,7 +1,7 @@
1
1
  // slide_page ツール。指定レイアウトのスケルトンページを talk-dir の pages/ 配下に生成し、
2
2
  // そのレイアウトの使い方 (参照 yaml 全文 + includes) を応答で返す。
3
3
  //
4
- // 対応する CLI サブコマンドは持たない (`slide_dev` / `setup` と同じ MCP 専用ツール)。
4
+ // 対応する CLI サブコマンドは持たない (`slide_dev` / `runtime_setup` と同じ MCP 専用ツール)。
5
5
  // 目的はエージェントの「`pages/_references/<layout>.yaml` を Read してから手書きする」ルートを
6
6
  // 1 回の呼び出しに畳むことなので、CLI から使う需要が無い。
7
7
  //
@@ -18,14 +18,11 @@ import { z } from 'zod';
18
18
  import { errorToReason as slideThemeErrorToReason, executeSlideTheme, } from '../../commands/slidev-project/theme.js';
19
19
  import { NodeThemeFiles } from '../../infra/slidev-theme/fs.js';
20
20
  import { createDiagnostics } from '../../diagnostics.js';
21
+ import { failureKindOf } from '../../domain/_shared/failure-kind.js';
21
22
  import { extractSkeleton, isFrontmatterBlock } from '../../domain/slidev-theme/skeleton.js';
22
23
  import { parsePathArguments, toCallToolResult } from '../result.js';
23
24
  import { captureCommandOutput, formatError, TOOL_OUTPUT_SCHEMA, WINDOWS_PATH_NOTE, } from './_shared.js';
24
25
  /**
25
- ページを生成できなかったときの exit code (各コマンドの RuntimeError と同じ 1)。
26
- */
27
- const SLIDE_PAGE_EXIT_CODE = 1;
28
- /**
29
26
  生成するページの拡張子。省略された `file` にはこれを補う。
30
27
  */
31
28
  const PAGE_EXTENSION = '.md';
@@ -59,8 +56,8 @@ includes ブロック内の yaml コメント行。項目の間に挟まって
59
56
  const YAML_COMMENT_REGEX = /^[ \t]*#/;
60
57
  const slidePageInput = z.object({
61
58
  layout: z.string()
62
- .describe('Layout name. Decide the presentation style from the categories (data.categories) in the slide_create / slide_sync response, '
63
- + 'then choose from the names in data.layouts that belong to that category'),
59
+ .describe('Layout name. Decide the presentation style from the categories (categories) in the slide_create / slide_sync response, '
60
+ + 'then choose from the names in layouts that belong to that category'),
64
61
  dir: z.string()
65
62
  .describe('Absolute path of the talk-dir to generate the page in. Relative paths are not accepted. ' + WINDOWS_PATH_NOTE),
66
63
  file: z.string()
@@ -69,15 +66,14 @@ const slidePageInput = z.object({
69
66
  .describe('Overwrite when a page with the same name already exists'),
70
67
  });
71
68
  /**
72
- 失敗時の ToolResult (stdout / stderr は呼び出し側が付ける)。
69
+ 失敗時の ToolResult (捕捉した出力は呼び出し側が output.finish で移す)。
73
70
  */
74
71
  function failure(reason, detail, extra = {}) {
75
72
  return {
76
73
  ok: false,
77
- exitCode: SLIDE_PAGE_EXIT_CODE,
78
- artifacts: [],
79
- data: { event: 'slide.page.error', reason, detail, ...extra },
80
- message: detail,
74
+ kind: failureKindOf(reason),
75
+ detail,
76
+ data: { event: 'slide.page.error', ...extra },
81
77
  };
82
78
  }
83
79
  /**
@@ -179,10 +175,10 @@ function themeFailure(error) {
179
175
  return failure(slideThemeErrorToReason(error), formatError(error));
180
176
  }
181
177
  /**
182
- 引数検証後の実処理。stdout / stderr は呼び出し側が一括で載せる。
178
+ 引数検証後の実処理。捕捉した出力は呼び出し側が output.finish で移す。
183
179
 
184
180
  実行時依存 (永続層) と Chromium は要らない。参照 yaml の読み取りと 1 ファイルの書き込み
185
- だけなので、`setup` 前の環境でも通る。
181
+ だけなので、`runtime_setup` 前の環境でも通る。
186
182
  */
187
183
  async function generatePage(input, readReferenceText,
188
184
  // CommandOutput の stderr は WritableStream で write が mutate のため readonly 化できない。
@@ -210,7 +206,7 @@ output) {
210
206
  const reference = references.entries.find(candidate => candidate.name === input.layout);
211
207
  if (entry === undefined || reference === undefined) {
212
208
  return failure('unknown-layout', `layout not found in theme ${theme.theme.name} referenced by ${input.dir}: ${input.layout}`
213
- + '; decide the presentation style from data.categories, then choose from data.layouts of that category', { categories: theme.categories, layouts: theme.layouts });
209
+ + '; decide the presentation style from categories, then choose from layouts of that category', { categories: theme.categories, layouts: theme.layouts });
214
210
  }
215
211
  if (!reference.file.endsWith('.yaml')) {
216
212
  return failure('skeleton-unavailable', `cannot write a skeleton: theme ${theme.theme.name} has no reference yaml for ${entry.layout} (references/${entry.layout}.yaml)`
@@ -249,10 +245,9 @@ output) {
249
245
  throw error;
250
246
  return failure('file-exists', `file already exists: ${target}; pass force: true to overwrite, or specify a different file`);
251
247
  }
248
+ // 書いたページのパスは path の項目で返す。
252
249
  return {
253
250
  ok: true,
254
- exitCode: 0,
255
- artifacts: [target],
256
251
  data: {
257
252
  event: 'slide.page.done',
258
253
  layout: entry.layout,
@@ -264,7 +259,7 @@ output) {
264
259
  includes: included.includes,
265
260
  },
266
261
  message: `slide page: generated (${target})`
267
- + '; fill in the content following props / text_constraints in data.reference, '
262
+ + '; fill in the content following props / text_constraints in reference, '
268
263
  + `then register "src: ./pages/${file.filename}" in slides.md separately`,
269
264
  };
270
265
  }
@@ -278,14 +273,13 @@ async function handleSlidePage(arguments_, readReferenceText) {
278
273
  const validated = parsePathArguments(slidePageInput, arguments_, ['dir']);
279
274
  if (validated.rejected !== undefined)
280
275
  return toCallToolResult(validated.rejected);
281
- // テーマの警告を stderr へ出す。捕捉先を用意して
282
- // 「捕捉したなら空でもキーを残す」契約 (tools/_shared.ts) を全 return ルートで満たす。
276
+ // テーマの警告は捕捉先の stderr に書き、output.finish で warnings へ移す。
283
277
  const output = captureCommandOutput();
284
278
  try {
285
- return toCallToolResult({ ...await generatePage(validated.input, readReferenceText, output), ...output.part() });
279
+ return output.finish(await generatePage(validated.input, readReferenceText, output));
286
280
  }
287
281
  catch (error) {
288
- return toCallToolResult({ ...failure('write-failed', formatError(error)), ...output.part() });
282
+ return output.finish(failure('write-failed', formatError(error)));
289
283
  }
290
284
  }
291
285
  /**
@@ -300,10 +294,10 @@ readReferenceText = file => readFile(file, 'utf8')) {
300
294
  title: 'Generate a Slidev page',
301
295
  description: 'Generates a skeleton page for one layout under pages/ of the talk-dir, '
302
296
  + 'and returns the specification of that layout (props / text_constraints / clicks / best_practices / anti_patterns / examples). '
303
- + 'The specification is returned in data.reference and data.includes. '
304
- + 'Decide the presentation style from the categories (data.categories) in the slide_create / slide_sync response, '
305
- + 'then choose the layout name from data.layouts of that category '
306
- + '(passing an unknown name returns data.categories and data.layouts in the response). '
297
+ + 'The specification is returned in reference and includes. '
298
+ + 'Decide the presentation style from the categories (categories) in the slide_create / slide_sync response, '
299
+ + 'then choose the layout name from layouts of that category '
300
+ + '(passing an unknown name returns categories and layouts in the response). '
307
301
  + 'The generated page must be registered separately as a src: entry in slides.md.',
308
302
  inputSchema: slidePageInput,
309
303
  outputSchema: TOOL_OUTPUT_SCHEMA,
@@ -6,12 +6,9 @@
6
6
  // 読み取りだけで、ネットワークには出ない。
7
7
  import { z } from 'zod';
8
8
  import { errorToReason, executeSlideTheme, slideThemeDefaultDependencies, } from '../../commands/slidev-project/theme.js';
9
+ import { failureKindOf } from '../../domain/_shared/failure-kind.js';
9
10
  import { parsePathArguments, toCallToolResult } from '../result.js';
10
11
  import { formatError, TOOL_OUTPUT_SCHEMA, WINDOWS_PATH_NOTE } from './_shared.js';
11
- /**
12
- 解決・宣言の失敗の exit code(各コマンドの RuntimeError と同じ 1)。
13
- */
14
- const SLIDE_THEME_EXIT_CODE = 1;
15
12
  const slideThemeInput = z.object({
16
13
  dir: z.string()
17
14
  .describe('Absolute path of the talk-dir whose theme to inspect. Relative paths are not accepted. ' + WINDOWS_PATH_NOTE),
@@ -42,20 +39,16 @@ export function slideThemeTool(buildDependencies = slideThemeDefaultDependencies
42
39
  const { data } = await executeSlideTheme({ dir }, buildDependencies());
43
40
  return toCallToolResult({
44
41
  ok: true,
45
- exitCode: 0,
46
- artifacts: [],
47
42
  data: { ...data },
48
43
  message: `slide theme: ${data.theme.name} (${String(data.layouts.length)} layouts)`,
49
44
  });
50
45
  }
51
46
  catch (error) {
52
- const detail = formatError(error);
53
47
  return toCallToolResult({
54
48
  ok: false,
55
- exitCode: SLIDE_THEME_EXIT_CODE,
56
- artifacts: [],
57
- data: { event: 'slide.theme.error', reason: errorToReason(error), detail },
58
- message: detail,
49
+ kind: failureKindOf(errorToReason(error)),
50
+ detail: formatError(error),
51
+ data: { event: 'slide.theme.error' },
59
52
  });
60
53
  }
61
54
  },
@@ -22,8 +22,8 @@ export declare function slideConvertTool(buildDependencies?: () => SlideConvertD
22
22
  */
23
23
  export declare function slideSyncTool(buildDependencies?: () => SlideSyncDependencies, buildRuntimeDependencies?: () => RuntimeDependencies): ToolDefinition;
24
24
  /**
25
- `pecotv slide lint` 相当。違反の検出は「報告が成果」なので ok: true / exitCode 1 で返す
26
- (CLI の exit code 規約は exitCode 側に載せ、ok は目的の実行を完了できたかだけを表す)。
25
+ `pecotv slide lint` 相当。違反の検出は「報告が成果」なので、違反があっても成功で返す (CLI は exit 1)。
26
+ 違反の有無は outcome の項目で読む。
27
27
  */
28
28
  export declare function slideLintTool(buildDependencies?: () => SlideLintDependencies): ToolDefinition;
29
29
  /**