@marktrue/dsh-mobile-remote 3.2.4-alpha.8 → 3.2.4-alpha.9
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/CHANGELOG.md +36 -0
- package/docs/03-api.md +6 -3
- package/lib/endpoint-registry.js +11 -3
- package/lib/index.js +291 -38
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v3.2.4-alpha.9(build 41,issues #29 / #32 / #33 等)— 身份/轮末/工具卡复核修复
|
|
4
|
+
|
|
5
|
+
> 插件 `3.2.4-alpha.9` / App `3.2.4+41` / 载体 `3.2.4-alpha.9-app`。
|
|
6
|
+
|
|
7
|
+
### 身份与诊断安全(attention / review 修复)
|
|
8
|
+
|
|
9
|
+
- 宿主通知身份改用稳定 hostId:并发发布改为「身份文件 wx 单赢家」+ 显式状态机,无锁不得发布;bootstrap 权威必须替换或清空旧 hostId;通知 scope 改用宿主稳定身份。
|
|
10
|
+
- 审批身份按**实际请求**唯一(`callId` 仅作关联),重连恢复用例从真实 requested frame 取身份;身份赢家回读校验内容,发现同 inode 原地覆写;quarantine 恢复改用 link 原子发布,不覆盖并发赢家。
|
|
11
|
+
- 修复诊断信息泄露与文件身份竞态(复核 P1/P2 系列)。
|
|
12
|
+
|
|
13
|
+
### 轮末两卡(turn-tail)
|
|
14
|
+
|
|
15
|
+
- 交付文件用**不泄路径的稳定身份**去重;行内链接按逻辑文件身份合并 delivered/changed;`recordFileId` 归一路径后再哈希(混合 abs/rel 共享同一逻辑身份)。
|
|
16
|
+
- 多次 `present` 按持久记录坐标取最新声明;旧插件兼容仅允许两类各一个去重坐标合并。
|
|
17
|
+
- diff 页切换文件后按请求代际丢弃旧响应;改动摘要请求引入 load generation 与 in-flight 门闩;摘要/diff 重新派生安全 display。
|
|
18
|
+
|
|
19
|
+
### 工具卡(tool-cards)
|
|
20
|
+
|
|
21
|
+
- 失败态同时保留真实错误原因与通用参数;`callId` 从真实 `tool/result` 形状解析并关联命令工具;终止状态只在已关联命令工具时展示;只解析结果末尾的宿主终止 trailer;无内联 diff 时回退通用参数与结果。
|
|
22
|
+
|
|
23
|
+
### turn-process 与 canary
|
|
24
|
+
|
|
25
|
+
- 缺 `turn/start` 的部分轮次保留轮次身份;过程抬头与轮次页脚随语言设置本地化。
|
|
26
|
+
- 宿主兼容 canary:install/runtime 错误码白名单收窄并统一为单一常量来源;缺依赖具体码纳入下游白名单;路径归一与 quarantine 恢复修复;隔离宿主原生加载与诊断链路修复;fake-host 身份文件原子发布;移除临时诊断输出。
|
|
27
|
+
|
|
28
|
+
### 测试与 CI 稳定性
|
|
29
|
+
|
|
30
|
+
- 宿主身份新契约(身份不可发布即拒绝启动)适配只读夹具:预置合法 host-identity 后只让 auth-token/默认更新目录写入失败,保留原有降级断言。
|
|
31
|
+
- host-canary-smoke 的 fake-host 已知抖动夹具(KNOWN-FLAKY #40)仅放宽计时窗口,不改安全断言。
|
|
32
|
+
|
|
33
|
+
### 工具链
|
|
34
|
+
|
|
35
|
+
- `sync-upstream`:403 结合响应原因区分缺失 Workflows 权限与分支保护。
|
|
36
|
+
- endpoint registry:`/turn-file` 方法契约改为 `GET/HEAD`;时间线契约检查同步更新。
|
|
37
|
+
- 文档:ADR 记录展示身份、宿主/审批身份相关复核决策。
|
|
38
|
+
|
|
3
39
|
## v3.2.4-alpha.8(build 40,issues #61 / #62)— 免重启插件更新与轮次 UI 收尾
|
|
4
40
|
|
|
5
41
|
> 插件 `3.2.4-alpha.8` / App `3.2.4+40` / 载体 `3.2.4-alpha.8-app`。
|
package/docs/03-api.md
CHANGED
|
@@ -128,6 +128,7 @@
|
|
|
128
128
|
|
|
129
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
130
|
- `capabilities.toolCards`:工具卡结构化能力位(v3.3,issue #54):`{ "version": 1, "tools": [本插件实际投影的工具名…] }`;bootstrap 与 SSE hello 同判据,App 逐工具决定专用卡或通用卡,缺失时全部通用卡(见 §6.24)。
|
|
131
|
+
- `plugin.hostId`:宿主**稳定身份**(随机 UUID,持久化于插件状态目录;与访问口令、`instanceId` 无关,issue #60 R15)。手机用它隔离通知账本(同口令的不同宿主不得互相撤销);旧插件缺失该字段时 App 回退既有 scope。
|
|
131
132
|
|
|
132
133
|
- 未认证:`401`(见通用约定)。
|
|
133
134
|
### 3.2 POST /m/api/send
|
|
@@ -306,7 +307,7 @@
|
|
|
306
307
|
| `agent/status` | `{ agentId, sessionId, status, child }`——`status` 只有 `running` / `idle` 两值(内核 `AgentStatus` 即为二元联合);`sessionId` 为去 `session:` 前缀的会话 id,`child` 标记子代理会话(v2.7.2 起携带后两字段)。**不存在 `waiting`**:等待用户审批/作答时 agent 仍为 `running`,该事实由 `mobile/frame` 的挂起问询/审批承载 |
|
|
307
308
|
| `notifications/changed` | 通知记录增删(如移动端删除后),客户端刷新列表与角标 |
|
|
308
309
|
| `mobile/notify` | `{ notification: { id, kind, sessionId, title, detail, time } }`——插件"真结束"判定后推送的通知(completed / failed / needs-answer),桌面宠物/App 与通知中心同源渲染(v2.7.2) |
|
|
309
|
-
| `mobile/frame` | 内核瞬态帧(问询/审批)。`frame` 字段为 `question/requested`(含 `rpcId`、`questions[]`)、`question/resolved`(`questionRpcId`)、`approval/requested`(`rpcId`、`approvalId`、`toolName`、`reason?`)、`approval/resolved`(`approvalId
|
|
310
|
+
| `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` 回放) |
|
|
310
311
|
| `mobile/queue` | `{ sessionId, rows: [{ id, text, placement }] }`——内核队列快照(`agent/inbox/spliced` 即时镜像,v3.0.2):认领/删除/编辑实时反映,App 端 dock 以此为权威源(`placement`: `queued` / `steering` / `context`,与 GET /queue 同款形状);断线重连时 mux 回放当前队列 |
|
|
311
312
|
| `attention/snapshot` | `{ version: 1, pending: [{ kind, sessionId, identity }] }`——在断线重连的 `mobile/frame` 挂起帧回放**之后**、同一有序 SSE 流上追加的**完整待办快照边界**(v3.3)。App 只据此撤销该宿主已不在 pending 中的业务通知,不得凭超时猜测待办已结束;旧宿主无此帧时保留既有行为 |
|
|
312
313
|
| `git/changed`(规划中) | 设计目标为 `{ repositoryId }`;当前版本未实现 Git provider,也不会推送此帧 |
|
|
@@ -1225,7 +1226,7 @@ graph 的每个提交与 commit 详情都**保留旧的** `refs: string[]`(dep
|
|
|
1225
1226
|
"state": "available",
|
|
1226
1227
|
"turn": 12,
|
|
1227
1228
|
"files": [
|
|
1228
|
-
{ "seq": 843, "index": 0, "display": "src/a.ts", "name": "a.ts",
|
|
1229
|
+
{ "seq": 843, "index": 0, "id": "a1b2c3d4e5f60718", "display": "src/a.ts", "name": "a.ts",
|
|
1229
1230
|
"added": 12, "deleted": 3, "binary": false, "oversized": false }
|
|
1230
1231
|
],
|
|
1231
1232
|
"total": 5,
|
|
@@ -1237,7 +1238,8 @@ graph 的每个提交与 commit 详情都**保留旧的** `refs: string[]`(dep
|
|
|
1237
1238
|
|
|
1238
1239
|
- `state` 三态:`available`(宿主仍有该轮摘要)、`absent`(该轮没有改动记录)、`unavailable`(宿主没有 `workspaceChanges` 服务、会话休眠、宿主重启后摘要丢失或读取超时)。后两者 `files` 为空,App 不渲染改动卡、不占位。
|
|
1239
1240
|
- `files[].seq` 是该轮最新 `workspace/changes` 事件的持久序号(供预览与 diff 坐标);`index` 是该文件在宿主摘要中的下标。
|
|
1240
|
-
- `display`
|
|
1241
|
+
- `files[].display` 由插件按记录路径 + 会话 cwd **重新派生**(工作目录内相对路径、家目录为 `~/…`,其余仅 basename),不透传宿主 display,因此响应**不包含可拼接的绝对路径**(issue #60 R05)。
|
|
1242
|
+
- `files[].id`:记录路径归一化(相对路径按 cwd 展开、realpath 别名解析)后的 SHA-256 前 16 位,只用于同一逻辑文件在 presented/changed 之间去重与行内链接;不可逆、不携带路径(issue #60 R08/F2)。旧插件无该字段时 App 按坐标保守处理。
|
|
1241
1243
|
- `truncated`:受宿主 `maxFiles`(默认 500)与移动端上限(200)截断时为 `true`,`total` 仍是全量计数。
|
|
1242
1244
|
- 稳定错误:`400 bad-request`(缺参/非法 turn)、`503 sessions-unavailable`。服务不可用**不**返回 5xx,按 `state: "unavailable"` 返回,便于 App 统一降级。
|
|
1243
1245
|
|
|
@@ -1266,6 +1268,7 @@ graph 的每个提交与 commit 详情都**保留旧的** `refs: string[]`(dep
|
|
|
1266
1268
|
- 宿主返回 `{ kind, display, before, after, hunks, coarse }`;插件把 hunks 渲染成统一 diff 文本(`---`/`+++`/`@@`),供 App 复用 `GitFileViewer` 差异模式,并限制文本体积(512 KiB,超出 `truncated: true`)。
|
|
1267
1269
|
- `kind` 为 `binary` / `oversized` 时只带 `display` 与原因式 `kind`,App 显示不可比对提示。
|
|
1268
1270
|
- `coarse: true` 表示宿主逐行对比超时后退化为整文件替换。
|
|
1271
|
+
- `display` 与统一 diff 的 `---/+++` 标头同样由插件按记录 path + 会话 cwd 重新派生;`binary`/`oversized` 分支也只返回安全 display,不直通宿主 display(issue #60 R05)。
|
|
1269
1272
|
- 稳定错误:`400 bad-request`、`404 diff-not-found`(摘要已失效或下标不存在)、`503 changes-unavailable`。
|
|
1270
1273
|
|
|
1271
1274
|
### 6.23 GET /m/api/turn-file(按轮末记录坐标读取文件,issue #53)
|
package/lib/endpoint-registry.js
CHANGED
|
@@ -33,8 +33,16 @@ export function extractEndpointDetails(source) {
|
|
|
33
33
|
if (out.has(path)) continue;
|
|
34
34
|
const next = markLines.find((l) => l > index);
|
|
35
35
|
const segment = lines.slice(index, next ?? Math.min(lines.length, index + 400)).join("\n");
|
|
36
|
+
// 路由**头部**(分派行 + 紧随其后的 2 行)才代表该端点的方法契约;块内更深处的
|
|
37
|
+
// GET/HEAD 分支(如 /goal 内部图片/下载分支)不能把整个端点判成 GET/HEAD。
|
|
38
|
+
const header = lines.slice(index, Math.min(lines.length, index + 3)).join("\n");
|
|
36
39
|
let methods = "GET/POST";
|
|
37
|
-
|
|
40
|
+
// issue #60 recheck-2(R02):头部显式 `(method === "GET" || method === "HEAD")`
|
|
41
|
+
// 必须抽成 GET/HEAD——HEAD 是真实分派语义,不能被默认成 GET/POST。
|
|
42
|
+
const allowsHead = /method\s*===\s*['"]GET['"]\s*\|\|\s*method\s*===\s*['"]HEAD['"]/.test(header);
|
|
43
|
+
const allowsPost = /method\s*===\s*['"]POST['"]/.test(segment) || /requirePost\(method,\s*res\)/.test(segment);
|
|
44
|
+
if (allowsHead && !allowsPost) methods = "GET/HEAD";
|
|
45
|
+
else if (/requireGet\(method,\s*res\)/.test(segment) || /method\s*!==\s*['"]GET['"]/.test(segment)) methods = "GET";
|
|
38
46
|
else if (/method\s*!==\s*['"]POST['"]/.test(segment)) methods = "POST";
|
|
39
47
|
out.set(path, methods);
|
|
40
48
|
}
|
|
@@ -119,7 +127,7 @@ export const REGISTERED_ENDPOINTS = Object.freeze([
|
|
|
119
127
|
{ path: "/event-detail", methods: "GET", capability: "eventTimeline" },
|
|
120
128
|
{ path: "/events", methods: "GET", capability: "eventTimeline" },
|
|
121
129
|
{ path: "/feedback", methods: "GET/POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
122
|
-
{ path: "/files", methods: "GET/
|
|
130
|
+
{ path: "/files", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
123
131
|
{ path: "/files/upload", methods: "GET/POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
124
132
|
{ path: "/git/branches", methods: "GET", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
125
133
|
{ path: "/git/capabilities", methods: "GET", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
@@ -160,7 +168,7 @@ export const REGISTERED_ENDPOINTS = Object.freeze([
|
|
|
160
168
|
{ path: "/subagents", methods: "GET", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
161
169
|
{ path: "/subagents/interrupt", methods: "GET/POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
162
170
|
{ path: "/todos", methods: "GET", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
163
|
-
{ path: "/turn-file", methods: "GET/
|
|
171
|
+
{ path: "/turn-file", methods: "GET/HEAD", capability: "turnTail" },
|
|
164
172
|
{ path: "/turn-outline", methods: "GET", capability: "turnOutline" },
|
|
165
173
|
{ path: "/update/apk", methods: "GET", capability: null, auth: "anonymous", why: NO_CAPABILITY_NEEDED },
|
|
166
174
|
{ path: "/update/manifest", methods: "GET", capability: null, auth: "required", why: NO_CAPABILITY_NEEDED },
|
package/lib/index.js
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
import { networkInterfaces, homedir } from "node:os";
|
|
11
11
|
import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
12
12
|
import {
|
|
13
|
-
accessSync, closeSync, constants, createReadStream, existsSync, fstatSync, mkdirSync, openSync,
|
|
14
|
-
rmSync, statSync, writeFileSync,
|
|
13
|
+
accessSync, closeSync, constants, createReadStream, existsSync, fstatSync, linkSync, mkdirSync, openSync,
|
|
14
|
+
readFileSync, readSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, unlinkSync,
|
|
15
15
|
} from "node:fs";
|
|
16
16
|
import { readdir } from "node:fs/promises";
|
|
17
17
|
import { join, sep, resolve, relative, isAbsolute, basename, dirname, extname } from "node:path";
|
|
@@ -343,6 +343,64 @@ export function pluginStateDir(home = homedir()) {
|
|
|
343
343
|
export function generatedAuthTokenFile(home = homedir()) {
|
|
344
344
|
return join(pluginStateDir(home), "auth-token");
|
|
345
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* 宿主的**稳定身份**文件(issue #60 R15):随机 UUID 持久化到插件状态目录。
|
|
348
|
+
* 与访问口令解耦:口令可被用户显式配置成相同值,不能拿它当宿主身份;同一宿主跨
|
|
349
|
+
* 重启/地址轮换保持不变,不同宿主(不同 home/状态目录)必然不同。
|
|
350
|
+
*/
|
|
351
|
+
export function hostIdentityFile(home = homedir()) {
|
|
352
|
+
return join(pluginStateDir(home), "host-identity");
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* 发布稳定宿主身份:先完整写私有文件,再以 hard link 原子、不可覆盖地发布。
|
|
357
|
+
* 已存在但无效的身份可能属于暂停的旧写入者;无法安全判定其死亡,绝不自动删除。
|
|
358
|
+
* 所有实例切换到本协议前须停止旧版宿主;恢复损坏文件前也须停止所有宿主并先备份。
|
|
359
|
+
* 首次发布要求同一文件系统支持 hard link;不可用时显式拒绝启动而非伪造稳定身份。
|
|
360
|
+
*/
|
|
361
|
+
export function resolveHostIdentity({ home = homedir(), onBeforePublish } = {}) {
|
|
362
|
+
const file = hostIdentityFile(home);
|
|
363
|
+
const valid = value => typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value.trim());
|
|
364
|
+
const readIdentity = () => {
|
|
365
|
+
try { const value = readFileSync(file, "utf8").trim(); return valid(value) ? value : null; }
|
|
366
|
+
catch { return null; }
|
|
367
|
+
};
|
|
368
|
+
const unavailable = () => Object.assign(new Error("host identity unavailable; stop all hosts and inspect the identity file"), { code: "HOST_IDENTITY_LOCK_UNAVAILABLE" });
|
|
369
|
+
const existing = readIdentity();
|
|
370
|
+
if (existing !== null) return existing;
|
|
371
|
+
let temporary;
|
|
372
|
+
try {
|
|
373
|
+
mkdirSync(pluginStateDir(home), { recursive: true, mode: 0o700 });
|
|
374
|
+
temporary = `${file}.candidate.${process.pid}.${randomBytes(12).toString("hex")}`;
|
|
375
|
+
const identity = randomUUID();
|
|
376
|
+
writeFileSync(temporary, `${identity}\n`, { flag: "wx", mode: 0o600 });
|
|
377
|
+
onBeforePublish?.();
|
|
378
|
+
try { linkSync(temporary, file); }
|
|
379
|
+
catch (err) {
|
|
380
|
+
if (err?.code !== "EEXIST") throw err;
|
|
381
|
+
// 旧版进程可能刚以 wx 创建空文件,给它有限时间写入;绝不清理占位。
|
|
382
|
+
const deadline = Date.now() + 3000;
|
|
383
|
+
while (Date.now() < deadline) {
|
|
384
|
+
const published = readIdentity();
|
|
385
|
+
if (published !== null) return published;
|
|
386
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
|
|
387
|
+
}
|
|
388
|
+
throw unavailable();
|
|
389
|
+
}
|
|
390
|
+
const published = readIdentity();
|
|
391
|
+
if (published !== null) return published;
|
|
392
|
+
throw unavailable();
|
|
393
|
+
} catch (err) {
|
|
394
|
+
const published = readIdentity();
|
|
395
|
+
if (published !== null) return published;
|
|
396
|
+
if (err?.code === "HOST_IDENTITY_LOCK_UNAVAILABLE") throw err;
|
|
397
|
+
// 只暴露固定错误码,不把宿主路径等系统错误正文写入日志。
|
|
398
|
+
throw Object.assign(new Error("host identity storage cannot publish an atomic hard link"), { code: "HOST_IDENTITY_STORAGE_UNAVAILABLE" });
|
|
399
|
+
} finally {
|
|
400
|
+
if (temporary) { try { unlinkSync(temporary); } catch { /* private candidate only */ } }
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
346
404
|
/** randomBytes(32) 的 base64url 恰好 43 个 URL-safe 字符。 */
|
|
347
405
|
const GENERATED_TOKEN_PATTERN = /^[A-Za-z0-9_-]{43}$/;
|
|
348
406
|
|
|
@@ -1781,6 +1839,65 @@ function sniffImageType(data) {
|
|
|
1781
1839
|
const posixPathText = (value) => String(value ?? "").replaceAll("\\", "/");
|
|
1782
1840
|
/** 是否绝对路径(POSIX 根 / Windows 盘符);`display` 派生只看文本,不依赖宿主平台。 */
|
|
1783
1841
|
const isAbsolutePathText = (value) => value.startsWith("/") || /^[A-Za-z]:\//.test(value);
|
|
1842
|
+
/**
|
|
1843
|
+
* issue #60 round7(F2):把「记录路径 + 会话 cwd」归一到同一规范绝对路径。
|
|
1844
|
+
* 宿主两条投影的路径形状可能不同:presented 常是 realpath 绝对路径(或相对),
|
|
1845
|
+
* changed 常是相对路径;两处 cwd 文本也可能不同(header.cwd 含 symlink 别名、
|
|
1846
|
+
* summary.cwd 是 realpath 或子目录)。只靠文本 resolve 会发散,故哈希/派生前统一:
|
|
1847
|
+
* 1) 仅对会话 cwd 做 realpath,合并同一工作目录的符号链接别名;
|
|
1848
|
+
* 2) 记录路径按 cwd 词法展开,保留各路径段(包括符号链接条目)作为文件身份。
|
|
1849
|
+
* 任何失败都 try/catch 兜底退回纯文本 resolve,**绝不因 realpath 抛错**、
|
|
1850
|
+
* 也绝不改变 id 的格式(仍是 sha256 前 16 hex、不可逆、不含可拼路径)。
|
|
1851
|
+
* 注意:本函数只在服务端内部用于派生 id / display,规范绝对路径绝不下发到任何响应。
|
|
1852
|
+
* @returns {string} 规范绝对路径文本;path 非法时返回空串。
|
|
1853
|
+
*/
|
|
1854
|
+
const canonicalWorkspacePath = (path, cwd) => {
|
|
1855
|
+
const text = normalizeServerPath(path);
|
|
1856
|
+
if (typeof text !== "string" || text === "") return "";
|
|
1857
|
+
if (typeof cwd !== "string" || cwd === "") return isAbsolute(text) ? resolve(text) : text;
|
|
1858
|
+
const lexicalCwd = resolve(normalizeServerPath(cwd));
|
|
1859
|
+
let canonicalCwd = lexicalCwd;
|
|
1860
|
+
try { canonicalCwd = realpathSync(lexicalCwd); } catch { /* unavailable cwd */ }
|
|
1861
|
+
const absolute = isAbsolute(text) ? resolve(text) : resolve(lexicalCwd, text);
|
|
1862
|
+
const within = (root, target) => {
|
|
1863
|
+
const rel = relative(root, target);
|
|
1864
|
+
return rel === "" || (!isAbsolute(rel) && rel !== ".." && !rel.startsWith(`..${sep}`));
|
|
1865
|
+
};
|
|
1866
|
+
// 只解析 cwd 本身的别名;保留记录相对路径每一段,包括末级/中间符号链接。
|
|
1867
|
+
// Git 工作区中符号链接条目和目标是不同记录,不能对文件全路径调用 realpath。
|
|
1868
|
+
if (within(lexicalCwd, absolute)) return resolve(canonicalCwd, relative(lexicalCwd, absolute));
|
|
1869
|
+
if (within(canonicalCwd, absolute)) return absolute;
|
|
1870
|
+
// 绝对路径可能通过 cwd 的另一别名进入工作区(如 /var/run 与 /run)。
|
|
1871
|
+
// 只寻找真实指向 cwd 的祖先;保留其后的每一段,即使中间条目是符号链接或不存在。
|
|
1872
|
+
let head = dirname(absolute);
|
|
1873
|
+
const suffix = [basename(absolute)];
|
|
1874
|
+
let entryPath = null;
|
|
1875
|
+
while (true) {
|
|
1876
|
+
// 取最外层 cwd 别名。内层 symlink 也可能恰好指回 cwd,不能把它当别名吞掉。
|
|
1877
|
+
try { if (realpathSync(head) === canonicalCwd) entryPath = resolve(canonicalCwd, ...suffix); }
|
|
1878
|
+
catch { /* 尚不存在或不可读:继续寻找更高祖先 */ }
|
|
1879
|
+
const parent = dirname(head);
|
|
1880
|
+
if (parent === head) break;
|
|
1881
|
+
suffix.unshift(basename(head));
|
|
1882
|
+
head = parent;
|
|
1883
|
+
}
|
|
1884
|
+
return entryPath ?? absolute;
|
|
1885
|
+
};
|
|
1886
|
+
/**
|
|
1887
|
+
* 记录内文件的**不泄路径稳定身份**(issue #60 round4-2 / R08):
|
|
1888
|
+
* 路径 SHA-256 前 16 位十六进制。presented 与 changed 两条投影必须使用同一 helper,
|
|
1889
|
+
* App 才能把同一逻辑文件在两种来源下合并(不可逆、不含主机前缀)。
|
|
1890
|
+
* @param {unknown} path 记录内的路径(绝对或相对)。
|
|
1891
|
+
* @param {unknown} cwd 会话工作目录(两处调用须同源,见 /changes/summary 的 idBase)。
|
|
1892
|
+
* @returns {string} 16 位 hex;path 非法时返回空串。
|
|
1893
|
+
*/
|
|
1894
|
+
export function recordFileId(path, cwd) {
|
|
1895
|
+
if (typeof path !== "string" || path === "") return "";
|
|
1896
|
+
const canonical = canonicalWorkspacePath(path, cwd);
|
|
1897
|
+
if (canonical === "") return "";
|
|
1898
|
+
return createHash("sha256").update(canonical).digest("hex").slice(0, 16);
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1784
1901
|
/** 不依赖宿主平台的 basename(`basename()` 在 Windows 路径上会保留反斜杠段)。 */
|
|
1785
1902
|
const posixBasenameOf = (value) => {
|
|
1786
1903
|
const text = posixPathText(value).replace(/\/+$/, "");
|
|
@@ -1801,14 +1918,71 @@ export function mobileDisplayPath(path, cwd) {
|
|
|
1801
1918
|
const text = posixPathText(path).trim();
|
|
1802
1919
|
if (text === "") return "";
|
|
1803
1920
|
if (!isAbsolutePathText(text)) return text.replace(/^\.\//, "");
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1921
|
+
// issue #60(F2):规范 cwd 及其别名、保留工作区内的词法条目后再比较,避免
|
|
1922
|
+
// presented 绝对路径落在 symlink 别名 cwd 的「文本之外」而退化成 basename,
|
|
1923
|
+
// changed 却是 `src/a.ts`(display 不一致 → App 精确链接丢失)。
|
|
1924
|
+
// canonicalWorkspacePath 只在服务端内部使用;返回的相对/`~/`/basename 满足 R05,
|
|
1925
|
+
// 绝不把规范绝对路径写进响应。
|
|
1926
|
+
const canonicalPath = posixPathText(canonicalWorkspacePath(text, cwd));
|
|
1927
|
+
let cwdText = typeof cwd === "string" && cwd !== "" ? posixPathText(cwd).replace(/\/+$/, "") : "";
|
|
1928
|
+
if (cwdText !== "") {
|
|
1929
|
+
try { cwdText = realpathSync(cwdText); } catch { /* cwd 不存在:退回原文本 */ }
|
|
1930
|
+
cwdText = posixPathText(cwdText).replace(/\/+$/, "");
|
|
1931
|
+
}
|
|
1932
|
+
if (cwdText !== "" && (canonicalPath === cwdText || canonicalPath.startsWith(`${cwdText}/`))) {
|
|
1933
|
+
const rel = canonicalPath.slice(cwdText.length).replace(/^\/+/, "");
|
|
1934
|
+
return rel === "" ? posixBasenameOf(canonicalPath) : rel;
|
|
1808
1935
|
}
|
|
1809
1936
|
const homeText = posixPathText(homedir()).replace(/\/+$/, "");
|
|
1810
|
-
if (homeText !== "" &&
|
|
1811
|
-
return posixBasenameOf(
|
|
1937
|
+
if (homeText !== "" && canonicalPath.startsWith(`${homeText}/`)) return `~/${canonicalPath.slice(homeText.length + 1)}`;
|
|
1938
|
+
return posixBasenameOf(canonicalPath);
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
/**
|
|
1942
|
+
* 从会话事件折叠 `callId → tool/call.name`(issue #60 R14):结果事件通常不带工具名,
|
|
1943
|
+
* 调用方用它在投影前解析"这次调用是什么工具",避免无名字时从内容猜终止状态。
|
|
1944
|
+
* @param {any[]} events 会话原始事件。
|
|
1945
|
+
* @returns {Map<string, string>}
|
|
1946
|
+
*/
|
|
1947
|
+
export function toolNamesOf(events) {
|
|
1948
|
+
const names = new Map();
|
|
1949
|
+
for (const event of events ?? []) {
|
|
1950
|
+
if (event?.type !== "tool/call") continue;
|
|
1951
|
+
const callId = event?.data?.callId;
|
|
1952
|
+
const name = event?.data?.name;
|
|
1953
|
+
if (typeof callId === "string" && callId !== "" && typeof name === "string" && name !== "") {
|
|
1954
|
+
names.set(callId, name);
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
return names;
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
/**
|
|
1961
|
+
* `tool/result` 的真实调用坐标(issue #60 recheck-4 / R14):
|
|
1962
|
+
* 当前内核把 callId 放在 `message.source.callId`、`message.toolCallId` 或
|
|
1963
|
+
* `message.content[].toolCallId`,**不在** `event.data.callId`。统一从这些位置提取,
|
|
1964
|
+
* 供摘要 callId、toolNamesOf 关联(history/SSE)与 App 生命周期合并共用。
|
|
1965
|
+
* @param {any} event tool/result 事件。
|
|
1966
|
+
* @returns {string} callId;无法确定时为空串。
|
|
1967
|
+
*/
|
|
1968
|
+
export function toolResultCallIdOf(event) {
|
|
1969
|
+
const data = event?.data ?? {};
|
|
1970
|
+
const message = data.message;
|
|
1971
|
+
const content = Array.isArray(message?.content) ? message.content : [];
|
|
1972
|
+
const candidates = [
|
|
1973
|
+
data.callId,
|
|
1974
|
+
data.toolCallId,
|
|
1975
|
+
message?.toolCallId,
|
|
1976
|
+
message?.source?.callId,
|
|
1977
|
+
];
|
|
1978
|
+
for (const block of content) {
|
|
1979
|
+
if (!block || typeof block !== "object") continue;
|
|
1980
|
+
candidates.push(block.toolCallId);
|
|
1981
|
+
if (Array.isArray(block.content)) {
|
|
1982
|
+
for (const inner of block.content) candidates.push(inner?.toolCallId);
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
return candidates.find((value) => typeof value === "string" && value !== "") ?? "";
|
|
1812
1986
|
}
|
|
1813
1987
|
|
|
1814
1988
|
/** 工具参数解析(issue #54):只接受 JSON 对象;非法/非对象一律 fail-open 返回 null。 */
|
|
@@ -1980,6 +2154,32 @@ export function toolCallSummaryOf(toolName, rawArguments, cwd) {
|
|
|
1980
2154
|
return summary;
|
|
1981
2155
|
}
|
|
1982
2156
|
|
|
2157
|
+
/**
|
|
2158
|
+
* 宿主的命令终止 trailer:`[exit code: N]` / `[killed by signal: X]` / `[stopped: …]`。
|
|
2159
|
+
*
|
|
2160
|
+
* issue #60 R13:这些标记由 bash/pwsh 在结果**末尾**追加;stdout 正文可能碰巧包含同样的
|
|
2161
|
+
* 字符串。因此只接受**最后一条**且其后仅剩空白(换行)的标记;signal/stopped/exit 三者
|
|
2162
|
+
* 互斥,按宿主追加顺序取最后一条(signal 优先于 stopped,二者都优先于 exit)。
|
|
2163
|
+
* @param {string} text 未 clamp 的结果文本。
|
|
2164
|
+
* @returns {{kind: "exit", exitCode: number} | {kind: "signal", signal: string} | {kind: "stopped", stopped: string} | null}
|
|
2165
|
+
*/
|
|
2166
|
+
function terminalTrailerOf(text) {
|
|
2167
|
+
if (typeof text !== "string" || text === "") return null;
|
|
2168
|
+
const pattern = /\[(exit code: (-?\d+)|killed by signal: ([^\]\n]+)|stopped: ([^\]\n]+))\]/g;
|
|
2169
|
+
let last = null;
|
|
2170
|
+
let match;
|
|
2171
|
+
while ((match = pattern.exec(text)) !== null) last = match;
|
|
2172
|
+
if (last === null) return null;
|
|
2173
|
+
// marker 必须位于结果末尾(允许尾随空白/换行);正文中间的类似文本一律不算。
|
|
2174
|
+
if (text.slice(last.index + last[0].length).trim() !== "") return null;
|
|
2175
|
+
if (matchPrefixSignal(last[3])) return { kind: "signal", signal: clampText(last[3].trim(), 40) };
|
|
2176
|
+
if (matchPrefixStopped(last[4])) return { kind: "stopped", stopped: clampText(last[4].trim(), 120) };
|
|
2177
|
+
return { kind: "exit", exitCode: Number(last[2]) };
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
const matchPrefixSignal = (value) => typeof value === "string" && value !== "";
|
|
2181
|
+
const matchPrefixStopped = (value) => typeof value === "string" && value !== "";
|
|
2182
|
+
|
|
1983
2183
|
/**
|
|
1984
2184
|
* `tool/result` 的结构化摘要(issue #54 §3):只从结果**文本标记**与宿主 `meta` 解析,
|
|
1985
2185
|
* 解析不到就缺省(不猜)。exit/signal 标记只由 bash/pwsh 输出;grep/glob 的匹配总数优先
|
|
@@ -1993,13 +2193,15 @@ export function toolResultSummaryOf(toolName, rawResultText, meta) {
|
|
|
1993
2193
|
const summary = {};
|
|
1994
2194
|
const text = typeof rawResultText === "string" ? rawResultText : "";
|
|
1995
2195
|
const tool = typeof toolName === "string" ? toolName : "";
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
const
|
|
2002
|
-
if (
|
|
2196
|
+
// issue #60 R14:终止状态只对**已确定是 bash/pwsh** 的结果下发;无工具名时不得从内容猜
|
|
2197
|
+
// (调用方应按 callId→tool/call.name 关联后再传 resolvedToolName)。
|
|
2198
|
+
if (tool === "bash" || tool === "pwsh") {
|
|
2199
|
+
// issue #60 R13:只认宿主在**结果末尾**追加的终止 trailer,且取最后一条;
|
|
2200
|
+
// stdout 里碰巧出现的 `[exit code: N]` 不得覆盖真实终止状态。
|
|
2201
|
+
const trailer = terminalTrailerOf(text);
|
|
2202
|
+
if (trailer?.kind === "exit") summary.exitCode = trailer.exitCode;
|
|
2203
|
+
else if (trailer?.kind === "signal") summary.signal = trailer.signal;
|
|
2204
|
+
else if (trailer?.kind === "stopped") summary.stopped = trailer.stopped;
|
|
2003
2205
|
}
|
|
2004
2206
|
const metaShape = meta && typeof meta === "object" ? meta.shape : undefined;
|
|
2005
2207
|
const searchShaped = metaShape === "matches" || metaShape === "paths";
|
|
@@ -2085,8 +2287,12 @@ export function turnTailsOf(events) {
|
|
|
2085
2287
|
* @param {any} diff 宿主返回的对比结果(text 形态)。
|
|
2086
2288
|
* @returns {{text: string, truncated: boolean}}
|
|
2087
2289
|
*/
|
|
2088
|
-
export function renderUnifiedDiffText(diff) {
|
|
2089
|
-
|
|
2290
|
+
export function renderUnifiedDiffText(diff, displayOverride) {
|
|
2291
|
+
// issue #60 R05:展示值必须由调用方用 mobileDisplayPath 重派生后传入;未传时退回
|
|
2292
|
+
// 宿主 display/路径的 basename,绝不把可拼接的绝对路径写进 diff 标头。
|
|
2293
|
+
const display = typeof displayOverride === "string" && displayOverride !== ""
|
|
2294
|
+
? displayOverride
|
|
2295
|
+
: posixBasenameOf(diff?.path ?? diff?.display);
|
|
2090
2296
|
const lines = [
|
|
2091
2297
|
diff?.before === false ? "--- /dev/null" : `--- a/${display}`,
|
|
2092
2298
|
diff?.after === false ? "+++ /dev/null" : `+++ b/${display}`,
|
|
@@ -2237,7 +2443,9 @@ function summarizeEventCoreBody(event, options = {}) {
|
|
|
2237
2443
|
const message = data.message;
|
|
2238
2444
|
const blocks = Array.isArray(message?.content) ? message.content : [];
|
|
2239
2445
|
// 兼容旧宿主/测试夹具直接提供的 { callId, name, text, isError } wire 形态。
|
|
2240
|
-
|
|
2446
|
+
// issue #60 recheck-4:真实结果形状的 callId 在 message.source.callId /
|
|
2447
|
+
// message.toolCallId / content[].toolCallId,不在 event.data.callId。
|
|
2448
|
+
let callId = toolResultCallIdOf(event);
|
|
2241
2449
|
let isError = data.error !== undefined || data.isError === true;
|
|
2242
2450
|
let text = typeof data.text === "string" ? data.text : "";
|
|
2243
2451
|
const images = Array.isArray(data.images)
|
|
@@ -2261,7 +2469,10 @@ function summarizeEventCoreBody(event, options = {}) {
|
|
|
2261
2469
|
const resultName = directName || errName;
|
|
2262
2470
|
// issue #54:结果摘要从**未 clamp 的原始文本**与宿主 meta 解析(exit/signal 标记
|
|
2263
2471
|
// 通常在输出末尾,clamp 后可能被截掉;meta 只用来取匹配总数,不透传)。
|
|
2264
|
-
|
|
2472
|
+
// issue #60 R14:结果事件常不带工具名;调用方通过 callId→tool/call.name 解析出
|
|
2473
|
+
// resolvedToolName 后再传进来,只有确定是 bash/pwsh 时才下发命令终止状态。
|
|
2474
|
+
const resolvedToolName = typeof options.resolvedToolName === "string" ? options.resolvedToolName : resultName;
|
|
2475
|
+
const resultSummary = toolResultSummaryOf(resolvedToolName, text, data.meta);
|
|
2265
2476
|
return {
|
|
2266
2477
|
seq,
|
|
2267
2478
|
type,
|
|
@@ -2306,7 +2517,15 @@ function summarizeEventCoreBody(event, options = {}) {
|
|
|
2306
2517
|
for (const file of files.slice(0, TURN_TAIL_MAX_FILES)) {
|
|
2307
2518
|
const path = typeof file?.path === "string" ? file.path : "";
|
|
2308
2519
|
if (path === "") continue;
|
|
2309
|
-
|
|
2520
|
+
// issue #60 R08:服务端 display 是**脱敏后的展示值**,不同目录的同名文件会
|
|
2521
|
+
// 得到相同 display;再下发一个不泄路径的稳定身份(路径摘要)供 App 去重。
|
|
2522
|
+
// 该 id 不含可逆路径/主机前缀,只用于同一轮内跨 present 事件的同一文件合并。
|
|
2523
|
+
const identity = recordFileId(path, cwd);
|
|
2524
|
+
const entry = {
|
|
2525
|
+
id: identity,
|
|
2526
|
+
name: posixBasenameOf(path),
|
|
2527
|
+
display: mobileDisplayPath(path, cwd),
|
|
2528
|
+
};
|
|
2310
2529
|
if (typeof file.description === "string" && file.description.trim() !== "") entry.description = clampText(file.description, 200);
|
|
2311
2530
|
mapped.push(entry);
|
|
2312
2531
|
}
|
|
@@ -2757,6 +2976,8 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
2757
2976
|
? { token: String(runtime.authToken.token ?? ""), source: String(runtime.authToken.source ?? "runtime") }
|
|
2758
2977
|
: resolvePluginAuthToken({ home: homedir(), configured: config.authToken });
|
|
2759
2978
|
const authToken = authTokenState.token;
|
|
2979
|
+
// 不能把临时 UUID 宣告为稳定身份:身份不可用时阻止插件启动,保留现场供人工恢复。
|
|
2980
|
+
const hostIdentity = resolveHostIdentity();
|
|
2760
2981
|
const authEnabled = authToken !== "";
|
|
2761
2982
|
const authGenerated = authTokenState.source === "generated";
|
|
2762
2983
|
// ── LAN 桥三态(#36 S1)配置归一(bootstrap/qr-config/diagnostics 在请求期读这些)──
|
|
@@ -5487,7 +5708,11 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
5487
5708
|
if (isLiveTimelineRecord(event)) {
|
|
5488
5709
|
// issue #53:交付文件声明的 display 需要会话工作目录才能派生;turn/end 额外带
|
|
5489
5710
|
// 轮末信号 `tail`(§6.20),供 App 决定是否渲染改动卡/交付卡。
|
|
5490
|
-
|
|
5711
|
+
// issue #60 R14:实时 tool/result 同样按 callId→name 解析命令工具身份。
|
|
5712
|
+
const resolvedToolName = event.type === "tool/result"
|
|
5713
|
+
? toolNamesOf(eventsOf(session)).get(toolResultCallIdOf(event))
|
|
5714
|
+
: undefined;
|
|
5715
|
+
const summary = summarizeEvent(event, { cwd: sessionCwdOf(session), resolvedToolName });
|
|
5491
5716
|
if (event.type === "turn/end") {
|
|
5492
5717
|
const tail = turnTailOf(eventsOf(session), event.data?.turn);
|
|
5493
5718
|
if (tail) summary.data = { ...(summary.data ?? {}), tail };
|
|
@@ -6209,7 +6434,7 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
6209
6434
|
// contentSha256 = **当前正在运行的代码**的内容标识:监督器与手机据此确认
|
|
6210
6435
|
// "新实例已健康生效",而不是只看磁盘字节或版本号(评审 R1/R7)
|
|
6211
6436
|
// instanceId = 本服务实例身份:换实例后旧健康结论不能冒充新的(§5.3)。
|
|
6212
|
-
plugin: { name: "dsh-mobile-remote", version: pluginVersion(), contentSha256: selfContentSha256, pid: process.pid, instanceId: pluginInstanceId },
|
|
6437
|
+
plugin: { name: "dsh-mobile-remote", version: pluginVersion(), contentSha256: selfContentSha256, pid: process.pid, instanceId: pluginInstanceId, hostId: hostIdentity },
|
|
6213
6438
|
capabilities: {
|
|
6214
6439
|
eventTimeline: EVENT_TIMELINE_CAPABILITIES,
|
|
6215
6440
|
// 宿主是否**真的**挂了 `turnOutline` 投影单元、且观察接口可用,决定声明是
|
|
@@ -7330,6 +7555,8 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
7330
7555
|
// 仍含被过滤的 `workspace/changes`),不额外调用宿主服务;只含有产出物的轮次。
|
|
7331
7556
|
const turnTails = turnTailsOf(eventsOf(session));
|
|
7332
7557
|
const cwd = sessionCwdOf(session);
|
|
7558
|
+
// issue #60 R14:结果事件通常无工具名,用 callId→name 关联后再解析终止状态。
|
|
7559
|
+
const toolNames = toolNamesOf(eventsOf(session));
|
|
7333
7560
|
let events;
|
|
7334
7561
|
let hasMore = false;
|
|
7335
7562
|
if (afterParam !== null) {
|
|
@@ -7358,7 +7585,10 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
7358
7585
|
after: events.length ? events[events.length - 1].seq : 0,
|
|
7359
7586
|
hasMore,
|
|
7360
7587
|
turnTails,
|
|
7361
|
-
events: events.map((event) => summarizeEvent(event, {
|
|
7588
|
+
events: events.map((event) => summarizeEvent(event, {
|
|
7589
|
+
cwd,
|
|
7590
|
+
resolvedToolName: event?.type === "tool/result" ? toolNames.get(toolResultCallIdOf(event)) : undefined,
|
|
7591
|
+
})),
|
|
7362
7592
|
});
|
|
7363
7593
|
return;
|
|
7364
7594
|
}
|
|
@@ -8431,7 +8661,7 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
8431
8661
|
checks.updateDir = `${updateDirState.source}${updateDirState.ready ? "" : `(${updateDirState.reason || "not-ready"})`}`;
|
|
8432
8662
|
sendJson(res, 200, {
|
|
8433
8663
|
ok: true,
|
|
8434
|
-
plugin: { name: "dsh-mobile-remote", version: pluginVersion(), contentSha256: selfContentSha256, instanceId: pluginInstanceId },
|
|
8664
|
+
plugin: { name: "dsh-mobile-remote", version: pluginVersion(), contentSha256: selfContentSha256, instanceId: pluginInstanceId, hostId: hostIdentity },
|
|
8435
8665
|
runtime: {
|
|
8436
8666
|
// #36 follow-up(note 1509 §3/§4):form 取**桥启动决策时的同一份形态快照**,
|
|
8437
8667
|
// 不再按请求重新探测(避免"诊断 desktop、启动 form-unknown"不一致);
|
|
@@ -8716,12 +8946,29 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
8716
8946
|
}
|
|
8717
8947
|
if (!summary || !Array.isArray(summary.files)) return sendJson(res, 200, unavailable);
|
|
8718
8948
|
const allFiles = summary.files;
|
|
8949
|
+
// issue #60 round7(F2):presented 的 cwd 来自 sessionCwdOf(session)(header.cwd),
|
|
8950
|
+
// changed 的 cwd 来自宿主 workspaceChanges.summary().cwd,**两者文本/基准不保证相同**
|
|
8951
|
+
// (同一 display 下会算出两个逻辑 id → App 行内/basename 链接丢失)。两条投影统一用
|
|
8952
|
+
// 「会话 base」:会话 cwd 优先、宿主摘要 cwd 兜底,再交给 canonicalWorkspacePath
|
|
8953
|
+
// 按 realpath 归一(消掉 symlink 别名 / 绝对路径形状差异)。绝不把 cwd 写进响应。
|
|
8954
|
+
// 真宿主 dsh-workspace-changes 的 recorderFor(session, cwd) 冻结 cwd=session.header.cwd
|
|
8955
|
+
// 并作为 summary.cwd 返回,故生产里两者本就相同;这里用会话 base 兜底裁剪/旧宿主。
|
|
8956
|
+
// 已知 P3 接受:① 裁剪宿主把 header.cwd 与 summary.cwd 指向不同子目录、且两处
|
|
8957
|
+
// 记录各自相对该 cwd 的文本时,单一 base 无法同时对齐(非真宿主形状);
|
|
8958
|
+
// ② 两处 cwd 都缺失且绝对/相对混排时无基准可归一(live 会话 header.cwd 必存在)。
|
|
8959
|
+
const idBase = sessionCwdOf(session) ?? summary.cwd;
|
|
8719
8960
|
const files = allFiles.slice(0, TURN_TAIL_MAX_FILES).map((file, index) => {
|
|
8720
8961
|
const recordedPath = typeof file?.path === "string" ? file.path : "";
|
|
8721
|
-
|
|
8962
|
+
// issue #60 R05:宿主 display 可能是 cwd/home 外的**绝对路径**(合法宿主形状);
|
|
8963
|
+
// 一律从记录路径 + 会话 cwd 重新派生安全 display,绝不直通宿主 display。
|
|
8964
|
+
const displaySource = recordedPath !== "" ? recordedPath : (typeof file?.display === "string" ? file.display : "");
|
|
8965
|
+
const display = mobileDisplayPath(displaySource, idBase) || posixBasenameOf(displaySource);
|
|
8722
8966
|
return {
|
|
8723
8967
|
seq: source.seq,
|
|
8724
8968
|
index,
|
|
8969
|
+
// round4-2:与 presented 共用同一路径摘要,供 App 按逻辑身份合并
|
|
8970
|
+
// delivered/changed;不含可拼路径。
|
|
8971
|
+
id: recordFileId(recordedPath, idBase),
|
|
8725
8972
|
display,
|
|
8726
8973
|
name: posixBasenameOf(recordedPath || display),
|
|
8727
8974
|
added: Number.isFinite(file?.added) ? Math.max(0, Math.trunc(file.added)) : 0,
|
|
@@ -8766,20 +9013,24 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
8766
9013
|
return error(res, 503, "changes-unavailable");
|
|
8767
9014
|
}
|
|
8768
9015
|
if (!diff) return error(res, 404, "diff-not-found");
|
|
9016
|
+
// issue #60 R05:diff 的 display 同样不得直通宿主(可能是绝对路径);从 diff.path
|
|
9017
|
+
// 与会话 cwd 重新派生,并让统一 diff 的 ---/+++ 标头使用同一安全值。
|
|
9018
|
+
const diffPathSource = typeof diff.path === "string" && diff.path !== "" ? diff.path : (typeof diff.display === "string" ? diff.display : "");
|
|
9019
|
+
const safeDisplay = mobileDisplayPath(diffPathSource, sessionCwdOf(session)) || posixBasenameOf(diffPathSource);
|
|
8769
9020
|
if (diff.kind === "binary" || diff.kind === "oversized") {
|
|
8770
9021
|
return sendJson(res, 200, {
|
|
8771
9022
|
ok: true,
|
|
8772
9023
|
state: "available",
|
|
8773
|
-
diff: { kind: diff.kind, display:
|
|
9024
|
+
diff: { kind: diff.kind, display: safeDisplay },
|
|
8774
9025
|
});
|
|
8775
9026
|
}
|
|
8776
|
-
const rendered = renderUnifiedDiffText(diff);
|
|
9027
|
+
const rendered = renderUnifiedDiffText(diff, safeDisplay);
|
|
8777
9028
|
return sendJson(res, 200, {
|
|
8778
9029
|
ok: true,
|
|
8779
9030
|
state: "available",
|
|
8780
9031
|
diff: {
|
|
8781
9032
|
kind: "text",
|
|
8782
|
-
display:
|
|
9033
|
+
display: safeDisplay,
|
|
8783
9034
|
before: diff.before !== false,
|
|
8784
9035
|
after: diff.after !== false,
|
|
8785
9036
|
coarse: diff.coarse === true,
|
|
@@ -9468,9 +9719,14 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
9468
9719
|
// 旧值空串让服务端只能靠 `find(e => e.rpcId === "")` 命中"第一个"条目——
|
|
9469
9720
|
// 多会话并发接管时会张冠李戴。
|
|
9470
9721
|
const holdApproval = (req, sessionId) => {
|
|
9471
|
-
|
|
9722
|
+
// issue #60 R16:审批身份必须标识**这一次审批请求**,callId 只作关联。同一工具在
|
|
9723
|
+
// pre-execute 与工具体内 sandbox escalation 会复用 callId;若用 sessionId:callId
|
|
9724
|
+
// 作身份,App 会把第二次新审批误当成已解决请求重放而永久静默。
|
|
9725
|
+
// 因此每次实际请求生成唯一 approvalId;断线重连回放同一 entry 时 id 不变。
|
|
9726
|
+
const callRef = typeof req?.callId === "string" && req.callId !== ""
|
|
9472
9727
|
? req.callId
|
|
9473
|
-
: Date.now().toString(36)
|
|
9728
|
+
: Date.now().toString(36);
|
|
9729
|
+
const phoneKey = `${sessionId}:${callRef}:${randomUUID()}`;
|
|
9474
9730
|
const phoneOnline = connections.size > 0;
|
|
9475
9731
|
const holdMs = phoneOnline ? PENDING_TIMEOUT_MS : OFFLINE_HOLD_MS;
|
|
9476
9732
|
ctx.logger.info?.(`mobile-remote: approval/request 手机接管(${sessionId} tool=${req?.toolName}${phoneOnline ? "" : `,手机离线,最多等待 ${Math.round(holdMs / 1000)}s`})`);
|
|
@@ -9546,14 +9802,11 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
9546
9802
|
if (!sessionId || !eventId) return;
|
|
9547
9803
|
const request = frame.request ?? {};
|
|
9548
9804
|
if (frame.event === "approval/request") {
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9554
|
-
// questionId 查到新条目」,合法回答被判 400。`eventId` 稳定且已是本条的 rpcId,
|
|
9555
|
-
// 用它兜底可让上面的 has() 去重真正生效。
|
|
9556
|
-
: eventId}`;
|
|
9805
|
+
// issue #60 R16:$events 路径的身份必须标识**这一次实际审批请求**,callId 只作
|
|
9806
|
+
// 关联(同一工具 pre-execute 与 sandbox escalation 会复用同一个 callId)。
|
|
9807
|
+
// eventId 每次实际请求唯一,且宿主断线重放同一事件时保持不变——既不会让第二次
|
|
9808
|
+
// 新审批被第一次的 resolved 身份拦截,又保留重放去重(下面的 has())。
|
|
9809
|
+
const phoneKey = `${sessionId}:${eventId}`;
|
|
9557
9810
|
if (pendingApprovals.has(phoneKey)) return;
|
|
9558
9811
|
ctx.logger.info?.(`mobile-remote: approval/request 双端呈现(${sessionId} tool=${request?.toolName}${phoneOnline ? "" : ",手机离线→记账待回放"})`);
|
|
9559
9812
|
const entry = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktrue/dsh-mobile-remote",
|
|
3
|
-
"version": "3.2.4-alpha.
|
|
3
|
+
"version": "3.2.4-alpha.9",
|
|
4
4
|
"description": "DSH Mobile:把 DeepSeek Harness 变成随身控制台——手机远程发消息派活、看进度、收通知、审批决策、管理会话;配套 Flutter App(当前 Android 端,iOS 未开发)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"qrcode"
|
|
53
53
|
],
|
|
54
54
|
"optionalDependencies": {
|
|
55
|
-
"@marktrue/dsh-mobile-remote-app": "npm:@marktrue/dsh-mobile-remote@3.2.4-alpha.
|
|
55
|
+
"@marktrue/dsh-mobile-remote-app": "npm:@marktrue/dsh-mobile-remote@3.2.4-alpha.9-app"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@deepseek-ai/dsh-credentials": ">=0.1.0-rc.6 <=0.2.2 || >=0.2.0-0 <0.2.0 || >=0.2.1-0 <0.2.1 || >=0.2.2-0 <0.2.2",
|