Skip to content

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

fix(host-core): retain identifiable background command prefixes

cauliflowerc9974f542662
diff --git a/apps/desktop/src/lib/subagent-topology.ts b/apps/desktop/src/lib/subagent-topology.ts
index 13fd0dd9a..6188090fd 100644
--- a/apps/desktop/src/lib/subagent-topology.ts
+++ b/apps/desktop/src/lib/subagent-topology.ts
@@ -402,7 +402,8 @@ export function backgroundJobRowOf(message: UiMessage) {
if (ref?.kind !== "bash") return null;
const state = snapshot?.state;
return {
- kind, command: typeof snapshot?.command === "string" ? snapshot.command : "Bash",
+ kind, command: typeof snapshot?.command === "string"
+ ? snapshot.command + (snapshot.commandTruncated === true ? "…" : "") : "Bash",
state: state === "running" && snapshot?.stopRequested ? "stopping" as const :
state === "running" || state === "exited" || state === "failed" || state === "stopped" ? state : undefined,
};
diff --git a/apps/desktop/test/subagent-topology.test.mjs b/apps/desktop/test/subagent-topology.test.mjs
index 5e05bdc0a..ba871c6bb 100644
--- a/apps/desktop/test/subagent-topology.test.mjs
+++ b/apps/desktop/test/subagent-topology.test.mjs
@@ -433,6 +433,8 @@ test("background controls describe the command, including pending stops and mixe
assert.equal(backgroundJobRowOf(wait).command, "Bash");
const pending = lifecycle("TaskStop", { job: { job: ref, command: "npm test", state: "running", stopRequested: true } }).message;
assert.deepEqual(backgroundJobRowOf(pending), { kind: "stop", command: "npm test", state: "stopping" });
+ const clipped = lifecycle("TaskWait", { job: { job: ref, command: "npm test", commandTruncated: true } }).message;
+ assert.equal(backgroundJobRowOf(clipped).command, "npm test…");
const mixed = lifecycle("TaskList", { delegations: [{ delegationId: "d", agent: "reviewer" }], backgroundJobs: { supported: true, tasks: [ref] } }).message;
assert.equal(backgroundJobRowOf(mixed).count, 1);
assert.equal(delegationRosterSummary(delegationRoster(mixed)), "reviewer");
diff --git a/crates/host-core/src/background_tasks/jobs.rs b/crates/host-core/src/background_tasks/jobs.rs
index 8e8c258db..d9b430da8 100644
--- a/crates/host-core/src/background_tasks/jobs.rs
+++ b/crates/host-core/src/background_tasks/jobs.rs
@@ -3,6 +3,7 @@ use super::*;
use std::time::Duration;
const MODEL_STREAM_BYTES: usize = 8 * 1024;
+const MODEL_COMMAND_BYTES: usize = 1024;
pub(crate) fn find(
registry: &BackgroundTaskRegistry,
@@ -27,10 +28,15 @@ fn tail(text: String, limit: usize) -> (String, bool) {
pub(crate) async fn snapshot(task: &BackgroundTask, output: bool) -> serde_json::Value {
let shared = task.shared.lock().await;
// List results must also have a budget; commands may contain large scripts.
- let (command, _) = tail(task.command.clone(), 1024);
+ let mut end = task.command.len().min(MODEL_COMMAND_BYTES);
+ while !task.command.is_char_boundary(end) {
+ end -= 1;
+ }
+ let command = &task.command[..end];
let mut result = serde_json::json!({
"job": { "kind": "bash", "id": task.id },
"command": command,
+ "commandTruncated": command.len() < task.command.len(),
"state": shared.state,
"exitCode": shared.exit_code,
"elapsedMs": task.elapsed_ms(),
@@ -102,6 +108,36 @@ mod tests {
assert_eq!(tail("中文".into(), 6), ("中文".into(), false));
}
+ #[tokio::test]
+ async fn command_preview_uses_a_utf8_prefix_independently_of_output_truncation() {
+ let (mut task, _receiver) = task();
+ for (command, expected, cut) in [
+ ("fixture".into(), "fixture".into(), false),
+ ("x".repeat(1024), "x".repeat(1024), false),
+ ("x".repeat(1025), "x".repeat(1024), true),
+ (format!("{}中", "x".repeat(1023)), "x".repeat(1023), true),
+ ] {
+ task.command = command;
+ for output in [false, true] {
+ let observed = snapshot(&task, output).await;
+ assert_eq!(observed["command"], expected);
+ assert_eq!(observed["commandTruncated"], cut);
+ if output {
+ assert_eq!(observed["truncated"], false);
+ }
+ }
+ }
+ task.command = "fixture".into();
+ task.shared
+ .lock()
+ .await
+ .push_stderr(&("x".repeat(8192) + "last error"));
+ let observed = snapshot(&task, true).await;
+ assert_eq!(observed["commandTruncated"], false);
+ assert_eq!(observed["truncated"], true);
+ assert!(observed["stderr"].as_str().unwrap().ends_with("last error"));
+ }
+
#[tokio::test]
async fn completed_before_wait_is_immediate_and_output_is_repeatable() {
let (task, _receiver) = task();
diff --git a/docs/spec/03-runtime/02-agent-runtime.md b/docs/spec/03-runtime/02-agent-runtime.md
index 7c8847596..4862e631d 100644
--- a/docs/spec/03-runtime/02-agent-runtime.md
+++ b/docs/spec/03-runtime/02-agent-runtime.md
@@ -2010,7 +2010,9 @@ Bash background startup and Task startup return an additive `job: {kind, id}`
reference, where kind is `bash` or `delegation`; their original identifiers
remain available. TaskList preserves `delegations` and `resumable` and adds
`backgroundJobs: {supported, tasks}`. Delegation summaries also include job
-references. Bash summaries contain no logs and bound command text to 1 KiB.
+references. Bash summaries contain no logs. The command preview retains the
+first 1 KiB at a UTF-8 boundary. `commandTruncated` marks a shortened command
+independently of output truncation; older Hosts may omit the field.
TaskWait and TaskStop accept one explicit `job`. For a delegation job,
`delegationIds` may be omitted, empty, or contain only that job's id (duplicates
diff --git a/docs/spec/03-runtime/06-host-rpc-protocol.md b/docs/spec/03-runtime/06-host-rpc-protocol.md
index ac4f7bf36..61542a353 100644
--- a/docs/spec/03-runtime/06-host-rpc-protocol.md
+++ b/docs/spec/03-runtime/06-host-rpc-protocol.md
@@ -1603,7 +1603,8 @@ timeoutMs is an integer in 0–1000, default 0. Wait observes a per-job completi
signal without holding AppState. Stop signals the existing supervisor before
observing completion. The returned state is authoritative; stopRequested is
only an acknowledgement, and a running job may need another wait. Snapshot
-metadata includes job {kind: bash, id}, command (at most 1024 UTF-8 bytes),
+metadata includes job {kind: bash, id}, command (a UTF-8 prefix of at most 1024 bytes),
+commandTruncated (whether that prefix omits bytes; older Hosts may omit the flag),
elapsedMs, state, nullable exitCode and stopRequested. Wait/stop additionally
return stdout and stderr (each at most 8192 UTF-8 bytes), and truncated for
either Host retention loss or this observation's clipping.
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 5ee166e85..47be2ebfa 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -20491,6 +20491,9 @@ Scenario: E2E-REVIEW-ROUNDS (local desktop, implemented)
### E2E-TOOLS-session-background-jobs
+- Split follow-up regression: command previews retain a UTF-8 prefix with an independent truncation flag; old snapshots omit the flag and output still retains final errors.
+
+
- Entry: build shared/agent-runtime/host-runtime and Host, then run
`PI_DESKTOP_HOST_BIN=<candidate-host> node scripts/e2e-session-background-jobs.mjs`.
- Environment: isolated Host data and workspace, production runtime and pi tool
diff --git a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md b/docs/zh-CN/spec/03-runtime/02-agent-runtime.md
index 84014ad7c..e01885442 100644
--- a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md
+++ b/docs/zh-CN/spec/03-runtime/02-agent-runtime.md
@@ -1329,7 +1329,7 @@ that the model intended an action.
Agent 模式下,即使没有配置子代理,也提供 TaskWait、TaskList 和 TaskStop。Task 仍要求子代理目录。Plan/Goal 保留声明以兼容对话历史,执行时拒绝这些工具。
-后台 Bash 和 Task 的启动结果新增 `job: {kind, id}`,kind 为 bash 或 delegation,同时保留原 ID 字段。TaskList 保留 delegations 和 resumable,增加 backgroundJobs 的 supported 和 tasks;委派摘要也包含 job。Bash 列表不带日志,命令文字限制为 1 KiB。
+后台 Bash 和 Task 的启动结果新增 `job: {kind, id}`,kind 为 bash 或 delegation,同时保留原 ID 字段。TaskList 保留 delegations 和 resumable,增加 backgroundJobs 的 supported 和 tasks;委派摘要也包含 job。Bash 列表不带日志,命令摘要按 UTF-8 字符边界保留最多 1 KiB 的前缀。`commandTruncated` 单独标记命令裁剪,旧 Host 可省略该字段。
TaskWait/TaskStop 接受单个显式 job,与 delegationIds、mode、minCompleted 混用会报错。无 job 时保留原委派默认集合。旧 backgroundTaskId 可写成 `{kind: "bash", id: backgroundTaskId}`。
diff --git a/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md b/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md
index 27113da9f..e6ec4ec38 100644
--- a/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md
+++ b/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md
@@ -1178,7 +1178,7 @@ tools.execute 增加可选 fileBatchTicket,绑定封存后的单次调用。
接口要求已存在的本地 Agent 会话。未知与其他会话作业均返回 NOT_FOUND;非法参数返回 INVALID_PARAMS;合约模式返回 PERMISSION_DENIED。作业归属不变,会话身份取自 runtime,模型工具参数不提供会话选择。
-timeoutMs 为 0–1000 的整数,默认 0。wait 观察单作业完成信号,释放全局锁;stop 先向已有主管发停止信号,再观察结果。返回 state 为实际状态,stopRequested 仅表示请求已发出。摘要含 job、最多 1024 UTF-8 字节的 command、elapsedMs、state、可空 exitCode 和 stopRequested。wait/stop 另含分别最多 8192 UTF-8 字节的 stdout/stderr,以及表示 Host 缓冲丢失或本次裁剪的 truncated。
+timeoutMs 为 0–1000 的整数,默认 0。wait 观察单作业完成信号,释放全局锁;stop 先向已有主管发停止信号,再观察结果。返回 state 为实际状态,stopRequested 仅表示请求已发出。摘要含 job、最多 1024 UTF-8 字节的 command、elapsedMs、state、可空 exitCode 和 stopRequested。wait/stop 另含分别最多 8192 UTF-8 字节的 stdout/stderr,以及表示 Host 缓冲丢失或本次裁剪的 truncated。 命令保留最多 1024 字节的完整 UTF-8 前缀;commandTruncated 表示命令是否裁剪,旧 Host 可省略该字段。
终态和最终输出在同一作业锁下读取。读操作不消耗输出,进行中的观察持有作业句柄直至有界请求结束,历史淘汰不会拆散这次读取。等待后重新校验会话。放弃请求不会停止进程。旧 Host 能力缺失会明确报告,其他错误不会转为空列表。桌面原 RPC 结构保持兼容。
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 7e7698b2b..6d07634ae 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -10474,6 +10474,9 @@ Electron 一侧——工具自动签发、指示器、"停止"中止轮次、绘
### E2E-TOOLS-session-background-jobs
+- 拆分修复回归:命令摘要保留 UTF-8 前缀并独立标记截断;兼容没有标记的旧快照,错误输出仍保留末尾。
+
+
- 构建 shared、agent-runtime、host-runtime 与 Host 后,运行 `PI_DESKTOP_HOST_BIN=<candidate-host> node scripts/e2e-session-background-jobs.mjs`。
- 使用隔离 Host 数据、工作目录、生产 runtime/pi 循环与本地 HTTP 模型夹具。
- 后台启动测试,列举并等待失败结果;启动常驻命令,等待超时、无参停止,再显式停止并等待。
diff --git a/packages/shared/src/background-jobs.ts b/packages/shared/src/background-jobs.ts
index 0f5706442..ecbb200c3 100644
--- a/packages/shared/src/background-jobs.ts
+++ b/packages/shared/src/background-jobs.ts
@@ -4,6 +4,7 @@ export type JobReference = { kind: "bash" | "delegation"; id: string };
export type BackgroundJobSummary = {
job: JobReference;
command: string;
+ commandTruncated?: boolean;
state: "running" | "exited" | "failed" | "stopped";
elapsedMs: number;
exitCode: number | null;