@chrysb/alphaclaw 0.7.0 → 0.7.2-beta.0
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/lib/public/css/cron.css +26 -17
- package/lib/public/css/explorer.css +12 -0
- package/lib/public/css/theme.css +14 -0
- package/lib/public/js/components/cron-tab/cron-calendar.js +17 -12
- package/lib/public/js/components/cron-tab/cron-job-list.js +11 -1
- package/lib/public/js/components/cron-tab/cron-overview.js +2 -1
- package/lib/public/js/components/cron-tab/cron-run-history-panel.js +65 -49
- package/lib/public/js/components/cron-tab/index.js +16 -2
- package/lib/public/js/components/icons.js +11 -0
- package/lib/public/js/components/routes/watchdog-route.js +1 -1
- package/lib/public/js/components/sidebar.js +14 -2
- package/lib/public/js/components/update-modal.js +173 -0
- package/lib/public/js/components/watchdog-tab/console/index.js +115 -0
- package/lib/public/js/components/watchdog-tab/console/use-console.js +137 -0
- package/lib/public/js/components/watchdog-tab/helpers.js +106 -0
- package/lib/public/js/components/watchdog-tab/incidents/index.js +56 -0
- package/lib/public/js/components/watchdog-tab/incidents/use-incidents.js +33 -0
- package/lib/public/js/components/watchdog-tab/index.js +84 -0
- package/lib/public/js/components/watchdog-tab/resource-bar.js +76 -0
- package/lib/public/js/components/watchdog-tab/resources/index.js +85 -0
- package/lib/public/js/components/watchdog-tab/resources/use-resources.js +13 -0
- package/lib/public/js/components/watchdog-tab/settings/index.js +44 -0
- package/lib/public/js/components/watchdog-tab/settings/use-settings.js +117 -0
- package/lib/public/js/components/watchdog-tab/terminal/index.js +20 -0
- package/lib/public/js/components/watchdog-tab/terminal/use-terminal.js +263 -0
- package/lib/public/js/components/watchdog-tab/use-watchdog-tab.js +55 -0
- package/lib/public/js/lib/api.js +75 -0
- package/lib/server/constants.js +3 -0
- package/lib/server/init/register-server-routes.js +240 -0
- package/lib/server/init/runtime-init.js +44 -0
- package/lib/server/init/server-lifecycle.js +55 -0
- package/lib/server/routes/system.js +98 -0
- package/lib/server/routes/watchdog.js +62 -0
- package/lib/server/watchdog-terminal-ws.js +114 -0
- package/lib/server/watchdog-terminal.js +262 -0
- package/lib/server.js +89 -215
- package/package.json +3 -2
- package/lib/public/js/components/watchdog-tab.js +0 -535
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
const crypto = require("crypto");
|
|
2
|
+
const { spawn, spawnSync } = require("child_process");
|
|
3
|
+
|
|
4
|
+
const kSessionIdleTtlMs = 15 * 60 * 1000;
|
|
5
|
+
const kCleanupIntervalMs = 30 * 1000;
|
|
6
|
+
const kMaxBufferedOutputChars = 200000;
|
|
7
|
+
|
|
8
|
+
const hasScriptCommand = () => {
|
|
9
|
+
try {
|
|
10
|
+
const result = spawnSync("sh", ["-lc", "command -v script >/dev/null 2>&1"], {
|
|
11
|
+
stdio: "ignore",
|
|
12
|
+
});
|
|
13
|
+
return result.status === 0;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const createShellProcess = ({
|
|
20
|
+
shell = "/bin/bash",
|
|
21
|
+
cwd = process.cwd(),
|
|
22
|
+
env = {},
|
|
23
|
+
preferPty = false,
|
|
24
|
+
} = {}) => {
|
|
25
|
+
if (preferPty && process.platform === "darwin") {
|
|
26
|
+
return spawn("script", ["-q", "/dev/null", shell, "-i"], {
|
|
27
|
+
cwd,
|
|
28
|
+
env: { ...env, TERM: env.TERM || "xterm-256color" },
|
|
29
|
+
stdio: "pipe",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (preferPty) {
|
|
33
|
+
return spawn("script", ["-q", "-f", "-c", `${shell} -i`, "/dev/null"], {
|
|
34
|
+
cwd,
|
|
35
|
+
env: { ...env, TERM: env.TERM || "xterm-256color" },
|
|
36
|
+
stdio: "pipe",
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return spawn(shell, ["-i"], {
|
|
40
|
+
cwd,
|
|
41
|
+
env: { ...env, TERM: env.TERM || "xterm-256color" },
|
|
42
|
+
stdio: "pipe",
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const createWatchdogTerminalService = ({
|
|
47
|
+
cwd = process.cwd(),
|
|
48
|
+
shell = process.env.SHELL || "/bin/bash",
|
|
49
|
+
env = process.env,
|
|
50
|
+
} = {}) => {
|
|
51
|
+
let session = null;
|
|
52
|
+
const preferPty = hasScriptCommand();
|
|
53
|
+
|
|
54
|
+
const notifySubscribers = (event) => {
|
|
55
|
+
if (!session?.subscribers?.size) return;
|
|
56
|
+
session.subscribers.forEach((subscriber) => {
|
|
57
|
+
try {
|
|
58
|
+
subscriber(event);
|
|
59
|
+
} catch {}
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const appendOutput = (chunk = "") => {
|
|
64
|
+
if (!session || !chunk) return;
|
|
65
|
+
const chunkText = String(chunk);
|
|
66
|
+
session.output += chunkText;
|
|
67
|
+
session.endCursor += chunkText.length;
|
|
68
|
+
if (session.output.length > kMaxBufferedOutputChars) {
|
|
69
|
+
const trimCount = session.output.length - kMaxBufferedOutputChars;
|
|
70
|
+
session.output = session.output.slice(trimCount);
|
|
71
|
+
session.startCursor += trimCount;
|
|
72
|
+
}
|
|
73
|
+
notifySubscribers({ type: "output", data: chunkText });
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const markActive = () => {
|
|
77
|
+
if (!session) return;
|
|
78
|
+
session.lastActiveAtMs = Date.now();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const createOrReuseSession = () => {
|
|
82
|
+
if (session && !session.ended) {
|
|
83
|
+
markActive();
|
|
84
|
+
return {
|
|
85
|
+
id: session.id,
|
|
86
|
+
shell,
|
|
87
|
+
cwd,
|
|
88
|
+
ended: false,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if (session && session.ended) session = null;
|
|
92
|
+
|
|
93
|
+
const proc = createShellProcess({ shell, cwd, env, preferPty });
|
|
94
|
+
const sessionId = crypto.randomUUID();
|
|
95
|
+
session = {
|
|
96
|
+
id: sessionId,
|
|
97
|
+
proc,
|
|
98
|
+
output: "",
|
|
99
|
+
startCursor: 0,
|
|
100
|
+
endCursor: 0,
|
|
101
|
+
ended: false,
|
|
102
|
+
exitCode: null,
|
|
103
|
+
signal: null,
|
|
104
|
+
lastActiveAtMs: Date.now(),
|
|
105
|
+
subscribers: new Set(),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
proc.stdout.setEncoding("utf8");
|
|
109
|
+
proc.stderr.setEncoding("utf8");
|
|
110
|
+
proc.stdout.on("data", (chunk) => appendOutput(chunk));
|
|
111
|
+
proc.stderr.on("data", (chunk) => appendOutput(chunk));
|
|
112
|
+
proc.on("close", (code, signal) => {
|
|
113
|
+
if (!session || session.id !== sessionId) return;
|
|
114
|
+
session.ended = true;
|
|
115
|
+
session.exitCode = code;
|
|
116
|
+
session.signal = signal;
|
|
117
|
+
const endLine = `\r\n[terminal exited${code != null ? ` with code ${code}` : ""}${signal ? ` (${signal})` : ""}]\r\n`;
|
|
118
|
+
appendOutput(endLine);
|
|
119
|
+
notifySubscribers({
|
|
120
|
+
type: "exit",
|
|
121
|
+
code,
|
|
122
|
+
signal,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
id: session.id,
|
|
128
|
+
shell,
|
|
129
|
+
cwd,
|
|
130
|
+
ended: false,
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const subscribe = ({
|
|
135
|
+
sessionId = "",
|
|
136
|
+
onEvent = () => {},
|
|
137
|
+
replayBuffer = true,
|
|
138
|
+
tailLines = 0,
|
|
139
|
+
} = {}) => {
|
|
140
|
+
if (!session || String(session.id) !== String(sessionId || "")) {
|
|
141
|
+
return {
|
|
142
|
+
ok: false,
|
|
143
|
+
error: "Terminal session not found",
|
|
144
|
+
unsubscribe: () => {},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
markActive();
|
|
148
|
+
const subscriber = (event) => onEvent(event);
|
|
149
|
+
session.subscribers.add(subscriber);
|
|
150
|
+
if (replayBuffer && session.output) {
|
|
151
|
+
onEvent({ type: "output", data: session.output });
|
|
152
|
+
} else if (!replayBuffer && Number(tailLines || 0) > 0 && !session.ended) {
|
|
153
|
+
const lines = String(session.output || "").split("\n");
|
|
154
|
+
const count = Math.max(1, Math.floor(Number(tailLines || 0)));
|
|
155
|
+
const tail = lines.slice(-count).join("\n");
|
|
156
|
+
if (tail.trim()) onEvent({ type: "output", data: tail });
|
|
157
|
+
}
|
|
158
|
+
if (session.ended) {
|
|
159
|
+
onEvent({
|
|
160
|
+
type: "exit",
|
|
161
|
+
code: session.exitCode,
|
|
162
|
+
signal: session.signal,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
ok: true,
|
|
167
|
+
unsubscribe: () => {
|
|
168
|
+
if (!session) return;
|
|
169
|
+
session.subscribers.delete(subscriber);
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const readOutput = ({ sessionId = "", cursor = 0 } = {}) => {
|
|
175
|
+
if (!session || String(session.id) !== String(sessionId || "")) {
|
|
176
|
+
return {
|
|
177
|
+
found: false,
|
|
178
|
+
output: "",
|
|
179
|
+
cursor: 0,
|
|
180
|
+
startCursor: 0,
|
|
181
|
+
endCursor: 0,
|
|
182
|
+
ended: true,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
markActive();
|
|
186
|
+
const requestedCursor = Number(cursor);
|
|
187
|
+
const safeCursor = Number.isFinite(requestedCursor)
|
|
188
|
+
? Math.max(0, Math.floor(requestedCursor))
|
|
189
|
+
: 0;
|
|
190
|
+
const effectiveCursor =
|
|
191
|
+
safeCursor < session.startCursor || safeCursor > session.endCursor
|
|
192
|
+
? session.startCursor
|
|
193
|
+
: safeCursor;
|
|
194
|
+
const sliceIndex = Math.max(0, effectiveCursor - session.startCursor);
|
|
195
|
+
return {
|
|
196
|
+
found: true,
|
|
197
|
+
output: session.output.slice(sliceIndex),
|
|
198
|
+
cursor: session.endCursor,
|
|
199
|
+
startCursor: session.startCursor,
|
|
200
|
+
endCursor: session.endCursor,
|
|
201
|
+
ended: !!session.ended,
|
|
202
|
+
exitCode: session.exitCode,
|
|
203
|
+
signal: session.signal,
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const writeInput = ({ sessionId = "", input = "" } = {}) => {
|
|
208
|
+
if (!session || String(session.id) !== String(sessionId || "")) {
|
|
209
|
+
return { ok: false, error: "Terminal session not found" };
|
|
210
|
+
}
|
|
211
|
+
if (session.ended || !session.proc.stdin.writable) {
|
|
212
|
+
return { ok: false, error: "Terminal session has ended" };
|
|
213
|
+
}
|
|
214
|
+
markActive();
|
|
215
|
+
session.proc.stdin.write(String(input || ""));
|
|
216
|
+
return { ok: true };
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const closeSession = ({ sessionId = "" } = {}) => {
|
|
220
|
+
if (!session || String(session.id) !== String(sessionId || "")) {
|
|
221
|
+
return { ok: true };
|
|
222
|
+
}
|
|
223
|
+
const targetProc = session.proc;
|
|
224
|
+
session = null;
|
|
225
|
+
try {
|
|
226
|
+
targetProc.kill("SIGTERM");
|
|
227
|
+
} catch {}
|
|
228
|
+
return { ok: true };
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const disposeSession = () => {
|
|
232
|
+
if (!session) return;
|
|
233
|
+
const targetProc = session.proc;
|
|
234
|
+
session = null;
|
|
235
|
+
try {
|
|
236
|
+
targetProc.kill("SIGTERM");
|
|
237
|
+
} catch {}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const cleanupTimer = setInterval(() => {
|
|
241
|
+
if (!session || session.ended) return;
|
|
242
|
+
const idleForMs = Date.now() - Number(session.lastActiveAtMs || 0);
|
|
243
|
+
if (idleForMs < kSessionIdleTtlMs) return;
|
|
244
|
+
try {
|
|
245
|
+
session.proc.kill("SIGTERM");
|
|
246
|
+
} catch {}
|
|
247
|
+
}, kCleanupIntervalMs);
|
|
248
|
+
cleanupTimer.unref?.();
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
createOrReuseSession,
|
|
252
|
+
subscribe,
|
|
253
|
+
readOutput,
|
|
254
|
+
writeInput,
|
|
255
|
+
closeSession,
|
|
256
|
+
disposeSession,
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
module.exports = {
|
|
261
|
+
createWatchdogTerminalService,
|
|
262
|
+
};
|
package/lib/server.js
CHANGED
|
@@ -107,39 +107,36 @@ const { createDiscordApi } = require("./server/discord-api");
|
|
|
107
107
|
const { createSlackApi } = require("./server/slack-api");
|
|
108
108
|
const { createWatchdogNotifier } = require("./server/watchdog-notify");
|
|
109
109
|
const { createWatchdog } = require("./server/watchdog");
|
|
110
|
+
const { createWatchdogTerminalService } = require("./server/watchdog-terminal");
|
|
111
|
+
const {
|
|
112
|
+
createWatchdogTerminalWsBridge,
|
|
113
|
+
} = require("./server/watchdog-terminal-ws");
|
|
110
114
|
const { createDoctorService } = require("./server/doctor/service");
|
|
111
115
|
const { createAgentsService } = require("./server/agents/service");
|
|
112
116
|
const { createOperationEventsService } = require("./server/operation-events");
|
|
113
117
|
const { runOnboardedBootSequence } = require("./server/startup");
|
|
114
118
|
const { createCronService } = require("./server/cron-service");
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const { registerTelegramRoutes } = require("./server/routes/telegram");
|
|
127
|
-
const { registerWebhookRoutes } = require("./server/routes/webhooks");
|
|
128
|
-
const { registerWatchdogRoutes } = require("./server/routes/watchdog");
|
|
129
|
-
const { registerUsageRoutes } = require("./server/routes/usage");
|
|
130
|
-
const { registerGmailRoutes } = require("./server/routes/gmail");
|
|
131
|
-
const { registerDoctorRoutes } = require("./server/routes/doctor");
|
|
132
|
-
const { registerAgentRoutes } = require("./server/routes/agents");
|
|
133
|
-
const { registerCronRoutes } = require("./server/routes/cron");
|
|
119
|
+
const {
|
|
120
|
+
initializeServerRuntime,
|
|
121
|
+
initializeServerDatabases,
|
|
122
|
+
} = require("./server/init/runtime-init");
|
|
123
|
+
const {
|
|
124
|
+
registerServerRoutes,
|
|
125
|
+
} = require("./server/init/register-server-routes");
|
|
126
|
+
const {
|
|
127
|
+
startServerLifecycle,
|
|
128
|
+
registerServerShutdown,
|
|
129
|
+
} = require("./server/init/server-lifecycle");
|
|
134
130
|
|
|
135
131
|
const { PORT, kTrustProxyHops, SETUP_API_PREFIXES } = constants;
|
|
136
132
|
|
|
137
|
-
|
|
138
|
-
attachGatewaySignalHandlers();
|
|
139
|
-
cleanupStaleImportTempDirs();
|
|
140
|
-
migrateManagedInternalFiles({
|
|
133
|
+
initializeServerRuntime({
|
|
141
134
|
fs,
|
|
142
|
-
|
|
135
|
+
constants,
|
|
136
|
+
startEnvWatcher,
|
|
137
|
+
attachGatewaySignalHandlers,
|
|
138
|
+
cleanupStaleImportTempDirs,
|
|
139
|
+
migrateManagedInternalFiles,
|
|
143
140
|
});
|
|
144
141
|
|
|
145
142
|
const app = express();
|
|
@@ -194,118 +191,19 @@ const cronService = createCronService({
|
|
|
194
191
|
getSessionUsageByKeyPattern,
|
|
195
192
|
});
|
|
196
193
|
|
|
197
|
-
const { requireAuth, isAuthorizedRequest } = registerAuthRoutes({
|
|
198
|
-
app,
|
|
199
|
-
loginThrottle,
|
|
200
|
-
});
|
|
201
194
|
app.use(express.static(path.join(__dirname, "public")));
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
pruneDays: constants.kWatchdogLogRetentionDays,
|
|
209
|
-
});
|
|
210
|
-
initUsageDb({
|
|
211
|
-
rootDir: constants.kRootDir,
|
|
212
|
-
});
|
|
213
|
-
initDoctorDb({
|
|
214
|
-
rootDir: constants.kRootDir,
|
|
195
|
+
initializeServerDatabases({
|
|
196
|
+
constants,
|
|
197
|
+
initWebhooksDb,
|
|
198
|
+
initWatchdogDb,
|
|
199
|
+
initUsageDb,
|
|
200
|
+
initDoctorDb,
|
|
215
201
|
});
|
|
216
202
|
const webhookMiddleware = createWebhookMiddleware({
|
|
217
203
|
getGatewayUrl,
|
|
218
204
|
insertRequest,
|
|
219
205
|
maxPayloadBytes: constants.kMaxPayloadBytes,
|
|
220
206
|
});
|
|
221
|
-
|
|
222
|
-
registerPageRoutes({ app, requireAuth, isGatewayRunning });
|
|
223
|
-
registerModelRoutes({
|
|
224
|
-
app,
|
|
225
|
-
shellCmd,
|
|
226
|
-
gatewayEnv,
|
|
227
|
-
parseJsonFromNoisyOutput,
|
|
228
|
-
normalizeOnboardingModels,
|
|
229
|
-
authProfiles,
|
|
230
|
-
readEnvFile,
|
|
231
|
-
writeEnvFile,
|
|
232
|
-
reloadEnv,
|
|
233
|
-
});
|
|
234
|
-
registerOnboardingRoutes({
|
|
235
|
-
app,
|
|
236
|
-
fs,
|
|
237
|
-
constants,
|
|
238
|
-
shellCmd,
|
|
239
|
-
gatewayEnv,
|
|
240
|
-
readEnvFile,
|
|
241
|
-
writeEnvFile,
|
|
242
|
-
reloadEnv,
|
|
243
|
-
isOnboarded,
|
|
244
|
-
resolveGithubRepoUrl,
|
|
245
|
-
resolveModelProvider,
|
|
246
|
-
hasCodexOauthProfile: authProfiles.hasCodexOauthProfile,
|
|
247
|
-
authProfiles,
|
|
248
|
-
ensureGatewayProxyConfig,
|
|
249
|
-
getBaseUrl,
|
|
250
|
-
startGateway,
|
|
251
|
-
});
|
|
252
|
-
registerSystemRoutes({
|
|
253
|
-
app,
|
|
254
|
-
fs,
|
|
255
|
-
readEnvFile,
|
|
256
|
-
writeEnvFile,
|
|
257
|
-
reloadEnv,
|
|
258
|
-
kKnownVars: constants.kKnownVars,
|
|
259
|
-
kKnownKeys: constants.kKnownKeys,
|
|
260
|
-
kSystemVars: constants.kSystemVars,
|
|
261
|
-
syncChannelConfig,
|
|
262
|
-
isGatewayRunning,
|
|
263
|
-
isOnboarded,
|
|
264
|
-
getChannelStatus,
|
|
265
|
-
openclawVersionService,
|
|
266
|
-
alphaclawVersionService,
|
|
267
|
-
clawCmd,
|
|
268
|
-
restartGateway,
|
|
269
|
-
OPENCLAW_DIR: constants.OPENCLAW_DIR,
|
|
270
|
-
restartRequiredState,
|
|
271
|
-
topicRegistry,
|
|
272
|
-
authProfiles,
|
|
273
|
-
});
|
|
274
|
-
registerBrowseRoutes({
|
|
275
|
-
app,
|
|
276
|
-
fs,
|
|
277
|
-
kRootDir: constants.OPENCLAW_DIR,
|
|
278
|
-
});
|
|
279
|
-
registerPairingRoutes({ app, clawCmd, isOnboarded });
|
|
280
|
-
registerCodexRoutes({
|
|
281
|
-
app,
|
|
282
|
-
createPkcePair,
|
|
283
|
-
parseCodexAuthorizationInput,
|
|
284
|
-
getCodexAccountId,
|
|
285
|
-
authProfiles,
|
|
286
|
-
});
|
|
287
|
-
registerGoogleRoutes({
|
|
288
|
-
app,
|
|
289
|
-
fs,
|
|
290
|
-
isGatewayRunning,
|
|
291
|
-
gogCmd,
|
|
292
|
-
getBaseUrl,
|
|
293
|
-
readGoogleCredentials,
|
|
294
|
-
getApiEnableUrl,
|
|
295
|
-
constants,
|
|
296
|
-
});
|
|
297
|
-
const gmailWatchService = registerGmailRoutes({
|
|
298
|
-
app,
|
|
299
|
-
fs,
|
|
300
|
-
constants,
|
|
301
|
-
gogCmd,
|
|
302
|
-
getBaseUrl,
|
|
303
|
-
readGoogleCredentials,
|
|
304
|
-
readEnvFile,
|
|
305
|
-
writeEnvFile,
|
|
306
|
-
reloadEnv,
|
|
307
|
-
restartRequiredState,
|
|
308
|
-
});
|
|
309
207
|
const telegramApi = createTelegramApi(() => process.env.TELEGRAM_BOT_TOKEN);
|
|
310
208
|
const discordApi = createDiscordApi(() => process.env.DISCORD_BOT_TOKEN);
|
|
311
209
|
const slackApi = createSlackApi(() => process.env.SLACK_BOT_TOKEN);
|
|
@@ -320,6 +218,9 @@ const watchdog = createWatchdog({
|
|
|
320
218
|
reloadEnv,
|
|
321
219
|
resolveSetupUrl,
|
|
322
220
|
});
|
|
221
|
+
const watchdogTerminal = createWatchdogTerminalService({
|
|
222
|
+
cwd: constants.OPENCLAW_DIR,
|
|
223
|
+
});
|
|
323
224
|
const doctorService = createDoctorService({
|
|
324
225
|
clawCmd,
|
|
325
226
|
listDoctorRuns,
|
|
@@ -353,116 +254,89 @@ const doSyncPromptFiles = () => {
|
|
|
353
254
|
});
|
|
354
255
|
installGogCliSkill({ fs, openclawDir: constants.OPENCLAW_DIR });
|
|
355
256
|
};
|
|
356
|
-
|
|
357
|
-
app,
|
|
358
|
-
telegramApi,
|
|
359
|
-
syncPromptFiles: doSyncPromptFiles,
|
|
360
|
-
shellCmd,
|
|
361
|
-
});
|
|
362
|
-
registerWebhookRoutes({
|
|
257
|
+
const { isAuthorizedRequest, gmailWatchService } = registerServerRoutes({
|
|
363
258
|
app,
|
|
364
259
|
fs,
|
|
365
260
|
constants,
|
|
366
|
-
|
|
261
|
+
loginThrottle,
|
|
367
262
|
shellCmd,
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
263
|
+
clawCmd,
|
|
264
|
+
gogCmd,
|
|
265
|
+
gatewayEnv,
|
|
266
|
+
parseJsonFromNoisyOutput,
|
|
267
|
+
normalizeOnboardingModels,
|
|
268
|
+
authProfiles,
|
|
269
|
+
readEnvFile,
|
|
270
|
+
writeEnvFile,
|
|
271
|
+
reloadEnv,
|
|
272
|
+
isOnboarded,
|
|
273
|
+
isGatewayRunning,
|
|
274
|
+
resolveGithubRepoUrl,
|
|
275
|
+
resolveModelProvider,
|
|
276
|
+
ensureGatewayProxyConfig,
|
|
277
|
+
getBaseUrl,
|
|
278
|
+
startGateway,
|
|
279
|
+
syncChannelConfig,
|
|
280
|
+
getChannelStatus,
|
|
281
|
+
openclawVersionService,
|
|
282
|
+
alphaclawVersionService,
|
|
283
|
+
restartGateway,
|
|
374
284
|
restartRequiredState,
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
285
|
+
topicRegistry,
|
|
286
|
+
createPkcePair,
|
|
287
|
+
parseCodexAuthorizationInput,
|
|
288
|
+
getCodexAccountId,
|
|
289
|
+
readGoogleCredentials,
|
|
290
|
+
getApiEnableUrl,
|
|
291
|
+
telegramApi,
|
|
292
|
+
doSyncPromptFiles,
|
|
293
|
+
getRequests,
|
|
294
|
+
getRequestById,
|
|
295
|
+
getHookSummaries,
|
|
296
|
+
deleteRequestsByHook,
|
|
379
297
|
watchdog,
|
|
380
298
|
getRecentEvents,
|
|
381
299
|
readLogTail,
|
|
382
|
-
|
|
383
|
-
registerUsageRoutes({
|
|
384
|
-
app,
|
|
385
|
-
requireAuth,
|
|
300
|
+
watchdogTerminal,
|
|
386
301
|
getDailySummary,
|
|
387
302
|
getSessionsList,
|
|
388
303
|
getSessionDetail,
|
|
389
304
|
getSessionTimeSeries,
|
|
390
|
-
});
|
|
391
|
-
registerCronRoutes({
|
|
392
|
-
app,
|
|
393
|
-
requireAuth,
|
|
394
305
|
cronService,
|
|
395
|
-
});
|
|
396
|
-
registerDoctorRoutes({
|
|
397
|
-
app,
|
|
398
|
-
requireAuth,
|
|
399
306
|
doctorService,
|
|
400
|
-
});
|
|
401
|
-
registerAgentRoutes({
|
|
402
|
-
app,
|
|
403
307
|
agentsService,
|
|
404
|
-
restartRequiredState,
|
|
405
308
|
operationEvents,
|
|
406
|
-
});
|
|
407
|
-
registerProxyRoutes({
|
|
408
|
-
app,
|
|
409
309
|
proxy,
|
|
410
310
|
getGatewayUrl,
|
|
411
311
|
SETUP_API_PREFIXES,
|
|
412
|
-
requireAuth,
|
|
413
312
|
webhookMiddleware,
|
|
414
313
|
});
|
|
415
314
|
|
|
416
315
|
const server = http.createServer(app);
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const upgradeReq = {
|
|
424
|
-
headers: req.headers,
|
|
425
|
-
path: requestUrl.pathname,
|
|
426
|
-
query: Object.fromEntries(requestUrl.searchParams.entries()),
|
|
427
|
-
};
|
|
428
|
-
if (!isAuthorizedRequest(upgradeReq)) {
|
|
429
|
-
socket.write(
|
|
430
|
-
"HTTP/1.1 401 Unauthorized\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\nUnauthorized",
|
|
431
|
-
);
|
|
432
|
-
socket.destroy();
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
proxy.ws(req, socket, head, { target: getGatewayUrl() });
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
server.listen(PORT, "0.0.0.0", () => {
|
|
440
|
-
console.log(`[alphaclaw] Express listening on :${PORT}`);
|
|
441
|
-
if (isOnboarded()) {
|
|
442
|
-
runOnboardedBootSequence({
|
|
443
|
-
doSyncPromptFiles,
|
|
444
|
-
reloadEnv,
|
|
445
|
-
syncChannelConfig,
|
|
446
|
-
readEnvFile,
|
|
447
|
-
ensureGatewayProxyConfig,
|
|
448
|
-
resolveSetupUrl,
|
|
449
|
-
startGateway,
|
|
450
|
-
watchdog,
|
|
451
|
-
gmailWatchService,
|
|
452
|
-
});
|
|
453
|
-
} else {
|
|
454
|
-
console.log("[alphaclaw] Awaiting onboarding via Setup UI");
|
|
455
|
-
}
|
|
316
|
+
createWatchdogTerminalWsBridge({
|
|
317
|
+
server,
|
|
318
|
+
proxy,
|
|
319
|
+
getGatewayUrl,
|
|
320
|
+
isAuthorizedRequest,
|
|
321
|
+
watchdogTerminal,
|
|
456
322
|
});
|
|
457
323
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
324
|
+
startServerLifecycle({
|
|
325
|
+
server,
|
|
326
|
+
PORT,
|
|
327
|
+
isOnboarded,
|
|
328
|
+
runOnboardedBootSequence,
|
|
329
|
+
doSyncPromptFiles,
|
|
330
|
+
reloadEnv,
|
|
331
|
+
syncChannelConfig,
|
|
332
|
+
readEnvFile,
|
|
333
|
+
ensureGatewayProxyConfig,
|
|
334
|
+
resolveSetupUrl,
|
|
335
|
+
startGateway,
|
|
336
|
+
watchdog,
|
|
337
|
+
gmailWatchService,
|
|
465
338
|
});
|
|
466
|
-
|
|
467
|
-
|
|
339
|
+
registerServerShutdown({
|
|
340
|
+
gmailWatchService,
|
|
341
|
+
watchdogTerminal,
|
|
468
342
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrysb/alphaclaw",
|
|
3
|
-
"version": "0.7.0",
|
|
3
|
+
"version": "0.7.2-beta.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"express": "^4.21.0",
|
|
33
33
|
"http-proxy": "^1.18.1",
|
|
34
|
-
"openclaw": "2026.3.11"
|
|
34
|
+
"openclaw": "2026.3.11",
|
|
35
|
+
"ws": "^8.19.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@vitest/coverage-v8": "^4.0.18",
|