@teamclaws/teamclaw 2026.8.0 → 2026.11.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/cli.mjs +46 -15
- package/dist/api.js +1 -0
- package/dist/index.js +325 -0
- package/dist/src/config.js +412 -0
- package/dist/src/controller/clarification-routes.js +315 -0
- package/dist/src/controller/controller-capacity.js +14 -0
- package/dist/src/controller/controller-intake.js +895 -0
- package/dist/src/controller/controller-planning.js +813 -0
- package/dist/src/controller/controller-runs.js +175 -0
- package/dist/src/controller/controller-service.js +624 -0
- package/dist/src/controller/controller-tools.js +587 -0
- package/dist/src/controller/delivery-report.js +458 -0
- package/dist/src/controller/github-auth.js +564 -0
- package/dist/src/controller/http-server.js +284 -0
- package/dist/src/controller/kickoff-orchestrator.js +246 -0
- package/dist/src/controller/managed-gateway-process.js +286 -0
- package/dist/src/controller/message-delivery.js +28 -0
- package/dist/src/controller/message-router.js +38 -0
- package/dist/src/controller/message-routes.js +114 -0
- package/dist/src/controller/orchestration-manifest.js +151 -0
- package/dist/src/controller/preview-manager.js +586 -0
- package/dist/src/controller/preview-proxy.js +98 -0
- package/dist/src/controller/profile-switch.js +289 -0
- package/dist/src/controller/project-registry.js +294 -0
- package/dist/src/controller/prompt-injector.js +197 -0
- package/dist/src/controller/repo-routes.js +63 -0
- package/dist/src/controller/role-inference.js +246 -0
- package/dist/src/controller/route-table.js +1353 -0
- package/dist/src/controller/task-assignment.js +508 -0
- package/dist/src/controller/task-cleanup.js +258 -0
- package/dist/src/controller/task-execution.js +240 -0
- package/dist/src/controller/task-results.js +461 -0
- package/dist/src/controller/task-router.js +137 -0
- package/dist/src/controller/task-routes.js +703 -0
- package/dist/src/controller/teamauto-routes.js +124 -0
- package/dist/src/controller/tunnel-manager.js +548 -0
- package/dist/src/controller/ui-assets.js +68 -0
- package/dist/src/controller/websocket.js +42 -0
- package/dist/src/controller/worker-provisioning.js +1674 -0
- package/dist/src/controller/worker-routes.js +188 -0
- package/dist/src/discovery.js +86 -0
- package/dist/src/git-collaboration.js +694 -0
- package/dist/src/identity.js +132 -0
- package/dist/src/install-defaults.js +1 -0
- package/dist/src/interaction-contracts.js +531 -0
- package/dist/src/networking.js +91 -0
- package/dist/src/openclaw-workspace.js +925 -0
- package/dist/src/profile-loader.js +486 -0
- package/dist/src/profiles/banking.json +178 -0
- package/dist/src/profiles/crossborder-ecom.json +253 -0
- package/dist/src/profiles/insurance.json +157 -0
- package/dist/src/profiles/knowledge/hs-structure.md +97 -0
- package/dist/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/dist/src/profiles/knowledge/vat-principles.md +85 -0
- package/dist/src/profiles/schema.json +201 -0
- package/dist/src/profiles/securities.json +137 -0
- package/dist/src/profiles/software-rd.json +264 -0
- package/dist/src/profiles/trading-co.json +200 -0
- package/dist/src/prompt-policy.js +386 -0
- package/dist/src/protocol.js +58 -0
- package/dist/src/role-ids.js +29 -0
- package/dist/src/roles.js +390 -0
- package/dist/src/session-roles.js +14 -0
- package/dist/src/state.js +361 -0
- package/dist/src/task-executor.js +1023 -0
- package/dist/src/teamauto/github-client.js +210 -0
- package/dist/src/teamauto/norms.js +85 -0
- package/dist/src/teamauto/repo-sync.js +423 -0
- package/dist/src/teamauto/scanner.js +207 -0
- package/dist/src/teamauto/schedule.js +123 -0
- package/dist/src/teamauto/scheduler.js +907 -0
- package/dist/src/teamauto/store.js +133 -0
- package/dist/src/types.js +290 -0
- package/dist/src/ui/app.js +4860 -0
- package/dist/src/ui/assets/teamclaw-app-icon.png +0 -0
- package/dist/src/ui/github-login.html +296 -0
- package/dist/src/ui/index.html +447 -0
- package/dist/src/ui/style.css +2805 -0
- package/dist/src/worker/http-handler.js +146 -0
- package/dist/src/worker/message-queue.js +24 -0
- package/dist/src/worker/prompt-injector.js +78 -0
- package/dist/src/worker/skill-installer.js +255 -0
- package/dist/src/worker/tools.js +541 -0
- package/dist/src/worker/worker-service.js +307 -0
- package/dist/src/workspace-browser.js +269 -0
- package/openclaw.plugin.json +28 -1
- package/package.json +3 -2
- package/src/config.ts +33 -2
- package/src/controller/clarification-routes.ts +404 -0
- package/src/controller/controller-intake.ts +1113 -0
- package/src/controller/controller-planning.ts +1029 -0
- package/src/controller/controller-runs.ts +239 -0
- package/src/controller/controller-service.ts +295 -41
- package/src/controller/controller-tools.ts +11 -7
- package/src/controller/http-server.ts +294 -6971
- package/src/controller/kickoff-orchestrator.ts +70 -7
- package/src/controller/message-delivery.ts +49 -0
- package/src/controller/message-routes.ts +137 -0
- package/src/controller/orchestration-manifest.ts +6 -29
- package/src/controller/preview-proxy.ts +127 -0
- package/src/controller/profile-switch.ts +366 -0
- package/src/controller/project-registry.ts +361 -0
- package/src/controller/prompt-injector.ts +23 -8
- package/src/controller/repo-routes.ts +91 -0
- package/src/controller/role-inference.ts +260 -22
- package/src/controller/route-table.ts +1616 -0
- package/src/controller/task-assignment.ts +618 -0
- package/src/controller/task-cleanup.ts +344 -0
- package/src/controller/task-execution.ts +356 -0
- package/src/controller/task-results.ts +544 -0
- package/src/controller/task-router.ts +98 -6
- package/src/controller/task-routes.ts +812 -0
- package/src/controller/teamauto-routes.ts +121 -0
- package/src/controller/ui-assets.ts +70 -0
- package/src/controller/websocket.ts +13 -1
- package/src/controller/worker-provisioning.ts +32 -4
- package/src/controller/worker-routes.ts +241 -0
- package/src/identity.ts +3 -2
- package/src/interaction-contracts.ts +7 -7
- package/src/openclaw-workspace.ts +44 -18
- package/src/profile-loader.ts +650 -0
- package/src/profiles/banking.json +178 -0
- package/src/profiles/crossborder-ecom.json +253 -0
- package/src/profiles/insurance.json +157 -0
- package/src/profiles/knowledge/hs-structure.md +97 -0
- package/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/src/profiles/knowledge/vat-principles.md +85 -0
- package/src/profiles/schema.json +201 -0
- package/src/profiles/securities.json +137 -0
- package/src/profiles/software-rd.json +264 -0
- package/src/profiles/trading-co.json +200 -0
- package/src/prompt-policy.ts +27 -13
- package/src/role-ids.ts +31 -0
- package/src/roles.ts +60 -14
- package/src/session-roles.ts +14 -0
- package/src/state.ts +236 -9
- package/src/task-executor.ts +7 -18
- package/src/teamauto/github-client.ts +21 -0
- package/src/teamauto/repo-sync.ts +246 -6
- package/src/teamauto/scanner.ts +47 -13
- package/src/teamauto/scheduler.ts +259 -16
- package/src/teamauto/store.ts +12 -0
- package/src/types.ts +133 -16
- package/src/ui/app.js +592 -24
- package/src/ui/index.html +44 -11
- package/src/ui/style.css +194 -0
- package/src/worker/prompt-injector.ts +48 -8
- package/src/worker/skill-installer.ts +3 -1
- package/src/worker/worker-service.ts +83 -3
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
import { createHeartbeatPayload } from "../protocol.js";
|
|
4
|
+
import { IdentityManager } from "../identity.js";
|
|
5
|
+
import { MessageQueue } from "./message-queue.js";
|
|
6
|
+
import { createWorkerHttpHandler } from "./http-handler.js";
|
|
7
|
+
import { buildTeamClawAgentSessionKey, ensureOpenClawWorkspaceMemoryDir } from "../openclaw-workspace.js";
|
|
8
|
+
/**
|
|
9
|
+
* Issue #27: container detection mirrors the controller's resolve step in
|
|
10
|
+
* controller-service.ts (/.dockerenv, /run/.containerenv, or the Kubernetes
|
|
11
|
+
* service env). Inside Docker/K8s the worker must bind all interfaces so
|
|
12
|
+
* port mapping, service networking, and the controller can reach it; on a
|
|
13
|
+
* host it stays loopback by default.
|
|
14
|
+
*/
|
|
15
|
+
export function detectWorkerContainerEnvironment() {
|
|
16
|
+
return fs.existsSync("/.dockerenv") ||
|
|
17
|
+
fs.existsSync("/run/.containerenv") ||
|
|
18
|
+
process.env.KUBERNETES_SERVICE_HOST !== undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Issue #27: worker HTTP bind address resolution. Precedence:
|
|
22
|
+
* 1. explicit `listenHost` config (overrides everything),
|
|
23
|
+
* 2. 0.0.0.0 inside containers (Docker/K8s),
|
|
24
|
+
* 3. 127.0.0.1 loopback default on hosts.
|
|
25
|
+
* Previously `listen(config.port)` bound `::` (all interfaces) everywhere,
|
|
26
|
+
* exposing the unauthenticated task/message endpoints to the whole network.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveWorkerListenHost(config) {
|
|
29
|
+
const explicit = config.listenHost?.trim();
|
|
30
|
+
if (explicit) {
|
|
31
|
+
return explicit;
|
|
32
|
+
}
|
|
33
|
+
return detectWorkerContainerEnvironment() ? "0.0.0.0" : "127.0.0.1";
|
|
34
|
+
}
|
|
35
|
+
function isLoopbackHost(host) {
|
|
36
|
+
return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]";
|
|
37
|
+
}
|
|
38
|
+
export function createWorkerService(deps) {
|
|
39
|
+
const { config, logger, onIdentityEstablished, taskExecutor: externalTaskExecutor } = deps;
|
|
40
|
+
let identityManager;
|
|
41
|
+
let messageQueue;
|
|
42
|
+
let server = null;
|
|
43
|
+
let heartbeatTimer = null;
|
|
44
|
+
let controllerUrl = null;
|
|
45
|
+
let workerId = null;
|
|
46
|
+
let activeTaskId;
|
|
47
|
+
const activeTaskSessionKeys = new Map();
|
|
48
|
+
const cancelledTaskIds = new Set();
|
|
49
|
+
let consecutiveHeartbeatFailures = 0;
|
|
50
|
+
let warnedLoopbackReachability = false;
|
|
51
|
+
// Issue #27: with the loopback bind default, an external worker (controller
|
|
52
|
+
// on another host) still advertises its LAN IP (identity.ts getLocalIp),
|
|
53
|
+
// so the controller could never reach it. Surface that mismatch once
|
|
54
|
+
// instead of failing silently; `listenHost` is the escape hatch.
|
|
55
|
+
function warnIfLoopbackBindBlocksRemoteController(targetControllerUrl) {
|
|
56
|
+
if (warnedLoopbackReachability) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const listenHost = resolveWorkerListenHost(config);
|
|
60
|
+
if (!isLoopbackHost(listenHost)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
let controllerHost;
|
|
64
|
+
try {
|
|
65
|
+
controllerHost = new URL(targetControllerUrl).hostname;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!controllerHost || isLoopbackHost(controllerHost)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
warnedLoopbackReachability = true;
|
|
74
|
+
logger.warn(`Worker: HTTP server is bound to loopback (${listenHost}) but the controller is at ${targetControllerUrl} (different host) - the controller cannot reach this worker. ` +
|
|
75
|
+
`Set the "listenHost" plugin config (e.g. "0.0.0.0" or this machine's LAN address) for external-worker deployments.`);
|
|
76
|
+
}
|
|
77
|
+
const taskExecutor = externalTaskExecutor
|
|
78
|
+
? async (assignment) => {
|
|
79
|
+
const taskId = assignment.taskId;
|
|
80
|
+
cancelledTaskIds.delete(taskId);
|
|
81
|
+
activeTaskId = taskId;
|
|
82
|
+
activeTaskSessionKeys.set(taskId, assignment.executionSessionKey || buildTeamClawAgentSessionKey(`teamclaw-task-${taskId}`));
|
|
83
|
+
try {
|
|
84
|
+
await deps.prepareTaskAssignment?.(assignment);
|
|
85
|
+
let taskPrompt = [assignment.title.trim(), assignment.description.trim()].filter(Boolean).join("\n\n");
|
|
86
|
+
if (assignment.checkpoint) {
|
|
87
|
+
const cp = assignment.checkpoint;
|
|
88
|
+
const resumeLines = [
|
|
89
|
+
"## RESUMED EXECUTION",
|
|
90
|
+
`This task was interrupted mid-execution (resume attempt ${assignment.resumeAttempt ?? cp.attempt}). You are CONTINUING previous work, not starting over. The OpenClaw session you are running in already contains the full prior conversation - review it before acting.`,
|
|
91
|
+
"Do NOT redo steps that are already done. Re-verify state on disk/git instead of redoing work.",
|
|
92
|
+
"",
|
|
93
|
+
"Last assistant activity before interruption:",
|
|
94
|
+
(cp.lastAssistantMessage || "(none recorded)").slice(0, 4000),
|
|
95
|
+
];
|
|
96
|
+
if (cp.progressNotes?.length) {
|
|
97
|
+
resumeLines.push("", "Progress notes from prior attempts:", ...cp.progressNotes.map((n) => `- ${n}`));
|
|
98
|
+
}
|
|
99
|
+
taskPrompt = `${taskPrompt}\n\n${resumeLines.join("\n")}`;
|
|
100
|
+
}
|
|
101
|
+
const raw = await externalTaskExecutor(taskPrompt, assignment);
|
|
102
|
+
if (cancelledTaskIds.has(taskId)) {
|
|
103
|
+
throw new Error("Task execution cancelled by controller");
|
|
104
|
+
}
|
|
105
|
+
const result = typeof raw === "string" ? { text: raw } : raw;
|
|
106
|
+
await deps.publishTaskAssignment?.(assignment, result.text);
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
activeTaskId = undefined;
|
|
111
|
+
activeTaskSessionKeys.delete(taskId);
|
|
112
|
+
if (!cancelledTaskIds.has(taskId)) {
|
|
113
|
+
cancelledTaskIds.delete(taskId);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
: undefined;
|
|
118
|
+
function reportTaskResult(taskId, result, error, contract) {
|
|
119
|
+
if (cancelledTaskIds.has(taskId)) {
|
|
120
|
+
logger.info(`Worker: suppressing result report for cancelled task ${taskId}`);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (!controllerUrl)
|
|
124
|
+
return;
|
|
125
|
+
const body = { result, error, workerId };
|
|
126
|
+
if (contract) {
|
|
127
|
+
body.resultContract = contract;
|
|
128
|
+
}
|
|
129
|
+
fetch(`${controllerUrl}/api/v1/tasks/${taskId}/result`, {
|
|
130
|
+
method: "POST",
|
|
131
|
+
headers: { "Content-Type": "application/json" },
|
|
132
|
+
body: JSON.stringify(body),
|
|
133
|
+
}).catch((err) => {
|
|
134
|
+
logger.error(`Worker: failed to report task result: ${String(err)}`);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
async function cancelAssignedTask(taskId) {
|
|
138
|
+
if (activeTaskId !== taskId) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
cancelledTaskIds.add(taskId);
|
|
142
|
+
try {
|
|
143
|
+
const cancelled = await deps.cancelTaskExecution?.(taskId, activeTaskSessionKeys.get(taskId));
|
|
144
|
+
return cancelled ?? true;
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
logger.warn(`Worker: failed to cancel task ${taskId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function isTaskCancelled(taskId) {
|
|
152
|
+
return cancelledTaskIds.has(taskId);
|
|
153
|
+
}
|
|
154
|
+
async function startServer() {
|
|
155
|
+
// Kickoff assessor — uses the worker's subagent runtime for lightweight assessment
|
|
156
|
+
const kickoffAssessor = externalTaskExecutor
|
|
157
|
+
? async (requirement, role) => {
|
|
158
|
+
const { buildKickoffAssessmentPrompt } = await import("../controller/kickoff-orchestrator.js");
|
|
159
|
+
const prompt = buildKickoffAssessmentPrompt(role, requirement);
|
|
160
|
+
const sessionKey = buildTeamClawAgentSessionKey(`teamclaw-kickoff-${role}-${Date.now()}`);
|
|
161
|
+
const raw = await externalTaskExecutor(prompt, {
|
|
162
|
+
taskId: `kickoff-${role}`,
|
|
163
|
+
title: `Kickoff Assessment (${role})`,
|
|
164
|
+
description: prompt,
|
|
165
|
+
executionSessionKey: sessionKey,
|
|
166
|
+
});
|
|
167
|
+
const text = typeof raw === "string" ? raw : raw.text;
|
|
168
|
+
// Parse the JSON response
|
|
169
|
+
const jsonMatch = text.match(/```(?:json)?\s*([\s\S]*?)```/) || text.match(/(\{[\s\S]*\})/);
|
|
170
|
+
const jsonStr = jsonMatch?.[1]?.trim() ?? text.trim();
|
|
171
|
+
try {
|
|
172
|
+
const parsed = JSON.parse(jsonStr);
|
|
173
|
+
return {
|
|
174
|
+
role,
|
|
175
|
+
needed: Boolean(parsed.needed),
|
|
176
|
+
scope: String(parsed.scope ?? ""),
|
|
177
|
+
suggestedTasks: Array.isArray(parsed.suggestedTasks) ? parsed.suggestedTasks : [],
|
|
178
|
+
dependencies: Array.isArray(parsed.dependencies) ? parsed.dependencies : [],
|
|
179
|
+
risks: Array.isArray(parsed.risks) ? parsed.risks : [],
|
|
180
|
+
questions: Array.isArray(parsed.questions) ? parsed.questions : [],
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return { role, needed: false, scope: `Could not parse: ${text.slice(0, 200)}`, suggestedTasks: [], dependencies: [], risks: [], questions: [] };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
: undefined;
|
|
188
|
+
const handler = createWorkerHttpHandler({ role: config.role, port: config.port }, logger, messageQueue, workerId ?? "", taskExecutor, reportTaskResult, cancelAssignedTask, isTaskCancelled, kickoffAssessor);
|
|
189
|
+
if (server) {
|
|
190
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
191
|
+
}
|
|
192
|
+
server = http.createServer(handler);
|
|
193
|
+
const listenHost = resolveWorkerListenHost(config);
|
|
194
|
+
await new Promise((resolve, reject) => {
|
|
195
|
+
server.listen(config.port, listenHost, () => {
|
|
196
|
+
logger.info(`Worker: HTTP server listening on ${listenHost}:${config.port}`);
|
|
197
|
+
resolve();
|
|
198
|
+
});
|
|
199
|
+
server.on("error", (err) => {
|
|
200
|
+
if (err.code === "EADDRINUSE") {
|
|
201
|
+
// Issue #27: the worker default port is also the controller default,
|
|
202
|
+
// so same-host dual-process setups crash here with no pointer.
|
|
203
|
+
reject(new Error(`Worker: cannot listen on ${listenHost}:${config.port} - address already in use` +
|
|
204
|
+
(config.port === 9527
|
|
205
|
+
? ". Port 9527 is also the controller default; when running a controller and this worker on the same host, point this worker's \`port\` config at another value"
|
|
206
|
+
: "") +
|
|
207
|
+
". Adjust the `port` and `listenHost` plugin config keys to change the bind address."));
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
reject(err);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
id: "teamclaw-worker",
|
|
216
|
+
async start(_ctx) {
|
|
217
|
+
await ensureOpenClawWorkspaceMemoryDir(logger);
|
|
218
|
+
messageQueue = deps.messageQueue ?? new MessageQueue();
|
|
219
|
+
identityManager = new IdentityManager(config, logger);
|
|
220
|
+
// Start HTTP server initially (without identity)
|
|
221
|
+
await startServer();
|
|
222
|
+
// Register with controller
|
|
223
|
+
const identity = await identityManager.register();
|
|
224
|
+
if (!identity) {
|
|
225
|
+
logger.warn("Worker: could not register with controller, will retry on next heartbeat");
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
controllerUrl = identity.controllerUrl;
|
|
229
|
+
workerId = identity.workerId;
|
|
230
|
+
onIdentityEstablished(identity);
|
|
231
|
+
warnIfLoopbackBindBlocksRemoteController(controllerUrl);
|
|
232
|
+
// Restart server with worker ID and task executor
|
|
233
|
+
await startServer();
|
|
234
|
+
}
|
|
235
|
+
// Start heartbeat
|
|
236
|
+
heartbeatTimer = setInterval(async () => {
|
|
237
|
+
if (!identityManager.hasIdentity()) {
|
|
238
|
+
const newIdentity = await identityManager.register();
|
|
239
|
+
if (newIdentity && !controllerUrl) {
|
|
240
|
+
controllerUrl = newIdentity.controllerUrl;
|
|
241
|
+
workerId = newIdentity.workerId;
|
|
242
|
+
onIdentityEstablished(newIdentity);
|
|
243
|
+
warnIfLoopbackBindBlocksRemoteController(controllerUrl);
|
|
244
|
+
await startServer();
|
|
245
|
+
}
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const id = identityManager.getIdentity();
|
|
249
|
+
if (!id || !controllerUrl)
|
|
250
|
+
return;
|
|
251
|
+
try {
|
|
252
|
+
const heartbeat = createHeartbeatPayload(id.workerId, activeTaskId ? "busy" : "idle", activeTaskId);
|
|
253
|
+
const res = await fetch(`${controllerUrl}/api/v1/workers/${id.workerId}/heartbeat`, {
|
|
254
|
+
method: "POST",
|
|
255
|
+
headers: { "Content-Type": "application/json" },
|
|
256
|
+
body: JSON.stringify(heartbeat),
|
|
257
|
+
});
|
|
258
|
+
if (!res.ok) {
|
|
259
|
+
consecutiveHeartbeatFailures += 1;
|
|
260
|
+
logger.warn(`Worker: heartbeat failed (${res.status})`);
|
|
261
|
+
if (consecutiveHeartbeatFailures >= 3) {
|
|
262
|
+
logger.warn("Worker: controller heartbeat failed repeatedly; clearing identity and forcing re-registration");
|
|
263
|
+
await identityManager.clear();
|
|
264
|
+
controllerUrl = null;
|
|
265
|
+
workerId = null;
|
|
266
|
+
consecutiveHeartbeatFailures = 0;
|
|
267
|
+
await startServer();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
consecutiveHeartbeatFailures = 0;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
consecutiveHeartbeatFailures += 1;
|
|
276
|
+
logger.warn(`Worker: heartbeat error: ${err instanceof Error ? err.message : String(err)}`);
|
|
277
|
+
if (consecutiveHeartbeatFailures >= 3) {
|
|
278
|
+
logger.warn("Worker: controller heartbeat errored repeatedly; clearing identity and forcing re-registration");
|
|
279
|
+
await identityManager.clear();
|
|
280
|
+
controllerUrl = null;
|
|
281
|
+
workerId = null;
|
|
282
|
+
consecutiveHeartbeatFailures = 0;
|
|
283
|
+
await startServer();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}, config.heartbeatIntervalMs);
|
|
287
|
+
if (heartbeatTimer) {
|
|
288
|
+
const timer = heartbeatTimer;
|
|
289
|
+
timer.unref?.();
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
async stop() {
|
|
293
|
+
if (heartbeatTimer) {
|
|
294
|
+
clearInterval(heartbeatTimer);
|
|
295
|
+
heartbeatTimer = null;
|
|
296
|
+
}
|
|
297
|
+
if (server) {
|
|
298
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
299
|
+
server = null;
|
|
300
|
+
}
|
|
301
|
+
if (identityManager) {
|
|
302
|
+
await identityManager.clear();
|
|
303
|
+
}
|
|
304
|
+
logger.info("Worker: stopped");
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveTeamClawWorkspaceDir } from "./openclaw-workspace.js";
|
|
4
|
+
const MAX_PREVIEW_BYTES = 256 * 1024;
|
|
5
|
+
const MAX_TREE_DEPTH = 8;
|
|
6
|
+
const HIDDEN_WORKSPACE_NAMES = new Set([
|
|
7
|
+
".git",
|
|
8
|
+
".openclaw",
|
|
9
|
+
"node_modules",
|
|
10
|
+
"memory",
|
|
11
|
+
"AGENTS.md",
|
|
12
|
+
"BOOTSTRAP.md",
|
|
13
|
+
"HEARTBEAT.md",
|
|
14
|
+
"IDENTITY.md",
|
|
15
|
+
"SOUL.md",
|
|
16
|
+
"TOOLS.md",
|
|
17
|
+
"USER.md",
|
|
18
|
+
]);
|
|
19
|
+
const MARKDOWN_EXTENSIONS = new Set([".md", ".markdown", ".mdown"]);
|
|
20
|
+
const HTML_EXTENSIONS = new Set([".html", ".htm"]);
|
|
21
|
+
const TEXT_EXTENSIONS = new Set([
|
|
22
|
+
".txt",
|
|
23
|
+
".js",
|
|
24
|
+
".mjs",
|
|
25
|
+
".cjs",
|
|
26
|
+
".jsx",
|
|
27
|
+
".ts",
|
|
28
|
+
".tsx",
|
|
29
|
+
".css",
|
|
30
|
+
".scss",
|
|
31
|
+
".sass",
|
|
32
|
+
".less",
|
|
33
|
+
".json",
|
|
34
|
+
".yml",
|
|
35
|
+
".yaml",
|
|
36
|
+
".xml",
|
|
37
|
+
".svg",
|
|
38
|
+
".sh",
|
|
39
|
+
".bash",
|
|
40
|
+
".zsh",
|
|
41
|
+
".py",
|
|
42
|
+
".go",
|
|
43
|
+
".rs",
|
|
44
|
+
".java",
|
|
45
|
+
".kt",
|
|
46
|
+
".swift",
|
|
47
|
+
".rb",
|
|
48
|
+
".php",
|
|
49
|
+
".sql",
|
|
50
|
+
".env",
|
|
51
|
+
".gitignore",
|
|
52
|
+
".gitattributes",
|
|
53
|
+
".npmrc",
|
|
54
|
+
".editorconfig",
|
|
55
|
+
]);
|
|
56
|
+
export async function listWorkspaceTree(maxDepth) {
|
|
57
|
+
const workspaceDir = await ensureWorkspaceDir();
|
|
58
|
+
const entries = await readTree(workspaceDir, "", 0, maxDepth);
|
|
59
|
+
return {
|
|
60
|
+
root: "/",
|
|
61
|
+
entries,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Load children of a single directory (one level). Used for lazy-loading. */
|
|
65
|
+
export async function listWorkspaceSubtree(relativePath) {
|
|
66
|
+
const { absolutePath, normalizedPath } = await resolveWorkspacePath(relativePath);
|
|
67
|
+
const stat = await fs.stat(absolutePath);
|
|
68
|
+
if (!stat.isDirectory()) {
|
|
69
|
+
throw new Error("Path is not a directory");
|
|
70
|
+
}
|
|
71
|
+
return readTree(absolutePath, normalizedPath, 0, 1);
|
|
72
|
+
}
|
|
73
|
+
export async function readWorkspaceFile(relativePath) {
|
|
74
|
+
const { normalizedPath, absolutePath } = await resolveWorkspacePath(relativePath);
|
|
75
|
+
const stat = await fs.stat(absolutePath);
|
|
76
|
+
if (!stat.isFile()) {
|
|
77
|
+
throw new Error("Workspace path is not a file");
|
|
78
|
+
}
|
|
79
|
+
const extension = path.extname(normalizedPath).toLowerCase();
|
|
80
|
+
const contentType = getContentType(normalizedPath);
|
|
81
|
+
const handle = await fs.open(absolutePath, "r");
|
|
82
|
+
try {
|
|
83
|
+
const length = Math.min(stat.size, MAX_PREVIEW_BYTES + 1);
|
|
84
|
+
const buffer = Buffer.alloc(length);
|
|
85
|
+
const { bytesRead } = await handle.read(buffer, 0, length, 0);
|
|
86
|
+
const slice = buffer.subarray(0, bytesRead);
|
|
87
|
+
const truncated = stat.size > MAX_PREVIEW_BYTES;
|
|
88
|
+
const previewType = detectPreviewType(normalizedPath, slice);
|
|
89
|
+
return {
|
|
90
|
+
name: path.basename(normalizedPath),
|
|
91
|
+
path: normalizedPath,
|
|
92
|
+
size: stat.size,
|
|
93
|
+
extension,
|
|
94
|
+
previewType,
|
|
95
|
+
truncated,
|
|
96
|
+
content: previewType === "binary" ? undefined : slice.subarray(0, Math.min(slice.length, MAX_PREVIEW_BYTES)).toString("utf8"),
|
|
97
|
+
rawUrl: buildWorkspaceRawUrl(normalizedPath),
|
|
98
|
+
contentType,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
await handle.close();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export async function readWorkspaceRawFile(relativePath) {
|
|
106
|
+
const { absolutePath } = await resolveWorkspacePath(relativePath);
|
|
107
|
+
const stat = await fs.stat(absolutePath);
|
|
108
|
+
if (!stat.isFile()) {
|
|
109
|
+
throw new Error("Workspace path is not a file");
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
content: await fs.readFile(absolutePath),
|
|
113
|
+
contentType: getContentType(absolutePath),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export function buildWorkspaceRawUrl(relativePath) {
|
|
117
|
+
const normalizedPath = normalizeWorkspacePath(relativePath);
|
|
118
|
+
const encodedPath = normalizedPath.split("/").map((segment) => encodeURIComponent(segment)).join("/");
|
|
119
|
+
return `/api/v1/workspace/raw/${encodedPath}`;
|
|
120
|
+
}
|
|
121
|
+
async function ensureWorkspaceDir() {
|
|
122
|
+
const workspaceDir = resolveTeamClawWorkspaceDir();
|
|
123
|
+
await fs.mkdir(workspaceDir, { recursive: true });
|
|
124
|
+
return workspaceDir;
|
|
125
|
+
}
|
|
126
|
+
async function resolveWorkspacePath(relativePath) {
|
|
127
|
+
const workspaceDir = await ensureWorkspaceDir();
|
|
128
|
+
const normalizedPath = normalizeWorkspacePath(relativePath);
|
|
129
|
+
if (!normalizedPath) {
|
|
130
|
+
throw new Error("workspace path is required");
|
|
131
|
+
}
|
|
132
|
+
const absolutePath = path.resolve(workspaceDir, normalizedPath);
|
|
133
|
+
const relativeFromWorkspace = path.relative(workspaceDir, absolutePath).replace(/\\/g, "/");
|
|
134
|
+
if (!relativeFromWorkspace || relativeFromWorkspace.startsWith("..") || path.isAbsolute(relativeFromWorkspace)) {
|
|
135
|
+
throw new Error("workspace path must stay inside the workspace");
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
workspaceDir,
|
|
139
|
+
normalizedPath: relativeFromWorkspace,
|
|
140
|
+
absolutePath,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function normalizeWorkspacePath(relativePath) {
|
|
144
|
+
const value = String(relativePath || "").trim().replace(/\\/g, "/").replace(/^\/+/, "");
|
|
145
|
+
if (!value) {
|
|
146
|
+
return "";
|
|
147
|
+
}
|
|
148
|
+
const normalized = path.posix.normalize(value);
|
|
149
|
+
if (normalized === "." || normalized === ".." || normalized.startsWith("../")) {
|
|
150
|
+
throw new Error("Invalid workspace path");
|
|
151
|
+
}
|
|
152
|
+
return normalized;
|
|
153
|
+
}
|
|
154
|
+
async function readTree(dirPath, relativeDir, depth, maxDepth) {
|
|
155
|
+
const effectiveMaxDepth = maxDepth ?? MAX_TREE_DEPTH;
|
|
156
|
+
if (depth > effectiveMaxDepth) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
const dirents = await fs.readdir(dirPath, { withFileTypes: true });
|
|
160
|
+
const visibleDirents = dirents
|
|
161
|
+
.filter((dirent) => !HIDDEN_WORKSPACE_NAMES.has(dirent.name))
|
|
162
|
+
.sort((left, right) => {
|
|
163
|
+
if (left.isDirectory() && !right.isDirectory())
|
|
164
|
+
return -1;
|
|
165
|
+
if (!left.isDirectory() && right.isDirectory())
|
|
166
|
+
return 1;
|
|
167
|
+
return left.name.localeCompare(right.name);
|
|
168
|
+
});
|
|
169
|
+
const nodes = [];
|
|
170
|
+
for (const dirent of visibleDirents) {
|
|
171
|
+
const childRelativePath = relativeDir ? `${relativeDir}/${dirent.name}` : dirent.name;
|
|
172
|
+
const childAbsolutePath = path.join(dirPath, dirent.name);
|
|
173
|
+
if (dirent.isDirectory()) {
|
|
174
|
+
// At max depth, mark directory as lazy-loadable (no children yet)
|
|
175
|
+
const atLimit = depth + 1 > effectiveMaxDepth;
|
|
176
|
+
nodes.push({
|
|
177
|
+
name: dirent.name,
|
|
178
|
+
path: childRelativePath,
|
|
179
|
+
type: "directory",
|
|
180
|
+
children: atLimit ? undefined : await readTree(childAbsolutePath, childRelativePath, depth + 1, effectiveMaxDepth),
|
|
181
|
+
});
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (!dirent.isFile()) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const stat = await fs.stat(childAbsolutePath);
|
|
188
|
+
nodes.push({
|
|
189
|
+
name: dirent.name,
|
|
190
|
+
path: childRelativePath,
|
|
191
|
+
type: "file",
|
|
192
|
+
size: stat.size,
|
|
193
|
+
previewType: classifyPreviewType(childRelativePath),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return nodes;
|
|
197
|
+
}
|
|
198
|
+
function classifyPreviewType(filePath) {
|
|
199
|
+
const extension = path.extname(filePath).toLowerCase();
|
|
200
|
+
if (MARKDOWN_EXTENSIONS.has(extension)) {
|
|
201
|
+
return "markdown";
|
|
202
|
+
}
|
|
203
|
+
if (HTML_EXTENSIONS.has(extension)) {
|
|
204
|
+
return "html";
|
|
205
|
+
}
|
|
206
|
+
return TEXT_EXTENSIONS.has(extension) ? "source" : "binary";
|
|
207
|
+
}
|
|
208
|
+
function detectPreviewType(filePath, content) {
|
|
209
|
+
const classified = classifyPreviewType(filePath);
|
|
210
|
+
if (classified === "markdown" || classified === "html") {
|
|
211
|
+
return classified;
|
|
212
|
+
}
|
|
213
|
+
if (classified === "source") {
|
|
214
|
+
return "source";
|
|
215
|
+
}
|
|
216
|
+
return isLikelyBinary(content) ? "binary" : "source";
|
|
217
|
+
}
|
|
218
|
+
function isLikelyBinary(content) {
|
|
219
|
+
const sample = content.subarray(0, Math.min(content.length, 4096));
|
|
220
|
+
for (const byte of sample) {
|
|
221
|
+
if (byte === 0) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
function getContentType(filePath) {
|
|
228
|
+
const extension = path.extname(filePath).toLowerCase();
|
|
229
|
+
switch (extension) {
|
|
230
|
+
case ".html":
|
|
231
|
+
case ".htm":
|
|
232
|
+
return "text/html; charset=utf-8";
|
|
233
|
+
case ".md":
|
|
234
|
+
case ".markdown":
|
|
235
|
+
case ".mdown":
|
|
236
|
+
return "text/markdown; charset=utf-8";
|
|
237
|
+
case ".css":
|
|
238
|
+
return "text/css; charset=utf-8";
|
|
239
|
+
case ".js":
|
|
240
|
+
case ".mjs":
|
|
241
|
+
case ".cjs":
|
|
242
|
+
return "application/javascript; charset=utf-8";
|
|
243
|
+
case ".json":
|
|
244
|
+
return "application/json; charset=utf-8";
|
|
245
|
+
case ".svg":
|
|
246
|
+
return "image/svg+xml";
|
|
247
|
+
case ".txt":
|
|
248
|
+
case ".sh":
|
|
249
|
+
case ".bash":
|
|
250
|
+
case ".zsh":
|
|
251
|
+
case ".yml":
|
|
252
|
+
case ".yaml":
|
|
253
|
+
case ".ts":
|
|
254
|
+
case ".tsx":
|
|
255
|
+
case ".jsx":
|
|
256
|
+
case ".py":
|
|
257
|
+
case ".go":
|
|
258
|
+
case ".rs":
|
|
259
|
+
case ".java":
|
|
260
|
+
case ".kt":
|
|
261
|
+
case ".swift":
|
|
262
|
+
case ".rb":
|
|
263
|
+
case ".php":
|
|
264
|
+
case ".sql":
|
|
265
|
+
return "text/plain; charset=utf-8";
|
|
266
|
+
default:
|
|
267
|
+
return "application/octet-stream";
|
|
268
|
+
}
|
|
269
|
+
}
|
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.11.0",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true
|
|
8
8
|
},
|
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
"label": "Port",
|
|
41
41
|
"help": "HTTP server port for this instance"
|
|
42
42
|
},
|
|
43
|
+
"listenHost": {
|
|
44
|
+
"label": "Listen Host",
|
|
45
|
+
"help": "HTTP bind address override; empty defaults to 127.0.0.1 on hosts and 0.0.0.0 in containers. Use 0.0.0.0 when a remote controller must reach this worker"
|
|
46
|
+
},
|
|
43
47
|
"role": {
|
|
44
48
|
"label": "Role",
|
|
45
49
|
"help": "Worker role (worker mode only)"
|
|
@@ -52,6 +56,10 @@
|
|
|
52
56
|
"label": "Team Name",
|
|
53
57
|
"help": "Team identifier for mDNS"
|
|
54
58
|
},
|
|
59
|
+
"teamProfile": {
|
|
60
|
+
"label": "Team Profile",
|
|
61
|
+
"help": "Team profile package id; applies to the first team initialization only (Phase 2 adds profile switching)"
|
|
62
|
+
},
|
|
55
63
|
"heartbeatIntervalMs": {
|
|
56
64
|
"label": "Heartbeat Interval",
|
|
57
65
|
"help": "In milliseconds, minimum 1000"
|
|
@@ -60,6 +68,10 @@
|
|
|
60
68
|
"label": "Task Stall Threshold",
|
|
61
69
|
"help": "In milliseconds, how long TeamClaw waits without visible progress before probing the task instead of failing it"
|
|
62
70
|
},
|
|
71
|
+
"teamSwitchDrainTimeoutMs": {
|
|
72
|
+
"label": "Profile Switch Drain Timeout",
|
|
73
|
+
"help": "In milliseconds, how long a team profile switch waits for in-flight tasks to finish before force-collecting them"
|
|
74
|
+
},
|
|
63
75
|
"maxConcurrentTasks": {
|
|
64
76
|
"label": "Max Concurrent Tasks",
|
|
65
77
|
"hint": "number",
|
|
@@ -208,6 +220,11 @@
|
|
|
208
220
|
"default": 9527,
|
|
209
221
|
"description": "HTTP server port for this instance"
|
|
210
222
|
},
|
|
223
|
+
"listenHost": {
|
|
224
|
+
"type": "string",
|
|
225
|
+
"default": "",
|
|
226
|
+
"description": "HTTP listen host override (empty = 127.0.0.1 on hosts, 0.0.0.0 in containers); set 0.0.0.0 for external workers reachable by a remote controller"
|
|
227
|
+
},
|
|
211
228
|
"role": {
|
|
212
229
|
"type": "string",
|
|
213
230
|
"default": "developer",
|
|
@@ -223,6 +240,11 @@
|
|
|
223
240
|
"default": "TeamClaw",
|
|
224
241
|
"description": "Team name for mDNS identification"
|
|
225
242
|
},
|
|
243
|
+
"teamProfile": {
|
|
244
|
+
"type": "string",
|
|
245
|
+
"default": "software-rd",
|
|
246
|
+
"description": "Team profile package id (software-rd baseline); seeds first initialization only - the persisted team state profile is the runtime truth"
|
|
247
|
+
},
|
|
226
248
|
"heartbeatIntervalMs": {
|
|
227
249
|
"type": "number",
|
|
228
250
|
"default": 10000,
|
|
@@ -233,6 +255,11 @@
|
|
|
233
255
|
"default": 600000,
|
|
234
256
|
"description": "Inactivity threshold in milliseconds before TeamClaw probes a stalled role task instead of failing it"
|
|
235
257
|
},
|
|
258
|
+
"teamSwitchDrainTimeoutMs": {
|
|
259
|
+
"type": "number",
|
|
260
|
+
"default": 30000,
|
|
261
|
+
"description": "How long a team profile switch waits for in-flight tasks to finish before force-collecting them (design 2.3 graceful drain)"
|
|
262
|
+
},
|
|
236
263
|
"maxConcurrentTasks": {
|
|
237
264
|
"type": "integer",
|
|
238
265
|
"default": 5,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamclaws/teamclaw",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.11.0",
|
|
4
4
|
"description": "OpenClaw virtual software team orchestration plugin - controller, role-based workers, Web UI with internet tunnel sharing",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -45,8 +45,9 @@
|
|
|
45
45
|
"tsconfig.build.json"
|
|
46
46
|
],
|
|
47
47
|
"scripts": {
|
|
48
|
-
"build": "tsc -p tsconfig.build.json && node -e \"require('fs').cpSync('src/ui','dist/src/ui',{recursive:true})\"",
|
|
48
|
+
"build": "tsc -p tsconfig.build.json && node -e \"const fs=require('fs');fs.cpSync('src/ui','dist/src/ui',{recursive:true});fs.cpSync('src/profiles','dist/src/profiles',{recursive:true})\"",
|
|
49
49
|
"manifest:sync": "cd .. && node scripts/sync-teamclaw-plugin-manifest.mjs src",
|
|
50
|
+
"profile:sync": "cd .. && node scripts/generate-software-rd-profile.mjs src",
|
|
50
51
|
"pack:dry-run": "npm pack --dry-run --json --ignore-scripts",
|
|
51
52
|
"release:check": "cd .. && node scripts/teamclaw-package-check.mjs src",
|
|
52
53
|
"release:clawhub:dry-run": "cd .. && bash scripts/teamclaw-clawhub-release.sh --dry-run"
|