Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
387381f
fix(engine): keep a rejection's reason from a racing drain
ShriD5 Nov 17, 2026
c85e634
fix(engine): queue files sent with no words while a turn runs
ShriD5 Nov 17, 2026
b956545
perf(engine): commit the first streamed change after a pause at once
ShriD5 Nov 17, 2026
ee6fcc3
fix(engine): never open a chat without an id
ShriD5 Nov 17, 2026
989af02
perf(engine): send chat lists as changes to clients that ask
ShriD5 Nov 17, 2026
99d480d
perf(engine): send a long reply's changed parts alone to a viewport t…
ShriD5 Nov 17, 2026
7e377e5
fix(harness): use discovered names for configured Claude Code models
ShriD5 Nov 17, 2026
723d703
fix(engine): deliver a terminal's writes in the order they were sent
ShriD5 Nov 17, 2026
b2b879c
fix(engine): a message from another chat never stops the running command
ShriD5 Nov 17, 2026
5286c7c
fix(engine): Windows terminals open PowerShell, cmd only without it
ShriD5 Nov 17, 2026
0e380f5
fix(engine): pass -NoLogo on the Windows ConPTY PowerShell launch
ShriD5 Nov 17, 2026
9eb9981
fix(engine): Ctrl+C in a Windows terminal tab interrupts the shell's …
ShriD5 Nov 17, 2026
3440a71
fix(engine): a message sent before the running turn started is its ow…
ShriD5 Nov 17, 2026
d3823dd
fix(engine): hold a send only behind a turn an earlier send started
ShriD5 Nov 17, 2026
1afaf58
fix(mcp): show_visual hover must not move the page
ShriD5 Nov 17, 2026
5ab1ffc
fix(mcp): a show_visual chart's hover readout never changes its height
ShriD5 Nov 17, 2026
8f2d6fe
fix(engine): PowerShell's name reads the same on every platform
ShriD5 Nov 17, 2026
c8f4eaa
fix(harness): make the Claude 200K context window choice limit the wi…
ShriD5 Nov 17, 2026
6f93717
fix(engine): an attachment reaches the agent by its path on the runni…
ShriD5 Nov 17, 2026
0eb79c4
docs: sync with Zeron through 09766b39
ShriD5 Nov 17, 2026
7b55d33
perf(engine): the connectivity monitor looks every 5 s once nothing c…
ShriD5 Nov 18, 2026
4063f27
perf(engine): relay presence probes back off for devices gone a while
ShriD5 Nov 18, 2026
f73eba6
fix(engine): home search walks with a bounded pool whose idle workers…
ShriD5 Nov 18, 2026
25a5b44
test(engine): a launch over parked chats starts no agent; a cut-off t…
ShriD5 Nov 18, 2026
8075a99
perf(engine): read the checkout beside the agent's start, not before it
ShriD5 Nov 18, 2026
03373d3
fix(engine): stamp a run's source context on a task of its own
ShriD5 Nov 18, 2026
89b1e66
perf(engine): the run journal writes each chat's events in batches
ShriD5 Nov 18, 2026
fe36d91
fix(engine): the journal writes events left waiting after a turn's la…
ShriD5 Nov 18, 2026
b4e6edc
test(engine): the home search bench runs on macOS only
ShriD5 Nov 18, 2026
7d1769e
perf(engine): no presence beat for a local profile
ShriD5 Nov 18, 2026
0ab9c88
fix(engine): opening New project asks for no privacy prompt
ShriD5 Nov 18, 2026
926f6e0
perf(harness): Claude runs skip the CLI's own session-title request
ShriD5 Nov 18, 2026
13202a2
fix(harness): refuse a FIFO, device or runaway config file on the ope…
ShriD5 Nov 18, 2026
a6e4550
docs: sync with Zeron through c58f65e8
ShriD5 Nov 18, 2026
87b790e
fix(preview): discovery leaves test servers alone
ShriD5 Nov 20, 2026
bd766ed
docs: sync with Zeron through 2e3513c6
ShriD5 Nov 20, 2026
078d322
fix(voice): omit ort copy-dylibs to fix Windows build on Rust 1.100
ShriD5 Nov 21, 2026
d617dae
docs: sync with Zeron through 46f18fe4
ShriD5 Nov 21, 2026
0bf81ab
fix(harness): skip a Pi model that set_model refuses during discovery
ShriD5 Nov 23, 2026
4c55928
fix(mobile): treat image-named attachment mentions as image chips
ShriD5 Nov 23, 2026
d26fa93
docs: sync with Zeron through b2ee6d1b
ShriD5 Nov 23, 2026
ed1137b
docs: sync with Zeron through fbb4083a4
ShriD5 Nov 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

201 changes: 199 additions & 2 deletions crates/doc/src/transcript_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,38 @@ pub enum TranscriptFrame {
append: Vec<TextAppend>,
#[serde(default)]
remove: Vec<String>,
/// Parts of an entry replaced or added, the entry otherwise as it
/// was: a tool call arriving or finishing in a long reply sends that
/// call alone, not the reply. Only to a consumer that asked for them
/// (`DiffOptions::part_patches`); never sent empty, so an older
/// reader never sees the field.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
parts: Vec<PartPatch>,
/// Expected transcript length after applying this frame — the desync
/// tripwire: a consumer that lands elsewhere resubscribes for a reset.
count: usize,
},
}

/// One part of entry `entry` set at `at` (from 0): a part there replaced (the
/// same part, changed), or one added at its end (`at` its part count). `len`
/// is the entry's part count after the frame's patches (desync tripwire).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PartPatch {
pub entry: String,
pub at: usize,
pub part: MessagePart,
pub len: usize,
}

/// What a consumer of `WatchDocMessages` takes beyond the original frames.
#[derive(Debug, Clone, Copy, Default)]
pub struct DiffOptions {
/// Part patches (`TranscriptFrame::Delta::parts`) for an entry whose
/// header and part order are unchanged, rather than the entry whole.
pub part_patches: bool,
}

/// An inserted or replaced entry, positioned after `after` (`None` = head).
/// Anchors are prior upserts of the same frame or unchanged entries, so
/// applying upserts in frame order always finds them settled.
Expand Down Expand Up @@ -247,8 +273,8 @@ impl TranscriptFrame {
pub fn is_empty_delta(&self) -> bool {
matches!(
self,
Self::Delta { upsert, append, remove, .. }
if upsert.is_empty() && append.is_empty() && remove.is_empty()
Self::Delta { upsert, append, remove, parts, .. }
if upsert.is_empty() && append.is_empty() && remove.is_empty() && parts.is_empty()
)
}
}
Expand Down Expand Up @@ -296,13 +322,55 @@ fn try_text_append(prev: &SessionMessageEntry, next: &SessionMessageEntry) -> Op
append
}

/// When `next` is `prev` with some of its parts changed in place (each the
/// same part, by id) and/or parts added at its end, its header the same: those
/// parts alone, as patches. `None` for any other change (a part removed or
/// moved, the status or duration changed): the entry is sent whole.
fn try_part_patches(prev: &SessionMessageEntry, next: &SessionMessageEntry) -> Option<Vec<PartPatch>> {
if prev.id != next.id
|| prev.role != next.role
|| prev.created_at != next.created_at
|| prev.device_id != next.device_id
|| prev.status != next.status
|| prev.continuation_of != next.continuation_of
|| prev.duration_ms != next.duration_ms
|| next.parts.len() < prev.parts.len()
{
return None;
}
let mut patches = Vec::new();
for (at, n) in next.parts.iter().enumerate() {
match prev.parts.get(at) {
Some(p) if p == n => {}
Some(p) if p.id() != n.id() => return None,
_ => patches.push(PartPatch {
entry: next.id.clone(),
at,
part: n.clone(),
len: next.parts.len(),
}),
}
}
Some(patches)
}

/// Diff two transcript states into a frame. An entry is upserted when it is
/// new, its content changed, or its predecessor changed (a Loro list merge can
/// interleave a remote entry mid-list). Falls back to `Reset` when the delta
/// would carry most of the transcript anyway.
pub fn diff_transcript(
prev: &[SessionMessageEntry],
next: &[SessionMessageEntry],
) -> TranscriptFrame {
diff_transcript_with(prev, next, DiffOptions::default())
}

/// `diff_transcript`, with what the consumer takes beyond the original
/// frames (`options`).
pub fn diff_transcript_with(
prev: &[SessionMessageEntry],
next: &[SessionMessageEntry],
options: DiffOptions,
) -> TranscriptFrame {
let prev_by_id: std::collections::HashMap<&str, (usize, &SessionMessageEntry)> = prev
.iter()
Expand All @@ -319,6 +387,7 @@ pub fn diff_transcript(

let mut upsert = Vec::new();
let mut append = Vec::new();
let mut parts = Vec::new();
for (i, entry) in next.iter().enumerate() {
let after = i.checked_sub(1).map(|p| next[p].id.as_str());
match prev_by_id.get(entry.id.as_str()) {
Expand All @@ -333,6 +402,13 @@ pub fn diff_transcript(
append.push(text_append);
continue;
}
if options.part_patches
&& prev_after == after
&& let Some(patches) = try_part_patches(prev_entry, entry)
{
parts.extend(patches);
continue;
}
upsert.push(TranscriptUpsert {
after: after.map(str::to_string),
entry: entry.clone(),
Expand All @@ -353,6 +429,7 @@ pub fn diff_transcript(
upsert,
append,
remove,
parts,
count: next.len(),
}
}
Expand All @@ -377,6 +454,7 @@ pub fn apply_transcript_frame(
upsert,
append,
remove,
parts,
count,
} => {
if !remove.is_empty() {
Expand Down Expand Up @@ -428,6 +506,33 @@ pub fn apply_transcript_frame(
)));
}
}
for PartPatch {
entry,
at,
part,
len,
} in parts
{
let Some(target) = current.iter_mut().find(|e| e.id == entry) else {
return Err(TranscriptDesync(format!("missing patch entry {entry}")));
};
let have = target.parts.len();
if at < have && target.parts[at].id() == part.id() {
target.parts[at] = part;
} else if at == have {
target.parts.push(part);
} else {
return Err(TranscriptDesync(format!(
"patch out of place on {entry}#{at}"
)));
}
if target.parts.len() > len {
return Err(TranscriptDesync(format!(
"patch length mismatch on {entry}: have {}, expected {len}",
target.parts.len()
)));
}
}
if current.len() != count {
return Err(TranscriptDesync(format!(
"count mismatch: have {}, expected {count}",
Expand Down Expand Up @@ -567,12 +672,103 @@ mod tests {
len: 99,
}],
remove: vec![],
parts: vec![],
count: 1,
};
let mut current = vec![entry("a", "hello")];
assert!(apply_transcript_frame(&mut current, frame).is_err());
}

fn tool(id: &str, output: Option<&str>) -> MessagePart {
MessagePart::Tool {
id: id.into(),
call: serde_json::from_value(serde_json::json!({ "kind": "exec", "command": "ls" })).unwrap(),
is_error: false,
resolved: output.is_some(),
output: output.map(Into::into),
diff: None,
output_ref: None,
output_bytes: None,
diff_ref: None,
diff_stats: None,
subagent_ref: None,
subagent_status: None,
subagent_tail: None,
}
}

fn working(calls: &[MessagePart]) -> SessionMessageEntry {
let mut e = entry("b", "");
e.parts = calls.to_vec();
e.status = Some(crate::parts::MessageStatus::Streaming);
e
}

/// A call arriving and another finishing in a long reply: asked for,
/// those two parts alone travel; not asked for, the entry whole, as ever.
#[test]
fn a_reply_s_changed_parts_travel_alone_when_asked_for() {
let a = entry("a", "prompt");
let calls: Vec<_> = (0..50).map(|i| tool(&format!("t{i}"), Some("ok"))).collect();
let b0 = working(&[calls.clone(), vec![tool("t50", None)]].concat());
let b1 = working(&[calls, vec![tool("t50", Some("done")), tool("t51", None)]].concat());
let options = DiffOptions { part_patches: true };
let frame = diff_transcript_with(&[a.clone(), b0.clone()], &[a.clone(), b1.clone()], options);
match &frame {
TranscriptFrame::Delta { upsert, parts, .. } => {
assert!(upsert.is_empty(), "the entry isn't sent whole");
let at: Vec<_> = parts.iter().map(|p| (p.at, p.part.id().to_owned())).collect();
assert_eq!(at, vec![(50, "t50".into()), (51, "t51".into())]);
}
other => panic!("expected delta, got {other:?}"),
}
let json = serde_json::to_value(&frame).unwrap();
let mut current = vec![a.clone(), b0.clone()];
apply_transcript_frame(&mut current, serde_json::from_value(json).unwrap()).unwrap();
assert_eq!(current, vec![a.clone(), b1.clone()]);
// Not asked for: whole, and no `parts` field on the wire.
let frame = diff_transcript(&[a.clone(), b0.clone()], &[a.clone(), b1.clone()]);
let json = serde_json::to_value(&frame).unwrap();
assert!(json.get("parts").is_none(), "{json}");
assert_eq!(json["upsert"].as_array().map(Vec::len), Some(1));
apply(&[a.clone(), b0], &[a, b1]);
}

/// A change parts can't say (the reply settling, a part going) is the
/// entry whole even when they're asked for.
#[test]
fn other_changes_send_the_entry_whole() {
let b0 = working(&[tool("t0", None), tool("t1", None)]);
let mut settled = b0.clone();
settled.status = Some(crate::parts::MessageStatus::Complete);
let fewer = working(&[tool("t0", None)]);
let moved = working(&[tool("t1", None), tool("t0", None)]);
let options = DiffOptions { part_patches: true };
for next in [settled, fewer, moved] {
let frame = diff_transcript_with(std::slice::from_ref(&b0), std::slice::from_ref(&next), options);
match &frame {
TranscriptFrame::Delta { upsert, parts, .. } => {
assert_eq!(upsert.len(), 1);
assert!(parts.is_empty());
}
other => panic!("expected delta, got {other:?}"),
}
}
}

#[test]
fn a_patch_out_of_place_is_desync() {
let frame = TranscriptFrame::Delta {
upsert: vec![],
append: vec![],
remove: vec![],
parts: vec![PartPatch { entry: "b".into(), at: 5, part: tool("t5", None), len: 6 }],
count: 1,
};
let mut current = vec![working(&[tool("t0", None)])];
assert!(apply_transcript_frame(&mut current, frame).is_err());
}

#[test]
fn large_change_falls_back_to_reset() {
let prev: Vec<_> = (0..10).map(|i| entry(&format!("p{i}"), "x")).collect();
Expand All @@ -592,6 +788,7 @@ mod tests {
}],
append: vec![],
remove: vec![],
parts: vec![],
count: 2,
};
let mut current = Vec::new();
Expand Down
Loading
Loading