@teamclaws/teamclaw 2026.11.2 → 2026.11.3
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/dist/src/controller/http-server.js +18 -0
- package/dist/src/controller/journal.js +68 -0
- package/dist/src/controller/provisioning/process-supervisor.js +58 -2
- package/dist/src/controller/provisioning-config.js +53 -0
- package/dist/src/controller/route-table.js +5 -0
- package/dist/src/controller/security.js +39 -0
- package/dist/src/controller/teamauto-routes.js +12 -0
- package/dist/src/controller/tunnel-manager.js +33 -1
- package/dist/src/controller/tunnel-routes.js +17 -1
- package/dist/src/controller/websocket.js +4 -0
- package/dist/src/controller/worker-provisioning.js +36 -0
- package/dist/src/state.js +77 -1
- package/dist/src/teamauto/github-client.js +33 -0
- package/dist/src/teamauto/scanner.js +9 -1
- package/dist/src/teamauto/scheduler.js +292 -17
- package/dist/src/teamauto/store.js +9 -0
- package/dist/src/ui/app.js +44 -0
- package/dist/src/ui/index.html +15 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/controller/http-server.ts +18 -0
- package/src/controller/journal.ts +89 -0
- package/src/controller/provisioning/process-supervisor.ts +56 -2
- package/src/controller/provisioning-config.ts +54 -0
- package/src/controller/route-table.ts +5 -0
- package/src/controller/security.ts +40 -0
- package/src/controller/teamauto-routes.ts +12 -0
- package/src/controller/tunnel-manager.ts +34 -1
- package/src/controller/tunnel-routes.ts +18 -1
- package/src/controller/websocket.ts +5 -0
- package/src/controller/worker-provisioning.ts +34 -0
- package/src/state.ts +73 -2
- package/src/teamauto/github-client.ts +36 -0
- package/src/teamauto/scanner.ts +9 -1
- package/src/teamauto/scheduler.ts +295 -17
- package/src/teamauto/store.ts +31 -1
- package/src/ui/app.js +44 -0
- package/src/ui/index.html +15 -0
|
@@ -16,6 +16,15 @@ export function pushTeamAutoActivity(store, entry) {
|
|
|
16
16
|
store.activity = store.activity.slice(store.activity.length - TEAMAUTO_ACTIVITY_LIMIT);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
/** #267-2: bounded per-repo sweep ring (newest last, cap 20) - same slice
|
|
20
|
+
* pattern as pushTeamAutoActivity. */
|
|
21
|
+
export function pushSweepRecord(repo, entry) {
|
|
22
|
+
repo.sweeps = repo.sweeps ?? [];
|
|
23
|
+
repo.sweeps.push(entry);
|
|
24
|
+
if (repo.sweeps.length > 20) {
|
|
25
|
+
repo.sweeps = repo.sweeps.slice(repo.sweeps.length - 20);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
19
28
|
export function defaultPolicy() {
|
|
20
29
|
return {
|
|
21
30
|
maxTasksPerSweep: 5,
|
package/dist/src/ui/app.js
CHANGED
|
@@ -78,6 +78,11 @@
|
|
|
78
78
|
"tab.workspace": "Workspace",
|
|
79
79
|
"common.showOlder": "Show older ({n})",
|
|
80
80
|
"tab.settings": "Settings",
|
|
81
|
+
"tab.activity": "Activity",
|
|
82
|
+
"activity.events.title": "Controller activity",
|
|
83
|
+
"activity.events.hint": "Live provisioning, sweeps, task routing and team events (ring buffer, last 400).",
|
|
84
|
+
"activity.log.title": "TeamClaw log tail",
|
|
85
|
+
"activity.log.all": "unfiltered",
|
|
81
86
|
"settings.models.title": "Model settings",
|
|
82
87
|
"settings.models.hint": "Default model and per-role overrides.",
|
|
83
88
|
"settings.workers.title": "Worker scaling (hot)",
|
|
@@ -373,6 +378,11 @@
|
|
|
373
378
|
"tab.workspace": "工作区",
|
|
374
379
|
"common.showOlder": "显示更早({n})",
|
|
375
380
|
"tab.settings": "设置",
|
|
381
|
+
"tab.activity": "活动",
|
|
382
|
+
"activity.events.title": "控制器活动",
|
|
383
|
+
"activity.events.hint": "实时的 worker 供给、sweep、任务分派与团队事件(环形缓冲,最近 400 条)。",
|
|
384
|
+
"activity.log.title": "TeamClaw 日志尾随",
|
|
385
|
+
"activity.log.all": "不过滤",
|
|
376
386
|
"settings.models.title": "模型设置",
|
|
377
387
|
"settings.models.hint": "默认模型与按角色覆盖。",
|
|
378
388
|
"settings.workers.title": "Worker 弹性伸缩(热)",
|
|
@@ -4131,6 +4141,9 @@
|
|
|
4131
4141
|
if (activeTab === "settings") {
|
|
4132
4142
|
renderWorkerSettingsPanel();
|
|
4133
4143
|
}
|
|
4144
|
+
if (activeTab === "activity") {
|
|
4145
|
+
renderActivityTab();
|
|
4146
|
+
}
|
|
4134
4147
|
if (activeTab === "teamauto") {
|
|
4135
4148
|
refreshTeamAutoTab();
|
|
4136
4149
|
}
|
|
@@ -5306,6 +5319,37 @@ function renderWorkerSettingsPanel() {
|
|
|
5306
5319
|
});
|
|
5307
5320
|
}
|
|
5308
5321
|
|
|
5322
|
+
// Controller Activity tab (#ui-blindness): journal event stream + gateway
|
|
5323
|
+
// log tail. Polls only while the tab is active (no background traffic).
|
|
5324
|
+
var activityTimer = null;
|
|
5325
|
+
function renderActivityTab() {
|
|
5326
|
+
var journalEl = document.getElementById("activity-journal");
|
|
5327
|
+
if (!journalEl) return;
|
|
5328
|
+
function fmtTime(at) {
|
|
5329
|
+
var d = new Date(at);
|
|
5330
|
+
return ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2) + ":" + ("0" + d.getSeconds()).slice(-2);
|
|
5331
|
+
}
|
|
5332
|
+
function load() {
|
|
5333
|
+
apiRequest("/controller/journal?limit=200").then(function (d) {
|
|
5334
|
+
var ev = d.events || [];
|
|
5335
|
+
journalEl.innerHTML = ev.length
|
|
5336
|
+
? ev.map(function (e) { return escapeHtml(fmtTime(e.at) + " [" + e.type + "] " + e.summary); }).join("\n")
|
|
5337
|
+
: "(no events yet)";
|
|
5338
|
+
}).catch(function (err) { journalEl.textContent = (err && err.message) || "load failed"; });
|
|
5339
|
+
var all = document.getElementById("activity-log-all");
|
|
5340
|
+
apiRequest("/controller/log-tail?lines=200" + (all && all.checked ? "&all=1" : "")).then(function (d) {
|
|
5341
|
+
var logEl = document.getElementById("activity-log");
|
|
5342
|
+
if (logEl) {
|
|
5343
|
+
logEl.textContent = ((d.path || "") + "\n" + (d.lines || []).join("\n")) || "(no log lines matched)";
|
|
5344
|
+
logEl.scrollTop = logEl.scrollHeight;
|
|
5345
|
+
}
|
|
5346
|
+
}).catch(function () { /* transient */ });
|
|
5347
|
+
}
|
|
5348
|
+
if (activityTimer) clearInterval(activityTimer);
|
|
5349
|
+
load();
|
|
5350
|
+
activityTimer = setInterval(load, 5000);
|
|
5351
|
+
}
|
|
5352
|
+
|
|
5309
5353
|
function openModelSettings() {
|
|
5310
5354
|
var modal = document.querySelector("#model-settings-modal");
|
|
5311
5355
|
if (!modal) return;
|
package/dist/src/ui/index.html
CHANGED
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
</button>
|
|
80
80
|
<button class="tab" data-tab="workspace"><span class="tab-label" data-i18n="tab.workspace">Workspace</span></button>
|
|
81
81
|
<button class="tab" data-tab="settings"><span class="tab-label" data-i18n="tab.settings">Settings</span></button>
|
|
82
|
+
<button class="tab" data-tab="activity"><span class="tab-label" data-i18n="tab.activity">Activity</span></button>
|
|
82
83
|
<button class="tab" data-tab="clarifications">
|
|
83
84
|
<span class="tab-label" data-i18n="tab.clarifications">Clarifications</span>
|
|
84
85
|
<span id="clarifications-tab-count" class="tab-badge">0</span>
|
|
@@ -151,6 +152,20 @@
|
|
|
151
152
|
</div>
|
|
152
153
|
|
|
153
154
|
<!-- Workspace Tab -->
|
|
155
|
+
<div id="tab-activity" class="tab-panel">
|
|
156
|
+
<div class="panel-note" style="padding:12px 14px">
|
|
157
|
+
<h3 data-i18n="activity.events.title" style="margin:0 0 6px">Controller activity</h3>
|
|
158
|
+
<p data-i18n="activity.events.hint" style="margin:0 0 8px;color:#666">Live provisioning, sweeps, task routing and team events (ring buffer, last 400).</p>
|
|
159
|
+
<div id="activity-journal" style="font:12px/1.6 ui-monospace,monospace;max-height:320px;overflow:auto;background:#f6f6f6;padding:8px;border-radius:6px;white-space:pre-wrap"></div>
|
|
160
|
+
</div>
|
|
161
|
+
<div class="panel-note" style="padding:12px 14px;margin-top:10px">
|
|
162
|
+
<h3 data-i18n="activity.log.title" style="margin:0 0 6px">TeamClaw log tail</h3>
|
|
163
|
+
<p style="margin:0 0 8px">
|
|
164
|
+
<label style="font-size:12px;color:#666"><input id="activity-log-all" type="checkbox" /> <span data-i18n="activity.log.all">unfiltered</span></label>
|
|
165
|
+
</p>
|
|
166
|
+
<div id="activity-log" style="font:12px/1.6 ui-monospace,monospace;max-height:420px;overflow:auto;background:#111;color:#9f9;padding:10px;border-radius:6px;white-space:pre-wrap"></div>
|
|
167
|
+
</div>
|
|
168
|
+
</div>
|
|
154
169
|
<div id="tab-settings" class="tab-panel">
|
|
155
170
|
<div class="panel-note" style="padding:12px 14px">
|
|
156
171
|
<h3 data-i18n="settings.models.title" style="margin:0 0 6px">Model settings</h3>
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "teamclaw",
|
|
3
3
|
"name": "TeamClaw",
|
|
4
4
|
"description": "Virtual team collaboration - multiple OpenClaw instances form a virtual software company with role-based task routing.",
|
|
5
|
-
"version": "2026.11.
|
|
5
|
+
"version": "2026.11.3",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true
|
|
8
8
|
},
|
package/package.json
CHANGED
|
@@ -286,6 +286,7 @@ export function createControllerHttpServer(deps: ControllerHttpDeps): http.Serve
|
|
|
286
286
|
verifyUpgrade: createWebSocketUpgradeGuard({
|
|
287
287
|
...deps,
|
|
288
288
|
isTunnelHost: (host) => tunnelManagerSingleton?.isTunnelRequest(host) ?? false,
|
|
289
|
+
gateAllows: (req) => tunnelManagerSingleton?.gateAllows(req) ?? false,
|
|
289
290
|
}),
|
|
290
291
|
});
|
|
291
292
|
|
|
@@ -304,6 +305,23 @@ export function createControllerHttpServer(deps: ControllerHttpDeps): http.Serve
|
|
|
304
305
|
logger.warn(`TeamClaw tunnel: boot recovery failed: ${String(err)}`);
|
|
305
306
|
});
|
|
306
307
|
|
|
308
|
+
// Shutdown counterpart of the boot recover above: when the gateway process
|
|
309
|
+
// stops (SIGTERM/SIGINT - e.g. a config change restarting the plugin, or
|
|
310
|
+
// launchctl kickstart), detach() kills ONLY the local connector and keeps
|
|
311
|
+
// both tunnel-state.json and the remote relay tunnel alive, so the next
|
|
312
|
+
// boot's recover() reconnects the SAME tunnel. Without this, the
|
|
313
|
+
// connector's exit handler ran mid-shutdown, cleared the state file and
|
|
314
|
+
// DELETEd the relay tunnel - after which nothing could recover and the
|
|
315
|
+
// hostname served 530 (issue timeline: 2026-11-12, two consecutive
|
|
316
|
+
// restarts). Idempotent and safe to register repeatedly per http server.
|
|
317
|
+
for (const signal of ["SIGTERM", "SIGINT"] as const) {
|
|
318
|
+
process.on(signal, () => {
|
|
319
|
+
try {
|
|
320
|
+
tunnelManagerSingleton?.detach();
|
|
321
|
+
} catch { /* best effort during shutdown */ }
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
307
325
|
setTimeout(() => {
|
|
308
326
|
const state = deps.getTeamState();
|
|
309
327
|
const pendingCount = state
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Controller activity journal (#ui-blindness): an in-memory ring of recent
|
|
2
|
+
// controller-side events, plus a tail reader for the teamclaw-relevant slice
|
|
3
|
+
// of the host gateway log. The web UI's Activity tab polls the journal and
|
|
4
|
+
// follows the log tail so operators can SEE provisioning, sweeps, task
|
|
5
|
+
// routing and tunnel lifecycle without ssh-ing into logs.
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import type { ServerResponse } from "node:http";
|
|
10
|
+
import { sendJson } from "../protocol.js";
|
|
11
|
+
|
|
12
|
+
// Structural event shape (deliberately NOT importing the WsEvent type from
|
|
13
|
+
// websocket.js: journal <- websocket is fine, but websocket -> journal for
|
|
14
|
+
// the broadcast hook would make the pair a cycle under the arch gate. Keep
|
|
15
|
+
// this module leaf-level.)
|
|
16
|
+
type BroadcastLike = { type?: unknown; data?: unknown };
|
|
17
|
+
|
|
18
|
+
export type JournalEntry = {
|
|
19
|
+
at: number;
|
|
20
|
+
source: "ws" | "provisioner";
|
|
21
|
+
type: string;
|
|
22
|
+
summary: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const RING_LIMIT = 400;
|
|
26
|
+
const ring: JournalEntry[] = [];
|
|
27
|
+
|
|
28
|
+
/** Record a controller event into the ring (callers also broadcast it). */
|
|
29
|
+
export function journalRecord(source: JournalEntry["source"], type: string, summary: string): void {
|
|
30
|
+
ring.push({ at: Date.now(), source, type, summary: summary.slice(0, 240) });
|
|
31
|
+
if (ring.length > RING_LIMIT) ring.splice(0, ring.length - RING_LIMIT);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Summarize a broadcast WS event into the journal (best effort, never throws). */
|
|
35
|
+
export function journalFromWsEvent(event: BroadcastLike): void {
|
|
36
|
+
try {
|
|
37
|
+
const t = String(event.type ?? "unknown");
|
|
38
|
+
if (t === "task:created" || t === "task:completed" || t === "task:updated" || t === "worker:online" || t === "worker:offline" || t === "team:config_updated" || t === "controller:run") {
|
|
39
|
+
journalRecord("ws", t, JSON.stringify(event.data ?? {}).slice(0, 200));
|
|
40
|
+
}
|
|
41
|
+
} catch { /* journal must never break broadcasting */ }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function journalSnapshot(limit = 200): JournalEntry[] {
|
|
45
|
+
return ring.slice(-Math.min(limit, RING_LIMIT));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Host gateway log tail (read-only). The teamclaw plugin logs land in the
|
|
50
|
+
// openclaw gateway log; filter to the teamclaw-relevant lines.
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
const TEAMCLAW_LOG_FILTER = /TeamClaw|TeamAuto|Provisioner|ProvisionedWorker|TaskRouter|tunnel|Controller:/i;
|
|
54
|
+
|
|
55
|
+
function gatewayLogCandidates(): string[] {
|
|
56
|
+
const home = process.env.OPENCLAW_HOME || path.join(os.homedir(), ".openclaw");
|
|
57
|
+
return [
|
|
58
|
+
process.env.TEAMCLAW_GATEWAY_LOG,
|
|
59
|
+
path.join(home, "logs", "gateway.log"),
|
|
60
|
+
path.join(process.env.HOME ?? "", "Library", "Logs", "openclaw", "gateway.log"),
|
|
61
|
+
].filter((p): p is string => Boolean(p));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function readGatewayLogTail(lines = 200, filter = true): { path: string | null; lines: string[] } {
|
|
65
|
+
for (const candidate of gatewayLogCandidates()) {
|
|
66
|
+
try {
|
|
67
|
+
const raw = fs.readFileSync(candidate, "utf8");
|
|
68
|
+
const all = raw.split("\n").filter((l) => l.trim().length > 0);
|
|
69
|
+
const picked = filter ? all.filter((l) => TEAMCLAW_LOG_FILTER.test(l)) : all;
|
|
70
|
+
return { path: candidate, lines: picked.slice(-lines) };
|
|
71
|
+
} catch {
|
|
72
|
+
// try next candidate
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { path: null, lines: [] };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Route handlers (bound in route-table.ts, appended at the table tail on the
|
|
79
|
+
// append-only precedent; both read-only GETs).
|
|
80
|
+
export function controllerJournalRoute({ res, requestUrl }: { res: ServerResponse; requestUrl: URL }): void {
|
|
81
|
+
const limit = Math.min(Math.max(parseInt(requestUrl.searchParams.get("limit") ?? "200", 10) || 200, 1), 400);
|
|
82
|
+
sendJson(res, 200, { events: journalSnapshot(limit) });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function controllerLogTailRoute({ res, requestUrl }: { res: ServerResponse; requestUrl: URL }): void {
|
|
86
|
+
const lines = Math.min(Math.max(parseInt(requestUrl.searchParams.get("lines") ?? "200", 10) || 200, 1), 1000);
|
|
87
|
+
const unfiltered = requestUrl.searchParams.get("all") === "1";
|
|
88
|
+
sendJson(res, 200, readGatewayLogTail(lines, !unfiltered));
|
|
89
|
+
}
|
|
@@ -9,6 +9,7 @@ import path from "node:path";
|
|
|
9
9
|
import readline from "node:readline";
|
|
10
10
|
import { spawn, type ChildProcess } from "node:child_process";
|
|
11
11
|
import type { PluginLogger } from "../../../api.js";
|
|
12
|
+
import { resolveControllerTeamclawEntryPath } from "../provisioning-config.js";
|
|
12
13
|
import {
|
|
13
14
|
resolveDefaultOpenClawConfigPath,
|
|
14
15
|
resolveDefaultTeamClawRuntimeRootDir,
|
|
@@ -28,7 +29,7 @@ export class ProcessProvisioner implements WorkerProvisionerBackend {
|
|
|
28
29
|
readonly type = "process" as const;
|
|
29
30
|
private readonly logger: PluginLogger;
|
|
30
31
|
private readonly processByWorkerId = new Map<string, ChildProcess>();
|
|
31
|
-
private
|
|
32
|
+
private baseDirPromise: Promise<string>; // mutable: ensureBaseDir self-heal swaps it
|
|
32
33
|
|
|
33
34
|
constructor(logger: PluginLogger) {
|
|
34
35
|
this.logger = logger;
|
|
@@ -37,8 +38,32 @@ export class ProcessProvisioner implements WorkerProvisionerBackend {
|
|
|
37
38
|
.then(() => fs.mkdtemp(path.join(provisionedRoot, "session-")));
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
/**
|
|
42
|
+
* #watchdog (observer-found 2026-11-13, workers starved 2.3h+): the
|
|
43
|
+
* session baseDir is created ONCE in the constructor and cached - if an
|
|
44
|
+
* external cleanup removes it (gateway restarts / culling sweeps), every
|
|
45
|
+
* later launch's mkdtemp hits ENOENT (mkdtemp never creates parents),
|
|
46
|
+
* the provisioner cools down, and pending tasks starve until process
|
|
47
|
+
* restart. Self-heal: verify the cached dir still exists on every
|
|
48
|
+
* launch; on ENOENT, rebuild it and swap the cached promise.
|
|
49
|
+
*/
|
|
50
|
+
private async ensureBaseDir(): Promise<string> {
|
|
51
|
+
const dir = await this.baseDirPromise;
|
|
52
|
+
try {
|
|
53
|
+
await fs.stat(dir);
|
|
54
|
+
return dir;
|
|
55
|
+
} catch {
|
|
56
|
+
const provisionedRoot = path.join(resolveDefaultTeamClawRuntimeRootDir(), "provisioned-workers");
|
|
57
|
+
const fresh = fs.mkdir(provisionedRoot, { recursive: true })
|
|
58
|
+
.then(() => fs.mkdtemp(path.join(provisionedRoot, "session-")));
|
|
59
|
+
this.baseDirPromise = fresh;
|
|
60
|
+
this.logger.warn?.(`TeamClaw: provisioner session dir vanished (${dir}) - rebuilt`);
|
|
61
|
+
return fresh;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
40
65
|
async launch(spec: LaunchSpec): Promise<LaunchResult> {
|
|
41
|
-
const baseDir = await this.
|
|
66
|
+
const baseDir = await this.ensureBaseDir();
|
|
42
67
|
const runtimeHomeDir = await fs.mkdtemp(path.join(baseDir, `${sanitizePathSegment(spec.role)}-`));
|
|
43
68
|
const stateDir = path.join(runtimeHomeDir, ".openclaw");
|
|
44
69
|
const configPath = path.join(stateDir, "openclaw.json");
|
|
@@ -61,6 +86,35 @@ export class ProcessProvisioner implements WorkerProvisionerBackend {
|
|
|
61
86
|
});
|
|
62
87
|
await fs.writeFile(configPath, spec.configJson, { encoding: "utf8", mode: 0o600 });
|
|
63
88
|
|
|
89
|
+
// #task-stuck (13th layer, physical half): the worker sandbox has no
|
|
90
|
+
// teamclaw installation of its own, and entries.enabled does not resolve
|
|
91
|
+
// the plugin. Symlink the controller's teamclaw package into the
|
|
92
|
+
// sandbox's extensions/ dir - the host auto-discovers extensions/ - and
|
|
93
|
+
// mirror it into the config's plugins.load.paths so discovery sees the
|
|
94
|
+
// same physical path. Idempotent; failures are non-fatal (worker still
|
|
95
|
+
// boots, just without the plugin).
|
|
96
|
+
try {
|
|
97
|
+
const controllerEntry = resolveControllerTeamclawEntryPath();
|
|
98
|
+
if (controllerEntry) {
|
|
99
|
+
const pkgDir = path.dirname(path.dirname(controllerEntry)); // dist/index.js -> package root
|
|
100
|
+
const extDir = path.join(stateDir, "extensions");
|
|
101
|
+
await fs.mkdir(extDir, { recursive: true });
|
|
102
|
+
const linkPath = path.join(extDir, "teamclaw");
|
|
103
|
+
await fs.rm(linkPath, { force: true }).catch(() => undefined);
|
|
104
|
+
await fs.symlink(pkgDir, linkPath, "dir");
|
|
105
|
+
// Mirror into the written config (configJson was already serialized).
|
|
106
|
+
try {
|
|
107
|
+
const cfg = JSON.parse(await fs.readFile(configPath, "utf8"));
|
|
108
|
+
const plugins = (cfg.plugins ??= {});
|
|
109
|
+
const load = (plugins.load ??= { paths: [] });
|
|
110
|
+
if (Array.isArray(load.paths) && !load.paths.includes(linkPath)) load.paths.push(linkPath);
|
|
111
|
+
await fs.writeFile(configPath, JSON.stringify(cfg, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
|
|
112
|
+
} catch { /* config mirror best-effort */ }
|
|
113
|
+
}
|
|
114
|
+
} catch (e) {
|
|
115
|
+
this.logger.warn?.(`TeamClaw: could not link teamclaw into worker extensions: ${e instanceof Error ? e.message : String(e)}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
64
118
|
const gatewayEntrypoint = resolveGatewayEntrypoint();
|
|
65
119
|
const child = spawn(process.execPath, [
|
|
66
120
|
gatewayEntrypoint,
|
|
@@ -17,6 +17,41 @@ import {
|
|
|
17
17
|
TEAMCLAW_AGENT_ID,
|
|
18
18
|
} from "../openclaw-workspace.js";
|
|
19
19
|
import { cloneJson, pathExists, sanitizePathSegment } from "../shared/utils.js";
|
|
20
|
+
import os from "node:os";
|
|
21
|
+
import fsSync from "node:fs";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* #task-stuck (13th layer): resolve the teamclaw entry the CONTROLLER is
|
|
25
|
+
* actually loading, so process workers can plugins.load the same physical
|
|
26
|
+
* path. Discovery order: openclaw npm projects generation dirs (newest
|
|
27
|
+
* mtime wins - that is what the host loaded), then the global node_modules
|
|
28
|
+
* install. Returns undefined when nothing resolvable exists.
|
|
29
|
+
*/
|
|
30
|
+
export function resolveControllerTeamclawEntryPath(): string | undefined {
|
|
31
|
+
const candidates: string[] = [];
|
|
32
|
+
const home = process.env.OPENCLAW_HOME?.trim() || process.env.HOME?.trim() || os.homedir();
|
|
33
|
+
const projectsDir = path.join(home, ".openclaw", "npm", "projects");
|
|
34
|
+
try {
|
|
35
|
+
for (const proj of fsSync.readdirSync(projectsDir)) {
|
|
36
|
+
if (!proj.startsWith("teamclaws-teamclaw")) continue;
|
|
37
|
+
candidates.push(
|
|
38
|
+
path.join(projectsDir, proj, "node_modules", "@teamclaws", "teamclaw"),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
} catch { /* no projects dir */ }
|
|
42
|
+
candidates.push(
|
|
43
|
+
"/opt/homebrew/lib/node_modules/@teamclaws/teamclaw/dist/index.js",
|
|
44
|
+
"/usr/local/lib/node_modules/@teamclaws/teamclaw/dist/index.js",
|
|
45
|
+
);
|
|
46
|
+
let best: { p: string; m: number } | undefined;
|
|
47
|
+
for (const p of candidates) {
|
|
48
|
+
try {
|
|
49
|
+
const m = fsSync.statSync(p).mtimeMs;
|
|
50
|
+
if (!best || m > best.m) best = { p, m };
|
|
51
|
+
} catch { /* candidate absent */ }
|
|
52
|
+
}
|
|
53
|
+
return best?.p;
|
|
54
|
+
}
|
|
20
55
|
|
|
21
56
|
export function buildProvisionedWorkerConfig(
|
|
22
57
|
baseConfig: Record<string, unknown>,
|
|
@@ -108,6 +143,25 @@ export function buildProvisionedWorkerConfig(
|
|
|
108
143
|
if (controllerConfig.workerProvisioningType === "docker" || controllerConfig.workerProvisioningType === "kubernetes") {
|
|
109
144
|
delete plugins.load;
|
|
110
145
|
}
|
|
146
|
+
// #task-stuck (2026-11-13, 13th layer): a PROCESS worker sandbox has NO
|
|
147
|
+
// local teamclaw installation (no extensions dir, no npm registration),
|
|
148
|
+
// and entries.enabled alone does not make the host resolve the plugin -
|
|
149
|
+
// the worker gateway booted as bare openclaw (plugins: anthropic,
|
|
150
|
+
// memory-core) and never registered with the controller, so pending
|
|
151
|
+
// tasks sat unclaimed forever. Point plugins.load at the CONTROLLER's
|
|
152
|
+
// teamclaw entry (the npm project dir the controller itself loads from).
|
|
153
|
+
if (controllerConfig.workerProvisioningType === "process" || !controllerConfig.workerProvisioningType) {
|
|
154
|
+
const controllerEntryPath = resolveControllerTeamclawEntryPath();
|
|
155
|
+
if (controllerEntryPath) {
|
|
156
|
+
// Host schema: plugins.load = { paths: string[] } (object, not array).
|
|
157
|
+
const loadObj = ensureRecord(plugins).load;
|
|
158
|
+
const existing = ensureRecord(loadObj && typeof loadObj === "object" ? loadObj : {});
|
|
159
|
+
const paths = Array.isArray(existing.paths) ? existing.paths.filter((p) => typeof p === "string") : [];
|
|
160
|
+
if (!paths.includes(controllerEntryPath)) paths.push(controllerEntryPath);
|
|
161
|
+
existing.paths = paths;
|
|
162
|
+
plugins.load = existing;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
111
165
|
const entries = ensureRecord(plugins.entries);
|
|
112
166
|
const teamclawEntry = ensureRecord(entries.teamclaw);
|
|
113
167
|
teamclawEntry.enabled = true;
|
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
archivedTeamsRoute,
|
|
54
54
|
} from "./status-routes.js";
|
|
55
55
|
import { teamConfigGetRoute, teamConfigPatchRoute } from "./config-routes.js";
|
|
56
|
+
import * as journalRoutes from "./journal.js";
|
|
56
57
|
import {
|
|
57
58
|
reportsListRoute,
|
|
58
59
|
reportsSessionRoute,
|
|
@@ -600,4 +601,8 @@ export const controllerRouteTable: readonly RouteDef[] = [
|
|
|
600
601
|
// (no path overlap with any earlier route).
|
|
601
602
|
{ method: "GET", path: "/api/v1/team/config", handler: teamConfigGetRoute },
|
|
602
603
|
{ method: "PATCH", path: "/api/v1/team/config", handler: teamConfigPatchRoute },
|
|
604
|
+
// Controller observability (#ui-blindness): event journal + gateway log
|
|
605
|
+
// tail for the web UI's Activity tab. Appended on the same precedent.
|
|
606
|
+
{ method: "GET", path: "/api/v1/controller/journal", handler: journalRoutes.controllerJournalRoute },
|
|
607
|
+
{ method: "GET", path: "/api/v1/controller/log-tail", handler: journalRoutes.controllerLogTailRoute },
|
|
603
608
|
];
|
|
@@ -469,6 +469,30 @@ export function createSecurityMiddleware(deps: SecurityMiddlewareDeps): Security
|
|
|
469
469
|
return true;
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
+
// Loopback is the controller host itself: the desktop app, the web UI,
|
|
473
|
+
// provisioned workers registering/heart-beating, and the owner's own
|
|
474
|
+
// CLI/curl. Requiring device pairing from the SAME MACHINE broke all of
|
|
475
|
+
// them the moment protection turned on (provisioned workers 401'd their
|
|
476
|
+
// registration and the worker pool starved; the local desktop could not
|
|
477
|
+
// talk to its own gateway - reported as a UX defect 2026-11-12). Local
|
|
478
|
+
// peers stay first-party: tunnel traffic never earns loopback trust
|
|
479
|
+
// (classifySecurityPeer strips it via viaTunnel) and LAN peers still
|
|
480
|
+
// need a device token. When a loopback caller DOES present a valid
|
|
481
|
+
// device token, authenticate anyway so lastSeenAt keeps updating (the
|
|
482
|
+
// token may belong to a paired remote console the owner is driving).
|
|
483
|
+
// VIA-TUNNEL requests are ALSO exempt: cloudflared dials in from
|
|
484
|
+
// loopback (the tunnel IS a local connection), and their credential is
|
|
485
|
+
// the tunnel GATE TOKEN - http-server checks gateAllows for every
|
|
486
|
+
// tunnel request AFTER this gate. Pairing them is a category error: a
|
|
487
|
+
// visitor can never obtain a pairing code, so protection-on would just
|
|
488
|
+
// kill the tunnel with an unanswerable 401 (user design ruling
|
|
489
|
+
// 2026-11-12). LAN peers remain the pairing boundary.
|
|
490
|
+
if (peer.loopback || peer.viaTunnel) {
|
|
491
|
+
const authAny = authenticateDeviceToken(state, extractDeviceToken(req));
|
|
492
|
+
if (authAny) touchDeviceLastSeen(deps, authAny.device.id);
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
|
|
472
496
|
const auth = authenticateDeviceToken(state, extractDeviceToken(req));
|
|
473
497
|
if (!auth) {
|
|
474
498
|
deps.logger.warn(`Controller: rejected unauthenticated ${req.method ?? "?"} ${pathname} from ${peer.ip}${peer.viaTunnel ? " (via tunnel)" : ""}`);
|
|
@@ -492,6 +516,7 @@ export function createSecurityMiddleware(deps: SecurityMiddlewareDeps): Security
|
|
|
492
516
|
*/
|
|
493
517
|
export type WebSocketUpgradeGuardDeps = SecurityMiddlewareDeps & {
|
|
494
518
|
isTunnelHost: (host: string | undefined) => boolean;
|
|
519
|
+
gateAllows?: (req: { headers: Record<string, unknown> }) => boolean;
|
|
495
520
|
};
|
|
496
521
|
|
|
497
522
|
export function createWebSocketUpgradeGuard(deps: WebSocketUpgradeGuardDeps): (req: IncomingMessage) => boolean {
|
|
@@ -503,6 +528,21 @@ export function createWebSocketUpgradeGuard(deps: WebSocketUpgradeGuardDeps): (r
|
|
|
503
528
|
recordNonLanPeerSignal(deps, state, peer, "/ws");
|
|
504
529
|
return true;
|
|
505
530
|
}
|
|
531
|
+
// 8b03ed6 layering (user design ruling): loopback peers are first-party
|
|
532
|
+
// (the host itself - web UI, desktop, provisioned workers) and NEVER
|
|
533
|
+
// need a pairing token. The HTTP gate got this exemption; this WS guard
|
|
534
|
+
// missed it and rejected every loopback UI connection (92362 rejects,
|
|
535
|
+
// user-found: tasks UI stuck on pending because /ws never upgraded).
|
|
536
|
+
if (peer.loopback) {
|
|
537
|
+
return true;
|
|
538
|
+
}
|
|
539
|
+
// Tunnel-origin upgrades (cloudflared loopback + tunnel Host): the
|
|
540
|
+
// visitor holds the GATE token, not a pairing token - same layering
|
|
541
|
+
// as the HTTP gate (a device token here would be an unanswerable
|
|
542
|
+
// wall, 8b03ed6). Verify the gate cookie instead.
|
|
543
|
+
if (peer.viaTunnel && deps.gateAllows && deps.gateAllows(req)) {
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
506
546
|
let token = extractDeviceToken(req);
|
|
507
547
|
if (!token) {
|
|
508
548
|
const url = new URL(req.url ?? "/ws", `http://${req.headers.host ?? "localhost"}`);
|
|
@@ -102,6 +102,18 @@ export async function handleTeamAutoRepoItemRequest(
|
|
|
102
102
|
let body: Record<string, unknown> = {};
|
|
103
103
|
try { body = await parseJsonBody(req); } catch { /* empty */ }
|
|
104
104
|
try {
|
|
105
|
+
// #269 (user report): the enabled flag used to be silently dropped
|
|
106
|
+
// here - the web UI's disable toggle returned 200 but never reached
|
|
107
|
+
// setRepoEnabled, so sweeps kept running. Wire it explicitly; the
|
|
108
|
+
// enable/disable path has different persistence semantics (pausedReason
|
|
109
|
+
// + timer reschedule) than the plain field patch below.
|
|
110
|
+
if (typeof body.enabled === "boolean" && Object.keys(body).every((k) => k === "enabled")) {
|
|
111
|
+
await teamAuto.setRepoEnabled(repoId, body.enabled);
|
|
112
|
+
const status = await teamAuto.getStatus();
|
|
113
|
+
const repo = (status?.repos ?? []).find((r: { id: string }) => r.id === repoId);
|
|
114
|
+
sendJson(res, 200, repo ?? { ok: true });
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
105
117
|
const updated = await teamAuto.updateRepo(repoId, {
|
|
106
118
|
schedule: typeof body.schedule === "string" ? body.schedule : undefined,
|
|
107
119
|
maxTasksPerSweep: typeof body.maxTasksPerSweep === "number" ? body.maxTasksPerSweep : undefined,
|
|
@@ -203,6 +203,9 @@ export function createTunnelManager(deps: { logger: PluginLogger; localPort: num
|
|
|
203
203
|
// an unexpected crash (which must clear the active state so /tunnel/status
|
|
204
204
|
// never reports a dead tunnel as live).
|
|
205
205
|
let userStopping = false;
|
|
206
|
+
// True while the gateway process itself is shutting down (detach()): the
|
|
207
|
+
// connector's death then is EXPECTED and must not tear down tunnel state.
|
|
208
|
+
let processShuttingDown = false;
|
|
206
209
|
let startOp: { running: boolean; phase: string; detail: string | null } = { running: false, phase: "idle", detail: null };
|
|
207
210
|
let installState: { running: boolean; phase: string; percent: number | null; detail: string | null } = { running: false, phase: "idle", percent: null, detail: null };
|
|
208
211
|
|
|
@@ -359,6 +362,14 @@ export function createTunnelManager(deps: { logger: PluginLogger; localPort: num
|
|
|
359
362
|
logger.warn(`TeamClaw tunnel: cloudflared exited (code ${code})`);
|
|
360
363
|
if (child !== proc) return;
|
|
361
364
|
child = null;
|
|
365
|
+
// During process shutdown (detach()) the connector dies WITH the
|
|
366
|
+
// gateway; that is expected, and tunnel-state.json must survive so the
|
|
367
|
+
// next boot's recover() can reconnect the SAME tunnel (gate cookies
|
|
368
|
+
// stay valid). Only a genuine mid-run crash clears state.
|
|
369
|
+
if (processShuttingDown) {
|
|
370
|
+
logger.info("TeamClaw tunnel: connector exited during process shutdown; state retained for recovery");
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
362
373
|
if (!userStopping && handle) {
|
|
363
374
|
handle = null;
|
|
364
375
|
lastError = `tunnel connector exited unexpectedly (code ${code ?? "null"})`;
|
|
@@ -386,6 +397,16 @@ export function createTunnelManager(deps: { logger: PluginLogger; localPort: num
|
|
|
386
397
|
// Unexpected exit (crash, network loss, cloudflared auto-kill): tear
|
|
387
398
|
// the logical state down too, otherwise status() keeps reporting
|
|
388
399
|
// active=true and the UI shows a dead tunnel as live forever.
|
|
400
|
+
// EXCEPTION - process shutdown: when the gateway itself is stopping,
|
|
401
|
+
// the connector dies by design (SIGTERM cascade). Clearing state (and
|
|
402
|
+
// worse, DELETE-ing the relay tunnel) at that moment destroyed the
|
|
403
|
+
// recovery chain: the next boot found no tunnel-state.json and never
|
|
404
|
+
// reconnected, leaving the CNAME live but 530. Keep both state and the
|
|
405
|
+
// relay tunnel; recover() owns them next boot.
|
|
406
|
+
if (processShuttingDown) {
|
|
407
|
+
logger.info("TeamClaw tunnel: connector exited during process shutdown; state retained for recovery");
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
389
410
|
if (!userStopping && handle) {
|
|
390
411
|
const gone = handle;
|
|
391
412
|
handle = null;
|
|
@@ -412,6 +433,18 @@ export function createTunnelManager(deps: { logger: PluginLogger; localPort: num
|
|
|
412
433
|
}
|
|
413
434
|
}
|
|
414
435
|
|
|
436
|
+
// Process-lifecycle teardown: kill ONLY the local connector. The remote
|
|
437
|
+
// tunnel (relay) and tunnel-state.json both survive, so the next gateway
|
|
438
|
+
// boot's recover() reconnects the SAME tunnel (id/gate token/cookies all
|
|
439
|
+
// preserved). This is the shutdown-path counterpart to recover(); stop()
|
|
440
|
+
// remains the user-facing "turn it off" (full teardown + relay DELETE).
|
|
441
|
+
function detach(): void {
|
|
442
|
+
processShuttingDown = true;
|
|
443
|
+
stopConnector();
|
|
444
|
+
logger.info(handle ? "TeamClaw tunnel: detached connector for process shutdown (state retained; recover on next boot)" : "TeamClaw tunnel: shutdown detach (no active connector)");
|
|
445
|
+
handle = null;
|
|
446
|
+
}
|
|
447
|
+
|
|
415
448
|
async function stop(): Promise<void> {
|
|
416
449
|
userStopping = true;
|
|
417
450
|
stopConnector();
|
|
@@ -584,7 +617,7 @@ export function createTunnelManager(deps: { logger: PluginLogger; localPort: num
|
|
|
584
617
|
}
|
|
585
618
|
|
|
586
619
|
|
|
587
|
-
return { start: launchStart, startSelfHosted, startQuick, stop, recover, status, installCloudflared, isTunnelRequest, gateAllows };
|
|
620
|
+
return { start: launchStart, startSelfHosted, startQuick, stop, detach, recover, status, installCloudflared, isTunnelRequest, gateAllows };
|
|
588
621
|
}
|
|
589
622
|
|
|
590
623
|
export type TunnelManager = ReturnType<typeof createTunnelManager>;
|
|
@@ -119,6 +119,19 @@ export function createTunnelGateRoutes(tunnelManager: TunnelManager): readonly R
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/** /api/v1/tunnel/* management API (direct requests only, never via tunnel). */
|
|
122
|
+
// Audit trail for every tunnel lifecycle call (#ghost-stop): the gateway's
|
|
123
|
+
// plugin log previously only showed the EFFECT ("stopped team-..."), never
|
|
124
|
+
// the caller, so a stop of unknown origin was undiagnosable (two such
|
|
125
|
+
// incidents: 2026-11-12 14:23 and 15:20). Log origin + user-agent on every
|
|
126
|
+
// mutating tunnel endpoint; status stays quiet (polled constantly).
|
|
127
|
+
function tunnelCaller(req: IncomingMessage): string {
|
|
128
|
+
const ua = String(req.headers["user-agent"] ?? "-");
|
|
129
|
+
const origin = String(req.headers.origin ?? "-");
|
|
130
|
+
const xff = String(req.headers["x-forwarded-for"] ?? "-");
|
|
131
|
+
const remote = req.socket.remoteAddress ?? "-";
|
|
132
|
+
return `caller=${remote} xff=${xff} origin=${origin} ua=${ua.slice(0, 120)}`;
|
|
133
|
+
}
|
|
134
|
+
|
|
122
135
|
export function createTunnelManagementRoutes(tunnelManager: TunnelManager, deps: ControllerHttpDeps): readonly RouteDef[] {
|
|
123
136
|
const { config, logger } = deps;
|
|
124
137
|
|
|
@@ -161,6 +174,7 @@ export function createTunnelManagementRoutes(tunnelManager: TunnelManager, deps:
|
|
|
161
174
|
if (!tunnelStartAllowedFrom(req, res)) {
|
|
162
175
|
return;
|
|
163
176
|
}
|
|
177
|
+
logger.info(`TeamClaw tunnel: start requested (${tunnelCaller(req)})`);
|
|
164
178
|
const authStatus = await getGithubAuthManager(config, logger).getStatus();
|
|
165
179
|
const account = authStatus.account;
|
|
166
180
|
if (!account?.login) { sendError(res, 401, "GitHub login required to share a tunnel"); return; }
|
|
@@ -180,6 +194,7 @@ export function createTunnelManagementRoutes(tunnelManager: TunnelManager, deps:
|
|
|
180
194
|
if (!tunnelStartAllowedFrom(req, res)) {
|
|
181
195
|
return;
|
|
182
196
|
}
|
|
197
|
+
logger.info(`TeamClaw tunnel: start-self-hosted requested (${tunnelCaller(req)})`);
|
|
183
198
|
let token = "";
|
|
184
199
|
try {
|
|
185
200
|
const body = await readFormBody(req) as { token?: unknown };
|
|
@@ -202,6 +217,7 @@ export function createTunnelManagementRoutes(tunnelManager: TunnelManager, deps:
|
|
|
202
217
|
if (!tunnelStartAllowedFrom(req, res)) {
|
|
203
218
|
return;
|
|
204
219
|
}
|
|
220
|
+
logger.info(`TeamClaw tunnel: start-quick requested (${tunnelCaller(req)})`);
|
|
205
221
|
const r = tunnelManager.startQuick();
|
|
206
222
|
if (!r.launched) { sendError(res, 400, r.error ?? "failed to start quick tunnel"); return; }
|
|
207
223
|
sendJson(res, 202, { launched: true, status: tunnelManager.status() });
|
|
@@ -210,7 +226,8 @@ export function createTunnelManagementRoutes(tunnelManager: TunnelManager, deps:
|
|
|
210
226
|
{
|
|
211
227
|
method: "POST",
|
|
212
228
|
path: "/api/v1/tunnel/stop",
|
|
213
|
-
handler: async ({ res }) => {
|
|
229
|
+
handler: async ({ req, res }) => {
|
|
230
|
+
logger.warn(`TeamClaw tunnel: STOP requested (${tunnelCaller(req)})`);
|
|
214
231
|
await tunnelManager.stop();
|
|
215
232
|
sendJson(res, 200, tunnelManager.status());
|
|
216
233
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WebSocketServer, WebSocket } from "ws";
|
|
2
2
|
import type { IncomingMessage, Server } from "node:http";
|
|
3
3
|
import type { PluginLogger } from "../../api.js";
|
|
4
|
+
import { journalFromWsEvent } from "./journal.js";
|
|
4
5
|
|
|
5
6
|
export type WsEvent =
|
|
6
7
|
| { type: "worker:online"; data: unknown }
|
|
@@ -77,6 +78,10 @@ export class TeamWebSocketServer {
|
|
|
77
78
|
broadcastUpdate(event: WsEvent): void {
|
|
78
79
|
if (!this.wss) return;
|
|
79
80
|
|
|
81
|
+
// Every broadcast also lands in the controller journal so the web UI's
|
|
82
|
+
// Activity tab can backfill history after a reconnect (#ui-blindness).
|
|
83
|
+
journalFromWsEvent(event);
|
|
84
|
+
|
|
80
85
|
const data = JSON.stringify(event);
|
|
81
86
|
for (const client of this.wss.clients) {
|
|
82
87
|
if (client.readyState === WebSocket.OPEN) {
|