@teamclaws/teamclaw 2026.8.1 → 2026.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/cli.mjs +46 -15
  2. package/dist/src/config.js +33 -2
  3. package/dist/src/controller/clarification-routes.js +315 -0
  4. package/dist/src/controller/controller-intake.js +895 -0
  5. package/dist/src/controller/controller-planning.js +813 -0
  6. package/dist/src/controller/controller-runs.js +175 -0
  7. package/dist/src/controller/controller-service.js +271 -40
  8. package/dist/src/controller/controller-tools.js +11 -6
  9. package/dist/src/controller/http-server.js +256 -6004
  10. package/dist/src/controller/kickoff-orchestrator.js +32 -6
  11. package/dist/src/controller/message-delivery.js +28 -0
  12. package/dist/src/controller/message-routes.js +114 -0
  13. package/dist/src/controller/orchestration-manifest.js +6 -28
  14. package/dist/src/controller/preview-proxy.js +98 -0
  15. package/dist/src/controller/profile-switch.js +289 -0
  16. package/dist/src/controller/project-registry.js +294 -0
  17. package/dist/src/controller/prompt-injector.js +19 -9
  18. package/dist/src/controller/repo-routes.js +63 -0
  19. package/dist/src/controller/role-inference.js +231 -20
  20. package/dist/src/controller/route-table.js +1353 -0
  21. package/dist/src/controller/task-assignment.js +508 -0
  22. package/dist/src/controller/task-cleanup.js +258 -0
  23. package/dist/src/controller/task-execution.js +240 -0
  24. package/dist/src/controller/task-results.js +461 -0
  25. package/dist/src/controller/task-router.js +74 -4
  26. package/dist/src/controller/task-routes.js +703 -0
  27. package/dist/src/controller/teamauto-routes.js +124 -0
  28. package/dist/src/controller/ui-assets.js +68 -0
  29. package/dist/src/controller/worker-provisioning.js +30 -4
  30. package/dist/src/controller/worker-routes.js +188 -0
  31. package/dist/src/identity.js +3 -2
  32. package/dist/src/interaction-contracts.js +7 -7
  33. package/dist/src/openclaw-workspace.js +40 -18
  34. package/dist/src/profile-loader.js +486 -0
  35. package/dist/src/profiles/banking.json +178 -0
  36. package/dist/src/profiles/crossborder-ecom.json +253 -0
  37. package/dist/src/profiles/insurance.json +157 -0
  38. package/dist/src/profiles/knowledge/hs-structure.md +97 -0
  39. package/dist/src/profiles/knowledge/incoterms-2020.md +188 -0
  40. package/dist/src/profiles/knowledge/vat-principles.md +85 -0
  41. package/dist/src/profiles/schema.json +201 -0
  42. package/dist/src/profiles/securities.json +137 -0
  43. package/dist/src/profiles/software-rd.json +264 -0
  44. package/dist/src/profiles/trading-co.json +200 -0
  45. package/dist/src/prompt-policy.js +26 -13
  46. package/dist/src/role-ids.js +29 -0
  47. package/dist/src/roles.js +54 -13
  48. package/dist/src/session-roles.js +14 -0
  49. package/dist/src/state.js +188 -10
  50. package/dist/src/task-executor.js +7 -17
  51. package/dist/src/teamauto/github-client.js +18 -0
  52. package/dist/src/teamauto/repo-sync.js +228 -6
  53. package/dist/src/teamauto/scanner.js +40 -12
  54. package/dist/src/teamauto/scheduler.js +231 -12
  55. package/dist/src/types.js +62 -15
  56. package/dist/src/ui/app.js +592 -24
  57. package/dist/src/ui/index.html +44 -11
  58. package/dist/src/ui/style.css +194 -0
  59. package/dist/src/worker/prompt-injector.js +44 -8
  60. package/dist/src/worker/skill-installer.js +3 -1
  61. package/dist/src/worker/worker-service.js +76 -3
  62. package/openclaw.plugin.json +28 -1
  63. package/package.json +3 -2
  64. package/src/config.ts +33 -2
  65. package/src/controller/clarification-routes.ts +404 -0
  66. package/src/controller/controller-intake.ts +1113 -0
  67. package/src/controller/controller-planning.ts +1029 -0
  68. package/src/controller/controller-runs.ts +239 -0
  69. package/src/controller/controller-service.ts +295 -41
  70. package/src/controller/controller-tools.ts +11 -7
  71. package/src/controller/http-server.ts +294 -6971
  72. package/src/controller/kickoff-orchestrator.ts +70 -7
  73. package/src/controller/message-delivery.ts +49 -0
  74. package/src/controller/message-routes.ts +137 -0
  75. package/src/controller/orchestration-manifest.ts +6 -29
  76. package/src/controller/preview-proxy.ts +127 -0
  77. package/src/controller/profile-switch.ts +366 -0
  78. package/src/controller/project-registry.ts +361 -0
  79. package/src/controller/prompt-injector.ts +23 -8
  80. package/src/controller/repo-routes.ts +91 -0
  81. package/src/controller/role-inference.ts +260 -22
  82. package/src/controller/route-table.ts +1616 -0
  83. package/src/controller/task-assignment.ts +618 -0
  84. package/src/controller/task-cleanup.ts +344 -0
  85. package/src/controller/task-execution.ts +356 -0
  86. package/src/controller/task-results.ts +544 -0
  87. package/src/controller/task-router.ts +98 -6
  88. package/src/controller/task-routes.ts +812 -0
  89. package/src/controller/teamauto-routes.ts +121 -0
  90. package/src/controller/ui-assets.ts +70 -0
  91. package/src/controller/websocket.ts +13 -1
  92. package/src/controller/worker-provisioning.ts +32 -4
  93. package/src/controller/worker-routes.ts +241 -0
  94. package/src/identity.ts +3 -2
  95. package/src/interaction-contracts.ts +7 -7
  96. package/src/openclaw-workspace.ts +44 -18
  97. package/src/profile-loader.ts +650 -0
  98. package/src/profiles/banking.json +178 -0
  99. package/src/profiles/crossborder-ecom.json +253 -0
  100. package/src/profiles/insurance.json +157 -0
  101. package/src/profiles/knowledge/hs-structure.md +97 -0
  102. package/src/profiles/knowledge/incoterms-2020.md +188 -0
  103. package/src/profiles/knowledge/vat-principles.md +85 -0
  104. package/src/profiles/schema.json +201 -0
  105. package/src/profiles/securities.json +137 -0
  106. package/src/profiles/software-rd.json +264 -0
  107. package/src/profiles/trading-co.json +200 -0
  108. package/src/prompt-policy.ts +27 -13
  109. package/src/role-ids.ts +31 -0
  110. package/src/roles.ts +60 -14
  111. package/src/session-roles.ts +14 -0
  112. package/src/state.ts +236 -9
  113. package/src/task-executor.ts +7 -18
  114. package/src/teamauto/github-client.ts +21 -0
  115. package/src/teamauto/repo-sync.ts +246 -6
  116. package/src/teamauto/scanner.ts +47 -13
  117. package/src/teamauto/scheduler.ts +259 -16
  118. package/src/teamauto/store.ts +12 -0
  119. package/src/types.ts +133 -16
  120. package/src/ui/app.js +592 -24
  121. package/src/ui/index.html +44 -11
  122. package/src/ui/style.css +194 -0
  123. package/src/worker/prompt-injector.ts +48 -8
  124. package/src/worker/skill-installer.ts +3 -1
  125. package/src/worker/worker-service.ts +83 -3
package/src/ui/index.html CHANGED
@@ -29,6 +29,9 @@
29
29
  <button id="language-toggle" class="header-mini-btn" type="button">中文</button>
30
30
  <button id="toast-settings-toggle" class="header-mini-btn" type="button" title="Toast notifications">Toasts</button>
31
31
  <button id="worker-install-toggle" class="header-mini-btn" type="button" hidden>Add worker</button>
32
+ <!-- Team profile indicator (Phase 5.1): shows the active profile's
33
+ icon + localized name; click opens #team-profile-modal. -->
34
+ <button id="team-profile-toggle" class="header-mini-btn team-profile-toggle" type="button" title="Team profile">Team</button>
32
35
  <span id="team-name">Team</span>
33
36
  <button id="github-corner-login" class="header-mini-btn" type="button">Login</button>
34
37
  <span id="github-corner-user" class="github-corner-user hidden" role="button" tabindex="0" title="GitHub: click to sign out">
@@ -200,6 +203,11 @@
200
203
  <!-- TeamAuto Tab -->
201
204
  <div id="tab-teamauto" class="tab-panel">
202
205
  <div class="teamauto-wrap">
206
+ <div class="ta-subtabs" role="tablist">
207
+ <button type="button" class="ta-subtab active" data-ta-pane="config" data-i18n="teamauto.tabConfig">Config</button>
208
+ <button type="button" class="ta-subtab" data-ta-pane="activity" data-i18n="teamauto.activity">Activity</button>
209
+ </div>
210
+ <div class="ta-pane" data-ta-pane-body="config">
203
211
  <div class="teamauto-bind card">
204
212
  <div class="teamauto-bind-row">
205
213
  <select id="teamauto-repo-select" class="teamauto-select"></select>
@@ -224,8 +232,11 @@
224
232
  <p class="teamauto-hint" data-i18n="teamauto.hint">Pick one of your GitHub repositories. TeamClaw sweeps it on its own schedule, reviews issues/PRs, takes ownership of unassigned issues, and posts results with teamclaw markers.</p>
225
233
  </div>
226
234
  <div id="teamauto-repos" class="teamauto-repos"></div>
235
+ </div>
236
+ <div class="ta-pane is-hidden" data-ta-pane-body="activity">
227
237
  <h3 class="teamauto-section-title" data-i18n="teamauto.activity">Activity</h3>
228
238
  <div id="teamauto-activity" class="teamauto-activity"></div>
239
+ </div>
229
240
  </div>
230
241
  </div>
231
242
 
@@ -258,19 +269,11 @@
258
269
  </div>
259
270
  <div class="form-group">
260
271
  <label for="task-role" data-i18n="manualTask.assignedRole">Assigned Role</label>
272
+ <!-- Role options are rendered by app.js from GET /api/v1/roles
273
+ (renderTaskRoleOptions) so profile-driven role sets need no
274
+ HTML change. Only the Auto-assign placeholder lives here. -->
261
275
  <select id="task-role">
262
276
  <option value="" data-i18n="manualTask.autoAssign">Auto-assign</option>
263
- <option value="pm">Product Manager</option>
264
- <option value="architect">Software Architect</option>
265
- <option value="developer">Developer</option>
266
- <option value="qa">QA Engineer</option>
267
- <option value="release-engineer">Release Engineer</option>
268
- <option value="infra-engineer">Infra Engineer</option>
269
- <option value="devops">DevOps Engineer</option>
270
- <option value="security-engineer">Security Engineer</option>
271
- <option value="designer">UI/UX Designer</option>
272
- <option value="marketing">Marketing Specialist</option>
273
- <option value="data-engineer">Data Engineer</option>
274
277
  </select>
275
278
  </div>
276
279
  </div>
@@ -327,6 +330,36 @@
327
330
  </section>
328
331
  </div>
329
332
 
333
+ <!-- Team profile switcher modal (Phase 5.1): step 1 lists
334
+ GET /api/v1/profiles cards, step 2 confirms the archive consequences
335
+ before POST /api/v1/team/profile; the archived-teams section lists
336
+ GET /api/v1/archived-teams metadata (read-only). -->
337
+ <div id="team-profile-modal" class="workspace-prompt-modal" aria-hidden="true">
338
+ <div class="workspace-prompt-backdrop" data-team-profile-close></div>
339
+ <section class="workspace-prompt-panel team-profile-panel" role="dialog" aria-modal="true" aria-labelledby="team-profile-title">
340
+ <header class="workspace-prompt-header">
341
+ <div class="workspace-prompt-kicker" data-i18n="teamProfile.kicker">Team profile</div>
342
+ <h2 id="team-profile-title" data-i18n="teamProfile.title">Switch team profile</h2>
343
+ </header>
344
+ <div class="workspace-prompt-body">
345
+ <div id="team-profile-transition" class="team-profile-transition" hidden></div>
346
+ <div id="team-profile-list" class="team-profile-list"></div>
347
+ <div id="team-profile-confirm" class="team-profile-confirm" hidden>
348
+ <div id="team-profile-confirm-body" class="team-profile-confirm-body"></div>
349
+ <div class="workspace-prompt-actions">
350
+ <button id="team-profile-confirm-btn" class="btn btn-primary" type="button" data-i18n="teamProfile.confirmButton">Switch team</button>
351
+ <button id="team-profile-confirm-back" class="btn btn-small" type="button" data-i18n="teamProfile.cancel">Back</button>
352
+ </div>
353
+ </div>
354
+ <p id="team-profile-switch-status" class="team-profile-switch-status" hidden></p>
355
+ <section class="team-profile-archived">
356
+ <h3 data-i18n="teamProfile.archivedTitle">Archived teams</h3>
357
+ <div id="team-profile-archives" class="team-profile-archives"></div>
358
+ </section>
359
+ </div>
360
+ </section>
361
+ </div>
362
+
330
363
  <div id="clarification-prompt-modal" class="clarification-prompt-modal" aria-hidden="true">
331
364
  <div class="clarification-prompt-backdrop" data-clarification-prompt-close></div>
332
365
  <section class="clarification-prompt-panel" role="dialog" aria-modal="true" aria-labelledby="clarification-prompt-title">
package/src/ui/style.css CHANGED
@@ -652,6 +652,28 @@ body {
652
652
  color: var(--text-secondary);
653
653
  }
654
654
 
655
+ /* TeamAuto sub-tabs (Config / Activity) */
656
+ .ta-subtabs {
657
+ display: flex;
658
+ gap: 8px;
659
+ margin-bottom: 12px;
660
+ }
661
+ .ta-subtab {
662
+ border: 1px solid var(--border-color, rgba(255,255,255,0.15));
663
+ background: transparent;
664
+ color: var(--text-secondary);
665
+ border-radius: 8px;
666
+ padding: 4px 14px;
667
+ font-size: 12px;
668
+ cursor: pointer;
669
+ }
670
+ .ta-subtab.active {
671
+ background: var(--accent-soft, rgba(226,183,111,0.15));
672
+ color: var(--accent, #e2b76f);
673
+ border-color: var(--accent, #e2b76f);
674
+ }
675
+ .ta-pane.is-hidden { display: none; }
676
+
655
677
  .clarification-reason,
656
678
  .clarification-context,
657
679
  .clarification-answer {
@@ -660,6 +682,46 @@ body {
660
682
  line-height: 1.5;
661
683
  }
662
684
 
685
+ /* Markdown-rendered clarification context (worker-authored) */
686
+ .clarification-context-md h1,
687
+ .clarification-context-md h2,
688
+ .clarification-context-md h3,
689
+ .clarification-context-md h4 {
690
+ font-size: 13px;
691
+ font-weight: 600;
692
+ margin: 10px 0 4px;
693
+ color: var(--text-primary);
694
+ }
695
+ .clarification-context-md p { margin: 6px 0; }
696
+ .clarification-context-md ul,
697
+ .clarification-context-md ol { margin: 6px 0; padding-left: 18px; }
698
+ .clarification-context-md li { margin: 2px 0; }
699
+ .clarification-context-md code {
700
+ font-family: var(--font-mono, ui-monospace, monospace);
701
+ font-size: 12px;
702
+ background: var(--bg-tertiary, rgba(255,255,255,0.06));
703
+ padding: 1px 4px;
704
+ border-radius: 4px;
705
+ }
706
+ .clarification-context-md pre {
707
+ margin: 8px 0;
708
+ padding: 8px 10px;
709
+ overflow-x: auto;
710
+ background: var(--bg-tertiary, rgba(255,255,255,0.06));
711
+ border-radius: 6px;
712
+ }
713
+ .clarification-context-md pre code { background: none; padding: 0; }
714
+ .clarification-context-md blockquote {
715
+ margin: 6px 0;
716
+ padding: 2px 10px;
717
+ border-left: 3px solid var(--border-color, rgba(255,255,255,0.15));
718
+ color: var(--text-secondary);
719
+ }
720
+ .clarification-context-md table { border-collapse: collapse; margin: 8px 0; font-size: 12px; }
721
+ .clarification-context-md th,
722
+ .clarification-context-md td { border: 1px solid var(--border-color, rgba(255,255,255,0.15)); padding: 4px 8px; }
723
+ .clarification-context-md a { color: var(--accent, #e2b76f); }
724
+
663
725
  .clarification-answer-meta {
664
726
  color: var(--text-secondary);
665
727
  font-size: 12px;
@@ -2609,3 +2671,135 @@ body {
2609
2671
  .tunnel-popover-card .tunnel-on { word-break: break-all; }
2610
2672
  .tunnel-note { margin-left: 10px; color: var(--text-muted); font-size: 12px; }
2611
2673
  .tunnel-err { color: var(--danger); font-size: 12.5px; margin-top: 8px; }
2674
+
2675
+ /* ==================== Team profile switcher (Phase 5.1) ==================== */
2676
+ /* Capability gate (GET /team/profile capabilities.teamauto): the tab node is
2677
+ hidden, not removed, so the DOM keeps the full 7-tab contract. `.tab`
2678
+ sets display:inline-flex which would beat the UA [hidden] rule, so the
2679
+ hidden state needs an explicit rule. */
2680
+ .tab[hidden] { display: none; }
2681
+
2682
+ .team-profile-toggle {
2683
+ max-width: 220px;
2684
+ overflow: hidden;
2685
+ text-overflow: ellipsis;
2686
+ white-space: nowrap;
2687
+ }
2688
+
2689
+ .team-profile-panel { max-width: 640px; }
2690
+
2691
+ .team-profile-transition {
2692
+ margin: 0 0 10px;
2693
+ padding: 8px 12px;
2694
+ border-radius: 8px;
2695
+ font-size: 12.5px;
2696
+ background: rgba(230, 162, 60, 0.12);
2697
+ border: 1px solid rgba(230, 162, 60, 0.4);
2698
+ color: var(--warning, #e6a23c);
2699
+ }
2700
+
2701
+ .team-profile-list {
2702
+ display: flex;
2703
+ flex-direction: column;
2704
+ gap: 10px;
2705
+ margin: 6px 0 4px;
2706
+ }
2707
+
2708
+ .team-profile-card {
2709
+ display: flex;
2710
+ align-items: flex-start;
2711
+ gap: 12px;
2712
+ width: 100%;
2713
+ box-sizing: border-box;
2714
+ text-align: left;
2715
+ padding: 12px 14px;
2716
+ border-radius: 10px;
2717
+ border: 1px solid var(--border);
2718
+ background: var(--bg-tertiary);
2719
+ color: var(--text-primary);
2720
+ cursor: pointer;
2721
+ }
2722
+ .team-profile-card:hover { border-color: var(--accent); }
2723
+ .team-profile-card.active {
2724
+ border-color: var(--accent);
2725
+ background: rgba(217, 166, 100, 0.08);
2726
+ cursor: default;
2727
+ }
2728
+ .team-profile-card.is-locked { opacity: 0.6; }
2729
+
2730
+ .team-profile-card-icon { font-size: 20px; line-height: 1.3; }
2731
+ .team-profile-card-main {
2732
+ flex: 1;
2733
+ min-width: 0;
2734
+ display: flex;
2735
+ flex-direction: column;
2736
+ gap: 3px;
2737
+ }
2738
+ .team-profile-card-name { font-weight: 600; font-size: 13.5px; }
2739
+ .team-profile-card-name-alt { font-weight: 400; opacity: 0.65; font-size: 12.5px; }
2740
+ .team-profile-card-desc { font-size: 12.5px; opacity: 0.75; line-height: 1.45; }
2741
+ .team-profile-card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
2742
+
2743
+ .team-profile-chip {
2744
+ display: inline-block;
2745
+ padding: 1px 8px;
2746
+ border-radius: 999px;
2747
+ font-size: 11px;
2748
+ border: 1px solid var(--border);
2749
+ opacity: 0.85;
2750
+ }
2751
+ .team-profile-chip.pending {
2752
+ border-color: rgba(230, 162, 60, 0.5);
2753
+ background: rgba(230, 162, 60, 0.14);
2754
+ color: var(--warning, #e6a23c);
2755
+ opacity: 1;
2756
+ }
2757
+ .team-profile-card-current {
2758
+ flex-shrink: 0;
2759
+ padding: 2px 10px;
2760
+ border-radius: 999px;
2761
+ font-size: 11px;
2762
+ border: 1px solid var(--accent);
2763
+ color: var(--accent);
2764
+ }
2765
+
2766
+ .team-profile-confirm-body h3 { margin: 2px 0 10px; font-size: 15px; }
2767
+ .team-profile-confirm-warning {
2768
+ margin: 6px 0;
2769
+ padding: 8px 12px;
2770
+ border-radius: 8px;
2771
+ font-size: 12.5px;
2772
+ background: rgba(230, 90, 90, 0.1);
2773
+ border: 1px solid rgba(230, 90, 90, 0.35);
2774
+ color: var(--danger, #ff7b7b);
2775
+ }
2776
+
2777
+ .team-profile-switch-status {
2778
+ margin: 8px 0 0;
2779
+ font-size: 12.5px;
2780
+ opacity: 0.75;
2781
+ }
2782
+
2783
+ .team-profile-archived {
2784
+ margin-top: 16px;
2785
+ padding-top: 10px;
2786
+ border-top: 1px solid rgba(255, 255, 255, 0.08);
2787
+ }
2788
+ .team-profile-archived h3 { margin: 0 0 8px; font-size: 13px; opacity: 0.8; }
2789
+ .team-profile-archives {
2790
+ max-height: 180px;
2791
+ overflow-y: auto;
2792
+ display: flex;
2793
+ flex-direction: column;
2794
+ gap: 6px;
2795
+ }
2796
+ .team-profile-archive-row {
2797
+ display: flex;
2798
+ flex-wrap: wrap;
2799
+ gap: 10px;
2800
+ align-items: baseline;
2801
+ font-size: 12.5px;
2802
+ }
2803
+ .team-profile-archive-team { font-weight: 600; }
2804
+ .team-profile-archive-profile { opacity: 0.7; }
2805
+ .team-profile-archive-meta { margin-left: auto; opacity: 0.6; font-size: 12px; }
@@ -1,13 +1,30 @@
1
1
  import type { PluginConfig, WorkerIdentity } from "../types.js";
2
- import { getRole } from "../roles.js";
3
- import { buildWorkerSessionRules, composePrompt } from "../prompt-policy.js";
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
- const TEAMCLAW_ROLE_IDS_TEXT = [
7
- "pm", "architect", "developer", "qa",
8
- "release-engineer", "infra-engineer", "devops", "security-engineer",
9
- "designer", "marketing", "data-engineer",
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 = getRole(identity.role);
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,7 +2,9 @@ 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
- import { normalizeRecommendedSkills } from "../roles.js";
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";
8
10
 
@@ -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,39 @@ 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
+
12
46
  export type WorkerServiceDeps = {
13
47
  config: PluginConfig;
14
48
  logger: PluginLogger;
@@ -32,6 +66,35 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
32
66
  const activeTaskSessionKeys = new Map<string, string>();
33
67
  const cancelledTaskIds = new Set<string>();
34
68
  let consecutiveHeartbeatFailures = 0;
69
+ let warnedLoopbackReachability = false;
70
+
71
+ // Issue #27: with the loopback bind default, an external worker (controller
72
+ // on another host) still advertises its LAN IP (identity.ts getLocalIp),
73
+ // so the controller could never reach it. Surface that mismatch once
74
+ // instead of failing silently; `listenHost` is the escape hatch.
75
+ function warnIfLoopbackBindBlocksRemoteController(targetControllerUrl: string): void {
76
+ if (warnedLoopbackReachability) {
77
+ return;
78
+ }
79
+ const listenHost = resolveWorkerListenHost(config);
80
+ if (!isLoopbackHost(listenHost)) {
81
+ return;
82
+ }
83
+ let controllerHost: string;
84
+ try {
85
+ controllerHost = new URL(targetControllerUrl).hostname;
86
+ } catch {
87
+ return;
88
+ }
89
+ if (!controllerHost || isLoopbackHost(controllerHost)) {
90
+ return;
91
+ }
92
+ warnedLoopbackReachability = true;
93
+ logger.warn(
94
+ `Worker: HTTP server is bound to loopback (${listenHost}) but the controller is at ${targetControllerUrl} (different host) - the controller cannot reach this worker. ` +
95
+ `Set the "listenHost" plugin config (e.g. "0.0.0.0" or this machine's LAN address) for external-worker deployments.`,
96
+ );
97
+ }
35
98
 
36
99
  const taskExecutor = externalTaskExecutor
37
100
  ? async (assignment: TaskAssignmentPayload): Promise<{ text: string; contract?: Record<string, unknown> }> => {
@@ -163,12 +226,27 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
163
226
  }
164
227
 
165
228
  server = http.createServer(handler);
229
+ const listenHost = resolveWorkerListenHost(config);
166
230
  await new Promise<void>((resolve, reject) => {
167
- server!.listen(config.port, () => {
168
- logger.info(`Worker: HTTP server listening on port ${config.port}`);
231
+ server!.listen(config.port, listenHost, () => {
232
+ logger.info(`Worker: HTTP server listening on ${listenHost}:${config.port}`);
169
233
  resolve();
170
234
  });
171
- server!.on("error", reject);
235
+ server!.on("error", (err: NodeJS.ErrnoException) => {
236
+ if (err.code === "EADDRINUSE") {
237
+ // Issue #27: the worker default port is also the controller default,
238
+ // so same-host dual-process setups crash here with no pointer.
239
+ reject(new Error(
240
+ `Worker: cannot listen on ${listenHost}:${config.port} - address already in use` +
241
+ (config.port === 9527
242
+ ? ". 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"
243
+ : "") +
244
+ ". Adjust the `port` and `listenHost` plugin config keys to change the bind address.",
245
+ ));
246
+ return;
247
+ }
248
+ reject(err);
249
+ });
172
250
  });
173
251
  }
174
252
 
@@ -191,6 +269,7 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
191
269
  controllerUrl = identity.controllerUrl;
192
270
  workerId = identity.workerId;
193
271
  onIdentityEstablished(identity);
272
+ warnIfLoopbackBindBlocksRemoteController(controllerUrl);
194
273
  // Restart server with worker ID and task executor
195
274
  await startServer();
196
275
  }
@@ -203,6 +282,7 @@ export function createWorkerService(deps: WorkerServiceDeps): OpenClawPluginServ
203
282
  controllerUrl = newIdentity.controllerUrl;
204
283
  workerId = newIdentity.workerId;
205
284
  onIdentityEstablished(newIdentity);
285
+ warnIfLoopbackBindBlocksRemoteController(controllerUrl);
206
286
  await startServer();
207
287
  }
208
288
  return;