From 1fcc251b0abd120637af01e586e8e7ba7f5eda52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Sun, 22 Nov 2026 09:56:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=89=8B=E6=A9=9F=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E6=95=B4=E5=80=8B=E7=95=AB=E4=B8=8D=E5=87=BA=E4=BE=86=EF=BC=88?= =?UTF-8?q?=E6=97=A5=E7=A8=8B=E6=96=B0=E5=8A=A0=E7=9A=84=20dayLabel=20?= =?UTF-8?q?=E8=93=8B=E6=8E=89=E8=81=8A=E5=A4=A9=E7=9A=84=E5=90=8C=E5=90=8D?= =?UTF-8?q?=E5=87=BD=E5=BC=8F=EF=BC=89=EF=BC=9B=E5=8A=A0=E6=B8=AC=E8=A9=A6?= =?UTF-8?q?=E6=93=8B=E4=BD=8F=E6=89=8B=E6=A9=9F=E9=A0=81=E9=9D=A2=E9=87=8D?= =?UTF-8?q?=E8=A4=87=E7=9A=84=E5=90=8D=E5=AD=97=EF=BC=9B=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E8=A3=A1=E7=9A=84=E6=B5=81=E7=A8=8B=E5=9C=96=E7=95=AB=E6=88=90?= =?UTF-8?q?=E5=9C=96=EF=BC=9B=E6=89=8B=E6=A9=9F=E7=9A=84=E5=9C=96=E8=A1=A8?= =?UTF-8?q?=EF=BC=88SVG=EF=BC=89=E4=B8=8D=E5=86=8D=E7=A0=B4=E5=9C=96?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 嚴重:89fb6a5(手機日程)在 mobile/index.html 新加了 function dayLabel(d, today),跟聊天畫「今天/昨天」分隔線的 dayLabel(ms) 同名;同一個全域、後宣告的蓋掉前面,renderMsgs 一碰到有時間的訊息就丟例外,聊天只剩空白(之後幾輪的截圖沒抓到:看到的是本機先畫的那一則)。改名 schedDay。 - 防再犯:remote::tests::the_phone_page_names_each_thing_once 掃 mobile/index.html 頂層的 function/const/let,同一個名字只准一次(把 schedDay 改回 dayLabel 會失敗:declared more than once: ["dayLabel"])。 - 聊天的流程圖:新 POST api/diagram {src, dark}(用 diagram::svg,跟頁面的圖同一個畫法;空的或超過 2 萬字回 400;團隊成員也可以,只畫圖不讀任何東西);手機的 pageMd 遇到 ```mermaid(聊天裡 id 是 0)放一格,畫好換成圖,畫不出來顯示原始碼;renderMsgs 畫完有圖就叫 loadCharts。 - 圖表破圖:safeBlob 為了安全把 SVG 當成下載檔, 顯示不出來——頁面的圖原本就這樣。新 chartUrl:SVG 只做成 用的 SVG 圖片( 裡不跑任何程式),其他照 safeBlob。 已驗證: cargo test 883 個、relay 27 個全過;scratch 手機:打開聊天,7 則訊息、1 條「今天」分隔線都畫出來;Bot 回一張 ```mermaid,聊天裡出現 266×337 的圖(之前是破圖、再之前是整個聊天空白)。 未驗證: 頁面裡的圖在手機上(同一個 chartUrl,沒有另外建頁面看)。經帳號連的手機要 make update-server 才是新頁面——在那之前它用的是帳號伺服器上的舊頁面,沒有這個 bug(bug 只在這個分支)。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm --- FEATURES.md | 2 +- docs/feature-map/phone.md | 2 +- mobile/index.html | 26 ++++++++++++++++++++++---- src/remote.rs | 38 +++++++++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 2c01289..4195e70 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -2324,7 +2324,7 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) - 手機與帳號:直接連線的手機清單,可以登出別支手機; - 更新:版本和有沒有新版。 - 個人資料與用量:見「個人資料與用量」。 -- 手機補上的(以前只有電腦有):搜尋聊天裡的訊息和檔名;Bot 設定的「執行步驟用的模型」「思考模式」;釘選的 Bot 在 ⋯ ›「更多…」往前、往後移,分區的 ⋯「往上移/往下移」;「匯出 Bot 檔案(.anybot)」「匯出文字記錄(.md)」「匯入 Bot 檔案」(iPhone 跳分享選單,可以存到「檔案」或 AirDrop);每個 Bot 各自的草稿(切換 Bot、關掉頁面都留著,存在這支手機);程式碼塊右上的「複製」;頁面 ⋯ 的「存成檔案(.md)」。之後又補:設定 › 一般「電腦的外觀」(電腦的主題、聊天的顏色)和「其他時區…」自己打;Bot 設定技能「全選/全不選」、模型可讀長度 400K;稽核的「只看沒人看著時做的」;首頁上面一排「日程」「工作流」「檔案」(見各節)。再補:權限頁「一律放行」開關(跟 /always-approve 同一件事)和「智慧模式:卡片沒人回答時」幾秒後自己回答;聊天上方「一律放行開著」一條,擁有者可以「關閉」;一般「記憶與文件」(用意思找記憶、Bot 可以翻的資料夾);更新頁「你不在時自動更新」「園丁報告」;模型的服務網址、測試連線並取得模型清單、本機模型的看圖小幫手;設定 ›「語音」整頁;Bot 設定的備用模型、起始資料夾、自訂頭像顏色(手機自己的選色器)、語音(朗讀每個回答、聲音、速度、語言)。同一個網路直接連的手機照樣只能收緊:打開一律放行、縮短智慧模式等待、加資料夾、換起始資料夾、打開看圖小幫手都被擋,說明「請在電腦上改,或用帳號連線」。 +- 手機補上的(以前只有電腦有):搜尋聊天裡的訊息和檔名;Bot 設定的「執行步驟用的模型」「思考模式」;釘選的 Bot 在 ⋯ ›「更多…」往前、往後移,分區的 ⋯「往上移/往下移」;「匯出 Bot 檔案(.anybot)」「匯出文字記錄(.md)」「匯入 Bot 檔案」(iPhone 跳分享選單,可以存到「檔案」或 AirDrop);每個 Bot 各自的草稿(切換 Bot、關掉頁面都留著,存在這支手機);程式碼塊右上的「複製」;頁面 ⋯ 的「存成檔案(.md)」。之後又補:設定 › 一般「電腦的外觀」(電腦的主題、聊天的顏色)和「其他時區…」自己打;Bot 設定技能「全選/全不選」、模型可讀長度 400K;稽核的「只看沒人看著時做的」;首頁上面一排「日程」「工作流」「檔案」(見各節)。聊天裡的流程圖(```mermaid)由大腦畫成圖(`api/diagram`,跟頁面的圖同一個畫法),畫不出來時顯示原始碼;圖表的 SVG 只放在 裡顯示(以前被當成下載檔,頁面和聊天的圖都破圖)。再補:權限頁「一律放行」開關(跟 /always-approve 同一件事)和「智慧模式:卡片沒人回答時」幾秒後自己回答;聊天上方「一律放行開著」一條,擁有者可以「關閉」;一般「記憶與文件」(用意思找記憶、Bot 可以翻的資料夾);更新頁「你不在時自動更新」「園丁報告」;模型的服務網址、測試連線並取得模型清單、本機模型的看圖小幫手;設定 ›「語音」整頁;Bot 設定的備用模型、起始資料夾、自訂頭像顏色(手機自己的選色器)、語音(朗讀每個回答、聲音、速度、語言)。同一個網路直接連的手機照樣只能收緊:打開一律放行、縮短智慧模式等待、加資料夾、換起始資料夾、打開看圖小幫手都被擋,說明「請在電腦上改,或用帳號連線」。 - 看電腦畫面: - 「Bot 的電腦」每秒更新一次畫面;在休眠時按「叫醒」。 - 「這台 Mac」要先在設定裡打開才會出現。 diff --git a/docs/feature-map/phone.md b/docs/feature-map/phone.md index ff28a87..af2341a 100644 --- a/docs/feature-map/phone.md +++ b/docs/feature-map/phone.md @@ -4,7 +4,7 @@ ## 子功能 -- `phone-pages` 頁面:Bot 清單(分區、工作中/等你)、聊天(附檔、拍照、語音輸入、插話、停止;叫醒 Bot 的訊息上方標是什麼叫醒的;各 Bot 自己的草稿;程式碼塊的「複製」)、允許請求卡片(「一律允許」「允許一次」、「這輪都准」(智慧模式,一直開著;它是主按鈕)、「拒絕」、「全部允許,之後直接操作」;卡片太高時卡在內面自己捲,輸入框不會被頂出螢幕)、問題卡、「需要處理」與接管、Bot 設定、例行任務(詳細頁有最近幾次執行和送出證據)、頁面、記憶、檔案預覽、Bot 的電腦畫面、設定(一般、個人資料與用量、模型、權限、整合、電腦、保險庫、語音、手機與帳號、更新;開著的設定頁跟著電腦那邊的改變重讀,不用重新整理;直接連線只能收緊、不能放寬,見 [autonomy](autonomy.md))、傳送到其他裝置。智慧模式一直開著,輸入列沒有它的晶片。 +- `phone-pages` 頁面:Bot 清單(分區、工作中/等你)、聊天(附檔、拍照、語音輸入、插話、停止;叫醒 Bot 的訊息上方標是什麼叫醒的;各 Bot 自己的草稿;程式碼塊的「複製」;流程圖畫成圖)、允許請求卡片(「一律允許」「允許一次」、「這輪都准」(智慧模式,一直開著;它是主按鈕)、「拒絕」、「全部允許,之後直接操作」;卡片太高時卡在內面自己捲,輸入框不會被頂出螢幕)、問題卡、「需要處理」與接管、Bot 設定、例行任務(詳細頁有最近幾次執行和送出證據)、頁面、記憶、檔案預覽、Bot 的電腦畫面、設定(一般、個人資料與用量、模型、權限、整合、電腦、保險庫、語音、手機與帳號、更新;開著的設定頁跟著電腦那邊的改變重讀,不用重新整理;直接連線只能收緊、不能放寬,見 [autonomy](autonomy.md))、傳送到其他裝置。智慧模式一直開著,輸入列沒有它的晶片。 - `phone-cards` 手機上的卡(允許、需要處理、問題卡)只答它畫出來的那一張:那張已經在電腦或另一支手機上回答、被停止、或換成下一張時,按了不算,聊天裡寫「手機上的回答沒有用上…」;開了很久沒重新整理的舊頁面也一樣。螢幕電腦上的卡也是;比大腦舊的螢幕電腦答不了任何卡,要在那台 設定 › 更新 換新版(重新整理沒用)。支線的卡沒用上時,寫在主線的聊天。 - `phone-look` 長相(和電腦版同一份設計規格:字級、間距、圓角都是同一組數字):Bot 的回答不放在泡泡裡,像文件一樣直接排在畫面上,跟介面同一種字(iPhone 是 SF Pro 加蘋方)、16px、行距寬;裡面的表格只有橫向細線、數字欄靠右,提示框([!NOTE] 等)同一種淡底、只有圖示依種類上色,程式碼是淡底圓角塊。標題用半粗體。手機沒有字型選項。 - `phone-colors` 顏色跟電腦版一樣:電腦上 設定 › 一般 › 外觀 的主題(淺色/深色/跟隨系統)、底色、強調色、對比,手機照著穿;手機自己的「外觀」可以選「跟著電腦」(預設)、「跟著手機」、「淺色」、「深色」。狀態列的顏色跟著畫面。舊版的電腦沒送顏色時,手機用內建的「紙」。 diff --git a/mobile/index.html b/mobile/index.html index 8399570..0db45fb 100644 --- a/mobile/index.html +++ b/mobile/index.html @@ -2288,6 +2288,8 @@ function renderMsgs() { h += `
${x.text ? `
${esc(x.text)}
` : ""}${names}
${said}
`; }); $("msgs").innerHTML = h; + // (Diagrams in the answers: drawn by the brain once they are on the page.) + if ($("msgs").querySelector(".chart[data-mermaid]")) loadCharts(); renderSendBtn(); loadFiles(); seenWatch(); @@ -3465,7 +3467,7 @@ async function listSchedule(el) { S.sched = v; drawSchedule(el); } -function dayLabel(d, today) { +function schedDay(d, today) { const [y, m, dd] = d.split("-").map(Number), t = new Date(y, m - 1, dd), [ty, tm, td] = today.split("-").map(Number); const diff = Math.round((t - new Date(ty, tm - 1, td)) / 864e5); const wd = "日一二三四五六"[t.getDay()]; @@ -3475,7 +3477,7 @@ function drawSchedule(el) { const v = S.sched || {}, items = v.items || [], today = v.today || ""; const row = (i, showDay) => { const b = bot(i.bot) || {}, [cls, icon, word] = SCH_MARK[i.status] || ["", "clock", ""]; - const right = showDay ? (i.day === today ? "今天 " : dayLabel(i.day, today).replace(/(.)$/, "") + " ") + i.clock : word; + const right = showDay ? (i.day === today ? "今天 " : schedDay(i.day, today).replace(/(.)$/, "") + " ") + i.clock : word; return ``; }; let h = group("即將執行", (v.coming || []).map((i) => row(i, true)).join("") || `
接下來兩週沒有排定的事
`); @@ -3485,7 +3487,7 @@ function drawSchedule(el) { for (const d of days) { const list = items.filter((i) => i.day === d); if (!list.length && d !== today) continue; - h += group(dayLabel(d, today), list.map((i) => row(i, false)).join("") || `
這一天沒有排定的事
`); + h += group(schedDay(d, today), list.map((i) => row(i, false)).join("") || `
這一天沒有排定的事
`); } h += `
只放排程或事件自己跑的;你按的「立即執行」在各自的執行紀錄裡。新增:在聊天裡跟 Bot 說「每天早上 9 點幫我…」。
`; const sc = el.scrollTop; @@ -4233,13 +4235,27 @@ function saveFile(path, name, att, bot) { $("b-filesave").innerHTML = ic("download", 20); $("b-filesave").onclick = () => { if (S.file) saveFile(S.file.path, S.file.name, S.file.att, S.file.bot); }; const isDark = () => document.documentElement.dataset.theme === "dark" || (!document.documentElement.dataset.theme && matchMedia("(prefers-color-scheme: dark)").matches); +// A drawn chart as a picture: an SVG kept as an SVG image — only ever shown in an , where it +// runs nothing (safeBlob turns SVG into a download, so the picture showed broken). +async function chartUrl(r) { + if (/^image\/svg\+xml/i.test(r.headers.get("Content-Type") || "")) return URL.createObjectURL(new Blob([await r.text()], {type: "image/svg+xml"})); + return URL.createObjectURL(await safeBlob(r)); +} async function loadCharts() { + for (const el of document.querySelectorAll(".chart[data-mermaid]")) { + const src = el.dataset.mermaid; el.removeAttribute("data-mermaid"); + try { + const r = await api(base() + "api/diagram", {json: {src, dark: isDark()}, raw: true}); + if (!r.ok) throw new Error(); + el.innerHTML = `圖表`; + } catch (_) { el.innerHTML = `
${esc(src)}
`; } + } for (const el of document.querySelectorAll(".chart[data-src]")) { const src = el.dataset.src; el.removeAttribute("data-src"); try { const r = await api(base() + src + (src.includes("?") ? "&" : "?") + "dark=" + (isDark() ? 1 : 0), {raw: true}); if (!r.ok) throw new Error(); - el.innerHTML = `圖表`; + el.innerHTML = `圖表`; } catch (_) { el.innerHTML = `
這張圖畫不出來
`; } } } @@ -4509,6 +4525,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; } + // (A diagram in a chat: drawn by the brain from its words, as the computer draws it.) + if (lang === "mermaid") { 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; } } diff --git a/src/remote.rs b/src/remote.rs index 54ae730..13f18e0 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -776,6 +776,19 @@ pub fn handle(req: Req, via_relay: bool) -> Resp { out["latest"] = json!(cur.revision); Resp::json(&out) } + // A Mermaid diagram in a chat (a page's have their own path above): drawn here, the same + // way, from the words the phone holds (nothing else is read). + ("POST", ["api", "diagram"]) => { + let v = req.json(); + let src = v["src"].as_str().unwrap_or(""); + if src.trim().is_empty() || src.len() > 20_000 { + return Resp::error(400, "這張圖太大或是空的"); + } + match crate::diagram::svg(src, v["dark"].as_bool().unwrap_or(false)) { + Ok(svg) => Resp::bytes("image/svg+xml", svg.into_bytes()), + Err(e) => Resp::error(422, &e), + } + } ("GET", ["api", "pages", id, "chart", n]) => { let id: u64 = id.parse().unwrap_or(0); let n: usize = n.parse().unwrap_or(0); @@ -1364,7 +1377,7 @@ pub fn role_allows(role: &str, method: &str, path: &[&str]) -> bool { // 大腦: the owner's other AnyBots showing this one's bots. "mirror" => sync, "owner" | "admin" => !device && !sync, - "member" => matches!((method, path), ("GET", ["api", "state"]) | ("GET", ["api", "bots", _]) | ("GET", ["api", "pages", ..]) | ("GET", ["api", "file"]) | ("GET", ["api", "preview", ..]) | ("POST", ["api", "bots", _, "send" | "read" | "seen" | "upload"]) | ("POST", ["api", "voice", "transcribe" | "speech"])), + "member" => matches!((method, path), ("GET", ["api", "state"]) | ("GET", ["api", "bots", _]) | ("GET", ["api", "pages", ..]) | ("GET", ["api", "file"]) | ("GET", ["api", "preview", ..]) | ("POST", ["api", "bots", _, "send" | "read" | "seen" | "upload"]) | ("POST", ["api", "voice", "transcribe" | "speech"]) | ("POST", ["api", "diagram"])), _ => false, } } @@ -3620,6 +3633,29 @@ pub fn page(req: &Req) -> Resp { #[cfg(test)] mod tests { + /// The phone page is one file of plain scripts sharing one global scope: a function or a + /// top-level name declared twice silently replaces the first (a second `dayLabel`, for the + /// 日程, once replaced the chat's — every chat on the phone drew empty). Each name once. + #[test] + fn the_phone_page_names_each_thing_once() { + let mut seen: HashMap<String, usize> = HashMap::new(); + for line in PAGE.lines() { + let l = line.strip_prefix("async ").unwrap_or(line); + let name = if let Some(r) = l.strip_prefix("function ") { + r.split('(').next() + } else if let Some(r) = l.strip_prefix("const ").or_else(|| l.strip_prefix("let ")) { + r.split([' ', '=']).next() + } else { + None + }; + if let Some(n) = name.map(str::trim).filter(|n| !n.is_empty() && n.chars().all(|c| c.is_alphanumeric() || c == '_' || c == '$')) { + *seen.entry(n.to_string()).or_default() += 1; + } + } + let twice: Vec<&String> = seen.iter().filter(|(_, n)| **n > 1).map(|(k, _)| k).collect(); + assert!(twice.is_empty(), "declared more than once in mobile/index.html: {twice:?}"); + } + /// 虛擬觸控板 (mobile/trackpad.js): a tap clicks, one finger moves the pointer, two fingers /// scroll or right-click, double tap and slide drags, a long press right-clicks; the key /// bar's modifiers hold for one key or lock. Run in node when it is there (the gestures are