Commit Graph
15 Commits
Author SHA1 Message Date
Menghuan1918 2237f3787b perf(diff): parse a patch once and cap the default expansion 2026-10-24 02:17:10 +08:00
Atlas Zeng 23598d1f51 Merge pull request #910 from UNscientific-9/fix/diff-hunk-header-guard
fix(diff): 改动块内的 `---`/`+++` 不再当文件头,删掉 `-- …` 行不再截断 diff
2026-10-12 01:21:16 +08:00
Menghuan1918 d4ca9eb6fb feat(transfer): 流式传输与原生打包,JSONL 预览/编辑与大文件分页预览
宿主半:
- /sidebar/file 与 /sidebar/html 改为 createReadStream + pipeline(新增
  file-stream.ts),删除 mediaLimit;流开始后失败由 writeJson 的
  headersSent 守卫降级为 destroy,不再抛 ERR_HTTP_HEADERS_SENT
- 上传本就是流式的,只删掉客户端 MAX_UPLOAD_BYTES 预检与宿主 limit 逐块检查
- 删除 readLimit / mediaLimit / uploadLimit 三个配置键,新增共享常量模块
  editor-limits.ts(MAX_EDITABLE_BYTES = 5 MiB、PAGE_BYTES、写入体护栏)
- fs.read 重塑为 text | binary | too-large 三态,不再有「截断文本」这个
  既不可信又不可保存的中间态;新增 fs.readPage 字节窗口分页(按行对齐、
  按 path+size+mtime 缓存首次探测到的编码)
- 删除 JSON 版 fs.write,改为 /sidebar/write raw 路由(文档即请求体),
  拆掉 MAX_BODY_BYTES=1MiB 这道保存墙;编码与行尾还原逻辑原样搬到
  fs-operations.writeWorkspaceText
- 打包改原生命令:新增 archive-tools.ts(zip → tar 探测、公共祖先定位、
  argv 规划、stdio 重定向),archive-route 改为后台写临时文件 + 流式下发,
  删除手写 ZIP writer src/zip.ts;新增 unavailable 错误码

客户端半:
- 新增 text-pages.ts(字节偏移分页游标,显式翻页)、jsonl.ts(逐行记录
  解析与摘要)、lang-jsonl.ts(每行独立的 JSON tokenizer,替代会为每条记录
  产生错误节点的 json() 语法)、LargeFileView.tsx(记录卡片 / 日志行两种
  只读分页视图)
- 新增 jsonl viewer 描述符(预览 = 记录列表,编辑 = 可保存的 CodeMirror)
- FileViewerProps 用 size/largeFile 取代 truncated;超限文件改为只读分页
  预览并可下载,不再提供编辑器
- tags.invalid 由纯白改为红色波浪线(浅色主题下原本白底白字不可见)
- zip 下载改回普通 <a download> 直链,不再把整包放进浏览器内存
2026-10-11 22:25:25 +08:00
unsc9 9f1724e3df fix(diff): 改动块内的 ---/+++ 不再当文件头,删掉 -- … 行不再截断 diff
删除行的 diff 原文是 `-` 加源码原文,所以删掉一行以「`-- `」(两个减号加
一个空格)开头的内容——SQL / Lua / Haskell 注释、文档或脚本里的命令行参数
行——会产出 `--- foo`,与文件头分隔行 `--- a/路径` 逐字节同形。解析器把
「在 hunk 内」那道闸门排在 `---`/`+++` 两个分支之后,等于没保护它们:命中
后当前 hunk 当场被截断(该行之后没有 `@@` 可重新同步时,剩下的改动整段不
显示),并把被删文本盖到 oldPath 上。新增行原文以 `++ ` 开头(C 的
`++ i;`)同理会把 newPath 改成 `i;` 并丢掉那一行。

git 从不在 hunk 内写 `---`/`+++`,所以判据是「在不在 hunk 内」:两个分支
各加 !inHunk 守卫(等价于把它们挪到那道闸门之后)。

实测(同一份 fixture,修复前 → 修复后,直接跑真实 parseUnifiedDiff):

  删掉 `-- foo`:oldPath `"foo"` → `"a/sample.txt"`;hunk 1 行 → 3 行
  新增 `++ i;`:newPath `"i;"` → `"b/loop.c"`;新增行丢失 → 保留
  统计与 `git diff --numstat` 一致(0/1 与 1/0)

用例:`tests/diff-rows.spec.ts` 新增一组 3 例(删除行、新增行,以及 hunk
之后的真文件头仍要认得——守护这道守卫别把正常头也挡掉)。
2026-10-10 20:34:23 +08:00
Menghuan1918 4a03e131e5 fix(diff): 会话镜头 diff 的超大输入退化为全删全增,不再建稠密 LCS 表(#734)
rows.ts 的 lcsTable 是无护栏的稠密普通数组矩阵(每单元约 8 字节),成本
完全由输入行数乘积决定。实测:1000×1000 → 8MB、3000×3000 → 71MB、
5000×5000 → 193MB、10000×10000 → heapDelta 765MB(峰值 RSS 865MB)。
会话镜头把上一次 write 的完整文件内容当 prior 传进 diffOf(ops.ts 对
content 无字节/行数截断),选中一个 op 就在 useMemo 里同步跑完,因此一份
万行文件的改动预览会一次性吃掉数百 MB 主线程内存。

护栏落在 diffLines 内部、lcsTable 调用之前(它是会话镜头唯一的 LCS 入口,
一处覆盖 diffOf 的三个分支):新增导出常量 MAX_LCS_CELLS = 4_000_000
(≈32MB,仍精确覆盖 2000×2000 的重写配对),判定
oldLines.length * newLines.length;超限不建表,直接产出全删(oldLines
顺序,oldLine 1..n)+ 全增(newLines 顺序,newLine 1..m)。

退化路径同时跳过 pairMods:在没有找到任何对齐的情况下,del 段与 add 段
会被成对标成 mod,那不是「已判定为改写」。所以退化语义是无 context、无
mod,只有 del/add。10000×10000(中间改一行制造错位)实测 0.44–0.96ms,
原实现为 592ms/765MB;渲染侧既有 MAX_ROWS = 600 截断,无需新增提示文案。

测试新增规模用例(20000 行、kind 全为 del/add、两侧行号严格递增
1..10000、单次耗时 < 2000ms,阈值按慢 CI 放宽)与边界用例(恰好
MAX_LCS_CELLS 时仍走表路径)。

Refs #734
2026-10-05 01:29:00 +08:00
HuanLinOTO a5c3befc57 Merge PR #664: fix(diff): 二进制/纯重命名/仅改模式的文件行补回路径,并关掉 git 路径 C 转义 2026-10-01 17:18:09 +08:00
HuanLinOTO 65eb0957fb Merge PR #665: fix(diff): 头部 +n/−m 改为 git 口径,一处改写不再两侧各计一次 2026-10-01 17:18:09 +08:00
Menghuan1918 36fbc5ac7e feat(sidebar): 文件页与文件变动页 UIUX 重构 + 全局组件抽取
文件页(FileTree/TreePanel)
- Ctrl/Cmd 多选 + Shift 按可见行序连选(Esc/点空白/右键收敛),批量条支持复制路径、批量删除(共享 ConfirmDialog + 顺序 fsRemove)
- Git 变更着色:行名按状态上色 + M/A/D/U 徽标,目录按 dirHasChanges 着色,非仓库静默降级(数据来自共享 git 状态存储)
- 新建文件夹:fs.mkdir 路由 + mkdirWorkspaceEntry + 内联输入行(Enter/Esc/blur/IME 守卫)
- 性能:FileRow/DirRow memo(含反向验证)、搜索 hidden 停车不再卸载树、level 拉取世代守卫 + AbortController、fs.tree truncated 提示、use-dir-watch 入参 memo
- 拖拽上传视觉 token 化(硬编码色清零);可见性下传后隐藏页签停止轮询
- 右键「打开方式」改为复用 DSH 自带 open-in-app(宿主探测的关联应用 + 文件管理器显示)

文件变动页(changes/diff)
- 36px 头(宿主 SegmentedControl)+ 单一 ChangeRow + SectionHeader 分组 + 吸底提交条单状态行 + 历史独立空态
- 修掉:双份空态、暂存失败 unhandled rejection、手动刷新被丢、仓库切换刷新两次、worktree 清单缺 repoRoot、工作树被自动切走、预览持旧快照、恢复高度未 clamp、session ops 无谓轮询
- DiffPane/DiffTab 共用 use-git-diff;修掉 DiffPane 的 untracked 预览从不渲染

全局组件与宿主接入
- 新增 src/client/ui(IconButton/Chip/SectionHeader/Notice/ConfirmDialog/StatusBadge + 共享 git 状态存储)
- 新增 src/client/open-in-app.ts(宿主 open-in-app 客户端适配),删除自研 open-with 全链路与 open.external 路由
- 客户端 inject 补 remote / remote.session:缺声明时 ctx.get('remote').session 会抛出并把整个面板打成错误条(真实挂载 lane 抓到)
- 词典:+25 键 / -20 openWith* / -noChanges,20 份同步

验证:typecheck / lint / test(126 文件 1322 通过)/ build 全绿;
DSH_CMD='npx -y --package @deepseek-ai/dsh@0.1.7-rc.1 dsh' pnpm test:mount 7/7 通过(含 tab sweep 与 perf lane)
2026-09-28 00:27:31 +08:00
ymac 43a209939c fix(diff): count a rewritten line once in the +n/-m chips
diffStats counted ROWS, treating every `mod` row as both an insertion and
a deletion — but pairMods turns one rewritten line into two `mod` rows
(one per side), so a single-line rewrite reported +2 -2. Neither reference
agrees with that: `git diff --numstat` says 1/1, and the renderer draws
exactly one `-old` plus one `+new` line for it.

Count sides instead: an `add` row, or the new side of a `mod` row, is one
insertion; a `del` row, or the old side, is one deletion. On the commit
that surfaced this (taktop_redo 8b4b933) the changes-tab header read
+3300 -2 while `git show --shortstat` printed "3299 insertions(+),
1 deletion(-)"; it now reads +3299 -1, and CURRENT_STATUS.md's chip reads
+8 -1 against numstat's `8 1`. The session-op lane (the same function over
diffLines rows) moves to the same accounting.

tests/diff-rows.spec.ts replaces the "mods on both sides" expectation
(5/4 -> 3/2 for the same fixture) and adds a single-line-rewrite case plus
a session-op case.
2026-09-14 00:11:40 +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
haruhi d990c10e59 feat(diff): 折叠行异步展开状态机与内容切片
- src/client/api.ts: 仿 gitCommitDiff 新增 gitShow 封装,走既有 git.show 服务路由(payload {rev, path},返回 content 或 null),服务端零改动
- src/client/diff/rows.ts: 新增 foldRowsFromContents 纯函数——old 侧按 fold 行号切片为 context 行(new 侧经区间偏移映射,落界才带行号),new 侧补纯增行;越界截断、\r 保留
- src/client/diff/DiffRows.tsx: 新增 resolveFold prop;foldData/foldLoading/foldFailed 三态,加载中不可点,失败降级静态标记;foldEpoch 使 segments 重置后 in-flight 回调失效
- src/client/diff/DiffFiles.tsx: resolveFold 下传各文件 DiffRows,fold 级 Promise 缓存去重并发点击与重挂载
- tests/diff-rows.spec.ts: foldRowsFromContents 六用例(对称/纯删/纯增/\r\n/空内容/越界)

背景:git -U3 不输出 hunk 间未改动行,gap fold 只有行号范围没有 rows,渲染复用「点击展开」文案却无交互;展开能力建为独立状态机(含 api 封装),git lens 只需注入取数 loader。
设计 docs/plans/2026-09-07-git-fold-expand-design.md §4.1-4.4。
2026-09-07 23:51:06 +08:00
Menghuan1918 157e02e768 refactor(changes): dedup the op-preview path and align conventions
- redaction useMemo: one redactText pass per field (the outcome carries
  both text and hit; was a hit-scan plus a mask pass), and the banner
  condition drops the redundant redactionOn check (hit implies on)
- three copy-pasted header toggles -> PaneToggle; the md reading body
  -> MdReadingView (absorbing the mermaid branch + codeLabels)
- redaction preference persisted under the repo's dsh-sidebar:v1: prefix
- render toggle limited to .html/.htm (the editor html viewer's ext set;
  .xhtml went beyond any claim)
- tsx/jsx share TS_WORDS/JS_WORDS; CSS word list loses its duplicate
  entries and its nonexistent true/false constants
- parseReadContent/parseReadLines share the contentLines() envelope core
  (content extraction + Showing-lines filter)
2026-09-06 23:46:46 +08:00
lhh010 0142ac550b feat(diff): expand syntax highlighting — mjs/cjs/mts/cts, CSS/SCSS/Less, HTML/XML/SVG/Vue, GraphQL, JSONC/JSON5
Ports dsh-file-trace v0.2.1 highlight coverage into the shared diff engine: JS/TS module suffixes share the js/ts keyword lists; CSS gains its own config (slash-star block comments threaded across lines, hyphenated property words via a wider word charset, 120+ properties/selectors/at-rules); markup files gain markup comments plus common tags/attributes; GraphQL and JSONC/JSON5 map in. Previously css/scss/less had a wrong hash-comment config and html was plain CONFIG_LANG, so both effectively rendered uncolored.
2026-09-01 23:05:26 +08:00
Menghuan1918 f024fbf092 fix(changes): 会话事件改走宿主 changes.ops 路由 + diff 展开二级设置 + 视觉迭代
CI 修复(plugin-mount 的 ctx.sessions.get TypeError ×1003):
- 客户端 runtime 无事件日志面——badge/SessionLens 原在客户端直读
  ctx.sessions.get(id).events / ctx.on('session/event'),全部不可达。
- 新增宿主路由 changes.ops:live 会话日志优先,冷会话回放
  sessionPersistence.inspect;afterSeq 增量(缺省游标含 seq 0,
  显式游标为 seq > afterSeq,同 sidechat.events 约定),窗口上限
  4000 与客户端累加器一致。
- ChangesTab 轮询(mount 一拉 + visible 2.5s 增量)折入 ops,写
  模块级 opCounts 缓存供 badge 同步读取;SessionLens 改纯展示。

diff 展开二级设置(changesDiffFloat,默认浮窗):
- prefs 四处接线 + git tab settings select(浮窗/面板,图标选项卡)
- 预览面板「展开为 diff tab」按设置落点:浮窗居中弹出或源 pane
  下方 split;i18n 全 21 词典同步。

视觉迭代(真机挂载截图审查后调整):
- Session 视角:kind 徽章为左轨,大小+相对时间右对齐元列;失败
  操作行红色内嵌条;文件组头降为三级标签并加组间距。
- Git 视角:untracked '?' 徽章与新增同绿色;stage 按钮改 plus 图标。
- diff 折叠行:可展开折叠带 › 箭头 + 次级对比度,静态 gap 不再
  显示 pointer/hover;预览头路径改尾部截断(RTL 技巧,保文件名)。

验证:typecheck ✓ / vitest 1123 ✓ / pnpm test:mount(钉 alpha.2 CLI)
14/14 ✓;真机挂载截图(badge=5、双视角、浮窗展开)0 console error。
2026-08-31 17:52:59 +08:00
Menghuan1918 24a3813c63 feat!: 合并 Git 面板与文件追踪为统一「文件变动」tab(双视角 + 统一 diff 栈)
在 PR #471(file-trace)基础上的演进:

- 合并 tab:git tab(id 保留,兼容持久化布局)升级为「文件变动」双视角
  tab——Git 视角(原 GitView 全部能力:staged/unstaged/提交/历史/worktree·
  子仓库选择/右键菜单/确认弹窗)+ 本轮文件视角(原 file-trace:会话事件
  日志实时折叠的模型读写编辑记录,按文件分组、新增类型筛选 chips、相对
  时间);file-trace tab 移除(未随任何版本发布)。
- 统一 diff 组件:新 src/client/diff/ 模块(rows.ts 引擎 + DiffRows/
  DiffFiles 渲染器 + highlight.ts 语法着色)——git diff 与会话操作 diff
  共用一套渲染:mod 改写配对(del-run/add-run 对半标蓝)、行内字符级
  高亮(修复了旧实现旧侧失配不高亮的问题,改为行对象身份键)、上下文
  hunk 折叠、git hunk 间未输出区间按行号范围生成不可展开折叠、语法着色
  色相落位 diff 三色空档、+n −m 统计 chips、行底色 tint;DiffTab 改用
  该栈(git diff tab 从此也有高亮)。
- 交互:两视角共用底部可拖拽预览面板(点击文件/提交/操作即预览,不再
  直接开 diff tab;面板可刷新、可键盘/拖拽调高、git 目标可一键展开为
  独立 diff tab);视角选择与面板高度持久化在 tab.meta;git 行 XY 徽章
  按状态字母着色;选中行高亮。
- i18n:fileTrace* 十键重命名为 changes* 前缀,git 键值更新为「文件
  变动」,新增 7 键(视角/筛选/面板操作),全部 21 个词典同步。
- 结构:src/client/changes/(ChangesTab/GitLens/SessionLens/DiffPane/
  ops)+ src/client/diff/;GitView/DiffView/filetrace/ 删除;git 样式
  从 sidebar.module.css 迁至 changes.module.css。
- 测试:builtins 8→7(git tab 承接 badge pin)、diff-rows(unified
  转换/mod 配对/间隙折叠/统计)、changes-tab(壳交互 jsdom)、
  diff-files-collapse(原 DiffView 折叠行为钉住)、changes-ops(原
  filetrace 数据层)、git-view-worktree 迁移至 GitLens;全量 1122 通过。
- 文档:README ×2 功能矩阵合并、external-plugin-guide §4.4 与内置清单
  7 tab、mount e2e 菜单标题同步。
2026-08-31 01:31:22 +08:00