AnyBot/docs/restructure/notes/b02i-plan-goal.md

30 lines
5.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# b02i — 两个长任务模式:`plan.rs`(565) /plan + `goal.rs`(541) /goal
## plan.rs — 計畫模式(先读只做,拟好经使用者同意才动手)
- 常量:MAX_STEPS=20、MAX_TITLE_CHARS=160、MAX_TEXT_CHARS=1500、MAX_TASK_CHARS=4000、MANY_REVISIONS=5、UPDATE_TOOL=update_plan、SUBMIT_TOOL=submit_plan。
- Stage{Proposed{revised},Doing,Done,Abandoned};Plan{at,title,steps,stage,since,notes};current()/done()/unfinished();note 上限 20 条。
- 工具规格:submit_plan(steps 数组 title+detail,2..20)/update_plan({done|working|blocked|skipped|finished},title≤160);describe_plan。
- on_tool_result:Done→Event::Progress{plan_id,step,title,state};running_plan_for(since==head.at) 才记。
- **turn_starts**(起轮前,app.rs:3793):/plan 命令→on_command;若 bot.plan 是 Proposed/Doing→Some("計畫模式:只能 read_only 工具(看/問/列/查/想/列任務)+update_plan,做完一步 update_plan 報狀態;submit_plan 拟計畫给使用者批")(轮文约束)。
- **after_turn**(轮末):Proposed→Event::Card{plan_card}(按鈕開始照計畫做/…/先不要);Doing→未完一步的完成卡 Event::Card(開始下一步/先停/改成…;多未完步列 8 个标题);全做完→stage=Done+Event::Finished;有 change 反应→stage=Proposed+Event::Changed(使用者改了計畫:要重新 submit_plan)。
- **on_card**:開始照計畫做→stage=Doing+Event::Started;先不要/改成→Proposed+Event::Declined/Changed;下一步→下一个 unfinished 的 Event::PlanStep;先停→Event::Paused;做完→Event::Finished;同意卡超 MAX_STEPS→Event::TooBig。
- **on_step**(每步跑完):Doing 轮内 running_plan_for→update_plan 自动记:成功→finished;失败/拒→blocked(第 3 次连续失败→paused+Event::Stuck 卡)。
- **on_task**(新工作起轮):无 plan 且(/plan 开头 或 文字含 ≥2 个「、/,+ 做完|完成|然後|接著|之後|步驟|流程|順序|最後|全部|每|和」)→Event::Suggested(「用 /plan 先拟計畫」)。
- **on_wake**:「[計畫…」:照計畫做下一步:X」→next_step(标题)==X→Event::PlanStep;不符→Event::Stale;步已不在→Event::Stale;无 plan→Event::Stale。
- 反应词表:change=改/修改/重新拟/修訂/revised…;ok=同意/批准/開始/go/同意執行…;stop=先停/暫停/等一下/暫停/先不要/pause…
- card_words(使用者看的卡文)、started_words、note_of、status_words(1/5)、plan_of(回滚)。
- 测试锁 9 项:plan_mode_limits_a_running_turn_to_reading_and_reporting(turn_starts 文含 read_only/update_plan/submit_plan)、suggests_only_multi_step_words、submit_card_starts_only_when_agreed、starting_a_plan_runs_the_first_step、next_step_wakes_fire_once_and_only_in_order、wakes_belonging_to_a_rewritten_plan_are_stale、steps_report_themselves…等。
## goal.rs — 目标模式(condition 留在 bot,每轮末第二个模型判 met/not-yet/impossible)
- 常量:MAX_CONDITION_CHARS=4000、TURNS=20(轮上限→暂停)、IDLE_TURNS=3(连续没活动→停)、BRIEF_CHARS=24000(喂判官的 brief)、TEXT_CHARS=2500、ARGS_CHARS=300、RESULT_HEAD=400、RESULT_TAIL=1100。
- Goal{condition,at,turns,prompted,prompted_at,active,paused,reason,prompt};active 默认 true;TAG="[目標]";goal_id()=at。
- 命令:/goal 设定(同条件重复→不重置 turns,note;空→提示;超长→拒)、clear/stop 词群、status(中英);无参→提示;含 set 词(設定|设立|定一個目標|set a goal|…)才生效;条件可含空格。
- **judge(brief,now)**:第二个模型(无 tools、无图、system=JUDGE_SYSTEM 判官文、user=条件+brief)→Verdict{met,not_yet,impossible};JSON 解析(reason/verdict 双语,"met" 前缀容错);解析失败/调用失败→NotYet{reason:"檢查失敗…先當未達成",unparseable:true}(判官故障不能当停下来的理由)。
- **brief(turn,now)**:从轮头起(wake 轮找源头 head)、到下次 /goal 设定前;行格式:「使用者說:」/「Bot 說:」/「做了:tool args → 结果头400+尾1100」;工具结果截(head 400 tail 1100);跳过空 assistant、tool-only 轮;≤BRIEF_CHARS。
- **after_turn**(轮末):无 goal→false;active→turns+1;取 head→turn;brief;judge;met→清 goal+Event::Done{prompt};impossible→清+Event::Impossible;not_yet→reason 记、unparseable 不记;idle 检测(brief 最后活动 ms:连续 IDLE_TURNS 轮没动→paused);TURNS 上限→paused;轮文进 prompt(截 TEXT_CHARS,上限 2 次→Event::Prompted{prompt_id})。
- **wake_of**:「[目標]{condition}\n還沒達成:{reason}\n請接著做。」(goal 字段=condition);**continue_text**:使用者回话(active 恢复,goal_set 记)。
- 常量表+TAG 锁;测试锁:goal_survives_clearing_the_chat(clear 保留 goal 字段)、waking_text_carries_the_goal_so_the_next_turn_continues_it 等。
## 迁移笔记
plan/goal 进 core::modes(ui 依赖 app 事件流,留 app)。Event::Progress/Card/PlanStep/Finished/Changed/Started/Paused/Stuck/Declined/TooBig/Suggested→ui::events;Event::Done/Impossible/Prompted→ui::events。两模式状态各挂 Bot::plan/Bot::goal(model 拆出后归 core::agent::state)。