@teamclaws/teamclaw 2026.5.0 → 2026.6.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/openclaw.plugin.json +1 -1
- package/package.json +2 -2
- package/src/controller/controller-service.ts +6 -0
- package/src/controller/http-server.ts +145 -1
- package/src/controller/tunnel-manager.ts +386 -0
- package/src/controller/websocket.ts +2 -1
- package/src/controller/worker-provisioning.ts +15 -0
- package/src/teamauto/scheduler.ts +16 -6
- package/src/ui/app.js +355 -1
- package/src/ui/index.html +5 -0
- package/src/ui/style.css +9 -0
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.
|
|
5
|
+
"version": "2026.6.0",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true
|
|
8
8
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamclaws/teamclaw",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.6.0",
|
|
4
4
|
"description": "OpenClaw virtual software team orchestration plugin",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/node": "^24",
|
|
61
61
|
"@types/ws": "^8.18.2",
|
|
62
|
-
"typescript": "
|
|
62
|
+
"typescript": "5.9"
|
|
63
63
|
},
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
@@ -266,6 +266,12 @@ export function createControllerService(deps: ControllerServiceDeps): OpenClawPl
|
|
|
266
266
|
onTasksCreated: async () => {
|
|
267
267
|
await autoAssignPendingTasks(httpDepsForAutoAssign);
|
|
268
268
|
},
|
|
269
|
+
onActivity: (entry) => {
|
|
270
|
+
wsServer.broadcastUpdate({
|
|
271
|
+
type: "teamauto:activity",
|
|
272
|
+
data: { at: entry.at, repoId: entry.repoId, kind: entry.kind, text: entry.text },
|
|
273
|
+
});
|
|
274
|
+
},
|
|
269
275
|
});
|
|
270
276
|
await teamAutoSchedulerRef.start();
|
|
271
277
|
} catch (err) {
|
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import http from "node:http";
|
|
4
4
|
import zlib from "node:zlib";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
5
6
|
import { execFileSync } from "node:child_process";
|
|
6
7
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
7
8
|
import type { OpenClawPluginApi, PluginLogger } from "../../api.js";
|
|
@@ -53,6 +54,7 @@ import type { WorkerProvisioningManager } from "./worker-provisioning.js";
|
|
|
53
54
|
import type { PreviewManager } from "./preview-manager.js";
|
|
54
55
|
import { createControllerPromptInjector } from "./prompt-injector.js";
|
|
55
56
|
import { getGithubAuthManager } from "./github-auth.js";
|
|
57
|
+
import { createTunnelManager, gatePageHtml, computeGateCookie, GATE_COOKIE_NAME, type TunnelManager } from "./tunnel-manager.js";
|
|
56
58
|
import { createGithubClient } from "../teamauto/github-client.js";
|
|
57
59
|
import type { TeamAutoScheduler } from "../teamauto/scheduler.js";
|
|
58
60
|
import { buildControllerNoWorkersMessage, shouldBlockControllerWithoutWorkers } from "./controller-capacity.js";
|
|
@@ -3582,6 +3584,52 @@ async function cancelTaskExecution(
|
|
|
3582
3584
|
}, deps);
|
|
3583
3585
|
}
|
|
3584
3586
|
|
|
3587
|
+
// Tunnel/CDN caches rewrite the origin's Cache-Control: no-cache into a long
|
|
3588
|
+
// browser freeze for cacheable extensions like .js (observed: Cloudflare
|
|
3589
|
+
// Browser Cache TTL max-age=14400 on tunneled UI assets). A UI update then
|
|
3590
|
+
// never reaches visitors through the tunnel. Serving content-versioned URLs
|
|
3591
|
+
// (?v=<hash>) makes every UI deploy a URL no browser or edge has ever seen,
|
|
3592
|
+
// so stale-cache behavior cannot recur.
|
|
3593
|
+
const uiAssetVersionCache = new Map<string, { mtimeMs: number; version: string }>();
|
|
3594
|
+
|
|
3595
|
+
function uiAssetVersion(uiPath: string, file: string): string {
|
|
3596
|
+
const full = path.join(uiPath, file);
|
|
3597
|
+
try {
|
|
3598
|
+
const mtimeMs = fs.statSync(full).mtimeMs;
|
|
3599
|
+
const cached = uiAssetVersionCache.get(full);
|
|
3600
|
+
if (cached && cached.mtimeMs === mtimeMs) return cached.version;
|
|
3601
|
+
const version = createHash("sha1").update(fs.readFileSync(full)).digest("hex").slice(0, 10);
|
|
3602
|
+
uiAssetVersionCache.set(full, { mtimeMs, version });
|
|
3603
|
+
return version;
|
|
3604
|
+
} catch {
|
|
3605
|
+
return String(Date.now()); // unreadable asset: bust for this request
|
|
3606
|
+
}
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3609
|
+
const UI_HTML_ASSET_REFS = [
|
|
3610
|
+
"/ui/style.css",
|
|
3611
|
+
"/ui/app.js",
|
|
3612
|
+
"/ui/assets/teamclaw-app-icon.png",
|
|
3613
|
+
];
|
|
3614
|
+
|
|
3615
|
+
function serveVersionedHtml(res: ServerResponse, htmlPath: string): void {
|
|
3616
|
+
try {
|
|
3617
|
+
const uiPath = path.dirname(htmlPath);
|
|
3618
|
+
let html = fs.readFileSync(htmlPath, "utf8");
|
|
3619
|
+
for (const ref of UI_HTML_ASSET_REFS) {
|
|
3620
|
+
html = html.split(`"${ref}"`).join(`"${ref}?v=${uiAssetVersion(uiPath, ref.slice("/ui/".length))}"`);
|
|
3621
|
+
}
|
|
3622
|
+
res.writeHead(200, {
|
|
3623
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
3624
|
+
"Access-Control-Allow-Origin": "*",
|
|
3625
|
+
"Cache-Control": "no-cache",
|
|
3626
|
+
});
|
|
3627
|
+
res.end(html);
|
|
3628
|
+
} catch {
|
|
3629
|
+
sendError(res, 404, "File not found");
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3632
|
+
|
|
3585
3633
|
function serveStaticFile(res: ServerResponse, filePath: string, contentType: string): void {
|
|
3586
3634
|
try {
|
|
3587
3635
|
const content = fs.readFileSync(filePath);
|
|
@@ -4658,6 +4706,16 @@ export async function autoAssignPendingTasks(
|
|
|
4658
4706
|
|
|
4659
4707
|
export function createControllerHttpServer(deps: ControllerHttpDeps): http.Server {
|
|
4660
4708
|
const { logger, wsServer } = deps;
|
|
4709
|
+
let tunnelManagerSingleton: TunnelManager | null = null;
|
|
4710
|
+
|
|
4711
|
+
const readFormBody = async (request: IncomingMessage): Promise<Record<string, unknown>> => {
|
|
4712
|
+
const chunks: Buffer[] = [];
|
|
4713
|
+
for await (const chunk of request) chunks.push(chunk as Buffer);
|
|
4714
|
+
const raw = Buffer.concat(chunks).toString("utf8");
|
|
4715
|
+
const out: Record<string, unknown> = {};
|
|
4716
|
+
for (const [k, v] of new URLSearchParams(raw)) out[k] = v;
|
|
4717
|
+
return out;
|
|
4718
|
+
};
|
|
4661
4719
|
|
|
4662
4720
|
const server = http.createServer(async (req: IncomingMessage, res: ServerResponse) => {
|
|
4663
4721
|
// CORS preflight
|
|
@@ -4674,6 +4732,76 @@ export function createControllerHttpServer(deps: ControllerHttpDeps): http.Serve
|
|
|
4674
4732
|
const url = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
|
|
4675
4733
|
const pathname = url.pathname;
|
|
4676
4734
|
|
|
4735
|
+
// Tunnel sharing: every request arriving via <user>.apps.teamclaw.dev is
|
|
4736
|
+
// gated behind the token the local web UI displays.
|
|
4737
|
+
let tunnelManager = tunnelManagerSingleton;
|
|
4738
|
+
if (!tunnelManager) {
|
|
4739
|
+
tunnelManager = tunnelManagerSingleton = createTunnelManager({ logger, localPort: deps.config.port });
|
|
4740
|
+
}
|
|
4741
|
+
const viaTunnel = tunnelManager.isTunnelRequest(typeof req.headers.host === "string" ? req.headers.host : undefined);
|
|
4742
|
+
if (viaTunnel) {
|
|
4743
|
+
if (req.method === "GET" && (pathname === "/__tunnel_gate" || pathname === "/")) {
|
|
4744
|
+
// Valid gate cookie on "/" goes straight to the dashboard; the gate
|
|
4745
|
+
// page only greets visitors who have not authenticated yet.
|
|
4746
|
+
if (pathname === "/" && tunnelManager.gateAllows(req)) {
|
|
4747
|
+
res.writeHead(302, { Location: "/ui/" });
|
|
4748
|
+
res.end();
|
|
4749
|
+
return;
|
|
4750
|
+
}
|
|
4751
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
4752
|
+
res.end(gatePageHtml(String(req.headers.host), false));
|
|
4753
|
+
return;
|
|
4754
|
+
}
|
|
4755
|
+
if (req.method === "POST" && pathname === "/__tunnel_gate/verify") {
|
|
4756
|
+
const form = await readFormBody(req);
|
|
4757
|
+
const submitted = String((form as { token?: unknown }).token ?? "").trim().toUpperCase();
|
|
4758
|
+
const st = tunnelManager.status();
|
|
4759
|
+
if (st.active && st.gateToken && submitted === st.gateToken) {
|
|
4760
|
+
const cookie = `${GATE_COOKIE_NAME}=${computeGateCookie(st.gateToken, st.tunnelId ?? "")}; Path=/; Max-Age=43200; HttpOnly; SameSite=Lax`;
|
|
4761
|
+
res.writeHead(302, { "Set-Cookie": cookie, Location: "/" });
|
|
4762
|
+
res.end();
|
|
4763
|
+
return;
|
|
4764
|
+
}
|
|
4765
|
+
res.writeHead(403, { "Content-Type": "text/html; charset=utf-8" });
|
|
4766
|
+
res.end(gatePageHtml(String(req.headers.host), true));
|
|
4767
|
+
return;
|
|
4768
|
+
}
|
|
4769
|
+
if (!tunnelManager.gateAllows(req)) {
|
|
4770
|
+
res.writeHead(403, { "Content-Type": "text/html; charset=utf-8" });
|
|
4771
|
+
res.end(gatePageHtml(String(req.headers.host), false));
|
|
4772
|
+
return;
|
|
4773
|
+
}
|
|
4774
|
+
} else {
|
|
4775
|
+
if (req.method === "GET" && pathname === "/api/v1/tunnel/status") {
|
|
4776
|
+
sendJson(res, 200, tunnelManager.status());
|
|
4777
|
+
return;
|
|
4778
|
+
}
|
|
4779
|
+
if (req.method === "POST" && pathname === "/api/v1/tunnel/start") {
|
|
4780
|
+
const authStatus = await getGithubAuthManager(deps.config, logger).getStatus();
|
|
4781
|
+
const account = authStatus.account;
|
|
4782
|
+
if (!account?.login) { sendError(res, 401, "GitHub login required to share a tunnel"); return; }
|
|
4783
|
+
// Async launch: poll /tunnel/status for phase progress and the
|
|
4784
|
+
// resulting hostname/gateToken once startOp.phase === "done".
|
|
4785
|
+
const launched = tunnelManager.start(account.login);
|
|
4786
|
+
sendJson(res, 202, { launched, status: tunnelManager.status() });
|
|
4787
|
+
return;
|
|
4788
|
+
}
|
|
4789
|
+
if (req.method === "POST" && pathname === "/api/v1/tunnel/stop") {
|
|
4790
|
+
await tunnelManager.stop();
|
|
4791
|
+
sendJson(res, 200, tunnelManager.status());
|
|
4792
|
+
return;
|
|
4793
|
+
}
|
|
4794
|
+
if (req.method === "POST" && pathname === "/api/v1/tunnel/install-cloudflared") {
|
|
4795
|
+
try {
|
|
4796
|
+
const result = await tunnelManager.installCloudflared();
|
|
4797
|
+
sendJson(res, result.ok ? 200 : 500, { ...result, status: tunnelManager.status() });
|
|
4798
|
+
} catch (err) {
|
|
4799
|
+
sendError(res, 500, err instanceof Error ? err.message : "install failed");
|
|
4800
|
+
}
|
|
4801
|
+
return;
|
|
4802
|
+
}
|
|
4803
|
+
}
|
|
4804
|
+
|
|
4677
4805
|
try {
|
|
4678
4806
|
await handleRequest(req, res, pathname, deps);
|
|
4679
4807
|
} catch (err) {
|
|
@@ -4685,6 +4813,21 @@ export function createControllerHttpServer(deps: ControllerHttpDeps): http.Serve
|
|
|
4685
4813
|
// Attach WebSocket
|
|
4686
4814
|
wsServer.attach(server);
|
|
4687
4815
|
|
|
4816
|
+
// Plugin shutdown: kill the local connector and tear down the remote
|
|
4817
|
+
// tunnel so gateway exits never leak orphan cloudflared processes.
|
|
4818
|
+
server.on("close", () => {
|
|
4819
|
+
void tunnelManagerSingleton?.stop().catch(() => undefined);
|
|
4820
|
+
});
|
|
4821
|
+
|
|
4822
|
+
// Boot reconciliation: reconnect a share persisted by a previous run
|
|
4823
|
+
// (gateway restart or kill -9) so the tunnel id and gate token survive.
|
|
4824
|
+
if (!tunnelManagerSingleton) {
|
|
4825
|
+
tunnelManagerSingleton = createTunnelManager({ logger, localPort: deps.config.port });
|
|
4826
|
+
}
|
|
4827
|
+
void tunnelManagerSingleton.recover().catch((err) => {
|
|
4828
|
+
logger.warn(`TeamClaw tunnel: boot recovery failed: ${String(err)}`);
|
|
4829
|
+
});
|
|
4830
|
+
|
|
4688
4831
|
setTimeout(() => {
|
|
4689
4832
|
const state = deps.getTeamState();
|
|
4690
4833
|
const pendingCount = state
|
|
@@ -4742,6 +4885,7 @@ async function handleRequest(
|
|
|
4742
4885
|
pathname: string,
|
|
4743
4886
|
deps: ControllerHttpDeps,
|
|
4744
4887
|
): Promise<void> {
|
|
4888
|
+
void pathname;
|
|
4745
4889
|
const { config, logger, getTeamState, updateTeamState, taskRouter, messageRouter, wsServer } = deps;
|
|
4746
4890
|
const requestUrl = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
|
|
4747
4891
|
const currentState = getTeamState();
|
|
@@ -4756,7 +4900,7 @@ async function handleRequest(
|
|
|
4756
4900
|
|
|
4757
4901
|
if (req.method === "GET" && (pathname === "/ui" || pathname === "/ui/")) {
|
|
4758
4902
|
const uiPath = path.join(import.meta.dirname, "..", "ui");
|
|
4759
|
-
|
|
4903
|
+
serveVersionedHtml(res, path.join(uiPath, "index.html"));
|
|
4760
4904
|
return;
|
|
4761
4905
|
}
|
|
4762
4906
|
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { execFileSync, spawn, type ChildProcess } from "node:child_process";
|
|
2
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import type { PluginLogger } from "../../api.js";
|
|
5
|
+
import https from "node:https";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
|
|
9
|
+
const TUNNEL_API_HOST = "apps.teamclaw.dev";
|
|
10
|
+
async function tunnelFetch(pathq: string, method: "POST" | "DELETE", body?: unknown): Promise<{ status: number; json: any }> {
|
|
11
|
+
const ip = await new Promise<string>((resolve, reject) => {
|
|
12
|
+
const r = https.request({ host: "1.1.1.1", path: `/dns-query?name=${TUNNEL_API_HOST}&type=A`, method: "GET", headers: { accept: "application/dns-json" }, servername: "cloudflare-dns.com" } as never, (res: import("node:http").IncomingMessage) => {
|
|
13
|
+
let d = ""; res.on("data", (c: Buffer) => (d += c)); res.on("end", () => {
|
|
14
|
+
try { const rec = (JSON.parse(d).Answer || []).map((x: { data: string }) => x.data).find((x: string) => /^\d+\./.test(x)); rec ? resolve(rec) : reject(new Error("DoH no A record")); } catch (e) { reject(e); }
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
r.on("error", reject); r.end();
|
|
18
|
+
});
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const payload = body === undefined ? null : JSON.stringify(body);
|
|
21
|
+
const req = https.request({ host: ip, servername: TUNNEL_API_HOST, path: `/api${pathq}`, method, headers: { host: TUNNEL_API_HOST, "Content-Type": "application/json", ...(payload ? { "Content-Length": Buffer.byteLength(payload) } : {}) } } as never, (res: import("node:http").IncomingMessage) => {
|
|
22
|
+
let d = ""; res.on("data", (c: Buffer) => (d += c)); res.on("end", () => { try { resolve({ status: res.statusCode ?? 0, json: d ? JSON.parse(d) : {} }); } catch { resolve({ status: res.statusCode ?? 0, json: {} }); } });
|
|
23
|
+
});
|
|
24
|
+
req.on("error", reject);
|
|
25
|
+
if (payload) req.write(payload);
|
|
26
|
+
req.end();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Internet tunnel sharing for the local web UI.
|
|
33
|
+
*
|
|
34
|
+
* Flow: the controller asks the TeamClaw tunnel server (a Cloudflare Worker
|
|
35
|
+
* at apps.teamclaw.dev/api) to provision a per-user Cloudflare Tunnel, then
|
|
36
|
+
* runs `cloudflared` locally with the returned connector token. Visitors hit
|
|
37
|
+
* https://<github_user>.apps.teamclaw.dev and must enter the gate token that
|
|
38
|
+
* the local web UI displays (enforced by the controller's gate middleware).
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
export const TUNNEL_SERVER_URL = "https://apps.teamclaw.dev/api";
|
|
42
|
+
const TUNNEL_HOST_SUFFIX = ".teamclaw.dev";
|
|
43
|
+
const GATE_COOKIE = "tc_tunnel_gate";
|
|
44
|
+
|
|
45
|
+
export type TunnelStatus = {
|
|
46
|
+
active: boolean;
|
|
47
|
+
hostname: string | null;
|
|
48
|
+
gateToken: string | null;
|
|
49
|
+
connectorRunning: boolean;
|
|
50
|
+
tunnelId: string | null;
|
|
51
|
+
cloudflaredInstalled: boolean;
|
|
52
|
+
cloudflaredPath: string | null;
|
|
53
|
+
startOp: { running: boolean; phase: string; detail: string | null };
|
|
54
|
+
install: { running: boolean; phase: string; percent: number | null; detail: string | null };
|
|
55
|
+
error: string | null;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type TunnelHandle = {
|
|
59
|
+
tunnelId: string;
|
|
60
|
+
hostname: string;
|
|
61
|
+
gateToken: string;
|
|
62
|
+
// HMAC(tunnelId) issued by the tunnel server at create time; required to
|
|
63
|
+
// delete a live tunnel (tunnel ids are public via the DNS CNAME).
|
|
64
|
+
deleteToken: string;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const CLOUDFLARED_CANDIDATES = [
|
|
68
|
+
"cloudflared",
|
|
69
|
+
"/opt/homebrew/bin/cloudflared",
|
|
70
|
+
"/usr/local/bin/cloudflared",
|
|
71
|
+
"/usr/bin/cloudflared",
|
|
72
|
+
];
|
|
73
|
+
function tunnelRuntimeHome(): string {
|
|
74
|
+
try {
|
|
75
|
+
const dir = path.join(os.tmpdir(), "teamclaw-cloudflared-home");
|
|
76
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
77
|
+
return dir;
|
|
78
|
+
} catch {
|
|
79
|
+
return process.env.HOME ?? "/tmp";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface PersistedTunnelState {
|
|
84
|
+
tunnelId: string;
|
|
85
|
+
hostname: string;
|
|
86
|
+
gateToken: string;
|
|
87
|
+
deleteToken: string;
|
|
88
|
+
connectorToken: string;
|
|
89
|
+
pid: number | null;
|
|
90
|
+
savedAt: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function tunnelStatePath(): string {
|
|
94
|
+
return path.join(tunnelRuntimeHome(), "tunnel-state.json");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function readTunnelState(): PersistedTunnelState | null {
|
|
98
|
+
try {
|
|
99
|
+
const raw = JSON.parse(fs.readFileSync(tunnelStatePath(), "utf8")) as PersistedTunnelState;
|
|
100
|
+
return raw && raw.tunnelId && raw.connectorToken ? raw : null;
|
|
101
|
+
} catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function writeTunnelState(st: PersistedTunnelState): void {
|
|
107
|
+
try {
|
|
108
|
+
fs.writeFileSync(tunnelStatePath(), JSON.stringify(st), { mode: 0o600 });
|
|
109
|
+
} catch { /* best effort */ }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function clearTunnelState(): void {
|
|
113
|
+
try { fs.rmSync(tunnelStatePath(), { force: true }); } catch { /* best effort */ }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// pid-reuse-safe liveness: only treat the pid as OUR orphan when the binary
|
|
117
|
+
// still matches cloudflared.
|
|
118
|
+
function connectorPidIsCloudflared(pid: number): boolean {
|
|
119
|
+
try {
|
|
120
|
+
const out = execFileSync("ps", ["-p", String(pid), "-o", "comm="], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
121
|
+
return out.includes("cloudflared");
|
|
122
|
+
} catch {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function findCloudflared(): string | null {
|
|
128
|
+
for (const bin of CLOUDFLARED_CANDIDATES) {
|
|
129
|
+
try {
|
|
130
|
+
if (fs.existsSync(bin) && fs.accessSync(bin, fs.constants.X_OK) === undefined) {
|
|
131
|
+
return bin;
|
|
132
|
+
}
|
|
133
|
+
} catch {
|
|
134
|
+
/* try next */
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function gateCookieValue(gateToken: string, tunnelId: string): string {
|
|
141
|
+
return createHash("sha256").update(`${gateToken}:${tunnelId}`).digest("hex").slice(0, 32);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function createTunnelManager(deps: { logger: PluginLogger; localPort: number }) {
|
|
145
|
+
const { logger } = deps;
|
|
146
|
+
let child: ChildProcess | null = null;
|
|
147
|
+
let handle: TunnelHandle | null = null;
|
|
148
|
+
let lastError: string | null = null;
|
|
149
|
+
let startOp: { running: boolean; phase: string; detail: string | null } = { running: false, phase: "idle", detail: null };
|
|
150
|
+
let installState: { running: boolean; phase: string; percent: number | null; detail: string | null } = { running: false, phase: "idle", percent: null, detail: null };
|
|
151
|
+
|
|
152
|
+
function isTunnelRequest(hostHeader: string | undefined): boolean {
|
|
153
|
+
return Boolean(hostHeader && hostHeader.toLowerCase().endsWith(TUNNEL_HOST_SUFFIX));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function gateAllows(req: { headers: Record<string, unknown> }): boolean {
|
|
157
|
+
if (!handle) return false;
|
|
158
|
+
const cookie = String(req.headers.cookie ?? "");
|
|
159
|
+
const match = cookie.match(new RegExp(`${GATE_COOKIE}=([0-9a-f]+)`));
|
|
160
|
+
return Boolean(match && match[1] === gateCookieValue(handle.gateToken, handle.tunnelId));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function launchStart(githubUser: string): { running: boolean; phase: string } {
|
|
164
|
+
if (startOp.running) return { running: true, phase: startOp.phase };
|
|
165
|
+
startOp = { running: true, phase: "creating-tunnel", detail: null };
|
|
166
|
+
void (async () => {
|
|
167
|
+
try {
|
|
168
|
+
const h = await start(githubUser);
|
|
169
|
+
startOp = { running: false, phase: "done", detail: h.hostname };
|
|
170
|
+
} catch (e) {
|
|
171
|
+
startOp = { running: false, phase: "error", detail: e instanceof Error ? e.message : String(e) };
|
|
172
|
+
}
|
|
173
|
+
})();
|
|
174
|
+
return { running: true, phase: startOp.phase };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function start(githubUser: string): Promise<TunnelHandle> {
|
|
178
|
+
if (handle && child) return handle;
|
|
179
|
+
const bin = findCloudflared();
|
|
180
|
+
if (!bin) throw new Error("cloudflared not found (brew install cloudflared)");
|
|
181
|
+
const gateToken = randomBytes(6).toString("base64url").replace(/[-_]/g, "").slice(0, 8).toUpperCase();
|
|
182
|
+
const res = await tunnelFetch("/tunnels", "POST", { github_user: githubUser, local_port: deps.localPort });
|
|
183
|
+
const body = res.json as { tunnel_id?: string; connector_token?: string; hostname?: string; delete_token?: string; error?: string };
|
|
184
|
+
if (res.status !== 201 || !body.tunnel_id || !body.connector_token || !body.hostname) {
|
|
185
|
+
throw new Error(body.error ?? `tunnel server responded ${res.status}`);
|
|
186
|
+
}
|
|
187
|
+
startOp = { running: true, phase: "starting-connector", detail: body.hostname };
|
|
188
|
+
stopConnector();
|
|
189
|
+
child = spawnConnector(bin, body.connector_token);
|
|
190
|
+
handle = { tunnelId: body.tunnel_id, hostname: body.hostname, gateToken, deleteToken: body.delete_token ?? "" };
|
|
191
|
+
writeTunnelState({ tunnelId: body.tunnel_id, hostname: body.hostname, gateToken, deleteToken: body.delete_token ?? "", connectorToken: body.connector_token, pid: child.pid ?? null, savedAt: Date.now() });
|
|
192
|
+
lastError = null;
|
|
193
|
+
logger.info(`TeamClaw tunnel: serving https://${body.hostname}`);
|
|
194
|
+
return handle;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function spawnConnector(bin: string, connectorToken: string): ChildProcess {
|
|
198
|
+
const proc = spawn(bin, ["tunnel", "--no-autoupdate", "--protocol", "http2", "run", "--token", connectorToken], {
|
|
199
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
200
|
+
detached: false,
|
|
201
|
+
// Isolate from ~/.cloudflared/cert.pem (a local origin-cert would
|
|
202
|
+
// override the remotely-managed token config) and from QUIC-blocking
|
|
203
|
+
// networks (http2 rides regular TCP 443).
|
|
204
|
+
env: { ...process.env, HOME: tunnelRuntimeHome() },
|
|
205
|
+
});
|
|
206
|
+
proc.on("exit", (code: number | null) => {
|
|
207
|
+
logger.warn(`TeamClaw tunnel: cloudflared exited (code ${code})`);
|
|
208
|
+
if (child === proc) child = null;
|
|
209
|
+
});
|
|
210
|
+
// cloudflared logs (stderr) land in a single file for diagnosis.
|
|
211
|
+
// (stdout is "ignore" in stdio above, so there is nothing to pipe.)
|
|
212
|
+
const logPath = path.join(tunnelRuntimeHome(), "cloudflared.log");
|
|
213
|
+
proc.stderr?.pipe(fs.createWriteStream(logPath, { flags: "a" }));
|
|
214
|
+
return proc;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function stopConnector(): void {
|
|
218
|
+
if (child) {
|
|
219
|
+
child.kill("SIGTERM");
|
|
220
|
+
child = null;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async function stop(): Promise<void> {
|
|
225
|
+
stopConnector();
|
|
226
|
+
if (handle) {
|
|
227
|
+
const gone = handle;
|
|
228
|
+
handle = null;
|
|
229
|
+
await tunnelFetch(`/tunnels/${gone.tunnelId}?user=${encodeURIComponent(gone.hostname.split(".")[0]!.replace(/^team-/, ""))}&token=${encodeURIComponent(gone.deleteToken)}`, "DELETE").catch(() => undefined);
|
|
230
|
+
clearTunnelState();
|
|
231
|
+
logger.info(`TeamClaw tunnel: stopped ${gone.hostname}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Boot reconciliation: reconnect the share persisted by a previous run.
|
|
236
|
+
// Reuses the SAME remotely-managed tunnel (its connector token), so the
|
|
237
|
+
// tunnel id and gate token survive gateway restarts and visitor gate
|
|
238
|
+
// cookies stay valid.
|
|
239
|
+
async function recover(): Promise<TunnelHandle | null> {
|
|
240
|
+
if (handle) return handle;
|
|
241
|
+
const st = readTunnelState();
|
|
242
|
+
if (!st) return null;
|
|
243
|
+
const bin = findCloudflared();
|
|
244
|
+
if (!bin) {
|
|
245
|
+
logger.warn("TeamClaw tunnel: previous share found but cloudflared is not installed; not recovering");
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
// kill -9 of the gateway leaves an orphaned connector behind (SIGKILL
|
|
249
|
+
// cannot run the close handler). Reap it before reconnecting - pid-reuse
|
|
250
|
+
// safe: only when the binary still matches.
|
|
251
|
+
if (st.pid && connectorPidIsCloudflared(st.pid)) {
|
|
252
|
+
try {
|
|
253
|
+
process.kill(st.pid, "SIGKILL");
|
|
254
|
+
logger.warn(`TeamClaw tunnel: killed orphaned connector (pid ${st.pid})`);
|
|
255
|
+
} catch { /* already gone */ }
|
|
256
|
+
}
|
|
257
|
+
startOp = { running: true, phase: "starting-connector", detail: st.hostname };
|
|
258
|
+
stopConnector();
|
|
259
|
+
child = spawnConnector(bin, st.connectorToken);
|
|
260
|
+
handle = { tunnelId: st.tunnelId, hostname: st.hostname, gateToken: st.gateToken, deleteToken: st.deleteToken };
|
|
261
|
+
writeTunnelState({ ...st, pid: child.pid ?? null, savedAt: Date.now() });
|
|
262
|
+
startOp = { running: false, phase: "done", detail: st.hostname };
|
|
263
|
+
lastError = null;
|
|
264
|
+
logger.info(`TeamClaw tunnel: recovered https://${st.hostname} (tunnel id and gate token preserved)`);
|
|
265
|
+
return handle;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function status(): TunnelStatus {
|
|
269
|
+
return {
|
|
270
|
+
active: Boolean(handle),
|
|
271
|
+
tunnelId: handle?.tunnelId ?? null,
|
|
272
|
+
hostname: handle?.hostname ?? null,
|
|
273
|
+
gateToken: handle?.gateToken ?? null,
|
|
274
|
+
connectorRunning: Boolean(child),
|
|
275
|
+
cloudflaredInstalled: findCloudflared() !== null,
|
|
276
|
+
cloudflaredPath: findCloudflared(),
|
|
277
|
+
startOp: { ...startOp },
|
|
278
|
+
install: { ...installState },
|
|
279
|
+
error: lastError,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* One-click cloudflared install across platforms:
|
|
285
|
+
* darwin -> brew install cloudflared (Homebrew), tarball fallback
|
|
286
|
+
* linux -> official tarball into ~/.local/bin (no sudo needed)
|
|
287
|
+
* win32 -> winget install Cloudflare.cloudflared
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
function installCloudflared(): Promise<{ ok: boolean; detail: string }> {
|
|
291
|
+
if (installState.running) {
|
|
292
|
+
return Promise.resolve({ ok: false, detail: "install already in progress" });
|
|
293
|
+
}
|
|
294
|
+
const home = process.env.HOME ?? "/tmp";
|
|
295
|
+
const userBin = path.join(home, ".local", "bin");
|
|
296
|
+
const target = path.join(userBin, "cloudflared");
|
|
297
|
+
const tail = (s: string) => s.trim().split("\n").slice(-2).join(" ").slice(0, 200);
|
|
298
|
+
const setPhase = (phase: string, percent: number | null, detail: string | null) => {
|
|
299
|
+
installState = { running: true, phase, percent, detail };
|
|
300
|
+
};
|
|
301
|
+
const finish = (phase: string, detail: string) => {
|
|
302
|
+
installState = { running: false, phase, percent: phase === "done" ? 100 : null, detail };
|
|
303
|
+
};
|
|
304
|
+
const run = (cmd: string, args: string[]) =>
|
|
305
|
+
new Promise<{ code: number; out: string }>((resolve) => {
|
|
306
|
+
const proc = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
307
|
+
let out = "";
|
|
308
|
+
proc.stdout?.on("data", (c) => (out += c));
|
|
309
|
+
proc.stderr?.on("data", (c) => (out += c));
|
|
310
|
+
proc.on("error", (e) => resolve({ code: 1, out: String(e) }));
|
|
311
|
+
proc.on("close", (code) => resolve({ code: code ?? 1, out }));
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const job = (async (): Promise<{ ok: boolean; detail: string }> => {
|
|
315
|
+
const plat = process.platform + ":" + process.arch;
|
|
316
|
+
logger.info("TeamClaw tunnel: installing cloudflared for " + plat);
|
|
317
|
+
setPhase("installing", null, plat);
|
|
318
|
+
if (process.platform === "win32") {
|
|
319
|
+
const w = await run("winget", ["install", "--id", "Cloudflare.cloudflared", "--accept-source-agreements", "--accept-package-agreements"]);
|
|
320
|
+
return w.code === 0 ? { ok: true, detail: "installed via winget" } : { ok: false, detail: "winget: " + tail(w.out) };
|
|
321
|
+
}
|
|
322
|
+
if (process.platform === "darwin") {
|
|
323
|
+
setPhase("brew", 30, "Homebrew");
|
|
324
|
+
const brew = await run("brew", ["install", "cloudflared"]);
|
|
325
|
+
if (brew.code === 0) return { ok: true, detail: "installed via Homebrew" };
|
|
326
|
+
}
|
|
327
|
+
const arch = process.arch === "arm64" ? "arm64" : process.arch === "ia32" ? "386" : "amd64";
|
|
328
|
+
const name = process.platform === "darwin" ? "cloudflared-darwin-" + arch + ".tgz" : "cloudflared-linux-" + arch + ".tgz";
|
|
329
|
+
fs.mkdirSync(userBin, { recursive: true });
|
|
330
|
+
const tgz = path.join(userBin, name);
|
|
331
|
+
const url = "https://github.com/cloudflare/cloudflared/releases/latest/download/" + name;
|
|
332
|
+
let total = 0;
|
|
333
|
+
try {
|
|
334
|
+
const head = await new Promise<import("node:http").IncomingMessage>((resolve, reject) => {
|
|
335
|
+
const r = https.request(url, { method: "HEAD" } as never, resolve as never);
|
|
336
|
+
r.on("error", reject); r.end();
|
|
337
|
+
});
|
|
338
|
+
total = Number(head.headers["content-length"] ?? 0);
|
|
339
|
+
} catch { total = 0; }
|
|
340
|
+
setPhase("downloading", 0, url);
|
|
341
|
+
const timer = setInterval(() => {
|
|
342
|
+
try {
|
|
343
|
+
const size = fs.statSync(tgz).size;
|
|
344
|
+
if (total > 0) setPhase("downloading", Math.min(99, Math.floor((size / total) * 100)), null);
|
|
345
|
+
} catch { /* file not created yet */ }
|
|
346
|
+
}, 500);
|
|
347
|
+
const dl = await run("curl", ["-fsSL", "--retry", "3", "-o", tgz, url]);
|
|
348
|
+
clearInterval(timer);
|
|
349
|
+
if (dl.code !== 0) return { ok: false, detail: "download: " + tail(dl.out) };
|
|
350
|
+
setPhase("extracting", 99, null);
|
|
351
|
+
const ex = await run("tar", ["xzf", tgz, "-C", userBin]);
|
|
352
|
+
fs.rmSync(tgz, { force: true });
|
|
353
|
+
if (ex.code !== 0) return { ok: false, detail: "extract: " + tail(ex.out) };
|
|
354
|
+
fs.chmodSync(target, 0o755);
|
|
355
|
+
return { ok: true, detail: "installed to " + target };
|
|
356
|
+
})();
|
|
357
|
+
|
|
358
|
+
job.then(
|
|
359
|
+
(r) => finish(r.ok ? "done" : "error", r.detail),
|
|
360
|
+
(e) => finish("error", String(e)),
|
|
361
|
+
);
|
|
362
|
+
return job;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
return { start: launchStart, stop, recover, status, installCloudflared, isTunnelRequest, gateAllows };
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export type TunnelManager = ReturnType<typeof createTunnelManager>;
|
|
370
|
+
|
|
371
|
+
export function gatePageHtml(hostname: string, wrong: boolean): string {
|
|
372
|
+
return `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>TeamClaw Tunnel</title>
|
|
373
|
+
<style>body{font-family:-apple-system,system-ui,sans-serif;background:#121110;color:#ecebe6;display:flex;align-items:center;justify-content:center;height:100vh;margin:0}
|
|
374
|
+
.card{background:#1a1917;border:1px solid #2d2b27;border-radius:12px;padding:32px;width:min(360px,90vw);text-align:center}
|
|
375
|
+
h1{font-size:16px;margin:0 0 6px}p{font-size:12.5px;color:#a8a49a;margin:0 0 18px}
|
|
376
|
+
input{width:100%;padding:10px 12px;border-radius:8px;border:1px solid #3a3731;background:#232120;color:#ecebe6;font-size:16px;letter-spacing:.2em;text-align:center;text-transform:uppercase;box-sizing:border-box}
|
|
377
|
+
button{margin-top:12px;width:100%;padding:10px;border:none;border-radius:8px;background:#d9a664;color:#1a1510;font-weight:600;font-size:14px;cursor:pointer}
|
|
378
|
+
.err{color:#c96f5e;font-size:12px;margin-top:10px}</style></head>
|
|
379
|
+
<body><div class="card"><h1>TeamClaw</h1><p>${hostname} is protected by a gate token. Ask the owner for it.</p>
|
|
380
|
+
<form method="POST" action="/__tunnel_gate/verify"><input name="token" placeholder="GATE TOKEN" autofocus autocomplete="off"><button type="submit">Enter</button>${wrong ? '<div class="err">Wrong token, try again.</div>' : ""}</form></div></body></html>`;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export const GATE_COOKIE_NAME = GATE_COOKIE;
|
|
384
|
+
export function computeGateCookie(gateToken: string, tunnelId: string): string {
|
|
385
|
+
return gateCookieValue(gateToken, tunnelId);
|
|
386
|
+
}
|
|
@@ -19,7 +19,8 @@ export type WsEvent =
|
|
|
19
19
|
| { type: "message:deleted"; data: unknown }
|
|
20
20
|
| { type: "project:deleted"; data: unknown }
|
|
21
21
|
| { type: "requirement:complete"; data: unknown }
|
|
22
|
-
| { type: "report:ready"; data: unknown }
|
|
22
|
+
| { type: "report:ready"; data: unknown }
|
|
23
|
+
| { type: "teamauto:activity"; data: unknown };
|
|
23
24
|
|
|
24
25
|
export class TeamWebSocketServer {
|
|
25
26
|
private wss: WebSocketServer | null = null;
|
|
@@ -1374,6 +1374,21 @@ function buildProvisionedWorkerConfig(
|
|
|
1374
1374
|
} else {
|
|
1375
1375
|
delete agentDefaults.workspace;
|
|
1376
1376
|
}
|
|
1377
|
+
// The host controller may run a newer openclaw that persists the keyed
|
|
1378
|
+
// agents.entries schema (e.g. agents.entries.teamclaw.model written by the
|
|
1379
|
+
// model-configuration feature). Provisioned workers can run an older
|
|
1380
|
+
// openclaw that rejects unknown agents keys ("Unrecognized key: entries"),
|
|
1381
|
+
// so fold the teamclaw entry's model back into the legacy
|
|
1382
|
+
// agents.defaults.model and drop the entries map. New-schema workers also
|
|
1383
|
+
// accept agents.defaults, keeping the folded config compatible both ways.
|
|
1384
|
+
const agentsRecord = agents as { entries?: Record<string, { model?: string }> };
|
|
1385
|
+
if (agentsRecord.entries && typeof agentsRecord.entries === "object") {
|
|
1386
|
+
const entryModel = agentsRecord.entries[TEAMCLAW_AGENT_ID]?.model;
|
|
1387
|
+
if (entryModel && !agentDefaults.model) {
|
|
1388
|
+
agentDefaults.model = entryModel;
|
|
1389
|
+
}
|
|
1390
|
+
delete agentsRecord.entries;
|
|
1391
|
+
}
|
|
1377
1392
|
agents.defaults = agentDefaults;
|
|
1378
1393
|
config.agents = agents;
|
|
1379
1394
|
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
loadTeamAutoStore,
|
|
15
15
|
pushTeamAutoActivity,
|
|
16
16
|
saveTeamAutoStore,
|
|
17
|
+
type TeamAutoActivityEntry,
|
|
17
18
|
type TeamAutoRepo,
|
|
18
19
|
type TeamAutoRepoNorms,
|
|
19
20
|
type TeamAutoRepoProvision,
|
|
@@ -55,10 +56,17 @@ export type TeamAutoSchedulerDeps = {
|
|
|
55
56
|
getTeamState: () => TeamState | null;
|
|
56
57
|
updateTeamState: (updater: (state: TeamState) => void) => TeamState;
|
|
57
58
|
onTasksCreated: () => Promise<void>;
|
|
59
|
+
/** Optional hook fired for every recorded activity entry (WS broadcast). */
|
|
60
|
+
onActivity?: (entry: TeamAutoActivityEntry) => void;
|
|
58
61
|
};
|
|
59
62
|
|
|
60
63
|
export function createTeamAutoScheduler(deps: TeamAutoSchedulerDeps) {
|
|
61
64
|
const { logger, auth } = deps;
|
|
65
|
+
|
|
66
|
+
function recordActivity(store: TeamAutoStore, entry: TeamAutoActivityEntry): void {
|
|
67
|
+
pushTeamAutoActivity(store, entry);
|
|
68
|
+
deps.onActivity?.(entry);
|
|
69
|
+
}
|
|
62
70
|
const client = createGithubClient(auth);
|
|
63
71
|
const sync = createRepoSync(auth, logger);
|
|
64
72
|
const timers = new Map<string, NodeJS.Timeout>();
|
|
@@ -113,7 +121,7 @@ export function createTeamAutoScheduler(deps: TeamAutoSchedulerDeps) {
|
|
|
113
121
|
// returns immediately; sweeps stay gated until provision completes.
|
|
114
122
|
repo.provision = { status: "provisioning", message: "cloning repo", startedAt: Date.now(), updatedAt: Date.now() };
|
|
115
123
|
s.repos.push(repo);
|
|
116
|
-
|
|
124
|
+
recordActivity(s, { at: Date.now(), repoId: normalized, kind: "bind", text: `bound (schedule ${repo.schedule})` });
|
|
117
125
|
await saveTeamAutoStore(s);
|
|
118
126
|
scheduleRepo(repo);
|
|
119
127
|
void provisionRepoInBackground(normalized, info.cloneUrl, info.defaultBranch);
|
|
@@ -130,12 +138,14 @@ export function createTeamAutoScheduler(deps: TeamAutoSchedulerDeps) {
|
|
|
130
138
|
const norms = await learnNorms(repoRef, client, sync, cloneUrl, defaultBranch);
|
|
131
139
|
await updateRepoProvision(repoId, { status: "ready", message: "ready", norms });
|
|
132
140
|
const sReady = await ensureStore();
|
|
133
|
-
|
|
141
|
+
recordActivity(sReady, { at: Date.now(), repoId, kind: "provision", text: "ready (clone + norms done)" });
|
|
134
142
|
logger.info(`TeamAuto: provisioned ${repoId} (clone + norms done)`);
|
|
135
143
|
} catch (err) {
|
|
136
144
|
const message = err instanceof Error ? err.message : String(err);
|
|
137
145
|
logger.warn(`TeamAuto: provisioning failed for ${repoId}: ${message}`);
|
|
138
146
|
await updateRepoProvision(repoId, { status: "failed", message });
|
|
147
|
+
const sFailed = await ensureStore();
|
|
148
|
+
recordActivity(sFailed, { at: Date.now(), repoId, kind: "provision", text: `failed: ${message}` });
|
|
139
149
|
}
|
|
140
150
|
}
|
|
141
151
|
|
|
@@ -260,7 +270,7 @@ export function createTeamAutoScheduler(deps: TeamAutoSchedulerDeps) {
|
|
|
260
270
|
for (const candidate of capped) {
|
|
261
271
|
const taskId = enqueueCandidate(repo, candidate);
|
|
262
272
|
if (taskId) {
|
|
263
|
-
|
|
273
|
+
recordActivity(s, { at: Date.now(), repoId: repo.id, kind: "task", text: `${candidate.kind}: ${candidate.title}` });
|
|
264
274
|
const action = candidate.kind === "prReview"
|
|
265
275
|
? ("prComment" as const)
|
|
266
276
|
: candidate.kind === "fullReview"
|
|
@@ -279,7 +289,7 @@ export function createTeamAutoScheduler(deps: TeamAutoSchedulerDeps) {
|
|
|
279
289
|
repo.lastSweepSummary = "no new work";
|
|
280
290
|
}
|
|
281
291
|
repo.lastSweepAt = Date.now();
|
|
282
|
-
|
|
292
|
+
recordActivity(s, { at: Date.now(), repoId: repo.id, kind: "sweep", text: repo.lastSweepSummary ?? "sweep complete" });
|
|
283
293
|
await saveTeamAutoStore(s);
|
|
284
294
|
if (created > 0) {
|
|
285
295
|
await deps.onTasksCreated().catch((err) => {
|
|
@@ -424,7 +434,7 @@ export function createTeamAutoScheduler(deps: TeamAutoSchedulerDeps) {
|
|
|
424
434
|
const pr = await client.createPullRequest(repoId.split("/")[0]!, repoId.split("/")[1]!, branch, info.defaultBranch, `[teamclaw:${role}] ${task.title.replace(/^\[[^\]]+\]\s*/, "")}`.slice(0, 120), `${task.result.trim()}\n${MARKER_FOOTER(role)}`);
|
|
425
435
|
entry.prUrl = pr.url;
|
|
426
436
|
body = `${body}\n\nDelivered as PR: ${pr.url}`;
|
|
427
|
-
|
|
437
|
+
recordActivity(s, { at: Date.now(), repoId, kind: "writeback", text: `PR opened: ${pr.url}` });
|
|
428
438
|
}
|
|
429
439
|
await sync.removeTaskWorktree(repoId, task.id);
|
|
430
440
|
} catch (prErr) {
|
|
@@ -474,7 +484,7 @@ export function createTeamAutoScheduler(deps: TeamAutoSchedulerDeps) {
|
|
|
474
484
|
entry.error = `unsupported action ${entry.action}`;
|
|
475
485
|
}
|
|
476
486
|
if (writebackDone) {
|
|
477
|
-
|
|
487
|
+
recordActivity(s, { at: Date.now(), repoId: entry.repoId, kind: "writeback", text: `${entry.action} #${entry.targetId ?? "-"} ok (${task.id})` });
|
|
478
488
|
}
|
|
479
489
|
}
|
|
480
490
|
} catch (err) {
|
package/src/ui/app.js
CHANGED
|
@@ -87,6 +87,36 @@
|
|
|
87
87
|
"empty.noTasksWithStatus": "No tasks with status \"{status}\"",
|
|
88
88
|
"empty.noClarifications": "No clarification requests",
|
|
89
89
|
"empty.noControllerActivity": "No controller activity yet",
|
|
90
|
+
"toast.taskCompleted": "Task completed",
|
|
91
|
+
"toast.taskFailed": "Task failed",
|
|
92
|
+
"toast.clarificationRequested": "Clarification needed",
|
|
93
|
+
"toast.clarificationAnswered": "Clarification answered",
|
|
94
|
+
"toast.teamautoPrefix": "TeamAuto",
|
|
95
|
+
"toast.workerOnline": "Worker online",
|
|
96
|
+
"toast.workerOffline": "Worker offline",
|
|
97
|
+
"toast.taskCreated": "Task created",
|
|
98
|
+
"toast.taskUpdated": "Task updated",
|
|
99
|
+
"toast.messageNew": "New message",
|
|
100
|
+
"toast.settingsTitle": "Toast notifications",
|
|
101
|
+
"toast.enableAll": "Enable all",
|
|
102
|
+
"toast.disableAll": "Disable all",
|
|
103
|
+
"toast.freqTaskCompleted": "Low - once per task",
|
|
104
|
+
"toast.freqTaskCreated": "Medium - once per flow stage",
|
|
105
|
+
"toast.freqTaskUpdated": "High - several times per task lifecycle",
|
|
106
|
+
"toast.freqClarification": "Rare - only when a worker needs a human decision",
|
|
107
|
+
"toast.freqWorker": "Topology-dependent - external workers rare; provisioned workers may cycle every task (idle TTL 120s)",
|
|
108
|
+
"toast.freqTeamauto": "Low - per sweep, claim, or write-back",
|
|
109
|
+
"toast.freqMessageNew": "High - every controller message",
|
|
110
|
+
"toast.taBind": "TeamAuto: repo bound",
|
|
111
|
+
"toast.taProvision": "TeamAuto: repo ready",
|
|
112
|
+
"toast.taTask": "TeamAuto: task queued",
|
|
113
|
+
"toast.taSweep": "TeamAuto: sweep finished",
|
|
114
|
+
"toast.taWriteback": "TeamAuto: write-back posted",
|
|
115
|
+
"toast.freqTaBind": "Rare - once per repo at bind time",
|
|
116
|
+
"toast.freqTaProvision": "Rare - once per repo after clone + norms",
|
|
117
|
+
"toast.freqTaTask": "Medium - each claimed issue/PR per sweep",
|
|
118
|
+
"toast.freqTaSweep": "Highest - every sweep cycle of every bound repo (cron)",
|
|
119
|
+
"toast.freqTaWriteback": "Medium - each comment/PR posted to GitHub",
|
|
90
120
|
"empty.noMessages": "No messages yet",
|
|
91
121
|
"empty.noPlanningSessions": "No planning sessions yet",
|
|
92
122
|
"empty.noKickoffData": "No kickoff data",
|
|
@@ -215,6 +245,36 @@
|
|
|
215
245
|
"empty.noTasksWithStatus": "没有状态为“{status}”的任务",
|
|
216
246
|
"empty.noClarifications": "暂无澄清请求",
|
|
217
247
|
"empty.noControllerActivity": "暂无 controller 活动",
|
|
248
|
+
"toast.taskCompleted": "任务完成",
|
|
249
|
+
"toast.taskFailed": "任务失败",
|
|
250
|
+
"toast.clarificationRequested": "需要澄清",
|
|
251
|
+
"toast.clarificationAnswered": "澄清已回答",
|
|
252
|
+
"toast.teamautoPrefix": "TeamAuto",
|
|
253
|
+
"toast.workerOnline": "Worker 上线",
|
|
254
|
+
"toast.workerOffline": "Worker 下线",
|
|
255
|
+
"toast.taskCreated": "任务已创建",
|
|
256
|
+
"toast.taskUpdated": "任务更新",
|
|
257
|
+
"toast.messageNew": "新消息",
|
|
258
|
+
"toast.settingsTitle": "Toast 通知管理",
|
|
259
|
+
"toast.enableAll": "全部启用",
|
|
260
|
+
"toast.disableAll": "全部关闭",
|
|
261
|
+
"toast.freqTaskCompleted": "低 - 每任务一次",
|
|
262
|
+
"toast.freqTaskCreated": "中 - 每阶段一次",
|
|
263
|
+
"toast.freqTaskUpdated": "高 - 每任务生命周期多次",
|
|
264
|
+
"toast.freqClarification": "很少 - 仅当 worker 需要人来决策时",
|
|
265
|
+
"toast.freqWorker": "视拓扑而定 - 外部 worker 很少;按需供给 worker 可能每任务上下线一次(空闲 120 秒回收)",
|
|
266
|
+
"toast.freqTeamauto": "低 - 每次扫描/认领/回写",
|
|
267
|
+
"toast.freqMessageNew": "高 - 每条 controller 消息",
|
|
268
|
+
"toast.taBind": "TeamAuto:仓库已绑定",
|
|
269
|
+
"toast.taProvision": "TeamAuto:仓库就绪",
|
|
270
|
+
"toast.taTask": "TeamAuto:任务入队",
|
|
271
|
+
"toast.taSweep": "TeamAuto:扫描完成",
|
|
272
|
+
"toast.taWriteback": "TeamAuto:已回写",
|
|
273
|
+
"toast.freqTaBind": "很少 - 每仓库绑定一次",
|
|
274
|
+
"toast.freqTaProvision": "很少 - 每仓库克隆学习完成后一次",
|
|
275
|
+
"toast.freqTaTask": "中 - 每次扫描认领的 issue/PR",
|
|
276
|
+
"toast.freqTaSweep": "最高 - 每个绑定仓库每个周期都触发(cron)",
|
|
277
|
+
"toast.freqTaWriteback": "中 - 每次向 GitHub 发评论/PR",
|
|
218
278
|
"empty.noMessages": "暂无消息",
|
|
219
279
|
"empty.noPlanningSessions": "暂无规划会话",
|
|
220
280
|
"empty.noKickoffData": "暂无 kickoff 数据",
|
|
@@ -1395,6 +1455,201 @@
|
|
|
1395
1455
|
setTimeout(dismiss, 5000);
|
|
1396
1456
|
}
|
|
1397
1457
|
|
|
1458
|
+
var TOAST_PREFS_KEY = "teamclaw.toast.prefs.v1";
|
|
1459
|
+
var TOAST_EVENT_DEFS = [
|
|
1460
|
+
{ id: "task:completed", titleKey: "toast.taskCompleted", freqKey: "toast.freqTaskCompleted" },
|
|
1461
|
+
{ id: "task:created", titleKey: "toast.taskCreated", freqKey: "toast.freqTaskCreated" },
|
|
1462
|
+
{ id: "task:updated", titleKey: "toast.taskUpdated", freqKey: "toast.freqTaskUpdated" },
|
|
1463
|
+
{ id: "clarification:requested", titleKey: "toast.clarificationRequested", freqKey: "toast.freqClarification" },
|
|
1464
|
+
{ id: "clarification:answered", titleKey: "toast.clarificationAnswered", freqKey: "toast.freqClarification" },
|
|
1465
|
+
{ id: "worker:online", titleKey: "toast.workerOnline", freqKey: "toast.freqWorker" },
|
|
1466
|
+
{ id: "worker:offline", titleKey: "toast.workerOffline", freqKey: "toast.freqWorker" },
|
|
1467
|
+
{ id: "teamauto:activity", titleKey: "toast.teamautoPrefix", freqKey: "toast.freqTeamauto" },
|
|
1468
|
+
{ id: "teamauto:activity:bind", titleKey: "toast.taBind", freqKey: "toast.freqTaBind" },
|
|
1469
|
+
{ id: "teamauto:activity:provision", titleKey: "toast.taProvision", freqKey: "toast.freqTaProvision" },
|
|
1470
|
+
{ id: "teamauto:activity:task", titleKey: "toast.taTask", freqKey: "toast.freqTaTask" },
|
|
1471
|
+
{ id: "teamauto:activity:sweep", titleKey: "toast.taSweep", freqKey: "toast.freqTaSweep" },
|
|
1472
|
+
{ id: "teamauto:activity:writeback", titleKey: "toast.taWriteback", freqKey: "toast.freqTaWriteback" },
|
|
1473
|
+
{ id: "message:new", titleKey: "toast.messageNew", freqKey: "toast.freqMessageNew" },
|
|
1474
|
+
];
|
|
1475
|
+
|
|
1476
|
+
function loadToastPrefs() {
|
|
1477
|
+
try {
|
|
1478
|
+
var raw = window.localStorage.getItem(TOAST_PREFS_KEY);
|
|
1479
|
+
if (raw) {
|
|
1480
|
+
var parsed = JSON.parse(raw);
|
|
1481
|
+
if (parsed && typeof parsed === "object") {
|
|
1482
|
+
return parsed;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
} catch (_err) {}
|
|
1486
|
+
return {};
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
function toastEnabled(eventId) {
|
|
1490
|
+
// All event toasts are enabled by default; users opt out per event.
|
|
1491
|
+
return loadToastPrefs()[eventId] !== false;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
function setToastPref(eventId, enabled) {
|
|
1495
|
+
var prefs = loadToastPrefs();
|
|
1496
|
+
prefs[eventId] = !!enabled;
|
|
1497
|
+
try {
|
|
1498
|
+
window.localStorage.setItem(TOAST_PREFS_KEY, JSON.stringify(prefs));
|
|
1499
|
+
} catch (_err) {}
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
function workerEventLabel(data) {
|
|
1503
|
+
data = data || {};
|
|
1504
|
+
return String(data.id || data.workerId || data.name || data.role || "");
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
function messageEventLabel(data) {
|
|
1508
|
+
data = data || {};
|
|
1509
|
+
var from = data.fromRole || data.role || data.sender || "";
|
|
1510
|
+
var text = String(data.text || data.content || data.body || "").slice(0, 80);
|
|
1511
|
+
return (from ? from + ": " : "") + text;
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
function toggleToastSettingsPanel() {
|
|
1515
|
+
var existing = document.getElementById("toast-settings-panel");
|
|
1516
|
+
if (existing) {
|
|
1517
|
+
existing.remove();
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
var panel = document.createElement("div");
|
|
1521
|
+
panel.id = "toast-settings-panel";
|
|
1522
|
+
panel.style.cssText = "position:fixed;top:64px;right:16px;z-index:2100;background:#111827;color:#fff;"
|
|
1523
|
+
+ "border-radius:12px;box-shadow:0 12px 32px rgba(0,0,0,0.4);padding:16px;"
|
|
1524
|
+
+ "min-width:320px;max-width:min(430px,92vw);font-size:13px;line-height:1.5;";
|
|
1525
|
+
var head = document.createElement("div");
|
|
1526
|
+
head.style.cssText = "display:flex;align-items:center;justify-content:space-between;margin-bottom:10px;";
|
|
1527
|
+
var title = document.createElement("div");
|
|
1528
|
+
title.style.fontWeight = "600";
|
|
1529
|
+
title.textContent = t("toast.settingsTitle");
|
|
1530
|
+
var close = document.createElement("button");
|
|
1531
|
+
close.type = "button";
|
|
1532
|
+
close.textContent = t("teamauto.close");
|
|
1533
|
+
close.style.cssText = "background:none;border:1px solid rgba(255,255,255,0.3);color:#fff;border-radius:6px;padding:2px 8px;cursor:pointer;font-size:12px;";
|
|
1534
|
+
close.addEventListener("click", function () { panel.remove(); });
|
|
1535
|
+
head.appendChild(title);
|
|
1536
|
+
head.appendChild(close);
|
|
1537
|
+
panel.appendChild(head);
|
|
1538
|
+
var prefs = loadToastPrefs();
|
|
1539
|
+
TOAST_EVENT_DEFS.forEach(function (def) {
|
|
1540
|
+
var row = document.createElement("label");
|
|
1541
|
+
row.style.cssText = "display:flex;gap:10px;align-items:flex-start;padding:7px 0;border-top:1px solid rgba(255,255,255,0.08);cursor:pointer;";
|
|
1542
|
+
var box = document.createElement("input");
|
|
1543
|
+
box.type = "checkbox";
|
|
1544
|
+
box.checked = prefs[def.id] !== false;
|
|
1545
|
+
box.style.marginTop = "3px";
|
|
1546
|
+
box.addEventListener("change", function () {
|
|
1547
|
+
setToastPref(def.id, box.checked);
|
|
1548
|
+
});
|
|
1549
|
+
var text = document.createElement("div");
|
|
1550
|
+
var name = document.createElement("div");
|
|
1551
|
+
name.style.fontWeight = "600";
|
|
1552
|
+
name.textContent = t(def.titleKey);
|
|
1553
|
+
var freq = document.createElement("div");
|
|
1554
|
+
freq.style.cssText = "opacity:0.65;font-size:12px;";
|
|
1555
|
+
freq.textContent = t(def.freqKey);
|
|
1556
|
+
text.appendChild(name);
|
|
1557
|
+
text.appendChild(freq);
|
|
1558
|
+
row.appendChild(box);
|
|
1559
|
+
row.appendChild(text);
|
|
1560
|
+
panel.appendChild(row);
|
|
1561
|
+
});
|
|
1562
|
+
var foot = document.createElement("div");
|
|
1563
|
+
foot.style.cssText = "display:flex;gap:8px;justify-content:flex-end;margin-top:10px;";
|
|
1564
|
+
var allOn = document.createElement("button");
|
|
1565
|
+
allOn.type = "button";
|
|
1566
|
+
allOn.textContent = t("toast.enableAll");
|
|
1567
|
+
var allOff = document.createElement("button");
|
|
1568
|
+
allOff.type = "button";
|
|
1569
|
+
allOff.textContent = t("toast.disableAll");
|
|
1570
|
+
[allOn, allOff].forEach(function (btn) {
|
|
1571
|
+
btn.style.cssText = "background:rgba(255,255,255,0.1);border:1px solid rgba(255,255,255,0.25);color:#fff;border-radius:6px;padding:4px 10px;cursor:pointer;font-size:12px;";
|
|
1572
|
+
});
|
|
1573
|
+
allOn.addEventListener("click", function () {
|
|
1574
|
+
TOAST_EVENT_DEFS.forEach(function (def) { setToastPref(def.id, true); });
|
|
1575
|
+
panel.remove();
|
|
1576
|
+
toggleToastSettingsPanel();
|
|
1577
|
+
});
|
|
1578
|
+
allOff.addEventListener("click", function () {
|
|
1579
|
+
TOAST_EVENT_DEFS.forEach(function (def) { setToastPref(def.id, false); });
|
|
1580
|
+
panel.remove();
|
|
1581
|
+
toggleToastSettingsPanel();
|
|
1582
|
+
});
|
|
1583
|
+
foot.appendChild(allOff);
|
|
1584
|
+
foot.appendChild(allOn);
|
|
1585
|
+
panel.appendChild(foot);
|
|
1586
|
+
document.body.appendChild(panel);
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
var toastSettingsToggle = $("#toast-settings-toggle");
|
|
1590
|
+
if (toastSettingsToggle) {
|
|
1591
|
+
toastSettingsToggle.addEventListener("click", function (event) {
|
|
1592
|
+
event.stopPropagation();
|
|
1593
|
+
toggleToastSettingsPanel();
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
const recentNoticeKeys = {};
|
|
1598
|
+
|
|
1599
|
+
function showNotice(eventId, kind, title, body) {
|
|
1600
|
+
// Status-change toasts (task/worker/clarification/TeamAuto events).
|
|
1601
|
+
// Per-event toggles persist in localStorage (all on by default);
|
|
1602
|
+
// deduped against event bursts and capped so a busy team cannot
|
|
1603
|
+
// flood the corner.
|
|
1604
|
+
if (!toastEnabled(eventId)) {
|
|
1605
|
+
return;
|
|
1606
|
+
}
|
|
1607
|
+
const now = Date.now();
|
|
1608
|
+
const dedupeKey = kind + "|" + title + "|" + body;
|
|
1609
|
+
if (recentNoticeKeys[dedupeKey] && now - recentNoticeKeys[dedupeKey] < 4000) {
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
recentNoticeKeys[dedupeKey] = now;
|
|
1613
|
+
if (Object.keys(recentNoticeKeys).length > 200) {
|
|
1614
|
+
for (var staleKey in recentNoticeKeys) {
|
|
1615
|
+
if (now - recentNoticeKeys[staleKey] >= 4000) {
|
|
1616
|
+
delete recentNoticeKeys[staleKey];
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
let container = document.getElementById("toast-container");
|
|
1621
|
+
if (!container) {
|
|
1622
|
+
container = document.createElement("div");
|
|
1623
|
+
container.id = "toast-container";
|
|
1624
|
+
container.style.cssText = "position:fixed;bottom:24px;right:24px;z-index:2000;display:flex;flex-direction:column;gap:10px;max-width:min(420px,80vw);";
|
|
1625
|
+
document.body.appendChild(container);
|
|
1626
|
+
}
|
|
1627
|
+
while (container.children.length >= 6) {
|
|
1628
|
+
container.removeChild(container.firstChild);
|
|
1629
|
+
}
|
|
1630
|
+
const toast = document.createElement("div");
|
|
1631
|
+
const bg = kind === "success" ? "#14532d" : kind === "attention" ? "#7f1d1d" : "#1e3a5f";
|
|
1632
|
+
toast.style.cssText = "background:" + bg + ";color:#fff;padding:12px 16px;border-radius:10px;"
|
|
1633
|
+
+ "box-shadow:0 8px 24px rgba(0,0,0,0.35);font-size:13px;line-height:1.45;"
|
|
1634
|
+
+ "cursor:pointer;opacity:0;transition:opacity 0.25s ease;";
|
|
1635
|
+
const titleEl = document.createElement("div");
|
|
1636
|
+
titleEl.style.cssText = "font-weight:600;";
|
|
1637
|
+
titleEl.textContent = title;
|
|
1638
|
+
const bodyEl = document.createElement("div");
|
|
1639
|
+
bodyEl.style.cssText = "opacity:.85;margin-top:2px;";
|
|
1640
|
+
bodyEl.textContent = body;
|
|
1641
|
+
toast.appendChild(titleEl);
|
|
1642
|
+
toast.appendChild(bodyEl);
|
|
1643
|
+
container.appendChild(toast);
|
|
1644
|
+
requestAnimationFrame(function () { toast.style.opacity = "1"; });
|
|
1645
|
+
const dismiss = function () {
|
|
1646
|
+
toast.style.opacity = "0";
|
|
1647
|
+
setTimeout(function () { toast.remove(); }, 250);
|
|
1648
|
+
};
|
|
1649
|
+
toast.onclick = dismiss;
|
|
1650
|
+
setTimeout(dismiss, 6000);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1398
1653
|
async function apiRequest(path, options) {
|
|
1399
1654
|
const res = await fetch(API_BASE + path, options);
|
|
1400
1655
|
let data = {};
|
|
@@ -1961,18 +2216,67 @@
|
|
|
1961
2216
|
handleTaskExecutionEvent(event.data || {});
|
|
1962
2217
|
break;
|
|
1963
2218
|
case "worker:online":
|
|
2219
|
+
refreshAll();
|
|
2220
|
+
showNotice("worker:online", "info", t("toast.workerOnline"), workerEventLabel(event.data));
|
|
2221
|
+
break;
|
|
1964
2222
|
case "worker:offline":
|
|
2223
|
+
refreshAll();
|
|
2224
|
+
showNotice("worker:offline", "info", t("toast.workerOffline"), workerEventLabel(event.data));
|
|
2225
|
+
break;
|
|
1965
2226
|
case "task:created":
|
|
2227
|
+
refreshAll();
|
|
2228
|
+
if (selectedTaskId && taskId && taskId === selectedTaskId) {
|
|
2229
|
+
refreshTaskDetail(true);
|
|
2230
|
+
}
|
|
2231
|
+
showNotice("task:created", "info", t("toast.taskCreated"), (event.data || {}).title || taskId || "");
|
|
2232
|
+
break;
|
|
1966
2233
|
case "task:updated":
|
|
1967
|
-
|
|
2234
|
+
refreshAll();
|
|
2235
|
+
if (selectedTaskId && taskId && taskId === selectedTaskId) {
|
|
2236
|
+
refreshTaskDetail(true);
|
|
2237
|
+
}
|
|
2238
|
+
showNotice("task:updated", "info", t("toast.taskUpdated"), (event.data || {}).title || taskId || "");
|
|
2239
|
+
break;
|
|
1968
2240
|
case "message:new":
|
|
2241
|
+
refreshAll();
|
|
2242
|
+
showNotice("message:new", "info", t("toast.messageNew"), messageEventLabel(event.data));
|
|
2243
|
+
break;
|
|
2244
|
+
case "task:completed": {
|
|
2245
|
+
refreshAll();
|
|
2246
|
+
if (selectedTaskId && taskId && taskId === selectedTaskId) {
|
|
2247
|
+
refreshTaskDetail(true);
|
|
2248
|
+
}
|
|
2249
|
+
const doneData = event.data || {};
|
|
2250
|
+
const doneStatus = String(doneData.status || "").toLowerCase();
|
|
2251
|
+
const doneFailed = doneStatus === "failed" || doneStatus === "blocked";
|
|
2252
|
+
showNotice("task:completed", doneFailed ? "attention" : "success",
|
|
2253
|
+
t(doneFailed ? "toast.taskFailed" : "toast.taskCompleted"),
|
|
2254
|
+
doneData.title || taskId || "");
|
|
2255
|
+
break;
|
|
2256
|
+
}
|
|
1969
2257
|
case "clarification:requested":
|
|
2258
|
+
refreshAll();
|
|
2259
|
+
if (selectedTaskId && taskId && taskId === selectedTaskId) {
|
|
2260
|
+
refreshTaskDetail(true);
|
|
2261
|
+
}
|
|
2262
|
+
showNotice("clarification:requested", "attention", t("toast.clarificationRequested"), (event.data || {}).question || taskId || "");
|
|
2263
|
+
break;
|
|
1970
2264
|
case "clarification:answered":
|
|
1971
2265
|
refreshAll();
|
|
1972
2266
|
if (selectedTaskId && taskId && taskId === selectedTaskId) {
|
|
1973
2267
|
refreshTaskDetail(true);
|
|
1974
2268
|
}
|
|
2269
|
+
showNotice("clarification:answered", "info", t("toast.clarificationAnswered"), (event.data || {}).question || taskId || "");
|
|
2270
|
+
break;
|
|
2271
|
+
case "teamauto:activity": {
|
|
2272
|
+
const entry = event.data || {};
|
|
2273
|
+
const kindId = "teamauto:activity:" + String(entry.kind || "activity");
|
|
2274
|
+
if (toastEnabled("teamauto:activity") && toastEnabled(kindId)) {
|
|
2275
|
+
showNotice(kindId, "info", t("toast.teamautoPrefix") + " - " + String(entry.kind || "activity"),
|
|
2276
|
+
String(entry.repoId || "") + (entry.text ? " - " + String(entry.text) : ""));
|
|
2277
|
+
}
|
|
1975
2278
|
break;
|
|
2279
|
+
}
|
|
1976
2280
|
case "report:ready":
|
|
1977
2281
|
handleReportReady(event.data || {});
|
|
1978
2282
|
break;
|
|
@@ -3856,4 +4160,54 @@ function closeModelSettings() {
|
|
|
3856
4160
|
if (activeTab === "teamauto") { refreshTeamAutoTab(); }
|
|
3857
4161
|
}, 10000);
|
|
3858
4162
|
|
|
4163
|
+
|
|
4164
|
+
// Tunnel sharing (internet gate for the local web UI).
|
|
4165
|
+
function initTunnelPanel() {
|
|
4166
|
+
const wrap = document.getElementById("tunnel-panel");
|
|
4167
|
+
if (!wrap || wrap.dataset.bound) return;
|
|
4168
|
+
wrap.dataset.bound = "true";
|
|
4169
|
+
// Visitor view: when the dashboard itself is reached through a tunnel
|
|
4170
|
+
// domain, management APIs are gated - degrade to a provenance badge
|
|
4171
|
+
// instead of a spinner that can never resolve.
|
|
4172
|
+
const host = (location.hostname || "").toLowerCase();
|
|
4173
|
+
const isLocalView = host === "127.0.0.1" || host === "localhost" || host.endsWith(".local");
|
|
4174
|
+
if (!isLocalView) {
|
|
4175
|
+
wrap.innerHTML = '<h3>Internet Tunnel</h3><div class="tunnel-state"><span class="tunnel-note">This dashboard is shared via a TeamClaw tunnel.</span></div>';
|
|
4176
|
+
return;
|
|
4177
|
+
}
|
|
4178
|
+
const render = (st) => {
|
|
4179
|
+
var progress = st.startOp && st.startOp.running
|
|
4180
|
+
? '<div class="tunnel-note">Starting tunnel: ' + escapeHtml(st.startOp.phase) + '…</div>'
|
|
4181
|
+
: (st.install && st.install.running
|
|
4182
|
+
? '<div class="tunnel-note">cloudflared ' + escapeHtml(st.install.phase) + (st.install.percent != null ? ' ' + st.install.percent + '%' : '') + '…</div>'
|
|
4183
|
+
: '');
|
|
4184
|
+
if (progress) { wrap.querySelector(".tunnel-state").innerHTML = progress; return; }
|
|
4185
|
+
wrap.querySelector(".tunnel-state").innerHTML = st.active
|
|
4186
|
+
? '<div class="tunnel-on">Live: <a href="https://' + st.hostname + '" target="_blank" rel="noopener">https://' + st.hostname + '</a></div>'
|
|
4187
|
+
+ '<div class="tunnel-token">Gate token: <b>' + st.gateToken + '</b></div>'
|
|
4188
|
+
+ '<button class="btn btn-small" data-act="stop">Stop sharing</button>'
|
|
4189
|
+
: st.cloudflaredInstalled === false
|
|
4190
|
+
? '<div class="tunnel-note">cloudflared connector is not installed.</div>'
|
|
4191
|
+
+ '<button class="btn btn-small btn-primary" data-act="install">Install cloudflared</button>'
|
|
4192
|
+
: '<button class="btn btn-small btn-primary" data-act="start">Share via tunnel</button>'
|
|
4193
|
+
+ '<span class="tunnel-note">requires GitHub login</span>';
|
|
4194
|
+
};
|
|
4195
|
+
const refresh = () => apiGet("/tunnel/status").then((st) => render(st || {})).catch(() => {});
|
|
4196
|
+
wrap.addEventListener("click", (e) => {
|
|
4197
|
+
const act = e.target.getAttribute && e.target.getAttribute("data-act");
|
|
4198
|
+
if (!act) return;
|
|
4199
|
+
e.target.disabled = true;
|
|
4200
|
+
var call = act === "start" ? apiRequest("/tunnel/start", { method: "POST" })
|
|
4201
|
+
: act === "install" ? apiRequest("/tunnel/install-cloudflared", { method: "POST" })
|
|
4202
|
+
: apiRequest("/tunnel/stop", { method: "POST" });
|
|
4203
|
+
call.then(refresh).catch((err) => { wrap.querySelector(".tunnel-state").innerHTML = '<div class="tunnel-err">' + escapeHtml(String(err.message || err)) + "</div>"; });
|
|
4204
|
+
});
|
|
4205
|
+
refresh();
|
|
4206
|
+
setInterval(refresh, 5000);
|
|
4207
|
+
}
|
|
4208
|
+
// Script loads at end of body: DOM is already parsed - run immediately
|
|
4209
|
+
// (DOMContentLoaded may have already fired).
|
|
4210
|
+
initTunnelPanel();
|
|
3859
4211
|
})();
|
|
4212
|
+
|
|
4213
|
+
|
package/src/ui/index.html
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
<div class="header-status">
|
|
26
26
|
<span id="connection-status" class="status-dot disconnected"></span>
|
|
27
27
|
<button id="language-toggle" class="header-mini-btn" type="button">中文</button>
|
|
28
|
+
<button id="toast-settings-toggle" class="header-mini-btn" type="button" title="Toast notifications">Toasts</button>
|
|
28
29
|
<button id="worker-install-toggle" class="header-mini-btn" type="button" hidden>Add worker</button>
|
|
29
30
|
<span id="team-name">Team</span>
|
|
30
31
|
<button id="github-corner-login" class="header-mini-btn" type="button">Login</button>
|
|
@@ -130,6 +131,10 @@
|
|
|
130
131
|
|
|
131
132
|
<!-- Workspace Tab -->
|
|
132
133
|
<div id="tab-workspace" class="tab-panel">
|
|
134
|
+
<div class="tunnel-card" id="tunnel-panel">
|
|
135
|
+
<h3>Internet Tunnel</h3>
|
|
136
|
+
<div class="tunnel-state"><span class="tunnel-note">loading…</span></div>
|
|
137
|
+
</div>
|
|
133
138
|
<div class="workspace-browser">
|
|
134
139
|
<aside class="workspace-sidebar-panel">
|
|
135
140
|
<div class="workspace-panel-header">
|
package/src/ui/style.css
CHANGED
|
@@ -2551,3 +2551,12 @@ body {
|
|
|
2551
2551
|
.task-keyword-input { margin-left: auto; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border, #2a2f3a); background: var(--bg-primary); color: var(--text-primary); font-size: 12.5px; width: 200px; }
|
|
2552
2552
|
.task-keyword-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
|
|
2553
2553
|
.tasks-show-more { display: block; margin: 14px auto 4px; }
|
|
2554
|
+
|
|
2555
|
+
/* Tunnel sharing panel (workspace tab) */
|
|
2556
|
+
.tunnel-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-secondary); padding: 14px 18px; margin: 18px 0; }
|
|
2557
|
+
.tunnel-card h3 { font-size: 13px; margin-bottom: 8px; letter-spacing: .04em; text-transform: uppercase; color: var(--text-secondary); }
|
|
2558
|
+
.tunnel-on a { color: var(--accent); font-family: var(--mono); }
|
|
2559
|
+
.tunnel-token { margin: 8px 0; font-size: 13px; }
|
|
2560
|
+
.tunnel-token b { font-family: var(--mono); letter-spacing: .15em; color: var(--accent); }
|
|
2561
|
+
.tunnel-note { margin-left: 10px; color: var(--text-muted); font-size: 12px; }
|
|
2562
|
+
.tunnel-err { color: var(--danger); font-size: 12.5px; margin-top: 8px; }
|