@marktrue/dsh-mobile-remote 3.2.4-alpha.2 → 3.2.4-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/03-api.md CHANGED
@@ -46,7 +46,10 @@
46
46
  | GET | `/m/api/workspaces` | 已注册工作区 | 是 |
47
47
  | GET/POST | `/m/api/directories` | 目录浏览/新建文件夹 | 是 |
48
48
  | GET | `/m/api/diagnostics` | 环境诊断(插件运行时、services、checks) | 是 |
49
- | — | `/m/api/git/*`(规划中) | 设计草案;v3.1.5 未注册这些路由 | 不适用 |
49
+ | GET | `/m/api/changes/summary` | 本轮改动文件摘要(按轮查询,宿主内存态,v3.3) | 是 |
50
+ | GET | `/m/api/changes/diff` | 本轮单文件对比(最小闭环 diff,v3.3) | 是 |
51
+ | GET | `/m/api/turn-file` | 按轮末记录坐标读取文件(预览/下载,v3.3) | 是 |
52
+ | GET/POST | `/m/api/git/*` | Git 只读/写接口(v3.3 已实现,见「Git API」节) | 是 |
50
53
  | GET | `/m/api/balance` | DeepSeek 官方余额 | 是 |
51
54
  | GET | `/m/api/account-usage` | 用量与额度(DeepSeek / Codex / OpenCode Go) | 是 |
52
55
  | GET | `/m/api/qr-config` | 桌面二维码数据(loopback only) | 否(loopback) |
@@ -122,6 +125,11 @@
122
125
  - `urls`:按优先级排列——默认「局域网私有地址优先」(`10./192.168.x` → `172.16-31` → Tailscale CGNAT `100.64/10` → 其他),首个非 internal IPv4 在前,loopback 最后;**仅当机器上没有任何局域网私有地址时**,才把 Tailscale CGNAT 提到最前(issue #49,避免校园网/热点等场景选出不可达地址);`port` 来自 `ctx.webServer.port`。v3.0.0:`lanBridge` 监听成功时首选地址为桥地址(`http://<IP>:<lanBridge.port>`,端口默认 3080),回环 webserver 地址仅作本机自连兜底。
123
126
  - `agents[].status`:`"running" | "idle"`(映射自 agent 状态与最近事件推断)。
124
127
  - `capabilities.turnOutline`:轮次大纲能力位(轮次导航)。宿主**真的注册了** `turnOutline` 投影单元、且投影感知观察面(`sessionQuery.observeSession`)可用时,返回 `{ "version": 1, "supported": true, "unloaded": true, "truncated": true }`——`unloaded` 表示未加载轮次也可跳转、`truncated` 表示超过体积上限会显式截断;否则返回 `{ "version": 1, "supported": false }`。**不按宿主版本号推断**:旧宿主/裁剪宿主显式声明不支持,App 据此退回「只用已加载轮次」的降级行为。SSE hello 的同名字段与该处**同判据、同形状**(见 §3.6 与 §6.18)。
128
+
129
+ - `capabilities.turnTail`:轮末页脚能力位(v3.3,issue #52/#53):宿主注册了 `workspaceChanges` 服务时返回 `{ "version": 1, "presented": true, "changed": true, "changesDiff": true }`,否则 `presented` 仍可为真而 `changed`/`changesDiff` 为假;旧插件不下发该字段,App 据此不渲染轮末卡片与展示模式设置。判据与字段详见 §6.20,SSE hello 同名字段与之同判据、同形状。
130
+ - `capabilities.toolCards`:工具卡结构化能力位(v3.3,issue #54):`{ "version": 1, "tools": [本插件实际投影的工具名…] }`;bootstrap 与 SSE hello 同判据,App 逐工具决定专用卡或通用卡,缺失时全部通用卡(见 §6.24)。v3.4(issue #68)追加 `ptc: { "version": 1 }`:新 App 据此把 PTC 子调用合入根工具卡;旧 App 忽略该键,`version`/`tools` 语义不变(见 §6.24.1)。
131
+ - `plugin.hostId`:宿主**稳定身份**(随机 UUID,持久化于插件状态目录;与访问口令、`instanceId` 无关,issue #60 R15)。手机用它隔离通知账本(同口令的不同宿主不得互相撤销);旧插件缺失该字段时 App 回退既有 scope。
132
+
125
133
  - 未认证:`401`(见通用约定)。
126
134
  ### 3.2 POST /m/api/send
127
135
  **请求**
@@ -185,6 +193,14 @@
185
193
  }
186
194
  ```
187
195
 
196
+ - **默认排除零可见消息的空会话**(issue #109):没有 `user/message`(真人发言)或非空 `assistant/message` 的会话不返回,避免“创建过但从未对话”的空会话出现在列表。`?includeEmpty=1` 返回全部(排查/清理用);其他值(含缺失、`0`、`true`、非法串)按 false 处理。
197
+ - “可见消息”与 `lastMessageAt` 同口径:仅 `user/message`(`source.kind` 为 `user`/旧内核无 source)和正文非空的 `assistant/message`;`tool/call`、`tool/result`、权限/sandbox/approval/model selection、`session/end-seed`、系统注入等都不计入。空会话仍可通过 includeEmpty 或深链访问。
198
+ - 过滤在标题折叠与消息时间回填之后执行;休眠/归档空会话同样默认隐藏。空会话 = **零可见对话消息且无 `tool/call`/`tool/result`**(工具活动是有价值内容,不能当空会话删除);纯配置/生命周期/空 assistant/系统注入不算对话。判空**不看 `time`**:可见消息没有时间戳时仍保留(仅排序回退 `lastActivity`/`createdAt`)。
199
+ - 优先用 `ctx.sessionPersistence.list()` 的廉价 metadata 判空(请求级 1.5s 上限,失败/超时退回有界 read):生产 JSONL backend 当前**没有 eventCount**,以 `sizeBytes` 为主。
200
+ · `sizeBytes ≤ 1024` 才直接判空(实测空会话 329–704B;正常对话实测最小 40KB);若同时有 eventCount 且 `>8` 则视为非空。
201
+ · `1024 < sizeBytes ≤ 2048` 为灰区,**不直接删**,回退 `readSession` 用 tool-aware 事件判定(防小 tool-only/only-user 误删)。
202
+ · `sizeBytes > 2048` 视为非空;`sizeBytes` 缺失为未知,走有界读确认;eventCount 不能单独判空。
203
+ - metadata 不足(服务缺失/条目缺失)才退回有界 `readSession`;只删**本次请求成功读到且确认空**的会话;读取失败、超出预算、仍在途、旧回填缓存一律保留可见,宁可多显示也不误删。兜底读取受单次 deadline + 总 2.5s 硬上限约束,并发 ≤4。
188
204
  - 排序(规划中):优先按 `lastMessageAt` 倒序,缺失时回退 `lastActivity`,再回退 `createdAt`;等值时以 `id` 为次级键保证顺序稳定。数据源:优先 `sessionQuery.listSessions()`(含休眠会话),回退 `ctx.sessions.list()`(仅活动会话)。
189
205
  - `archived`:是否已归档(见 3.4 归档接口)。
190
206
  - `lastActivity`:最近活跃时间(ms)。任意会话事件(SSE)与移动端"打开会话"(3.4 touch)都会更新,持久化于 `~/.dsh/mobile-remote/session-activity.json`。保留给旧版 App,且在消息时间缺失时仍作为排序回退值;旧 App 调用 `touch` 或内部事件发生时,这类会话仍可能重排。
@@ -219,7 +235,7 @@
219
235
  - `limit`(可选,默认 500,上限 1000):最多返回条数
220
236
  **过滤规则**:返回可进入 Conversation timeline 的事件;`assistant/chunk` / `assistant/live-chunk` 只用于实时草稿,`agent/inbox/spliced` 由队列投影承载,`request/header`(含 system prompt/tool schema)、`request/context`、`session/end-seed`、`step/start`、`step/end`、`system/message`、`assistant/attempt`(重试/中断的原始 stream 记录)与 `compaction/start` / `compaction/summary` / `compaction/prune` / `compaction/end`(压缩生命周期;summary 正文即替换 shadowed 区间后的上下文快照)属于内部/重建/快照元数据,历史、实时与 3.5b 详情三处都不返回。`compaction/end` 作为不落卡片的实时控制帧通知 App 重新加载 durable snapshot。未知 type(即使带 `ignorable: true`)保留 `seq`/`type`,但不提供详情指针;由于详情端点采用 fail-closed allow-list,未知类型请求详情会返回 `404 event-not-found`。只有经审查并列入 allow-list 的可见类型可通过 3.5b 读取详情。
221
237
 
222
- > 客户端呈现约定:`session/title`、`model/selection`、`sandbox/mode`、`agent-preset/selected`、`subagent/*`、`team/*`、`feedback/*`、`command/*`、`approval/policy`、`tool/ptc-dispatch*`、`goal/change` 属协议/运行时元数据;普通模式不渲染,调试模式按摘要可用字段展示。只有 `user/message`、`assistant/message`、`tool/call`、`tool/result`、`todo/write`、`turn/start`、`turn/end` 在服务端详情 allow-list 中,其他事件没有详情指针(见 3.5b)。`approval/asked` / `approval/decided` 是 durable 审批记录,普通模式以可读标题呈现(历史回放的权威源;问询只有瞬态帧,不保证回放)。
238
+ > 客户端呈现约定:`session/title`、`model/selection`、`sandbox/mode`、`agent-preset/selected`、`subagent/*`、`team/*`、`feedback/*`、`command/*`、`approval/policy`、`tool/ptc-dispatch*`、`goal/change` 属协议/运行时元数据;普通模式不渲染,调试模式按摘要可用字段展示。只有 `user/message`、`assistant/message`、`tool/call`、`tool/result`、`todo/write`、`turn/start`、`turn/end` 在服务端详情 allow-list 中,其他事件没有详情指针(见 3.5b)。`approval/asked` / `approval/decided` 是 durable 审批记录,普通模式以可读标题呈现(历史回放的权威源;问询只有瞬态帧,不保证回放)。v3.4(issue #68):`tool/ptc-dispatch*` 在能力位 `toolCards.ptc` 存在时由新 App 消费结构化 data 合入根工具卡子调用树(普通模式仍不出现裸事件卡);旧 App / 无能力位 / 坏 data 时保持上述调试模式行为,不伪造根卡。
223
239
  **响应 200**
224
240
 
225
241
  ```json
@@ -282,6 +298,8 @@
282
298
  | `assistant/chunk` / `assistant/live-chunk` | `{ text: string }` 文本/reasoning delta;工具参数 delta 的 canonical `chunk.id` 归一为摘要 `callId`(仅实时过程,历史过滤) |
283
299
  | `tool/call` | `{ turn, step, callId, name, arguments }`;长参数可通过详情端点获取 |
284
300
  | `tool/result` | `{ callId, name, isError, text, images? }`;长结果可通过详情端点获取;**不再下发 `files`**(issue #1 需求变更:工具产出文件不上时间线;图片仍带 `images`) |
301
+ | `tool/ptc-dispatch-start` | PTC 子调用开始(v3.4,issue #68):`{ turn?, step?, rootCallId?, parentCallId, callId, name?, status: "running", summary? }`;`callId` 即内核对 `subCallId`,**不下发** `arguments` 原文 / `meta`;仍属 debug-only(见 §6.24.1) |
302
+ | `tool/ptc-dispatch` | PTC 子调用落定(v3.4,issue #68):同上 + `{ status: "success" \| "failed", isError, text?, error? }`;`text` 仅失败时下发且只含**合法安全码**(`^[A-Za-z][A-Za-z0-9_.-]{0,63}$`:合法 `error.code` 优先、否则合法 `error.name`,≤500),`error` 仅 `{ name, code }` 且两者都合法才下发;超 50 子调用时下发最小 `truncated: true` 通知(见 §6.24.1) |
285
303
  | `turn/start` | `{ turn: number }` |
286
304
  | `turn/end` | `{ turn: number, reason: object }` |
287
305
  | 其他可见事件 | 保留 `type`、`seq`,未知类型使用通用卡保留顺序;不提供详情指针,也不允许通过 3.5b 读取原始载荷 |
@@ -299,9 +317,10 @@
299
317
  | `agent/status` | `{ agentId, sessionId, status, child }`——`status` 只有 `running` / `idle` 两值(内核 `AgentStatus` 即为二元联合);`sessionId` 为去 `session:` 前缀的会话 id,`child` 标记子代理会话(v2.7.2 起携带后两字段)。**不存在 `waiting`**:等待用户审批/作答时 agent 仍为 `running`,该事实由 `mobile/frame` 的挂起问询/审批承载 |
300
318
  | `notifications/changed` | 通知记录增删(如移动端删除后),客户端刷新列表与角标 |
301
319
  | `mobile/notify` | `{ notification: { id, kind, sessionId, title, detail, time } }`——插件"真结束"判定后推送的通知(completed / failed / needs-answer),桌面宠物/App 与通知中心同源渲染(v2.7.2) |
302
- | `mobile/frame` | 内核瞬态帧(问询/审批)。`frame` 字段为 `question/requested`(含 `rpcId`、`questions[]`)、`question/resolved`(`questionRpcId`)、`approval/requested`(`rpcId`、`approvalId`、`toolName`、`reason?`)、`approval/resolved`(`approvalId`)。**App 断线重连时服务端补发挂起的待答帧**(`pendingFrames` 回放) |
320
+ | `mobile/frame` | 内核瞬态帧(问询/审批)。`frame` 字段为 `question/requested`(含 `rpcId`、`questions[]`)、`question/resolved`(`questionRpcId`)、`approval/requested`(`rpcId`、`approvalId`、`toolName`、`reason?`)、`approval/resolved`(`approvalId`)。**`approvalId` 标识一次实际审批请求**:同一 `callId` 的 pre-execute 与 sandbox escalation 是两个不同 `approvalId`,`callId` 仅作关联(issue #60 R16);`$events` 路径的 `rpcId` 使用稳定的 `eventId`。**App 断线重连时服务端补发挂起的待答帧**(`pendingFrames` 回放) |
303
321
  | `mobile/queue` | `{ sessionId, rows: [{ id, text, placement }] }`——内核队列快照(`agent/inbox/spliced` 即时镜像,v3.0.2):认领/删除/编辑实时反映,App 端 dock 以此为权威源(`placement`: `queued` / `steering` / `context`,与 GET /queue 同款形状);断线重连时 mux 回放当前队列 |
304
- | `git/changed`(规划中) | 设计目标为 `{ repositoryId }`;当前版本未实现 Git provider,也不会推送此帧 |
322
+ | `attention/snapshot` | `{ version: 1, pending: [{ kind, sessionId, identity }] }`——在断线重连的 `mobile/frame` 挂起帧回放**之后**、同一有序 SSE 流上追加的**完整待办快照边界**(v3.3)。App 只据此撤销该宿主已不在 pending 中的业务通知,不得凭超时猜测待办已结束;旧宿主无此帧时保留既有行为 |
323
+ | `git/changed`(v3.3) | Git 改动通知帧:至少包含 `{ repositoryId }`,可带 `changeKinds`(`index`/`head`) |
305
324
 
306
325
  客户端应按 `type` 分派;未知 type 使用通用事件卡保留顺序(前向兼容)。当前服务端故意不给未知 type 详情指针,按需详情端点对其返回 `404 event-not-found`,避免未经审查地暴露事件载荷。
307
326
  ### 3.7 GET /m/qr.png
@@ -348,7 +367,7 @@
348
367
  | POST | `/m/api/actions/:id/invoke` | 执行插件动作 |
349
368
  | GET | `/m/api/usage` | 会话 token 用量统计(v2.1) |
350
369
  | GET | `/m/api/workspaces` | 已注册工作区(新建会话默认目录,v2.1) |
351
- | GET | `/m/api/directories` | 目录浏览(盘符/子目录,v2.1;v3.1.1 根视图响应新增 `sep` 字段) |
370
+ | GET | `/m/api/directories` | 目录浏览(盘符/子目录,v2.1;v3.1.1 根视图响应新增 `sep` 字段;issue #45 可选 `includeHidden=1` 显示点开头条目,`.git` 永不返回) |
352
371
  | POST | `/m/api/directories` | 新建文件夹(v2.1) |
353
372
  | GET | `/m/api/diagnostics` | 环境诊断(服务端端点实测,v2.1) |
354
373
  | GET | `/m/api/balance` | DeepSeek 官方余额(服务端代查,v2.1) |
@@ -363,6 +382,16 @@
363
382
  > 根视图响应(`path` 为空)携带 `sep`(服务端真实分隔符),新版 App 据此拼接子目录,不再按 Windows 习惯硬编码 `\`;
364
383
  > 该字段为纯增量,旧版 App 忽略即可。
365
384
 
385
+ > **隐藏条目(issue #45,纯增量)**:`GET /m/api/directories?path=<非空>&includeHidden=1` 时,
386
+ > 点开头的目录与文件会同时出现在 `dirs` / `files` / `fileEntries` 三条列表里(排序规则不变);
387
+ > 缺省或 `includeHidden` 不是 `1` 时保持旧行为,全部隐藏点开头条目。无论是否 `includeHidden`,
388
+ > 名称恰为 `.git` 的条目(**文件或目录**)永远不返回——避免暴露对象库与可能含凭据的 `.git/config`,
389
+ > 列表也不提供进入其内部的入口。根视图(`path` 为空)与 `POST /m/api/directories` 不受该参数影响;
390
+ > `/m/api/files` 下载/预览通道对隐藏文件与普通文件一视同仁(可按普通文件路径读取隐藏文件)。
391
+ > 隐藏判定只看**名字是否以 `.` 开头**(Windows 隐藏属性不在本次范围);显式按路径发起的列表/读取
392
+ > 仍沿用既有只读信任模型,本参数只影响目录列表的可见性。旧客户端不传该参数即可,契约纯增量,
393
+ > 不新增 capability 位。
394
+
366
395
  ### 6.2 GET /m/api/catalog
367
396
 
368
397
  返回 PC 端真实枚举(单一事实源,客户端不硬编码):
@@ -544,9 +573,9 @@
544
573
 
545
574
  环境诊断在 `checks` 下提供宿主兼容自检(ADR 0017,**纯增量字段,旧 App 忽略即可**):
546
575
 
547
- - `checks.hostCapabilities`:逐项三态 `ok` / `drift` / `missing`。`drift` = 能力语义漂移(服务在、调用不报错、成员形状或实参语义已变)。包含 `jobs.callerShape`、`jobs.eventsApi`、`settings.read`、`gateway.wireStream`、`gateway.eventsPeer`(issue #34,0.2.1 的进程内 Peer 来源)、`permissionPresets.apply`、`permissionPresets.catalog`、`workspaceRegistry.stateWrite`。
576
+ - `checks.hostCapabilities`:逐项三态 `ok` / `drift` / `missing`。`drift` = 能力语义漂移(服务在、调用不报错、成员形状或实参语义已变)。包含 `jobs.callerShape`、`jobs.eventsApi`、`settings.read`、`gateway.wireStream`、`gateway.eventsPeer`(issue #34,0.2.1 的进程内 Peer 来源)、`permissionPresets.apply`、`permissionPresets.catalog`、`workspaceRegistry.stateWrite`,以及 issue #87 的 `subagents.catalog`(`listDescendants` 或 `listChildren` 至少一个可用)与 `subagents.interrupt`(`interruptByUser` 或 `interruptByParent` 至少一个可用)。
548
577
  - `checks.hostCapabilityReasons`:仅对 `drift` 项给出的允许清单原因码(如 `settings.read` 的 `settings-get-threw`;`gateway.eventsPeer` 的 `gateway-peer-source-missing`)。
549
- - `checks.hostGeneration`:插件实际走到的代际路径——`jobsCaller`(`sessionId` / `agent`)、`settingsRead`(`describe` / `get`)、`wireStreamArgs`(`controlArg` / `legacyArg`)、`eventsPeer`(`createPeer` / `operatorPeer` / `legacy` / `none` / `unknown`)。
578
+ - `checks.hostGeneration`:插件实际走到的代际路径——`jobsCaller`(`sessionId` / `agent`)、`settingsRead`(`describe` / `get`)、`wireStreamArgs`(`controlArg` / `legacyArg`)、`eventsPeer`(`createPeer` / `operatorPeer` / `legacy` / `none` / `unknown`),以及 issue #87 的 `subagents.catalog`(`descendants` / `children` / `none`)与 `subagents.interrupt`(`user` / `parent` / `none`)。
550
579
  - `checks.remoteEvents` / `checks.approvalMode`:`$events` 双端审批通道是否就绪与实际生效的审批呈现策略。
551
580
 
552
581
  详见 `docs/09-compatibility.md` §2.5/§2.6。
@@ -618,19 +647,27 @@
618
647
  { "id": "…", "kind": "child", "status": "running", "title": "…", "createdAt": 1730000000000 }
619
648
  ]}
620
649
  ```
621
- - 目录来源按优先级取:① 宿主持久目录 `ctx.subagents.listChildren(parentSessionId)` → ② 持久化枚举(父会话休眠/归档时入口不消失)→ ③ 会话注册表派生。
650
+ - 目录来源按优先级取(能力探测,不看宿主版本号):
651
+ ① rc.2+ `ctx.subagents.listDescendants(parentSessionId, signal)`(递归,**只取 `depth===1`**)→
652
+ ①' rc.1 `ctx.subagents.listChildren(parentSessionId, signal)` → ② 持久化枚举(父会话休眠/归档时入口不消失)→ ③ 会话注册表派生。
622
653
  **不调用 `subagents/list` Remote 端点**——该端点在宿主 0.2.0 已被删除
623
- - `kind`:`child`(普通子代理)或 `diagnostic`(目录 `mode: "unknown"` 的不受支持条目,此时 `status` 为原因 `unsupported`)
624
- - `status`:活 agent 的 AgentStatus 映射(`running`/`inactive`)或 diagnostic reason
625
- - `createdAt` 可选,用于排序;`catalogDegraded: true` 表示来源 ②/③ 不完整,客户端据此区分"确实没有子代理"与"目录读不到"
654
+ - `kind`:`child`(普通子代理)或 `diagnostic`(rc.2 的 `kind:"diagnostic"` / rc.1 的 `mode:"unknown"`)。
655
+ diagnostic 行**没有 `mode`**,客户端不得用 `row.mode` 判分支。
656
+ - `status`:普通行为活 agent 的 AgentStatus 映射(`running`/`inactive`);diagnostic 行为三枚举原因:
657
+ `unsupported`(该条目自身可继续遍历)/ `corrupt`(目录数据损坏、分支中止)/ `unavailable`(子目录读不到、分支中止)。
658
+ - `createdAt`:rc.2 目录无该字段,回落 `session.header.createdAt`;两者都缺失时排到列表末尾(组内 `id` 升序),
659
+ 排序仍为 createdAt 降序;`catalogDegraded: true` 表示来源 ②/③ 不完整,客户端据此区分"确实没有子代理"与"目录读不到"
626
660
  - 缺参数 `400 parentSessionId-required`;三条路径都取不到会话 `404 session-not-found`
627
661
 
628
662
  **POST `/m/api/subagents/interrupt`** — 中断子代理
629
663
  ```json
630
664
  请求: { "parentSessionId": "…", "childSessionId": "…" }
631
- 响应: { "ok": true }
665
+ 响应: { "ok": true, "accepted": true }
632
666
  ```
633
- - 映射内核 `subagent.interrupt`(payload `{ parentSessionId, childSessionId, mode: "continuable" }`)
667
+ - rc.2+(宿主暴露 `subagents.interruptByUser`):映射 `subagents/interruptByUser`,payload **仅** `{ childSessionId }`;
668
+ 响应透传 `SubagentInterruptReceipt.accepted`。语义是**中断信号已受理**,不等于目标已静默/已退出。
669
+ - rc.1(仅 `subagents.interruptByParent`):映射旧端点,payload `{ childSessionId, parentSessionId, mode: "continuable" }`;
670
+ 旧宿主无 receipt,响应省略 `accepted`。
634
671
 
635
672
  **GET `/m/api/goal?sessionId=…`** — 当前目标(无目标返回 `{ "goal": null }`)
636
673
  ```json
@@ -675,9 +712,9 @@
675
712
  - `commands.execute` 外层套 `AbortSignal.timeout(15000)`:15s 是**整个命令**的上限。`/compact` 之类会等一次完整的 LLM 摘要,长会话可能超时 → `504 commands-execute-failed`;客户端此时**不能断言失败**(结果未知)
676
713
  - `result` 为内核 settle 对象(`commandId` + `result.{kind,text}`),与 PC 端一致
677
714
 
678
- ### Git API 设计草案(本版本未实现)
715
+ ### Git API(v3.3 已实现)
679
716
 
680
- > 以下 Git endpoints 是设计目标,不属于 v3.1.5 已实现 API;当前 `lib/index.js` 未注册 `/m/api/git/*` 路由,客户端不得依赖这些端点。设计背景见 `docs/design/mobile-git.md` 与 `docs/adr/` 中相关 ADR。
717
+ > `/m/api/git/*` 已注册并可用;以下为当前契约。设计背景见 `docs/design/mobile-git.md` 与 `docs/adr/` 中相关 ADR。
681
718
 
682
719
  Git 接口计划由项目自有 provider 提供,执行通过 DSH `subprocess`,仓库必须位于
683
720
  `workspaceRegistry` 已注册工作区内。`repositoryId` 为 provider 分配的不透明仓库标识,客户端不得自行拼接
@@ -688,7 +725,7 @@ shell 命令。Slice A 是只读基础;B1/B2 提供受保护的 stage/commit
688
725
  `GET /m/api/git/context?sessionId=…` 返回不透明的稳定 `repositoryId`、仓库名称和能力,不返回主机路径。
689
726
  其余接口均要求 `repositoryId`:`status` 返回分支与文件状态,`branches` 返回本地/远端分支。
690
727
  客户端不得将主机路径当作 B1 写操作的 `repositoryId`;服务端仅接受由 `context` 返回、并在授权工作区内解析的仓库标识。
691
- `graph` 支持 `limit/cursor` 和可选 JSON `refs`(最多 5 个 `{name,tipOid}` 引用对;本地与远程引用合计);首次请求返回
728
+ `graph` 支持 `limit/cursor` 和可选 JSON `refs`(GET 最多 32 个、POST 最多 128 个 `{name,tipOid}` 引用对;本地与远程引用合计);首次请求返回
692
729
  `snapshotId`、绑定的 `tips`、提交页和 `nextCursor`,后续请求必须使用同一快照的不透明游标。
693
730
  引用移动、删除、tip 不匹配、仓库变化、游标上下文错误或快照过期返回 `409 graph-stale`,客户端不得
694
731
  静默回退到全量图。`commit` 要求 `oid`,`diff` 支持 `kind=working|staged|commit`、`oid/path`。
@@ -828,6 +865,9 @@ fetch/push 序列化 common domain,pull/sync/abort 同时序列化 common 与
828
865
  - 响应:`200` 文件流(`content-type` 按扩展名推断、`content-disposition: attachment` 带 UTF-8 文件名);路径不存在或非文件 → `404 file-not-found`;缺 `path` → `400 bad-request`
829
866
  - 与目录选择器(§6.2)同信任模型:口令鉴权 + 现有限流,路径由手机显式指定;服务端先打开句柄、`fstat` 复核为普通文件,再按 descriptor 真实路径做工作区包含校验,符号链接/越界路径一律 `404`
830
867
  - 平台范围:descriptor-relative 保护需 procfs/devfs,**仅 Linux/macOS 提供**;Windows 返回 `503 files-unavailable`(安全 fail-closed,见 docs/04 §6)
868
+ - 支持 `HEAD`、单区间 `Range`、`ETag`、`If-None-Match`;有效区间返回 `206 + Content-Range`,越界返回 `416`。续传携带 `Range: bytes=N-` 与此前保存的 `If-Range: <ETag>`;只有标记一致才返回区间,不一致、弱标记或日期标记均返回完整 `200`,客户端截断旧文件后从头写。
869
+ - App 侧断点保存在私有支持目录,按地址、API 路径与认证身份摘要隔离(不持久化口令);恢复时核对 ETag、实际本地长度、完整区间和最终总长度,旧宿主缺标记时从头下载。暂停、断网、锁屏中断与进程退出后可从下载入口继续;保存到系统下载目录失败时保留已下载文件以便重试保存。恢复列表最多八项,七天后清理,可手动删除。
870
+ - Android 用户发起下载后启动专用 `dataSync` 前台服务(通知提供进度与暂停,完成、失败或暂停后退出);服务不可用或通知关闭时明确退回前台下载。服务与宠物 / 提醒保活开关独立,不传递 URL、口令或远端路径。Android 15+ 累计后台时限由系统管理,`onTimeout` 立即停止服务并通知 Dart 暂停、保留私有断点,不通过重启服务绕过预算。
831
871
 
832
872
  **POST `/m/api/files/upload`** — 上传文件到电脑(写会话工作目录)
833
873
  ```json
@@ -937,7 +977,8 @@ fetch/push 序列化 common domain,pull/sync/abort 同时序列化 common 与
937
977
  | GET | `/m/api/git/capabilities` | Git 只读能力与契约版本 |
938
978
  | GET | `/m/api/git/repository` | 当前会话 cwd 解析出的仓库标识 |
939
979
  | GET | `/m/api/git/branches` | 本地/远程分支列表 |
940
- | GET | `/m/api/git/graph` | 一至五个 tip 之间的提交拓扑(分页) |
980
+ | GET | `/m/api/git/graph` | 1–32 tip 的提交拓扑(分页) |
981
+ | POST | `/m/api/git/graph` | 1–128 tip 的提交拓扑(JSON body,分页/续页) |
941
982
  | GET | `/m/api/git/commit` | 提交详情 + 变更文件(分页) |
942
983
  | GET | `/m/api/git/worktree` | 工作区快照(已暂存/未暂存/未跟踪) |
943
984
  | GET | `/m/api/git/preview` | 单文件文本差异预览(有界) |
@@ -956,6 +997,7 @@ fetch/push 序列化 common domain,pull/sync/abort 同时序列化 common 与
956
997
  "readOnly": true,
957
998
  "provider": "bundled",
958
999
  "features": {
1000
+ "graphTips": { "max": 128, "getMax": 32 },
959
1001
  "repository": true, "branches": true, "graph": true, "commit": true,
960
1002
  "worktree": true, "preview": true, "refsDetail": true, "fileHistory": true
961
1003
  }
@@ -1020,15 +1062,19 @@ graph 的每个提交与 commit 详情都**保留旧的** `refs: string[]`(dep
1020
1062
 
1021
1063
  `branches` 响应:`{ ok, repositoryId, branches: [{ name, displayName, oid, kind, current, tracking, ahead, behind }] }`,`kind` 为 `local` / `remote`,`name` 为完整 ref 名。
1022
1064
 
1023
- #### 6.19.4 GET /m/api/git/graph
1065
+ #### 6.19.4 GET/POST /m/api/git/graph
1024
1066
 
1025
1067
  | 参数 | 说明 |
1026
1068
  |---|---|
1027
- | `tips` | JSON 数组字符串:`[{"name":"refs/heads/main"\|"HEAD"\|"refs/remotes/origin/main","tipOid":"<可选>"}]`,1–5 个且不重复 |
1069
+ | `tips` | GET:JSON 数组字符串 `1–32` 个;POST:body `tips` 数组 `1–128` 个。元素 `{"name":"refs/heads/main"\|"HEAD"\|"refs/remotes/origin/main","tipOid":"<可选>"}`,不重复 |
1028
1070
  | `snapshotId` / `cursor` | 翻页时成对提交:首次请求省略,响应返回 `snapshotId` 与 `nextCursor` |
1029
1071
  | `limit` | 每页条数,1–200,默认 100 |
1030
1072
 
1031
- 响应:`{ ok, repositoryId, snapshotId, tips, commits, nextCursor }`,`commits[]` 含 `oid` / `parents` / `author` / `timestamp` / `subject` / `refs` / `refsDetail` / `tagsDetail`。引用在翻页期间移动、tip 失效、快照过期或游标非法返回 `409 graph-stale`;非法 tip 返回 `409 graph-tip-invalid`,超过 5 个返回 `400 graph-too-many-tips`。
1073
+ POST 请求体:`{"sessionId","repositoryId","tips":[...],"limit"?,"snapshotId"?,"cursor"?}`;续页可省略 `tips`,`snapshotId/cursor` 与 GET 互通(传输方式不参与快照身份)。POST body ≤256 KiB、每个 `name` ≤1024 B,超限 `413 payload-too-large`。`HEAD /git/graph` 返回 200 无 body,不创建快照。
1074
+
1075
+ **all 模式(仅 POST)**:`{"sessionId","repositoryId","all":true,"focus"?:ref|oid,"limit":16,"snapshotId"?,"cursor"?}`。服务端解析 `refs/heads/* + refs/remotes/*`(排除 `/HEAD`)作为 tips;**tag 不作为 tip/分支线**,只作为分支历史内可达提交上的 label。固定每页 16 提交;`focus` 返回包含该提交的页并带 `focusOid/pageStart/prevCursor/nextCursor/hasNewer/hasOlder`,`prevCursor` 更新、`nextCursor` 更旧。all 快照绑定全部分支 refs 指纹;分支新增/移动/删除返回 `409 graph-stale`。保护超限返回 `400 graph-too-many-refs`、focus 非法/未找到返回 `400 graph-focus-invalid`/`409 graph-focus-not-found`,不静默截断。GET 不接受 `all=true`。
1076
+
1077
+ 响应:`{ ok, repositoryId, snapshotId, tips, commits, nextCursor }`(all 模式另含 `all/pageSize/pageStart/focusOid/prevCursor/hasNewer/hasOlder`),`commits[]` 含 `oid` / `parents` / `author` / `timestamp` / `subject` / `refs` / `refsDetail` / `tagsDetail`。引用在翻页期间移动、tip 失效、快照过期或游标非法返回 `409 graph-stale`;非法 tip 返回 `409 graph-tip-invalid`;GET 超过 32 / POST 超过 128 返回 `400 graph-too-many-tips`(detail 声明对应上限);服务端 25s deadline 返回 `504 graph-timeout`。
1032
1078
 
1033
1079
  #### 6.19.5 GET /m/api/git/commit
1034
1080
 
@@ -1093,11 +1139,26 @@ graph 的每个提交与 commit 详情都**保留旧的** `refs: string[]`(dep
1093
1139
  | `no-history` | 仓库尚无提交(空仓库) |
1094
1140
  | `path-invalid` | 越界(`..`、仓库外绝对路径、无法映射的 Windows 绝对路径)或无法归一化的路径 |
1095
1141
 
1096
- - **路径归一化由宿主负责**:接受工作区绝对路径或仓库相对路径,归一化到仓库根内;越界/仓库外返回 `path-invalid`。目录路径(含仓库根、`.`)返回 `400 path-invalid`;只接受文件路径。
1142
+ - **路径归一化由宿主负责**:接受工作区绝对路径或仓库相对路径,归一化到仓库根内;越界/仓库外返回 `path-invalid`。目录路径(含仓库根、`.`)返回 `400 path-invalid`;只接受文件路径。Windows 客户端可能提交 8.3 短别名,宿主会把最近的存在父目录规范化到长名、保留文件名,同一仓库的两种写法视为同一路径。
1097
1143
  - `reason: "path-invalid"` 的 200 响应中,`path` 为客户端提交的原值(便于回填/纠错);这是客户端输入的回显,不是宿主发现的新路径信息。
1098
1144
  - **有界**:单次最多扫描 5000 条提交或 20 秒软超时;达到上限时返回已取部分并 `truncated: true`(客户端可提示「仅显示最近 N 条提交」)。
1099
1145
  - 缺失 `path` → `400 bad-request`。
1100
1146
 
1147
+ #### 6.19.12 GET/HEAD /m/api/workspace-image
1148
+
1149
+ 只读返回当前会话工作区内的图片字节,供 App 渲染 Markdown 本地图片。**不是任意文件读取接口。**
1150
+
1151
+ | 参数 | 说明 |
1152
+ |---|---|
1153
+ | `sessionId` | 必填;会话 cwd 必须位于已登记工作区内 |
1154
+ | `path` | 必填;会话 cwd 内的工作区路径(词法前缀 + realpath containment) |
1155
+
1156
+ - 仅接受普通图片文件(png/jpeg/gif/webp;扩展名与 magic 必须一致);目录/FIFO/device/空文件拒绝;**末级符号链接拒绝**。
1157
+ - 安全读取(Linux):`open(O_RDONLY|O_NOFOLLOW|O_NONBLOCK)` → `fstat` → `/proc/self/fd/<fd>` 实际路径 containment(cwd + 登记工作区)→ 有界 `readSync` → `close`;不再按路径二次 `stat/readFileSync`。**非 Linux/无 O_NOFOLLOW/无 procfs 返回 `501 image-verification-unavailable`,不回退到不安全读取。**
1158
+ - 上限:8 MiB / 8192px 单边 / 40 MP;超限 `413 image-too-large`;类型不符/无法解析尺寸 `415 unsupported-image-type`;越界/工作区未授权 `403 path-outside-workspace`;不存在 `404 image-not-found`;错误不泄露主机路径。
1159
+ - 响应:`200` 图片字节 + `content-type` + 强 ETag;`HEAD` 同 headers 无 body;`If-None-Match` 命中 `304`;`cache-control: private, max-age=86400`;`x-content-type-options: nosniff`。POST/其它方法 `405`。
1160
+ - App:只对工作区本地路径调用此端点;`http(s)` 图片本轮不自动加载(显示 alt/占位),避免第三方请求;本地图片失败显示 alt + 可读原因。
1161
+
1101
1162
  #### 6.19.9 Git 只读端点错误码
1102
1163
 
1103
1164
  | HTTP | error 值 | 场景 |
@@ -1106,12 +1167,16 @@ graph 的每个提交与 commit 详情都**保留旧的** `refs: string[]`(dep
1106
1167
  | 400 | `invalid-oid` / `invalid-files-cursor` / `invalid-history-cursor` | 非法 OID / 文件分页游标 / 历史分页游标 |
1107
1168
  | 400 | `path-invalid` | `/git/file-history` 传入目录路径 |
1108
1169
  | 400 | `preview-invalid` | 预览参数非法 |
1109
- | 400 | `graph-tip-invalid` / `graph-too-many-tips` | 非法 tip / 超过 5 个 tip |
1170
+ | 400 | `graph-tip-invalid` / `graph-too-many-tips` / `graph-too-many-refs` / `graph-focus-invalid` | 非法 tip / 超选择集上限 / all refs 超保护 / all focus 非法 |
1110
1171
  | 401 | `auth-required` / `bad-token` | 未鉴权(同 §1) |
1111
- | 403 | `repository-not-authorized` / `workspace-not-allowed` | 会话/仓库不匹配或路径不在已注册工作区 |
1112
- | 404 | `session-not-found` / `not-git-repository` / `preview-file-not-found` | 会话不存在 / cwd 不是仓库 / 提交中无该文件 |
1113
- | 409 | `graph-stale` / `graph-tip-invalid` | 快照或 tip 已变化 |
1114
- | 413 | `git-output-too-large` | Git 输出超过宿主上限(graph/commit/preview 的输出、`/git/files` 的 HEAD 路径总表,均为 8 MiB 级) |
1172
+ | 403 | `repository-not-authorized` / `workspace-not-allowed` / `path-outside-workspace` | 会话/仓库不匹配、路径不在工作区、图片实际 fd 越界 |
1173
+ | 404 | `session-not-found` / `not-git-repository` / `preview-file-not-found` / `image-not-found` | 会话不存在 / cwd 不是仓库 / 提交中无该文件 / 图片不存在或非普通文件 |
1174
+ | 409 | `graph-stale` / `graph-tip-invalid` / `graph-focus-not-found` | 快照/tip 已变化 / all focus 扫描未命中 |
1175
+ | 413 | `git-output-too-large` / `payload-too-large` / `image-too-large` | Git 输出/请求体超限;图片超 8 MiB/8192px/40MP |
1176
+ | 415 | `unsupported-image-type` | 图片扩展名/magic 不符或尺寸不可解析 |
1177
+ | 501 | `image-verification-unavailable` | 当前平台无法提供 fd 级安全校验(Windows/macOS/无 procfs) |
1178
+ | 504 | `graph-timeout` | graph 25s deadline(任意阶段) |
1179
+ | 431 | —(HTTP) | GET URL 过长;新 App 在能力允许时自动改 POST 重试一次 |
1115
1180
  | 503 | `git-provider-unavailable` / `provider-incompatible` | provider 不可用 / 旧 provider 不支持所需方法 |
1116
1181
 
1117
1182
  #### 6.19.10 兼容与降级
@@ -1152,3 +1217,240 @@ graph 的每个提交与 commit 详情都**保留旧的** `refs: string[]`(dep
1152
1217
  `HistoryEntry`(`fileHistory()` 元素):`{ oid, shortOid, author, timestamp, subject, status }`;`status` 为 Git 单字母(`A`/`M`/`D`/`R`/`C`/`T`,实际出现哪些由 provider 决定);`author` 只含姓名;`timestamp` 为 Unix 秒。provider 只返回有界结果,不应抛出宿主未知的错误码(未知错误会被映射为 `git-provider-unavailable`)。
1153
1218
 
1154
1219
  约束:provider 不得返回主机绝对路径、remote URL 或邮箱;路径事实必须限定在 `repositoryRoot` 授权仓库内。
1220
+
1221
+ ### 6.20 轮次页脚能力位与信号(v3.3,issue #52/#53)
1222
+
1223
+ 手机端要呈现「轮次过程折叠 + 轮末产出物」,需要的信号与能力都按增量字段下发;旧 App 忽略未知字段,旧插件不提供能力位时新 App 静默降级。
1224
+
1225
+ **能力位**(`GET /m/api/bootstrap` 与 SSE `hello` 同判据、同形状):
1226
+
1227
+ ```json
1228
+ "capabilities": {
1229
+ "turnTail": { "version": 1, "presented": true, "changed": true, "changesDiff": true }
1230
+ }
1231
+ ```
1232
+
1233
+ - `presented`:事件摘要会下发 `deliverables/presented` 的文件声明(见下)。
1234
+ - `changed`:`/m/api/changes/summary` 可用;宿主**真的注册了** `workspaceChanges` 服务时才是 `true`,不按宿主版本推断(ADR 0017)。
1235
+ - `changesDiff`:`/m/api/changes/diff` 可用。
1236
+ - 三者缺省(旧插件)时 App 不渲染对应卡片,也不显示展示模式设置。
1237
+
1238
+ **事件摘要增量 `time`**:所有时间线事件摘要新增顶层 `time`(Unix 毫秒,取自 SessionEvent.time),供轮次/过程组计算用时。旧插件不下发时 App 不显示任何耗时,**不得**用本地接收时间推算。
1239
+
1240
+ **交付文件声明**(`deliverables/presented` 摘要 data):
1241
+
1242
+ ```json
1243
+ { "turn": 12, "callId": "call_abc", "files": [ { "name": "报告.pdf", "display": "~/Documents/报告.pdf", "description": "最终交付" } ] }
1244
+ ```
1245
+
1246
+ - 只下发文件名、显示名与说明;**不下发主机绝对路径**。预览坐标 = 该事件 `seq` + `files` 下标。
1247
+ - 同轮多次 `present` 时由 App 按路径去重,说明取该轮最后一次声明(与桌面一致)。
1248
+
1249
+ **`GET /m/api/history` 响应增量 `turnTails`**:
1250
+
1251
+ ```json
1252
+ "turnTails": { "12": { "changes": true, "presented": true } }
1253
+ ```
1254
+
1255
+ - key 为轮次号的字符串形式;只包含有产出物的轮次;服务端单次遍历已加载事件得出(不额外调用宿主服务)。
1256
+ - 实时侧:`turn/end` 摘要 data 增量 `tail`,形状相同。App 据此决定是否渲染卡片位置与是否按需拉摘要。
1257
+
1258
+ **兼容**:新插件 + 旧 App —— 旧 App 忽略上述字段;`workspace/changes` 事件不再进入移动时间线(见 6.21),旧 App 也不会再渲染裸类型名空卡。旧插件 + 新 App —— 无 `turnTail` 能力位,两卡与展示模式设置不显示;新 App 同时把裸 `workspace/changes` 归入调试可见。
1259
+
1260
+ ### 6.21 GET /m/api/changes/summary(本轮改动文件摘要,issue #53)
1261
+
1262
+ **查询参数**:`sessionId`(必填)、`turn`(必填,非负整数)。
1263
+
1264
+ **响应**:
1265
+
1266
+ ```json
1267
+ {
1268
+ "ok": true,
1269
+ "state": "available",
1270
+ "turn": 12,
1271
+ "files": [
1272
+ { "seq": 843, "index": 0, "id": "a1b2c3d4e5f60718", "display": "src/a.ts", "name": "a.ts",
1273
+ "added": 12, "deleted": 3, "binary": false, "oversized": false }
1274
+ ],
1275
+ "total": 5,
1276
+ "added": 42,
1277
+ "deleted": 7,
1278
+ "truncated": false
1279
+ }
1280
+ ```
1281
+
1282
+ - `state` 三态:`available`(宿主仍有该轮摘要)、`absent`(该轮没有改动记录)、`unavailable`(宿主没有 `workspaceChanges` 服务、会话休眠、宿主重启后摘要丢失或读取超时)。后两者 `files` 为空,App 不渲染改动卡、不占位。
1283
+ - `files[].seq` 是该轮最新 `workspace/changes` 事件的持久序号(供预览与 diff 坐标);`index` 是该文件在宿主摘要中的下标。
1284
+ - `files[].display` 由插件按记录路径 + 会话 cwd **重新派生**(工作目录内相对路径、家目录为 `~/…`,其余仅 basename),不透传宿主 display,因此响应**不包含可拼接的绝对路径**(issue #60 R05)。
1285
+ - `files[].id`:记录路径归一化(相对路径按 cwd 展开、realpath 别名解析)后的 SHA-256 前 16 位,只用于同一逻辑文件在 presented/changed 之间去重与行内链接;不可逆、不携带路径(issue #60 R08/F2)。旧插件无该字段时 App 按坐标保守处理。
1286
+ - `truncated`:受宿主 `maxFiles`(默认 500)与移动端上限(200)截断时为 `true`,`total` 仍是全量计数。
1287
+ - 稳定错误:`400 bad-request`(缺参/非法 turn)、`503 sessions-unavailable`。服务不可用**不**返回 5xx,按 `state: "unavailable"` 返回,便于 App 统一降级。
1288
+
1289
+ ### 6.22 GET /m/api/changes/diff(本轮单文件对比,issue #53)
1290
+
1291
+ **查询参数**:`sessionId`、`turn`、`index`(均必填,非负整数)。
1292
+
1293
+ **响应(文本)**:
1294
+
1295
+ ```json
1296
+ {
1297
+ "ok": true,
1298
+ "state": "available",
1299
+ "diff": {
1300
+ "kind": "text",
1301
+ "display": "src/a.ts",
1302
+ "before": true,
1303
+ "after": true,
1304
+ "coarse": false,
1305
+ "diff": "--- a/src/a.ts\n+++ b/src/a.ts\n@@ -1,3 +1,4 @@\n ...",
1306
+ "truncated": false
1307
+ }
1308
+ }
1309
+ ```
1310
+
1311
+ - 宿主返回 `{ kind, display, before, after, hunks, coarse }`;插件把 hunks 渲染成统一 diff 文本(`---`/`+++`/`@@`),供 App 复用 `GitFileViewer` 差异模式,并限制文本体积(512 KiB,超出 `truncated: true`)。
1312
+ - `kind` 为 `binary` / `oversized` 时只带 `display` 与原因式 `kind`,App 显示不可比对提示。
1313
+ - `coarse: true` 表示宿主逐行对比超时后退化为整文件替换。
1314
+ - `display` 与统一 diff 的 `---/+++` 标头同样由插件按记录 path + 会话 cwd 重新派生;`binary`/`oversized` 分支也只返回安全 display,不直通宿主 display(issue #60 R05)。
1315
+ - 稳定错误:`400 bad-request`、`404 diff-not-found`(摘要已失效或下标不存在)、`503 changes-unavailable`。
1316
+
1317
+ ### 6.23 GET /m/api/turn-file(按轮末记录坐标读取文件,issue #53)
1318
+
1319
+ **查询参数**:`sessionId`、`kind`(`presented` | `changed`)、`seq`(记录事件序号)、`index`(文件下标,均必填)。
1320
+
1321
+ - `kind=presented`:`seq` 为 `deliverables/presented` 事件序号;`index` 为该事件 `files` 下标。
1322
+ - `kind=changed`:`seq` 为 `workspace/changes` 事件序号;`index` 为摘要 `files` 下标。
1323
+
1324
+ **响应**:文件字节流;头部与 `/m/api/files` 一致(`content-type`、`content-length`、`content-disposition`、`etag`、`last-modified`、`accept-ranges`、`connection: close`,支持 `Range`/`HEAD`,见 §6.17)。
1325
+
1326
+ **与 `/m/api/files` 的边界**:本端点**不接受客户端指定路径**,路径由服务端从会话记录解析;只允许该记录内的文件(GitLab #16 的收紧方向)。读取失败不泄露主机路径。
1327
+
1328
+ - 稳定错误:`400 bad-request`、`404 record-not-found`(事件不存在/不属于该会话/下标越界)、`404 file-not-found`(记录内的文件已被删除)、`503 changes-unavailable`(改动摘要已失效)。
1329
+
1330
+ ### 6.24 工具卡结构化投影(v3.3–v3.4,issue #54 / #66 / #67 / #68,M3 Batch 1–2)
1331
+
1332
+ 手机端工具卡从「通用卡」升级为「按工具类型专用卡」。服务端只做**结构化投影**,不改变工具执行语义;所有字段只增不改,旧 App 忽略。
1333
+
1334
+ **能力位**(`GET /m/api/bootstrap` 与 SSE `hello` 同判据、同形状):
1335
+
1336
+ ```json
1337
+ "capabilities": {
1338
+ "toolCards": {
1339
+ "version": 1,
1340
+ "tools": ["bash","pwsh","read","write","edit","grep","glob","web_fetch","web_search","read_image","todo_write","ask_user_question","skill"],
1341
+ "ptc": { "version": 1 }
1342
+ }
1343
+ }
1344
+ ```
1345
+
1346
+ - `tools` 是本插件**实际能投影**的工具名集合;App 逐工具决定是否使用专用卡,不在集合内一律回退通用卡。
1347
+ - `ptc`(v3.4,issue #68):PTC 子调用树能力位;App 仅在 `ptc.version >= 1` 时把 `tool/ptc-dispatch*` 的结构化 data 合入根工具卡(见 §6.24.1)。
1348
+ - 旧插件不下发该字段 → 新 App 全部通用卡(不按版本号推断,ADR 0017);新插件多出的 `ptc` 键被旧 App 忽略。
1349
+
1350
+ **`tool/call` 摘要增量 `summary`**(从原始 `arguments` 解析,先解析后 clamp;非法 JSON/未知工具 fail-open):
1351
+
1352
+ | 字段 | 类型 | 适用 | 说明 |
1353
+ |---|---|---|---|
1354
+ | `kind` | string | 全部 | `command` / `file` / `search` / `web` / `image` |
1355
+ | `tool` | string | 全部 | 工具名 |
1356
+ | `command` | string | bash/pwsh | 单行化命令,≤200 字 |
1357
+ | `workdir` | string? | bash/pwsh | 显示用目录(`mobileDisplayPath`),非绝对路径 |
1358
+ | `background` | bool? | bash/pwsh | 后台调用标志 |
1359
+ | `description` | string? | bash/pwsh | 工具自带的说明,≤120 字 |
1360
+ | `filePath` | string | read/write/edit/read_image | 显示用路径,**绝不下发可拼接绝对路径** |
1361
+ | `relative` | string? | read/write/edit/read_image | 仅当目标完整验证通过时下发:会话 cwd 相对、POSIX `/`、无前导 `/`/盘符/`.`/`..`/空段、≤300 字且**绝不截断**;与 `previewable` 严格同现(issue #67) |
1362
+ | `previewable` | bool? | read/write/edit/read_image | 唯一值 `true`(与 `relative` 同现,**不发 `false`**);缺省 = 不可预览(fail-closed,issue #67) |
1363
+ | `offset` / `limit` | number? | read | 行范围(正整数,可缺省) |
1364
+ | `sizeKb` | number? | write/edit | `ceil(UTF-16 长度/1024)`,与桌面 `NKB` 同口径 |
1365
+ | `added` / `deleted` | number? | write/edit | 折叠行行数统计;write 为新增行数,edit 为**行数近似**(见口径) |
1366
+ | `diff` | string? | write/edit | 统一 diff 文本,仅 ≤8 KiB 时下发 |
1367
+ | `diffTruncated` | bool? | write/edit | diff 超过上限而为缺省时为 `true`(不截半段) |
1368
+ | `pattern` | string | grep/glob | 搜索模式,≤200 字 |
1369
+ | `path` | string? | grep/glob | 搜索路径显示名 |
1370
+ | `include` | string? | grep | include 过滤 |
1371
+ | `url` | string? | web_fetch | 目标 URL |
1372
+ | `query` | string? | web_search | 首个查询词 |
1373
+
1374
+ **`tool/result` 摘要增量 `summary`**(从未 clamp 的原始结果文本/宿主 meta 解析,解析不到缺省):
1375
+
1376
+ | 字段 | 类型 | 适用 | 说明 |
1377
+ |---|---|---|---|
1378
+ | `exitCode` | number? | bash/pwsh | 从结果文本 `[exit code: N]` 标记解析 |
1379
+ | `signal` | string? | bash/pwsh | 从 `[killed by signal: X]` 解析 |
1380
+ | `stopped` | string? | bash/pwsh | 从 `[stopped: …]` 解析;App 显示「已停止」胶囊 |
1381
+ | `resultCount` | number? | grep/glob | 匹配总数:优先宿主 `meta.total`(meta 本身不透传),缺失时按稳定文本句式解析 |
1382
+
1383
+ **显式口径**:
1384
+
1385
+ 1. `summary.stopped` 为契约外新增的**可选**字段(需求只要求解析 `[stopped: …]`),保留并作为「已停止」语义。
1386
+ 2. write 的 `diff` 为「全新增」统一 diff;edit 的 `added`/`deleted` 是 **old/new 行数近似**,不承诺与宿主精确行级统计一致。
1387
+ 3. `resultCount` 的文本兜底是启发式(如 glob 在结果上限内按非空行计数);无 meta 且无工具名时保守缺省,不猜。
1388
+ 4. 全部字段 fail-open:字段异常/超长/非法 JSON 一律忽略并回退通用卡,不得让摘要、历史或 SSE 出错。
1389
+ 5. 路径安全:`filePath`/`workdir`/`path` 只下发 `mobileDisplayPath` 派生结果,不提供可直接读取的主机路径。
1390
+
1391
+ **路径可预览口径(issue #67,M3 Batch 2-B)**:
1392
+
1393
+ 折叠行路径可点进「会话文件预览」的安全契约。服务端只做**判定与相对化**,不新增任何读取端点。
1394
+
1395
+ 1. **计算顺序即安全边界**:原始 `args.file_path`/`args.filePath` 词法校验(零 fs 调用:非空 String、无 NUL、无首尾空白、只剥一次前导 `./`、拒绝空段/`.`/`..`/含 `:` 段;UNC 归一后含空段即在此步拒绝,盘符路径按绝对路径形态处理)→ 会话 cwd `realpath` + `isDirectory`(缺失/非法 fail-closed)→ 词法夹取(绝对路径必须**词法与 realpath 都在 cwd 内**才换算成相对路径;cwd 外绝对路径**不做任何 fs 探测**——此承诺仅指 **preview 判定**;同一摘要的 `display` 派生沿用 #54/#60 既有 `mobileDisplayPath`→`canonicalWorkspacePath`,会为合并 cwd 符号链接别名而对已给出的绝对路径祖先做 realpath,语义未改、不属于 #67 新增探测面)→ 候选 `realpath` containment(拒绝符号链接逃逸)→ `isFile` → `R_OK`。
1396
+ 2. **两字段严格同现**:任一步失败 → `relative` 与 `previewable` **一起省略**(不存在 `previewable:false`)。目录/缺失/不可读/FIFO/设备/超长(>300,不截断)/非法 cwd 一律缺省;符号链接目标仍在 cwd 内则允许,`relative` 保留用户路径的**词法形状**(如 `link/x`,realpath 只当闸门)。
1397
+ 3. **显示与点击分离**:折叠行显示文本仍用 `filePath`(安全 display),点击目标只用 `relative`;二者不得互相推导(display 可能被 clamp,或为 `~/…`/basename)。
1398
+ 4. **App 二次夹取**:只认 `previewable === true && relative` 合法;拼路径前再拒绝绝对/盘符/反斜杠/`.`/`..`/空段/超长/首尾空白/NUL,并用会话 cwd 做 `isWithinRoot` 夹取,失败视为不可点(零请求)。唯一拼接点是与预览页共用的控制器。
1399
+ 5. **边界不变**:不新增端点、不改 `/m/api/files` 语义、不改 `display`;能力位 `toolCards.version` 仍为 `1`(旧 App 忽略新字段,新 App 缺字段即纯文本)。
1400
+ 6. **已知边界**:`tool/call` 摘要发生在工具执行**前**,实时 `write` 新建文件当刻不可预览,历史重投影后才可点;读取侧 realpath 夹取不在本 issue 范围(#16 独立跟踪)。
1401
+
1402
+ ### 6.24.1 PTC 子调用投影(v3.4,issue #68 / M3 Batch 2-C)
1403
+
1404
+ `run_code`(PTC 模式)里每个嵌套工具调用由内核落一对会话事件 `tool/ptc-dispatch-start` / `tool/ptc-dispatch`;本插件把它们投影为**结构化子调用事件**,供 App 挂到根 `run_code` 工具卡下。事件本身仍属 debug-only:普通模式不渲染裸事件卡,`/event-detail` 详情 allow-list **不放行**(无 detail 指针)。
1405
+
1406
+ **事件字段**(`{ seq, type, time?, data }`;`data` 投影自内核载荷,只增不改):
1407
+
1408
+ | 字段 | 类型 | start | result | 说明 |
1409
+ |---|---|---|---|---|
1410
+ | `turn` / `step` | number? | ✓ | ✓ | 由原始会话事件(`turn/start`/`step/start`)派生;派生不到则省略,**不用 0 伪造** |
1411
+ | `rootCallId` | string? | ✓ | ✓ | 外层 `run_code` 的 callId;非法/缺失时省略 |
1412
+ | `parentCallId` | string | 必填 | 必填 | 直接父调用(根或另一子调用);缺失/非法 → 整条无 `data`(事件仍在) |
1413
+ | `callId` | string | 必填 | 必填 | **内核 `subCallId`**(形如 `<parentCallId>:ptc:<n>`);App 按它原地合并 start→result |
1414
+ | `name` | string? | ✓ | ✓ | 工具名,≤120 字 |
1415
+ | `status` | string | `"running"` | `"success"` / `"failed"` | `failed` 当且仅当内核 `isError === true` |
1416
+ | `summary` | object? | ✓ | ✓ | 复用 `tool/call` 的安全摘要(见 §6.24)经 PTC 紧凑白名单裁剪:`kind`/`tool` + command/file/search/web/image/todo/question/skill 的折叠行字段;**丢弃** `diff`/`diffTruncated`/`relative`/`previewable`;自由文本 `command`/`description` 再做主机路径脱敏(cwd→`.`、homedir→`~`、剩余绝对路径→`…/<basename>`;带引号/转义空格的路径整体脱敏,`path:`/`--flag=`/`file:` 边界与盘符边界正确,http(s) URL 保留);单条 `JSON ≤ 2048` 字节,超限整份降级为 `{kind,tool}` |
1417
+ | `text` | string? | — | ✓ | **仅失败时**下发,且只含**合法安全码**(`^[A-Za-z][A-Za-z0-9_.-]{0,63}$`,对**原串**严格验证,含空白/换行即非法):合法 `error.code` 优先、否则合法 `error.name`,≤500;两者都不合法 → 省略;**绝不**取 `content`/`arguments`/`meta`/`error.reason`(工具输出可能含绝对路径) |
1418
+ | `isError` | bool | — | 必填 | 成功也显式下发 `false` |
1419
+ | `error` | object? | — | 仅失败 | 只含 `{ name, code }`,且 name 与 code **都**符合安全码语法才整对象下发(各 ≤120 字);任一不合法 → 省略;**无 `reason`** |
1420
+ | `truncated` | bool | 可能 | 可能 | 超 50 子调用的最小截断通知(无 turn/step/summary/text/isError/error),见下 |
1421
+
1422
+ **安全与体积**:永不下发 `arguments` 原文、`meta`、`content`/`images`、`error.reason`、绝对主机路径(`summary` 内结构路径均为 `mobileDisplayPath` 派生,自由文本 `command`/`description` 另做上述脱敏)。缺 `data`/非法 id → 该事件无 `data`(`{seq,type}`,事件仍保留);坏 `content`/坏 `error` 被**忽略并正常投影**(`content` 完全不参与投影),绝不抛错(`/history`、SSE 与契约自检共用同一 `summarizeEvent` 分支)。
1423
+
1424
+ **50 子调用上限**:按 `rootCallId` 分组、以 `callId` 去重计数(同一子调用的 start/result 只占 1 个名额)。前 50 个正常投影;第 51 个新 `callId` 的首个事件下发**最小截断通知**(仅 `rootCallId?/parentCallId/callId/name?/status` + `truncated: true`,**无 turn/step/summary/text/isError/error**),同一计数作用域最多一条;此后该 root 的其它超限事件降级为**无 `data` 的 `{seq,type}`**(事件仍保留,通用顶层 `time` 等既不删除也不改写;App 据此显示「已截断」)。计数作用域:`/history` 每响应一个,SSE 每会话一个(进程内按插入序 FIFO 有界逐出,不做触碰刷新)。
1425
+
1426
+ **App 消费约束**:根工具卡折叠行显示「N 个子调用」;展开后每个子调用只显示名称 + 状态 + 安全摘要,**不提供** args/结果二级展开、不显示图片;子调用不进入 M1 过程行;默认收起、失败不自动展开;无 `toolCards.ptc` 能力位时完全降级(不显示计数/子行)。
1427
+
1428
+
1429
+ ### 6.24.2 todo_write / ask_user_question / skill 专用行(v3.4,issue #66 / M3 Batch 2-A)
1430
+
1431
+ `toolCards.tools` 追加 `todo_write`、`ask_user_question`、`skill`;三者仍走 `tool/call`/`tool/result` 的 `summary`,字段只增不改,旧 App 忽略。
1432
+
1433
+ **`tool/call` 摘要**
1434
+
1435
+ | 字段 | 类型 | 适用 | 说明 |
1436
+ |---|---|---|---|
1437
+ | `kind` | string | 三者 | `todo` / `question` / `skill` |
1438
+ | `tool` | string | 全部 | 工具名 |
1439
+ | `items` | array | todo_write | `[{content,status}]`,≤50 项;`content` ≤200 字、`status ∈ pending/in_progress/completed`(未知归 pending);`counts` 与归一后的 items 一致(三项和 = items.length) |
1440
+ | `counts` | object | todo_write | `{pending,inProgress,completed}`(整数,恒带三键) |
1441
+ | `questions` | array | ask_user_question | `[{header?, question, options?:[{label,description?}], multiSelect?}]`;≤10 题、每题选项 ≤20;`header` ≤120、`question` ≤500、`label` ≤200、`description` ≤300 字 |
1442
+ | `name` | string | skill | 技能名,≤120 字 |
1443
+
1444
+ **`tool/result` 摘要**
1445
+
1446
+ | 字段 | 类型 | 适用 | 说明 |
1447
+ |---|---|---|---|
1448
+ | `answers` | array | ask_user_question | `[{questionId, values:[string…]}]`;只读回放,题号/取值不做解释或补全;缺失即缺省(不猜) |
1449
+
1450
+ **口径**:非法/缺失参数 fail-open(能安全投影的字段才下发,其余省略并回退通用卡);`todo_write` 的非数组 `todos` 只回 `{kind,tool}`;未知状态归 `pending`;不修改 attention/`/respond` 流程;`answers` 不回写、不做校验错误提示。PTC 子调用内的同名工具走 §6.24.1 的紧凑白名单摘要。
1451
+
1452
+ ### 6.24.3 客户端侧交付(无 API 变更)
1453
+
1454
+ - **图库增强(issue #69)**:附图全屏查看器、多图分页、尺寸/名称/mediaType 元数据、保存/分享、失败重试;仍使用既有 `images[]` 元数据与 `/m/api/attachment`,服务端契约不变。
1455
+ - **实时思维链(issue #70)**:`assistant/chunk` 的 reasoning delta 仅由 App 生成 provisional 过程行并在落定后去重;无新字段/端点。
1456
+ - **diff 视图收尾(issue #71)**:整块横向滚动、固定行号列、大 diff 懒构建;`/changes/diff` 契约不变。
@@ -75,6 +75,20 @@
75
75
  - `trustedHosts`(v2.4.2+):隧道/中继类方案(frp/SakuraFrp 托管)下请求 Host 是中继地址,需在此显式放行(配合强口令);纯虚拟组网/局域网无需配置。
76
76
  ## 6. 数据安全
77
77
 
78
+ ### 文件与工作目录的权限边界(issue #68)
79
+
80
+ `GET /files`、`GET/POST /directories` 允许访问宿主进程有权限的显式路径;空目录路径可列根视图,读取会跟随符号链接。会话文件浏览页面的工作目录边界和隐藏 `.git` 只限制界面导航,不是服务端授权边界。
81
+
82
+ 同一认证身份还能通过 `POST /sessions {cwd}` 注册新的工作目录。因此仅按“已注册工作区”过滤文件接口无法限制持有口令的客户端:它可以先注册更大的目录。本轮保留任意新目录建会话的行为,不引入可被该入口绕过的访问控制承诺。若要增加受限身份,需要一并设计宿主批准的根目录、`realpath` / 符号链接检查和工作目录注册授权;不能只更改文件下载接口。当前权限上限由宿主操作系统身份、沙箱与可信传输控制。
83
+
84
+ ### 工作区图片端点(`/m/api/workspace-image`,issue #95)
85
+
86
+ 该端点比通用文件传输更窄:只允许当前会话 cwd 内、cwd 属于已登记工作区的普通图片,且使用 **fd 绑定**读取:`open(O_RDONLY|O_NOFOLLOW|O_NONBLOCK)` 后以 `fstat` 与 `/proc/self/fd/<fd>` 的实际路径做 cwd/工作区 containment,再 `readSync(fd)` 有界读取并 `finally close`;不再按路径二次 `stat`/`readFileSync`。末级 symlink 被 `O_NOFOLLOW` 拒绝,中间目录换链由 fd 实际路径校验拒绝。非 Linux/无 procfs/无 O_NOFOLLOW 一律 `501 image-verification-unavailable`,**fail-closed,不回退**。
87
+
88
+ 已知/接受边界:hardlink 与 bind-mount 的同用户场景不在本端点威胁模型内;8 MiB/8192px/40MP 上限;HEAD 仍完整读取以生成强 ETag。通用 `/files*` 的既有任意路径/符号链接边界见上节,二者不可混用。
89
+
90
+ ### 持久化与投递
91
+
78
92
  - 插件**持久化仅限最小移动端状态**(`~/.dsh/mobile-remote/`:通知已读 id、会话最近活跃时间),不含会话内容;口令只存在于 profile 配置。
79
93
  - 会话内容沿用 dsh 现有策略存储;插件仅在请求处理期间持有内存副本。
80
94
  - **二维码数据端点 `/m/api/qr-config` 仅允许 loopback**(TCP socket 来源校验,无法伪造)—— 桌面设置页读取后展示二维码;二维码含地址+口令,请勿截屏转发。