diff --git a/CHANGELOG.md b/CHANGELOG.md index adcee7a..6fb34ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased ### Added +- **`ext/agent` A2(过程可见)**: `plan` 过程事件默认写入返回 map 的 `events`(SSE 仍仅 `stream=True`);OKF 命中记 `REUSE` decision;view plan 卡渲染过程时间线。对齐 [agent-streaming.md](doc/roadmap/agent-streaming.md)。 - **`ext/agent` A1(OKF 复用飞轮)**: `agent_kb_list_tasks` 返回 description/aliases/status/llm_free/hits;`plan` 命中路径暴露 `match`/`score`(summary 含 match kind);soft_match 策展提示带 status/llm_free/description;view plan 卡显示 match。金样 `agent-kb-plan-hit`。路线 [ext-agent-optimize.md](doc/roadmap/ext-agent-optimize.md)。 - **`ext/web` 样式装配(`web_style` / `网页.样式装配`)**: 样式即数据表格 —— GFM 样式表(`|选择器|属性|值|`,可用 `|媒体|` 列分组进 `@media` 块)经 `样式装配` 函数转成 CSS 文本,再拼装成完整主题。替代"整段手写 CSS 字符串"的写法,贯彻 文档即代码。见 [marqdo-blog](examples/marqdo-blog/styles/theme.mq.md)。 - **网络能力调研(`doc/design/web-net-capabilities.md`)**: 盘点 `ext/web` + `plugins/web` + `lib/net` 现状,对照主流语言网络栈(FastAPI / Express / Flask / axum),给出「开发一个完整 Web 项目」所需能力的差距清单与分波次补强路线(W1–W7 + P3,**2026-08-28 已全部落地**)。 diff --git a/doc/roadmap/ext-agent-optimize.md b/doc/roadmap/ext-agent-optimize.md index 7359e94..7ace0c8 100644 --- a/doc/roadmap/ext-agent-optimize.md +++ b/doc/roadmap/ext-agent-optimize.md @@ -2,7 +2,7 @@ | | | |---|---| -| 状态 | **进行中 · A0/A1 完成**(A1:list_tasks 策展字段;plan hit 暴露 match/score;金样 `agent-kb-plan-hit`) | +| 状态 | **进行中 · A0–A2 完成**(A2:过程事件默认落盘;view plan 过程卡) | | 日期 | 2026-08-28 | | 调研 | [agent-frameworks-and-marqdo.md](../research/agent-frameworks-and-marqdo.md) | | 设计 | [ext-agent.md](../design/ext-agent.md) · [ext-agent-plan.md](../design/ext-agent-plan.md) · [ext-agent-parent.md](../design/ext-agent-parent.md) · [okf.md](../design/okf.md) | @@ -26,7 +26,7 @@ |------|------|----------| | **A0** | 工作簿补丁 / 固化可靠性 | **done** — 整文件 FIND 护栏;`soft` 仅 miss;decompose `n` 检查;`workbook_solidify` 单测;金样 `agent-workbook-patch-a0`(双 CONTINUE + solidify) | | **A1** | OKF 复用飞轮(lookup / near / soft_match UX) | **done** — `list_tasks` 含 description/aliases/status/llm_free/hits;`plan` 命中路径暴露 `match`/`score`;soft_match 策展行含 meta;view plan 卡显示 match;金样 `agent-kb-plan-hit`(exact hit + near soft-hit) | -| **A2** | 过程可见(stream + view 过程卡) | 对齐 [agent-streaming.md](agent-streaming.md);真相仍可写回 | +| **A2** | 过程可见(stream + view 过程卡) | **done** — `plan_append_*` / `plan_finish_stream` 始终写入 `events`(SSE 仍仅 `stream=True`);OKF REUSE 记 `decision`;view `plan-card` 渲染过程时间线(跳过 delta);金样断言 `events-ok`;对齐 [agent-streaming.md](agent-streaming.md) | | **A3** | 上下文预算(源码/Skill 渐进披露) | 长 runbook 不爆窗,仍保持「源码即提示」 | | **A4** | 可选:RAG/MCP 工具适配器 | 金样调用外置检索,权威仍是 `.mq.md` | diff --git a/ext/ai/agent.mq.md b/ext/ai/agent.mq.md index 8924a12..a907531 100644 --- a/ext/ai/agent.mq.md +++ b/ext/ai/agent.mq.md @@ -417,18 +417,18 @@ Truncate a tool result for `tool_end` events (~1KiB). + `result`=None + `stream`=False -Publish `tool_start` / `tool_end` when `stream=True`. +Always append `tool_start` / `tool_end` to `events` for audit / view process cards. SSE publish only when `stream=True`. +*ev = > json.parse text={}* +*ev = > json.set map=`ev` key="type" value=`type`* +*ev = > json.set map=`ev` key="name" value=`name`* +*ev = > json.set map=`ev` key="kind" value=`kind`* +1. `result` + *ev = > json.set map=`ev` key="result" value=`result`* +2. * + *_ = 1* +*events = > json.append list=`events` item=`ev`* 1. `stream` - *ev = > json.parse text={}* - *ev = > json.set map=`ev` key="type" value=`type`* - *ev = > json.set map=`ev` key="name" value=`name`* - *ev = > json.set map=`ev` key="kind" value=`kind`* - 1. `result` - *ev = > json.set map=`ev` key="result" value=`result`* - 2. * - *_ = 1* - *events = > json.append list=`events` item=`ev`* > sys.stream_publish event=`ev` 2. * *_ = 1* @@ -1221,23 +1221,23 @@ True when source still contains `worker.step` or `.单步`. + `stream`=False + `echo`=False -Append a `round` event when `stream=True`. Optional `result` is the child `# main` return (for view Child cards). Optional `echo` prints a short TTY marker (not the full workbook path). +Always append a `round` event (child workbook finished) for audit / view. Optional `result` is the child `# main` return. SSE + optional TTY `plan:round` only when `stream` / `echo`. +*ev = > json.parse text={"type":"round"}* +*ev = > json.set map=`ev` key="round" value=`round`* +*ev = > json.set map=`ev` key="workbook" value=`workbook`* +*ev = > json.set map=`ev` key="exit_code" value=`exit_code`* +1. `result` + *ev = > json.set map=`ev` key="result" value=`result`* +2. * + *_ = 1* +*events = > json.append list=`events` item=`ev`* 1. `stream` - *ev = > json.parse text={"type":"round"}* - *ev = > json.set map=`ev` key="round" value=`round`* - *ev = > json.set map=`ev` key="workbook" value=`workbook`* - *ev = > json.set map=`ev` key="exit_code" value=`exit_code`* - 1. `result` - *ev = > json.set map=`ev` key="result" value=`result`* - 2. * - *_ = 1* - *events = > json.append list=`events` item=`ev`* > sys.stream_publish event=`ev` - 1. `echo` - > print text=plan:round - 2. * - *_ = 1* +2. * + *_ = 1* +1. `echo` + > print text=plan:round 2. * *_ = 1* @@ -1249,14 +1249,16 @@ Append a `round` event when `stream=True`. Optional `result` is the child `# mai + `stream`=False + `summary`=None +Always append a `decision` event. SSE publish only when `stream=True`. + +*ev = > json.parse text={"type":"decision"}* +*ev = > json.set map=`ev` key="decision" value=`decision`* +1. `summary` + *ev = > json.set map=`ev` key="summary" value=`summary`* +2. * + *_ = 1* +*events = > json.append list=`events` item=`ev`* 1. `stream` - *ev = > json.parse text={"type":"decision"}* - *ev = > json.set map=`ev` key="decision" value=`decision`* - 1. `summary` - *ev = > json.set map=`ev` key="summary" value=`summary`* - 2. * - *_ = 1* - *events = > json.append list=`events` item=`ev`* > sys.stream_publish event=`ev` 2. * *_ = 1* @@ -1268,21 +1270,18 @@ Append a `round` event when `stream=True`. Optional `result` is the child `# mai + `from` + `stream`=False -Bubble parent `complete stream=True` reasoning/deltas (and errors) into the plan event list. Skip nested `done` so plan owns the final `done`. +Bubble parent `complete stream=True` reasoning/deltas (and errors) into the plan event list. Skip nested `done` so plan owns the final `done`. Always merge into `events` when present; `stream` reserved for callers that also SSE-publish upstream. -1. `stream` - - [`ev`](`from`) - *t = > json.get value=`ev` key="type"* - 1. `t` == delta - *events = > json.append list=`events` item=`ev`* - 2. `t` == reasoning - *events = > json.append list=`events` item=`ev`* - 3. `t` == error - *events = > json.append list=`events` item=`ev`* - 4. * - *_ = 1* -2. * - *_ = 1* +- [`ev`](`from`) + *t = > json.get value=`ev` key="type"* + 1. `t` == delta + *events = > json.append list=`events` item=`ev`* + 2. `t` == reasoning + *events = > json.append list=`events` item=`ev`* + 3. `t` == error + *events = > json.append list=`events` item=`ev`* + 4. * + *_ = 1* **events** @@ -1293,19 +1292,19 @@ Bubble parent `complete stream=True` reasoning/deltas (and errors) into the plan + `trace`=False + `result`=None -When `stream=True`, append `done` and attach `events` on the result map. Optional `trace=True` writes the event list to writeback slot `trace`. +Always append `done` and attach `events` on the result map (process audit even when not streaming). SSE publish of `done` only when `stream=True`. Optional `trace=True` writes the event list to writeback slot `trace`. -1. `stream` - *ev = > json.parse text={"type":"done"}* - 1. `result` - *ev = > json.set map=`ev` key="result" value=`result`* - 2. * - *_ = 1* - *events = > json.append list=`events` item=`ev`* - > sys.stream_publish event=`ev` - *out = > json.set map=`out` key="events" value=`events`* +*ev = > json.parse text={"type":"done"}* +1. `result` + *ev = > json.set map=`ev` key="result" value=`result`* 2. * *_ = 1* +*events = > json.append list=`events` item=`ev`* +1. `stream` + > sys.stream_publish event=`ev` +2. * + *_ = 1* +*out = > json.set map=`out` key="events" value=`events`* 1. `trace` *body = > json.stringify value=`events`* @@ -1462,7 +1461,7 @@ With `stream=True`, the model call uses SSE; `echo=True` prints delta text to st Multi-step with OKF agent-kb. Default workbook is `kb_dir/resources/.mq.md`. While task file count `< explore_n` and skill is not llm_free, force a new explore variant under `kb_dir/explore//`. Code-first: llm_free hits skip parent LLM. File children return via `# main`; `plan` exposes that as `result`. -Reuse lookup: exact → alias → canonicalize → optional local n-gram `near` when `near_match=True` and score ≥ `near_threshold`. Non-hit path: optional `soft_match=True` parent REUSE/NEW over ranked `agent_kb_near_match` candidates; else **decompose** before first child spawn (`DECISION: RUN` / `CONTINUE`+patch / solidified `DONE`). Then `await` → revise loop. With `stream=True`, emit parent `delta` / `decision` / `tool_start`/`tool_end` / `round` / `done` on `events`. `echo=True` prints `plan:decompose` / `plan:await` / deltas. `trace=True` writes events to writeback slot `trace`. Quiet child subtasks stay quiet. +Reuse lookup: exact → alias → canonicalize → optional local n-gram `near` when `near_match=True` and score ≥ `near_threshold`. Non-hit path: optional `soft_match=True` parent REUSE/NEW over ranked `agent_kb_near_match` candidates; else **decompose** before first child spawn (`DECISION: RUN` / `CONTINUE`+patch / solidified `DONE`). Then `await` → revise loop. Process events (`decision` / `round` / `done` / tools) are **always** attached on the result map for audit and view process cards; `stream=True` additionally SSE-publishes them (and parent `delta`). `echo=True` prints `plan:decompose` / `plan:await` / deltas. `trace=True` writes events to writeback slot `trace`. Quiet child subtasks stay quiet. *tools = > json.get value=`self` key="tools"* *cache = "miss"* @@ -1531,6 +1530,7 @@ Reuse lookup: exact → alias → canonicalize → optional local n-gram `near` *out = > json.set map=`out` key="summary" value=`sum`* *out = > json.set map=`out` key="observation" value=`last_obs`* *out = > json.set map=`out` key="result" value=`child_val`* + *events = > plan_append_decision events=`events` decision="REUSE" stream=`stream` summary=`sum`* *events = > plan_append_round events=`events` round=1 workbook=`path` exit_code=`code` result=`child_val` stream=`stream` echo=`echo`* 1. `writeback` *body = > json.stringify value=`out`* @@ -1587,6 +1587,7 @@ Reuse lookup: exact → alias → canonicalize → optional local n-gram `near` *out = > json.set map=`out` key="summary" value=`sum`* *out = > json.set map=`out` key="observation" value=`last_obs`* *out = > json.set map=`out` key="result" value=`child_val`* + *events = > plan_append_decision events=`events` decision="REUSE" stream=`stream` summary=`sum`* *events = > plan_append_round events=`events` round=1 workbook=`path` exit_code=`code` result=`child_val` stream=`stream` echo=`echo`* 1. `writeback` *body = > json.stringify value=`out`* @@ -1641,6 +1642,7 @@ Reuse lookup: exact → alias → canonicalize → optional local n-gram `near` *out = > json.set map=`out` key="workbook" value=`path`* *out = > json.set map=`out` key="rounds" value=1* *out = > json.set map=`out` key="cache" value="soft-hit"* + *out = > json.set map=`out` key="match" value="soft"* *sk = > json.get value=`hit` key="skill"* *out = > json.set map=`out` key="skill" value=`sk`* *st = > json.get value=`hit` key="status"* @@ -1649,6 +1651,7 @@ Reuse lookup: exact → alias → canonicalize → optional local n-gram `near` *out = > json.set map=`out` key="summary" value=`sum`* *out = > json.set map=`out` key="observation" value=`last_obs`* *out = > json.set map=`out` key="result" value=`child_val`* + *events = > plan_append_decision events=`events` decision="REUSE" stream=`stream` summary=`sum`* *events = > plan_append_round events=`events` round=1 workbook=`path` exit_code=`code` result=`child_val` stream=`stream` echo=`echo`* 1. `writeback` *body = > json.stringify value=`out`* diff --git a/src/view/html.rs b/src/view/html.rs index bd1b62b..f3c2613 100644 --- a/src/view/html.rs +++ b/src/view/html.rs @@ -760,6 +760,34 @@ section.block > h2 { font: 0.8rem/1.35 var(--mono); } .plan-card a { color: #1d4ed8; } +.plan-card .plan-process { + list-style: none; + margin: 0.45rem 0 0; + padding: 0; + border-top: 1px solid var(--line); +} +.plan-card .plan-process li { + display: flex; + flex-wrap: wrap; + gap: 0.35rem 0.65rem; + padding: 0.4rem 0; + border-bottom: 1px solid #eef2f7; + font: 0.8rem/1.35 var(--sans); + color: var(--ink); +} +.plan-card .plan-process li:last-child { border-bottom: none; } +.plan-card .plan-process .pp-type { + font: 0.72rem/1.2 var(--mono); + letter-spacing: 0.04em; + text-transform: uppercase; + color: #475569; + min-width: 4.5rem; +} +.plan-card .plan-process .pp-detail { + color: var(--muted); + font: 0.78rem/1.35 var(--mono); + word-break: break-word; +} .stream-panel { margin: 0 0 0.85rem; border: 1px solid var(--line); @@ -2290,7 +2318,7 @@ window.MARQDO_AUTO_STREAM = {auto_stream}; layout(rel, &nav, &main) } -/// Plan / agent result map → card with workbook link and cache/rounds. +/// Plan / agent result map → card with workbook link, cache/rounds, and process events. fn plan_result_card(stdout: &str, links: &LinkMode) -> String { let trimmed = stdout.trim(); if trimmed.is_empty() { @@ -2312,7 +2340,8 @@ fn plan_result_card(stdout: &str, links: &LinkMode) -> String { .and_then(|x| x.as_u64()) .or_else(|| v.get("round").and_then(|x| x.as_u64())); let status = v.get("status").and_then(|x| x.as_str()); - if workbook.is_none() && cache.is_none() && rounds.is_none() { + let events = v.get("events").and_then(|x| x.as_array()); + if workbook.is_none() && cache.is_none() && rounds.is_none() && events.is_none() { return String::new(); } let mut meta = Vec::new(); @@ -2341,13 +2370,88 @@ fn plan_result_card(stdout: &str, links: &LinkMode) -> String { } _ => String::new(), }; + let process = plan_process_list(events); format!( - r#"
Plan result
{}
{}
"#, + r#"
Plan result
{}
{}{}
"#, meta.join(" · "), - link + link, + process ) } +fn plan_process_list(events: Option<&Vec>) -> String { + let Some(events) = events else { + return String::new(); + }; + if events.is_empty() { + return String::new(); + } + let mut items = Vec::new(); + for ev in events { + let t = ev.get("type").and_then(|x| x.as_str()).unwrap_or("event"); + // Skip raw token deltas in the static card — live Stream panel owns those. + if matches!(t, "delta" | "reasoning") { + continue; + } + let detail = match t { + "decision" => { + let d = ev.get("decision").and_then(|x| x.as_str()).unwrap_or("?"); + let sum = ev.get("summary").and_then(|x| x.as_str()).unwrap_or(""); + if sum.is_empty() { + escape(d) + } else { + format!("{} — {}", escape(d), escape(sum)) + } + } + "round" => { + let mut bits = Vec::new(); + if let Some(r) = ev.get("round") { + bits.push(format!("round={r}")); + } + if let Some(wb) = ev.get("workbook").and_then(|x| x.as_str()) { + bits.push(format!("workbook={}", escape(wb))); + } + if let Some(c) = ev.get("exit_code") { + bits.push(format!("exit={c}")); + } + if let Some(res) = ev.get("result").and_then(|x| x.as_str()) { + let brief: String = res.chars().take(80).collect(); + bits.push(format!("result={}", escape(&brief))); + } + bits.join(" · ") + } + "tool_start" | "tool_end" => { + let name = ev.get("name").and_then(|x| x.as_str()).unwrap_or("?"); + let kind = ev.get("kind").and_then(|x| x.as_str()).unwrap_or(""); + if kind.is_empty() { + escape(name) + } else { + format!("{} ({})", escape(name), escape(kind)) + } + } + "done" => { + if let Some(res) = ev.get("result").and_then(|x| x.as_str()) { + let brief: String = res.chars().take(80).collect(); + escape(&brief) + } else { + String::new() + } + } + "error" => escape(ev.get("message").and_then(|x| x.as_str()).unwrap_or("error")), + _ => String::new(), + }; + items.push(format!( + r#"
  • {}{}
  • "#, + escape(t), + detail + )); + } + if items.is_empty() { + return String::new(); + } + format!(r#"
      {}
    "#, items.join("")) +} + fn urlencoding_path(s: &str) -> String { let mut out = String::new(); for b in s.as_bytes() { @@ -2378,3 +2482,21 @@ fn escape_js_string(s: &str) -> String { out.push('"'); out } + +#[cfg(test)] +mod plan_card_tests { + use super::{plan_result_card, LinkMode}; + + #[test] + fn plan_card_renders_process_events() { + let stdout = r#"{"status":"ok","cache":"hit","match":"exact","rounds":1,"workbook":"wb.mq.md","events":[{"type":"decision","decision":"REUSE","summary":"OKF hit"},{"type":"round","round":1,"workbook":"wb.mq.md","exit_code":0,"result":"pong"},{"type":"delta","text":"skip"},{"type":"done","result":"pong"}]}"#; + let html = plan_result_card(stdout, &LinkMode::Static { from: None }); + assert!(html.contains("plan-card"), "{html}"); + assert!(html.contains("cache=hit"), "{html}"); + assert!(html.contains("match=exact"), "{html}"); + assert!(html.contains("plan-process"), "{html}"); + assert!(html.contains("REUSE"), "{html}"); + assert!(html.contains("pp-type\">round"), "{html}"); + assert!(!html.contains("pp-type\">delta"), "{html}"); + } +} diff --git a/tests/ext/agent-kb-plan-hit.mq.md b/tests/ext/agent-kb-plan-hit.mq.md index 66e80d6..75955a1 100644 --- a/tests/ext/agent-kb-plan-hit.mq.md +++ b/tests/ext/agent-kb-plan-hit.mq.md @@ -30,6 +30,11 @@ import sys:lib/sys.mq.md *near_g = > json.get value=`paths` key="near"* *body = > json.get value=`paths` key="body"* +1. > fs.exists path=`kb` + > fs.remove path=`kb` +2. * + *_ = 1* + > fs.write_text path=`wb` text=`body` *prom = > agent_kb_promote kb_dir=`kb` goal=`goal` workbook=`wb`* @@ -78,6 +83,18 @@ import sys:lib/sys.mq.md 2. * > print text=sum-bad +*evs = > json.get value=`out` key="events"* +*en = > len value=`evs`* +1. `en` > 2 + > print text=events-ok +2. * + > print text=events-bad +*e0 = > at value=`evs` index=0* +*t0 = > json.get value=`e0` key="type"* +> print text=`t0` +*d0 = > json.get value=`e0` key="decision"* +> print text=`d0` + *out2 = > `助手`.plan goal=`near_g` max_rounds=2 writeback=False kb_dir=`kb` explore_n=0 promote=False* *cache2 = > json.get value=`out2` key="cache"* > print text=`cache2` diff --git a/tests/gold.rs b/tests/gold.rs index 1d51d78..195ce79 100644 --- a/tests/gold.rs +++ b/tests/gold.rs @@ -2740,7 +2740,7 @@ fn ext_agent_kb_plan_hit() { assert!(status.success(), "failed to build marqdo_plugin_agent"); assert_out( "tests/ext/agent-kb-plan-hit.mq.md", - "promoted\nlist-ok\nlist-free\nstable\nlist-desc\nhit\nexact\npong\nsum-exact\nsoft-hit\nnear\npong", + "promoted\nlist-ok\nlist-free\nstable\nlist-desc\nhit\nexact\npong\nsum-exact\nevents-ok\ndecision\nREUSE\nsoft-hit\nnear\npong", ); }