@marktrue/dsh-mobile-remote 3.2.4-alpha.14 → 3.2.4-alpha.15
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 +38 -0
- package/docs/03-api.md +25 -6
- package/docs/04-security.md +6 -0
- package/docs/09-compatibility.md +4 -0
- package/lib/endpoint-registry.js +2 -0
- package/lib/git-read-service.js +115 -9
- package/lib/index.js +307 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v3.2.4-alpha.15(build 47,issues #90 / #91 / #92 / #93 / #94 / #95)— 斜杠菜单、全部分支图与本地图片
|
|
4
|
+
|
|
5
|
+
> 插件 `3.2.4-alpha.15` / App `3.2.4+47` / 载体 `3.2.4-alpha.15-app`。
|
|
6
|
+
|
|
7
|
+
### 斜杠命令与技能菜单(#90 / #95)
|
|
8
|
+
|
|
9
|
+
- 输入 `/` 自动列出命令与技能(内联菜单):按前缀筛选、命令/技能分组、键盘与点按选择;选中即插入输入框,不打断已输入文本;
|
|
10
|
+
- 命令/技能目录按需加载并缓存(同一会话/同一时间线复用):只有输入框或时间线出现 slash 时才拉取,普通会话不再多两次请求;
|
|
11
|
+
- 用户消息中的 slash 命令双高亮;命令 chip 改为 surface + 细边框,在用户气泡底色上可辨识;长按复制等原有交互不变。
|
|
12
|
+
|
|
13
|
+
### 插话与压缩回放(#91 / #92)
|
|
14
|
+
|
|
15
|
+
- 同 turn 插话时按提示词识别过程块宿主,禁止把 user 消息当宿主,思考/工具过程块归属正确轮次,不再错位到插话消息;
|
|
16
|
+
- compaction 回放:孤儿工具 partial 结果并入历史过程组,不再回退为旧版独立工具卡;折叠/展开与正常轮次一致。
|
|
17
|
+
|
|
18
|
+
### 全部分支图(#93)
|
|
19
|
+
|
|
20
|
+
- 新增全部分支模式(`POST /git/graph` `all:true`)与 focus 定位:解析 `refs/heads/* + refs/remotes/*`(排除 `/HEAD`)为 tips,tag 仅作为可达提交上的 label,不画分支线;
|
|
21
|
+
- 固定每页 16 提交、双向分页(`prevCursor` 更新 / `nextCursor` 更旧)、prev 锚定、隐藏分支筛选与横向滚动;focus 返回包含该提交的页并带 `focusOid/pageStart/prevCursor/hasNewer/hasOlder`;
|
|
22
|
+
- 快照绑定全部分支 refs 指纹:refs 新增/移动/删除返回 `409 graph-stale`;保护超限 `400 graph-too-many-refs`、focus 非法/未找到 `400 graph-focus-invalid` / `409 graph-focus-not-found`,不静默截断;GET 不接受 all。
|
|
23
|
+
|
|
24
|
+
### 本地 Markdown 图片(#94 / #95)
|
|
25
|
+
|
|
26
|
+
- 新增 `GET/HEAD /m/api/workspace-image` 只读端点:仅会话 cwd(且属于已登记工作区)内的普通图片,fd 绑定读取(`O_NOFOLLOW`/`O_NONBLOCK` → `fstat` → `/proc/self/fd` 实际路径 containment → 有界 `readSync` → `close`),末级符号链接与中间目录换链均拒绝;非 Linux/无 procfs 返回 `501 image-verification-unavailable`,fail-closed 不回退;
|
|
27
|
+
- 上限 8 MiB / 8192px 单边 / 40 MP(`413 image-too-large`);扩展名与 magic 一致校验(`415 unsupported-image-type`);强 ETag、HEAD 同 headers 无 body、`If-None-Match` 命中 304;
|
|
28
|
+
- App 渲染 `` 本地图片;http(s) 远程图片本轮不自动加载,显示 alt/占位以避免第三方请求;`WorkspaceImageCache` 增加会话 LRU 上限、clear 与并发槽位,避免长会话内存膨胀。
|
|
29
|
+
|
|
30
|
+
### 文档
|
|
31
|
+
|
|
32
|
+
- docs/03-api §6.19.12 新增 workspace-image 契约与错误码;docs/04-security 新增工作区图片端点安全边界;docs/09-compatibility 记录 2.x 本地 Markdown 图片兼容说明(Linux/fd 校验限制)。
|
|
33
|
+
|
|
34
|
+
### 验证
|
|
35
|
+
|
|
36
|
+
- 本机发布门禁:node 测试 **1139**(1126 通过 / 13 跳过 / 0 失败)、flutter test **1373** 全绿、flutter analyze 0 error/warning(20 条既有 info);
|
|
37
|
+
- 独立 review 无 P0/P1/P2,verify 5/5;
|
|
38
|
+
- 真机/320 宽/深色主题、分支图 5/10/all、本地 Markdown 图片渲染列为本版验收项(发布后按验收清单执行)。
|
|
39
|
+
|
|
40
|
+
|
|
3
41
|
## v3.2.4-alpha.14(build 46,issues #83 / #84 / #85 / #86 / #88)— 交互修复与分支图上限
|
|
4
42
|
|
|
5
43
|
> 插件 `3.2.4-alpha.14` / App `3.2.4+46` / 载体 `3.2.4-alpha.14-app`。
|
package/docs/03-api.md
CHANGED
|
@@ -1056,7 +1056,9 @@ graph 的每个提交与 commit 详情都**保留旧的** `refs: string[]`(dep
|
|
|
1056
1056
|
|
|
1057
1057
|
POST 请求体:`{"sessionId","repositoryId","tips":[...],"limit"?,"snapshotId"?,"cursor"?}`;续页可省略 `tips`,`snapshotId/cursor` 与 GET 互通(传输方式不参与快照身份)。POST body ≤256 KiB、每个 `name` ≤1024 B,超限 `413 payload-too-large`。`HEAD /git/graph` 返回 200 无 body,不创建快照。
|
|
1058
1058
|
|
|
1059
|
-
|
|
1059
|
+
**all 模式(仅 POST)**:`{"sessionId","repositoryId","all":true,"focus"?:ref|oid,"limit":16,"snapshotId"?,"cursor"?}`。服务端解析 `refs/heads/* + refs/remotes/*`(排除 `/HEAD`)作为 tips;**tag 不作为 tip/分支线**,只作为分支历史内可达提交上的 label。固定每页 16 提交;`focus` 返回包含该提交的页并带 `focusOid/pageStart/prevCursor/nextCursor/hasNewer/hasOlder`,`prevCursor` 更新、`nextCursor` 更旧。all 快照绑定全部分支 refs 指纹;分支新增/移动/删除返回 `409 graph-stale`。保护超限返回 `400 graph-too-many-refs`、focus 非法/未找到返回 `400 graph-focus-invalid`/`409 graph-focus-not-found`,不静默截断。GET 不接受 `all=true`。
|
|
1060
|
+
|
|
1061
|
+
响应:`{ ok, repositoryId, snapshotId, tips, commits, nextCursor }`(all 模式另含 `all/pageSize/pageStart/focusOid/prevCursor/hasNewer/hasOlder`),`commits[]` 含 `oid` / `parents` / `author` / `timestamp` / `subject` / `refs` / `refsDetail` / `tagsDetail`。引用在翻页期间移动、tip 失效、快照过期或游标非法返回 `409 graph-stale`;非法 tip 返回 `409 graph-tip-invalid`;GET 超过 32 / POST 超过 128 返回 `400 graph-too-many-tips`(detail 声明对应上限);服务端 25s deadline 返回 `504 graph-timeout`。
|
|
1060
1062
|
|
|
1061
1063
|
#### 6.19.5 GET /m/api/git/commit
|
|
1062
1064
|
|
|
@@ -1126,6 +1128,21 @@ POST 请求体:`{"sessionId","repositoryId","tips":[...],"limit"?,"snapshotId"
|
|
|
1126
1128
|
- **有界**:单次最多扫描 5000 条提交或 20 秒软超时;达到上限时返回已取部分并 `truncated: true`(客户端可提示「仅显示最近 N 条提交」)。
|
|
1127
1129
|
- 缺失 `path` → `400 bad-request`。
|
|
1128
1130
|
|
|
1131
|
+
#### 6.19.12 GET/HEAD /m/api/workspace-image
|
|
1132
|
+
|
|
1133
|
+
只读返回当前会话工作区内的图片字节,供 App 渲染 Markdown 本地图片。**不是任意文件读取接口。**
|
|
1134
|
+
|
|
1135
|
+
| 参数 | 说明 |
|
|
1136
|
+
|---|---|
|
|
1137
|
+
| `sessionId` | 必填;会话 cwd 必须位于已登记工作区内 |
|
|
1138
|
+
| `path` | 必填;会话 cwd 内的工作区路径(词法前缀 + realpath containment) |
|
|
1139
|
+
|
|
1140
|
+
- 仅接受普通图片文件(png/jpeg/gif/webp;扩展名与 magic 必须一致);目录/FIFO/device/空文件拒绝;**末级符号链接拒绝**。
|
|
1141
|
+
- 安全读取(Linux):`open(O_RDONLY|O_NOFOLLOW|O_NONBLOCK)` → `fstat` → `/proc/self/fd/<fd>` 实际路径 containment(cwd + 登记工作区)→ 有界 `readSync` → `close`;不再按路径二次 `stat/readFileSync`。**非 Linux/无 O_NOFOLLOW/无 procfs 返回 `501 image-verification-unavailable`,不回退到不安全读取。**
|
|
1142
|
+
- 上限:8 MiB / 8192px 单边 / 40 MP;超限 `413 image-too-large`;类型不符/无法解析尺寸 `415 unsupported-image-type`;越界/工作区未授权 `403 path-outside-workspace`;不存在 `404 image-not-found`;错误不泄露主机路径。
|
|
1143
|
+
- 响应:`200` 图片字节 + `content-type` + 强 ETag;`HEAD` 同 headers 无 body;`If-None-Match` 命中 `304`;`cache-control: private, max-age=86400`;`x-content-type-options: nosniff`。POST/其它方法 `405`。
|
|
1144
|
+
- App:只对工作区本地路径调用此端点;`http(s)` 图片本轮不自动加载(显示 alt/占位),避免第三方请求;本地图片失败显示 alt + 可读原因。
|
|
1145
|
+
|
|
1129
1146
|
#### 6.19.9 Git 只读端点错误码
|
|
1130
1147
|
|
|
1131
1148
|
| HTTP | error 值 | 场景 |
|
|
@@ -1134,12 +1151,14 @@ POST 请求体:`{"sessionId","repositoryId","tips":[...],"limit"?,"snapshotId"
|
|
|
1134
1151
|
| 400 | `invalid-oid` / `invalid-files-cursor` / `invalid-history-cursor` | 非法 OID / 文件分页游标 / 历史分页游标 |
|
|
1135
1152
|
| 400 | `path-invalid` | `/git/file-history` 传入目录路径 |
|
|
1136
1153
|
| 400 | `preview-invalid` | 预览参数非法 |
|
|
1137
|
-
| 400 | `graph-tip-invalid` / `graph-too-many-tips` | 非法 tip /
|
|
1154
|
+
| 400 | `graph-tip-invalid` / `graph-too-many-tips` / `graph-too-many-refs` / `graph-focus-invalid` | 非法 tip / 超选择集上限 / all refs 超保护 / all focus 非法 |
|
|
1138
1155
|
| 401 | `auth-required` / `bad-token` | 未鉴权(同 §1) |
|
|
1139
|
-
| 403 | `repository-not-authorized` / `workspace-not-allowed` |
|
|
1140
|
-
| 404 | `session-not-found` / `not-git-repository` / `preview-file-not-found` | 会话不存在 / cwd 不是仓库 / 提交中无该文件 |
|
|
1141
|
-
| 409 | `graph-stale` / `graph-tip-invalid` |
|
|
1142
|
-
| 413 | `git-output-too-large` / `payload-too-large` | Git
|
|
1156
|
+
| 403 | `repository-not-authorized` / `workspace-not-allowed` / `path-outside-workspace` | 会话/仓库不匹配、路径不在工作区、图片实际 fd 越界 |
|
|
1157
|
+
| 404 | `session-not-found` / `not-git-repository` / `preview-file-not-found` / `image-not-found` | 会话不存在 / cwd 不是仓库 / 提交中无该文件 / 图片不存在或非普通文件 |
|
|
1158
|
+
| 409 | `graph-stale` / `graph-tip-invalid` / `graph-focus-not-found` | 快照/tip 已变化 / all focus 扫描未命中 |
|
|
1159
|
+
| 413 | `git-output-too-large` / `payload-too-large` / `image-too-large` | Git 输出/请求体超限;图片超 8 MiB/8192px/40MP |
|
|
1160
|
+
| 415 | `unsupported-image-type` | 图片扩展名/magic 不符或尺寸不可解析 |
|
|
1161
|
+
| 501 | `image-verification-unavailable` | 当前平台无法提供 fd 级安全校验(Windows/macOS/无 procfs) |
|
|
1143
1162
|
| 504 | `graph-timeout` | graph 25s deadline(任意阶段) |
|
|
1144
1163
|
| 431 | —(HTTP) | GET URL 过长;新 App 在能力允许时自动改 POST 重试一次 |
|
|
1145
1164
|
| 503 | `git-provider-unavailable` / `provider-incompatible` | provider 不可用 / 旧 provider 不支持所需方法 |
|
package/docs/04-security.md
CHANGED
|
@@ -81,6 +81,12 @@
|
|
|
81
81
|
|
|
82
82
|
同一认证身份还能通过 `POST /sessions {cwd}` 注册新的工作目录。因此仅按“已注册工作区”过滤文件接口无法限制持有口令的客户端:它可以先注册更大的目录。本轮保留任意新目录建会话的行为,不引入可被该入口绕过的访问控制承诺。若要增加受限身份,需要一并设计宿主批准的根目录、`realpath` / 符号链接检查和工作目录注册授权;不能只更改文件下载接口。当前权限上限由宿主操作系统身份、沙箱与可信传输控制。
|
|
83
83
|
|
|
84
|
+
### 工作区图片端点(`/m/api/workspace-image`,issue #95)
|
|
85
|
+
|
|
86
|
+
该端点比通用文件传输更窄:只允许当前会话 cwd 内、cwd 属于已登记工作区的普通图片,且使用 **fd 绑定**读取:`open(O_RDONLY|O_NOFOLLOW|O_NONBLOCK)` 后以 `fstat` 与 `/proc/self/fd/<fd>` 的实际路径做 cwd/工作区 containment,再 `readSync(fd)` 有界读取并 `finally close`;不再按路径二次 `stat`/`readFileSync`。末级 symlink 被 `O_NOFOLLOW` 拒绝,中间目录换链由 fd 实际路径校验拒绝。非 Linux/无 procfs/无 O_NOFOLLOW 一律 `501 image-verification-unavailable`,**fail-closed,不回退**。
|
|
87
|
+
|
|
88
|
+
已知/接受边界:hardlink 与 bind-mount 的同用户场景不在本端点威胁模型内;8 MiB/8192px/40MP 上限;HEAD 仍完整读取以生成强 ETag。通用 `/files*` 的既有任意路径/符号链接边界见上节,二者不可混用。
|
|
89
|
+
|
|
84
90
|
### 持久化与投递
|
|
85
91
|
|
|
86
92
|
- 插件**持久化仅限最小移动端状态**(`~/.dsh/mobile-remote/`:通知已读 id、会话最近活跃时间),不含会话内容;口令只存在于 profile 配置。
|
package/docs/09-compatibility.md
CHANGED
|
@@ -171,6 +171,10 @@
|
|
|
171
171
|
|
|
172
172
|
---
|
|
173
173
|
|
|
174
|
+
### 2.x 本地 Markdown 图片(issue #95)
|
|
175
|
+
|
|
176
|
+
`/m/api/workspace-image` 仅在宿主为 Linux、具备 `O_NOFOLLOW` 与 procfs 时可用;Windows/macOS 返回 `501 image-verification-unavailable`,App 不自动回退到路径读取,而是显示 alt/明确占位。HTTP(S) Markdown 图片本轮不自动加载。该限制是安全边界的一部分,不是可静默降级的体验差异。
|
|
177
|
+
|
|
174
178
|
## 3. Android 多品牌适配
|
|
175
179
|
|
|
176
180
|
App 为 Flutter 原生 APK(`com.dsh.remote`),渲染后端为 **Impeller(Vulkan,自动回退 OpenGLES)**。
|
package/lib/endpoint-registry.js
CHANGED
|
@@ -126,6 +126,7 @@ export const REGISTERED_ENDPOINTS = Object.freeze([
|
|
|
126
126
|
{ path: "/changes/diff", methods: "GET", capability: "turnTail" },
|
|
127
127
|
{ path: "/changes/summary", methods: "GET", capability: "turnTail" },
|
|
128
128
|
{ path: "/commands", methods: "GET/POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
129
|
+
{ path: "/skills", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
129
130
|
{ path: "/defaults", methods: "GET/POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
130
131
|
{ path: "/dev/approval-test", methods: "GET/POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
131
132
|
{ path: "/diagnostics", methods: "GET", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
@@ -135,6 +136,7 @@ export const REGISTERED_ENDPOINTS = Object.freeze([
|
|
|
135
136
|
{ path: "/feedback", methods: "GET/POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
136
137
|
{ path: "/files", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
137
138
|
{ path: "/files/upload", methods: "GET/POST", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
139
|
+
{ path: "/workspace-image", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
138
140
|
{ path: "/git/branches", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
139
141
|
{ path: "/git/capabilities", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
|
140
142
|
{ path: "/git/commit", methods: "GET/HEAD", capability: null, why: NO_CAPABILITY_NEEDED },
|
package/lib/git-read-service.js
CHANGED
|
@@ -7,6 +7,10 @@ import { createBundledGitReadProvider } from "./git-read-bundled-provider.js";
|
|
|
7
7
|
const MAX_GRAPH_TIPS_GET = 32;
|
|
8
8
|
const MAX_GRAPH_TIPS_POST = 128;
|
|
9
9
|
const GRAPH_DEADLINE_MS = 25_000;
|
|
10
|
+
// issue #93(全部分支模式):refs/扫描/页大小。阈值必须高于正常仓库(211 分支)。
|
|
11
|
+
const GRAPH_ALL_PAGE_SIZE = 16;
|
|
12
|
+
const MAX_GRAPH_ALL_REFS = 4096;
|
|
13
|
+
const MAX_GRAPH_ALL_SCAN = 5000;
|
|
10
14
|
const MAX_TRACKED_FILES = 200;
|
|
11
15
|
const FILE_HISTORY_DEFAULT_LIMIT = 20;
|
|
12
16
|
const FILE_HISTORY_MAX_LIMIT = 100;
|
|
@@ -322,6 +326,36 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
322
326
|
if (Date.now() > deadline) throw graphTimeout();
|
|
323
327
|
}
|
|
324
328
|
};
|
|
329
|
+
/**
|
|
330
|
+
* issue #93:解析**全部分支**(refs/heads/* + refs/remotes/*,排除 /HEAD)。
|
|
331
|
+
* tags 不参与 tips;返回按 name 排序的 `{name, tipOid}`,供 provider.graph 使用。
|
|
332
|
+
* 超内部保护上限抛明确 graph-too-many-refs(绝不静默截断)。
|
|
333
|
+
*/
|
|
334
|
+
const resolveAllGraphRefs = async (root, deadline) => {
|
|
335
|
+
const byName = await graphRefsByName(root, deadline);
|
|
336
|
+
if (byName === null) throw failure("git-provider-unavailable", 503);
|
|
337
|
+
const refs = [];
|
|
338
|
+
for (const [name, oid] of byName) {
|
|
339
|
+
if (!name.startsWith("refs/heads/") && !name.startsWith("refs/remotes/")) continue;
|
|
340
|
+
if (name.endsWith("/HEAD")) continue;
|
|
341
|
+
if (!validOid(oid)) continue; // 非 commit 目标的 branch 不进图(与 provider 语义一致)
|
|
342
|
+
refs.push({ name, tipOid: String(oid) });
|
|
343
|
+
if (Date.now() > deadline) throw graphTimeout();
|
|
344
|
+
}
|
|
345
|
+
refs.sort((a, b) => compareText(a.name, b.name));
|
|
346
|
+
if (refs.length > MAX_GRAPH_ALL_REFS) {
|
|
347
|
+
throw failure("graph-too-many-refs", 400, `all branch refs exceed ${MAX_GRAPH_ALL_REFS}`);
|
|
348
|
+
}
|
|
349
|
+
return refs;
|
|
350
|
+
};
|
|
351
|
+
/** 全部分支快照指纹:name+oid 排序后 sha256;任一分支新增/移动/删除都会变。 */
|
|
352
|
+
const allRefsFingerprint = (refs) => createHash("sha256")
|
|
353
|
+
.update(refs.map((ref) => `${ref.name}:${ref.tipOid}`).join("\n"))
|
|
354
|
+
.digest("hex");
|
|
355
|
+
const verifyAllGraphRefs = async (snapshot, root, deadline) => {
|
|
356
|
+
const current = await resolveAllGraphRefs(root, deadline);
|
|
357
|
+
if (allRefsFingerprint(current) !== snapshot.refFingerprint) throw stale();
|
|
358
|
+
};
|
|
325
359
|
/** graph 专用:readRefRecords 纳入同一 absolute deadline(挂起→504,不返回半页)。 */
|
|
326
360
|
const readRefRecordsWithin = async (root, deadline) => {
|
|
327
361
|
if (typeof provider.refs !== "function") return null;
|
|
@@ -344,6 +378,8 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
344
378
|
readOnly: true, provider: provider === external ? "external" : "bundled",
|
|
345
379
|
// task-28:POST graph 的 tips 上限(旧宿主缺该字段,App 回退 5/5)。
|
|
346
380
|
graphTips: { max: MAX_GRAPH_TIPS_POST, getMax: MAX_GRAPH_TIPS_GET },
|
|
381
|
+
// issue #93:全部分支模式(all=true)与内部保护阈值;旧宿主缺该字段 → App 回退选择档。
|
|
382
|
+
graphAll: { pageSize: GRAPH_ALL_PAGE_SIZE, maxRefs: MAX_GRAPH_ALL_REFS, maxScan: MAX_GRAPH_ALL_SCAN },
|
|
347
383
|
features: {
|
|
348
384
|
repository: true, branches: true, graph: true, commit: true, worktree: true, preview: true,
|
|
349
385
|
// Both flags are independent and additive: refsDetail can be
|
|
@@ -530,20 +566,68 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
530
566
|
* 图分页。task-28:`maxTips` 由 HTTP 层按传输方式传入(GET=32 / POST=128),
|
|
531
567
|
* 续页可省略 tips;snapshotId/cursor 与传输方式无关(GET/POST 互通)。
|
|
532
568
|
*/
|
|
533
|
-
async graph(sessionId, repositoryId, { tips, snapshotId, cursor, limit = 100, maxTips = MAX_GRAPH_TIPS_GET } = {}) {
|
|
569
|
+
async graph(sessionId, repositoryId, { tips, snapshotId, cursor, limit = 100, maxTips = MAX_GRAPH_TIPS_GET, all = false, focus } = {}) {
|
|
534
570
|
const authorized = await binding(sessionId, repositoryId);
|
|
535
571
|
prune();
|
|
536
572
|
const deadline = Date.now() + graphDeadlineMs;
|
|
537
573
|
const tipCap = maxTips === MAX_GRAPH_TIPS_POST ? MAX_GRAPH_TIPS_POST : MAX_GRAPH_TIPS_GET;
|
|
538
|
-
const
|
|
574
|
+
const allMode = all === true;
|
|
575
|
+
// issue #93:全部分支模式固定每页 16;5/10 选择集保持原 limit 语义。
|
|
576
|
+
const pageSize = allMode
|
|
577
|
+
? GRAPH_ALL_PAGE_SIZE
|
|
578
|
+
: Math.max(1, Math.min(200, Number(limit) || 100));
|
|
539
579
|
let snapshot, offset = 0;
|
|
540
580
|
let snapshotCreatedNow = false;
|
|
541
581
|
if (snapshotId !== undefined || cursor !== undefined) {
|
|
542
582
|
if (!snapshotId || !cursor) throw stale();
|
|
543
583
|
snapshot = snapshots.get(snapshotId);
|
|
544
584
|
if (!snapshot || snapshot.sessionId !== sessionId || snapshot.repositoryId !== repositoryId || snapshot.root !== authorized.root || snapshot.expiresAt <= now()) throw stale();
|
|
585
|
+
if (allMode !== (snapshot.all === true)) throw stale();
|
|
545
586
|
offset = snapshot.cursors.get(cursor);
|
|
546
587
|
if (!Number.isInteger(offset)) throw stale();
|
|
588
|
+
} else if (allMode) {
|
|
589
|
+
// 全部分支:忽略 tips 选择集,自行解析 refs/heads/* + refs/remotes/*。
|
|
590
|
+
const refs = await resolveAllGraphRefs(authorized.root, deadline);
|
|
591
|
+
if (refs.length === 0) throw failure("graph-tip-invalid", 400, "no branch refs");
|
|
592
|
+
const refFingerprint = allRefsFingerprint(refs);
|
|
593
|
+
let focusOid = null;
|
|
594
|
+
let focusIndex = null;
|
|
595
|
+
if (typeof focus === "string" && focus !== "") {
|
|
596
|
+
if (!validRef(focus) && !validOid(focus)) throw failure("graph-focus-invalid", 400);
|
|
597
|
+
if (validOid(focus)) {
|
|
598
|
+
focusOid = String(focus).toLowerCase();
|
|
599
|
+
} else {
|
|
600
|
+
const hit = refs.find((ref) => ref.name === focus);
|
|
601
|
+
if (!hit) throw failure("graph-focus-invalid", 400, "focus is not a branch ref");
|
|
602
|
+
focusOid = String(hit.tipOid).toLowerCase();
|
|
603
|
+
}
|
|
604
|
+
// 与图相同的 topo/date 顺序定位 focus;扫描上限明确报错,不静默截断。
|
|
605
|
+
const scan = await graphRace(
|
|
606
|
+
() => provider.graph(authorized.root, {
|
|
607
|
+
refs: refs.map((ref) => ref.tipOid),
|
|
608
|
+
offset: 0,
|
|
609
|
+
limit: MAX_GRAPH_ALL_SCAN,
|
|
610
|
+
timeoutMs: Math.max(1, deadline - Date.now()),
|
|
611
|
+
}),
|
|
612
|
+
deadline,
|
|
613
|
+
);
|
|
614
|
+
if (scan && scan.timedOut === true) throw graphTimeout();
|
|
615
|
+
const rows = Array.isArray(scan) ? scan : [];
|
|
616
|
+
focusIndex = rows.findIndex((row) => String(row?.oid ?? "").toLowerCase() === focusOid);
|
|
617
|
+
if (focusIndex < 0) throw failure("graph-focus-not-found", 409, "focus commit not found within scan limit");
|
|
618
|
+
}
|
|
619
|
+
const pageStart = focusIndex === null ? 0 : Math.floor(focusIndex / pageSize) * pageSize;
|
|
620
|
+
snapshot = {
|
|
621
|
+
id: randomUUID(), sessionId, repositoryId, root: authorized.root,
|
|
622
|
+
all: true, branchRefs: refs, refFingerprint,
|
|
623
|
+
tips: refs.map((ref) => ({ name: ref.name, tipOid: ref.tipOid })),
|
|
624
|
+
focusOid, focusIndex, pageStart,
|
|
625
|
+
expiresAt: now() + snapshotTtlMs, cursors: new Map(),
|
|
626
|
+
};
|
|
627
|
+
snapshotCreatedNow = true;
|
|
628
|
+
snapshots.set(snapshot.id, snapshot);
|
|
629
|
+
keepBounded(snapshots, 128);
|
|
630
|
+
offset = pageStart;
|
|
547
631
|
} else {
|
|
548
632
|
const selected = tips === undefined ? [{ name: "HEAD", tipOid: null }] : tips;
|
|
549
633
|
if (!Array.isArray(selected) || selected.length > tipCap) throw failure("graph-too-many-tips", 400, `tips limit is ${tipCap}`);
|
|
@@ -552,7 +636,7 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
552
636
|
if (new Set(names).size !== names.length || names.some((name) => !validRef(name)) || selected.some((tip) => tip?.tipOid != null && !validOid(tip.tipOid))) throw failure("graph-tip-invalid", 400);
|
|
553
637
|
// P0 批量解析:128 tips 只做一次 provider.refs(外部 provider 无 refs 才逐 tip)。
|
|
554
638
|
const resolved = await resolveGraphTips(authorized.root, selected, deadline);
|
|
555
|
-
snapshot = { id: randomUUID(), sessionId, repositoryId, root: authorized.root, tips: resolved, expiresAt: now() + snapshotTtlMs, cursors: new Map() };
|
|
639
|
+
snapshot = { id: randomUUID(), sessionId, repositoryId, root: authorized.root, all: false, tips: resolved, expiresAt: now() + snapshotTtlMs, cursors: new Map(), pageStart: 0 };
|
|
556
640
|
snapshotCreatedNow = true;
|
|
557
641
|
snapshots.set(snapshot.id, snapshot);
|
|
558
642
|
keepBounded(snapshots, 128);
|
|
@@ -573,16 +657,21 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
573
657
|
disposeSnapshot();
|
|
574
658
|
};
|
|
575
659
|
try {
|
|
576
|
-
|
|
660
|
+
// 全部分支:指纹覆盖全部分支 refs(新增/移动/删除都 stale);5/10:只校验选择集。
|
|
661
|
+
if (snapshot.all === true) await verifyAllGraphRefs(snapshot, authorized.root, deadline);
|
|
662
|
+
else await verifyGraphTips(authorized.root, snapshot.tips, deadline);
|
|
577
663
|
} catch (error) {
|
|
578
664
|
disposeOnGraphFailure(error);
|
|
579
665
|
throw error;
|
|
580
666
|
}
|
|
667
|
+
const graphRefs = snapshot.all === true
|
|
668
|
+
? snapshot.branchRefs.map((ref) => ref.tipOid)
|
|
669
|
+
: snapshot.tips.map((tip) => tip.tipOid);
|
|
581
670
|
let rawCommits;
|
|
582
671
|
try {
|
|
583
672
|
rawCommits = await graphRace(
|
|
584
673
|
() => provider.graph(authorized.root, {
|
|
585
|
-
refs:
|
|
674
|
+
refs: graphRefs,
|
|
586
675
|
offset,
|
|
587
676
|
limit: pageSize,
|
|
588
677
|
timeoutMs: Math.max(1, deadline - Date.now()),
|
|
@@ -599,7 +688,8 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
599
688
|
throw error;
|
|
600
689
|
}
|
|
601
690
|
try {
|
|
602
|
-
await
|
|
691
|
+
if (snapshot.all === true) await verifyAllGraphRefs(snapshot, authorized.root, deadline);
|
|
692
|
+
else await verifyGraphTips(authorized.root, snapshot.tips, deadline);
|
|
603
693
|
} catch (verifyError) {
|
|
604
694
|
// 混合错误:provider.graph 先抛临时 503,随后为判 stale 的二次
|
|
605
695
|
// verify 因 deadline 挂起 —— 必须原样透传 504,并按统一策略
|
|
@@ -614,7 +704,8 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
614
704
|
throw error;
|
|
615
705
|
}
|
|
616
706
|
try {
|
|
617
|
-
await
|
|
707
|
+
if (snapshot.all === true) await verifyAllGraphRefs(snapshot, authorized.root, deadline);
|
|
708
|
+
else await verifyGraphTips(authorized.root, snapshot.tips, deadline);
|
|
618
709
|
} catch (error) {
|
|
619
710
|
disposeOnGraphFailure(error);
|
|
620
711
|
throw error;
|
|
@@ -642,13 +733,28 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
642
733
|
refs: legacy, refsDetail: refDetails.refsDetail, tagsDetail: refDetails.tagsDetail,
|
|
643
734
|
};
|
|
644
735
|
});
|
|
736
|
+
// issue #93:双向分页。nextCursor 更早(offset+本页),prevCursor 更新(offset-页)。
|
|
645
737
|
let nextCursor = null;
|
|
646
738
|
if (commits.length === pageSize) {
|
|
647
739
|
nextCursor = randomUUID();
|
|
648
740
|
snapshot.cursors.set(nextCursor, offset + commits.length);
|
|
649
|
-
keepBounded(snapshot.cursors, 128);
|
|
650
741
|
}
|
|
651
|
-
|
|
742
|
+
let prevCursor = null;
|
|
743
|
+
if (offset > 0) {
|
|
744
|
+
prevCursor = randomUUID();
|
|
745
|
+
snapshot.cursors.set(prevCursor, Math.max(0, offset - pageSize));
|
|
746
|
+
}
|
|
747
|
+
keepBounded(snapshot.cursors, 256);
|
|
748
|
+
return {
|
|
749
|
+
repositoryId, snapshotId: snapshot.id, tips: snapshot.tips, commits,
|
|
750
|
+
nextCursor, prevCursor,
|
|
751
|
+
all: snapshot.all === true,
|
|
752
|
+
pageSize,
|
|
753
|
+
pageStart: offset,
|
|
754
|
+
focusOid: snapshot.all === true ? snapshot.focusOid : null,
|
|
755
|
+
hasNewer: offset > 0,
|
|
756
|
+
hasOlder: nextCursor !== null,
|
|
757
|
+
};
|
|
652
758
|
},
|
|
653
759
|
async files(sessionId, repositoryId, { q, limit } = {}) {
|
|
654
760
|
const authorized = await binding(sessionId, repositoryId);
|
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, readSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, unlinkSync,
|
|
14
|
+
readFileSync, 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";
|
|
@@ -1367,6 +1367,148 @@ const FILE_MIME = {
|
|
|
1367
1367
|
".js": "text/javascript; charset=utf-8", ".ts": "text/plain; charset=utf-8", ".py": "text/plain; charset=utf-8",
|
|
1368
1368
|
".html": "text/html; charset=utf-8", ".mp4": "video/mp4", ".apk": "application/vnd.android.package-archive",
|
|
1369
1369
|
};
|
|
1370
|
+
|
|
1371
|
+
/** issue #94:图片字节端点的白名单/嗅探(不依赖扩展名信任)。 */
|
|
1372
|
+
const IMAGE_EXTENSIONS = new Map([
|
|
1373
|
+
[".png", "image/png"],
|
|
1374
|
+
[".jpg", "image/jpeg"],
|
|
1375
|
+
[".jpeg", "image/jpeg"],
|
|
1376
|
+
[".gif", "image/gif"],
|
|
1377
|
+
[".webp", "image/webp"],
|
|
1378
|
+
]);
|
|
1379
|
+
const IMAGE_MAX_BYTES = 8 * 1024 * 1024;
|
|
1380
|
+
const IMAGE_MAX_DIMENSION = 8192;
|
|
1381
|
+
const IMAGE_MAX_PIXELS = 40_000_000;
|
|
1382
|
+
|
|
1383
|
+
/** 按 magic bytes 嗅探图片类型;未知返回 null。 */
|
|
1384
|
+
function sniffImageBufferType(buf) {
|
|
1385
|
+
if (!Buffer.isBuffer(buf) || buf.length < 12) return null;
|
|
1386
|
+
if (buf.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))) return "image/png";
|
|
1387
|
+
if (buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) return "image/jpeg";
|
|
1388
|
+
const ascii = buf.subarray(0, 6).toString("ascii");
|
|
1389
|
+
if (ascii === "GIF87a" || ascii === "GIF89a") return "image/gif";
|
|
1390
|
+
if (buf.subarray(0, 4).toString("ascii") === "RIFF" && buf.subarray(8, 12).toString("ascii") === "WEBP") return "image/webp";
|
|
1391
|
+
return null;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
/** 从图片头解析像素尺寸(支持 PNG/GIF/WebP/JPEG);解析不到返回 null。 */
|
|
1395
|
+
function imageDimensions(buf) {
|
|
1396
|
+
try {
|
|
1397
|
+
if (sniffImageBufferType(buf) === "image/png") {
|
|
1398
|
+
return { width: buf.readUInt32BE(16), height: buf.readUInt32BE(20) };
|
|
1399
|
+
}
|
|
1400
|
+
if (sniffImageBufferType(buf) === "image/gif") {
|
|
1401
|
+
return { width: buf.readUInt16LE(6), height: buf.readUInt16LE(8) };
|
|
1402
|
+
}
|
|
1403
|
+
if (sniffImageBufferType(buf) === "image/webp") {
|
|
1404
|
+
const chunk = buf.subarray(12, 16).toString("ascii");
|
|
1405
|
+
if (chunk === "VP8X") {
|
|
1406
|
+
return { width: 1 + buf.readUIntLE(24, 3), height: 1 + buf.readUIntLE(27, 3) };
|
|
1407
|
+
}
|
|
1408
|
+
if (chunk === "VP8 " && buf.length >= 30) {
|
|
1409
|
+
return { width: buf.readUInt16LE(26) & 0x3fff, height: buf.readUInt16LE(28) & 0x3fff };
|
|
1410
|
+
}
|
|
1411
|
+
if (chunk === "VP8L" && buf.length >= 25) {
|
|
1412
|
+
const b = buf.readUInt32LE(21);
|
|
1413
|
+
return { width: (b & 0x3fff) + 1, height: ((b >> 14) & 0x3fff) + 1 };
|
|
1414
|
+
}
|
|
1415
|
+
return null;
|
|
1416
|
+
}
|
|
1417
|
+
if (sniffImageBufferType(buf) === "image/jpeg") {
|
|
1418
|
+
let i = 2;
|
|
1419
|
+
while (i + 9 < buf.length) {
|
|
1420
|
+
if (buf[i] !== 0xff) return null;
|
|
1421
|
+
const marker = buf[i + 1];
|
|
1422
|
+
const length = buf.readUInt16BE(i + 2);
|
|
1423
|
+
if (length < 2) return null;
|
|
1424
|
+
// SOF0-SOF15(排除 DHT/JPG/DAC)带尺寸。
|
|
1425
|
+
if (marker >= 0xc0 && marker <= 0xcf && ![0xc4, 0xc8, 0xcc].includes(marker)) {
|
|
1426
|
+
return { width: buf.readUInt16BE(i + 7), height: buf.readUInt16BE(i + 5) };
|
|
1427
|
+
}
|
|
1428
|
+
i += 2 + length;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
} catch {
|
|
1432
|
+
return null;
|
|
1433
|
+
}
|
|
1434
|
+
return null;
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* issue #95(#94 TOCTOU):打开并验证工作区图片 fd,避免 realpath→stat→read(path)
|
|
1438
|
+
* 的二次路径读取竞态。必须在 open 后经 `/proc/self/fd/<fd>` 校验实际路径仍落在
|
|
1439
|
+
* cwd + 已登记工作区内;无 O_NOFOLLOW / 无 procfs / 非 Linux 一律 501 fail-closed。
|
|
1440
|
+
*
|
|
1441
|
+
* 供 HTTP 端点与确定性竞态测试共用;fs 可注入(测试换链/无 proc/非 Linux)。
|
|
1442
|
+
*/
|
|
1443
|
+
export function openVerifiedWorkspaceImage({
|
|
1444
|
+
candidateLex,
|
|
1445
|
+
cwdReal,
|
|
1446
|
+
workspaceRoots,
|
|
1447
|
+
expectedType,
|
|
1448
|
+
platform = process.platform,
|
|
1449
|
+
fs = { existsSync, openSync, fstatSync, readlinkSync, closeSync, readSync, constants },
|
|
1450
|
+
maxBytes = IMAGE_MAX_BYTES,
|
|
1451
|
+
}) {
|
|
1452
|
+
const inside = (parent, child) => {
|
|
1453
|
+
const rel = relative(parent, child);
|
|
1454
|
+
return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
|
|
1455
|
+
};
|
|
1456
|
+
const noProc = !fs.existsSync?.("/proc/self/fd");
|
|
1457
|
+
const noFollow = fs.constants?.O_NOFOLLOW;
|
|
1458
|
+
if (platform !== "linux" || noFollow === undefined || noProc) {
|
|
1459
|
+
return { ok: false, status: 501, code: "image-verification-unavailable" };
|
|
1460
|
+
}
|
|
1461
|
+
let fd = null;
|
|
1462
|
+
try {
|
|
1463
|
+
try {
|
|
1464
|
+
fd = fs.openSync(
|
|
1465
|
+
candidateLex,
|
|
1466
|
+
fs.constants.O_RDONLY | noFollow | (fs.constants.O_NONBLOCK ?? 0),
|
|
1467
|
+
);
|
|
1468
|
+
} catch (err) {
|
|
1469
|
+
if (err?.code === "ELOOP") return { ok: false, status: 403, code: "path-outside-workspace" };
|
|
1470
|
+
if (err?.code === "EACCES" || err?.code === "EPERM") return { ok: false, status: 403, code: "path-outside-workspace" };
|
|
1471
|
+
return { ok: false, status: 404, code: "image-not-found" };
|
|
1472
|
+
}
|
|
1473
|
+
let st;
|
|
1474
|
+
try { st = fs.fstatSync(fd); } catch { return { ok: false, status: 404, code: "image-not-found" }; }
|
|
1475
|
+
if (!st.isFile()) return { ok: false, status: 404, code: "image-not-found" };
|
|
1476
|
+
if (st.size <= 0) return { ok: false, status: 404, code: "image-not-found" };
|
|
1477
|
+
if (st.size > maxBytes) return { ok: false, status: 413, code: "image-too-large" };
|
|
1478
|
+
let actual;
|
|
1479
|
+
try { actual = fs.readlinkSync(`/proc/self/fd/${fd}`); }
|
|
1480
|
+
catch { return { ok: false, status: 501, code: "image-verification-unavailable" }; }
|
|
1481
|
+
actual = String(actual ?? "").replace(/ \(deleted\)$/, "");
|
|
1482
|
+
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
|
+
// 实际文件名也必须仍是期望图片扩展名(防止中间目录换链后指向别的文件)。
|
|
1491
|
+
if (IMAGE_EXTENSIONS.get(extname(actual).toLowerCase()) !== expectedType) {
|
|
1492
|
+
return { ok: false, status: 403, code: "path-outside-workspace" };
|
|
1493
|
+
}
|
|
1494
|
+
const buffer = Buffer.alloc(st.size);
|
|
1495
|
+
let offset = 0;
|
|
1496
|
+
while (offset < st.size) {
|
|
1497
|
+
let read = 0;
|
|
1498
|
+
try { read = fs.readSync(fd, buffer, offset, st.size - offset, offset); }
|
|
1499
|
+
catch { return { ok: false, status: 404, code: "image-not-found" }; }
|
|
1500
|
+
if (!Number.isInteger(read) || read <= 0) break;
|
|
1501
|
+
offset += read;
|
|
1502
|
+
}
|
|
1503
|
+
if (offset === 0) return { ok: false, status: 404, code: "image-not-found" };
|
|
1504
|
+
return { ok: true, bytes: buffer.subarray(0, offset) };
|
|
1505
|
+
} finally {
|
|
1506
|
+
if (fd !== null) {
|
|
1507
|
+
try { fs.closeSync(fd); } catch {}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1370
1512
|
const fileMimeOf = (name) => FILE_MIME[extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
1371
1513
|
|
|
1372
1514
|
/**
|
|
@@ -7345,6 +7487,9 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
7345
7487
|
}
|
|
7346
7488
|
const GRAPH_POST_BODY_LIMIT = 256 * 1024;
|
|
7347
7489
|
const GRAPH_TIP_NAME_LIMIT = 1024;
|
|
7490
|
+
// focus 只接受分支 ref 或完整 commit oid;字符串长度有界,避免日志/扫描放大。
|
|
7491
|
+
const sourceFocusInvalid = (value) => value !== undefined
|
|
7492
|
+
&& (typeof value !== "string" || value.length === 0 || Buffer.byteLength(value, "utf8") > GRAPH_TIP_NAME_LIMIT);
|
|
7348
7493
|
let postBody = null;
|
|
7349
7494
|
if (method === "POST") {
|
|
7350
7495
|
const declared = Number(req.headers?.["content-length"]);
|
|
@@ -7365,11 +7510,22 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
7365
7510
|
}
|
|
7366
7511
|
}
|
|
7367
7512
|
}
|
|
7368
|
-
|
|
7513
|
+
const allMode = postBody.all === true;
|
|
7514
|
+
if (allMode) {
|
|
7515
|
+
// issue #93:all 模式忽略/不接受 tips 选择集;focus 可选(分支 ref)。
|
|
7516
|
+
if (tips !== undefined && (!Array.isArray(tips) || tips.length > 0)) {
|
|
7517
|
+
return error(res, 400, "bad-request", "tips must be omitted in all mode");
|
|
7518
|
+
}
|
|
7519
|
+
if (sourceFocusInvalid(postBody.focus)) return error(res, 400, "bad-request", "focus must be a ref or oid");
|
|
7520
|
+
} else if (postBody.snapshotId === undefined && postBody.cursor === undefined && !Array.isArray(tips)) {
|
|
7369
7521
|
return error(res, 400, "bad-request", "tips is required");
|
|
7370
7522
|
}
|
|
7371
7523
|
}
|
|
7372
7524
|
const source = postBody ?? {};
|
|
7525
|
+
const allMode = method === "POST" && source.all === true;
|
|
7526
|
+
if (method === "GET" && (url.searchParams.get("all") === "true" || url.searchParams.get("all") === "1")) {
|
|
7527
|
+
return error(res, 400, "bad-request", "all mode requires POST");
|
|
7528
|
+
}
|
|
7373
7529
|
const sessionId = (method === "POST" ? source.sessionId : null) ?? url.searchParams.get("sessionId") ?? "";
|
|
7374
7530
|
if (!sessionId) return error(res, 400, "bad-request", "sessionId is required");
|
|
7375
7531
|
const repositoryId = (method === "POST" ? source.repositoryId : null) ?? url.searchParams.get("repositoryId") ?? "";
|
|
@@ -7383,6 +7539,8 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
7383
7539
|
cursor: source.cursor,
|
|
7384
7540
|
limit: source.limit,
|
|
7385
7541
|
maxTips: 128,
|
|
7542
|
+
all: allMode,
|
|
7543
|
+
focus: allMode ? (typeof source.focus === "string" ? source.focus : undefined) : undefined,
|
|
7386
7544
|
});
|
|
7387
7545
|
} else {
|
|
7388
7546
|
let tips;
|
|
@@ -7400,7 +7558,7 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
7400
7558
|
}
|
|
7401
7559
|
sendJson(res, 200, { ok: true, ...value });
|
|
7402
7560
|
} catch (err) {
|
|
7403
|
-
const known = new Set(["session-not-found", "workspace-not-allowed", "not-git-repository", "git-provider-unavailable", "repository-not-authorized", "graph-stale", "graph-tip-invalid", "graph-too-many-tips", "graph-timeout", "invalid-oid", "git-command-failed", "git-output-too-large", "provider-incompatible"]);
|
|
7561
|
+
const known = new Set(["session-not-found", "workspace-not-allowed", "not-git-repository", "git-provider-unavailable", "repository-not-authorized", "graph-stale", "graph-tip-invalid", "graph-too-many-tips", "graph-too-many-refs", "graph-focus-invalid", "graph-focus-not-found", "graph-timeout", "invalid-oid", "git-command-failed", "git-output-too-large", "provider-incompatible"]);
|
|
7404
7562
|
const code = known.has(err?.code) ? err.code : "git-provider-unavailable";
|
|
7405
7563
|
const status = Number(err?.status);
|
|
7406
7564
|
ctx.logger.warn?.(`mobile-remote: Git graph failed (${code}): ${err?.message ?? err}`);
|
|
@@ -9940,6 +10098,97 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
9940
10098
|
}
|
|
9941
10099
|
return;
|
|
9942
10100
|
}
|
|
10101
|
+
if (rest === "/workspace-image") {
|
|
10102
|
+
if (method !== "GET" && method !== "HEAD") return error(res, 405, "method-not-allowed");
|
|
10103
|
+
// issue #94:只读图片字节端点。只允许当前会话 cwd(且属于已注册工作区)内的
|
|
10104
|
+
// 普通图片文件;realpath + 前缀校验拒绝 .. / symlink / 任意绝对路径逃逸。
|
|
10105
|
+
const sessionId = url.searchParams.get("sessionId") ?? "";
|
|
10106
|
+
if (!sessionId) return error(res, 400, "bad-request", "missing sessionId");
|
|
10107
|
+
const rawPath = url.searchParams.get("path");
|
|
10108
|
+
if (!rawPath || rawPath.includes("\0")) return error(res, 400, "bad-request", "missing path");
|
|
10109
|
+
const agents = ctx.get("agents");
|
|
10110
|
+
const sessions = ctx.get("sessions");
|
|
10111
|
+
const liveSession = agents?.get?.(sessionId)?.session;
|
|
10112
|
+
const session = liveSession ?? sessions?.get?.(sessionId);
|
|
10113
|
+
if (!session) return error(res, 404, "session-not-found");
|
|
10114
|
+
const cwd = sessionCwdOf(session);
|
|
10115
|
+
if (typeof cwd !== "string" || cwd === "") return error(res, 404, "workspace-not-found");
|
|
10116
|
+
const cwdLex = resolve(normalizeServerPath(cwd));
|
|
10117
|
+
let candidateLex;
|
|
10118
|
+
try {
|
|
10119
|
+
const normalized = normalizeServerPath(rawPath);
|
|
10120
|
+
candidateLex = isAbsolute(normalized) ? resolve(normalized) : resolve(cwdLex, normalized);
|
|
10121
|
+
} catch {
|
|
10122
|
+
return error(res, 400, "bad-request", "invalid path");
|
|
10123
|
+
}
|
|
10124
|
+
const inside = (parent, child) => {
|
|
10125
|
+
const rel = relative(parent, child);
|
|
10126
|
+
return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
|
|
10127
|
+
};
|
|
10128
|
+
if (!inside(cwdLex, candidateLex)) return error(res, 403, "path-outside-workspace");
|
|
10129
|
+
const extension = extname(candidateLex).toLowerCase();
|
|
10130
|
+
const expectedType = IMAGE_EXTENSIONS.get(extension);
|
|
10131
|
+
if (!expectedType) return error(res, 415, "unsupported-image-type");
|
|
10132
|
+
let realCwd;
|
|
10133
|
+
try { realCwd = realpathSync(cwdLex); } catch { return error(res, 404, "workspace-not-found"); }
|
|
10134
|
+
// 注册工作区闸门:cwd 必须属于某个 workspaceRegistry 登记的工作区。
|
|
10135
|
+
const registry = ctx.get("workspaceRegistry");
|
|
10136
|
+
const listed = registry?.list?.();
|
|
10137
|
+
const workspaces = Array.isArray(listed) ? listed : [];
|
|
10138
|
+
const workspaceRoots = [];
|
|
10139
|
+
let cwdInWorkspace = false;
|
|
10140
|
+
for (const entry of workspaces) {
|
|
10141
|
+
const root = entry?.path;
|
|
10142
|
+
if (typeof root !== "string" || root === "") continue;
|
|
10143
|
+
try {
|
|
10144
|
+
const realRoot = realpathSync(root);
|
|
10145
|
+
workspaceRoots.push(realRoot);
|
|
10146
|
+
if (inside(realRoot, realCwd)) cwdInWorkspace = true;
|
|
10147
|
+
} catch {}
|
|
10148
|
+
}
|
|
10149
|
+
if (!cwdInWorkspace) return error(res, 403, "workspace-not-authorized");
|
|
10150
|
+
const opened = openVerifiedWorkspaceImage({
|
|
10151
|
+
candidateLex,
|
|
10152
|
+
cwdReal: realCwd,
|
|
10153
|
+
workspaceRoots,
|
|
10154
|
+
expectedType,
|
|
10155
|
+
});
|
|
10156
|
+
if (!opened.ok) return error(res, opened.status, opened.code);
|
|
10157
|
+
const bytes = opened.bytes;
|
|
10158
|
+
if (bytes.length === 0) return error(res, 404, "image-not-found");
|
|
10159
|
+
if (bytes.length > IMAGE_MAX_BYTES) return error(res, 413, "image-too-large");
|
|
10160
|
+
const sniffed = sniffImageBufferType(bytes);
|
|
10161
|
+
if (!sniffed || sniffed !== expectedType) return error(res, 415, "unsupported-image-type");
|
|
10162
|
+
const dims = imageDimensions(bytes);
|
|
10163
|
+
// issue #95:解析不到像素尺寸一律 fail-closed(不把未知尺寸当通过)。
|
|
10164
|
+
if (!dims) return error(res, 415, "unsupported-image-type");
|
|
10165
|
+
if (dims.width <= 0 || dims.height <= 0 ||
|
|
10166
|
+
dims.width > IMAGE_MAX_DIMENSION || dims.height > IMAGE_MAX_DIMENSION ||
|
|
10167
|
+
dims.width * dims.height > IMAGE_MAX_PIXELS) {
|
|
10168
|
+
return error(res, 413, "image-too-large");
|
|
10169
|
+
}
|
|
10170
|
+
const etag = `"${createHash("sha256").update(bytes).digest("hex").slice(0, 32)}"`;
|
|
10171
|
+
const headers = {
|
|
10172
|
+
"content-type": sniffed,
|
|
10173
|
+
"content-length": String(bytes.length),
|
|
10174
|
+
"cache-control": "private, max-age=86400",
|
|
10175
|
+
etag,
|
|
10176
|
+
"x-content-type-options": "nosniff",
|
|
10177
|
+
connection: "close",
|
|
10178
|
+
};
|
|
10179
|
+
if (String(req.headers?.["if-none-match"] ?? "") === etag) {
|
|
10180
|
+
res.writeHead(304, { etag, "cache-control": headers["cache-control"], connection: "close" });
|
|
10181
|
+
res.end();
|
|
10182
|
+
return;
|
|
10183
|
+
}
|
|
10184
|
+
res.writeHead(200, headers);
|
|
10185
|
+
if (method === "HEAD") {
|
|
10186
|
+
res.end();
|
|
10187
|
+
return;
|
|
10188
|
+
}
|
|
10189
|
+
res.end(bytes);
|
|
10190
|
+
return;
|
|
10191
|
+
}
|
|
9943
10192
|
if (rest === "/files" && (method === "GET" || method === "HEAD")) {
|
|
9944
10193
|
const path = url.searchParams.get("path");
|
|
9945
10194
|
if (!path || path === "") return error(res, 400, "bad-request", "missing path");
|
|
@@ -10192,6 +10441,61 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
10192
10441
|
}
|
|
10193
10442
|
return;
|
|
10194
10443
|
}
|
|
10444
|
+
if (rest === "/skills") {
|
|
10445
|
+
if (method !== "GET" && method !== "HEAD") return error(res, 405, "method-not-allowed");
|
|
10446
|
+
// issue #90:只读技能目录(DSH ctx.skills.list 的透传)。
|
|
10447
|
+
// 仅下发 name/description/whenToUse/modelInvocable;不暴露 path/正文/资源。
|
|
10448
|
+
// 旧宿主/服务缺失/目录失败一律 200 + unavailable(不 5xx、不阻塞命令)。
|
|
10449
|
+
const sessionId = url.searchParams.get("sessionId") ?? "";
|
|
10450
|
+
if (!sessionId) return error(res, 400, "bad-request", "missing sessionId");
|
|
10451
|
+
const agents = ctx.get("agents");
|
|
10452
|
+
const presets = ctx.get("agentPresets");
|
|
10453
|
+
const sessions = ctx.get("sessions");
|
|
10454
|
+
const skillRegistryOf = (agent) => {
|
|
10455
|
+
try {
|
|
10456
|
+
const scoped = presets?.serviceFor?.(agent, "skills");
|
|
10457
|
+
if (scoped) return scoped;
|
|
10458
|
+
} catch {}
|
|
10459
|
+
return ctx.get("skills");
|
|
10460
|
+
};
|
|
10461
|
+
const listSkills = async (agent) => {
|
|
10462
|
+
const registry = skillRegistryOf(agent);
|
|
10463
|
+
if (!registry || typeof registry.list !== "function") return null;
|
|
10464
|
+
const cwd = agent?.session?.header?.cwd
|
|
10465
|
+
?? sessions?.get?.(sessionId)?.header?.cwd
|
|
10466
|
+
?? process.cwd();
|
|
10467
|
+
const skills = await registry.list({ cwd, scope: agent });
|
|
10468
|
+
return (Array.isArray(skills) ? skills : [])
|
|
10469
|
+
.filter((skill) => skill?.invocation?.userInvocable === true)
|
|
10470
|
+
.map((skill) => ({
|
|
10471
|
+
name: String(skill.name),
|
|
10472
|
+
description: String(skill.description ?? ""),
|
|
10473
|
+
...(skill.whenToUse ? { whenToUse: String(skill.whenToUse) } : {}),
|
|
10474
|
+
modelInvocable: skill.invocation?.modelInvocable === true,
|
|
10475
|
+
}));
|
|
10476
|
+
};
|
|
10477
|
+
try {
|
|
10478
|
+
let agent = agents?.get?.(sessionId);
|
|
10479
|
+
if (!agent) {
|
|
10480
|
+
try { agent = (await resumeDormantAgent(sessionId))?.agent; } catch {}
|
|
10481
|
+
}
|
|
10482
|
+
if (!agent) {
|
|
10483
|
+
// 会话确实不存在:明确 404(与 /commands 一致),但技能目录缺失本身不会走到这里。
|
|
10484
|
+
return error(res, 404, "session-not-found", `session not found: ${sessionId}`);
|
|
10485
|
+
}
|
|
10486
|
+
const skills = await listSkills(agent);
|
|
10487
|
+
if (skills === null) {
|
|
10488
|
+
sendJson(res, 200, { ok: true, skills: [], unavailable: true });
|
|
10489
|
+
return;
|
|
10490
|
+
}
|
|
10491
|
+
sendJson(res, 200, { ok: true, skills });
|
|
10492
|
+
} catch (err) {
|
|
10493
|
+
// 技能目录不可用必须静默降级:命令菜单仍可用。
|
|
10494
|
+
ctx.logger.warn?.(`mobile-remote: skills list unavailable (${sessionId}): ${err?.message ?? err}`);
|
|
10495
|
+
sendJson(res, 200, { ok: true, skills: [], unavailable: true });
|
|
10496
|
+
}
|
|
10497
|
+
return;
|
|
10498
|
+
}
|
|
10195
10499
|
if (rest === "/commands") {
|
|
10196
10500
|
// v2.8.0:斜杠命令目录(对齐 PC 端 ctx.commands)——GET 列出、POST 执行
|
|
10197
10501
|
// v2.8.2 适配:commands 服务可能未注册(desktop profile / 旧 DSH 无 dsh-commands host 服务)——
|
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.15",
|
|
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.15-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",
|