feat: add dev mode with DEV_ env prefix
Support dual configuration: PROXY_TOKEN/SERVER_URL for production, DEV_PROXY_TOKEN/DEV_SERVER_URL for local development. - npm start → production - npm run start:dev → dev (PROXY_MODE=dev) - npm run dev → dev with hot-reload - Restore PTY auto-creation on sync_state for existing chats Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
22
src/main.ts
22
src/main.ts
@ -23,15 +23,16 @@ import { existsSync, readdirSync, statSync, readFileSync } from 'fs';
|
||||
class ClaudeCliProxy {
|
||||
private ws: WsClient;
|
||||
private pty: PtyManager;
|
||||
private config: ReturnType<typeof loadConfig>;
|
||||
|
||||
constructor() {
|
||||
const config = loadConfig();
|
||||
this.config = loadConfig();
|
||||
|
||||
this.pty = new PtyManager();
|
||||
|
||||
this.ws = new WsClient({
|
||||
url: config.serverUrl,
|
||||
token: config.proxyToken,
|
||||
url: this.config.serverUrl,
|
||||
token: this.config.proxyToken,
|
||||
onMessage: (msg) => this.handleMessage(msg),
|
||||
onBinary: (data) => this.handleBinaryFrame(data),
|
||||
onConnected: () => this.onConnected(),
|
||||
@ -40,7 +41,8 @@ class ClaudeCliProxy {
|
||||
}
|
||||
|
||||
async start(): Promise<void> {
|
||||
console.log('[proxy] Starting claude-cli-proxy (xterm mode)...');
|
||||
const mode = this.config.isDev ? 'DEV' : 'PROD';
|
||||
console.log(`[proxy] Starting claude-cli-proxy (${mode}) → ${this.config.serverUrl}`);
|
||||
|
||||
this.ws.connect();
|
||||
|
||||
@ -114,15 +116,23 @@ class ClaudeCliProxy {
|
||||
const activePtys = new Set(this.pty.listPtys());
|
||||
const chatIds = new Set(payload.chats.map((c) => c.id));
|
||||
|
||||
// Only send replay + pty_ready for PTYs that already exist
|
||||
// Do NOT auto-create PTYs — they should only be created via explicit create_pty
|
||||
for (const chat of payload.chats) {
|
||||
if (activePtys.has(chat.id)) {
|
||||
// PTY exists — send replay + ready
|
||||
const replay = this.pty.getReplayBuffer(chat.id);
|
||||
if (replay) {
|
||||
this.ws.sendBinary(encodeBinaryFrame(DIR_PTY_OUTPUT, chat.id, replay));
|
||||
}
|
||||
this.ws.send({ type: 'pty_ready', payload: { chatId: chat.id } });
|
||||
} else if (chat.workDir) {
|
||||
// PTY not running — create it
|
||||
this.handleCreatePty({
|
||||
chatId: chat.id,
|
||||
dir: chat.workDir,
|
||||
resumeSessionId: chat.sessionId ?? undefined,
|
||||
cols: chat.cols ?? 120,
|
||||
rows: chat.rows ?? 40,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user