From 94bbbd049300e18b42a9b10c738ad4859902fc60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Mon, 16 Nov 2026 22:28:37 +0800 Subject: [PATCH] =?UTF-8?q?design:=20=E8=A8=AD=E5=AE=9A=E6=B8=9B=E5=AD=97?= =?UTF-8?q?=EF=BC=8B=E9=A0=81=E9=9D=A2=E7=85=A7=20Anthropic=20=E7=9A=84?= =?UTF-8?q?=E5=A0=B1=E5=91=8A=E5=AF=AB=E6=B3=95=EF=BC=88=E5=AF=AB=E6=B3=95?= =?UTF-8?q?=E8=A6=8F=E5=89=87=E3=80=81=E5=AD=98=E6=AA=94=E5=89=8D=E6=AA=A2?= =?UTF-8?q?=E6=9F=A5=E3=80=81=E5=8F=AF=E6=94=B6=E8=B5=B7=E7=9A=84=E7=B4=B0?= =?UTF-8?q?=E7=AF=80=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 設定頁(字太多): - 設定列的「?」平常不顯示,滑鼠移到那一列才出現(位置保留,名稱不跳動) - 設定下面的說明只顯示一行,長的結尾「…」,滑過看全文 - 外觀只留主題、強調色、聊天的顏色、語言;底色、對比、密度、慶祝動畫、重設收進「更多外觀設定」 - 聊天的顏色只有點(選中的有外圈),不再加一段文字;「你的電腦已是最新版本」改成灰字一行,不再是橘框 頁面(內容太亂、字太多): - 給 Bot 的寫法規則改成 Anthropic 的寫法:標題就是結論、第一句補理由、最多三點;數字放 stats/表格; 一節最多一處粗體;不用「→」、分隔線、標題編號;待辦用 steps、指令放程式碼;細節放 details - 存檔前檢查(pages::review):段落太長、粗體太多、括號裡一串數字、標題編號、分隔線、「→」、表格裡的指令、 很長卻沒有 details——退回一次並列出每一處;同一頁第二次照存,不會卡住 - 新頁面區塊 ```details 標題:預設收起的一行「▸ 標題」,點了展開(電腦和手機) 已驗證: cargo test 523 全過(新增:寫法檢查抓得到那頁的毛病、乾淨的頁面不報;退回一次第二次照存; details 標題與收起)、clippy 21=基線、手機四段腳本 node --check、深色設定頁截圖目視 未驗證: 真的模型照新規則寫出來的頁面長怎樣(要等 Bot 下次寫頁面) --- FEATURES.md | 4 +- docs/feature-map/pages.md | 3 +- docs/feature-map/settings.md | 2 +- mobile/index.html | 5 ++ src/app.rs | 81 ++++++++++++---------- src/app/computers_ui.rs | 10 ++- src/app/kit.rs | 22 ++++-- src/app/markdown_ui.rs | 57 ++++++++++++++- src/appctl.rs | 34 +++++++++ src/pages.rs | 131 ++++++++++++++++++++++++++++++++++- 10 files changed, 302 insertions(+), 47 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 14f3264..e7aa188 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -1566,6 +1566,8 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) - 你請 Bot 追蹤、整理、比較一件之後還會回來看的事(例如「幫我追蹤一下台灣 FSD 狀況」),它用 `write_page` 做成一頁:先寫現況,再寫細節和來源(附日期)。回答裡用「[標題](page:ID)」連到它,回答下面出現頁面卡片(標題、開頭幾行、頁面圖示、「頁面 · 更新時間」、最近一次更新了什麼),點一下打開。 - 頁面可以放表格、Mermaid 圖表(圓餅、長條、折線、時間軸…白底卡節點、細灰連線),以及頁面專用的區塊:```stats 數字卡片(數字大字,超過 10 個字的值縮成小一號;值和備註開頭 ↑/+ 綠色、↓/−/- 紅色,「+」「-」後面要緊接著東西才算,單獨一個「-」當作沒資料;電腦和手機同一套規則)、```steps 進度(✓ 完成、◉ 進行中、○ 還沒到)、```chart 原生圖表(bar 長條、line 折線、pie 圓餅;只畫淡水平參考線,長條自動由大到小排序——月份/年份等自有順序的標籤不排;單系列把數字直接標在圖上、不畫 y 軸;多條線在線尾標系列名;懸停看數值、拖曳平移、右鍵框選放大、雙擊還原,圖下自動附數據表,不會破版;多系列用 `| 1月 | 2月` 當表頭;第一行可以是「圖型 標題」、只寫圖型(bar/line/pie 或 長條/折線/圓餅)或只寫標題,`#` 開頭的行是註解,`|---|` 分隔列略過,少填的格子當 0——電腦和手機同一套讀法;手機看同一頁也畫同樣樣式的原生 SVG 圖:照手機寬度畫、字不會縮小,折線和多系列長條有 y 軸數字,圖下同樣附數據表,只有一項的圓餅畫成整圓,圖例項目再多也都畫得到,負數的數字不會壓到下面的標籤)、`> [!NOTE]`/`[!TIP]`/`[!WARNING]`/`[!IMPORTANT]` 提示框。這些區塊在聊天裡也能用。所有圖表(含 Mermaid 圓餅)共用同一套低飽和六色色板,深淺兩主題各一組。 +- **細節區塊** ```details 標題:預設收起,只顯示一行灰色「▸ 標題」(沒寫標題就是「細節」),點了展開裡面的 Markdown。讓第一屏只有結論、數字和下一步;證據、長清單、指令收在下面。 +- **寫法檢查**:Bot 存頁面時程式先看一遍(Anthropic 的報告寫法:結論先講、句子短、少粗體、數字放卡片或表格、不用裝飾)。段落超過 120 字、一節超過一處粗體、括號裡一串數字、標題編號、分隔線、用「→」帶結論、表格裡放指令、正文很長卻沒有收起的細節——有就退回一次、列出每一處要怎麼改;同一頁第二次照存,不會卡住。 - 頁面是「閱讀排版」:內文排在置中的 720 像素欄位裡,行高 1.55 倍、段落有呼吸空間,不會貼著視窗邊緣;聊天室保持原本的緊湊排版。頁面上的數字表格(2–3 欄、資料不超過 8 列)在寬度夠時會自動左表右圖併排。 - 有 3 個以上標題的頁面,標題下面有一行小字「▸ 目錄 · N 節」(不佔第一屏):點了展開成標題清單,每條可點、點了跳到那一節;展開時上面有小搜尋框可以篩標題(⌘F 直接展開並把光標放進去,Esc 離開)。 - 寫頁面時 Bot 會選一種「種類」(data 數據分析/compare 比較評測/decision 決策備忘/howto 教學步驟/timeline 時間線/prose 長文/notes 筆記),第一屏跟著內容走:data 頁頂部放 2–4 張 KPI 數字卡(附漲跌,漲綠跌紅),compare/decision 頁先給一行「結論」卡;種類顯示在頁面標題和聊天卡片的列中。字段全部可省略——沒有數字就不硬湊卡片。 @@ -1919,7 +1921,7 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) - **群組**:一張卡(細框、圓角 14)裝一組設定列,列與列之間一條細線。 - **設定列**:左邊名稱 14 px(可以多一行 13 px 灰色狀態)和「?」說明,右邊開關、選單或按鈕;名稱太長就「…」,不會擠掉右邊。 - **卡片**:一整塊有標題、有欄位的內容(Bot 設定的「Bot 資料」「頭像」等)。**卡片裡不再放卡片**(以前「瀏覽器設定檔」裡的兩個選項各自是一張小卡;「更新」頁每一列都是一張卡)。 -- **欄位**:上面 13 px 灰色小標,下面輸入框。**說明**:13 px 灰字(以前 12 px 更淡的灰)。 +- **欄位**:上面 13 px 灰色小標,下面輸入框。**說明**:13 px 灰字、一行(長的滑過看全文;以前 12 px 更淡的灰、整段攤開)。設定列名稱旁的「?」只在滑鼠移到那一列時出現。 - **按鈕**:實心(一個畫面一顆主要動作)、淡底、紅色;刪除這種不能回頭的按兩次。 - 設定左邊的分頁:選中的是淡底加粗字(以前是一整顆黑色膠囊)。 - 測試看守:畫面程式裡自己畫的「底色+外框」卡片只准變少(`kit.rs` 以外)。 diff --git a/docs/feature-map/pages.md b/docs/feature-map/pages.md index 458981b..3a3ffb5 100644 --- a/docs/feature-map/pages.md +++ b/docs/feature-map/pages.md @@ -4,7 +4,8 @@ Bot 把要追蹤、整理、比較的事寫成一頁,之後一直更新同一 ## 子功能 -- 寫頁面:標題和整頁 Markdown(標題、表格、連結、Mermaid 圖),加上頁面區塊:```stats 數字卡(數字大字顯示;值和備註開頭是 ↑/+ 綠色、↓/−/- 紅色,+ − - 後面要緊接著字才算,單獨一個「-」是沒資料、不上色;電腦和手機同一條規則)、```steps 進度([x] 完成、[>] 進行中、[ ] 還沒到)、```chart 圖表(bar/line/pie,可以多系列;長條圖自動由大到小排序,月份/年份等自有順序的標籤不排;單系列把數字直接標在圖上不畫 y 軸;多條線在線尾標系列名;圖下附數據表;第一行可以是「圖型 標題」、只寫圖型(bar/line/pie 或 長條/折線/圓餅)或只寫標題,`#` 開頭是註解,`|---|` 分隔列略過,少填的格子當 0;手機也畫原生圖,讀法和樣式相同:照手機寬度畫、字不縮小,折線和多系列長條有 y 軸數字,只有一項的圓餅是整圓,圖例再多項都畫得到)、`> [!NOTE]`/`[!TIP]`/`[!WARNING]`/`[!IMPORTANT]` 提示框。 +- 寫頁面:標題和整頁 Markdown(標題、表格、連結、Mermaid 圖),加上頁面區塊:```details 標題(預設收起的一段 Markdown,「▸ 標題」點了才展開;放證據、長清單、指令,電腦和手機都是)、```stats 數字卡(數字大字顯示;值和備註開頭是 ↑/+ 綠色、↓/−/- 紅色,+ − - 後面要緊接著字才算,單獨一個「-」是沒資料、不上色;電腦和手機同一條規則)、```steps 進度([x] 完成、[>] 進行中、[ ] 還沒到)、```chart 圖表(bar/line/pie,可以多系列;長條圖自動由大到小排序,月份/年份等自有順序的標籤不排;單系列把數字直接標在圖上不畫 y 軸;多條線在線尾標系列名;圖下附數據表;第一行可以是「圖型 標題」、只寫圖型(bar/line/pie 或 長條/折線/圓餅)或只寫標題,`#` 開頭是註解,`|---|` 分隔列略過,少填的格子當 0;手機也畫原生圖,讀法和樣式相同:照手機寬度畫、字不縮小,折線和多系列長條有 y 軸數字,只有一項的圓餅是整圓,圖例再多項都畫得到)、`> [!NOTE]`/`[!TIP]`/`[!WARNING]`/`[!IMPORTANT]` 提示框。 +- 寫法檢查(Anthropic 的報告寫法):Bot 用 write_page 存頁面時先檢查——段落超過 120 字、一節超過一處粗體、括號裡一串數字、標題編號(一、二、1.)、分隔線、用「→」帶結論、表格裡放指令、正文超過 1800 字卻沒有 ```details——有就退回一次並列出要改的地方,同樣的標題第二次照存(不會卡住)。程式碼、```stats、```details 等區塊裡面不檢查。 - 種類(kind):data 數據分析、compare 比較評測、decision 決策備忘、howto 教學步驟、timeline 時間線、prose 長文、notes 筆記。種類決定第一屏:data 頁上面放 2–4 個 KPI 數字(kpis),compare/decision 頁先給一行「結論」(verdict)。沒給種類就是一般頁面。 - 更新:帶 id(或同一個標題)就換掉內容,上一版留著,最多留 10 版;note 寫這次改了什麼,頁面上顯示「這一版更新了:…」。內容一模一樣就不更新。 - 一直留著:跨聊天、跨例行任務都在。例行任務每一輪從新的開始,要接著上次做就先讀頁面。 diff --git a/docs/feature-map/settings.md b/docs/feature-map/settings.md index 9a10e07..bc1d556 100644 --- a/docs/feature-map/settings.md +++ b/docs/feature-map/settings.md @@ -6,7 +6,7 @@ 設定視窗,分頁由上到下: - 「一般」: - - 外觀:主題、底色(冷→暖滑桿)、對比(柔和→鮮明滑桿)、強調色(八個點:黏土、靛藍、苔綠、藍綠、玫紅、琥珀、石板、墨黑)、密度(寬鬆/緊湊)、慶祝動畫(開/關,目標達成時撒彩帶)、外殼顏色重設(回預設「紙」;這幾項調了立刻整個殼跟著換,不用重開)、聊天的顏色(你的訊息泡泡:安靜=淡灰,預設;跟著 Bot;只用黑色——手機同一個設定)、語言(選單和 Bot 回答用的語言)。沒有字型選項:介面思源黑體、讀的文字(回答、頁面)思源宋體。 + - 外觀:主題、強調色(八個點:黏土、靛藍、苔綠、藍綠、玫紅、琥珀、石板、墨黑)、聊天的顏色(你的訊息泡泡:安靜=淡灰,預設;跟著 Bot;只用黑色——手機同一個設定;只有點,選中的有外圈)、語言(選單和 Bot 回答用的語言),最後一列「更多外觀設定」按「展開」才出現:底色(冷→暖滑桿)、對比(柔和→鮮明滑桿)、密度(寬鬆/緊湊)、慶祝動畫(開/關,目標達成時撒彩帶)、外殼顏色重設(回預設「紙」)。這幾項調了立刻整個殼跟著換,不用重開。沒有字型選項:介面思源黑體、讀的文字(回答、頁面)思源宋體。設定列名稱旁的「?」平常不顯示,滑鼠移到那一列才出現;設定下面的說明只有一行,長的滑過看全文。 - 記憶與文件:用意思找記憶(本機模型/Ollama/關閉)、Bot 可以翻的資料夾([memory](memory.md))。 - 通知:Bot 做完或等你時通知、需要你時響一聲([phone](phone.md))。Mac 上的通知是 AnyBot.app 自己發的(貓的圖示),點一下打開那個 Bot;從建置資料夾直接跑(不是 .app)時改用系統的 display notification,圖示會是「工序指令編寫程式」。 - Bot:時區,例行任務和提醒用([routines](routines.md))。 diff --git a/mobile/index.html b/mobile/index.html index e8e2fbe..a9c8728 100644 --- a/mobile/index.html +++ b/mobile/index.html @@ -137,6 +137,9 @@ a{color:var(--accent-ink)} /* The chat takes its bot's colour (--bot, set when the chat opens; a black bot keeps the plain bubble). */ .m.user .bub{background-color:var(--bot,var(--bubble-user));color:var(--bot-ink,var(--bubble-user-ink));white-space:pre-wrap;border-radius:var(--r-l) var(--r-l) var(--r-s) var(--r-l)} .quiet .m.user .bub{background-color:var(--hover);color:var(--text)} +details.dt{margin:var(--sp-3) 0}details.dt>summary{font-size:var(--fs-small);color:var(--text2);cursor:pointer;list-style:none} +details.dt>summary::-webkit-details-marker{display:none}details.dt>summary::before{content:"▸ "}details.dt[open]>summary::before{content:"▾ "} +details.dt>.dt-in{padding-left:var(--sp-4);margin-top:var(--sp-2)} /* The bot's words sit on the page like a document; only an error gets a bubble. */ .m.bot .bub{background-color:transparent;padding:0;max-width:100%;border-radius:0;box-shadow:none;background-image:none} .m.bot.err .bub{color:var(--danger);background-color:var(--bubble-bot);padding:7px 12px;border-radius:var(--r-l);font-family:var(--font);font-size:var(--fs-ui);line-height:1.5} @@ -2903,6 +2906,8 @@ function pageMd(text, id, rev) { while (i < L.length && !L[i].trim().startsWith("```")) body.push(L[i++]); i++; if (lang === "mermaid" && id) { out.push(`
圖表載入中…
`); continue; } + // ```details : folded under one quiet line (細節 without a title); the inside is the page's Markdown. + if (lang === "details") { const title = t.replace(/^```\s*details/i, "").trim() || "細節"; out.push(`<details class="dt"><summary>${esc(title)}</summary><div class="dt-in">${pageMd(body.join("\n"), id, rev)}</div></details>`); continue; } if (lang === "chart") { const html = chartMd(body); if (html) { out.push(html); continue; } } if (lang === "stats") { const tiles = body.map(cells).filter((c) => c.length >= 2 && c[0]).map((c) => `<div class="stat"><div class="k">${inl(c[0])}</div><div class="v${trend(c[1])}${c[1].length > 10 ? " long" : ""}">${inl(c[1])}</div>${c[2] ? `<div class="s${trend(c[2])}">${inl(c[2])}</div>` : ""}</div>`); diff --git a/src/app.rs b/src/app.rs index 581e0bb..4623906 100644 --- a/src/app.rs +++ b/src/app.rs @@ -197,6 +197,8 @@ pub struct App { page_find: String, /// The open page's 目錄 is unfolded (a click on 「目錄 · N 節」, or ⌘F). page_toc_open: bool, + /// 設定 › 一般 › 外觀: the less used dials (底色、對比、密度、慶祝動畫、重設) unfolded. + appearance_more: bool, /// A heading the 目錄 asked to jump to (consumed by the frame that draws it). page_goto: Option<String>, /// Heading rects the Markdown renderer measured for the page it last drew (article mode), @@ -477,6 +479,7 @@ impl App { draft_changed: None, page_find: String::new(), page_toc_open: false, + appearance_more: false, page_goto: None, md_head_rects: Vec::new(), popup_hidden: Default::default(), @@ -5000,20 +5003,6 @@ impl App { theme_changed = true; } }); - card_row(ui, p, "底色", "", "整個殼的色溫:偏左藍灰、偏右米白。", |ui| { - let before = self.state.shell_tone; - ui.add(egui::Slider::new(&mut self.state.shell_tone, 0.0..=1.0).show_value(false).text(" ")); - if self.state.shell_tone != before { - self.dirty = true; - } - }); - card_row(ui, p, "對比", "", "拉高:分層、細線和文字階級更明顯。", |ui| { - let before = self.state.shell_contrast; - ui.add(egui::Slider::new(&mut self.state.shell_contrast, 0.75..=1.35).show_value(false).text(" ")); - if self.state.shell_contrast != before { - self.dirty = true; - } - }); card_row(ui, p, "強調色", "", "選中項、連結和新訊息點的顏色;圖表六色跟著它轉。", |ui| { let darkish = is_dark(self.pal); for (name, label, light, darkv) in crate::theme::ACCENTS { @@ -5029,26 +5018,6 @@ impl App { } } }); - card_row(ui, p, "密度", "", "緊湊:行距和按鈕縮一點,一屏看更多。", |ui| { - if let Some(v) = segmented(ui, p, self.state.dense, &[(false, "寬鬆"), (true, "緊湊")]) { - self.state.dense = v; - self.dirty = true; - } - }); - card_row(ui, p, "慶祝動畫", "", "工作完成時撒一下彩帶。", |ui| { - if let Some(v) = segmented(ui, p, self.state.celebrate, &[(true, "開"), (false, "關")]) { - self.state.celebrate = v; - self.dirty = true; - } - }); - card_row(ui, p, "外殼顏色重設", "", "底色、強調色、對比回到預設(紙)。", |ui| { - if ui.button(t("重設")).clicked() { - self.state.shell_tone = 1.0; - self.state.shell_accent = "clay".into(); - self.state.shell_contrast = 1.0; - self.dirty = true; - } - }); card_row(ui, p, "聊天的顏色", "", "安靜:你的訊息是淡灰的泡泡、字是一般的黑(像 Claude)。跟著 Bot:你的訊息、送出鈕和選中的 Bot 用那隻 Bot 的顏色。只用黑色:都是黑的。", |ui| { // Three dots (from the right): the bots' own colours, black, quiet. let name = |a: Accent| match a { @@ -5081,7 +5050,6 @@ impl App { self.dirty = true; } } - ui.label(RichText::new(t(name(self.state.accent))).size(FONT_SM).color(p.text2)); }); let other_menu = !matches!(crate::i18n::lang().as_str(), "zh-TW" | "zh-CN" | "en" | "ja"); card_row(ui, p, "語言", if other_menu { "選單用英文顯示,Bot 用你選的語言回答" } else { "" }, "AnyBot 的選單和 Bot 回答用的語言", |ui| { @@ -5103,6 +5071,49 @@ impl App { } }); }); + // The rest of the look, folded: most people never move these. + card_row(ui, p, "更多外觀設定", "", "", |ui| { + let open = self.appearance_more; + if ui.add(egui::Button::new(RichText::new(t(if open { "收起" } else { "展開" })).size(FONT_SM).color(p.text2)).frame(false)).clicked() { + self.appearance_more = !open; + } + }); + if self.appearance_more { + card_row(ui, p, "底色", "", "整個殼的色溫:偏左藍灰、偏右米白。", |ui| { + let before = self.state.shell_tone; + ui.add(egui::Slider::new(&mut self.state.shell_tone, 0.0..=1.0).show_value(false).text(" ")); + if self.state.shell_tone != before { + self.dirty = true; + } + }); + card_row(ui, p, "對比", "", "拉高:分層、細線和文字階級更明顯。", |ui| { + let before = self.state.shell_contrast; + ui.add(egui::Slider::new(&mut self.state.shell_contrast, 0.75..=1.35).show_value(false).text(" ")); + if self.state.shell_contrast != before { + self.dirty = true; + } + }); + card_row(ui, p, "密度", "", "緊湊:行距和按鈕縮一點,一屏看更多。", |ui| { + if let Some(v) = segmented(ui, p, self.state.dense, &[(false, "寬鬆"), (true, "緊湊")]) { + self.state.dense = v; + self.dirty = true; + } + }); + card_row(ui, p, "慶祝動畫", "", "工作完成時撒一下彩帶。", |ui| { + if let Some(v) = segmented(ui, p, self.state.celebrate, &[(true, "開"), (false, "關")]) { + self.state.celebrate = v; + self.dirty = true; + } + }); + card_row(ui, p, "外殼顏色重設", "", "底色、強調色、對比回到預設(紙)。", |ui| { + if ui.button(t("重設")).clicked() { + self.state.shell_tone = 1.0; + self.state.shell_accent = "clay".into(); + self.state.shell_contrast = 1.0; + self.dirty = true; + } + }); + } }); section(ui, "記憶與文件", p); rows_card(ui, p, |ui| { diff --git a/src/app/computers_ui.rs b/src/app/computers_ui.rs index 1a26471..425e776 100644 --- a/src/app/computers_ui.rs +++ b/src/app/computers_ui.rs @@ -480,10 +480,16 @@ impl App { } else { (crate::icons::Icon::Update, t("有新版的 Bot 的電腦可以更新"), true) }; + // Up to date is a plain grey line; only something to do (a new version) or to know + // before pressing (who would be stopped) gets a block. + let up_to_date = !update_ready; Frame::new().inner_margin(Margin { left: 14, right: 14, top: 0, bottom: 8 }).show(ui, |ui| { + if up_to_date { + crate::icons::label(ui, icon, &text, FONT_SM, p.text3); + return; + } let fill = if accent { p.accent.gamma_multiply(0.09) } else { p.hover }; - let stroke = if accent { Stroke::new(0.5, p.accent.gamma_multiply(0.6)) } else { Stroke::NONE }; - Frame::new().fill(fill).stroke(stroke).corner_radius(R_M).inner_margin(Margin { left: 12, right: 8, top: 8, bottom: 8 }).show(ui, |ui| { + Frame::new().fill(fill).corner_radius(R_M).inner_margin(Margin { left: 12, right: 8, top: 8, bottom: 8 }).show(ui, |ui| { ui.set_width(ui.available_width()); crate::icons::label(ui, icon, &text, FONT_SM, if accent { p.accent } else { p.text2 }); }); diff --git a/src/app/kit.rs b/src/app/kit.rs index 959f7b3..f3c4c7c 100644 --- a/src/app/kit.rs +++ b/src/app/kit.rs @@ -10,7 +10,8 @@ //! - **卡片** `setting_card` + `setting_title`:給一整塊有標題、有欄位的內容(Bot 設定的幾段)。 //! 卡片裡放列、欄位、文字——**不再放卡片**(卡中卡是畫面亂的主因)。 //! - **欄位** `field_label`(13 灰小標)+輸入框;**表單列** `form_row`(固定寬的標籤欄)。 -//! - **說明** `hint`:13 px 灰字,設定下面的一兩句話。`help_mark` 是名稱旁的「?」。 +//! - **說明** `hint`:13 px 灰字,**一行**(長的結尾「…」,滑過看全文)。`help_mark` 是名稱旁的「?」, +//! 設定列上的只在滑鼠移到那一列時出現。 //! - **按鈕** `primary_button`(實心,一個畫面一顆)、`secondary_button`(淡底)、`danger_button`; //! 刪除這種不能回頭的,用紅字無底按鈕並按兩次確認(由呼叫的地方做)。 //! - **分段選擇** `segmented`;**對話框底部** `dialog_footer`(左:影響內容本身的;右:完成)。 @@ -40,12 +41,22 @@ pub(super) fn section_with(ui: &mut egui::Ui, title: &str, p: Palette, accessory /// A small「?」after a setting's name. Its explanation shows as soon as the pointer is on it (no /// waiting for the pointer to be still), and a click keeps it open until the next click. pub(super) fn help_mark(ui: &mut egui::Ui, text: &str, p: Palette) { + help_mark_when(ui, text, p, true); +} + +/// The 「?」 of a settings row: drawn only while the pointer is on its row (`visible`) or its +/// note is pinned open — a page of rows doesn't show a page of question marks. Its place is +/// kept either way, so the name beside it never moves. +pub(super) fn help_mark_when(ui: &mut egui::Ui, text: &str, p: Palette, visible: bool) { if text.trim().is_empty() { return; } let (rect, r) = ui.allocate_exact_size(vec2(18.0, 18.0), egui::Sense::click()); let pinned_id = r.id.with("pinned"); let mut pinned = ui.ctx().data(|d| d.get_temp::<bool>(pinned_id)).unwrap_or(false); + if !visible && !pinned && !r.hovered() { + return; + } if r.clicked() { pinned = !pinned; } else if pinned && ui.input(|i| i.pointer.any_pressed()) && !r.hovered() { @@ -93,6 +104,7 @@ pub(super) fn card_row(ui: &mut egui::Ui, p: Palette, label: &str, sub: &str, he } let h = if sub.is_empty() { 52.0 } else { 62.0 }; let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), h), egui::Sense::hover()); + let row_hovered = ui.rect_contains_pointer(rect); // The control first, from the right edge; the words get the room that is left. let mut right = ui.new_child(egui::UiBuilder::new().max_rect(rect).layout(Layout::right_to_left(Align::Center))); right.spacing_mut().item_spacing.x = 8.0; @@ -102,14 +114,14 @@ pub(super) fn card_row(ui: &mut egui::Ui, p: Palette, label: &str, sub: &str, he let mut left = ui.new_child(egui::UiBuilder::new().max_rect(words).layout(Layout::left_to_right(Align::Center))); left.spacing_mut().item_spacing.x = 4.0; left.add(egui::Label::new(RichText::new(t(label)).size(FONT_BASE).color(p.text)).truncate()); - help_mark(&mut left, help, p); + help_mark_when(&mut left, help, p, row_hovered); } else { let mut left = ui.new_child(egui::UiBuilder::new().max_rect(words).layout(Layout::top_down(Align::Min))); left.spacing_mut().item_spacing = vec2(4.0, 1.0); left.add_space((h - 42.0) / 2.0); left.horizontal(|ui| { ui.add(egui::Label::new(RichText::new(t(label)).size(FONT_BASE).color(p.text)).truncate()); - help_mark(ui, help, p); + help_mark_when(ui, help, p, row_hovered); }); left.add(egui::Label::new(RichText::new(t(sub)).size(FONT_SM).color(p.text2)).truncate()); } @@ -148,7 +160,9 @@ pub(super) fn setting_title(ui: &mut egui::Ui, title: &str, desc: &str, p: Palet /// Small grey text under a setting. pub(super) fn hint(ui: &mut egui::Ui, text: impl Into<String>, p: Palette) { - ui.add(egui::Label::new(RichText::new(t(&text.into())).size(FONT_SM).color(p.text2)).wrap()); + // One line: a settings page is names and controls, not paragraphs. A longer note ends in + // 「…」 and shows whole under the pointer. + ui.add(egui::Label::new(RichText::new(t(&text.into())).size(FONT_SM).color(p.text2)).truncate()); } /// A rounded group of related settings, like a macOS settings card. diff --git a/src/app/markdown_ui.rs b/src/app/markdown_ui.rs index 34b2f1f..9da8e19 100644 --- a/src/app/markdown_ui.rs +++ b/src/app/markdown_ui.rs @@ -145,11 +145,16 @@ pub fn parse(text: &str) -> Vec<Block> { } Event::Start(Tag::CodeBlock(kind)) => { flush(&mut stack, &mut spans, None); - let lang = match kind { + let lang = match &kind { CodeBlockKind::Fenced(l) => l.split_whitespace().next().unwrap_or("").to_lowercase(), CodeBlockKind::Indented => String::new(), }; - code = Some((lang, String::new())); + // ```details <title>: the title rides as the block's first line (empty: none). + let first = match (&kind, lang.as_str()) { + (CodeBlockKind::Fenced(l), "details") => format!("{}\n", l.trim().split_once(char::is_whitespace).map(|(_, r)| r.trim()).unwrap_or("")), + _ => String::new(), + }; + code = Some((lang, first)); } Event::Start(Tag::BlockQuote(_)) => { flush(&mut stack, &mut spans, None); @@ -608,6 +613,7 @@ impl App { Block::Code { lang, text } if lang == "stats" && !crate::pages::stats(text).is_empty() => self.md_stats(ui, text), Block::Code { lang, text } if lang == "chart" && crate::pages::chart(text).is_some() => self.md_chart(ui, text), Block::Code { lang, text } if lang == "steps" && !crate::pages::steps(text).is_empty() => self.md_steps(ui, text), + Block::Code { lang, text } if lang == "details" => self.md_details(ui, text, col, streaming, depth), Block::Code { lang, text } => self.md_code(ui, lang, text, col), } } @@ -1056,6 +1062,35 @@ impl App { } /// `> [!WARNING] …`: a tinted box with a coloured edge and a small title. + /// ```details <title>: what a reader may want but needn't see — the evidence, the commands, + /// the long list — folded under one quiet line 「▸ title」 (「細節」 without one); a click + /// unfolds its Markdown. The first screen of a page stays its conclusions. + fn md_details(&mut self, ui: &mut egui::Ui, src: &str, col: Color32, streaming: bool, depth: usize) { + let p = self.pal; + let (title, inner) = src.split_once('\n').unwrap_or((src, "")); + let title = if title.trim().is_empty() { t("細節") } else { title.trim().to_string() }; + let id = ui.make_persistent_id(("details", key_of(src, false))); + let mut open = ui.data(|d| d.get_temp::<bool>(id)).unwrap_or(false); + let head = format!("{} {}", if open { "▾" } else { "▸" }, title); + let r = ui.add(egui::Label::new(RichText::new(head).size(FONT_SM).color(p.text2)).sense(egui::Sense::click())); + if r.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() { + open = !open; + ui.data_mut(|d| d.insert_temp(id, open)); + } + if open { + ui.add_space(crate::theme::sp::S2); + Frame::new().inner_margin(Margin { left: 16, right: 0, top: 0, bottom: 0 }).show(ui, |ui| { + ui.spacing_mut().item_spacing.y = 0.0; + for (i, b) in parse(inner).iter().enumerate() { + if i > 0 { + ui.add_space(crate::theme::sp::S3); + } + self.md_block(ui, b, col, streaming, depth + 1); + } + }); + } + } + fn md_callout(&mut self, ui: &mut egui::Ui, kind: &str, inner: &[Block], streaming: bool, depth: usize) { let p = self.pal; // A quiet block on the page's muted fill; only its small label carries the kind's colour @@ -1429,6 +1464,24 @@ mod tests { assert!(x["備註"].0 - a.1 < 60.0, "the numbers column isn't stretched: 3,500 ends {} and 備註 starts {}", a.1, x["備註"].0); } + /// ```details 標題: the title comes from the fence line, the inside is Markdown (folded until + /// clicked); with no title the block is 「細節」 and keeps all its lines. + #[test] + fn a_details_block_keeps_its_title_and_folds() { + let b = parse("```details 指令\n- git init\n- git push\n```"); + match &b[..] { + [Block::Code { lang, text }] => { + assert_eq!(lang, "details"); + assert_eq!(text.split_once('\n').map(|(t, _)| t), Some("指令")); + assert!(matches!(&parse(text.split_once('\n').unwrap().1)[..], [Block::List { .. }])); + } + other => panic!("{other:?}"), + } + let x = table_text_x("```details\n第一行就是內容\n```"); + assert!(x.keys().any(|k| k.contains("細節")), "folded under 「細節」: {x:?}"); + assert!(!x.keys().any(|k| k.contains("第一行就是內容")), "folded: {x:?}"); + } + #[test] fn number_cells_are_told_from_words() { for t in ["1,234", "12%", "−5%", "NT$300", "↑ 12", "3.5 萬", "2026", "$9.99"] { diff --git a/src/appctl.rs b/src/appctl.rs index 3373f35..741f9b3 100644 --- a/src/appctl.rs +++ b/src/appctl.rs @@ -250,6 +250,9 @@ pub struct Outcome { pub page: Option<u64>, } +/// Pages sent back once by the 寫法檢查 (bot, title): the next write of the same page is saved. +static SENT_BACK: std::sync::Mutex<std::collections::BTreeSet<(u64, String)>> = std::sync::Mutex::new(std::collections::BTreeSet::new()); + fn ok(text: String) -> Outcome { Outcome { text, ok: true, wake: vec![], theme_changed: false, page: None } } @@ -404,6 +407,20 @@ pub fn apply(state: &mut State, bot_id: u64, name: &str, args: &str) -> Outcome let who = state.bot(owner).map(|b| b.name.clone()).unwrap_or_else(|| "別的 Bot".into()); return err(format!("這是「{who}」的頁面,你只能讀不能改。要改請它改(ask_bot 或 message_bot 交代要改什麼),或不帶 id 做一頁你自己的。")); } + // 寫法檢查: a page that reads badly is sent back once with what to fix; the next try + // is saved whatever it still has (no loop when something can't be helped). + let key = (bot_id, v["title"].as_str().unwrap_or("").trim().to_string()); + let fixes = crate::pages::review(v["content"].as_str().unwrap_or("")); + { + let mut sent_back = SENT_BACK.lock().unwrap_or_else(|e| e.into_inner()); + if !fixes.is_empty() && sent_back.insert(key.clone()) { + return err(format!( + "頁面還沒存:照這幾點改寫後再呼叫一次 write_page(同樣的標題)——\n• {}\n改不掉的地方第二次會照樣存。", + fixes.join("\n• ") + )); + } + sent_back.remove(&key); + } match crate::pages::write(&mut state.pages, &mut state.next_page_id, bot_id, &v, crate::model::now_ms()) { Ok(w) => Outcome { text: w.text, ok: true, wake: vec![], theme_changed: false, page: Some(w.id) }, Err(e) => err(e), @@ -1075,6 +1092,23 @@ mod tests { assert!(!b.repair_interrupted(), "a second pass changes nothing"); } + /// 寫法檢查: a page that reads badly is sent back once, with each fix named; the second + /// write of the same page is saved, fixed or not (never a loop). A clean page goes straight in. + #[test] + fn a_hard_to_read_page_is_sent_back_once() { + let mut st = State::samples(); + let b = st.bots[0].id; + let messy = json!({"title": "改善計畫(測試)", "content": "## 一、證據\n332 個操作裡有 156 個是寫入(POST 83、PUT 28、DELETE 28)。"}).to_string(); + let first = apply(&mut st, b, "write_page", &messy); + assert!(!first.ok && first.text.contains("頁面還沒存") && first.text.contains("編號") && first.text.contains("一串數字"), "{}", first.text); + assert!(!st.pages.iter().any(|p| p.title == "改善計畫(測試)")); + let second = apply(&mut st, b, "write_page", &messy); + assert!(second.ok, "{}", second.text); + assert!(st.pages.iter().any(|p| p.title == "改善計畫(測試)")); + let clean = json!({"title": "安靜的一頁", "content": "## 現況\n還在審查。"}).to_string(); + assert!(apply(&mut st, b, "write_page", &clean).ok); + } + /// 共用資源: a colleague's page is read, never overwritten; a skill is taught (the person is /// asked first); what's about the person is kept once for every bot; a request can't go /// round the bots for ever. diff --git a/src/pages.rs b/src/pages.rs index 26f95b7..2687a38 100644 --- a/src/pages.rs +++ b/src/pages.rs @@ -77,7 +77,7 @@ fn one() -> u32 { pub fn specs() -> Vec<Value> { vec![ - json!({"name": "write_page", "description": "Make or update a page: a lasting, nicely laid-out document the person can open from the chat and that you keep up to date — a tracker (e.g. 「台灣 Tesla FSD 追蹤」), a report, a comparison, a plan, research notes. Use it whenever the person asks you to track, follow, summarise or compare something they will come back to; then link it in your reply as [標題](page:ID). With an id (or the same title) it replaces that page's content and keeps the old version. Write Markdown: headings, short paragraphs, lists, tables, links to sources, Mermaid charts (```mermaid: pie, xychart-beta bar/line, timeline, gantt, flowchart), and these page blocks:\n```stats\n狀態 | 審查中 | 第 1 步\n預計開放 | 2027 Q2 | 媒體推估\n```\n```steps\n[x] 道路測試計畫審查 | 7/9 月開過兩次會\n[>] 道路測試 | 等交通部核定\n[ ] 正式開放\n```\n```chart\nbar 標題(bar | line | pie 換圖型)\n1月 | 120\n2月 | 320\n```\n多系列:首行 `| 1月 | 2月`(第一格留空),每列 `名稱 | 120 | 320`。圖表用原生繪製(可縮放、hover 看數值,下方自動附數據表),優於 ```mermaid 的圖片。排版由渲染器接手:長條圖自動由大到小排序(月份/年份等自有順序的標籤不排);單系列把數字直接標在圖上、不畫 y 軸;多條線在線尾標系列名——你只要把圖標題寫成結論。\n> [!NOTE] / [!TIP] / [!WARNING] / [!IMPORTANT] call-outs.\n\n寫法(讀者是先掃一眼、要深才細讀的人,不是讀報告的人):\n• 選 kind(data 數據分析 / compare 比較評測 / decision 決策備忘 / howto 教學步驟 / timeline 時間線 / prose 純敘述 / notes 筆記),第一屏跟著它:data → 一句結論+kpis 三個真數字+主圖表;compare → 一句取捨+verdict+對比表;decision → 結論先行(verdict)+三條證據+風險;howto → 適合誰/成品+步驟(steps);timeline → 時間軸(mermaid timeline);prose/notes → 直接內文,不準硬湊 KPI 卡。\n• kpis 只放真資料算得出的數字(附 delta,如 +12%);湊不出三個就少放或不放。verdict 只在有明確結論時寫。\n• 每段不超過 4 行;連續段落不超過 3 段,中間改用列表/表格/圖。\n• 有數字就出 ```chart,圖標題直接寫結論並帶數字(如「Q3 營收創新高 42 萬」),軸標籤帶單位;細節數字放表格。\n• 每節先一句結論再給證據;來源放最後,帶連結與日期。更新時把整頁維持成現況(不是日誌),並在 `note` 寫出改了什麼。", + json!({"name": "write_page", "description": "Make or update a page: a lasting, nicely laid-out document the person can open from the chat and that you keep up to date — a tracker (e.g. 「台灣 Tesla FSD 追蹤」), a report, a comparison, a plan, research notes. Use it whenever the person asks you to track, follow, summarise or compare something they will come back to; then link it in your reply as [標題](page:ID). With an id (or the same title) it replaces that page's content and keeps the old version. Write Markdown: headings, short paragraphs, lists, tables, links to sources, Mermaid charts (```mermaid: pie, xychart-beta bar/line, timeline, gantt, flowchart), and these page blocks:\n```stats\n狀態 | 審查中 | 第 1 步\n預計開放 | 2027 Q2 | 媒體推估\n```\n```steps\n[x] 道路測試計畫審查 | 7/9 月開過兩次會\n[>] 道路測試 | 等交通部核定\n[ ] 正式開放\n```\n```chart\nbar 標題(bar | line | pie 換圖型)\n1月 | 120\n2月 | 320\n```\n```details 指令與原始數據\n(預設收起的 Markdown:證據、長清單、指令)\n```\n多系列:首行 `| 1月 | 2月`(第一格留空),每列 `名稱 | 120 | 320`。圖表用原生繪製(可縮放、hover 看數值,下方自動附數據表),優於 ```mermaid 的圖片。排版由渲染器接手:長條圖自動由大到小排序(月份/年份等自有順序的標籤不排);單系列把數字直接標在圖上、不畫 y 軸;多條線在線尾標系列名——你只要把圖標題寫成結論。\n> [!NOTE] / [!TIP] / [!WARNING] / [!IMPORTANT] call-outs.\n\n寫法(Anthropic 的報告寫法:讀者先掃一眼,需要才往下讀):\n• 選 kind(data 數據分析 / compare 比較評測 / decision 決策備忘 / howto 教學步驟 / timeline 時間線 / prose 純敘述 / notes 筆記),第一屏跟著它:data → 一句結論+kpis 三個真數字+主圖表;compare → 一句取捨+verdict+對比表;decision → verdict 先講+三個理由+風險;howto → 適合誰+steps;timeline → mermaid timeline;prose/notes → 直接內文,不硬湊 KPI 卡。kpis 只放算得出的真數字(附 delta 如 +12%),verdict 只在有明確結論時寫。\n• 每一節的標題就是結論(「240 環境是測試場」,不是「240 環境的現實」),下面第一句補一個理由,再最多三點清單。\n• 數字放 ```stats 或表格,不塞在句子和括號裡;有趨勢或比較就出 ```chart,圖標題寫結論並帶數字,軸標籤帶單位。\n• 粗體一節最多一處(或不用);不用「→」帶結論、不用分隔線(---)、標題不編號(一、二、1.)——標題本身就是分段。\n• 待辦寫成 ```steps 勾選清單;指令放程式碼區塊,不放進表格。\n• 證據、長清單、指令、原始數據放進 ```details 標題(預設收起);第一屏只留結論、數字和下一步。\n• 句子短、主動語氣、用讀者的話(說「通知」不說「webhook 設定」);不寫「值得注意的是」這類套話。\n• 來源放最後,帶連結與日期。更新時把整頁維持成現況(不是日誌),並在 `note` 寫出改了什麼。\n• 存檔時會自動檢查寫法:被退回就照列出的地方改,用同樣的標題再送一次。", "parameters": {"type": "object", "properties": { "title": {"type": "string", "description": "Short title, e.g. 台灣 Tesla FSD 追蹤"}, "content": {"type": "string", "description": "The whole page in Markdown (without the title)"}, @@ -401,6 +401,115 @@ pub fn stats(src: &str) -> Vec<(String, String, String)> { .collect() } +/// 寫法檢查 (Anthropic's way of writing a report: the conclusion first, short sentences, one +/// emphasis at most, numbers in tiles or tables, nothing decorative). What a page breaks, each +/// as a fix the bot can make; empty when the page reads well. Fenced blocks (code, ```stats, +/// ```details …) aren't checked — they are where long or dense things belong. +pub fn review(body: &str) -> Vec<String> { + let mut out: Vec<String> = vec![]; + let mut push = |s: String| { + if !out.contains(&s) { + out.push(s); + } + }; + let short = |s: &str| { + let t: String = s.chars().filter(|c| *c != '*').take(14).collect(); + if s.chars().count() > 14 { format!("{t}…") } else { t } + }; + let mut fenced = false; + let mut section = String::from("開頭"); + let mut bolds = 0usize; + let mut para = String::new(); + let mut prose_chars = 0usize; + let mut has_details = false; + let flush_para = |para: &mut String, push: &mut dyn FnMut(String)| { + let n = para.chars().filter(|c| *c != '*').count(); + if n > 120 { + push(format!("「{}」這段 {n} 字:先寫一句結論,其餘拆成清單,或放進 ```details", short(para))); + } + para.clear(); + }; + let flush_section = |section: &str, bolds: usize, push: &mut dyn FnMut(String)| { + if bolds > 1 { + push(format!("「{section}」這節有 {bolds} 處粗體:最多留一處,或都不用")); + } + }; + for raw in body.lines() { + let line = raw.trim(); + if line.starts_with("```") { + if !fenced && line.trim_start_matches('`').trim_start().starts_with("details") { + has_details = true; + } + fenced = !fenced; + flush_para(&mut para, &mut push); + continue; + } + if fenced { + continue; + } + if line.is_empty() { + flush_para(&mut para, &mut push); + continue; + } + if let Some(h) = line.strip_prefix('#') { + flush_para(&mut para, &mut push); + flush_section(§ion, bolds, &mut push); + let h = h.trim_start_matches('#').trim(); + section = h.chars().filter(|c| *c != '*').collect(); + bolds = 0; + let numbered = ["一、", "二、", "三、", "四、", "五、", "六、", "七、", "八、", "九、", "十、", "第一", "第二", "第三", "(1)", "(1)"].iter().any(|k| h.starts_with(k)) + || h.split_once(['.', '、', ')', ')']).is_some_and(|(n, _)| !n.is_empty() && n.chars().all(|c| c.is_ascii_digit())); + if numbered { + push(format!("標題「{}」不用編號(一、二、1. …):標題本身就是分段", short(h))); + } + continue; + } + if line.chars().all(|c| matches!(c, '-' | '*' | '_' | ' ')) && line.chars().filter(|c| !c.is_whitespace()).count() >= 3 { + push("不用分隔線(---):用標題分段就好".into()); + continue; + } + bolds += line.matches("**").count() / 2; + if line.starts_with('|') { + // A command in a table cell: `…` with a space inside. + let mut parts = line.split('`'); + parts.next(); + if parts.step_by(2).any(|code| code.trim().contains(' ')) { + push("表格裡放了指令:待辦用 ```steps 寫成清單,指令放程式碼區塊(或 ```details)".into()); + } + continue; + } + if line.starts_with('→') || line.starts_with("->") || line.starts_with("=>") { + push("結論不用「→」帶出來:寫在那一節的第一句".into()); + } + // (1, 2, 3)-style runs of numbers inside parentheses. + for open in ['(', '('] { + for seg in line.split(open).skip(1) { + let inner = seg.split([')', ')']).next().unwrap_or(""); + let numbers = inner.split(|c: char| !(c.is_ascii_digit() || c == '.' || c == ',')).filter(|w| w.chars().any(|c| c.is_ascii_digit())).count(); + if numbers >= 3 { + push(format!("「({})」括號裡一串數字:放進 ```stats 數字卡或表格", short(inner))); + } + } + } + let is_list = line.starts_with("- ") || line.starts_with("* ") || line.starts_with('>') || line.split_once(". ").is_some_and(|(n, _)| !n.is_empty() && n.chars().all(|c| c.is_ascii_digit())); + prose_chars += line.chars().count(); + if !is_list { + if !para.is_empty() { + para.push(' '); + } + para.push_str(line); + } else { + flush_para(&mut para, &mut push); + } + } + flush_para(&mut para, &mut push); + flush_section(§ion, bolds, &mut push); + if prose_chars > 1800 && !has_details { + push(format!("全頁正文 {prose_chars} 字:第一屏只留結論、數字和下一步,細節放進 ```details")); + } + out +} + /// A stats value's or note's direction: `Some(true)` up (↑, +), `Some(false)` down (↓, −, and /// the plain "-" bots usually type), `None` neither. A sign counts only when something follows /// it right away — a lone "-" is "no data", not a drop. (mobile/index.html `trend` is the same rule.) @@ -573,6 +682,26 @@ pub fn demo(now: i64) -> (Vec<Page>, u64, u64) { mod tests { use super::*; + /// 寫法檢查:使用者那頁「改善計畫」的毛病一個一個抓得到;照規矩寫的頁面一個都不報。 + #[test] + fn review_points_at_what_makes_a_page_hard_to_read() { + let messy = "## 一、證據(2026-11-14 實查)\n332 個操作裡有 **156 個是寫入/破壞性**(POST 83、PUT 28、DELETE 28、PATCH 17)。現在全在一組 **admin 帳密**後面。\n\n→ 這是測試場,不是生產場。\n\n---\n\n## 二、今天就收\n| # | 動作 |\n|---|---|\n| 1 | `cd ~/Documents/AnyMetal && git init` |\n"; + let found = review(messy); + let has = |k: &str| found.iter().any(|f| f.contains(k)); + assert!(has("編號"), "{found:?}"); + assert!(has("粗體"), "{found:?}"); + assert!(has("一串數字"), "{found:?}"); + assert!(has("→"), "{found:?}"); + assert!(has("分隔線"), "{found:?}"); + assert!(has("指令"), "{found:?}"); + let long = format!("## 現況\n{}", "交通部把它當輔助駕駛,走新技術駕駛系統審查,不用修法。".repeat(6)); + assert!(review(&long).iter().any(|f| f.contains("字")), "a long paragraph"); + let clean = "## 240 環境是測試場\n護欄要有能放大規模的目標才測得出來。\n\n```stats\n機器 | 375 台 | 362 台狀態不明\n韌體符合 | 33.6% | 110 台裡 73 台不合格\n```\n\n## 今天收尾\n```steps\n[ ] AnyMetal 加上版本控制\n[ ] facade 那 5 個檔案:提交或還原\n```\n\n```details 指令\n```\n\n| 檔案 | 狀態 |\n|---|---|\n| facade | 未提交 |\n"; + assert!(review(clean).is_empty(), "{:?}", review(clean)); + // Inside a fence (code, a details block) nothing is checked. + assert!(review("```\n→ (1, 2, 3) **a** **b**\n---\n```").is_empty()); + } + /// 數字卡的漲跌(桌面和手機同一套規則):箭頭、+、全形 −,還有 Bot 最常寫的一般「-」。 /// 單獨一個符號(「-」當作「沒有資料」)不算漲跌。 #[test]