底部 + 菜单里开得出 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。
93 lines
2.0 KiB
CSS
93 lines
2.0 KiB
CSS
/*
|
|
* The bottom terminal's shell (src/client/TerminalView.tsx).
|
|
*
|
|
* Skin contract (guide §12): every declaration resolves to a `--dsw-*` /
|
|
* `--ds-*` token, and `color` never carries a literal — `tests/theme.spec.ts`
|
|
* enforces the second half mechanically. The screen element is also the token
|
|
* BRIDGE for xterm's own palette: the component reads its computed
|
|
* `background-color` / `color` / `font-family` back and hands those concrete
|
|
* values to the emulator, so a skin flip re-themes the terminal in place.
|
|
*/
|
|
|
|
.root {
|
|
display: flex;
|
|
flex: 1;
|
|
flex-direction: column;
|
|
box-sizing: border-box;
|
|
height: 100%;
|
|
min-height: 0;
|
|
color: var(--dsw-alias-label-primary);
|
|
}
|
|
|
|
.screen {
|
|
flex: 1;
|
|
min-width: 0;
|
|
min-height: 0;
|
|
padding: 8px;
|
|
overflow: hidden;
|
|
color: var(--dsw-alias-label-primary);
|
|
background: var(--dsw-alias-bg-base);
|
|
font-family: var(--ds-font-family-code, monospace);
|
|
}
|
|
|
|
.screen .xterm {
|
|
height: 100%;
|
|
}
|
|
|
|
.screen .xterm-viewport {
|
|
background: var(--dsw-alias-bg-base);
|
|
}
|
|
|
|
.status {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
gap: 8px;
|
|
padding: 5px 12px;
|
|
color: var(--dsw-alias-label-secondary, var(--dsw-alias-label-primary));
|
|
background: var(--dsw-alias-bg-l2);
|
|
}
|
|
|
|
.noticeBlock {
|
|
display: flex;
|
|
flex: 1;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 16px;
|
|
min-height: 0;
|
|
padding: 24px;
|
|
overflow: auto;
|
|
}
|
|
|
|
.notice {
|
|
max-width: 32ch;
|
|
margin: 0;
|
|
line-height: 1.6;
|
|
text-align: center;
|
|
overflow-wrap: anywhere;
|
|
color: var(--dsw-alias-label-primary);
|
|
}
|
|
|
|
.error {
|
|
margin: 0;
|
|
padding: 10px 12px;
|
|
overflow-wrap: anywhere;
|
|
color: var(--dsw-alias-label-primary);
|
|
background: var(--dsw-alias-bg-l2);
|
|
}
|
|
|
|
.action {
|
|
flex: none;
|
|
padding: 3px 10px;
|
|
border: 0.5px solid var(--dsw-alias-border-l4);
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
color: var(--dsw-alias-label-primary);
|
|
background: var(--dsw-alias-bg-layer-1);
|
|
}
|
|
|
|
.action:hover {
|
|
background: var(--dsw-alias-bg-l2);
|
|
}
|