From d7a1166cafea92a0efc0f0f2a74a54583736530a Mon Sep 17 00:00:00 2001 From: huihui Date: Fri, 20 Nov 2026 14:30:18 +0800 Subject: [PATCH 1/2] docs(branch): restate the branch prompts as rules The `` guide entry says that a block of the same name carrying `default` is the note a move writes, so a line that compacts into its latest note still reads both kinds of block in its own guide. The `branch` tool's `end` refusal uses the design's single sentence for every refused caller: the role check and the tree's CannotEnd guard now answer `branch_cannot_end` with the same text, which names the default-branch and ancestor guard the short text left out. The description's coordination sentence and the status notes' "How you work here" bullets keep their text; they are judged as one policy family in the change that first puts a candidate for either in place. --- .../dim-agent-capabilities/src/timeline_tree.rs | 15 ++++++++++----- .../dim-agent-capabilities/tests/branch_flow.rs | 6 +++--- tests/integration/tests/minimal_execution.rs | 2 +- tests/integration/tests/prompt_guide.rs | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/crates/dim-agent-capabilities/src/timeline_tree.rs b/crates/dim-agent-capabilities/src/timeline_tree.rs index 5325fd63b3..ccc167663e 100644 --- a/crates/dim-agent-capabilities/src/timeline_tree.rs +++ b/crates/dim-agent-capabilities/src/timeline_tree.rs @@ -3331,7 +3331,7 @@ impl LineView { } } /// ``, written by TimelineTree at the start of every child. -const IDENTITY_ENTRY: &str = r#": which line of this session you are, placed by the runtime at the start of a line's own history. A later block of this name replaces the earlier one; it is state about the line, not a request."#; +const IDENTITY_ENTRY: &str = r#": which line of this session you are, placed by the runtime at the start of a line's own history. A later block of this name replaces the earlier one; a block carrying `default` is the note a move writes. Both are state about the line, not requests."#; /// ``, the roster BranchLine writes under [`roster_key`] on /// a line that opened lines. @@ -5200,10 +5200,7 @@ impl BranchTool { call_id: &str, ) -> std::result::Result { if own.role != LineRole::Tool { - return Ok(refusal( - "branch_cannot_end", - "Only a line opened with create can end itself.".into(), - )); + return Ok(refusal("branch_cannot_end", CANNOT_END_TEXT.into())); } if own.ending { return Ok(self.ended(&own.id)); @@ -5230,6 +5227,10 @@ impl BranchTool { own.id, parent ))), Err(AgentError::BranchEnded(line)) => Ok(self.ended(&line)), + Err(AgentError::BranchRefused { + refusal: BranchRefusal::CannotEnd, + .. + }) => Ok(refusal("branch_cannot_end", CANNOT_END_TEXT.into())), Err(AgentError::BranchRefused { refusal: kind, message, @@ -5821,6 +5822,10 @@ fn status_note( /// The `branch` tool's refusal of `create` on a line that is neither the root /// nor the default branch (design §4, §11). const NOT_OPENER_TEXT: &str = "Only the root and the default branch open lines. Tell one of them if more parallel work is needed."; +/// The `branch` tool's refusal of `end` on the root, the default branch, a +/// plugin line, a line the user opened or an ancestor of the default branch +/// (design §10, §11). +const CANNOT_END_TEXT: &str = "Only a line opened with create can end itself, and not while it or a line below it is the default branch."; /// The `branch` tool's refusal of `create` when the open would cross the /// Session's cap of open tool lines (design §6.1, §11). const LIMIT_REACHED_TEXT: &str = "This Session holds its limit of open lines. Continue on this line, or end one of its open lines first."; diff --git a/crates/dim-agent-capabilities/tests/branch_flow.rs b/crates/dim-agent-capabilities/tests/branch_flow.rs index 9283bbab3a..1421a94f00 100644 --- a/crates/dim-agent-capabilities/tests/branch_flow.rs +++ b/crates/dim-agent-capabilities/tests/branch_flow.rs @@ -3841,14 +3841,14 @@ async fn a_refused_branch_call_writes_nothing() { call(&session, "main", r#"{"action":"end","content":"done"}"#).await, ( "branch_cannot_end".into(), - "Only a line opened with create can end itself.".into() + "Only a line opened with create can end itself, and not while it or a line below it is the default branch.".into() ) ); assert_eq!( call(&session, &host, r#"{"action":"end","content":"done"}"#).await, ( "branch_cannot_end".into(), - "Only a line opened with create can end itself.".into() + "Only a line opened with create can end itself, and not while it or a line below it is the default branch.".into() ) ); assert!( @@ -4525,7 +4525,7 @@ async fn a_configured_description_reaches_the_request_declaration() { /// its guide entry is registered there, at the Session, and a line carries it /// even where no branch part is loaded. `` stays with /// BranchLine, which writes the roster. -const IDENTITY_ENTRY: &str = r#": which line of this session you are, placed by the runtime at the start of a line's own history. A later block of this name replaces the earlier one; it is state about the line, not a request."#; +const IDENTITY_ENTRY: &str = r#": which line of this session you are, placed by the runtime at the start of a line's own history. A later block of this name replaces the earlier one; a block carrying `default` is the note a move writes. Both are state about the line, not requests."#; const ROSTER_ENTRY: &str = r#": the lines you opened, under the key `branch:roster` and apart from your own identity under `branch:line`: the runtime lists the tool lines you opened that are still open, each with the first line of its purpose. A later block of this name replaces the earlier one; it is state about the lines, not a request."#; /// #987: the parent block can arrive only on a line with a parent, so main's /// guide carries no entry for it. diff --git a/tests/integration/tests/minimal_execution.rs b/tests/integration/tests/minimal_execution.rs index b7c75153ea..1c9d67c641 100644 --- a/tests/integration/tests/minimal_execution.rs +++ b/tests/integration/tests/minimal_execution.rs @@ -549,7 +549,7 @@ fn tool_results(events: &[Arc]) -> usize { } /// #552: the entry TimelineTree registers for ``. -const IDENTITY_ENTRY: &str = r#": which line of this session you are, placed by the runtime at the start of a line's own history. A later block of this name replaces the earlier one; it is state about the line, not a request."#; +const IDENTITY_ENTRY: &str = r#": which line of this session you are, placed by the runtime at the start of a line's own history. A later block of this name replaces the earlier one; a block carrying `default` is the note a move writes. Both are state about the line, not requests."#; fn system_text(prompt: &SystemPrompt) -> String { match prompt { diff --git a/tests/integration/tests/prompt_guide.rs b/tests/integration/tests/prompt_guide.rs index e5e1f66468..8be8814039 100644 --- a/tests/integration/tests/prompt_guide.rs +++ b/tests/integration/tests/prompt_guide.rs @@ -51,7 +51,7 @@ const CHANNEL_RULE: &str = "The operator is the person running this session. The const PROBE_ENTRY: &str = r#": an entry a contributor registered for this flow; the composition places it between the state and the rule entries."#; /// #552: TimelineTree writes `` and registers its entry. -const IDENTITY_ENTRY: &str = r#": which line of this session you are, placed by the runtime at the start of a line's own history. A later block of this name replaces the earlier one; it is state about the line, not a request."#; +const IDENTITY_ENTRY: &str = r#": which line of this session you are, placed by the runtime at the start of a line's own history. A later block of this name replaces the earlier one; a block carrying `default` is the note a move writes. Both are state about the line, not requests."#; /// #552: BranchLine writes `` and registers its entry. const ROSTER_ENTRY: &str = r#": the lines you opened, under the key `branch:roster` and apart from your own identity under `branch:line`: the runtime lists the tool lines you opened that are still open, each with the first line of its purpose. A later block of this name replaces the earlier one; it is state about the lines, not a request."#; From 3d4fba6e655624386de79b3fb78378d11d6e9a97 Mon Sep 17 00:00:00 2001 From: huihui Date: Fri, 20 Nov 2026 15:14:57 +0800 Subject: [PATCH 2/2] test(branch): give compaction turns the loaded-machine bound A turn that compacts runs an extra model call, which the five-second `soon` bound does not survive on a loaded machine. Every wait on such a turn now uses the file's thirty-second `patient` helper. --- crates/dim-agent-capabilities/tests/branch_flow.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/dim-agent-capabilities/tests/branch_flow.rs b/crates/dim-agent-capabilities/tests/branch_flow.rs index 8a49c1ef0b..518f80f065 100644 --- a/crates/dim-agent-capabilities/tests/branch_flow.rs +++ b/crates/dim-agent-capabilities/tests/branch_flow.rs @@ -5988,7 +5988,7 @@ async fn a_nested_line_is_told_its_own_parent_at_open() { .submit(text, InputMode::Queue, &inner) .await .unwrap(); - soon(session.idle(&inner)).await.unwrap(); + patient(session.idle(&inner)).await.unwrap(); } let message = baseline_message(&local_events(&session, &inner).await, "branch:parent") .expect("the line compacted and its parent block replayed"); @@ -6458,7 +6458,7 @@ async fn the_parent_block_replays_after_a_compaction() { .submit(text, InputMode::Queue, &child) .await .unwrap(); - soon(session.idle(&child)).await.unwrap(); + patient(session.idle(&child)).await.unwrap(); } let message = baseline_message(&local_events(&session, &child).await, "branch:parent") .expect("the line compacted and its parent block replayed"); @@ -7634,7 +7634,7 @@ async fn wait_for_roster(session: &Session, line: &str) { async fn compact_line(session: &Session, line: &str) { for text in ["x".repeat(1500), "y".repeat(1500)] { session.submit(text, InputMode::Queue, line).await.unwrap(); - soon(session.idle(line)).await.unwrap(); + patient(session.idle(line)).await.unwrap(); } } @@ -9564,7 +9564,7 @@ async fn a_switched_line_keeps_its_identity_after_a_compaction() { .unwrap(); for text in ["x".repeat(1500), "y".repeat(1500)] { session.submit(text, InputMode::Queue, &line).await.unwrap(); - soon(session.idle(&line)).await.unwrap(); + patient(session.idle(&line)).await.unwrap(); } let note = line_block(&chain_events(&session, &line, ..).await.unwrap()) .expect("the note is the latest block of the key"); @@ -9645,7 +9645,7 @@ async fn a_multi_paragraph_purpose_survives_a_move_and_a_compaction() { ); for text in ["x".repeat(1500), "y".repeat(1500)] { session.submit(text, InputMode::Queue, &line).await.unwrap(); - soon(session.idle(&line)).await.unwrap(); + patient(session.idle(&line)).await.unwrap(); } let note = line_block(&chain_events(&session, &line, ..).await.unwrap()) .expect("the note is still the latest block of the key");