feat: open local runtime clients from the composer
Add composer shortcuts for local Continue and OpenCode terminals and the official DeepSeek Harness Web client, using the current project and model bridge. Manage browser service reuse, stop actions and terminal cleanup. Upgrade DeepSeek Harness to 0.1.7-rc.2 and Cordis to 4.0.4. Include the coordinated IPC handler extraction and related tests and documentation. Remote native-client coordinator wiring, managed Node consolidation, Ask MCP mappings and full desktop/package acceptance remain unfinished; this commit records the implemented local workflow and supporting SSH groundwork. Validation: typecheck and lint passed; 267 focused tests passed and 5 skipped. No new real-provider calls were made for this commit. Prior real-model evidence and remaining acceptance work are documented in the feature progress files. Release note: 本地项目选择 Continue 或 OpenCode 后,可从输入框下方打开原生终端;选择 DS 后,可打开使用当前项目和模型的官方 Web 客户端。客户端使用独立会话,DS 网页关闭后服务继续运行,可在 GoodBuddy 中停止;远程入口尚未完成。
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { createHmac, getCiphers, randomBytes } from "node:crypto";
|
||||
import { connect as connectLoopback, type Socket } from "node:net";
|
||||
import { Client } from "ssh2";
|
||||
import type { ClientChannel, ConnectConfig, SFTPWrapper } from "ssh2";
|
||||
import {
|
||||
@@ -69,12 +70,18 @@ export type SshTerminalShellOptions = {
|
||||
cols: number;
|
||||
rows: number;
|
||||
term?: string;
|
||||
/** Main-generated native launch, not part of the renderer terminal contract. */
|
||||
command?: string;
|
||||
pty?: false;
|
||||
};
|
||||
|
||||
export type SshLoopbackForward = { port: number; close(): Promise<void> };
|
||||
|
||||
export interface AuthenticatedSshConnection {
|
||||
readonly identity: SshPoolConnectionIdentity;
|
||||
isUsable(): boolean;
|
||||
onDisconnect(listener: (error?: Error) => void): () => void;
|
||||
forwardLoopback(localPort: number): Promise<SshLoopbackForward>;
|
||||
openTerminalShell(
|
||||
options: SshTerminalShellOptions,
|
||||
signal?: AbortSignal,
|
||||
@@ -170,7 +177,7 @@ type InternalSshConnectionLease = SshTerminalConnectionLease &
|
||||
|
||||
type ClientLike = Pick<
|
||||
Client,
|
||||
"connect" | "end" | "destroy" | "exec" | "shell" | "sftp" | "on" | "once"
|
||||
"connect" | "end" | "destroy" | "exec" | "shell" | "sftp" | "on" | "once" | "removeListener" | "forwardIn" | "unforwardIn"
|
||||
>;
|
||||
|
||||
type SshConnectionDependencies = {
|
||||
@@ -468,20 +475,58 @@ export class Ssh2AuthenticatedConnection implements AuthenticatedSshConnection {
|
||||
finish(new Error("SSH 终端通道打开超时"));
|
||||
}, CHANNEL_OPEN_TIMEOUT_MS);
|
||||
signal?.addEventListener("abort", abort, { once: true });
|
||||
this.client.shell(
|
||||
{
|
||||
const pty = {
|
||||
term: options.term ?? "xterm-256color",
|
||||
cols: options.cols,
|
||||
rows: options.rows,
|
||||
width: 0,
|
||||
height: 0,
|
||||
},
|
||||
{ env: {}, x11: false },
|
||||
(error, channel) => finish(error, channel),
|
||||
);
|
||||
};
|
||||
if (options.command) {
|
||||
this.client.exec(options.command, { pty: options.pty === false ? false : pty, env: {}, x11: false }, (error, channel) => finish(error, channel));
|
||||
} else {
|
||||
this.client.shell(pty, { env: {}, x11: false }, (error, channel) => finish(error, channel));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async forwardLoopback(localPort: number): Promise<SshLoopbackForward> {
|
||||
this.assertUsable();
|
||||
const port = await new Promise<number>((resolve, reject) => {
|
||||
this.client.forwardIn("127.0.0.1", 0, (error, allocated) => error ? reject(error) : resolve(allocated));
|
||||
});
|
||||
const streams = new Set<Socket | ClientChannel>();
|
||||
const acceptConnection = (details: { destPort: number }, accept: () => ClientChannel): void => {
|
||||
if (details.destPort !== port) return;
|
||||
const remote = accept();
|
||||
const local = connectLoopback({ host: "127.0.0.1", port: localPort });
|
||||
streams.add(remote);
|
||||
streams.add(local);
|
||||
const close = (): void => {
|
||||
streams.delete(remote);
|
||||
streams.delete(local);
|
||||
remote.destroy();
|
||||
local.destroy();
|
||||
};
|
||||
remote.once("error", close);
|
||||
local.once("error", close);
|
||||
remote.once("close", close);
|
||||
local.once("close", close);
|
||||
remote.pipe(local).pipe(remote);
|
||||
};
|
||||
this.client.on("tcp connection", acceptConnection);
|
||||
let closing: Promise<void> | undefined;
|
||||
const removeDisconnect = this.onDisconnect(() => { void close(); });
|
||||
const close = (): Promise<void> => closing ??= (async () => {
|
||||
removeDisconnect();
|
||||
this.client.removeListener("tcp connection", acceptConnection);
|
||||
for (const stream of streams) stream.destroy();
|
||||
streams.clear();
|
||||
if (this.isUsable()) await new Promise<void>(resolve => this.client.unforwardIn("127.0.0.1", port, () => resolve()));
|
||||
})();
|
||||
return { port, close };
|
||||
}
|
||||
|
||||
async openAgentAttach(
|
||||
installationId: VerifiedAgentInstallationId,
|
||||
signal?: AbortSignal,
|
||||
@@ -1023,6 +1068,10 @@ export class SshConnectionPool {
|
||||
assertActive();
|
||||
return connection.openTerminalShell(options, signal);
|
||||
},
|
||||
forwardLoopback: (localPort) => {
|
||||
assertActive();
|
||||
return connection.forwardLoopback(localPort);
|
||||
},
|
||||
openAgentAttach: (installationId, signal) => {
|
||||
assertActive();
|
||||
return connection.openAgentAttach(installationId, signal);
|
||||
|
||||
Reference in New Issue
Block a user