@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
package/src/types.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  import { TEAMCLAW_PUBLISHED_RUNTIME_IMAGE } from "./install-defaults.js";
2
- import { DEFAULT_GITHUB_CLIENT_ID } from "./controller/github-auth.js";
2
+ import { DEFAULT_GITHUB_CLIENT_ID } from "./shared/github-auth.js";
3
+ // Safe value import: roles.js only pulls prompt-policy.js -> openclaw-workspace.js
4
+ // at runtime (its types.js import is type-only), so no module cycle is formed.
5
+ import { DEFAULT_ROLE } from "./roles.js";
6
+ import { validateRoleId, validateRoleIdList } from "./roles.js";
7
+ import { ROLE_IDS } from "./roles.js";
8
+ // Phase 1.6: profile-loader has no runtime edge back into this module (its
9
+ // types.js import is type-only), so the software-rd baseline id stays a
10
+ // single literal shared with the loader.
11
+ import { SOFTWARE_RD_PROFILE_ID } from "./profile-loader.js";
3
12
 
4
13
  export type TeamClawMode = "controller" | "worker";
5
14
 
@@ -64,6 +73,22 @@ export type RepoSyncInfo = {
64
73
  headSummary?: string;
65
74
  };
66
75
 
76
+ /**
77
+ * Phase 1.1 (vertical-team-profiles-design.md v1.3): RoleId is an open
78
+ * branded string so future TeamProfiles can carry arbitrary role sets;
79
+ * runtime legitimacy of a role id is enforced by validateRoleId/
80
+ * validateRoleIdList in roles.ts (Phase 0.3), not by the compiler.
81
+ *
82
+ * Hybrid form ruling (design v1.3, section 1.5 errata + section 6
83
+ * decision): TS 5.9 - the repo-locked compiler - rejects direct assignment
84
+ * of string literals to `string & { __roleId: true }` (the #33050
85
+ * unsoundness fix), while the role definitions in roles.ts/role-ids.ts
86
+ * are pure JS array literals that the manifest generator regex-extracts
87
+ * and evaluates, and their RoleId[] annotations are pinned by
88
+ * tests/test-role-single-source.mjs. The software-rd seed ids therefore
89
+ * stay as a literal arm; any other string must pass validateRoleId or an
90
+ * explicit cast to enter the branded arm.
91
+ */
67
92
  export type RoleId =
68
93
  | "pm"
69
94
  | "architect"
@@ -75,7 +100,8 @@ export type RoleId =
75
100
  | "security-engineer"
76
101
  | "designer"
77
102
  | "marketing"
78
- | "data-engineer";
103
+ | "data-engineer"
104
+ | (string & { __roleId: true });
79
105
 
80
106
  export type RoleDefinition = {
81
107
  id: RoleId;
@@ -132,6 +158,37 @@ export type TaskInfo = {
132
158
  /** Surviving progress snapshot for interrupted executions (resume support). */
133
159
  checkpoint?: TaskCheckpoint;
134
160
  resumeAttempt?: number;
161
+ /**
162
+ * Design 2.4 workflow-chain membership: set ONLY by the workflow engine
163
+ * (controller/workflow-routes.ts) when it creates a step task, never by
164
+ * client task creation (the create route builds TaskInfo field-by-field
165
+ * and does not accept this field). The task-completion hook reads it to
166
+ * route the chain by the step's conclusion. The task chain itself is the
167
+ * workflow run state - there is no separate run registry by design.
168
+ */
169
+ workflow?: TaskWorkflowContext;
170
+ };
171
+
172
+ /**
173
+ * Workflow-chain context carried on each design-2.4 step task. `visitCounts`
174
+ * is the loop guard for return edges (e.g. 退回补充材料 -> step 0) and the
175
+ * routed* fields are the once-only routing latch: exactly one completion of
176
+ * a step task may spawn the follow-up task.
177
+ */
178
+ export type TaskWorkflowContext = {
179
+ /** Profile workflow template id (e.g. "credit-approval"). */
180
+ workflowId: string;
181
+ /** Run nonce shared by every task of one started workflow instance. */
182
+ runId: string;
183
+ /** String form of the executed step's id (numeric spine or branch key). */
184
+ stepKey: string;
185
+ /** Visits per step key so return edges cannot loop forever. */
186
+ visitCounts?: Record<string, number>;
187
+ /** Routing latch: step key the completion hook routed to (chain end = ""). */
188
+ routedToStepKey?: string;
189
+ routedAt?: number;
190
+ /** Conclusion phrase that drove the routing (observability/audit). */
191
+ routedConclusion?: string;
135
192
  };
136
193
 
137
194
  export type TaskExecutionEvent = {
@@ -494,9 +551,23 @@ export type TeamProvisioningState = {
494
551
  export type PluginConfig = {
495
552
  mode: TeamClawMode;
496
553
  port: number;
554
+ /**
555
+ * Issue #27: explicit HTTP listen host override for the worker HTTP server.
556
+ * Empty/undefined = follow the default policy (127.0.0.1 on hosts,
557
+ * 0.0.0.0 inside containers) - same resolution the controller applies.
558
+ */
559
+ listenHost?: string;
497
560
  role: RoleId;
498
561
  controllerUrl: string;
499
562
  teamName: string;
563
+ /**
564
+ * Phase 1.6 (vertical-team-profiles-design.md section 2.3): the team
565
+ * profile package id. Bootstrap value for FIRST initialization only -
566
+ * once a TeamState exists, TeamState.profileId is the single runtime
567
+ * truth and config changes have no effect (profile switching lands in
568
+ * Phase 2).
569
+ */
570
+ teamProfile: string;
500
571
  heartbeatIntervalMs: number;
501
572
  processModel: ProcessModel;
502
573
  /**
@@ -506,6 +577,12 @@ export type PluginConfig = {
506
577
  */
507
578
  roleModelOverrides?: Partial<Record<RoleId, string>>;
508
579
  taskTimeoutMs: number;
580
+ /**
581
+ * Phase 2.1 (design section 2.3, switch step 2): how long a profile switch
582
+ * drains in-flight tasks (assigned/in_progress) before force-collecting
583
+ * them and terminating the workers.
584
+ */
585
+ teamSwitchDrainTimeoutMs: number;
509
586
  gitEnabled: boolean;
510
587
  gitRemoteUrl: string;
511
588
  gitDefaultBranch: string;
@@ -519,6 +596,19 @@ export type PluginConfig = {
519
596
  */
520
597
  githubClientSecret: string;
521
598
  agentIsolationMode: AgentIsolationMode;
599
+ /**
600
+ * Issue #23: controller device-pairing security options. Parsed with
601
+ * safe defaults (autoPair: true) so hand-built configs without the key
602
+ * keep the L1 zero-input LAN pairing behavior.
603
+ */
604
+ security?: SecurityConfig;
605
+ /**
606
+ * Issue #23 (client wave): device token this instance presents to a
607
+ * protected controller (X-TeamClaw-Token on every API call). Written by
608
+ * `teamclaw pair` / the desktop pairing flow; empty string = unpaired L0
609
+ * behavior. NEVER logged or echoed back through config UIs.
610
+ */
611
+ securityToken: string;
522
612
  workerProvisioningType: WorkerProvisioningType;
523
613
  workerProvisioningDisabled: boolean;
524
614
  workerProvisioningControllerUrl: string;
@@ -551,9 +641,98 @@ export type WorkerIdentity = {
551
641
  registeredAt: number;
552
642
  };
553
643
 
644
+ // ===========================================================================
645
+ // Device pairing security (issue #23, backend wave).
646
+ //
647
+ // Zero-friction ladder (product semantics, FIXED):
648
+ // L0 local - no devices persisted => no authentication at all (the
649
+ // historical behavior; a state without `security` is L0)
650
+ // L1 LAN - LAN peers (loopback / RFC1918 / ULA / link-local) may
651
+ // self-pair via POST /api/v1/security/pair-auto while
652
+ // config.security.autoPair is true (default)
653
+ // L2 exposed - one-shot 60s pairing codes minted by an authenticated
654
+ // device or the loopback console
655
+ // The user never configures a token and the UI never shows a login page.
656
+ // Tokens are 32-byte hex secrets returned to the pairing caller EXACTLY
657
+ // ONCE; only their sha256 hex digest is persisted.
658
+ // ===========================================================================
659
+
660
+ export type SecurityDeviceKind = "web" | "worker" | "desktop" | "cli";
661
+
662
+ export type SecurityDevice = {
663
+ id: string;
664
+ name: string;
665
+ kind: SecurityDeviceKind;
666
+ /** sha256 hex of the device token. The plaintext token is never persisted. */
667
+ tokenHash: string;
668
+ createdAt: number;
669
+ /** Epoch ms of the last authenticated request (throttled persistence). */
670
+ lastSeenAt?: number;
671
+ /** Where the device paired from (peer IP, or "loopback" for the console). */
672
+ origin?: string;
673
+ };
674
+
675
+ export type SecurityPairingCode = {
676
+ /** 8-character uppercase base32 (RFC 4648) code, displayed once to a human. */
677
+ code: string;
678
+ /** Absolute expiry (epoch ms); pairing codes live 60 seconds. */
679
+ expiresAt: number;
680
+ purpose: string;
681
+ /** Set when consumed; a used code can never pair a second device. */
682
+ usedAt?: number;
683
+ };
684
+
685
+ export type NonLanPeerObservation = {
686
+ ip: string;
687
+ at: number;
688
+ path: string;
689
+ };
690
+
691
+ export type TeamSecurityState = {
692
+ /** Set when protection was first enabled (first device minted); the suggestion signal below may exist without it while still L0. */
693
+ enabledAt?: number;
694
+ /** Protection is ON iff this array is non-empty (the L0/L1/L2 ladder switch). */
695
+ devices: SecurityDevice[];
696
+ pairingCode?: SecurityPairingCode;
697
+ /** Suggestion signal: latest non-LAN peer observed while protection is off. */
698
+ lastNonLanPeer?: NonLanPeerObservation;
699
+ };
700
+
701
+ export type SecurityConfig = {
702
+ /** Allow zero-input pairing from LAN peers (POST /api/v1/security/pair-auto). */
703
+ autoPair: boolean;
704
+ };
705
+
706
+ /**
707
+ * Phase 2.1 (vertical-team-profiles-design.md section 2.3): the transition
708
+ * state machine for an in-flight team profile switch. Persisted inside
709
+ * TeamState so a controller crash can resume idempotently (archive file
710
+ * exists -> rebuild the new team; otherwise re-drain from scratch).
711
+ */
712
+ export type TeamSwitchTransitionPhase = "draining" | "archiving" | "warming";
713
+
714
+ export type TeamSwitchTransition = {
715
+ phase: TeamSwitchTransitionPhase;
716
+ targetProfileId: string;
717
+ startedAt: number;
718
+ };
719
+
554
720
  export type TeamState = {
555
721
  /** Schema version for forward-compatible state migration. */
556
722
  version?: number;
723
+ /**
724
+ * Phase 1.6 (design section 2.3): the active TeamProfile id. Single
725
+ * runtime truth - config teamProfile only seeds first initialization.
726
+ * Legacy states without this field migrate to the software-rd baseline.
727
+ */
728
+ profileId: string;
729
+ /**
730
+ * Phase 2.1 (design section 2.3): set while a profile switch is in
731
+ * progress (drain -> archive -> rebuild -> warmup). Absent on a settled
732
+ * team. Its presence drives the 409/503 concurrency matrix and the
733
+ * crash-resume path in the controller startup chain.
734
+ */
735
+ transition?: TeamSwitchTransition;
557
736
  teamName: string;
558
737
  workers: Record<string, WorkerInfo>;
559
738
  tasks: Record<string, TaskInfo>;
@@ -565,6 +744,13 @@ export type TeamState = {
565
744
  provisioning?: TeamProvisioningState;
566
745
  previews?: Record<string, DynamicPreviewRecord>;
567
746
  reports?: Record<string, DeliveryReportRecord>;
747
+ /**
748
+ * Issue #23: device-pairing security state. ABSENT or carrying an empty
749
+ * devices array = protection off (L0 zero-friction default, the exact
750
+ * pre-issue behavior); a non-empty devices array turns the auth
751
+ * middleware on (see controller/security.ts).
752
+ */
753
+ security?: TeamSecurityState;
568
754
  createdAt: number;
569
755
  updatedAt: number;
570
756
  };
@@ -621,8 +807,9 @@ function parseRoleModelOverrides(raw: unknown): Partial<Record<RoleId, string>>
621
807
  const result: Partial<Record<RoleId, string>> = {};
622
808
  let hasAny = false;
623
809
  for (const [key, value] of Object.entries(raw as Record<string, unknown>)) {
624
- if (VALID_ROLES.includes(key as RoleId) && typeof value === "string" && value.trim()) {
625
- result[key as RoleId] = value.trim();
810
+ const roleKey = validateRoleId(key);
811
+ if (roleKey && typeof value === "string" && value.trim()) {
812
+ result[roleKey] = value.trim();
626
813
  hasAny = true;
627
814
  }
628
815
  }
@@ -638,9 +825,39 @@ export function parsePluginConfig(raw: Record<string, unknown> = {}): PluginConf
638
825
  ? raw.port
639
826
  : 9527;
640
827
 
641
- const role = typeof raw.role === "string" && VALID_ROLES.includes(raw.role as RoleId)
642
- ? raw.role as RoleId
643
- : "developer" as RoleId;
828
+ // Issue #27: explicit listen-host override for the worker HTTP server.
829
+ // Empty/absent keeps the default policy (loopback on hosts, all interfaces
830
+ // in containers) resolved in worker-service.ts.
831
+ const listenHost = typeof raw.listenHost === "string" && raw.listenHost.trim()
832
+ ? raw.listenHost.trim()
833
+ : undefined;
834
+
835
+ // Issue #27: 9527 is ALSO the controller's default port. A controller and a
836
+ // worker on the same host both defaulting to it collide with a confusing
837
+ // EADDRINUSE at startup. Only the same-host dual-process case is a problem -
838
+ // an external worker legitimately using 9527 must keep working - so this
839
+ // stays a parse-time warning, never an error.
840
+ if (mode === "worker" && port === 9527) {
841
+ console.warn(
842
+ "[teamclaw] config warning: worker mode uses port 9527, which is also the controller default. " +
843
+ "Running a controller and this worker on the same host will conflict (EADDRINUSE); set this worker's `port` config key to another value in that topology.",
844
+ );
845
+ }
846
+
847
+ // Issue #192 (Phase 3 prerequisite): lenient worker-side role parsing.
848
+ // The registry validateRoleId folded any unknown role string (e.g. a
849
+ // minimal-bank "credit-officer") to developer, so a worker provisioned
850
+ // under an industry profile registered with the WRONG role against its
851
+ // controller (mismatch or 400). A non-empty string role is now preserved
852
+ // as written - RoleId is an open branded string and this explicit cast is
853
+ // the documented way for non-seed ids to enter (see the RoleId ruling
854
+ // above) - and legitimacy is finally adjudicated by the controller's
855
+ // validateActiveRoleId at registration, where the ACTIVE profile is the
856
+ // single source of truth. DEFAULT_ROLE still applies only when the role
857
+ // is missing, not a string, or blank.
858
+ const role = typeof raw.role === "string" && raw.role.trim()
859
+ ? (raw.role.trim() as RoleId)
860
+ : DEFAULT_ROLE;
644
861
 
645
862
  const controllerUrl = typeof raw.controllerUrl === "string"
646
863
  ? raw.controllerUrl.trim()
@@ -650,6 +867,13 @@ export function parsePluginConfig(raw: Record<string, unknown> = {}): PluginConf
650
867
  ? raw.teamName.trim()
651
868
  : "TeamClaw";
652
869
 
870
+ // Phase 1.6: first-initialization bootstrap value. Existence of the id is
871
+ // checked by the controller startup chain (unknown ids fall back to the
872
+ // software-rd baseline with a warning); here we only normalize the shape.
873
+ const teamProfile = typeof raw.teamProfile === "string" && raw.teamProfile.trim()
874
+ ? raw.teamProfile.trim()
875
+ : SOFTWARE_RD_PROFILE_ID;
876
+
653
877
  const heartbeatIntervalMs = typeof raw.heartbeatIntervalMs === "number" && raw.heartbeatIntervalMs >= 1000
654
878
  ? raw.heartbeatIntervalMs
655
879
  : 10000;
@@ -660,6 +884,11 @@ export function parsePluginConfig(raw: Record<string, unknown> = {}): PluginConf
660
884
  ? raw.taskTimeoutMs
661
885
  : 600_000;
662
886
 
887
+ // Phase 2.1: graceful-drain budget for a team profile switch (design 2.3).
888
+ const teamSwitchDrainTimeoutMs = typeof raw.teamSwitchDrainTimeoutMs === "number" && raw.teamSwitchDrainTimeoutMs >= 1000
889
+ ? raw.teamSwitchDrainTimeoutMs
890
+ : 30_000;
891
+
663
892
  const gitEnabled = typeof raw.gitEnabled === "boolean" ? raw.gitEnabled : true;
664
893
 
665
894
  const gitRemoteUrl = typeof raw.gitRemoteUrl === "string"
@@ -691,6 +920,20 @@ export function parsePluginConfig(raw: Record<string, unknown> = {}): PluginConf
691
920
  ? raw.agentIsolationMode
692
921
  : "independent";
693
922
 
923
+ // Issue #23: security.autoPair defaults to true (L1 zero-input LAN
924
+ // pairing); only an explicit boolean false disables pair-auto.
925
+ const rawSecurity = raw.security;
926
+ const rawAutoPair = rawSecurity && typeof rawSecurity === "object" && !Array.isArray(rawSecurity)
927
+ ? (rawSecurity as { autoPair?: unknown }).autoPair
928
+ : undefined;
929
+ const security: SecurityConfig = {
930
+ autoPair: typeof rawAutoPair === "boolean" ? rawAutoPair : true,
931
+ };
932
+
933
+ // Issue #23 (client wave): the paired device token, if this instance
934
+ // paired with a protected controller. Empty/absent keeps L0 behavior.
935
+ const securityToken = typeof raw.securityToken === "string" ? raw.securityToken.trim() : "";
936
+
694
937
  const rawWorkerProvisioningType = parseProvisioningType(raw.workerProvisioningType);
695
938
  const workerProvisioningDisabled = raw.workerProvisioningDisabled === true;
696
939
  // Legacy local installs often persisted workerProvisioningType="none" without
@@ -780,13 +1023,16 @@ export function parsePluginConfig(raw: Record<string, unknown> = {}): PluginConf
780
1023
  return {
781
1024
  mode,
782
1025
  port,
1026
+ listenHost,
783
1027
  role,
784
1028
  controllerUrl,
785
1029
  teamName,
1030
+ teamProfile,
786
1031
  heartbeatIntervalMs,
787
1032
  processModel,
788
1033
  roleModelOverrides: parseRoleModelOverrides(raw.roleModelOverrides),
789
1034
  taskTimeoutMs,
1035
+ teamSwitchDrainTimeoutMs,
790
1036
  gitEnabled,
791
1037
  gitRemoteUrl,
792
1038
  gitDefaultBranch,
@@ -795,6 +1041,8 @@ export function parsePluginConfig(raw: Record<string, unknown> = {}): PluginConf
795
1041
  githubClientId,
796
1042
  githubClientSecret,
797
1043
  agentIsolationMode,
1044
+ security,
1045
+ securityToken,
798
1046
  workerProvisioningType,
799
1047
  workerProvisioningDisabled,
800
1048
  workerProvisioningControllerUrl,
@@ -822,11 +1070,9 @@ export function parsePluginConfig(raw: Record<string, unknown> = {}): PluginConf
822
1070
  }
823
1071
 
824
1072
  function parseRoleList(raw: unknown): RoleId[] {
825
- return Array.isArray(raw)
826
- ? [...new Set(raw
827
- .filter((entry): entry is RoleId => typeof entry === "string" && VALID_ROLES.includes(entry as RoleId))
828
- .map((entry) => entry as RoleId))]
829
- : [];
1073
+ // Phase 0.3: delegates to the shared validateRoleIdList guard in roles.ts
1074
+ // (same filter + first-occurrence dedup semantics as before).
1075
+ return validateRoleIdList(raw);
830
1076
  }
831
1077
 
832
1078
  function parseProvisioningType(raw: unknown): WorkerProvisioningType {
@@ -877,8 +1123,8 @@ const VALID_PROVISIONING_TYPES: WorkerProvisioningType[] = [
877
1123
  "kubernetes",
878
1124
  ];
879
1125
 
880
- const VALID_ROLES: RoleId[] = [
881
- "pm", "architect", "developer", "qa",
882
- "release-engineer", "infra-engineer", "devops", "security-engineer",
883
- "designer", "marketing", "data-engineer",
884
- ];
1126
+ // Not referenced at runtime anymore: role validation goes through
1127
+ // validateRoleId/validateRoleIdList in roles.ts (Phase 0.3). Phase 1.2 folds
1128
+ // the former hand-written copy into the registry: the value now derives from
1129
+ // roles.ts ROLE_IDS so it can never drift from the single source of truth.
1130
+ const VALID_ROLES: RoleId[] = ROLE_IDS;