@first-ch/tools-mcp 0.47.0 → 0.48.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/README.md CHANGED
@@ -91,6 +91,7 @@ This server is also registered in the [MCP Registry](https://registry.modelconte
91
91
  | `wiki_doc_lint` | Audits an exported internal wiki — Markdown, HTML or text exported from Notion, Backlog Wiki, Confluence and the like (same logic as tools.first-ch.com/wiki-doc-lint/). Returns **near-duplicate page pairs** (`duplicates`: Jaccard index of four-character fragments of the text with symbols and spaces removed, at or above `threshold`, with the lines only one side has and a fix that keeps the page with more incoming links, or the longer one on a tie), **orphan pages that no other page links to** (`orphans`, with `addLine` — the link line to add to a Notion-style parent or a contents page; index/README/home pages are not counted unless `entryPages=false`), **inconsistent and outdated terms** (`terms`: a "preferred ← variant" dictionary — your `dictionary` is added to the default one — plus Japanese katakana words found both with and without a final long-vowel mark, suggesting the majority form; every hit has its line and the line before/after the fix), **broken links** (`broken`: relative links with a document extension and `[[Page name]]` links whose target is not among the files) and a Markdown `report` of suggested fixes. Links are read from `[text](path)`, `[[Page name]]` and `<a href>`, matched by relative path, title, Notion file names with their IDs and the page name at the end of Notion/Confluence URLs. Code blocks, inline code, URLs and tags are skipped for terms, and matches inside a longer word (ユーザ in ユーザビリティ, Javascript in Javascripts) are ignored. Pass `paths` (absolute files or folders, read recursively; hidden folders and node_modules are skipped) or `files`. UTF-8, Shift_JIS and UTF-16 (BOM) are detected; up to 3,000 files / 60 MB. Read-only — it never edits the files | `paths?` or `files?` (`[{ path, text }]`), `threshold?` (0.5–1, default 0.8), `dictionary?`, `useDefaultDictionary?`, `autoChoon?`, `entryPages?`, `format?` (`both` default / `json` / `markdown`), `lang?` (`ja` default / `en`) |
92
92
  | `fit_to_box` | Character size and line breaks for writing a string by hand into a printed box — e.g. the address, amount and name boxes on the inner envelope (nakabukuro) of a Japanese wedding or condolence money envelope (same logic as tools.first-ch.com/en/nakabukuro-ran/). From the box width and height (mm) and direction, returns the character size that fits (mm, rounded down to 0.1 mm), the line count and each line. Size uses a 1.5 mm margin inside each side and a 0.3× line gap, limited by both line length and line count (half-width letters/digits count as 0.6 in horizontal boxes; caps of 9 mm for addresses, 14 mm for amount/name). `kind: "address"` breaks between the street number and the building/room first, and only when that cannot reach 4 mm also after the prefecture/city or before the street number (runs like 12番地の18 or 1203号室 are never split; a line break in `text` marks the building; up to 4 lines); `postalCode` adds a 〒 line; vertical boxes get kanji street numbers (`numerals`: `digits` = 一〇, `tens` = 十). Below 4 mm, `alternatives` gives the size and lines with the prefecture dropped and with the building on two lines (it does not decide what may be dropped); `asIs` is how many characters spill out when written unbroken at 5 mm. `kind: "amount"` writes 30000 / 3万 / 30,000円 in formal numerals (daiji) as 金参萬円 (1–99,999,999; 圓, 也 and pre-printed 金/円 supported); `name` breaks only at spaces; `plain` takes any text | `text`, `width`, `height` (mm), `orientation?` (`vertical` default / `horizontal`), `kind?` (`address` default / `name` / `amount` / `plain`), `postalCode?`, `numerals?`, `thousandChar?` (阡 default / 千 / 仟), `yenChar?` (円 / 圓), `nari?`, `kinEnPrinted?`, `lang?` |
93
93
  | `invoice_nebiki_check` | For a freelancer in Japan who is **not a registered invoice issuer** and is asked for a price cut (same logic as tools.first-ch.com/invoice-nebiki/). From three answers — the client's consumption tax `method` (`general` / `simplified` / `niwari` 20% rule / `sanwari` 30% rule / `exempt` / `unknown`), `party` (`individual` / `corporation`, required for the special rules) and `small` (is one invoice under ¥10,000 incl. tax) — returns `rows` per period from `today`: `diff` (monthly difference = amount × 10/110 × 20/30/50/70/100%, rounded down), `none` or `check`. The 20% rule gives no difference to 2026 for sole proprietors and to the tax period including Sep 30, 2026 for corporations; the 30% rule covers sole proprietors' 2027–2028 only; after that `recheck: true` (no assumption of simplified taxation). Purchases that may fall under the small-amount rule (to Sep 30, 2029) are `check`. Optional `monthly`, `cutRate` / `cutAmount` add a comparison; `message` asks only the open points (`format: "md"` for Markdown) and always carries the four assumptions; `showAmount: false` hides yen amounts. |
94
+ | `reply_check` | Checks an AI-drafted reply against the email it answers before you send it (same logic as tools.first-ch.com/okurumae/). From `reply` it picks up **dates, weekdays, times, amounts, quantities (guests, nights, %), phone numbers, emails, URLs, names** (〇〇様, Dear Ms. …) and other numbers; those found in neither `received` nor your optional `facts` (hours, prices, dates) are `red` (`missing`), matches are `green` with the matching spots in `hits`, and leftover placeholders (`[Customer 1]`, 〇〇, XX, 【】, `{name}`) are `yellow`. A weekday that does not fit the date (e.g. Friday, November 8 in 2026) or a date that does not exist is `red` too (`weekday` / `nodate`, with the actual weekday). Dates without a year are checked in the year that falls between 60 days before and 305 days after `today`. Full-/half-width forms, commas, 18時30分 vs 18:30 and 3千円 vs 3,000円 are aligned for matching only — the text is never rewritten, and `start`/`end`/`line`/`column` point into `reply` as written. `count` covers every item; `items` stops at 500 (`truncated`). A `note` always says that 0 red does not mean the reply is correct. No auto-fix, no tone editing. Up to 20,000 characters per field | `reply`, `received?`, `facts?`, `today?` (YYYY-MM-DD), `includeGreen?` (default true), `lang?` (`ja` default / `en`) |
94
95
 
95
96
  ### App tools (`app_*`, sent to apps.first-ch.com)
96
97
 
@@ -280,6 +281,7 @@ claude mcp add firstch-tools -- npx -y @first-ch/tools-mcp
280
281
  | `wiki_doc_lint` | Notion・Backlog Wiki・Confluence などから書き出した社内文書(Markdown / HTML / テキスト)を点検する(tools.first-ch.com/wiki-doc-lint/ と同一ロジック)。**内容がほぼ同じページの組**(`duplicates`: 記号と空白を除いた本文の4文字単位の断片の Jaccard 係数が `threshold` 以上の組・それぞれにしかない行・被リンクの多い方〔同数なら本文が長い方〕を残す修正案)、**ほかのどのページからもリンクされていない孤立ページ**(`orphans`: Notion 型の親ページか目次ページに足すリンクの1行 `addLine` つき。index・README・home などの目次ページは `entryPages=false` にしない限り数えない)、**表記ゆれ・旧称**(`terms`: 「揃える表記 ← ゆれ」の辞書〔`dictionary` は既定の辞書に足す〕と、辞書に無いカタカナ語の語末の長音ゆれ〔多い方に揃える案〕。各箇所の行番号と修正前後の文)、**リンク切れ**(`broken`: 文書の拡張子を持つ相対リンクと `[[ページ名]]` のうち行き先が無いもの)、修正案をまとめた Markdown の `report` を返す。リンクは `[文字](パス)`・`[[ページ名]]`・a タグを読み、相対パス・ページ名・Notion のIDつきファイル名・Notion/Confluence のURL末尾のページ名で照合する。コードブロック・インラインコード・URL・タグは表記ゆれの対象外で、語の途中(ユーザビリティの中のユーザ)は拾わない。`paths`(ファイル・フォルダーの絶対パス。サブフォルダーまで読み、隠しフォルダーと node_modules は飛ばす)か `files` を渡す。UTF-8・Shift_JIS・UTF-16(BOM)を自動判別し、3,000ファイル・合計60MBまで。ファイルは読むだけで書き換えない | `paths?` または `files?`(`[{ path, text }]`)、`threshold?`(0.5〜1・既定 0.8)、`dictionary?`、`useDefaultDictionary?`、`autoChoon?`、`entryPages?`、`format?`(既定 `both` / `json` / `markdown`)、`lang?`(既定 `ja` / `en`) |
281
282
  | `fit_to_box` | 印刷済みの記入欄(市販の中袋〔ご祝儀袋・香典袋〕の「住所」「金額」「氏名」の欄など)に手で書くとき、欄の幅・高さ(mm)と向きから、収まる1字の大きさ(mm・0.1mm単位で切り捨て)・行数・改行した後の各行を返す(tools.first-ch.com/nakabukuro-ran/ と同一ロジック)。欄の線から内側へ1.5mmずつ余白を取り、行間を字の0.3倍として、行の長さと行数の両方から決める(横書きの半角英数は0.6字分・上限は住所9mm・金額と氏名14mm)。`kind: "address"` は「〜番地」と「建物名・部屋番号」の境目で改行し、そこで4mmに届かないときだけ都道府県・市区町村の後や番地の前でも区切る(「12番地の18」「1203号室」など数字の並びの途中では切らない・`text` の改行は建物名の前として扱う・最大4行)。`postalCode` で「〒」の行を先頭に足し、縦書きの欄では番地を漢数字にする(`numerals`: `digits`=一〇型 / `tens`=十型)。1字が4mm未満なら `alternatives` に「都道府県を省いた場合」「建物名を2行にした場合」の大きさと行を返す(省いてよいかは判断しない)。`asIs` は改行せずに1字5mmで書いたときにはみ出す字数。`kind: "amount"` は 30000・3万・30,000円 を大字の「金参萬円」にして欄に合わせる(1〜99,999,999円・圓/也/「金」「円」が印刷済みに対応)。`name` は空白でだけ改行し、`plain` は任意の文字列 | `text`、`width`・`height`(mm)、`orientation?`(既定 `vertical` / `horizontal`)、`kind?`(既定 `address` / `name` / `amount` / `plain`)、`postalCode?`、`numerals?`、`thousandChar?`(既定 阡 / 千 / 仟)、`yenChar?`(円 / 圓)、`nari?`、`kinEnPrinted?`、`lang?` |
282
283
  | `invoice_nebiki_check` | インボイス未登録のまま取引先から値下げを求められた個人の制作者向け(tools.first-ch.com/invoice-nebiki/ と同一ロジック)。取引先の申告方式 `method`(`general` 一般課税・`simplified` 簡易課税・`niwari` 2割特例・`sanwari` 3割特例・`exempt` 免税・`unknown`)、`party`(個人・法人。特例では必須)、`small`(1回の請求が税込1万円未満か)の3問から、`today` を含む時期以降を `diff`(差あり・月額=税込×10/110×20/30/50/70/100% の1円未満切り捨て)・`none`(差なし)・`check`(要確認)で返す。2割特例は個人2026年分・法人は2026年9月30日を含む課税期間まで、3割特例は個人の2027・2028年分だけで、期限後は `recheck: true`(簡易課税へ移ったとは仮定しない)。少額特例(2029年9月30日まで)が効きうる取引は要確認。任意の `monthly`・`cutRate`/`cutAmount` で値下げと比べ、`message` は要確認の点だけを尋ねる確認文(前提4点つき・`format: "md"` で Markdown)。`showAmount: false` で金額を出さない。 |
284
+ | `reply_check` | 届いたメール(`received`)と任意の「自分で決めた事実」(`facts`:営業時間・料金・日程など)を、AI が書いた返信案(`reply`)と照らし合わせる(tools.first-ch.com/okurumae/ と同一ロジック)。返信案の**日付・曜日・時刻・金額・数量(〇名・〇泊・%)・電話番号・メールアドレス・URL・宛名(〇〇様・Dear Ms. …)・番号**のうち、原文のどちらにも無いものを `red`(`missing`)、あるものを `green`(一致した箇所は `hits`)、`[お客様1]`・〇〇・XX・【】・`{name}` などの消し忘れを `yellow` で返す。日付と曜日の食い違い(例: 2026年の11月8日(金))と存在しない日付も `red`(`weekday` / `nodate`・実際の曜日つき)。年の無い日付は `today` の60日前〜305日後に入る年で確かめる。全角/半角・カンマ・「18時30分」と「18:30」・「3千円」と「3,000円」は照合のときだけそろえ、本文は書き換えない(`start`/`end`/`line`/`column` は元の返信案の位置)。`count` は全件、`items` は500件まで(`truncated`)。「赤が0件でも内容の正しさは保証しない」注意(`note`)を常に付ける。自動修正・文体の添削はしない。各欄2万字まで | `reply`、`received?`、`facts?`、`today?`(YYYY-MM-DD)、`includeGreen?`(既定 true)、`lang?`(既定 `ja` / `en`) |
283
285
 
284
286
  #### apps のツール(`app_*`・apps.first-ch.com へ送信)
285
287
 
@@ -193,7 +193,10 @@ function pick(v, list, name) {
193
193
 
194
194
  function isoDay(d) {
195
195
  if (d == null || d === '') { var n = new Date(); return n.getFullYear() + '-' + String(n.getMonth() + 1).padStart(2, '0') + '-' + String(n.getDate()).padStart(2, '0'); }
196
- if (!/^\d{4}-\d{2}-\d{2}$/.test(String(d))) throw new InvoiceNebikiError('INVALID_TODAY', 'today must be YYYY-MM-DD');
196
+ var m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(d));
197
+ var t = m && new Date(Date.UTC(+m[1], +m[2] - 1, +m[3]));
198
+ // 形式だけでなく実在する日付か(2026-13-45 や 2026-02-29 を時期の判定に通さない)
199
+ if (!t || t.getUTCFullYear() !== +m[1] || t.getUTCMonth() !== +m[2] - 1 || t.getUTCDate() !== +m[3]) throw new InvoiceNebikiError('INVALID_TODAY', 'today must be an existing date in YYYY-MM-DD');
197
200
  return String(d);
198
201
  }
199
202
 
@@ -373,7 +376,8 @@ export function decodeState(hash) {
373
376
  var out = {};
374
377
  String(hash || '').replace(/^#/, '').split('&').forEach(function (kv) {
375
378
  var i = kv.indexOf('='); if (i < 0) return;
376
- var k = kv.slice(0, i), v = decodeURIComponent(kv.slice(i + 1));
379
+ var k = kv.slice(0, i), v;
380
+ try { v = decodeURIComponent(kv.slice(i + 1)); } catch (e) { return; } // 壊れた % はその項目だけ読まない
377
381
  if (k === 'm' && METHODS.indexOf(v) >= 0) out.method = v;
378
382
  if (k === 's' && SMALLS.indexOf(v) >= 0) out.small = v;
379
383
  if (k === 'p' && (v === 'i' || v === 'c')) out.party = v === 'i' ? 'individual' : 'corporation';
@@ -385,6 +389,12 @@ export function decodeState(hash) {
385
389
  // ===== ここまでコア =====
386
390
 
387
391
  // ---- MCP の入口 ----
392
+ // showAmount:false で、額の値下げを月額なしで渡したとき(率が出せない)の比較の文。額を伏せたまま状況だけを伝える
393
+ const HIDDEN_CUT = {
394
+ ja: { noDiff: '今の時期、前提のもとで相手側の差は出ない見込みです(値下げの額は伏せています)。', check: '要確認の点が分かるまで、相手側の差は確定しません(値下げの額は伏せています)。' },
395
+ en: { noDiff: 'For now, under these assumptions, they see no difference (the cut amount is hidden).', check: 'Their difference is not fixed until the open points are confirmed (the cut amount is hidden).' },
396
+ };
397
+
388
398
  export function invoiceNebikiTool(opts = {}) {
389
399
  const lang = opts.lang === 'en' ? 'en' : 'ja';
390
400
  const showAmount = opts.showAmount !== false;
@@ -393,9 +403,13 @@ export function invoiceNebikiTool(opts = {}) {
393
403
  const r = judge({ method: opts.method, party: opts.party, small: opts.small, monthly: opts.monthly, cut, today: opts.today });
394
404
  const L = T[lang];
395
405
  const cmp = showAmount ? r.compare : { ...r.compare, cutAmount: null, diffAmount: null };
406
+ // 金額を出さない指定では、返り値の input と fragment からも額(月額・額の値下げ)を外す。率の値下げは額ではないので残す
407
+ const cutOut = showAmount || !r.input.cut || r.input.cut.type === 'rate' ? r.input.cut : { type: 'amount', value: null };
408
+ const shown = { ...r.input, monthly: showAmount ? r.input.monthly : null, cut: cutOut };
409
+ const hiddenCut = !showAmount && cmp.cutPct == null && (cmp.kind === 'noDiff' || cmp.kind === 'check');
396
410
  return {
397
411
  ok: true,
398
- input: { ...r.input, methodLabel: L.method[r.input.method] },
412
+ input: { ...shown, methodLabel: L.method[r.input.method] },
399
413
  rows: r.rows.map((row) => {
400
414
  const t = rowText(row, lang, showAmount);
401
415
  return { from: row.from, to: row.to, status: row.status, statusLabel: t.status, recheck: row.recheck, current: row.now,
@@ -403,10 +417,10 @@ export function invoiceNebikiTool(opts = {}) {
403
417
  monthlyDiff: showAmount ? row.amount : null, ifStandardMonthlyDiff: showAmount && row.status === 'check' ? row.hintAmount : null,
404
418
  label: t.label, text: row.status === 'diff' ? t.value : row.status === 'check' ? t.hint : '', note: t.note };
405
419
  }),
406
- comparison: { ...cmp, text: cutText({ ...r, compare: cmp }, lang) },
420
+ comparison: { ...cmp, text: hiddenCut ? HIDDEN_CUT[lang][cmp.kind] : cutText({ ...r, compare: cmp }, lang) },
407
421
  questions: r.questions.map((q) => ({ id: q, text: L.msg.q[q] })),
408
422
  message: buildMessage(r, { lang, format: opts.format === 'md' ? 'md' : 'text', showAmount }),
409
423
  premises: L.premises,
410
- fragment: encodeState({ method: r.input.method, party: r.input.party, small: r.input.small, monthly: r.input.monthly, cut: r.input.cut }),
424
+ fragment: encodeState({ method: r.input.method, party: r.input.party, small: r.input.small, monthly: shown.monthly, cut: cutOut && cutOut.value != null ? cutOut : null }),
411
425
  };
412
426
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@first-ch/tools-mcp",
3
- "version": "0.47.0",
4
- "description": "First CH Tools の計算ロジック(WCAGコントラスト比・文字数/Xウェイト・WebP変換・JSON-LD生成・llms.txt生成・文字コード/改行コード変換・Marp Markdown→スライド レンダリング・テストデータ生成・テキスト/コード差分・Cron式の解説・Base64/Data URI変換・URLパラメータの分解/再構築・HTML特殊文字のエスケープ/エンティティのデコード・JSON⇄YAMLの相互変換・px⇄rem/emの単位換算とCSSの一括変換・カラーコードの相互変換とアルファ透過の合成・MD5/SHA-1/SHA-256/SHA-384/SHA-512のハッシュ生成と照合・JWTのデコードと有効期限/署名の検証・User-Agent文字列の解析とデバイス判定・UUID v4/ULIDの一括生成・アスペクト比の計算とレスポンシブサイズの算出・TSV/CSVからMarkdownテーブルへの整形と相互変換・SQLクエリの整形と予約語の大文字化・URL/テキストからのQRコード生成・UNIXタイムスタンプと日時表記の相互変換・robots.txtの生成(AIクローラーの許可プリセット付き)・文字列のケース変換(camelCase/snake_case/kebab-case など11形式)・CSV/TSVとJSON配列の相互変換(区切りの自動判定・a.b 列と入れ子の相互展開)・全角⇄半角の変換とテキストの掃除(文字種ごとの向き指定・半角カナの合成/分解・空白と空行の整理)・IPアドレス/CIDRの計算(ネットワーク・ブロードキャスト・ホスト範囲とホスト数・IPv4/IPv6・サブネット分割・包含判定・IP範囲→最小CIDR集合の逆算)・日数/営業日の計算(2日付間の日数と営業日数・起点日+N日/N営業日の期日・締め日と支払サイトからの支払日・土日と日本の祝日を内蔵)・HTML→Markdownの変換(見出し/リスト/表/リンク/画像/コード・script/styleや装飾タグの除去・本文だけの抽出・相対URLの絶対化)・和暦⇄西暦の変換(令和〜明治・自動判定・曜日と干支・存在しない和暦の指摘・満年齢と入学/卒業の年・元号一覧と早見表)・日本語タイトルからのURLスラッグ生成(かな→ヘボン式ローマ字・記号除去・ハイフン/アンダースコア連結・小文字化・長音の省略/表記)・Basic認証用 htpasswd の生成と照合(bcrypt / apr1-md5・パスワードの自動生成・Apache / nginx の設定スニペット)・OpenAPI/Swagger仕様書から日本語のMarkdownドキュメントとTypeScript型定義の生成(OpenAPI 3.x / Swagger 2.0・YAML/JSON・$ref/allOf/oneOf 対応・エンドポイントごとの引数/レスポンス型・外部 $ref は読みに行かない)・FAQ構造化データ(FAQPage の JSON-LD・Markdown・details/summary の HTML を同時生成・回答のリンク/箇条書きを HTML 化・「Q: / A:」形式の一括貼り付けの解析)・テキストの行操作(重複行の削除・数値を認識する並べ替え・シード付きシャッフル・行番号・空行除去・前後トリム・接頭辞/接尾辞)・印刷サイズとDPIの計算(用紙×解像度×塗り足しから必要なピクセル数・手持ちの画像の実効dpiと判定・早見表・mm/inch/px/pt/級の換算)・SERPのメタタグ文字数チェック(title / description が検索結果に収まるかをピクセル幅で判定・切り詰め位置と表示行・パンくず表示・https や階層の指摘)・Flexbox / CSS GridのCSS生成(既定値を省いた宣言・repeat()への畳み込み・grid-template-areasの検証・効かない組み合わせの指摘・定番プリセット)・社内文書の点検(Notion・Confluence などから書き出した Markdown/HTML の重複ページ・孤立ページ・表記ゆれや旧称・リンク切れの検出と修正案)・記入欄に収める字の大きさと改行位置(中袋〔ご祝儀袋・香典袋〕の住所欄などの幅・高さmmから1字の大きさ・行数・改行位置・縦書きの漢数字・金額の大字))をMCPツールとして提供するサーバー。あわせて apps.first-ch.com のWebアプリ38本(GEO・メタタグ・セキュリティヘッダー・SSL・DNS・リダイレクト・リンク切れ・構造化データ・AIクローラー許可・和文可読性・ビジネス文面チェック等)の JSON API を呼ぶ app_* ツールも提供する(こちらは入力を apps.first-ch.com へ送るため既定では無効・FIRSTCH_ENABLE_APPS=1 で有効)",
3
+ "version": "0.48.0",
4
+ "description": "First CH Tools の計算ロジック(WCAGコントラスト比・文字数/Xウェイト・WebP変換・JSON-LD生成・llms.txt生成・文字コード/改行コード変換・Marp Markdown→スライド レンダリング・テストデータ生成・テキスト/コード差分・Cron式の解説・Base64/Data URI変換・URLパラメータの分解/再構築・HTML特殊文字のエスケープ/エンティティのデコード・JSON⇄YAMLの相互変換・px⇄rem/emの単位換算とCSSの一括変換・カラーコードの相互変換とアルファ透過の合成・MD5/SHA-1/SHA-256/SHA-384/SHA-512のハッシュ生成と照合・JWTのデコードと有効期限/署名の検証・User-Agent文字列の解析とデバイス判定・UUID v4/ULIDの一括生成・アスペクト比の計算とレスポンシブサイズの算出・TSV/CSVからMarkdownテーブルへの整形と相互変換・SQLクエリの整形と予約語の大文字化・URL/テキストからのQRコード生成・UNIXタイムスタンプと日時表記の相互変換・robots.txtの生成(AIクローラーの許可プリセット付き)・文字列のケース変換(camelCase/snake_case/kebab-case など11形式)・CSV/TSVとJSON配列の相互変換(区切りの自動判定・a.b 列と入れ子の相互展開)・全角⇄半角の変換とテキストの掃除(文字種ごとの向き指定・半角カナの合成/分解・空白と空行の整理)・IPアドレス/CIDRの計算(ネットワーク・ブロードキャスト・ホスト範囲とホスト数・IPv4/IPv6・サブネット分割・包含判定・IP範囲→最小CIDR集合の逆算)・日数/営業日の計算(2日付間の日数と営業日数・起点日+N日/N営業日の期日・締め日と支払サイトからの支払日・土日と日本の祝日を内蔵)・HTML→Markdownの変換(見出し/リスト/表/リンク/画像/コード・script/styleや装飾タグの除去・本文だけの抽出・相対URLの絶対化)・和暦⇄西暦の変換(令和〜明治・自動判定・曜日と干支・存在しない和暦の指摘・満年齢と入学/卒業の年・元号一覧と早見表)・日本語タイトルからのURLスラッグ生成(かな→ヘボン式ローマ字・記号除去・ハイフン/アンダースコア連結・小文字化・長音の省略/表記)・Basic認証用 htpasswd の生成と照合(bcrypt / apr1-md5・パスワードの自動生成・Apache / nginx の設定スニペット)・OpenAPI/Swagger仕様書から日本語のMarkdownドキュメントとTypeScript型定義の生成(OpenAPI 3.x / Swagger 2.0・YAML/JSON・$ref/allOf/oneOf 対応・エンドポイントごとの引数/レスポンス型・外部 $ref は読みに行かない)・FAQ構造化データ(FAQPage の JSON-LD・Markdown・details/summary の HTML を同時生成・回答のリンク/箇条書きを HTML 化・「Q: / A:」形式の一括貼り付けの解析)・テキストの行操作(重複行の削除・数値を認識する並べ替え・シード付きシャッフル・行番号・空行除去・前後トリム・接頭辞/接尾辞)・印刷サイズとDPIの計算(用紙×解像度×塗り足しから必要なピクセル数・手持ちの画像の実効dpiと判定・早見表・mm/inch/px/pt/級の換算)・SERPのメタタグ文字数チェック(title / description が検索結果に収まるかをピクセル幅で判定・切り詰め位置と表示行・パンくず表示・https や階層の指摘)・Flexbox / CSS GridのCSS生成(既定値を省いた宣言・repeat()への畳み込み・grid-template-areasの検証・効かない組み合わせの指摘・定番プリセット)・社内文書の点検(Notion・Confluence などから書き出した Markdown/HTML の重複ページ・孤立ページ・表記ゆれや旧称・リンク切れの検出と修正案)・記入欄に収める字の大きさと改行位置(中袋〔ご祝儀袋・香典袋〕の住所欄などの幅・高さmmから1字の大きさ・行数・改行位置・縦書きの漢数字・金額の大字)・AIが書いた返信案と届いたメールの照合(原文に無い日付・曜日・時刻・金額・数量・電話・宛名を赤、消し忘れの仮の文字を黄))をMCPツールとして提供するサーバー。あわせて apps.first-ch.com のWebアプリ38本(GEO・メタタグ・セキュリティヘッダー・SSL・DNS・リダイレクト・リンク切れ・構造化データ・AIクローラー許可・和文可読性・ビジネス文面チェック等)の JSON API を呼ぶ app_* ツールも提供する(こちらは入力を apps.first-ch.com へ送るため既定では無効・FIRSTCH_ENABLE_APPS=1 で有効)",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "firstch-tools-mcp": "server.mjs"
@@ -281,6 +281,7 @@
281
281
  "fs-safe.mjs",
282
282
  "fit-to-box.mjs",
283
283
  "invoice-nebiki.mjs",
284
+ "reply-check.mjs",
284
285
  "webp.mjs",
285
286
  "marp.mjs",
286
287
  "marp-theme.css",
@@ -0,0 +1,497 @@
1
+ /* AI の返信案の送る前チェック(reply_check)
2
+ * 照合のコア(normalize / extract / checkReply ほか)は FirstCHTools の site/okurumae/app.js と同一
3
+ * (2箇所ルール: site側が正本・片方を直したらもう片方も同じ内容で反映する)。
4
+ * 両ファイルからコアの開始/終了コメントに挟まれた範囲を切り出し(site側は字下げ2文字を落とす。
5
+ * こちらはコアの中に export を書かず、末尾でまとめて export する)、diff が空になることで同期を確かめる:
6
+ * diff <(sed -n '/^ \/\/ ===== ここからコア/,/^ \/\/ ===== ここまでコア/p' site/okurumae/app.js | sed 's/^ //') \
7
+ * <(sed -n '/^\/\/ ===== ここからコア/,/^\/\/ ===== ここまでコア/p' reply-check.mjs | sed 's/^export //')
8
+ *
9
+ * 届いたメール(+自分で決めた事実)と AI が書いた返信案を照らし合わせ、返信案の日付・曜日・時刻・金額・数量・電話・
10
+ * メール・URL・宛名・番号のうち、原文のどちらにも無いものを赤、あるものを緑、[お客様1]・〇〇・XX などの消し忘れを黄で返す。
11
+ * 本文は書き換えず、照合のときだけ全角/半角などをそろえる。完全ローカル処理・ネットワーク送信なし。 */
12
+
13
+ // ===== ここからコア(DOM に触らない。document の無いときは globalThis.__okurumae で公開し、tests/okurumae.test.mjs が確かめる。MCP の reply-check.mjs と同じ) =====
14
+ var WD_JA = '日月火水木金土';
15
+ var WD_EN = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
16
+ var MONTHS_EN = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
17
+ var KANJI_NUM = '〇一二三四五六七八九';
18
+ // 宛名の前に来ても名前ではない語(お客様・皆様・ご担当者様など)
19
+ var NOT_NAMES = ['客', '皆', '各位', '会員', '利用者', '担当者', '担当', '担当者各位', '保護者', '関係者', '奥', '旦那', '生徒', '参加者', '出席者', '応募者',
20
+ '購入者', '一同', '子', '家族', '親御', '両親', '主人', '先方', '相手', '神', '王', '仏', '仕', '模', '同', '異', '多', '有', '左', '一', '皆々', 'みな', 'みなさ',
21
+ '店長', '部長', '課長', '社長', '先生', '院長', '会長', '係', '幹事', '代表', '業者', '来店者', 'ゲスト', 'メンバー', 'スタッフ', 'オーナー', '運営', '事務局',
22
+ '予約係', 'ご予約係', '受付', '窓口', '貴社', '御社', '貴店', '利用', '入会者', '新入会員', '児童', '園児', '父兄', 'お父', 'お母', 'じい', 'ばあ', 'お兄', 'お姉',
23
+ '兄', '姉', '弟', '妹', '娘', '息子', '奥方', 'お連れ', '連れ', '患者', '契約者', '依頼者', '世帯主', 'ご本人', '本人', '母', '父', '孫', '嬢', '主',
24
+ '苦労', '世話', '馳走', '愁傷', '気の毒', 'おかげ', 'たく', '注文者', '予約者', '依頼主', '得意', '取引先', '店舗', '施主', '入居者', '宿泊者', '利用者各位'];
25
+ var NOT_NAMES_EN = ['customer', 'customers', 'sir', 'madam', 'sir or madam', 'guest', 'guests', 'team', 'all', 'valued', 'friend', 'friends', 'member', 'members', 'client', 'parent', 'parents'];
26
+ var TITLE_TAIL = /(?:部長|課長|係長|社長|店長|先生|院長|会長|代表|さん|様)$/;
27
+
28
+ // 照合用にそろえる(本文は書き換えない)。NFKC で全角英数・記号を半角に、数字の間の長音・ダッシュを「-」に。
29
+ // map[i] は、そろえた文字列の i 文字目が元の文字列の何文字目から来たか(最後に元の長さを足す)
30
+ function normalize(s) {
31
+ s = String(s == null ? '' : s);
32
+ var out = '', map = [];
33
+ for (var i = 0; i < s.length;) {
34
+ var cp = s.codePointAt(i), ch = String.fromCodePoint(cp), n = ch.normalize('NFKC');
35
+ if (ch === '〜' || ch === '~') n = '~';
36
+ for (var k = 0; k < n.length; k++) { out += n[k]; map.push(i); }
37
+ i += ch.length;
38
+ }
39
+ map.push(s.length);
40
+ out = out.replace(/(\d)(\s*)[ー‐‑‒–—―−](?=\s*\d)/g, '$1$2-'); // 長さを変えない(map がそのまま使える)
41
+ return { t: out, map: map, src: s };
42
+ }
43
+ function toOrig(N, s, e) {
44
+ var a = N.map[s], j = e;
45
+ while (j < N.t.length && N.map[j] === N.map[e - 1]) j++;
46
+ return [a, j >= N.t.length ? N.src.length : N.map[j]];
47
+ }
48
+ function kanjiNum(s) {
49
+ if (/^\d+(?:\.\d+)?$/.test(s)) return parseFloat(s);
50
+ if (s === '十') return 10;
51
+ var m = /^([一二三四五六七八九])?十([一二三四五六七八九])?$/.exec(s);
52
+ if (m) return (m[1] ? KANJI_NUM.indexOf(m[1]) : 1) * 10 + (m[2] ? KANJI_NUM.indexOf(m[2]) : 0);
53
+ if (/^[〇一二三四五六七八九]$/.test(s)) return KANJI_NUM.indexOf(s);
54
+ return NaN;
55
+ }
56
+ function num(s) { return parseFloat(String(s).replace(/,/g, '')); }
57
+ function digits(s) { return String(s).replace(/\D/g, ''); }
58
+
59
+ // 月日から年を決める(年が書かれていなければ、今日の60日前〜305日後に入る年)
60
+ function inferYear(m, d, today) {
61
+ var t0 = Date.UTC(today.getFullYear(), today.getMonth(), today.getDate());
62
+ for (var dy = -1; dy <= 1; dy++) {
63
+ var y = today.getFullYear() + dy, t = Date.UTC(y, m - 1, d), diff = (t - t0) / 864e5;
64
+ if (diff >= -60 && diff <= 305) return y;
65
+ }
66
+ return today.getFullYear();
67
+ }
68
+ function weekdayOf(y, m, d) {
69
+ var dt = new Date(Date.UTC(y, m - 1, d));
70
+ if (dt.getUTCMonth() !== m - 1) return -1; // 11月31日など存在しない日
71
+ return dt.getUTCDay();
72
+ }
73
+ function wdIndex(w) {
74
+ if (!w) return -1;
75
+ var i = WD_JA.indexOf(w);
76
+ if (i >= 0 && w.length === 1) return i;
77
+ var k = w.toLowerCase().slice(0, 3);
78
+ return WD_EN.indexOf(k);
79
+ }
80
+ function monthIndex(w) { return MONTHS_EN.indexOf(w.toLowerCase().slice(0, 3)) + 1; }
81
+
82
+ // 1つの文章から照合の対象を拾う。種類ごとに順に探し、先に拾った範囲とは重ねない
83
+ function extract(text) {
84
+ var N = normalize(text), t = N.t, used = new Uint8Array(t.length + 1), toks = [];
85
+ function free(s, e) { for (var i = s; i < e; i++) if (used[i]) return false; return true; }
86
+ function add(tok, s, e) {
87
+ if (e <= s || !free(s, e)) return null;
88
+ for (var i = s; i < e; i++) used[i] = 1;
89
+ var o = toOrig(N, s, e);
90
+ tok.ns = s; tok.ne = e; tok.start = o[0]; tok.end = o[1]; tok.text = N.src.slice(o[0], o[1]);
91
+ toks.push(tok);
92
+ return tok;
93
+ }
94
+ function each(re, fn) {
95
+ re.lastIndex = 0;
96
+ var m;
97
+ while ((m = re.exec(t))) {
98
+ var s = m.index, e = s + m[0].length;
99
+ if (!free(s, e)) { re.lastIndex = s + 1; continue; } // 先に拾った範囲にかかるなら、1字ずらして探し直す
100
+ fn(m, s, e);
101
+ if (m[0].length === 0) re.lastIndex++;
102
+ }
103
+ }
104
+
105
+ // URL・メール
106
+ each(/\bhttps?:\/\/[^\s<>"'()\[\]{}「」『』【】、。]+|\bwww\.[A-Za-z0-9-]+\.[^\s<>"'()\[\]{}「」『』【】、。]+/gi, function (m, s, e) {
107
+ var v = m[0].replace(/[.,!?;:]+$/, ''); e = s + v.length;
108
+ // 大小文字をそろえるのはスキームとホストだけ(パス・クエリの /Reserve と /reserve は別のリンク。RFC 3986 6.2.2.1)
109
+ // スキーム・wwwの有無・末尾の「/」は別の接続先になり得るのでそろえない。空のパスだけ「/」と同じに扱う(RFC 3986 6.2.3)
110
+ var sc = (v.match(/^https?:\/\//i) || [''])[0], u = v.slice(sc.length), cut = u.search(/[\/?#]/), host = cut < 0 ? u : u.slice(0, cut), rest = cut < 0 ? '' : u.slice(cut);
111
+ if (rest.charAt(0) !== '/') rest = '/' + rest;
112
+ add({ type: 'url', key: sc.toLowerCase() + host.toLowerCase() + rest }, s, e);
113
+ });
114
+ each(/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/g, function (m, s, e) { add({ type: 'email', key: m[0].toLowerCase() }, s, e); });
115
+
116
+ // 消し忘れ(黄)。宛名・数字より先に拾う
117
+ var PH_WORDS = '名前|氏名|名|日付|日時|時間|時刻|金額|料金|会社|店名|住所|電話|番号|担当|お客様|宛名|URL|メール|ここ|入力|記入|挿入|要確認|未定|〇|○|◯|X|x';
118
+ each(new RegExp('\\[[^\\[\\]\\n]{1,30}\\](?!\\()|【\\s*】|【[^【】\\n]{0,20}?(?:' + PH_WORDS + ')[^【】\\n]{0,10}】|\\{\\{?[^{}\\n]{1,30}\\}\\}?|<[^<>\\n]*[^\\x00-\\x7f<>\\n][^<>\\n]*>|_{3,}', 'g'), function (m, s, e) {
119
+ add({ type: 'placeholder', key: m[0] }, s, e);
120
+ });
121
+ each(/(?<![一二三四五六七八九十〇])[〇○◯●△□■◇×]{2,}(?![一二三四五六七八九十〇])|[〇○◯●△□×](?=[月日時分円様名人号年])/g, function (m, s, e) { add({ type: 'placeholder', key: m[0] }, s, e); });
122
+ each(/(?<![A-Za-z0-9])[Xx]{2,}(?:[-:\/][Xx]{2,})*(?![A-Za-z0-9])/g, function (m, s, e) { add({ type: 'placeholder', key: m[0] }, s, e); });
123
+
124
+ // 日付(年月日・月/日・年-月-日・英語の月名)。直後(英語は直前も)の曜日を含める
125
+ function attachWeekday(tok, s, e) {
126
+ var rest = t.slice(e, e + 16), m;
127
+ if ((m = /^\s*\(\s*([月火水木金土日])(?:曜日?)?\s*(?:[・,、]\s*祝日?\s*)?\)/.exec(rest)) || (m = /^\s*([月火水木金土日])曜日?/.exec(rest))) {
128
+ tok.wd = wdIndex(m[1]); e += m[0].length;
129
+ } else if ((m = /^\s*\(\s*(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*\.?\s*\)/i.exec(rest))) {
130
+ tok.wd = wdIndex(m[1]); e += m[0].length;
131
+ } else {
132
+ var before = t.slice(Math.max(0, s - 14), s);
133
+ if ((m = /\b(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*\.?,?\s*(?:the\s+)?$/i.exec(before))) { tok.wd = wdIndex(m[1]); s -= m[0].length; }
134
+ }
135
+ return [s, e];
136
+ }
137
+ function addDate(y, mo, d, s, e) {
138
+ mo = mo ? +mo : 0; d = +d;
139
+ if ((mo && (mo < 1 || mo > 12)) || d < 1 || d > 31) return;
140
+ var tok = { type: 'date', y: y ? +y : 0, m: mo, d: d, wd: -1 }, r = attachWeekday(tok, s, e);
141
+ tok.key = (tok.y || '') + '-' + (mo || '*') + '-' + d;
142
+ add(tok, r[0], r[1]);
143
+ }
144
+ each(/(?:(\d{4})\s*年\s*)?(\d{1,2})\s*月\s*(\d{1,2})\s*日/g, function (m, s, e) { addDate(m[1], m[2], m[3], s, e); });
145
+ each(/(?<![\d\/.:-])(\d{4})[\/.-](\d{1,2})[\/.-](\d{1,2})(?![\d\/.-])/g, function (m, s, e) { addDate(m[1], m[2], m[3], s, e); });
146
+ each(/(?<![\d\/.:-])(\d{1,2})\/(\d{1,2})(?![\d\/])/g, function (m, s, e) { addDate(0, m[1], m[2], s, e); });
147
+ each(/\b(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t(?:ember)?)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\.?\s+(\d{1,2})(?:st|nd|rd|th)?\b(?:,?\s+(\d{4})\b)?/gi, function (m, s, e) { addDate(m[3], monthIndex(m[1]), m[2], s, e); });
148
+ each(/\b(\d{1,2})(?:st|nd|rd|th)?\s+(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t(?:ember)?)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b(?:,?\s+(\d{4})\b)?/gi, function (m, s, e) { addDate(m[3], monthIndex(m[2]), m[1], s, e); });
149
+ // 日だけ(「8日(日)」「〜10日」)。月は前の日付から引き継ぐ
150
+ each(/(?<![\d月\/.,泊])(\d{1,2})\s*日(?!間|本|後|前|目|分|以|中|ぶり|おき|毎|ごと|当日|程度|ほど|くらい|ぐらい|まで以内)/g, function (m, s, e) { addDate(0, 0, m[1], s, e); });
151
+
152
+ // 時刻(18:30・18時30分・18時半・午後6時・6:30 pm・6 pm)。「18:00」「06:00」のようなコロンの形は24時間表記として読み、
153
+ // 午前・午後の無い「〇時」だけを両方に読む(06:00 を 18時 と一致させない)
154
+ function addTime(ap1, h, mi, half, ap2, s, e, colon) {
155
+ h = +h; mi = half ? 30 : (mi ? +mi : 0);
156
+ if (h > 30 || mi > 59) return;
157
+ var ap = (ap1 || ap2 || '').toLowerCase().replace(/\./g, ''), keys = [];
158
+ if (ap === '午後' || ap === 'pm') keys.push((h % 12 + 12) * 60 + mi);
159
+ else if (ap === '午前' || ap === 'am') keys.push((h % 12) * 60 + mi);
160
+ else { keys.push(h * 60 + mi); if (!colon && h >= 1 && h <= 11) keys.push((h + 12) * 60 + mi); if (!colon && h === 12) keys.push(mi); }
161
+ add({ type: 'time', keys: keys, key: keys.join('|') }, s, e);
162
+ }
163
+ var AP = '(午前|午後|AM|PM|am|pm|a\\.m\\.|p\\.m\\.)';
164
+ each(new RegExp('(?:' + AP + '\\s*)?(?<![\\d:.])(\\d{1,2})\\s*(?::(\\d{2})(?!\\d)|時(?!間)(?:\\s*(\\d{1,2})\\s*分(?!間)|(半))?)(?:\\s*' + AP + '(?![A-Za-z]))?', 'g'), function (m, s, e) { addTime(m[1], m[2], m[3] || m[4], m[5], m[6], s, e, m[3] != null); });
165
+ each(new RegExp('(?<![\\d:.])(\\d{1,2})\\s*' + AP + '(?![A-Za-z])', 'g'), function (m, s, e) { addTime('', m[1], 0, '', m[2], s, e); });
166
+
167
+ // 電話(数字が10〜11桁。+81 は 0 に読み替える。「+81 (0)90」の (0) は国内の0なので重ねない)
168
+ each(/(?<![\w.\/-])(?:\+81[-\s]?\(?0?\)?|\(?0)\d{1,4}\)?[-\s]?\d{1,4}[-\s]?\d{3,4}(?![\w-])/g, function (m, s, e) {
169
+ var dg = digits(m[0]);
170
+ if (m[0].charAt(0) === '+') dg = dg.slice(2);
171
+ if (dg[0] !== '0') dg = '0' + dg;
172
+ if (dg.length >= 10 && dg.length <= 11) add({ type: 'phone', key: dg }, s, e);
173
+ });
174
+
175
+ // 金額(円・万・千・¥・$・yen)
176
+ each(/(?:[¥\\]\s?)?(\d[\d,]*(?:\.\d+)?)(?:\s*(万|千)(?:(\d[\d,]*)(千)?)?)?\s*円/g, function (m, s, e) {
177
+ var v = num(m[1]) * (m[2] === '万' ? 10000 : m[2] === '千' ? 1000 : 1);
178
+ if (m[3]) v += num(m[3]) * (m[4] ? 1000 : 1);
179
+ add({ type: 'money', key: 'JPY:' + Math.round(v) }, s, e);
180
+ });
181
+ each(/[¥\\]\s?(\d[\d,]*(?:\.\d+)?)(?:\s*(万))?/g, function (m, s, e) { add({ type: 'money', key: 'JPY:' + Math.round(num(m[1]) * (m[2] ? 10000 : 1)) }, s, e); });
182
+ each(/\b(\d[\d,]*(?:\.\d+)?)\s*(?:yen|JPY)\b/gi, function (m, s, e) { add({ type: 'money', key: 'JPY:' + Math.round(num(m[1])) }, s, e); });
183
+ each(/(?:US)?\$\s?(\d[\d,]*(?:\.\d{1,2})?)|\b(\d[\d,]*(?:\.\d{1,2})?)\s*(?:dollars?|USD)\b/gi, function (m, s, e) { add({ type: 'money', key: 'USD:' + num(m[1] || m[2]) }, s, e); });
184
+
185
+ // 数量(2名・3泊・50%・4 adults)。「お一人様」「1人あたり」は単価の言い方なので数えない
186
+ // 桁区切り(1,100)は1つの数として読み、数の途中(「1,100」の「100」)からは読み始めない。
187
+ // 止めるのは直前が数字のときと、「数字,」「数字.」の後ろがちょうど3桁のとき(桁区切りの続き)だけ。「2泊,3名」「2,3人」の後ろの数は読む
188
+ // 直前に大人・子どもの語があれば区分(adult・child)を組にして持つ(「大人2名・子ども1名」と「大人1名・子ども2名」を取り違えない)。
189
+ // 区分は2つだけにし、男性・女性・学生などの言い換えには付けない(数と単位だけで照合する)
190
+ var QTY_LABEL = { '大人': 'adult', 'おとな': 'adult', '成人': 'adult', '子ども': 'child', '子供': 'child', 'こども': 'child', 'お子様': 'child', 'お子さま': 'child', '子様': 'child',
191
+ '小人': 'child', '児童': 'child', '小学生': 'child', '幼児': 'child', '乳児': 'child', '未就学児': 'child', '赤ちゃん': 'child' };
192
+ var QTY_LABEL_RE = new RegExp('(' + Object.keys(QTY_LABEL).sort(function (a, b) { return b.length - a.length; }).join('|') + ')\\s*(?::|は|が)?\\s*$');
193
+ function qtyLabel(s) { var m = QTY_LABEL_RE.exec(t.slice(Math.max(0, s - 10), s)); return m ? QTY_LABEL[m[1]] : ''; }
194
+ var UNIT = { '名': '人', '名様': '人', '人': '人', '人様': '人', 'つ': '個', 'ヶ月': 'か月', 'ケ月': 'か月', 'カ月': 'か月', 'ヵ月': 'か月', 'か月': 'か月', '才': '歳', 'パーセント': '%', '%': '%' };
195
+ var UNIT_EN = { people: '人', persons: '人', person: '人', guests: '人', guest: '人', adults: '人', adult: '人', children: '人', child: '人', kids: '人', pax: '人',
196
+ nights: '泊', night: '泊', pieces: '個', pcs: '個', items: '個', item: '個', tickets: '枚', ticket: '枚', seats: '席', seat: '席', rooms: '室', room: '室',
197
+ hours: '時間', hour: '時間', hrs: '時間', minutes: '分', minute: '分', mins: '分', days: '日間', day: '日間', weeks: '週間', week: '週間', months: 'か月', month: 'か月', percent: '%' };
198
+ each(/(お|ご)?(?<!\d)(?<!\d[,.](?=\d{3}(?!\d)))(\d{1,3}(?:,\d{3})+(?![\d,])|\d+(?:\.\d+)?|[一二三四五六七八九十]{1,3})\s*(名様|人様|名|人|個|つ|枚|本|台|件|部|冊|泊|回|杯|皿|席|組|箱|セット|点|日間|時間|分間|分|秒|週間|か月|カ月|ヶ月|ケ月|ヵ月|年間|年|歳|才|%|パーセント|割|cm|mm|km|kg|ml|mL|m|g|L|坪|畳|階|番|号室|号|室)(?![A-Za-z])(あたり|当たり|につき|ずつ)?/g, function (m, s, e) {
199
+ var isK = !/^\d/.test(m[2]);
200
+ if (isK && !/^(名様?|人様?|泊|組)$/.test(m[3])) return; // 漢数字は「一杯」「もう一つ」などの言い回しが多いので人数・泊・組だけ
201
+ var v = isK ? kanjiNum(m[2]) : num(m[2]);
202
+ if (isNaN(v)) return;
203
+ if (m[4] || (m[1] && v === 1 && /^(名|人)/.test(m[3]))) return; // 単価の言い方
204
+ var u = UNIT[m[3]] || m[3];
205
+ add({ type: 'qty', key: v + u, label: qtyLabel(s) }, s + (m[1] ? m[1].length : 0), e - (m[4] ? m[4].length : 0));
206
+ });
207
+ var LABEL_EN = { adults: 'adult', adult: 'adult', children: 'child', child: 'child', kids: 'child' };
208
+ each(/(?<!\d)(?<!\d[,.](?=\d{3}(?!\d)))(\d{1,3}(?:,\d{3})+(?![\d,])|\d+(?:\.\d+)?)\s*(people|persons?|guests?|adults?|children|child|kids|pax|nights?|pieces|pcs|items?|tickets?|seats?|rooms?|hours?|hrs|minutes?|mins|days?|weeks?|months?|percent)\b/gi, function (m, s, e) {
209
+ var w = m[2].toLowerCase();
210
+ add({ type: 'qty', key: num(m[1]) + UNIT_EN[w], label: LABEL_EN[w] || qtyLabel(s) }, s, e);
211
+ });
212
+
213
+ // 曜日だけ(「土曜日」「Saturday」「土日」)
214
+ each(/([月火水木金土日])曜日?/g, function (m, s, e) { add({ type: 'weekday', wds: [wdIndex(m[1])], key: m[1] }, s, e); });
215
+ each(/土日(?!曜)/g, function (m, s, e) { add({ type: 'weekday', wds: [6, 0], key: '土日' }, s, e); });
216
+ each(/\b(Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sun|Mon|Tues?|Wed|Thur?s?|Fri|Sat)s?\b\.?/g, function (m, s, e) { add({ type: 'weekday', wds: [wdIndex(m[1])], key: m[1] }, s, e); });
217
+
218
+ // 宛名(〇〇様・さま・さん・殿・御中、Dear / Mr. / Ms.)
219
+ each(/(様|さま|さん|殿|御中)/g, function (m, s, e) {
220
+ if (used[s]) return;
221
+ if (m[1] === '様' && /^[々子式相]/.test(t.slice(e, e + 1))) return;
222
+ var s0 = s;
223
+ while (s0 > 0 && t[s0 - 1] === ' ' && !used[s0 - 1]) s0--; // 「田中 様」
224
+ var i = s0, sp = 0;
225
+ while (i > 0 && s0 - i < 14) {
226
+ var c = t[i - 1];
227
+ if (used[i - 1]) break;
228
+ if (/[\p{Script=Han}々〆ヵヶ\p{Script=Katakana}ー・A-Za-z]/u.test(c)) { i--; continue; }
229
+ if (c === ' ' && !sp && i < s0 && i > 1 && /[\p{Script=Han}々\p{Script=Katakana}A-Za-z]/u.test(t[i - 2])) { sp = 1; i--; continue; }
230
+ break;
231
+ }
232
+ if (i === s0) { // ひらがなの名前(行頭・空白・句読点の直後から)
233
+ var j = s0;
234
+ while (j > 0 && s0 - j < 8 && /[ぁ-ゟ]/.test(t[j - 1]) && !used[j - 1]) j--;
235
+ if (j < s0 && (j === 0 || /[\s、。「『(,]/.test(t[j - 1]))) i = j;
236
+ }
237
+ var name = t.slice(i, s0).replace(/^ +/, '');
238
+ i = s0 - name.length;
239
+ var bare = name.replace(/^[おご]/, '').replace(/ /g, '');
240
+ if (!bare || NOT_NAMES.indexOf(bare) >= 0 || NOT_NAMES.indexOf(name.replace(/ /g, '')) >= 0) return;
241
+ if (m[1] === '様' && /[同仕模異多有左]$/.test(bare)) return; // 同様・仕様・模様など
242
+ if (/^[一二三四五六七八九十]+[人名]$/.test(bare)) return; // お一人様・二名様
243
+ var nm = name.replace(/ +$/, '').replace(/^[おご](?=.)/, '');
244
+ add({ type: 'name', key: bare.replace(TITLE_TAIL, '') || bare, parts: nm.replace(TITLE_TAIL, '').split(/ +/).filter(Boolean) }, i, e);
245
+ });
246
+ each(/\b(?:Dear\s+(?:(?:Mr|Ms|Mrs|Mx|Dr|Miss)\.?\s+)?|(?:Mr|Ms|Mrs|Mx|Dr)\.?\s+|Miss\s+)([A-Z][A-Za-z'’-]+(?:\s+[A-Z][A-Za-z'’-]+)?)/g, function (m, s, e) {
247
+ var nm = m[1];
248
+ if (NOT_NAMES_EN.indexOf(nm.toLowerCase()) >= 0 || NOT_NAMES_EN.indexOf(nm.split(/\s+/)[0].toLowerCase()) >= 0) return;
249
+ add({ type: 'name', key: nm.replace(/\s+/g, ''), parts: nm.split(/\s+/) }, e - nm.length, e);
250
+ });
251
+
252
+ // そのほかの番号(3桁以上・123-4567 など)
253
+ each(/(?<![\d,.])\d{1,3}(?:,\d{3})+(?![\d,])|(?<![\d-])\d[\d-]{1,}\d(?![\d-])/g, function (m, s, e) {
254
+ var dg = digits(m[0]);
255
+ if (dg.length >= 3) add({ type: 'number', key: /,/.test(m[0]) ? String(num(m[0])) : dg }, s, e);
256
+ });
257
+
258
+ // 日だけの日付に、同じ文章の前の日付の月を入れる
259
+ toks.sort(function (a, b) { return a.start - b.start; });
260
+ var lastM = 0, lastY = 0;
261
+ toks.forEach(function (k) {
262
+ if (k.type !== 'date') return;
263
+ if (k.m) { lastM = k.m; lastY = k.y; } else if (lastM) { k.m = lastM; k.y = k.y || lastY; k.inherited = true; }
264
+ });
265
+ return { tokens: toks, norm: N };
266
+ }
267
+
268
+ var NAME_CH = '\\p{Script=Han}々〆ヵヶ\\p{Script=Katakana}ーA-Za-z\'’';
269
+ function nameRe(key) {
270
+ var body = Array.from(key).map(function (c) { return c.replace(/[.*+?^${}()|[\]\\\/]/g, '\\$&'); }).join(' ?');
271
+ return new RegExp('(?<![' + NAME_CH + '])' + body + '(?![' + NAME_CH + '])', 'gu');
272
+ }
273
+ function dateMatch(a, b) {
274
+ if (a.d !== b.d) return false;
275
+ if (a.m && b.m && a.m !== b.m) return false;
276
+ if (a.y && b.y && a.y !== b.y) return false;
277
+ return true;
278
+ }
279
+ function matches(r, s) {
280
+ if (r.type === 'date') return s.type === 'date' && dateMatch(r, s);
281
+ if (r.type === 'time') return s.type === 'time' && r.keys.some(function (k) { return s.keys.indexOf(k) >= 0; });
282
+ if (r.type === 'weekday') return (s.type === 'weekday' && r.wds.every(function (w) { return s.wds.indexOf(w) >= 0; })) || (s.type === 'date' && r.wds.length === 1 && s.wd === r.wds[0]);
283
+ if (r.type === 'phone' || r.type === 'number') return (s.type === 'phone' || s.type === 'number') && s.key === r.key;
284
+ // 宛名は敬称・空白を除いた名前が一致すること。姓だけ・名だけは、相手が空白で区切って書いた部分と一致するときだけ(「林」と「小林」は別人)
285
+ // 逆向き(原文が「田中様」・返信案が「田中 次郎様」)は緑にしない。原文に無い「次郎」を足しているため
286
+ // 数量は数と単位が同じこと。両方に区分(adult・child)があり、それが食い違うときだけ一致にしない
287
+ if (r.type === 'qty') return s.type === 'qty' && s.key === r.key && (!r.label || !s.label || r.label === s.label);
288
+ if (r.type === 'name') return s.type === 'name' && (s.key === r.key || (s.parts || []).indexOf(r.key) >= 0);
289
+ return s.type === r.type && s.key === r.key;
290
+ }
291
+
292
+ // 照らし合わせる。received・facts のどちらかに同じものがあれば緑、無ければ赤、消し忘れは黄
293
+ function checkReply(received, reply, facts, opts) {
294
+ opts = opts || {};
295
+ var today = opts.today instanceof Date ? opts.today : new Date();
296
+ var R = extract(reply), S = [{ id: 'received', x: extract(received) }, { id: 'facts', x: extract(facts || '') }];
297
+ var items = [], MAX_HITS = 20, nameHits = {};
298
+ R.tokens.forEach(function (tok) {
299
+ var it = { type: tok.type, text: tok.text, start: tok.start, end: tok.end, status: 'green', reasons: [], hits: [] };
300
+ if (tok.type === 'placeholder') { it.status = 'yellow'; it.reasons.push('placeholder'); items.push(it); return; }
301
+ // 一致の記録は1件あたり MAX_HITS 箇所まで(同じ語が大量にある文章でメモリを使い切らない)
302
+ for (var si = 0; si < S.length && it.hits.length < MAX_HITS; si++) {
303
+ var sts = S[si].x.tokens;
304
+ for (var ti = 0; ti < sts.length && it.hits.length < MAX_HITS; ti++) {
305
+ var st = sts[ti];
306
+ if (matches(tok, st)) it.hits.push({ src: S[si].id, start: st.start, end: st.end, y: st.y || 0, m: st.m || 0 });
307
+ }
308
+ }
309
+ // 署名・名乗り(「森川 結衣」「井上です」)は原文の中を探す。前後が名前の文字に続いていないこと(「小林」の中の「林」は数えない)
310
+ // 同じ名前は1回だけ探す
311
+ if (tok.type === 'name' && !it.hits.length) {
312
+ if (!Object.prototype.hasOwnProperty.call(nameHits, tok.key)) {
313
+ var found = [];
314
+ S.forEach(function (src) {
315
+ var N = src.x.norm, re = nameRe(tok.key), m;
316
+ while (found.length < MAX_HITS && (m = re.exec(N.t))) { var o = toOrig(N, m.index, m.index + m[0].length); found.push({ src: src.id, start: o[0], end: o[1] }); }
317
+ });
318
+ nameHits[tok.key] = found;
319
+ }
320
+ it.hits = nameHits[tok.key].slice();
321
+ }
322
+ if (!it.hits.length) { it.status = 'red'; it.reasons.push('missing'); }
323
+ if (tok.type === 'date' && tok.wd >= 0) {
324
+ var m = tok.m, y = tok.y;
325
+ if (!m) { var h0 = it.hits.filter(function (h) { return h.m; })[0]; if (h0) { m = h0.m; y = y || h0.y; } }
326
+ if (!y) { var hy = it.hits.filter(function (h) { return h.y; })[0]; if (hy) y = hy.y; }
327
+ if (m) {
328
+ y = y || inferYear(m, tok.d, today);
329
+ var real = weekdayOf(y, m, tok.d);
330
+ it.date = { y: y, m: m, d: tok.d, written: tok.wd, actual: real };
331
+ if (real !== tok.wd) { it.status = 'red'; it.reasons.push(real < 0 ? 'nodate' : 'weekday'); }
332
+ }
333
+ } else if (tok.type === 'date' && tok.m) {
334
+ var yy = tok.y || inferYear(tok.m, tok.d, today);
335
+ if (weekdayOf(yy, tok.m, tok.d) < 0) { it.status = 'red'; it.reasons.push('nodate'); it.date = { y: yy, m: tok.m, d: tok.d, written: -1, actual: -1 }; }
336
+ }
337
+ items.push(it);
338
+ });
339
+ var count = { red: 0, yellow: 0, green: 0 };
340
+ items.forEach(function (it) { count[it.status]++; });
341
+ return { items: items, count: count };
342
+ }
343
+
344
+ // 見本(架空のメール)。日付は今日から数えて作る(年が変わっても曜日が合う)
345
+ function addDays(d, n) { return new Date(d.getFullYear(), d.getMonth(), d.getDate() + n); }
346
+ function nextWeekday(today, wd, minAhead) { var d = addDays(today, minAhead); while (d.getDay() !== wd) d = addDays(d, 1); return d; }
347
+ function md(d) { return (d.getMonth() + 1) + '月' + d.getDate() + '日'; }
348
+ function wj(d) { return WD_JA[d.getDay()]; }
349
+ function mdEn(d) { return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()] + ' ' + d.getDate(); }
350
+ function samples(today) {
351
+ var sat = nextWeekday(today, 6, 8), sun = addDays(sat, 1), thu = nextWeekday(today, 4, 8), fri = addDays(thu, 1), sun2 = nextWeekday(today, 0, 10);
352
+ return {
353
+ main: {
354
+ received: '見本亭 ご予約係様\n\nはじめまして。森川と申します。\n' + md(sat) + '(' + wj(sat) + ')の18時30分から、大人4名で夕食の予約をお願いできますか。\nコースはお一人5,500円のものを希望します。\n当日の連絡先は 090-0000-1234 です。\n\n森川 結衣',
355
+ facts: '営業時間 17:00〜23:00(月曜定休)\nコース 5,500円/7,700円\n電話 03-0000-5678',
356
+ reply: '森田様\n\nこのたびは見本亭へご予約のご連絡をいただき、ありがとうございます。\n' + md(sun) + '(' + wj(sat) + ')18:30より、大人4名様でご予約を承りました。\nコースはお一人様6,600円のものをご用意いたします。\n当日は17時より営業しております。お気をつけてお越しください。\nご不明な点は 03-0000-5678 までお電話ください。\n\n見本亭',
357
+ expectRed: ['森田様', md(sun) + '(' + wj(sat) + ')', '6,600円']
358
+ },
359
+ weekday: {
360
+ received: 'こんにちは。PTA広報係の佐々木です。\n次回の打ち合わせは ' + md(fri) + '(' + wj(fri) + ')の10時からでいかがでしょうか。\n場所は図書室を予定しています。',
361
+ facts: '',
362
+ reply: '佐々木様\n\nご連絡ありがとうございます。\n' + md(fri) + '(' + wj(thu) + ')の10時から、図書室で承知しました。\n当日はよろしくお願いいたします。',
363
+ expectRed: [md(fri) + '(' + wj(thu) + ')']
364
+ },
365
+ price: {
366
+ received: 'はじめまして、山本と申します。\n来月の子ども向けクッキー教室に、親子2人で参加したいのですが、料金はおいくらでしょうか。',
367
+ facts: '参加費 1人1,500円(材料費込み)\n時間 10:00〜12:00\n定員 8組',
368
+ reply: '山本様\n\nお問い合わせありがとうございます。\n参加費はお一人1,500円です。親子2人でのご参加をお待ちしております。\n別途、材料費として500円をいただきます。\n時間は10:00〜12:00、定員は8組です。\nキャンセルは前日まで無料、当日は50%を頂戴します。',
369
+ expectRed: ['500円', '50%']
370
+ },
371
+ name: {
372
+ received: '町内会の中村です。\n' + md(sun2) + '(' + wj(sun2) + ')の清掃活動ですが、雨の場合は延期でしょうか。',
373
+ facts: '',
374
+ reply: '中川様\n\nお問い合わせありがとうございます。\n' + md(sun2) + '(' + wj(sun2) + ')の清掃活動は、雨天の場合は翌週に延期します。\n決まり次第、回覧板でお知らせします。',
375
+ expectRed: ['中川様']
376
+ },
377
+ placeholder: {
378
+ received: 'お世話になっております。見本工務店の小林です。\n先日お送りした見積書について、ご確認いただけましたでしょうか。',
379
+ facts: '',
380
+ reply: '[お客様名]様\n\nいつもお世話になっております。〇〇でございます。\nお見積書を拝見しました。XX日までにお返事いたします。\n\n【担当者名】',
381
+ expectRed: [], expectYellow: ['[お客様名]', '〇〇', 'XX', '【担当者名】']
382
+ },
383
+ phone: {
384
+ received: 'はじめまして。ネイルの予約をしたい井上です。\n折り返しのお電話は 080-0000-2468 にお願いします。',
385
+ facts: '',
386
+ reply: '井上様\n\nご連絡ありがとうございます。\n080-0000-2468 に本日中にお電話いたします。',
387
+ expectRed: []
388
+ },
389
+ ok: {
390
+ received: '見本ヨガ教室様\n' + md(thu) + '(' + wj(thu) + ')19時のクラスに、友人と2名で参加できますか。\nメールは yoga-taro@example.com です。\n田村',
391
+ facts: '料金 1回2,000円\nヨガマットの貸出 300円\nhttps://example.com/yoga',
392
+ reply: '田村様\n\nお問い合わせありがとうございます。\n' + md(thu) + '(' + wj(thu) + ')19:00のクラス、2名様で承りました。\n料金はお一人1回2,000円です。ヨガマットの貸出は300円です。\n詳しくは https://example.com/yoga をご覧ください。\n確認のメールを yoga-taro@example.com にお送りします。',
393
+ expectRed: []
394
+ },
395
+ en: {
396
+ received: 'Hi, this is Yui Morikawa.\nCould I book a table for 4 adults on ' + WD_EN_FULL[sat.getDay()] + ', ' + mdEn(sat) + ' at 6:30 pm?\nI would like the $55 course. My number is 090-0000-1234.',
397
+ facts: 'Open 5:00 pm – 11:00 pm, closed on Mondays\nCourses: $55 / $77\nPhone: 03-0000-5678',
398
+ reply: 'Dear Ms. Morita,\n\nThank you for your reservation request.\nWe have booked a table for 4 adults on ' + WD_EN_FULL[sat.getDay()] + ', ' + mdEn(sun) + ' at 6:30 pm.\nWe will prepare the $66 course for you.\nWe open at 5 pm. If you have any questions, please call 03-0000-5678.\n\nMihon-tei',
399
+ expectRed: ['Morita', WD_EN_FULL[sat.getDay()] + ', ' + mdEn(sun), '$66']
400
+ }
401
+ };
402
+ }
403
+ var WD_EN_FULL = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
404
+ // ===== ここまでコア =====
405
+
406
+ // ---- MCP の入口 ----
407
+ export { normalize, extract, checkReply, inferYear, weekdayOf, samples };
408
+
409
+ export class ReplyCheckError extends Error {
410
+ constructor(code, message) { super(message); this.code = code; }
411
+ }
412
+
413
+ // 1欄あたりの上限(文字数)。拾い出しの正規表現と照合の総当たりは長さの2乗で重くなるため、メール1通に十分な長さで止める
414
+ export const REPLY_CHECK_MAX_CHARS = 20000;
415
+ // 返す項目と、1項目あたりの一致箇所の上限(件数 count は上限で切る前の全件)。応答が数MBにならないようにする
416
+ export const REPLY_CHECK_MAX_ITEMS = 500;
417
+ export const REPLY_CHECK_MAX_HITS = 5;
418
+
419
+ const RC_MSG = {
420
+ ja: {
421
+ missing: '届いたメールにも事実欄にも無い',
422
+ weekday: (d) => d.y + '年' + d.m + '月' + d.d + '日は' + WD_JA[d.actual] + '曜日(' + WD_JA[d.written] + 'ではない)',
423
+ nodate: (d) => d.m + '月' + d.d + '日は存在しない日付',
424
+ placeholder: '記号・仮の文字が残っている',
425
+ note: '赤が0件でも内容の正しさは保証しません。拾うのは日付・曜日・時刻・金額・数量・電話・メール・URL・宛名・番号だけで、文の意味や言い回しは見ていません。',
426
+ },
427
+ en: {
428
+ missing: 'Not in the email or your facts',
429
+ weekday: (d) => d.m + '/' + d.d + '/' + d.y + ' is a ' + WD_EN_FULL[d.actual] + ', not ' + WD_EN_FULL[d.written],
430
+ nodate: (d) => d.m + '/' + d.d + ' does not exist',
431
+ placeholder: 'Placeholder left in the reply',
432
+ note: 'A score of 0 red does not mean the reply is correct. Only dates, weekdays, times, amounts, quantities, phone numbers, emails, URLs, names and numbers are checked — not meaning or tone.',
433
+ },
434
+ };
435
+
436
+ function rcText(v, name) {
437
+ if (v == null) return '';
438
+ if (typeof v !== 'string') throw new ReplyCheckError('INVALID_INPUT', name + ' must be a string');
439
+ if (v.length > REPLY_CHECK_MAX_CHARS) throw new ReplyCheckError('TOO_LONG', name + ' is longer than ' + REPLY_CHECK_MAX_CHARS + ' characters');
440
+ return v;
441
+ }
442
+
443
+ function rcToday(s) {
444
+ if (s == null || s === '') return new Date();
445
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(s));
446
+ const dt = m ? new Date(+m[1], +m[2] - 1, +m[3]) : null;
447
+ if (!dt || dt.getFullYear() !== +m[1] || dt.getMonth() !== +m[2] - 1 || dt.getDate() !== +m[3]) {
448
+ throw new ReplyCheckError('INVALID_TODAY', 'today must be a real date in YYYY-MM-DD');
449
+ }
450
+ return dt;
451
+ }
452
+
453
+ const pad2 = (n) => String(n).padStart(2, '0');
454
+
455
+ export function replyCheckTool(opts = {}) {
456
+ const lang = opts.lang === 'en' ? 'en' : 'ja';
457
+ const L = RC_MSG[lang];
458
+ const reply = rcText(opts.reply, 'reply');
459
+ if (!reply.trim()) throw new ReplyCheckError('REPLY_REQUIRED', 'reply (the AI-drafted reply to check) is required');
460
+ const received = rcText(opts.received, 'received');
461
+ const facts = rcText(opts.facts, 'facts');
462
+ const today = rcToday(opts.today);
463
+ const includeGreen = opts.includeGreen !== false;
464
+ const sources = { received, facts };
465
+
466
+ const r = checkReply(received, reply, facts, { today });
467
+ const lineStarts = [0];
468
+ for (let i = 0; i < reply.length; i++) if (reply[i] === '\n') lineStarts.push(i + 1);
469
+ const lineOf = (pos) => {
470
+ let lo = 0, hi = lineStarts.length - 1;
471
+ while (lo < hi) { const mid = (lo + hi + 1) >> 1; if (lineStarts[mid] <= pos) lo = mid; else hi = mid - 1; }
472
+ return { line: lo + 1, column: pos - lineStarts[lo] + 1 };
473
+ };
474
+
475
+ const picked = r.items.filter((it) => includeGreen || it.status !== 'green');
476
+ const items = picked.slice(0, REPLY_CHECK_MAX_ITEMS).map((it) => {
477
+ const out = { status: it.status, type: it.type, text: it.text, start: it.start, end: it.end, ...lineOf(it.start), reasons: it.reasons.slice() };
478
+ const msgs = it.reasons.map((k) => (k === 'weekday' || k === 'nodate' ? L[k](it.date) : L[k])).filter(Boolean);
479
+ if (msgs.length) out.message = msgs.join(' / ');
480
+ if (it.date) {
481
+ out.date = { date: it.date.y + '-' + pad2(it.date.m) + '-' + pad2(it.date.d) };
482
+ if (it.date.written >= 0) out.date.writtenWeekday = WD_EN_FULL[it.date.written];
483
+ if (it.date.actual >= 0) out.date.actualWeekday = WD_EN_FULL[it.date.actual];
484
+ }
485
+ out.hitCount = it.hits.length;
486
+ out.hits = it.hits.slice(0, REPLY_CHECK_MAX_HITS).map((h) => ({ source: h.src, start: h.start, end: h.end, text: sources[h.src].slice(h.start, h.end) }));
487
+ return out;
488
+ });
489
+
490
+ return {
491
+ count: { ...r.count },
492
+ items,
493
+ truncated: picked.length > items.length,
494
+ note: L.note,
495
+ today: today.getFullYear() + '-' + pad2(today.getMonth() + 1) + '-' + pad2(today.getDate()),
496
+ };
497
+ }
package/server.mjs CHANGED
@@ -48,6 +48,7 @@ import { cssLayoutGenerateTool } from './css-layout.mjs';
48
48
  import { wikiDocLintTool } from './wiki-doc-lint.mjs';
49
49
  import { fitToBoxTool } from './fit-to-box.mjs';
50
50
  import { invoiceNebikiTool } from './invoice-nebiki.mjs';
51
+ import { replyCheckTool } from './reply-check.mjs';
51
52
 
52
53
  const { version } = createRequire(import.meta.url)('./package.json');
53
54
  // SDK v2 の serveStdio は接続ごとに factory から McpServer を1つ作る(旧仕様の initialize と
@@ -2026,7 +2027,7 @@ registerTool(
2026
2027
  cutAmount: z.number().optional().describe('言われた値下げの額(円/月。cutRate とどちらか)'),
2027
2028
  today: z.string().optional().describe('基準日 YYYY-MM-DD(省略時はサーバーの今日)'),
2028
2029
  format: z.enum(['text', 'md']).optional().describe("message の形式(既定 'text')"),
2029
- showAmount: z.boolean().optional().describe('金額を返すか(既定 true。false なら割合だけ)'),
2030
+ showAmount: z.boolean().optional().describe('金額を返すか(既定 true。false なら割合だけで、返り値の input・fragment からも月額と額の値下げを外す)'),
2030
2031
  lang: z.enum(['ja', 'en']).optional().describe("文言の言語(既定 'ja')"),
2031
2032
  },
2032
2033
  },
@@ -2036,4 +2037,31 @@ registerTool(
2036
2037
  },
2037
2038
  );
2038
2039
 
2040
+ registerTool(
2041
+ 'reply_check',
2042
+ {
2043
+ title: 'AIの返信案の送る前チェック(日付・金額・宛名などの照合)',
2044
+ description:
2045
+ '届いたメール(received)と、任意の「自分で決めた事実」(facts:営業時間・料金・日程など)を、AI が書いた返信案(reply)と照らし合わせる(tools.first-ch.com/okurumae/ と同一ロジック)。' +
2046
+ '返信案から日付・曜日・時刻・金額・数量(〇名・〇泊・%)・電話番号・メールアドレス・URL・宛名(〇〇様・Dear Ms. …)・番号を拾い、received と facts のどちらにも無いものを status=red(reasons に missing)、あるものを green、' +
2047
+ '[お客様1]・〇〇・XX・【】・{name} などの消し忘れを yellow(placeholder)で返す。日付と曜日の食い違い(例: 2026年11月8日(金))と存在しない日付も red(weekday / nodate・date に実際の曜日)。' +
2048
+ '年の書かれていない日付は today の60日前〜305日後に入る年で曜日を確かめる。全角/半角・カンマ・「18時30分」と「18:30」・「3千円」と「3,000円」は照合のときだけそろえ、本文は書き換えない。' +
2049
+ 'items の start / end は reply の中の位置(JavaScript の文字列の添字=UTF-16)、line / column は1始まり。hits は一致した原文の箇所(1項目5件まで・hitCount は全数)。' +
2050
+ 'count は全項目の件数で、items は500件まで(超えたら truncated:true)。赤が0件でも内容の正しさは保証しない(note)。自動修正・文体の添削・伏せ字はしない。' +
2051
+ '各欄2万字まで。入力の誤りは ReplyCheckError(code 付き)。完全ローカル処理・ネットワーク送信なし。',
2052
+ inputSchema: {
2053
+ received: z.string().optional().describe('届いたメール(返信の元になった原文)'),
2054
+ reply: z.string().describe('AI が書いた返信案(照合する文章)'),
2055
+ facts: z.string().optional().describe('自分で決めた事実(営業時間・料金・日程・電話番号など。任意)'),
2056
+ today: z.string().optional().describe('基準日 YYYY-MM-DD(年の無い日付の年を決めるのに使う。省略時はサーバーの今日)'),
2057
+ includeGreen: z.boolean().optional().describe('緑(一致した項目)も items に入れるか(既定 true)'),
2058
+ lang: z.enum(['ja', 'en']).optional().describe("message・note の言語(既定 'ja')"),
2059
+ },
2060
+ },
2061
+ async (opts) => {
2062
+ await logUsage('reply_check');
2063
+ return asText(replyCheckTool(opts));
2064
+ },
2065
+ );
2066
+
2039
2067
  serveStdio(buildServer);