diff --git a/crates/dim-agent-capabilities/src/narrative.rs b/crates/dim-agent-capabilities/src/narrative.rs index 7909a0da5..eec9bf344 100644 --- a/crates/dim-agent-capabilities/src/narrative.rs +++ b/crates/dim-agent-capabilities/src/narrative.rs @@ -1501,10 +1501,15 @@ fn write_line(write: &LineWrite<'_>, working: bool, person: Person) -> String { } } -/// The first line of a block's body: after its opening tag and without its -/// closing tag, or of its text when it opens with no tag (§3.4). +/// The first line of a block's body (§3.4). fn body_line(text: &str) -> &str { - let body = match tag(text) { + body(text).lines().next().unwrap_or_default() +} + +/// A block's body: after its opening tag and without its own closing tag, or +/// its text when it opens with no tag (§3.4). +fn body(text: &str) -> &str { + match tag(text) { Some(head) => { let name = head.split(' ').next().unwrap_or_default(); let (_, rest) = text.split_once('>').unwrap_or_default(); @@ -1514,8 +1519,13 @@ fn body_line(text: &str) -> &str { .trim() } None => text, - }; - body.lines().next().unwrap_or_default() + } +} + +/// A block's body as one line: each run of whitespace, line breaks included, +/// becomes one space, and nothing else is added (§3.4). +fn flat_body(text: &str) -> String { + body(text).split_whitespace().collect::>().join(" ") } /// The value of one attribute of an opening tag, when it has one. @@ -1535,16 +1545,17 @@ fn tag(text: &str) -> Option<&str> { (!head.is_empty() && !head.starts_with('/')).then_some(head) } -/// An input with blocks only, told by its blocks and the first line of the -/// first block's body, or by its blocks alone when that body is empty (§3.4); -/// a turn it opens is titled the same (§3.6). +/// An input with blocks only, told by its blocks and the first block's body +/// as one line, or by its blocks alone when that body is empty (§3.4); a turn +/// it opens is titled the same (§3.6). fn blocks_line(blocks: &[InputBlock], live: &[bool]) -> String { let names = part(&blocks_name(blocks, live)); - match blocks.first() { - Some(InputBlock::Raw { text, .. }) if !body_line(text).is_empty() => { - format!("{names}: {}", part(body_line(text))) - } - _ => names, + let Some(InputBlock::Raw { text, .. }) = blocks.first() else { + return names; + }; + match flat_body(text) { + body if body.is_empty() => names, + body => format!("{names}: {}", part(&body)), } } diff --git a/crates/dim-agent-capabilities/tests/recall_flow.rs b/crates/dim-agent-capabilities/tests/recall_flow.rs index 5662693e0..26f1ed242 100644 --- a/crates/dim-agent-capabilities/tests/recall_flow.rs +++ b/crates/dim-agent-capabilities/tests/recall_flow.rs @@ -1903,7 +1903,7 @@ fn opening_a_call_shows_the_effects_it_declared() { // §3.4, §3.6: a block's body is what lies between its own opening and // closing tags; a tag inside the body stays, an empty body leaves the // blocks alone, and a block with no tag is told by its text. -fn a_blocks_line_keeps_its_body_and_drops_only_its_own_closing_tag() { +fn a_blocks_line_keeps_its_body_as_one_line_and_drops_only_its_own_closing_tag() { let mut recorded = Recorded::new(); recorded.at(10, 0); let mut turns = Vec::new(); @@ -1913,6 +1913,7 @@ fn a_blocks_line_keeps_its_body_and_drops_only_its_own_closing_tag() { "", "", "plain first line\nsecond line", + "\n 1 client attached:\n\n tui\tpid=4123 \r\n", ] .into_iter() .enumerate() @@ -1935,7 +1936,8 @@ fn a_blocks_line_keeps_its_body_and_drops_only_its_own_closing_tag() { "note: Close it with ", "note: ", "note", - "block: plain first line", + "block: plain first line second line", + "note: 1 client attached: tui pid=4123", ]) { assert_eq!( line_of(&index, started), diff --git a/crates/dim-app-server/tests/storage_flow/recall.rs b/crates/dim-app-server/tests/storage_flow/recall.rs index b7a9f6ad2..a70dc42e6 100644 --- a/crates/dim-app-server/tests/storage_flow/recall.rs +++ b/crates/dim-app-server/tests/storage_flow/recall.rs @@ -191,7 +191,7 @@ async fn sqlite_recall_verifies_indexed_candidates_and_fallbacks_against_the_sam " turn: note: Ready — ", " turn: note: — ", " turn: note — ", - " turn: block: plain first line — ", + " turn: block: plain first line second line — ", ] { assert!(index.contains(title), "{title} in {index}"); } diff --git a/crates/dim-app-server/tests/transport_flow/collaboration.rs b/crates/dim-app-server/tests/transport_flow/collaboration.rs index 09f67ca4a..6f81f21fa 100644 --- a/crates/dim-app-server/tests/transport_flow/collaboration.rs +++ b/crates/dim-app-server/tests/transport_flow/collaboration.rs @@ -3623,8 +3623,10 @@ async fn member_work(mut config: ServerConfig) { "the latest turns come first and name their calls: {turns}" ); assert!( - turns.contains(": Agent default, your team leader, assigned you this work: — called hold"), - "a turn a message opened is titled by its first line: {turns}" + turns.contains( + ": Agent default, your team leader, assigned you this work: tool:hold {} — called hold" + ), + "a turn a message opened is titled by its body as one line: {turns}" ); assert!( turns diff --git a/docs/design/plugins/Recall.md b/docs/design/plugins/Recall.md index 92df55376..84964625e 100644 --- a/docs/design/plugins/Recall.md +++ b/docs/design/plugins/Recall.md @@ -236,7 +236,7 @@ context is the origin of, or joined to, a thing (§14). | Thing | Line | | --- | --- | -| Input | with user content: `user: ` (images as `[image]`), followed by `+ ` when it also carries blocks; with blocks only: `: `, or `` alone when that body is empty. A block's body is the text between its opening tag and its own closing tag, so a tag inside the body stays; a block whose text opens with no tag has that text as its body. `` names each block in order by its opening tag and attributes as written, or `block` for a block whose text opens with no tag, with `(current)` for a live block and `(ended)` for one that retires its `key` | +| Input | with user content: `user: ` (images as `[image]`), followed by `+ ` when it also carries blocks; with blocks only: `: `, or `` alone when that body is empty. A block's body is the text between its opening tag and its own closing tag, so a tag inside the body stays; a block whose text opens with no tag has that text as its body. The body reads as one line: each run of whitespace in it, line breaks included, becomes one space, and nothing else is added, so a body whose first line only leads into the rest still says what follows. `` names each block in order by its opening tag and attributes as written, or `block` for a block whose text opens with no tag, with `(current)` for a live block and `(ended)` for one that retires its `key` | | Your reply | `you: `, thinking left out; an output that did not complete is `your reply was cut off (): `, with the committed text and the outcome of its `step/model-output-end`; an output the head ends inside is `you (still writing): ` | | Tool call | `you called → `; a call whose arguments never arrived is `you started calling (arguments not received) → ` | | Interrupt | `the user interrupted the turn` | @@ -292,7 +292,8 @@ context)` or `(ended)` where it applies, paged by characters like any thing. **The input brief** is generic, for every tool alike: the scalar fields of `input` as `key=value`, nested values as `{…}`. Opening the call shows the full input. -**Every line has a fixed maximum length.** A line is one line: a quoted text is its first line. +**Every line has a fixed maximum length.** A line is one line: a quoted text is its first line, +except a block's body, which reads as one line with its whitespace joined (§3.4). Each variable part of a line is cut at 120 characters with `…`: a quoted text (user text, a reply, a block's body, a result), the input brief as a whole, ``, a tool name, a turn's tool summary, a reason, a task id, an agent name, a mode or a parent line. No line has more than four @@ -335,7 +336,7 @@ The inputs that open a turn are the ones it consumed before its first model requ later, such as a steer while it works, does not open it. The line gives the first user text among the opening inputs; when none of them carries user text (a Goal continuation, a message from another line), the first of them that carries a line write (§3.4), or else the driving input as its line -reads, `: `: the first opening input that is not Append, since an Append input joins the request +reads, `: `: the first opening input that is not Append, since an Append input joins the request but does not open the turn. A turn with no opening input has none of these: its line reads `turn: no opening input`. diff --git a/docs/zh/design/plugins/Recall.md b/docs/zh/design/plugins/Recall.md index 44a081fb3..68c6dc9a5 100644 --- a/docs/zh/design/plugins/Recall.md +++ b/docs/zh/design/plugins/Recall.md @@ -86,7 +86,7 @@ Recall 就像客户端里的会话视图,只是讲给模型而不是展示给 | 事 | 行 | | --- | --- | -| 输入 | 有用户内容时:`user: <文本>`(图片为 `[image]`),同时带块时后接 `+ `;只有块时:`: <第一个块正文的第一行>`,正文为空时只有 ``。块的正文是它的开头标签与它自己的结束标签之间的文本,所以正文里的标签保留;文本不以标签开头的块,正文就是它的文本。`` 按顺序列出每个块的开头标签和属性(照写),文本不以标签开头的块写作 `block`;生效中的块加 `(current)`,让其 `key` 失效的块加 `(ended)` | +| 输入 | 有用户内容时:`user: <文本>`(图片为 `[image]`),同时带块时后接 `+ `;只有块时:`: <第一个块的正文,压成一行>`,正文为空时只有 ``。块的正文是它的开头标签与它自己的结束标签之间的文本,所以正文里的标签保留;文本不以标签开头的块,正文就是它的文本。正文压成一行:其中每一段连续空白(包括换行)变成一个空格,不加任何别的字,所以第一行只是引子的正文,行里仍能看到后面的内容。`` 按顺序列出每个块的开头标签和属性(照写),文本不以标签开头的块写作 `block`;生效中的块加 `(current)`,让其 `key` 失效的块加 `(ended)` | | 你的回复 | `you: <文本>`,省略 thinking;未完成的输出为 `your reply was cut off (<原因>): <部分文本>`,带已提交的文本和其 `step/model-output-end` 的结果;head 停在其中的输出为 `you (still writing): <目前的文本>` | | 工具调用 | `you called <参数简述> → <结局>`;参数从未到达的调用为 `you started calling (arguments not received) → <结局>` | | 中断 | `the user interrupted the turn` | @@ -126,7 +126,7 @@ Recall 按块文本的开头标签与属性,以及 `InputBlock::Raw` 的 `key` **参数简述**对所有工具通用:`input` 的标量字段写作 `key=value`,嵌套的值显示为 `{…}`。展开这次调用时给出完整参数。 -**每行都有固定的最大长度。** 一行就是一行:引用的文本取其第一行。行中每个可变部分超过 120 个字符时截断并加 `…`:引用的文本(用户文本、回复、块的正文、结果)、整个参数简述、``、工具名、一轮的工具汇总、原因、任务 id、agent 名、模式或父行。一行最多有四个可变部分(最多的是工具调用:工具名、参数简述、任务和结果文本),其时间、id 和固定文字最多占 120 个字符,所以**一行绝不超过 600 个字符**。因此一页 20 个条目,连同日期行和最后一行,不超过 13,000 个字符。每个部分的全文都可用 `open` 展开。这是行格式,不是可调的限制。 +**每行都有固定的最大长度。** 一行就是一行:引用的文本取其第一行,块的正文除外,它的空白合并后压成一行(§3.4)。行中每个可变部分超过 120 个字符时截断并加 `…`:引用的文本(用户文本、回复、块的正文、结果)、整个参数简述、``、工具名、一轮的工具汇总、原因、任务 id、agent 名、模式或父行。一行最多有四个可变部分(最多的是工具调用:工具名、参数简述、任务和结果文本),其时间、id 和固定文字最多占 120 个字符,所以**一行绝不超过 600 个字符**。因此一页 20 个条目,连同日期行和最后一行,不超过 13,000 个字符。每个部分的全文都可用 `open` 展开。这是行格式,不是可调的限制。 **结果**是 `content` 的文本;blob 和图片为 `[file]` 与 `[image]`;工具带入的上下文消息为 `with context messages`。展开这次调用时给出全部内容。结果比调用晚到不同的分钟时,结局带上结果的时间。 @@ -142,7 +142,7 @@ Recall 按块文本的开头标签与属性,以及 `InputBlock::Raw` 的 `key` ### 3.6 轮次 -一轮是同一个 `turn_id` 从 `turn/start` 到 `turn/end` 的跨度;它消费的输入属于它。任何轮次之外的事(两轮之间的压缩、开通本行、Session fork)是轮次之间独立的行。索引中一轮的那一行给出它的第一段用户文本、调用过的工具及次数,以及 `turn/end` 中的结局(`completed`、`failed`、`cancelled`)。开启一轮的输入是它在第一次模型请求之前消费的那些;之后才读到的输入,例如它工作时到达的 steer,不开启这一轮。这一行给出开启它的输入中最先的一段用户文本;这些输入都没有用户文本时(Goal 续行、其他行发来的消息),给出其中第一个携带行写的输入(§3.4),否则按驱动这一轮的输入那一行的样子给出 `: <第一个块正文的第一行>`,驱动的输入即第一个不是 Append 的开启输入:Append 输入只加入请求,不开启这一轮。没有开启输入的轮次没有这些:它的索引行读作 `turn: no opening input`。 +一轮是同一个 `turn_id` 从 `turn/start` 到 `turn/end` 的跨度;它消费的输入属于它。任何轮次之外的事(两轮之间的压缩、开通本行、Session fork)是轮次之间独立的行。索引中一轮的那一行给出它的第一段用户文本、调用过的工具及次数,以及 `turn/end` 中的结局(`completed`、`failed`、`cancelled`)。开启一轮的输入是它在第一次模型请求之前消费的那些;之后才读到的输入,例如它工作时到达的 steer,不开启这一轮。这一行给出开启它的输入中最先的一段用户文本;这些输入都没有用户文本时(Goal 续行、其他行发来的消息),给出其中第一个携带行写的输入(§3.4),否则按驱动这一轮的输入那一行的样子给出 `: <第一个块的正文,压成一行>`,驱动的输入即第一个不是 Append 的开启输入:Append 输入只加入请求,不开启这一轮。没有开启输入的轮次没有这些:它的索引行读作 `turn: no opening input`。 固定历史中没有 `turn/end` 的一轮:若是发起调用的这一轮,结局为 `in progress`;若是子分支继承前缀截断的父分支那一轮,结局为 `continued on the parent line`。发起调用的这次 `recall` 本身也在这一轮中,结局为 `no result yet`。