Commit Graph
43 Commits
Author SHA1 Message Date
lhh010 37bc30f164 fix(git): harden runGit's output caps — latch, killTree, stderr budget
dev already caps stdout bytes (GIT_OUTPUT_MAX_BYTES) and NUL fields, but
three gaps remain, all proven by the 2026-10-13 host crashes (twice:
RangeError: Invalid string length at the stdout accumulator, a junction-
forest workspace driving 'git status -uall' to gigabytes):

1. no latch after a byte-cap reject — later chunks kept ACCUMULATING on
   the retained strings. On Windows spawn('git') resolves to the cmd
   shim, whose grandchild survives child.kill() and keeps feeding the
   dead accumulator (measured: the orphan outlived kill() by 20+s). The
   fieldCapped guard covered only the row cap; the byte cap had none.
2. kill() reaches only the wrapper — the orphaned grandchild needs its
   pipes destroyed (EPIPE) to actually stop. killTree() destroys both
   streams and is now used by every kill path (timeout, byte cap, field
   cap).
3. stderr was uncapped — a command whose DIAGNOSTICS stream past the
   budget is as able to kill the host via string length as its answer;
   stderr now shares the same maxBytes budget.

Worst case in a pathological workspace is now one failed SCM refresh,
never a dead host.
2026-10-18 20:18:57 +08:00
Menghuan1918 40ed740f3a merge pr-944 (#944 feat(git): Git 内容区改为 VS Code Source Control 结构) into dev(@hairyf)
冲突解决(按 D4 与仓库现役不变量):
- status() 改为 porcelain v2(branch/upstream/ahead-behind/detached/operation 一次读回),
  但保留 dev 的行/字段上限、pathspec 化 numstat 与 #909 的分侧计数;v2 记录遍历抽成
  porcelainV2Tokens,状态解析与 pathspec 提取共用同一份字段知识;
- GitLens 的 Merge/Staged/Changes 三组取 #944,两组各读自己那一侧(#909),
  Merge 组不印行数(冲突不是行数故事,也不许把某一侧当「这个数」);
  sideEntries 保留(每组只读自己那一半的 XY 字母);
- ChangesTab 保留 #939 的官方 Tabs 外观与 a11y 包装、刷新按 #944 只留给本轮文件镜头;
- 测试:git.spec 导入取并集、rmSync 清理改回 removeTree、smoke 的 branch/detached 断言
  按 porcelain v2 语义改写,其余用例按新契约微调(band 顺序、changesOps 第 4 参 wait)。

剔除夹带(D4):.agents/skills/handle/SKILL.md、eslint/vitest 的 soruce/vscode 忽略项、
webRuntime→connection.requestRejection 栅栏与 ownEntryId 放宽(index.ts / context-types.ts
取 dev)、栅栏类测试桩与注释一并回退,栅栏归属留给 0.2.1 兼容批。
2026-10-16 17:14:06 +08:00
Menghuan1918 172ca849dd fix(git): BFS 发现根与 rev-parse 的路径拼法统一(#607 收尾)
macOS 的 tmpdir 是软链(/var → /private/var),Windows 上 join 出的是反斜杠而
`rev-parse --show-toplevel` 用正斜杠:两种拼法都会让同一个检出在仓库选择器里出现两次,
CI 的 canonical() 断言先红。发现根现在走 realpath +(Windows 才做的)分隔符折叠。

在 5b6f7319 的 ci-windows 上实测到 5 条 git.spec.ts 失败(全是分隔符)。
2026-10-16 16:54:39 +08:00
Menghuan1918 5b6f7319f9 merge pr-909 (#909 fix(changes): 变更面板两侧行数不再相加,各分组各读自己那一侧) into dev(@UNscientific-9)
冲突解决:删除 addLineCounts,状态读数改为分侧(staged/unstaged 各自一张表),
保留 dev 的 pathspec 化 numstat 读取(--literal-pathspecs + 原路径 + 行/字段上限)。
同批带上 #607 落地后暴露的两处适配:
- discoverRepoRoots 的 BFS 发现根改走 realpath(macOS tmpdir 的 /var → /private/var 别名,
  否则 rev-parse 的根与扫描根是同一仓库的两种拼法,dev 的 canonical() 断言当场红);
- tests/git-worktree 的 numstat pathspec 用例按分侧形状断言(合计仍为 +3/−0)。
2026-10-16 16:35:59 +08:00
Menghuan1918 15665f1ff3 merge pr-607 (#607 feat(git): 工作区根为仓库时仍探测并展示子目录独立仓库) into dev(@iasiv5) 2026-10-16 16:33:40 +08:00
Menghuan1918 f132c69cb0 merge pr-827 (#827 fix(git): 自动应答 dubious ownership 守卫,单命令注入 safe.directory) into dev(@yanzhaohui1999)
冲突解决:保留 dev 的 runGit 三道护栏(8 MiB 输出上限 / maxNulFields 行数上限 / core.quotePath=false),
把 #827 的 spawnGit + safe.directory 重试叠在其上;GIT_ENV 取并集(GIT_OPTIONAL_LOCKS=0 + LC_ALL=C)。
不复活已被 ebc5d0b6 删除的 runGitRaw(无调用者)。
2026-10-16 16:33:38 +08:00
Menghuan1918 a628bdd1e9 fix(git): 行数封顶后不再累加输出 + 用注入式子进程确定性钉住两道上限
CI 在 ubuntu 上抓到 new 用例红:`stops producing once the NUL field cap is reached`
断言 2500 < 2500 不成立。查下来是**产品语义与断言不符**,不只是测试问题:

- `runGit` 在 `fieldCapped` 置位并 kill 子进程之后,仍然继续把后续 chunk 累加进
  `stdout`。子进程早已把整份输出写进管道时(125 KB 的 status 在 CI 上就是如此),
  被「封顶」的调用会原样返回全部 2500 行——「封顶」只约束了 kill,没有约束调用方
  拿到的东西。现在置位后忽略后续 chunk,保留量真正有界(封顶值 + 至多一个跨越
  封顶的 chunk)。
- 真 git 那条用例的 `toBeLessThan` 本质是竞态(kill 与子进程写完谁先到),把文件名
  加长到「一个 64 KiB chunk 至多携带约 500 个字段」让上界成立,并在注释里写明这条
  推理;**kill 本身**改由 `tests/git-spawn.spec.ts` 的注入式子进程确定性钉住
  (跨过封顶的 chunk + 封顶之后才到达的尾巴 + kill 恰好一次),另补字节上限的
  rejects 用例。撤掉产品守卫该用例当场红(kill 被调两次且尾巴进了结果)。

本地门禁:typecheck / lint 干净,全量 210 文件 / 2524 通过。
2026-10-16 00:28:41 +08:00
Menghuan1918 3e5576ffbb perf(host): cwd 解析加在飞去重与 TTL 对齐、numstat 加 pathspec 与输出上限
src/active-worktree.ts 是 v0.25 新文件,却插进了 12 条 /sidebar/* 路由共用的
cwdOf():实测每次缓存未命中 9.6–44.7ms、1–4 次真实 git spawn,而 TTL 3s 与客户端
新的 5s 每-tab 轮询错配——每次轮询必然未命中。

- active-worktree:(session, base) 整链与 base 探针都加在飞去重(并发 8 次只 spawn
  一次);ACTIVE_ROOT_TTL_MS 3s→15s(跟随 worktree 的延迟代价写进注释);三个模块级
  缓存加 LRU 上界 512/512/256,负结果仍缓存但可淘汰。
- git.ts:两条 --numstat 加 pathspec(非 ?? 路径 + R/C 的 origin,必须
  --literal-pathspecs;未跟踪路径不参与 ⇒ 未忽略的大目录从两条全仓库 diff 变成零条;
  路径超 8KB 回退整仓库 diff)、runGit 加 8MiB 输出上限、状态行上限改在产出侧生效。
- fs-tree:折叠探测每层封顶 32 且截断层不探测(折叠是纯装饰)。
- index.ts:单层 fs.tree 补 ProbeGate;teardown 主动关闭三个 noServer WSS 的已接受
  连接(ws@8 的 close() 不终止在连 socket,句柄会活到浏览器断开)。
- sidechat-routes:冷线程日志按 (childId, revision, size) memo(16 线程,句柄照旧
  open/close,只有结果被缓存)。
- agent-opens:每会话队列封顶 64,最旧的丢弃,FIFO 与 drainAll 语义不变。

测试:扩展 active-worktree / git-worktree / fs-tree-probe-gate / sidechat-routes /
smoke / agent-opens;14 项「临时回退→变红→还原」突变全部被捕获。
2026-10-15 23:05:32 +08:00
iasiv5 d311798565 feat(git): 有界深度 BFS 扫描,发现二/三层嵌套的子目录独立仓库
v1 只扫描 cwd 下一层目录,且每个子目录用 `git rev-parse --show-toplevel`
解析——该命令只沿父目录向上找 toplevel、从不向下探测,因此复合工作区根
目录下嵌套两层及以上的独立仓库(如 group/project、group/project/vendor-lib)
结构性不可见。

将一层扫描替换为有界深度 BFS:

- 新常量 DISCOVERY_MAX_DEPTH = 4(BFS 层数):检出深度 = 层数 − 1 = 3,
  覆盖三层嵌套;第 4 层 frontier 只收集、不再展开,成本被深度 ≤ 3 的
  目录数约束。
- 每个访问目录只做一次 readdir,以 dirent 的 `.git` 存在性判定是否为
  仓库(目录 / 文件 / symlink 三态,覆盖 worktree 与 submodule 的 `.git`
  文件形态),子目录探测零 git 子进程——#369 那种"数百个 git 子进程
  串行卡死面板"的模式结构上不可能回归。
- 发现 .git 后仍继续下钻,非 submodule 的嵌入仓库(repo 套 repo)同样可见。
- 跳过隐藏目录、symlink 目录与 node_modules;每层保留 DISCOVERY_LIMIT
  上限;pathIdentity 去重不变。

典型复合工作区(访问深度 ≤ 3 目录约 336 个)实测全部仓库根检出耗时约
12–17ms。
2026-10-14 06:19:57 +08:00
iasi 19320814c4 feat(git): discover root and child repos when workspace is also a git repo 2026-10-14 06:19:57 +08:00
hairyf 5efc7beae0 Merge remote-tracking branch 'origin/dev' into feat/git-scm-941
# Conflicts:
#	eslint.config.js
2026-10-13 23:19:26 +08:00
hairyf f0ce77b401 feat(git): replace Git interior with SCM changes and parent graph 2026-10-13 20:36:55 +08:00
Menghuan1918 751720f4f0 perf(git): 状态轮询基线降到 30 s 并按实测退档;编辑器 gutter 不再持有轮询
一次抓取是 `git status --untracked-files=all` 加两条全仓库 `--numstat`(4 个
进程)。在未忽略的大目录上(嵌套 node_modules、pnpm store——根锚定
`/node_modules` 盖不住子目录那种仓库)实测 59,631 条 / 9.24 MB / 0.131 s,
而 `GIT_STATUS_LIMIT = 2000` 是在整份输出产出、拼进字符串、切成五万多个对象
之后才截断的。三处一起收:

- **编辑器 gutter 不再持有轮询**:它此前把功能开关当作页签可见性传进共享
  store,而那个参数正是启动定时器的开关;原生页签 `keepMounted` 又让编辑器
  切走不卸载,于是打开过任何一个 `code` / `jsonl` 文件之后,整页生命周期都在
  每 2.5 s 跑一次那个扫描。现在订阅改为 `{ visible: active, poll: false }`,
  只在换文件或保存时各 `refresh()` 一次,页签不可见时连订阅都不建立。
- **基线 30 s + 按实测退档**:往返超 750 ms / 2 s / 5 s 依次退到 60 s /
  180 s / 停止自动轮询;tier 是最近一次耗时的纯函数,快响应自动回落,事件
  驱动刷新(暂存、提交、丢弃、保存、手动刷新)永远即时,也是恢复通道。
- **空闲轮询不再通知**:`notify()` 原先无条件自增 `slot.version`,而它就是
  `useSyncExternalStore` 的 snapshot,于是每个消费者每 tick 整体重渲染一次
  (文件树那一列逐行重算 git 状态也在其中),即便数据一字未变。
- **linked-checkout 清单改单命令计数**:变动页的 worktree 选择器每 30 s 为
  每个 checkout 跑一次完整 `status()` 只为读条目数,现为一条轻量
  `status --untracked-files=normal`。一处刻意的语义变化:未跟踪目录计 1
  (此前展开计入每个文件,且数字被 2000 上限悄悄截断)。

消费方 API 零变化;`FileViewerProps` / `ctx.betterSidebar` 均未动。文件树与
文件变动页的条目与配色语义不变,只是刷新节奏变慢。

测试:新增 `tests/git-status-poll.spec.tsx`(7 例,含「非轮询消费者不得启动
定时器」「空闲同结果不通知(snapshot 恒等)」「慢往返退档与快响应回落」);
`tests/editor-git-gutter.spec.tsx` +3;`tests/git-worktree.spec.ts` +1;
`tests/git-view-worktree.spec.tsx` 的计数重发布用例跟着新节奏推进假时钟。
判别性已逐条实测:回退空闲守卫、`poll` 归属、gutter 的 `poll: false`,
对应用例当场红。

设计、实测数据与普查后续项见
docs/plans/2026-10-13-git-poll-ladder-and-idle-notify.md。
2026-10-13 13:12:00 +08:00
unsc9 42bfd9386e refactor(changes): 精简两侧行数改动的注释、测试夹具与合约(行为不变)
上一个提交(bdf3c33)过了一轮「代码精简」审查(复用 / 简化 / 效率 / 修在哪一层
四个角度,四个只读子代理并发),这里只落地行为完全不变的那批。

- 同一个「两侧不能相加」的理由原先在 5 处源码注释与 4 处测试注释里各写一遍,
  措辞已经开始分叉。完整理由只留在权威位置 `GitStatusEntry` 的字段文档;
  `status()`、`api.ts` 的镜像类型、`ChangeFile.counts`、GitLens 的调用处与三处
  测试注释压成一行并指回去。
- 用例夹具:`change-tree-counts.spec.ts` 的 `entry()` 从「传一个 sides 对象」改成
  「传一个读数 + 一个侧」,收掉 13 处 `{ unstaged: … }` 外壳;那个 `side` 用生产
  侧导出的 `ChangeSide`——它此前导出了却没有任何消费者。
- 同文件「两侧不相加」的用例原先两侧读数对称(都是 1/1),两条断言的期望值逐字
  相同:把两侧读反也照样绿。夹具改成不对称(staged 1/1、unstaged 5/0),「相加」
  与「读错边」两种错误现在都会失败。
- `git.spec.ts` 里第 4 份「建仓引导」提成局部 `mkRepo(files, config)`,与紧邻用例
  共用(少一次重复的 4 个 git 进程)。
- `git-view-worktree.spec.tsx` 的 `mountTree` 形参原先手写镜像了 `GitStatusEntry`
  的四个成员,改回 `GitStatusEntry[]`(同文件上方本就 import 了它)。

按「超出本次 diff / 会改变行为」跳过的四条,留档:GitLens 里 band↔侧的六处穿线
(要重写两个本 diff 没动过、近乎逐字重复的渲染块)、「这行会不会印数字」的两处
判断(合一就必须让 0/0 行不再渲染那个空 span,那是改输出)、快照身份的两份实现
(造键 vs 判等,本就是两件事)、服务端 `git.suggest-message` 又推一遍「属于哪
一侧」(本 diff 之外,且与本次 bug 同类)。另:`GitStatusEntry` 在 `git.ts` 与
`api.ts` 的两份声明是刻意的镜像(浏览器侧声明图不能碰 `node:*`),不合并。

验证:`tsc --noEmit` 通过;eslint 对 7 个改动文件无输出;受影响的 6 个测试文件
173 条全绿(含真起 git 进程的用例);完整单测 189 文件 / 2234 用例,失败仍是与
改动前同一批 8 条环境性失败(3 条 Windows 建符号链接 EPERM、1 条 `tar` 在 Windows
输出 CRLF、4 条中文语言标签),无新增。
2026-10-11 17:59:32 +08:00
unsc9 bdf3c33865 fix(changes): 变更面板两侧行数不再相加,各分组各读自己那一侧(#131)
同一文件同时有已暂存与未暂存改动(porcelain 'MM')时,status() 把
`git diff --cached --numstat`(index 对 HEAD)与 `git diff --numstat`
(worktree 对 index)按路径相加成一个数。两次 diff 的基线不同,相加会把
两者都看到的那几行算两遍:改写一行并暂存、再改同一行,两组各自显示
`+2 −2`,真值只有 `+1 −1`;面板里该文件出现两次,于是同一个虚高值被印
两遍、也被两个分组头各合计一遍。原注释写的「两侧都是对 HEAD 量的」前提
不成立——不带 --cached 的 git diff 量的是 worktree 对 index。

改为让两侧各自保留读数,一路传到分组:

- src/git.ts / src/client/api.ts:`counts` 拆成 `staged` / `unstaged`,
  各查各的 numstat 表;删掉 addLineCounts
- src/client/changes/change-tree.ts:`buildChangeTree(entries, side)`
  按分组取自己那一侧,叶子上的 `counts` 因此只代表所在分组
- src/client/changes/GitLens.tsx:两个分组各传自己的 side;内容键改成
  同时含两侧,否则「只动了一侧的行数」不会重建树
- src/client/ui/git-status.ts:快照比较逐侧比,语义与原来一致

用例:`tests/git.spec.ts` 新增真实仓库用例钉住 `MM` 的两侧读数并断言不再
出现相加值(原用例正好钉着旧行为,一并改);`tests/change-tree-counts.spec.ts`
与 `tests/git-view-worktree.spec.tsx` 钉住每个分组只读自己那一侧。
2026-10-10 20:07:32 +08:00
unsc9 ebc5d0b6b7 refactor: 精简 dev 相对 main 新增代码里的重复与白干(行为不变)
dev 分支的新增代码过了一轮「代码精简」审查(复用 / 简化 / 效率 / 修在哪一层四个角度,
分宿主侧、客户端外壳、客户端功能面板三片,另加测试与脚本),这里只落地行为完全不变的那批:

- `runGitRaw` 是 `runGit` 的纯转发别名(三个角度都点到):导出 `runGit`、删掉别名,
  `active-worktree.ts` 与它的 `vi.mock` 键同步改名。
- `open-external.ts` 的 `messageOf` 与 `fs-tree.ts` 的导出逐字相同:删本地实现改 import。
- `fs-operations.ts` 的单段名校验抄了三遍(注释却自称 shared rule):提成
  `assertSingleSegmentName`,rename / mkdir / 新建文件三处共用。
- `fs-tree.ts` 两个探测函数各抄一遍有界并发池:提成 `forEachRow`。
- `index.ts` 自己复刻了一遍 `request/header` 的 provider/model 读取:改调
  `collectModelRoutes(events, 1)[0]`;`lowestReasoningEffortOf` 的三态循环收成
  best/bestRank;`formatModelRoute` 零调用点,删掉(连带自测)。
- `state.ts`:`markUnread` / `clearUnread` 的当前会话路径改走已有的 `reduce`
  (「归约器返回同引用即 no-op」本来就在 reduce 里),删掉私有的 `replaceCurrent`;
  非当前会话那条仍只写内存不落盘,行为未动。
- `editor-dirty.ts`:`DirtyEntry.sessionId` 只服务一个没有生产调用者的
  `dirtyCountForSession`,会话隔离已由 `sessionId::tabId` 这个键承载,两个一起删,
  用例改断 `isEditorDirty(tabId, sessionId)`。
- `FileTree.tsx`:同一批行原先 `renderLevel` 与 `visibleRows` 各排一次,收进按
  `(data, sort)` 记忆的 `entriesFor`(照 `chainFor` 的形状)。
- `dock-fallback.tsx`:500ms 重测出的坐标没变就不换 state 对象(省掉一次无意义重渲染)。
- 其余同形收口:`DiffPane` 的死分支、`terminal-client` 的 `bottomTerminalKey`
  (与 `bottomTerminalContentId` 同值,调用点复用同一个 id)、`SideChatView` 的
  O(线程×目录) 排序扫描降为 Map、`conversation-draft` 的末段路径复用 `paths.baseName`、
  `TreePanel` 的目录命中集按 results 记忆。

验证:`tsc --noEmit` 只剩改动前那 3 条缺 `@xterm/*` 的既有报错;eslint 干净;
全套 vitest 与改动前的失败集合逐条一致(13 条,均为环境原因:缺 xterm 的构建/转换类
3 条、Windows 符号链接权限 3 条、语言字典串味 4 条、真起 git 的冒烟 1 条、文件级 1 条)。
2026-10-09 16:04:24 +08:00
Menghuan1918 bce22cfaf1 merge feat/212-editor-git-gutter into dev(#212 编辑器变更提示:code 视图行号槽着色 + 左侧细色条 + hover blame,一个布尔开关,样式极简) 2026-10-05 22:32:26 +08:00
Menghuan1918 2c8d11a8fc feat(editor): 编辑器未提交变更提示(行号着色 + 左侧色条 + hover blame)(#212)
code 视图(可编辑 CodeMirror)显示未提交变更的行级提示,一个布尔设置
editorGitGutter(默认开)总开关:

- 行号槽着色 + 行号左侧 2px 细色条(新增/修改/删除),取色复用文件树
  既有 tone 口径(--dsw-alias-state-*);
- hover 某行时按需取该行 blame,纯文本 tooltip(作者 · 时间 + 摘要),
  按 sessionId+path+line 记忆化,不预取整文件、滚动不重复请求;
- 行映射复用既有 useGitStatus 共享 store 与既有统一 diff 引擎
  (parseUnifiedDiff/unifiedSegments),不新增第二个 git status 轮询器;
  未跟踪文件按状态 store 整篇标新增;
- 新增宿主路由 git.diff-head(git diff HEAD,部分暂存时给出已暂存+未暂存
  的整份未提交变更,未出生 HEAD 回退 --cached)与 git.blame
  (git blame --porcelain -L,四条失败路径一律返回空,不抛);
- 只给 viewerId === 'code' 挂 decoration/gutter/tooltip,markdown/html 与
  关闭设置后不安装任何扩展;开关经 Compartment 原地重配。

不做行尾常驻作者 widget、不做徽章、不做动画、不做渐变、不做四个独立开关。
2026-10-05 22:25:51 +08:00
Menghuan1918 99eb9190e0 feat(git-lens): 变更行数统计(numstat 随既有 status 一次取回,分组头合计 + 文件行增删,未跟踪显示新文件)(#131) 2026-10-05 22:19:26 +08:00
ymac 31e5a78e40 Merge remote-tracking branch 'origin/dev' into fix/git-dubious-ownership
# Conflicts:
#	src/git.ts
2026-10-05 09:45:16 +08:00
Menghuan1918andAhdong&Shouey 7cf3d609ff feat(changes): AI commit-message suggestion + push/pull in the git lens
Port PR #434's two Git-panel features onto the current dev structure. The
PR's third commit (file-tree context-menu rename) is dropped: dev already
has it (#550, e39ea92) with a different `fs.rename` payload contract
(`name`, not `newName`) and its own i18n keys, so keeping it would break the
route and duplicate dictionary keys (TS1117).

Why this is a rewrite rather than the PR's diff applied:

- The client carrier moved. `src/client/GitView.tsx` was deleted by 24a3813
  (the unified "changes" tab), so the client half lands in
  `src/client/changes/GitLens.tsx` and follows that file's conventions: the
  bar's single `actionError` status line instead of a second `remoteError`
  channel, `runAction` for the git mutations, the kit's `IconButton`, and the
  host's own `IconSparkleRegular` rather than a new react-icons import.
- The host route could not read `Session.events` at all: it was renamed to
  `snapshotEvents()` in DSH 0.1.2-alpha.4, and 0.2.0-rc.1 marks it `new calls
  are prohibited`. `git.suggest-message` resolves its provider/model from the
  incrementally folded `Session.requestHeader()` — the same `request/header`
  record the PR was after, but O(new events) instead of a full reverse scan.
  `SidebarSessionStore` gains that face; `snapshotEvents()` is marked
  deprecated there.
- Message source is the plugin's own producer kind
  (`plugin:dsh-better-sidebar`, the existing `MessageSourceMap` augmentation):
  a bare `plugin` kind is rejected outright in session format v4.
- The commit row stays where dev put it. PR moved it to the top of the panel
  because it was buried between the two file lists; dev's commit bar is
  already a `position: sticky` footer, so that problem is gone — and
  `changes-tab.spec.tsx` pins the bar's status line to the message row.

Beyond the port, the route reads `assembler.finish` so a provider-side failure
is reported with the provider's own reason instead of "the model returned an
empty message", bounds the call with a 30s deadline, and truncates the diff at
12K characters.

Refs #434

Co-authored-by: Ahdong&Shouey <131278957+LiuStar656@users.noreply.github.com>
2026-10-05 02:11:10 +08:00
Menghuan1918 a96b99c565 feat(changes): AI commit-message suggestion + push/pull in the git lens
Port PR #434's two Git-panel features onto the current dev structure. The
PR's third commit (file-tree context-menu rename) is dropped: dev already
has it (#550, e39ea92) with a different `fs.rename` payload contract
(`name`, not `newName`) and its own i18n keys, so keeping it would break the
route and duplicate dictionary keys (TS1117).

Why this is a rewrite rather than the PR's diff applied:

- The client carrier moved. `src/client/GitView.tsx` was deleted by 24a3813
  (the unified "changes" tab), so the client half lands in
  `src/client/changes/GitLens.tsx` and follows that file's conventions: the
  bar's single `actionError` status line instead of a second `remoteError`
  channel, `runAction` for the git mutations, the kit's `IconButton`, and the
  host's own `IconSparkleRegular` rather than a new react-icons import.
- The host route could not read `Session.events` at all: it was renamed to
  `snapshotEvents()` in DSH 0.1.2-alpha.4, and 0.2.0-rc.1 marks it `new calls
  are prohibited`. `git.suggest-message` resolves its provider/model from the
  incrementally folded `Session.requestHeader()` — the same `request/header`
  record the PR was after, but O(new events) instead of a full reverse scan.
  `SidebarSessionStore` gains that face; `snapshotEvents()` is marked
  deprecated there.
- Message source is the plugin's own producer kind
  (`plugin:dsh-better-sidebar`, the existing `MessageSourceMap` augmentation):
  a bare `plugin` kind is rejected outright in session format v4.
- The commit row stays where dev put it. PR moved it to the top of the panel
  because it was buried between the two file lists; dev's commit bar is
  already a `position: sticky` footer, so that problem is gone — and
  `changes-tab.spec.tsx` pins the bar's status line to the message row.

Beyond the port, the route reads `assembler.finish` so a provider-side failure
is reported with the provider's own reason instead of "the model returned an
empty message", bounds the call with a 30s deadline, and truncates the diff at
12K characters.

Refs #434
2026-10-05 02:11:10 +08:00
Menghuan1918 c5d8b13aa7 merge #802 into dev(文件树跟随活动 worktree,按 dev 原位解冲突)
三处冲突都是 main/dev 侧后插入行与变量改名造成的上下文漂移,被改的目标代码在
dev 上逐字仍在,按 dev 原位解(不是回退到 PR 的旧上下文):

- src/index.ts 导入区:保留 dev 新增的 FS_TREES_MAX_PATHS 导入与注释,同时加
  activeWorktreeRootOf 导入——两边都要;
- src/index.ts /sidebar/file 路由:保留 dev 的路径解析注释(dev 里本来就重复了
  一份,本次不顺手清理,避免把无关改动混进合并),cwd 改走 activeWorktreeRootOf;
- src/client/Sidebar.tsx:删掉 summaryCwd(改由 useSessionRoot 提供根),保留
  dev 插入的「空白会话」注释;
- src/client/native/tab-adapter.tsx:保留 dev 的 seat/scope 双会话命名与注释,
  useSessionCwd(ctx, scopeSessionId) → useSessionRoot(ctx, scopeSessionId)。

落地方另修三处(PR 自带 spec 在本机 macOS 上红,逐条有实测证据):

1. src/active-worktree.ts 的 normalizeActivePath 把分隔符一律折成反斜杠,POSIX
   路径随即不再 isAbsolute 而被 addActivePath 丢弃——该特性在 Linux/macOS 上
   静默空转(只在 Windows 上有效)。改为折成平台分隔符 sep;Windows 上 sep 就是
   反斜杠,行为不变。
2. active-worktree.ts 的根缓存改到 git 探测之前查询,并缓存「不在仓库里」这一
   结果:探测是一次真实 spawn(实测 ~6.5ms/次),此前每个 watch 帧、每个路由
   调用都要付一遍。dev 的 tests/zip.spec.ts「第 5 个并发构建被拒」正因此从 5/5
   绿变成 5/5 红(A/B:只回退 cwdOf 包装即恢复绿),本改动后该用例恢复 5/5 绿。
3. tests/active-worktree.spec.ts 的期望值改用 realpathSync.native:根来自
   `git rev-parse --show-toplevel`,本就是规范化路径,macOS 的 /var →
   /private/var 会让 resolve() 断言恒红(与 tests/git-worktree.spec.ts 同款写法)。

Refs #802
2026-10-05 01:35:58 +08:00
unsc9 9c248d0933 fix(git): checkout 的分支名不再被当成选项(补 4100e16 漏掉的那处)
`git.checkout` 把调用方给的分支名当裸操作数拼进 argv,所以 `-f` 被 git 的选项解析器吃掉,直接强制覆盖工作区并丢弃未保存的改动(`--work-tree=…` 则重定向 checkout)。同批加固 4100e16 给 show / commitDiff / revert / cherryPick 四个兄弟调用都加了 `--end-of-options`,只漏了这一处。

实测(真实 git,临时仓库):加哨兵前 `checkout -f` 退出码 0 且未保存改动被覆盖;加哨兵后 `-f` 与 `--work-tree=…` 均被拒且改动保留,正常分支名照常切换。

回归用例:tests/git.spec.ts「never lets a branch operand reach git as an option (checkout)」。
2026-10-04 21:47:17 +08:00
ymac c0b66e11b1 fix(git): answer the dubious-ownership guard per command (#690) 2026-10-01 22:00:36 +08:00
HuanLinOTO a5c3befc57 Merge PR #664: fix(diff): 二进制/纯重命名/仅改模式的文件行补回路径,并关掉 git 路径 C 转义 2026-10-01 17:18:09 +08:00
张虎 3bc8b4675a feat(sidebar): 文件树跟随会话实际所在的 git worktree(含跨仓库 linked worktree) 2026-09-29 14:40:03 +08:00
6699ll 4100e16c73 fix(security): stop git operands parsing as options, and harden the API dispatch
Three small hardening fixes on the host half, all in the same request path.

1) git revisions were spliced into argv as bare operands, so a value beginning
   with `-` was consumed by git's OPTION parser instead of being treated as a
   revision. `git.show` with rev `--stat` (or `--output=…`) returned empty
   instead of failing, which silently blanked the Changes tab's diff/blame
   panes; `git.commit-diff`/`revert`/`cherry-pick` took the same shape. Adding
   `--end-of-options` before the operand ends option parsing.

   Chosen over a regex allowlist on purpose: the UI legitimately sends `:0`
   (git's index selector, used for the worktree side of a diff) and `<hash>^`,
   and users have branch names this code cannot enumerate. A whitelist would
   have to keep growing and would still reject valid refs; the sentinel is
   exact and needs no enumeration.

2) `GitCommandError` had no branch in `writeError`, so every ordinary git
   failure — unknown ref, path outside the repository, not a repository —
   surfaced as 500 `internal`. That reads as a plugin crash and meant the
   `not-repo` code (already defined in git.ts) and its localized copy were
   unreachable from every route. Non-repository now answers 409 `not-repo`;
   other git failures answer 400 `git-error`.

3) the `/sidebar/api` dispatch table is an object literal, so a bare lookup
   resolved `Object.prototype` members as handlers:

     POST /sidebar/api/constructor     -> 200 {}
     POST /sidebar/api/toString        -> 200 "[object Undefined]"
     POST /sidebar/api/valueOf         -> 500 internal
     POST /sidebar/api/hasOwnProperty  -> 500 internal

   Switched to `Object.hasOwn` plus a `typeof === 'function'` guard, so every
   one of those is the documented 404.

Verified:
- `tests/smoke.spec.ts` gains four cases. Three are red on the pre-change
  source (operand guard: `show(dir,'--stat',…)` returned content instead of
  null; dispatch: `constructor` answered 200; git status: 500 instead of 409)
  and green after.
- the fourth pins the `:0` index selector as a NON-regression, so a future
  tightening of the operand handling cannot silently break the diff UI.
- the repo's own `harden` regression is covered: `git.revert(dir, '--abort')`
  and `cherryPick(dir, '--abort')` now reject rather than being honoured.
- empirically re-verified against git 2.53.0 that every legitimate revision
  form still resolves (`HEAD`, `:0`, `<hash>`, `<hash>^`, `HEAD~1`) while
  `--stat` / `--output=nul` / `-n` are refused.
- the wire.ts -> git.ts import introduces no cycle (git.ts imports only node
  builtins) and both bundles build clean; typecheck / lint / build /
  check:consumer-types clean.
- `pnpm test:windows` 1351 passed, 4 failed — byte-identical to the clean-main
  baseline for those two files (pre-existing Windows environment failures).
2026-09-22 03:12:00 +08:00
ymac e4b189b7b5 fix(diff): name the rows git sends without ---/+++
git emits no ---/+++ for a binary file, a pure rename and a mode-only
change, and parseUnifiedDiff only ever read paths from those two lines.
The section therefore kept oldPath/newPath === '', so DiffFiles drew a
header carrying just the binary badge and no file name (sandwiched
between two .md rows, which is exactly how it reads as if those .md files
were the binary ones), and a pure rename / mode-only change collapsed to
an empty disabled button (no path, and fileTag cannot see a rename).

Recover the paths in order of authority: ---/+++ when present, else the
section's own `rename from|to`, `Binary files A and B differ`, or the
`diff --git` header. Only the mode-only shape needs the last one: it takes
the ` b/` whose two sides name the same file, and leaves the path empty
rather than guessing. ---/+++ values also lose the TAB git appends to a
spaced path, and decodeGitPath undoes git's C-quoting so diff text from a
default-quotePath source still renders the real file name.

runGit gains `-c core.quotePath=false` for the same reason at the source:
git's default turns a space/CJK path into an octal-escaped quoted string,
which every diff surface then renders as the file name. The `-z`-framed
porcelain callers are unaffected (git never quotes NUL-framed output).

Verified against taktop_redo 8b4b933, the commit whose three .jpg rows
rendered as bare badges: all three now carry their full path, and real git
output for space/CJK paths parses with no escapes and no trailing TAB.
New tests: tests/diff-binary-row.spec.tsx (rendered rows) and the path
matrix in tests/diff-rows.spec.ts; tests/git-spawn.spec.ts now derives the
subcommand from runGit's prefix instead of counting its flags.

tests/git.spec.ts had pinned the empty path (`oldPath === ''`) as the known
behaviour of a mode/rename-only section; it now asserts the recovered paths
instead, and the binary section there asserts its own name too.
2026-09-14 00:08:38 +08:00
Kunping Wang 5d8c33832c fix(git): 兼容旧版 Git 的 worktree 列表 2026-08-29 15:31:08 +08:00
Menghuan1918 eed40bb11a fix(git): raise the discovery probe timeout to 5s (#369)
3s was tight for cold caches on large home directories; 5s still bounds a
stalled mount well below the 30s command budget while cutting false
negatives on slow-but-healthy checkouts.
2026-08-25 11:15:16 +08:00
Menghuan1918 2cbcba8d11 fix(git): bound status payload and repo discovery; add reset escape hatch (#369)
Opening the source-control panel could freeze the whole sidebar, and the
frozen layout restored itself after every reload, leaving no way out
(issue #369). Three unbounded layers compounded:

- `git status --porcelain -z --untracked-files=all` shipped every row of a
  pathological untracked set into one response; the browser main thread
  froze on response.json() plus the unvirtualized change list, and the 2s
  poll replayed the freeze. status() now caps entries at 2000 and reports
  `truncated` (the panel shows a notice, mirroring fs.read's truncation
  semantics); worktree change counts inherit the bound for free.
- repoRoots() probed every visible child directory of a non-repo cwd
  (e.g. ~) serially, once per git.* call, each with the full 30s command
  budget. Discovery now uses a 3s probe timeout, caps probes at 200
  directories, and shares one in-flight scan plus a 60s TTL cache per cwd.
- A hung layout persisted `panelOpen: true` with the git tab active, so a
  reload remounted straight back into the freeze with no escape hatch.
  Loading with `?dsh-sidebar-reset` now drops the persisted layout (and
  the shared width) and starts from the default.

statusTruncated copy synced across all 19 shipped dictionaries.
2026-08-25 11:04:43 +08:00
HuanLinOTO 751fb954a2 fix: address Copilot review (9 comments)
#1 GitView: hide/disable 'open in editor' for external linked worktrees
   (path outside session workspace is rejected by the fence); add
   isWithinWorkspace client helper for the gate.
#2 DiffTab: untracked diff read resolves against diff.repoRoot (child-repo
   paths are repo-root-relative, not cwd-relative); fs.read route threads
   selectedRepoOf into resolveGitPath so the host resolves the right base.
#3 GitView: chooseRepo handler mirrors chooseWorktree — clears status/
   history/log and bumps generation before async refresh, preventing stale
   rows from acting on the newly selected repository.
#4 git.ts: repoRoots/repoRoot compare roots via pathIdentity() (platform-
   aware) instead of raw includes(), fixing win32 forward/backslash
   mismatch that silently fell back to roots[0].
#5 markdown-images: mask fenced code blocks and inline code spans before
   rewriting; only rewrite reference definitions whose label is actually
   referenced by image syntax (not plain links). +3 tests.
#6 package.json: downgrade unrun ^0.3.1 → ^0.2.39 (0.3.x requires Node
   ^22.13, incompatible with declared engines >=20).
#7 market-manifest.spec: shell:true on win32 so execFileSync resolves the
   pnpm .cmd shim.
#8 smoke.spec: build html-route URL via encodeHtmlUrl() (production
   encoder) so the Windows drive separator is correct.
#9 index.ts git.worktrees route: thread selectedRepoOf so a workspace
   container's selected child repo's linked worktrees appear.
2026-08-23 22:02:47 +08:00
HuanLinOTO d63de6f815 merge #326: support selecting child git repositories
# Conflicts:
#	src/client/GitView.tsx
#	src/client/state.ts
#	src/index.ts
2026-08-23 20:25:52 +08:00
HuanLinOTOandxxxg0001 5c88279d7a merge #285: forward-port linked worktrees to RC8
Co-authored-by: xxxg0001 <xxxg0001@users.noreply.github.com>
2026-08-23 20:17:14 +08:00
lx 57a4ad82e1 merge main into fix/multi-repository-git-selector 2026-08-23 02:50:34 +08:00
Xinchen Lee 71c5413e5c fix(git): hide spawned git windows on Windows (#301) 2026-08-22 23:11:27 +08:00
SKXandMenghuan1918 e867e27106 fix(git): 切换未跟踪文件显示模式以支持新文件夹内文件差异 (#242)
* fix(git): 切换未跟踪文件显示模式以支持新文件夹内文件差异
当使用 `git status --untracked-files=normal` 时,新文件夹会被折叠为单条 `?? dir/` 条目,点击后因无法读取目录(`fs.read` 报错 "is a directory")而无法加载差异。切换至 `--untracked-files=all` 使新文件夹下的每个文件独立显示为一行,并可正常查看差异,与 VSCode 默认行为一致。同时添加回归测试以验证 porcelain 输出格式。

* test(git): 补真实 git 集成测试钉住 status() 的 --untracked-files=all(review feedback)

---------

Co-authored-by: Menghuan1918 <menghuan2003@outlook.com>
2026-08-22 23:09:58 +08:00
lx 78de79c9d6 fix: support selecting child git repositories 2026-08-22 18:13:50 +08:00
dsh-better-sidebar-fix 04374b23e4 fix(git): keep worktree views transactionally consistent 2026-08-21 00:45:24 +08:00
dsh-better-sidebar-fix 6d6d582996 fix(git): show changes across linked worktrees
The Git panel only ran git status against the session's own worktree,
so when DSH (or any coding agent) created a linked worktree via
'git worktree add' and modified files there, the sidebar's Git panel
stayed empty - no changed files, no diff, nothing to commit.

Enumerate all linked checkouts of the session repository and let the
user select which one the panel targets. Auto-select the dirty linked
worktree when the primary checkout is clean and exactly one linked
worktree has changes (the common DSH agent pattern). Poll status every
2s while the panel is visible so model-authored edits appear without
a manual refresh.

Security: resolveWorktree validates the client-supplied worktree path
against 'git worktree list' before using it as a git -C cwd. Uses -z
porcelain framing, which disables core.quotePath C-style quoting so
non-ASCII checkout paths round-trip losslessly.
2026-08-21 00:45:24 +08:00
Menghuan1918 069c754877 feat: Git 面板真正的 diff 显示 + VSCode 式历史与右键高级操作,v0.3.0
- 真正的统一 diff 显示:hunk 头 + 双行号 + 红绿着色,长行换行无横向滚动,untracked 全新增视图
- 点击变更/历史自动打开独立 diff tab(首次在下半栏新增分栏,同变更去重聚焦,临时页签刷新不恢复)
- 历史行:分支徽章 + 作者/相对时间,懒加载分页(20 条/页 + 加载更多)
- 右键菜单:文件行(打开/暂存/放弃更改/复制路径)、历史行(复制哈希/信息/还原/捡取),破坏性操作确认弹窗
- 修复暂存/未暂存分类错误(' M' 被误标为已暂存导致 diff 恒空)
- 修复 git 相对路径解析(会话在仓库子目录时 diff/discard/show/read 可用)
- host 新增 git.commit-diff / git.discard / git.revert / git.cherry-pick 路由与 log 分页
2026-08-10 22:29:24 +08:00
Menghuan1918 63e2988ef1 dsh-better-sidebar: VSCode-like right sidebar plugin for the DSH web GUI
Host half (src/index.ts): /sidebar/api JSON API (session cwd, fs tree/read/
write, git status/diff/stage/commit/branch/log/show), /sidebar/file media
route, /sidebar/ws/terminal WebSocket over node-pty; routes share the /api
trust fence (Host-header loopback or connection.trustedHosts).

Client half (src/client): portal-mounted right panel with a per-session
split-pane workbench (recursive row/col splits, draggable dividers, tab
drag-move), tab bar with max-width 160px + plus-menu (explorer/git/terminal
multi-open rules), lazy file explorer rooted at the session cwd, editable
text editor (dirty dot, Ctrl/Cmd+S), image + Markdown preview, xterm
terminal with reconnect, and a VSCode-style git panel. Per-session state
persists to localStorage (dsh-sidebar:v1:<sessionId>). Intercepts the chat
turn-tail produced-files row (priority -1 chain entry) to open files in the
sidebar. UI styled with the dsh --dsw-* theme tokens and ui-primitives.

Build: tsdown emits the host lib plus the __ModuleLoader__ client bundle
(externals = module table words; xterm/css inlined). Tests: 19 unit + smoke
specs (pure state/tree/git parsers + real git/fs integration).
2026-08-08 01:02:24 +08:00