dsh-linked-workspace 0.9.0 → 0.10.0

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.0 — 2026-11-12
4
+
5
+ Fourth review round: transfer safety, content search, document find and comparison actions.
6
+
7
+ - **No silent overwrite (fix)**: dropping a file onto a folder that already has that name now asks first — cancel, keep both, or overwrite. `fs.pullToLocal` and `fs.upload` accept `conflict=error|overwrite|unique`; `unique` goes through `uniqueLocalPath` / `remoteUniqueTarget`. Verified by overwriting `REMOTE-OVER` with `LOCAL-OVER` and by creating `same copy.txt` and `overwrite (2).txt`.
8
+ - **Transfer and drag fixes**: single-file transfers create missing parent directories (previously `writeFileAtomic … No such file`); same-tree drops point at “Move to…”; dropping a folder shows a direction-specific notice; hovering a folder for 700 ms while dragging expands it.
9
+ - **Content search (feature)**: `fs.grep` searches file contents — the local scan is bounded to 1 MB per file, 2000 files, 8 MB and 5 s; the remote side runs `grep -rIl … | head`. The search bar switches between “File name” and “Content” modes; `fs.search` stays a filename search (now documented, and the placeholder was corrected).
10
+ - **Document find (feature)**: the Markdown document pane supports Ctrl/Cmd+F with a counter, next/previous and Escape; it is read-only (replace remains in the text editor).
11
+ - **Compare actions (feature)**: comparison rows can be pushed to the remote side or pulled to the local side; the dialog notes a missing local folder and per-side truncation, closes when a row is opened, and derives the local path separator instead of hardcoding `\`.
12
+ - **Queue retry (feature)**: failed transfer-queue items gain “Retry”.
13
+ - **Workspace registration (feature)**: when a link has no `workspaceId`, settings offers “Register workspace” (`linked.update` with `ensureWorkspace: true`).
14
+ - **Smaller fixes**: the find counter is announced (`aria-live`), Escape closes the find bar from the replace field, and the editor status bar no longer shows a pointless `Ctrl+S` keycap.
15
+ - Tests: 63 unit tests pass; `test/host-api.mjs` passes 28 steps.
3
16
  ## 0.9.0 — 2026-11-12
4
17
 
5
18
  Third review round: in-editor editing, local/remote comparison and drag-and-drop, plus refresh behaviour.
package/README.en.md CHANGED
@@ -119,6 +119,19 @@ Old “Remote directories” tabs are restored after refresh through hidden lega
119
119
 
120
120
  See [CHANGELOG.md](CHANGELOG.md) for the full version history.
121
121
 
122
+ ### 0.10.0
123
+
124
+ Transfer safety, content search, document find and comparison actions (fourth review round):
125
+
126
+ - **No silent overwrite**: dropping a file onto a folder that already has that name now asks first — cancel, keep both or overwrite. `fs.pullToLocal` and `fs.upload` accept `conflict=error|overwrite|unique`; unique names go through `uniqueLocalPath` / `remoteUniqueTarget` (verified by overwriting `REMOTE-OVER` with `LOCAL-OVER`, and by producing `same copy.txt` and `overwrite (2).txt`).
127
+ - **Transfer and drag fixes**: single-file transfers create missing parent directories (previously `writeFileAtomic … No such file`); same-tree drops point at “Move to…”; dropping a folder shows a direction-specific notice; hovering a folder for 700 ms while dragging expands it.
128
+ - **Content search**: `fs.grep` searches file contents — local scans are bounded to 1 MB per file, 2000 files, 8 MB and 5 s; the remote side runs `grep -rIl … | head`. The search bar switches between “File name” and “Content”; `fs.search` remains a filename search (now documented, placeholder corrected).
129
+ - **Document find**: the Markdown document pane supports `Ctrl/Cmd + F` with a counter, next/previous and Escape; it is read-only (replace stays in the text editor).
130
+ - **Compare actions**: rows can be pushed to the remote side or pulled to the local side; a missing local folder and per-side truncation are explained; opening a row closes the dialog; the local path separator is inferred instead of hardcoded.
131
+ - **Queue retry**: failed transfer-queue items gain “Retry”.
132
+ - **Workspace registration**: when a link has no `workspaceId`, settings offers “Register workspace” (`linked.update` with `ensureWorkspace`).
133
+ - **Smaller fixes**: the find counter is announced (`aria-live`); Escape closes the find bar from the replace field; the editor status bar no longer shows a pointless `Ctrl+S` keycap.
134
+ - Tests: 63 unit tests pass; `test/host-api.mjs` passes 28 steps.
122
135
  ### 0.9.0
123
136
 
124
137
  In-editor find/replace, local↔remote comparison, multi-select and drag-and-drop, plus refresh fixes (third review round):
package/README.md CHANGED
@@ -114,6 +114,19 @@ dsh plugin --profile "$DSH_PROFILE" add "file:$PWD/dsh-linked-workspace"
114
114
 
115
115
  已打开的旧右侧栏「远程目录」标签页会在刷新后自动恢复(插件保留了两个隐藏的旧 tab 类型别名),标签标题也会自动改成「联动工作区目录」,新开的标签使用新的 `dsh-linked-workspace` 类型。
116
116
 
117
+ ### 0.10.0 变化
118
+
119
+ 传输安全、内容搜索、文档查找与对比操作(第四轮评审):
120
+
121
+ - **不再静默覆盖**:把文件拖到已有同名文件的目标目录时,先弹「取消 / 保留两者 / 覆盖」;`fs.pullToLocal`、`fs.upload` 新增 `conflict=error|overwrite|unique`,唯一名走 `uniqueLocalPath` / `remoteUniqueTarget`(实测覆盖 `REMOTE-OVER` → `LOCAL-OVER`,保留两者生成 `same copy.txt`、`overwrite (2).txt`)。
122
+ - **传输与拖拽修正**:单文件传输会自动创建缺失的父目录(此前报 `writeFileAtomic … No such file`);同侧拖拽会提示改用「移动到…」;拖目录时按方向给出明确提示;拖拽悬停目录 700 ms 自动展开。
123
+ - **内容搜索**:新增 `fs.grep` 搜索文件内容——本地限制单文件 1 MB、2000 个文件、8 MB、5 秒;远端用 `grep -rIl … | head`。搜索条可在「文件名 / 内容」之间切换;`fs.search` 仍是文件名匹配(已写入文档,占位文案同步修正)。
124
+ - **文档内查找**:Markdown 文档面板支持 `Ctrl/Cmd + F`,带计数、上一个/下一个与 Esc 关闭;只读,替换仍在文本编辑器中。
125
+ - **对比操作**:对比行可「推送到远端 / 拉取到本地」;本地缺少对应目录、单侧截断都有说明;点行打开后对话框自动关闭;本地路径分隔符按路径推断,不再写死 `\`。
126
+ - **队列重试**:传输队列的失败项增加「重试」。
127
+ - **注册工作区**:联动记录没有 `workspaceId` 时,设置页显示「注册为工作区」(`linked.update` 的 `ensureWorkspace`)。
128
+ - **其他修正**:查找计数加 `aria-live`;焦点在替换框时 Esc 也能关闭查找条;编辑器状态栏移除无用的 `Ctrl+S` 键帽。
129
+ - 测试:63 项单元测试通过;`test/host-api.mjs` 通过 28 步。
117
130
  ### 0.9.0 变化
118
131
 
119
132
  编辑器内查找替换、本地⇄远端对比、多选与拖拽,以及刷新行为修复(第三轮评审):
package/docs/API.md CHANGED
@@ -74,7 +74,7 @@ relative to the scope root, or absolute inside it.
74
74
  | `local.mkdir` | `{ path, name }` | `{ path }` (existing target → 409) |
75
75
  | `linked.list` | `{}` | `{ links: LinkInfo[] }` (each link carries `running`) |
76
76
  | `linked.create` | `{ hostId, remotePath, localPath, name?, mirror? }` | `{ link, workspaceId: string|null }` |
77
- | `linked.update` | `{ id, name?, mirror? }` | `{ link }` |
77
+ | `linked.update` | `{ id, name?, mirror?, ensureWorkspace? }` | `{ link }` (`ensureWorkspace: true` registers the local directory as a DSH workspace when it is not registered yet) |
78
78
  | `linked.remove` | `{ id, removeWorkspace?, deleteLocalState? }` | `{ removedWorkspace, deletedLocalState }` |
79
79
  | `linked.sync` | `{ id, maxFiles?, maxBytes? }` | `{ job: SyncJob }` (starts a background job) |
80
80
  | `linked.syncStatus` | `{ id }` | `{ job: SyncJob | null }` |
@@ -88,10 +88,11 @@ relative to the scope root, or absolute inside it.
88
88
  | `skills.list` | `{ linkedId }` | `{ localPath, skills: [{ name, description, whenToUse, path, source }] }` |
89
89
  | `skills.read` | `{ linkedId, name }` | `{ name, description, content, path }` |
90
90
  | `git.status` | `{ workspaceId?/linkedId?, side: 'remote'|'local' }` | `{ ok, repo, root, branch, changes, error? }` |
91
- | `fs.search` | `{ workspaceId?/linkedId?, side, query, maxResults? }` | `{ ok, query, entries, truncated }` (matches file names, not contents) |
92
- | `fs.compare` | `{ workspaceId?/linkedId?, path? }` | `{ path, relative, localPath, localMissing, counts: { onlyLocal, onlyRemote, changed, same }, onlyLocal, onlyRemote, changed, truncated }` (linked workspaces only; excludes `.git`, `node_modules`, `.local`, `.remote`; max 4000 files, depth 12, 200 rows per group) |
93
- | `fs.pullToLocal` | `{ workspaceId?/linkedId?, path, targetDir? }` | `{ path, relative, size, mtime }` (single file, ≤64 MB; `targetDir` must stay inside the local root) |
94
- | `fs.upload` | `{ workspaceId?/linkedId?, path, paths }` | `{ side: 'remote', target, files, bytes, skipped }` (≤50 local files, 64 MB each) |
91
+ | `fs.search` | `{ workspaceId?/linkedId?, side, query, maxResults? }` | `{ ok, query, entries, truncated }` (matches **file names**, not contents; use `fs.grep` for contents) |
92
+ | `fs.grep` | `{ workspaceId?/linkedId?, side, query, maxResults? }` | `{ ok, query, entries, truncated }` (searches file **contents**; local scans stop at 1 MB per file, 2000 files, 8 MB and 5 s; remote uses `grep -rIl`; max 1000 rows) |
93
+ | `fs.compare` | `{ workspaceId?/linkedId?, path? }` | `{ path, relative, localPath, localMissing, counts: { onlyLocal, onlyRemote, changed, same }, onlyLocal, onlyRemote, changed, truncated, remoteTruncated, localTruncated, skippedLinks }` (linked workspaces only; excludes `.git`, `node_modules`, `.local`, `.remote`; 4000 files and depth 12 **per side**, 200 rows per group; `skippedLinks` counts symlinks and non-regular files) |
94
+ | `fs.pullToLocal` | `{ workspaceId?/linkedId?, path, targetDir?, conflict? }` | `{ path, relative, size, mtime }` (single file, ≤64 MB; `targetDir` must stay inside the local root; `conflict` is `error` (default), `overwrite` or `unique`) |
95
+ | `fs.upload` | `{ workspaceId?/linkedId?, path, paths, conflict? }` | `{ side: 'remote', target, files, bytes, skipped }` (≤50 local files, 64 MB each; `conflict` is `error` (default), `overwrite` or `unique`; a missing target directory is created) |
95
96
  | `fs.transfer` | `{ workspaceId?/linkedId?, path }` | `{ files, bytes, skipped, truncated, dest }` |
96
97
  | `fs.download` | `{ workspaceId?/linkedId?, path }` | `{ path, files, bytes, skipped, truncated }` |
97
98
  | `fs.edit` | `{ workspaceId?/linkedId?, path, app? }` | `{ localPath, size }` (opens Notepad/default app) |
package/docs/VERIFY.md CHANGED
@@ -170,3 +170,17 @@ Host code (lib/) reloads live with `plugin_manager set_plugin include:linked-wor
170
170
  9. **分页按钮**:把 >500 项的目录加载到底:`.rw-load-more` 按钮应消失,不再显示「剩余 0 项」。
171
171
  10. **搜索截断**:在目录中放 250 个文件名含 `needle` 的文件后搜索:结果顶部应提示「结果过多,仅显示前 200 条;请输入更精确的关键词」。
172
172
  11. **注意**:搜索按**文件名**匹配(不是内容),界面占位符「在文件中搜索…」为既有文案问题,已列入下一轮缺陷候选。
173
+
174
+ ## 传输安全、内容搜索与对比操作(0.10.0)
175
+
176
+ 1. **拖拽冲突**:目标目录已有同名文件时,把文件拖进去:应弹「取消 / 保留两者 / 覆盖」;选「保留两者」生成 `name copy.txt`(或 `name (2).txt`),选「覆盖」后内容为拖入版本,选「取消」目标不变。
177
+ 2. **单文件传输建父目录**:向远端不存在的子目录传输单个文件:应成功,且不再出现 `writeFileAtomic … No such file`。
178
+ 3. **内容搜索**:搜索条切到「内容」后搜一个只出现在正文里的词(如 `beta`):本地应列出 `notes.md` 等文件;远端命中很多时显示「结果过多,仅显示前 200 条」;切回「文件名」仍按名称匹配。
179
+ 4. **文档内查找**:打开 Markdown 文档,`Ctrl/Cmd + F` 输入 `beta`:计数应显示「第 1 / 3 个」,Enter/Shift+Enter 上下跳转并选中,Esc 关闭且焦点回到编辑区。
180
+ 5. **对比操作**:右键远端目录「与本地对比…」,点「仅本地」行的「推送到远端」:远端出现该文件;点「仅远端」行的「拉取到本地」:本地出现该文件;打开某行后对话框自动关闭。
181
+ 6. **本地缺少对应目录**:对比一个本地没有的远程子目录:对话框应提示「本地没有对应目录,远端独有的文件无法对比」。
182
+ 7. **队列重试**:制造一次传输失败(例如目标路径是文件而非目录),在队列中点「重试」:修好原因后应成功并刷新树。
183
+ 8. **注册工作区**:联动记录的 `workspaceId` 为空时,设置页应显示「注册为工作区」,点击后变为正常的工作区信息。
184
+ 9. **拖拽提示**:同侧拖动、拖本地目录到远端、拖远端目录到本地:应分别给出「请使用移动到…」「暂不支持把本地目录拖拽到远端…」「暂不支持把远程目录拖拽到本地…」。
185
+ 10. **悬停展开**:拖拽停在折叠目录行 700 ms:该目录应自动展开。
186
+ 11. **host-api**:`node test/host-api.mjs` 应为 28 步全部通过。
package/lib/client.js CHANGED
@@ -2199,6 +2199,7 @@ function attributeViolation(name, value, tagName) {
2199
2199
  dropImported: '已导入 {{count}} 个文件',
2200
2200
  dropSkipped: '{{count}} 个文件被跳过(过大或不是普通文件)',
2201
2201
  dropDirUnsupported: '暂不支持把远程目录拖拽到本地,请使用右键「传输」',
2202
+ dropLocalDirUnsupported: '暂不支持把本地目录拖拽到远端,请使用右键「传输」',
2202
2203
  sheetTruncated: '仅显示前 {{rows}} 行 × {{cols}} 列',
2203
2204
  sheetMore: '工作表较多,仅显示前 20 个',
2204
2205
  noCredential: '缺少凭据',
@@ -2225,6 +2226,25 @@ function attributeViolation(name, value, tagName) {
2225
2226
  removeWorkspaceHint: '「同时移除工作区」会把该本地目录从 DSH 工作区列表移除(会话保留,显示在未分组下)。',
2226
2227
  openWorkspace: '打开工作区',
2227
2228
  workspaceMissing: '工作区未注册',
2229
+ workspaceRegister: '注册为工作区',
2230
+ workspaceRegistered: '已注册为工作区',
2231
+ conflictDropTitle: '目标已存在',
2232
+ conflictOverwrite: '覆盖',
2233
+ conflictKeepBoth: '保留两者',
2234
+ conflictCancel: '取消',
2235
+ compareLocalMissing: '本地没有对应目录,远端独有的文件无法对比',
2236
+ compareTruncatedRemote: '远端条目过多,对比只覆盖前 4000 项',
2237
+ compareTruncatedLocal: '本地条目过多,对比只覆盖前 4000 项',
2238
+ comparePush: '推送到远端',
2239
+ comparePull: '拉取到本地',
2240
+ comparePushed: '已推送 {{name}}',
2241
+ comparePulled: '已拉取 {{name}}',
2242
+ dropSameSide: '同一工作区内请使用「移动到…」;拖拽只用于本地与远端之间',
2243
+ searchModeName: '文件名',
2244
+ searchModeContent: '内容',
2245
+ searchPlaceholderContent: '在文件内容中搜索…',
2246
+ queueRetry: '重试',
2247
+ shortcutWebNote: 'Web GUI 中 Ctrl+W、Ctrl+Tab 由浏览器占用,请在 DSH 桌面端使用这些快捷键。',
2228
2248
  themeTitle: '编辑器主题',
2229
2249
  themeHint: '远程文件编辑器的配色;主题只影响本插件的远程文件视图。',
2230
2250
  themeDark: '深色',
@@ -2561,6 +2581,7 @@ function attributeViolation(name, value, tagName) {
2561
2581
  dropImported: 'Imported {{count}} file(s)',
2562
2582
  dropSkipped: '{{count}} file(s) skipped (too large or not a regular file)',
2563
2583
  dropDirUnsupported: 'Dropping a remote folder onto local is not supported yet; use Transfer instead',
2584
+ dropLocalDirUnsupported: 'Dropping a local folder onto remote is not supported yet; use Transfer instead',
2564
2585
  sheetTruncated: 'Showing the first {{rows}} rows × {{cols}} columns',
2565
2586
  sheetMore: 'Showing the first 20 worksheets only',
2566
2587
  noCredential: 'No credentials',
@@ -2587,6 +2608,25 @@ function attributeViolation(name, value, tagName) {
2587
2608
  removeWorkspaceHint: '“Remove workspace too” also removes the local folder from the DSH workspace list (sessions stay, shown under ungrouped).',
2588
2609
  openWorkspace: 'Open workspace',
2589
2610
  workspaceMissing: 'Workspace not registered',
2611
+ workspaceRegister: 'Register as workspace',
2612
+ workspaceRegistered: 'Registered as workspace',
2613
+ conflictDropTitle: 'Target already exists',
2614
+ conflictOverwrite: 'Overwrite',
2615
+ conflictKeepBoth: 'Keep both',
2616
+ conflictCancel: 'Cancel',
2617
+ compareLocalMissing: 'The local folder has no counterpart here; remote-only entries cannot be compared',
2618
+ compareTruncatedRemote: 'Too many remote entries; the comparison covers the first 4000',
2619
+ compareTruncatedLocal: 'Too many local entries; the comparison covers the first 4000',
2620
+ comparePush: 'Push to remote',
2621
+ comparePull: 'Pull to local',
2622
+ comparePushed: 'Pushed {{name}}',
2623
+ comparePulled: 'Pulled {{name}}',
2624
+ dropSameSide: 'Within one side, use “Move to…”; dragging is for local ↔ remote only',
2625
+ searchModeName: 'Name',
2626
+ searchModeContent: 'Content',
2627
+ searchPlaceholderContent: 'Search file contents…',
2628
+ queueRetry: 'Retry',
2629
+ shortcutWebNote: 'In the Web GUI, Ctrl+W and Ctrl+Tab are reserved by the browser; use these shortcuts in the DSH desktop app.',
2590
2630
  themeTitle: 'Editor theme',
2591
2631
  themeHint: 'Colors of the remote file editor. Themes affect this plugin’s remote file views only.',
2592
2632
  themeDark: 'Dark',
@@ -3382,6 +3422,13 @@ function attributeViolation(name, value, tagName) {
3382
3422
  '.rw-compare-row:hover{background:var(--dsw-alias-interactive-bg-hover)}',
3383
3423
  '.rw-compare-path{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
3384
3424
  '.rw-compare-size{flex:0 0 auto;color:var(--dsw-alias-label-tertiary)}',
3425
+ '.rw-compare-item{display:flex;align-items:center;gap:4px}',
3426
+ '.rw-compare-item .rw-compare-row{flex:1 1 auto;min-width:0}',
3427
+ '.rw-compare-actions{display:flex;gap:4px;flex:0 0 auto;padding-right:4px}',
3428
+ '.rw-compare-act{border:1px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:10.5px;padding:1px 6px;border-radius:4px;cursor:pointer;white-space:nowrap}',
3429
+ '.rw-compare-act:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}',
3430
+ '.rw-search-mode{display:flex;gap:2px;flex:0 0 auto}',
3431
+ '.rw-doc-find{flex:0 0 auto}',
3385
3432
  '.rw-dialog-note{font-size:11px;color:var(--dsw-alias-label-tertiary);padding:2px 0}',
3386
3433
  '.rw-dialog-error{color:var(--dsw-alias-state-error-primary)}',
3387
3434
  '.rw-row.is-drop-target{outline:1px dashed var(--dsw-alias-brand-primary);outline-offset:-1px}',
@@ -4621,7 +4668,7 @@ function attributeViolation(name, value, tagName) {
4621
4668
  if (event.key === 'Escape') { event.preventDefault(); closeFind(); }
4622
4669
  },
4623
4670
  }),
4624
- h('span', { className: 'rw-find-counter' }, counter),
4671
+ h('span', { className: 'rw-find-counter', 'aria-live': 'polite' }, counter),
4625
4672
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('findNext'), disabled: findMatches.length === 0, onClick: function () { stepMatch(1); } }, IconChevron(12)),
4626
4673
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('findPrev'), disabled: findMatches.length === 0, onClick: function () { stepMatch(-1); } }, h('span', { style: { display: 'inline-flex', transform: 'rotate(180deg)' } }, IconChevron(12))),
4627
4674
  h('input', {
@@ -4635,7 +4682,10 @@ function attributeViolation(name, value, tagName) {
4635
4682
  var value = event.currentTarget.value;
4636
4683
  setFind(function (previous) { return Object.assign({}, previous, { replace: value }); });
4637
4684
  },
4638
- onKeyDown: function (event) { if (event.key === 'Enter') { event.preventDefault(); replaceCurrent(); } },
4685
+ onKeyDown: function (event) {
4686
+ if (event.key === 'Enter') { event.preventDefault(); replaceCurrent(); }
4687
+ if (event.key === 'Escape') { event.preventDefault(); closeFind(); }
4688
+ },
4639
4689
  }),
4640
4690
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: !editable || findMatches.length === 0, onClick: replaceCurrent }, t('replaceOne')),
4641
4691
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: !editable || findMatches.length === 0, onClick: replaceAll }, t('replaceAll')),
@@ -4818,8 +4868,7 @@ function attributeViolation(name, value, tagName) {
4818
4868
  : file.tooLarge || file.truncated || file.binary
4819
4869
  ? h('span', { className: 'rw-status-chip rw-status-error' }, t('readOnly'))
4820
4870
  : h('span', { className: 'rw-status-chip rw-status-ok' }, theme.label ? (locale === 'zh' ? theme.label.zh : theme.label.en) : theme.id),
4821
- h('span', { className: 'rw-fill', style: { flex: '1 1 auto' } }),
4822
- h('span', { className: 'rw-status-chip' }, h('span', { className: 'rw-kbd' }, 'Ctrl'), h('span', { className: 'rw-kbd' }, 'S'))));
4871
+ h('span', { className: 'rw-fill', style: { flex: '1 1 auto' } })));
4823
4872
  }
4824
4873
 
4825
4874
  // ── linked workspace directory workbench ──────────────────────────────
@@ -5009,6 +5058,10 @@ function attributeViolation(name, value, tagName) {
5009
5058
  });
5010
5059
  }
5011
5060
 
5061
+ var rootRecord = cache.entries.get(rootPath);
5062
+ var rootSiblings = rootRecord && rootRecord.entries ? rootRecord.entries.map(function (item) {
5063
+ return { path: item.path, name: item.name, isDir: item.type === 'dir' };
5064
+ }) : [];
5012
5065
  return h('div', {
5013
5066
  className: 'rw-tree',
5014
5067
  role: 'tree',
@@ -5045,6 +5098,7 @@ function attributeViolation(name, value, tagName) {
5045
5098
  : null,
5046
5099
  selectedPath: props.selectedPath || '',
5047
5100
  selectedSet: props.selectedPaths && props.selectedPaths.length > 0 ? new Set(props.selectedPaths) : null,
5101
+ siblings: rootSiblings,
5048
5102
  }));
5049
5103
  }
5050
5104
 
@@ -5432,32 +5486,64 @@ function attributeViolation(name, value, tagName) {
5432
5486
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: props.onClose }, props.t('close'))));
5433
5487
  }
5434
5488
 
5489
+ function joinRelativePath(parent, relative, side) {
5490
+ var sep = side === 'remote' ? '/' : (String(parent || '').indexOf('\\') >= 0 ? '\\' : '/');
5491
+ var base = String(parent || '').replace(/[\\/]+$/, '');
5492
+ var tail = String(relative || '').split('/').filter(function (part) { return part !== ''; }).join(sep);
5493
+ if (base === '') return sep + tail;
5494
+ if (base === '/') return '/' + tail;
5495
+ return base + sep + tail;
5496
+ }
5497
+
5435
5498
  function CompareDialog(props) {
5436
5499
  var t = props.t;
5437
5500
  var data = props.data;
5438
- function section(key, title, rows, count, side) {
5501
+ function rowAction(side, row, kind) {
5502
+ var label = kind === 'push' ? t('comparePush') : t('comparePull');
5503
+ var title = label + ' · ' + row.path;
5504
+ return h('button', {
5505
+ key: kind,
5506
+ type: 'button',
5507
+ className: 'rw-btn rw-btn-sm rw-compare-act',
5508
+ title: title,
5509
+ onClick: function () {
5510
+ if (kind === 'push') props.onPush(row.path);
5511
+ else props.onPull(row.path);
5512
+ },
5513
+ }, label);
5514
+ }
5515
+ function section(key, title, rows, count, side, actions) {
5439
5516
  return h('div', { key: key, className: 'rw-compare-section' },
5440
5517
  h('div', { className: 'rw-compare-title' }, title + ' (' + count + ')'),
5441
5518
  count === 0
5442
5519
  ? h('div', { className: 'rw-compare-empty' }, t('compareNone'))
5443
5520
  : rows.map(function (row) {
5444
5521
  var size = row.size != null ? row.size : row.localSize;
5445
- return h('button', {
5446
- key: row.path,
5447
- type: 'button',
5448
- className: 'rw-compare-row',
5449
- title: row.path,
5450
- onClick: function () { props.onOpen(side, row.path); },
5451
- },
5452
- h('span', { className: 'rw-compare-path' }, row.path),
5453
- h('span', { className: 'rw-compare-size' }, typeof size === 'number' ? formatBytes(size) : ''));
5522
+ return h('div', { key: row.path, className: 'rw-compare-item' },
5523
+ h('button', {
5524
+ type: 'button',
5525
+ className: 'rw-compare-row',
5526
+ title: row.path,
5527
+ onClick: function () { props.onOpen(side, row.path); },
5528
+ },
5529
+ h('span', { className: 'rw-compare-path' }, row.path),
5530
+ h('span', { className: 'rw-compare-size' }, typeof size === 'number' ? formatBytes(size) : '')),
5531
+ actions && actions.length > 0 ? h('span', { className: 'rw-compare-actions' }, actions.map(function (kind) { return rowAction(side, row, kind); })) : null);
5454
5532
  }));
5455
5533
  }
5534
+ var notes = [];
5535
+ if (data.localMissing) notes.push(t('compareLocalMissing'));
5536
+ if (data.remoteTruncated) notes.push(t('compareTruncatedRemote'));
5537
+ if (data.localTruncated) notes.push(t('compareTruncatedLocal'));
5538
+ var note = notes.length > 0
5539
+ ? h('div', { className: 'rw-dialog-note' }, notes.join(' '))
5540
+ : null;
5456
5541
  return h(DialogShell, { title: props.title, onClose: props.onClose },
5457
5542
  h('div', { className: 'rw-dialog-message rw-compare-root', title: data.localPath }, data.localPath),
5458
- section('onlyLocal', t('compareOnlyLocal'), data.onlyLocal || [], data.counts.onlyLocal, 'local'),
5459
- section('onlyRemote', t('compareOnlyRemote'), data.onlyRemote || [], data.counts.onlyRemote, 'remote'),
5460
- section('changed', t('compareChanged'), data.changed || [], data.counts.changed, 'remote'),
5543
+ note,
5544
+ section('onlyLocal', t('compareOnlyLocal'), data.onlyLocal || [], data.counts.onlyLocal, 'local', ['push']),
5545
+ section('onlyRemote', t('compareOnlyRemote'), data.onlyRemote || [], data.counts.onlyRemote, 'remote', ['pull']),
5546
+ section('changed', t('compareChanged'), data.changed || [], data.counts.changed, 'remote', ['push', 'pull']),
5461
5547
  data.truncated ? h('div', { className: 'rw-dialog-note' }, t('compareTruncated')) : null,
5462
5548
  h('div', { className: 'rw-dialog-actions' },
5463
5549
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: props.onClose }, t('close'))));
@@ -5487,7 +5573,14 @@ function attributeViolation(name, value, tagName) {
5487
5573
  : props.queue.map(function (entry) {
5488
5574
  return h('div', { key: entry.id, className: 'rw-queue-row' },
5489
5575
  h('span', { className: 'rw-queue-label', title: entry.path }, entry.label),
5490
- h('span', { className: 'rw-queue-state' }, entry.message || entry.state));
5576
+ h('span', { className: 'rw-queue-state' }, entry.message || entry.state),
5577
+ entry.state === 'error' && props.onRetry
5578
+ ? h('button', {
5579
+ type: 'button',
5580
+ className: 'rw-btn rw-btn-sm',
5581
+ onClick: function () { props.onRetry(entry); },
5582
+ }, props.t('queueRetry'))
5583
+ : null);
5491
5584
  }),
5492
5585
  h('div', { className: 'rw-dialog-actions' },
5493
5586
  props.queue.some(function (entry) { return entry.state === 'done' || entry.state === 'error'; })
@@ -5510,9 +5603,11 @@ function attributeViolation(name, value, tagName) {
5510
5603
  loading: true, error: '', data: null, text: '', dirty: false, saving: false,
5511
5604
  preview: false, html: '', previewLoading: false, page: 0, sheet: 0, slide: 0,
5512
5605
  updates: {}, pptxUpdates: {}, rotations: {}, deleted: {}, pdfLoading: false, notice: '',
5606
+ findOpen: false, findQuery: '', findIndex: 0,
5513
5607
  });
5514
5608
  var state = stateRef[0];
5515
5609
  var setState = stateRef[1];
5610
+ var docTextareaRef = useRef(null);
5516
5611
 
5517
5612
  function patch(next) {
5518
5613
  setState(function (previous) { return Object.assign({}, previous, next); });
@@ -5587,13 +5682,57 @@ function attributeViolation(name, value, tagName) {
5587
5682
  if (props.visible === false) return undefined;
5588
5683
  function onKey(event) {
5589
5684
  var mod = event.ctrlKey || event.metaKey;
5590
- if (!mod || String(event.key || '').toLowerCase() !== 's') return;
5591
- event.preventDefault();
5592
- saveRef.current();
5685
+ if (!mod) return;
5686
+ var key = String(event.key || '').toLowerCase();
5687
+ if (key === 's') {
5688
+ event.preventDefault();
5689
+ saveRef.current();
5690
+ return;
5691
+ }
5692
+ // Read-only find inside the document editor (no replace).
5693
+ if (key === 'f' && kind === 'markdown' && !state.preview) {
5694
+ event.preventDefault();
5695
+ patch({ findOpen: true });
5696
+ }
5593
5697
  }
5594
5698
  window.addEventListener('keydown', onKey, true);
5595
5699
  return function () { window.removeEventListener('keydown', onKey, true); };
5596
- }, [props.visible]);
5700
+ }, [props.visible, kind, state.preview]);
5701
+
5702
+ function docMatches() {
5703
+ var query = state.findQuery;
5704
+ if (!query) return [];
5705
+ var haystack = state.text;
5706
+ var needle = query.toLowerCase();
5707
+ var lower = haystack.toLowerCase();
5708
+ var found = [];
5709
+ var from = 0;
5710
+ while (found.length < 2000) {
5711
+ var at = lower.indexOf(needle, from);
5712
+ if (at < 0) break;
5713
+ found.push(at);
5714
+ from = at + Math.max(needle.length, 1);
5715
+ }
5716
+ return found;
5717
+ }
5718
+
5719
+ function stepDocMatch(delta) {
5720
+ var matches = docMatches();
5721
+ if (matches.length === 0) return;
5722
+ var next = ((state.findIndex + delta) % matches.length + matches.length) % matches.length;
5723
+ patch({ findIndex: next });
5724
+ var area = docTextareaRef.current;
5725
+ if (!area) return;
5726
+ area.focus();
5727
+ area.setSelectionRange(matches[next], matches[next] + state.findQuery.length);
5728
+ var ratio = matches[next] / Math.max(area.value.length, 1);
5729
+ area.scrollTop = Math.max(0, ratio * area.scrollHeight - area.clientHeight / 2);
5730
+ }
5731
+
5732
+ function closeDocFind() {
5733
+ patch({ findOpen: false });
5734
+ if (docTextareaRef.current) docTextareaRef.current.focus();
5735
+ }
5597
5736
 
5598
5737
  useEffect(function () {
5599
5738
  if (!settings.autoSave || !state.dirty || state.saving) return undefined;
@@ -5704,7 +5843,32 @@ function attributeViolation(name, value, tagName) {
5704
5843
  state.previewLoading ? h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')) : null,
5705
5844
  state.html ? h('div', { className: 'rw-doc-preview', dangerouslySetInnerHTML: { __html: state.html } }) : null)
5706
5845
  : h('div', { className: 'rw-doc-body' },
5846
+ state.findOpen ? h('div', { className: 'rw-find-bar rw-doc-find' },
5847
+ h('input', {
5848
+ className: 'rw-input',
5849
+ value: state.findQuery,
5850
+ placeholder: t('findPlaceholder'),
5851
+ 'aria-label': t('findPlaceholder'),
5852
+ spellCheck: false,
5853
+ autoFocus: true,
5854
+ onChange: function (event) { patch({ findQuery: event.currentTarget.value, findIndex: 0 }); },
5855
+ onKeyDown: function (event) {
5856
+ if (event.key === 'Enter') { event.preventDefault(); stepDocMatch(event.shiftKey ? -1 : 1); }
5857
+ if (event.key === 'Escape') { event.preventDefault(); closeDocFind(); }
5858
+ },
5859
+ }),
5860
+ h('span', { className: 'rw-find-counter', 'aria-live': 'polite' },
5861
+ (function () {
5862
+ var total = docMatches().length;
5863
+ if (state.findQuery === '') return '';
5864
+ return total === 0 ? t('findNoMatch') : t('findCounter', { index: state.findIndex + 1, total: total });
5865
+ })()),
5866
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('findPrev'), onClick: function () { stepDocMatch(-1); } }, h('span', { style: { display: 'inline-flex', transform: 'rotate(180deg)' } }, IconChevron(12))),
5867
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('findNext'), onClick: function () { stepDocMatch(1); } }, IconChevron(12)),
5868
+ h('button', { type: 'button', className: 'rw-icon-btn', title: t('close'), onClick: closeDocFind }, IconClose(12)))
5869
+ : null,
5707
5870
  h('textarea', {
5871
+ ref: docTextareaRef,
5708
5872
  className: 'rw-doc-textarea', value: state.text, spellCheck: false,
5709
5873
  onChange: function (event) { patch({ text: event.currentTarget.value, dirty: true, html: '' }); },
5710
5874
  }));
@@ -5824,6 +5988,9 @@ function attributeViolation(name, value, tagName) {
5824
5988
  var searchQueryState = useState('');
5825
5989
  var searchQuery = searchQueryState[0];
5826
5990
  var setSearchQuery = searchQueryState[1];
5991
+ var searchModeState = useState('name');
5992
+ var searchMode = searchModeState[0];
5993
+ var setSearchMode = searchModeState[1];
5827
5994
  var searchState = useState({ loading: false, remote: [], local: [], error: null });
5828
5995
  var search = searchState[0];
5829
5996
  var setSearch = searchState[1];
@@ -5857,6 +6024,8 @@ function attributeViolation(name, value, tagName) {
5857
6024
  var multiState = useState([]);
5858
6025
  var multi = multiState[0];
5859
6026
  var setMulti = multiState[1];
6027
+ // Anchor for Shift+click range selection (a ref: it must not re-render).
6028
+ var selectionAnchorRef = useRef(null);
5860
6029
  var showHiddenState = useState(true);
5861
6030
  var showHidden = showHiddenState[0];
5862
6031
  var setShowHidden = showHiddenState[1];
@@ -6229,6 +6398,26 @@ function attributeViolation(name, value, tagName) {
6229
6398
  setSelectedEntry(entry);
6230
6399
  var toggle = Boolean(event && (event.ctrlKey || event.metaKey));
6231
6400
  var extend = Boolean(event && event.shiftKey);
6401
+ if (extend) {
6402
+ var anchor = selectionAnchorRef.current;
6403
+ var siblings = Array.isArray(info.siblings) ? info.siblings : [];
6404
+ if (anchor && anchor.side === side && siblings.length > 0) {
6405
+ var anchorIndex = -1;
6406
+ var targetIndex = -1;
6407
+ siblings.forEach(function (item, index) {
6408
+ if (item.path === anchor.path) anchorIndex = index;
6409
+ if (item.path === info.path) targetIndex = index;
6410
+ });
6411
+ if (anchorIndex >= 0 && targetIndex >= 0) {
6412
+ var start = Math.min(anchorIndex, targetIndex);
6413
+ var end = Math.max(anchorIndex, targetIndex);
6414
+ setMulti(siblings.slice(start, end + 1).map(function (item) {
6415
+ return { side: side, path: item.path, name: item.name, isDir: Boolean(item.isDir) };
6416
+ }));
6417
+ return;
6418
+ }
6419
+ }
6420
+ }
6232
6421
  setMulti(function (previous) {
6233
6422
  var exists = previous.some(function (item) { return item.side === side && item.path === entry.path; });
6234
6423
  if (extend) return exists ? previous : previous.concat([entry]);
@@ -6239,6 +6428,7 @@ function attributeViolation(name, value, tagName) {
6239
6428
  }
6240
6429
  return [entry];
6241
6430
  });
6431
+ if (!extend) selectionAnchorRef.current = toggle ? selectionAnchorRef.current : { side: side, path: info.path };
6242
6432
  }
6243
6433
 
6244
6434
  function selectedOn(side) {
@@ -6408,6 +6598,28 @@ function attributeViolation(name, value, tagName) {
6408
6598
  } catch (error) { /* drag payload unsupported */ }
6409
6599
  }
6410
6600
 
6601
+ // A drop that would replace an existing file asks first: file transfer is
6602
+ // destructive and previously overwrote the target silently.
6603
+ function openConflict(error, method, params) {
6604
+ if (!error || String(error.code || '') !== 'FS_EXISTS') return false;
6605
+ setDialog({ kind: 'conflict', message: messageOf(error, t, locale), method: method, params: params });
6606
+ return true;
6607
+ }
6608
+
6609
+ function resolveConflict(choice) {
6610
+ var current = dialog;
6611
+ setDialog(null);
6612
+ if (!current || current.kind !== 'conflict' || choice === 'cancel') return;
6613
+ var params = Object.assign({}, current.params, { conflict: choice === 'overwrite' ? 'overwrite' : 'unique' });
6614
+ apiCall(current.method, params).then(function (result) {
6615
+ var skipped = Number(result && result.skipped) || 0;
6616
+ var count = current.method === 'fs.upload' ? Number(result && result.files) || 0 : 1;
6617
+ if (count > 0) showNotice('success', t('dropImported', { count: count }));
6618
+ if (skipped > 0) showNotice('warn', t('dropSkipped', { count: skipped }));
6619
+ refreshTree();
6620
+ }).catch(noticeError);
6621
+ }
6622
+
6411
6623
  // Drop target handling for both trees: OS files are imported into the
6412
6624
  // target directory, while an entry dragged from the other tree is pushed
6413
6625
  // across the boundary (remote→local or local→remote).
@@ -6428,12 +6640,16 @@ function attributeViolation(name, value, tagName) {
6428
6640
  var payload = side === 'remote'
6429
6641
  ? Object.assign({ path: targetDir, paths: osPaths }, scopeParams(scopeRef))
6430
6642
  : { dir: targetDir, paths: osPaths };
6431
- apiCall(side === 'remote' ? 'fs.upload' : 'local.import', payload).then(function (result) {
6643
+ var method = side === 'remote' ? 'fs.upload' : 'local.import';
6644
+ apiCall(method, payload).then(function (result) {
6432
6645
  var count = side === 'remote' ? Number(result.files) || 0 : Number(result.copied) || 0;
6433
6646
  showNotice('success', t('dropImported', { count: count }));
6434
6647
  if (Number(result.skipped) > 0) showNotice('warn', t('dropSkipped', { count: result.skipped }));
6435
6648
  refreshTree();
6436
- }).catch(noticeError);
6649
+ }).catch(function (error) {
6650
+ if (openConflict(error, method, payload)) return;
6651
+ noticeError(error);
6652
+ });
6437
6653
  return;
6438
6654
  }
6439
6655
  var raw = '';
@@ -6441,23 +6657,39 @@ function attributeViolation(name, value, tagName) {
6441
6657
  if (!raw) return;
6442
6658
  var entry;
6443
6659
  try { entry = JSON.parse(raw); } catch (error) { return; }
6444
- if (!entry || typeof entry.path !== 'string' || entry.side === side) return;
6660
+ if (!entry || typeof entry.path !== 'string') return;
6661
+ if (entry.side === side) {
6662
+ showNotice('error', t('dropSameSide'));
6663
+ return;
6664
+ }
6445
6665
  if (entry.side === 'remote') {
6446
6666
  if (entry.isDir) {
6447
6667
  showNotice('error', t('dropDirUnsupported'));
6448
6668
  return;
6449
6669
  }
6450
- apiCall('fs.pullToLocal', Object.assign({ path: entry.path, targetDir: targetDir }, scopeParams(scopeRef))).then(function () {
6670
+ var pullParams = Object.assign({ path: entry.path, targetDir: targetDir }, scopeParams(scopeRef));
6671
+ apiCall('fs.pullToLocal', pullParams).then(function () {
6451
6672
  showNotice('success', t('dropImported', { count: 1 }));
6452
6673
  refreshTree();
6453
- }).catch(noticeError);
6674
+ }).catch(function (error) {
6675
+ if (openConflict(error, 'fs.pullToLocal', pullParams)) return;
6676
+ noticeError(error);
6677
+ });
6454
6678
  return;
6455
6679
  }
6456
- apiCall('fs.upload', Object.assign({ path: targetDir, paths: [entry.path] }, scopeParams(scopeRef))).then(function (result) {
6680
+ if (entry.isDir) {
6681
+ showNotice('error', t('dropLocalDirUnsupported'));
6682
+ return;
6683
+ }
6684
+ var pushParams = Object.assign({ path: targetDir, paths: [entry.path] }, scopeParams(scopeRef));
6685
+ apiCall('fs.upload', pushParams).then(function (result) {
6457
6686
  if (Number(result.skipped) > 0) showNotice('warn', t('dropSkipped', { count: result.skipped }));
6458
6687
  else showNotice('success', t('dropImported', { count: Number(result.files) || 1 }));
6459
6688
  refreshTree();
6460
- }).catch(noticeError);
6689
+ }).catch(function (error) {
6690
+ if (openConflict(error, 'fs.upload', pushParams)) return;
6691
+ noticeError(error);
6692
+ });
6461
6693
  }
6462
6694
 
6463
6695
  function submitRenamed(side, oldPath, name) {
@@ -6644,9 +6876,27 @@ function attributeViolation(name, value, tagName) {
6644
6876
  data: dialog.data,
6645
6877
  onClose: function () { setDialog(null); },
6646
6878
  onOpen: function (side, relative) {
6647
- var root = dialog.root;
6648
- var target = side === 'local' ? dialog.localPath : root;
6649
- openInternalFile(side === 'local' ? 'local' : 'remote', target + (target.endsWith('/') || target.endsWith('\\') ? '' : side === 'local' ? '\\' : '/') + relative.split('/').join(side === 'local' ? '\\' : '/'));
6879
+ setDialog(null);
6880
+ var target = side === 'local' ? dialog.localPath : dialog.root;
6881
+ openInternalFile(side === 'local' ? 'local' : 'remote', joinRelativePath(target, relative, side === 'local' ? 'local' : 'remote'));
6882
+ },
6883
+ onPush: function (relative) {
6884
+ var source = joinRelativePath(dialog.localPath, relative, 'local');
6885
+ var remoteDir = parentPathOf(joinRelativePath(dialog.root, relative, 'remote'), 'remote');
6886
+ apiCall('fs.upload', Object.assign({ path: remoteDir, paths: [source], conflict: 'overwrite' }, scopeParams(scopeRef))).then(function () {
6887
+ showNotice('success', t('comparePushed', { name: relative.split('/').pop() }));
6888
+ setDialog(null);
6889
+ refreshTree();
6890
+ }).catch(noticeError);
6891
+ },
6892
+ onPull: function (relative) {
6893
+ var remoteFile = joinRelativePath(dialog.root, relative, 'remote');
6894
+ var localDir = parentPathOf(joinRelativePath(dialog.localPath, relative, 'local'), 'local');
6895
+ apiCall('fs.pullToLocal', Object.assign({ path: remoteFile, targetDir: localDir, conflict: 'overwrite' }, scopeParams(scopeRef))).then(function () {
6896
+ showNotice('success', t('comparePulled', { name: relative.split('/').pop() }));
6897
+ setDialog(null);
6898
+ refreshTree();
6899
+ }).catch(noticeError);
6650
6900
  },
6651
6901
  });
6652
6902
  }
@@ -6663,6 +6913,7 @@ function attributeViolation(name, value, tagName) {
6663
6913
  queueRef.current = queueRef.current.filter(function (entry) { return entry.state !== 'done' && entry.state !== 'error'; });
6664
6914
  setQueueList(queueRef.current.slice());
6665
6915
  },
6916
+ onRetry: function (entry) { enqueueTransfer(entry.side, entry.path, entry.label); },
6666
6917
  });
6667
6918
  }
6668
6919
  if (dialog.kind === 'delete') {
@@ -6685,6 +6936,14 @@ function attributeViolation(name, value, tagName) {
6685
6936
  onConfirm: function () { setDialog(null); confirmDeleteMany(dialog.entries); },
6686
6937
  });
6687
6938
  }
6939
+ if (dialog.kind === 'conflict') {
6940
+ return h(DialogShell, { title: t('conflictDropTitle'), onClose: function () { resolveConflict('cancel'); } },
6941
+ h('div', { className: 'rw-dialog-message' }, dialog.message),
6942
+ h('div', { className: 'rw-dialog-actions' },
6943
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: function () { resolveConflict('cancel'); } }, t('conflictCancel')),
6944
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: function () { resolveConflict('unique'); } }, t('conflictKeepBoth')),
6945
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm rw-btn-danger', onClick: function () { resolveConflict('overwrite'); } }, t('conflictOverwrite'))));
6946
+ }
6688
6947
  if (dialog.kind === 'move') {
6689
6948
  return h(MoveDialog, {
6690
6949
  t: t, locale: locale,
@@ -6758,11 +7017,12 @@ function attributeViolation(name, value, tagName) {
6758
7017
  var timer = setTimeout(function () {
6759
7018
  setSearch(function (previous) { return { loading: true, remote: previous.remote, local: previous.local, truncated: false, error: null }; });
6760
7019
  var scopeNow = sourceScopeOf(selected);
6761
- var jobs = [apiCall('fs.search', Object.assign({ side: 'remote', query: query, maxResults: 200 }, scopeParams(scopeNow))).catch(function (error) {
7020
+ var method = searchMode === 'content' ? 'fs.grep' : 'fs.search';
7021
+ var jobs = [apiCall(method, Object.assign({ side: 'remote', query: query, maxResults: 200 }, scopeParams(scopeNow))).catch(function (error) {
6762
7022
  return { ok: false, entries: [], error: messageOf(error, t, locale) };
6763
7023
  })];
6764
7024
  if (selected.kind === 'linked') {
6765
- jobs.push(apiCall('fs.search', Object.assign({ side: 'local', query: query, maxResults: 200 }, scopeParams(scopeNow))).catch(function (error) {
7025
+ jobs.push(apiCall(method, Object.assign({ side: 'local', query: query, maxResults: 200 }, scopeParams(scopeNow))).catch(function (error) {
6766
7026
  return { ok: false, entries: [], error: messageOf(error, t, locale) };
6767
7027
  }));
6768
7028
  } else {
@@ -6780,7 +7040,7 @@ function attributeViolation(name, value, tagName) {
6780
7040
  });
6781
7041
  }, 320);
6782
7042
  return function () { alive = false; clearTimeout(timer); };
6783
- }, [searchOpen, searchQuery, selectedKey, version]);
7043
+ }, [searchOpen, searchQuery, selectedKey, version, searchMode]);
6784
7044
 
6785
7045
  if (!selected) {
6786
7046
  return h('div', { className: 'rw-workbench rw-workspace', ref: workbenchRef },
@@ -6951,9 +7211,22 @@ function attributeViolation(name, value, tagName) {
6951
7211
  searchOpen
6952
7212
  ? h('div', { className: 'rw-searchbar' },
6953
7213
  IconSearch(13),
7214
+ h('span', { className: 'rw-search-mode' },
7215
+ h('button', {
7216
+ type: 'button',
7217
+ className: 'rw-chip-btn' + (searchMode === 'name' ? ' is-on' : ''),
7218
+ title: t('searchModeName'),
7219
+ onClick: function () { setSearchMode('name'); },
7220
+ }, t('searchModeName')),
7221
+ h('button', {
7222
+ type: 'button',
7223
+ className: 'rw-chip-btn' + (searchMode === 'content' ? ' is-on' : ''),
7224
+ title: t('searchModeContent'),
7225
+ onClick: function () { setSearchMode('content'); },
7226
+ }, t('searchModeContent'))),
6954
7227
  h('input', {
6955
7228
  value: searchQuery,
6956
- placeholder: t('searchPlaceholder'),
7229
+ placeholder: searchMode === 'content' ? t('searchPlaceholderContent') : t('searchPlaceholder'),
6957
7230
  spellCheck: false,
6958
7231
  autoFocus: true,
6959
7232
  onChange: function (event) { setSearchQuery(event.currentTarget.value); },
@@ -7058,6 +7331,18 @@ function attributeViolation(name, value, tagName) {
7058
7331
  var selectedPath = props.selectedPath;
7059
7332
  var isOpen = expanded.has(path);
7060
7333
  var entry = state.entries.get(path) || { loading: false, error: null, entries: [] };
7334
+ var childSiblings = entry.entries.map(function (item) {
7335
+ return { path: item.path, name: item.name, isDir: item.type === 'dir' };
7336
+ });
7337
+ // Hovering over a collapsed folder during a drag expands it after a short
7338
+ // delay, so dropping into a nested folder does not require two passes.
7339
+ var dragOpenTimer = useRef(null);
7340
+
7341
+ useEffect(function () {
7342
+ return function () {
7343
+ if (dragOpenTimer.current) clearTimeout(dragOpenTimer.current);
7344
+ };
7345
+ }, []);
7061
7346
 
7062
7347
  useEffect(function () {
7063
7348
  if (isOpen && !entry.loading && !entry.loaded && !entry.error) props.load(path);
@@ -7098,6 +7383,7 @@ function attributeViolation(name, value, tagName) {
7098
7383
  onDropOnPath: props.onDropOnPath,
7099
7384
  selectedPath: selectedPath,
7100
7385
  selectedSet: props.selectedSet,
7386
+ siblings: childSiblings,
7101
7387
  }));
7102
7388
  } else if (child.type === 'file' || child.type === 'symlink') {
7103
7389
  var active = selectedPath === child.path || Boolean(props.selectedSet && props.selectedSet.has(child.path));
@@ -7115,7 +7401,7 @@ function attributeViolation(name, value, tagName) {
7115
7401
  if (props.onDragStart) props.onDragStart(event, { path: child.path, name: child.name, isDir: false });
7116
7402
  },
7117
7403
  onClick: function (event) {
7118
- if (onSelectPath) onSelectPath({ path: child.path, name: child.name, isDir: false, event: event });
7404
+ if (onSelectPath) onSelectPath({ path: child.path, name: child.name, isDir: false, siblings: childSiblings, event: event });
7119
7405
  if (event.detail !== 2) onSelect(child.path);
7120
7406
  },
7121
7407
  onDoubleClick: function () { if (onPin) onPin(child.path); },
@@ -7162,7 +7448,7 @@ function attributeViolation(name, value, tagName) {
7162
7448
  if (props.onDragStart) props.onDragStart(event, { path: path, name: name, isDir: true });
7163
7449
  },
7164
7450
  onClick: function (event) {
7165
- if (onSelectPath) onSelectPath({ path: path, name: name, isDir: true, event: event });
7451
+ if (onSelectPath) onSelectPath({ path: path, name: name, isDir: true, siblings: props.siblings || [], event: event });
7166
7452
  if (event.detail !== 2) toggle(path);
7167
7453
  },
7168
7454
  onKeyDown: function (event) {
@@ -7175,10 +7461,26 @@ function attributeViolation(name, value, tagName) {
7175
7461
  event.stopPropagation();
7176
7462
  try { event.dataTransfer.dropEffect = 'copy'; } catch (error) { /* ignore */ }
7177
7463
  event.currentTarget.classList.add('is-drop-target');
7464
+ if (!isOpen && !dragOpenTimer.current) {
7465
+ dragOpenTimer.current = setTimeout(function () {
7466
+ dragOpenTimer.current = null;
7467
+ toggle(path);
7468
+ }, 700);
7469
+ }
7470
+ },
7471
+ onDragLeave: function (event) {
7472
+ event.currentTarget.classList.remove('is-drop-target');
7473
+ if (dragOpenTimer.current) {
7474
+ clearTimeout(dragOpenTimer.current);
7475
+ dragOpenTimer.current = null;
7476
+ }
7178
7477
  },
7179
- onDragLeave: function (event) { event.currentTarget.classList.remove('is-drop-target'); },
7180
7478
  onDrop: function (event) {
7181
7479
  event.currentTarget.classList.remove('is-drop-target');
7480
+ if (dragOpenTimer.current) {
7481
+ clearTimeout(dragOpenTimer.current);
7482
+ dragOpenTimer.current = null;
7483
+ }
7182
7484
  if (props.onDropOnPath) props.onDropOnPath(path, event);
7183
7485
  },
7184
7486
  onContextMenu: function (event) {
@@ -7851,6 +8153,20 @@ function attributeViolation(name, value, tagName) {
7851
8153
  dismissSettingsOverlay();
7852
8154
  }
7853
8155
 
8156
+ function registerWorkspace() {
8157
+ setLocal(function (previous) { return Object.assign({}, previous, { busy: 'register', message: null }); });
8158
+ apiCall('linked.update', { id: link.id, ensureWorkspace: true }).then(function () {
8159
+ setLocal(function (previous) {
8160
+ return Object.assign({}, previous, { busy: '', message: { kind: 'success', text: t('workspaceRegistered') } });
8161
+ });
8162
+ refresh();
8163
+ }).catch(function (error) {
8164
+ setLocal(function (previous) {
8165
+ return Object.assign({}, previous, { busy: '', message: { kind: 'error', text: messageOf(error, t, locale) } });
8166
+ });
8167
+ });
8168
+ }
8169
+
7854
8170
  function pollSync(job) {
7855
8171
  if (!job) {
7856
8172
  setLocal(function (previous) { return Object.assign({}, previous, { busy: '', message: null }); });
@@ -7949,7 +8265,12 @@ function attributeViolation(name, value, tagName) {
7949
8265
  h('div', { className: 'rw-actions' },
7950
8266
  link.workspaceId
7951
8267
  ? h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: openWorkspace }, IconExternal(12), t('openWorkspace'))
7952
- : h('span', { className: 'rw-chip' }, t('workspaceMissing')),
8268
+ : h('button', {
8269
+ type: 'button', className: 'rw-btn rw-btn-sm',
8270
+ onClick: registerWorkspace,
8271
+ disabled: local.busy === 'register',
8272
+ title: t('workspaceMissing'),
8273
+ }, local.busy === 'register' ? Spinner(12) : IconPlus(12), t('workspaceRegister')),
7953
8274
  h('button', {
7954
8275
  type: 'button', className: 'rw-btn rw-btn-sm',
7955
8276
  onClick: sync, disabled: local.busy !== '' || !link.mirror, title: link.mirror ? t('sync') : t('mirrorHint'),
@@ -8118,6 +8439,7 @@ function attributeViolation(name, value, tagName) {
8118
8439
  h('kbd', { className: 'rw-kbd' }, item[0]),
8119
8440
  h('span', null, item[1]));
8120
8441
  })),
8442
+ h('div', { className: 'rw-group-hint', style: { marginTop: 8 } }, t('shortcutWebNote')),
8121
8443
  local.message
8122
8444
  ? h(Banner, {
8123
8445
  kind: local.message.kind === 'success' ? 'success' : 'error',
package/lib/index.js CHANGED
@@ -1495,6 +1495,9 @@ export function apply(ctx) {
1495
1495
  return
1496
1496
  }
1497
1497
  const data = readFileSync(localPath)
1498
+ // A single-file transfer can target a directory that does not exist on the
1499
+ // remote side yet (only the directory branch used to mkdirp).
1500
+ await remote.mkdirp(posix.dirname(remotePath))
1498
1501
  await withTimeout(remote.writeFileAtomic(remotePath, data), LINKED_SYNC_TIMEOUT_MS, `transfer ${relative}`)
1499
1502
  limits.files += 1
1500
1503
  limits.bytes += data.length
@@ -1785,6 +1788,95 @@ export function apply(ctx) {
1785
1788
  try { return await target.scope.remote.stat(target.path) } catch { return null }
1786
1789
  }
1787
1790
 
1791
+ // Content search: `fs.search` (git.localSearch / remoteSearch) only matches
1792
+ // file *names*. The workbench therefore needs a separate, bounded scan of
1793
+ // file bodies; both sides stop at a budget and report `truncated` instead of
1794
+ // hanging on a huge tree.
1795
+ const GREP_MAX_FILE_BYTES = 1024 * 1024
1796
+ const GREP_MAX_FILES = 2000
1797
+ const GREP_MAX_BYTES = 8 * 1024 * 1024
1798
+ const GREP_DEADLINE_MS = 5000
1799
+
1800
+ function grepDirectoryExcluded(name) {
1801
+ return LINKED_SYNC_EXCLUDES.has(name) || name === '.local' || name === '.remote'
1802
+ }
1803
+
1804
+ function contentSearchLocal(root, query, maxResults) {
1805
+ const needle = Buffer.from(query, 'utf8')
1806
+ const entries = []
1807
+ const started = Date.now()
1808
+ let files = 0
1809
+ let bytes = 0
1810
+ let truncated = false
1811
+ const visit = (directory, prefix) => {
1812
+ if (truncated) return
1813
+ if (files >= GREP_MAX_FILES || bytes >= GREP_MAX_BYTES || Date.now() - started > GREP_DEADLINE_MS) {
1814
+ truncated = true
1815
+ return
1816
+ }
1817
+ let listing
1818
+ try {
1819
+ listing = readdirSync(directory, { withFileTypes: true })
1820
+ } catch {
1821
+ return
1822
+ }
1823
+ for (const entry of listing) {
1824
+ if (truncated) return
1825
+ if (grepDirectoryExcluded(entry.name)) continue
1826
+ const absolute = join(directory, entry.name)
1827
+ const relative = prefix === '' ? entry.name : `${prefix}/${entry.name}`
1828
+ if (entry.isDirectory()) {
1829
+ visit(absolute, relative)
1830
+ continue
1831
+ }
1832
+ if (!entry.isFile()) continue
1833
+ if (files >= GREP_MAX_FILES || bytes >= GREP_MAX_BYTES || Date.now() - started > GREP_DEADLINE_MS) {
1834
+ truncated = true
1835
+ return
1836
+ }
1837
+ files += 1
1838
+ let data
1839
+ try {
1840
+ data = readFileSync(absolute)
1841
+ } catch {
1842
+ continue
1843
+ }
1844
+ if (data.length > GREP_MAX_FILE_BYTES) continue
1845
+ bytes += data.length
1846
+ if (data.includes(0)) continue
1847
+ if (data.indexOf(needle) === -1) continue
1848
+ if (entries.length >= maxResults) {
1849
+ truncated = true
1850
+ return
1851
+ }
1852
+ entries.push({ path: absolute, relative, size: data.length })
1853
+ }
1854
+ }
1855
+ visit(resolve(root), '')
1856
+ return { ok: true, query, entries, truncated }
1857
+ }
1858
+
1859
+ async function contentSearchRemote(remote, root, query, maxResults) {
1860
+ const command = 'grep -rIl --binary-files=without-match'
1861
+ + ' --exclude-dir=.git --exclude-dir=node_modules --exclude-dir=.local'
1862
+ + ' --exclude-dir=.remote --exclude-dir=__pycache__'
1863
+ + ` -e ${shellQuoteArg(query)} -- ${shellQuoteArg(root)} 2>/dev/null`
1864
+ + ` | head -n ${maxResults + 1}`
1865
+ const result = await remote.exec(command, { timeoutMs: 20000 })
1866
+ if (result.code !== 0 && result.stdout.trim() === '') {
1867
+ // grep exits 1 when nothing matched; a real failure has code > 1.
1868
+ if (result.code > 1) throw new ApiError('INTERNAL', `内容搜索失败:${String(result.stderr || '').trim().slice(0, 200)}`)
1869
+ return { ok: true, query, entries: [], truncated: false }
1870
+ }
1871
+ const lines = String(result.stdout || '').split('\n').map((line) => line.trim()).filter((line) => line !== '')
1872
+ const truncated = lines.length > maxResults
1873
+ const entries = lines.slice(0, maxResults).map((line) => {
1874
+ const relative = line.startsWith(`${root}/`) ? line.slice(root.length + 1) : line
1875
+ return { path: line, relative, size: null }
1876
+ })
1877
+ return { ok: true, query, entries, truncated }
1878
+ }
1879
+
1788
1880
  // ── method table ─────────────────────────────────────────────────────────
1789
1881
 
1790
1882
  const methods = {
@@ -2757,6 +2849,18 @@ export function apply(ctx) {
2757
2849
  return await git.localSearch(scope.record.localPath, query, { maxResults })
2758
2850
  },
2759
2851
 
2852
+ /** Search file *contents* (fs.search only matches names). */
2853
+ async 'fs.grep'(params = {}) {
2854
+ const scope = await requireScope(params)
2855
+ const query = typeof params.query === 'string' ? params.query.trim() : ''
2856
+ const maxResults = Math.min(Math.max(Number(params.maxResults) || 200, 1), 1000)
2857
+ if (query === '') return { ok: true, query: '', entries: [], truncated: false }
2858
+ const side = params.side === 'local' ? 'local' : 'remote'
2859
+ if (side === 'remote') return await contentSearchRemote(scope.remote, scope.root, query, maxResults)
2860
+ if (scope.kind !== 'linked') throw new ApiError('BAD_REQUEST', '只有联动工作区有本地目录')
2861
+ return contentSearchLocal(scope.record.localPath, query, maxResults)
2862
+ },
2863
+
2760
2864
  /**
2761
2865
  * Read-only comparison of one directory pair. Lists files that exist on one
2762
2866
  * side only and files whose size or mtime disagree; it never touches data.
@@ -2777,23 +2881,25 @@ export function apply(ctx) {
2777
2881
  const excluded = (entryName) => LINKED_SYNC_EXCLUDES.has(entryName) || entryName === '.local' || entryName === '.remote'
2778
2882
  const remoteMap = new Map()
2779
2883
  const localMap = new Map()
2780
- const state = { files: 0, truncated: false }
2884
+ // Each side gets its own budget: a huge remote tree must not silently cut
2885
+ // the local walk (and the other way round).
2886
+ const state = { remoteFiles: 0, localFiles: 0, remoteTruncated: false, localTruncated: false, skippedLinks: 0 }
2781
2887
  const walkRemote = async (directory, prefix, depth) => {
2782
- if (depth > MAX_DEPTH || state.files >= MAX_FILES) {
2783
- state.truncated = true
2888
+ if (depth > MAX_DEPTH || state.remoteFiles >= MAX_FILES) {
2889
+ state.remoteTruncated = true
2784
2890
  return
2785
2891
  }
2786
2892
  let listing
2787
2893
  try {
2788
2894
  listing = await scope.remote.listDir(directory)
2789
2895
  } catch (error) {
2790
- state.truncated = true
2896
+ state.remoteTruncated = true
2791
2897
  return
2792
2898
  }
2793
2899
  for (const entry of listing.entries) {
2794
2900
  if (excluded(entry.name)) continue
2795
- if (state.files >= MAX_FILES) {
2796
- state.truncated = true
2901
+ if (state.remoteFiles >= MAX_FILES) {
2902
+ state.remoteTruncated = true
2797
2903
  return
2798
2904
  }
2799
2905
  const relative = prefix === '' ? entry.name : `${prefix}/${entry.name}`
@@ -2801,27 +2907,30 @@ export function apply(ctx) {
2801
2907
  await walkRemote(entry.path, relative, depth + 1)
2802
2908
  continue
2803
2909
  }
2804
- if (entry.type !== 'file') continue
2910
+ if (entry.type !== 'file') {
2911
+ state.skippedLinks += 1
2912
+ continue
2913
+ }
2805
2914
  remoteMap.set(relative, { size: entry.size, mtime: entry.mtime })
2806
- state.files += 1
2915
+ state.remoteFiles += 1
2807
2916
  }
2808
2917
  }
2809
2918
  const walkLocal = (directory, prefix, depth) => {
2810
- if (depth > MAX_DEPTH || state.files >= MAX_FILES) {
2811
- state.truncated = true
2919
+ if (depth > MAX_DEPTH || state.localFiles >= MAX_FILES) {
2920
+ state.localTruncated = true
2812
2921
  return
2813
2922
  }
2814
2923
  let entries
2815
2924
  try {
2816
2925
  entries = readdirSync(directory, { withFileTypes: true })
2817
2926
  } catch (error) {
2818
- state.truncated = true
2927
+ state.localTruncated = true
2819
2928
  return
2820
2929
  }
2821
2930
  for (const entry of entries) {
2822
2931
  if (excluded(entry.name)) continue
2823
- if (state.files >= MAX_FILES) {
2824
- state.truncated = true
2932
+ if (state.localFiles >= MAX_FILES) {
2933
+ state.localTruncated = true
2825
2934
  return
2826
2935
  }
2827
2936
  const relative = prefix === '' ? entry.name : `${prefix}/${entry.name}`
@@ -2830,16 +2939,19 @@ export function apply(ctx) {
2830
2939
  walkLocal(absolute, relative, depth + 1)
2831
2940
  continue
2832
2941
  }
2833
- if (!entry.isFile()) continue
2942
+ if (!entry.isFile()) {
2943
+ state.skippedLinks += 1
2944
+ continue
2945
+ }
2834
2946
  let info
2835
2947
  try {
2836
2948
  info = statSync(absolute)
2837
2949
  } catch (error) {
2838
- state.truncated = true
2950
+ state.localTruncated = true
2839
2951
  continue
2840
2952
  }
2841
2953
  localMap.set(relative, { size: info.size, mtime: info.mtimeMs })
2842
- state.files += 1
2954
+ state.localFiles += 1
2843
2955
  }
2844
2956
  }
2845
2957
  await walkRemote(root, '', 0)
@@ -2886,7 +2998,10 @@ export function apply(ctx) {
2886
2998
  onlyLocal: sorted(onlyLocal).slice(0, MAX_LIST),
2887
2999
  onlyRemote: sorted(onlyRemote).slice(0, MAX_LIST),
2888
3000
  changed: sorted(changed).slice(0, MAX_LIST),
2889
- truncated: state.truncated,
3001
+ truncated: state.remoteTruncated || state.localTruncated,
3002
+ remoteTruncated: state.remoteTruncated,
3003
+ localTruncated: state.localTruncated,
3004
+ skippedLinks: state.skippedLinks,
2890
3005
  }
2891
3006
  },
2892
3007
 
@@ -2916,6 +3031,12 @@ export function apply(ctx) {
2916
3031
  } else {
2917
3032
  localTarget = join(localRoot, ...relative.split('/'))
2918
3033
  }
3034
+ // Dropping a file must never silently replace an existing local file.
3035
+ const conflict = params.conflict === 'overwrite' || params.conflict === 'unique' ? params.conflict : 'error'
3036
+ if (existsSync(localTarget)) {
3037
+ if (conflict === 'error') throw new ApiError('FS_EXISTS', `本地已存在同名文件:${basename(localTarget)}`)
3038
+ if (conflict === 'unique') localTarget = uniqueLocalPath(dirname(localTarget), basename(localTarget))
3039
+ }
2919
3040
  mkdirSync(dirname(localTarget), { recursive: true })
2920
3041
  const temp = join(dirname(localTarget), `.~${basename(localTarget)}.${process.pid}.${Date.now()}.tmp`)
2921
3042
  try {
@@ -2934,12 +3055,20 @@ export function apply(ctx) {
2934
3055
  async 'fs.upload'(params = {}) {
2935
3056
  const scope = await requireScope(params)
2936
3057
  const targetDir = scopeTarget(scope, params.path)
2937
- const stat = await scope.remote.stat(targetDir)
3058
+ // Upload targets come from dialogs and from compare "push"; nested folders
3059
+ // may not exist remotely yet, so create the chain before validating.
3060
+ let stat = await scope.remote.stat(targetDir).catch(() => null)
3061
+ if (!stat) {
3062
+ await scope.remote.mkdirp(targetDir)
3063
+ stat = await scope.remote.stat(targetDir)
3064
+ }
2938
3065
  if (stat.type !== 'dir') throw new ApiError('FS_NOT_DIR', '目标不是目录')
2939
3066
  const rawPaths = Array.isArray(params.paths) ? params.paths : [params.path]
2940
3067
  const paths = rawPaths.filter((item) => typeof item === 'string' && item.trim() !== '').map((item) => resolve(item.trim()))
2941
3068
  if (paths.length === 0) throw new ApiError('BAD_REQUEST', '没有可上传的文件')
2942
3069
  if (paths.length > 50) throw new ApiError('BAD_REQUEST', '一次最多上传 50 个文件')
3070
+ const conflict = params.conflict === 'overwrite' || params.conflict === 'unique' ? params.conflict : 'error'
3071
+ const prepared = []
2943
3072
  const limits = { files: 0, bytes: 0, skipped: 0 }
2944
3073
  for (const source of paths) {
2945
3074
  let info
@@ -2953,8 +3082,30 @@ export function apply(ctx) {
2953
3082
  limits.skipped += 1
2954
3083
  continue
2955
3084
  }
2956
- const data = readFileSync(source)
2957
- await scope.remote.writeFileAtomic(posix.join(targetDir, basename(source)), data)
3085
+ prepared.push({ source, name: basename(source) })
3086
+ }
3087
+ if (conflict === 'error' && prepared.length > 0) {
3088
+ const conflicts = []
3089
+ for (const item of prepared) {
3090
+ const existing = await scope.remote.stat(posix.join(targetDir, item.name)).catch(() => null)
3091
+ if (existing) conflicts.push(item.name)
3092
+ }
3093
+ if (conflicts.length > 0) {
3094
+ const shown = conflicts.slice(0, 5).join('、')
3095
+ const more = conflicts.length > 5 ? ` 等 ${conflicts.length} 个` : ''
3096
+ throw new ApiError('FS_EXISTS', `目标目录已有同名文件:${shown}${more}`)
3097
+ }
3098
+ }
3099
+ for (const item of prepared) {
3100
+ let targetName = item.name
3101
+ if (conflict === 'unique') {
3102
+ const existing = await scope.remote.stat(posix.join(targetDir, targetName)).catch(() => null)
3103
+ // Computed per item, after the previous write landed, so a batch of
3104
+ // same-named sources cannot collide with itself.
3105
+ if (existing) targetName = posix.basename(await remoteUniqueTarget(scope.remote, targetDir, targetName))
3106
+ }
3107
+ const data = readFileSync(item.source)
3108
+ await scope.remote.writeFileAtomic(posix.join(targetDir, targetName), data)
2958
3109
  limits.files += 1
2959
3110
  limits.bytes += data.length
2960
3111
  }
@@ -3053,6 +3204,13 @@ export function apply(ctx) {
3053
3204
  const workspace = findWorkspaceByPath(linkedRegistry(), record.localPath)
3054
3205
  if (workspace) await renameDshWorkspace(ctx, String(workspace.id), linkedWorkspaceTitle(record.name))
3055
3206
  }
3207
+ if (params.ensureWorkspace === true) {
3208
+ const existing = findWorkspaceByPath(linkedRegistry(), record.localPath)
3209
+ if (!existing) {
3210
+ const created = await ensureDshWorkspace(ctx.get('workspaceRegistry', true), record.localPath, linkedWorkspaceTitle(record.name))
3211
+ if (!created) throw new ApiError('INTERNAL', '无法注册本地工作区')
3212
+ }
3213
+ }
3056
3214
  if (nextMirror === true && params.mirror === true) {
3057
3215
  try {
3058
3216
  startSyncJob(record, { reason: 'enable' })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-linked-workspace",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Linked local ⇄ remote workspaces and SSH-backed remote directories for DeepSeek Harness: theme-aware split editor, file-type icons, and an agent tool that edits remote files directly.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",