@first-ch/tools-mcp 0.34.1 → 0.37.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/sql-format.mjs CHANGED
@@ -3,7 +3,8 @@
3
3
  // 「整形コア」ブロックは site 側の site/sql-format/app.js と同一の実装。
4
4
  // 2箇所ルール: 片方を直したらもう片方も同じ内容で直す(site側が正本)。
5
5
  // 使っているのは String/RegExp/Array/Set だけなので、ブラウザ版のコードをそのまま持ってこられる。
6
- import { readFile, writeFile } from 'node:fs/promises';
6
+ import { readFile } from 'node:fs/promises';
7
+ import { writeOutput } from './fs-safe.mjs';
7
8
  import { basename } from 'node:path';
8
9
 
9
10
  /* ==================== ここから整形コア(site / MCP で同一) ==================== */
@@ -685,7 +686,7 @@ export async function sqlFormatTool(opts = {}) {
685
686
  notes: r.notes.map((n) => ({ code: n.code, message: noteMessage(n) })),
686
687
  };
687
688
  if (opts.outputPath) {
688
- await writeFile(opts.outputPath, r.text, 'utf8');
689
+ await writeOutput(opts.outputPath, r.text, { overwrite: opts.overwrite });
689
690
  result.output = opts.outputPath;
690
691
  // ファイルに書けたなら本文は重複した重い情報でしかない
691
692
  delete result.text;
package/webp.mjs CHANGED
@@ -4,7 +4,8 @@
4
4
  // =ブラウザ版と同一品質・同一アルゴリズム。
5
5
  // PNG/JPEG のデコードのみ Node に Canvas がないため pure-JS の pngjs / jpeg-js で行う。
6
6
 
7
- import { readFile, writeFile } from 'node:fs/promises';
7
+ import { readFile } from 'node:fs/promises';
8
+ import { writeOutput } from './fs-safe.mjs';
8
9
  import path from 'node:path';
9
10
  import { PNG } from 'pngjs';
10
11
  import jpeg from 'jpeg-js';
@@ -42,7 +43,7 @@ function decodeImage(buf, file) {
42
43
  /**
43
44
  * 1ファイルをWebPへ変換する。
44
45
  * @param {string} input 入力ファイルの絶対パス(PNG/JPEG)
45
- * @param {object} opts { output?: 出力パス(既定=入力の拡張子を.webpに), quality?: 1-100(既定80・サイト版と同じ) }
46
+ * @param {object} opts { output?: 出力パス(既定=入力の拡張子を.webpに), quality?: 1-100(既定80・サイト版と同じ), overwrite?: 既存ファイルを上書きするか(既定 false) }
46
47
  * @returns {Promise<object>} { input, output, width, height, bytesIn, bytesOut, saving }
47
48
  */
48
49
  export async function convertToWebp(input, opts = {}) {
@@ -54,7 +55,7 @@ export async function convertToWebp(input, opts = {}) {
54
55
  const result = encoder.encode(image.data, image.width, image.height, { ...defaultOptions, quality });
55
56
  if (!result) throw new Error(`${path.basename(input)}: エンコードに失敗しました`);
56
57
  const webp = result.buffer;
57
- await writeFile(output, Buffer.from(webp));
58
+ await writeOutput(output, Buffer.from(webp), { overwrite: opts.overwrite === true });
58
59
  const bytesOut = webp.byteLength;
59
60
  return {
60
61
  input,
package/zenkaku.mjs CHANGED
@@ -3,7 +3,8 @@
3
3
  // 「変換コア」ブロックは site 側の site/zenkaku/app.js と同一の実装。
4
4
  // 2箇所ルール: 片方を直したらもう片方も同じ内容で直す(site側が正本)。
5
5
  // 使っているのは String/RegExp/Map だけなので、ブラウザ版のコードをそのまま持ってこられる。
6
- import { readFile, writeFile } from 'node:fs/promises';
6
+ import { readFile } from 'node:fs/promises';
7
+ import { writeOutput } from './fs-safe.mjs';
7
8
  import { basename } from 'node:path';
8
9
 
9
10
  /* ==================== ここから変換コア(site / MCP で同一) ==================== */
@@ -445,7 +446,7 @@ export async function zenkakuConvertTool(opts = {}) {
445
446
  const i = notes.findIndex((n) => n.code === 'UNCHANGED');
446
447
  if (i !== -1) notes.splice(i, 1);
447
448
  } else if (opts.outputPath) {
448
- await writeFile(opts.outputPath, r.text, 'utf8');
449
+ await writeOutput(opts.outputPath, r.text, { overwrite: opts.overwrite });
449
450
  result.output = opts.outputPath;
450
451
  } else if ([...r.text].length > MAX_TEXT) {
451
452
  result.text = [...r.text].slice(0, MAX_TEXT).join('');