@pecot/visual-mcp 3.1.1-dev.141 → 3.1.1-dev.143

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 (101) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/cli/dist/commands/drawio/export.d.ts +9 -24
  3. package/cli/dist/commands/drawio/export.js +15 -135
  4. package/cli/dist/commands/drawio/theme.d.ts +3 -3
  5. package/cli/dist/commands/drawio/theme.js +10 -10
  6. package/cli/dist/commands/drawio/url.d.ts +9 -26
  7. package/cli/dist/commands/drawio/url.js +18 -131
  8. package/cli/dist/commands/evidence-xlsx/create.d.ts +4 -12
  9. package/cli/dist/commands/evidence-xlsx/create.js +9 -92
  10. package/cli/dist/commands/slidev-project/create.d.ts +5 -30
  11. package/cli/dist/commands/slidev-project/create.js +12 -136
  12. package/cli/dist/commands/slidev-project/linked-theme.d.ts +1 -1
  13. package/cli/dist/commands/slidev-project/linked-theme.js +2 -2
  14. package/cli/dist/commands/slidev-project/lint.d.ts +8 -37
  15. package/cli/dist/commands/slidev-project/lint.js +16 -161
  16. package/cli/dist/commands/slidev-project/sync.d.ts +7 -26
  17. package/cli/dist/commands/slidev-project/sync.js +15 -156
  18. package/cli/dist/commands/slidev-project/theme.d.ts +2 -13
  19. package/cli/dist/commands/slidev-project/theme.js +3 -93
  20. package/cli/dist/commands/slidev-to-pptx/convert.d.ts +10 -17
  21. package/cli/dist/commands/slidev-to-pptx/convert.js +25 -266
  22. package/cli/dist/diagnostics.d.ts +0 -4
  23. package/cli/dist/diagnostics.js +0 -6
  24. package/cli/dist/domain/_shared/failure-kind.d.ts +2 -2
  25. package/cli/dist/domain/_shared/failure-kind.js +2 -2
  26. package/cli/dist/domain/_shared/ports.d.ts +3 -4
  27. package/cli/dist/domain/evidence-xlsx/image-dimensions.d.ts +1 -1
  28. package/cli/dist/domain/pptx-ooxml/preview-normalize.d.ts +0 -12
  29. package/cli/dist/domain/pptx-ooxml/preview-normalize.js +1 -25
  30. package/cli/dist/domain/slidev-project/errors.js +2 -2
  31. package/cli/dist/domain/slidev-project/generated-files.js +3 -3
  32. package/cli/dist/domain/slidev-project/lint.d.ts +7 -7
  33. package/cli/dist/domain/slidev-project/lint.js +8 -8
  34. package/cli/dist/domain/slidev-project/package-json.d.ts +1 -1
  35. package/cli/dist/domain/slidev-project/package-json.js +2 -2
  36. package/cli/dist/domain/slidev-project/sync.d.ts +11 -11
  37. package/cli/dist/domain/slidev-project/sync.js +18 -19
  38. package/cli/dist/domain/slidev-theme/deck-lint-input.js +1 -1
  39. package/cli/dist/domain/slidev-theme/declaration.js +1 -1
  40. package/cli/dist/domain/slidev-theme/skeleton.js +1 -1
  41. package/cli/dist/domain/slidev-theme/talk-theme.d.ts +3 -3
  42. package/cli/dist/domain/slidev-theme/talk-theme.js +5 -7
  43. package/cli/dist/domain/slidev-to-pptx/config.d.ts +1 -1
  44. package/cli/dist/domain/slidev-to-pptx/config.js +1 -1
  45. package/cli/dist/domain/slidev-to-pptx/errors.d.ts +4 -4
  46. package/cli/dist/domain/slidev-to-pptx/errors.js +4 -4
  47. package/cli/dist/domain/slidev-to-pptx/types.d.ts +1 -1
  48. package/cli/dist/infra/_shared/dependency-root.d.ts +9 -67
  49. package/cli/dist/infra/_shared/dependency-root.js +15 -126
  50. package/cli/dist/infra/_shared/flock.js +1 -2
  51. package/cli/dist/infra/_shared/plugin-root.d.ts +3 -5
  52. package/cli/dist/infra/_shared/plugin-root.js +5 -12
  53. package/cli/dist/infra/evidence-xlsx/workbook-writer.d.ts +1 -1
  54. package/cli/dist/infra/playwright/chromium.d.ts +4 -15
  55. package/cli/dist/infra/playwright/chromium.js +6 -18
  56. package/cli/dist/infra/playwright/host-dependencies.d.ts +2 -2
  57. package/cli/dist/infra/playwright/host-dependencies.js +6 -6
  58. package/cli/dist/infra/pptx-ooxml/soffice.js +1 -1
  59. package/cli/dist/infra/slidev-project/eslint-runner.d.ts +1 -1
  60. package/cli/dist/infra/slidev-project/eslint-runner.js +2 -2
  61. package/cli/dist/infra/slidev-to-pptx/index.js +1 -1
  62. package/cli/dist/infra/slidev-to-pptx/pipeline.js +1 -1
  63. package/cli/dist/infra/slidev-to-pptx/prerender-capture.js +1 -1
  64. package/cli/dist/infra/slidev-to-pptx/server.js +2 -2
  65. package/cli/dist/main.d.ts +3 -0
  66. package/cli/dist/main.js +28 -0
  67. package/cli/dist/mcp/result.d.ts +5 -1
  68. package/cli/dist/mcp/result.js +9 -1
  69. package/cli/dist/mcp/serve.d.ts +2 -3
  70. package/cli/dist/mcp/serve.js +4 -5
  71. package/cli/dist/mcp/server.d.ts +5 -1
  72. package/cli/dist/mcp/server.js +10 -7
  73. package/cli/dist/mcp/tool-names.js +4 -1
  74. package/cli/dist/mcp/tools/_shared.d.ts +1 -1
  75. package/cli/dist/mcp/tools/_shared.js +2 -2
  76. package/cli/dist/mcp/tools/drawio.js +12 -15
  77. package/cli/dist/mcp/tools/evidence.js +2 -2
  78. package/cli/dist/mcp/tools/file.d.ts +31 -0
  79. package/cli/dist/mcp/tools/file.js +482 -0
  80. package/cli/dist/mcp/tools/index.d.ts +1 -1
  81. package/cli/dist/mcp/tools/index.js +6 -3
  82. package/cli/dist/mcp/tools/setup.js +3 -3
  83. package/cli/dist/mcp/tools/slide-dev.js +6 -7
  84. package/cli/dist/mcp/tools/slide-page.js +3 -3
  85. package/cli/dist/mcp/tools/slide-theme.d.ts +0 -1
  86. package/cli/dist/mcp/tools/slide-theme.js +2 -3
  87. package/cli/dist/mcp/tools/slide.d.ts +4 -4
  88. package/cli/dist/mcp/tools/slide.js +13 -14
  89. package/cli/dist/node-runtime.d.ts +2 -2
  90. package/cli/dist/node-runtime.js +4 -13
  91. package/cli/dist/version.d.ts +1 -8
  92. package/cli/dist/version.js +2 -11
  93. package/npm-shrinkwrap.json +7 -17
  94. package/package.json +2 -3
  95. package/bin/pecot-visual-mcp.mjs +0 -10
  96. package/cli/dist/cli.d.ts +0 -5
  97. package/cli/dist/cli.js +0 -109
  98. package/cli/dist/commands/chromium/host-dependencies.d.ts +0 -18
  99. package/cli/dist/commands/chromium/host-dependencies.js +0 -75
  100. package/cli/dist/commands/pptx-ooxml/preview.d.ts +0 -74
  101. package/cli/dist/commands/pptx-ooxml/preview.js +0 -399
@@ -1,30 +1,26 @@
1
- // `pecotv drawio url <input.drawio> [--mode view|edit] [--theme <spec>] [--json]` の実装。
2
- // slidev-project/create.ts と同形の DI / 二段例外 / writeErr フックを採用する。
1
+ // drawio_url ツールの実装。slidev-project/create.ts と同形の DI / 二段例外を採用する。
3
2
  //
4
- // exit code 規約:
5
- // 0 = success (warnings なし)。
6
- // 1 = RuntimeError (input/output IO failure、文面の違反、文章規則の判定の失敗、解けないテーマ)。
7
- // 2 = UsageError (invalid option / -o の拡張子が .html でない / テーマの指定の誤り)。
8
- // 3 = warnings present (validateHtml の warning or icon resolver warn が 1 件以上)。
3
+ // 失敗の種類:
4
+ // RuntimeError = input/output IO failure、文面の違反、文章規則の判定の失敗、解けないテーマ。
5
+ // UsageError = 出力パスの拡張子が .html でない / テーマの指定の誤り。
6
+ // 警告 (validateHtml の warning or icon resolver warn) は warningCount に数える。
9
7
  import { performance } from 'node:perf_hooks';
10
8
  import { mkdir, readFile, writeFile } from 'node:fs/promises';
11
9
  import path from 'node:path';
12
- import { Command } from 'commander';
13
10
  import { collectTextViolations, formatTextViolations } from '../../domain/_shared/text-check.js';
14
11
  import { siblingPath } from '../../domain/drawio/export.js';
15
12
  import { labelTexts } from '../../domain/drawio/label-text.js';
16
13
  import { generateDrawioUrl, generateDrawioViewerUrl, prepareDrawioXml, renderRedirectHtml, validateHtml, validateSlideFonts, validateSlideFontSizes, validateWhitespaceWrap } from '../../domain/drawio/url.js';
17
14
  import { themeErrorReason } from '../../domain/slidev-theme/error-reason.js';
18
- import { ThemeSpecError } from '../../domain/slidev-theme/theme-spec.js';
19
15
  import { pluginDependencyRoot } from '../../infra/_shared/dependency-root.js';
16
+ import { resolvePluginRoot } from '../../infra/_shared/plugin-root.js';
20
17
  import { createIconResolver, defaultIconRoot } from '../../infra/drawio/icons.js';
21
18
  import { capturePng } from '../../infra/drawio/screenshot.js';
22
19
  import { defaultLintText } from '../../infra/text-lint.js';
23
- import { createDiagnostics, passthrough, writeData } from '../../diagnostics.js';
20
+ import { createDiagnostics } from '../../diagnostics.js';
24
21
  import { DrawioUrlRuntimeError, DrawioUrlUsageError } from './errors.js';
25
22
  import { resolveDrawioTheme, themeData, themeFontNames } from './theme.js';
26
23
  export { DrawioUrlRuntimeError, DrawioUrlUsageError } from './errors.js';
27
- const VALID_MODES = new Set(['view', 'edit']);
28
24
  export async function runDrawioUrl(inputFile, options,
29
25
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- write は可変。DI 経由の write は mutate メソッド
30
26
  dependencies) {
@@ -44,9 +40,9 @@ dependencies) {
44
40
  // 文面の違反があれば、警告の確認や成果物の生成より前に止める
45
41
  await assertLabelsClean(trimmed, dependencies.lintText);
46
42
  let warningCount = 0;
47
- // 診断のうち、exit code に反映するのは warning だけ。
48
- // note (fontColor 二重指定など) は stderr に流すが、exit code には影響させない。
49
- // 書体は常に確かめる。5 段のサイズは、テーマが決まったとき(talk-dir の中か --theme 指定)だけ確かめる。
43
+ // 診断のうち、警告の件数に数えるのは warning だけ。
44
+ // note (fontColor 二重指定など) は stderr に流すが、件数には数えない。
45
+ // 書体は常に確かめる。5 段のサイズは、テーマが決まったとき(talk-dir の中か theme 指定)だけ確かめる。
50
46
  const { fontSizes } = theme;
51
47
  const validators = [
52
48
  validateHtml,
@@ -65,10 +61,6 @@ dependencies) {
65
61
  }
66
62
  }
67
63
  }
68
- // pluginRoot は env 必須の deps のまま据え置く。
69
- // 既定の icons root を resolvePluginRoot() へ寄せたのは drawio_export だけで、これは意図した保留。
70
- // このため CLAUDE_PLUGIN_ROOT 無しで直接起動すると、drawio_export は動くが、
71
- // drawio_create は deps の構築時に失敗する。この差が残っている。
72
64
  const iconRoot = defaultIconRoot(dependencies.pluginRoot);
73
65
  // 同一メッセージ (= 未解決アイコン 1 種) は初回だけ報告する。色付き解決に失敗した
74
66
  // 参照が色を落としたフォールバック表記で色なし regex に再ヒットし、同じ警告が
@@ -114,9 +106,8 @@ async function assertLabelsClean(xml, lintText) {
114
106
  }
115
107
  }
116
108
  /**
117
- URL 生成から出力ファイル・PNG の書き出しまでを実行し、`--json` の data 同形を組み立てる。
109
+ URL 生成から出力ファイル・PNG の書き出しまでを実行し、ツールの結果に載せる data を組み立てる。
118
110
 
119
- 呼び出し元(commander action / MCP ツール)に残るのは「どう見せるか」だけで、
120
111
  出力先の解決・PNG の兄弟ファイル命名・警告件数の集計はすべてここに閉じる。
121
112
  */
122
113
  export async function executeDrawioUrl(inputFile, options,
@@ -128,7 +119,7 @@ dependencies) {
128
119
  // 書き出すのは表示用 HTML だけなので、それ以外の拡張子は成果物を作る前に弾く。
129
120
  // 入力の読み込みより先に確認し、UsageError のときは成果物と警告を残さない。
130
121
  if (outputFile !== undefined && path.extname(outputFile).toLowerCase() !== '.html') {
131
- throw new DrawioUrlUsageError(`-o accepts only the .html extension: ${outputFile}`, 'invalid-output-extension');
122
+ throw new DrawioUrlUsageError(`output accepts only the .html extension: ${outputFile}`, 'invalid-output-extension');
132
123
  }
133
124
  const summary = await runDrawioUrl(inputFile, options, dependencies);
134
125
  const diagnostics = createDiagnostics(dependencies.stderr);
@@ -162,7 +153,7 @@ dependencies) {
162
153
  }
163
154
  payload = {
164
155
  file: outputFile,
165
- // eslint-disable-next-line unicorn/no-null -- JSON スキーマで PNG 失敗時に `png: null` を pin したいため
156
+ // eslint-disable-next-line unicorn/no-null -- 結果のスキーマで PNG 失敗時に `png: null` を pin したいため
166
157
  png: isPngFailed ? null : pngPath,
167
158
  pngFailed: isPngFailed,
168
159
  };
@@ -175,7 +166,6 @@ dependencies) {
175
166
  data: { event: 'drawio.url.done', ...payload, warnings: warningCount, theme: themeData(summary.theme) },
176
167
  artifacts,
177
168
  warningCount,
178
- exitCode: warningCount > 0 ? 3 : 0,
179
169
  url: summary.url,
180
170
  outputFile,
181
171
  };
@@ -196,7 +186,7 @@ export function errorToReason(error) {
196
186
  return themeErrorReason(error) ?? 'unknown';
197
187
  }
198
188
  /**
199
- `--json` のエラーイベントと MCP の data に載せる内容。CLI と MCP が同じ組み立てを使う。
189
+ 失敗時にツールの data に載せる内容。
200
190
  */
201
191
  export function errorData(error) {
202
192
  const violations = error instanceof DrawioUrlRuntimeError ? error.violations : undefined;
@@ -207,118 +197,15 @@ export function errorData(error) {
207
197
  ...(violations !== undefined && { violations }),
208
198
  };
209
199
  }
210
- /**
211
- 例外を exit code 規約へ写す(2 = UsageError とテーマの指定の誤り、1 = それ以外)。
212
-
213
- CLI の action と MCP ツールが同じ対応表を使うための共有点。
214
- */
215
- export function toExitCode(error) {
216
- // 呼び出し元に届くのは次のとおり。
217
- // runDrawioUrl / executeDrawioUrl 由来の RuntimeError と、テーマの解決・取得・宣言の失敗(exit 1)。
218
- // 出力拡張子の確認とテーマのパスの確認が投げる UsageError、テーマの指定の誤り(ThemeSpecError)は exit 2。
219
- // parseMode の UsageError だけは、呼び出し側 (action の options 組み立て) で処理済。
220
- return error instanceof DrawioUrlUsageError || error instanceof ThemeSpecError ? 2 : 1;
221
- }
222
- function doesArgvWantJson(argv) {
223
- return argv.includes('--json');
224
- }
225
- function parseMode(raw) {
226
- if (typeof raw !== 'string' || !VALID_MODES.has(raw)) {
227
- throw new DrawioUrlUsageError(`option --mode accepts only view or edit: ${String(raw)}`, 'invalid-mode');
228
- }
229
- return raw === 'edit' ? 'edit' : 'view';
230
- }
231
- export function createDrawioUrlCommand(buildDependencies) {
232
- const command = new Command('url')
233
- .description('turn drawio XML into artifacts that open directly in a browser (viewer HTML / rendered PNG)')
234
- .argument('<input>', 'input .drawio file path')
235
- .option('--mode <mode>', 'view or edit (cli-surface §2.4; the generated URL is the same)', 'view')
236
- .option('-o, --output <path>', 'output path of the viewer HTML (.html only; when given, no URL is printed to stdout)')
237
- .option('--json', 'print machine-readable JSON to stdout', false)
238
- .option('--theme <spec>', 'theme used to check fonts and font sizes (git+https://<host>/<owner>/<repo>.git#<tag>, file:<path>, or a talk-dir or theme root path); default: the diagram\'s ancestor talk-dir, else the plugin default')
239
- .option('--no-png', 'do not write the PNG alongside -o (default: write the PNG)', true)
240
- .exitOverride()
241
- .configureOutput({
242
- writeErr: (string_) => {
243
- const dependencies = buildDependencies();
244
- if (doesArgvWantJson(process.argv)) {
245
- writeData(dependencies.stdout, JSON.stringify({
246
- event: 'drawio.url.error',
247
- reason: 'invalid-option',
248
- detail: string_.replace(/^error:[ \t]*/i, '').trim(),
249
- }));
250
- }
251
- else {
252
- passthrough(dependencies.stderr, string_);
253
- }
254
- },
255
- writeOut: (string_) => { writeData(buildDependencies().stdout, string_); },
256
- })
257
- .action(async (input, raw) => {
258
- const dependencies = buildDependencies();
259
- let options;
260
- try {
261
- options = {
262
- mode: parseMode(raw['mode']),
263
- json: raw['json'] === true,
264
- png: raw['png'] !== false,
265
- theme: typeof raw['theme'] === 'string' ? raw['theme'] : undefined,
266
- output: typeof raw['output'] === 'string' ? raw['output'] : undefined,
267
- };
268
- }
269
- catch (error) {
270
- if (raw['json'] === true) {
271
- writeData(dependencies.stdout, JSON.stringify(errorData(error)));
272
- }
273
- else {
274
- createDiagnostics(dependencies.stderr).error(formatError(error));
275
- }
276
- process.exitCode = 2;
277
- return;
278
- }
279
- try {
280
- const execution = await executeDrawioUrl(input, options, dependencies);
281
- if (options.json) {
282
- writeData(dependencies.stdout, JSON.stringify(execution.data));
283
- }
284
- else if (execution.outputFile === undefined) {
285
- writeData(dependencies.stdout, execution.url);
286
- }
287
- else {
288
- createDiagnostics(dependencies.stderr).done({ verb: 'create', target: execution.outputFile });
289
- }
290
- if (execution.exitCode !== 0) {
291
- process.exitCode = execution.exitCode;
292
- }
293
- }
294
- catch (error) {
295
- if (options.json) {
296
- writeData(dependencies.stdout, JSON.stringify(errorData(error)));
297
- }
298
- else {
299
- createDiagnostics(dependencies.stderr).error(formatError(error));
300
- }
301
- process.exitCode = toExitCode(error);
302
- }
303
- });
304
- return command;
305
- }
306
200
  export function drawioUrlDefaultDependencies() {
307
- const pluginRoot = process.env['CLAUDE_PLUGIN_ROOT'];
308
- /* c8 ignore next 3 -- bin/pecotv が CLAUDE_PLUGIN_ROOT を必ず export する。未設定は実運用で発生しない */
309
- if (pluginRoot === undefined || pluginRoot === '') {
310
- throw new DrawioUrlRuntimeError('CLAUDE_PLUGIN_ROOT is not set', 'unknown');
311
- }
312
- const dependencyRoot = pluginDependencyRoot();
313
201
  return {
314
- pluginRoot,
315
- ...(dependencyRoot !== undefined && { dependencyRoot }),
202
+ pluginRoot: resolvePluginRoot(),
203
+ dependencyRoot: pluginDependencyRoot(),
316
204
  stdout: process.stdout,
317
205
  stderr: process.stderr,
318
206
  readFile: (filePath) => readFile(filePath, 'utf8'),
319
- // 出力先ディレクトリは pecotv 利用検知 hook が作る。
320
- // hook が動かない環境(旧プラグイン・CLAUDE_PROJECT_DIR 未設定)でも書き込めるよう、
321
- // capturePng (screenshot.ts) と同様に親ディレクトリを補う。
207
+ // 出力先ディレクトリは利用検知 hook が作る。
208
+ // hook が動かない環境でも書き込めるよう、capturePng (screenshot.ts) と同様に親ディレクトリを補う。
322
209
  // mkdir / writeFile のどちらが失敗しても、呼び出し元で output-write-failed に包まれる。
323
210
  writeFile: async (filePath, content) => {
324
211
  await mkdir(path.dirname(filePath), { recursive: true });
@@ -1,14 +1,8 @@
1
1
  import type { FailureReason } from '../../domain/_shared/failure-kind.js';
2
- import { Command } from 'commander';
3
2
  import type { LintText, TextViolation } from '../../domain/_shared/text-check.js';
4
3
  import type { NormalizedEvidenceSpec } from '../../domain/evidence-xlsx/spec-schema.js';
5
4
  import type { EvidenceSkippedImage, EvidenceWriteResult } from '../../infra/evidence-xlsx/workbook-writer.js';
6
5
  /**
7
- 実行失敗時の exit code。usage エラー (exit 2) は commander が cli.ts の main へ委譲するため、
8
- 本コマンド自身が設定するのは 1 のみ。
9
- */
10
- export declare const EVIDENCE_CREATE_FAILURE_EXIT_CODE = 1;
11
- /**
12
6
  spec の読込・parse・検証・文面確認の失敗理由。
13
7
  */
14
8
  export type EvidenceCreateErrorReason = 'input-not-found' | 'invalid-json' | 'invalid-spec' | 'text-violation' | 'text-lint-failed';
@@ -43,9 +37,9 @@ export interface EvidenceCreateOptions {
43
37
  readonly out: string;
44
38
  }
45
39
  /**
46
- `--json` の成功イベント。
40
+ 成功の結果。
47
41
 
48
- event 名が `evidence.create.done` ではなく `result` なのは、既存 CLI の外形に合わせたため。
42
+ event 名が `evidence.create.done` ではなく `result` なのは、従来の外形に合わせたため。
49
43
  他コマンドの `<command>.done` 規約からは外れるが、互換のため追認している。
50
44
  */
51
45
  export interface EvidenceCreateResultData {
@@ -56,15 +50,13 @@ export interface EvidenceCreateResultData {
56
50
  readonly skipped: readonly EvidenceSkippedImage[];
57
51
  }
58
52
  /**
59
- xlsx を生成し、`--json` と同形の結果オブジェクトを返す。
60
- CLI の action と MCP ツールはどちらもこの関数を呼ぶ (実行と結果組み立ての単一実装)。
53
+ xlsx を生成し、結果オブジェクトを返す。MCP ツールがこの関数を呼ぶ。
61
54
  */
62
55
  export declare function executeEvidenceCreate(options: Readonly<EvidenceCreateOptions>, dependencies: EvidenceCreateDependencies): Promise<EvidenceCreateResultData>;
63
- export declare function createEvidenceCreateCommand(buildDependencies: () => EvidenceCreateDependencies): Command;
64
56
  export declare function evidenceCreateDefaultDependencies(): EvidenceCreateDependencies;
65
57
  export declare function errorToReason(error: unknown): FailureReason;
66
58
  /**
67
- `--json` のエラーイベントと MCP の data に載せる内容。CLI と MCP が同じ組み立てを使う。
59
+ 失敗時にツールの data に載せる内容。
68
60
  */
69
61
  export declare function errorData(error: unknown): Readonly<Record<string, unknown>>;
70
62
  //# sourceMappingURL=create.d.ts.map
@@ -1,32 +1,21 @@
1
- // `pecotv evidence create --input <spec.json> [--out <path.xlsx>] [--json]` の実装。
2
- // drawio/url.ts と同形の DI / configureOutput の writeErr フックを採用する。
1
+ // evidence_create ツールの実装。drawio/url.ts と同形の DI を採用する。
3
2
  //
4
- // exit code 規約は contracts/evidence-cli.md §1 に従う。
5
- // 0 = 生成成功。除外警告があっても、有効画像が 1 件以上あれば成功とする。
6
- // 1 = spec の読込・parse・検証エラー、文面の違反、有効画像 0 件、xlsx の書き出し失敗。
7
- // 入力不正・文面の違反・有効画像 0 件では、出力に触れない。
8
- // output-write-failed では、部分生成物が残り得る。
9
- // 2 = commander の usage エラー。required option 未指定などが当たり、cli.ts の main が変換する。
10
- // ただし --help / --version は commander の想定内終了なので exit 0 とする。
3
+ // 失敗する場合:
4
+ // spec の読込・parse・検証エラー、文面の違反、有効画像 0 件、xlsx の書き出し失敗。
5
+ // 入力不正・文面の違反・有効画像 0 件では、出力に触れない。
6
+ // output-write-failed では、部分生成物が残り得る。
7
+ // 除外警告があっても、有効画像が 1 件以上あれば成功とする。
11
8
  import { readFile } from 'node:fs/promises';
12
9
  import path from 'node:path';
13
- import { Command } from 'commander';
14
- import { createDiagnostics, passthrough, writeData } from '../../diagnostics.js';
15
10
  import { collectTextViolations, formatTextViolations } from '../../domain/_shared/text-check.js';
16
11
  import { parseEvidenceSpec } from '../../domain/evidence-xlsx/spec-schema.js';
17
12
  import { specTexts } from '../../domain/evidence-xlsx/spec-text.js';
18
13
  import { EvidenceWorkbookError, writeEvidenceWorkbook } from '../../infra/evidence-xlsx/workbook-writer.js';
19
14
  import { defaultLintText } from '../../infra/text-lint.js';
20
- const DEFAULT_OUT = './evidence.xlsx';
21
15
  /**
22
- --json のエラーイベント名。契約に定義が無いため drawio 同形の `<command>.error` に揃える。
16
+ エラーの event 名。契約に定義が無いため drawio 同形の `<command>.error` に揃える。
23
17
  */
24
18
  const ERROR_EVENT = 'evidence.create.error';
25
- /**
26
- 実行失敗時の exit code。usage エラー (exit 2) は commander が cli.ts の main へ委譲するため、
27
- 本コマンド自身が設定するのは 1 のみ。
28
- */
29
- export const EVIDENCE_CREATE_FAILURE_EXIT_CODE = 1;
30
19
  export class EvidenceCreateError extends Error {
31
20
  reason;
32
21
  violations;
@@ -86,8 +75,7 @@ async function assertTextsClean(spec, lintText) {
86
75
  }
87
76
  }
88
77
  /**
89
- xlsx を生成し、`--json` と同形の結果オブジェクトを返す。
90
- CLI の action と MCP ツールはどちらもこの関数を呼ぶ (実行と結果組み立ての単一実装)。
78
+ xlsx を生成し、結果オブジェクトを返す。MCP ツールがこの関数を呼ぶ。
91
79
  */
92
80
  export async function executeEvidenceCreate(options,
93
81
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- write は可変。DI 経由の write は mutate メソッド
@@ -101,54 +89,6 @@ dependencies) {
101
89
  skipped: result.skipped,
102
90
  };
103
91
  }
104
- export function createEvidenceCreateCommand(buildDependencies) {
105
- return new Command('create')
106
- .description('generate a work-evidence xlsx from an EvidenceSpec JSON')
107
- .requiredOption('--input <path>', 'EvidenceSpec JSON path')
108
- .option('--out <path>', 'output xlsx path (an existing file is overwritten)', DEFAULT_OUT)
109
- .option('--json', 'print machine-readable JSON to stdout', false)
110
- .exitOverride()
111
- .configureOutput({
112
- writeErr: (string_) => {
113
- const dependencies = buildDependencies();
114
- if (doesArgvWantJson(process.argv)) {
115
- writeData(dependencies.stdout, JSON.stringify({
116
- event: ERROR_EVENT,
117
- reason: 'invalid-option',
118
- detail: string_.replace(/^error:[ \t]*/i, '').trim(),
119
- }));
120
- }
121
- else {
122
- passthrough(dependencies.stderr, string_);
123
- }
124
- },
125
- })
126
- .action(async (raw) => {
127
- const dependencies = buildDependencies();
128
- const isJson = raw['json'] === true;
129
- try {
130
- const data = await executeEvidenceCreate({
131
- input: optionString(raw['input'], ''),
132
- out: optionString(raw['out'], DEFAULT_OUT),
133
- }, dependencies);
134
- if (isJson) {
135
- writeData(dependencies.stdout, JSON.stringify(data));
136
- }
137
- else {
138
- writeHumanSummary(dependencies.stdout, data);
139
- }
140
- }
141
- catch (error) {
142
- if (isJson) {
143
- writeData(dependencies.stdout, JSON.stringify(errorData(error)));
144
- }
145
- else {
146
- createDiagnostics(dependencies.stderr).error(`evidence create: ${formatError(error)}`);
147
- }
148
- process.exitCode = EVIDENCE_CREATE_FAILURE_EXIT_CODE;
149
- }
150
- });
151
- }
152
92
  export function evidenceCreateDefaultDependencies() {
153
93
  return {
154
94
  stdout: process.stdout,
@@ -159,22 +99,6 @@ export function evidenceCreateDefaultDependencies() {
159
99
  };
160
100
  }
161
101
  /**
162
- 人間向けサマリ (contracts §1)。除外が無いときは除外ブロックを出さない。
163
- */
164
- function writeHumanSummary(
165
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- write は mutate メソッド
166
- stdout, data) {
167
- writeData(stdout, `created: ${data.outPath}`);
168
- writeData(stdout, `items: ${data.items.toString()} / annotations: ${data.annotations.toString()}`);
169
- if (data.skipped.length === 0) {
170
- return;
171
- }
172
- writeData(stdout, `skipped: ${data.skipped.length.toString()}`);
173
- for (const entry of data.skipped) {
174
- writeData(stdout, ` - ${entry.path} (${entry.reason})`);
175
- }
176
- }
177
- /**
178
102
  検証エラーは全件列挙する (どれを直せば通るかを 1 回の実行で示す)。
179
103
  */
180
104
  function formatSpecErrors(errors) {
@@ -182,13 +106,6 @@ function formatSpecErrors(errors) {
182
106
  .map(error => ` - ${error.path === '' ? '(root)' : error.path}: ${error.message}`)
183
107
  .join('\n');
184
108
  }
185
- function optionString(value, fallback) {
186
- /* c8 ignore next -- requiredOption と既定値により commander が非 string を通さない、防御網のみ */
187
- return typeof value === 'string' ? value : fallback;
188
- }
189
- function doesArgvWantJson(argv) {
190
- return argv.includes('--json');
191
- }
192
109
  export function errorToReason(error) {
193
110
  if (error instanceof EvidenceCreateError)
194
111
  return error.reason;
@@ -198,7 +115,7 @@ export function errorToReason(error) {
198
115
  return 'unknown';
199
116
  }
200
117
  /**
201
- `--json` のエラーイベントと MCP の data に載せる内容。CLI と MCP が同じ組み立てを使う。
118
+ 失敗時にツールの data に載せる内容。
202
119
  */
203
120
  export function errorData(error) {
204
121
  const violations = error instanceof EvidenceCreateError ? error.violations : undefined;
@@ -1,5 +1,4 @@
1
1
  import type { FailureReason } from '../../domain/_shared/failure-kind.js';
2
- import { Command } from 'commander';
3
2
  import type { ThemeFiles } from '../../domain/slidev-theme/ports.js';
4
3
  import type { LayoutCatalog } from '../../domain/slidev-theme/references.js';
5
4
  import { fetchTheme } from '../../infra/slidev-theme/store.js';
@@ -11,20 +10,10 @@ export interface SlideCreateOptions {
11
10
  */
12
11
  readonly theme: string;
13
12
  readonly force: boolean;
14
- /**
15
- レイアウトの一覧を stdout に書き出すか。
16
-
17
- 人間向け出力専用の副作用なので、判定材料を `--json` フラグから独立させている。
18
- CLI は `--json` 無しのときだけ true にし、MCP ツールルートは常に false で呼ぶ
19
- (結果として捕捉する stdout にカタログを混在させないため)。
20
-
21
- 読むのは `executeSlideCreate` だけで、`runSlideCreate` は一覧に触れない。
22
- */
23
- readonly emitCatalog: boolean;
24
13
  }
25
14
  export interface SlideCreateDependencies {
26
15
  /**
27
- 同梱アセットの起点。CLAUDE_PLUGIN_ROOT。
16
+ 同梱アセットの起点(resolvePluginRoot)。
28
17
  */
29
18
  readonly pluginRoot: string;
30
19
  /**
@@ -74,7 +63,7 @@ export { SlideCreateUsageError } from '../../domain/slidev-project/errors.js';
74
63
  テーマを取得し、talk-dir を生成する。
75
64
 
76
65
  生成は生成先と同じ親の下の一時 dir で組み立て、最後に入れ替える。
77
- `--force` で既存の生成先があっても、取得・生成のどこで失敗しても、既存は消えない。
66
+ `force` で既存の生成先があっても、取得・生成のどこで失敗しても、既存は消えない。
78
67
  失敗したら一時 dir を消す。取得中の警告は、失敗の前に出たものも stderr へ流す。
79
68
  */
80
69
  export declare function runSlideCreate(projectDirectory: string, options: Readonly<SlideCreateOptions>, dependencies: SlideCreateDependencies): Promise<SlideCreateRun>;
@@ -82,31 +71,17 @@ export interface SlideCreateExecution {
82
71
  readonly summary: SlideCreateResultSummary;
83
72
  readonly lint: AutoDeckLintReport;
84
73
  /**
85
- `--json` の `slide.create.done` payload。MCP ツールの構造化データもこれをそのまま返す。
74
+ `slide.create.done` の payload。MCP ツールの構造化データもこれをそのまま返す。
86
75
  */
87
76
  readonly data: Readonly<Record<string, unknown>>;
88
77
  }
89
78
  /**
90
- `slide create` の実処理と機械可読な結果組み立て。CLI action と MCP ツールの双方がここを通る。
91
-
92
- @param onCreated 生成完了時点(deck lint より前)に呼ばれる。CLI は人間向けの成否行を
93
- ここで書き、違反一覧より先に出す。MCP ツールは渡さない。
79
+ slide_create の実処理と機械可読な結果組み立て。MCP ツールがここを通る。
94
80
  */
95
- export declare function executeSlideCreate(projectDirectory: string, options: Readonly<SlideCreateOptions>, dependencies: SlideCreateDependencies, onCreated?: (summary: Readonly<SlideCreateResultSummary>) => void): Promise<SlideCreateExecution>;
96
- /**
97
- 収集済みのレイアウトの一覧を人間向けに stdout へ書き出す。分類ごとに群化し、deprecated は群内で
98
- `[deprecated]` 接頭辞を付ける(選ばない対象だが、分類から外して別枠にすると、その分類に
99
- 何が属するかが読めなくなる)。レイアウトが 0 件の分類も見出しを出して不足を見せる。
100
- */
101
- export declare function emitLayoutCatalog(catalog: Readonly<Pick<LayoutCatalog, 'categories' | 'layouts'>>, stdout: NodeJS.WritableStream): void;
81
+ export declare function executeSlideCreate(projectDirectory: string, options: Readonly<SlideCreateOptions>, dependencies: SlideCreateDependencies): Promise<SlideCreateExecution>;
102
82
  /**
103
83
  失敗の reason。テーマの取得・宣言・指定の失敗は `theme-<reason>`(`themeErrorReason`)にする。
104
84
  */
105
85
  export declare function errorToReason(error: unknown): FailureReason;
106
- /**
107
- 失敗時の exit code。usage error(引数の誤り、テーマの指定の誤り)= 2、それ以外の実行失敗 = 1。
108
- */
109
- export declare function toExitCode(error: unknown): number;
110
- export declare function createSlideCreateCommand(buildDependencies: () => SlideCreateDependencies): Command;
111
86
  export declare function slideCreateDefaultDependencies(): SlideCreateDependencies;
112
87
  //# sourceMappingURL=create.d.ts.map