Commit Graph
23 Commits
Author SHA1 Message Date
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
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