dsh-bash-terminal-ts 0.8.8 → 0.9.1

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +205 -190
  2. package/CHANGELOG.pt.md +151 -0
  3. package/README.de.md +1 -1
  4. package/README.en.md +3 -2
  5. package/README.es.md +1 -1
  6. package/README.fr.md +1 -1
  7. package/README.it.md +1 -1
  8. package/README.md +4 -3
  9. package/README.pt.md +212 -0
  10. package/README.ru.md +1 -1
  11. package/agent-presets/README.md +171 -170
  12. package/agent-presets/install-presets.mjs +180 -179
  13. package/agent-presets/standard-win-niu/agent.cordis.yml +271 -0
  14. package/agent-presets/standard-win-niu/preset.yml +2 -0
  15. package/cordis.patch.yml +84 -83
  16. package/dist/client.core.js +59 -2
  17. package/dist/client.js +59 -2
  18. package/docs/dsh-plugin-development.md +169 -0
  19. package/docs/niu-backend.md +197 -0
  20. package/dsh.plugin.json +4 -3
  21. package/lib/client.js +59 -2
  22. package/lib/dsh-types.d.ts +14 -2
  23. package/lib/index.d.ts +15 -2
  24. package/lib/index.js +43 -5
  25. package/lib/locales.js +59 -2
  26. package/lib/shell-id.d.ts +1 -1
  27. package/lib/shells.d.ts +1 -0
  28. package/lib/shells.js +8 -2
  29. package/lib/terminal.js +4 -0
  30. package/lib/webterminals/host.js +2 -2
  31. package/lib/webterminals/mount.js +1 -0
  32. package/locale/de.json +6 -6
  33. package/locale/en.json +6 -6
  34. package/locale/es.json +6 -6
  35. package/locale/fr.json +6 -6
  36. package/locale/it.json +6 -6
  37. package/locale/ja.json +6 -6
  38. package/locale/ko.json +6 -6
  39. package/locale/pt.json +6 -0
  40. package/locale/ru.json +6 -6
  41. package/locale/zh.json +6 -6
  42. package/package.json +153 -149
  43. package/scripts/check-artifacts.mjs +96 -96
  44. package/src/client.tsx +685 -685
  45. package/src/dsh-types.ts +332 -320
  46. package/src/index.ts +1316 -1275
  47. package/src/locales.ts +509 -452
  48. package/src/shell-id.ts +11 -11
  49. package/src/shells.ts +279 -272
  50. package/src/terminal.ts +616 -612
  51. package/src/webterminals/host.ts +361 -361
  52. package/src/webterminals/mount.ts +237 -236
package/locale/ja.json CHANGED
@@ -1,6 +1,6 @@
1
- {
2
- "meta": {
3
- "title": "下部ターミナル",
4
- "description": "shell ツールと下部ドックの埋め込みターミナル(PowerShell / Git Bash / MSYS2 / WSL)。shell 単位の有効化スイッチと既定 shell の代替チェーン付き。"
5
- }
6
- }
1
+ {
2
+ "meta": {
3
+ "title": "下部ターミナル",
4
+ "description": "shell ツールと下部ドックの埋め込みターミナル(PowerShell / Git Bash / MSYS2 / WSL / Niubash)。shell 単位の有効化スイッチと既定 shell の代替チェーン付き。"
5
+ }
6
+ }
package/locale/ko.json CHANGED
@@ -1,6 +1,6 @@
1
- {
2
- "meta": {
3
- "title": "하단 터미널",
4
- "description": "shell 도구와 하단 독의 내장 터미널(PowerShell / Git Bash / MSYS2 / WSL). shell별 활성화 스위치와 기본 shell 대체 체인을 제공합니다."
5
- }
6
- }
1
+ {
2
+ "meta": {
3
+ "title": "하단 터미널",
4
+ "description": "shell 도구와 하단 독의 내장 터미널(PowerShell / Git Bash / MSYS2 / WSL / Niubash). shell별 활성화 스위치와 기본 shell 대체 체인을 제공합니다."
5
+ }
6
+ }
package/locale/pt.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Terminal inferior",
4
+ "description": "A ferramenta shell e o terminal embutido do painel inferior (PowerShell / Git Bash / MSYS2 / WSL / Niubash), com chaves de ativação por shell e cadeia de fallback do shell padrão."
5
+ }
6
+ }
package/locale/ru.json CHANGED
@@ -1,6 +1,6 @@
1
- {
2
- "meta": {
3
- "title": "Нижний терминал",
4
- "description": "Инструмент shell и встроенный терминал нижней панели (PowerShell / Git Bash / MSYS2 / WSL) с активацией по оболочкам и цепочкой замещения."
5
- }
6
- }
1
+ {
2
+ "meta": {
3
+ "title": "Нижний терминал",
4
+ "description": "Инструмент shell и встроенный терминал нижней панели (PowerShell / Git Bash / MSYS2 / WSL / Niubash) с активацией по оболочкам и цепочкой замещения."
5
+ }
6
+ }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
- {
2
- "meta": {
3
- "title": "底部终端",
4
- "description": "shell 工具与底部工作台终端(PowerShell / Git Bash / MSYS2 / WSL),带激活开关与默认 shell 回落链。"
5
- }
6
- }
1
+ {
2
+ "meta": {
3
+ "title": "底部终端",
4
+ "description": "shell 工具与底部工作台终端(PowerShell / Git Bash / MSYS2 / WSL / Niubash),带激活开关与默认 shell 回落链。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,149 +1,153 @@
1
- {
2
- "name": "dsh-bash-terminal-ts",
3
- "version": "0.8.8",
4
- "publishConfig": {
5
- "tag": "latest"
6
- },
7
- "description": "DSH plugin: one shell tool that runs commands through PowerShell, Git Bash, MSYS2, or WSL on Windows, plus an embedded terminal for the bottom dock (dsh-better-sidebar's terminal tab) with per-shell activation switches and a default-shell fallback chain.",
8
- "author": "drscrewdriver",
9
- "license": "MIT",
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/drscrewdriver/dsh-bash-terminal-ts.git"
13
- },
14
- "bugs": {
15
- "url": "https://github.com/drscrewdriver/dsh-bash-terminal-ts/issues"
16
- },
17
- "homepage": "https://github.com/drscrewdriver/dsh-bash-terminal-ts#readme",
18
- "keywords": [
19
- "deepseek-harness",
20
- "dsh",
21
- "plugin",
22
- "terminal",
23
- "terminal-ui",
24
- "bottom-dock",
25
- "shell",
26
- "powershell",
27
- "git-bash",
28
- "wsl",
29
- "windows",
30
- "typescript"
31
- ],
32
- "engines": {
33
- "node": ">=22",
34
- "dsh": ">=0.1.0-rc.2 <0.3.0-0"
35
- },
36
- "type": "module",
37
- "main": "lib/index.js",
38
- "exports": {
39
- ".": "./lib/index.js",
40
- "./client": "./lib/client.js",
41
- "./locale/*.json": "./locale/*.json",
42
- "./package.json": "./package.json"
43
- },
44
- "files": [
45
- "lib",
46
- "dist",
47
- "src",
48
- "scripts",
49
- "template",
50
- "agent-presets",
51
- "locale",
52
- "tsconfig.json",
53
- "tsconfig.client.json",
54
- "tsconfig.test.json",
55
- "README.md",
56
- "README.en.md",
57
- "README.de.md",
58
- "README.fr.md",
59
- "README.it.md",
60
- "README.ru.md",
61
- "README.es.md",
62
- "CHANGELOG.de.md",
63
- "CHANGELOG.fr.md",
64
- "CHANGELOG.it.md",
65
- "CHANGELOG.ru.md",
66
- "CHANGELOG.es.md",
67
- "LICENSE",
68
- "CHANGELOG.md",
69
- "cordis.patch.yml",
70
- "dsh.plugin.json",
71
- "screenshots.json"
72
- ],
73
- "scripts": {
74
- "build": "tsc -p tsconfig.json && tsc -p tsconfig.client.json && node scripts/build-client.mjs && tsc -p tsconfig.test.json && node scripts/build-browser-tests.mjs && node scripts/check-artifacts.mjs",
75
- "check:artifacts": "node scripts/check-artifacts.mjs",
76
- "prepack": "npm run build",
77
- "build:client": "node scripts/build-client.mjs",
78
- "test": "node test-dist/unit.js && node test-dist/apply.js && node test-dist/client.js && node test-dist/terminal.js && node test-dist/shells.js && node test-dist/webterminals.js && node test/browser.mjs",
79
- "lint": "eslint .",
80
- "link:shells": "node scripts/link-shells.mjs",
81
- "payload:provision": "node scripts/provision-payload.mjs",
82
- "presets:install": "node agent-presets/install-presets.mjs"
83
- },
84
- "dsh": {
85
- "bundle": {
86
- "patch": "./cordis.patch.yml"
87
- },
88
- "client": {
89
- "platform": "web",
90
- "immediately": true,
91
- "inject": [
92
- "@deepseek-ai/dsh-client-locale"
93
- ]
94
- }
95
- },
96
- "optionalDependencies": {
97
- "@drscrewdriver/posix-runtime-win32-x64": "0.1.2"
98
- },
99
- "peerDependencies": {
100
- "@deepseek-ai/cordis": "^4.0.2",
101
- "@deepseek-ai/dsh-client-locale": ">=0.1.0-rc.2 <0.3.0-0",
102
- "@deepseek-ai/dsh-client-ui-slots": ">=0.1.0-rc.2 <0.3.0-0",
103
- "@deepseek-ai/dsh-llm": ">=0.1.0-rc.2 <0.3.0-0",
104
- "@deepseek-ai/dsh-sandbox": ">=0.1.0-rc.2 <0.3.0-0",
105
- "@deepseek-ai/dsh-settings": ">=0.1.0-rc.2 <0.3.0-0",
106
- "@deepseek-ai/dsh-shell": ">=0.1.0-rc.2 <0.3.0-0",
107
- "@deepseek-ai/dsh-timeout": ">=0.1.0-rc.2 <0.3.0-0",
108
- "@deepseek-ai/dsh-tools": ">=0.1.0-rc.2 <0.3.0-0",
109
- "react": "^18.2.0"
110
- },
111
- "dependencies": {
112
- "@deepseek-ai/schemastery": "^3.18.4",
113
- "@xterm/addon-fit": "^0.10.0",
114
- "@xterm/xterm": "^5.5.0",
115
- "node-pty": "1.2.0-beta.15",
116
- "ws": "^8.18.0"
117
- },
118
- "devDependencies": {
119
- "@deepseek-ai/cordis": "^4.0.2",
120
- "@deepseek-ai/dsh-client-locale": "0.2.0-rc.1",
121
- "@deepseek-ai/dsh-client-store": "0.2.0-rc.1",
122
- "@deepseek-ai/dsh-client-ui-primitives": "0.2.0-rc.1",
123
- "@deepseek-ai/dsh-client-ui-settings": "0.2.0-rc.1",
124
- "@deepseek-ai/dsh-client-ui-slots": "0.2.0-rc.1",
125
- "@deepseek-ai/dsh-http-proxy": "0.2.0-rc.1",
126
- "@deepseek-ai/dsh-llm": "0.2.0-rc.1",
127
- "@deepseek-ai/dsh-sandbox": "0.2.0-rc.1",
128
- "@deepseek-ai/dsh-sandbox-policy": "0.2.0-rc.1",
129
- "@deepseek-ai/dsh-scope": "0.2.0-rc.1",
130
- "@deepseek-ai/dsh-settings": "0.2.0-rc.1",
131
- "@deepseek-ai/dsh-shell": "0.2.0-rc.1",
132
- "@deepseek-ai/dsh-subprocess": "0.2.0-rc.1",
133
- "@deepseek-ai/dsh-timeout": "0.2.0-rc.1",
134
- "@deepseek-ai/dsh-tools": "0.2.0-rc.1",
135
- "@eslint/js": "^10.0.1",
136
- "@types/node": "^22.10.0",
137
- "@types/react": "^18.2.0",
138
- "@types/react-dom": "^18.2.0",
139
- "@types/ws": "^8.5.13",
140
- "esbuild": "^0.28.2",
141
- "eslint": "^10.11.0",
142
- "eslint-plugin-react-hooks": "^7.1.1",
143
- "globals": "^17.12.0",
144
- "react": "^18.2.0",
145
- "react-dom": "^18.2.0",
146
- "typescript": "^5.9.0",
147
- "typescript-eslint": "^8.71.0"
148
- }
149
- }
1
+ {
2
+ "name": "dsh-bash-terminal-ts",
3
+ "version": "0.9.1",
4
+ "publishConfig": {
5
+ "registry": "https://registry.npmjs.org",
6
+ "tag": "latest"
7
+ },
8
+ "description": "DSH plugin: one shell tool that runs commands through PowerShell, Git Bash, MSYS2, WSL or Niubash on Windows, plus an embedded terminal for the bottom dock (dsh-better-sidebar's terminal tab) with per-shell activation switches and a default-shell fallback chain.",
9
+ "author": "drscrewdriver",
10
+ "license": "MIT",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/drscrewdriver/dsh-bash-terminal-ts.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/drscrewdriver/dsh-bash-terminal-ts/issues"
17
+ },
18
+ "homepage": "https://github.com/drscrewdriver/dsh-bash-terminal-ts#readme",
19
+ "keywords": [
20
+ "deepseek-harness",
21
+ "dsh",
22
+ "plugin",
23
+ "terminal",
24
+ "terminal-ui",
25
+ "bottom-dock",
26
+ "shell",
27
+ "powershell",
28
+ "git-bash",
29
+ "wsl",
30
+ "windows",
31
+ "typescript"
32
+ ],
33
+ "engines": {
34
+ "node": ">=22",
35
+ "dsh": ">=0.1.0-rc.2 <0.3.0-0"
36
+ },
37
+ "type": "module",
38
+ "main": "lib/index.js",
39
+ "exports": {
40
+ ".": "./lib/index.js",
41
+ "./client": "./lib/client.js",
42
+ "./locale/*.json": "./locale/*.json",
43
+ "./package.json": "./package.json"
44
+ },
45
+ "files": [
46
+ "lib",
47
+ "dist",
48
+ "src",
49
+ "scripts",
50
+ "template",
51
+ "agent-presets",
52
+ "docs",
53
+ "locale",
54
+ "tsconfig.json",
55
+ "tsconfig.client.json",
56
+ "tsconfig.test.json",
57
+ "README.md",
58
+ "README.en.md",
59
+ "README.de.md",
60
+ "README.fr.md",
61
+ "README.it.md",
62
+ "README.ru.md",
63
+ "README.es.md",
64
+ "README.pt.md",
65
+ "CHANGELOG.de.md",
66
+ "CHANGELOG.fr.md",
67
+ "CHANGELOG.it.md",
68
+ "CHANGELOG.ru.md",
69
+ "CHANGELOG.es.md",
70
+ "CHANGELOG.pt.md",
71
+ "LICENSE",
72
+ "CHANGELOG.md",
73
+ "cordis.patch.yml",
74
+ "dsh.plugin.json",
75
+ "screenshots.json"
76
+ ],
77
+ "scripts": {
78
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.client.json && node scripts/build-client.mjs && tsc -p tsconfig.test.json && node scripts/build-browser-tests.mjs && node scripts/check-artifacts.mjs",
79
+ "check:artifacts": "node scripts/check-artifacts.mjs",
80
+ "prepack": "npm run build",
81
+ "build:client": "node scripts/build-client.mjs",
82
+ "test": "node test-dist/unit.js && node test-dist/apply.js && node test-dist/client.js && node test-dist/terminal.js && node test-dist/shells.js && node test-dist/webterminals.js && node test/browser.mjs",
83
+ "lint": "eslint .",
84
+ "link:shells": "node scripts/link-shells.mjs",
85
+ "payload:provision": "node scripts/provision-payload.mjs",
86
+ "presets:install": "node agent-presets/install-presets.mjs"
87
+ },
88
+ "dsh": {
89
+ "bundle": {
90
+ "patch": "./cordis.patch.yml"
91
+ },
92
+ "client": {
93
+ "platform": "web",
94
+ "immediately": true,
95
+ "inject": [
96
+ "@deepseek-ai/dsh-client-locale"
97
+ ]
98
+ }
99
+ },
100
+ "optionalDependencies": {
101
+ "@drscrewdriver/posix-runtime-win32-x64": "0.1.2"
102
+ },
103
+ "peerDependencies": {
104
+ "@deepseek-ai/cordis": "^4.0.2",
105
+ "@deepseek-ai/dsh-client-locale": ">=0.1.0-rc.2 <0.3.0-0",
106
+ "@deepseek-ai/dsh-client-ui-slots": ">=0.1.0-rc.2 <0.3.0-0",
107
+ "@deepseek-ai/dsh-llm": ">=0.1.0-rc.2 <0.3.0-0",
108
+ "@deepseek-ai/dsh-sandbox": ">=0.1.0-rc.2 <0.3.0-0",
109
+ "@deepseek-ai/dsh-settings": ">=0.1.0-rc.2 <0.3.0-0",
110
+ "@deepseek-ai/dsh-shell": ">=0.1.0-rc.2 <0.3.0-0",
111
+ "@deepseek-ai/dsh-timeout": ">=0.1.0-rc.2 <0.3.0-0",
112
+ "@deepseek-ai/dsh-tools": ">=0.1.0-rc.2 <0.3.0-0",
113
+ "react": "^18.2.0"
114
+ },
115
+ "dependencies": {
116
+ "@deepseek-ai/schemastery": "^3.18.4",
117
+ "@xterm/addon-fit": "^0.10.0",
118
+ "@xterm/xterm": "^5.5.0",
119
+ "node-pty": "1.2.0-beta.15",
120
+ "ws": "^8.18.0"
121
+ },
122
+ "devDependencies": {
123
+ "@deepseek-ai/cordis": "^4.0.2",
124
+ "@deepseek-ai/dsh-client-locale": "0.2.0-rc.1",
125
+ "@deepseek-ai/dsh-client-store": "0.2.0-rc.1",
126
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.0-rc.1",
127
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.0-rc.1",
128
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.0-rc.1",
129
+ "@deepseek-ai/dsh-http-proxy": "0.2.0-rc.1",
130
+ "@deepseek-ai/dsh-llm": "0.2.0-rc.1",
131
+ "@deepseek-ai/dsh-sandbox": "0.2.0-rc.1",
132
+ "@deepseek-ai/dsh-sandbox-policy": "0.2.0-rc.1",
133
+ "@deepseek-ai/dsh-scope": "0.2.0-rc.1",
134
+ "@deepseek-ai/dsh-settings": "0.2.0-rc.1",
135
+ "@deepseek-ai/dsh-shell": "0.2.0-rc.1",
136
+ "@deepseek-ai/dsh-subprocess": "0.2.0-rc.1",
137
+ "@deepseek-ai/dsh-timeout": "0.2.0-rc.1",
138
+ "@deepseek-ai/dsh-tools": "0.2.0-rc.1",
139
+ "@eslint/js": "^10.0.1",
140
+ "@types/node": "^22.10.0",
141
+ "@types/react": "^18.2.0",
142
+ "@types/react-dom": "^18.2.0",
143
+ "@types/ws": "^8.5.13",
144
+ "esbuild": "^0.28.2",
145
+ "eslint": "^10.11.0",
146
+ "eslint-plugin-react-hooks": "^7.1.1",
147
+ "globals": "^17.12.0",
148
+ "react": "^18.2.0",
149
+ "react-dom": "^18.2.0",
150
+ "typescript": "^5.9.0",
151
+ "typescript-eslint": "^8.71.0"
152
+ }
153
+ }
@@ -1,96 +1,96 @@
1
- // Artifact gates: the checks that only make sense against the BUILT bundle.
2
- //
3
- // Unit tests cannot see these. Every one of them is a failure mode that ships
4
- // green through `tsc` and then dies silently in the browser:
5
- //
6
- // - `__ModuleLoader__.load({ id })` must equal the package name, or the host never
7
- // binds the client half and the whole UI side goes dark without an error;
8
- // - the client bundle must carry no Node builtins (the browser has none, and a
9
- // leaked `node:` import is a runtime `require is not defined`);
10
- // - `ws` must stay an EXTERNAL import in the host bundle: bundling it pulls
11
- // `buffer`/`net` into a browser-shaped artifact and breaks the PTY socket;
12
- // - `locale/en.json` is the anchor the host's package-meta scan insists on, so all
13
- // nine files have to be present in the tarball list.
14
-
15
- import { readdirSync, readFileSync } from "node:fs";
16
- import assert from "node:assert";
17
-
18
- const pkg = JSON.parse(readFileSync("package.json", "utf8"));
19
- const bundle = readFileSync("lib/client.js", "utf8");
20
- const host = readFileSync("lib/webterminals/ws.js", "utf8");
21
-
22
- // 1) the loader identity.
23
- const idMatch = /id:\s*"([^"]+)"/.exec(bundle);
24
- assert.ok(idMatch, "the client bundle wraps itself in __ModuleLoader__.load({ id })");
25
- assert.strictEqual(idMatch[1], pkg.name, "the client bundle id equals the package name");
26
-
27
- // 2) client purity.
28
- const leaks = ["node:crypto", "node:stream", "node:http", "node:fs", "node:path", "node:os", "string_decoder", "WebSocketServer"].filter((needle) => bundle.includes(needle));
29
- assert.deepStrictEqual(leaks, [], `the client bundle must carry no Node-only module: ${leaks.join(", ")}`);
30
-
31
- // 3) ws stays external on the host side.
32
- assert.ok(/from "ws"/.test(host) || /require\("ws"\)/.test(host), "the host socket module imports ws as an external dependency");
33
-
34
- // 4) the nine metadata files the host scans, with en as the anchor.
35
- const langs = ["zh", "en", "ja", "ko", "fr", "de", "it", "ru", "es"];
36
- for (const lang of langs) {
37
- const parsed = JSON.parse(readFileSync(`locale/${lang}.json`, "utf8"));
38
- // locale 元数据落成 `{ meta: { title, description } }`(gen-locale-meta 的产物形状);
39
- // 兼容旧的根级平铺形状,避免误报。
40
- const meta = parsed.meta ?? parsed;
41
- assert.ok(typeof meta.title === "string" && meta.title.length > 0, `locale/${lang}.json needs a title`);
42
- assert.ok(typeof meta.description === "string" && meta.description.length > 0, `locale/${lang}.json needs a description`);
43
- }
44
-
45
- // 5) the client dictionary really ships nine languages, keyed identically to zh.
46
- const locales = readFileSync("lib/locales.js", "utf8");
47
- const registered = /dictionaries\s*=\s*\{([^}]*)\}/.exec(locales)?.[1] ?? "";
48
- for (const lang of langs) {
49
- assert.ok(new RegExp(`\\b${lang}\\b`).test(registered), `lib/locales.js registers ${lang}`);
50
- }
51
-
52
- // 6) the multi-shell bottom tab ships, and xterm is INSIDE the bundle.
53
- //
54
- // Three failure modes worth a gate each. Registering the tab without `bottomOnly`
55
- // turns it into a second "Terminal" capsule in DSH's native right sidebar, shadowing
56
- // the host's. Leaving xterm EXTERNAL cannot work at all - the client module table
57
- // resolves only seed words, shell-owned modules, registered factories and boot
58
- // modules, and a live desktop host answered `require("@xterm/xterm")` with "missed the
59
- // module table" - so the gate now asserts the opposite of what it did, with the
60
- // emulator's own DOM marker as the witness. And the ceiling catches the reverse drift:
61
- // a second heavyweight dependency creeping in unannounced.
62
- assert.ok(bundle.includes("dsh-bash-terminal-ts:multi"), "the multi-shell tab id is in the client bundle");
63
- assert.ok(bundle.includes("bottomOnly"), "the tab declares itself bottom-workbench only");
64
- assert.ok(bundle.includes("xterm-helper-textarea"), "xterm is bundled (an external require cannot resolve in the client module table)");
65
- assert.ok(!/require\("@xterm\/xterm"\)/.test(bundle), "no external @xterm require survives in the bundle");
66
- assert.ok(bundle.includes("xterm-screen"), "xterm's stylesheet is inlined as text");
67
- assert.ok(bundle.length < 900_000, `the client bundle did not grow unexpectedly: ${bundle.length} bytes`);
68
-
69
- // 7) no dead copy: every dictionary key must be referenced by something that renders.
70
- //
71
- // A key defined in nine languages and read by nobody is not a spare string - it is a
72
- // feature that was planned, translated, and never wired (this family shipped exactly
73
- // that once: a `notice.standsDown` key with no renderer, and here a seven-language
74
- // dictionary the component bypassed by reading `zh[...]` directly).
75
- //
76
- // Checked against the SOURCES, not the bundle: the dictionary itself is bundled, so a
77
- // bundle substring test would match every key against its own definition and pass
78
- // forever. Concatenated keys (`"shell." + id`) are covered by the prefix below.
79
- //
80
- // The consumer set walks the browser directory rather than listing files: a key moved
81
- // into a new component used to read as dead copy here, which is the wrong lesson to
82
- // teach whoever split the file up.
83
- const consumerFiles = [
84
- "src/client.tsx",
85
- "src/browser-i18n.ts",
86
- ...readdirSync("src/webterminals/browser", { recursive: true }).map((rel) => `src/webterminals/browser/${String(rel)}`),
87
- ];
88
- const consumers = consumerFiles.map((rel) => readFileSync(rel, "utf8"));
89
- const zhKeys = [...new Set([...locales.matchAll(/"((?:shell|dock|tab)\.[A-Za-z0-9.]+)"\s*:/g)].map((match) => match[1]))];
90
- assert.ok(zhKeys.length >= 30, `expected the full key set in lib/locales.js, found ${zhKeys.length}`);
91
- const unusedKeys = zhKeys.filter((key) => !consumers.some((text) => text.includes(`"${key}"`)));
92
- // `shell.<id>` is built by concatenation in the preference row, so those are wired.
93
- const trulyUnused = unusedKeys.filter((key) => !/^shell\.(powershell|gitbash|msys2|wsl|payload)$/.test(key));
94
- assert.deepStrictEqual(trulyUnused, [], `dictionary keys rendered by nothing: ${trulyUnused.join(", ")}`);
95
-
96
- console.log(`ARTIFACT GATES PASS: id=${idMatch[1]} | client ${(bundle.length / 1024).toFixed(0)}KB, no node leaks, xterm bundled, css inlined | ws external | ${langs.length} locale files | ${zhKeys.length} dictionary keys, none dead`);
1
+ // Artifact gates: the checks that only make sense against the BUILT bundle.
2
+ //
3
+ // Unit tests cannot see these. Every one of them is a failure mode that ships
4
+ // green through `tsc` and then dies silently in the browser:
5
+ //
6
+ // - `__ModuleLoader__.load({ id })` must equal the package name, or the host never
7
+ // binds the client half and the whole UI side goes dark without an error;
8
+ // - the client bundle must carry no Node builtins (the browser has none, and a
9
+ // leaked `node:` import is a runtime `require is not defined`);
10
+ // - `ws` must stay an EXTERNAL import in the host bundle: bundling it pulls
11
+ // `buffer`/`net` into a browser-shaped artifact and breaks the PTY socket;
12
+ // - `locale/en.json` is the anchor the host's package-meta scan insists on, so all
13
+ // ten files have to be present in the tarball list.
14
+
15
+ import { readdirSync, readFileSync } from "node:fs";
16
+ import assert from "node:assert";
17
+
18
+ const pkg = JSON.parse(readFileSync("package.json", "utf8"));
19
+ const bundle = readFileSync("lib/client.js", "utf8");
20
+ const host = readFileSync("lib/webterminals/ws.js", "utf8");
21
+
22
+ // 1) the loader identity.
23
+ const idMatch = /id:\s*"([^"]+)"/.exec(bundle);
24
+ assert.ok(idMatch, "the client bundle wraps itself in __ModuleLoader__.load({ id })");
25
+ assert.strictEqual(idMatch[1], pkg.name, "the client bundle id equals the package name");
26
+
27
+ // 2) client purity.
28
+ const leaks = ["node:crypto", "node:stream", "node:http", "node:fs", "node:path", "node:os", "string_decoder", "WebSocketServer"].filter((needle) => bundle.includes(needle));
29
+ assert.deepStrictEqual(leaks, [], `the client bundle must carry no Node-only module: ${leaks.join(", ")}`);
30
+
31
+ // 3) ws stays external on the host side.
32
+ assert.ok(/from "ws"/.test(host) || /require\("ws"\)/.test(host), "the host socket module imports ws as an external dependency");
33
+
34
+ // 4) the ten metadata files the host scans, with en as the anchor.
35
+ const langs = ["zh", "en", "ja", "ko", "fr", "de", "it", "ru", "es", "pt"];
36
+ for (const lang of langs) {
37
+ const parsed = JSON.parse(readFileSync(`locale/${lang}.json`, "utf8"));
38
+ // locale 元数据落成 `{ meta: { title, description } }`(gen-locale-meta 的产物形状);
39
+ // 兼容旧的根级平铺形状,避免误报。
40
+ const meta = parsed.meta ?? parsed;
41
+ assert.ok(typeof meta.title === "string" && meta.title.length > 0, `locale/${lang}.json needs a title`);
42
+ assert.ok(typeof meta.description === "string" && meta.description.length > 0, `locale/${lang}.json needs a description`);
43
+ }
44
+
45
+ // 5) the client dictionary really ships ten languages, keyed identically to zh.
46
+ const locales = readFileSync("lib/locales.js", "utf8");
47
+ const registered = /dictionaries\s*=\s*\{([^}]*)\}/.exec(locales)?.[1] ?? "";
48
+ for (const lang of langs) {
49
+ assert.ok(new RegExp(`\\b${lang}\\b`).test(registered), `lib/locales.js registers ${lang}`);
50
+ }
51
+
52
+ // 6) the multi-shell bottom tab ships, and xterm is INSIDE the bundle.
53
+ //
54
+ // Three failure modes worth a gate each. Registering the tab without `bottomOnly`
55
+ // turns it into a second "Terminal" capsule in DSH's native right sidebar, shadowing
56
+ // the host's. Leaving xterm EXTERNAL cannot work at all - the client module table
57
+ // resolves only seed words, shell-owned modules, registered factories and boot
58
+ // modules, and a live desktop host answered `require("@xterm/xterm")` with "missed the
59
+ // module table" - so the gate now asserts the opposite of what it did, with the
60
+ // emulator's own DOM marker as the witness. And the ceiling catches the reverse drift:
61
+ // a second heavyweight dependency creeping in unannounced.
62
+ assert.ok(bundle.includes("dsh-bash-terminal-ts:multi"), "the multi-shell tab id is in the client bundle");
63
+ assert.ok(bundle.includes("bottomOnly"), "the tab declares itself bottom-workbench only");
64
+ assert.ok(bundle.includes("xterm-helper-textarea"), "xterm is bundled (an external require cannot resolve in the client module table)");
65
+ assert.ok(!/require\("@xterm\/xterm"\)/.test(bundle), "no external @xterm require survives in the bundle");
66
+ assert.ok(bundle.includes("xterm-screen"), "xterm's stylesheet is inlined as text");
67
+ assert.ok(bundle.length < 900_000, `the client bundle did not grow unexpectedly: ${bundle.length} bytes`);
68
+
69
+ // 7) no dead copy: every dictionary key must be referenced by something that renders.
70
+ //
71
+ // A key defined in ten languages and read by nobody is not a spare string - it is a
72
+ // feature that was planned, translated, and never wired (this family shipped exactly
73
+ // that once: a `notice.standsDown` key with no renderer, and here a seven-language
74
+ // dictionary the component bypassed by reading `zh[...]` directly).
75
+ //
76
+ // Checked against the SOURCES, not the bundle: the dictionary itself is bundled, so a
77
+ // bundle substring test would match every key against its own definition and pass
78
+ // forever. Concatenated keys (`"shell." + id`) are covered by the prefix below.
79
+ //
80
+ // The consumer set walks the browser directory rather than listing files: a key moved
81
+ // into a new component used to read as dead copy here, which is the wrong lesson to
82
+ // teach whoever split the file up.
83
+ const consumerFiles = [
84
+ "src/client.tsx",
85
+ "src/browser-i18n.ts",
86
+ ...readdirSync("src/webterminals/browser", { recursive: true }).map((rel) => `src/webterminals/browser/${String(rel)}`),
87
+ ];
88
+ const consumers = consumerFiles.map((rel) => readFileSync(rel, "utf8"));
89
+ const zhKeys = [...new Set([...locales.matchAll(/"((?:shell|dock|tab)\.[A-Za-z0-9.]+)"\s*:/g)].map((match) => match[1]))];
90
+ assert.ok(zhKeys.length >= 30, `expected the full key set in lib/locales.js, found ${zhKeys.length}`);
91
+ const unusedKeys = zhKeys.filter((key) => !consumers.some((text) => text.includes(`"${key}"`)));
92
+ // `shell.<id>` is built by concatenation in the preference row, so those are wired.
93
+ const trulyUnused = unusedKeys.filter((key) => !/^shell\.(powershell|gitbash|msys2|wsl|payload|niu)$/.test(key));
94
+ assert.deepStrictEqual(trulyUnused, [], `dictionary keys rendered by nothing: ${trulyUnused.join(", ")}`);
95
+
96
+ console.log(`ARTIFACT GATES PASS: id=${idMatch[1]} | client ${(bundle.length / 1024).toFixed(0)}KB, no node leaks, xterm bundled, css inlined | ws external | ${langs.length} locale files | ${zhKeys.length} dictionary keys, none dead`);