@phenx-inc/ctlsurf 0.1.12 → 0.1.15

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 (25) hide show
  1. package/out/headless/index.mjs +1 -1
  2. package/out/headless/index.mjs.map +1 -1
  3. package/out/main/index.js +1 -1
  4. package/out/renderer/assets/{cssMode-CY6x0qXW.js → cssMode-woG3Vtms.js} +3 -3
  5. package/out/renderer/assets/{freemarker2-BXSW9BAX.js → freemarker2-DgtqmvCd.js} +1 -1
  6. package/out/renderer/assets/{handlebars-BYUZ1IOs.js → handlebars-YEqC-zOn.js} +1 -1
  7. package/out/renderer/assets/{html-DPocQM4t.js → html-CwvkGxeB.js} +1 -1
  8. package/out/renderer/assets/{htmlMode-CsPinKYA.js → htmlMode-DzdyF21q.js} +3 -3
  9. package/out/renderer/assets/{index-Bml7oDn9.js → index-CpDga7fF.js} +44 -31
  10. package/out/renderer/assets/{javascript-_HVGB-lj.js → javascript-Dy9cX9Fu.js} +2 -2
  11. package/out/renderer/assets/{jsonMode-JbrRQBOU.js → jsonMode-CPhJ_ION.js} +3 -3
  12. package/out/renderer/assets/{liquid-B7izKdqo.js → liquid-BJdFPWrv.js} +1 -1
  13. package/out/renderer/assets/{lspLanguageFeatures-DzxH499X.js → lspLanguageFeatures-BMM3SRX4.js} +1 -1
  14. package/out/renderer/assets/{mdx-CmvUeYLw.js → mdx-kg2kuPRK.js} +1 -1
  15. package/out/renderer/assets/{python-DJqYTFoi.js → python-aIrmxkmH.js} +1 -1
  16. package/out/renderer/assets/{razor-CGEA5nUK.js → razor-DdymcPOc.js} +1 -1
  17. package/out/renderer/assets/{tsMode-CN0FOHMy.js → tsMode-D7kqIJ_o.js} +1 -1
  18. package/out/renderer/assets/{typescript-CIn-DSfY.js → typescript-Cq3g-z7h.js} +1 -1
  19. package/out/renderer/assets/{xml-C5t3U2jS.js → xml-BuBP5jOc.js} +1 -1
  20. package/out/renderer/assets/{yaml-n-Jb6xf1.js → yaml-B-3hWmol.js} +1 -1
  21. package/out/renderer/index.html +1 -1
  22. package/package.json +1 -1
  23. package/src/main/bridge.ts +1 -1
  24. package/src/renderer/App.tsx +12 -0
  25. package/src/renderer/components/TerminalPanel.tsx +4 -1
@@ -231,7 +231,7 @@ var ConversationBridge = class {
231
231
  sessionActive = false;
232
232
  inputBuffer = "";
233
233
  outputBuffer = "";
234
- FLUSH_BYTES = 2e3;
234
+ FLUSH_BYTES = 500;
235
235
  setWsClient(ws) {
236
236
  this.wsClient = ws;
237
237
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../node_modules/electron/index.js", "../../src/main/orchestrator.ts", "../../src/main/pty.ts", "../../src/main/agents.ts", "../../src/main/ctlsurfApi.ts", "../../src/main/bridge.ts", "../../src/main/workerWs.ts", "../../src/main/settingsDir.ts", "../../src/main/tui.ts", "../../src/main/headless.ts"],
4
- "sourcesContent": ["const fs = require('fs');\nconst path = require('path');\n\nconst pathFile = path.join(__dirname, 'path.txt');\n\nfunction getElectronPath () {\n let executablePath;\n if (fs.existsSync(pathFile)) {\n executablePath = fs.readFileSync(pathFile, 'utf-8');\n }\n if (process.env.ELECTRON_OVERRIDE_DIST_PATH) {\n return path.join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath || 'electron');\n }\n if (executablePath) {\n return path.join(__dirname, 'dist', executablePath);\n } else {\n throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again');\n }\n}\n\nmodule.exports = getElectronPath();\n", "import path from 'path'\nimport fs from 'fs'\nimport os from 'os'\n\nimport { PtyManager } from './pty'\nimport { AgentConfig, isCodingAgent } from './agents'\nimport { CtlsurfApi } from './ctlsurfApi'\nimport { ConversationBridge } from './bridge'\nimport { WorkerWsClient, type WorkerWsStatus, type IncomingMessage } from './workerWs'\n\nfunction log(...args: unknown[]): void {\n try { console.log(...args) } catch { /* EPIPE safe */ }\n}\n\n// \u2500\u2500\u2500 Types \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport interface Profile {\n name: string\n apiKey: string\n baseUrl: string\n dataspacePageId: string\n}\n\nexport interface SettingsData {\n activeProfile: string\n profiles: Record<string, Profile>\n ctlsurfApiKey?: string\n ctlsurfBaseUrl?: string\n ctlsurfDataspacePageId?: string\n}\n\nexport interface OrchestratorEvents {\n onPtyData: (data: string) => void\n onPtyExit: (code: number) => void\n onWorkerStatus: (status: string) => void\n onWorkerMessage: (message: IncomingMessage) => void\n onWorkerRegistered: (data: { worker_id: string; folder_id: string | null; status: string }) => void\n onCwdChanged: () => void\n}\n\n// \u2500\u2500\u2500 Orchestrator \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst DEFAULT_PROFILES: Record<string, Profile> = {\n production: {\n name: 'Production',\n apiKey: '',\n baseUrl: 'https://app.ctlsurf.com',\n dataspacePageId: '',\n },\n}\n\nconst TERM_STREAM_INTERVAL_MS = 50\n\nexport class Orchestrator {\n private settingsDir: string\n private events: OrchestratorEvents\n\n // Core services\n readonly ctlsurfApi = new CtlsurfApi()\n readonly bridge = new ConversationBridge()\n readonly workerWs: WorkerWsClient\n\n // State\n private ptyManager: PtyManager | null = null\n private currentAgent: AgentConfig | null = null\n private currentCwd: string | null = null\n private settings: SettingsData = {\n activeProfile: 'production',\n profiles: { ...DEFAULT_PROFILES },\n }\n\n // Terminal stream batching\n private termStreamBuffer = ''\n private termStreamTimer: ReturnType<typeof setTimeout> | null = null\n\n constructor(settingsDir: string, events: OrchestratorEvents) {\n this.settingsDir = settingsDir\n this.events = events\n\n this.workerWs = new WorkerWsClient({\n onStatusChange: (status: WorkerWsStatus) => {\n log(`[worker-ws] Status: ${status}`)\n events.onWorkerStatus(status)\n },\n onMessage: (message: IncomingMessage) => {\n log(`[worker-ws] Incoming message: ${message.id} (${message.type})`)\n events.onWorkerMessage(message)\n this.workerWs.sendAck(message.id)\n\n if (message.type === 'prompt' || message.type === 'task_dispatch') {\n if (this.ptyManager) {\n this.ptyManager.write(message.content + '\\r')\n this.bridge.feedInput(message.content)\n }\n }\n },\n onRegistered: (data) => {\n log(`[worker-ws] Registered: worker_id=${data.worker_id}, folder_id=${data.folder_id}, status=${data.status}`)\n events.onWorkerRegistered(data)\n if (!data.folder_id) {\n events.onWorkerStatus('no_project')\n }\n },\n onTerminalInput: (data: string) => {\n this.ptyManager?.write(data)\n },\n })\n\n this.bridge.setWsClient(this.workerWs)\n }\n\n // \u2500\u2500\u2500 Settings \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n getActiveProfile(): Profile {\n return this.settings.profiles[this.settings.activeProfile] || this.settings.profiles.production || DEFAULT_PROFILES.production\n }\n\n get settingsData(): SettingsData {\n return this.settings\n }\n\n get cwd(): string | null {\n return this.currentCwd\n }\n\n get agent(): AgentConfig | null {\n return this.currentAgent\n }\n\n applyProfile(profile: Profile): void {\n const apiKey = profile.apiKey || process.env.CTLSURF_API_KEY || ''\n if (apiKey) {\n this.ctlsurfApi.setApiKey(apiKey)\n this.workerWs.setApiKey(apiKey)\n } else {\n this.ctlsurfApi.setApiKey('')\n this.workerWs.setApiKey(null)\n }\n\n const baseUrl = profile.baseUrl || process.env.CTLSURF_BASE_URL || 'https://app.ctlsurf.com'\n this.ctlsurfApi.setBaseUrl(baseUrl)\n this.workerWs.setBaseUrl(baseUrl)\n\n log(`[settings] Profile applied: ${profile.name} (${baseUrl})`)\n }\n\n loadSettings(): void {\n // Ensure settings dir exists\n try { fs.mkdirSync(this.settingsDir, { recursive: true }) } catch { /* ignore */ }\n\n const settingsPath = path.join(this.settingsDir, 'settings.json')\n try {\n if (fs.existsSync(settingsPath)) {\n const raw = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'))\n\n if (!raw.profiles) {\n this.settings = {\n activeProfile: 'production',\n profiles: {\n production: {\n name: 'Production',\n apiKey: raw.ctlsurfApiKey || '',\n baseUrl: raw.ctlsurfBaseUrl || 'https://app.ctlsurf.com',\n dataspacePageId: raw.ctlsurfDataspacePageId || '',\n },\n },\n }\n this.saveSettings()\n log('[settings] Migrated legacy settings to profiles')\n } else {\n this.settings = raw as SettingsData\n if (!this.settings.profiles.production) {\n this.settings.profiles.production = { ...DEFAULT_PROFILES.production }\n }\n }\n }\n } catch {\n this.settings = {\n activeProfile: 'production',\n profiles: { ...DEFAULT_PROFILES },\n }\n }\n\n this.applyProfile(this.getActiveProfile())\n }\n\n saveSettings(): void {\n const settingsPath = path.join(this.settingsDir, 'settings.json')\n try {\n fs.mkdirSync(this.settingsDir, { recursive: true })\n fs.writeFileSync(settingsPath, JSON.stringify(this.settings, null, 2))\n } catch (err: any) {\n log('[settings] Failed to save:', err.message)\n }\n }\n\n overrideApiKey(key: string): void {\n this.ctlsurfApi.setApiKey(key)\n this.workerWs.setApiKey(key)\n }\n\n overrideBaseUrl(url: string): void {\n this.ctlsurfApi.setBaseUrl(url)\n this.workerWs.setBaseUrl(url)\n }\n\n // \u2500\u2500\u2500 Profile CRUD \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n listProfiles() {\n return {\n activeProfile: this.settings.activeProfile,\n profiles: Object.entries(this.settings.profiles).map(([id, p]) => ({\n id,\n name: p.name,\n baseUrl: p.baseUrl,\n hasApiKey: !!p.apiKey,\n dataspacePageId: p.dataspacePageId || null,\n })),\n }\n }\n\n getProfile(profileId: string) {\n const p = this.settings.profiles[profileId]\n if (!p) return null\n return {\n id: profileId,\n name: p.name,\n baseUrl: p.baseUrl,\n hasApiKey: !!p.apiKey,\n dataspacePageId: p.dataspacePageId || '',\n }\n }\n\n saveProfile(profileId: string, data: { name: string; apiKey?: string; baseUrl: string; dataspacePageId: string }) {\n const existing = this.settings.profiles[profileId]\n this.settings.profiles[profileId] = {\n name: data.name,\n apiKey: data.apiKey !== undefined ? data.apiKey : (existing?.apiKey || ''),\n baseUrl: data.baseUrl || 'https://app.ctlsurf.com',\n dataspacePageId: data.dataspacePageId || '',\n }\n this.saveSettings()\n\n if (profileId === this.settings.activeProfile) {\n this.applyProfile(this.settings.profiles[profileId])\n if (this.currentAgent && this.currentCwd) {\n this.workerWs.disconnect()\n this.connectWorkerWs(this.currentAgent, this.currentCwd)\n }\n }\n }\n\n switchProfile(profileId: string): { ok: boolean; error?: string } {\n if (!this.settings.profiles[profileId]) return { ok: false, error: 'Profile not found' }\n this.workerWs.disconnect()\n this.settings.activeProfile = profileId\n this.saveSettings()\n this.applyProfile(this.getActiveProfile())\n if (this.currentAgent && this.currentCwd) {\n this.connectWorkerWs(this.currentAgent, this.currentCwd)\n }\n return { ok: true }\n }\n\n deleteProfile(profileId: string): { ok: boolean; error?: string } {\n if (profileId === 'production') return { ok: false, error: 'Cannot delete Production profile' }\n if (!this.settings.profiles[profileId]) return { ok: false, error: 'Profile not found' }\n\n if (this.settings.activeProfile === profileId) {\n this.workerWs.disconnect()\n this.settings.activeProfile = 'production'\n this.applyProfile(this.getActiveProfile())\n if (this.currentAgent && this.currentCwd) {\n this.connectWorkerWs(this.currentAgent, this.currentCwd)\n }\n }\n\n delete this.settings.profiles[profileId]\n this.saveSettings()\n return { ok: true }\n }\n\n // \u2500\u2500\u2500 PTY & Agent \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async spawnAgent(agent: AgentConfig, cwd: string): Promise<void> {\n if (this.ptyManager) {\n this.bridge.endSession()\n this.ptyManager.kill()\n }\n\n this.currentAgent = agent\n const prevCwd = this.currentCwd\n this.currentCwd = cwd\n if (prevCwd !== cwd) {\n this.events.onCwdChanged()\n }\n\n this.ptyManager = new PtyManager(agent, cwd)\n\n this.ptyManager.onData((data: string) => {\n this.events.onPtyData(data)\n this.bridge.feedOutput(data)\n this.streamTerminalData(data)\n })\n\n const thisPtyManager = this.ptyManager\n\n this.ptyManager.onExit(async (exitCode: number) => {\n this.events.onPtyExit(exitCode)\n this.bridge.endSession()\n if (thisPtyManager === this.ptyManager && this.currentAgent && isCodingAgent(this.currentAgent)) {\n this.workerWs.disconnect()\n }\n })\n\n this.bridge.startSession()\n\n if (isCodingAgent(agent)) {\n this.connectWorkerWs(agent, cwd)\n } else {\n this.workerWs.disconnect()\n this.checkProjectStatus(cwd)\n }\n }\n\n writePty(data: string): void {\n this.ptyManager?.write(data)\n this.bridge.feedInput(data)\n }\n\n resizePty(cols: number, rows: number): void {\n this.ptyManager?.resize(cols, rows)\n this.bridge.resize(cols, rows)\n this.workerWs.sendTerminalResize(cols, rows)\n }\n\n async killAgent(): Promise<void> {\n this.bridge.endSession()\n this.ptyManager?.kill()\n this.ptyManager = null\n if (this.currentAgent && isCodingAgent(this.currentAgent)) {\n this.workerWs.disconnect()\n }\n }\n\n // \u2500\u2500\u2500 Worker WebSocket \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n connectWorkerWs(agent: AgentConfig, cwd: string): void {\n const profile = this.getActiveProfile()\n const apiKey = profile.apiKey || process.env.CTLSURF_API_KEY\n if (!apiKey) {\n log('[worker-ws] No API key, skipping WS connect')\n return\n }\n\n this.workerWs.connect({\n machine: os.hostname(),\n cwd,\n agent: agent.name,\n })\n }\n\n private async checkProjectStatus(cwd: string): Promise<void> {\n if (!this.ctlsurfApi.getApiKey()) {\n this.events.onWorkerStatus('no_project')\n return\n }\n try {\n const folder = await this.ctlsurfApi.findFolderByPath(cwd)\n if (!folder?.id) {\n this.events.onWorkerStatus('no_project')\n }\n } catch {\n this.events.onWorkerStatus('no_project')\n }\n }\n\n private streamTerminalData(data: string): void {\n this.termStreamBuffer += data\n if (!this.termStreamTimer) {\n this.termStreamTimer = setTimeout(() => {\n if (this.termStreamBuffer) {\n this.workerWs.sendTerminalData(this.termStreamBuffer)\n this.termStreamBuffer = ''\n }\n this.termStreamTimer = null\n }, TERM_STREAM_INTERVAL_MS)\n }\n }\n\n // \u2500\u2500\u2500 Shutdown \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async shutdown(): Promise<void> {\n this.bridge.endSession()\n this.ptyManager?.kill()\n this.ptyManager = null\n this.workerWs.disconnect()\n if (this.termStreamTimer) {\n clearTimeout(this.termStreamTimer)\n this.termStreamTimer = null\n }\n }\n}\n", "import { createRequire } from 'module'\nimport { AgentConfig } from './agents'\n\n// Use createRequire to load native module at runtime, bypassing bundler\nconst require = createRequire(import.meta.url)\nconst pty = require('node-pty')\n\nexport class PtyManager {\n private process: any | null = null\n private dataCallbacks: ((data: string) => void)[] = []\n private exitCallbacks: ((code: number) => void)[] = []\n\n constructor(agent: AgentConfig, cwd: string) {\n const shell = agent.command\n const args = agent.args || []\n\n try {\n console.log(`[pty] Spawning: ${shell} ${args.join(' ')} in ${cwd}`)\n } catch {\n // Ignore EPIPE errors when stdout is closed\n }\n\n this.process = pty.spawn(shell, args, {\n name: 'xterm-256color',\n cwd,\n env: process.env as Record<string, string>,\n cols: 80,\n rows: 24\n })\n\n this.process.onData((data: string) => {\n for (const cb of this.dataCallbacks) {\n cb(data)\n }\n })\n\n this.process.onExit(({ exitCode }: { exitCode: number }) => {\n for (const cb of this.exitCallbacks) {\n cb(exitCode)\n }\n this.process = null\n })\n }\n\n write(data: string): void {\n this.process?.write(data)\n }\n\n resize(cols: number, rows: number): void {\n this.process?.resize(cols, rows)\n }\n\n kill(): void {\n this.process?.kill()\n this.process = null\n }\n\n onData(cb: (data: string) => void): void {\n this.dataCallbacks.push(cb)\n }\n\n onExit(cb: (code: number) => void): void {\n this.exitCallbacks.push(cb)\n }\n}\n", "export interface AgentConfig {\n id: string\n name: string\n command: string\n args: string[]\n description: string\n}\n\nfunction getShellCommand(): string {\n if (process.platform === 'win32') return 'powershell.exe'\n return process.env.SHELL || '/bin/zsh'\n}\n\nexport function getBuiltinAgents(): AgentConfig[] {\n return [\n {\n id: 'shell',\n name: 'Shell',\n command: getShellCommand(),\n args: ['-l'], // login shell to load PATH\n description: 'Default system shell'\n },\n {\n id: 'claude',\n name: 'Claude Code',\n command: 'claude',\n args: [],\n description: 'Anthropic Claude Code CLI'\n },\n {\n id: 'codex',\n name: 'Codex CLI',\n command: 'codex',\n args: [],\n description: 'OpenAI Codex CLI'\n }\n ]\n}\n\nexport function getDefaultAgent(): AgentConfig {\n return getBuiltinAgents()[0]\n}\n\nexport function isCodingAgent(agent: AgentConfig): boolean {\n return agent.id !== 'shell'\n}\n", "const CTLSURF_BASE_URL = 'https://app.ctlsurf.com/api'\n\nexport class CtlsurfApi {\n private baseUrl: string\n private apiKey: string | null = null\n\n constructor(baseUrl?: string) {\n this.baseUrl = baseUrl || CTLSURF_BASE_URL\n }\n\n setApiKey(key: string): void {\n this.apiKey = key\n }\n\n setBaseUrl(url: string): void {\n this.baseUrl = url.endsWith('/api') ? url : `${url}/api`\n }\n\n getApiKey(): string | null {\n return this.apiKey\n }\n\n private headers(): Record<string, string> {\n const h: Record<string, string> = { 'Content-Type': 'application/json' }\n if (this.apiKey) {\n h['Authorization'] = `Bearer ${this.apiKey}`\n }\n return h\n }\n\n private async request(method: string, path: string, body?: unknown): Promise<any> {\n const url = `${this.baseUrl}${path}`\n const opts: RequestInit = {\n method,\n headers: this.headers()\n }\n if (body) {\n opts.body = JSON.stringify(body)\n }\n\n const res = await fetch(url, opts)\n if (!res.ok) {\n const text = await res.text()\n throw new Error(`ctlsurf API ${method} ${path}: ${res.status} ${text}`)\n }\n return res.json()\n }\n\n // \u2500\u2500\u2500 Pages \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async createPage(params: {\n title: string\n type?: string\n parent_id?: string\n folder_id?: string\n cwd?: string\n tags?: string[]\n }): Promise<any> {\n return this.request('POST', '/pages', params)\n }\n\n async findPageByRootPath(rootPath: string): Promise<any> {\n return this.request('POST', '/pages/find-by-root-path', { root_path: rootPath })\n }\n\n // \u2500\u2500\u2500 Blocks \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async createBlock(pageId: string, params: {\n type: string\n title?: string\n props?: Record<string, unknown>\n }): Promise<any> {\n return this.request('POST', `/blocks/page/${pageId}`, params)\n }\n\n async getBlock(blockId: string): Promise<any> {\n return this.request('GET', `/blocks/${blockId}`)\n }\n\n async updateBlock(blockId: string, params: {\n props?: Record<string, unknown>\n title?: string\n }): Promise<any> {\n return this.request('PUT', `/blocks/${blockId}`, params)\n }\n\n // \u2500\u2500\u2500 Folders \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async createFolder(params: { name: string; root_path: string }): Promise<any> {\n return this.request('POST', '/folders', params)\n }\n\n // \u2500\u2500\u2500 Workers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async getAuthCode(): Promise<{ code: string }> {\n return this.request('POST', '/workers/token-exchange')\n }\n\n async findFolderByPath(rootPath: string): Promise<any> {\n return this.request('POST', '/folders/find-by-path', { root_path: rootPath })\n }\n\n async getFolderPages(folderId: string): Promise<any[]> {\n const folder = await this.request('GET', `/folders/${folderId}`)\n return folder?.pages || []\n }\n\n async findFolderByGitRemote(gitRemote: string): Promise<any> {\n // Search folders by listing all and matching git_remote\n const folders = await this.request('GET', '/folders')\n return folders?.find((f: any) => f.git_remote === gitRemote || f.root_path === gitRemote) || null\n }\n\n // \u2500\u2500\u2500 Log convenience \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async appendLog(blockId: string, action: string, message: string, data?: Record<string, unknown>): Promise<any> {\n // Read-modify-write: get current entries, append, put back\n const block = await this.getBlock(blockId)\n const props = block.props || {}\n const entries = Array.isArray(props.entries) ? [...props.entries] : []\n const maxEntries = props.max_entries || 1000\n\n const entry: Record<string, unknown> = {\n _id: `log_${entries.length}`,\n _timestamp: new Date().toISOString(),\n action,\n message\n }\n if (data) {\n entry.data = data\n }\n\n entries.push(entry)\n\n // Trim oldest if over max\n const trimmed = entries.length > maxEntries ? entries.slice(-maxEntries) : entries\n\n return this.updateBlock(blockId, {\n props: { ...props, entries: trimmed }\n })\n }\n}\n", "import { WorkerWsClient } from './workerWs'\n\n/**\n * Conversation Bridge\n *\n * Captures PTY output, strips ANSI codes and terminal artifacts,\n * and sends cleaned text to the backend via WebSocket for chat logging.\n * Uses a simple buffer + byte threshold approach (no timers, since\n * setTimeout/setInterval don't reliably fire under TUI raw mode).\n */\nexport class ConversationBridge {\n private wsClient: WorkerWsClient | null = null\n private sessionActive: boolean = false\n private inputBuffer: string = ''\n private outputBuffer: string = ''\n\n private readonly FLUSH_BYTES = 2000\n\n setWsClient(ws: WorkerWsClient): void {\n this.wsClient = ws\n }\n\n startSession(): void {\n this.outputBuffer = ''\n this.inputBuffer = ''\n this.sessionActive = true\n console.log('[bridge] Session started')\n }\n\n feedOutput(data: string): void {\n if (!this.sessionActive) return\n\n this.outputBuffer += data\n\n if (this.outputBuffer.length >= this.FLUSH_BYTES) {\n this.flush()\n }\n }\n\n feedInput(data: string): void {\n if (!this.sessionActive) return\n this.inputBuffer += data\n\n if (data.includes('\\r') || data.includes('\\n')) {\n const cleaned = cleanInput(this.inputBuffer)\n if (cleaned.length > 0) {\n this.sendEntry('user_input', cleaned)\n }\n this.inputBuffer = ''\n }\n }\n\n resize(_cols: number, _rows: number): void {\n // no-op now (was used for xterm)\n }\n\n private flush(): void {\n if (this.outputBuffer.length === 0) return\n\n const raw = this.outputBuffer\n this.outputBuffer = ''\n\n const cleaned = cleanOutput(raw)\n if (cleaned.length === 0) return\n\n this.sendEntry('terminal_output', cleaned)\n }\n\n private sendEntry(type: string, content: string): void {\n if (!this.wsClient) return\n this.wsClient.sendChatLog({\n ts: new Date().toISOString(),\n type,\n content,\n })\n }\n\n endSession(): void {\n if (!this.sessionActive) return\n\n this.flush()\n\n this.sessionActive = false\n this.inputBuffer = ''\n this.outputBuffer = ''\n console.log('[bridge] Session ended')\n }\n}\n\n/**\n * Strip ANSI escape codes from a string.\n */\nfunction stripAnsi(str: string): string {\n return str\n // CSI sequences (e.g. \\x1b[0m, \\x1b[?2004h, \\x1b[1;32m, \\x1b[38;2;r;g;bm)\n .replace(/\\x1b\\[[\\x30-\\x3f]*[\\x20-\\x2f]*[\\x40-\\x7e]/g, '')\n // OSC sequences (e.g. \\x1b]0;title\\x07, \\x1b]...\\x1b\\\\)\n .replace(/\\x1b\\][^\\x07\\x1b]*(?:\\x07|\\x1b\\\\)/g, '')\n // DCS/PM/APC sequences\n .replace(/\\x1b[PX^_][^\\x1b]*\\x1b\\\\/g, '')\n // Other escape sequences (charset, keypad mode, etc.)\n .replace(/\\x1b[^[\\]PX^_](.|$)/g, '')\n // Remaining single ESC\n .replace(/\\x1b/g, '')\n}\n\n/**\n * Process backspace characters: each \\x7f or \\b deletes the preceding char.\n */\nfunction processBackspaces(str: string): string {\n const result: string[] = []\n for (const ch of str) {\n if (ch === '\\x7f' || ch === '\\b') {\n result.pop()\n } else {\n result.push(ch)\n }\n }\n return result.join('')\n}\n\n/**\n * Clean user input: strip ANSI, process backspaces, remove control chars.\n */\nfunction cleanInput(str: string): string {\n let cleaned = stripAnsi(str)\n cleaned = processBackspaces(cleaned)\n // eslint-disable-next-line no-control-regex\n cleaned = cleaned.replace(/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/g, '')\n return cleaned.trim()\n}\n\n/**\n * Clean terminal output: strip ANSI, remove control chars, collapse noise.\n */\nfunction cleanOutput(str: string): string {\n let cleaned = stripAnsi(str)\n // Remove carriage returns\n cleaned = cleaned.replace(/\\r/g, '')\n // Remove control characters except newline/tab\n // eslint-disable-next-line no-control-regex\n cleaned = cleaned.replace(/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/g, '')\n // Collapse 3+ consecutive newlines into 2\n cleaned = cleaned.replace(/\\n{3,}/g, '\\n\\n')\n // Remove lines that are only whitespace\n cleaned = cleaned.split('\\n').filter(line => line.trim().length > 0).join('\\n')\n return cleaned.trim()\n}\n", "import os from 'os'\nimport crypto from 'crypto'\nimport WsModule from 'ws'\n\n// Use native WebSocket if available (Node 22+), otherwise fall back to ws package\nconst WS: typeof WebSocket = typeof WebSocket !== 'undefined' ? WebSocket : WsModule as any\n\nfunction log(...args: unknown[]): void {\n try { console.log(...args) } catch { /* EPIPE safe */ }\n}\n\nconst HEARTBEAT_INTERVAL_MS = 30_000\nconst RECONNECT_DELAY_MS = 5_000\nconst MAX_RECONNECT_DELAY_MS = 60_000\n\nexport interface WorkerRegistration {\n machine: string\n cwd: string\n repo_url?: string\n agent: string\n fingerprint: string\n}\n\nexport interface WorkerWsEvents {\n onStatusChange: (status: WorkerWsStatus) => void\n onMessage: (message: IncomingMessage) => void\n onRegistered: (data: { worker_id: string; folder_id: string | null; status: string; pending_messages?: IncomingMessage[] }) => void\n onTerminalInput?: (data: string) => void\n}\n\nexport interface IncomingMessage {\n id: string\n type: string\n content: string\n metadata?: Record<string, unknown> | null\n parent_id?: string | null\n}\n\nexport type WorkerWsStatus = 'disconnected' | 'connecting' | 'connected' | 'pending_approval'\n\nexport class WorkerWsClient {\n private ws: WebSocket | null = null\n private apiKey: string | null = null\n private baseUrl: string\n private events: WorkerWsEvents\n private heartbeatTimer: ReturnType<typeof setInterval> | null = null\n private reconnectTimer: ReturnType<typeof setTimeout> | null = null\n private reconnectDelay = RECONNECT_DELAY_MS\n private registration: WorkerRegistration | null = null\n private workerId: string | null = null\n private _status: WorkerWsStatus = 'disconnected'\n private shouldReconnect = false\n private fingerprint: string\n\n constructor(events: WorkerWsEvents, baseUrl?: string) {\n this.events = events\n this.baseUrl = baseUrl || 'wss://app.ctlsurf.com'\n // Generate a stable machine fingerprint\n this.fingerprint = this.generateFingerprint()\n }\n\n get status(): WorkerWsStatus {\n return this._status\n }\n\n get currentWorkerId(): string | null {\n return this.workerId\n }\n\n setApiKey(key: string | null): void {\n this.apiKey = key\n }\n\n setBaseUrl(url: string): void {\n this.baseUrl = url\n }\n\n private generateFingerprint(): string {\n const data = `${os.hostname()}:${os.userInfo().username}:${os.platform()}:${os.arch()}`\n return crypto.createHash('sha256').update(data).digest('hex').slice(0, 32)\n }\n\n private setStatus(status: WorkerWsStatus): void {\n if (this._status !== status) {\n this._status = status\n this.events.onStatusChange(status)\n }\n }\n\n connect(registration: WorkerRegistration): void {\n this.registration = { ...registration, fingerprint: this.fingerprint }\n this.shouldReconnect = true\n this.doConnect()\n }\n\n disconnect(): void {\n this.shouldReconnect = false\n this.clearTimers()\n if (this.ws) {\n const oldWs = this.ws\n this.ws = null\n // Remove handlers before closing to prevent stale onclose from firing\n oldWs.onopen = null\n oldWs.onmessage = null\n oldWs.onclose = null\n oldWs.onerror = null\n try { oldWs.close(1000, 'client disconnect') } catch { /* ignore */ }\n }\n this.setStatus('disconnected')\n }\n\n sendResponse(parentId: string, content: string, metadata?: Record<string, unknown>): void {\n this.send({\n type: 'response',\n parent_id: parentId,\n content,\n metadata,\n })\n }\n\n sendStatusUpdate(status: string): void {\n this.send({ type: 'status_update', status })\n }\n\n sendAck(messageId: string): void {\n this.send({ type: 'ack', message_id: messageId })\n }\n\n sendTerminalData(data: string): void {\n this.send({ type: 'terminal_stream', data })\n }\n\n sendTerminalResize(cols: number, rows: number): void {\n this.send({ type: 'terminal_resize', cols, rows })\n }\n\n sendChatLog(entry: { type: string; content: string; ts?: string }): void {\n this.send({ type: 'chat_log', entry })\n }\n\n private doConnect(): void {\n if (!this.apiKey || !this.registration) {\n log('[worker-ws] No API key or registration, skipping connect')\n return\n }\n\n this.clearTimers()\n if (this.ws) {\n const oldWs = this.ws\n this.ws = null\n oldWs.onopen = null\n oldWs.onmessage = null\n oldWs.onclose = null\n oldWs.onerror = null\n try { oldWs.close() } catch { /* ignore */ }\n // Let the old connection fully close before opening a new one\n setTimeout(() => this.doConnectNow(), 500)\n return\n }\n\n this.doConnectNow()\n }\n\n private doConnectNow(): void {\n if (!this.apiKey || !this.registration) return\n if (!this.shouldReconnect) {\n log('[worker-ws] shouldReconnect is false, aborting connect')\n return\n }\n\n this.setStatus('connecting')\n\n // Use ws:// for localhost, wss:// for remote\n const wsBase = this.baseUrl.replace(/^http/, 'ws')\n const url = `${wsBase}/api/ws/worker?token=${encodeURIComponent(this.apiKey)}`\n\n log(`[worker-ws] Connecting to ${url.replace(/token=.*/, 'token=***')}...`)\n\n try {\n this.ws = new WS(url) as unknown as WebSocket\n } catch (err) {\n log('[worker-ws] Failed to create WebSocket:', err)\n this.scheduleReconnect()\n return\n }\n\n this.ws.onopen = () => {\n log('[worker-ws] Connected, sending register')\n this.reconnectDelay = RECONNECT_DELAY_MS // Reset backoff\n this.send({\n type: 'register',\n ...this.registration,\n })\n this.startHeartbeat()\n }\n\n this.ws.onmessage = (event) => {\n try {\n const data = JSON.parse(String(event.data))\n this.handleMessage(data)\n } catch (err) {\n log('[worker-ws] Failed to parse message:', err)\n }\n }\n\n this.ws.onclose = (event) => {\n log(`[worker-ws] Disconnected: ${event.code} ${event.reason}`)\n this.ws = null\n this.clearHeartbeat()\n this.setStatus('disconnected')\n if (this.shouldReconnect) {\n this.scheduleReconnect()\n }\n }\n\n this.ws.onerror = () => {\n log('[worker-ws] WebSocket error')\n }\n }\n\n private handleMessage(data: Record<string, unknown>): void {\n const msgType = data.type as string\n\n switch (msgType) {\n case 'registered': {\n this.workerId = data.worker_id as string\n const workerStatus = data.status as string\n console.log(`[worker-ws] Registered as ${this.workerId}, status: ${workerStatus}`)\n\n if (workerStatus === 'pending_approval') {\n this.setStatus('pending_approval')\n } else {\n this.setStatus('connected')\n }\n\n const pendingMessages = (data.pending_messages || []) as IncomingMessage[]\n this.events.onRegistered({\n worker_id: this.workerId,\n folder_id: data.folder_id as string | null,\n status: workerStatus,\n pending_messages: pendingMessages,\n })\n\n // Deliver pending messages\n for (const msg of pendingMessages) {\n this.events.onMessage(msg)\n }\n break\n }\n\n case 'approved': {\n log('[worker-ws] Worker approved!')\n this.setStatus('connected')\n break\n }\n\n case 'message': {\n const msg = data.message as IncomingMessage\n if (msg) {\n console.log(`[worker-ws] Received message: ${msg.id}`)\n this.events.onMessage(msg)\n }\n break\n }\n\n case 'terminal_input': {\n const inputData = data.data as string\n if (inputData && this.events.onTerminalInput) {\n this.events.onTerminalInput(inputData)\n }\n break\n }\n\n case 'heartbeat_ack':\n break\n\n default:\n console.log(`[worker-ws] Unknown message type: ${msgType}`)\n }\n }\n\n private send(data: Record<string, unknown>): void {\n if (this.ws && this.ws.readyState === WS.OPEN) {\n this.ws.send(JSON.stringify(data))\n }\n }\n\n\n private startHeartbeat(): void {\n this.clearHeartbeat()\n this.heartbeatTimer = setInterval(() => {\n this.send({ type: 'heartbeat' })\n }, HEARTBEAT_INTERVAL_MS)\n }\n\n private clearHeartbeat(): void {\n if (this.heartbeatTimer) {\n clearInterval(this.heartbeatTimer)\n this.heartbeatTimer = null\n }\n }\n\n private scheduleReconnect(): void {\n if (!this.shouldReconnect) return\n console.log(`[worker-ws] Reconnecting in ${this.reconnectDelay / 1000}s...`)\n this.reconnectTimer = setTimeout(() => {\n this.doConnect()\n }, this.reconnectDelay)\n // Exponential backoff\n this.reconnectDelay = Math.min(this.reconnectDelay * 2, MAX_RECONNECT_DELAY_MS)\n }\n\n private clearTimers(): void {\n this.clearHeartbeat()\n if (this.reconnectTimer) {\n clearTimeout(this.reconnectTimer)\n this.reconnectTimer = null\n }\n }\n}\n", "import path from 'path'\nimport os from 'os'\n\nexport function getSettingsDir(useElectron: boolean): string {\n if (useElectron) {\n const { app } = require('electron')\n return app.getPath('userData')\n }\n\n if (process.platform === 'darwin') {\n return path.join(os.homedir(), 'Library', 'Application Support', 'ctlsurf-worker')\n }\n return path.join(\n process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'),\n 'ctlsurf-worker'\n )\n}\n", "/**\n * Terminal UI (TUI) renderer\n *\n * Draws a title bar and status bar around the PTY output area.\n * Uses ANSI escape codes and scroll regions \u2014 no external dependencies.\n */\n\nconst ESC = '\\x1b'\nconst CSI = `${ESC}[`\n\n// Colors (Tokyo Night palette)\nconst BG_BAR = `${CSI}48;2;22;22;30m` // #16161e\nconst FG_TITLE = `${CSI}38;2;192;202;245m` // #c0caf5\nconst FG_DIM = `${CSI}38;2;86;95;137m` // #565f89\nconst FG_ACCENT = `${CSI}38;2;122;162;247m` // #7aa2f7\nconst FG_GREEN = `${CSI}38;2;158;206;106m` // #9ece6a\nconst FG_RED = `${CSI}38;2;247;118;142m` // #f7768e\nconst FG_YELLOW = `${CSI}38;2;224;175;104m` // #e0af68\nconst FG_WHITE = `${CSI}38;2;169;177;214m` // #a9b1d6\nconst BG_MODAL = `${CSI}48;2;31;35;53m` // #1f2335\nconst BG_SELECTED = `${CSI}48;2;42;43;61m` // #2a2b3d\nconst RESET = `${CSI}0m`\n\nexport interface TuiState {\n agentName: string\n cwd: string\n wsStatus: string\n workerId: string | null\n mode: string\n}\n\nexport class Tui {\n private rows: number = 0\n private cols: number = 0\n private state: TuiState = {\n agentName: '',\n cwd: '',\n wsStatus: 'disconnected',\n workerId: null,\n mode: 'terminal',\n }\n\n constructor() {\n this.rows = process.stdout.rows || 24\n this.cols = process.stdout.columns || 80\n }\n\n /**\n * Initialize the TUI: alternate screen, hide cursor reporting, set scroll region\n */\n init(): void {\n // Alternate screen buffer\n this.write(`${CSI}?1049h`)\n // Set scroll region: lines 2 to (rows - 1), leaving line 1 for title, line rows for status\n this.setScrollRegion()\n // Move cursor to the PTY area\n this.moveToPtyArea()\n // Draw chrome\n this.drawTitleBar()\n this.drawStatusBar()\n }\n\n /**\n * Restore terminal to normal state\n */\n destroy(): void {\n // Reset scroll region\n this.write(`${CSI}r`)\n // Leave alternate screen\n this.write(`${CSI}?1049l`)\n // Show cursor\n this.write(`${CSI}?25h`)\n }\n\n /**\n * Handle terminal resize\n */\n resize(cols: number, rows: number): void {\n this.cols = cols\n this.rows = rows\n this.setScrollRegion()\n this.drawTitleBar()\n this.drawStatusBar()\n this.moveToPtyArea()\n }\n\n /**\n * Get the PTY dimensions (main area minus title + status bars)\n */\n getPtySize(): { cols: number; rows: number } {\n return {\n cols: this.cols,\n rows: Math.max(1, this.rows - 2),\n }\n }\n\n /**\n * Update state and redraw bars\n */\n update(partial: Partial<TuiState>): void {\n Object.assign(this.state, partial)\n // Save cursor, draw bars, restore cursor\n this.write(`${CSI}s`) // save cursor\n this.drawTitleBar()\n this.drawStatusBar()\n this.write(`${CSI}u`) // restore cursor\n }\n\n /**\n * Write PTY output to the scroll region.\n * Cursor is assumed to be in the PTY area already.\n */\n writePtyData(data: string): void {\n // PTY data goes straight to stdout \u2014 it's already in the scroll region\n this.write(data)\n }\n\n /**\n * Update the terminal window/tab title via OSC escape sequence.\n * Works in passthrough mode (no chrome) \u2014 doesn't conflict with the agent's TUI.\n */\n setTerminalTitle(title: string): void {\n this.write(`${ESC}]0;${title}\\x07`)\n }\n\n /**\n * Build a title string from current state for the terminal tab.\n */\n updateTerminalTitle(): void {\n const { agentName, wsStatus, cwd } = this.state\n const displayCwd = this.shortenPath(cwd)\n const statusIcon = {\n connected: '\\u25CF',\n connecting: '\\u25CB',\n disconnected: '\\u25CB',\n pending_approval: '\\u25CB',\n no_project: '\\u25CB',\n }[wsStatus] || '\\u25CB'\n const statusLabel = {\n connected: 'Connected',\n connecting: 'Connecting...',\n disconnected: 'Disconnected',\n pending_approval: 'Pending',\n no_project: 'No Project',\n }[wsStatus] || wsStatus\n\n this.setTerminalTitle(`ctlsurf \\u00B7 ${agentName} \\u00B7 ${statusIcon} ${statusLabel} \\u00B7 ${displayCwd}`)\n }\n\n /**\n * Show an interactive agent picker modal.\n * Returns a promise that resolves with the selected agent index.\n */\n showAgentPicker(agents: { name: string; description: string }[]): Promise<number> {\n return new Promise((resolve) => {\n let selected = 0\n const modalWidth = 44\n const modalHeight = agents.length + 4 // border + title + items + border\n const startCol = Math.max(1, Math.floor((this.cols - modalWidth) / 2))\n const startRow = Math.max(1, Math.floor((this.rows - modalHeight) / 2))\n\n // Enter alternate screen if not already\n this.write(`${CSI}?1049h`)\n // Hide cursor\n this.write(`${CSI}?25l`)\n\n const drawModal = () => {\n const topBorder = '\\u250c' + '\\u2500'.repeat(modalWidth - 2) + '\\u2510'\n const botBorder = '\\u2514' + '\\u2500'.repeat(modalWidth - 2) + '\\u2518'\n const emptyLine = '\\u2502' + ' '.repeat(modalWidth - 2) + '\\u2502'\n\n // Draw background fill\n for (let r = 0; r < this.rows; r++) {\n this.write(`${CSI}${r + 1};1H${BG_BAR}${CSI}2K${RESET}`)\n }\n\n // Draw logo/branding centered\n const brand = 'ctlsurf'\n const brandCol = Math.max(1, Math.floor((this.cols - brand.length) / 2))\n this.write(`${CSI}${startRow - 2};${brandCol}H${FG_ACCENT}${brand}${RESET}`)\n\n // Top border\n this.write(`${CSI}${startRow};${startCol}H${BG_MODAL}${FG_DIM}${topBorder}${RESET}`)\n\n // Title\n const title = ' Select Agent'\n const titlePad = ' '.repeat(Math.max(0, modalWidth - 2 - title.length))\n this.write(`${CSI}${startRow + 1};${startCol}H${BG_MODAL}${FG_DIM}\\u2502${RESET}${BG_MODAL}${FG_TITLE}${title}${titlePad}${FG_DIM}\\u2502${RESET}`)\n\n // Separator\n const sep = '\\u251c' + '\\u2500'.repeat(modalWidth - 2) + '\\u2524'\n this.write(`${CSI}${startRow + 2};${startCol}H${BG_MODAL}${FG_DIM}${sep}${RESET}`)\n\n // Agent items\n for (let i = 0; i < agents.length; i++) {\n const agent = agents[i]\n const row = startRow + 3 + i\n const isSelected = i === selected\n const bg = isSelected ? BG_SELECTED : BG_MODAL\n const pointer = isSelected ? `${FG_ACCENT}\\u25B8 ` : ' '\n const nameFg = isSelected ? FG_ACCENT : FG_WHITE\n const descFg = FG_DIM\n const nameStr = agent.name\n const descStr = agent.description ? ` ${FG_DIM}\u2014 ${agent.description.slice(0, 20)}` : ''\n const content = `${pointer}${nameFg}${nameStr}${descStr}`\n const contentLen = (isSelected ? 2 : 2) + nameStr.length + (agent.description ? 3 + Math.min(20, agent.description.length) : 0)\n const pad = ' '.repeat(Math.max(0, modalWidth - 2 - contentLen))\n this.write(`${CSI}${row};${startCol}H${bg}${FG_DIM}\\u2502${RESET}${bg}${content}${pad}${RESET}${BG_MODAL}${FG_DIM}\\u2502${RESET}`)\n }\n\n // Bottom border\n const botRow = startRow + 3 + agents.length\n this.write(`${CSI}${botRow};${startCol}H${BG_MODAL}${FG_DIM}${botBorder}${RESET}`)\n\n // Hint\n const hint = '\\u2191\\u2193 navigate \u00B7 Enter select \u00B7 q quit'\n const hintCol = Math.max(1, Math.floor((this.cols - hint.length) / 2))\n this.write(`${CSI}${botRow + 2};${hintCol}H${FG_DIM}${hint}${RESET}`)\n }\n\n drawModal()\n\n // Set raw mode to capture keypresses\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(true)\n }\n process.stdin.resume()\n\n const onKey = (data: Buffer) => {\n const key = data.toString()\n\n if (key === '\\x1b[A' || key === 'k') {\n // Up\n selected = (selected - 1 + agents.length) % agents.length\n drawModal()\n } else if (key === '\\x1b[B' || key === 'j') {\n // Down\n selected = (selected + 1) % agents.length\n drawModal()\n } else if (key === '\\r' || key === '\\n') {\n // Enter \u2014 select\n cleanup()\n resolve(selected)\n } else if (key === 'q' || key === '\\x1b' || key === '\\x03') {\n // q, Escape, Ctrl+C \u2014 quit\n cleanup()\n this.write(`${CSI}?25h`) // show cursor\n this.write(`${CSI}?1049l`) // leave alt screen\n process.exit(0)\n }\n }\n\n const cleanup = () => {\n process.stdin.removeListener('data', onKey)\n // Show cursor again\n this.write(`${CSI}?25h`)\n // Clear the modal (will be redrawn by init())\n }\n\n process.stdin.on('data', onKey)\n })\n }\n\n // \u2500\u2500\u2500 Internal \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n private write(data: string): void {\n try {\n process.stdout.write(data)\n } catch { /* EPIPE safe */ }\n }\n\n private setScrollRegion(): void {\n // Scroll region from line 2 to line (rows - 1)\n this.write(`${CSI}2;${this.rows - 1}r`)\n }\n\n private moveToPtyArea(): void {\n // Move cursor to top of PTY area (line 2)\n this.write(`${CSI}2;1H`)\n }\n\n private drawTitleBar(): void {\n const { agentName, cwd, wsStatus } = this.state\n // Move to line 1\n this.write(`${CSI}1;1H`)\n // Clear line and draw\n this.write(`${BG_BAR}${CSI}2K`)\n\n const displayCwd = this.shortenPath(cwd)\n\n // WS status indicator\n const statusColor = {\n connected: FG_GREEN,\n connecting: FG_YELLOW,\n disconnected: FG_RED,\n pending_approval: FG_YELLOW,\n no_project: FG_DIM,\n }[wsStatus] || FG_DIM\n const statusLabel = {\n connected: 'Connected',\n connecting: 'Connecting...',\n disconnected: 'Disconnected',\n pending_approval: 'Pending',\n no_project: 'No Project',\n }[wsStatus] || wsStatus\n const wsIndicator = `${statusColor}\\u25CF ${statusLabel}${RESET}${BG_BAR}`\n\n const left = ` ${FG_ACCENT}ctlsurf${RESET}${BG_BAR} ${FG_DIM}\\u2502${RESET}${BG_BAR} ${FG_TITLE}${agentName || 'starting...'}${RESET}${BG_BAR} ${FG_DIM}\\u2502${RESET}${BG_BAR} ${FG_DIM}${displayCwd}${RESET}${BG_BAR}`\n const right = `${wsIndicator} ${RESET}${BG_BAR}`\n\n this.write(left)\n const pad = Math.max(0, this.cols - this.visibleLen(left) - this.visibleLen(right))\n this.write(' '.repeat(pad))\n this.write(right)\n this.write(RESET)\n }\n\n private drawStatusBar(): void {\n const { wsStatus, workerId, cwd } = this.state\n // Move to last line\n this.write(`${CSI}${this.rows};1H`)\n // Clear line and draw\n this.write(`${BG_BAR}${CSI}2K`)\n\n const statusColor = {\n connected: FG_GREEN,\n connecting: FG_YELLOW,\n disconnected: FG_RED,\n pending_approval: FG_YELLOW,\n no_project: FG_DIM,\n }[wsStatus] || FG_DIM\n\n const statusDot = `${statusColor}\\u25CF${RESET}${BG_BAR}`\n const statusLabel = {\n connected: 'Connected',\n connecting: 'Connecting...',\n disconnected: 'Disconnected',\n pending_approval: 'Pending Approval',\n no_project: 'No Project',\n }[wsStatus] || wsStatus\n\n const displayCwd = this.shortenPath(cwd)\n const left = ` ${statusDot} ${FG_DIM}${statusLabel}${RESET}${BG_BAR}`\n const right = `${FG_DIM}Ctrl+\\\\ exit${RESET}${BG_BAR} ${FG_DIM}${displayCwd} ${RESET}${BG_BAR}`\n\n this.write(left)\n const pad = Math.max(0, this.cols - this.visibleLen(left) - this.visibleLen(right))\n this.write(' '.repeat(pad))\n this.write(right)\n this.write(RESET)\n }\n\n private shortenPath(p: string): string {\n if (!p) return ''\n const home = process.env.HOME || ''\n if (home && p.startsWith(home)) {\n return '~' + p.slice(home.length)\n }\n return p\n }\n\n private visibleLen(s: string): number {\n // Strip ANSI codes to get visible length\n return s.replace(/\\x1b\\[[^m]*m/g, '').length\n }\n}\n", "#!/usr/bin/env node\n\n/**\n * ctlsurf terminal mode (TUI)\n *\n * Runs the agent in a PTY with a terminal UI: title bar, status bar,\n * conversation logging, and WebSocket control. No Electron required.\n *\n * Usage:\n * ctlsurf --terminal [--agent claude] [--cwd /path] [--api-key KEY] [--base-url URL] [--profile NAME]\n *\n * If no --agent is given, shows an interactive agent picker.\n * Press Ctrl+\\ to exit at any time.\n */\n\n// Prevent EPIPE crashes\nprocess.stdout?.on?.('error', () => {})\nprocess.stderr?.on?.('error', () => {})\nprocess.on('uncaughtException', (err) => {\n if (err.message === 'write EPIPE') return\n try { console.error('[uncaught]', err) } catch { /* ignore */ }\n})\n\nimport { Orchestrator } from './orchestrator'\nimport { getSettingsDir } from './settingsDir'\nimport { getBuiltinAgents, getDefaultAgent, isCodingAgent, type AgentConfig } from './agents'\nimport { Tui } from './tui'\n\n// \u2500\u2500\u2500 CLI arg parsing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\ninterface CliArgs {\n agent: string | null\n cwd: string\n apiKey: string | null\n baseUrl: string | null\n profile: string | null\n}\n\nfunction parseArgs(argv: string[]): CliArgs {\n const args: CliArgs = {\n agent: null,\n cwd: process.env.CTLSURF_WORKER_CWD || process.cwd(),\n apiKey: null,\n baseUrl: null,\n profile: null,\n }\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i]\n const next = argv[i + 1]\n switch (arg) {\n case '--agent': args.agent = next; i++; break\n case '--cwd': args.cwd = next; i++; break\n case '--api-key': args.apiKey = next; i++; break\n case '--base-url': args.baseUrl = next; i++; break\n case '--profile': args.profile = next; i++; break\n case '--terminal': break\n case '--desktop': break\n }\n }\n return args\n}\n\n// \u2500\u2500\u2500 Main \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nasync function main() {\n const args = parseArgs(process.argv.slice(2))\n const settingsDir = getSettingsDir(false)\n\n const tui = new Tui()\n const agents = getBuiltinAgents()\n\n // \u2500\u2500\u2500 Agent selection \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n let agent: AgentConfig\n\n if (args.agent) {\n const found = agents.find(a => a.id === args.agent)\n agent = found || {\n id: args.agent,\n name: args.agent,\n command: args.agent,\n args: [],\n description: `Custom agent: ${args.agent}`,\n }\n } else {\n // Show interactive picker\n const selectedIdx = await tui.showAgentPicker(agents)\n agent = agents[selectedIdx]\n }\n\n // \u2500\u2500\u2500 Start TUI + agent \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n tui.update({\n agentName: agent.name,\n cwd: args.cwd,\n mode: 'terminal',\n })\n\n tui.init()\n\n const orchestrator = new Orchestrator(settingsDir, {\n onPtyData: (data) => {\n tui.writePtyData(data)\n },\n onPtyExit: (code) => {\n tui.destroy()\n console.log(`Agent exited with code ${code}`)\n orchestrator.shutdown().then(() => process.exit(code))\n },\n onWorkerStatus: (status) => {\n tui.update({ wsStatus: status })\n },\n onWorkerMessage: () => {},\n onWorkerRegistered: () => {\n tui.update({ wsStatus: 'connected' })\n },\n onCwdChanged: () => {\n tui.update({ cwd: orchestrator.cwd || '' })\n },\n })\n\n orchestrator.loadSettings()\n\n if (args.profile) orchestrator.switchProfile(args.profile)\n if (args.apiKey) orchestrator.overrideApiKey(args.apiKey)\n if (args.baseUrl) orchestrator.overrideBaseUrl(args.baseUrl)\n\n // Spawn agent with PTY sized to fit the TUI content area\n const ptySize = tui.getPtySize()\n await orchestrator.spawnAgent(agent, args.cwd)\n orchestrator.resizePty(ptySize.cols, ptySize.rows)\n\n // For coding agents, send an initial prompt to kick-start them\n if (isCodingAgent(agent)) {\n setTimeout(() => {\n orchestrator.writePty('hello\\r')\n }, 1000)\n }\n\n // Pipe stdin to PTY, with Ctrl+\\ as the exit key\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(true)\n process.stdin.resume()\n process.stdin.on('data', (data) => {\n const str = data.toString()\n // Ctrl+\\ (0x1c) = exit\n if (str === '\\x1c') {\n shutdown()\n return\n }\n orchestrator.writePty(str)\n })\n }\n\n // Handle terminal resize\n process.stdout.on('resize', () => {\n const cols = process.stdout.columns || 80\n const rows = process.stdout.rows || 24\n tui.resize(cols, rows)\n const size = tui.getPtySize()\n orchestrator.resizePty(size.cols, size.rows)\n })\n\n // Graceful shutdown\n const shutdown = async () => {\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(false)\n }\n tui.destroy()\n await orchestrator.shutdown()\n process.exit(0)\n }\n\n process.on('SIGINT', shutdown)\n process.on('SIGTERM', shutdown)\n}\n\nmain().catch((err) => {\n process.stdout.write('\\x1b[?1049l')\n console.error('Fatal error:', err)\n process.exit(1)\n})\n"],
4
+ "sourcesContent": ["const fs = require('fs');\nconst path = require('path');\n\nconst pathFile = path.join(__dirname, 'path.txt');\n\nfunction getElectronPath () {\n let executablePath;\n if (fs.existsSync(pathFile)) {\n executablePath = fs.readFileSync(pathFile, 'utf-8');\n }\n if (process.env.ELECTRON_OVERRIDE_DIST_PATH) {\n return path.join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath || 'electron');\n }\n if (executablePath) {\n return path.join(__dirname, 'dist', executablePath);\n } else {\n throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again');\n }\n}\n\nmodule.exports = getElectronPath();\n", "import path from 'path'\nimport fs from 'fs'\nimport os from 'os'\n\nimport { PtyManager } from './pty'\nimport { AgentConfig, isCodingAgent } from './agents'\nimport { CtlsurfApi } from './ctlsurfApi'\nimport { ConversationBridge } from './bridge'\nimport { WorkerWsClient, type WorkerWsStatus, type IncomingMessage } from './workerWs'\n\nfunction log(...args: unknown[]): void {\n try { console.log(...args) } catch { /* EPIPE safe */ }\n}\n\n// \u2500\u2500\u2500 Types \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport interface Profile {\n name: string\n apiKey: string\n baseUrl: string\n dataspacePageId: string\n}\n\nexport interface SettingsData {\n activeProfile: string\n profiles: Record<string, Profile>\n ctlsurfApiKey?: string\n ctlsurfBaseUrl?: string\n ctlsurfDataspacePageId?: string\n}\n\nexport interface OrchestratorEvents {\n onPtyData: (data: string) => void\n onPtyExit: (code: number) => void\n onWorkerStatus: (status: string) => void\n onWorkerMessage: (message: IncomingMessage) => void\n onWorkerRegistered: (data: { worker_id: string; folder_id: string | null; status: string }) => void\n onCwdChanged: () => void\n}\n\n// \u2500\u2500\u2500 Orchestrator \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst DEFAULT_PROFILES: Record<string, Profile> = {\n production: {\n name: 'Production',\n apiKey: '',\n baseUrl: 'https://app.ctlsurf.com',\n dataspacePageId: '',\n },\n}\n\nconst TERM_STREAM_INTERVAL_MS = 50\n\nexport class Orchestrator {\n private settingsDir: string\n private events: OrchestratorEvents\n\n // Core services\n readonly ctlsurfApi = new CtlsurfApi()\n readonly bridge = new ConversationBridge()\n readonly workerWs: WorkerWsClient\n\n // State\n private ptyManager: PtyManager | null = null\n private currentAgent: AgentConfig | null = null\n private currentCwd: string | null = null\n private settings: SettingsData = {\n activeProfile: 'production',\n profiles: { ...DEFAULT_PROFILES },\n }\n\n // Terminal stream batching\n private termStreamBuffer = ''\n private termStreamTimer: ReturnType<typeof setTimeout> | null = null\n\n constructor(settingsDir: string, events: OrchestratorEvents) {\n this.settingsDir = settingsDir\n this.events = events\n\n this.workerWs = new WorkerWsClient({\n onStatusChange: (status: WorkerWsStatus) => {\n log(`[worker-ws] Status: ${status}`)\n events.onWorkerStatus(status)\n },\n onMessage: (message: IncomingMessage) => {\n log(`[worker-ws] Incoming message: ${message.id} (${message.type})`)\n events.onWorkerMessage(message)\n this.workerWs.sendAck(message.id)\n\n if (message.type === 'prompt' || message.type === 'task_dispatch') {\n if (this.ptyManager) {\n this.ptyManager.write(message.content + '\\r')\n this.bridge.feedInput(message.content)\n }\n }\n },\n onRegistered: (data) => {\n log(`[worker-ws] Registered: worker_id=${data.worker_id}, folder_id=${data.folder_id}, status=${data.status}`)\n events.onWorkerRegistered(data)\n if (!data.folder_id) {\n events.onWorkerStatus('no_project')\n }\n },\n onTerminalInput: (data: string) => {\n this.ptyManager?.write(data)\n },\n })\n\n this.bridge.setWsClient(this.workerWs)\n }\n\n // \u2500\u2500\u2500 Settings \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n getActiveProfile(): Profile {\n return this.settings.profiles[this.settings.activeProfile] || this.settings.profiles.production || DEFAULT_PROFILES.production\n }\n\n get settingsData(): SettingsData {\n return this.settings\n }\n\n get cwd(): string | null {\n return this.currentCwd\n }\n\n get agent(): AgentConfig | null {\n return this.currentAgent\n }\n\n applyProfile(profile: Profile): void {\n const apiKey = profile.apiKey || process.env.CTLSURF_API_KEY || ''\n if (apiKey) {\n this.ctlsurfApi.setApiKey(apiKey)\n this.workerWs.setApiKey(apiKey)\n } else {\n this.ctlsurfApi.setApiKey('')\n this.workerWs.setApiKey(null)\n }\n\n const baseUrl = profile.baseUrl || process.env.CTLSURF_BASE_URL || 'https://app.ctlsurf.com'\n this.ctlsurfApi.setBaseUrl(baseUrl)\n this.workerWs.setBaseUrl(baseUrl)\n\n log(`[settings] Profile applied: ${profile.name} (${baseUrl})`)\n }\n\n loadSettings(): void {\n // Ensure settings dir exists\n try { fs.mkdirSync(this.settingsDir, { recursive: true }) } catch { /* ignore */ }\n\n const settingsPath = path.join(this.settingsDir, 'settings.json')\n try {\n if (fs.existsSync(settingsPath)) {\n const raw = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'))\n\n if (!raw.profiles) {\n this.settings = {\n activeProfile: 'production',\n profiles: {\n production: {\n name: 'Production',\n apiKey: raw.ctlsurfApiKey || '',\n baseUrl: raw.ctlsurfBaseUrl || 'https://app.ctlsurf.com',\n dataspacePageId: raw.ctlsurfDataspacePageId || '',\n },\n },\n }\n this.saveSettings()\n log('[settings] Migrated legacy settings to profiles')\n } else {\n this.settings = raw as SettingsData\n if (!this.settings.profiles.production) {\n this.settings.profiles.production = { ...DEFAULT_PROFILES.production }\n }\n }\n }\n } catch {\n this.settings = {\n activeProfile: 'production',\n profiles: { ...DEFAULT_PROFILES },\n }\n }\n\n this.applyProfile(this.getActiveProfile())\n }\n\n saveSettings(): void {\n const settingsPath = path.join(this.settingsDir, 'settings.json')\n try {\n fs.mkdirSync(this.settingsDir, { recursive: true })\n fs.writeFileSync(settingsPath, JSON.stringify(this.settings, null, 2))\n } catch (err: any) {\n log('[settings] Failed to save:', err.message)\n }\n }\n\n overrideApiKey(key: string): void {\n this.ctlsurfApi.setApiKey(key)\n this.workerWs.setApiKey(key)\n }\n\n overrideBaseUrl(url: string): void {\n this.ctlsurfApi.setBaseUrl(url)\n this.workerWs.setBaseUrl(url)\n }\n\n // \u2500\u2500\u2500 Profile CRUD \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n listProfiles() {\n return {\n activeProfile: this.settings.activeProfile,\n profiles: Object.entries(this.settings.profiles).map(([id, p]) => ({\n id,\n name: p.name,\n baseUrl: p.baseUrl,\n hasApiKey: !!p.apiKey,\n dataspacePageId: p.dataspacePageId || null,\n })),\n }\n }\n\n getProfile(profileId: string) {\n const p = this.settings.profiles[profileId]\n if (!p) return null\n return {\n id: profileId,\n name: p.name,\n baseUrl: p.baseUrl,\n hasApiKey: !!p.apiKey,\n dataspacePageId: p.dataspacePageId || '',\n }\n }\n\n saveProfile(profileId: string, data: { name: string; apiKey?: string; baseUrl: string; dataspacePageId: string }) {\n const existing = this.settings.profiles[profileId]\n this.settings.profiles[profileId] = {\n name: data.name,\n apiKey: data.apiKey !== undefined ? data.apiKey : (existing?.apiKey || ''),\n baseUrl: data.baseUrl || 'https://app.ctlsurf.com',\n dataspacePageId: data.dataspacePageId || '',\n }\n this.saveSettings()\n\n if (profileId === this.settings.activeProfile) {\n this.applyProfile(this.settings.profiles[profileId])\n if (this.currentAgent && this.currentCwd) {\n this.workerWs.disconnect()\n this.connectWorkerWs(this.currentAgent, this.currentCwd)\n }\n }\n }\n\n switchProfile(profileId: string): { ok: boolean; error?: string } {\n if (!this.settings.profiles[profileId]) return { ok: false, error: 'Profile not found' }\n this.workerWs.disconnect()\n this.settings.activeProfile = profileId\n this.saveSettings()\n this.applyProfile(this.getActiveProfile())\n if (this.currentAgent && this.currentCwd) {\n this.connectWorkerWs(this.currentAgent, this.currentCwd)\n }\n return { ok: true }\n }\n\n deleteProfile(profileId: string): { ok: boolean; error?: string } {\n if (profileId === 'production') return { ok: false, error: 'Cannot delete Production profile' }\n if (!this.settings.profiles[profileId]) return { ok: false, error: 'Profile not found' }\n\n if (this.settings.activeProfile === profileId) {\n this.workerWs.disconnect()\n this.settings.activeProfile = 'production'\n this.applyProfile(this.getActiveProfile())\n if (this.currentAgent && this.currentCwd) {\n this.connectWorkerWs(this.currentAgent, this.currentCwd)\n }\n }\n\n delete this.settings.profiles[profileId]\n this.saveSettings()\n return { ok: true }\n }\n\n // \u2500\u2500\u2500 PTY & Agent \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async spawnAgent(agent: AgentConfig, cwd: string): Promise<void> {\n if (this.ptyManager) {\n this.bridge.endSession()\n this.ptyManager.kill()\n }\n\n this.currentAgent = agent\n const prevCwd = this.currentCwd\n this.currentCwd = cwd\n if (prevCwd !== cwd) {\n this.events.onCwdChanged()\n }\n\n this.ptyManager = new PtyManager(agent, cwd)\n\n this.ptyManager.onData((data: string) => {\n this.events.onPtyData(data)\n this.bridge.feedOutput(data)\n this.streamTerminalData(data)\n })\n\n const thisPtyManager = this.ptyManager\n\n this.ptyManager.onExit(async (exitCode: number) => {\n this.events.onPtyExit(exitCode)\n this.bridge.endSession()\n if (thisPtyManager === this.ptyManager && this.currentAgent && isCodingAgent(this.currentAgent)) {\n this.workerWs.disconnect()\n }\n })\n\n this.bridge.startSession()\n\n if (isCodingAgent(agent)) {\n this.connectWorkerWs(agent, cwd)\n } else {\n this.workerWs.disconnect()\n this.checkProjectStatus(cwd)\n }\n }\n\n writePty(data: string): void {\n this.ptyManager?.write(data)\n this.bridge.feedInput(data)\n }\n\n resizePty(cols: number, rows: number): void {\n this.ptyManager?.resize(cols, rows)\n this.bridge.resize(cols, rows)\n this.workerWs.sendTerminalResize(cols, rows)\n }\n\n async killAgent(): Promise<void> {\n this.bridge.endSession()\n this.ptyManager?.kill()\n this.ptyManager = null\n if (this.currentAgent && isCodingAgent(this.currentAgent)) {\n this.workerWs.disconnect()\n }\n }\n\n // \u2500\u2500\u2500 Worker WebSocket \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n connectWorkerWs(agent: AgentConfig, cwd: string): void {\n const profile = this.getActiveProfile()\n const apiKey = profile.apiKey || process.env.CTLSURF_API_KEY\n if (!apiKey) {\n log('[worker-ws] No API key, skipping WS connect')\n return\n }\n\n this.workerWs.connect({\n machine: os.hostname(),\n cwd,\n agent: agent.name,\n })\n }\n\n private async checkProjectStatus(cwd: string): Promise<void> {\n if (!this.ctlsurfApi.getApiKey()) {\n this.events.onWorkerStatus('no_project')\n return\n }\n try {\n const folder = await this.ctlsurfApi.findFolderByPath(cwd)\n if (!folder?.id) {\n this.events.onWorkerStatus('no_project')\n }\n } catch {\n this.events.onWorkerStatus('no_project')\n }\n }\n\n private streamTerminalData(data: string): void {\n this.termStreamBuffer += data\n if (!this.termStreamTimer) {\n this.termStreamTimer = setTimeout(() => {\n if (this.termStreamBuffer) {\n this.workerWs.sendTerminalData(this.termStreamBuffer)\n this.termStreamBuffer = ''\n }\n this.termStreamTimer = null\n }, TERM_STREAM_INTERVAL_MS)\n }\n }\n\n // \u2500\u2500\u2500 Shutdown \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async shutdown(): Promise<void> {\n this.bridge.endSession()\n this.ptyManager?.kill()\n this.ptyManager = null\n this.workerWs.disconnect()\n if (this.termStreamTimer) {\n clearTimeout(this.termStreamTimer)\n this.termStreamTimer = null\n }\n }\n}\n", "import { createRequire } from 'module'\nimport { AgentConfig } from './agents'\n\n// Use createRequire to load native module at runtime, bypassing bundler\nconst require = createRequire(import.meta.url)\nconst pty = require('node-pty')\n\nexport class PtyManager {\n private process: any | null = null\n private dataCallbacks: ((data: string) => void)[] = []\n private exitCallbacks: ((code: number) => void)[] = []\n\n constructor(agent: AgentConfig, cwd: string) {\n const shell = agent.command\n const args = agent.args || []\n\n try {\n console.log(`[pty] Spawning: ${shell} ${args.join(' ')} in ${cwd}`)\n } catch {\n // Ignore EPIPE errors when stdout is closed\n }\n\n this.process = pty.spawn(shell, args, {\n name: 'xterm-256color',\n cwd,\n env: process.env as Record<string, string>,\n cols: 80,\n rows: 24\n })\n\n this.process.onData((data: string) => {\n for (const cb of this.dataCallbacks) {\n cb(data)\n }\n })\n\n this.process.onExit(({ exitCode }: { exitCode: number }) => {\n for (const cb of this.exitCallbacks) {\n cb(exitCode)\n }\n this.process = null\n })\n }\n\n write(data: string): void {\n this.process?.write(data)\n }\n\n resize(cols: number, rows: number): void {\n this.process?.resize(cols, rows)\n }\n\n kill(): void {\n this.process?.kill()\n this.process = null\n }\n\n onData(cb: (data: string) => void): void {\n this.dataCallbacks.push(cb)\n }\n\n onExit(cb: (code: number) => void): void {\n this.exitCallbacks.push(cb)\n }\n}\n", "export interface AgentConfig {\n id: string\n name: string\n command: string\n args: string[]\n description: string\n}\n\nfunction getShellCommand(): string {\n if (process.platform === 'win32') return 'powershell.exe'\n return process.env.SHELL || '/bin/zsh'\n}\n\nexport function getBuiltinAgents(): AgentConfig[] {\n return [\n {\n id: 'shell',\n name: 'Shell',\n command: getShellCommand(),\n args: ['-l'], // login shell to load PATH\n description: 'Default system shell'\n },\n {\n id: 'claude',\n name: 'Claude Code',\n command: 'claude',\n args: [],\n description: 'Anthropic Claude Code CLI'\n },\n {\n id: 'codex',\n name: 'Codex CLI',\n command: 'codex',\n args: [],\n description: 'OpenAI Codex CLI'\n }\n ]\n}\n\nexport function getDefaultAgent(): AgentConfig {\n return getBuiltinAgents()[0]\n}\n\nexport function isCodingAgent(agent: AgentConfig): boolean {\n return agent.id !== 'shell'\n}\n", "const CTLSURF_BASE_URL = 'https://app.ctlsurf.com/api'\n\nexport class CtlsurfApi {\n private baseUrl: string\n private apiKey: string | null = null\n\n constructor(baseUrl?: string) {\n this.baseUrl = baseUrl || CTLSURF_BASE_URL\n }\n\n setApiKey(key: string): void {\n this.apiKey = key\n }\n\n setBaseUrl(url: string): void {\n this.baseUrl = url.endsWith('/api') ? url : `${url}/api`\n }\n\n getApiKey(): string | null {\n return this.apiKey\n }\n\n private headers(): Record<string, string> {\n const h: Record<string, string> = { 'Content-Type': 'application/json' }\n if (this.apiKey) {\n h['Authorization'] = `Bearer ${this.apiKey}`\n }\n return h\n }\n\n private async request(method: string, path: string, body?: unknown): Promise<any> {\n const url = `${this.baseUrl}${path}`\n const opts: RequestInit = {\n method,\n headers: this.headers()\n }\n if (body) {\n opts.body = JSON.stringify(body)\n }\n\n const res = await fetch(url, opts)\n if (!res.ok) {\n const text = await res.text()\n throw new Error(`ctlsurf API ${method} ${path}: ${res.status} ${text}`)\n }\n return res.json()\n }\n\n // \u2500\u2500\u2500 Pages \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async createPage(params: {\n title: string\n type?: string\n parent_id?: string\n folder_id?: string\n cwd?: string\n tags?: string[]\n }): Promise<any> {\n return this.request('POST', '/pages', params)\n }\n\n async findPageByRootPath(rootPath: string): Promise<any> {\n return this.request('POST', '/pages/find-by-root-path', { root_path: rootPath })\n }\n\n // \u2500\u2500\u2500 Blocks \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async createBlock(pageId: string, params: {\n type: string\n title?: string\n props?: Record<string, unknown>\n }): Promise<any> {\n return this.request('POST', `/blocks/page/${pageId}`, params)\n }\n\n async getBlock(blockId: string): Promise<any> {\n return this.request('GET', `/blocks/${blockId}`)\n }\n\n async updateBlock(blockId: string, params: {\n props?: Record<string, unknown>\n title?: string\n }): Promise<any> {\n return this.request('PUT', `/blocks/${blockId}`, params)\n }\n\n // \u2500\u2500\u2500 Folders \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async createFolder(params: { name: string; root_path: string }): Promise<any> {\n return this.request('POST', '/folders', params)\n }\n\n // \u2500\u2500\u2500 Workers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async getAuthCode(): Promise<{ code: string }> {\n return this.request('POST', '/workers/token-exchange')\n }\n\n async findFolderByPath(rootPath: string): Promise<any> {\n return this.request('POST', '/folders/find-by-path', { root_path: rootPath })\n }\n\n async getFolderPages(folderId: string): Promise<any[]> {\n const folder = await this.request('GET', `/folders/${folderId}`)\n return folder?.pages || []\n }\n\n async findFolderByGitRemote(gitRemote: string): Promise<any> {\n // Search folders by listing all and matching git_remote\n const folders = await this.request('GET', '/folders')\n return folders?.find((f: any) => f.git_remote === gitRemote || f.root_path === gitRemote) || null\n }\n\n // \u2500\u2500\u2500 Log convenience \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n async appendLog(blockId: string, action: string, message: string, data?: Record<string, unknown>): Promise<any> {\n // Read-modify-write: get current entries, append, put back\n const block = await this.getBlock(blockId)\n const props = block.props || {}\n const entries = Array.isArray(props.entries) ? [...props.entries] : []\n const maxEntries = props.max_entries || 1000\n\n const entry: Record<string, unknown> = {\n _id: `log_${entries.length}`,\n _timestamp: new Date().toISOString(),\n action,\n message\n }\n if (data) {\n entry.data = data\n }\n\n entries.push(entry)\n\n // Trim oldest if over max\n const trimmed = entries.length > maxEntries ? entries.slice(-maxEntries) : entries\n\n return this.updateBlock(blockId, {\n props: { ...props, entries: trimmed }\n })\n }\n}\n", "import { WorkerWsClient } from './workerWs'\n\n/**\n * Conversation Bridge\n *\n * Captures PTY output, strips ANSI codes and terminal artifacts,\n * and sends cleaned text to the backend via WebSocket for chat logging.\n * Uses a simple buffer + byte threshold approach (no timers, since\n * setTimeout/setInterval don't reliably fire under TUI raw mode).\n */\nexport class ConversationBridge {\n private wsClient: WorkerWsClient | null = null\n private sessionActive: boolean = false\n private inputBuffer: string = ''\n private outputBuffer: string = ''\n\n private readonly FLUSH_BYTES = 500\n\n setWsClient(ws: WorkerWsClient): void {\n this.wsClient = ws\n }\n\n startSession(): void {\n this.outputBuffer = ''\n this.inputBuffer = ''\n this.sessionActive = true\n console.log('[bridge] Session started')\n }\n\n feedOutput(data: string): void {\n if (!this.sessionActive) return\n\n this.outputBuffer += data\n\n if (this.outputBuffer.length >= this.FLUSH_BYTES) {\n this.flush()\n }\n }\n\n feedInput(data: string): void {\n if (!this.sessionActive) return\n this.inputBuffer += data\n\n if (data.includes('\\r') || data.includes('\\n')) {\n const cleaned = cleanInput(this.inputBuffer)\n if (cleaned.length > 0) {\n this.sendEntry('user_input', cleaned)\n }\n this.inputBuffer = ''\n }\n }\n\n resize(_cols: number, _rows: number): void {\n // no-op now (was used for xterm)\n }\n\n private flush(): void {\n if (this.outputBuffer.length === 0) return\n\n const raw = this.outputBuffer\n this.outputBuffer = ''\n\n const cleaned = cleanOutput(raw)\n if (cleaned.length === 0) return\n\n this.sendEntry('terminal_output', cleaned)\n }\n\n private sendEntry(type: string, content: string): void {\n if (!this.wsClient) return\n this.wsClient.sendChatLog({\n ts: new Date().toISOString(),\n type,\n content,\n })\n }\n\n endSession(): void {\n if (!this.sessionActive) return\n\n this.flush()\n\n this.sessionActive = false\n this.inputBuffer = ''\n this.outputBuffer = ''\n console.log('[bridge] Session ended')\n }\n}\n\n/**\n * Strip ANSI escape codes from a string.\n */\nfunction stripAnsi(str: string): string {\n return str\n // CSI sequences (e.g. \\x1b[0m, \\x1b[?2004h, \\x1b[1;32m, \\x1b[38;2;r;g;bm)\n .replace(/\\x1b\\[[\\x30-\\x3f]*[\\x20-\\x2f]*[\\x40-\\x7e]/g, '')\n // OSC sequences (e.g. \\x1b]0;title\\x07, \\x1b]...\\x1b\\\\)\n .replace(/\\x1b\\][^\\x07\\x1b]*(?:\\x07|\\x1b\\\\)/g, '')\n // DCS/PM/APC sequences\n .replace(/\\x1b[PX^_][^\\x1b]*\\x1b\\\\/g, '')\n // Other escape sequences (charset, keypad mode, etc.)\n .replace(/\\x1b[^[\\]PX^_](.|$)/g, '')\n // Remaining single ESC\n .replace(/\\x1b/g, '')\n}\n\n/**\n * Process backspace characters: each \\x7f or \\b deletes the preceding char.\n */\nfunction processBackspaces(str: string): string {\n const result: string[] = []\n for (const ch of str) {\n if (ch === '\\x7f' || ch === '\\b') {\n result.pop()\n } else {\n result.push(ch)\n }\n }\n return result.join('')\n}\n\n/**\n * Clean user input: strip ANSI, process backspaces, remove control chars.\n */\nfunction cleanInput(str: string): string {\n let cleaned = stripAnsi(str)\n cleaned = processBackspaces(cleaned)\n // eslint-disable-next-line no-control-regex\n cleaned = cleaned.replace(/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/g, '')\n return cleaned.trim()\n}\n\n/**\n * Clean terminal output: strip ANSI, remove control chars, collapse noise.\n */\nfunction cleanOutput(str: string): string {\n let cleaned = stripAnsi(str)\n // Remove carriage returns\n cleaned = cleaned.replace(/\\r/g, '')\n // Remove control characters except newline/tab\n // eslint-disable-next-line no-control-regex\n cleaned = cleaned.replace(/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/g, '')\n // Collapse 3+ consecutive newlines into 2\n cleaned = cleaned.replace(/\\n{3,}/g, '\\n\\n')\n // Remove lines that are only whitespace\n cleaned = cleaned.split('\\n').filter(line => line.trim().length > 0).join('\\n')\n return cleaned.trim()\n}\n", "import os from 'os'\nimport crypto from 'crypto'\nimport WsModule from 'ws'\n\n// Use native WebSocket if available (Node 22+), otherwise fall back to ws package\nconst WS: typeof WebSocket = typeof WebSocket !== 'undefined' ? WebSocket : WsModule as any\n\nfunction log(...args: unknown[]): void {\n try { console.log(...args) } catch { /* EPIPE safe */ }\n}\n\nconst HEARTBEAT_INTERVAL_MS = 30_000\nconst RECONNECT_DELAY_MS = 5_000\nconst MAX_RECONNECT_DELAY_MS = 60_000\n\nexport interface WorkerRegistration {\n machine: string\n cwd: string\n repo_url?: string\n agent: string\n fingerprint: string\n}\n\nexport interface WorkerWsEvents {\n onStatusChange: (status: WorkerWsStatus) => void\n onMessage: (message: IncomingMessage) => void\n onRegistered: (data: { worker_id: string; folder_id: string | null; status: string; pending_messages?: IncomingMessage[] }) => void\n onTerminalInput?: (data: string) => void\n}\n\nexport interface IncomingMessage {\n id: string\n type: string\n content: string\n metadata?: Record<string, unknown> | null\n parent_id?: string | null\n}\n\nexport type WorkerWsStatus = 'disconnected' | 'connecting' | 'connected' | 'pending_approval'\n\nexport class WorkerWsClient {\n private ws: WebSocket | null = null\n private apiKey: string | null = null\n private baseUrl: string\n private events: WorkerWsEvents\n private heartbeatTimer: ReturnType<typeof setInterval> | null = null\n private reconnectTimer: ReturnType<typeof setTimeout> | null = null\n private reconnectDelay = RECONNECT_DELAY_MS\n private registration: WorkerRegistration | null = null\n private workerId: string | null = null\n private _status: WorkerWsStatus = 'disconnected'\n private shouldReconnect = false\n private fingerprint: string\n\n constructor(events: WorkerWsEvents, baseUrl?: string) {\n this.events = events\n this.baseUrl = baseUrl || 'wss://app.ctlsurf.com'\n // Generate a stable machine fingerprint\n this.fingerprint = this.generateFingerprint()\n }\n\n get status(): WorkerWsStatus {\n return this._status\n }\n\n get currentWorkerId(): string | null {\n return this.workerId\n }\n\n setApiKey(key: string | null): void {\n this.apiKey = key\n }\n\n setBaseUrl(url: string): void {\n this.baseUrl = url\n }\n\n private generateFingerprint(): string {\n const data = `${os.hostname()}:${os.userInfo().username}:${os.platform()}:${os.arch()}`\n return crypto.createHash('sha256').update(data).digest('hex').slice(0, 32)\n }\n\n private setStatus(status: WorkerWsStatus): void {\n if (this._status !== status) {\n this._status = status\n this.events.onStatusChange(status)\n }\n }\n\n connect(registration: WorkerRegistration): void {\n this.registration = { ...registration, fingerprint: this.fingerprint }\n this.shouldReconnect = true\n this.doConnect()\n }\n\n disconnect(): void {\n this.shouldReconnect = false\n this.clearTimers()\n if (this.ws) {\n const oldWs = this.ws\n this.ws = null\n // Remove handlers before closing to prevent stale onclose from firing\n oldWs.onopen = null\n oldWs.onmessage = null\n oldWs.onclose = null\n oldWs.onerror = null\n try { oldWs.close(1000, 'client disconnect') } catch { /* ignore */ }\n }\n this.setStatus('disconnected')\n }\n\n sendResponse(parentId: string, content: string, metadata?: Record<string, unknown>): void {\n this.send({\n type: 'response',\n parent_id: parentId,\n content,\n metadata,\n })\n }\n\n sendStatusUpdate(status: string): void {\n this.send({ type: 'status_update', status })\n }\n\n sendAck(messageId: string): void {\n this.send({ type: 'ack', message_id: messageId })\n }\n\n sendTerminalData(data: string): void {\n this.send({ type: 'terminal_stream', data })\n }\n\n sendTerminalResize(cols: number, rows: number): void {\n this.send({ type: 'terminal_resize', cols, rows })\n }\n\n sendChatLog(entry: { type: string; content: string; ts?: string }): void {\n this.send({ type: 'chat_log', entry })\n }\n\n private doConnect(): void {\n if (!this.apiKey || !this.registration) {\n log('[worker-ws] No API key or registration, skipping connect')\n return\n }\n\n this.clearTimers()\n if (this.ws) {\n const oldWs = this.ws\n this.ws = null\n oldWs.onopen = null\n oldWs.onmessage = null\n oldWs.onclose = null\n oldWs.onerror = null\n try { oldWs.close() } catch { /* ignore */ }\n // Let the old connection fully close before opening a new one\n setTimeout(() => this.doConnectNow(), 500)\n return\n }\n\n this.doConnectNow()\n }\n\n private doConnectNow(): void {\n if (!this.apiKey || !this.registration) return\n if (!this.shouldReconnect) {\n log('[worker-ws] shouldReconnect is false, aborting connect')\n return\n }\n\n this.setStatus('connecting')\n\n // Use ws:// for localhost, wss:// for remote\n const wsBase = this.baseUrl.replace(/^http/, 'ws')\n const url = `${wsBase}/api/ws/worker?token=${encodeURIComponent(this.apiKey)}`\n\n log(`[worker-ws] Connecting to ${url.replace(/token=.*/, 'token=***')}...`)\n\n try {\n this.ws = new WS(url) as unknown as WebSocket\n } catch (err) {\n log('[worker-ws] Failed to create WebSocket:', err)\n this.scheduleReconnect()\n return\n }\n\n this.ws.onopen = () => {\n log('[worker-ws] Connected, sending register')\n this.reconnectDelay = RECONNECT_DELAY_MS // Reset backoff\n this.send({\n type: 'register',\n ...this.registration,\n })\n this.startHeartbeat()\n }\n\n this.ws.onmessage = (event) => {\n try {\n const data = JSON.parse(String(event.data))\n this.handleMessage(data)\n } catch (err) {\n log('[worker-ws] Failed to parse message:', err)\n }\n }\n\n this.ws.onclose = (event) => {\n log(`[worker-ws] Disconnected: ${event.code} ${event.reason}`)\n this.ws = null\n this.clearHeartbeat()\n this.setStatus('disconnected')\n if (this.shouldReconnect) {\n this.scheduleReconnect()\n }\n }\n\n this.ws.onerror = () => {\n log('[worker-ws] WebSocket error')\n }\n }\n\n private handleMessage(data: Record<string, unknown>): void {\n const msgType = data.type as string\n\n switch (msgType) {\n case 'registered': {\n this.workerId = data.worker_id as string\n const workerStatus = data.status as string\n console.log(`[worker-ws] Registered as ${this.workerId}, status: ${workerStatus}`)\n\n if (workerStatus === 'pending_approval') {\n this.setStatus('pending_approval')\n } else {\n this.setStatus('connected')\n }\n\n const pendingMessages = (data.pending_messages || []) as IncomingMessage[]\n this.events.onRegistered({\n worker_id: this.workerId,\n folder_id: data.folder_id as string | null,\n status: workerStatus,\n pending_messages: pendingMessages,\n })\n\n // Deliver pending messages\n for (const msg of pendingMessages) {\n this.events.onMessage(msg)\n }\n break\n }\n\n case 'approved': {\n log('[worker-ws] Worker approved!')\n this.setStatus('connected')\n break\n }\n\n case 'message': {\n const msg = data.message as IncomingMessage\n if (msg) {\n console.log(`[worker-ws] Received message: ${msg.id}`)\n this.events.onMessage(msg)\n }\n break\n }\n\n case 'terminal_input': {\n const inputData = data.data as string\n if (inputData && this.events.onTerminalInput) {\n this.events.onTerminalInput(inputData)\n }\n break\n }\n\n case 'heartbeat_ack':\n break\n\n default:\n console.log(`[worker-ws] Unknown message type: ${msgType}`)\n }\n }\n\n private send(data: Record<string, unknown>): void {\n if (this.ws && this.ws.readyState === WS.OPEN) {\n this.ws.send(JSON.stringify(data))\n }\n }\n\n\n private startHeartbeat(): void {\n this.clearHeartbeat()\n this.heartbeatTimer = setInterval(() => {\n this.send({ type: 'heartbeat' })\n }, HEARTBEAT_INTERVAL_MS)\n }\n\n private clearHeartbeat(): void {\n if (this.heartbeatTimer) {\n clearInterval(this.heartbeatTimer)\n this.heartbeatTimer = null\n }\n }\n\n private scheduleReconnect(): void {\n if (!this.shouldReconnect) return\n console.log(`[worker-ws] Reconnecting in ${this.reconnectDelay / 1000}s...`)\n this.reconnectTimer = setTimeout(() => {\n this.doConnect()\n }, this.reconnectDelay)\n // Exponential backoff\n this.reconnectDelay = Math.min(this.reconnectDelay * 2, MAX_RECONNECT_DELAY_MS)\n }\n\n private clearTimers(): void {\n this.clearHeartbeat()\n if (this.reconnectTimer) {\n clearTimeout(this.reconnectTimer)\n this.reconnectTimer = null\n }\n }\n}\n", "import path from 'path'\nimport os from 'os'\n\nexport function getSettingsDir(useElectron: boolean): string {\n if (useElectron) {\n const { app } = require('electron')\n return app.getPath('userData')\n }\n\n if (process.platform === 'darwin') {\n return path.join(os.homedir(), 'Library', 'Application Support', 'ctlsurf-worker')\n }\n return path.join(\n process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'),\n 'ctlsurf-worker'\n )\n}\n", "/**\n * Terminal UI (TUI) renderer\n *\n * Draws a title bar and status bar around the PTY output area.\n * Uses ANSI escape codes and scroll regions \u2014 no external dependencies.\n */\n\nconst ESC = '\\x1b'\nconst CSI = `${ESC}[`\n\n// Colors (Tokyo Night palette)\nconst BG_BAR = `${CSI}48;2;22;22;30m` // #16161e\nconst FG_TITLE = `${CSI}38;2;192;202;245m` // #c0caf5\nconst FG_DIM = `${CSI}38;2;86;95;137m` // #565f89\nconst FG_ACCENT = `${CSI}38;2;122;162;247m` // #7aa2f7\nconst FG_GREEN = `${CSI}38;2;158;206;106m` // #9ece6a\nconst FG_RED = `${CSI}38;2;247;118;142m` // #f7768e\nconst FG_YELLOW = `${CSI}38;2;224;175;104m` // #e0af68\nconst FG_WHITE = `${CSI}38;2;169;177;214m` // #a9b1d6\nconst BG_MODAL = `${CSI}48;2;31;35;53m` // #1f2335\nconst BG_SELECTED = `${CSI}48;2;42;43;61m` // #2a2b3d\nconst RESET = `${CSI}0m`\n\nexport interface TuiState {\n agentName: string\n cwd: string\n wsStatus: string\n workerId: string | null\n mode: string\n}\n\nexport class Tui {\n private rows: number = 0\n private cols: number = 0\n private state: TuiState = {\n agentName: '',\n cwd: '',\n wsStatus: 'disconnected',\n workerId: null,\n mode: 'terminal',\n }\n\n constructor() {\n this.rows = process.stdout.rows || 24\n this.cols = process.stdout.columns || 80\n }\n\n /**\n * Initialize the TUI: alternate screen, hide cursor reporting, set scroll region\n */\n init(): void {\n // Alternate screen buffer\n this.write(`${CSI}?1049h`)\n // Set scroll region: lines 2 to (rows - 1), leaving line 1 for title, line rows for status\n this.setScrollRegion()\n // Move cursor to the PTY area\n this.moveToPtyArea()\n // Draw chrome\n this.drawTitleBar()\n this.drawStatusBar()\n }\n\n /**\n * Restore terminal to normal state\n */\n destroy(): void {\n // Reset scroll region\n this.write(`${CSI}r`)\n // Leave alternate screen\n this.write(`${CSI}?1049l`)\n // Show cursor\n this.write(`${CSI}?25h`)\n }\n\n /**\n * Handle terminal resize\n */\n resize(cols: number, rows: number): void {\n this.cols = cols\n this.rows = rows\n this.setScrollRegion()\n this.drawTitleBar()\n this.drawStatusBar()\n this.moveToPtyArea()\n }\n\n /**\n * Get the PTY dimensions (main area minus title + status bars)\n */\n getPtySize(): { cols: number; rows: number } {\n return {\n cols: this.cols,\n rows: Math.max(1, this.rows - 2),\n }\n }\n\n /**\n * Update state and redraw bars\n */\n update(partial: Partial<TuiState>): void {\n Object.assign(this.state, partial)\n // Save cursor, draw bars, restore cursor\n this.write(`${CSI}s`) // save cursor\n this.drawTitleBar()\n this.drawStatusBar()\n this.write(`${CSI}u`) // restore cursor\n }\n\n /**\n * Write PTY output to the scroll region.\n * Cursor is assumed to be in the PTY area already.\n */\n writePtyData(data: string): void {\n // PTY data goes straight to stdout \u2014 it's already in the scroll region\n this.write(data)\n }\n\n /**\n * Update the terminal window/tab title via OSC escape sequence.\n * Works in passthrough mode (no chrome) \u2014 doesn't conflict with the agent's TUI.\n */\n setTerminalTitle(title: string): void {\n this.write(`${ESC}]0;${title}\\x07`)\n }\n\n /**\n * Build a title string from current state for the terminal tab.\n */\n updateTerminalTitle(): void {\n const { agentName, wsStatus, cwd } = this.state\n const displayCwd = this.shortenPath(cwd)\n const statusIcon = {\n connected: '\\u25CF',\n connecting: '\\u25CB',\n disconnected: '\\u25CB',\n pending_approval: '\\u25CB',\n no_project: '\\u25CB',\n }[wsStatus] || '\\u25CB'\n const statusLabel = {\n connected: 'Connected',\n connecting: 'Connecting...',\n disconnected: 'Disconnected',\n pending_approval: 'Pending',\n no_project: 'No Project',\n }[wsStatus] || wsStatus\n\n this.setTerminalTitle(`ctlsurf \\u00B7 ${agentName} \\u00B7 ${statusIcon} ${statusLabel} \\u00B7 ${displayCwd}`)\n }\n\n /**\n * Show an interactive agent picker modal.\n * Returns a promise that resolves with the selected agent index.\n */\n showAgentPicker(agents: { name: string; description: string }[]): Promise<number> {\n return new Promise((resolve) => {\n let selected = 0\n const modalWidth = 44\n const modalHeight = agents.length + 4 // border + title + items + border\n const startCol = Math.max(1, Math.floor((this.cols - modalWidth) / 2))\n const startRow = Math.max(1, Math.floor((this.rows - modalHeight) / 2))\n\n // Enter alternate screen if not already\n this.write(`${CSI}?1049h`)\n // Hide cursor\n this.write(`${CSI}?25l`)\n\n const drawModal = () => {\n const topBorder = '\\u250c' + '\\u2500'.repeat(modalWidth - 2) + '\\u2510'\n const botBorder = '\\u2514' + '\\u2500'.repeat(modalWidth - 2) + '\\u2518'\n const emptyLine = '\\u2502' + ' '.repeat(modalWidth - 2) + '\\u2502'\n\n // Draw background fill\n for (let r = 0; r < this.rows; r++) {\n this.write(`${CSI}${r + 1};1H${BG_BAR}${CSI}2K${RESET}`)\n }\n\n // Draw logo/branding centered\n const brand = 'ctlsurf'\n const brandCol = Math.max(1, Math.floor((this.cols - brand.length) / 2))\n this.write(`${CSI}${startRow - 2};${brandCol}H${FG_ACCENT}${brand}${RESET}`)\n\n // Top border\n this.write(`${CSI}${startRow};${startCol}H${BG_MODAL}${FG_DIM}${topBorder}${RESET}`)\n\n // Title\n const title = ' Select Agent'\n const titlePad = ' '.repeat(Math.max(0, modalWidth - 2 - title.length))\n this.write(`${CSI}${startRow + 1};${startCol}H${BG_MODAL}${FG_DIM}\\u2502${RESET}${BG_MODAL}${FG_TITLE}${title}${titlePad}${FG_DIM}\\u2502${RESET}`)\n\n // Separator\n const sep = '\\u251c' + '\\u2500'.repeat(modalWidth - 2) + '\\u2524'\n this.write(`${CSI}${startRow + 2};${startCol}H${BG_MODAL}${FG_DIM}${sep}${RESET}`)\n\n // Agent items\n for (let i = 0; i < agents.length; i++) {\n const agent = agents[i]\n const row = startRow + 3 + i\n const isSelected = i === selected\n const bg = isSelected ? BG_SELECTED : BG_MODAL\n const pointer = isSelected ? `${FG_ACCENT}\\u25B8 ` : ' '\n const nameFg = isSelected ? FG_ACCENT : FG_WHITE\n const descFg = FG_DIM\n const nameStr = agent.name\n const descStr = agent.description ? ` ${FG_DIM}\u2014 ${agent.description.slice(0, 20)}` : ''\n const content = `${pointer}${nameFg}${nameStr}${descStr}`\n const contentLen = (isSelected ? 2 : 2) + nameStr.length + (agent.description ? 3 + Math.min(20, agent.description.length) : 0)\n const pad = ' '.repeat(Math.max(0, modalWidth - 2 - contentLen))\n this.write(`${CSI}${row};${startCol}H${bg}${FG_DIM}\\u2502${RESET}${bg}${content}${pad}${RESET}${BG_MODAL}${FG_DIM}\\u2502${RESET}`)\n }\n\n // Bottom border\n const botRow = startRow + 3 + agents.length\n this.write(`${CSI}${botRow};${startCol}H${BG_MODAL}${FG_DIM}${botBorder}${RESET}`)\n\n // Hint\n const hint = '\\u2191\\u2193 navigate \u00B7 Enter select \u00B7 q quit'\n const hintCol = Math.max(1, Math.floor((this.cols - hint.length) / 2))\n this.write(`${CSI}${botRow + 2};${hintCol}H${FG_DIM}${hint}${RESET}`)\n }\n\n drawModal()\n\n // Set raw mode to capture keypresses\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(true)\n }\n process.stdin.resume()\n\n const onKey = (data: Buffer) => {\n const key = data.toString()\n\n if (key === '\\x1b[A' || key === 'k') {\n // Up\n selected = (selected - 1 + agents.length) % agents.length\n drawModal()\n } else if (key === '\\x1b[B' || key === 'j') {\n // Down\n selected = (selected + 1) % agents.length\n drawModal()\n } else if (key === '\\r' || key === '\\n') {\n // Enter \u2014 select\n cleanup()\n resolve(selected)\n } else if (key === 'q' || key === '\\x1b' || key === '\\x03') {\n // q, Escape, Ctrl+C \u2014 quit\n cleanup()\n this.write(`${CSI}?25h`) // show cursor\n this.write(`${CSI}?1049l`) // leave alt screen\n process.exit(0)\n }\n }\n\n const cleanup = () => {\n process.stdin.removeListener('data', onKey)\n // Show cursor again\n this.write(`${CSI}?25h`)\n // Clear the modal (will be redrawn by init())\n }\n\n process.stdin.on('data', onKey)\n })\n }\n\n // \u2500\u2500\u2500 Internal \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n private write(data: string): void {\n try {\n process.stdout.write(data)\n } catch { /* EPIPE safe */ }\n }\n\n private setScrollRegion(): void {\n // Scroll region from line 2 to line (rows - 1)\n this.write(`${CSI}2;${this.rows - 1}r`)\n }\n\n private moveToPtyArea(): void {\n // Move cursor to top of PTY area (line 2)\n this.write(`${CSI}2;1H`)\n }\n\n private drawTitleBar(): void {\n const { agentName, cwd, wsStatus } = this.state\n // Move to line 1\n this.write(`${CSI}1;1H`)\n // Clear line and draw\n this.write(`${BG_BAR}${CSI}2K`)\n\n const displayCwd = this.shortenPath(cwd)\n\n // WS status indicator\n const statusColor = {\n connected: FG_GREEN,\n connecting: FG_YELLOW,\n disconnected: FG_RED,\n pending_approval: FG_YELLOW,\n no_project: FG_DIM,\n }[wsStatus] || FG_DIM\n const statusLabel = {\n connected: 'Connected',\n connecting: 'Connecting...',\n disconnected: 'Disconnected',\n pending_approval: 'Pending',\n no_project: 'No Project',\n }[wsStatus] || wsStatus\n const wsIndicator = `${statusColor}\\u25CF ${statusLabel}${RESET}${BG_BAR}`\n\n const left = ` ${FG_ACCENT}ctlsurf${RESET}${BG_BAR} ${FG_DIM}\\u2502${RESET}${BG_BAR} ${FG_TITLE}${agentName || 'starting...'}${RESET}${BG_BAR} ${FG_DIM}\\u2502${RESET}${BG_BAR} ${FG_DIM}${displayCwd}${RESET}${BG_BAR}`\n const right = `${wsIndicator} ${RESET}${BG_BAR}`\n\n this.write(left)\n const pad = Math.max(0, this.cols - this.visibleLen(left) - this.visibleLen(right))\n this.write(' '.repeat(pad))\n this.write(right)\n this.write(RESET)\n }\n\n private drawStatusBar(): void {\n const { wsStatus, workerId, cwd } = this.state\n // Move to last line\n this.write(`${CSI}${this.rows};1H`)\n // Clear line and draw\n this.write(`${BG_BAR}${CSI}2K`)\n\n const statusColor = {\n connected: FG_GREEN,\n connecting: FG_YELLOW,\n disconnected: FG_RED,\n pending_approval: FG_YELLOW,\n no_project: FG_DIM,\n }[wsStatus] || FG_DIM\n\n const statusDot = `${statusColor}\\u25CF${RESET}${BG_BAR}`\n const statusLabel = {\n connected: 'Connected',\n connecting: 'Connecting...',\n disconnected: 'Disconnected',\n pending_approval: 'Pending Approval',\n no_project: 'No Project',\n }[wsStatus] || wsStatus\n\n const displayCwd = this.shortenPath(cwd)\n const left = ` ${statusDot} ${FG_DIM}${statusLabel}${RESET}${BG_BAR}`\n const right = `${FG_DIM}Ctrl+\\\\ exit${RESET}${BG_BAR} ${FG_DIM}${displayCwd} ${RESET}${BG_BAR}`\n\n this.write(left)\n const pad = Math.max(0, this.cols - this.visibleLen(left) - this.visibleLen(right))\n this.write(' '.repeat(pad))\n this.write(right)\n this.write(RESET)\n }\n\n private shortenPath(p: string): string {\n if (!p) return ''\n const home = process.env.HOME || ''\n if (home && p.startsWith(home)) {\n return '~' + p.slice(home.length)\n }\n return p\n }\n\n private visibleLen(s: string): number {\n // Strip ANSI codes to get visible length\n return s.replace(/\\x1b\\[[^m]*m/g, '').length\n }\n}\n", "#!/usr/bin/env node\n\n/**\n * ctlsurf terminal mode (TUI)\n *\n * Runs the agent in a PTY with a terminal UI: title bar, status bar,\n * conversation logging, and WebSocket control. No Electron required.\n *\n * Usage:\n * ctlsurf --terminal [--agent claude] [--cwd /path] [--api-key KEY] [--base-url URL] [--profile NAME]\n *\n * If no --agent is given, shows an interactive agent picker.\n * Press Ctrl+\\ to exit at any time.\n */\n\n// Prevent EPIPE crashes\nprocess.stdout?.on?.('error', () => {})\nprocess.stderr?.on?.('error', () => {})\nprocess.on('uncaughtException', (err) => {\n if (err.message === 'write EPIPE') return\n try { console.error('[uncaught]', err) } catch { /* ignore */ }\n})\n\nimport { Orchestrator } from './orchestrator'\nimport { getSettingsDir } from './settingsDir'\nimport { getBuiltinAgents, getDefaultAgent, isCodingAgent, type AgentConfig } from './agents'\nimport { Tui } from './tui'\n\n// \u2500\u2500\u2500 CLI arg parsing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\ninterface CliArgs {\n agent: string | null\n cwd: string\n apiKey: string | null\n baseUrl: string | null\n profile: string | null\n}\n\nfunction parseArgs(argv: string[]): CliArgs {\n const args: CliArgs = {\n agent: null,\n cwd: process.env.CTLSURF_WORKER_CWD || process.cwd(),\n apiKey: null,\n baseUrl: null,\n profile: null,\n }\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i]\n const next = argv[i + 1]\n switch (arg) {\n case '--agent': args.agent = next; i++; break\n case '--cwd': args.cwd = next; i++; break\n case '--api-key': args.apiKey = next; i++; break\n case '--base-url': args.baseUrl = next; i++; break\n case '--profile': args.profile = next; i++; break\n case '--terminal': break\n case '--desktop': break\n }\n }\n return args\n}\n\n// \u2500\u2500\u2500 Main \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nasync function main() {\n const args = parseArgs(process.argv.slice(2))\n const settingsDir = getSettingsDir(false)\n\n const tui = new Tui()\n const agents = getBuiltinAgents()\n\n // \u2500\u2500\u2500 Agent selection \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n let agent: AgentConfig\n\n if (args.agent) {\n const found = agents.find(a => a.id === args.agent)\n agent = found || {\n id: args.agent,\n name: args.agent,\n command: args.agent,\n args: [],\n description: `Custom agent: ${args.agent}`,\n }\n } else {\n // Show interactive picker\n const selectedIdx = await tui.showAgentPicker(agents)\n agent = agents[selectedIdx]\n }\n\n // \u2500\u2500\u2500 Start TUI + agent \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n tui.update({\n agentName: agent.name,\n cwd: args.cwd,\n mode: 'terminal',\n })\n\n tui.init()\n\n const orchestrator = new Orchestrator(settingsDir, {\n onPtyData: (data) => {\n tui.writePtyData(data)\n },\n onPtyExit: (code) => {\n tui.destroy()\n console.log(`Agent exited with code ${code}`)\n orchestrator.shutdown().then(() => process.exit(code))\n },\n onWorkerStatus: (status) => {\n tui.update({ wsStatus: status })\n },\n onWorkerMessage: () => {},\n onWorkerRegistered: () => {\n tui.update({ wsStatus: 'connected' })\n },\n onCwdChanged: () => {\n tui.update({ cwd: orchestrator.cwd || '' })\n },\n })\n\n orchestrator.loadSettings()\n\n if (args.profile) orchestrator.switchProfile(args.profile)\n if (args.apiKey) orchestrator.overrideApiKey(args.apiKey)\n if (args.baseUrl) orchestrator.overrideBaseUrl(args.baseUrl)\n\n // Spawn agent with PTY sized to fit the TUI content area\n const ptySize = tui.getPtySize()\n await orchestrator.spawnAgent(agent, args.cwd)\n orchestrator.resizePty(ptySize.cols, ptySize.rows)\n\n // For coding agents, send an initial prompt to kick-start them\n if (isCodingAgent(agent)) {\n setTimeout(() => {\n orchestrator.writePty('hello\\r')\n }, 1000)\n }\n\n // Pipe stdin to PTY, with Ctrl+\\ as the exit key\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(true)\n process.stdin.resume()\n process.stdin.on('data', (data) => {\n const str = data.toString()\n // Ctrl+\\ (0x1c) = exit\n if (str === '\\x1c') {\n shutdown()\n return\n }\n orchestrator.writePty(str)\n })\n }\n\n // Handle terminal resize\n process.stdout.on('resize', () => {\n const cols = process.stdout.columns || 80\n const rows = process.stdout.rows || 24\n tui.resize(cols, rows)\n const size = tui.getPtySize()\n orchestrator.resizePty(size.cols, size.rows)\n })\n\n // Graceful shutdown\n const shutdown = async () => {\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(false)\n }\n tui.destroy()\n await orchestrator.shutdown()\n process.exit(0)\n }\n\n process.on('SIGINT', shutdown)\n process.on('SIGTERM', shutdown)\n}\n\nmain().catch((err) => {\n process.stdout.write('\\x1b[?1049l')\n console.error('Fatal error:', err)\n process.exit(1)\n})\n"],
5
5
  "mappings": ";;;;;;;;;;;;;AAAA;AAAA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AC;",
6
6
  "names": ["fs", "path", "os", "require", "path", "log", "os", "path", "os"]
7
7
  }
package/out/main/index.js CHANGED
@@ -207,7 +207,7 @@ class ConversationBridge {
207
207
  sessionActive = false;
208
208
  inputBuffer = "";
209
209
  outputBuffer = "";
210
- FLUSH_BYTES = 2e3;
210
+ FLUSH_BYTES = 500;
211
211
  setWsClient(ws) {
212
212
  this.wsClient = ws;
213
213
  }
@@ -1,6 +1,6 @@
1
- import { c as createWebWorker, l as languages } from "./index-Bml7oDn9.js";
2
- import { C as CompletionAdapter, H as HoverAdapter, D as DocumentHighlightAdapter, a as DefinitionAdapter, R as ReferenceAdapter, b as DocumentSymbolAdapter, c as RenameAdapter, d as DocumentColorAdapter, F as FoldingRangeAdapter, e as DiagnosticsAdapter, S as SelectionRangeAdapter, f as DocumentFormattingEditProvider, g as DocumentRangeFormattingEditProvider } from "./lspLanguageFeatures-DzxH499X.js";
3
- import { h, i, j, t, k } from "./lspLanguageFeatures-DzxH499X.js";
1
+ import { c as createWebWorker, l as languages } from "./index-CpDga7fF.js";
2
+ import { C as CompletionAdapter, H as HoverAdapter, D as DocumentHighlightAdapter, a as DefinitionAdapter, R as ReferenceAdapter, b as DocumentSymbolAdapter, c as RenameAdapter, d as DocumentColorAdapter, F as FoldingRangeAdapter, e as DiagnosticsAdapter, S as SelectionRangeAdapter, f as DocumentFormattingEditProvider, g as DocumentRangeFormattingEditProvider } from "./lspLanguageFeatures-BMM3SRX4.js";
3
+ import { h, i, j, t, k } from "./lspLanguageFeatures-BMM3SRX4.js";
4
4
  const STOP_WHEN_IDLE_FOR = 2 * 60 * 1e3;
5
5
  class WorkerManager {
6
6
  constructor(defaults) {
@@ -1,4 +1,4 @@
1
- import { l as languages } from "./index-Bml7oDn9.js";
1
+ import { l as languages } from "./index-CpDga7fF.js";
2
2
  const EMPTY_ELEMENTS = [
3
3
  "assign",
4
4
  "flush",
@@ -1,4 +1,4 @@
1
- import { l as languages } from "./index-Bml7oDn9.js";
1
+ import { l as languages } from "./index-CpDga7fF.js";
2
2
  const EMPTY_ELEMENTS = [
3
3
  "area",
4
4
  "base",
@@ -1,4 +1,4 @@
1
- import { l as languages } from "./index-Bml7oDn9.js";
1
+ import { l as languages } from "./index-CpDga7fF.js";
2
2
  const EMPTY_ELEMENTS = [
3
3
  "area",
4
4
  "base",
@@ -1,6 +1,6 @@
1
- import { c as createWebWorker, l as languages } from "./index-Bml7oDn9.js";
2
- import { H as HoverAdapter, D as DocumentHighlightAdapter, h as DocumentLinkAdapter, F as FoldingRangeAdapter, b as DocumentSymbolAdapter, S as SelectionRangeAdapter, c as RenameAdapter, f as DocumentFormattingEditProvider, g as DocumentRangeFormattingEditProvider, C as CompletionAdapter } from "./lspLanguageFeatures-DzxH499X.js";
3
- import { a, e, d, R, i, j, t, k } from "./lspLanguageFeatures-DzxH499X.js";
1
+ import { c as createWebWorker, l as languages } from "./index-CpDga7fF.js";
2
+ import { H as HoverAdapter, D as DocumentHighlightAdapter, h as DocumentLinkAdapter, F as FoldingRangeAdapter, b as DocumentSymbolAdapter, S as SelectionRangeAdapter, c as RenameAdapter, f as DocumentFormattingEditProvider, g as DocumentRangeFormattingEditProvider, C as CompletionAdapter } from "./lspLanguageFeatures-BMM3SRX4.js";
3
+ import { a, e, d, R, i, j, t, k } from "./lspLanguageFeatures-BMM3SRX4.js";
4
4
  const STOP_WHEN_IDLE_FOR = 2 * 60 * 1e3;
5
5
  class WorkerManager {
6
6
  constructor(defaults) {
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./cssMode-CY6x0qXW.js","./lspLanguageFeatures-DzxH499X.js","./htmlMode-CsPinKYA.js","./jsonMode-JbrRQBOU.js","./javascript-_HVGB-lj.js","./typescript-CIn-DSfY.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./cssMode-woG3Vtms.js","./lspLanguageFeatures-BMM3SRX4.js","./htmlMode-DzdyF21q.js","./jsonMode-CPhJ_ION.js","./javascript-Dy9cX9Fu.js","./typescript-Cq3g-z7h.js"])))=>i.map(i=>d[i]);
2
2
  function getDefaultExportFromCjs(x) {
3
3
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
4
4
  }
@@ -18755,6 +18755,7 @@ function TerminalPanel({ agent, onSpawn, onExit }) {
18755
18755
  brightWhite: "#c0caf5"
18756
18756
  },
18757
18757
  scrollback: 1e4,
18758
+ scrollOnUserInput: true,
18758
18759
  allowTransparency: false
18759
18760
  });
18760
18761
  const fitAddon = new addonFitExports.FitAddon();
@@ -18781,6 +18782,7 @@ function TerminalPanel({ agent, onSpawn, onExit }) {
18781
18782
  resizeTimeout = setTimeout(() => {
18782
18783
  if (fitAddonRef.current && terminalRef.current) {
18783
18784
  fitAddonRef.current.fit();
18785
+ terminalRef.current.scrollToBottom();
18784
18786
  const { cols, rows } = terminalRef.current;
18785
18787
  window.worker.resizePty(cols, rows);
18786
18788
  }
@@ -18808,6 +18810,7 @@ function TerminalPanel({ agent, onSpawn, onExit }) {
18808
18810
  onSpawn(agent).then(() => {
18809
18811
  if (fitAddonRef.current && terminalRef.current) {
18810
18812
  fitAddonRef.current.fit();
18813
+ terminalRef.current.scrollToBottom();
18811
18814
  const { cols, rows } = terminalRef.current;
18812
18815
  window.worker.resizePty(cols, rows);
18813
18816
  }
@@ -206489,7 +206492,7 @@ const lessDefaults = new LanguageServiceDefaultsImpl$3(
206489
206492
  modeConfigurationDefault$2
206490
206493
  );
206491
206494
  function getMode$3() {
206492
- return __vitePreload(() => import("./cssMode-CY6x0qXW.js"), true ? __vite__mapDeps([0,1]) : void 0, import.meta.url);
206495
+ return __vitePreload(() => import("./cssMode-woG3Vtms.js"), true ? __vite__mapDeps([0,1]) : void 0, import.meta.url);
206493
206496
  }
206494
206497
  languages.onLanguage("less", () => {
206495
206498
  getMode$3().then((mode2) => mode2.setupMode(lessDefaults));
@@ -206594,7 +206597,7 @@ const razorLanguageService = registerHTMLLanguageService(
206594
206597
  );
206595
206598
  const razorDefaults = razorLanguageService.defaults;
206596
206599
  function getMode$2() {
206597
- return __vitePreload(() => import("./htmlMode-CsPinKYA.js"), true ? __vite__mapDeps([2,1]) : void 0, import.meta.url);
206600
+ return __vitePreload(() => import("./htmlMode-DzdyF21q.js"), true ? __vite__mapDeps([2,1]) : void 0, import.meta.url);
206598
206601
  }
206599
206602
  function registerHTMLLanguageService(languageId, options = optionsDefault, modeConfiguration = getConfigurationDefault(languageId)) {
206600
206603
  const defaults = new LanguageServiceDefaultsImpl$2(languageId, options, modeConfiguration);
@@ -206678,7 +206681,7 @@ const jsonDefaults = new LanguageServiceDefaultsImpl$1(
206678
206681
  );
206679
206682
  const getWorker$1 = () => getMode$1().then((mode2) => mode2.getWorker());
206680
206683
  function getMode$1() {
206681
- return __vitePreload(() => import("./jsonMode-JbrRQBOU.js"), true ? __vite__mapDeps([3,1]) : void 0, import.meta.url);
206684
+ return __vitePreload(() => import("./jsonMode-CPhJ_ION.js"), true ? __vite__mapDeps([3,1]) : void 0, import.meta.url);
206682
206685
  }
206683
206686
  languages.register({
206684
206687
  id: "json",
@@ -206924,7 +206927,7 @@ const getJavaScriptWorker = () => {
206924
206927
  return getMode().then((mode) => mode.getJavaScriptWorker());
206925
206928
  };
206926
206929
  function getMode() {
206927
- return __vitePreload(() => import("./tsMode-CN0FOHMy.js"), true ? [] : void 0, import.meta.url);
206930
+ return __vitePreload(() => import("./tsMode-D7kqIJ_o.js"), true ? [] : void 0, import.meta.url);
206928
206931
  }
206929
206932
  languages.onLanguage("typescript", () => {
206930
206933
  return getMode().then((mode) => mode.setupTypeScript(typescriptDefaults));
@@ -207119,49 +207122,49 @@ registerLanguage({
207119
207122
  extensions: [".ftl", ".ftlh", ".ftlx"],
207120
207123
  aliases: ["FreeMarker2", "Apache FreeMarker2"],
207121
207124
  loader: () => {
207122
- return __vitePreload(() => import("./freemarker2-BXSW9BAX.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationDollar);
207125
+ return __vitePreload(() => import("./freemarker2-DgtqmvCd.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationDollar);
207123
207126
  }
207124
207127
  });
207125
207128
  registerLanguage({
207126
207129
  id: "freemarker2.tag-angle.interpolation-dollar",
207127
207130
  aliases: ["FreeMarker2 (Angle/Dollar)", "Apache FreeMarker2 (Angle/Dollar)"],
207128
207131
  loader: () => {
207129
- return __vitePreload(() => import("./freemarker2-BXSW9BAX.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAngleInterpolationDollar);
207132
+ return __vitePreload(() => import("./freemarker2-DgtqmvCd.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAngleInterpolationDollar);
207130
207133
  }
207131
207134
  });
207132
207135
  registerLanguage({
207133
207136
  id: "freemarker2.tag-bracket.interpolation-dollar",
207134
207137
  aliases: ["FreeMarker2 (Bracket/Dollar)", "Apache FreeMarker2 (Bracket/Dollar)"],
207135
207138
  loader: () => {
207136
- return __vitePreload(() => import("./freemarker2-BXSW9BAX.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagBracketInterpolationDollar);
207139
+ return __vitePreload(() => import("./freemarker2-DgtqmvCd.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagBracketInterpolationDollar);
207137
207140
  }
207138
207141
  });
207139
207142
  registerLanguage({
207140
207143
  id: "freemarker2.tag-angle.interpolation-bracket",
207141
207144
  aliases: ["FreeMarker2 (Angle/Bracket)", "Apache FreeMarker2 (Angle/Bracket)"],
207142
207145
  loader: () => {
207143
- return __vitePreload(() => import("./freemarker2-BXSW9BAX.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAngleInterpolationBracket);
207146
+ return __vitePreload(() => import("./freemarker2-DgtqmvCd.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAngleInterpolationBracket);
207144
207147
  }
207145
207148
  });
207146
207149
  registerLanguage({
207147
207150
  id: "freemarker2.tag-bracket.interpolation-bracket",
207148
207151
  aliases: ["FreeMarker2 (Bracket/Bracket)", "Apache FreeMarker2 (Bracket/Bracket)"],
207149
207152
  loader: () => {
207150
- return __vitePreload(() => import("./freemarker2-BXSW9BAX.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagBracketInterpolationBracket);
207153
+ return __vitePreload(() => import("./freemarker2-DgtqmvCd.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagBracketInterpolationBracket);
207151
207154
  }
207152
207155
  });
207153
207156
  registerLanguage({
207154
207157
  id: "freemarker2.tag-auto.interpolation-dollar",
207155
207158
  aliases: ["FreeMarker2 (Auto/Dollar)", "Apache FreeMarker2 (Auto/Dollar)"],
207156
207159
  loader: () => {
207157
- return __vitePreload(() => import("./freemarker2-BXSW9BAX.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationDollar);
207160
+ return __vitePreload(() => import("./freemarker2-DgtqmvCd.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationDollar);
207158
207161
  }
207159
207162
  });
207160
207163
  registerLanguage({
207161
207164
  id: "freemarker2.tag-auto.interpolation-bracket",
207162
207165
  aliases: ["FreeMarker2 (Auto/Bracket)", "Apache FreeMarker2 (Auto/Bracket)"],
207163
207166
  loader: () => {
207164
- return __vitePreload(() => import("./freemarker2-BXSW9BAX.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationBracket);
207167
+ return __vitePreload(() => import("./freemarker2-DgtqmvCd.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationBracket);
207165
207168
  }
207166
207169
  });
207167
207170
  registerLanguage({
@@ -207182,7 +207185,7 @@ registerLanguage({
207182
207185
  extensions: [".handlebars", ".hbs"],
207183
207186
  aliases: ["Handlebars", "handlebars", "hbs"],
207184
207187
  mimetypes: ["text/x-handlebars-template"],
207185
- loader: () => __vitePreload(() => import("./handlebars-BYUZ1IOs.js"), true ? [] : void 0, import.meta.url)
207188
+ loader: () => __vitePreload(() => import("./handlebars-YEqC-zOn.js"), true ? [] : void 0, import.meta.url)
207186
207189
  });
207187
207190
  registerLanguage({
207188
207191
  id: "hcl",
@@ -207195,7 +207198,7 @@ registerLanguage({
207195
207198
  extensions: [".html", ".htm", ".shtml", ".xhtml", ".mdoc", ".jsp", ".asp", ".aspx", ".jshtm"],
207196
207199
  aliases: ["HTML", "htm", "html", "xhtml"],
207197
207200
  mimetypes: ["text/html", "text/x-jshtm", "text/template", "text/ng-template"],
207198
- loader: () => __vitePreload(() => import("./html-DPocQM4t.js"), true ? [] : void 0, import.meta.url)
207201
+ loader: () => __vitePreload(() => import("./html-CwvkGxeB.js"), true ? [] : void 0, import.meta.url)
207199
207202
  });
207200
207203
  registerLanguage({
207201
207204
  id: "ini",
@@ -207218,7 +207221,7 @@ registerLanguage({
207218
207221
  filenames: ["jakefile"],
207219
207222
  aliases: ["JavaScript", "javascript", "js"],
207220
207223
  mimetypes: ["text/javascript"],
207221
- loader: () => __vitePreload(() => import("./javascript-_HVGB-lj.js"), true ? __vite__mapDeps([4,5]) : void 0, import.meta.url)
207224
+ loader: () => __vitePreload(() => import("./javascript-Dy9cX9Fu.js"), true ? __vite__mapDeps([4,5]) : void 0, import.meta.url)
207222
207225
  });
207223
207226
  registerLanguage({
207224
207227
  id: "julia",
@@ -207257,7 +207260,7 @@ registerLanguage({
207257
207260
  extensions: [".liquid", ".html.liquid"],
207258
207261
  aliases: ["Liquid", "liquid"],
207259
207262
  mimetypes: ["application/liquid"],
207260
- loader: () => __vitePreload(() => import("./liquid-B7izKdqo.js"), true ? [] : void 0, import.meta.url)
207263
+ loader: () => __vitePreload(() => import("./liquid-BJdFPWrv.js"), true ? [] : void 0, import.meta.url)
207261
207264
  });
207262
207265
  registerLanguage({
207263
207266
  id: "m3",
@@ -207275,7 +207278,7 @@ registerLanguage({
207275
207278
  id: "mdx",
207276
207279
  extensions: [".mdx"],
207277
207280
  aliases: ["MDX", "mdx"],
207278
- loader: () => __vitePreload(() => import("./mdx-CmvUeYLw.js"), true ? [] : void 0, import.meta.url)
207281
+ loader: () => __vitePreload(() => import("./mdx-kg2kuPRK.js"), true ? [] : void 0, import.meta.url)
207279
207282
  });
207280
207283
  registerLanguage({
207281
207284
  id: "mips",
@@ -207374,7 +207377,7 @@ registerLanguage({
207374
207377
  extensions: [".py", ".rpy", ".pyw", ".cpy", ".gyp", ".gypi"],
207375
207378
  aliases: ["Python", "py"],
207376
207379
  firstLine: "^#!/.*\\bpython[0-9.-]*\\b",
207377
- loader: () => __vitePreload(() => import("./python-DJqYTFoi.js"), true ? [] : void 0, import.meta.url)
207380
+ loader: () => __vitePreload(() => import("./python-aIrmxkmH.js"), true ? [] : void 0, import.meta.url)
207378
207381
  });
207379
207382
  registerLanguage({
207380
207383
  id: "qsharp",
@@ -207393,7 +207396,7 @@ registerLanguage({
207393
207396
  extensions: [".cshtml"],
207394
207397
  aliases: ["Razor", "razor"],
207395
207398
  mimetypes: ["text/x-cshtml"],
207396
- loader: () => __vitePreload(() => import("./razor-CGEA5nUK.js"), true ? [] : void 0, import.meta.url)
207399
+ loader: () => __vitePreload(() => import("./razor-DdymcPOc.js"), true ? [] : void 0, import.meta.url)
207397
207400
  });
207398
207401
  registerLanguage({
207399
207402
  id: "redis",
@@ -207526,7 +207529,7 @@ registerLanguage({
207526
207529
  aliases: ["TypeScript", "ts", "typescript"],
207527
207530
  mimetypes: ["text/typescript"],
207528
207531
  loader: () => {
207529
- return __vitePreload(() => import("./typescript-CIn-DSfY.js"), true ? [] : void 0, import.meta.url);
207532
+ return __vitePreload(() => import("./typescript-Cq3g-z7h.js"), true ? [] : void 0, import.meta.url);
207530
207533
  }
207531
207534
  });
207532
207535
  registerLanguage({
@@ -207571,14 +207574,14 @@ registerLanguage({
207571
207574
  firstLine: "(\\<\\?xml.*)|(\\<svg)|(\\<\\!doctype\\s+svg)",
207572
207575
  aliases: ["XML", "xml"],
207573
207576
  mimetypes: ["text/xml", "application/xml", "application/xaml+xml", "application/xml-dtd"],
207574
- loader: () => __vitePreload(() => import("./xml-C5t3U2jS.js"), true ? [] : void 0, import.meta.url)
207577
+ loader: () => __vitePreload(() => import("./xml-BuBP5jOc.js"), true ? [] : void 0, import.meta.url)
207575
207578
  });
207576
207579
  registerLanguage({
207577
207580
  id: "yaml",
207578
207581
  extensions: [".yaml", ".yml"],
207579
207582
  aliases: ["YAML", "yaml", "YML", "yml"],
207580
207583
  mimetypes: ["application/x-yaml", "text/x-yaml"],
207581
- loader: () => __vitePreload(() => import("./yaml-n-Jb6xf1.js"), true ? [] : void 0, import.meta.url)
207584
+ loader: () => __vitePreload(() => import("./yaml-B-3hWmol.js"), true ? [] : void 0, import.meta.url)
207582
207585
  });
207583
207586
  var __defProp = Object.defineProperty;
207584
207587
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -211779,15 +211782,25 @@ function App() {
211779
211782
  ))
211780
211783
  ] })
211781
211784
  ] }),
211782
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "main-content", children: visiblePaneIds.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "multi-split-empty", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "All panes hidden. Use the titlebar buttons to show a pane." }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
211783
- PaneLayout,
211784
- {
211785
- layout: layout2,
211786
- panes: panes.filter((p) => visiblePaneIds.includes(p.id)),
211787
- onLayoutChange: setLayout,
211788
- onToggle: togglePane
211789
- }
211790
- ) }),
211785
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "main-content", children: [
211786
+ visiblePaneIds.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "multi-split-empty", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "All panes hidden. Use the titlebar buttons to show a pane." }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
211787
+ PaneLayout,
211788
+ {
211789
+ layout: layout2,
211790
+ panes: panes.filter((p) => visiblePaneIds.includes(p.id)),
211791
+ onLayoutChange: setLayout,
211792
+ onToggle: togglePane
211793
+ }
211794
+ ),
211795
+ panes.filter((p) => !visiblePaneIds.includes(p.id)).map((p) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: {
211796
+ position: "absolute",
211797
+ width: "1px",
211798
+ height: "1px",
211799
+ overflow: "hidden",
211800
+ opacity: 0,
211801
+ pointerEvents: "none"
211802
+ }, children: p.content }, p.id))
211803
+ ] }),
211791
211804
  /* @__PURE__ */ jsxRuntimeExports.jsx(StatusBar, { wsStatus, cwd: cwd2, onChangeCwd: handleChangeCwd }),
211792
211805
  /* @__PURE__ */ jsxRuntimeExports.jsx(SettingsDialog, { open: showSettings, onClose: () => setShowSettings(false) }),
211793
211806
  showAgentPicker && agents.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -1,5 +1,5 @@
1
- import { conf as conf$1, language as language$1 } from "./typescript-CIn-DSfY.js";
2
- import "./index-Bml7oDn9.js";
1
+ import { conf as conf$1, language as language$1 } from "./typescript-Cq3g-z7h.js";
2
+ import "./index-CpDga7fF.js";
3
3
  const conf = conf$1;
4
4
  const language = {
5
5
  // Set defaultToken to invalid to see what you do not tokenize yet
@@ -1,6 +1,6 @@
1
- import { c as createWebWorker, l as languages, e as editor } from "./index-Bml7oDn9.js";
2
- import { f as DocumentFormattingEditProvider, g as DocumentRangeFormattingEditProvider, C as CompletionAdapter, H as HoverAdapter, b as DocumentSymbolAdapter, d as DocumentColorAdapter, F as FoldingRangeAdapter, S as SelectionRangeAdapter, e as DiagnosticsAdapter } from "./lspLanguageFeatures-DzxH499X.js";
3
- import { a, D, h, R, c, i, j, t, k } from "./lspLanguageFeatures-DzxH499X.js";
1
+ import { c as createWebWorker, l as languages, e as editor } from "./index-CpDga7fF.js";
2
+ import { f as DocumentFormattingEditProvider, g as DocumentRangeFormattingEditProvider, C as CompletionAdapter, H as HoverAdapter, b as DocumentSymbolAdapter, d as DocumentColorAdapter, F as FoldingRangeAdapter, S as SelectionRangeAdapter, e as DiagnosticsAdapter } from "./lspLanguageFeatures-BMM3SRX4.js";
3
+ import { a, D, h, R, c, i, j, t, k } from "./lspLanguageFeatures-BMM3SRX4.js";
4
4
  const STOP_WHEN_IDLE_FOR = 2 * 60 * 1e3;
5
5
  class WorkerManager {
6
6
  constructor(defaults) {
@@ -1,4 +1,4 @@
1
- import { l as languages } from "./index-Bml7oDn9.js";
1
+ import { l as languages } from "./index-CpDga7fF.js";
2
2
  const EMPTY_ELEMENTS = [
3
3
  "area",
4
4
  "base",
@@ -1,4 +1,4 @@
1
- import { R as Range$1, l as languages, e as editor, U as Uri, M as MarkerSeverity } from "./index-Bml7oDn9.js";
1
+ import { R as Range$1, l as languages, e as editor, U as Uri, M as MarkerSeverity } from "./index-CpDga7fF.js";
2
2
  var DocumentUri;
3
3
  (function(DocumentUri2) {
4
4
  function is(value) {
@@ -1,4 +1,4 @@
1
- import { l as languages } from "./index-Bml7oDn9.js";
1
+ import { l as languages } from "./index-CpDga7fF.js";
2
2
  const conf = {
3
3
  comments: {
4
4
  blockComment: ["{/*", "*/}"]
@@ -1,4 +1,4 @@
1
- import { l as languages } from "./index-Bml7oDn9.js";
1
+ import { l as languages } from "./index-CpDga7fF.js";
2
2
  const conf = {
3
3
  comments: {
4
4
  lineComment: "#",
@@ -1,4 +1,4 @@
1
- import { l as languages } from "./index-Bml7oDn9.js";
1
+ import { l as languages } from "./index-CpDga7fF.js";
2
2
  const EMPTY_ELEMENTS = [
3
3
  "area",
4
4
  "base",
@@ -1,4 +1,4 @@
1
- import { c as createWebWorker, e as editor, U as Uri, a as MarkerTag, M as MarkerSeverity, l as languages, t as typescriptDefaults, R as Range } from "./index-Bml7oDn9.js";
1
+ import { c as createWebWorker, e as editor, U as Uri, a as MarkerTag, M as MarkerSeverity, l as languages, t as typescriptDefaults, R as Range } from "./index-CpDga7fF.js";
2
2
  class WorkerManager {
3
3
  constructor(_modeId, _defaults) {
4
4
  this._modeId = _modeId;
@@ -1,4 +1,4 @@
1
- import { l as languages } from "./index-Bml7oDn9.js";
1
+ import { l as languages } from "./index-CpDga7fF.js";
2
2
  const conf = {
3
3
  wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
4
4
  comments: {
@@ -1,4 +1,4 @@
1
- import { l as languages } from "./index-Bml7oDn9.js";
1
+ import { l as languages } from "./index-CpDga7fF.js";
2
2
  const conf = {
3
3
  comments: {
4
4
  blockComment: ["<!--", "-->"]
@@ -1,4 +1,4 @@
1
- import { l as languages } from "./index-Bml7oDn9.js";
1
+ import { l as languages } from "./index-CpDga7fF.js";
2
2
  const conf = {
3
3
  comments: {
4
4
  lineComment: "#"
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>ctlsurf-worker</title>
7
- <script type="module" crossorigin src="./assets/index-Bml7oDn9.js"></script>
7
+ <script type="module" crossorigin src="./assets/index-CpDga7fF.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="./assets/index-DK9wLFFm.css">
9
9
  </head>
10
10
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phenx-inc/ctlsurf",
3
- "version": "0.1.12",
3
+ "version": "0.1.15",
4
4
  "description": "Agent-agnostic terminal and desktop app for ctlsurf — run Claude Code, Codex, or any coding agent with live session logging and remote control",
5
5
  "main": "out/main/index.js",
6
6
  "bin": {
@@ -14,7 +14,7 @@ export class ConversationBridge {
14
14
  private inputBuffer: string = ''
15
15
  private outputBuffer: string = ''
16
16
 
17
- private readonly FLUSH_BYTES = 2000
17
+ private readonly FLUSH_BYTES = 500
18
18
 
19
19
  setWsClient(ws: WorkerWsClient): void {
20
20
  this.wsClient = ws
@@ -274,6 +274,18 @@ export default function App() {
274
274
  onToggle={togglePane}
275
275
  />
276
276
  )}
277
+ {panes.filter(p => !visiblePaneIds.includes(p.id)).map(p => (
278
+ <div key={p.id} style={{
279
+ position: 'absolute',
280
+ width: '1px',
281
+ height: '1px',
282
+ overflow: 'hidden',
283
+ opacity: 0,
284
+ pointerEvents: 'none',
285
+ }}>
286
+ {p.content}
287
+ </div>
288
+ ))}
277
289
  </div>
278
290
 
279
291
  <StatusBar wsStatus={wsStatus} cwd={cwd} onChangeCwd={handleChangeCwd} />
@@ -55,6 +55,7 @@ export function TerminalPanel({ agent, onSpawn, onExit }: TerminalPanelProps) {
55
55
  brightWhite: '#c0caf5'
56
56
  },
57
57
  scrollback: 10000,
58
+ scrollOnUserInput: true,
58
59
  allowTransparency: false
59
60
  })
60
61
 
@@ -84,13 +85,14 @@ export function TerminalPanel({ agent, onSpawn, onExit }: TerminalPanelProps) {
84
85
  onExit()
85
86
  })
86
87
 
87
- // Resize handling
88
+ // Resize handling — scroll to bottom after fit to prevent jumping to top
88
89
  let resizeTimeout: ReturnType<typeof setTimeout>
89
90
  const handleResize = () => {
90
91
  clearTimeout(resizeTimeout)
91
92
  resizeTimeout = setTimeout(() => {
92
93
  if (fitAddonRef.current && terminalRef.current) {
93
94
  fitAddonRef.current.fit()
95
+ terminalRef.current.scrollToBottom()
94
96
  const { cols, rows } = terminalRef.current
95
97
  window.worker.resizePty(cols, rows)
96
98
  }
@@ -127,6 +129,7 @@ export function TerminalPanel({ agent, onSpawn, onExit }: TerminalPanelProps) {
127
129
  // Send initial resize after spawn
128
130
  if (fitAddonRef.current && terminalRef.current) {
129
131
  fitAddonRef.current.fit()
132
+ terminalRef.current.scrollToBottom()
130
133
  const { cols, rows } = terminalRef.current
131
134
  window.worker.resizePty(cols, rows)
132
135
  }