@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,18 +1,22 @@
1
1
  import { buildTeamClawProjectAgentRelativePath } from "./openclaw-workspace.js";
2
- export const TEAMCLAW_ROLE_IDS = [
3
- "pm",
4
- "architect",
5
- "developer",
6
- "qa",
7
- "release-engineer",
8
- "infra-engineer",
9
- "devops",
10
- "security-engineer",
11
- "designer",
12
- "marketing",
13
- "data-engineer",
14
- ];
2
+ // Phase 1.2: the role id list is derived from the canonical role-ids.ts leaf
3
+ // module. prompt-policy.ts cannot value-import roles.ts (roles.ts imports
4
+ // this module and evaluates its builders at module init), so the dependency-
5
+ // free leaf keeps a single source of truth without a module cycle. roles.ts
6
+ // asserts its ROLES registry agrees with the same list.
7
+ import { ROLE_IDS } from "./role-ids.js";
8
+ import { getActiveRoleIds } from "./profile-loader.js";
9
+ export const TEAMCLAW_ROLE_IDS = ROLE_IDS;
15
10
  export const TEAMCLAW_ROLE_IDS_TEXT = TEAMCLAW_ROLE_IDS.join(", ");
11
+ // #251 (design 2.3): the four role-list prompt injections must reflect the
12
+ // ACTIVE team profile, not the software-11 constant - a banking team must
13
+ // not be told to collaborate using "architect"/"release-engineer" IDs.
14
+ // profile-loader is runtime dependency-free (fs + JSON only), so importing
15
+ // it here cannot create a module cycle. Under software-rd the active list
16
+ // IS the canonical software-11 list, so baseline prompts are byte-identical.
17
+ function activeRoleIdsText() {
18
+ return getActiveRoleIds().join(", ");
19
+ }
16
20
  export function composePrompt(...sections) {
17
21
  const lines = [];
18
22
  for (const section of sections) {
@@ -27,7 +31,28 @@ export function composePrompt(...sections) {
27
31
  }
28
32
  return lines.join("\n");
29
33
  }
34
+ /**
35
+ * Phase 2.4 (design 2.1/2.4, replacement semantics): when the caller passes a
36
+ * non-empty `domainInstructions` (the active TeamProfile's industry
37
+ * guardrails), the domain lines REPLACE the software engineering operating
38
+ * rules wholesale - none of the software rules below are injected. Without
39
+ * the option (software-rd baseline, roles.ts registry init) the output is
40
+ * byte-identical to the pre-Phase-2.4 value, which the Phase 1.7 prompt
41
+ * goldens lock. The option is injected by the prompt pipelines (controller
42
+ * and worker prompt-injector) rather than read from the loader here.
43
+ * (#251 exception: the four role-LIST injections below now read
44
+ * getActiveRoleIds() directly - see activeRoleIdsText(). profile-loader is
45
+ * runtime dependency-free, so this still cannot cycle.)
46
+ */
30
47
  export function buildRoleOperatingRules(options) {
48
+ const domainInstructions = options.domainInstructions ?? [];
49
+ if (domainInstructions.length > 0) {
50
+ return [
51
+ "",
52
+ "## TeamClaw Operating Contract",
53
+ ...domainInstructions,
54
+ ];
55
+ }
31
56
  const suggestedRoles = options.suggestedRoles.length > 0 ? options.suggestedRoles.join(", ") : "none";
32
57
  const recommendedSkills = options.recommendedSkills.length > 0 ? options.recommendedSkills.join(", ") : "none";
33
58
  return [
@@ -46,7 +71,7 @@ export function buildRoleOperatingRules(options) {
46
71
  "- Treat other workers' OpenClaw sessions and session keys as unavailable; use the shared workspace, the current task context, and teammate messages instead of trying cross-session inspection.",
47
72
  "- Do not mark a task completed or failed via progress updates. Finish by returning the deliverable or raising the blocking error so TeamClaw can close the task correctly.",
48
73
  "- Do not infer ownership, license scope, or lack of user authorization from technical characteristics such as proprietary branding, bundled assets, binary files, minified code, or repository layout. Focus on technical feasibility and the user's explicit requirements.",
49
- `- Use exact TeamClaw role IDs when collaborating: ${TEAMCLAW_ROLE_IDS_TEXT}.`,
74
+ `- Use exact TeamClaw role IDs when collaborating: ${activeRoleIdsText()}.`,
50
75
  `- If a true follow-up is required after your deliverable, prefer these exact next roles: ${suggestedRoles}.`,
51
76
  `- Default starter skills for this role: ${recommendedSkills}. If the task includes more specific recommended skills, prefer those.`,
52
77
  ];
@@ -78,7 +103,7 @@ export function buildWorkerSessionRules() {
78
103
  "7. If another role must continue later, use review/handoff tools on the current task instead of spawning work.",
79
104
  "8. Other workers' OpenClaw sessions are isolated from this worker. Do not attempt cross-session inspection; use task context, the shared workspace, and queued team messages instead.",
80
105
  "9. Do not mark the task completed or failed via progress updates. Return the final deliverable and let TeamClaw close the task.",
81
- `10. Valid TeamClaw role IDs: ${TEAMCLAW_ROLE_IDS_TEXT}.`,
106
+ `10. Valid TeamClaw role IDs: ${activeRoleIdsText()}.`,
82
107
  "11. Treat file paths from documents, plans, and teammate messages as hints, not guarantees. Verify the real path exists in the current workspace before reading or editing it; if it does not exist, search for the closest real file and note the drift instead of repeatedly calling missing paths.",
83
108
  "12. The workspace may be backed by a TeamClaw-managed git repository. Treat the current checkout as canonical project state; do not delete `.git` or replace the repo with ad-hoc archives.",
84
109
  "13. If the assigned task includes recommended skills, use those exact skill slugs first. Missing skills should be searched/installed before execution when supported by the runtime.",
@@ -112,7 +137,7 @@ export function buildTaskExecutionRules(rateLimitWaitingSentinel) {
112
137
  `- Do NOT use sessions_yield or end your turn while background work, coding agents, or process sessions are still running; if the task is not complete yet, reply with exactly ${rateLimitWaitingSentinel}.`,
113
138
  "- Never return 'running in background' as the final result for a TeamClaw task. If you spawn a helper session, keep monitoring it and only return after you have the actual deliverable.",
114
139
  "- Use structured fields on progress, review, handoff, and messaging tools whenever coordination is needed.",
115
- `- When naming a role, use exact TeamClaw role IDs: ${TEAMCLAW_ROLE_IDS_TEXT}.`,
140
+ `- When naming a role, use exact TeamClaw role IDs: ${activeRoleIdsText()}.`,
116
141
  ];
117
142
  }
118
143
  export function buildVerificationPolicy() {
@@ -356,7 +381,7 @@ export function buildControllerDisciplineRules(options) {
356
381
  ? "- If no workers are currently registered but on-demand provisioning is enabled, you may still create execution-ready tasks so the required roles can be provisioned."
357
382
  : "- If no workers are registered, you may mention which roles would be needed, but stop there and report the worker-capacity block to the human.",
358
383
  "- Use the controller itself for requirement analysis; use the PM role only for PM-owned deliverables after intake is clear.",
359
- `- Use exact TeamClaw role IDs only: ${TEAMCLAW_ROLE_IDS_TEXT}.`,
384
+ `- Use exact TeamClaw role IDs only: ${activeRoleIdsText()}.`,
360
385
  "- Never guess or summarize a worker's unfinished output as if it were a completed result. While work is still in flight, report only current status plus the next concrete step.",
361
386
  "- Never fabricate downstream readiness from intent alone. Downstream creation requires evidence: completed task state, a structured result contract, concrete deliverables, or an explicit handoff.",
362
387
  "- Never ask the human to manually run an obvious machine step such as rebuild/retest/repro/verification (for example git pull, go build, npm test, rerun and report whether it still crashes) when TeamClaw can create an execution task and do that work itself.",
@@ -1,13 +1,62 @@
1
+ import { randomBytes, timingSafeEqual } from "node:crypto";
1
2
  export const MDNS_TYPE = "_teamclaw._tcp";
2
3
  export const DEFAULT_PORT = 9527;
3
4
  export const HEARTBEAT_MS = 10000;
4
5
  export const WORKER_TIMEOUT_MS = 30000;
5
6
  export const API_PREFIX = "/api/v1";
7
+ // Issue #255 P0-1: id fragments used to come from the V8 Math PRNG
8
+ // (xorshift128+ - the internal state is recoverable from a handful of
9
+ // observed outputs, so past fragments leak future ones). Fragments now
10
+ // derive from the CSPRNG. The output shape (timestamp + 6 base36 chars) is
11
+ // kept byte-compatible so no generateId consumer sees a format change.
12
+ const ID_FRAGMENT_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
13
+ function randomIdFragment(length = 6) {
14
+ let fragment = "";
15
+ while (fragment.length < length) {
16
+ for (const byte of randomBytes(length * 2)) {
17
+ // 256 is not a multiple of 36: bytes >= 252 would bias the last four
18
+ // alphabet symbols - reject them and draw again.
19
+ if (byte >= 252) {
20
+ continue;
21
+ }
22
+ fragment += ID_FRAGMENT_ALPHABET[byte % 36];
23
+ if (fragment.length === length) {
24
+ break;
25
+ }
26
+ }
27
+ }
28
+ return fragment;
29
+ }
6
30
  function generateId() {
7
31
  const ts = Date.now().toString(36);
8
- const rand = Math.random().toString(36).slice(2, 8);
32
+ const rand = randomIdFragment();
9
33
  return `${ts}-${rand}`;
10
34
  }
35
+ /**
36
+ * Issue #255 P0-1: bearer token a provisioned worker must present at
37
+ * registration (and that the controller echoes on task dispatch). 256 bits
38
+ * from the CSPRNG, hex-encoded. This is an internal value with no external
39
+ * format contract - it travels controller -> worker through the
40
+ * TEAMCLAW_LAUNCH_TOKEN env var and is only ever equality-checked - so the
41
+ * old `${generateId()}-${generateId()}` shape (two ~31-bit xorshift128+
42
+ * fragments) is replaced outright. Tokens minted by older builds stay valid:
43
+ * the check is an equality either way (now constant-time), only generation
44
+ * changes.
45
+ */
46
+ function generateLaunchToken() {
47
+ return randomBytes(32).toString("hex");
48
+ }
49
+ /** Constant-time string equality for secrets (length guard: token length is
50
+ * a public format detail, not secret content).
51
+ * #259 follow-up: canonical home is this leaf module so controller leaves
52
+ * (worker-provisioning) can compare secrets without importing
53
+ * controller/security.ts, which would close a module cycle
54
+ * (http-server <-> route-table <-> security <-> worker-provisioning). */
55
+ export function secretsEqual(a, b) {
56
+ const left = Buffer.from(a, "utf8");
57
+ const right = Buffer.from(b, "utf8");
58
+ return left.length === right.length && timingSafeEqual(left, right);
59
+ }
11
60
  async function parseJsonBody(req) {
12
61
  const raw = await readRequestBody(req);
13
62
  if (!raw.length) {
@@ -30,12 +79,26 @@ async function readRequestBody(req) {
30
79
  req.on("error", reject);
31
80
  });
32
81
  }
82
+ /**
83
+ * Issue #23: the Access-Control-Allow-Origin value a response should carry.
84
+ * A header the security gate PINNED before dispatch (device protection on:
85
+ * same-origin echo, or an explicit empty value for foreign origins) wins;
86
+ * with nothing pinned (protection off / non-browser requests) the value is
87
+ * the historical wildcard, byte for byte. Every response path that sets
88
+ * ACAO (sendJson here, the raw-file and repo-bundle octet-stream writers in
89
+ * the controller routes) must go through this helper so no route can widen
90
+ * a pinned response back to the L0 wildcard.
91
+ */
92
+ function pinnedCorsAllowOrigin(res) {
93
+ const pinned = res.getHeader("Access-Control-Allow-Origin");
94
+ return typeof pinned === "string" ? pinned : "*";
95
+ }
33
96
  function sendJson(res, status, data) {
34
97
  const body = JSON.stringify(data);
35
98
  res.writeHead(status, {
36
99
  "Content-Type": "application/json",
37
100
  "Content-Length": Buffer.byteLength(body),
38
- "Access-Control-Allow-Origin": "*",
101
+ "Access-Control-Allow-Origin": pinnedCorsAllowOrigin(res),
39
102
  "Access-Control-Allow-Methods": "GET, POST, PATCH, DELETE, OPTIONS",
40
103
  "Access-Control-Allow-Headers": "Content-Type",
41
104
  });
@@ -55,4 +118,4 @@ function createHeartbeatPayload(workerId, status, currentTaskId) {
55
118
  timestamp: Date.now(),
56
119
  };
57
120
  }
58
- export { generateId, parseJsonBody, readRequestBody, sendJson, sendError, createRegistrationRequest, createHeartbeatPayload, };
121
+ export { generateId, generateLaunchToken, parseJsonBody, readRequestBody, sendJson, sendError, pinnedCorsAllowOrigin, createRegistrationRequest, createHeartbeatPayload, };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Canonical ordered TeamClaw role id list (Phase 1.2 single-source
3
+ * convergence, vertical-team-profiles-design.md section 1.1).
4
+ *
5
+ * This module is deliberately dependency-free (type-only import) so it can be
6
+ * imported from anywhere - including prompt-policy.ts and
7
+ * openclaw-workspace.ts, which sit BELOW roles.ts in the module graph and
8
+ * therefore cannot value-import roles.ts without creating a cycle
9
+ * (roles.ts -> prompt-policy.ts -> openclaw-workspace.ts at runtime).
10
+ *
11
+ * roles.ts keeps ROLE_IDS derived from its ROLES registry and asserts at
12
+ * module init that both lists agree, so this file and the registry can never
13
+ * silently drift apart. The manifest generator
14
+ * (scripts/sync-teamclaw-plugin-manifest.mjs) extracts this array from the
15
+ * source text so openclaw.plugin.json derives from the same list.
16
+ */
17
+ export const ROLE_IDS = [
18
+ "pm",
19
+ "architect",
20
+ "developer",
21
+ "qa",
22
+ "release-engineer",
23
+ "infra-engineer",
24
+ "devops",
25
+ "security-engineer",
26
+ "designer",
27
+ "marketing",
28
+ "data-engineer",
29
+ ];
package/dist/src/roles.js CHANGED
@@ -1,17 +1,9 @@
1
1
  import { buildRoleOperatingRules, buildWorkerMemoryContractRules, composePrompt } from "./prompt-policy.js";
2
- const TEAMCLAW_ROLE_IDS_TEXT = [
3
- "pm",
4
- "architect",
5
- "developer",
6
- "qa",
7
- "release-engineer",
8
- "infra-engineer",
9
- "devops",
10
- "security-engineer",
11
- "designer",
12
- "marketing",
13
- "data-engineer",
14
- ];
2
+ // Phase 1.2 single-source convergence: the canonical role id list lives in
3
+ // the dependency-free role-ids.ts leaf (importable by prompt-policy.ts and
4
+ // openclaw-workspace.ts, which sit below this module). The guard below makes
5
+ // this registry and that list impossible to drift apart silently.
6
+ import { ROLE_IDS as CANONICAL_ROLE_IDS } from "./role-ids.js";
15
7
  const ROLES = [
16
8
  {
17
9
  id: "pm",
@@ -315,6 +307,55 @@ for (const role of ROLES) {
315
307
  }
316
308
  const ROLE_MAP = new Map(ROLES.map((r) => [r.id, r]));
317
309
  const ROLE_IDS = ROLES.map((r) => r.id);
310
+ // Fail fast when the ROLES registry and the canonical role-ids.ts list
311
+ // disagree (length, order, or membership): every consumer of either module
312
+ // must see exactly one role set.
313
+ if (ROLE_IDS.length !== CANONICAL_ROLE_IDS.length || ROLE_IDS.some((id, index) => id !== CANONICAL_ROLE_IDS[index])) {
314
+ const registryOnly = ROLE_IDS.filter((id) => !CANONICAL_ROLE_IDS.includes(id));
315
+ const leafOnly = CANONICAL_ROLE_IDS.filter((id) => !ROLE_IDS.includes(id));
316
+ throw new Error(`roles.ts ROLES ids and role-ids.ts ROLE_IDS have drifted apart - update both so the registry, prompts, and manifest stay in sync `
317
+ + `(registry-only: [${registryOnly.join(", ")}]; role-ids.ts-only: [${leafOnly.join(", ")}])`);
318
+ }
319
+ /**
320
+ * Phase 0.3 convergence point for `as RoleId` casts: validate an untrusted
321
+ * value against the registered role ids. Returns the trimmed role id when
322
+ * `raw` is a string that matches a registered role, otherwise `undefined`.
323
+ * Never throws — callers treat invalid input exactly like a missing field.
324
+ * Semantics intentionally mirror the former normalizeContractRole guard in
325
+ * interaction-contracts.ts, which now delegates here.
326
+ */
327
+ export function validateRoleId(raw) {
328
+ if (typeof raw !== "string") {
329
+ return undefined;
330
+ }
331
+ return ROLE_MAP.get(raw.trim())?.id;
332
+ }
333
+ /**
334
+ * Array-filtering counterpart of validateRoleId: keeps order, drops
335
+ * non-strings, blank entries, and unknown roles, and dedupes by first
336
+ * occurrence. Phase 0.3 replaces the per-file list guards (types.ts
337
+ * parseRoleList, orchestration-manifest.ts normalizeManifestRoleList).
338
+ */
339
+ export function validateRoleIdList(raw) {
340
+ if (!Array.isArray(raw)) {
341
+ return [];
342
+ }
343
+ const roleIds = [];
344
+ for (const entry of raw) {
345
+ const roleId = validateRoleId(entry);
346
+ if (roleId && !roleIds.includes(roleId)) {
347
+ roleIds.push(roleId);
348
+ }
349
+ }
350
+ return roleIds;
351
+ }
352
+ /**
353
+ * Single source of truth for the fallback role used when no better signal
354
+ * exists (role inference miss, unconfigured startup provisioning, unset
355
+ * worker config role). Callers must import this constant instead of
356
+ * hardcoding a role id.
357
+ */
358
+ export const DEFAULT_ROLE = "developer";
318
359
  function getRole(id) {
319
360
  return ROLE_MAP.get(id);
320
361
  }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Session-role string normalization, shared by the controller http-server and
3
+ * the worker task executor (single source since issue #204's dedupe finding).
4
+ */
5
+ export function normalizeSessionRole(value) {
6
+ if (typeof value !== "string") {
7
+ return "";
8
+ }
9
+ const normalized = value.trim().toLowerCase().replace(/[-\s]+/g, "_");
10
+ if (normalized === "toolresult") {
11
+ return "tool_result";
12
+ }
13
+ return normalized;
14
+ }
@@ -0,0 +1,65 @@
1
+ export function normalizeOptionalManifestText(raw) {
2
+ if (typeof raw !== "string") {
3
+ return undefined;
4
+ }
5
+ const normalized = raw.trim();
6
+ return normalized || undefined;
7
+ }
8
+ export function normalizeClarificationOptions(raw) {
9
+ if (!Array.isArray(raw)) {
10
+ return [];
11
+ }
12
+ return raw
13
+ .filter((entry) => !!entry && typeof entry === "object")
14
+ .map((entry) => ({
15
+ value: typeof entry.value === "string" ? entry.value.trim() : "",
16
+ label: typeof entry.label === "string" ? entry.label.trim() : "",
17
+ hint: typeof entry.hint === "string" && entry.hint.trim() ? entry.hint.trim() : undefined,
18
+ }))
19
+ .filter((entry) => entry.value && entry.label);
20
+ }
21
+ export function normalizeClarificationQuestionSchema(raw) {
22
+ if (!raw || typeof raw !== "object") {
23
+ return undefined;
24
+ }
25
+ const input = raw;
26
+ const kind = typeof input.kind === "string" ? input.kind.trim() : "";
27
+ const title = typeof input.title === "string" ? input.title.trim() : "";
28
+ if (!title || !["single-select", "multi-select", "number", "text"].includes(kind)) {
29
+ return undefined;
30
+ }
31
+ const options = normalizeClarificationOptions(input.options);
32
+ const schema = {
33
+ kind: kind,
34
+ title,
35
+ description: normalizeOptionalManifestText(input.description),
36
+ required: input.required == null ? true : Boolean(input.required),
37
+ allowOther: Boolean(input.allowOther),
38
+ placeholder: normalizeOptionalManifestText(input.placeholder),
39
+ unit: normalizeOptionalManifestText(input.unit),
40
+ };
41
+ if (options.length > 0) {
42
+ schema.options = options;
43
+ }
44
+ if (typeof input.min === "number" && Number.isFinite(input.min)) {
45
+ schema.min = input.min;
46
+ }
47
+ if (typeof input.max === "number" && Number.isFinite(input.max)) {
48
+ schema.max = input.max;
49
+ }
50
+ if (typeof input.step === "number" && Number.isFinite(input.step)) {
51
+ schema.step = input.step;
52
+ }
53
+ if ((schema.kind === "single-select" || schema.kind === "multi-select") && (!schema.options || schema.options.length === 0)) {
54
+ return undefined;
55
+ }
56
+ return schema;
57
+ }
58
+ export function normalizeClarificationQuestionSchemas(raw) {
59
+ if (!Array.isArray(raw)) {
60
+ return [];
61
+ }
62
+ return raw
63
+ .map((entry) => normalizeClarificationQuestionSchema(entry))
64
+ .filter((entry) => Boolean(entry));
65
+ }
@@ -0,0 +1,15 @@
1
+ // Shared contracts layer (issue #226, W5): the GitHub auth manager TYPE
2
+ // contract. The teamauto subsystem consumes this type (github-client,
3
+ // scheduler, repo-sync all take a GithubAuthManager), so the cross-subsystem
4
+ // contract lives here — teamauto must not import the controller tree. Only
5
+ // types moved; the factory (createGithubAuthManager) and the singleton cache
6
+ // (getGithubAuthManager) stay in controller/github-auth.ts, which annotates
7
+ // the factory's return type with this contract so the compiler keeps the
8
+ // structural definition in lockstep with the implementation.
9
+ //
10
+ // GithubAuthManager was previously `ReturnType<typeof createGithubAuthManager>`;
11
+ // the explicit structural form below is signature-identical (each member
12
+ // mirrors one returned closure verbatim) and no longer requires importing the
13
+ // controller factory to name the type.
14
+ /** Default GitHub OAuth client id (moved from controller/github-auth, W3 residual edge). */
15
+ export const DEFAULT_GITHUB_CLIENT_ID = "Iv23liqWmzrS3swGiIvK";
@@ -0,0 +1,37 @@
1
+ import { getActiveRole } from "../profile-loader.js";
2
+ /**
3
+ * Build the kickoff assessment prompt sent to a worker.
4
+ * The worker should respond with structured JSON matching KickoffAssessment.
5
+ */
6
+ export function buildKickoffAssessmentPrompt(role, requirement) {
7
+ const roleDef = getActiveRole(role);
8
+ const roleLabel = roleDef?.label ?? role;
9
+ return [
10
+ `You are the ${roleLabel} in a virtual software team.`,
11
+ `Your team is conducting a kickoff meeting for a new requirement.`,
12
+ ``,
13
+ `## Requirement`,
14
+ requirement,
15
+ ``,
16
+ `## Your Task`,
17
+ `Evaluate this requirement from your professional perspective as ${roleLabel}.`,
18
+ `Respond with a JSON object (and nothing else) with these fields:`,
19
+ ``,
20
+ `{`,
21
+ ` "needed": boolean, // Is your role needed for this project?`,
22
+ ` "scope": string, // What would you contribute? (1-2 sentences)`,
23
+ ` "suggestedTasks": string[], // Specific tasks you'd handle (2-5 items)`,
24
+ ` "dependencies": string[], // What you need from other roles before or during your work`,
25
+ ` "risks": string[], // Concerns or risks from your perspective`,
26
+ ` "questions": string[] // Clarifications you'd want before starting`,
27
+ `}`,
28
+ ``,
29
+ `Guidelines:`,
30
+ `- Be honest about whether your role is truly needed. Don't inflate your importance.`,
31
+ `- For "needed", consider: does the project actually require ${roleLabel}-level expertise?`,
32
+ `- A simple single-file script does NOT need an architect. A TODO app does NOT need a security engineer.`,
33
+ `- Keep suggestedTasks concrete and actionable, not vague.`,
34
+ `- Only list dependencies on roles that are actually relevant.`,
35
+ `- Return ONLY the JSON object, no markdown fencing, no explanation.`,
36
+ ].join("\n");
37
+ }
@@ -0,0 +1,47 @@
1
+ // Shared generic utilities (issue #226 W6 dedup + W1 worker-provisioning
2
+ // split). Everything here is extracted VERBATIM from its former private
3
+ // copies - semantics are frozen, see the W6 notes per function:
4
+ // - pathExists strict: only ENOENT resolves false, other errors
5
+ // rethrow (former worker-provisioning.ts copy)
6
+ // - pathExistsTolerant swallowing: any access error resolves false (the
7
+ // former git-collaboration.ts / worker/skill-installer.ts
8
+ // / index.ts copies, kept as a distinct name so each
9
+ // call site keeps its exact original behavior)
10
+ // - sleep / cloneJson / sanitizePathSegment / sanitizeName: single shared
11
+ // copies of byte-identical former duplicates.
12
+ import fs from "node:fs/promises";
13
+ export function sleep(ms) {
14
+ return new Promise((resolve) => setTimeout(resolve, ms));
15
+ }
16
+ export function cloneJson(value) {
17
+ return JSON.parse(JSON.stringify(value));
18
+ }
19
+ export async function pathExists(targetPath) {
20
+ try {
21
+ await fs.access(targetPath);
22
+ return true;
23
+ }
24
+ catch (err) {
25
+ if (err.code === "ENOENT") {
26
+ return false;
27
+ }
28
+ throw err;
29
+ }
30
+ }
31
+ export async function pathExistsTolerant(targetPath) {
32
+ try {
33
+ await fs.access(targetPath);
34
+ return true;
35
+ }
36
+ catch {
37
+ return false;
38
+ }
39
+ }
40
+ export function sanitizePathSegment(value) {
41
+ const normalized = value.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "");
42
+ return normalized || "worker";
43
+ }
44
+ export function sanitizeName(value, maxLength = 63) {
45
+ const normalized = sanitizePathSegment(value).slice(0, maxLength).replace(/^-+|-+$/g, "");
46
+ return normalized || "teamclaw";
47
+ }