底部 + 菜单里开得出 shell,刷新后认回同一个 shell,且**不**变成宿主 右列终端的第二个入口。 实现分三层: 1. 宿主能力层(src/client/terminal-client.ts,核心 bundle 安全):结构化 探测 `ctx.webTerminals`(view/close/recover 三个函数都在才算数)+ 身份助手。**不写进 dsh.client.inject**:注入一个不存在的服务会把整行 拖成 pending,插件在无终端控制器的部署上会整体不加载;也**不** value-import 任何 @deepseek-ai/*(纯度门),类型面手工声明。 2. chunk 层(src/client/TerminalView.tsx + terminal.module.css + chunks/terminal.tsx + terminal-lazy.tsx):xterm 与它的样式表整份打进 lib/client-terminal.js(750 KB),核心包一处都没有;chunk 名在 9 处 镜像(tsdown / bundle-route / chunk-loader / package.json.files / package-registry / bundle-route.spec),另两处 spec 从 CHUNK_NAMES 派生。 3. 描述符层(builtins/tabs.tsx):第 6 个内置类型,`bottomOnly: true` (见上一个 commit)、`single`、`available` 读同一份探测、`onClose` 结束进程。 三条恢复语义的由来: - **contentId 恒定,terminalId 不写进 tab.meta**:宿主 view() 显式传 terminalId 会关掉「缺了就建」分支,一个过期 id 会把页签永久卡在 missingTerminal;宿主自己的 (sessionId, contentId) → 终端 id 持久绑定 本来就能在刷新后认回同一个 shell。 - **「新建终端」换代号**:DSH 重启后 PTY 没了而 localStorage 绑定还在, 恒定 contentId 会永远认领死绑定。tab.meta.terminalRun(默认 0)+1 换 一代 contentId 让宿主另铸进程;key 与 contentId 一起换(views 按 (sessionId, key) 记忆化)。 - **关页签才结束进程**:宿主的契约是「视图跨 DOM 卸载存活」,这正是刷新 能认回同一个 shell 的原因,所以卸载不 close;但不 close 会让每个关掉 的终端永久占一个 per-session 终端槽位(terminalLimit),因此 descriptor 的 onClose → webTerminals.close() 是唯一且必须存在的回收路径。 测试(判别性证据见交付报告): - tests/terminal-tab.spec.tsx 14 条:view() 调用形状与 contentId 恒定性、 mount/detach、write/resize 转发与上限夹紧、snapshot 重放 + acknowledge、 无服务降级、missingTerminal → 换代号、onClose → close()。 - tests/builtins.spec.ts 内置清单 5 → 6,并新增「terminal-bottom 是 bottomOnly、其余内置都不是」。 - tests/chunk-artifact.spec.ts 新增产物包含性断言:chunk 里必须有 xterm(xterm-char-measure-element / @xterm/xterm/lib/xterm.js), lib/client.js 与 lib/client-registry.js 里一处都不许有。 - tests/e2e/mount.e2e.ts 第三条真实浏览器用例:先开原生右列(guide 基线 = 宿主 terminal 恰好 1 条)→ 展开底部工作台(data-active + 布局推挤 > 0)→ 点空面板的 Terminal 卡片 → 断言 tab 挂载、.xterm 在、chunk 有 响应、状态不停在 unavailable/loading、宿主 terminal 条目仍为 1 且 terminal-bottom 条目为 0、无 pageerror / 插件 console 错误。 依赖:@xterm/xterm@^6.0.0 + @xterm/addon-fit@^0.11.0(与宿主自用版本一致, 安装期零脚本,不触市场拒绝名单)。lockfile 只手工拼接这 2 个包的 4 个块: pnpm add 会顺手重解析无关 caret 范围,产出 99+/69- 的噪声 diff。
64 lines
2.4 KiB
JavaScript
64 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Assemble the plugin-registry installable root (`registry/`) from the built
|
|
* `lib/` output. Run after `pnpm build`:
|
|
*
|
|
* pnpm build
|
|
* node scripts/package-registry.mjs
|
|
* dsh registry install ./registry
|
|
* dsh registry enable dsh-external/dsh-better-sidebar
|
|
*
|
|
* The registry install copies the whole source directory (`cp -r`), so
|
|
* installing the repo root would drag in `node_modules/` (machine-local
|
|
* `link:` devDependency symlinks) and `.git/`. This
|
|
* staging directory carries exactly the files the manifest references plus
|
|
* the docs — same layout as the dsh-subagent-tree `registry/` pattern. It is
|
|
* gitignored and rebuilt from scratch on every run.
|
|
*/
|
|
import { cpSync, existsSync, mkdirSync, rmSync } from 'node:fs'
|
|
import { dirname, join, resolve } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const root = resolve(fileURLToPath(import.meta.url), '..', '..')
|
|
const out = join(root, 'registry')
|
|
|
|
/** Files copied into registry/, preserving relative paths (lib/ stays lib/). */
|
|
const files = [
|
|
'dsh.plugin.json',
|
|
'lib/index.js',
|
|
'lib/invariant.js',
|
|
'lib/client-registry.js',
|
|
'lib/client-registry.js.map',
|
|
// Lazy chunks: the client fetches these from the host's /sidebar/bundle
|
|
// route on first use (see src/client/chunk-loader.ts / src/bundle-route.ts).
|
|
// EVERY `CHUNK_NAMES` entry belongs here — the route reads the file out of
|
|
// the installed copy, so a chunk left out of this list 404s on the registry
|
|
// channel (`locale` was). tests/manifest-consistency.spec.ts guards the list
|
|
// against src/bundle-route.ts.
|
|
'lib/client-editor.js',
|
|
'lib/client-editor.js.map',
|
|
'lib/client-mermaid.js',
|
|
'lib/client-mermaid.js.map',
|
|
'lib/client-locale.js',
|
|
'lib/client-locale.js.map',
|
|
'lib/client-terminal.js',
|
|
'lib/client-terminal.js.map',
|
|
'README.md',
|
|
'LICENSE',
|
|
]
|
|
|
|
rmSync(out, { recursive: true, force: true })
|
|
mkdirSync(out, { recursive: true })
|
|
for (const file of files) {
|
|
const source = join(root, file)
|
|
if (!existsSync(source)) {
|
|
console.error(`missing ${file} — run \`pnpm build\` first`)
|
|
process.exit(1)
|
|
}
|
|
const target = join(out, file)
|
|
mkdirSync(dirname(target), { recursive: true })
|
|
cpSync(source, target)
|
|
}
|
|
console.log(`registry/ assembled (${files.length} files)`)
|
|
console.log('next: dsh registry install ./registry && dsh registry enable dsh-external/dsh-better-sidebar')
|