@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.
- package/cli.mjs +318 -17
- package/dist/index.js +54 -32
- package/dist/src/config.js +57 -2
- package/dist/src/controller/auth-routes.js +129 -0
- package/dist/src/controller/clarification-routes.js +315 -0
- package/dist/src/controller/controller-intake.js +895 -0
- package/dist/src/controller/controller-planning.js +814 -0
- package/dist/src/controller/controller-routes.js +195 -0
- package/dist/src/controller/controller-runs.js +175 -0
- package/dist/src/controller/controller-service.js +338 -50
- package/dist/src/controller/controller-tools.js +14 -7
- package/dist/src/controller/github-auth.js +2 -1
- package/dist/src/controller/http-server.js +290 -6003
- package/dist/src/controller/kickoff-orchestrator.js +33 -43
- package/dist/src/controller/message-delivery.js +31 -0
- package/dist/src/controller/message-routes.js +114 -0
- package/dist/src/controller/orchestration-manifest.js +11 -93
- package/dist/src/controller/preview-manager.js +51 -3
- package/dist/src/controller/preview-proxy.js +98 -0
- package/dist/src/controller/profile-switch.js +309 -0
- package/dist/src/controller/project-registry.js +294 -0
- package/dist/src/controller/prompt-injector.js +19 -9
- package/dist/src/controller/provisioning/backend-contract.js +9 -0
- package/dist/src/controller/provisioning/container-shared.js +64 -0
- package/dist/src/controller/provisioning/docker.js +214 -0
- package/dist/src/controller/provisioning/kubernetes.js +244 -0
- package/dist/src/controller/provisioning/plugin-root.js +41 -0
- package/dist/src/controller/provisioning/process-supervisor.js +190 -0
- package/dist/src/controller/provisioning-config.js +239 -0
- package/dist/src/controller/repo-routes.js +129 -0
- package/dist/src/controller/report-routes.js +56 -0
- package/dist/src/controller/role-inference.js +231 -20
- package/dist/src/controller/route-table.js +375 -0
- package/dist/src/controller/security.js +775 -0
- package/dist/src/controller/status-routes.js +287 -0
- package/dist/src/controller/task-assignment.js +511 -0
- package/dist/src/controller/task-cleanup.js +258 -0
- package/dist/src/controller/task-execution.js +271 -0
- package/dist/src/controller/task-results.js +471 -0
- package/dist/src/controller/task-router.js +74 -4
- 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 +41 -8
- package/dist/src/controller/tunnel-routes.js +225 -0
- package/dist/src/controller/ui-assets.js +68 -0
- package/dist/src/controller/websocket.js +6 -2
- package/dist/src/controller/webui-routes.js +49 -0
- package/dist/src/controller/worker-provisioning.js +69 -953
- package/dist/src/controller/worker-routes.js +188 -0
- package/dist/src/controller/workflow-routes.js +407 -0
- package/dist/src/controller/workspace-routes.js +200 -0
- package/dist/src/git-collaboration.js +4 -9
- package/dist/src/identity.js +15 -3
- package/dist/src/interaction-contracts.js +7 -7
- package/dist/src/openclaw-workspace.js +40 -18
- package/dist/src/profile-loader.js +604 -0
- package/dist/src/profiles/banking.json +202 -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 +281 -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 +42 -17
- package/dist/src/protocol.js +66 -3
- package/dist/src/role-ids.js +29 -0
- package/dist/src/roles.js +54 -13
- package/dist/src/session-roles.js +14 -0
- package/dist/src/shared/clarification-schema.js +65 -0
- package/dist/src/shared/github-auth.js +15 -0
- package/dist/src/shared/kickoff-prompt.js +37 -0
- package/dist/src/shared/utils.js +47 -0
- package/dist/src/state.js +275 -11
- package/dist/src/task-executor.js +7 -17
- package/dist/src/teamauto/github-client.js +18 -0
- package/dist/src/teamauto/repo-sync.js +228 -6
- package/dist/src/teamauto/scanner.js +40 -12
- package/dist/src/teamauto/scheduler.js +231 -12
- package/dist/src/types.js +77 -16
- package/dist/src/ui/app.js +1434 -82
- package/dist/src/ui/github-login.html +1 -0
- package/dist/src/ui/index.html +144 -45
- package/dist/src/ui/style.css +194 -0
- package/dist/src/worker/http-handler.js +59 -0
- package/dist/src/worker/prompt-injector.js +44 -8
- package/dist/src/worker/skill-installer.js +6 -10
- package/dist/src/worker/tools.js +20 -10
- package/dist/src/worker/worker-service.js +93 -7
- package/index.ts +61 -32
- package/openclaw.plugin.json +50 -2
- package/package.json +3 -2
- package/src/config.ts +57 -2
- package/src/controller/auth-routes.ts +157 -0
- package/src/controller/clarification-routes.ts +404 -0
- package/src/controller/controller-intake.ts +1113 -0
- package/src/controller/controller-planning.ts +1037 -0
- package/src/controller/controller-routes.ts +237 -0
- package/src/controller/controller-runs.ts +239 -0
- package/src/controller/controller-service.ts +422 -50
- package/src/controller/controller-tools.ts +16 -9
- package/src/controller/github-auth.ts +28 -63
- package/src/controller/http-server.ts +336 -6964
- package/src/controller/kickoff-orchestrator.ts +69 -45
- package/src/controller/message-delivery.ts +52 -0
- package/src/controller/message-routes.ts +137 -0
- package/src/controller/orchestration-manifest.ts +14 -100
- package/src/controller/preview-manager.ts +53 -3
- package/src/controller/preview-proxy.ts +127 -0
- package/src/controller/profile-switch.ts +396 -0
- package/src/controller/project-registry.ts +361 -0
- package/src/controller/prompt-injector.ts +23 -8
- package/src/controller/provisioning/backend-contract.ts +51 -0
- package/src/controller/provisioning/container-shared.ts +84 -0
- package/src/controller/provisioning/docker.ts +260 -0
- package/src/controller/provisioning/kubernetes.ts +263 -0
- package/src/controller/provisioning/plugin-root.ts +42 -0
- package/src/controller/provisioning/process-supervisor.ts +214 -0
- package/src/controller/provisioning-config.ts +289 -0
- package/src/controller/repo-routes.ts +163 -0
- package/src/controller/report-routes.ts +64 -0
- package/src/controller/role-inference.ts +260 -22
- package/src/controller/route-table.ts +597 -0
- package/src/controller/security.ts +899 -0
- package/src/controller/status-routes.ts +354 -0
- package/src/controller/task-assignment.ts +622 -0
- package/src/controller/task-cleanup.ts +344 -0
- package/src/controller/task-execution.ts +399 -0
- package/src/controller/task-results.ts +556 -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/tunnel-manager.ts +45 -8
- package/src/controller/tunnel-routes.ts +231 -0
- package/src/controller/ui-assets.ts +70 -0
- package/src/controller/websocket.ts +32 -4
- package/src/controller/webui-routes.ts +55 -0
- package/src/controller/worker-provisioning.ts +83 -1121
- package/src/controller/worker-routes.ts +241 -0
- package/src/controller/workflow-routes.ts +498 -0
- package/src/controller/workspace-routes.ts +222 -0
- package/src/git-collaboration.ts +4 -9
- package/src/identity.ts +16 -3
- package/src/interaction-contracts.ts +7 -7
- package/src/openclaw-workspace.ts +44 -18
- package/src/profile-loader.ts +816 -0
- package/src/profiles/banking.json +202 -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 +281 -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 +44 -17
- package/src/protocol.ts +72 -2
- package/src/role-ids.ts +31 -0
- package/src/roles.ts +60 -14
- package/src/session-roles.ts +14 -0
- package/src/shared/clarification-schema.ts +81 -0
- package/src/shared/github-auth.ts +92 -0
- package/src/shared/kickoff-prompt.ts +47 -0
- package/src/shared/utils.ts +51 -0
- package/src/state.ts +326 -10
- package/src/task-executor.ts +7 -18
- package/src/teamauto/github-client.ts +23 -1
- package/src/teamauto/repo-sync.ts +248 -7
- package/src/teamauto/scanner.ts +47 -13
- package/src/teamauto/scheduler.ts +261 -17
- package/src/teamauto/store.ts +12 -0
- package/src/types.ts +263 -17
- package/src/ui/app.js +1434 -82
- package/src/ui/github-login.html +1 -0
- package/src/ui/index.html +144 -45
- package/src/ui/style.css +194 -0
- package/src/worker/http-handler.ts +64 -1
- package/src/worker/prompt-injector.ts +48 -8
- package/src/worker/skill-installer.ts +6 -10
- package/src/worker/tools.ts +21 -10
- package/src/worker/worker-service.ts +101 -7
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
import type { PluginConfig, WorkerIdentity } from "../types.js";
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
// Phase 1.3: the worker role prompt comes from the active TeamProfile.
|
|
3
|
+
import { getActiveDomainInstructions, getActiveKnowledgePacks, getActiveRole } from "../profile-loader.js";
|
|
4
|
+
import { buildRoleOperatingRules, buildWorkerSessionRules, composePrompt } from "../prompt-policy.js";
|
|
4
5
|
import { MessageQueue } from "./message-queue.js";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
// Phase 1.2: the local TEAMCLAW_ROLE_IDS_TEXT copy that used to live here was
|
|
8
|
+
// dead code (no references) and duplicated the canonical role id list; the
|
|
9
|
+
// shared text is exported from prompt-policy.ts (TEAMCLAW_ROLE_IDS_TEXT).
|
|
10
|
+
|
|
11
|
+
// Phase 4 hard rule appended to every Reference Packs section (zero-cost
|
|
12
|
+
// exception, design 3 Phase 4): the packs ground stable concepts, and
|
|
13
|
+
// everything time-sensitive stays TBD + authoritative-source-driven.
|
|
14
|
+
const KNOWLEDGE_PACK_HARD_RULE = "When answering, prefer these pack definitions over memory; "
|
|
15
|
+
+ "for anything time-sensitive (rates, thresholds, regulations), direct the user to current "
|
|
16
|
+
+ "authoritative sources and mark TBD.";
|
|
17
|
+
|
|
18
|
+
function buildKnowledgePackSection(packs: Array<{ name: string; content: string }>): string[] {
|
|
19
|
+
const lines: string[] = ["", "## Reference Packs"];
|
|
20
|
+
for (const pack of packs) {
|
|
21
|
+
lines.push(`### ${pack.name}`);
|
|
22
|
+
lines.push(pack.content.trimEnd());
|
|
23
|
+
lines.push("");
|
|
24
|
+
}
|
|
25
|
+
lines.push(KNOWLEDGE_PACK_HARD_RULE);
|
|
26
|
+
return lines;
|
|
27
|
+
}
|
|
11
28
|
|
|
12
29
|
export function createWorkerPromptInjector(
|
|
13
30
|
config: PluginConfig,
|
|
@@ -20,14 +37,37 @@ export function createWorkerPromptInjector(
|
|
|
20
37
|
return null;
|
|
21
38
|
}
|
|
22
39
|
|
|
23
|
-
const roleDef =
|
|
40
|
+
const roleDef = getActiveRole(identity.role);
|
|
24
41
|
if (!roleDef) {
|
|
25
42
|
return null;
|
|
26
43
|
}
|
|
27
44
|
|
|
45
|
+
// Phase 2.4 (design 2.4): when the active profile carries industry
|
|
46
|
+
// guardrails they REPLACE the software operating rules and are assembled
|
|
47
|
+
// right after the role systemPrompt. Profiles without domainInstructions
|
|
48
|
+
// (software-rd) inject nothing here - the operating contract is already
|
|
49
|
+
// pre-composed into their systemPrompt - so the worker prompt bytes are
|
|
50
|
+
// unchanged (Phase 1.7 golden).
|
|
51
|
+
const domainInstructions = getActiveDomainInstructions();
|
|
52
|
+
|
|
53
|
+
// Phase 4 static knowledge packs (design 2.1/2.2, 3 Phase 4 exception):
|
|
54
|
+
// appended right after the operating contract, only when the active
|
|
55
|
+
// profile declares them. software-rd carries none, so the section (and
|
|
56
|
+
// every byte around it) stays absent - the Phase 1.7 goldens keep the
|
|
57
|
+
// baseline worker prompt byte-identical.
|
|
58
|
+
const knowledgePacks = getActiveKnowledgePacks();
|
|
59
|
+
|
|
28
60
|
const parts: string[] = [
|
|
29
61
|
`## TeamClaw Role: ${roleDef.label} ${roleDef.icon}`,
|
|
30
62
|
roleDef.systemPrompt,
|
|
63
|
+
...(domainInstructions
|
|
64
|
+
? buildRoleOperatingRules({
|
|
65
|
+
suggestedRoles: roleDef.suggestedNextRoles,
|
|
66
|
+
recommendedSkills: roleDef.recommendedSkills,
|
|
67
|
+
domainInstructions,
|
|
68
|
+
})
|
|
69
|
+
: []),
|
|
70
|
+
...(knowledgePacks.length > 0 ? buildKnowledgePackSection(knowledgePacks) : []),
|
|
31
71
|
...buildWorkerSessionRules(),
|
|
32
72
|
"Important: submit structured collaboration contracts for all handoffs, reviews, progress updates, and result deliveries so the controller can route work without parsing freeform prose.",
|
|
33
73
|
"Do not use sessions_yield or end your turn while background work, coding agents, or process sessions are still running.",
|
|
@@ -2,9 +2,14 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import type { PluginLogger } from "../../api.js";
|
|
5
|
-
|
|
5
|
+
// Phase 1.3: recommended-skill normalization lives on the profile loader
|
|
6
|
+
// face (same semantics as the registry helper).
|
|
7
|
+
import { normalizeRecommendedSkills } from "../profile-loader.js";
|
|
6
8
|
import { resolveTeamClawWorkspaceDir } from "../openclaw-workspace.js";
|
|
7
9
|
import type { TaskAssignmentPayload, TaskExecutionEventInput } from "../types.js";
|
|
10
|
+
// W6 of issue #226: local swallowing pathExists copy replaced by the shared
|
|
11
|
+
// one (identical semantics; alias keeps the call sites byte-identical).
|
|
12
|
+
import { pathExistsTolerant as pathExists } from "../shared/utils.js";
|
|
8
13
|
|
|
9
14
|
type SkillCli = "openclaw" | "clawhub";
|
|
10
15
|
const ON_DEMAND_DISCOVERY_SKILLS = new Set(["find-skills"]);
|
|
@@ -42,15 +47,6 @@ function isSkillSlug(value: string): boolean {
|
|
|
42
47
|
return /^[a-z0-9][a-z0-9._/-]*$/i.test(value) && !/\s/.test(value);
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
async function pathExists(filePath: string): Promise<boolean> {
|
|
46
|
-
try {
|
|
47
|
-
await fs.access(filePath);
|
|
48
|
-
return true;
|
|
49
|
-
} catch {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
50
|
async function runCommand(
|
|
55
51
|
command: string,
|
|
56
52
|
args: string[],
|
package/src/worker/tools.ts
CHANGED
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
} from "../interaction-contracts.js";
|
|
13
13
|
import { loadWorkerIdentity } from "../state.js";
|
|
14
14
|
import type { PluginConfig, WorkerIdentity } from "../types.js";
|
|
15
|
-
|
|
15
|
+
// Issue #226 W3: shared contract — the worker must not import the controller tree.
|
|
16
|
+
import { normalizeClarificationQuestionSchema } from "../shared/clarification-schema.js";
|
|
16
17
|
|
|
17
18
|
const ALLOWED_PROGRESS_STATUSES = new Set(["in_progress", "review"]);
|
|
18
19
|
|
|
@@ -44,6 +45,16 @@ export function createWorkerTools(deps: WorkerToolsDeps) {
|
|
|
44
45
|
return getIdentity() ?? await loadWorkerIdentity();
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Issue #23 (client wave): worker-tool calls into the controller carry the
|
|
50
|
+
* paired device token (config.securityToken) as X-TeamClaw-Token when one
|
|
51
|
+
* is configured; without it the headers are unchanged (L0). Never logged.
|
|
52
|
+
*/
|
|
53
|
+
function withDeviceToken(headers: Record<string, string>): Record<string, string> {
|
|
54
|
+
const token = config.securityToken?.trim();
|
|
55
|
+
return token ? { ...headers, "X-TeamClaw-Token": token } : headers;
|
|
56
|
+
}
|
|
57
|
+
|
|
47
58
|
return [
|
|
48
59
|
{
|
|
49
60
|
name: "teamclaw_ask_peer",
|
|
@@ -87,7 +98,7 @@ export function createWorkerTools(deps: WorkerToolsDeps) {
|
|
|
87
98
|
});
|
|
88
99
|
const res = await fetch(`${identity.controllerUrl}/api/v1/messages/direct`, {
|
|
89
100
|
method: "POST",
|
|
90
|
-
headers: { "Content-Type": "application/json" },
|
|
101
|
+
headers: withDeviceToken({ "Content-Type": "application/json" }),
|
|
91
102
|
body: JSON.stringify({
|
|
92
103
|
from: identity.workerId,
|
|
93
104
|
fromRole: identity.role,
|
|
@@ -146,7 +157,7 @@ export function createWorkerTools(deps: WorkerToolsDeps) {
|
|
|
146
157
|
});
|
|
147
158
|
const res = await fetch(`${identity.controllerUrl}/api/v1/messages/broadcast`, {
|
|
148
159
|
method: "POST",
|
|
149
|
-
headers: { "Content-Type": "application/json" },
|
|
160
|
+
headers: withDeviceToken({ "Content-Type": "application/json" }),
|
|
150
161
|
body: JSON.stringify({
|
|
151
162
|
from: identity.workerId,
|
|
152
163
|
fromRole: identity.role,
|
|
@@ -206,7 +217,7 @@ export function createWorkerTools(deps: WorkerToolsDeps) {
|
|
|
206
217
|
});
|
|
207
218
|
const res = await fetch(`${identity.controllerUrl}/api/v1/messages/review-request`, {
|
|
208
219
|
method: "POST",
|
|
209
|
-
headers: { "Content-Type": "application/json" },
|
|
220
|
+
headers: withDeviceToken({ "Content-Type": "application/json" }),
|
|
210
221
|
body: JSON.stringify({
|
|
211
222
|
from: identity.workerId,
|
|
212
223
|
fromRole: identity.role,
|
|
@@ -263,7 +274,7 @@ export function createWorkerTools(deps: WorkerToolsDeps) {
|
|
|
263
274
|
});
|
|
264
275
|
const res = await fetch(`${identity.controllerUrl}/api/v1/tasks/${taskId}/handoff`, {
|
|
265
276
|
method: "POST",
|
|
266
|
-
headers: { "Content-Type": "application/json" },
|
|
277
|
+
headers: withDeviceToken({ "Content-Type": "application/json" }),
|
|
267
278
|
body: JSON.stringify({
|
|
268
279
|
fromWorkerId: identity.workerId,
|
|
269
280
|
targetRole,
|
|
@@ -348,7 +359,7 @@ export function createWorkerTools(deps: WorkerToolsDeps) {
|
|
|
348
359
|
try {
|
|
349
360
|
const res = await fetch(`${identity.controllerUrl}/api/v1/tasks/${taskId}/result-contract`, {
|
|
350
361
|
method: "POST",
|
|
351
|
-
headers: { "Content-Type": "application/json" },
|
|
362
|
+
headers: withDeviceToken({ "Content-Type": "application/json" }),
|
|
352
363
|
body: JSON.stringify({ contract, workerId: identity.workerId }),
|
|
353
364
|
});
|
|
354
365
|
if (!res.ok) {
|
|
@@ -402,7 +413,7 @@ export function createWorkerTools(deps: WorkerToolsDeps) {
|
|
|
402
413
|
try {
|
|
403
414
|
const res = await fetch(`${identity.controllerUrl}/api/v1/tasks/${taskId}/parallel-help`, {
|
|
404
415
|
method: "POST",
|
|
405
|
-
headers: { "Content-Type": "application/json" },
|
|
416
|
+
headers: withDeviceToken({ "Content-Type": "application/json" }),
|
|
406
417
|
body: JSON.stringify({
|
|
407
418
|
requestedBy: identity.workerId,
|
|
408
419
|
requestedByRole: identity.role,
|
|
@@ -475,7 +486,7 @@ export function createWorkerTools(deps: WorkerToolsDeps) {
|
|
|
475
486
|
try {
|
|
476
487
|
const res = await fetch(`${identity.controllerUrl}/api/v1/clarifications`, {
|
|
477
488
|
method: "POST",
|
|
478
|
-
headers: { "Content-Type": "application/json" },
|
|
489
|
+
headers: withDeviceToken({ "Content-Type": "application/json" }),
|
|
479
490
|
body: JSON.stringify({
|
|
480
491
|
taskId,
|
|
481
492
|
requestedBy: identity.workerId,
|
|
@@ -510,7 +521,7 @@ export function createWorkerTools(deps: WorkerToolsDeps) {
|
|
|
510
521
|
}
|
|
511
522
|
|
|
512
523
|
try {
|
|
513
|
-
const res = await fetch(`${identity.controllerUrl}/api/v1/team/status
|
|
524
|
+
const res = await fetch(`${identity.controllerUrl}/api/v1/team/status`, { headers: withDeviceToken({}) });
|
|
514
525
|
if (!res.ok) {
|
|
515
526
|
return { details: {}, content: [{ type: "text" as const, text: `Failed to get status: ${res.status}` }] };
|
|
516
527
|
}
|
|
@@ -582,7 +593,7 @@ export function createWorkerTools(deps: WorkerToolsDeps) {
|
|
|
582
593
|
|
|
583
594
|
const res = await fetch(`${identity.controllerUrl}/api/v1/tasks/${taskId}`, {
|
|
584
595
|
method: "PATCH",
|
|
585
|
-
headers: { "Content-Type": "application/json" },
|
|
596
|
+
headers: withDeviceToken({ "Content-Type": "application/json" }),
|
|
586
597
|
body: JSON.stringify(patch),
|
|
587
598
|
});
|
|
588
599
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
1
2
|
import http from "node:http";
|
|
2
3
|
import type { OpenClawPluginService, OpenClawPluginServiceContext, PluginLogger } from "../../api.js";
|
|
3
4
|
import type { PluginConfig, TaskAssignmentPayload, WorkerIdentity } from "../types.js";
|
|
@@ -9,6 +10,50 @@ import { buildTeamClawAgentSessionKey, ensureOpenClawWorkspaceMemoryDir } from "
|
|
|
9
10
|
|
|
10
11
|
export type TaskExecutorResultLike = string | { text: string; contract?: Record<string, unknown> };
|
|
11
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Issue #27: container detection mirrors the controller's resolve step in
|
|
15
|
+
* controller-service.ts (/.dockerenv, /run/.containerenv, or the Kubernetes
|
|
16
|
+
* service env). Inside Docker/K8s the worker must bind all interfaces so
|
|
17
|
+
* port mapping, service networking, and the controller can reach it; on a
|
|
18
|
+
* host it stays loopback by default.
|
|
19
|
+
*/
|
|
20
|
+
export function detectWorkerContainerEnvironment(): boolean {
|
|
21
|
+
return fs.existsSync("/.dockerenv") ||
|
|
22
|
+
fs.existsSync("/run/.containerenv") ||
|
|
23
|
+
process.env.KUBERNETES_SERVICE_HOST !== undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Issue #27: worker HTTP bind address resolution. Precedence:
|
|
28
|
+
* 1. explicit `listenHost` config (overrides everything),
|
|
29
|
+
* 2. 0.0.0.0 inside containers (Docker/K8s),
|
|
30
|
+
* 3. 127.0.0.1 loopback default on hosts.
|
|
31
|
+
* Previously `listen(config.port)` bound `::` (all interfaces) everywhere,
|
|
32
|
+
* exposing the unauthenticated task/message endpoints to the whole network.
|
|
33
|
+
*/
|
|
34
|
+
export function resolveWorkerListenHost(config: Pick<PluginConfig, "listenHost">): string {
|
|
35
|
+
const explicit = config.listenHost?.trim();
|
|
36
|
+
if (explicit) {
|
|
37
|
+
return explicit;
|
|
38
|
+
}
|
|
39
|
+
return detectWorkerContainerEnvironment() ? "0.0.0.0" : "127.0.0.1";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isLoopbackHost(host: string): boolean {
|
|
43
|
+
return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Issue #23 (client wave): worker -> controller requests carry the paired
|
|
48
|
+
* device token (config.securityToken) as X-TeamClaw-Token when one is
|
|
49
|
+
* configured; without a token the headers are unchanged (L0 behavior). The
|
|
50
|
+
* token value is never logged.
|
|
51
|
+
*/
|
|
52
|
+
function withDeviceToken(config: PluginConfig, headers: Record<string, string>): Record<string, string> {
|
|
53
|
+
const token = config.securityToken?.trim();
|
|
54
|
+
return token ? { ...headers, "X-TeamClaw-Token": token } : headers;
|
|
55
|
+
}
|
|
56
|
+
|
|
12
57
|
export type WorkerServiceDeps = {
|
|
13
58
|
config: PluginConfig;
|
|
14
59
|
logger: PluginLogger;
|
|
@@ -32,6 +77,35 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
|
|
|
32
77
|
const activeTaskSessionKeys = new Map<string, string>();
|
|
33
78
|
const cancelledTaskIds = new Set<string>();
|
|
34
79
|
let consecutiveHeartbeatFailures = 0;
|
|
80
|
+
let warnedLoopbackReachability = false;
|
|
81
|
+
|
|
82
|
+
// Issue #27: with the loopback bind default, an external worker (controller
|
|
83
|
+
// on another host) still advertises its LAN IP (identity.ts getLocalIp),
|
|
84
|
+
// so the controller could never reach it. Surface that mismatch once
|
|
85
|
+
// instead of failing silently; `listenHost` is the escape hatch.
|
|
86
|
+
function warnIfLoopbackBindBlocksRemoteController(targetControllerUrl: string): void {
|
|
87
|
+
if (warnedLoopbackReachability) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const listenHost = resolveWorkerListenHost(config);
|
|
91
|
+
if (!isLoopbackHost(listenHost)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
let controllerHost: string;
|
|
95
|
+
try {
|
|
96
|
+
controllerHost = new URL(targetControllerUrl).hostname;
|
|
97
|
+
} catch {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!controllerHost || isLoopbackHost(controllerHost)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
warnedLoopbackReachability = true;
|
|
104
|
+
logger.warn(
|
|
105
|
+
`Worker: HTTP server is bound to loopback (${listenHost}) but the controller is at ${targetControllerUrl} (different host) - the controller cannot reach this worker. ` +
|
|
106
|
+
`Set the "listenHost" plugin config (e.g. "0.0.0.0" or this machine's LAN address) for external-worker deployments.`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
35
109
|
|
|
36
110
|
const taskExecutor = externalTaskExecutor
|
|
37
111
|
? async (assignment: TaskAssignmentPayload): Promise<{ text: string; contract?: Record<string, unknown> }> => {
|
|
@@ -86,7 +160,7 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
|
|
|
86
160
|
}
|
|
87
161
|
fetch(`${controllerUrl}/api/v1/tasks/${taskId}/result`, {
|
|
88
162
|
method: "POST",
|
|
89
|
-
headers: { "Content-Type": "application/json" },
|
|
163
|
+
headers: withDeviceToken(config, { "Content-Type": "application/json" }),
|
|
90
164
|
body: JSON.stringify(body),
|
|
91
165
|
}).catch((err) => {
|
|
92
166
|
logger.error(`Worker: failed to report task result: ${String(err)}`);
|
|
@@ -116,7 +190,10 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
|
|
|
116
190
|
// Kickoff assessor — uses the worker's subagent runtime for lightweight assessment
|
|
117
191
|
const kickoffAssessor = externalTaskExecutor
|
|
118
192
|
? async (requirement: string, role: string): Promise<Record<string, unknown>> => {
|
|
119
|
-
|
|
193
|
+
// Issue #226 W3: the kickoff prompt contract lives in the shared
|
|
194
|
+
// layer now — this dynamic import must never point back at the
|
|
195
|
+
// controller tree (worker-mode deployments would drag it in).
|
|
196
|
+
const { buildKickoffAssessmentPrompt } = await import("../shared/kickoff-prompt.js");
|
|
120
197
|
const prompt = buildKickoffAssessmentPrompt(role as import("../types.js").RoleId, requirement);
|
|
121
198
|
const sessionKey = buildTeamClawAgentSessionKey(`teamclaw-kickoff-${role}-${Date.now()}`);
|
|
122
199
|
const raw = await externalTaskExecutor(prompt, {
|
|
@@ -147,7 +224,7 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
|
|
|
147
224
|
: undefined;
|
|
148
225
|
|
|
149
226
|
const handler = createWorkerHttpHandler(
|
|
150
|
-
{ role: config.role, port: config.port },
|
|
227
|
+
{ role: config.role, port: config.port, securityToken: config.securityToken },
|
|
151
228
|
logger,
|
|
152
229
|
messageQueue,
|
|
153
230
|
workerId ?? "",
|
|
@@ -163,12 +240,27 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
|
|
|
163
240
|
}
|
|
164
241
|
|
|
165
242
|
server = http.createServer(handler);
|
|
243
|
+
const listenHost = resolveWorkerListenHost(config);
|
|
166
244
|
await new Promise<void>((resolve, reject) => {
|
|
167
|
-
server!.listen(config.port, () => {
|
|
168
|
-
logger.info(`Worker: HTTP server listening on
|
|
245
|
+
server!.listen(config.port, listenHost, () => {
|
|
246
|
+
logger.info(`Worker: HTTP server listening on ${listenHost}:${config.port}`);
|
|
169
247
|
resolve();
|
|
170
248
|
});
|
|
171
|
-
server!.on("error",
|
|
249
|
+
server!.on("error", (err: NodeJS.ErrnoException) => {
|
|
250
|
+
if (err.code === "EADDRINUSE") {
|
|
251
|
+
// Issue #27: the worker default port is also the controller default,
|
|
252
|
+
// so same-host dual-process setups crash here with no pointer.
|
|
253
|
+
reject(new Error(
|
|
254
|
+
`Worker: cannot listen on ${listenHost}:${config.port} - address already in use` +
|
|
255
|
+
(config.port === 9527
|
|
256
|
+
? ". 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"
|
|
257
|
+
: "") +
|
|
258
|
+
". Adjust the `port` and `listenHost` plugin config keys to change the bind address.",
|
|
259
|
+
));
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
reject(err);
|
|
263
|
+
});
|
|
172
264
|
});
|
|
173
265
|
}
|
|
174
266
|
|
|
@@ -191,6 +283,7 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
|
|
|
191
283
|
controllerUrl = identity.controllerUrl;
|
|
192
284
|
workerId = identity.workerId;
|
|
193
285
|
onIdentityEstablished(identity);
|
|
286
|
+
warnIfLoopbackBindBlocksRemoteController(controllerUrl);
|
|
194
287
|
// Restart server with worker ID and task executor
|
|
195
288
|
await startServer();
|
|
196
289
|
}
|
|
@@ -203,6 +296,7 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
|
|
|
203
296
|
controllerUrl = newIdentity.controllerUrl;
|
|
204
297
|
workerId = newIdentity.workerId;
|
|
205
298
|
onIdentityEstablished(newIdentity);
|
|
299
|
+
warnIfLoopbackBindBlocksRemoteController(controllerUrl);
|
|
206
300
|
await startServer();
|
|
207
301
|
}
|
|
208
302
|
return;
|
|
@@ -219,7 +313,7 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
|
|
|
219
313
|
);
|
|
220
314
|
const res = await fetch(`${controllerUrl}/api/v1/workers/${id.workerId}/heartbeat`, {
|
|
221
315
|
method: "POST",
|
|
222
|
-
headers: { "Content-Type": "application/json" },
|
|
316
|
+
headers: withDeviceToken(config, { "Content-Type": "application/json" }),
|
|
223
317
|
body: JSON.stringify(heartbeat),
|
|
224
318
|
});
|
|
225
319
|
|