diff --git a/FEATURES.md b/FEATURES.md index 6a923be..feb211d 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -1963,7 +1963,7 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) - 排程或事件自己跑的那幾次照執行紀錄:✓ 完成、✗ 失敗或中斷、■ 停止、圓點執行中。你按的「立即執行」「執行工作流」、請 Bot 跑的、試跑一步都不放(以前一按就出現在日曆上,像是排好的事);它們在執行紀錄裡。還沒到的照排程算出來(跟真的排程同一套算法),暫停的變灰帶 ‖。事件觸發的例行任務只看得到跑過的。週每筆是時間、Bot 的頭像和名稱;月每天最多三筆、多的「還有 N 個」,點那天換成日看法;日照時間一列列。 - 下面「即將執行」:每個例行任務、工作流各一行,寫它下一次什麼時候跑,照時間排、最多六行,帶頭像(以前一個每天跑的就把六行占滿)。 - 點任何一筆打開卡片:哪個 Bot、那次的時間和狀態、怎麼重複、最近一次怎麼樣、要它做什麼;「打開聊天」「立即執行」「暫停/繼續」(工作流:「打開工作流」「立即執行」)。 -- 「+ 新增例行任務」回到 Bot 的聊天,輸入框先放好「每天早上 9 點幫我」,接著用一般的話說要做什麼。手機還沒有日程。 +- 「+ 新增例行任務」回到 Bot 的聊天,輸入框先放好「每天早上 9 點幫我」,接著用一般的話說要做什麼。手機首頁上面一排有「日程」:最上面「即將執行」(每件一行,寫下次的日子和時間),接著三天前到七天後一天一組,每列時間、名字、Bot、怎麼重複,跑過的寫 ✓ 完成/✗ 失敗/停止了,暫停的變淡;打開捲到今天;點例行任務打開它的卡、點工作流打開那個工作流。大腦的路是 `api/act/schedule`(同一份 `schedule::items`/`coming`)。 ## 26. Bot 可以直接操作 App 的功能 diff --git a/docs/feature-map/schedule.md b/docs/feature-map/schedule.md index 15456ba..c691efe 100644 --- a/docs/feature-map/schedule.md +++ b/docs/feature-map/schedule.md @@ -10,10 +10,11 @@ - `schedule-card` 點任何一筆打開卡片:哪個 Bot、那一次的時間和狀態、怎麼重複、最近一次怎麼樣、要它做什麼;按鈕「打開聊天」「立即執行」「暫停/繼續」。工作流的是「打開工作流」「立即執行」(在螢幕電腦上按,交給大腦執行)。 - `schedule-new` 「+ 新增例行任務」:回到那個 Bot 的聊天,輸入框先放好「每天早上 9 點幫我」,接著說要做什麼;Bot 用 `create_routine` 設好,日程上就出現。 +- `schedule-phone` 手機的日程:最上面「即將執行」(每件一行:頭像、名字、怎麼重複、下次的日子和時間),接著三天前到七天後一天一組(「今天・11月22日(日)」,沒事的那天只有今天寫「這一天沒有排定的事」),每列時間、名字、Bot、怎麼重複,跑過的右邊 ✓ 完成/✗ 失敗/停止了,暫停的變淡;打開時捲到今天。點例行任務打開它的卡,點工作流打開那個工作流。手按的執行一樣不放。 ## 使用者怎麼到 - 側邊欄最左邊那一欄第三個(日曆圖示,滑過寫「日程」),在工作流和任務中間;再按一次、按那一欄的「聊天」、或左上「‹ 聊天」都回到聊天;在側邊欄點別的 Bot 也回到聊天。 -- 手機沒有日程:在聊天裡問 Bot「你有哪些例行任務」,它用 `list_routines` 回答(只有它自己的)。 +- 手機:首頁上面一排的「日程」(`schedule-phone`);或在聊天裡問 Bot「你有哪些例行任務」,它用 `list_routines` 回答(只有它自己的)。 ## 怎麼操作(verify-anybot) @@ -27,6 +28,7 @@ - **從側邊欄打開日程**(covers `schedule-views`、`schedule-entries`、`schedule-coming`):按側邊欄的日曆。指令:要開視窗——`ABV_ALLOW_WINDOW=1 $CTL desktop-shot schedule-open ANYBOT_SHOT_REAL=1 ANYBOT_SHOT_SIZE=1200x820 ANYBOT_SHOT_FRAMES=520 'ANYBOT_SHOT_CLICK=26,152@440'`。看到:「日程」,週看法這一週,今天那格強調色框、裡面沒有剛才立即執行的那次,之後每天 08:30 圓點「競品掃描」;工作日 09:00「晨間簡報」從週一起;右上沒有時區(跟這台一樣);下面「即將執行」競品掃描、晨間簡報各一行,照時間排、有 Bot 的頭像。 - **月和日**(covers `schedule-views`、`schedule-entries`):指令:要開視窗——`ABV_ALLOW_WINDOW=1 $CTL desktop-shot schedule-month ANYBOT_SHOT_REAL=1 ANYBOT_SHOT_VIEW=schedule ANYBOT_SHOT_TAB=month ANYBOT_SHOT_SIZE=1400x900 ANYBOT_SHOT_FRAMES=520 && ABV_ALLOW_WINDOW=1 $CTL desktop-shot schedule-day ANYBOT_SHOT_REAL=1 ANYBOT_SHOT_VIEW=schedule ANYBOT_SHOT_TAB=day ANYBOT_SHOT_SIZE=1400x900 ANYBOT_SHOT_FRAMES=520`。看到:月:週一到週日的格子,這個月以外的日期灰字,工作日的格子兩筆(08:30、09:00),今天之前沒跑過的日子是空的;日:今天寫「這一天沒有排定的事。」(立即執行的不放),下面照樣是即將執行。 - **卡片和暫停**(covers `schedule-card`、`schedule-coming`):按即將執行第一筆,再按卡片上的「暫停」。指令:要開視窗——`ABV_ALLOW_WINDOW=1 $CTL desktop-shot schedule-card ANYBOT_SHOT_REAL=1 ANYBOT_SHOT_VIEW=schedule ANYBOT_SHOT_SIZE=1400x900 ANYBOT_SHOT_FRAMES=560 'ANYBOT_SHOT_CLICK=700,439@530' && ABV_ALLOW_WINDOW=1 $CTL desktop-shot schedule-paused ANYBOT_SHOT_REAL=1 ANYBOT_SHOT_VIEW=schedule ANYBOT_SHOT_SIZE=1400x900 ANYBOT_SHOT_FRAMES=580 'ANYBOT_SHOT_CLICK=700,439@530;705,558@545' && $CTL state '[.bots[0].routines[] | {title, paused}]'`。看到:卡片「競品掃描」:驗證小幫手的頭像和名字、「明天 08:30(啟用中)」「每天 08:30」、最近一次完成、「找三則競品新聞」,按鈕「打開聊天、立即執行、暫停」;暫停後之後的競品掃描變灰帶 ‖,即將執行只剩晨間簡報;state 裡競品掃描 paused 是 true。 +- **手機的日程**(covers `schedule-phone`):先照 [workflow](workflow.md) 建好每天 09:00 的「Threads 早報」並在手機按過一次執行。指令:`$CTL phone click '#quick [data-q="schedule"]' && $CTL phone wait-text '即將執行' --in '#list' && $CTL phone shot schedule-phone && $CTL phone click '[data-sch^="workflow:1"]' && $CTL phone wait '.wf-steps'`。看到:即將執行「Threads 早報・明天 09:00」;今天「這一天沒有排定的事」(手機按的那次不在上面);明天起每天 09:00 一列;點了打開那個工作流。 - 自動測試:`cargo test schedule`、`cargo test layout_audit::`(「日程」週、月、日三景)。 ## 陷阱 diff --git a/mobile/index.html b/mobile/index.html index 681d3ba..d8d448a 100644 --- a/mobile/index.html +++ b/mobile/index.html @@ -580,6 +580,12 @@ textarea.field{min-height:96px;line-height:1.5} .tools .btn.once{background:color-mix(in srgb,var(--accent) 18%,transparent);color:var(--accent-ink)} .tools .btn.lock{background:var(--accent);color:var(--on-color)} .tools .btn.on{background:var(--primary);color:var(--on-primary)} +/* 日程: 即將執行, then a group a day — a row a time: when, what, how it went. */ +.item.sch .sch-t{width:44px;flex:none;font-size:var(--fs-small);color:var(--text2);font-variant-numeric:tabular-nums;display:flex;align-items:center} +.item.sch .av.sm{width:26px;height:26px}.item.sch .av.sm svg{width:26px;height:26px} +.item.sch .r{display:flex;align-items:center;gap:4px;font-size:var(--fs-caption);white-space:nowrap} +.item.sch .r.good{color:var(--ok)}.item.sch .r.bad{color:var(--danger)}.item.sch .r.go{color:var(--accent-ink)} +.item.sch.todo{opacity:.55} /* 工作流: a card each (run / stop at the right, the 等你確認 under it); one opened: its steps as a line from top to bottom, each with how this run (or the last) went there. */ .wf-card{padding:12px 16px;border-bottom:1px solid var(--line2);cursor:pointer} @@ -877,6 +883,7 @@ const LUCIDE = { "target": '', "alarm-clock": '', "sparkles": '', + "calendar": '', "list-checks": '', "camera": '', "paperclip": '', @@ -1581,6 +1588,7 @@ function renderHome() { const tn = taskAttention(); $("quick").innerHTML = owner() ? [ ``, + ``, ``, ``, ``, @@ -3299,7 +3307,7 @@ async function settingsChanged() { } let listTimer = null; function stopListTimer() { clearInterval(listTimer); listTimer = null; } -const TITLES = {tasks: "任務", workflows: "工作流", routines: "例行任務", pages: "頁面", computers: "電腦", settings: "設定", general: "一般", me: "個人資料與用量", models: "模型", perms: "權限", integrations: "整合", vault: "保險庫", account: "手機與帳號", updates: "更新"}; +const TITLES = {tasks: "任務", schedule: "日程", workflows: "工作流", routines: "例行任務", pages: "頁面", computers: "電腦", settings: "設定", general: "一般", me: "個人資料與用量", models: "模型", perms: "權限", integrations: "整合", vault: "保險庫", account: "手機與帳號", updates: "更新"}; async function renderList(arg) { const kind = arg.kind; $("list-title").textContent = TITLES[kind] || ""; @@ -3311,6 +3319,7 @@ async function renderList(arg) { if (kind === "pages") return listPages(el); if (kind === "me") return listMe(el); if (kind === "workflows") return listWorkflows(el, arg.wf); + if (kind === "schedule") return listSchedule(el); if (SETTINGS_PAGES.includes(kind)) { // (Drawn from what this phone has at once; read again behind it when it may be old.) if (!S.settings) { el.innerHTML = `
載入中…
`; await loadSettings(); } @@ -3321,6 +3330,56 @@ async function renderList(arg) { if (["computers", "integrations"].includes(kind)) listTimer = setInterval(async () => { await loadSettings(); if (cur().v === "list" && cur().arg.kind === kind) drawSettings(kind, true); }, 4000); } } +// ---------- 日程 ---------- +// What the bots are set to do, as on the computer's 日程: 即將執行 (each routine or workflow once, +// at its next time), then day by day from three days back to a week ahead — what ran on its own +// and how it went (✓ ✗ ■), what is coming, what is paused. (What you ran by hand is in each +// one's own runs, not here.) +const SCH_MARK = {done: ["good", "circle-check", "完成"], failed: ["bad", "circle-x", "失敗"], stopped: ["", "minus", "停止了"], running: ["go", "loader", "執行中"], coming: ["", "clock", ""], paused: ["todo", "pause", "暫停中"]}; +async function listSchedule(el) { + const here = () => cur().v === "list" && cur().arg.kind === "schedule"; + if (S.sched) drawSchedule(el); else el.innerHTML = `
載入中…
`; + const v = await act("schedule", {}, false); + if (!here() || !v) return; + S.sched = v; + drawSchedule(el); +} +function dayLabel(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()]; + return (diff === 0 ? "今天・" : diff === 1 ? "明天・" : diff === -1 ? "昨天・" : "") + `${m}月${dd}日(${wd})`; +} +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; + return ``; + }; + let h = group("即將執行", (v.coming || []).map((i) => row(i, true)).join("") || `
接下來兩週沒有排定的事
`); + const days = [...new Set(items.map((i) => i.day))]; + if (!days.includes(today)) days.push(today); + days.sort(); + 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 += `
只放排程或事件自己跑的;你按的「立即執行」在各自的執行紀錄裡。新增:在聊天裡跟 Bot 說「每天早上 9 點幫我…」。
`; + const sc = el.scrollTop; + el.innerHTML = h; + // (Today in view the first time; where you were after that.) + if (!S.schedShown) { S.schedShown = true; const t = [...el.querySelectorAll(".gt")].find((g) => g.textContent.startsWith("今天")); if (t) t.scrollIntoView({block: "start"}); } else el.scrollTop = sc; + el.querySelectorAll("[data-sch]").forEach((x) => x.onclick = async () => { + const [kind, id, bid] = x.dataset.sch.split(":"); + if (kind === "workflow") return go("list", {kind: "workflows", wf: +id}); + const b = bot(+bid); if (!b) return; + const d = S.detail[b.id] || await loadDetail(b.id) || {}; + const r = (d.routines || []).find((y) => y.id === +id); + if (r) routineSheet(b, r); else go("chat", {bot: b.id}); + }); +} // ---------- 工作流 ---------- // The workflows on the brain: what starts each, its steps in order, how its runs went — run it, // stop it, answer the 等你確認 a 審批 step waits on. (Drawing and editing are on the computer's diff --git a/src/app/remote_ui.rs b/src/app/remote_ui.rs index 5cc4855..8a89cb9 100644 --- a/src/app/remote_ui.rs +++ b/src/app/remote_ui.rs @@ -1506,7 +1506,7 @@ impl App { // model and computer, a new chat, regenerate) plus looking and small chat things; making, // changing or deleting bots, routines, memories, pages and settings stays the owner's. let admin_ok = match action { - "detail" | "settings" | "pages" | "search" | "export_bot" | "export_transcript" | "restart_bot" | "react" | "reply" | "resume" | "older" | "workflows" => true, + "detail" | "settings" | "pages" | "search" | "export_bot" | "export_transcript" | "restart_bot" | "react" | "reply" | "resume" | "older" | "workflows" | "schedule" => true, "bot" => b["key"].as_str() == Some("unread"), "box" => matches!(b["op"].as_str(), Some("wake" | "disk")), _ => false, @@ -1531,6 +1531,34 @@ impl App { // 工作流 on the phone: each one's steps in order, what starts it, how its runs went, and // the question it waits on — read here; run, stop, 繼續 and 停止 below. "workflows" => json!({"ok": true, "workflows": self.state.workflows.iter().map(|w| self.workflow_json(w)).collect::>()}), + // 日程 on the phone: three days back to a week ahead — what ran on its own and how it + // went, what is coming — and 即將執行 (each thing once, soonest first). + "schedule" => { + use crate::schedule::{self as sch, Status, What}; + let now = crate::routines::now(); + let tz = self.state.timezone.clone(); + let today = sch::day_of(now, &tz); + let from = sch::day_start(today - chrono::Duration::days(3), &tz); + let to = sch::day_start(today + chrono::Duration::days(7), &tz); + let one = |i: &sch::Item| { + let (kind, id) = match i.what { + What::Routine { id, .. } => ("routine", id), + What::Workflow { id } => ("workflow", id), + }; + let status = match i.status { + Status::Done => "done", + Status::Failed => "failed", + Status::Stopped => "stopped", + Status::Running => "running", + Status::Coming => "coming", + Status::Paused => "paused", + }; + json!({"at": i.at, "clock": sch::clock(i.at, &tz), "day": sch::day_of(i.at, &tz).to_string(), "title": i.title, "when": i.when, "bot": i.bot, "kind": kind, "id": id, "status": status}) + }; + let items: Vec = sch::items(&self.state, from, to, now).iter().take(400).map(one).collect(); + let coming: Vec = sch::coming(&self.state, now, 6).iter().map(one).collect(); + json!({"ok": true, "today": today.to_string(), "items": items, "coming": coming}) + } "workflow" => { let wf = b["wf"].as_u64().unwrap_or(0); let what = b["do"].as_str().unwrap_or(""); @@ -2818,6 +2846,22 @@ mod phone_act_tests { assert!(app.phone_act(&ctx, "workflow", &json!({"wf": 99, "do": "explode"}), "owner")["error"].is_string()); } + /// 日程 on the phone: the days around today and 即將執行, each thing once there. + #[test] + fn the_phone_reads_the_schedule() { + let (ctx, mut app) = demo(); + app.sched_demo(); + let v = app.phone_act(&ctx, "schedule", &json!({}), "admin"); + let items = v["items"].as_array().expect("items"); + assert!(!items.is_empty() && items.iter().all(|i| i["day"].as_str().is_some_and(|d| d.len() == 10) && i["clock"].as_str().is_some_and(|c| c.len() == 5)), "{v}"); + let coming: Vec<(String, u64)> = v["coming"].as_array().unwrap().iter().map(|i| (i["kind"].as_str().unwrap().to_string(), i["id"].as_u64().unwrap())).collect(); + let mut once = coming.clone(); + once.dedup(); + assert_eq!(coming.len(), once.len(), "即將執行 lists each thing once: {coming:?}"); + // (A team member never gets this far: the route refuses them.) + assert!(!crate::remote::role_allows("member", "POST", &["api", "act", "schedule"])); + } + #[test] fn web_client_search_export_import_and_pin_order() { let (ctx, mut app) = demo(); diff --git a/src/remote.rs b/src/remote.rs index d56c03d..c1cf458 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -1284,8 +1284,9 @@ pub(crate) fn lan_guard(action: &str, body: &Value, now: impl FnOnce() -> Value, // Looking; chats, pages and memories; bots made, imported (with no tools, grants, team or // running routines), deleted or restarted; models and keys; skills; signing in to ChatGPT; // signing a phone out; a workflow looked at, run, stopped or answered (its steps run with - // the bots' own settings, as when its schedule starts it) — none of these moves a guard. - "search" | "detail" | "settings" | "pages" | "export_bot" | "export_transcript" | "import_bot" | "section_move" | "memory" | "app" | "group_chat" | "delete_bot" | "restart_bot" | "react" | "reply" | "resume" | "clear" | "delete_page" | "provider" | "device_remove" | "skill" | "chatgpt" | "workflows" | "workflow" => Guard::Keeps, + // the bots' own settings, as when its schedule starts it); the 日程 — none of these + // moves a guard. + "search" | "detail" | "settings" | "pages" | "export_bot" | "export_transcript" | "import_bot" | "section_move" | "memory" | "app" | "group_chat" | "delete_bot" | "restart_bot" | "react" | "reply" | "resume" | "clear" | "delete_page" | "provider" | "device_remove" | "skill" | "chatgpt" | "workflows" | "workflow" | "schedule" => Guard::Keeps, // An action this list doesn't name is refused, not let through (import_bot slipped by // that way with a file's 「team」). A new one has to be put on one side or the other. _ => Guard::Unknown,