@teamclaws/teamclaw 2026.11.0 → 2026.11.1

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.
Files changed (120) hide show
  1. package/cli.mjs +272 -2
  2. package/dist/index.js +54 -32
  3. package/dist/src/config.js +24 -0
  4. package/dist/src/controller/auth-routes.js +129 -0
  5. package/dist/src/controller/clarification-routes.js +1 -1
  6. package/dist/src/controller/controller-planning.js +1 -0
  7. package/dist/src/controller/controller-routes.js +195 -0
  8. package/dist/src/controller/controller-service.js +67 -10
  9. package/dist/src/controller/controller-tools.js +3 -1
  10. package/dist/src/controller/github-auth.js +2 -1
  11. package/dist/src/controller/http-server.js +51 -16
  12. package/dist/src/controller/kickoff-orchestrator.js +3 -39
  13. package/dist/src/controller/message-delivery.js +4 -1
  14. package/dist/src/controller/orchestration-manifest.js +5 -65
  15. package/dist/src/controller/preview-manager.js +51 -3
  16. package/dist/src/controller/profile-switch.js +42 -22
  17. package/dist/src/controller/provisioning/backend-contract.js +9 -0
  18. package/dist/src/controller/provisioning/container-shared.js +64 -0
  19. package/dist/src/controller/provisioning/docker.js +214 -0
  20. package/dist/src/controller/provisioning/kubernetes.js +244 -0
  21. package/dist/src/controller/provisioning/plugin-root.js +41 -0
  22. package/dist/src/controller/provisioning/process-supervisor.js +190 -0
  23. package/dist/src/controller/provisioning-config.js +239 -0
  24. package/dist/src/controller/repo-routes.js +70 -4
  25. package/dist/src/controller/report-routes.js +56 -0
  26. package/dist/src/controller/route-table.js +67 -1045
  27. package/dist/src/controller/security.js +775 -0
  28. package/dist/src/controller/status-routes.js +287 -0
  29. package/dist/src/controller/task-assignment.js +5 -2
  30. package/dist/src/controller/task-execution.js +31 -0
  31. package/dist/src/controller/task-results.js +10 -0
  32. package/dist/src/controller/tunnel-manager.js +41 -8
  33. package/dist/src/controller/tunnel-routes.js +225 -0
  34. package/dist/src/controller/websocket.js +6 -2
  35. package/dist/src/controller/webui-routes.js +49 -0
  36. package/dist/src/controller/worker-provisioning.js +39 -949
  37. package/dist/src/controller/workflow-routes.js +407 -0
  38. package/dist/src/controller/workspace-routes.js +200 -0
  39. package/dist/src/git-collaboration.js +4 -9
  40. package/dist/src/identity.js +12 -1
  41. package/dist/src/profile-loader.js +119 -1
  42. package/dist/src/profiles/banking.json +26 -2
  43. package/dist/src/profiles/schema.json +82 -2
  44. package/dist/src/prompt-policy.js +18 -6
  45. package/dist/src/protocol.js +66 -3
  46. package/dist/src/shared/clarification-schema.js +65 -0
  47. package/dist/src/shared/github-auth.js +15 -0
  48. package/dist/src/shared/kickoff-prompt.js +37 -0
  49. package/dist/src/shared/utils.js +47 -0
  50. package/dist/src/state.js +89 -3
  51. package/dist/src/types.js +15 -1
  52. package/dist/src/ui/app.js +846 -62
  53. package/dist/src/ui/github-login.html +1 -0
  54. package/dist/src/ui/index.html +102 -36
  55. package/dist/src/worker/http-handler.js +59 -0
  56. package/dist/src/worker/skill-installer.js +3 -9
  57. package/dist/src/worker/tools.js +20 -10
  58. package/dist/src/worker/worker-service.js +17 -4
  59. package/index.ts +61 -32
  60. package/openclaw.plugin.json +23 -2
  61. package/package.json +1 -1
  62. package/src/config.ts +24 -0
  63. package/src/controller/auth-routes.ts +157 -0
  64. package/src/controller/clarification-routes.ts +1 -1
  65. package/src/controller/controller-planning.ts +8 -0
  66. package/src/controller/controller-routes.ts +237 -0
  67. package/src/controller/controller-service.ts +128 -10
  68. package/src/controller/controller-tools.ts +5 -2
  69. package/src/controller/github-auth.ts +28 -63
  70. package/src/controller/http-server.ts +66 -17
  71. package/src/controller/kickoff-orchestrator.ts +3 -42
  72. package/src/controller/message-delivery.ts +4 -1
  73. package/src/controller/orchestration-manifest.ts +8 -71
  74. package/src/controller/preview-manager.ts +53 -3
  75. package/src/controller/profile-switch.ts +53 -23
  76. package/src/controller/provisioning/backend-contract.ts +51 -0
  77. package/src/controller/provisioning/container-shared.ts +84 -0
  78. package/src/controller/provisioning/docker.ts +260 -0
  79. package/src/controller/provisioning/kubernetes.ts +263 -0
  80. package/src/controller/provisioning/plugin-root.ts +42 -0
  81. package/src/controller/provisioning/process-supervisor.ts +214 -0
  82. package/src/controller/provisioning-config.ts +289 -0
  83. package/src/controller/repo-routes.ts +84 -12
  84. package/src/controller/report-routes.ts +64 -0
  85. package/src/controller/route-table.ts +133 -1152
  86. package/src/controller/security.ts +899 -0
  87. package/src/controller/status-routes.ts +354 -0
  88. package/src/controller/task-assignment.ts +5 -1
  89. package/src/controller/task-execution.ts +43 -0
  90. package/src/controller/task-results.ts +12 -0
  91. package/src/controller/tunnel-manager.ts +45 -8
  92. package/src/controller/tunnel-routes.ts +231 -0
  93. package/src/controller/websocket.ts +19 -3
  94. package/src/controller/webui-routes.ts +55 -0
  95. package/src/controller/worker-provisioning.ts +51 -1117
  96. package/src/controller/workflow-routes.ts +498 -0
  97. package/src/controller/workspace-routes.ts +222 -0
  98. package/src/git-collaboration.ts +4 -9
  99. package/src/identity.ts +13 -1
  100. package/src/profile-loader.ts +167 -1
  101. package/src/profiles/banking.json +26 -2
  102. package/src/profiles/schema.json +82 -2
  103. package/src/prompt-policy.ts +19 -6
  104. package/src/protocol.ts +72 -2
  105. package/src/shared/clarification-schema.ts +81 -0
  106. package/src/shared/github-auth.ts +92 -0
  107. package/src/shared/kickoff-prompt.ts +47 -0
  108. package/src/shared/utils.ts +51 -0
  109. package/src/state.ts +92 -3
  110. package/src/teamauto/github-client.ts +2 -1
  111. package/src/teamauto/repo-sync.ts +2 -1
  112. package/src/teamauto/scheduler.ts +2 -1
  113. package/src/types.ts +130 -1
  114. package/src/ui/app.js +846 -62
  115. package/src/ui/github-login.html +1 -0
  116. package/src/ui/index.html +102 -36
  117. package/src/worker/http-handler.ts +64 -1
  118. package/src/worker/skill-installer.ts +3 -9
  119. package/src/worker/tools.ts +21 -10
  120. package/src/worker/worker-service.ts +18 -4
@@ -0,0 +1,225 @@
1
+ import { sendJson, sendError } from "../protocol.js";
2
+ import { getGithubAuthManager } from "./github-auth.js";
3
+ import { gatePageHtml, computeGateCookie, GATE_COOKIE_NAME, selfHostedTokenFromEnv } from "./tunnel-manager.js";
4
+ import { isLanIp, isProtectionOn, secretsEqual } from "./security.js";
5
+ async function readFormBody(request) {
6
+ const chunks = [];
7
+ for await (const chunk of request)
8
+ chunks.push(chunk);
9
+ const raw = Buffer.concat(chunks).toString("utf8");
10
+ const out = {};
11
+ for (const [k, v] of new URLSearchParams(raw))
12
+ out[k] = v;
13
+ return out;
14
+ }
15
+ // ===========================================================================
16
+ // Tunnel-side route tables (pre-PR-D http-server.ts lines 348-432, the
17
+ // outer server callback's tunnel branch). These run BEFORE handleRequest
18
+ // and are split exactly along the old viaTunnel if/else:
19
+ // - viaTunnel: the gate page routes answer; every other tunnel request
20
+ // must pass the gate cookie (403 gate page), then continues to the
21
+ // controller route table;
22
+ // - direct (non-tunnel): the tunnel management API answers, everything
23
+ // else continues to the controller route table.
24
+ // ===========================================================================
25
+ // Issue #237 W3: online-guessing throttle for POST /__tunnel_gate/verify.
26
+ // The endpoint answers on the PUBLIC tunnel URL, so repeated failures cool
27
+ // the gate down. Deliberately GLOBAL (not per-IP): every via-tunnel request
28
+ // arrives from the local cloudflared socket, so a per-IP key would collapse
29
+ // to one bucket for the whole internet anyway - this mirrors the pairing
30
+ // code throttle in security.ts (timestamps pruned against a sliding window).
31
+ const GATE_VERIFY_FAILURE_MAX = 10;
32
+ const GATE_VERIFY_COOLDOWN_MS = 60_000;
33
+ const gateVerifyFailures = [];
34
+ function gateVerifyThrottled() {
35
+ const now = Date.now();
36
+ while (gateVerifyFailures.length > 0 && now - gateVerifyFailures[0] >= GATE_VERIFY_COOLDOWN_MS) {
37
+ gateVerifyFailures.shift();
38
+ }
39
+ return gateVerifyFailures.length >= GATE_VERIFY_FAILURE_MAX;
40
+ }
41
+ function recordGateVerifyFailure() {
42
+ gateVerifyFailures.push(Date.now());
43
+ }
44
+ /** GET /__tunnel_gate + GET / + POST /__tunnel_gate/verify (via tunnel only). */
45
+ export function createTunnelGateRoutes(tunnelManager) {
46
+ return [
47
+ {
48
+ method: "GET",
49
+ path: "/__tunnel_gate",
50
+ handler: ({ res, req }) => {
51
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
52
+ res.end(gatePageHtml(String(req.headers.host), false));
53
+ },
54
+ },
55
+ {
56
+ // Valid gate cookie on "/" goes straight to the dashboard; the gate
57
+ // page only greets visitors who have not authenticated yet.
58
+ method: "GET",
59
+ path: "/",
60
+ handler: ({ res, req, pathname }) => {
61
+ if (pathname === "/" && tunnelManager.gateAllows(req)) {
62
+ res.writeHead(302, { Location: "/ui/" });
63
+ res.end();
64
+ return;
65
+ }
66
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
67
+ res.end(gatePageHtml(String(req.headers.host), false));
68
+ },
69
+ },
70
+ {
71
+ method: "POST",
72
+ path: "/__tunnel_gate/verify",
73
+ handler: async ({ res, req }) => {
74
+ // Issue #237 W3: check the throttle BEFORE touching the token - a
75
+ // cooled-down gate answers 429 without comparing anything, so
76
+ // brute-force attempts cannot outrun the cooldown.
77
+ if (gateVerifyThrottled()) {
78
+ res.setHeader("Retry-After", "60");
79
+ sendJson(res, 429, { error: "Too many gate verification attempts. Wait a minute and try again." });
80
+ return;
81
+ }
82
+ const form = await readFormBody(req);
83
+ // Issue #237 W3: gate tokens are 128-bit base64url and therefore
84
+ // case-sensitive - only surrounding whitespace is normalized (the
85
+ // old .toUpperCase() fold belonged to the retired 8-char token).
86
+ const submitted = String(form.token ?? "").trim();
87
+ const st = tunnelManager.status();
88
+ // Issue #237 W3: constant-time comparison (plain === was
89
+ // timing-leaky on this internet-reachable endpoint).
90
+ if (st.active && st.gateToken && secretsEqual(submitted, st.gateToken)) {
91
+ const cookie = `${GATE_COOKIE_NAME}=${computeGateCookie(st.gateToken, st.tunnelId ?? "")}; Path=/; Max-Age=43200; HttpOnly; SameSite=Lax`;
92
+ res.writeHead(302, { "Set-Cookie": cookie, Location: "/" });
93
+ res.end();
94
+ return;
95
+ }
96
+ recordGateVerifyFailure();
97
+ res.writeHead(403, { "Content-Type": "text/html; charset=utf-8" });
98
+ res.end(gatePageHtml(String(req.headers.host), true));
99
+ },
100
+ },
101
+ ];
102
+ }
103
+ /** /api/v1/tunnel/* management API (direct requests only, never via tunnel). */
104
+ export function createTunnelManagementRoutes(tunnelManager, deps) {
105
+ const { config, logger } = deps;
106
+ // Issue #222 (coordinated scope): creating a public tunnel is an
107
+ // internet-EXPOSURE escalation, so in L0 (protection off) the three start
108
+ // endpoints accept only loopback/LAN origins - a public-network peer that
109
+ // merely reached the port must never be able to open a share URL into
110
+ // this controller. While protection is on, the device gate in
111
+ // http-server.ts has already authenticated the caller (#23) and stays the
112
+ // governing rule: a deliberately paired device may share, including
113
+ // remotely. Loopback/LAN classification reuses the security module's
114
+ // isLanIp (via-tunnel requests never reach this table - they dispatch to
115
+ // the gate table instead - so the raw socket peer is authoritative).
116
+ const tunnelStartAllowedFrom = (req, res) => {
117
+ if (isProtectionOn(deps.getTeamState())) {
118
+ return true;
119
+ }
120
+ if (isLanIp(req.socket.remoteAddress)) {
121
+ return true;
122
+ }
123
+ sendJson(res, 403, {
124
+ error: "forbidden",
125
+ hint: "Creating a public tunnel exposes this controller to the internet. Start tunnels from the controller host (loopback or LAN), or enable device pairing (POST /api/v1/security/enable from the controller host) and share from a paired device.",
126
+ });
127
+ return false;
128
+ };
129
+ return [
130
+ {
131
+ method: "GET",
132
+ path: "/api/v1/tunnel/status",
133
+ handler: ({ res }) => {
134
+ sendJson(res, 200, tunnelManager.status());
135
+ },
136
+ },
137
+ {
138
+ method: "POST",
139
+ path: "/api/v1/tunnel/start",
140
+ handler: async ({ req, res }) => {
141
+ if (!tunnelStartAllowedFrom(req, res)) {
142
+ return;
143
+ }
144
+ const authStatus = await getGithubAuthManager(config, logger).getStatus();
145
+ const account = authStatus.account;
146
+ if (!account?.login) {
147
+ sendError(res, 401, "GitHub login required to share a tunnel");
148
+ return;
149
+ }
150
+ // Async launch: poll /tunnel/status for phase progress and the
151
+ // resulting hostname/gateToken once startOp.phase === "done".
152
+ const launched = tunnelManager.start(account.login);
153
+ sendJson(res, 202, { launched, status: tunnelManager.status() });
154
+ },
155
+ },
156
+ {
157
+ // Self-hosted: user-owned Cloudflare tunnel via connector token (no
158
+ // GitHub login, no platform tunnel server). Token from the request
159
+ // body, or the TEAMCLAW_TUNNEL_TOKEN env injection when body is empty.
160
+ method: "POST",
161
+ path: "/api/v1/tunnel/start-self-hosted",
162
+ handler: async ({ req, res }) => {
163
+ if (!tunnelStartAllowedFrom(req, res)) {
164
+ return;
165
+ }
166
+ let token = "";
167
+ try {
168
+ const body = await readFormBody(req);
169
+ token = String(body.token ?? "");
170
+ }
171
+ catch { /* fall through to env */ }
172
+ if (!token.trim()) {
173
+ const envToken = selfHostedTokenFromEnv();
174
+ if (!envToken) {
175
+ sendError(res, 400, "connector token required (or set TEAMCLAW_TUNNEL_TOKEN)");
176
+ return;
177
+ }
178
+ token = envToken;
179
+ }
180
+ const r = tunnelManager.startSelfHosted(token);
181
+ if (!r.launched) {
182
+ sendError(res, 400, r.error ?? "failed to start self-hosted tunnel");
183
+ return;
184
+ }
185
+ sendJson(res, 202, { launched: true, status: tunnelManager.status() });
186
+ },
187
+ },
188
+ {
189
+ method: "POST",
190
+ path: "/api/v1/tunnel/start-quick",
191
+ handler: ({ req, res }) => {
192
+ if (!tunnelStartAllowedFrom(req, res)) {
193
+ return;
194
+ }
195
+ const r = tunnelManager.startQuick();
196
+ if (!r.launched) {
197
+ sendError(res, 400, r.error ?? "failed to start quick tunnel");
198
+ return;
199
+ }
200
+ sendJson(res, 202, { launched: true, status: tunnelManager.status() });
201
+ },
202
+ },
203
+ {
204
+ method: "POST",
205
+ path: "/api/v1/tunnel/stop",
206
+ handler: async ({ res }) => {
207
+ await tunnelManager.stop();
208
+ sendJson(res, 200, tunnelManager.status());
209
+ },
210
+ },
211
+ {
212
+ method: "POST",
213
+ path: "/api/v1/tunnel/install-cloudflared",
214
+ handler: async ({ res }) => {
215
+ try {
216
+ const result = await tunnelManager.installCloudflared();
217
+ sendJson(res, result.ok ? 200 : 500, { ...result, status: tunnelManager.status() });
218
+ }
219
+ catch (err) {
220
+ sendError(res, 500, err instanceof Error ? err.message : "install failed");
221
+ }
222
+ },
223
+ },
224
+ ];
225
+ }
@@ -5,8 +5,12 @@ export class TeamWebSocketServer {
5
5
  constructor(logger) {
6
6
  this.logger = logger;
7
7
  }
8
- attach(server) {
9
- this.wss = new WebSocketServer({ server, path: "/ws" });
8
+ attach(server, options) {
9
+ this.wss = new WebSocketServer({
10
+ server,
11
+ path: "/ws",
12
+ ...(options?.verifyUpgrade ? { verifyClient: (info) => options.verifyUpgrade(info.req) } : {}),
13
+ });
10
14
  this.wss.on("connection", (ws) => {
11
15
  this.logger.info("WebSocket: client connected");
12
16
  ws.on("close", () => {
@@ -0,0 +1,49 @@
1
+ // Issue #226 W2 (route-table carve-up): the Web UI static-serving handlers
2
+ // moved verbatim from route-table.ts (PR-D had moved them verbatim from
3
+ // http-server.ts before that) - bodies byte-identical, only the module home
4
+ // changed. route-table.ts keeps the table entries that bind these handlers.
5
+ // Like security.ts, this module imports route-table.js as TYPE ONLY
6
+ // (RouteContext), so the module graph stays acyclic.
7
+ import path from "node:path";
8
+ import { serveStaticFile, serveVersionedHtml } from "./ui-assets.js";
9
+ function webUiRootRoute(ctx) {
10
+ const { res } = ctx;
11
+ res.statusCode = 302;
12
+ res.setHeader("Location", "/ui");
13
+ res.end();
14
+ }
15
+ function webUiIndexRoute(ctx) {
16
+ const { res } = ctx;
17
+ const uiPath = path.join(import.meta.dirname, "..", "ui");
18
+ serveVersionedHtml(res, path.join(uiPath, "index.html"));
19
+ }
20
+ // Standalone GitHub device-login page (big user code + prefilled link + polling).
21
+ function webUiGithubLoginPageRoute(ctx) {
22
+ const { res } = ctx;
23
+ const uiPath = path.join(import.meta.dirname, "..", "ui");
24
+ serveStaticFile(res, path.join(uiPath, "github-login.html"), "text/html; charset=utf-8");
25
+ }
26
+ function webUiAssetsRoute(ctx) {
27
+ const { res, pathname } = ctx;
28
+ const uiPath = path.join(import.meta.dirname, "..", "ui");
29
+ const file = pathname.slice(4); // remove "/ui/"
30
+ if (file.endsWith(".css")) {
31
+ serveStaticFile(res, path.join(uiPath, file), "text/css; charset=utf-8");
32
+ }
33
+ else if (file.endsWith(".js")) {
34
+ serveStaticFile(res, path.join(uiPath, file), "application/javascript; charset=utf-8");
35
+ }
36
+ else if (file.endsWith(".png")) {
37
+ serveStaticFile(res, path.join(uiPath, file), "image/png");
38
+ }
39
+ else if (file.endsWith(".svg")) {
40
+ serveStaticFile(res, path.join(uiPath, file), "image/svg+xml; charset=utf-8");
41
+ }
42
+ else if (file.endsWith(".ico")) {
43
+ serveStaticFile(res, path.join(uiPath, file), "image/x-icon");
44
+ }
45
+ else {
46
+ serveStaticFile(res, path.join(uiPath, file), "application/octet-stream");
47
+ }
48
+ }
49
+ export { webUiRootRoute, webUiIndexRoute, webUiGithubLoginPageRoute, webUiAssetsRoute, };