@maxbill/dsh-file-explorer 1.1.2 → 1.2.2

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/README.en.md CHANGED
@@ -27,7 +27,7 @@ Browse · preview · edit · organise — and hand files straight to your agent<
27
27
 
28
28
  </div>
29
29
 
30
- <p align="center"><img src="docs/panel.png" width="880" alt="File Explorer: the icon view you see right after opening it"></p>
30
+ <p align="center"><img src="docs/terminal-panel.png" width="880" alt="File Explorer: icon view with the built-in terminal docked below"></p>
31
31
 
32
32
  <table>
33
33
  <tr>
@@ -207,10 +207,12 @@ Do those four things once and you know the whole plugin.
207
207
  - Writes go through DSH's `ctx.fs` (atomic write + version guard): if the file changed on disk after you opened it, the host returns **409** and the editor offers *reload* or *overwrite* — never a silent overwrite.
208
208
  - Binary extensions (zip / images / media …) have no edit button, so bytes that cannot round-trip are never written back.
209
209
 
210
- #### 7. Zero dependencies, zero build step
210
+ #### 7. Very few dependencies, still no build step
211
211
 
212
212
  - The host side is plain ESM (`lib/index.js`); the browser side is a hand-written `window.__ModuleLoader__` factory module (`lib/client.js`). **There is no bundling step** — change it, reload the page, done.
213
- - At runtime it only needs React (provided by DSH); XLSX / DOCX / ZIP parsing all happens in the host using Node's standard library.
213
+ - The only third-party front-end dependency is the terminal renderer **@xterm/xterm**; the host hands it to the page on demand instead of bundling it.
214
+ - The **node-pty** binaries behind the real pty ship inside the plugin (`vendor/node-pty`, prebuilt for macOS arm64/x64 and Windows x64), so installing downloads nothing extra and compiles nothing; if they fail to load, the `python3` bridge is used, and plain pipes are the last resort.
215
+ - XLSX / DOCX / ZIP parsing happens in the host on Node's standard library; the terminal gets a pty from the machine's own `/usr/bin/python3`, so nothing native is compiled.
214
216
 
215
217
  ---
216
218
 
@@ -303,6 +305,16 @@ Do those four things once and you know the whole plugin.
303
305
  | Folders, extra | **Add as workspace** |
304
306
  | Empty space | New folder…, new file…, paste, reveal current folder in file manager, refresh |
305
307
 
308
+ #### 4.9 Terminal
309
+
310
+ - **Where**: a Terminal button right after Sort in the toolbar, and Open in terminal on a folder context menu, which starts a shell in that directory.
311
+ - **Layout**: it docks between the file list and the status bar; drag its top grip to change the height, capped at half the window, and the height is remembered.
312
+ - **Tabs**: the header is a tab strip — one tab per shell, named after its folder (the full path is in the tooltip), and **double-clicking a tab name renames it**. The × closes that terminal and + opens another one; clicking a tab switches to it, and the shells you switch away from keep running.
313
+ - **What it runs**: a real pty — the bundled **node-pty** (macOS and Windows ConPTY), otherwise a `pty.fork` bridge through the host's `python3`. Colours and full-screen programs such as `vim` and `top` work, and dragging the dock passes the new size to the shell. Output is polled every 120 ms; keystrokes are batched every 12 ms.
314
+ - **Look**: 13 px font with a 1.5 line height, and the palette follows the app between light and dark; there are no extra settings.
315
+ - **Sessions**: only the close button ends the shell. Switching to a conversation and back reattaches the same shell and keeps what was on screen, and a terminal nobody has looked at for half an hour is reclaimed.
316
+ - **Limits**: desktop only (the button and menu item are hidden over a remote connection), at most three sessions.
317
+
306
318
  ---
307
319
 
308
320
  ### 5. Previewable file types
@@ -337,6 +349,7 @@ Do those four things once and you know the whole plugin.
337
349
  | Move to trash | ✅ `~/.Trash` | ✅ Recycle Bin via PowerShell, falling back to `~/.Trash` | ✅ freedesktop (`.trashinfo`, restorable) |
338
350
  | Address bar paths | ✅ POSIX | ✅ drive letters and UNC | ✅ POSIX |
339
351
  | Upload a whole folder | ✅ | ✅ | ✅ `webkitdirectory` (Chrome / Edge / Firefox; Safari degrades to picking files) |
352
+ | Terminal | ✅ real pty (node-pty / python3) | ✅ ConPTY (with node-pty; pipes otherwise) | ✅ real pty (node-pty / python3) |
340
353
 
341
354
  > ⚠️ **Windows and Linux have not been verified end to end on real machines.** Both branches follow the platform conventions (Explorer's `/select,`, the PowerShell recycle-bin call, freedesktop's `files` + `info` layout) and are covered by “platform plan” test cases in `npm test` that check command and path construction — but nobody has clicked through them on real hardware.
342
355
 
@@ -393,6 +406,11 @@ The decision is made from the request's origin: a loopback Host counts as local;
393
406
  - **Search** — 4000 entries, 200 hits, 4 seconds
394
407
  - **Upload** — 512 MB
395
408
 
409
+ **Terminal**
410
+
411
+ - The terminal runs commands on the host machine, exactly like a shell there. It is only offered when the browser reached us over loopback; a remote browser gets 403.
412
+ - Closing the terminal or the panel ends the process, and at most three sessions are kept.
413
+
396
414
  **Git**
397
415
 
398
416
  - Read-only `git status --porcelain` with `GIT_OPTIONAL_LOCKS=0`; the index is never written and the working tree is never touched.
@@ -468,7 +486,7 @@ There is no build step: `lib/index.js` is plain ESM and `lib/client.js` is a han
468
486
  | File | Purpose |
469
487
  |:--|:--|
470
488
  | `lib/index.js` | Host side: registers the 25 `/api/file-explorer` routes on DSH's `connection` service, with every path `realpath`-ed into `$HOME` |
471
- | `lib/client.js` | Browser side: registers the sidebar icon and the `main` panel; zero dependencies (only `react`) |
489
+ | `lib/client.js` | Browser side: registers the sidebar icon and the `main` panel; needs only the host's `react` plus a lazily loaded xterm |
472
490
  | `cordis.patch.yml` | Bundle patch that inserts the Loader entry `dsh-file-explorer` |
473
491
  | `assets/icons/` | 12 ready-to-use two-tone SVGs (`node scripts/export-icons.mjs` exports them from `SHAPES`) |
474
492
  | `test/host-api.test.mjs` | Host API tests (including the three-platform command plans) |
package/README.md CHANGED
@@ -27,7 +27,7 @@
27
27
 
28
28
  </div>
29
29
 
30
- <p align="center"><img src="docs/panel.png" width="880" alt="文件管理器:打开后是首页的图标视图"></p>
30
+ <p align="center"><img src="docs/terminal-panel.png" width="880" alt="文件管理器:图标视图 + 底部内置终端"></p>
31
31
 
32
32
  <table>
33
33
  <tr>
@@ -206,10 +206,12 @@ dsh plugin --profile desktop add @maxbill/dsh-file-explorer
206
206
  - 写入走 DSH 的 `ctx.fs`(原子写 + 版本守卫):文件被外部改过时宿主返回 **409**,编辑器给「重新加载 / 覆盖保存」二选一,不静默覆盖。
207
207
  - 二进制扩展名(zip / 图片 / 音视频等)不给编辑入口,避免把无法往返的字节写回去。
208
208
 
209
- #### 7. 零依赖、零构建
209
+ #### 7. 依赖很少、没有构建步骤
210
210
 
211
211
  - 宿主端是普通 ESM(`lib/index.js`),浏览器端是手写的 `window.__ModuleLoader__` 工厂模块(`lib/client.js`),**没有打包步骤**,改完重载页面即生效。
212
- - 运行时只需要 React(由 DSH 提供);XLSX / DOCX / ZIP 的解析都在宿主用 Node 标准库完成。
212
+ - 前端唯一的第三方依赖是终端渲染器 **@xterm/xterm**:宿主按需从 `node_modules` 交给页面,不打进 client 模块。
213
+ - 真 PTY 用的 **node-pty** 预编译(macOS arm64/x64、Windows x64)已随插件打包在 `vendor/node-pty`,安装时不用再下载或编译;加载失败时回退到 `python3` 中继,再不行退到管道。
214
+ - XLSX / DOCX / ZIP 的解析都在宿主用 Node 标准库完成;终端用宿主自带的 `/usr/bin/python3` 建 PTY,不需要编译原生模块。
213
215
 
214
216
  ---
215
217
 
@@ -302,6 +304,16 @@ dsh plugin --profile desktop add @maxbill/dsh-file-explorer
302
304
  | 文件夹额外 | **添加为工作区** |
303
305
  | 空白处 | 新建文件夹…、新建文件…、粘贴、在访达中显示当前文件夹、刷新 |
304
306
 
307
+ #### 4.9 终端
308
+
309
+ - **入口**:工具栏「排序」之后的「终端」按钮;文件夹右键「在终端打开」,直接在该目录起一个 shell。
310
+ - **位置**:停在文件区与状态栏之间,拖动顶部把手可调高度,**最高不超过窗口一半**,高度记在浏览器里。
311
+ - **页签**:标题栏就是标签栏 —— 每个终端一个标签(名字取目录名,完整路径在悬停提示里),**双击标签名可以改名**;点 × 关掉这个终端、点 + 再开一个;标签之间点一下就切换,切走的终端在后台继续跑。
312
+ - **能力**:真 PTY —— 插件自带 `node-pty` 预编译(macOS / Windows 的 ConPTY),其它平台用 `python3` 的 `pty.fork` 中继,都可跑彩色输出与 `vim` / `top` 这类全屏程序,拖动高度会同步窗口大小;输出按 120 ms 轮询拉取,输入按 12 ms 合并发送。
313
+ - **外观**:字号 13、行高 1.5,配色跟随界面深浅自动切换,不提供额外设置。
314
+ - **会话**:点 × 关闭终端才结束 shell;切到会话再切回来会接回同一个 shell,屏幕内容保留;半小时无人查看的终端自动回收。
315
+ - **限制**:仅桌面端可用(远程访问时按钮与菜单项隐藏);同时最多保留 3 个会话。
316
+
305
317
  ---
306
318
 
307
319
  ### 五、可预览的文件类型
@@ -336,6 +348,7 @@ dsh plugin --profile desktop add @maxbill/dsh-file-explorer
336
348
  | 移到废纸篓 | ✅ `~/.Trash` | ✅ 系统回收站(PowerShell,失败退回 `~/.Trash`) | ✅ freedesktop(`.trashinfo`,可还原) |
337
349
  | 地址栏路径 | ✅ POSIX | ✅ 盘符与 UNC | ✅ POSIX |
338
350
  | 上传整个文件夹 | ✅ | ✅ | ✅ `webkitdirectory`(Chrome / Edge / Firefox;Safari 退化为选文件) |
351
+ | 终端 | ✅ 真 PTY(内置 node-pty / python3) | ✅ ConPTY(内置 node-pty) | ✅ 真 PTY(python3) |
339
352
 
340
353
  > ⚠️ **Windows 与 Linux 尚未实机完整验收**。两条分支按各自官方约定实现(Explorer 的 `/select,`、回收站的 `SendToRecycleBin`、freedesktop 的 `files`+`info` 目录结构),并在 `npm test` 里用「平台计划」用例模拟验证命令与路径拼接,但没有在真机点过一遍。
341
354
 
@@ -392,6 +405,11 @@ dsh plugin --profile desktop add @maxbill/dsh-file-explorer
392
405
  - **搜索** —— 4000 个目录项、200 条命中、4 秒
393
406
  - **上传** —— 512 MB
394
407
 
408
+ **终端**
409
+
410
+ - 终端执行的是宿主机器上的命令,等同在宿主上开一个 shell;只在浏览器来自本机(回环地址)时提供,远程访问一律 403。
411
+ - 关闭终端或面板时结束对应进程;同时最多保留 3 个会话。
412
+
395
413
  **Git**
396
414
 
397
415
  - 只读 `git status --porcelain`,设 `GIT_OPTIONAL_LOCKS=0`,绝不写索引、不改工作区。
@@ -467,7 +485,7 @@ npm test # 宿主端 HTTP 接口测试,在 $HOME 下的临时目录里
467
485
  | 文件 | 作用 |
468
486
  |:--|:--|
469
487
  | `lib/index.js` | Host 端:把 `/api/file-explorer` 的 25 条路由注册到 DSH `connection` 服务,路径统一 `realpath` 收敛在 `$HOME` |
470
- | `lib/client.js` | 浏览器端:注册左侧栏图标与 `main` 面板,零依赖(只要 `react`) |
488
+ | `lib/client.js` | 浏览器端:注册左侧栏图标与 `main` 面板;只依赖宿主提供的 `react` 与按需加载的 xterm |
471
489
  | `cordis.patch.yml` | Bundle patch,把 Loader 条目 `dsh-file-explorer` 插入 |
472
490
  | `assets/icons/` | 12 个可直接取用的双色 SVG(`node scripts/export-icons.mjs` 从 `SHAPES` 导出) |
473
491
  | `test/host-api.test.mjs` | 宿主接口测试(含三平台命令计划) |
@@ -0,0 +1,41 @@
1
+ # 往 awesome-dsh-plugin 提交条目
2
+
3
+ 我们的列表条目在 `data/plugins/MaxBill__dsh-file-explorer.yml`,通过 fork + PR 提交。踩过的坑记在这里。
4
+
5
+ ## 推送前必做
6
+
7
+ 1. **YAML 只留一个结尾引号**
8
+ 替换 `description.en` / `description.zh` 时,单引号字符串的结尾只能有一个 `'`。
9
+ 写成 `...压缩解压。''` 会让 CI 报 `invalid YAML — deficient indentation`。
10
+ 本地先验:`node -e "require('js-yaml').load(require('fs').readFileSync('data/plugins/MaxBill__dsh-file-explorer.yml','utf8'))"`
11
+
12
+ 2. **README 必须与 data/plugins 一致**
13
+ CI 会检查 README 有没有和数据不符的改动。改完 yml 跑:
14
+ ```
15
+ node scripts/generate-readme.mjs
16
+ ```
17
+ 会重新生成 README.md 与 README.zh.md,只动我们这一行。
18
+
19
+ 3. **分支先 rebase 到最新 upstream/main**
20
+ 上游一天能合几百个 PR,分支几天就落后几百个提交,PR 会变成 `CONFLICTING`。
21
+ 推荐做法:把分支重置到 `upstream/main`,只保留一条干净的提交,再强推:
22
+ ```
23
+ git fetch upstream main
24
+ git reset --hard upstream/main
25
+ # 改 yml、生成 README、提交
26
+ git push --force origin HEAD:upstream-entry
27
+ ```
28
+
29
+ 4. **推完等 check 变绿**
30
+ ```
31
+ gh pr view <号> --repo awesome-dsh-plugin/awesome-dsh-plugin --json mergeable,statusCheckRollup
32
+ ```
33
+ 要看到 `mergeable: MERGEABLE` 且 `conclusion: SUCCESS`,否则维护者不会合。
34
+
35
+ ## 提交流程
36
+
37
+ 1. 在 fork 上建分支(如 `upstream-entry`),只改 `data/plugins/MaxBill__dsh-file-explorer.yml`
38
+ 2. 跑 `node scripts/generate-readme.mjs`
39
+ 3. 提交(中文提交信息),推到 fork
40
+ 4. `gh pr create --repo awesome-dsh-plugin/awesome-dsh-plugin --head <fork>:upstream-entry`
41
+ 5. 后续更新同一个分支,PR 会自动带上新提交
@@ -0,0 +1,79 @@
1
+ # 用 ego-browser 调试面板
2
+
3
+ 界面改动不用手动截图:起一个测试宿主,用 `ego-browser` 驱动浏览器,点开面板、执行操作、把截图存下来。
4
+
5
+ ## 1. 起测试宿主
6
+
7
+ 面板需要一个带插件的 DSH 实例,不要动正在用的那个:
8
+
9
+ ```bash
10
+ PID=$(lsof -nP -iTCP:3199 -sTCP:LISTEN -t 2>/dev/null | head -1)
11
+ [ -n "$PID" ] && kill -9 "$PID"
12
+ export DSH_HOME=/tmp/fe-compose
13
+ rm -f /tmp/host.log
14
+ nohup "/Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh" \
15
+ --profile fe-check --no-open --port 3199 > /tmp/host.log 2>&1 &
16
+ for i in $(seq 1 30); do sleep 1; grep -q 'dsh web: http' /tmp/host.log && break; done
17
+ grep -o 'http://127.0.0.1:3199/?token=[A-Za-z0-9_-]*' /tmp/host.log | tail -1
18
+ ```
19
+
20
+ **必须用带 token 的 URL**:裸 `http://127.0.0.1:3199/` 会显示 `dsh web authentication required`。
21
+
22
+ ## 2. 一次调试脚本的样子
23
+
24
+ ```bash
25
+ ego-browser nodejs <<'EOF'
26
+ const task = await taskSpace("dsh-file-explorer dev");
27
+ const page = task.page("p1");
28
+ await page.goto("http://127.0.0.1:3199/?token=<TOKEN>", { timeout: 40000 });
29
+ await page.waitForTimeout(4500);
30
+
31
+ // 关掉首次进入的对话框
32
+ await page.evaluate(() => {
33
+ const d = document.querySelector('[role="dialog"]');
34
+ if (d) Array.from(d.querySelectorAll('button')).pop()?.click();
35
+ });
36
+
37
+ // 打开面板
38
+ await page.click('loc=css:button[aria-label="文件管理器"]', { label: "open file manager" });
39
+ await page.waitForSelector(".dfx-root", { state: "visible", timeout: 10000 });
40
+
41
+ // 断言 + 截图
42
+ const state = await page.evaluate(() => ({
43
+ rows: document.querySelectorAll(".dfx-rows > *").length,
44
+ tools: Array.from(document.querySelectorAll(".dfx-tool")).map((b) => b.textContent.trim()),
45
+ }));
46
+ await page.screenshot({ path: "/tmp/ego-dsh.png" });
47
+ console.log({ state });
48
+
49
+ await task.finish({ keep: [] });
50
+ EOF
51
+ ```
52
+
53
+ ## 3. 常用操作
54
+
55
+ | 目的 | 写法 |
56
+ |:--|:--|
57
+ | 看结构 / 找元素 | `await page.snapshot()`,元素带 `ref=N` 和 `loc=css:…` |
58
+ | 点元素 | `page.click('@10')` 或 `page.click('loc=css:button[aria-label="排序"]', { label: "open sort" })` |
59
+ | 等状态 | `page.waitForSelector('.dfx-term', { state: 'visible' })` |
60
+ | 读页面状态 | `page.evaluate(() => ({ … }))`(回调只在页面里跑) |
61
+ | 截图 | `page.screenshot({ path: '/tmp/x.png' })`,父目录会自动建 |
62
+ | 输入 | `page.fill(selector, text)` / `page.keyboard.type(text)` |
63
+ | 拖拽 | `page.mouse.move(x, y)` + `mouse.down()` + `move()` + `mouse.up()` |
64
+
65
+ ## 4. 规矩
66
+
67
+ - 一个调试目标用一个 TaskSpace,名字写清楚;同一目标的下一次调试复用它(先 `listTaskSpaces()` 找 id)
68
+ - 每次脚本最后 `task.finish({ keep: [] })`,只有需要给你留着看时才 `{ keep: ["p1"] }`
69
+ - 一次脚本里把「操作 + 等待 + 取样」串起来,少来回
70
+ - 每个 `ego-browser nodejs` 都是新进程,变量不跨脚本;任务空间、标签、页面标签会保留
71
+
72
+ ## 5. 常见坑
73
+
74
+ | 现象 | 原因 / 处理 |
75
+ |:--|:--|
76
+ | `dsh web authentication required` | 用了不带 token 的 URL |
77
+ | 点不到侧栏按钮 | 先 `snapshot()` 确认 `aria-label`,再 `loc=css:` 点 |
78
+ | 面板没出来 | 等 `.dfx-root`,首次进入还有对话框要关 |
79
+ | 截图是空白 | 页面还没渲染完,先 `waitForTimeout` 或 `waitForSelector` |
Binary file