Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

feat(session-collaboration): send the report as readable text, not JSON

Tioit-Wang77d5b7a03603
diff --git a/crates/host-core/src/session_collaboration/settlement.rs b/crates/host-core/src/session_collaboration/settlement.rs
index 61a5bd60f..bb58d7829 100644
--- a/crates/host-core/src/session_collaboration/settlement.rs
+++ b/crates/host-core/src/session_collaboration/settlement.rs
@@ -46,6 +46,40 @@ pub fn begin_turn(
Ok(turn)
}
+/// What a sender reads when its delivery settles. The receipt is a report a model
+/// can act on, not an encoded envelope: the labels are stable so a skill can name
+/// them, and the worker's own text carries whatever structure it chose.
+fn report_content(message: &Message) -> String {
+ let mut text = String::from("Sub-session report\n");
+ text.push_str(&format!(
+ "Session: {} ({})\n",
+ message.target_title, message.target_session_id
+ ));
+ text.push_str(&format!("Status: {}\n", message.status));
+ match message.turn_id.as_deref() {
+ Some(turn) => text.push_str(&format!("Delivery: {} (turn {turn})\n", message.id)),
+ None => text.push_str(&format!("Delivery: {}\n", message.id)),
+ }
+ match message.result.as_deref() {
+ Some(report) if !report.trim().is_empty() => {
+ text.push_str("\nReport:\n");
+ text.push_str(report.trim_end());
+ text.push('\n');
+ }
+ Some(_) => text.push_str("\nReport: (the worker finished without a final text)\n"),
+ None => text.push_str("\nReport: (none)\n"),
+ }
+ if let Some(error) = message
+ .error
+ .as_deref()
+ .map(str::trim)
+ .filter(|value| !value.is_empty())
+ {
+ text.push_str(&format!("\nError: {error}\n"));
+ }
+ text
+}
+
pub(super) fn callback(db: &Database, message: &Message) -> Result<Option<Message>> {
if !message.notify_on_completion || message.kind == "completion" {
return Ok(None);
@@ -68,8 +102,7 @@ pub(super) fn callback(db: &Database, message: &Message) -> Result<Option<Messag
let Some(target_title) = target_title else {
return Ok(None);
};
- let content = json!({"sessionId":message.target_session_id,"messageId":message.id,
- "turnId":message.turn_id,"status":message.status,"result":message.result,"error":message.error}).to_string();
+ let content = report_content(message);
let at = ms_to_ts(now_ms());
let receipt = Message {
id: Uuid::new_v4().to_string(),
diff --git a/crates/host-core/src/session_collaboration/tests.rs b/crates/host-core/src/session_collaboration/tests.rs
index 85d2b2ea8..544257999 100644
--- a/crates/host-core/src/session_collaboration/tests.rs
+++ b/crates/host-core/src/session_collaboration/tests.rs
@@ -162,6 +162,29 @@ fn turn_bound_result_and_callback_are_durable_and_exactly_once() {
Some(message.id.as_str())
);
assert!(!receipt.notify_on_completion);
+ // The receipt is a readable report a model can act on, not an encoded envelope.
+ assert!(
+ receipt.content.starts_with("Sub-session report\n"),
+ "{}",
+ receipt.content
+ );
+ assert!(
+ receipt.content.contains("Status: completed"),
+ "{}",
+ receipt.content
+ );
+ assert!(
+ receipt
+ .content
+ .contains("Report:\nAuthoritative final result"),
+ "{}",
+ receipt.content
+ );
+ assert!(
+ !receipt.content.contains("\"result\""),
+ "{}",
+ receipt.content
+ );
let result = handle(
&db,
"session.collaboration.result",
@@ -527,8 +550,12 @@ fn a_restart_reports_an_interrupted_delivery_to_its_sender_once() {
|row| row.get(0),
)
.unwrap();
- assert!(content.contains("\"status\":\"interrupted\""), "{content}");
- assert!(content.contains("\"result\":null"), "{content}");
+ assert!(content.contains("Status: interrupted"), "{content}");
+ assert!(
+ content.contains("Error: Execution interrupted by application restart"),
+ "{content}"
+ );
+ assert!(!content.contains("\"status\""), "{content}");
recover(&db).unwrap();
assert_eq!(receipt(&db), 1);
assert_eq!(turn_count(&db, &child), 1);
diff --git a/docs/spec/07-plugins/03-plugin-api.md b/docs/spec/07-plugins/03-plugin-api.md
index 539544de9..f5bcda4fa 100644
--- a/docs/spec/07-plugins/03-plugin-api.md
+++ b/docs/spec/07-plugins/03-plugin-api.md
@@ -1020,11 +1020,12 @@ the source delivery and is created at most once after the actual target turn
settles, including a delivery fenced as `interrupted` by an application restart.
A completion receipt is promoted in the target session's turn queue, so a busy
target runs it at the next turn boundary ahead of input the user queued earlier
-A completion receipt is promoted in the target session's turn queue, so a busy
-target runs it at the next turn boundary ahead of input the user queued earlier
-(ADR 0265); it is never injected into another session's running turn. A `send`
-may ask for the same treatment with `delivery: "immediate"`; the default
-`queue` appends behind whatever the target already queued.
+(ADR 0265); it is never injected into another session's running turn. Its content
+is a readable report — a `Sub-session report` line, then `Session:`, `Status:`,
+`Delivery:`, a `Report:` section with the worker's final text, and `Error:` when
+the run failed — not an encoded envelope. A `send` may ask for the same treatment
+with `delivery: "immediate"`; the default `queue` appends behind whatever the
+target already queued.
The callback is session data, not a new user authorization, and completion
messages do not trigger another callback.
diff --git a/docs/zh-CN/spec/07-plugins/03-plugin-api.md b/docs/zh-CN/spec/07-plugins/03-plugin-api.md
index d60cbcce9..87dae6bdc 100644
--- a/docs/zh-CN/spec/07-plugins/03-plugin-api.md
+++ b/docs/zh-CN/spec/07-plugins/03-plugin-api.md
@@ -842,8 +842,8 @@ Session ID,并复用该会话的项目、模型、上下文和权限配置;`
最多创建一次;被应用重启栅栏标记为 `interrupted` 的投递也一样会生成该回执。
完成回执会在目标会话的回合队列中被提升,因此繁忙的目标会在下一个回合边界优先执行它,
而不是排在用户早先排队的输入之后(ADR 0265);它永远不会被注入另一个会话正在运行的回合。
-完成回执会在目标会话的回合队列中被提升,因此繁忙的目标会在下一个回合边界优先执行它,
-而不是排在用户早先排队的输入之后(ADR 0265);它永远不会被注入另一个会话正在运行的回合。
+回执正文是可读报告而不是编码包:一行 `Sub-session report`,然后是 `Session:`、`Status:`、
+`Delivery:`,`Report:` 段放 worker 的最终文本,失败时附 `Error:`。
`send` 可以用 `delivery: "immediate"` 请求同样的处理;默认的 `queue` 会排到目标已排队输入之后。
回调是会话数据,不是新的用户授权;完成消息不会触发另一个回调。
渲染器可以读取单独的侧边栏协作投影,但插件面板不能绕过此网关调用变更操作。