@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,370 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { spawnSync } from 'child_process';
|
|
5
|
+
import { DEFAULT_PORT } from './cli-args.js';
|
|
6
|
+
import { EXIT_CODE, TunnelCliError } from './cli-errors.js';
|
|
7
|
+
import { getDataDir } from './cli-paths.js';
|
|
8
|
+
import { hasUiPasswordConfigured } from './cli-network.js';
|
|
9
|
+
import { searchPathFor } from './cli-executables.js';
|
|
10
|
+
|
|
11
|
+
const STARTUP_SERVICE_ID = 'dev.openchamber.web';
|
|
12
|
+
|
|
13
|
+
function getStartupServicePaths() {
|
|
14
|
+
if (process.platform === 'darwin') {
|
|
15
|
+
return {
|
|
16
|
+
platform: 'macos',
|
|
17
|
+
servicePath: path.join(os.homedir(), 'Library', 'LaunchAgents', `${STARTUP_SERVICE_ID}.plist`),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (process.platform === 'linux') {
|
|
21
|
+
return {
|
|
22
|
+
platform: 'linux',
|
|
23
|
+
servicePath: path.join(os.homedir(), '.config', 'systemd', 'user', 'openchamber.service'),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (process.platform === 'win32') {
|
|
27
|
+
return { platform: 'windows', servicePath: STARTUP_SERVICE_ID };
|
|
28
|
+
}
|
|
29
|
+
return { platform: process.platform, servicePath: null };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function escapeXml(value) {
|
|
33
|
+
return String(value)
|
|
34
|
+
.replace(/&/g, '&')
|
|
35
|
+
.replace(/</g, '<')
|
|
36
|
+
.replace(/>/g, '>')
|
|
37
|
+
.replace(/"/g, '"')
|
|
38
|
+
.replace(/'/g, ''');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function systemdEscapeArg(value) {
|
|
42
|
+
return String(value).replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function startupShellQuote(value) {
|
|
46
|
+
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function systemdUnitPath(value) {
|
|
50
|
+
return String(value).replace(/\\/g, '\\\\').replace(/ /g, '\\x20');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function powershellQuote(value) {
|
|
54
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function startupEnvFileQuote(value) {
|
|
58
|
+
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function systemdEnvFileQuote(value) {
|
|
62
|
+
return `"${String(value)
|
|
63
|
+
.replace(/\\/g, '\\\\')
|
|
64
|
+
.replace(/"/g, '\\"')
|
|
65
|
+
.replace(/`/g, '\\`')
|
|
66
|
+
.replace(/\$/g, '\\$')}"`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function getStartupEnvFilePath() {
|
|
70
|
+
return path.join(getDataDir(), 'startup.env');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getMacosStartupWrapperPath() {
|
|
74
|
+
return path.join(getDataDir(), 'bin', 'OpenChamber');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function collectStartupEnv(options = {}) {
|
|
78
|
+
const env = options.envSnapshot === false ? {} : Object.fromEntries(
|
|
79
|
+
Object.entries(process.env)
|
|
80
|
+
.filter(([key, value]) => shouldPersistStartupEnv(key, value))
|
|
81
|
+
.map(([key, value]) => [key, String(value)])
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (options.envSnapshot !== false) {
|
|
85
|
+
const opencodeBinary = process.env.OPENCODE_BINARY || searchPathFor('opencode');
|
|
86
|
+
if (typeof opencodeBinary === 'string' && opencodeBinary.trim().length > 0) {
|
|
87
|
+
env.OPENCODE_BINARY = opencodeBinary.trim();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const uiPassword = hasUiPasswordConfigured(options.uiPassword) ? options.uiPassword : undefined;
|
|
91
|
+
if (uiPassword) {
|
|
92
|
+
env.OPENCHAMBER_UI_PASSWORD = uiPassword;
|
|
93
|
+
}
|
|
94
|
+
if (options.apiOnly === true) {
|
|
95
|
+
env.OPENCHAMBER_API_ONLY = 'true';
|
|
96
|
+
}
|
|
97
|
+
if (typeof process.env.OPENCHAMBER_DATA_DIR === 'string' && process.env.OPENCHAMBER_DATA_DIR.trim().length > 0) {
|
|
98
|
+
env.OPENCHAMBER_DATA_DIR = path.resolve(process.env.OPENCHAMBER_DATA_DIR.trim());
|
|
99
|
+
}
|
|
100
|
+
return env;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function shouldPersistStartupEnv(key, value) {
|
|
104
|
+
if (typeof key !== 'string' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) return false;
|
|
105
|
+
if (typeof value !== 'string') return false;
|
|
106
|
+
if (/[\r\n]/.test(value)) return false;
|
|
107
|
+
|
|
108
|
+
// These are shell/session implementation details, not app configuration.
|
|
109
|
+
const volatileKeys = new Set([
|
|
110
|
+
'_',
|
|
111
|
+
'BASH_ENV',
|
|
112
|
+
'COLUMNS',
|
|
113
|
+
'CONDA_DEFAULT_ENV',
|
|
114
|
+
'CONDA_PREFIX',
|
|
115
|
+
'CONDA_PROMPT_MODIFIER',
|
|
116
|
+
'CONDA_SHLVL',
|
|
117
|
+
'ENV',
|
|
118
|
+
'HISTFILE',
|
|
119
|
+
'HISTFILESIZE',
|
|
120
|
+
'HISTSIZE',
|
|
121
|
+
'LINES',
|
|
122
|
+
'OLDPWD',
|
|
123
|
+
'PROMPT',
|
|
124
|
+
'PROMPT_COMMAND',
|
|
125
|
+
'PS1',
|
|
126
|
+
'PS2',
|
|
127
|
+
'PS3',
|
|
128
|
+
'PS4',
|
|
129
|
+
'PWD',
|
|
130
|
+
'PYENV_VERSION',
|
|
131
|
+
'SHLVL',
|
|
132
|
+
'TERM',
|
|
133
|
+
'TERM_PROGRAM',
|
|
134
|
+
'TERM_PROGRAM_VERSION',
|
|
135
|
+
'TTY',
|
|
136
|
+
'VIRTUAL_ENV',
|
|
137
|
+
'VIRTUAL_ENV_PROMPT',
|
|
138
|
+
]);
|
|
139
|
+
return !volatileKeys.has(key);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function writeStartupEnvFile(options = {}, fileOptions = {}) {
|
|
143
|
+
const envFilePath = getStartupEnvFilePath();
|
|
144
|
+
const lines = [];
|
|
145
|
+
const env = collectStartupEnv(options);
|
|
146
|
+
const quoteValue = typeof fileOptions.quoteValue === 'function' ? fileOptions.quoteValue : startupEnvFileQuote;
|
|
147
|
+
for (const [key, value] of Object.entries(env)) {
|
|
148
|
+
lines.push(`${key}=${quoteValue(value)}`);
|
|
149
|
+
}
|
|
150
|
+
fs.mkdirSync(path.dirname(envFilePath), { recursive: true, mode: 0o700 });
|
|
151
|
+
fs.writeFileSync(envFilePath, lines.length > 0 ? `${lines.join('\n')}\n` : '', { mode: 0o600 });
|
|
152
|
+
return envFilePath;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function removeStartupEnvFile() {
|
|
156
|
+
try { fs.unlinkSync(getStartupEnvFilePath()); } catch {}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function resolveCliEntrypoint() {
|
|
160
|
+
const entry = typeof process.argv[1] === 'string' && process.argv[1].trim().length > 0
|
|
161
|
+
? process.argv[1]
|
|
162
|
+
: path.join(__dirname, 'cli.js');
|
|
163
|
+
try {
|
|
164
|
+
return fs.realpathSync(entry);
|
|
165
|
+
} catch {
|
|
166
|
+
return path.resolve(entry);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function buildStartupArgs(options = {}) {
|
|
171
|
+
const args = [resolveCliEntrypoint(), 'serve', '--foreground', '--port', String(options.port || DEFAULT_PORT)];
|
|
172
|
+
if (typeof options.host === 'string' && options.host.length > 0) {
|
|
173
|
+
args.push('--host', options.host);
|
|
174
|
+
}
|
|
175
|
+
if (options.apiOnly === true) {
|
|
176
|
+
args.push('--api-only');
|
|
177
|
+
}
|
|
178
|
+
return args;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function writeMacosStartupWrapper(options = {}) {
|
|
182
|
+
const wrapperPath = getMacosStartupWrapperPath();
|
|
183
|
+
const args = buildStartupArgs(options).map(startupShellQuote).join(' ');
|
|
184
|
+
const content = `#!/bin/sh
|
|
185
|
+
exec ${startupShellQuote(process.execPath)} ${args}
|
|
186
|
+
`;
|
|
187
|
+
fs.mkdirSync(path.dirname(wrapperPath), { recursive: true, mode: 0o700 });
|
|
188
|
+
fs.writeFileSync(wrapperPath, content, { mode: 0o700 });
|
|
189
|
+
return wrapperPath;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function buildMacosLaunchAgent(options = {}) {
|
|
193
|
+
const wrapperPath = writeMacosStartupWrapper(options);
|
|
194
|
+
const args = [wrapperPath];
|
|
195
|
+
const env = collectStartupEnv(options);
|
|
196
|
+
const logDir = path.join(os.homedir(), 'Library', 'Logs', 'OpenChamber');
|
|
197
|
+
const argXml = args.map((arg) => ` <string>${escapeXml(arg)}</string>`).join('\n');
|
|
198
|
+
const envXml = Object.entries(env).length > 0
|
|
199
|
+
? ` <key>EnvironmentVariables</key>\n <dict>\n${Object.entries(env).map(([key, value]) => ` <key>${escapeXml(key)}</key>\n <string>${escapeXml(value)}</string>`).join('\n')}\n </dict>\n`
|
|
200
|
+
: '';
|
|
201
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
202
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
203
|
+
<plist version="1.0">
|
|
204
|
+
<dict>
|
|
205
|
+
<key>Label</key>
|
|
206
|
+
<string>${STARTUP_SERVICE_ID}</string>
|
|
207
|
+
<key>ProgramArguments</key>
|
|
208
|
+
<array>
|
|
209
|
+
${argXml}
|
|
210
|
+
</array>
|
|
211
|
+
${envXml} <key>ProcessType</key>
|
|
212
|
+
<string>Background</string>
|
|
213
|
+
<key>RunAtLoad</key>
|
|
214
|
+
<true/>
|
|
215
|
+
<key>KeepAlive</key>
|
|
216
|
+
<true/>
|
|
217
|
+
<key>WorkingDirectory</key>
|
|
218
|
+
<string>${escapeXml(os.homedir())}</string>
|
|
219
|
+
<key>StandardOutPath</key>
|
|
220
|
+
<string>${escapeXml(path.join(logDir, 'startup.log'))}</string>
|
|
221
|
+
<key>StandardErrorPath</key>
|
|
222
|
+
<string>${escapeXml(path.join(logDir, 'startup.err.log'))}</string>
|
|
223
|
+
</dict>
|
|
224
|
+
</plist>
|
|
225
|
+
`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function buildSystemdUserService(options = {}) {
|
|
229
|
+
const args = buildStartupArgs(options).map((arg) => `"${systemdEscapeArg(arg)}"`).join(' ');
|
|
230
|
+
const envFilePath = getStartupEnvFilePath();
|
|
231
|
+
return `[Unit]
|
|
232
|
+
Description=OpenChamber web server
|
|
233
|
+
After=network-online.target
|
|
234
|
+
|
|
235
|
+
[Service]
|
|
236
|
+
Type=simple
|
|
237
|
+
EnvironmentFile=-${systemdEscapeArg(envFilePath)}
|
|
238
|
+
ExecStart="${systemdEscapeArg(process.execPath)}" ${args}
|
|
239
|
+
WorkingDirectory=${systemdUnitPath(os.homedir())}
|
|
240
|
+
Restart=always
|
|
241
|
+
RestartSec=5
|
|
242
|
+
|
|
243
|
+
[Install]
|
|
244
|
+
WantedBy=default.target
|
|
245
|
+
`;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function runStartupCommand(command, args, options = {}) {
|
|
249
|
+
const result = spawnSync(command, args, {
|
|
250
|
+
encoding: 'utf8',
|
|
251
|
+
stdio: options.stdio || 'pipe',
|
|
252
|
+
windowsHide: true,
|
|
253
|
+
});
|
|
254
|
+
if (result.error) {
|
|
255
|
+
throw result.error;
|
|
256
|
+
}
|
|
257
|
+
if (result.status !== 0 && options.allowFailure !== true) {
|
|
258
|
+
const detail = (result.stderr || result.stdout || '').trim();
|
|
259
|
+
throw new Error(`${command} ${args.join(' ')} failed${detail ? `: ${detail}` : ''}`);
|
|
260
|
+
}
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function getStartupStatus() {
|
|
265
|
+
const paths = getStartupServicePaths();
|
|
266
|
+
if (!paths.servicePath) {
|
|
267
|
+
return { supported: false, platform: paths.platform, enabled: false, servicePath: null };
|
|
268
|
+
}
|
|
269
|
+
if (paths.platform === 'windows') {
|
|
270
|
+
const result = runStartupCommand('schtasks.exe', ['/Query', '/TN', STARTUP_SERVICE_ID], { allowFailure: true });
|
|
271
|
+
return { supported: true, platform: paths.platform, enabled: result.status === 0, active: null, servicePath: paths.servicePath };
|
|
272
|
+
}
|
|
273
|
+
if (paths.platform === 'linux') {
|
|
274
|
+
const enabledResult = runStartupCommand('systemctl', ['--user', 'is-enabled', 'openchamber.service'], { allowFailure: true });
|
|
275
|
+
const activeResult = runStartupCommand('systemctl', ['--user', 'is-active', 'openchamber.service'], { allowFailure: true });
|
|
276
|
+
const activeState = (activeResult.stdout || '').trim() || 'inactive';
|
|
277
|
+
return {
|
|
278
|
+
supported: true,
|
|
279
|
+
platform: paths.platform,
|
|
280
|
+
enabled: enabledResult.status === 0 || fs.existsSync(paths.servicePath),
|
|
281
|
+
active: activeState === 'active',
|
|
282
|
+
activeState,
|
|
283
|
+
servicePath: paths.servicePath,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
supported: true,
|
|
288
|
+
platform: paths.platform,
|
|
289
|
+
enabled: fs.existsSync(paths.servicePath),
|
|
290
|
+
active: null,
|
|
291
|
+
servicePath: paths.servicePath,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function enableStartupService(options = {}) {
|
|
296
|
+
const paths = getStartupServicePaths();
|
|
297
|
+
if (!paths.servicePath) {
|
|
298
|
+
throw new TunnelCliError(`Startup integration is not supported on ${paths.platform}.`, EXIT_CODE.USAGE_ERROR);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (paths.platform === 'macos') {
|
|
302
|
+
removeStartupEnvFile();
|
|
303
|
+
fs.mkdirSync(path.dirname(paths.servicePath), { recursive: true, mode: 0o700 });
|
|
304
|
+
fs.mkdirSync(path.join(os.homedir(), 'Library', 'Logs', 'OpenChamber'), { recursive: true, mode: 0o700 });
|
|
305
|
+
fs.writeFileSync(paths.servicePath, buildMacosLaunchAgent(options), { mode: 0o600 });
|
|
306
|
+
runStartupCommand('/bin/launchctl', ['bootout', `gui/${process.getuid()}`, paths.servicePath], { allowFailure: true });
|
|
307
|
+
runStartupCommand('/bin/launchctl', ['bootstrap', `gui/${process.getuid()}`, paths.servicePath]);
|
|
308
|
+
runStartupCommand('/bin/launchctl', ['kickstart', '-k', `gui/${process.getuid()}/${STARTUP_SERVICE_ID}`], { allowFailure: true });
|
|
309
|
+
return getStartupStatus();
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (paths.platform === 'linux') {
|
|
313
|
+
writeStartupEnvFile(options, { quoteValue: systemdEnvFileQuote });
|
|
314
|
+
fs.mkdirSync(path.dirname(paths.servicePath), { recursive: true, mode: 0o700 });
|
|
315
|
+
fs.writeFileSync(paths.servicePath, buildSystemdUserService(options), { mode: 0o600 });
|
|
316
|
+
runStartupCommand('systemctl', ['--user', 'daemon-reload']);
|
|
317
|
+
runStartupCommand('systemctl', ['--user', 'enable', '--now', 'openchamber.service']);
|
|
318
|
+
return getStartupStatus();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const envFilePath = writeStartupEnvFile(options);
|
|
322
|
+
const startupArgs = buildStartupArgs(options).map(powershellQuote).join(', ');
|
|
323
|
+
const powerShellCommand = [
|
|
324
|
+
`$envFile=${powershellQuote(envFilePath)}`,
|
|
325
|
+
`if (Test-Path $envFile) { Get-Content $envFile | ForEach-Object { if ($_ -match '^([^=]+)=(.*)$') { $v=$matches[2]; if ($v.StartsWith("'") -and $v.EndsWith("'")) { $v=$v.Substring(1,$v.Length-2).Replace("'\\''","'") }; [Environment]::SetEnvironmentVariable($matches[1], $v, 'Process') } } }`,
|
|
326
|
+
`& ${powershellQuote(process.execPath)} ${startupArgs}`,
|
|
327
|
+
].join('; ');
|
|
328
|
+
const taskArgs = `powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "${powerShellCommand.replace(/"/g, '\\"')}"`;
|
|
329
|
+
runStartupCommand('schtasks.exe', [
|
|
330
|
+
'/Create',
|
|
331
|
+
'/TN', STARTUP_SERVICE_ID,
|
|
332
|
+
'/SC', 'ONLOGON',
|
|
333
|
+
'/RL', 'LIMITED',
|
|
334
|
+
'/F',
|
|
335
|
+
'/TR', taskArgs,
|
|
336
|
+
]);
|
|
337
|
+
runStartupCommand('schtasks.exe', ['/Run', '/TN', STARTUP_SERVICE_ID], { allowFailure: true });
|
|
338
|
+
return getStartupStatus();
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function disableStartupService() {
|
|
342
|
+
const paths = getStartupServicePaths();
|
|
343
|
+
if (!paths.servicePath) {
|
|
344
|
+
throw new TunnelCliError(`Startup integration is not supported on ${paths.platform}.`, EXIT_CODE.USAGE_ERROR);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (paths.platform === 'macos') {
|
|
348
|
+
runStartupCommand('/bin/launchctl', ['bootout', `gui/${process.getuid()}`, paths.servicePath], { allowFailure: true });
|
|
349
|
+
try { fs.unlinkSync(paths.servicePath); } catch {}
|
|
350
|
+
return getStartupStatus();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (paths.platform === 'linux') {
|
|
354
|
+
runStartupCommand('systemctl', ['--user', 'disable', '--now', 'openchamber.service'], { allowFailure: true });
|
|
355
|
+
try { fs.unlinkSync(paths.servicePath); } catch {}
|
|
356
|
+
runStartupCommand('systemctl', ['--user', 'daemon-reload'], { allowFailure: true });
|
|
357
|
+
return getStartupStatus();
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
runStartupCommand('schtasks.exe', ['/End', '/TN', STARTUP_SERVICE_ID], { allowFailure: true });
|
|
361
|
+
runStartupCommand('schtasks.exe', ['/Delete', '/TN', STARTUP_SERVICE_ID, '/F'], { allowFailure: true });
|
|
362
|
+
return getStartupStatus();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
export {
|
|
367
|
+
getStartupStatus,
|
|
368
|
+
enableStartupService,
|
|
369
|
+
disableStartupService,
|
|
370
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { cloudflareTunnelProviderCapabilities } from '../../server/lib/tunnels/providers/cloudflare.js';
|
|
2
|
+
import { ngrokTunnelProviderCapabilities } from '../../server/lib/tunnels/providers/ngrok.js';
|
|
3
|
+
|
|
4
|
+
const DEFAULT_TUNNEL_PROVIDER_CAPABILITIES = [
|
|
5
|
+
cloudflareTunnelProviderCapabilities,
|
|
6
|
+
ngrokTunnelProviderCapabilities,
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
export { DEFAULT_TUNNEL_PROVIDER_CAPABILITIES };
|