@teamclaws/teamclaw 2026.8.1 → 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 (184) hide show
  1. package/cli.mjs +318 -17
  2. package/dist/index.js +54 -32
  3. package/dist/src/config.js +57 -2
  4. package/dist/src/controller/auth-routes.js +129 -0
  5. package/dist/src/controller/clarification-routes.js +315 -0
  6. package/dist/src/controller/controller-intake.js +895 -0
  7. package/dist/src/controller/controller-planning.js +814 -0
  8. package/dist/src/controller/controller-routes.js +195 -0
  9. package/dist/src/controller/controller-runs.js +175 -0
  10. package/dist/src/controller/controller-service.js +338 -50
  11. package/dist/src/controller/controller-tools.js +14 -7
  12. package/dist/src/controller/github-auth.js +2 -1
  13. package/dist/src/controller/http-server.js +290 -6003
  14. package/dist/src/controller/kickoff-orchestrator.js +33 -43
  15. package/dist/src/controller/message-delivery.js +31 -0
  16. package/dist/src/controller/message-routes.js +114 -0
  17. package/dist/src/controller/orchestration-manifest.js +11 -93
  18. package/dist/src/controller/preview-manager.js +51 -3
  19. package/dist/src/controller/preview-proxy.js +98 -0
  20. package/dist/src/controller/profile-switch.js +309 -0
  21. package/dist/src/controller/project-registry.js +294 -0
  22. package/dist/src/controller/prompt-injector.js +19 -9
  23. package/dist/src/controller/provisioning/backend-contract.js +9 -0
  24. package/dist/src/controller/provisioning/container-shared.js +64 -0
  25. package/dist/src/controller/provisioning/docker.js +214 -0
  26. package/dist/src/controller/provisioning/kubernetes.js +244 -0
  27. package/dist/src/controller/provisioning/plugin-root.js +41 -0
  28. package/dist/src/controller/provisioning/process-supervisor.js +190 -0
  29. package/dist/src/controller/provisioning-config.js +239 -0
  30. package/dist/src/controller/repo-routes.js +129 -0
  31. package/dist/src/controller/report-routes.js +56 -0
  32. package/dist/src/controller/role-inference.js +231 -20
  33. package/dist/src/controller/route-table.js +375 -0
  34. package/dist/src/controller/security.js +775 -0
  35. package/dist/src/controller/status-routes.js +287 -0
  36. package/dist/src/controller/task-assignment.js +511 -0
  37. package/dist/src/controller/task-cleanup.js +258 -0
  38. package/dist/src/controller/task-execution.js +271 -0
  39. package/dist/src/controller/task-results.js +471 -0
  40. package/dist/src/controller/task-router.js +74 -4
  41. package/dist/src/controller/task-routes.js +703 -0
  42. package/dist/src/controller/teamauto-routes.js +124 -0
  43. package/dist/src/controller/tunnel-manager.js +41 -8
  44. package/dist/src/controller/tunnel-routes.js +225 -0
  45. package/dist/src/controller/ui-assets.js +68 -0
  46. package/dist/src/controller/websocket.js +6 -2
  47. package/dist/src/controller/webui-routes.js +49 -0
  48. package/dist/src/controller/worker-provisioning.js +69 -953
  49. package/dist/src/controller/worker-routes.js +188 -0
  50. package/dist/src/controller/workflow-routes.js +407 -0
  51. package/dist/src/controller/workspace-routes.js +200 -0
  52. package/dist/src/git-collaboration.js +4 -9
  53. package/dist/src/identity.js +15 -3
  54. package/dist/src/interaction-contracts.js +7 -7
  55. package/dist/src/openclaw-workspace.js +40 -18
  56. package/dist/src/profile-loader.js +604 -0
  57. package/dist/src/profiles/banking.json +202 -0
  58. package/dist/src/profiles/crossborder-ecom.json +253 -0
  59. package/dist/src/profiles/insurance.json +157 -0
  60. package/dist/src/profiles/knowledge/hs-structure.md +97 -0
  61. package/dist/src/profiles/knowledge/incoterms-2020.md +188 -0
  62. package/dist/src/profiles/knowledge/vat-principles.md +85 -0
  63. package/dist/src/profiles/schema.json +281 -0
  64. package/dist/src/profiles/securities.json +137 -0
  65. package/dist/src/profiles/software-rd.json +264 -0
  66. package/dist/src/profiles/trading-co.json +200 -0
  67. package/dist/src/prompt-policy.js +42 -17
  68. package/dist/src/protocol.js +66 -3
  69. package/dist/src/role-ids.js +29 -0
  70. package/dist/src/roles.js +54 -13
  71. package/dist/src/session-roles.js +14 -0
  72. package/dist/src/shared/clarification-schema.js +65 -0
  73. package/dist/src/shared/github-auth.js +15 -0
  74. package/dist/src/shared/kickoff-prompt.js +37 -0
  75. package/dist/src/shared/utils.js +47 -0
  76. package/dist/src/state.js +275 -11
  77. package/dist/src/task-executor.js +7 -17
  78. package/dist/src/teamauto/github-client.js +18 -0
  79. package/dist/src/teamauto/repo-sync.js +228 -6
  80. package/dist/src/teamauto/scanner.js +40 -12
  81. package/dist/src/teamauto/scheduler.js +231 -12
  82. package/dist/src/types.js +77 -16
  83. package/dist/src/ui/app.js +1434 -82
  84. package/dist/src/ui/github-login.html +1 -0
  85. package/dist/src/ui/index.html +144 -45
  86. package/dist/src/ui/style.css +194 -0
  87. package/dist/src/worker/http-handler.js +59 -0
  88. package/dist/src/worker/prompt-injector.js +44 -8
  89. package/dist/src/worker/skill-installer.js +6 -10
  90. package/dist/src/worker/tools.js +20 -10
  91. package/dist/src/worker/worker-service.js +93 -7
  92. package/index.ts +61 -32
  93. package/openclaw.plugin.json +50 -2
  94. package/package.json +3 -2
  95. package/src/config.ts +57 -2
  96. package/src/controller/auth-routes.ts +157 -0
  97. package/src/controller/clarification-routes.ts +404 -0
  98. package/src/controller/controller-intake.ts +1113 -0
  99. package/src/controller/controller-planning.ts +1037 -0
  100. package/src/controller/controller-routes.ts +237 -0
  101. package/src/controller/controller-runs.ts +239 -0
  102. package/src/controller/controller-service.ts +422 -50
  103. package/src/controller/controller-tools.ts +16 -9
  104. package/src/controller/github-auth.ts +28 -63
  105. package/src/controller/http-server.ts +336 -6964
  106. package/src/controller/kickoff-orchestrator.ts +69 -45
  107. package/src/controller/message-delivery.ts +52 -0
  108. package/src/controller/message-routes.ts +137 -0
  109. package/src/controller/orchestration-manifest.ts +14 -100
  110. package/src/controller/preview-manager.ts +53 -3
  111. package/src/controller/preview-proxy.ts +127 -0
  112. package/src/controller/profile-switch.ts +396 -0
  113. package/src/controller/project-registry.ts +361 -0
  114. package/src/controller/prompt-injector.ts +23 -8
  115. package/src/controller/provisioning/backend-contract.ts +51 -0
  116. package/src/controller/provisioning/container-shared.ts +84 -0
  117. package/src/controller/provisioning/docker.ts +260 -0
  118. package/src/controller/provisioning/kubernetes.ts +263 -0
  119. package/src/controller/provisioning/plugin-root.ts +42 -0
  120. package/src/controller/provisioning/process-supervisor.ts +214 -0
  121. package/src/controller/provisioning-config.ts +289 -0
  122. package/src/controller/repo-routes.ts +163 -0
  123. package/src/controller/report-routes.ts +64 -0
  124. package/src/controller/role-inference.ts +260 -22
  125. package/src/controller/route-table.ts +597 -0
  126. package/src/controller/security.ts +899 -0
  127. package/src/controller/status-routes.ts +354 -0
  128. package/src/controller/task-assignment.ts +622 -0
  129. package/src/controller/task-cleanup.ts +344 -0
  130. package/src/controller/task-execution.ts +399 -0
  131. package/src/controller/task-results.ts +556 -0
  132. package/src/controller/task-router.ts +98 -6
  133. package/src/controller/task-routes.ts +812 -0
  134. package/src/controller/teamauto-routes.ts +121 -0
  135. package/src/controller/tunnel-manager.ts +45 -8
  136. package/src/controller/tunnel-routes.ts +231 -0
  137. package/src/controller/ui-assets.ts +70 -0
  138. package/src/controller/websocket.ts +32 -4
  139. package/src/controller/webui-routes.ts +55 -0
  140. package/src/controller/worker-provisioning.ts +83 -1121
  141. package/src/controller/worker-routes.ts +241 -0
  142. package/src/controller/workflow-routes.ts +498 -0
  143. package/src/controller/workspace-routes.ts +222 -0
  144. package/src/git-collaboration.ts +4 -9
  145. package/src/identity.ts +16 -3
  146. package/src/interaction-contracts.ts +7 -7
  147. package/src/openclaw-workspace.ts +44 -18
  148. package/src/profile-loader.ts +816 -0
  149. package/src/profiles/banking.json +202 -0
  150. package/src/profiles/crossborder-ecom.json +253 -0
  151. package/src/profiles/insurance.json +157 -0
  152. package/src/profiles/knowledge/hs-structure.md +97 -0
  153. package/src/profiles/knowledge/incoterms-2020.md +188 -0
  154. package/src/profiles/knowledge/vat-principles.md +85 -0
  155. package/src/profiles/schema.json +281 -0
  156. package/src/profiles/securities.json +137 -0
  157. package/src/profiles/software-rd.json +264 -0
  158. package/src/profiles/trading-co.json +200 -0
  159. package/src/prompt-policy.ts +44 -17
  160. package/src/protocol.ts +72 -2
  161. package/src/role-ids.ts +31 -0
  162. package/src/roles.ts +60 -14
  163. package/src/session-roles.ts +14 -0
  164. package/src/shared/clarification-schema.ts +81 -0
  165. package/src/shared/github-auth.ts +92 -0
  166. package/src/shared/kickoff-prompt.ts +47 -0
  167. package/src/shared/utils.ts +51 -0
  168. package/src/state.ts +326 -10
  169. package/src/task-executor.ts +7 -18
  170. package/src/teamauto/github-client.ts +23 -1
  171. package/src/teamauto/repo-sync.ts +248 -7
  172. package/src/teamauto/scanner.ts +47 -13
  173. package/src/teamauto/scheduler.ts +261 -17
  174. package/src/teamauto/store.ts +12 -0
  175. package/src/types.ts +263 -17
  176. package/src/ui/app.js +1434 -82
  177. package/src/ui/github-login.html +1 -0
  178. package/src/ui/index.html +144 -45
  179. package/src/ui/style.css +194 -0
  180. package/src/worker/http-handler.ts +64 -1
  181. package/src/worker/prompt-injector.ts +48 -8
  182. package/src/worker/skill-installer.ts +6 -10
  183. package/src/worker/tools.ts +21 -10
  184. package/src/worker/worker-service.ts +101 -7
@@ -0,0 +1,241 @@
1
+ // PR-C of issue #204 (http-server monolith split): the worker lifecycle
2
+ // routes (register/heartbeat/delete/list) and the startup provisioning
3
+ // readiness gate extracted verbatim from controller/http-server.ts. Zero
4
+ // behavior change - the route shells in http-server keep the method+pathname
5
+ // matches and call these handlers with the same deps object as before. This
6
+ // module must NEVER import http-server (the reverse edge exists:
7
+ // http-server -> worker-routes).
8
+ import type { IncomingMessage, ServerResponse } from "node:http";
9
+ import type {
10
+ StartupProvisioningReadiness,
11
+ TeamState,
12
+ WorkerInfo,
13
+ } from "../types.js";
14
+ import { parseJsonBody, sendError, sendJson } from "../protocol.js";
15
+ import {
16
+ getActiveDefaultRole,
17
+ getActiveProfileId,
18
+ getActiveRoleIds,
19
+ validateActiveRoleId,
20
+ } from "../profile-loader.js";
21
+ import {
22
+ resetTaskForFreshAttempt,
23
+ serializeTask,
24
+ type ControllerTaskDomainDeps,
25
+ } from "./task-execution.js";
26
+ import { autoAssignPendingTasks, scheduleProvisioningReconcile } from "./task-assignment.js";
27
+
28
+ // POST /api/v1/workers/register
29
+ export async function handleWorkerRegisterRequest(deps: ControllerTaskDomainDeps, req: IncomingMessage, res: ServerResponse): Promise<void> {
30
+ const { logger, updateTeamState, wsServer } = deps;
31
+ const body = await parseJsonBody(req);
32
+ const workerId = typeof body.workerId === "string" ? body.workerId : "";
33
+ const rawRole = typeof body.role === "string" ? body.role.trim() : "";
34
+ const role = validateActiveRoleId(rawRole) ?? "";
35
+ const label = typeof body.label === "string" ? body.label : role;
36
+ const workerUrl = typeof body.url === "string" ? body.url : "";
37
+ const capabilities = Array.isArray(body.capabilities) ? body.capabilities as string[] : [];
38
+ const launchToken = typeof body.launchToken === "string" ? body.launchToken : undefined;
39
+
40
+ if (!workerId || !role || !workerUrl) {
41
+ // Issue #192: a role string that the ACTIVE profile does not know is
42
+ // the actionable failure (worker config carried an id from another
43
+ // profile, or the team switched profiles underneath the worker) - say
44
+ // so with the valid id list instead of the generic "required" 400.
45
+ if (workerId && !role && workerUrl && rawRole) {
46
+ sendError(
47
+ res,
48
+ 400,
49
+ `role "${rawRole}" is not part of the active team profile "${getActiveProfileId()}" (valid roles: ${getActiveRoleIds().join(", ")}). ` +
50
+ "Update the worker's role config to one of these roles, or have the controller switch the team profile.",
51
+ );
52
+ return;
53
+ }
54
+ sendError(res, 400, "workerId, role, and url are required");
55
+ return;
56
+ }
57
+
58
+ const registrationValidation = deps.workerProvisioningManager?.validateRegistration(workerId, role, launchToken);
59
+ if (registrationValidation && !registrationValidation.ok) {
60
+ sendError(res, 403, registrationValidation.reason ?? "Worker registration rejected");
61
+ return;
62
+ }
63
+
64
+ const state = updateTeamState((s) => {
65
+ s.workers[workerId] = {
66
+ id: workerId,
67
+ role,
68
+ label,
69
+ status: "idle",
70
+ transport: "http",
71
+ url: workerUrl,
72
+ lastHeartbeat: Date.now(),
73
+ capabilities,
74
+ registeredAt: Date.now(),
75
+ };
76
+ });
77
+ deps.workerProvisioningManager?.onWorkerRegistered(workerId);
78
+
79
+ wsServer.broadcastUpdate({ type: "worker:online", data: state.workers[workerId] });
80
+ logger.info(`Controller: worker registered - ${label} (${workerId}) at ${workerUrl}`);
81
+ sendJson(res, 201, { status: "registered", worker: state.workers[workerId] });
82
+ void autoAssignPendingTasks(deps, workerId).catch((err) => {
83
+ logger.warn(`Controller: failed to auto-assign after worker registration (${workerId}): ${String(err)}`);
84
+ });
85
+ }
86
+
87
+ // DELETE /api/v1/workers/:id
88
+ export async function handleWorkerDeleteRequest(deps: ControllerTaskDomainDeps, res: ServerResponse, pathname: string): Promise<void> {
89
+ const { logger, getTeamState, updateTeamState, wsServer } = deps;
90
+ const workerId = pathname.split("/").pop()!;
91
+ if (deps.workerProvisioningManager?.hasManagedWorker(workerId)) {
92
+ await deps.workerProvisioningManager.onWorkerRemoved(workerId, "worker delete requested");
93
+ }
94
+
95
+ const affectedTaskIds: string[] = [];
96
+ updateTeamState((s) => {
97
+ const worker = s.workers[workerId];
98
+ if (worker) {
99
+ worker.status = "offline";
100
+ worker.currentTaskId = undefined;
101
+ delete s.workers[workerId];
102
+ }
103
+
104
+ for (const task of Object.values(s.tasks)) {
105
+ if (
106
+ task.assignedWorkerId === workerId &&
107
+ task.status !== "completed" &&
108
+ task.status !== "failed" &&
109
+ task.status !== "blocked"
110
+ ) {
111
+ task.status = "pending";
112
+ task.assignedWorkerId = undefined;
113
+ resetTaskForFreshAttempt(task);
114
+ task.updatedAt = Date.now();
115
+ affectedTaskIds.push(task.id);
116
+ }
117
+ }
118
+ });
119
+
120
+ await autoAssignPendingTasks(deps);
121
+ for (const taskId of affectedTaskIds) {
122
+ const task = getTeamState()?.tasks[taskId];
123
+ if (task) {
124
+ wsServer.broadcastUpdate({ type: "task:updated", data: serializeTask(task) });
125
+ }
126
+ }
127
+ wsServer.broadcastUpdate({ type: "worker:offline", data: { workerId } });
128
+ logger.info(`Controller: worker removed - ${workerId}`);
129
+ sendJson(res, 200, { status: "removed" });
130
+ }
131
+
132
+ // GET /api/v1/workers
133
+ export async function handleWorkerListRequest(deps: ControllerTaskDomainDeps, res: ServerResponse): Promise<void> {
134
+ const { getTeamState } = deps;
135
+ const state = getTeamState();
136
+ const workers = state
137
+ ? Object.values(state.workers).map((worker) => ({
138
+ ...worker,
139
+ // Ghost rows from previous gateway processes (provisioned workers
140
+ // die with the process they ran in). The controller cleans these on
141
+ // startup; the flag lets the UI mark leftovers as removable.
142
+ staleRemovable: worker.id.startsWith("provisioned-") && worker.status === "offline",
143
+ }))
144
+ : [];
145
+ sendJson(res, 200, { workers });
146
+ }
147
+
148
+ // POST /api/v1/workers/:id/heartbeat
149
+ export async function handleWorkerHeartbeatRequest(deps: ControllerTaskDomainDeps, req: IncomingMessage, res: ServerResponse, pathname: string): Promise<void> {
150
+ const { updateTeamState } = deps;
151
+ const workerId = pathname.split("/")[4]!;
152
+ const body = await parseJsonBody(req);
153
+ const status = typeof body.status === "string" ? body.status as WorkerInfo["status"] : "idle";
154
+ const currentTaskId = typeof body.currentTaskId === "string" ? body.currentTaskId : undefined;
155
+
156
+ updateTeamState((s) => {
157
+ if (s.workers[workerId]) {
158
+ s.workers[workerId].lastHeartbeat = Date.now();
159
+ s.workers[workerId].status = status;
160
+ s.workers[workerId].currentTaskId = currentTaskId;
161
+ }
162
+ });
163
+ deps.workerProvisioningManager?.onWorkerHeartbeat(workerId, status);
164
+
165
+ if (status === "idle") {
166
+ await autoAssignPendingTasks(deps, workerId);
167
+ } else {
168
+ scheduleProvisioningReconcile(deps, `heartbeat:${workerId}:${status}`);
169
+ }
170
+ sendJson(res, 200, { status: "ok" });
171
+ }
172
+
173
+ export function getEffectiveStartupReadiness(
174
+ deps: ControllerTaskDomainDeps,
175
+ state: TeamState | null,
176
+ ): StartupProvisioningReadiness | null {
177
+ if (!deps.workerProvisioningManager?.isEnabled()) {
178
+ return null;
179
+ }
180
+ // Both branches are already-validated RoleId sources: config roles go
181
+ // through parseRoleList (validateRoleIdList) and the fallback is the
182
+ // active profile's defaultRole — no runtime validation needed here.
183
+ const requiredRoles = deps.config.workerProvisioningRoles.length > 0
184
+ ? [...new Set(deps.config.workerProvisioningRoles)]
185
+ : [getActiveDefaultRole()];
186
+ const readyWorkerIds = requiredRoles
187
+ .map((role) => Object.values(state?.workers ?? {}).find((worker) =>
188
+ worker.role === role && (worker.status === "idle" || worker.status === "busy")
189
+ )?.id)
190
+ .filter((workerId): workerId is string => Boolean(workerId));
191
+
192
+ if (readyWorkerIds.length === requiredRoles.length) {
193
+ const recorded = state?.provisioning?.startupReadiness;
194
+ return {
195
+ status: "ready",
196
+ startedAt: recorded?.startedAt ?? state?.createdAt ?? Date.now(),
197
+ checkedAt: Date.now(),
198
+ attempts: recorded?.attempts ?? 0,
199
+ requiredRoles,
200
+ readyWorkerIds,
201
+ message: recorded?.status === "ready"
202
+ ? recorded.message
203
+ : `Startup provisioning ready with ${readyWorkerIds.length} warm worker(s).`,
204
+ };
205
+ }
206
+
207
+ return state?.provisioning?.startupReadiness ?? {
208
+ status: "checking",
209
+ startedAt: state?.createdAt ?? Date.now(),
210
+ checkedAt: Date.now(),
211
+ attempts: 0,
212
+ requiredRoles,
213
+ readyWorkerIds,
214
+ message: `Startup provisioning warm-up is still initializing for ${requiredRoles.join(", ")}.`,
215
+ };
216
+ }
217
+
218
+ export function buildStartupReadinessMessage(readiness: StartupProvisioningReadiness): string {
219
+ const requiredRoles = readiness.requiredRoles.length > 0 ? readiness.requiredRoles.join(", ") : "configured startup roles";
220
+ if (readiness.status === "ready") {
221
+ return readiness.message ?? "Startup provisioning is ready.";
222
+ }
223
+ if (readiness.status === "checking") {
224
+ return readiness.message ?? `Startup provisioning is still warming workers for ${requiredRoles}.`;
225
+ }
226
+ return readiness.message ?? `Startup provisioning is degraded for ${requiredRoles}. Check provisioning logs and fix worker startup before retrying.`;
227
+ }
228
+
229
+ export function shouldBlockControllerUntilProvisioningReady(
230
+ deps: ControllerTaskDomainDeps,
231
+ state: TeamState | null,
232
+ ): { blocked: boolean; readiness: StartupProvisioningReadiness | null } {
233
+ const readiness = getEffectiveStartupReadiness(deps, state);
234
+ if (!readiness) {
235
+ return { blocked: false, readiness: null };
236
+ }
237
+ return {
238
+ blocked: readiness.status !== "ready",
239
+ readiness,
240
+ };
241
+ }