@marktrue/dsh-mobile-remote 3.2.4-alpha.15 → 3.2.4-alpha.16
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 +58 -0
- package/docs/03-api.md +16 -8
- package/docs/09-compatibility.md +9 -3
- package/lib/endpoint-registry.js +2 -1
- package/lib/index.js +388 -40
- package/lib/npm-update-source.js +16 -16
- package/lib/plugin-update-check.js +268 -0
- package/lib/plugin-update-controller.js +53 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v3.2.4-alpha.16(build 48,issues #87 / #90 / #92 / #94 / #96 / #97 / #98 / #99 / #100 / #101 / #102)— 宿主兼容、触发卡与图片授权
|
|
4
|
+
|
|
5
|
+
> 插件 `3.2.4-alpha.16` / App `3.2.4+48` / 载体 `3.2.4-alpha.16-app`。
|
|
6
|
+
|
|
7
|
+
### 子代理/团队消息触发轮次卡(#101)
|
|
8
|
+
|
|
9
|
+
- 普通模式新增两类触发卡:`agent-message`「收到任务消息」、`team-message`「收到团队消息」;`subagent-settled` 与 agent-instructions/runtime-context/skill-catalog/tool/plugin 等系统注入仍隐藏;
|
|
10
|
+
- 紧凑卡片(图标 + 通用标签 + 首行预览),点按展开正文并沿用 `inj:` 每消息展开状态;空文本只显示标签、无预览,不铺普通气泡;
|
|
11
|
+
- 触发卡是 user item,天然位于该轮过程块之前;history 与 SSE 共用同一构建路径,重复 messageId 去重;debug 模式仍显示全部注入;320/深色/1.5x 适配。
|
|
12
|
+
|
|
13
|
+
### DSH 0.2.2-rc.2 宿主兼容(#87)
|
|
14
|
+
|
|
15
|
+
- **subagents 中断**:按能力探测 `interruptByUser` 分流——rc.2 调用 `subagents/interruptByUser` 且 payload 仅 `{childSessionId}`,rc.1 保持 `interruptByParent` + `{childSessionId,parentSessionId,mode}`;透传 rc.2 `SubagentInterruptReceipt.accepted`(受理 ≠ 已静默),旧宿主无 receipt 仍返回 `{ok:true}`;
|
|
16
|
+
- **子代理目录**:优先 `listDescendants(parent,signal)` 并只取 `depth===1`,失败/缺失回退 rc.1 `listChildren`,再回退既有持久化枚举;diagnostic 改按 `kind==="diagnostic"` 识别,reason 映射 `unsupported`/`corrupt`/`unavailable` 三枚举;目录缺 `createdAt` 时回落 `session.header.createdAt`,仍缺则沉底、组内 id 升序;App 面板显示对应「不受支持 / 目录数据损坏 / 目录不可用」;
|
|
17
|
+
- hostCapabilities 新增 `subagents.catalog`、`subagents.interrupt` 三态(ok/drift/missing),hostGeneration 记录实际代际(descendants/children/none、user/parent/none);host-canary 与 docs/09-compatibility §2.5/§2.6 同步为 10 项能力全绿口径。
|
|
18
|
+
|
|
19
|
+
### 分支图动态左边距与 focus 预取(#102 / #100)
|
|
20
|
+
|
|
21
|
+
- 按 scroll offset、rowHeight、viewport(+1 行 overscan)计算可见行区间与最大 lane;图宽 `max(80, 可见 lane 数*30+32)`,所有行标签共用同一列并随宽度移动;
|
|
22
|
+
- 100ms debounce + 150ms Tween 平滑,快照切换立即重置目标、首帧按真实视口重算;横向 offset 变化后仅 clamp 到新 max,不自动跳左/不重置 0;320/深色/1.5x 不溢出;
|
|
23
|
+
- #100:focus/prev 预取改为用户手势驱动——程序性 `jumpTo/animateTo` 不再触发 prev,focus 动画未稳定前禁止预取;prev 先缓存 pending,真实到顶才前插,并按可见首行 oid + 像素偏移锚定,不把当前视口推走;next 与 5/10 选择模式行为不变。
|
|
24
|
+
|
|
25
|
+
### 工作区外图片会话授权(#94 → #98)
|
|
26
|
+
|
|
27
|
+
- **#94 原始问题**:工作区外本地图片在 App 中无法显示;本版在不放宽读取边界的前提下,改为按会话显式授权后显示(修复 #98)。
|
|
28
|
+
|
|
29
|
+
- 工作区外图片改为按会话授权显示:授权卡片支持「仅本次 / 本目录」,取消后记录 declined 状态——组件重建、滚动回滚、重新加载只显示「授权读取」,不再自动弹窗;用户点按才重新弹;
|
|
30
|
+
- 切会话/dispose 清空授权、declined、pending prompt 与图片缓存;`consent-invalid` 清旧授权但保留 declined,避免自动弹窗循环;
|
|
31
|
+
- 服务端 consent 端点 `lstat` 提前拒绝末级 symlink(`415 unsupported-image-symlink`),授权后 GET 仍走 `O_NOFOLLOW` + fd 实际路径校验,不因授权放宽读取边界。
|
|
32
|
+
|
|
33
|
+
### 插件更新检查与 slash 菜单修复(#90 → #97 / #96)
|
|
34
|
+
|
|
35
|
+
- **#90 原始问题**:斜杠命令/技能菜单的滚动、高亮与配色体验问题;本版由 #97 收口(修复 #97)。
|
|
36
|
+
|
|
37
|
+
- 更新检查新增成功快照(5min)与失败/unavailable 独立短缓存(30s),`POST /plugin-update/check` 返回 checkId 异步轮询(GET 未知 404、过期 410、同 key in-flight 去重),整次检查 12s deadline → 稳定 `check-timeout`,不返回半结果;
|
|
38
|
+
- 代际(generation)防止旧在途检查写回污染缓存;异常统一脱敏为 `check-failed`;submit 遇 `check-unavailable` 直接 503 不进版本比对,仅成功检查且 targetVersion 真实不同才重查一次,仍不同才 409 `candidate-changed`;
|
|
39
|
+
- App 保留 35s 同步回退,超时后设置页显示「继续检查」并复用原 checkId(410 自动重启),旧宿主自动回退 GET;不抛裸 TimeoutException;
|
|
40
|
+
- #97 后续:slash 菜单滚动、输入框高亮、命令绿 / 技能蓝配色,修复 320+键盘菜单溢出、过滤残留与文件名误高亮。
|
|
41
|
+
|
|
42
|
+
### 压缩回放 surface 去重(#92 → #99)
|
|
43
|
+
|
|
44
|
+
- **#92 原始问题**:部分工具调用在压缩回放后仍显示为旧版独立工具卡且无法随过程折叠;本版由 #99 的 surface replay 去重与严格解析收口(修复 #99)。
|
|
45
|
+
|
|
46
|
+
- 服务端 `/history` 与 SSE 共用摘要,只读透传 `surfaceOp`(字符串 append / 对象 append/replace)与 `sourceEventSeqs`(去重正序 ≤64),非法 envelope 整组丢弃,不 bump 契约版本;
|
|
47
|
+
- App `SurfaceOp` 按真实 union 严格解析(缺失 vs 显式 null、append 可省 start/end、replace 必带且 start<=end、source 必须早于当前 seq),坏 envelope 不解释为 replace;
|
|
48
|
+
- 登记被 replace 遮蔽的 source seq:旧 source 后到不再生成工具卡、不清 surface 状态;replay 工具行锚回 source seq、按 source 排序且不新增历史工具卡;SSE 桥接保留 surface 字段,history/SSE 同语义。
|
|
49
|
+
|
|
50
|
+
### 文档
|
|
51
|
+
|
|
52
|
+
- docs/03-api §6.11b 同步 hostCapabilities/hostGeneration 的 subagents 三态与代际,§6.14 同步 `listDescendants` depth1、diagnostic 三枚举、createdAt 回落、interruptByUser 单字段与 accepted receipt 语义;
|
|
53
|
+
- docs/09-compatibility §2.5/§2.6 更新 rc.2 subagents 两处契约漂移与能力口径;CONTEXT 增补更新检查快照/检查任务与触发卡术语。
|
|
54
|
+
|
|
55
|
+
### 验证
|
|
56
|
+
|
|
57
|
+
- 本机发布门禁:node 测试 **1172**(1159 通过 / 13 跳过 / 0 失败)、flutter test **1442** 全绿、flutter analyze 0 error/warning(24 条既有 info);首轮 node 全量 1 例 host-canary 已知时序 flake(#40),单文件 46/46 与全量重跑均全绿;
|
|
58
|
+
- 真机/320 宽/深色、分支图 5/10/all、图片授权、trigger 卡、动态 margin 列为本版验收项(发布后按验收清单执行)。
|
|
59
|
+
|
|
60
|
+
|
|
3
61
|
## v3.2.4-alpha.15(build 47,issues #90 / #91 / #92 / #93 / #94 / #95)— 斜杠菜单、全部分支图与本地图片
|
|
4
62
|
|
|
5
63
|
> 插件 `3.2.4-alpha.15` / App `3.2.4+47` / 载体 `3.2.4-alpha.15-app`。
|
package/docs/03-api.md
CHANGED
|
@@ -565,9 +565,9 @@
|
|
|
565
565
|
|
|
566
566
|
环境诊断在 `checks` 下提供宿主兼容自检(ADR 0017,**纯增量字段,旧 App 忽略即可**):
|
|
567
567
|
|
|
568
|
-
- `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
|
|
568
|
+
- `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` 至少一个可用)。
|
|
569
569
|
- `checks.hostCapabilityReasons`:仅对 `drift` 项给出的允许清单原因码(如 `settings.read` 的 `settings-get-threw`;`gateway.eventsPeer` 的 `gateway-peer-source-missing`)。
|
|
570
|
-
- `checks.hostGeneration`:插件实际走到的代际路径——`jobsCaller`(`sessionId` / `agent`)、`settingsRead`(`describe` / `get`)、`wireStreamArgs`(`controlArg` / `legacyArg`)、`eventsPeer`(`createPeer` / `operatorPeer` / `legacy` / `none` / `unknown`)。
|
|
570
|
+
- `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`)。
|
|
571
571
|
- `checks.remoteEvents` / `checks.approvalMode`:`$events` 双端审批通道是否就绪与实际生效的审批呈现策略。
|
|
572
572
|
|
|
573
573
|
详见 `docs/09-compatibility.md` §2.5/§2.6。
|
|
@@ -639,19 +639,27 @@
|
|
|
639
639
|
{ "id": "…", "kind": "child", "status": "running", "title": "…", "createdAt": 1730000000000 }
|
|
640
640
|
]}
|
|
641
641
|
```
|
|
642
|
-
-
|
|
642
|
+
- 目录来源按优先级取(能力探测,不看宿主版本号):
|
|
643
|
+
① rc.2+ `ctx.subagents.listDescendants(parentSessionId, signal)`(递归,**只取 `depth===1`**)→
|
|
644
|
+
①' rc.1 `ctx.subagents.listChildren(parentSessionId, signal)` → ② 持久化枚举(父会话休眠/归档时入口不消失)→ ③ 会话注册表派生。
|
|
643
645
|
**不调用 `subagents/list` Remote 端点**——该端点在宿主 0.2.0 已被删除
|
|
644
|
-
- `kind`:`child`(普通子代理)或 `diagnostic
|
|
645
|
-
|
|
646
|
-
- `
|
|
646
|
+
- `kind`:`child`(普通子代理)或 `diagnostic`(rc.2 的 `kind:"diagnostic"` / rc.1 的 `mode:"unknown"`)。
|
|
647
|
+
diagnostic 行**没有 `mode`**,客户端不得用 `row.mode` 判分支。
|
|
648
|
+
- `status`:普通行为活 agent 的 AgentStatus 映射(`running`/`inactive`);diagnostic 行为三枚举原因:
|
|
649
|
+
`unsupported`(该条目自身可继续遍历)/ `corrupt`(目录数据损坏、分支中止)/ `unavailable`(子目录读不到、分支中止)。
|
|
650
|
+
- `createdAt`:rc.2 目录无该字段,回落 `session.header.createdAt`;两者都缺失时排到列表末尾(组内 `id` 升序),
|
|
651
|
+
排序仍为 createdAt 降序;`catalogDegraded: true` 表示来源 ②/③ 不完整,客户端据此区分"确实没有子代理"与"目录读不到"
|
|
647
652
|
- 缺参数 `400 parentSessionId-required`;三条路径都取不到会话 `404 session-not-found`
|
|
648
653
|
|
|
649
654
|
**POST `/m/api/subagents/interrupt`** — 中断子代理
|
|
650
655
|
```json
|
|
651
656
|
请求: { "parentSessionId": "…", "childSessionId": "…" }
|
|
652
|
-
响应: { "ok": true }
|
|
657
|
+
响应: { "ok": true, "accepted": true }
|
|
653
658
|
```
|
|
654
|
-
-
|
|
659
|
+
- rc.2+(宿主暴露 `subagents.interruptByUser`):映射 `subagents/interruptByUser`,payload **仅** `{ childSessionId }`;
|
|
660
|
+
响应透传 `SubagentInterruptReceipt.accepted`。语义是**中断信号已受理**,不等于目标已静默/已退出。
|
|
661
|
+
- rc.1(仅 `subagents.interruptByParent`):映射旧端点,payload `{ childSessionId, parentSessionId, mode: "continuable" }`;
|
|
662
|
+
旧宿主无 receipt,响应省略 `accepted`。
|
|
655
663
|
|
|
656
664
|
**GET `/m/api/goal?sessionId=…`** — 当前目标(无目标返回 `{ "goal": null }`)
|
|
657
665
|
```json
|
package/docs/09-compatibility.md
CHANGED
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
|
|
46
46
|
- `checks.hostCapabilities`:逐项给出三态——`ok` / `drift` / `missing`。`drift` 是**能力语义漂移**(服务在、调用不报错,但成员形状不是插件认识的样子),这正是 0.2.0 四处变更与 0.2.1 peer 收紧的形态,旧的两分法看不见它们。**`gateway.eventsPeer`(issue #34)** 专门覆盖"网关入口都在、但进程内 Peer 来源缺失"这一种漂移,原因码为 `gateway-peer-source-missing`。
|
|
47
47
|
- `checks.hostCapabilityReasons`(issue #30 审查修复):**只对 `drift` 项**给出 allow-list 原因码,避免"只报状态值查不出哪一步坏了"。`settings.read` 的取值:`settings-get-threw` / `settings-describe-threw` / `settings-describe-shape-invalid` / `settings-descriptor-without-value` / `settings-has-no-read-method`。该探针与真实读取**共享严格读取器**——对插件真正读取的命名空间逐个探测,"命名空间不存在"仍算 ok,读不到才报 `drift`。
|
|
48
|
-
- `checks.hostGeneration`:插件**实际走了哪条代际路径**(`jobsCaller` / `settingsRead` / `wireStreamArgs` / `eventsPeer`),排查"为什么同一功能在两台机器上表现不同"时先看这里。`eventsPeer` 取值:`createPeer`(0.2.1+)/ `operatorPeer`(0.2.0 网关兜底)/ `legacy`(旧代 3 参开流不需要 peer)/ `none`(必失败)/ `unknown`(网关服务缺失,无法判定)。
|
|
48
|
+
- `checks.hostGeneration`:插件**实际走了哪条代际路径**(`jobsCaller` / `settingsRead` / `wireStreamArgs` / `eventsPeer` / `subagents`),排查"为什么同一功能在两台机器上表现不同"时先看这里。`subagents` 为对象:`catalog`(`descendants` / `children` / `none`)与 `interrupt`(`user` / `parent` / `none`),对应 issue #87 的 rc.1/rc.2 目录与中断代际。`eventsPeer` 取值:`createPeer`(0.2.1+)/ `operatorPeer`(0.2.0 网关兜底)/ `legacy`(旧代 3 参开流不需要 peer)/ `none`(必失败)/ `unknown`(网关服务缺失,无法判定)。
|
|
49
49
|
|
|
50
50
|
`services.apiProxy` / `checks.respondBridge` / `checks.frameBridge` **已随 v3.1.6 删除**:该服务自 `0.1.2-rc.1` 起就不存在,保留它们只会让人以为有一条可用的旧代降级通道。同样地,`/m/api/respond` 在待办不在本地清单时返回 `404 respond-not-pending`(此前返回 `503` 并归咎于"内核过旧",属误导——真实原因通常是"另一端已先答"或"已超时")。
|
|
51
51
|
|
|
@@ -131,13 +131,15 @@
|
|
|
131
131
|
|
|
132
132
|
**另有一类风险单独处理**:插件依赖的若干宿主成员是 **TS-private**(无契约保证)——权限预设的 `names`/`presets`/`apply`,以及工作区注册表的 `enqueueOperation`/`requireState`/`setState`(后者此前**完全无守卫**)。v3.1.6 起这些成员缺失时**显式报错**(503)或显式降级,不再让 `TypeError` 在深处被吞成"按了没反应"。**不迁移**到公开 API——那是行为改变,与本次兼容修复分开评估。
|
|
133
133
|
|
|
134
|
+
**subagents 三态的口径**:`subagents.catalog` / `subagents.interrupt` 分别探测"任一目录方法(rc.2 `listDescendants` 或 rc.1 `listChildren`)"与"任一中断方法(rc.2 `interruptByUser` 或 rc.1 `interruptByParent`)"是否存在。宿主**完全无 `subagents` 服务**时两项为 `missing`(服务不存在,预期降级,不是可修复的 drift);服务在但两代成员都没有才报 `drift`;任一成员存在即 `ok`。金丝雀对 `missing`/`drift` 的判定与此一致,无需区分"完全没有服务"与"服务在但形状不对"的行为差异——两者都会被如实上报。
|
|
135
|
+
|
|
134
136
|
**`$events` 流断开改为退避重连**:原实现"就绪后一旦断开即永久放弃",使 `approvalMode: both` 在首次断流后永久退化为手机独占,直到重启宿主——而桌面 GUI 每次开关浏览器都会断流。现语义:**就绪前**失败 = 事件源尚未注册(有界重试 ≈15s);**就绪后**断开 = 瞬时断开(3s 起退避、上限 60s、无限重连,仅插件卸载才停止)。重新就绪后退避复位。
|
|
135
137
|
|
|
136
138
|
**`0.2.0` 另外两处破坏(issue #21,与上述四处同类,但位于 #19 未覆盖的位置)**:
|
|
137
139
|
|
|
138
140
|
| 差异 | `0.1.x` | `0.2.x` | 插件如何判别 | 传错的后果 |
|
|
139
141
|
|---|---|---|---|---|
|
|
140
|
-
| 子代理目录 | `subagents/list` Remote 端点 | **该端点已删除**(内核树内 0 命中;只剩 `subagents/prompt` 与 `subagents/interruptByParent`) |
|
|
142
|
+
| 子代理目录 | `subagents/list` Remote 端点 | **该端点已删除**(内核树内 0 命中;只剩 `subagents/prompt` 与 `subagents/interruptByParent` / rc.2 `interruptByUser`) | rc.1 用 `ctx.subagents.listChildren(parentSessionId)`;rc.2 改为 `ctx.subagents.listDescendants(parentSessionId, signal)`(递归全树,插件按 `depth === 1` 收窄为直接子级,diagnostic 行按 `kind`/`reason` 映射)。两者都是持久目录(**不要求父会话有活跃 Agent**) | 报 `no active Remote method exports this endpoint`,「会话工具 → 子代理」整页打不开;rc.2 若继续调用 `listChildren` 会静默落到持久化/注册表兜底,丢失已释放子代理与 label/mode 元数据 |
|
|
141
143
|
| Codex 代理配置 | `settings.get(ns)` | **该方法已移除** | 跨代读取 `readSettingsSectionStrict` | **读不到配置被误判为"用户没开代理"** → 静默改走直连 `chatgpt.com` → 连接超时 → 手机看不到 Codex 余额(桌面网页端正常,因为它用自己的新 API 读同一份设置) |
|
|
142
144
|
|
|
143
145
|
**"读不到配置"与"未启用"必须分开**:`codexProxyUrl` 返回三态——用户没开代理(走直连是对的)/代理可用/**读不到宿主设置**(`unreadable`,显式失败)。把第三种当成第一种,是 Codex 余额静默消失里最隐蔽的一环。严格读取还会区分「命名空间确实不存在」与「`get()`/`describe()` 抛错、describe 形状漂移、描述符缺 `value`」——后者一律 `unreadable`。
|
|
@@ -146,6 +148,10 @@
|
|
|
146
148
|
|
|
147
149
|
**子代理列表的完整性**:不能拿会话注册表当子代理目录——`sessions.list()` 只有 **live/驻留**会话,continuable 子代理结束并释放 handle 后会从中移除,而持久目录仍保留其身份。只用注册表会在父会话还活着时"成功却显示暂无子代理"。目录读不到时退回注册表并标注 `catalogDegraded`,**不让不完整列表冒充完整目录**。
|
|
148
150
|
|
|
151
|
+
**rc.2 的两处 subagents 契约漂移(issue #87)**:
|
|
152
|
+
- 中断:rc.1 `subagents/interruptByParent(childSessionId,parentSessionId,mode)` → rc.2 `subagents/interruptByUser(childSessionId)`(参数收窄,多传字段触发 `gateway/arguments-invalid`;返回 `accepted` receipt 表示已受理,不等于目标已静默)。插件按 `typeof interruptByUser === "function"` 选择端点与载荷,`hostCapabilities.subagents.interrupt` 报 `ok`/`drift`/`missing`。
|
|
153
|
+
- 目录:rc.1 `listChildren` → rc.2 `listDescendants`(递归全树、无 `createdAt`、未知 mode 用 `kind:"diagnostic"`+`reason` 表示)。插件优先 `listDescendants` 且只取 `depth===1`;diagnostic 改用 `kind` 判定,reason 透传为 `status` 三枚举 `unsupported`/`corrupt`/`unavailable`;createdAt 回落 `session.header.createdAt`,缺失排末尾。`hostCapabilities.subagents.catalog` 与 `hostGeneration.subagents` 可归因实际走到的代际。
|
|
154
|
+
|
|
149
155
|
**验证范围(如实标注)**:只对 **`0.2.x` 做真实宿主端到端验证**(本机宿主即 0.2.x)。`0.1.x` 那条路径的真实宿主验不到,**靠两代假宿主夹具保护**(`test/host-compat-020.test.mjs`:按真实签名复刻两代差异,让两条分支都被实际执行到)。因此 0.1.x 一侧属于"夹具已验证、真实宿主未验证"。
|
|
150
156
|
|
|
151
157
|
---
|
|
@@ -167,7 +173,7 @@
|
|
|
167
173
|
- `0.2.0`/`0.1.x` 不改变行为:没有 `createPeer` 时继续传 `undefined`,由网关兜底 / 旧代 3 参开流不需要 peer。
|
|
168
174
|
- 诊断显式化:`checks.hostCapabilities["gateway.eventsPeer"]`(`ok`/`drift`,按**真实创建结果**判定而非只看工厂存在)+ `checks.hostGeneration.eventsPeer`(`createPeer`/`operatorPeer`/`legacy`/`none`/`unknown`),`drift` 时附原因码 `gateway-peer-source-missing`;创建失败写一次性告警日志;`approvalMode: both` 的降级文案不再归咎"宿主版本过低"。
|
|
169
175
|
|
|
170
|
-
**验证范围(如实标注)**:`0.2.1-rc.2` 路径已在**隔离宿主**(`HOME`/`DSH_HOME` 独立、独立 profile、3099 端口)完成端到端验证:`hostCapabilities`
|
|
176
|
+
**验证范围(如实标注)**:`0.2.1-rc.2` 路径已在**隔离宿主**(`HOME`/`DSH_HOME` 独立、独立 profile、3099 端口)完成端到端验证:`hostCapabilities` 全绿(当前 10 项全部 `ok`,含 `gateway.eventsPeer: ok` 与 issue #87 的 `subagents.catalog` / `subagents.interrupt`)、`hostGeneration.eventsPeer: createPeer`、`hostGeneration.subagents: { catalog: "descendants", interrupt: "user" }`、`checks.remoteEvents: true`、`POST /m/api/defaults {"permissionPreset":"workspace-write"}` 返回 `200 {"ok":true}`。三代实参位次、peer 同源(含 `$events/result` 结算)、单例复用与释放、drift 上报由 `test/host-compat-021.test.mjs` 夹具钉住(变异验证:去掉结算 peer 或改为每次新建都会红);`0.2.0`/`0.1.x` 回归由 `test/host-compat-020.test.mjs` 保护。**生产宿主部署与真机验收不在本分支自动化范围内**,需按发布流程人工执行。
|
|
171
177
|
|
|
172
178
|
---
|
|
173
179
|
|
package/lib/endpoint-registry.js
CHANGED
|
@@ -137,6 +137,7 @@ export const REGISTERED_ENDPOINTS = Object.freeze([
|
|
|
137
137
|
{ path: "/files", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
138
138
|
{ path: "/files/upload", methods: "GET/POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
139
139
|
{ path: "/workspace-image", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
140
|
+
{ path: "/workspace-image/consent", methods: "POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
140
141
|
{ path: "/git/branches", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
141
142
|
{ path: "/git/capabilities", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
142
143
|
{ path: "/git/commit", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
@@ -156,7 +157,7 @@ export const REGISTERED_ENDPOINTS = Object.freeze([
|
|
|
156
157
|
{ path: "/notifications", methods: "GET", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
157
158
|
{ path: "/notifications/delete", methods: "GET/POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
158
159
|
{ path: "/notifications/read", methods: "GET/POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
159
|
-
{ path: "/plugin-update/check", methods: "GET", capability: null, auth: "required", why: NO_CAPABILITY_NEEDED },
|
|
160
|
+
{ path: "/plugin-update/check", methods: "GET/POST", capability: null, auth: "required", why: NO_CAPABILITY_NEEDED },
|
|
160
161
|
{ path: "/plugin-update/prepare", methods: "POST", capability: null, auth: "required", why: NO_CAPABILITY_NEEDED },
|
|
161
162
|
{ path: "/plugin-update/log", methods: "GET", capability: null, auth: "required", why: NO_CAPABILITY_NEEDED },
|
|
162
163
|
{ path: "/plugin-update", methods: "POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
package/lib/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { networkInterfaces, homedir } from "node:os";
|
|
|
11
11
|
import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
12
12
|
import {
|
|
13
13
|
accessSync, closeSync, constants, createReadStream, existsSync, fstatSync, linkSync, mkdirSync, openSync,
|
|
14
|
-
readFileSync, readlinkSync, readSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, unlinkSync,
|
|
14
|
+
readFileSync, lstatSync, readlinkSync, 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";
|
|
@@ -1445,6 +1445,7 @@ export function openVerifiedWorkspaceImage({
|
|
|
1445
1445
|
cwdReal,
|
|
1446
1446
|
workspaceRoots,
|
|
1447
1447
|
expectedType,
|
|
1448
|
+
consent = null,
|
|
1448
1449
|
platform = process.platform,
|
|
1449
1450
|
fs = { existsSync, openSync, fstatSync, readlinkSync, closeSync, readSync, constants },
|
|
1450
1451
|
maxBytes = IMAGE_MAX_BYTES,
|
|
@@ -1480,17 +1481,29 @@ export function openVerifiedWorkspaceImage({
|
|
|
1480
1481
|
catch { return { ok: false, status: 501, code: "image-verification-unavailable" }; }
|
|
1481
1482
|
actual = String(actual ?? "").replace(/ \(deleted\)$/, "");
|
|
1482
1483
|
if (!isAbsolute(actual)) return { ok: false, status: 501, code: "image-verification-unavailable" };
|
|
1483
|
-
// open 后(含中间目录换链)实际文件必须仍在 cwd real 与某个登记工作区内。
|
|
1484
|
-
if (!inside(cwdReal, actual)) return { ok: false, status: 403, code: "path-outside-workspace" };
|
|
1485
|
-
let inWorkspace = false;
|
|
1486
|
-
for (const root of workspaceRoots) {
|
|
1487
|
-
if (inside(root, actual)) { inWorkspace = true; break; }
|
|
1488
|
-
}
|
|
1489
|
-
if (!inWorkspace) return { ok: false, status: 403, code: "workspace-not-authorized" };
|
|
1490
1484
|
// 实际文件名也必须仍是期望图片扩展名(防止中间目录换链后指向别的文件)。
|
|
1491
1485
|
if (IMAGE_EXTENSIONS.get(extname(actual).toLowerCase()) !== expectedType) {
|
|
1492
1486
|
return { ok: false, status: 403, code: "path-outside-workspace" };
|
|
1493
1487
|
}
|
|
1488
|
+
if (consent) {
|
|
1489
|
+
// issue #98:工作区外读取必须由 fd 实际路径匹配授权(once=精确文件;
|
|
1490
|
+
// session-directory=图片所在目录,不递归)。授权不绕过 fd 校验。
|
|
1491
|
+
if (consent.scope === "once") {
|
|
1492
|
+
if (actual !== consent.realPath) return { ok: false, status: 403, code: "consent-invalid" };
|
|
1493
|
+
} else if (consent.scope === "session-directory") {
|
|
1494
|
+
if (dirname(actual) !== consent.realDir) return { ok: false, status: 403, code: "consent-invalid" };
|
|
1495
|
+
} else {
|
|
1496
|
+
return { ok: false, status: 403, code: "consent-invalid" };
|
|
1497
|
+
}
|
|
1498
|
+
} else {
|
|
1499
|
+
// open 后(含中间目录换链)实际文件必须仍在 cwd real 与某个登记工作区内。
|
|
1500
|
+
if (!inside(cwdReal, actual)) return { ok: false, status: 403, code: "path-outside-workspace" };
|
|
1501
|
+
let inWorkspace = false;
|
|
1502
|
+
for (const root of workspaceRoots) {
|
|
1503
|
+
if (inside(root, actual)) { inWorkspace = true; break; }
|
|
1504
|
+
}
|
|
1505
|
+
if (!inWorkspace) return { ok: false, status: 403, code: "workspace-not-authorized" };
|
|
1506
|
+
}
|
|
1494
1507
|
const buffer = Buffer.alloc(st.size);
|
|
1495
1508
|
let offset = 0;
|
|
1496
1509
|
while (offset < st.size) {
|
|
@@ -1501,7 +1514,7 @@ export function openVerifiedWorkspaceImage({
|
|
|
1501
1514
|
offset += read;
|
|
1502
1515
|
}
|
|
1503
1516
|
if (offset === 0) return { ok: false, status: 404, code: "image-not-found" };
|
|
1504
|
-
return { ok: true, bytes: buffer.subarray(0, offset) };
|
|
1517
|
+
return { ok: true, bytes: buffer.subarray(0, offset), actualPath: actual };
|
|
1505
1518
|
} finally {
|
|
1506
1519
|
if (fd !== null) {
|
|
1507
1520
|
try { fs.closeSync(fd); } catch {}
|
|
@@ -1509,6 +1522,41 @@ export function openVerifiedWorkspaceImage({
|
|
|
1509
1522
|
}
|
|
1510
1523
|
}
|
|
1511
1524
|
|
|
1525
|
+
/** issue #98:工作区外图片的会话授权(仅内存、12h TTL、不可伪造、绑定 session)。 */
|
|
1526
|
+
export function createWorkspaceImageConsentStore({ ttlMs = 12 * 60 * 60 * 1000, maxEntries = 512 } = {}) {
|
|
1527
|
+
const entries = new Map();
|
|
1528
|
+
const cleanup = (now = Date.now()) => {
|
|
1529
|
+
for (const [id, entry] of entries) {
|
|
1530
|
+
if (entry.expiresAtMs <= now) entries.delete(id);
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
return {
|
|
1534
|
+
issue({ sessionId, scope, realPath, realDir, ttl = ttlMs }) {
|
|
1535
|
+
if (typeof sessionId !== "string" || sessionId === "") throw new Error("session-required");
|
|
1536
|
+
if (scope !== "once" && scope !== "session-directory") throw new Error("invalid-scope");
|
|
1537
|
+
cleanup();
|
|
1538
|
+
while (entries.size >= maxEntries) entries.delete(entries.keys().next().value);
|
|
1539
|
+
const consentId = randomBytes(24).toString("base64url");
|
|
1540
|
+
const expiresAtMs = Date.now() + ttl;
|
|
1541
|
+
entries.set(consentId, { sessionId, scope, realPath, realDir, expiresAtMs });
|
|
1542
|
+
return { consentId, scope, expiresAt: new Date(expiresAtMs).toISOString() };
|
|
1543
|
+
},
|
|
1544
|
+
lookup(consentId, sessionId) {
|
|
1545
|
+
if (typeof consentId !== "string" || consentId === "") return null;
|
|
1546
|
+
cleanup();
|
|
1547
|
+
const entry = entries.get(consentId);
|
|
1548
|
+
if (!entry || entry.sessionId !== sessionId) return null;
|
|
1549
|
+
if (entry.expiresAtMs <= Date.now()) {
|
|
1550
|
+
entries.delete(consentId);
|
|
1551
|
+
return null;
|
|
1552
|
+
}
|
|
1553
|
+
return entry;
|
|
1554
|
+
},
|
|
1555
|
+
clear() { entries.clear(); },
|
|
1556
|
+
size: () => entries.size,
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1512
1560
|
const fileMimeOf = (name) => FILE_MIME[extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
1513
1561
|
|
|
1514
1562
|
/**
|
|
@@ -3393,11 +3441,84 @@ export function detailEventFor(event) {
|
|
|
3393
3441
|
}
|
|
3394
3442
|
|
|
3395
3443
|
/**
|
|
3396
|
-
*
|
|
3397
|
-
*
|
|
3444
|
+
* issue #99:把 surface 投影 envelope 的只读字段透传给移动端。
|
|
3445
|
+
*
|
|
3446
|
+
* DSH 的真实 surface 形状是 union(以 session 22226918 实测与内核落盘为准):
|
|
3447
|
+
* - `surfaceOp: "append"`(字符串,真实事件常见;可带 sourceEventSeqs);
|
|
3448
|
+
* - `surfaceOp: { op: "replace"|"append", startSeq, endSeq }`(对象;replace 必带
|
|
3449
|
+
* start/end,append 可省略 start/end)。
|
|
3450
|
+
* App 侧只有 **对象 replace** 触发 shadow;字符串/对象 append 只是投影元数据,
|
|
3451
|
+
* 不遮蔽 source 事件,且 sourceEventSeqs 不得丢弃。
|
|
3452
|
+
*
|
|
3453
|
+
* 输出形状(向后兼容、文档化):
|
|
3454
|
+
* - 输入字符串 append → 输出保持字符串 `"append"`;
|
|
3455
|
+
* - 输入对象 → 输出规范化对象 `{op:"replace"|"append", (startSeq,endSeq)?}`;
|
|
3456
|
+
* - 非法/未知字符串或对象字段 → **整组 envelope 字段丢弃**,绝不猜测。
|
|
3457
|
+
*
|
|
3458
|
+
* 严格校验(复审 P2):start/end 仅接受非负 safe integer(不做 Number() 强转);
|
|
3459
|
+
* replace 要求 startSeq<=endSeq;sourceEventSeqs 每一项严格小于当前事件 seq、
|
|
3460
|
+
* 去重后正序、最多 64 项。任一非法 → 整个 envelope 无输出。
|
|
3398
3461
|
*/
|
|
3462
|
+
const isSafeSeq = (value) =>
|
|
3463
|
+
typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
3464
|
+
|
|
3465
|
+
/** 规范化 surfaceOp;返回 undefined=非法/缺失(调用方整组丢弃)。 */
|
|
3466
|
+
function normalizeSurfaceOp(raw) {
|
|
3467
|
+
if (typeof raw === "string") {
|
|
3468
|
+
return raw === "append" ? "append" : undefined;
|
|
3469
|
+
}
|
|
3470
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
|
3471
|
+
if (raw.op !== "replace" && raw.op !== "append") return undefined;
|
|
3472
|
+
if (raw.op === "replace") {
|
|
3473
|
+
if (!isSafeSeq(raw.startSeq) || !isSafeSeq(raw.endSeq)) return undefined;
|
|
3474
|
+
if (raw.startSeq > raw.endSeq) return undefined;
|
|
3475
|
+
return { op: "replace", startSeq: raw.startSeq, endSeq: raw.endSeq };
|
|
3476
|
+
}
|
|
3477
|
+
// append:start/end 可整体省略;若出现则必须同时存在且合法有序。
|
|
3478
|
+
const hasStart = raw.startSeq !== undefined;
|
|
3479
|
+
const hasEnd = raw.endSeq !== undefined;
|
|
3480
|
+
if (!hasStart && !hasEnd) return { op: "append" };
|
|
3481
|
+
if (!hasStart || !hasEnd || !isSafeSeq(raw.startSeq) || !isSafeSeq(raw.endSeq)) {
|
|
3482
|
+
return undefined;
|
|
3483
|
+
}
|
|
3484
|
+
if (raw.startSeq > raw.endSeq) return undefined;
|
|
3485
|
+
return { op: "append", startSeq: raw.startSeq, endSeq: raw.endSeq };
|
|
3486
|
+
}
|
|
3487
|
+
|
|
3488
|
+
export function surfaceWireFields(event) {
|
|
3489
|
+
const hasSurfaceOp = event?.surfaceOp !== undefined;
|
|
3490
|
+
const hasSources = event?.sourceEventSeqs !== undefined;
|
|
3491
|
+
if (!hasSurfaceOp && !hasSources) return {};
|
|
3492
|
+
const fields = {};
|
|
3493
|
+
if (hasSurfaceOp) {
|
|
3494
|
+
const surfaceOp = normalizeSurfaceOp(event.surfaceOp);
|
|
3495
|
+
if (surfaceOp === undefined) return {};
|
|
3496
|
+
fields.surfaceOp = surfaceOp;
|
|
3497
|
+
}
|
|
3498
|
+
if (hasSources) {
|
|
3499
|
+
const source = event.sourceEventSeqs;
|
|
3500
|
+
const currentSeq = event.seq;
|
|
3501
|
+
if (!Array.isArray(source) || source.length === 0 || source.length > 64) return {};
|
|
3502
|
+
if (!isSafeSeq(currentSeq)) return {};
|
|
3503
|
+
const unique = [];
|
|
3504
|
+
const seen = new Set();
|
|
3505
|
+
for (const value of source) {
|
|
3506
|
+
if (!isSafeSeq(value) || value >= currentSeq) return {};
|
|
3507
|
+
if (seen.has(value)) continue;
|
|
3508
|
+
seen.add(value);
|
|
3509
|
+
unique.push(value);
|
|
3510
|
+
}
|
|
3511
|
+
if (unique.length === 0 || unique.length > 64) return {};
|
|
3512
|
+
unique.sort((a, b) => a - b);
|
|
3513
|
+
fields.sourceEventSeqs = unique;
|
|
3514
|
+
}
|
|
3515
|
+
return fields;
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3399
3518
|
export function summarizeEvent(event, options = {}) {
|
|
3400
|
-
const
|
|
3519
|
+
const base = summarizeEventCore(event, options);
|
|
3520
|
+
const wire = surfaceWireFields(event);
|
|
3521
|
+
const summary = Object.keys(wire).length > 0 ? { ...base, ...wire } : base;
|
|
3401
3522
|
if (event?.seq === undefined || event?.seq === null) return summary;
|
|
3402
3523
|
// 只对详情端点真的能取回的事件声明指针:token delta / 内部记录会被 /event-detail
|
|
3403
3524
|
// 拒绝(isTimelineRecord),未列入 allow-list 的类型同样会被拒(fail-closed)。
|
|
@@ -3905,9 +4026,13 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
3905
4026
|
if (pluginUpdateChecked) return;
|
|
3906
4027
|
pluginUpdateChecked = true;
|
|
3907
4028
|
if (resolvePluginUpdateSource(config.pluginUpdateManifest).kind === UPDATE_SOURCE_KIND.OFF) return;
|
|
3908
|
-
|
|
4029
|
+
// issue #96 review P2:bootstrap 也走共享 checkService(deadline/缓存/in-flight 去重),
|
|
4030
|
+
// 不再裸调 checkForUpdate;错误只落稳定 code,不把内部 message 写入公开状态。
|
|
4031
|
+
updates.checkSync()
|
|
3909
4032
|
.then((r) => Object.assign(pluginUpdateStatus, r))
|
|
3910
|
-
.catch((
|
|
4033
|
+
.catch(() => Object.assign(pluginUpdateStatus, {
|
|
4034
|
+
state: "unavailable", reason: "update-check-failed", source: "npm", checkedAt: new Date().toISOString(),
|
|
4035
|
+
}));
|
|
3911
4036
|
};
|
|
3912
4037
|
// 自更新能力与降级指引:内容状态驱动"能不能一键",版本号只管文案(评审 R11)。
|
|
3913
4038
|
//
|
|
@@ -4029,6 +4154,19 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4029
4154
|
transaction: transactionSummary(view),
|
|
4030
4155
|
};
|
|
4031
4156
|
}
|
|
4157
|
+
/** issue #96:检查结果按请求方投影(不带既有事务摘要)。 */
|
|
4158
|
+
function publicCheckResult(req, result) {
|
|
4159
|
+
const view = clientViewFor(req);
|
|
4160
|
+
return {
|
|
4161
|
+
...(result ?? {}),
|
|
4162
|
+
...pluginUpdateCapabilities(),
|
|
4163
|
+
release: result?.release ? clientReleaseView(result.release, view) : null,
|
|
4164
|
+
};
|
|
4165
|
+
}
|
|
4166
|
+
const consentTtlOverride = Number(ctx.get?.("workspaceImageConsentTtlMs"));
|
|
4167
|
+
const imageConsentStore = createWorkspaceImageConsentStore(
|
|
4168
|
+
Number.isFinite(consentTtlOverride) && consentTtlOverride > 0 ? { ttlMs: consentTtlOverride } : {},
|
|
4169
|
+
);
|
|
4032
4170
|
const updates = createPluginUpdateController({
|
|
4033
4171
|
home: homedir(), configValue: config.pluginUpdateManifest, profileDir: pluginProfileDir, packageName: pluginPackageName,
|
|
4034
4172
|
capabilities: pluginUpdateCapabilities, localVersion: () => pluginVersion(), localContentSha256: selfContentSha256,
|
|
@@ -6733,6 +6871,32 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
6733
6871
|
};
|
|
6734
6872
|
// 流式端点:只取首帧(如 session/control 基线流),unary invoke 会被网关拒绝
|
|
6735
6873
|
const RPC_STREAM_METHODS = new Set(["session.control"]);
|
|
6874
|
+
/**
|
|
6875
|
+
* issue #87:subagents 服务代际探测(ADR 0017:能力优先,不用版本号)。
|
|
6876
|
+
* rc.2 提供 listDescendants/interruptByUser;rc.1 提供 listChildren/interruptByParent。
|
|
6877
|
+
*/
|
|
6878
|
+
const subagentsService = () => {
|
|
6879
|
+
try {
|
|
6880
|
+
return ctx.get("subagents");
|
|
6881
|
+
} catch {
|
|
6882
|
+
return undefined;
|
|
6883
|
+
}
|
|
6884
|
+
};
|
|
6885
|
+
const subagentsGeneration = () => {
|
|
6886
|
+
const service = subagentsService();
|
|
6887
|
+
return {
|
|
6888
|
+
catalog: typeof service?.listDescendants === "function"
|
|
6889
|
+
? "descendants"
|
|
6890
|
+
: typeof service?.listChildren === "function"
|
|
6891
|
+
? "children"
|
|
6892
|
+
: "none",
|
|
6893
|
+
interrupt: typeof service?.interruptByUser === "function"
|
|
6894
|
+
? "user"
|
|
6895
|
+
: typeof service?.interruptByParent === "function"
|
|
6896
|
+
? "parent"
|
|
6897
|
+
: "none",
|
|
6898
|
+
};
|
|
6899
|
+
};
|
|
6736
6900
|
/** v3.1.2:session/control(baseline)中取某会话的投影值(modelSelection/imageLimits 等)。 */
|
|
6737
6901
|
const projectionOf = (control, sessionId) =>
|
|
6738
6902
|
control?.type === "baseline" ? control.value?.projections?.[sessionId]?.values : undefined;
|
|
@@ -6795,8 +6959,13 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
6795
6959
|
// 0.2.x 位置参数形态形参 ≥3;0.1.x 是 (endpoint, options) 两参
|
|
6796
6960
|
const modernGateway = gateway.invokeRpc.length >= 3;
|
|
6797
6961
|
const peer = modernGateway ? gatewayPeer() : void 0;
|
|
6798
|
-
|
|
6799
|
-
|
|
6962
|
+
let endpoint = RPC_ENDPOINT_RENAMES[method] ?? method.replace(".", "/");
|
|
6963
|
+
let adapted = RPC_PAYLOAD_ADAPTER[method]?.(payload) ?? { request: payload };
|
|
6964
|
+
// issue #87:rc.2 中断端点改名且参数收窄到仅 childSessionId;rc.1 保持旧 3 字段。
|
|
6965
|
+
if (method === "subagent.interrupt" && typeof subagentsService()?.interruptByUser === "function") {
|
|
6966
|
+
endpoint = "subagents/interruptByUser";
|
|
6967
|
+
adapted = { childSessionId: payload.childSessionId };
|
|
6968
|
+
}
|
|
6800
6969
|
if (RPC_STREAM_METHODS.has(method)) {
|
|
6801
6970
|
// 基线流(session/control 等):首帧即基线快照,取完即断
|
|
6802
6971
|
const [namespace, name] = endpoint.split("/");
|
|
@@ -7419,15 +7588,47 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
7419
7588
|
}
|
|
7420
7589
|
|
|
7421
7590
|
|
|
7422
|
-
// 只读 NPM
|
|
7591
|
+
// 只读 NPM 检查:旧 App GET 缓存命中立即返回;新 App POST 异步检查 + checkId 轮询。
|
|
7592
|
+
// 不下载产物、不改 profile、不重启,也不返回半结果。
|
|
7423
7593
|
if (rest === "/plugin-update/check") {
|
|
7424
|
-
|
|
7594
|
+
// registry 提取器按头部识别方法:用集合校验,避免被块内 GET 分支误判成 GET。
|
|
7595
|
+
if (!["GET", "POST"].includes(method)) return error(res, 405, "method-not-allowed");
|
|
7596
|
+
if (method === "GET") {
|
|
7597
|
+
const checkId = url.searchParams.get("checkId") ?? "";
|
|
7598
|
+
if (checkId !== "") {
|
|
7599
|
+
const status = updates.getAsyncCheck(checkId);
|
|
7600
|
+
if (status.status === 404) return error(res, 404, "check-not-found");
|
|
7601
|
+
if (status.status === 410) return error(res, 410, "check-expired");
|
|
7602
|
+
const body = status.body;
|
|
7603
|
+
if (body.state === "done") {
|
|
7604
|
+
return sendJson(res, 200, {
|
|
7605
|
+
ok: true,
|
|
7606
|
+
state: "done",
|
|
7607
|
+
checkId,
|
|
7608
|
+
pluginUpdate: publicCheckResult(req, body.result),
|
|
7609
|
+
});
|
|
7610
|
+
}
|
|
7611
|
+
return sendJson(res, 200, { ok: true, ...body });
|
|
7612
|
+
}
|
|
7613
|
+
try {
|
|
7614
|
+
Object.assign(pluginUpdateStatus, await updates.checkSync());
|
|
7615
|
+
} catch {
|
|
7616
|
+
Object.assign(pluginUpdateStatus, { state: "unavailable", reason: "update-check-failed", source: "npm", checkedAt: new Date().toISOString() });
|
|
7617
|
+
}
|
|
7618
|
+
return sendJson(res, 200, { ok: true, pluginUpdate: publicUpdateStatus(req) });
|
|
7619
|
+
}
|
|
7620
|
+
// POST:{force?:boolean} → 200 {ok:true,state:"checking",checkId}。绝不用 202,
|
|
7621
|
+
// 现有 App 的 postJson 只接受 200。
|
|
7622
|
+
let body;
|
|
7425
7623
|
try {
|
|
7426
|
-
|
|
7624
|
+
const text = await readBody(req, 16 * 1024);
|
|
7625
|
+
body = text ? JSON.parse(text) : {};
|
|
7427
7626
|
} catch {
|
|
7428
|
-
|
|
7627
|
+
return error(res, 400, "bad-request", "body must be JSON");
|
|
7429
7628
|
}
|
|
7430
|
-
|
|
7629
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return error(res, 400, "bad-request");
|
|
7630
|
+
const started = updates.startAsyncCheck({ force: body.force === true });
|
|
7631
|
+
return sendJson(res, 200, { ok: true, state: "checking", checkId: started.checkId });
|
|
7431
7632
|
}
|
|
7432
7633
|
|
|
7433
7634
|
// 旧 carrier 缺少 App build metadata 时,用户明确触发的预检只下载/校验 NPM 产物,不改 profile。
|
|
@@ -9532,6 +9733,7 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
9532
9733
|
const gatewaySvc = ctx.get("typertGateway");
|
|
9533
9734
|
const presetsSvc = ctx.get("permissionPresets");
|
|
9534
9735
|
const workspaceSvc = ctx.get("workspaceRegistry");
|
|
9736
|
+
const subagentsSvc = subagentsService();
|
|
9535
9737
|
// issue #34:0.2.1 的进程内 peer 来源(`connection.createPeer`);旧代靠网关 operator 兜底
|
|
9536
9738
|
let connectionSvc;
|
|
9537
9739
|
try {
|
|
@@ -9596,6 +9798,12 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
9596
9798
|
// (网关不再兜底)——只探存在性会把「开流必失败」报成绿灯,正是 ADR 0017 要防的
|
|
9597
9799
|
// "服务在、成员在、语义已变"。旧代 3 参开流不需要 peer,按 ok 处理。
|
|
9598
9800
|
"gateway.eventsPeer": eventsPeerProbe.state,
|
|
9801
|
+
// issue #87:rc.2 两处宿主契约漂移(中断端点改名/参数收窄、目录方法改名)。
|
|
9802
|
+
// 两种代际各自的成员都算 ok;都缺失才 drift/missing。
|
|
9803
|
+
"subagents.catalog": capabilityState(subagentsSvc, (s) =>
|
|
9804
|
+
typeof s.listDescendants === "function" || typeof s.listChildren === "function"),
|
|
9805
|
+
"subagents.interrupt": capabilityState(subagentsSvc, (s) =>
|
|
9806
|
+
typeof s.interruptByUser === "function" || typeof s.interruptByParent === "function"),
|
|
9599
9807
|
};
|
|
9600
9808
|
checks.hostCapabilities = hostCapabilities;
|
|
9601
9809
|
// 已探测到的代际选择:便于人工核对插件实际走了哪条路径(排查"为什么这个功能表现不同")
|
|
@@ -9611,6 +9819,8 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
9611
9819
|
: eventsPeerProbe.state === "ok"
|
|
9612
9820
|
? peerSource
|
|
9613
9821
|
: "none",
|
|
9822
|
+
// issue #87:实际走的 subagents 代际(descendants/children、user/parent)。
|
|
9823
|
+
subagents: subagentsGeneration(),
|
|
9614
9824
|
};
|
|
9615
9825
|
// 任一项非 ok 都必须给出可执行的原因,而不只是状态值
|
|
9616
9826
|
const degradedCaps = Object.entries(hostCapabilities).filter(([, state]) => state !== "ok");
|
|
@@ -10098,10 +10308,103 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
10098
10308
|
}
|
|
10099
10309
|
return;
|
|
10100
10310
|
}
|
|
10311
|
+
// issue #98:工作区外图片的会话授权(once / session-directory)。
|
|
10312
|
+
if (rest === "/workspace-image/consent") {
|
|
10313
|
+
if (method !== "POST") return error(res, 405, "method-not-allowed");
|
|
10314
|
+
let body;
|
|
10315
|
+
try {
|
|
10316
|
+
const text = await readBody(req, 16 * 1024);
|
|
10317
|
+
body = text ? JSON.parse(text) : {};
|
|
10318
|
+
} catch {
|
|
10319
|
+
return error(res, 400, "bad-request", "body must be JSON");
|
|
10320
|
+
}
|
|
10321
|
+
const sessionId = typeof body?.sessionId === "string" ? body.sessionId : "";
|
|
10322
|
+
const rawPath = typeof body?.path === "string" ? body.path : "";
|
|
10323
|
+
const scope = body?.scope === "session-directory" ? "session-directory" : body?.scope === "once" ? "once" : "";
|
|
10324
|
+
if (sessionId === "" || rawPath === "" || rawPath.includes("\0") || scope === "") {
|
|
10325
|
+
return error(res, 400, "bad-request", "sessionId/path/scope required");
|
|
10326
|
+
}
|
|
10327
|
+
const agents = ctx.get("agents");
|
|
10328
|
+
const sessions = ctx.get("sessions");
|
|
10329
|
+
const liveSession = agents?.get?.(sessionId)?.session;
|
|
10330
|
+
const session = liveSession ?? sessions?.get?.(sessionId);
|
|
10331
|
+
if (!session) return error(res, 404, "session-not-found");
|
|
10332
|
+
const cwd = sessionCwdOf(session);
|
|
10333
|
+
if (typeof cwd !== "string" || cwd === "") return error(res, 404, "workspace-not-found");
|
|
10334
|
+
const cwdLex = resolve(normalizeServerPath(cwd));
|
|
10335
|
+
let candidateLex;
|
|
10336
|
+
try {
|
|
10337
|
+
const normalized = normalizeServerPath(rawPath);
|
|
10338
|
+
candidateLex = isAbsolute(normalized) ? resolve(normalized) : resolve(cwdLex, normalized);
|
|
10339
|
+
} catch {
|
|
10340
|
+
return error(res, 400, "bad-request", "invalid path");
|
|
10341
|
+
}
|
|
10342
|
+
const regexExtension = extname(candidateLex).toLowerCase();
|
|
10343
|
+
const expectedType = IMAGE_EXTENSIONS.get(regexExtension);
|
|
10344
|
+
if (!expectedType) return error(res, 415, "unsupported-image-type");
|
|
10345
|
+
// 前置:会话 cwd 必须属于登记工作区(授权不改变工作区前置)。
|
|
10346
|
+
const registry = ctx.get("workspaceRegistry");
|
|
10347
|
+
const listed = registry?.list?.();
|
|
10348
|
+
const workspaces = Array.isArray(listed) ? listed : [];
|
|
10349
|
+
let realCwd;
|
|
10350
|
+
let cwdInWorkspace = false;
|
|
10351
|
+
let workspaceRoots = [];
|
|
10352
|
+
try { realCwd = realpathSync(cwdLex); } catch { return error(res, 404, "workspace-not-found"); }
|
|
10353
|
+
for (const entry of workspaces) {
|
|
10354
|
+
const root = entry?.path;
|
|
10355
|
+
if (typeof root !== "string" || root === "") continue;
|
|
10356
|
+
try {
|
|
10357
|
+
const realRoot = realpathSync(root);
|
|
10358
|
+
workspaceRoots.push(realRoot);
|
|
10359
|
+
if (relative(realRoot, realCwd) === "" || (!relative(realRoot, realCwd).startsWith("..") && !isAbsolute(relative(realRoot, realCwd)))) {
|
|
10360
|
+
cwdInWorkspace = true;
|
|
10361
|
+
}
|
|
10362
|
+
} catch {}
|
|
10363
|
+
}
|
|
10364
|
+
if (!cwdInWorkspace) return error(res, 403, "workspace-not-authorized");
|
|
10365
|
+
// issue #98 P3:GET 用 O_NOFOLLOW,末级 symlink 永远无法通过 fd 校验;
|
|
10366
|
+
// consent 端点提前拒绝,避免“授权后仍 403”的死循环。
|
|
10367
|
+
try {
|
|
10368
|
+
if (lstatSync(candidateLex).isSymbolicLink()) {
|
|
10369
|
+
return error(res, 415, "unsupported-image-symlink");
|
|
10370
|
+
}
|
|
10371
|
+
} catch {
|
|
10372
|
+
return error(res, 404, "image-not-found");
|
|
10373
|
+
}
|
|
10374
|
+
let realTarget;
|
|
10375
|
+
try { realTarget = realpathSync(candidateLex); } catch { return error(res, 404, "image-not-found"); }
|
|
10376
|
+
let targetStat;
|
|
10377
|
+
try { targetStat = statSync(realTarget); } catch { return error(res, 404, "image-not-found"); }
|
|
10378
|
+
if (!targetStat.isFile() || targetStat.size <= 0) return error(res, 404, "image-not-found");
|
|
10379
|
+
if (targetStat.size > IMAGE_MAX_BYTES) return error(res, 413, "image-too-large");
|
|
10380
|
+
let head;
|
|
10381
|
+
try { head = readFileSync(realTarget); } catch { return error(res, 404, "image-not-found"); }
|
|
10382
|
+
if (head.length > IMAGE_MAX_BYTES) return error(res, 413, "image-too-large");
|
|
10383
|
+
const sniffed = sniffImageBufferType(head);
|
|
10384
|
+
if (!sniffed || sniffed !== expectedType) return error(res, 415, "unsupported-image-type");
|
|
10385
|
+
const dims = imageDimensions(head);
|
|
10386
|
+
if (!dims) return error(res, 415, "unsupported-image-type");
|
|
10387
|
+
if (dims.width <= 0 || dims.height <= 0 ||
|
|
10388
|
+
dims.width > IMAGE_MAX_DIMENSION || dims.height > IMAGE_MAX_DIMENSION ||
|
|
10389
|
+
dims.width * dims.height > IMAGE_MAX_PIXELS) return error(res, 413, "image-too-large");
|
|
10390
|
+
let record = { sessionId, scope, realPath: realTarget, realDir: null };
|
|
10391
|
+
if (scope === "session-directory") {
|
|
10392
|
+
const realDir = dirname(realTarget);
|
|
10393
|
+
if (realDir === "/" || realDir === realpathSync(homedir()) ||
|
|
10394
|
+
workspaceRoots.some((root) => realDir === root)) {
|
|
10395
|
+
return error(res, 403, "consent-root-not-allowed");
|
|
10396
|
+
}
|
|
10397
|
+
record = { ...record, realDir };
|
|
10398
|
+
}
|
|
10399
|
+
let issued;
|
|
10400
|
+
try { issued = imageConsentStore.issue(record); }
|
|
10401
|
+
catch { return error(res, 400, "bad-request", "invalid consent scope"); }
|
|
10402
|
+
return sendJson(res, 200, { ok: true, ...issued });
|
|
10403
|
+
}
|
|
10101
10404
|
if (rest === "/workspace-image") {
|
|
10102
10405
|
if (method !== "GET" && method !== "HEAD") return error(res, 405, "method-not-allowed");
|
|
10103
|
-
// issue #94
|
|
10104
|
-
//
|
|
10406
|
+
// issue #94/#98:工作区内图片无需授权;工作区外必须携带有效 consentId。
|
|
10407
|
+
// fd/O_NOFOLLOW/proc containment、图片类型/大小/像素限制始终执行。
|
|
10105
10408
|
const sessionId = url.searchParams.get("sessionId") ?? "";
|
|
10106
10409
|
if (!sessionId) return error(res, 400, "bad-request", "missing sessionId");
|
|
10107
10410
|
const rawPath = url.searchParams.get("path");
|
|
@@ -10125,13 +10428,12 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
10125
10428
|
const rel = relative(parent, child);
|
|
10126
10429
|
return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
|
|
10127
10430
|
};
|
|
10128
|
-
|
|
10431
|
+
const insideCwd = inside(cwdLex, candidateLex);
|
|
10129
10432
|
const extension = extname(candidateLex).toLowerCase();
|
|
10130
10433
|
const expectedType = IMAGE_EXTENSIONS.get(extension);
|
|
10131
10434
|
if (!expectedType) return error(res, 415, "unsupported-image-type");
|
|
10132
10435
|
let realCwd;
|
|
10133
10436
|
try { realCwd = realpathSync(cwdLex); } catch { return error(res, 404, "workspace-not-found"); }
|
|
10134
|
-
// 注册工作区闸门:cwd 必须属于某个 workspaceRegistry 登记的工作区。
|
|
10135
10437
|
const registry = ctx.get("workspaceRegistry");
|
|
10136
10438
|
const listed = registry?.list?.();
|
|
10137
10439
|
const workspaces = Array.isArray(listed) ? listed : [];
|
|
@@ -10147,11 +10449,19 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
10147
10449
|
} catch {}
|
|
10148
10450
|
}
|
|
10149
10451
|
if (!cwdInWorkspace) return error(res, 403, "workspace-not-authorized");
|
|
10452
|
+
const consentId = url.searchParams.get("consentId") ?? "";
|
|
10453
|
+
let consent = null;
|
|
10454
|
+
if (!insideCwd) {
|
|
10455
|
+
if (consentId === "") return error(res, 403, "consent-required");
|
|
10456
|
+
consent = imageConsentStore.lookup(consentId, sessionId);
|
|
10457
|
+
if (!consent) return error(res, 403, "consent-invalid");
|
|
10458
|
+
}
|
|
10150
10459
|
const opened = openVerifiedWorkspaceImage({
|
|
10151
10460
|
candidateLex,
|
|
10152
10461
|
cwdReal: realCwd,
|
|
10153
10462
|
workspaceRoots,
|
|
10154
10463
|
expectedType,
|
|
10464
|
+
consent,
|
|
10155
10465
|
});
|
|
10156
10466
|
if (!opened.ok) return error(res, opened.status, opened.code);
|
|
10157
10467
|
const bytes = opened.bytes;
|
|
@@ -10160,7 +10470,6 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
10160
10470
|
const sniffed = sniffImageBufferType(bytes);
|
|
10161
10471
|
if (!sniffed || sniffed !== expectedType) return error(res, 415, "unsupported-image-type");
|
|
10162
10472
|
const dims = imageDimensions(bytes);
|
|
10163
|
-
// issue #95:解析不到像素尺寸一律 fail-closed(不把未知尺寸当通过)。
|
|
10164
10473
|
if (!dims) return error(res, 415, "unsupported-image-type");
|
|
10165
10474
|
if (dims.width <= 0 || dims.height <= 0 ||
|
|
10166
10475
|
dims.width > IMAGE_MAX_DIMENSION || dims.height > IMAGE_MAX_DIMENSION ||
|
|
@@ -10314,7 +10623,9 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
10314
10623
|
// issue #20:与 /sessions 同一条全量枚举路径,宿主目录与持久化回退都接入请求取消。
|
|
10315
10624
|
const signal = requestAbort(res);
|
|
10316
10625
|
const parent = sessions?.get?.(parentSessionId);
|
|
10317
|
-
|
|
10626
|
+
// issue #87:rc.2 用 listDescendants(递归,需 depth===1 收窄);rc.1 回退 listChildren。
|
|
10627
|
+
const hasDescendants = typeof subagentsSvc?.listDescendants === "function";
|
|
10628
|
+
const hasChildren = typeof subagentsSvc?.listChildren === "function";
|
|
10318
10629
|
// 目录来源按优先级取——**两边能力都要保留**(issue #14/#17/#21):
|
|
10319
10630
|
// ① 宿主持久目录 `subagents.listChildren`:包含已释放子代理和 mode/label 元数据,
|
|
10320
10631
|
// 不要求父会话有活跃 Agent;
|
|
@@ -10323,11 +10634,35 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
10323
10634
|
// 状态另取自活 agent(AgentStatus = idle | running);目录条目本身不带状态。
|
|
10324
10635
|
let catalogRows = null;
|
|
10325
10636
|
let catalogDegraded = false;
|
|
10326
|
-
|
|
10637
|
+
// 决策 1(A):listDescendants 返回整棵树,只取直接子级 depth===1。
|
|
10638
|
+
if (hasDescendants) {
|
|
10639
|
+
try {
|
|
10640
|
+
const rows = await subagentsSvc.listDescendants(parentSessionId, signal);
|
|
10641
|
+
if (signal.aborted) return;
|
|
10642
|
+
if (Array.isArray(rows)) {
|
|
10643
|
+
catalogRows = rows
|
|
10644
|
+
.filter((row) => row?.depth === 1)
|
|
10645
|
+
.map((row) => ({
|
|
10646
|
+
...row,
|
|
10647
|
+
// rc.2 diagnostic 行没有 mode,只有 kind + reason;不要用 mode 判分支。
|
|
10648
|
+
diagnosticReason: row?.kind === "diagnostic" ? row.reason : undefined,
|
|
10649
|
+
}));
|
|
10650
|
+
}
|
|
10651
|
+
} catch {
|
|
10652
|
+
if (signal.aborted) return;
|
|
10653
|
+
catalogRows = null; // 目录读取失败 → 回退 listChildren / 持久化枚举
|
|
10654
|
+
}
|
|
10655
|
+
}
|
|
10656
|
+
if (catalogRows === null && hasChildren) {
|
|
10327
10657
|
try {
|
|
10328
10658
|
const rows = await subagentsSvc.listChildren(parentSessionId, signal);
|
|
10329
10659
|
if (signal.aborted) return;
|
|
10330
|
-
if (Array.isArray(rows))
|
|
10660
|
+
if (Array.isArray(rows)) {
|
|
10661
|
+
catalogRows = rows.map((row) => ({
|
|
10662
|
+
...row,
|
|
10663
|
+
diagnosticReason: row?.mode === "unknown" ? "unsupported" : undefined,
|
|
10664
|
+
}));
|
|
10665
|
+
}
|
|
10331
10666
|
} catch {
|
|
10332
10667
|
if (signal.aborted) return; // 客户端已离开,不再触发回退或写响应
|
|
10333
10668
|
catalogRows = null; // 目录读取失败 → 落到持久化枚举
|
|
@@ -10380,7 +10715,17 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
10380
10715
|
const label = typeof row?.label === "string" && row.label !== "" ? row.label : undefined;
|
|
10381
10716
|
const rowTitle = typeof row?.title === "string" && row.title !== "" ? row.title : undefined;
|
|
10382
10717
|
const liveTitle = sessionTitleOf(session);
|
|
10383
|
-
|
|
10718
|
+
const diagnosticReason = ["unsupported", "corrupt", "unavailable"].includes(row?.diagnosticReason)
|
|
10719
|
+
? row.diagnosticReason
|
|
10720
|
+
: undefined;
|
|
10721
|
+
const isDiagnostic = row?.kind === "diagnostic" ||
|
|
10722
|
+
row?.diagnosticReason !== undefined ||
|
|
10723
|
+
row?.mode === "unknown";
|
|
10724
|
+
return {
|
|
10725
|
+
id, live, createdAt, label, rowTitle, liveTitle,
|
|
10726
|
+
rowName: typeof row?.name === "string" && row.name !== "" ? row.name : undefined,
|
|
10727
|
+
isDiagnostic, diagnosticReason,
|
|
10728
|
+
};
|
|
10384
10729
|
}).filter((row) => row.id !== "");
|
|
10385
10730
|
// issue #30 评审 WARNING 1:目录条目的 `label` 可省略,而**已释放**的子代理不在 live
|
|
10386
10731
|
// 注册表里(拿不到会话快照标题)。三个来源都拿不到时必须按需**补读持久标题**,
|
|
@@ -10395,18 +10740,16 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
10395
10740
|
const entries = rows
|
|
10396
10741
|
.map((row) => ({
|
|
10397
10742
|
id: row.id,
|
|
10398
|
-
// issue #
|
|
10399
|
-
//
|
|
10400
|
-
|
|
10401
|
-
// 顺带静默删掉既有诊断语义(docs/03-api 承诺 `status` 可为 diagnostic reason)。
|
|
10402
|
-
kind: row.mode === "unknown" ? "diagnostic" : "child",
|
|
10743
|
+
// issue #87:rc.2 diagnostic 用 kind==='diagnostic' 判定(无 mode 字段);
|
|
10744
|
+
// reason 映射为三枚举 status:unsupported / corrupt / unavailable(决策 3 C)。
|
|
10745
|
+
kind: row.isDiagnostic ? "diagnostic" : "child",
|
|
10403
10746
|
// 状态取自活 agent;已结束/已释放的子代理回落 inactive(与既有语义一致)
|
|
10404
|
-
status: row.
|
|
10405
|
-
? "unsupported"
|
|
10747
|
+
status: row.isDiagnostic
|
|
10748
|
+
? (row.diagnosticReason ?? "unsupported")
|
|
10406
10749
|
: (typeof row.live?.status === "string" && row.live.status !== ""
|
|
10407
10750
|
? (row.live.status === "running" ? "running" : "inactive") // AgentStatus = 'idle' | 'running'
|
|
10408
10751
|
: "inactive"),
|
|
10409
|
-
title: row.label ?? row.rowTitle ?? row.liveTitle ?? persistedTitleMap.get(row.id) ?? shortSessionId(row.id),
|
|
10752
|
+
title: row.label ?? row.rowName ?? row.rowTitle ?? row.liveTitle ?? persistedTitleMap.get(row.id) ?? shortSessionId(row.id),
|
|
10410
10753
|
...(row.createdAt === undefined ? {} : { createdAt: row.createdAt }),
|
|
10411
10754
|
}))
|
|
10412
10755
|
.sort((a, b) => {
|
|
@@ -10434,8 +10777,13 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
10434
10777
|
const childSessionId = typeof body.childSessionId === "string" ? body.childSessionId : "";
|
|
10435
10778
|
if (!parentSessionId || !childSessionId) return error(res, 400, "parentSessionId-and-childSessionId-required");
|
|
10436
10779
|
try {
|
|
10437
|
-
await apiRpc("subagent.interrupt", { parentSessionId, childSessionId, mode: "continuable" });
|
|
10438
|
-
|
|
10780
|
+
const receipt = await apiRpc("subagent.interrupt", { parentSessionId, childSessionId, mode: "continuable" });
|
|
10781
|
+
// issue #87:rc.2 返回 SubagentInterruptReceipt({accepted}),语义是「中断信号已受理」,
|
|
10782
|
+
// 不等于目标已经静默;旧宿主无 receipt 时保持 {ok:true}。
|
|
10783
|
+
sendJson(res, 200, {
|
|
10784
|
+
ok: true,
|
|
10785
|
+
...(receipt && typeof receipt.accepted === "boolean" ? { accepted: receipt.accepted } : {}),
|
|
10786
|
+
});
|
|
10439
10787
|
} catch (err) {
|
|
10440
10788
|
return error(res, ...rpcError(err, "subagent-interrupt-failed"));
|
|
10441
10789
|
}
|
package/lib/npm-update-source.js
CHANGED
|
@@ -89,14 +89,22 @@ export async function resolveNpmUpdateCandidate({ packageName, localVersion, pac
|
|
|
89
89
|
}
|
|
90
90
|
record(`→ ${channel.channel}=${candidateVersion}`);
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
// issue #96:dist-tags 只取一次;插件与 carrier 元数据**并行**取(两者版本都可从
|
|
93
|
+
// dist-tag 候选版本推出),把总检查耗时压到一次 npm view 的量级。
|
|
94
|
+
const carrierVersion = appCarrierVersion(candidateVersion);
|
|
95
|
+
const alias = appCarrierAlias(packageName);
|
|
96
|
+
const expectedAliasSpec = `npm:${packageName}@${carrierVersion}`;
|
|
93
97
|
record(`$ npm view ${packageName}@${candidateVersion} --json`);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
record(`$ npm view ${packageName}@${carrierVersion} --json`);
|
|
99
|
+
const [pluginOutcome, carrierOutcome] = await Promise.all([
|
|
100
|
+
packageView(`${packageName}@${candidateVersion}`).then((value) => ({ ok: true, value }), (error) => ({ ok: false, error })),
|
|
101
|
+
packageView(`${packageName}@${carrierVersion}`).then((value) => ({ ok: true, value }), (error) => ({ ok: false, error })),
|
|
102
|
+
]);
|
|
103
|
+
if (!pluginOutcome.ok) {
|
|
104
|
+
record(`→ 失败:${viewFailureReason(pluginOutcome.error)}`);
|
|
98
105
|
return { ok: false, reason: "npm-plugin-metadata-unavailable" };
|
|
99
106
|
}
|
|
107
|
+
const plugin = pluginOutcome.value;
|
|
100
108
|
if (!plugin || plugin.version !== candidateVersion) {
|
|
101
109
|
record(`→ 版本不符:${String(plugin?.version ?? "缺失")} ≠ ${candidateVersion}`);
|
|
102
110
|
return { ok: false, reason: "npm-plugin-version-mismatch" };
|
|
@@ -107,23 +115,15 @@ export async function resolveNpmUpdateCandidate({ packageName, localVersion, pac
|
|
|
107
115
|
return { ok: false, reason: "npm-plugin-integrity-missing" };
|
|
108
116
|
}
|
|
109
117
|
record(`→ 插件 v${candidateVersion}`);
|
|
110
|
-
|
|
111
|
-
const carrierVersion = appCarrierVersion(candidateVersion);
|
|
112
|
-
const alias = appCarrierAlias(packageName);
|
|
113
|
-
const expectedAliasSpec = `npm:${packageName}@${carrierVersion}`;
|
|
114
118
|
if (plugin.optionalDependencies?.[alias] !== expectedAliasSpec) {
|
|
115
119
|
record(`→ 载体别名不匹配:${String(plugin.optionalDependencies?.[alias] ?? "缺失")}(期望 ${expectedAliasSpec})`);
|
|
116
120
|
return { ok: false, reason: "npm-carrier-alias-mismatch" };
|
|
117
121
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
record(`$ npm view ${packageName}@${carrierVersion} --json`);
|
|
121
|
-
try {
|
|
122
|
-
carrier = await packageView(`${packageName}@${carrierVersion}`);
|
|
123
|
-
} catch (error) {
|
|
124
|
-
record(`→ 失败:${viewFailureReason(error)}`);
|
|
122
|
+
if (!carrierOutcome.ok) {
|
|
123
|
+
record(`→ 失败:${viewFailureReason(carrierOutcome.error)}`);
|
|
125
124
|
return { ok: false, reason: "npm-carrier-metadata-unavailable" };
|
|
126
125
|
}
|
|
126
|
+
const carrier = carrierOutcome.value;
|
|
127
127
|
if (!carrier || carrier.version !== carrierVersion) {
|
|
128
128
|
record(`→ 版本不符:${String(carrier?.version ?? "缺失")} ≠ ${carrierVersion}`);
|
|
129
129
|
return { ok: false, reason: "npm-carrier-version-mismatch" };
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// issue #96:插件更新检查快照 + 有界异步检查任务。
|
|
2
|
+
//
|
|
3
|
+
// - 一次检查总 deadline(默认 12s)严格小于旧 App 的 15s 兼容窗口;
|
|
4
|
+
// 单次 npm view 仍可 20s,但整次检查 race 到 deadline 时返回明确 check-timeout,
|
|
5
|
+
// 绝不返回半结果。
|
|
6
|
+
// - 成功快照 5min、失败/unavailable 30s;force 绕过读缓存;cache key 含更新源/本地版本,
|
|
7
|
+
// 源配置或本地版本变化自然失效;宿主更新成功后调用 invalidate()。
|
|
8
|
+
// - 异步任务只存内存 map + TTL;同 key in-flight 去重;不持久化、不复用更新事务。
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
10
|
+
|
|
11
|
+
export const UPDATE_CHECK_STATE = Object.freeze({
|
|
12
|
+
CHECKING: "checking",
|
|
13
|
+
DONE: "done",
|
|
14
|
+
ERROR: "error",
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const TIMEOUT_RESULT = {
|
|
18
|
+
state: "unavailable",
|
|
19
|
+
reason: "check-timeout",
|
|
20
|
+
source: "npm",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function isFailureResult(result) {
|
|
24
|
+
return result?.state !== "update-available" && result?.state !== "up-to-date" && result?.state !== "local-ahead";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {object} options
|
|
29
|
+
* @param {() => Promise<object>} options.checkFn 真正的 update check(不得自行吞掉总超时)
|
|
30
|
+
* @param {() => string} [options.cacheKey] 更新源/本地版本指纹
|
|
31
|
+
* @param {number} [options.checkTimeoutMs] 整次检查 deadline;必须 < 15000
|
|
32
|
+
* @param {number} [options.successTtlMs]
|
|
33
|
+
* @param {number} [options.failureTtlMs]
|
|
34
|
+
* @param {number} [options.taskTtlMs] checkId 结果保留时长
|
|
35
|
+
*/
|
|
36
|
+
export function createUpdateCheckService({
|
|
37
|
+
checkFn,
|
|
38
|
+
cacheKey = () => "",
|
|
39
|
+
checkTimeoutMs = 12_000,
|
|
40
|
+
successTtlMs = 5 * 60 * 1000,
|
|
41
|
+
failureTtlMs = 30 * 1000,
|
|
42
|
+
taskTtlMs = 10 * 60 * 1000,
|
|
43
|
+
now = () => Date.now(),
|
|
44
|
+
newCheckId = () => randomUUID(),
|
|
45
|
+
} = {}) {
|
|
46
|
+
if (typeof checkFn !== "function") throw new TypeError("checkFn is required");
|
|
47
|
+
// 成功快照与失败短缓存分开:失败结果不进入“更新检查快照”(CONTEXT 契约),
|
|
48
|
+
// 只有成功结果可供展示/提交复用;失败/unavailable 单独 30s 短缓存防止风暴。
|
|
49
|
+
const snapshot = { key: "", result: null, at: 0 };
|
|
50
|
+
const failureCache = { key: "", result: null, at: 0 };
|
|
51
|
+
const tasks = new Map();
|
|
52
|
+
let activeTask = null;
|
|
53
|
+
let inFlight = null; // { key, promise }
|
|
54
|
+
// 代际:invalidate/强制重查后旧 runCheck 的迟到写回必须被丢弃。
|
|
55
|
+
let generation = 0;
|
|
56
|
+
|
|
57
|
+
function freshResult(key) {
|
|
58
|
+
if (snapshot.result !== null &&
|
|
59
|
+
snapshot.key === key &&
|
|
60
|
+
now() - snapshot.at < successTtlMs) return snapshot.result;
|
|
61
|
+
if (failureCache.result !== null &&
|
|
62
|
+
failureCache.key === key &&
|
|
63
|
+
now() - failureCache.at < failureTtlMs) return failureCache.result;
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function staleResult() {
|
|
68
|
+
return {
|
|
69
|
+
state: "unavailable",
|
|
70
|
+
reason: "check-stale",
|
|
71
|
+
source: "npm",
|
|
72
|
+
checkedAt: new Date().toISOString(),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function rememberFailure(key, result) {
|
|
76
|
+
failureCache.key = key;
|
|
77
|
+
failureCache.result = result;
|
|
78
|
+
failureCache.at = now();
|
|
79
|
+
// 更新检查失败后,旧成功快照不再代表当前检查结果,必须失效。
|
|
80
|
+
snapshot.result = null;
|
|
81
|
+
snapshot.key = "";
|
|
82
|
+
snapshot.at = 0;
|
|
83
|
+
}
|
|
84
|
+
function rememberSuccess(key, result) {
|
|
85
|
+
snapshot.key = key;
|
|
86
|
+
snapshot.result = result;
|
|
87
|
+
snapshot.at = now();
|
|
88
|
+
failureCache.result = null;
|
|
89
|
+
failureCache.key = "";
|
|
90
|
+
failureCache.at = 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function timeoutError() {
|
|
94
|
+
return Object.assign(new Error("check-timeout"), { code: "check-timeout" });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function runWithDeadline() {
|
|
98
|
+
let timer = null;
|
|
99
|
+
const deadline = new Promise((_, reject) => {
|
|
100
|
+
timer = setTimeout(() => reject(timeoutError()), checkTimeoutMs);
|
|
101
|
+
timer.unref?.();
|
|
102
|
+
});
|
|
103
|
+
return Promise.race([Promise.resolve().then(checkFn), deadline]).finally(() => {
|
|
104
|
+
if (timer) clearTimeout(timer);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function runCheck(key, runGeneration) {
|
|
109
|
+
let result;
|
|
110
|
+
try {
|
|
111
|
+
result = await runWithDeadline();
|
|
112
|
+
if (result?.state === "checking") return result;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (error?.code === "check-timeout") {
|
|
115
|
+
result = { ...TIMEOUT_RESULT, checkedAt: new Date().toISOString() };
|
|
116
|
+
} else {
|
|
117
|
+
// review P2:checkFn 任意异常都脱敏成稳定失败结果并进入失败短缓存,
|
|
118
|
+
// 不原样返回 message,也避免连续两次 throw 都打 npm。
|
|
119
|
+
result = {
|
|
120
|
+
state: "unavailable",
|
|
121
|
+
reason: "check-failed",
|
|
122
|
+
source: "npm",
|
|
123
|
+
checkedAt: new Date().toISOString(),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!result || typeof result !== "object") {
|
|
128
|
+
result = {
|
|
129
|
+
state: "unavailable",
|
|
130
|
+
reason: "check-failed",
|
|
131
|
+
source: "npm",
|
|
132
|
+
checkedAt: new Date().toISOString(),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const stamped = typeof result.checkedAt === "string" ? result : { ...result, checkedAt: new Date().toISOString() };
|
|
136
|
+
// 旧代结果不写缓存,但调用方必须拿到明确的非 null stale 结果(可重试)。
|
|
137
|
+
if (runGeneration !== generation) return staleResult();
|
|
138
|
+
if (isFailureResult(stamped)) rememberFailure(key, stamped);
|
|
139
|
+
else rememberSuccess(key, stamped);
|
|
140
|
+
return stamped;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function check({ force = false } = {}) {
|
|
144
|
+
const key = String(cacheKey() ?? "");
|
|
145
|
+
if (!force) {
|
|
146
|
+
const cached = freshResult(key);
|
|
147
|
+
if (cached) return cached;
|
|
148
|
+
}
|
|
149
|
+
// bootstrap + 立即 force:仍复用同一个 in-flight(不重复出网)。
|
|
150
|
+
if (inFlight && inFlight.key === key) return inFlight.promise;
|
|
151
|
+
// force 且没有可复用 in-flight:换代,旧在途结果不得回填。
|
|
152
|
+
if (force) generation += 1;
|
|
153
|
+
const runGeneration = generation;
|
|
154
|
+
const promise = (async () => {
|
|
155
|
+
try {
|
|
156
|
+
return await runCheck(key, runGeneration);
|
|
157
|
+
} finally {
|
|
158
|
+
if (inFlight?.promise === promise) inFlight = null;
|
|
159
|
+
}
|
|
160
|
+
})();
|
|
161
|
+
inFlight = { key, promise };
|
|
162
|
+
return promise;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function scheduleTaskExpiry(task) {
|
|
166
|
+
const timer = setTimeout(() => {
|
|
167
|
+
if (tasks.get(task.checkId) === task) tasks.delete(task.checkId);
|
|
168
|
+
}, taskTtlMs);
|
|
169
|
+
timer.unref?.();
|
|
170
|
+
task.expiryTimer = timer;
|
|
171
|
+
if (activeTask === task) activeTask = null;
|
|
172
|
+
return () => clearTimeout(timer);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function startAsync({ force = false } = {}) {
|
|
176
|
+
const key = String(cacheKey() ?? "");
|
|
177
|
+
if (activeTask && activeTask.state === UPDATE_CHECK_STATE.CHECKING && activeTask.key === key) {
|
|
178
|
+
return { state: UPDATE_CHECK_STATE.CHECKING, checkId: activeTask.checkId };
|
|
179
|
+
}
|
|
180
|
+
const checkId = newCheckId();
|
|
181
|
+
const task = {
|
|
182
|
+
checkId,
|
|
183
|
+
key,
|
|
184
|
+
state: UPDATE_CHECK_STATE.CHECKING,
|
|
185
|
+
startedAt: now(),
|
|
186
|
+
result: null,
|
|
187
|
+
error: null,
|
|
188
|
+
promise: null,
|
|
189
|
+
expiryTimer: null,
|
|
190
|
+
};
|
|
191
|
+
tasks.set(checkId, task);
|
|
192
|
+
activeTask = task;
|
|
193
|
+
// 异步任务与同步 GET 共享同一个 check promise(含 deadline、缓存、in-flight 去重)。
|
|
194
|
+
task.promise = check({ force }).then(
|
|
195
|
+
(result) => {
|
|
196
|
+
task.result = result;
|
|
197
|
+
task.state = UPDATE_CHECK_STATE.DONE;
|
|
198
|
+
task.finishedAt = now();
|
|
199
|
+
scheduleTaskExpiry(task);
|
|
200
|
+
return result;
|
|
201
|
+
},
|
|
202
|
+
(error) => {
|
|
203
|
+
task.state = UPDATE_CHECK_STATE.ERROR;
|
|
204
|
+
// issue #96 review P2:HTTP 只回稳定 code,绝不返回 error.message(可能含路径)。
|
|
205
|
+
task.error = error?.code === "check-timeout" ? "check-timeout" : "check-failed";
|
|
206
|
+
task.finishedAt = now();
|
|
207
|
+
scheduleTaskExpiry(task);
|
|
208
|
+
return null;
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
return { state: UPDATE_CHECK_STATE.CHECKING, checkId };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function getAsync(checkId) {
|
|
215
|
+
const task = tasks.get(String(checkId ?? ""));
|
|
216
|
+
if (!task) return { status: 404, body: { state: "error", error: "check-not-found" } };
|
|
217
|
+
if (task.state === UPDATE_CHECK_STATE.CHECKING) {
|
|
218
|
+
const age = now() - (task.startedAt ?? now());
|
|
219
|
+
if (age > taskTtlMs) {
|
|
220
|
+
tasks.delete(task.checkId);
|
|
221
|
+
return { status: 410, body: { state: "error", error: "check-expired" } };
|
|
222
|
+
}
|
|
223
|
+
return { status: 200, body: { state: "checking", checkId: task.checkId } };
|
|
224
|
+
}
|
|
225
|
+
if (task.state === UPDATE_CHECK_STATE.ERROR) {
|
|
226
|
+
return { status: 200, body: { state: "error", checkId: task.checkId, error: task.error } };
|
|
227
|
+
}
|
|
228
|
+
return { status: 200, body: { state: "done", checkId: task.checkId, result: task.result } };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function checkSync() {
|
|
232
|
+
return check({ force: false });
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async function checkForSubmit() {
|
|
236
|
+
// 优先 5min 成功快照;过期时等待当前 async 任务(同一 in-flight)或启动有 deadline 检查。
|
|
237
|
+
return check({ force: false });
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function invalidate() {
|
|
241
|
+
generation += 1;
|
|
242
|
+
snapshot.result = null;
|
|
243
|
+
snapshot.key = "";
|
|
244
|
+
snapshot.at = 0;
|
|
245
|
+
failureCache.result = null;
|
|
246
|
+
failureCache.key = "";
|
|
247
|
+
failureCache.at = 0;
|
|
248
|
+
// issue #96 review P2:同时清掉 checkId 结果与 in-flight 去重;旧 checkId 不再 done。
|
|
249
|
+
for (const task of tasks.values()) {
|
|
250
|
+
if (task.expiryTimer) clearTimeout(task.expiryTimer);
|
|
251
|
+
}
|
|
252
|
+
tasks.clear();
|
|
253
|
+
activeTask = null;
|
|
254
|
+
inFlight = null;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
check,
|
|
259
|
+
checkSync,
|
|
260
|
+
checkForSubmit,
|
|
261
|
+
startAsync,
|
|
262
|
+
getAsync,
|
|
263
|
+
invalidate,
|
|
264
|
+
snapshot: () => snapshot.result,
|
|
265
|
+
failureSnapshot: () => failureCache.result,
|
|
266
|
+
_checkTimeoutMs: checkTimeoutMs,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
@@ -7,6 +7,7 @@ import { acquireLock, newOperationId, readTransaction, releaseLock, serverOperat
|
|
|
7
7
|
transactionFile, updateLockPath, validOperationId, writeOwnedTransaction, convergeStaleTransaction, workRoot } from './plugin-update-transaction.js';
|
|
8
8
|
import { checkForUpdate, prepareNpmArtifacts, runSelfUpdate, isTerminalPhase, resolvePluginUpdateSource, UPDATE_SOURCE_KIND } from './plugin-self-update.js';
|
|
9
9
|
import { createOperationLog } from './plugin-update-log.js';
|
|
10
|
+
import { createUpdateCheckService } from './plugin-update-check.js';
|
|
10
11
|
|
|
11
12
|
/// 客户端可达视图:只改写属于**本机回环主机源**的 artifact 路由,外部发布源保持原样(F1)。
|
|
12
13
|
export function clientReleaseView(release, { clientOrigin = '', basePath = '/m', loopback = false } = {}) {
|
|
@@ -40,6 +41,8 @@ export function publicTransaction(tx, view = {}) {
|
|
|
40
41
|
export function createPluginUpdateController(options) {
|
|
41
42
|
const { home = homedir(), configValue, profileDir, packageName = '', npmPackageView, capabilities, localVersion, localContentSha256,
|
|
42
43
|
status, log = () => {}, fetchImpl = fetch, auth = {}, basePath = '/m', workerOptions = {},
|
|
44
|
+
checkTimeoutMs = 12_000, checkSuccessTtlMs = 5 * 60 * 1000, checkFailureTtlMs = 30 * 1000,
|
|
45
|
+
asyncCheckTtlMs = 10 * 60 * 1000,
|
|
43
46
|
schedule = fn => setImmediate(fn), runSelfUpdate: runner = runSelfUpdate, prepareNpmArtifacts: prepareRunner = prepareNpmArtifacts,
|
|
44
47
|
runHostUpdate: hostRunner, persist = writeOwnedTransaction } = options;
|
|
45
48
|
// 只有调用方显式提供宿主更新执行器时才启用该通道(旧宿主/测试不提供即自动关闭)。
|
|
@@ -87,6 +90,15 @@ export function createPluginUpdateController(options) {
|
|
|
87
90
|
const checking = () => checkForUpdate({ configValue, packageName, npmCwd: profileDir, npmPackageView,
|
|
88
91
|
localVersion: typeof localVersion === 'function' ? localVersion() : localVersion, localContentSha256,
|
|
89
92
|
capabilities: capabilities(), fetchImpl, auth });
|
|
93
|
+
// issue #96:检查快照 + 有界异步任务(只读、内存、不持久化)。
|
|
94
|
+
const checkService = createUpdateCheckService({
|
|
95
|
+
checkFn: checking,
|
|
96
|
+
cacheKey: () => `${configValue}|${typeof localVersion === 'function' ? localVersion() : localVersion}|${localContentSha256 ?? ''}`,
|
|
97
|
+
checkTimeoutMs,
|
|
98
|
+
successTtlMs: checkSuccessTtlMs,
|
|
99
|
+
failureTtlMs: checkFailureTtlMs,
|
|
100
|
+
taskTtlMs: asyncCheckTtlMs,
|
|
101
|
+
});
|
|
90
102
|
/// 手机视图:**只用于 HTTP 出口**,绝不写回内部事务(F1)。
|
|
91
103
|
/// 内部 worker 必须继续用受信定位;当前 NPM 来源不会把 registry URL 投影给客户端。
|
|
92
104
|
const clientView = clientOrigin => ({
|
|
@@ -109,7 +121,7 @@ export function createPluginUpdateController(options) {
|
|
|
109
121
|
} };
|
|
110
122
|
const old = readTransaction(currentFile);
|
|
111
123
|
if (old && !isTerminalPhase(old.phase)) return { status: 409, body: { error: 'update-busy', transaction: publicTransaction(old) } };
|
|
112
|
-
const checked = await
|
|
124
|
+
const checked = await checkService.checkForSubmit(); Object.assign(status, checked);
|
|
113
125
|
if (checked.state !== 'update-available') return { status: 200, body: { ok: true, action: 'none', check: checked } };
|
|
114
126
|
const candidate = checked.candidate;
|
|
115
127
|
if (!candidate?.carrier?.legacyMetadataMissing) {
|
|
@@ -174,7 +186,34 @@ export function createPluginUpdateController(options) {
|
|
|
174
186
|
if (!['converged','terminal'].includes(convergence.action)) return { status: 409, body: {
|
|
175
187
|
error: convergence.action === 'recovery-required' ? 'recovery-required' : 'update-busy', transaction: publicTransaction(old, view) } };
|
|
176
188
|
}
|
|
177
|
-
|
|
189
|
+
let checked = await checkService.checkForSubmit(); Object.assign(status, checked);
|
|
190
|
+
// issue #96 review P2:检查本身不可用/超时时如实返回 503 check-unavailable,
|
|
191
|
+
// 不得被 targetVersion 比对误判成 candidate-changed,也不无意义重查。
|
|
192
|
+
if (checked.state === 'unavailable') {
|
|
193
|
+
return { status: 503, body: {
|
|
194
|
+
error: 'check-unavailable',
|
|
195
|
+
reason: checked.reason ?? 'update-check-unavailable',
|
|
196
|
+
check: checked,
|
|
197
|
+
} };
|
|
198
|
+
}
|
|
199
|
+
// 只有成功检查且 targetVersion 与候选确实不同,才强制重查一次;仍不同才 409。
|
|
200
|
+
if (typeof body.targetVersion === 'string') {
|
|
201
|
+
const snapshotTarget = () => checked.release?.plugin ?? checked.candidate?.plugin;
|
|
202
|
+
if (!snapshotTarget() || snapshotTarget()?.version !== body.targetVersion) {
|
|
203
|
+
checked = await checkService.check({ force: true });
|
|
204
|
+
Object.assign(status, checked);
|
|
205
|
+
if (checked.state === 'unavailable') {
|
|
206
|
+
return { status: 503, body: {
|
|
207
|
+
error: 'check-unavailable',
|
|
208
|
+
reason: checked.reason ?? 'update-check-unavailable',
|
|
209
|
+
check: checked,
|
|
210
|
+
} };
|
|
211
|
+
}
|
|
212
|
+
if (!snapshotTarget() || snapshotTarget()?.version !== body.targetVersion) {
|
|
213
|
+
return { status: 409, body: { error: 'candidate-changed', check: checked } };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
178
217
|
// **内部 release 原样保留**(持久化与 worker 都用它);只有响应体走手机视图。
|
|
179
218
|
if (checked.state !== 'update-available') {
|
|
180
219
|
return { status: 200, body: { ok: true, action: 'none', check: { ...checked, release: clientReleaseView(checked.release, view) } } };
|
|
@@ -220,6 +259,7 @@ export function createPluginUpdateController(options) {
|
|
|
220
259
|
finishOwnedTerminal(stateFile, { phase: 'settled', result: { ok: true, matched: 'host-manager' } },
|
|
221
260
|
{ lockPath, lease, currentFile });
|
|
222
261
|
Object.assign(status, { state: 'up-to-date', reason: 'host-manager-applied', opId });
|
|
262
|
+
checkService.invalidate();
|
|
223
263
|
} else {
|
|
224
264
|
const reason = safeUpdateReason(run.reason);
|
|
225
265
|
operationLog.setStage('failed', `Host plugin manager update failed: ${reason}`);
|
|
@@ -312,6 +352,7 @@ export function createPluginUpdateController(options) {
|
|
|
312
352
|
if (run.ok) {
|
|
313
353
|
operationLog.setStage('restart', 'Plugin install finished; waiting for host restart and health confirmation.');
|
|
314
354
|
Object.assign(status, { state: 'restarting', reason: 'update-staged', opId });
|
|
355
|
+
checkService.invalidate();
|
|
315
356
|
} else {
|
|
316
357
|
const reason = safeUpdateReason(run.error);
|
|
317
358
|
// 失败原因必须进日志:详情页要能直接看到,而不是只有一句“看安装输出”。
|
|
@@ -336,5 +377,14 @@ export function createPluginUpdateController(options) {
|
|
|
336
377
|
return { status: 200, body: { ok: true, action: 'accepted', opId,
|
|
337
378
|
transaction: publicTransaction(tx, view), check: { ...effectiveCheck, release: clientReleaseView(effectiveCheck.release, view) } } };
|
|
338
379
|
}
|
|
339
|
-
return {
|
|
380
|
+
return {
|
|
381
|
+
submit,
|
|
382
|
+
check: checking,
|
|
383
|
+
prepare,
|
|
384
|
+
checkSync: () => checkService.checkSync(),
|
|
385
|
+
checkForSubmit: () => checkService.checkForSubmit(),
|
|
386
|
+
startAsyncCheck: (options) => checkService.startAsync(options),
|
|
387
|
+
getAsyncCheck: (checkId) => checkService.getAsync(checkId),
|
|
388
|
+
invalidateCheck: () => checkService.invalidate(),
|
|
389
|
+
};
|
|
340
390
|
}
|
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.16",
|
|
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.16-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",
|