@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
@@ -1,23 +1,59 @@
1
- import { getRole } from "../roles.js";
2
- import { buildWorkerSessionRules, composePrompt } from "../prompt-policy.js";
3
- const TEAMCLAW_ROLE_IDS_TEXT = [
4
- "pm", "architect", "developer", "qa",
5
- "release-engineer", "infra-engineer", "devops", "security-engineer",
6
- "designer", "marketing", "data-engineer",
7
- ];
1
+ // Phase 1.3: the worker role prompt comes from the active TeamProfile.
2
+ import { getActiveDomainInstructions, getActiveKnowledgePacks, getActiveRole } from "../profile-loader.js";
3
+ import { buildRoleOperatingRules, buildWorkerSessionRules, composePrompt } from "../prompt-policy.js";
4
+ // Phase 1.2: the local TEAMCLAW_ROLE_IDS_TEXT copy that used to live here was
5
+ // dead code (no references) and duplicated the canonical role id list; the
6
+ // shared text is exported from prompt-policy.ts (TEAMCLAW_ROLE_IDS_TEXT).
7
+ // Phase 4 hard rule appended to every Reference Packs section (zero-cost
8
+ // exception, design 3 Phase 4): the packs ground stable concepts, and
9
+ // everything time-sensitive stays TBD + authoritative-source-driven.
10
+ const KNOWLEDGE_PACK_HARD_RULE = "When answering, prefer these pack definitions over memory; "
11
+ + "for anything time-sensitive (rates, thresholds, regulations), direct the user to current "
12
+ + "authoritative sources and mark TBD.";
13
+ function buildKnowledgePackSection(packs) {
14
+ const lines = ["", "## Reference Packs"];
15
+ for (const pack of packs) {
16
+ lines.push(`### ${pack.name}`);
17
+ lines.push(pack.content.trimEnd());
18
+ lines.push("");
19
+ }
20
+ lines.push(KNOWLEDGE_PACK_HARD_RULE);
21
+ return lines;
22
+ }
8
23
  export function createWorkerPromptInjector(config, getIdentity, messageQueue) {
9
24
  return () => {
10
25
  const identity = getIdentity();
11
26
  if (!identity) {
12
27
  return null;
13
28
  }
14
- const roleDef = getRole(identity.role);
29
+ const roleDef = getActiveRole(identity.role);
15
30
  if (!roleDef) {
16
31
  return null;
17
32
  }
33
+ // Phase 2.4 (design 2.4): when the active profile carries industry
34
+ // guardrails they REPLACE the software operating rules and are assembled
35
+ // right after the role systemPrompt. Profiles without domainInstructions
36
+ // (software-rd) inject nothing here - the operating contract is already
37
+ // pre-composed into their systemPrompt - so the worker prompt bytes are
38
+ // unchanged (Phase 1.7 golden).
39
+ const domainInstructions = getActiveDomainInstructions();
40
+ // Phase 4 static knowledge packs (design 2.1/2.2, 3 Phase 4 exception):
41
+ // appended right after the operating contract, only when the active
42
+ // profile declares them. software-rd carries none, so the section (and
43
+ // every byte around it) stays absent - the Phase 1.7 goldens keep the
44
+ // baseline worker prompt byte-identical.
45
+ const knowledgePacks = getActiveKnowledgePacks();
18
46
  const parts = [
19
47
  `## TeamClaw Role: ${roleDef.label} ${roleDef.icon}`,
20
48
  roleDef.systemPrompt,
49
+ ...(domainInstructions
50
+ ? buildRoleOperatingRules({
51
+ suggestedRoles: roleDef.suggestedNextRoles,
52
+ recommendedSkills: roleDef.recommendedSkills,
53
+ domainInstructions,
54
+ })
55
+ : []),
56
+ ...(knowledgePacks.length > 0 ? buildKnowledgePackSection(knowledgePacks) : []),
21
57
  ...buildWorkerSessionRules(),
22
58
  "Important: submit structured collaboration contracts for all handoffs, reviews, progress updates, and result deliveries so the controller can route work without parsing freeform prose.",
23
59
  "Do not use sessions_yield or end your turn while background work, coding agents, or process sessions are still running.",
@@ -1,8 +1,13 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
- import { normalizeRecommendedSkills } from "../roles.js";
4
+ // Phase 1.3: recommended-skill normalization lives on the profile loader
5
+ // face (same semantics as the registry helper).
6
+ import { normalizeRecommendedSkills } from "../profile-loader.js";
5
7
  import { resolveTeamClawWorkspaceDir } from "../openclaw-workspace.js";
8
+ // W6 of issue #226: local swallowing pathExists copy replaced by the shared
9
+ // one (identical semantics; alias keeps the call sites byte-identical).
10
+ import { pathExistsTolerant as pathExists } from "../shared/utils.js";
6
11
  const ON_DEMAND_DISCOVERY_SKILLS = new Set(["find-skills"]);
7
12
  function truncateOutput(value, limit = 400) {
8
13
  const trimmed = value.trim();
@@ -20,15 +25,6 @@ function normalizeKey(value) {
20
25
  function isSkillSlug(value) {
21
26
  return /^[a-z0-9][a-z0-9._/-]*$/i.test(value) && !/\s/.test(value);
22
27
  }
23
- async function pathExists(filePath) {
24
- try {
25
- await fs.access(filePath);
26
- return true;
27
- }
28
- catch {
29
- return false;
30
- }
31
- }
32
28
  async function runCommand(command, args, cwd) {
33
29
  return await new Promise((resolve) => {
34
30
  const child = spawn(command, args, {
@@ -1,7 +1,8 @@
1
1
  import { Type } from "@sinclair/typebox";
2
2
  import { backfillWorkerProgressContract, ensureTeamMessageContract, normalizeContractRole, normalizeContractStringList, normalizeTaskHandoffContract, normalizeWorkerProgressContract, normalizeWorkerTaskResultContract, renderWorkerProgressText, } from "../interaction-contracts.js";
3
3
  import { loadWorkerIdentity } from "../state.js";
4
- import { normalizeClarificationQuestionSchema } from "../controller/orchestration-manifest.js";
4
+ // Issue #226 W3: shared contract — the worker must not import the controller tree.
5
+ import { normalizeClarificationQuestionSchema } from "../shared/clarification-schema.js";
5
6
  const ALLOWED_PROGRESS_STATUSES = new Set(["in_progress", "review"]);
6
7
  function normalizeProgressText(params) {
7
8
  if (typeof params.progress === "string" && params.progress.trim()) {
@@ -23,6 +24,15 @@ export function createWorkerTools(deps) {
23
24
  async function resolveIdentity() {
24
25
  return getIdentity() ?? await loadWorkerIdentity();
25
26
  }
27
+ /**
28
+ * Issue #23 (client wave): worker-tool calls into the controller carry the
29
+ * paired device token (config.securityToken) as X-TeamClaw-Token when one
30
+ * is configured; without it the headers are unchanged (L0). Never logged.
31
+ */
32
+ function withDeviceToken(headers) {
33
+ const token = config.securityToken?.trim();
34
+ return token ? { ...headers, "X-TeamClaw-Token": token } : headers;
35
+ }
26
36
  return [
27
37
  {
28
38
  name: "teamclaw_ask_peer",
@@ -63,7 +73,7 @@ export function createWorkerTools(deps) {
63
73
  });
64
74
  const res = await fetch(`${identity.controllerUrl}/api/v1/messages/direct`, {
65
75
  method: "POST",
66
- headers: { "Content-Type": "application/json" },
76
+ headers: withDeviceToken({ "Content-Type": "application/json" }),
67
77
  body: JSON.stringify({
68
78
  from: identity.workerId,
69
79
  fromRole: identity.role,
@@ -119,7 +129,7 @@ export function createWorkerTools(deps) {
119
129
  });
120
130
  const res = await fetch(`${identity.controllerUrl}/api/v1/messages/broadcast`, {
121
131
  method: "POST",
122
- headers: { "Content-Type": "application/json" },
132
+ headers: withDeviceToken({ "Content-Type": "application/json" }),
123
133
  body: JSON.stringify({
124
134
  from: identity.workerId,
125
135
  fromRole: identity.role,
@@ -175,7 +185,7 @@ export function createWorkerTools(deps) {
175
185
  });
176
186
  const res = await fetch(`${identity.controllerUrl}/api/v1/messages/review-request`, {
177
187
  method: "POST",
178
- headers: { "Content-Type": "application/json" },
188
+ headers: withDeviceToken({ "Content-Type": "application/json" }),
179
189
  body: JSON.stringify({
180
190
  from: identity.workerId,
181
191
  fromRole: identity.role,
@@ -228,7 +238,7 @@ export function createWorkerTools(deps) {
228
238
  });
229
239
  const res = await fetch(`${identity.controllerUrl}/api/v1/tasks/${taskId}/handoff`, {
230
240
  method: "POST",
231
- headers: { "Content-Type": "application/json" },
241
+ headers: withDeviceToken({ "Content-Type": "application/json" }),
232
242
  body: JSON.stringify({
233
243
  fromWorkerId: identity.workerId,
234
244
  targetRole,
@@ -301,7 +311,7 @@ export function createWorkerTools(deps) {
301
311
  try {
302
312
  const res = await fetch(`${identity.controllerUrl}/api/v1/tasks/${taskId}/result-contract`, {
303
313
  method: "POST",
304
- headers: { "Content-Type": "application/json" },
314
+ headers: withDeviceToken({ "Content-Type": "application/json" }),
305
315
  body: JSON.stringify({ contract, workerId: identity.workerId }),
306
316
  });
307
317
  if (!res.ok) {
@@ -353,7 +363,7 @@ export function createWorkerTools(deps) {
353
363
  try {
354
364
  const res = await fetch(`${identity.controllerUrl}/api/v1/tasks/${taskId}/parallel-help`, {
355
365
  method: "POST",
356
- headers: { "Content-Type": "application/json" },
366
+ headers: withDeviceToken({ "Content-Type": "application/json" }),
357
367
  body: JSON.stringify({
358
368
  requestedBy: identity.workerId,
359
369
  requestedByRole: identity.role,
@@ -422,7 +432,7 @@ export function createWorkerTools(deps) {
422
432
  try {
423
433
  const res = await fetch(`${identity.controllerUrl}/api/v1/clarifications`, {
424
434
  method: "POST",
425
- headers: { "Content-Type": "application/json" },
435
+ headers: withDeviceToken({ "Content-Type": "application/json" }),
426
436
  body: JSON.stringify({
427
437
  taskId,
428
438
  requestedBy: identity.workerId,
@@ -455,7 +465,7 @@ export function createWorkerTools(deps) {
455
465
  return { details: {}, content: [{ type: "text", text: "Not registered with a team." }] };
456
466
  }
457
467
  try {
458
- const res = await fetch(`${identity.controllerUrl}/api/v1/team/status`);
468
+ const res = await fetch(`${identity.controllerUrl}/api/v1/team/status`, { headers: withDeviceToken({}) });
459
469
  if (!res.ok) {
460
470
  return { details: {}, content: [{ type: "text", text: `Failed to get status: ${res.status}` }] };
461
471
  }
@@ -524,7 +534,7 @@ export function createWorkerTools(deps) {
524
534
  }
525
535
  const res = await fetch(`${identity.controllerUrl}/api/v1/tasks/${taskId}`, {
526
536
  method: "PATCH",
527
- headers: { "Content-Type": "application/json" },
537
+ headers: withDeviceToken({ "Content-Type": "application/json" }),
528
538
  body: JSON.stringify(patch),
529
539
  });
530
540
  if (!res.ok) {
@@ -1,9 +1,50 @@
1
+ import fs from "node:fs";
1
2
  import http from "node:http";
2
3
  import { createHeartbeatPayload } from "../protocol.js";
3
4
  import { IdentityManager } from "../identity.js";
4
5
  import { MessageQueue } from "./message-queue.js";
5
6
  import { createWorkerHttpHandler } from "./http-handler.js";
6
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
+ /**
39
+ * Issue #23 (client wave): worker -> controller requests carry the paired
40
+ * device token (config.securityToken) as X-TeamClaw-Token when one is
41
+ * configured; without a token the headers are unchanged (L0 behavior). The
42
+ * token value is never logged.
43
+ */
44
+ function withDeviceToken(config, headers) {
45
+ const token = config.securityToken?.trim();
46
+ return token ? { ...headers, "X-TeamClaw-Token": token } : headers;
47
+ }
7
48
  export function createWorkerService(deps) {
8
49
  const { config, logger, onIdentityEstablished, taskExecutor: externalTaskExecutor } = deps;
9
50
  let identityManager;
@@ -16,6 +57,33 @@ export function createWorkerService(deps) {
16
57
  const activeTaskSessionKeys = new Map();
17
58
  const cancelledTaskIds = new Set();
18
59
  let consecutiveHeartbeatFailures = 0;
60
+ let warnedLoopbackReachability = false;
61
+ // Issue #27: with the loopback bind default, an external worker (controller
62
+ // on another host) still advertises its LAN IP (identity.ts getLocalIp),
63
+ // so the controller could never reach it. Surface that mismatch once
64
+ // instead of failing silently; `listenHost` is the escape hatch.
65
+ function warnIfLoopbackBindBlocksRemoteController(targetControllerUrl) {
66
+ if (warnedLoopbackReachability) {
67
+ return;
68
+ }
69
+ const listenHost = resolveWorkerListenHost(config);
70
+ if (!isLoopbackHost(listenHost)) {
71
+ return;
72
+ }
73
+ let controllerHost;
74
+ try {
75
+ controllerHost = new URL(targetControllerUrl).hostname;
76
+ }
77
+ catch {
78
+ return;
79
+ }
80
+ if (!controllerHost || isLoopbackHost(controllerHost)) {
81
+ return;
82
+ }
83
+ warnedLoopbackReachability = true;
84
+ logger.warn(`Worker: HTTP server is bound to loopback (${listenHost}) but the controller is at ${targetControllerUrl} (different host) - the controller cannot reach this worker. ` +
85
+ `Set the "listenHost" plugin config (e.g. "0.0.0.0" or this machine's LAN address) for external-worker deployments.`);
86
+ }
19
87
  const taskExecutor = externalTaskExecutor
20
88
  ? async (assignment) => {
21
89
  const taskId = assignment.taskId;
@@ -70,7 +138,7 @@ export function createWorkerService(deps) {
70
138
  }
71
139
  fetch(`${controllerUrl}/api/v1/tasks/${taskId}/result`, {
72
140
  method: "POST",
73
- headers: { "Content-Type": "application/json" },
141
+ headers: withDeviceToken(config, { "Content-Type": "application/json" }),
74
142
  body: JSON.stringify(body),
75
143
  }).catch((err) => {
76
144
  logger.error(`Worker: failed to report task result: ${String(err)}`);
@@ -97,7 +165,10 @@ export function createWorkerService(deps) {
97
165
  // Kickoff assessor — uses the worker's subagent runtime for lightweight assessment
98
166
  const kickoffAssessor = externalTaskExecutor
99
167
  ? async (requirement, role) => {
100
- const { buildKickoffAssessmentPrompt } = await import("../controller/kickoff-orchestrator.js");
168
+ // Issue #226 W3: the kickoff prompt contract lives in the shared
169
+ // layer now — this dynamic import must never point back at the
170
+ // controller tree (worker-mode deployments would drag it in).
171
+ const { buildKickoffAssessmentPrompt } = await import("../shared/kickoff-prompt.js");
101
172
  const prompt = buildKickoffAssessmentPrompt(role, requirement);
102
173
  const sessionKey = buildTeamClawAgentSessionKey(`teamclaw-kickoff-${role}-${Date.now()}`);
103
174
  const raw = await externalTaskExecutor(prompt, {
@@ -127,17 +198,30 @@ export function createWorkerService(deps) {
127
198
  }
128
199
  }
129
200
  : undefined;
130
- const handler = createWorkerHttpHandler({ role: config.role, port: config.port }, logger, messageQueue, workerId ?? "", taskExecutor, reportTaskResult, cancelAssignedTask, isTaskCancelled, kickoffAssessor);
201
+ const handler = createWorkerHttpHandler({ role: config.role, port: config.port, securityToken: config.securityToken }, logger, messageQueue, workerId ?? "", taskExecutor, reportTaskResult, cancelAssignedTask, isTaskCancelled, kickoffAssessor);
131
202
  if (server) {
132
203
  await new Promise((resolve) => server.close(() => resolve()));
133
204
  }
134
205
  server = http.createServer(handler);
206
+ const listenHost = resolveWorkerListenHost(config);
135
207
  await new Promise((resolve, reject) => {
136
- server.listen(config.port, () => {
137
- logger.info(`Worker: HTTP server listening on port ${config.port}`);
208
+ server.listen(config.port, listenHost, () => {
209
+ logger.info(`Worker: HTTP server listening on ${listenHost}:${config.port}`);
138
210
  resolve();
139
211
  });
140
- server.on("error", reject);
212
+ server.on("error", (err) => {
213
+ if (err.code === "EADDRINUSE") {
214
+ // Issue #27: the worker default port is also the controller default,
215
+ // so same-host dual-process setups crash here with no pointer.
216
+ reject(new Error(`Worker: cannot listen on ${listenHost}:${config.port} - address already in use` +
217
+ (config.port === 9527
218
+ ? ". 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"
219
+ : "") +
220
+ ". Adjust the `port` and `listenHost` plugin config keys to change the bind address."));
221
+ return;
222
+ }
223
+ reject(err);
224
+ });
141
225
  });
142
226
  }
143
227
  return {
@@ -157,6 +241,7 @@ export function createWorkerService(deps) {
157
241
  controllerUrl = identity.controllerUrl;
158
242
  workerId = identity.workerId;
159
243
  onIdentityEstablished(identity);
244
+ warnIfLoopbackBindBlocksRemoteController(controllerUrl);
160
245
  // Restart server with worker ID and task executor
161
246
  await startServer();
162
247
  }
@@ -168,6 +253,7 @@ export function createWorkerService(deps) {
168
253
  controllerUrl = newIdentity.controllerUrl;
169
254
  workerId = newIdentity.workerId;
170
255
  onIdentityEstablished(newIdentity);
256
+ warnIfLoopbackBindBlocksRemoteController(controllerUrl);
171
257
  await startServer();
172
258
  }
173
259
  return;
@@ -179,7 +265,7 @@ export function createWorkerService(deps) {
179
265
  const heartbeat = createHeartbeatPayload(id.workerId, activeTaskId ? "busy" : "idle", activeTaskId);
180
266
  const res = await fetch(`${controllerUrl}/api/v1/workers/${id.workerId}/heartbeat`, {
181
267
  method: "POST",
182
- headers: { "Content-Type": "application/json" },
268
+ headers: withDeviceToken(config, { "Content-Type": "application/json" }),
183
269
  body: JSON.stringify(heartbeat),
184
270
  });
185
271
  if (!res.ok) {
package/index.ts CHANGED
@@ -16,6 +16,9 @@ import { createControllerTools } from "./src/controller/controller-tools.js";
16
16
  import { publishWorkerRepo, syncWorkerRepo } from "./src/git-collaboration.js";
17
17
  import { resolveTeamClawProjectsDir } from "./src/openclaw-workspace.js";
18
18
  import { installRecommendedSkills } from "./src/worker/skill-installer.js";
19
+ // W6 of issue #226: local swallowing pathExists copy replaced by the shared
20
+ // one (identical semantics; alias keeps the call site byte-identical).
21
+ import { pathExistsTolerant as pathExists } from "./src/shared/utils.js";
19
22
 
20
23
  export default definePluginEntry({
21
24
  id: "teamclaw",
@@ -84,34 +87,42 @@ function registerController(api: OpenClawPluginApi, config: ReturnType<typeof pa
84
87
  });
85
88
  }
86
89
 
87
- function registerWorker(api: OpenClawPluginApi, config: ReturnType<typeof parsePluginConfig>) {
88
- const logger = api.logger;
89
- const messageQueue = new MessageQueue();
90
- let currentControllerUrl: string | null = null;
91
- let currentWorkerId: string | null = null;
92
-
93
- function getIdentity(): WorkerIdentity | null {
94
- if (!currentWorkerId || !currentControllerUrl) return null;
95
- return {
96
- workerId: currentWorkerId,
97
- role: config.role,
98
- controllerUrl: currentControllerUrl,
99
- registeredAt: Date.now(),
100
- };
101
- }
90
+ /**
91
+ * Issue #23 (client wave): headers for worker -> controller calls, same
92
+ * pattern as identity.ts / worker-service.ts / worker/tools.ts. A configured
93
+ * device token rides X-TeamClaw-Token; without one the headers are unchanged
94
+ * (L0). The token value is never logged.
95
+ */
96
+ function withDeviceToken(config: ReturnType<typeof parsePluginConfig>, headers: Record<string, string>): Record<string, string> {
97
+ const token = config.securityToken?.trim();
98
+ return token ? { ...headers, "X-TeamClaw-Token": token } : headers;
99
+ }
102
100
 
101
+ /**
102
+ * Execution-event + checkpoint reporters (issue #23 review follow-up: the
103
+ * execution stream and resume checkpoints MUST survive device protection, so
104
+ * both POSTs carry the paired device token). Extracted from registerWorker
105
+ * as an exported factory so the dist-level client tests can exercise the
106
+ * real header behavior against a stub controller.
107
+ */
108
+ export function createWorkerEventReporters(
109
+ config: ReturnType<typeof parsePluginConfig>,
110
+ logger: { warn(entry: string): void },
111
+ state: { getControllerUrl: () => string | null; getWorkerId: () => string | null },
112
+ ) {
103
113
  async function reportExecutionEvent(taskId: string, event: TaskExecutionEventInput): Promise<void> {
104
- if (!currentControllerUrl) {
114
+ const controllerUrl = state.getControllerUrl();
115
+ if (!controllerUrl) {
105
116
  return;
106
117
  }
107
118
 
108
119
  try {
109
- const res = await fetch(`${currentControllerUrl}/api/v1/tasks/${taskId}/execution`, {
120
+ const res = await fetch(`${controllerUrl}/api/v1/tasks/${taskId}/execution`, {
110
121
  method: "POST",
111
- headers: { "Content-Type": "application/json" },
122
+ headers: withDeviceToken(config, { "Content-Type": "application/json" }),
112
123
  body: JSON.stringify({
113
124
  ...event,
114
- workerId: currentWorkerId ?? undefined,
125
+ workerId: state.getWorkerId() ?? undefined,
115
126
  role: config.role,
116
127
  }),
117
128
  });
@@ -124,20 +135,47 @@ function registerWorker(api: OpenClawPluginApi, config: ReturnType<typeof parseP
124
135
  }
125
136
 
126
137
  async function reportCheckpoint(taskId: string, checkpoint: { lastAssistantMessage: string; progressNote?: string; sessionKey: string }): Promise<void> {
127
- if (!currentControllerUrl) {
138
+ const controllerUrl = state.getControllerUrl();
139
+ if (!controllerUrl) {
128
140
  return;
129
141
  }
130
142
  try {
131
- await fetch(`${currentControllerUrl}/api/v1/tasks/${taskId}/checkpoint`, {
143
+ await fetch(`${controllerUrl}/api/v1/tasks/${taskId}/checkpoint`, {
132
144
  method: "POST",
133
- headers: { "Content-Type": "application/json" },
134
- body: JSON.stringify({ ...checkpoint, workerId: currentWorkerId ?? undefined }),
145
+ headers: withDeviceToken(config, { "Content-Type": "application/json" }),
146
+ body: JSON.stringify({ ...checkpoint, workerId: state.getWorkerId() ?? undefined }),
135
147
  });
136
148
  } catch {
137
149
  // Checkpointing is best-effort; a lost heartbeat only costs resume freshness.
138
150
  }
139
151
  }
140
152
 
153
+ return { reportExecutionEvent, reportCheckpoint };
154
+ }
155
+
156
+ function registerWorker(api: OpenClawPluginApi, config: ReturnType<typeof parsePluginConfig>) {
157
+ const logger = api.logger;
158
+ const messageQueue = new MessageQueue();
159
+ let currentControllerUrl: string | null = null;
160
+ let currentWorkerId: string | null = null;
161
+
162
+ function getIdentity(): WorkerIdentity | null {
163
+ if (!currentWorkerId || !currentControllerUrl) return null;
164
+ return {
165
+ workerId: currentWorkerId,
166
+ role: config.role,
167
+ controllerUrl: currentControllerUrl,
168
+ registeredAt: Date.now(),
169
+ };
170
+ }
171
+
172
+ const { reportExecutionEvent, reportCheckpoint } = createWorkerEventReporters(config, logger, {
173
+ // Read through getters so the reporters always see the identity the
174
+ // worker service has established by the time an event fires.
175
+ getControllerUrl: () => currentControllerUrl,
176
+ getWorkerId: () => currentWorkerId,
177
+ });
178
+
141
179
  const getWorkerSessionKey = (assignment: TaskAssignmentPayload) =>
142
180
  assignment.executionSessionKey?.trim() || `teamclaw-task-${assignment.taskId}`;
143
181
 
@@ -171,15 +209,6 @@ function registerWorker(api: OpenClawPluginApi, config: ReturnType<typeof parseP
171
209
  return { sharedProjectDir, localProjectDir };
172
210
  }
173
211
 
174
- async function pathExists(targetPath: string): Promise<boolean> {
175
- try {
176
- await fs.access(targetPath);
177
- return true;
178
- } catch {
179
- return false;
180
- }
181
- }
182
-
183
212
  async function syncProjectDir(sourceDir: string, destinationDir: string): Promise<boolean> {
184
213
  if (!await pathExists(sourceDir)) {
185
214
  return false;
@@ -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.8.1",
5
+ "version": "2026.11.1",
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,10 +68,14 @@
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",
66
- "help": "Maximum number of tasks that can be in 'in_progress' status at the same time (1\u201350)"
78
+ "help": "Maximum number of tasks that can be in 'in_progress' status at the same time (1–50)"
67
79
  },
68
80
  "gitEnabled": {
69
81
  "label": "Git Collaboration",
@@ -94,6 +106,10 @@
94
106
  "hint": "optional - prefer the TEAMCLAW_GITHUB_CLIENT_SECRET env var",
95
107
  "help": "GitHub App OAuth client secret; the TEAMCLAW_GITHUB_CLIENT_SECRET environment variable takes precedence"
96
108
  },
109
+ "security": {
110
+ "label": "Device Pairing Security",
111
+ "help": "Controller device-pairing options; autoPair allows LAN devices to pair with zero input (POST /api/v1/security/pair-auto), disable it to require a pairing code for every new device"
112
+ },
97
113
  "agentIsolationMode": {
98
114
  "label": "Agent Isolation Mode",
99
115
  "help": "Use a dedicated TeamClaw agent/workspace by default, or the legacy shared main-agent mode"
@@ -208,6 +224,11 @@
208
224
  "default": 9527,
209
225
  "description": "HTTP server port for this instance"
210
226
  },
227
+ "listenHost": {
228
+ "type": "string",
229
+ "default": "",
230
+ "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"
231
+ },
211
232
  "role": {
212
233
  "type": "string",
213
234
  "default": "developer",
@@ -223,6 +244,11 @@
223
244
  "default": "TeamClaw",
224
245
  "description": "Team name for mDNS identification"
225
246
  },
247
+ "teamProfile": {
248
+ "type": "string",
249
+ "default": "software-rd",
250
+ "description": "Team profile package id (software-rd baseline); seeds first initialization only - the persisted team state profile is the runtime truth"
251
+ },
226
252
  "heartbeatIntervalMs": {
227
253
  "type": "number",
228
254
  "default": 10000,
@@ -233,6 +259,11 @@
233
259
  "default": 600000,
234
260
  "description": "Inactivity threshold in milliseconds before TeamClaw probes a stalled role task instead of failing it"
235
261
  },
262
+ "teamSwitchDrainTimeoutMs": {
263
+ "type": "number",
264
+ "default": 30000,
265
+ "description": "How long a team profile switch waits for in-flight tasks to finish before force-collecting them (design 2.3 graceful drain)"
266
+ },
236
267
  "maxConcurrentTasks": {
237
268
  "type": "integer",
238
269
  "default": 5,
@@ -275,6 +306,23 @@
275
306
  "default": "",
276
307
  "description": "GitHub App OAuth client secret; the TEAMCLAW_GITHUB_CLIENT_SECRET environment variable takes precedence"
277
308
  },
309
+ "security": {
310
+ "type": "object",
311
+ "default": {},
312
+ "description": "Controller device-pairing security (issue #23); protection itself is enabled per-team via POST /api/v1/security/enable",
313
+ "properties": {
314
+ "autoPair": {
315
+ "type": "boolean",
316
+ "default": true,
317
+ "description": "Allow zero-input pairing from LAN peers (POST /api/v1/security/pair-auto); disable to require a pairing code for every new device"
318
+ }
319
+ }
320
+ },
321
+ "securityToken": {
322
+ "type": "string",
323
+ "default": "",
324
+ "description": "Device pairing token for a protected controller (issue #23); written by `teamclaw pair`, sent as X-TeamClaw-Token on API calls. Leave empty for unpaired local mode"
325
+ },
278
326
  "agentIsolationMode": {
279
327
  "type": "string",
280
328
  "enum": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamclaws/teamclaw",
3
- "version": "2026.8.1",
3
+ "version": "2026.11.1",
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"