@openchamber/web 1.13.3 → 1.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli-output.js +0 -7
- package/bin/cli.js +132 -5548
- package/bin/cli.test.js +674 -0
- package/bin/lib/DOCUMENTATION.md +121 -0
- package/bin/lib/cli-args.js +726 -0
- package/bin/lib/cli-errors.js +18 -0
- package/bin/lib/cli-executables.js +54 -0
- package/bin/lib/cli-http.js +215 -0
- package/bin/lib/cli-lifecycle.js +421 -0
- package/bin/lib/cli-log-files.js +93 -0
- package/bin/lib/cli-network.js +153 -0
- package/bin/lib/cli-paths.js +111 -0
- package/bin/lib/cli-ports.js +51 -0
- package/bin/lib/cli-process.js +292 -0
- package/bin/lib/cli-startup.js +370 -0
- package/bin/lib/cli-tunnel-capabilities.js +9 -0
- package/bin/lib/cli-tunnel-profiles.js +366 -0
- package/bin/lib/cli-tunnel-utils.js +300 -0
- package/bin/lib/commands-connect-url.js +173 -0
- package/bin/lib/commands-lifecycle.js +396 -0
- package/bin/lib/commands-logs.js +110 -0
- package/bin/lib/commands-serve.js +396 -0
- package/bin/lib/commands-startup.js +64 -0
- package/bin/lib/commands-status.js +114 -0
- package/bin/lib/commands-tunnel.js +1757 -0
- package/bin/lib/commands-update.js +141 -0
- package/dist/assets/{DiagramView-BmHROYsX.js → DiagramView-BAoYIAGR.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DiJE-v5Q.js → MarkdownRendererImpl-B0NE4mIY.js} +3 -3
- package/dist/assets/MultiRunWindow-BT4kt6aB.js +1 -0
- package/dist/assets/NewWorktreeDialog-Bx-zQyBp.js +167 -0
- package/dist/assets/{OnboardingScreen-DpBF8dKJ.js → OnboardingScreen-CbJOPUxm.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-1xaHUxPK.js → SessionSwitcherDropdown-BbUzUNEi.js} +1 -1
- package/dist/assets/{SettingsWindow-ChwLyQAe.js → SettingsWindow-CSb8eo8p.js} +1 -1
- package/dist/assets/{TerminalView-DGEBNuAp.js → TerminalView-ME5MOz7S.js} +1 -1
- package/dist/assets/es-Bk-yR0w-.js +15 -0
- package/dist/assets/fr-f1ibV7QU.js +13 -0
- package/dist/assets/index-B82A6jBD.css +1 -0
- package/dist/assets/index-BsXkdBYx.js +3 -0
- package/dist/assets/ja-D9mS3zWP.js +15 -0
- package/dist/assets/ko-Cpl1IA3D.js +15 -0
- package/dist/assets/{main-fm_8J7Lk.js → main-D6eC2bnV.js} +2 -2
- package/dist/assets/main-fsOGbLGZ.js +214 -0
- package/dist/assets/miniChat-DKGU29GZ.js +2 -0
- package/dist/assets/mobile-YHQHMYWC.js +2 -0
- package/dist/assets/pl-CYke_fxL.js +15 -0
- package/dist/assets/pt-BR-Clb6Z8up.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-3vxeddJO.js +2 -0
- package/dist/assets/{renderMobileApp-6s0G1iIJ.js → renderMobileApp-BrvLHYCY.js} +5 -5
- package/dist/assets/uk-CXn8cxXa.js +15 -0
- package/dist/assets/{useAppFontEffects-CV5C5O0r.js → useAppFontEffects-b7bqtGFf.js} +124 -119
- package/dist/assets/{vendor-.bun-CC_Xso_s.js → vendor-.bun-By2L9XvG.js} +1 -1
- package/dist/assets/zh-CN-BRwwlEdG.js +15 -0
- package/dist/assets/zh-TW-D5pg5Z8l.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +1 -1
- package/server/lib/cloudflare-tunnel.js +2 -2
- package/server/lib/event-stream/global-hub.js +1 -1
- package/server/lib/event-stream/index.js +0 -12
- package/server/lib/event-stream/runtime.js +1 -1
- package/server/lib/git/service.js +18 -0
- package/server/lib/git/service.test.js +48 -0
- package/server/lib/notifications/index.js +1 -4
- package/server/lib/opencode/agents.js +0 -6
- package/server/lib/opencode/commands.js +0 -5
- package/server/lib/opencode/config-entity-routes.js +39 -21
- package/server/lib/opencode/feature-routes-runtime.js +27 -62
- package/server/lib/opencode/lifecycle.js +13 -1
- package/server/lib/opencode/npm-registry.js +3 -3
- package/server/lib/opencode/proxy.js +3 -3
- package/server/lib/opencode/shared.js +0 -6
- package/server/lib/opencode/skills.js +0 -2
- package/server/lib/opencode/snippets.js +0 -2
- package/server/lib/package-manager.js +5 -5
- package/server/lib/projects/project-config.js +0 -8
- package/server/lib/quota/DOCUMENTATION.md +3 -1
- package/server/lib/quota/providers/claude.js +1 -1
- package/server/lib/quota/providers/codex.js +1 -1
- package/server/lib/quota/providers/copilot.js +1 -1
- package/server/lib/quota/providers/cursor.js +1 -1
- package/server/lib/quota/providers/google/auth.js +2 -2
- package/server/lib/quota/providers/google/index.js +0 -27
- package/server/lib/quota/providers/google/transforms.js +1 -1
- package/server/lib/quota/providers/index.js +1 -1
- package/server/lib/quota/providers/kimi.js +1 -1
- package/server/lib/quota/providers/minimax-cn-coding-plan.js +1 -1
- package/server/lib/quota/providers/minimax-coding-plan.js +1 -1
- package/server/lib/quota/providers/nanogpt.js +1 -1
- package/server/lib/quota/providers/ollama-cloud.js +1 -1
- package/server/lib/quota/providers/openai.js +4 -4
- package/server/lib/quota/providers/openrouter.js +1 -1
- package/server/lib/quota/providers/wafer.js +1 -1
- package/server/lib/quota/providers/zai.js +1 -1
- package/server/lib/quota/providers/zhipuai-coding-plan.js +1 -1
- package/server/lib/skills-catalog/cache.js +0 -4
- package/server/lib/skills-catalog/clawdhub/api.js +0 -32
- package/server/lib/skills-catalog/clawdhub/scan.js +0 -52
- package/server/lib/skills-catalog/curated-sources.js +1 -1
- package/server/lib/skills-catalog/source.js +5 -0
- package/server/lib/terminal/runtime.js +11 -9
- package/server/lib/text/summarization.js +1 -1
- package/server/lib/tunnels/providers/ngrok.js +1 -1
- package/server/lib/tunnels/types.js +2 -2
- package/dist/assets/MultiRunWindow-yZoCT7F7.js +0 -1
- package/dist/assets/NewWorktreeDialog-CTMiE7Xd.js +0 -167
- package/dist/assets/es-CTE-E8we.js +0 -15
- package/dist/assets/fr-TVkZpyEo.js +0 -13
- package/dist/assets/index-B4pCDMbq.css +0 -1
- package/dist/assets/index-D9uMvTQF.js +0 -3
- package/dist/assets/ko-D_UCJIIL.js +0 -15
- package/dist/assets/main-eAd3a6tx.js +0 -214
- package/dist/assets/miniChat-Bbjg31IC.js +0 -2
- package/dist/assets/mobile-B3_j_DsB.js +0 -2
- package/dist/assets/pl-nDEkk-GZ.js +0 -15
- package/dist/assets/pt-BR-B_g2RcgU.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-CB13zs6N.js +0 -2
- package/dist/assets/uk-CWLhnPGW.js +0 -15
- package/dist/assets/zh-CN-BFxe1b5m.js +0 -15
- package/dist/assets/zh-TW-n-d-xbGV.js +0 -15
- package/server/lib/opencode/index.js +0 -95
- package/server/lib/quota/providers/interface.js +0 -55
- package/server/lib/skills-catalog/clawdhub/index.js +0 -30
- package/server/lib/skills-catalog/index.js +0 -42
- package/server/lib/terminal/index.js +0 -31
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { pathToFileURL } from 'url';
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
|
+
import { EXIT_CODE, TunnelCliError } from './cli-errors.js';
|
|
5
|
+
import { buildLocalUrl, resolveServeHost, assertSafeBrowserPort, hasUiPasswordConfigured, assertAuthenticatedNetworkExposure } from './cli-network.js';
|
|
6
|
+
import { fetchSystemInfoFromPort } from './cli-http.js';
|
|
7
|
+
import { isPortAvailable, resolveAvailablePort } from './cli-ports.js';
|
|
8
|
+
import { ensureLogsDir, getLogFilePath } from './cli-paths.js';
|
|
9
|
+
import { rotateLogFile } from './cli-log-files.js';
|
|
10
|
+
import { discoverOpenChamberInstanceOnPort, isDesktopRuntimeForPort } from './cli-lifecycle.js';
|
|
11
|
+
import { getPidFilePath, getInstanceFilePath, writePidFile, writeInstanceOptions, removePidFile, removeInstanceFile, isProcessRunning, terminateProcessTree } from './cli-process.js';
|
|
12
|
+
import { isNetworkExposedBindHost } from '../../server/lib/security/bind-host.js';
|
|
13
|
+
import {
|
|
14
|
+
intro as clackIntro,
|
|
15
|
+
outro as clackOutro,
|
|
16
|
+
isJsonMode,
|
|
17
|
+
isQuietMode,
|
|
18
|
+
shouldRenderHumanOutput,
|
|
19
|
+
createSpinner,
|
|
20
|
+
printJson,
|
|
21
|
+
logStatus,
|
|
22
|
+
} from '../cli-output.js';
|
|
23
|
+
|
|
24
|
+
const DAEMON_READY_TIMEOUT_MS = 30000;
|
|
25
|
+
|
|
26
|
+
function createServeCommand({
|
|
27
|
+
serverPath,
|
|
28
|
+
bunBin,
|
|
29
|
+
checkOpenCodeCLI,
|
|
30
|
+
getPreferredServerRuntime,
|
|
31
|
+
setForegroundServerActive,
|
|
32
|
+
setForegroundShutdown,
|
|
33
|
+
}) {
|
|
34
|
+
async function serveCommand(options) {
|
|
35
|
+
const showOutput = shouldRenderHumanOutput(options);
|
|
36
|
+
const jsonMessages = [];
|
|
37
|
+
const emitNotice = (notice) => {
|
|
38
|
+
if (!notice || typeof notice !== 'object' || typeof notice.message !== 'string') return;
|
|
39
|
+
const level = notice.level === 'error' ? 'error' : (notice.level === 'warning' ? 'warning' : 'info');
|
|
40
|
+
|
|
41
|
+
if (isJsonMode(options)) {
|
|
42
|
+
jsonMessages.push({
|
|
43
|
+
level,
|
|
44
|
+
code: notice.code,
|
|
45
|
+
message: notice.message,
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (showOutput) {
|
|
51
|
+
logStatus(level, notice.message);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!isQuietMode(options)) {
|
|
56
|
+
const prefix = level === 'warning' ? 'Warning' : level === 'error' ? 'Error' : 'Info';
|
|
57
|
+
const line = `${prefix}: ${notice.message}`;
|
|
58
|
+
if (level === 'error') {
|
|
59
|
+
console.error(line);
|
|
60
|
+
} else {
|
|
61
|
+
console.warn(line);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const explicitPort = options.explicitPort === true;
|
|
66
|
+
const effectiveHost = resolveServeHost(options.host);
|
|
67
|
+
const targetPort = await resolveAvailablePort(options.port, explicitPort, emitNotice);
|
|
68
|
+
|
|
69
|
+
if (targetPort !== 0 && !options.suppressUnsafePortWarning) {
|
|
70
|
+
assertSafeBrowserPort(targetPort, { context: 'OpenChamber serve' });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (targetPort !== 0) {
|
|
74
|
+
const existingInstance = await discoverOpenChamberInstanceOnPort(targetPort, { host: effectiveHost });
|
|
75
|
+
if (existingInstance?.runtime === 'desktop') {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`Port ${targetPort} is used by OpenChamber Desktop app. Choose another port or stop the desktop app.`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
if (existingInstance) {
|
|
81
|
+
const pidSuffix = Number.isFinite(existingInstance.pid) ? ` (PID: ${existingInstance.pid})` : '';
|
|
82
|
+
if (existingInstance.source === 'probe') {
|
|
83
|
+
throw new Error(`OpenChamber is already running on port ${targetPort}. Use \`openchamber status\` or \`openchamber stop --port ${targetPort}\`.`);
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`OpenChamber is already running on port ${targetPort}${pidSuffix}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (explicitPort && !(await isPortAvailable(targetPort, effectiveHost))) {
|
|
89
|
+
const systemInfo = await fetchSystemInfoFromPort(targetPort, globalThis.fetch, effectiveHost);
|
|
90
|
+
if (isDesktopRuntimeForPort(systemInfo, targetPort)) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Port ${targetPort} is used by OpenChamber Desktop app. Choose another port or stop the desktop app.`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const systemInfoRuntimeMatchesPort = systemInfo?.runtime !== 'desktop' || isDesktopRuntimeForPort(systemInfo, targetPort);
|
|
96
|
+
if (systemInfo?.runtime && systemInfoRuntimeMatchesPort) {
|
|
97
|
+
throw new Error(`OpenChamber is already running on port ${targetPort}. Use \`openchamber status\` or \`openchamber stop --port ${targetPort}\`.`);
|
|
98
|
+
}
|
|
99
|
+
throw new Error(`Port ${targetPort} is already in use by another process.`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const opencodeBinary = await checkOpenCodeCLI(emitNotice);
|
|
104
|
+
const preferredRuntime = getPreferredServerRuntime();
|
|
105
|
+
const runtimeBin = preferredRuntime === 'bun' ? bunBin : process.execPath;
|
|
106
|
+
|
|
107
|
+
ensureLogsDir();
|
|
108
|
+
const initialLogPort = targetPort === 0 ? 'auto' : String(targetPort);
|
|
109
|
+
const initialLogPath = getLogFilePath(initialLogPort);
|
|
110
|
+
rotateLogFile(initialLogPath);
|
|
111
|
+
const logFd = fs.openSync(initialLogPath, 'a');
|
|
112
|
+
|
|
113
|
+
const effectiveUiPassword = hasUiPasswordConfigured(options.uiPassword) ? options.uiPassword : undefined;
|
|
114
|
+
assertAuthenticatedNetworkExposure({
|
|
115
|
+
host: effectiveHost,
|
|
116
|
+
uiPassword: effectiveUiPassword,
|
|
117
|
+
});
|
|
118
|
+
if (!effectiveUiPassword && !options.suppressUiPasswordWarning) {
|
|
119
|
+
const bindHost = effectiveHost;
|
|
120
|
+
const networkExposed = isNetworkExposedBindHost(bindHost);
|
|
121
|
+
const warningLine = 'OPENCHAMBER_UI_PASSWORD is not set';
|
|
122
|
+
const warningDetail = networkExposed
|
|
123
|
+
? `server is bound to ${bindHost} and reachable on your network with no UI auth. `
|
|
124
|
+
+ 'Set --ui-password or OPENCHAMBER_UI_PASSWORD before exposing it over LAN.'
|
|
125
|
+
: 'browser UI is unsecured. Use --ui-password or OPENCHAMBER_UI_PASSWORD.';
|
|
126
|
+
if (showOutput) {
|
|
127
|
+
logStatus('warning', warningLine, warningDetail);
|
|
128
|
+
} else if (isJsonMode(options)) {
|
|
129
|
+
emitNotice({
|
|
130
|
+
level: 'warning',
|
|
131
|
+
code: 'UI_PASSWORD_MISSING',
|
|
132
|
+
message: `${warningLine}; ${warningDetail}`,
|
|
133
|
+
});
|
|
134
|
+
} else if (!isQuietMode(options)) {
|
|
135
|
+
console.warn(`Warning: ${warningLine}; ${warningDetail}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Foreground mode: run server inline so the CLI process is the server process.
|
|
139
|
+
// Required for process managers like systemd (Type=simple) that track the
|
|
140
|
+
// direct child rather than a detached grandchild.
|
|
141
|
+
// IMPORTANT: foreground MUST remain inline (in-process). Do not convert to
|
|
142
|
+
// child-process orchestration — that causes shell job-control suspension.
|
|
143
|
+
if (options.foreground) {
|
|
144
|
+
if (isJsonMode(options)) {
|
|
145
|
+
throw new TunnelCliError(
|
|
146
|
+
'--json is not supported with --foreground. Use --json with background (daemon) mode instead.',
|
|
147
|
+
EXIT_CODE.USAGE_ERROR
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Propagate resolved values into env before importing the server module.
|
|
152
|
+
if (opencodeBinary) {
|
|
153
|
+
process.env.OPENCODE_BINARY = opencodeBinary;
|
|
154
|
+
}
|
|
155
|
+
if (effectiveUiPassword) {
|
|
156
|
+
process.env.OPENCHAMBER_UI_PASSWORD = effectiveUiPassword;
|
|
157
|
+
}
|
|
158
|
+
process.env.OPENCHAMBER_HOST = effectiveHost;
|
|
159
|
+
process.env.OPENCHAMBER_RUNTIME = 'web';
|
|
160
|
+
|
|
161
|
+
// In --quiet mode, redirect stdout/stderr to the log file so that
|
|
162
|
+
// server runtime output (console.log calls) does not pollute the
|
|
163
|
+
// deterministic CLI output contract. In plain human mode, close the
|
|
164
|
+
// log fd and let output go to the inherited terminal as before.
|
|
165
|
+
const suppressServerOutput = isQuietMode(options);
|
|
166
|
+
// Keep a reference to the real stdout.write so CLI output (port, JSON)
|
|
167
|
+
// can bypass the log-file redirect.
|
|
168
|
+
const realStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
169
|
+
if (suppressServerOutput) {
|
|
170
|
+
const logStream = fs.createWriteStream(null, { fd: logFd });
|
|
171
|
+
process.stdout.write = (chunk, encoding, callback) => {
|
|
172
|
+
return logStream.write(chunk, encoding, callback);
|
|
173
|
+
};
|
|
174
|
+
process.stderr.write = (chunk, encoding, callback) => {
|
|
175
|
+
return logStream.write(chunk, encoding, callback);
|
|
176
|
+
};
|
|
177
|
+
} else {
|
|
178
|
+
// Close the log fd – in foreground human mode stdout/stderr are
|
|
179
|
+
// inherited from the parent (e.g. journald/terminal).
|
|
180
|
+
try {
|
|
181
|
+
fs.closeSync(logFd);
|
|
182
|
+
} catch {
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (!isQuietMode(options)) {
|
|
187
|
+
console.log(`Starting OpenChamber on port ${targetPort === 0 ? 'auto' : targetPort} (foreground)`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const { startWebUiServer } = await import(pathToFileURL(serverPath).href);
|
|
191
|
+
const controller = await startWebUiServer({
|
|
192
|
+
port: targetPort,
|
|
193
|
+
host: effectiveHost,
|
|
194
|
+
uiPassword: effectiveUiPassword,
|
|
195
|
+
apiOnly: options.apiOnly === true,
|
|
196
|
+
attachSignals: false,
|
|
197
|
+
exitOnShutdown: false,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const resolvedPort = controller.getPort();
|
|
201
|
+
|
|
202
|
+
// Write PID / instance files so status, stop, and restart can discover
|
|
203
|
+
// this foreground instance the same way they discover daemon instances.
|
|
204
|
+
const fgPidFilePath = await getPidFilePath(resolvedPort);
|
|
205
|
+
const fgInstanceFilePath = await getInstanceFilePath(resolvedPort);
|
|
206
|
+
writePidFile(fgPidFilePath, process.pid, emitNotice);
|
|
207
|
+
writeInstanceOptions(fgInstanceFilePath, {
|
|
208
|
+
port: resolvedPort,
|
|
209
|
+
host: effectiveHost,
|
|
210
|
+
launchMode: 'foreground',
|
|
211
|
+
uiPassword: effectiveUiPassword,
|
|
212
|
+
apiOnly: options.apiOnly === true,
|
|
213
|
+
}, emitNotice);
|
|
214
|
+
|
|
215
|
+
if (isQuietMode(options)) {
|
|
216
|
+
if (!options.suppressQuietOutput) {
|
|
217
|
+
realStdoutWrite(`${resolvedPort}\n`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Clean up PID / instance files.
|
|
222
|
+
const cleanupFiles = () => {
|
|
223
|
+
removePidFile(fgPidFilePath);
|
|
224
|
+
removeInstanceFile(fgInstanceFilePath);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
process.on('exit', cleanupFiles);
|
|
228
|
+
|
|
229
|
+
// Idempotent graceful shutdown with deterministic exit codes.
|
|
230
|
+
let shutdownInProgress = false;
|
|
231
|
+
const shutdownForegroundServer = async (signal = 'SIGTERM') => {
|
|
232
|
+
if (shutdownInProgress) return;
|
|
233
|
+
shutdownInProgress = true;
|
|
234
|
+
try {
|
|
235
|
+
await controller.stop({ exitProcess: false });
|
|
236
|
+
} catch {
|
|
237
|
+
}
|
|
238
|
+
cleanupFiles();
|
|
239
|
+
setForegroundServerActive(false);
|
|
240
|
+
setForegroundShutdown(null);
|
|
241
|
+
const exitCode = signal === 'SIGINT' ? 130 : signal === 'SIGQUIT' ? 131 : 143;
|
|
242
|
+
process.exit(exitCode);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// Expose shutdown to the global SIGINT handler.
|
|
246
|
+
setForegroundShutdown(shutdownForegroundServer);
|
|
247
|
+
setForegroundServerActive(true);
|
|
248
|
+
|
|
249
|
+
// Register signal handlers (additive, no removeAllListeners).
|
|
250
|
+
process.on('SIGINT', () => { void shutdownForegroundServer('SIGINT'); });
|
|
251
|
+
process.on('SIGTERM', () => { void shutdownForegroundServer('SIGTERM'); });
|
|
252
|
+
process.on('SIGQUIT', () => { void shutdownForegroundServer('SIGQUIT'); });
|
|
253
|
+
|
|
254
|
+
// Block forever – the process stays alive until signalled.
|
|
255
|
+
await new Promise(() => {});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const serverArgs = [serverPath, '--port', String(targetPort)];
|
|
259
|
+
serverArgs.push('--host', effectiveHost);
|
|
260
|
+
if (options.apiOnly === true) {
|
|
261
|
+
serverArgs.push('--api-only');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const serveSpin = showOutput ? createSpinner(options) : null;
|
|
265
|
+
|
|
266
|
+
const child = spawn(runtimeBin, serverArgs, {
|
|
267
|
+
detached: true,
|
|
268
|
+
windowsHide: true,
|
|
269
|
+
stdio: ['ignore', logFd, logFd, 'ipc'],
|
|
270
|
+
env: {
|
|
271
|
+
...process.env,
|
|
272
|
+
OPENCHAMBER_PORT: String(targetPort),
|
|
273
|
+
OPENCHAMBER_RUNTIME: 'web',
|
|
274
|
+
OPENCODE_BINARY: opencodeBinary,
|
|
275
|
+
OPENCHAMBER_HOST: effectiveHost,
|
|
276
|
+
...(effectiveUiPassword ? { OPENCHAMBER_UI_PASSWORD: effectiveUiPassword } : {}),
|
|
277
|
+
...(options.apiOnly === true ? { OPENCHAMBER_API_ONLY: 'true' } : {}),
|
|
278
|
+
...(process.env.OPENCODE_SKIP_START ? { OPENCHAMBER_SKIP_OPENCODE_START: process.env.OPENCODE_SKIP_START } : {}),
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
child.unref();
|
|
283
|
+
serveSpin?.start(`Starting OpenChamber on port ${targetPort === 0 ? 'auto' : targetPort}...`);
|
|
284
|
+
|
|
285
|
+
let resolvedPort;
|
|
286
|
+
try {
|
|
287
|
+
resolvedPort = await new Promise((resolve, reject) => {
|
|
288
|
+
let settled = false;
|
|
289
|
+
const timeout = setTimeout(() => {
|
|
290
|
+
if (settled) return;
|
|
291
|
+
settled = true;
|
|
292
|
+
reject(new Error(`OpenChamber daemon did not report ready within ${DAEMON_READY_TIMEOUT_MS / 1000}s`));
|
|
293
|
+
}, DAEMON_READY_TIMEOUT_MS);
|
|
294
|
+
|
|
295
|
+
child.on('message', (msg) => {
|
|
296
|
+
if (settled) return;
|
|
297
|
+
if (msg && msg.type === 'openchamber:ready' && typeof msg.port === 'number') {
|
|
298
|
+
settled = true;
|
|
299
|
+
clearTimeout(timeout);
|
|
300
|
+
resolve(msg.port);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
child.on('error', (error) => {
|
|
305
|
+
if (settled) return;
|
|
306
|
+
settled = true;
|
|
307
|
+
clearTimeout(timeout);
|
|
308
|
+
reject(error);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
child.on('exit', (code, signal) => {
|
|
312
|
+
if (settled) return;
|
|
313
|
+
settled = true;
|
|
314
|
+
clearTimeout(timeout);
|
|
315
|
+
reject(new Error(`OpenChamber daemon exited before reporting ready${signal ? ` (${signal})` : ` (code ${code ?? 'unknown'})`}`));
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
} catch (error) {
|
|
319
|
+
await terminateProcessTree(child.pid, { gracefulTimeoutMs: 1500, forceTimeoutMs: 1500 });
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
try {
|
|
324
|
+
if (typeof child.disconnect === 'function' && child.connected) {
|
|
325
|
+
child.disconnect();
|
|
326
|
+
}
|
|
327
|
+
} catch {
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
try {
|
|
331
|
+
fs.closeSync(logFd);
|
|
332
|
+
} catch {
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const resolvedLogPath = getLogFilePath(resolvedPort);
|
|
336
|
+
if (initialLogPath !== resolvedLogPath && !fs.existsSync(resolvedLogPath)) {
|
|
337
|
+
try {
|
|
338
|
+
fs.renameSync(initialLogPath, resolvedLogPath);
|
|
339
|
+
} catch {
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (!isProcessRunning(child.pid)) {
|
|
344
|
+
serveSpin?.error('Failed to start OpenChamber');
|
|
345
|
+
throw new Error('Failed to start server in daemon mode');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const pidFilePath = await getPidFilePath(resolvedPort);
|
|
349
|
+
const instanceFilePath = await getInstanceFilePath(resolvedPort);
|
|
350
|
+
writePidFile(pidFilePath, child.pid, emitNotice);
|
|
351
|
+
writeInstanceOptions(instanceFilePath, {
|
|
352
|
+
port: resolvedPort,
|
|
353
|
+
host: effectiveHost,
|
|
354
|
+
launchMode: 'daemon',
|
|
355
|
+
uiPassword: effectiveUiPassword,
|
|
356
|
+
apiOnly: options.apiOnly === true,
|
|
357
|
+
}, emitNotice);
|
|
358
|
+
|
|
359
|
+
const serveResult = {
|
|
360
|
+
port: resolvedPort,
|
|
361
|
+
pid: child.pid,
|
|
362
|
+
url: buildLocalUrl(resolvedPort, '/'),
|
|
363
|
+
logs: `openchamber logs -p ${resolvedPort}`,
|
|
364
|
+
launchMode: 'daemon',
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
if (isJsonMode(options)) {
|
|
368
|
+
printJson({ ...serveResult, messages: jsonMessages });
|
|
369
|
+
return resolvedPort;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (isQuietMode(options)) {
|
|
373
|
+
if (options.suppressQuietOutput) {
|
|
374
|
+
return resolvedPort;
|
|
375
|
+
}
|
|
376
|
+
process.stdout.write(`${resolvedPort}\n`);
|
|
377
|
+
return resolvedPort;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
serveSpin?.clear();
|
|
381
|
+
|
|
382
|
+
if (!options.suppressStartupSummary && showOutput) {
|
|
383
|
+
clackIntro('OpenChamber Started');
|
|
384
|
+
logStatus('success', `port ${serveResult.port} (PID: ${serveResult.pid})`);
|
|
385
|
+
logStatus('info', `visit: ${serveResult.url}`);
|
|
386
|
+
logStatus('info', `logs: ${serveResult.logs}`);
|
|
387
|
+
clackOutro('daemon running');
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return resolvedPort;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return serveCommand;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export { createServeCommand };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { EXIT_CODE, TunnelCliError } from './cli-errors.js';
|
|
2
|
+
import { getStartupStatus, enableStartupService, disableStartupService } from './cli-startup.js';
|
|
3
|
+
import {
|
|
4
|
+
intro as clackIntro,
|
|
5
|
+
outro as clackOutro,
|
|
6
|
+
isJsonMode,
|
|
7
|
+
isQuietMode,
|
|
8
|
+
printJson,
|
|
9
|
+
logStatus,
|
|
10
|
+
} from '../cli-output.js';
|
|
11
|
+
|
|
12
|
+
async function startupCommand(options, action = 'status') {
|
|
13
|
+
const normalized = typeof action === 'string' ? action.trim().toLowerCase() : 'status';
|
|
14
|
+
if (!['status', 'enable', 'disable'].includes(normalized)) {
|
|
15
|
+
throw new TunnelCliError(
|
|
16
|
+
`Unknown startup subcommand '${action}'. Use 'openchamber startup --help'.`,
|
|
17
|
+
EXIT_CODE.USAGE_ERROR
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let status;
|
|
22
|
+
if (normalized === 'enable') {
|
|
23
|
+
status = enableStartupService(options);
|
|
24
|
+
} else if (normalized === 'disable') {
|
|
25
|
+
status = disableStartupService();
|
|
26
|
+
} else {
|
|
27
|
+
status = getStartupStatus();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const result = { action: normalized, ...status };
|
|
31
|
+
if (!result.supported) {
|
|
32
|
+
throw new TunnelCliError(
|
|
33
|
+
`Startup integration is not supported on ${result.platform}.`,
|
|
34
|
+
EXIT_CODE.USAGE_ERROR
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (normalized === 'enable' && result.activeState === 'failed') {
|
|
38
|
+
throw new TunnelCliError(
|
|
39
|
+
'Startup service was installed but failed to start. Run `journalctl --user -u openchamber.service -n 80 --no-pager` for details.',
|
|
40
|
+
EXIT_CODE.GENERAL_ERROR
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (isJsonMode(options)) {
|
|
44
|
+
printJson(result);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isQuietMode(options)) {
|
|
49
|
+
process.stdout.write(`startup ${result.enabled ? 'enabled' : 'disabled'} platform:${result.platform} supported:${result.supported ? 'yes' : 'no'}${result.servicePath ? ` path:${result.servicePath}` : ''}\n`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
clackIntro('OpenChamber Startup');
|
|
54
|
+
logStatus(result.enabled ? 'success' : 'info', `startup ${result.enabled ? 'enabled' : 'disabled'}`, result.servicePath || undefined);
|
|
55
|
+
if (typeof result.activeState === 'string') {
|
|
56
|
+
logStatus(result.active ? 'success' : result.activeState === 'failed' ? 'error' : 'warning', `service ${result.activeState}`);
|
|
57
|
+
}
|
|
58
|
+
if (normalized === 'enable') {
|
|
59
|
+
logStatus('info', 'service command', 'openchamber serve --foreground');
|
|
60
|
+
}
|
|
61
|
+
clackOutro(normalized === 'status' ? 'status complete' : `${normalized} complete`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { startupCommand };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { readInstanceOptions } from './cli-process.js';
|
|
2
|
+
import { discoverLifecycleInstances, discoverDesktopInstance } from './cli-lifecycle.js';
|
|
3
|
+
import {
|
|
4
|
+
intro as clackIntro,
|
|
5
|
+
outro as clackOutro,
|
|
6
|
+
isJsonMode,
|
|
7
|
+
isQuietMode,
|
|
8
|
+
printJson,
|
|
9
|
+
logStatus,
|
|
10
|
+
} from '../cli-output.js';
|
|
11
|
+
|
|
12
|
+
async function statusCommand(options = {}) {
|
|
13
|
+
const [runningInstances, desktopInstance] = options.explicitPort
|
|
14
|
+
? [await discoverLifecycleInstances(options), null]
|
|
15
|
+
: await Promise.all([
|
|
16
|
+
discoverLifecycleInstances(options),
|
|
17
|
+
discoverDesktopInstance(),
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const toPasswordProtectionLabel = (value) => {
|
|
21
|
+
if (value === true) return 'yes';
|
|
22
|
+
if (value === false) return 'no';
|
|
23
|
+
return 'unknown';
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const desktopOnly = desktopInstance && !runningInstances.some((entry) => entry.port === desktopInstance.port)
|
|
27
|
+
? {
|
|
28
|
+
runtime: 'desktop',
|
|
29
|
+
port: desktopInstance.port,
|
|
30
|
+
pid: Number.isFinite(desktopInstance.pid) ? desktopInstance.pid : null,
|
|
31
|
+
launchMode: null,
|
|
32
|
+
passwordProtected: null,
|
|
33
|
+
}
|
|
34
|
+
: null;
|
|
35
|
+
|
|
36
|
+
const cliInstances = runningInstances
|
|
37
|
+
.filter((instance) => instance.runtime !== 'desktop')
|
|
38
|
+
.map((instance) => {
|
|
39
|
+
const storedOptions = instance.instanceFilePath ? (readInstanceOptions(instance.instanceFilePath) || {}) : {};
|
|
40
|
+
const passwordProtected = storedOptions.hasUiPassword === true
|
|
41
|
+
|| (typeof storedOptions.uiPassword === 'string' && storedOptions.uiPassword.trim().length > 0);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
runtime: instance.source === 'probe' ? 'unmanaged' : 'cli',
|
|
45
|
+
port: instance.port,
|
|
46
|
+
pid: instance.pid,
|
|
47
|
+
launchMode: instance.launchMode || 'daemon',
|
|
48
|
+
passwordProtected: instance.source === 'probe' ? null : passwordProtected,
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const explicitDesktop = options.explicitPort
|
|
53
|
+
? runningInstances.find((entry) => entry.runtime === 'desktop')
|
|
54
|
+
: null;
|
|
55
|
+
|
|
56
|
+
const instances = desktopOnly ? [...cliInstances, desktopOnly] : cliInstances;
|
|
57
|
+
if (explicitDesktop) {
|
|
58
|
+
instances.push({
|
|
59
|
+
runtime: 'desktop',
|
|
60
|
+
port: explicitDesktop.port,
|
|
61
|
+
pid: Number.isFinite(explicitDesktop.pid) ? explicitDesktop.pid : null,
|
|
62
|
+
launchMode: null,
|
|
63
|
+
passwordProtected: null,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const runningCount = instances.length;
|
|
67
|
+
|
|
68
|
+
if (isJsonMode(options)) {
|
|
69
|
+
printJson({
|
|
70
|
+
state: runningCount > 0 ? 'running' : 'stopped',
|
|
71
|
+
runningCount,
|
|
72
|
+
instances,
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (isQuietMode(options)) {
|
|
78
|
+
if (runningCount === 0) {
|
|
79
|
+
process.stdout.write('stopped\n');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const instance of instances) {
|
|
84
|
+
process.stdout.write(
|
|
85
|
+
`port ${instance.port} mode:${instance.launchMode || 'n/a'} pass:${toPasswordProtectionLabel(instance.passwordProtected)}\n`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
clackIntro('OpenChamber Status');
|
|
92
|
+
|
|
93
|
+
if (runningCount === 0) {
|
|
94
|
+
logStatus('warning', 'stopped');
|
|
95
|
+
clackOutro('no running instances');
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (const instance of instances) {
|
|
100
|
+
const pidSuffix = Number.isFinite(instance.pid) ? ` (PID: ${instance.pid})` : '';
|
|
101
|
+
const modeDetail = instance.launchMode ? `mode: ${instance.launchMode}` : '';
|
|
102
|
+
const protectionDetail = `password: ${toPasswordProtectionLabel(instance.passwordProtected)}`;
|
|
103
|
+
const detail = modeDetail ? `${modeDetail}; ${protectionDetail}` : protectionDetail;
|
|
104
|
+
if (instance.runtime === 'desktop') {
|
|
105
|
+
logStatus('info', `desktop app on port ${instance.port}${pidSuffix}`, detail);
|
|
106
|
+
} else {
|
|
107
|
+
logStatus('success', `port ${instance.port}${pidSuffix}`, detail);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
clackOutro(`${runningCount} running runtime(s)`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { statusCommand };
|