日程、工作流:第二次獨立審查(新開脈絡審 b4408cc)找到的問題修好——工作流的 6 個修正它逐條確認有效,日程的日期計算(時區、日光節約、週一開頭、月格、跨年)沒問題。
- P1:螢幕電腦上,日程卡片的「立即執行」會在螢幕自己身上開一次工作流執行,同步回大腦後那次永遠不會結束、之後的排程都被跳過。現在螢幕上工作流的卡片沒有「立即執行」(跟畫布一樣;例行任務的本來就轉給大腦)。 - 時間到了但 Bot 正忙的例行任務:以前從日程和即將執行消失,現在照原來的時間留著(圓點),即將執行排第一個。 - Bot 用工具刪掉正在跑的工作流:先停止那次(排在 Bot 後面的問題拿掉),跟選單的刪除一樣。 - 換畫布(日程卡片「打開工作流」、選單切換、刪除後換)時放掉上一個工作流的選取,不會在新的裡誤刪同編號的卡片。 - 「僅一次」跑過之後不再每秒存一次檔。 - 每小時的例行任務排滿月看法的六週(上限 200 → 1,100)。 - 還沒修(P2):等著交付的結果只在記憶體裡,Bot 那一輪結束前關掉 AnyBot 會不見。 已驗證: cargo test 860 過(新:日程測試加了「Bot 忙、時間過了還留著且即將執行第一」「每小時排滿六週」;工作流測試加了「工具刪除先停、排隊問題拿掉」「僅一次跑過後 tick 不存檔」);clippy 沒有新的。 未驗證: 螢幕電腦上的卡片(要一台登入同帳號的螢幕電腦);這幾條沒有再開 scratch 照步驟走(單元測試有走)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
This commit is contained in:
parent
b4408cce94
commit
069a9cfd1f
|
|
@ -5,9 +5,9 @@
|
|||
## 子功能
|
||||
|
||||
- `schedule-views` 看法:右上「日/週/月」,左上「‹ 今天 ›」往前往後、回到今天,旁邊寫「2026年11月」「11月16日 – 22日」「11月21日 星期六」;右上角寫「時間以 Asia/Taipei 為準」(你的時區)。週和月從週一開始,今天那格是強調色的框。
|
||||
- `schedule-entries` 每一筆:跑過的照它的執行紀錄(✓ 完成、✗ 失敗或中斷、■ 停止、圓點執行中),還沒到的照排程算出來(圓點;暫停的變灰、帶 ‖)。週:每天一欄,每筆是時間、Bot 的頭像,下面是名稱。月:每天最多三筆「時間 名稱」,多的寫「還有 N 個」;點那一天換成那天的日看法。日:照時間一列列,寫「名稱 · 時間 · 怎麼重複 · 啟用中/已暫停/完成」。事件觸發的例行任務沒有預定的時間,只看得到跑過的。一個每 5 分鐘跑的,一段期間最多列 200 次。
|
||||
- `schedule-entries` 每一筆:跑過的照它的執行紀錄(✓ 完成、✗ 失敗或中斷、■ 停止、圓點執行中),還沒到的照排程算出來(圓點;暫停的變灰、帶 ‖)。週:每天一欄,每筆是時間、Bot 的頭像,下面是名稱。月:每天最多三筆「時間 名稱」,多的寫「還有 N 個」;點那一天換成那天的日看法。日:照時間一列列,寫「名稱 · 時間 · 怎麼重複 · 啟用中/已暫停/完成」。事件觸發的例行任務沒有預定的時間,只看得到跑過的。時間到了但 Bot 正忙的,照原來的時間留著(圓點),等它空下來跑。每小時跑的排滿月看法的六週;每 5 分鐘跑的大約只列得下四天。
|
||||
- `schedule-coming` 即將執行:所有 Bot 接下來兩週內最先要跑的六筆(暫停的不算),每筆「名稱 · 明天 08:30 · 每天 08:30」和 Bot 的頭像;沒有時說怎麼設一個。
|
||||
- `schedule-card` 點任何一筆打開卡片:哪個 Bot、那一次的時間和狀態、怎麼重複、最近一次怎麼樣、要它做什麼;按鈕「打開聊天」「立即執行」「暫停/繼續」。工作流的是「打開工作流」「立即執行」。
|
||||
- `schedule-card` 點任何一筆打開卡片:哪個 Bot、那一次的時間和狀態、怎麼重複、最近一次怎麼樣、要它做什麼;按鈕「打開聊天」「立即執行」「暫停/繼續」。工作流的是「打開工作流」「立即執行」(螢幕電腦上沒有「立即執行」:工作流在大腦上跑)。
|
||||
- `schedule-new` 「+ 新增例行任務」:回到那個 Bot 的聊天,輸入框先放好「每天早上 9 點幫我」,接著說要做什麼;Bot 用 `create_routine` 設好,日程上就出現。
|
||||
|
||||
## 使用者怎麼到
|
||||
|
|
|
|||
|
|
@ -454,7 +454,9 @@ impl App {
|
|||
} else if ui.add(primary_button("打開聊天", p)).clicked() {
|
||||
act = Some("chat");
|
||||
}
|
||||
if ui.add(secondary_button("立即執行")).clicked() {
|
||||
// (A screen doesn't start a workflow itself: the brain runs them. A routine's
|
||||
// run is passed on to the brain.)
|
||||
if !(workflow.is_some() && self.mir.on) && ui.add(secondary_button("立即執行")).clicked() {
|
||||
act = Some("run");
|
||||
}
|
||||
if let Some(r) = &routine {
|
||||
|
|
@ -478,11 +480,14 @@ impl App {
|
|||
(What::Routine { bot, id }, "run" | "toggle") => self.routine_action(ctx, bot, Some((if a == "run" { "run" } else { "toggle" }, id))),
|
||||
(What::Workflow { id }, "open") => {
|
||||
self.sched.open = false;
|
||||
if self.wf.current != id {
|
||||
self.wf_let_go();
|
||||
}
|
||||
self.wf.current = id;
|
||||
self.wf.fitted = 0;
|
||||
self.wf_open();
|
||||
}
|
||||
(What::Workflow { id }, "run") => {
|
||||
(What::Workflow { id }, "run") if !self.mir.on => {
|
||||
self.wf_start(ctx, id, "手動");
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
|||
|
|
@ -286,6 +286,15 @@ impl App {
|
|||
let tz = self.state.timezone.clone();
|
||||
let showing = self.wf.open.then_some(self.wf.current);
|
||||
let who = crate::workflow::Who { me, bots: &bots, timezone: &tz };
|
||||
// (Deleting one that runs: its run stops first, as from the menu — a question still in
|
||||
// line for a bot comes out of the line.)
|
||||
if v["action"].as_str().is_some_and(|a| a.trim().eq_ignore_ascii_case("delete")) {
|
||||
if let Ok(id) = crate::workflow::target(&self.state.workflows, &v, showing) {
|
||||
if self.state.workflows.iter().any(|w| w.id == id && w.live_run().is_some()) {
|
||||
self.wf_stop(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
let (text, ok) = match crate::workflow::tool(&mut self.state.workflows, &who, &v, showing, crate::routines::now()) {
|
||||
Err(e) => (e, false),
|
||||
Ok(told) => {
|
||||
|
|
@ -309,6 +318,7 @@ impl App {
|
|||
}
|
||||
// Deleted: the canvas goes to another one (or back to the chat).
|
||||
if !self.state.workflows.iter().any(|w| w.id == id) && self.wf.current == id {
|
||||
self.wf_let_go();
|
||||
match self.state.workflows.first().map(|w| w.id) {
|
||||
Some(other) => self.wf.current = other,
|
||||
None => self.wf.open = false,
|
||||
|
|
@ -364,8 +374,12 @@ impl App {
|
|||
};
|
||||
match w.next_run {
|
||||
None => {
|
||||
w.next_run = crate::routines::next_run(&s, w.created_at, now);
|
||||
self.dirty = true;
|
||||
// (A 僅一次 that ran has no time left: nothing changes, nothing to save.)
|
||||
let next = crate::routines::next_run(&s, w.created_at, now);
|
||||
if next.is_some() {
|
||||
w.next_run = next;
|
||||
self.dirty = true;
|
||||
}
|
||||
}
|
||||
Some(t) if t <= now => {
|
||||
w.next_run = crate::routines::next_run(&s, w.created_at, now);
|
||||
|
|
@ -570,6 +584,21 @@ mod tests {
|
|||
assert!(!ok && text.contains("已經在跑了"), "{text}");
|
||||
let (_, ok) = call(&mut app, serde_json::json!({"action": "stop", "id": 2}));
|
||||
assert!(ok && app.state.workflows[1].runs.last().unwrap().state == RunState::Stopped);
|
||||
// Deleted while it runs: the run stops first — its question in line comes out.
|
||||
let (_, ok) = call(&mut app, serde_json::json!({"action": "run", "id": 2}));
|
||||
assert!(ok && app.waiting_wakes.iter().any(|(_, m)| m.text.contains("第 1/2 步")));
|
||||
let (text, ok) = call(&mut app, serde_json::json!({"action": "delete", "id": 2}));
|
||||
assert!(ok && text.contains("已刪除"), "{text}");
|
||||
assert!(!app.waiting_wakes.iter().any(|(_, m)| m.text.contains("第 1/2 步")), "the question went with it");
|
||||
// A 僅一次 that ran has no time left: the tick saves nothing.
|
||||
let (_, ok) = call(&mut app, serde_json::json!({"action": "create", "name": "一次", "schedule": {"frequency": "daily", "time": "09:00", "once": true}, "steps": [{"prompt": "x"}]}));
|
||||
assert!(ok);
|
||||
let w = app.state.workflows.last_mut().unwrap();
|
||||
w.created_at -= 3 * 86_400;
|
||||
w.next_run = None;
|
||||
app.dirty = false;
|
||||
app.tick_workflows(&ctx);
|
||||
assert!(!app.dirty && app.state.workflows.last().unwrap().next_run.is_none());
|
||||
}
|
||||
|
||||
/// Stopping a run whose question still waits in line for a busy bot takes the question out
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ impl App {
|
|||
|
||||
/// Another workflow on the canvas: nothing picked, typed, moved or drawn carries over (ids
|
||||
/// start from 1 in each one).
|
||||
fn wf_let_go(&mut self) {
|
||||
pub(super) fn wf_let_go(&mut self) {
|
||||
self.wf.selected = None;
|
||||
self.wf.selected_edge = None;
|
||||
self.wf.editing = None;
|
||||
|
|
@ -379,9 +379,11 @@ impl App {
|
|||
ui.painter().text(r.rect.right_center() - vec2(12.0, 0.0), egui::Align2::RIGHT_CENTER, format!("{n} {}", t("個步驟")), egui::FontId::proportional(FONT_XS), p.text3);
|
||||
if r.clicked() {
|
||||
self.wf_keep_version();
|
||||
if self.wf.current != id {
|
||||
self.wf_let_go();
|
||||
}
|
||||
self.wf.current = id;
|
||||
self.wf.fitted = 0;
|
||||
self.wf.selected = None;
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ pub struct Item {
|
|||
pub status: Status,
|
||||
}
|
||||
|
||||
/// At most this many times of one routine or workflow in one range (one every 5 minutes would
|
||||
/// fill a month).
|
||||
pub const MAX_PER_THING: usize = 200;
|
||||
/// At most this many times of one routine or workflow in one range: an hourly one fills the six
|
||||
/// weeks a month shows (1,008); one every 5 minutes fills about four days.
|
||||
pub const MAX_PER_THING: usize = 1_100;
|
||||
|
||||
/// Everything on the calendar from `from` up to `to` (seconds), oldest first: the runs that
|
||||
/// started then, and — from `now` on — the times still to come.
|
||||
|
|
@ -67,6 +67,11 @@ pub fn items(state: &State, from: i64, to: i64, now: i64) -> Vec<Item> {
|
|||
}
|
||||
if r.trigger.is_none() {
|
||||
let status = if r.paused { Status::Paused } else { Status::Coming };
|
||||
// (A time that came while its bot was busy: it runs once the bot is free — shown
|
||||
// at its time until then.)
|
||||
if let Some(due) = r.next_run.filter(|t| !r.paused && *t < now && *t >= from && *t < to) {
|
||||
out.push(Item { at: due, what, bot: b.id, title: r.title.clone(), when: when.clone(), status: Status::Coming });
|
||||
}
|
||||
for at in times(&r.schedule, r.created_at, from.max(now), to) {
|
||||
out.push(Item { at, what, bot: b.id, title: r.title.clone(), when: when.clone(), status });
|
||||
}
|
||||
|
|
@ -102,7 +107,8 @@ pub fn items(state: &State, from: i64, to: i64, now: i64) -> Vec<Item> {
|
|||
|
||||
/// The next few times coming, across everything (即將執行): paused ones left out.
|
||||
pub fn coming(state: &State, now: i64, n: usize) -> Vec<Item> {
|
||||
let mut out: Vec<Item> = items(state, now, now + 14 * 86_400, now).into_iter().filter(|i| i.status == Status::Coming).collect();
|
||||
// (From a day back: one whose time came while its bot was busy is still to run.)
|
||||
let mut out: Vec<Item> = items(state, now - 86_400, now + 14 * 86_400, now).into_iter().filter(|i| i.status == Status::Coming).collect();
|
||||
out.truncate(n);
|
||||
out
|
||||
}
|
||||
|
|
@ -214,8 +220,22 @@ mod tests {
|
|||
);
|
||||
assert!(next.iter().all(|i| i.status == Status::Coming && i.title != "週報"));
|
||||
assert!(next.windows(2).all(|w| w[0].at <= w[1].at));
|
||||
// A time that came while its bot was busy (next_run still before now): shown at its time
|
||||
// and first in 即將執行 until it runs.
|
||||
let due = now - 3 * 3600;
|
||||
st.bots[0].routines[1].next_run = Some(due);
|
||||
assert!(items(&st, from, to, now).iter().any(|i| i.title == "晨報" && i.at == due && i.status == Status::Coming));
|
||||
assert_eq!(coming(&st, now, 1)[0].at, due);
|
||||
st.bots[0].routines[1].next_run = None;
|
||||
// An hourly one fills the six weeks of a month.
|
||||
let six_weeks = from + 42 * 86_400;
|
||||
st.bots[0].routines.push(routine(6, "每小時", sched(serde_json::json!({"frequency": "hourly", "time": "00:15", "timezone": tz})), created));
|
||||
let hourly: Vec<i64> = items(&st, from, six_weeks, from).iter().filter(|i| i.title == "每小時").map(|i| i.at).collect();
|
||||
assert_eq!(hourly.len(), 42 * 24);
|
||||
assert!(*hourly.last().unwrap() > six_weeks - 3600);
|
||||
st.bots[0].routines.retain(|r| r.id != 6);
|
||||
// One every 5 minutes: capped.
|
||||
st.bots[0].routines.push(routine(5, "盯盤", sched(serde_json::json!({"frequency": "minutely", "interval": 5, "time": "00:00", "timezone": tz})), created));
|
||||
assert_eq!(items(&st, from, to, now).iter().filter(|i| i.title == "盯盤").count(), MAX_PER_THING);
|
||||
assert_eq!(items(&st, from, from + 42 * 86_400, now).iter().filter(|i| i.title == "盯盤").count(), MAX_PER_THING);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue