@first-ch/tools-mcp 0.56.1 → 0.57.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
@@ -95,6 +95,7 @@ This server is also registered in the [MCP Registry](https://registry.modelconte
95
95
  | `comfy_png_leak_scan` | Checks a ComfyUI PNG you received or posted for **API key formats** (Google `AIza`, OpenAI-style `sk-`, Anthropic `sk-ant-`, Hugging Face `hf_`, Replicate `r8_`) in its embedded data (same logic as tools.first-ch.com/en/comfy-key-leak/). Chunks are read in order with CRC checks; tEXt and uncompressed iTXt are searched. `status` is `found`, `none` (not a claim that the image is safe), `unchecked` (zTXt, compressed iTXt, eXIf, caBX, unknown chunks, data after IEND, over 30 MB) or `failed` (CRC mismatch, truncated, not a PNG). Each finding gives the place — node ID, `classType` and `input` from prompt, or node ID and `widgetIndex` when only a workflow exists (`fieldUnknown`) — plus flags for duplicate JSON keys, items outside inputs and bypassed/muted nodes. Node titles are not used. **Values are never returned**: only `masked` (first 4 characters) and `length`. `notice` is a heads-up message for the key owner (no values or file name; states that validity and cause were not checked) and `revoke` lists the official pages to disable each key type. With `outPath` it writes a copy without tEXt/iTXt/zTXt after re-reading it (0 text chunks, kept chunks byte-identical); the original is never changed, caBX (C2PA) PNGs are not rewritten. It does not test keys or fetch URLs, and sends nothing itself. Prefer `path`: with `base64` the image bytes (including any raw key) go into the AI conversation and to the model provider, and the result carries an `inputNote` saying so | `path` (absolute) or `base64`, `outPath?`, `overwrite?`, `includeUrl?`, `lang?` |
96
96
  | `ai_vs_search` | Compares visitors from AI with visitors from search in **your own GA4 data** (same logic as tools.first-ch.com/en/ai-vs-search/). Pass the CSV exported from Traffic acquisition (Session default channel group, no comparison or filter) as `csv` text or an absolute `path`; Japanese and English column names are read. Returns, for Google's `AI Assistant` and `Organic Search` rows and the total of all other channels, sessions, engagement rate (engaged sessions ÷ sessions), average engagement time per session (session-weighted) and key event rate (key events ÷ sessions — not GA4's Session key event rate), plus `ratios` (AI ÷ search; `null` under 30 AI sessions), `totals.basis` (`matched` with the grand total row / `read` when rows were skipped or totals differ / `noTotal`), `excluded` line numbers, `notes` (e.g. the period includes dates before 2026-05-13, when the AI Assistant channel was added) and a `summary` to paste. No outside study figures, own AI-service list or GA4 API. Local only, nothing is sent. |
97
97
  | `email_read_aloud` | For choosing a new email address you will repeat on the phone (same logic as tools.first-ch.com/en/mail-yomiage/). Pass up to five addresses or bare domains as `candidates`; for each it returns the read-aloud text (letters and digits one by one; `@` at, `.` dot, `-` hyphen, `_` underscore, `+` plus; only a final `.com`/`.net` read as a word) and its length in `units` (katakana morae with `lang: "ja"`, syllables with `"en"`), sorted shortest first (not a ranking). `facts` counts characters, symbols by kind (`@` excluded), repeated characters, digits and letter/digit switches. `chars` gives each character's reading, its phonetic-alphabet word from Japan's Radio Station Operation Rules Appended Table 5 (the same words as the ITU table) and a Japanese example word. Unreadable candidates come back with `ok: false` and an error code. `card` is a comparison line with the addresses masked. No ranking, look-alike checks, availability or existence checks. Fully local. |
98
+ | `renkyu_pair_plan` | For two people whose days off fall on different weekdays, planning 2027 together (same logic as tools.first-ch.com/en/renkyu-2027/). Give each person (`me`, `partner`) their weekdays off (`days`, 0=Sun…6=Sat; default Sat+Sun), whether they are off on Japanese public holidays (`holidays`) and over New Year 29 Dec–3 Jan (`yearEnd`), and the paid leave they can use (`leave`, 0–10), plus `maxTotal` (0–20) for both. Returns `together` (days both are off in 2027), `perMonth` (12 counts), each person's days off, and up to three `candidates`: runs where every day is off for both or covered by leave for whoever works, within each person's leave and `maxTotal`, bounded by a working day or the edge of the year (breaks across the new year are cut). Ordered by length, then total leave, then the gap between the two; overlapping runs keep only the top one. Each has `start`, `end`, `days`, `meLeave`, `partnerLeave` (YYYY-MM-DD) and a `label`. Also `text` (share sentence) and `url` (the page with the settings after `#`). Holidays follow the Cabinet Office table for 2027 (17 days). No shift work, three or more people, 2028+ or company calendars | `me?`, `partner?` (`days?`, `holidays?`, `yearEnd?`, `leave?`), `maxTotal?` (default: sum of both `leave`), `lang?` (`ja`/`en`) |
98
99
 
99
100
  ### App tools (`app_*`, sent to apps.first-ch.com)
100
101
 
@@ -292,6 +293,7 @@ claude mcp add firstch-tools -- npx -y @first-ch/tools-mcp
292
293
  | `comfy_png_leak_scan` | 受け取った・投稿した ComfyUI の PNG の埋め込みデータから **APIキーの形**(Google の `AIza`・OpenAI などの `sk-`・Anthropic の `sk-ant-`・Hugging Face の `hf_`・Replicate の `r8_`)を探す(tools.first-ch.com/comfy-key-leak/ と同一ロジック)。チャンクを順に読んで CRC を確かめ、tEXt と非圧縮の iTXt を調べる。`status` は `found`・`none`(安全という意味ではない)・`unchecked`(zTXt・圧縮 iTXt・eXIf・caBX・不明なチャンク・IEND の後ろ・30MB超)・`failed`(CRC 不一致・途中で切れた・PNG でない)。場所は prompt ならノードID・`classType`・`input`、workflow だけならノードIDと `widgetIndex`(`fieldUnknown`)で、JSON の重複キー・inputs の外の項目・迂回/無効のノードの印つき。ノードの表示名は使わない。**値は返さない**(`masked`=先頭4字と `length` だけ)。`notice` はキーの持ち主へのお知らせ文(値・ファイル名なし、有効性と原因は確認していないと書く)、`revoke` は種類ごとの公式の無効化画面。`outPath` で tEXt・iTXt・zTXt を抜いたコピーを、読み直して確かめてから書く(元は変えない・caBX 付きは書き換えない)。キーの有効性の確認・URL の取得はしない(ツール自体は何も送らない)。入力は `path` を優先する: `base64` だと画像のバイト列(生のキーを含む)が AI との会話に載りモデルの提供元へ渡るため、返り値の `inputNote` でそれを伝える | `path`(絶対パス)か `base64`、`outPath?`、`overwrite?`、`includeUrl?`、`lang?` |
293
294
  | `ai_vs_search` | **自分のサイトの GA4** で、AI から来た人と検索から来た人を比べる(tools.first-ch.com/ai-vs-search/ と同一ロジック)。[トラフィック獲得](セッションのデフォルト チャネル グループ・比較とフィルタなし)から書き出した CSV を `csv`(文字列)か `path`(絶対パス)で渡す。列名は日本語・英語とも読む。Google が分類した `AI Assistant`・`Organic Search` とそれ以外の合計について、セッション・エンゲージメント率(エンゲージのあったセッション÷セッション)・セッションあたりの平均エンゲージメント時間(セッションで重み付け)・キーイベント率(キーイベント÷セッション。GA4 の「セッションのキーイベント率」とは別)を返し、`ratios`(AI ÷ 検索。AI が30セッション未満なら `null`)、`totals.basis`(総計行と一致 `matched`/除外・ずれありの `read`/総計行なし `noTotal`)、除外した行番号 `excluded`、`notes`(2026-05-13=AI Assistant チャネルの追加日より前を含む期間など)、貼り付け用の `summary` を返す。外部の調査値・独自の AI サービス一覧・GA4 API は使わない。完全ローカル処理・送信なし。 |
294
295
  | `email_read_aloud` | 電話や名刺で言い続けるメールアドレスを候補から決めるとき向け(tools.first-ch.com/mail-yomiage/ と同一ロジック)。`candidates` にアドレスかドメインを最大5件渡すと、候補ごとの読み上げ文(英字・数字は1字ずつ、`@` アットマーク・`.` ドット・`-` ハイフン・`_` アンダーバー・`+` プラス、末尾の `.com`・`.net` だけ語で読む)と長さ `units`(`lang: "ja"` はカタカナの拍・`"en"` は音節)を短い順に返す(順位ではない)。`facts` は文字数・記号の種類(`@` は数えない)・同じ文字の連続・数字の桁数・英字と数字の切り替わり回数。`chars` は1文字ずつの読み・欧文通話表の語(無線局運用規則 別表第五号・ITU と同じ語)・日本語の言い換え例。読めない候補は `ok: false` とエラーコード。`card` はアドレスを伏せ字にした比べの文。順位・見た目の似た文字・空き・実在の確認はしない。完全ローカル。 |
296
+ | `renkyu_pair_plan` | 休みの曜日が違う2人が2027年の予定を立てるとき向け(tools.first-ch.com/renkyu-2027/ と同一ロジック)。`me`・`partner` にそれぞれ休みの曜日(`days`・0=日〜6=土・既定は土日)、祝日に休むか(`holidays`)、年末年始 12/29〜1/3 に休むか(`yearEnd`)、使える有給(`leave`・0〜10日)を、`maxTotal`(0〜20)に2人の有給の合計の上限を渡すと、2027年に2人そろって休める日数(`together`)と月ごとの内訳(`perMonth`)、有給を足した連休の候補(`candidates`・最大3件)を返す。候補は期間の毎日が「2人とも休み」か「休みでない方の有給」で埋まり、各自の上限と合計の上限を守る期間(年をまたぐ連休は年の端で切る)。並びは長い順→有給の合計の少ない順→2人の差の小さい順で、重なる候補は上位1件。各候補は `start`・`end`・`days`・`meLeave`・`partnerLeave`・`label`。共有用の `text` と、条件を `#` 以降に入れたページの `url` も返す。祝日は内閣府の2027年の表(17日)。シフト制・3人以上・2028年以降・会社独自の休日は対象外 | `me?`・`partner?`(`days?`・`holidays?`・`yearEnd?`・`leave?`)、`maxTotal?`(既定は2人の `leave` の和)、`lang?` |
295
297
 
296
298
  #### apps のツール(`app_*`・apps.first-ch.com へ送信)
297
299
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@first-ch/tools-mcp",
3
- "version": "0.56.1",
3
+ "version": "0.57.0",
4
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が書いた返信案と届いたメールの照合(原文に無い日付・曜日・時刻・金額・数量・電話・宛名を赤、消し忘れの仮の文字を黄)・ComfyUI画像(PNG)の埋め込みデータに残ったAPIキーの形の点検(ノードIDと入力欄で場所を示し値は伏せる・持ち主へのお知らせ文・文字のチャンクを抜いたコピー)・GA4「トラフィック獲得」のCSVから AI Assistant と Organic Search の訪問をエンゲージメント率・平均エンゲージメント時間・キーイベント率で比べる集計(倍率・総計行との突き合わせ・除外した行の行番号・要約)・メールアドレス候補の読み上げ文と拍数(記号・同じ文字の連続・数字の桁数などの数え上げと欧文通話表の1文字ずつの表))をMCPツールとして提供するサーバー。あわせて apps.first-ch.com のWebアプリ42本(GEO・メタタグ・セキュリティヘッダー・SSL・DNS・リダイレクト・リンク切れ・構造化データ・AIクローラー許可・和文可読性・ビジネス文面チェック等)の JSON API を呼ぶ app_* ツールも提供する(こちらは入力を apps.first-ch.com へ送るため既定では無効・FIRSTCH_ENABLE_APPS=1 で有効)",
5
5
  "type": "module",
6
6
  "bin": {
@@ -24,6 +24,7 @@
24
24
  "mcp",
25
25
  "text-fit",
26
26
  "email-address",
27
+ "paid-leave",
27
28
  "phonetic-alphabet",
28
29
  "japanese-address",
29
30
  "kanji-numerals",
@@ -286,6 +287,7 @@
286
287
  "comfy-png-leak.mjs",
287
288
  "ai-vs-search.mjs",
288
289
  "email-read-aloud.mjs",
290
+ "renkyu-pair.mjs",
289
291
  "reply-check.mjs",
290
292
  "webp.mjs",
291
293
  "marp.mjs",
@@ -0,0 +1,253 @@
1
+ /* 休みの曜日が違う2人の2027年(renkyu_pair_plan)
2
+ * 計算のコアは FirstCHTools の site/renkyu-2027/plan.js と同一
3
+ * (2箇所ルール: site側が正本・片方を直したらもう片方も同じ内容で反映する)。
4
+ * 両ファイルの「ここからコア」〜「ここまでコア」はバイト一致する(どちらも ES module):
5
+ * diff <(sed -n '/^\/\/ =* ここから/,/^\/\/ =* ここまで/p' site/renkyu-2027/plan.js) <(sed -n '/^\/\/ =* ここから/,/^\/\/ =* ここまで/p' renkyu-pair.mjs)
6
+ *
7
+ * 2人それぞれの休みの曜日・祝日と年末年始に休むか・使える有給と、2人の有給の合計の上限から、
8
+ * 2027年に2人そろって休める日数(月ごと)と、有給を足して作れる連休の候補(最大3件)を返す。
9
+ * 祝日は内閣府「国民の祝日について」の令和9年の表(17日)。完全ローカル処理・ネットワーク送信なし。 */
10
+
11
+ // ==================== ここからコア ====================
12
+ export const YEAR = 2027;
13
+
14
+ // 内閣府「国民の祝日について」の令和9年(2027年)の表どおり。祝日16日と、祝日法第3条第2項による休日(3/22)1日の計17日。
15
+ // 2028年以降は内閣府が翌年分を公表してから差し替える。
16
+ export const HOLIDAYS = [
17
+ ['2027-01-01', '元日', 'New Year’s Day'],
18
+ ['2027-01-11', '成人の日', 'Coming of Age Day'],
19
+ ['2027-02-11', '建国記念の日', 'National Foundation Day'],
20
+ ['2027-02-23', '天皇誕生日', 'Emperor’s Birthday'],
21
+ ['2027-03-21', '春分の日', 'Vernal Equinox Day'],
22
+ ['2027-03-22', '休日(振替休日)', 'Substitute holiday'],
23
+ ['2027-04-29', '昭和の日', 'Showa Day'],
24
+ ['2027-05-03', '憲法記念日', 'Constitution Memorial Day'],
25
+ ['2027-05-04', 'みどりの日', 'Greenery Day'],
26
+ ['2027-05-05', 'こどもの日', 'Children’s Day'],
27
+ ['2027-07-19', '海の日', 'Marine Day'],
28
+ ['2027-08-11', '山の日', 'Mountain Day'],
29
+ ['2027-09-20', '敬老の日', 'Respect for the Aged Day'],
30
+ ['2027-09-23', '秋分の日', 'Autumnal Equinox Day'],
31
+ ['2027-10-11', 'スポーツの日', 'Sports Day'],
32
+ ['2027-11-03', '文化の日', 'Culture Day'],
33
+ ['2027-11-23', '勤労感謝の日', 'Labour Thanksgiving Day'],
34
+ ];
35
+ export const SOURCE = { url: 'https://www8.cao.go.jp/chosei/shukujitsu/gaiyou.html', checked: '2026-11-17' };
36
+
37
+ export const LEAVE_MAX = 10; // 1人が使える有給の上限
38
+ export const TOTAL_MAX = 20; // 2人の合計の上限 N
39
+ export const SHARE_BASE = 'https://tools.first-ch.com/renkyu-2027/';
40
+ export const DEFAULTS = Object.freeze({
41
+ me: Object.freeze({ days: Object.freeze([0, 6]), holidays: true, yearEnd: true, leave: 3 }),
42
+ partner: Object.freeze({ days: Object.freeze([0, 6]), holidays: true, yearEnd: true, leave: 3 }),
43
+ maxTotal: 6,
44
+ });
45
+
46
+ const DAY_MS = 86400000;
47
+ const START = Date.UTC(YEAR, 0, 1);
48
+ export const DAYS_IN_YEAR = Math.round((Date.UTC(YEAR + 1, 0, 1) - START) / DAY_MS);
49
+ const HOLIDAY_SET = new Set(HOLIDAYS.map((h) => h[0]));
50
+
51
+ export class RenkyuError extends Error {
52
+ constructor(code, message) { super(message); this.code = code; }
53
+ }
54
+
55
+ const pad = (n) => String(n).padStart(2, '0');
56
+ export function isoOf(i) {
57
+ const d = new Date(START + i * DAY_MS);
58
+ return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
59
+ }
60
+ export function indexOf(iso) {
61
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(iso));
62
+ if (!m) return -1;
63
+ const t = Date.UTC(+m[1], +m[2] - 1, +m[3]);
64
+ const i = Math.round((t - START) / DAY_MS);
65
+ return i >= 0 && i < DAYS_IN_YEAR && isoOf(i) === iso ? i : -1;
66
+ }
67
+ export const weekdayOf = (i) => new Date(START + i * DAY_MS).getUTCDay(); // 0=日〜6=土
68
+ export const monthOf = (i) => new Date(START + i * DAY_MS).getUTCMonth(); // 0=1月
69
+ export const isHoliday = (i) => HOLIDAY_SET.has(isoOf(i));
70
+ // 年末年始(12/29〜1/3)のうち、この年に入る日(1/1〜1/3 と 12/29〜12/31)
71
+ export function isYearEnd(i) {
72
+ const d = new Date(START + i * DAY_MS);
73
+ const m = d.getUTCMonth(); const day = d.getUTCDate();
74
+ return (m === 0 && day <= 3) || (m === 11 && day >= 29);
75
+ }
76
+
77
+ function intIn(v, lo, hi, def) {
78
+ const n = typeof v === 'string' && v.trim() !== '' ? Number(v) : v;
79
+ if (typeof n !== 'number' || !Number.isFinite(n)) return def;
80
+ return Math.min(hi, Math.max(lo, Math.round(n)));
81
+ }
82
+ function normDays(v, def) {
83
+ if (v == null) return def.slice();
84
+ const list = Array.isArray(v) ? v : String(v).split('').filter((c) => /\d/.test(c));
85
+ const out = [...new Set(list.map(Number).filter((n) => Number.isInteger(n) && n >= 0 && n <= 6))];
86
+ return out.sort((a, b) => a - b);
87
+ }
88
+ function normPerson(p, def) {
89
+ const o = p && typeof p === 'object' ? p : {};
90
+ return {
91
+ days: normDays(o.days, def.days),
92
+ holidays: o.holidays == null ? def.holidays : !!o.holidays,
93
+ yearEnd: o.yearEnd == null ? def.yearEnd : !!o.yearEnd,
94
+ leave: intIn(o.leave, 0, LEAVE_MAX, def.leave),
95
+ };
96
+ }
97
+ // 範囲の外・形の違う値は既定値か端の値に寄せる(画面とURLの復元用)
98
+ export function normalize(input) {
99
+ const o = input && typeof input === 'object' ? input : {};
100
+ return {
101
+ me: normPerson(o.me, DEFAULTS.me),
102
+ partner: normPerson(o.partner, DEFAULTS.partner),
103
+ maxTotal: intIn(o.maxTotal, 0, TOTAL_MAX, DEFAULTS.maxTotal),
104
+ };
105
+ }
106
+
107
+ // 1人の休み(曜日・祝日・年末年始)を日ごとの真偽で返す
108
+ export function offDays(p) {
109
+ const wd = new Set(p.days);
110
+ const out = new Array(DAYS_IN_YEAR);
111
+ for (let i = 0; i < DAYS_IN_YEAR; i++) {
112
+ out[i] = wd.has(weekdayOf(i)) || (p.holidays && isHoliday(i)) || (p.yearEnd && isYearEnd(i));
113
+ }
114
+ return out;
115
+ }
116
+
117
+ // 2人の休み・そろって休める日数(月ごと)・有給を足した連休の候補(最大 limit 件)。
118
+ // 候補は「その期間の毎日、2人とも休みか有給」で、各自の有給の上限と合計の上限 N の両方を守る。
119
+ // 前後の日も2人そろって休みなら必ず延ばせるので、期間の外側の隣は「どちらかが休みでない日」か年の端に限る。
120
+ // 並べ方: 連続日数の長い順 → 有給の合計の少ない順 → 2人の有給の差の小さい順 → 始まりの早い順。期間が重なる候補は上位の1件だけ残す。
121
+ export function planPair(input, limit = 3) {
122
+ const c = normalize(input);
123
+ const A = offDays(c.me); const B = offDays(c.partner);
124
+ const both = A.map((a, i) => a && B[i]);
125
+ const perMonth = new Array(12).fill(0);
126
+ let together = 0; let meOff = 0; let partnerOff = 0;
127
+ const pa = [0]; const pb = [0];
128
+ for (let i = 0; i < DAYS_IN_YEAR; i++) {
129
+ if (both[i]) { together++; perMonth[monthOf(i)]++; }
130
+ if (A[i]) meOff++;
131
+ if (B[i]) partnerOff++;
132
+ pa.push(pa[i] + (A[i] ? 0 : 1));
133
+ pb.push(pb[i] + (B[i] ? 0 : 1));
134
+ }
135
+ const la = c.me.leave; const lb = c.partner.leave; const n = c.maxTotal;
136
+ const wins = [];
137
+ for (let s = 0; s < DAYS_IN_YEAR; s++) {
138
+ if (s > 0 && both[s - 1]) continue;
139
+ for (let e = s; e < DAYS_IN_YEAR; e++) {
140
+ const ua = pa[e + 1] - pa[s]; const ub = pb[e + 1] - pb[s];
141
+ if (ua > la || ub > lb || ua + ub > n) break;
142
+ if (e === DAYS_IN_YEAR - 1 || !both[e + 1]) wins.push({ s, e, ua, ub });
143
+ }
144
+ }
145
+ wins.sort((x, y) => (y.e - y.s) - (x.e - x.s) || (x.ua + x.ub) - (y.ua + y.ub)
146
+ || Math.abs(x.ua - x.ub) - Math.abs(y.ua - y.ub) || x.s - y.s);
147
+ const picked = [];
148
+ for (const w of wins) {
149
+ if (picked.length >= limit) break;
150
+ if (picked.some((p) => w.s <= p.e && p.s <= w.e)) continue;
151
+ picked.push(w);
152
+ }
153
+ const leaveOf = (arr, w) => { const r = []; for (let i = w.s; i <= w.e; i++) if (!arr[i]) r.push(isoOf(i)); return r; };
154
+ const candidates = picked.map((w) => ({
155
+ start: isoOf(w.s), end: isoOf(w.e), days: w.e - w.s + 1,
156
+ meLeave: leaveOf(A, w), partnerLeave: leaveOf(B, w), totalLeave: w.ua + w.ub,
157
+ }));
158
+ return { year: YEAR, conditions: c, together, perMonth, meOff, partnerOff, candidates };
159
+ }
160
+
161
+ // 2人分の条件を URL の # 以降の文字列にする(例 a=06&ah=1&ay=1&al=3&b=3&bh=0&by=1&bl=3&n=6)
162
+ export function toHash(input) {
163
+ const c = normalize(input);
164
+ const q = [];
165
+ for (const [k, p] of [['a', c.me], ['b', c.partner]]) {
166
+ q.push(`${k}=${p.days.join('')}`, `${k}h=${p.holidays ? 1 : 0}`, `${k}y=${p.yearEnd ? 1 : 0}`, `${k}l=${p.leave}`);
167
+ }
168
+ q.push(`n=${c.maxTotal}`);
169
+ return q.join('&');
170
+ }
171
+ export function fromHash(hash) {
172
+ const q = new URLSearchParams(String(hash || '').replace(/^#/, ''));
173
+ if (![...q.keys()].some((k) => /^(a|b)[hyl]?$|^n$/.test(k))) return null;
174
+ const flag = (k) => (q.has(k) ? q.get(k) === '1' : undefined);
175
+ const num = (k) => (q.has(k) ? q.get(k) : undefined);
176
+ const person = (k) => ({ days: q.has(k) ? q.get(k) : undefined, holidays: flag(k + 'h'), yearEnd: flag(k + 'y'), leave: num(k + 'l') });
177
+ return normalize({ me: person('a'), partner: person('b'), maxTotal: num('n') });
178
+ }
179
+ export const swap = (input) => { const c = normalize(input); return { me: c.partner, partner: c.me, maxTotal: c.maxTotal }; };
180
+
181
+ const WD = { ja: ['日', '月', '火', '水', '木', '金', '土'], en: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] };
182
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
183
+ // 5/1(土) / Sat 1 May
184
+ export function fmtDay(iso, lang = 'ja', withWeekday = true) {
185
+ const i = indexOf(iso); if (i < 0) return '';
186
+ const d = new Date(START + i * DAY_MS); const w = WD[lang === 'en' ? 'en' : 'ja'][d.getUTCDay()];
187
+ if (lang === 'en') return `${withWeekday ? w + ' ' : ''}${d.getUTCDate()} ${MON[d.getUTCMonth()]}`;
188
+ return `${d.getUTCMonth() + 1}/${d.getUTCDate()}${withWeekday ? `(${w})` : ''}`;
189
+ }
190
+ export function fmtRange(c, lang = 'ja', withWeekday = false) {
191
+ const a = fmtDay(c.start, lang, withWeekday);
192
+ if (c.start === c.end) return a;
193
+ return lang === 'en' ? `${a}–${fmtDay(c.end, lang, withWeekday)}` : `${a}〜${fmtDay(c.end, lang, withWeekday)}`;
194
+ }
195
+
196
+ // 「コピー」で写す文(URL は別に足す)
197
+ export function shareText(result, lang = 'ja') {
198
+ const r = result; const top = r.candidates[0];
199
+ if (lang === 'en') {
200
+ const head = `In ${r.year}, we can both be off on ${r.together} day${r.together === 1 ? '' : 's'}.`;
201
+ if (!top) return head;
202
+ const a = top.meLeave.length; const b = top.partnerLeave.length;
203
+ const use = a + b === 0 ? 'Without any paid leave' : `With ${a} day${a === 1 ? '' : 's'} of leave for me and ${b} for you`;
204
+ return `${head} ${use}, we get ${fmtRange(top, 'en')} off${top.days >= 2 ? `: ${top.days} days in a row` : ''}.`;
205
+ }
206
+ const head = `${r.year}年、2人そろって休めるのは${r.together}日。`;
207
+ if (!top) return head;
208
+ const a = top.meLeave.length; const b = top.partnerLeave.length;
209
+ const use = a + b === 0 ? '有給なしで' : `有給をわたし${a}日・相手${b}日使うと`;
210
+ return `${head}${use}${fmtRange(top, 'ja')}の${top.days >= 2 ? `${top.days}連休` : '1日'}`;
211
+ }
212
+ export const shareUrl = (input) => `${SHARE_BASE}#${toHash(input)}`;
213
+ // ==================== ここまでコア ====================
214
+
215
+ // ---- MCP の入口 ----
216
+ function checkPerson(p, name) {
217
+ if (p == null) return;
218
+ if (typeof p !== 'object' || Array.isArray(p)) throw new RenkyuError('BAD_INPUT', `${name} must be an object`);
219
+ if (p.days != null) {
220
+ if (!Array.isArray(p.days) || p.days.some((d) => !Number.isInteger(d) || d < 0 || d > 6)) {
221
+ throw new RenkyuError('BAD_DAYS', `${name}.days must be an array of integers 0 (Sunday) to 6 (Saturday)`);
222
+ }
223
+ }
224
+ if (p.leave != null && (!Number.isInteger(p.leave) || p.leave < 0 || p.leave > LEAVE_MAX)) {
225
+ throw new RenkyuError('BAD_LEAVE', `${name}.leave must be an integer from 0 to ${LEAVE_MAX}`);
226
+ }
227
+ }
228
+
229
+ export function renkyuPairTool(opts = {}) {
230
+ const lang = opts.lang === 'en' ? 'en' : 'ja';
231
+ checkPerson(opts.me, 'me');
232
+ checkPerson(opts.partner, 'partner');
233
+ if (opts.maxTotal != null && (!Number.isInteger(opts.maxTotal) || opts.maxTotal < 0 || opts.maxTotal > TOTAL_MAX)) {
234
+ throw new RenkyuError('BAD_TOTAL', `maxTotal must be an integer from 0 to ${TOTAL_MAX}`);
235
+ }
236
+ const base = normalize({ me: opts.me, partner: opts.partner });
237
+ // maxTotal を省いたら2人の有給の和(=合計では縛らない)
238
+ const input = { ...base, maxTotal: opts.maxTotal ?? base.me.leave + base.partner.leave };
239
+ const r = planPair(input);
240
+ const url = shareUrl(input).replace('/renkyu-2027/', lang === 'en' ? '/en/renkyu-2027/' : '/renkyu-2027/');
241
+ return {
242
+ year: r.year,
243
+ conditions: r.conditions,
244
+ together: r.together,
245
+ perMonth: r.perMonth,
246
+ meOff: r.meOff,
247
+ partnerOff: r.partnerOff,
248
+ candidates: r.candidates.map((c) => ({ ...c, label: fmtRange(c, lang, true) })),
249
+ text: shareText(r, lang),
250
+ url,
251
+ holidays: { count: HOLIDAYS.length, source: SOURCE.url, checked: SOURCE.checked },
252
+ };
253
+ }
package/server.mjs CHANGED
@@ -51,6 +51,7 @@ import { invoiceNebikiTool } from './invoice-nebiki.mjs';
51
51
  import { comfyPngLeakTool } from './comfy-png-leak.mjs';
52
52
  import { aiVsSearchTool } from './ai-vs-search.mjs';
53
53
  import { emailReadAloudTool } from './email-read-aloud.mjs';
54
+ import { renkyuPairTool } from './renkyu-pair.mjs';
54
55
  import { replyCheckTool } from './reply-check.mjs';
55
56
 
56
57
  const { version } = createRequire(import.meta.url)('./package.json');
@@ -2140,4 +2141,37 @@ registerTool(
2140
2141
  },
2141
2142
  );
2142
2143
 
2144
+ const renkyuPerson = z
2145
+ .object({
2146
+ days: z.array(z.number().int().min(0).max(6)).optional().describe('休みの曜日(0=日〜6=土・いくつでも。既定 [0, 6]=土日)'),
2147
+ holidays: z.boolean().optional().describe('祝日に休むか(既定 true)'),
2148
+ yearEnd: z.boolean().optional().describe('年末年始(12/29〜1/3 のうち年内の日)に休むか(既定 true)'),
2149
+ leave: z.number().int().min(0).max(10).optional().describe('1つの連休で使える有給の日数(0〜10・既定 3)'),
2150
+ })
2151
+ .optional();
2152
+
2153
+ registerTool(
2154
+ 'renkyu_pair_plan',
2155
+ {
2156
+ title: '休みの曜日が違う2人の2027年のそろって休める日と連休の候補',
2157
+ description:
2158
+ '2人(me と partner)の休みの曜日・祝日と年末年始に休むか・使える有給と、2人の有給の合計の上限 maxTotal から、2027年(1/1〜12/31)に2人そろって休める日数と月ごとの内訳(perMonth・1月から12個)、有給を足して作れる連休の候補を最大3件返す(tools.first-ch.com/renkyu-2027/ と同一ロジック)。' +
2159
+ '祝日は内閣府「国民の祝日について」の令和9年の表どおり(祝日16日+3/22 の振替休日=17日)。年末年始は 12/29〜12/31 と 1/1〜1/3。' +
2160
+ '候補は、期間の毎日が「2人とも休み」か「休みでない方の有給」で埋まり、各自の leave と maxTotal の両方を守る期間で、外側の隣は2人そろって休みでない日か年の端。年をまたぐ連休は年の端で切る。' +
2161
+ '並びは日数の長い順→有給の合計の少ない順→2人の有給の差の小さい順→始まりの早い順で、期間が重なる候補は上位の1件だけ残す。各候補は start・end・days・meLeave・partnerLeave(有給を取る日の YYYY-MM-DD)・totalLeave・label。' +
2162
+ 'text は共有用の文、url は条件を # 以降に入れたページの URL(開くとブラウザの中で同じ結果を復元する)。' +
2163
+ 'シフト制・3人以上・2028年以降・会社独自の休日には対応しない。完全ローカル処理・ネットワーク送信なし。',
2164
+ inputSchema: {
2165
+ me: renkyuPerson.describe('わたしの条件'),
2166
+ partner: renkyuPerson.describe('相手の条件'),
2167
+ maxTotal: z.number().int().min(0).max(20).optional().describe('2人で使う有給の合計の上限(0〜20。省くと2人の leave の和)'),
2168
+ lang: z.enum(['ja', 'en']).optional().describe("text・label・url の言語(既定 'ja')"),
2169
+ },
2170
+ },
2171
+ async (opts) => {
2172
+ await logUsage('renkyu_pair_plan');
2173
+ return asText(renkyuPairTool(opts));
2174
+ },
2175
+ );
2176
+
2143
2177
  serveStdio(buildServer);