@jingyi0605/codingns4dsh 0.1.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/README.md +1114 -0
- package/assets/provider-icons/claude-code.png +0 -0
- package/assets/provider-icons/codex.png +0 -0
- package/assets/provider-icons/command-code.svg +5 -0
- package/assets/provider-icons/deepseek-harness.svg +9 -0
- package/assets/provider-icons/gemini.png +0 -0
- package/assets/provider-icons/grok.png +0 -0
- package/assets/provider-icons/kimi.png +0 -0
- package/assets/provider-icons/opencode.png +0 -0
- package/assets/provider-icons/pi.svg +7 -0
- package/data/build/dist/bootstrap/dsh-connection-adapter.d.ts +97 -0
- package/data/build/dist/bootstrap/dsh-connection-adapter.js +169 -0
- package/data/build/dist/bootstrap/index.d.ts +38 -0
- package/data/build/dist/bootstrap/index.js +44 -0
- package/data/build/dist/client/account-bar.d.ts +9 -0
- package/data/build/dist/client/account-bar.js +398 -0
- package/data/build/dist/client/bundle.js +26167 -0
- package/data/build/dist/client/cli-catalog.d.ts +24 -0
- package/data/build/dist/client/cli-catalog.js +108 -0
- package/data/build/dist/client/cli-slots.d.ts +38 -0
- package/data/build/dist/client/cli-slots.js +297 -0
- package/data/build/dist/client/debug/ui.d.ts +12 -0
- package/data/build/dist/client/debug/ui.js +451 -0
- package/data/build/dist/client/dsh-h5-bootstrap.d.ts +64 -0
- package/data/build/dist/client/dsh-h5-bootstrap.js +293 -0
- package/data/build/dist/client/dsh-runtime-version.d.ts +3 -0
- package/data/build/dist/client/dsh-runtime-version.js +11 -0
- package/data/build/dist/client/external-tool-stream.d.ts +24 -0
- package/data/build/dist/client/external-tool-stream.js +114 -0
- package/data/build/dist/client/features/cli-adapters.d.ts +7 -0
- package/data/build/dist/client/features/cli-adapters.js +215 -0
- package/data/build/dist/client/features/debug.d.ts +4 -0
- package/data/build/dist/client/features/debug.js +24 -0
- package/data/build/dist/client/features/index.d.ts +33 -0
- package/data/build/dist/client/features/index.js +44 -0
- package/data/build/dist/client/features/lan-access-panel.d.ts +5 -0
- package/data/build/dist/client/features/lan-access-panel.js +146 -0
- package/data/build/dist/client/features/lan-access.d.ts +9 -0
- package/data/build/dist/client/features/lan-access.js +30 -0
- package/data/build/dist/client/features/login-protection-panel.d.ts +5 -0
- package/data/build/dist/client/features/login-protection-panel.js +91 -0
- package/data/build/dist/client/features/login-protection-session.d.ts +6 -0
- package/data/build/dist/client/features/login-protection-session.js +25 -0
- package/data/build/dist/client/features/login-protection.d.ts +4 -0
- package/data/build/dist/client/features/login-protection.js +23 -0
- package/data/build/dist/client/features/reverse-proxy-panel.d.ts +9 -0
- package/data/build/dist/client/features/reverse-proxy-panel.js +159 -0
- package/data/build/dist/client/features/reverse-proxy.d.ts +12 -0
- package/data/build/dist/client/features/reverse-proxy.js +112 -0
- package/data/build/dist/client/features/terminal-enhancement-panel.d.ts +5 -0
- package/data/build/dist/client/features/terminal-enhancement-panel.js +160 -0
- package/data/build/dist/client/features/terminal-enhancement.d.ts +4 -0
- package/data/build/dist/client/features/terminal-enhancement.js +24 -0
- package/data/build/dist/client/features/types.d.ts +58 -0
- package/data/build/dist/client/features/types.js +2 -0
- package/data/build/dist/client/features/workspace-session-enhancement-panel.d.ts +5 -0
- package/data/build/dist/client/features/workspace-session-enhancement-panel.js +66 -0
- package/data/build/dist/client/features/workspace-session-enhancement.d.ts +4 -0
- package/data/build/dist/client/features/workspace-session-enhancement.js +101 -0
- package/data/build/dist/client/h5-bootstrap-entry.d.ts +2 -0
- package/data/build/dist/client/h5-bootstrap-entry.js +17 -0
- package/data/build/dist/client/index.d.ts +31 -0
- package/data/build/dist/client/index.js +98 -0
- package/data/build/dist/client/lan-access.d.ts +28 -0
- package/data/build/dist/client/lan-access.js +68 -0
- package/data/build/dist/client/locale.d.ts +20 -0
- package/data/build/dist/client/locale.js +393 -0
- package/data/build/dist/client/provider-icon-assets.d.ts +2 -0
- package/data/build/dist/client/provider-icon-assets.js +23 -0
- package/data/build/dist/client/provider-icons.d.ts +19 -0
- package/data/build/dist/client/provider-icons.js +39 -0
- package/data/build/dist/client/remote-web-context.d.ts +57 -0
- package/data/build/dist/client/remote-web-context.js +939 -0
- package/data/build/dist/client/session-adapter-cache.d.ts +18 -0
- package/data/build/dist/client/session-adapter-cache.js +84 -0
- package/data/build/dist/client/settings-bridge.d.ts +32 -0
- package/data/build/dist/client/settings-bridge.js +126 -0
- package/data/build/dist/client/settings-section.d.ts +30 -0
- package/data/build/dist/client/settings-section.js +93 -0
- package/data/build/dist/client/subscription-slot.d.ts +18 -0
- package/data/build/dist/client/subscription-slot.js +223 -0
- package/data/build/dist/client/terminal/index.d.ts +4 -0
- package/data/build/dist/client/terminal/index.js +3 -0
- package/data/build/dist/client/terminal/model.d.ts +116 -0
- package/data/build/dist/client/terminal/model.js +435 -0
- package/data/build/dist/client/terminal/styles.d.ts +21 -0
- package/data/build/dist/client/terminal/styles.js +51 -0
- package/data/build/dist/client/terminal/ui.d.ts +19 -0
- package/data/build/dist/client/terminal/ui.js +257 -0
- package/data/build/dist/client/terminal/xterm-view.d.ts +13 -0
- package/data/build/dist/client/terminal/xterm-view.js +213 -0
- package/data/build/dist/client/theme.d.ts +56 -0
- package/data/build/dist/client/theme.js +186 -0
- package/data/build/dist/client/workspace-session-archive-dom.d.ts +29 -0
- package/data/build/dist/client/workspace-session-archive-dom.js +525 -0
- package/data/build/dist/client/workspace-session-fiber.d.ts +3 -0
- package/data/build/dist/client/workspace-session-fiber.js +33 -0
- package/data/build/dist/client/workspace-session-logo-dom.d.ts +26 -0
- package/data/build/dist/client/workspace-session-logo-dom.js +128 -0
- package/data/build/dist/features/index.d.ts +3 -0
- package/data/build/dist/features/index.js +2 -0
- package/data/build/dist/features/registry.d.ts +74 -0
- package/data/build/dist/features/registry.js +382 -0
- package/data/build/dist/features/resource-scope/index.d.ts +39 -0
- package/data/build/dist/features/resource-scope/index.js +161 -0
- package/data/build/dist/host/auth-session.d.ts +42 -0
- package/data/build/dist/host/auth-session.js +186 -0
- package/data/build/dist/host/cli-adapters/claude-driver.d.ts +14 -0
- package/data/build/dist/host/cli-adapters/claude-driver.js +103 -0
- package/data/build/dist/host/cli-adapters/codex-driver.d.ts +45 -0
- package/data/build/dist/host/cli-adapters/codex-driver.js +534 -0
- package/data/build/dist/host/cli-adapters/command-code-driver.d.ts +38 -0
- package/data/build/dist/host/cli-adapters/command-code-driver.js +394 -0
- package/data/build/dist/host/cli-adapters/command-code-subscription.d.ts +19 -0
- package/data/build/dist/host/cli-adapters/command-code-subscription.js +126 -0
- package/data/build/dist/host/cli-adapters/driver.d.ts +41 -0
- package/data/build/dist/host/cli-adapters/driver.js +2 -0
- package/data/build/dist/host/cli-adapters/dsh-message-projector.d.ts +37 -0
- package/data/build/dist/host/cli-adapters/dsh-message-projector.js +180 -0
- package/data/build/dist/host/cli-adapters/dsh-tool-history.d.ts +48 -0
- package/data/build/dist/host/cli-adapters/dsh-tool-history.js +373 -0
- package/data/build/dist/host/cli-adapters/feature.d.ts +7 -0
- package/data/build/dist/host/cli-adapters/feature.js +335 -0
- package/data/build/dist/host/cli-adapters/gemini-driver.d.ts +24 -0
- package/data/build/dist/host/cli-adapters/gemini-driver.js +427 -0
- package/data/build/dist/host/cli-adapters/grok-driver.d.ts +38 -0
- package/data/build/dist/host/cli-adapters/grok-driver.js +372 -0
- package/data/build/dist/host/cli-adapters/http-sse-client.d.ts +22 -0
- package/data/build/dist/host/cli-adapters/http-sse-client.js +99 -0
- package/data/build/dist/host/cli-adapters/interaction-events.d.ts +11 -0
- package/data/build/dist/host/cli-adapters/interaction-events.js +80 -0
- package/data/build/dist/host/cli-adapters/json-rpc-process.d.ts +65 -0
- package/data/build/dist/host/cli-adapters/json-rpc-process.js +256 -0
- package/data/build/dist/host/cli-adapters/kimi-driver.d.ts +21 -0
- package/data/build/dist/host/cli-adapters/kimi-driver.js +382 -0
- package/data/build/dist/host/cli-adapters/model-catalog.d.ts +22 -0
- package/data/build/dist/host/cli-adapters/model-catalog.js +89 -0
- package/data/build/dist/host/cli-adapters/opencode-driver.d.ts +55 -0
- package/data/build/dist/host/cli-adapters/opencode-driver.js +728 -0
- package/data/build/dist/host/cli-adapters/pi-driver.d.ts +43 -0
- package/data/build/dist/host/cli-adapters/pi-driver.js +312 -0
- package/data/build/dist/host/cli-adapters/process-utils.d.ts +16 -0
- package/data/build/dist/host/cli-adapters/process-utils.js +27 -0
- package/data/build/dist/host/cli-adapters/provider-subscription.d.ts +82 -0
- package/data/build/dist/host/cli-adapters/provider-subscription.js +610 -0
- package/data/build/dist/host/cli-adapters/registry.d.ts +95 -0
- package/data/build/dist/host/cli-adapters/registry.js +659 -0
- package/data/build/dist/host/cli-adapters/rpc-driver-utils.d.ts +24 -0
- package/data/build/dist/host/cli-adapters/rpc-driver-utils.js +119 -0
- package/data/build/dist/host/cli-adapters/session-probe.d.ts +20 -0
- package/data/build/dist/host/cli-adapters/session-probe.js +139 -0
- package/data/build/dist/host/cli-adapters/session-store.d.ts +68 -0
- package/data/build/dist/host/cli-adapters/session-store.js +180 -0
- package/data/build/dist/host/cli-adapters/standard-stream-driver.d.ts +45 -0
- package/data/build/dist/host/cli-adapters/standard-stream-driver.js +205 -0
- package/data/build/dist/host/cli-adapters/stream-normalizer.d.ts +25 -0
- package/data/build/dist/host/cli-adapters/stream-normalizer.js +83 -0
- package/data/build/dist/host/cli-adapters/tool-observation.d.ts +9 -0
- package/data/build/dist/host/cli-adapters/tool-observation.js +39 -0
- package/data/build/dist/host/control-api-client.d.ts +84 -0
- package/data/build/dist/host/control-api-client.js +130 -0
- package/data/build/dist/host/credential-store.d.ts +54 -0
- package/data/build/dist/host/credential-store.js +114 -0
- package/data/build/dist/host/debug.d.ts +79 -0
- package/data/build/dist/host/debug.js +295 -0
- package/data/build/dist/host/dsh-device-runtime.d.ts +39 -0
- package/data/build/dist/host/dsh-device-runtime.js +118 -0
- package/data/build/dist/host/dsh-gateway-feature.d.ts +5 -0
- package/data/build/dist/host/dsh-gateway-feature.js +55 -0
- package/data/build/dist/host/dsh-runtime-version.d.ts +12 -0
- package/data/build/dist/host/dsh-runtime-version.js +69 -0
- package/data/build/dist/host/features/auth.d.ts +11 -0
- package/data/build/dist/host/features/auth.js +273 -0
- package/data/build/dist/host/features/debug.d.ts +5 -0
- package/data/build/dist/host/features/debug.js +90 -0
- package/data/build/dist/host/features/host-status.d.ts +12 -0
- package/data/build/dist/host/features/host-status.js +54 -0
- package/data/build/dist/host/features/index.d.ts +19 -0
- package/data/build/dist/host/features/index.js +29 -0
- package/data/build/dist/host/features/lan-access-dsh.d.ts +8 -0
- package/data/build/dist/host/features/lan-access-dsh.js +45 -0
- package/data/build/dist/host/features/terminal-process.d.ts +5 -0
- package/data/build/dist/host/features/terminal-process.js +110 -0
- package/data/build/dist/host/features/terminal-status.d.ts +18 -0
- package/data/build/dist/host/features/terminal-status.js +56 -0
- package/data/build/dist/host/features/types.d.ts +41 -0
- package/data/build/dist/host/features/types.js +2 -0
- package/data/build/dist/host/index.d.ts +43 -0
- package/data/build/dist/host/index.js +135 -0
- package/data/build/dist/host/lan-access-dsh.d.ts +83 -0
- package/data/build/dist/host/lan-access-dsh.js +831 -0
- package/data/build/dist/host/native-session-bridge.d.ts +130 -0
- package/data/build/dist/host/native-session-bridge.js +317 -0
- package/data/build/dist/host/relay-tunnel-runtime.d.ts +97 -0
- package/data/build/dist/host/relay-tunnel-runtime.js +361 -0
- package/data/build/dist/host/remote-web-runtime.d.ts +78 -0
- package/data/build/dist/host/remote-web-runtime.js +559 -0
- package/data/build/dist/host/rpc-table.d.ts +32 -0
- package/data/build/dist/host/rpc-table.js +47 -0
- package/data/build/dist/host/rpc.d.ts +18 -0
- package/data/build/dist/host/rpc.js +248 -0
- package/data/build/dist/host/settings.d.ts +19 -0
- package/data/build/dist/host/settings.js +80 -0
- package/data/build/dist/host/terminal/attachment-registry.d.ts +17 -0
- package/data/build/dist/host/terminal/attachment-registry.js +49 -0
- package/data/build/dist/host/terminal/backends/conpty-backend.d.ts +39 -0
- package/data/build/dist/host/terminal/backends/conpty-backend.js +160 -0
- package/data/build/dist/host/terminal/backends/local-pty-backend.d.ts +36 -0
- package/data/build/dist/host/terminal/backends/local-pty-backend.js +178 -0
- package/data/build/dist/host/terminal/backends/tmux-backend.d.ts +40 -0
- package/data/build/dist/host/terminal/backends/tmux-backend.js +191 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-client.d.ts +27 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-client.js +154 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-process.d.ts +10 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-process.js +147 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-protocol.d.ts +92 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-protocol.js +134 -0
- package/data/build/dist/host/terminal/controller-factory.d.ts +37 -0
- package/data/build/dist/host/terminal/controller-factory.js +82 -0
- package/data/build/dist/host/terminal/index.d.ts +17 -0
- package/data/build/dist/host/terminal/index.js +17 -0
- package/data/build/dist/host/terminal/runtime-adapter.d.ts +77 -0
- package/data/build/dist/host/terminal/runtime-adapter.js +18 -0
- package/data/build/dist/host/terminal/runtime-manager.d.ts +41 -0
- package/data/build/dist/host/terminal/runtime-manager.js +179 -0
- package/data/build/dist/host/terminal/shell-detection.d.ts +23 -0
- package/data/build/dist/host/terminal/shell-detection.js +105 -0
- package/data/build/dist/host/terminal/startup.d.ts +33 -0
- package/data/build/dist/host/terminal/startup.js +100 -0
- package/data/build/dist/host/terminal/terminal-controller.d.ts +78 -0
- package/data/build/dist/host/terminal/terminal-controller.js +324 -0
- package/data/build/dist/host/terminal/terminal-process-service.d.ts +30 -0
- package/data/build/dist/host/terminal/terminal-process-service.js +194 -0
- package/data/build/dist/host/terminal/terminal-process-store.d.ts +45 -0
- package/data/build/dist/host/terminal/terminal-process-store.js +183 -0
- package/data/build/dist/host/terminal/terminal-service.d.ts +87 -0
- package/data/build/dist/host/terminal/terminal-service.js +528 -0
- package/data/build/dist/host/terminal/terminal-store.d.ts +49 -0
- package/data/build/dist/host/terminal/terminal-store.js +242 -0
- package/data/build/dist/index.d.ts +37 -0
- package/data/build/dist/index.js +26 -0
- package/data/build/dist/shared/contracts/auth.d.ts +122 -0
- package/data/build/dist/shared/contracts/auth.js +8 -0
- package/data/build/dist/shared/contracts/cli-adapter.d.ts +192 -0
- package/data/build/dist/shared/contracts/cli-adapter.js +2 -0
- package/data/build/dist/shared/contracts/command-code.d.ts +5 -0
- package/data/build/dist/shared/contracts/command-code.js +2 -0
- package/data/build/dist/shared/contracts/config.d.ts +113 -0
- package/data/build/dist/shared/contracts/config.js +86 -0
- package/data/build/dist/shared/contracts/debug-config.d.ts +28 -0
- package/data/build/dist/shared/contracts/debug-config.js +78 -0
- package/data/build/dist/shared/contracts/debug.d.ts +75 -0
- package/data/build/dist/shared/contracts/debug.js +121 -0
- package/data/build/dist/shared/contracts/dsh-device.d.ts +72 -0
- package/data/build/dist/shared/contracts/dsh-device.js +2 -0
- package/data/build/dist/shared/contracts/errors.d.ts +33 -0
- package/data/build/dist/shared/contracts/errors.js +41 -0
- package/data/build/dist/shared/contracts/feature.d.ts +71 -0
- package/data/build/dist/shared/contracts/feature.js +2 -0
- package/data/build/dist/shared/contracts/host-status.d.ts +14 -0
- package/data/build/dist/shared/contracts/host-status.js +2 -0
- package/data/build/dist/shared/contracts/lan-access-dsh.d.ts +30 -0
- package/data/build/dist/shared/contracts/lan-access-dsh.js +2 -0
- package/data/build/dist/shared/contracts/peer-host.d.ts +37 -0
- package/data/build/dist/shared/contracts/peer-host.js +9 -0
- package/data/build/dist/shared/contracts/signaling.d.ts +67 -0
- package/data/build/dist/shared/contracts/signaling.js +2 -0
- package/data/build/dist/shared/contracts/subscription.d.ts +69 -0
- package/data/build/dist/shared/contracts/subscription.js +2 -0
- package/data/build/dist/shared/contracts/terminal-process.d.ts +65 -0
- package/data/build/dist/shared/contracts/terminal-process.js +2 -0
- package/data/build/dist/shared/contracts/terminal.d.ts +127 -0
- package/data/build/dist/shared/contracts/terminal.js +2 -0
- package/data/build/dist/shared/contracts/transport.d.ts +45 -0
- package/data/build/dist/shared/contracts/transport.js +3 -0
- package/data/build/dist/shared/contracts/version.d.ts +19 -0
- package/data/build/dist/shared/contracts/version.js +74 -0
- package/data/build/dist/shared/index.d.ts +22 -0
- package/data/build/dist/shared/index.js +9 -0
- package/data/build/dist/transport/carrier.d.ts +38 -0
- package/data/build/dist/transport/carrier.js +268 -0
- package/data/build/dist/transport/debug.d.ts +22 -0
- package/data/build/dist/transport/debug.js +57 -0
- package/data/build/dist/transport/dsh-envelope.d.ts +41 -0
- package/data/build/dist/transport/dsh-envelope.js +107 -0
- package/data/build/dist/transport/dsh-gateway.d.ts +64 -0
- package/data/build/dist/transport/dsh-gateway.js +254 -0
- package/data/build/dist/transport/dsh-session.d.ts +55 -0
- package/data/build/dist/transport/dsh-session.js +256 -0
- package/data/build/dist/transport/dsh-transport.d.ts +57 -0
- package/data/build/dist/transport/dsh-transport.js +125 -0
- package/data/build/dist/transport/frame.d.ts +132 -0
- package/data/build/dist/transport/frame.js +168 -0
- package/data/build/dist/transport/index.d.ts +11 -0
- package/data/build/dist/transport/index.js +11 -0
- package/data/build/dist/transport/multiplexer.d.ts +63 -0
- package/data/build/dist/transport/multiplexer.js +323 -0
- package/data/build/dist/transport/webrtc-client.d.ts +65 -0
- package/data/build/dist/transport/webrtc-client.js +255 -0
- package/data/build/dist/transport/webrtc-host.d.ts +58 -0
- package/data/build/dist/transport/webrtc-host.js +252 -0
- package/data/build/dist/typert.host.d.ts +25 -0
- package/data/build/dist/typert.host.js +150 -0
- package/dsh.bundle.patch +12 -0
- package/package.json +135 -0
- package/profile/README.md +27 -0
- package/profile/cordis.patch.yml +2 -0
- package/profile/package.json +20 -0
- package/profile/scripts/check-dsh-install.mjs +71 -0
- package/profile/version.json +5 -0
- package/scripts/check-dsh-install.mjs +88 -0
- package/version.json +6 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
const STORE_VERSION = 1;
|
|
4
|
+
export class JsonFileTerminalProcessStorePersistence {
|
|
5
|
+
filename;
|
|
6
|
+
constructor(filename) {
|
|
7
|
+
this.filename = filename;
|
|
8
|
+
}
|
|
9
|
+
async load() {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(await readFile(this.filename, 'utf8'));
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (isMissingFile(error))
|
|
15
|
+
return { version: STORE_VERSION, profiles: [], instances: [] };
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async save(document) {
|
|
20
|
+
const directory = dirname(this.filename);
|
|
21
|
+
const temporary = `${this.filename}.${process.pid}.tmp`;
|
|
22
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
23
|
+
await writeFile(temporary, `${JSON.stringify(document, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
24
|
+
await rename(temporary, this.filename);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class InMemoryTerminalProcessStorePersistence {
|
|
28
|
+
document;
|
|
29
|
+
constructor(initial = { version: STORE_VERSION, profiles: [], instances: [] }) {
|
|
30
|
+
this.document = structuredClone(initial);
|
|
31
|
+
}
|
|
32
|
+
async load() { return structuredClone(this.document); }
|
|
33
|
+
async save(document) { this.document = structuredClone(document); }
|
|
34
|
+
}
|
|
35
|
+
export class TerminalProcessStore {
|
|
36
|
+
persistence;
|
|
37
|
+
profiles = new Map();
|
|
38
|
+
instances = new Map();
|
|
39
|
+
writeTail = Promise.resolve();
|
|
40
|
+
loaded = false;
|
|
41
|
+
constructor(persistence) {
|
|
42
|
+
this.persistence = persistence;
|
|
43
|
+
}
|
|
44
|
+
async load() {
|
|
45
|
+
if (this.loaded)
|
|
46
|
+
return;
|
|
47
|
+
const document = parseDocument(await this.persistence.load());
|
|
48
|
+
this.profiles = new Map(document.profiles.map((profile) => [profileKey(profile), cloneProfile(profile)]));
|
|
49
|
+
this.instances = new Map(document.instances.map((instance) => [instanceKey(instance), cloneInstance(instance)]));
|
|
50
|
+
this.loaded = true;
|
|
51
|
+
}
|
|
52
|
+
getProfile(workspaceId, profileId) {
|
|
53
|
+
this.requireLoaded();
|
|
54
|
+
const profile = this.profiles.get(JSON.stringify([workspaceId, profileId]));
|
|
55
|
+
return profile === undefined ? undefined : cloneProfile(profile);
|
|
56
|
+
}
|
|
57
|
+
listProfiles(workspaceId) {
|
|
58
|
+
this.requireLoaded();
|
|
59
|
+
return [...this.profiles.values()]
|
|
60
|
+
.filter((profile) => workspaceId === undefined || profile.workspaceId === workspaceId)
|
|
61
|
+
.map(cloneProfile);
|
|
62
|
+
}
|
|
63
|
+
putProfile(profile) {
|
|
64
|
+
this.requireLoaded();
|
|
65
|
+
return this.enqueue(async () => {
|
|
66
|
+
this.profiles.set(profileKey(profile), cloneProfile(profile));
|
|
67
|
+
await this.persist();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
deleteProfile(workspaceId, profileId) {
|
|
71
|
+
this.requireLoaded();
|
|
72
|
+
return this.enqueue(async () => {
|
|
73
|
+
const deleted = this.profiles.delete(JSON.stringify([workspaceId, profileId]));
|
|
74
|
+
if (deleted)
|
|
75
|
+
await this.persist();
|
|
76
|
+
return deleted;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
getInstance(instanceId) {
|
|
80
|
+
this.requireLoaded();
|
|
81
|
+
const instance = this.instances.get(instanceId);
|
|
82
|
+
return instance === undefined ? undefined : cloneInstance(instance);
|
|
83
|
+
}
|
|
84
|
+
listInstances(workspaceId) {
|
|
85
|
+
this.requireLoaded();
|
|
86
|
+
return [...this.instances.values()]
|
|
87
|
+
.filter((instance) => workspaceId === undefined || instance.workspaceId === workspaceId)
|
|
88
|
+
.sort((left, right) => (left.startedAt ?? '').localeCompare(right.startedAt ?? ''))
|
|
89
|
+
.map(cloneInstance);
|
|
90
|
+
}
|
|
91
|
+
putInstance(instance) {
|
|
92
|
+
this.requireLoaded();
|
|
93
|
+
return this.enqueue(async () => {
|
|
94
|
+
this.instances.set(instance.id, cloneInstance(instance));
|
|
95
|
+
await this.persist();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
enqueue(operation) {
|
|
99
|
+
const pending = this.writeTail.then(operation, operation);
|
|
100
|
+
this.writeTail = pending.then(() => undefined, () => undefined);
|
|
101
|
+
return pending;
|
|
102
|
+
}
|
|
103
|
+
async persist() {
|
|
104
|
+
await this.persistence.save({
|
|
105
|
+
version: STORE_VERSION,
|
|
106
|
+
profiles: [...this.profiles.values()],
|
|
107
|
+
instances: [...this.instances.values()],
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
requireLoaded() {
|
|
111
|
+
if (!this.loaded)
|
|
112
|
+
throw new Error('终端进程存储尚未加载');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function parseDocument(value) {
|
|
116
|
+
if (!isRecord(value) || value.version !== STORE_VERSION || !Array.isArray(value.profiles) || !Array.isArray(value.instances)) {
|
|
117
|
+
throw new TypeError('终端进程存储格式无效');
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
version: STORE_VERSION,
|
|
121
|
+
profiles: value.profiles.map(parseProfile),
|
|
122
|
+
instances: value.instances.map(parseInstance),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function parseProfile(value) {
|
|
126
|
+
if (!isRecord(value))
|
|
127
|
+
throw new TypeError('终端启动项必须是对象');
|
|
128
|
+
const profile = value;
|
|
129
|
+
validateProfile(profile);
|
|
130
|
+
return cloneProfile(profile);
|
|
131
|
+
}
|
|
132
|
+
function parseInstance(value) {
|
|
133
|
+
if (!isRecord(value))
|
|
134
|
+
throw new TypeError('终端进程实例必须是对象');
|
|
135
|
+
const instance = value;
|
|
136
|
+
validateInstance(instance);
|
|
137
|
+
return cloneInstance(instance);
|
|
138
|
+
}
|
|
139
|
+
export function validateProfile(profile) {
|
|
140
|
+
for (const [name, value] of [['id', profile.id], ['workspaceId', profile.workspaceId], ['name', profile.name], ['command', profile.command], ['createdAt', profile.createdAt], ['updatedAt', profile.updatedAt]]) {
|
|
141
|
+
if (typeof value !== 'string' || value.trim() === '')
|
|
142
|
+
throw new TypeError(`终端启动项字段 ${name} 无效`);
|
|
143
|
+
}
|
|
144
|
+
if (!isRelativePath(profile.cwdRelative))
|
|
145
|
+
throw new TypeError('终端启动项 cwdRelative 必须是 Workspace 内相对路径');
|
|
146
|
+
if (!Array.isArray(profile.args) || profile.args.some((value) => typeof value !== 'string'))
|
|
147
|
+
throw new TypeError('终端启动项 args 无效');
|
|
148
|
+
if (!isRecord(profile.env) || Object.entries(profile.env).some(([key, value]) => key.trim() === '' || typeof value !== 'string'))
|
|
149
|
+
throw new TypeError('终端启动项 env 无效');
|
|
150
|
+
if (Object.keys(profile.env).some(isSecretEnvironmentName))
|
|
151
|
+
throw new TypeError('终端启动项不能持久化 TOKEN、SECRET、PASSWORD 或 KEY 环境变量');
|
|
152
|
+
if (profile.runtimeMode !== 'pty')
|
|
153
|
+
throw new TypeError('当前终端启动器只支持 runtimeMode=pty');
|
|
154
|
+
if (!Number.isSafeInteger(profile.revision) || profile.revision < 1)
|
|
155
|
+
throw new TypeError('终端启动项 revision 无效');
|
|
156
|
+
}
|
|
157
|
+
function validateInstance(instance) {
|
|
158
|
+
for (const [name, value] of [['id', instance.id], ['workspaceId', instance.workspaceId], ['profileId', instance.profileId], ['terminalId', instance.terminalId]]) {
|
|
159
|
+
if (typeof value !== 'string' || value.trim() === '')
|
|
160
|
+
throw new TypeError(`终端进程实例字段 ${name} 无效`);
|
|
161
|
+
}
|
|
162
|
+
if (!['starting', 'running', 'stopping', 'exited', 'failed', 'lost'].includes(instance.state))
|
|
163
|
+
throw new TypeError('终端进程实例 state 无效');
|
|
164
|
+
if (instance.pid !== null && (!Number.isSafeInteger(instance.pid) || instance.pid < 1))
|
|
165
|
+
throw new TypeError('终端进程实例 pid 无效');
|
|
166
|
+
if (instance.runtimeSessionKey !== null && typeof instance.runtimeSessionKey !== 'string')
|
|
167
|
+
throw new TypeError('终端进程实例 runtimeSessionKey 无效');
|
|
168
|
+
if (!isRecord(instance.resolvedCommand) || typeof instance.resolvedCommand.command !== 'string' || !Array.isArray(instance.resolvedCommand.args) || typeof instance.resolvedCommand.cwd !== 'string')
|
|
169
|
+
throw new TypeError('终端进程实例 resolvedCommand 无效');
|
|
170
|
+
}
|
|
171
|
+
function cloneProfile(profile) {
|
|
172
|
+
return { ...profile, args: [...profile.args], env: { ...profile.env }, shell: { ...profile.shell, args: [...profile.shell.args] } };
|
|
173
|
+
}
|
|
174
|
+
function cloneInstance(instance) {
|
|
175
|
+
return { ...instance, resolvedCommand: { ...instance.resolvedCommand, args: [...instance.resolvedCommand.args] } };
|
|
176
|
+
}
|
|
177
|
+
function profileKey(profile) { return JSON.stringify([profile.workspaceId, profile.id]); }
|
|
178
|
+
function instanceKey(instance) { return instance.id; }
|
|
179
|
+
function isRelativePath(value) { return value === '.' || (value.trim() !== '' && !value.startsWith('/') && !/^[A-Za-z]:[\\/]/u.test(value) && value !== '..' && !value.startsWith('../') && !value.includes('/../') && !value.includes('\\..')); }
|
|
180
|
+
function isSecretEnvironmentName(value) { return /(?:TOKEN|SECRET|PASSWORD|PRIVATE_KEY|API_KEY)/iu.test(value); }
|
|
181
|
+
function isRecord(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); }
|
|
182
|
+
function isMissingFile(error) { return isRecord(error) && error.code === 'ENOENT'; }
|
|
183
|
+
//# sourceMappingURL=terminal-process-store.js.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { CodingNsTerminalFrame, CodingNsTerminalRuntimeType, CodingNsTerminalShell, CodingNsWebTerminalInfo, PersistentTerminalRecord, TerminalOwnerScope, TerminalRecordIdentity } from '../../shared/contracts/terminal.js';
|
|
2
|
+
import type { TerminalRuntimeManager } from './runtime-manager.js';
|
|
3
|
+
import type { CodingNsTerminalStore } from './terminal-store.js';
|
|
4
|
+
export interface CreatePersistentTerminalInput {
|
|
5
|
+
readonly scope: TerminalOwnerScope;
|
|
6
|
+
readonly terminalId: string;
|
|
7
|
+
readonly runtimeType: CodingNsTerminalRuntimeType;
|
|
8
|
+
readonly shell: CodingNsTerminalShell;
|
|
9
|
+
/** 可选的业务标题;普通终端未提供时使用 Shell 名称。 */
|
|
10
|
+
readonly title?: string;
|
|
11
|
+
readonly commandPath?: string;
|
|
12
|
+
readonly commandArgs?: readonly string[];
|
|
13
|
+
readonly commandEnv?: Readonly<Record<string, string>>;
|
|
14
|
+
readonly launchProfileId?: string;
|
|
15
|
+
readonly cwd: string;
|
|
16
|
+
readonly cols: number;
|
|
17
|
+
readonly rows: number;
|
|
18
|
+
/** 仅保存在当前 Host 内存中的运行时退出通知,不进入终端持久记录。 */
|
|
19
|
+
readonly onExit?: (exitCode: number | null) => void | Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export interface FollowPersistentTerminalInput {
|
|
22
|
+
readonly identity: TerminalRecordIdentity;
|
|
23
|
+
readonly attachmentId: string;
|
|
24
|
+
readonly generation: string;
|
|
25
|
+
readonly signal: AbortSignal;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 持久终端生命周期服务。
|
|
29
|
+
*
|
|
30
|
+
* store 决定“终端是什么”,runtime manager 决定“当前如何连上它”。插件停用时
|
|
31
|
+
* dispose 只释放后者;只有 close 会调用 backend.terminate。
|
|
32
|
+
*/
|
|
33
|
+
export declare class CodingNsTerminalService {
|
|
34
|
+
private readonly store;
|
|
35
|
+
private readonly runtimes;
|
|
36
|
+
private readonly now;
|
|
37
|
+
private readonly controllers;
|
|
38
|
+
private readonly followers;
|
|
39
|
+
private readonly operations;
|
|
40
|
+
private readonly exitCallbacks;
|
|
41
|
+
private initialized;
|
|
42
|
+
constructor(store: CodingNsTerminalStore, runtimes: TerminalRuntimeManager, now?: () => Date);
|
|
43
|
+
initialize(): Promise<void>;
|
|
44
|
+
list(scope: TerminalOwnerScope): readonly CodingNsWebTerminalInfo[];
|
|
45
|
+
/** 兼容旧调用名;真正的持久归属只按 Host + workspace 查询。 */
|
|
46
|
+
listSession(hostId: string, dshSessionId: string, workspaceId?: string): readonly CodingNsWebTerminalInfo[];
|
|
47
|
+
listWorkspace(hostId: string, workspaceId: string): readonly CodingNsWebTerminalInfo[];
|
|
48
|
+
findIdentity(hostId: string, dshSessionId: string, terminalId: string, workspaceId?: string): TerminalRecordIdentity;
|
|
49
|
+
create(input: CreatePersistentTerminalInput): Promise<CodingNsWebTerminalInfo>;
|
|
50
|
+
/** 返回 Host 侧完整记录,供进程服务读取 runtimeSessionKey 和运行身份。 */
|
|
51
|
+
getRecord(identity: TerminalRecordIdentity): PersistentTerminalRecord | undefined;
|
|
52
|
+
inspect(identity: TerminalRecordIdentity): Promise<import("./runtime-adapter.js").TerminalRuntimeIdentity>;
|
|
53
|
+
recover(): Promise<void>;
|
|
54
|
+
retain(identity: TerminalRecordIdentity, signal: AbortSignal): AsyncIterable<{
|
|
55
|
+
type: 'retained';
|
|
56
|
+
}>;
|
|
57
|
+
follow(input: FollowPersistentTerminalInput): AsyncIterable<CodingNsTerminalFrame>;
|
|
58
|
+
write(identity: TerminalRecordIdentity, attachmentId: string, data: string): Promise<void>;
|
|
59
|
+
/** Host 内部向持久终端发送一次输入,不改变浏览器 attach 控制权。 */
|
|
60
|
+
writeInitialInput(identity: TerminalRecordIdentity, data: string): Promise<void>;
|
|
61
|
+
resize(identity: TerminalRecordIdentity, attachmentId: string, cols: number, rows: number): Promise<void>;
|
|
62
|
+
rename(identity: TerminalRecordIdentity, title: string): Promise<void>;
|
|
63
|
+
close(identity: TerminalRecordIdentity): Promise<void>;
|
|
64
|
+
detachGeneration(generation: string): Promise<void>;
|
|
65
|
+
/** 插件卸载只断开 attach,持久 backend 必须继续运行。 */
|
|
66
|
+
dispose(): Promise<void>;
|
|
67
|
+
private requireController;
|
|
68
|
+
private requireAvailable;
|
|
69
|
+
private refreshRuntimeState;
|
|
70
|
+
private handleRuntimeExit;
|
|
71
|
+
private markExited;
|
|
72
|
+
private info;
|
|
73
|
+
private update;
|
|
74
|
+
private broadcastState;
|
|
75
|
+
private broadcastStateByKey;
|
|
76
|
+
private addFollower;
|
|
77
|
+
private removeFollower;
|
|
78
|
+
private finishFollowers;
|
|
79
|
+
private enqueue;
|
|
80
|
+
private requireInitialized;
|
|
81
|
+
}
|
|
82
|
+
export type TerminalServiceErrorCode = 'TERMINAL_UNAVAILABLE' | 'TERMINAL_CONTROL_UNAVAILABLE' | 'TERMINAL_RUNTIME_LOST';
|
|
83
|
+
export declare class TerminalServiceError extends Error {
|
|
84
|
+
readonly code: TerminalServiceErrorCode;
|
|
85
|
+
constructor(code: TerminalServiceErrorCode, message: string);
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=terminal-service.d.ts.map
|