@teamclaws/teamclaw 2026.7.1 → 2026.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/api.js +1 -0
- package/dist/index.js +325 -0
- package/dist/src/config.js +381 -0
- package/dist/src/controller/controller-capacity.js +14 -0
- package/dist/src/controller/controller-service.js +393 -0
- package/dist/src/controller/controller-tools.js +582 -0
- package/dist/src/controller/delivery-report.js +458 -0
- package/dist/src/controller/github-auth.js +564 -0
- package/dist/src/controller/http-server.js +6032 -0
- package/dist/src/controller/kickoff-orchestrator.js +220 -0
- package/dist/src/controller/managed-gateway-process.js +286 -0
- package/dist/src/controller/message-router.js +38 -0
- package/dist/src/controller/orchestration-manifest.js +173 -0
- package/dist/src/controller/preview-manager.js +586 -0
- package/dist/src/controller/prompt-injector.js +187 -0
- package/dist/src/controller/role-inference.js +35 -0
- package/dist/src/controller/task-router.js +67 -0
- package/dist/src/controller/tunnel-manager.js +548 -0
- package/dist/src/controller/websocket.js +42 -0
- package/dist/src/controller/worker-provisioning.js +1648 -0
- package/dist/src/discovery.js +86 -0
- package/dist/src/git-collaboration.js +694 -0
- package/dist/src/identity.js +131 -0
- package/dist/src/install-defaults.js +1 -0
- package/dist/src/interaction-contracts.js +531 -0
- package/dist/src/networking.js +91 -0
- package/dist/src/openclaw-workspace.js +903 -0
- package/dist/src/prompt-policy.js +373 -0
- package/dist/src/protocol.js +58 -0
- package/dist/src/roles.js +349 -0
- package/dist/src/state.js +183 -0
- package/dist/src/task-executor.js +1033 -0
- package/dist/src/teamauto/github-client.js +192 -0
- package/dist/src/teamauto/norms.js +85 -0
- package/dist/src/teamauto/repo-sync.js +201 -0
- package/dist/src/teamauto/scanner.js +179 -0
- package/dist/src/teamauto/schedule.js +123 -0
- package/dist/src/teamauto/scheduler.js +688 -0
- package/dist/src/teamauto/store.js +133 -0
- package/dist/src/types.js +243 -0
- package/dist/src/ui/app.js +4292 -0
- package/dist/src/ui/assets/teamclaw-app-icon.png +0 -0
- package/dist/src/ui/github-login.html +296 -0
- package/dist/src/ui/index.html +414 -0
- package/dist/src/ui/style.css +2611 -0
- package/dist/src/worker/http-handler.js +146 -0
- package/dist/src/worker/message-queue.js +24 -0
- package/dist/src/worker/prompt-injector.js +42 -0
- package/dist/src/worker/skill-installer.js +253 -0
- package/dist/src/worker/tools.js +541 -0
- package/dist/src/worker/worker-service.js +234 -0
- package/dist/src/workspace-browser.js +269 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +9 -7
- package/src/controller/http-server.ts +26 -1
- package/src/controller/tunnel-manager.ts +139 -15
- package/src/ui/app.js +97 -20
- package/src/ui/index.html +16 -4
- package/src/ui/style.css +49 -0
|
@@ -0,0 +1,349 @@
|
|
|
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
|
+
];
|
|
15
|
+
const ROLES = [
|
|
16
|
+
{
|
|
17
|
+
id: "pm",
|
|
18
|
+
label: "Product Manager",
|
|
19
|
+
icon: "\uD83D\uDCCB",
|
|
20
|
+
description: "Product planning, requirements analysis, user stories",
|
|
21
|
+
capabilities: [
|
|
22
|
+
"requirements-analysis", "user-stories", "product-specification",
|
|
23
|
+
"priority-planning", "stakeholder-communication",
|
|
24
|
+
],
|
|
25
|
+
recommendedSkills: ["find-skills"],
|
|
26
|
+
systemPrompt: [
|
|
27
|
+
"You are a Product Manager in a virtual software team.",
|
|
28
|
+
"Your responsibilities include analyzing requirements, writing user stories,",
|
|
29
|
+
"defining product specifications, and prioritizing features.",
|
|
30
|
+
"When receiving tasks, turn them into clear requirements and acceptance criteria inside your deliverable.",
|
|
31
|
+
"Always consider user impact and business value.",
|
|
32
|
+
].join("\n"),
|
|
33
|
+
suggestedNextRoles: ["architect", "designer"],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "architect",
|
|
37
|
+
label: "Software Architect",
|
|
38
|
+
icon: "\uD83D\uDEE0\uFE0F",
|
|
39
|
+
description: "System design, technical architecture, API design",
|
|
40
|
+
capabilities: [
|
|
41
|
+
"system-design", "api-design", "database-schema",
|
|
42
|
+
"technology-selection", "code-review-architecture",
|
|
43
|
+
],
|
|
44
|
+
recommendedSkills: ["find-skills"],
|
|
45
|
+
systemPrompt: [
|
|
46
|
+
"You are a Software Architect in a virtual software team.",
|
|
47
|
+
"Your responsibilities include system design, API design, database schema design,",
|
|
48
|
+
"and technology selection.",
|
|
49
|
+
"When receiving tasks, provide detailed technical designs with clear component boundaries.",
|
|
50
|
+
"Consider scalability, maintainability, and performance.",
|
|
51
|
+
].join("\n"),
|
|
52
|
+
suggestedNextRoles: ["developer", "devops"],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "developer",
|
|
56
|
+
label: "Developer",
|
|
57
|
+
icon: "\uD83D\uDCBB",
|
|
58
|
+
description: "Code implementation, bug fixes, feature development",
|
|
59
|
+
capabilities: [
|
|
60
|
+
"coding", "debugging", "feature-implementation",
|
|
61
|
+
"code-refactoring", "unit-testing",
|
|
62
|
+
],
|
|
63
|
+
recommendedSkills: ["find-skills"],
|
|
64
|
+
systemPrompt: [
|
|
65
|
+
"You are a Developer in a virtual software team.",
|
|
66
|
+
"Your responsibilities include implementing features, fixing bugs, refactoring code,",
|
|
67
|
+
"and writing unit tests.",
|
|
68
|
+
"Follow the architecture and design specifications provided by the architect.",
|
|
69
|
+
"Write clean, maintainable code with proper error handling.",
|
|
70
|
+
"",
|
|
71
|
+
"## Deliverable Preview",
|
|
72
|
+
"When you submit your result contract (teamclaw_submit_result_contract), you MUST",
|
|
73
|
+
"accurately describe each deliverable so the team can preview your work:",
|
|
74
|
+
"",
|
|
75
|
+
"For any runnable web application or API service, set the deliverable fields:",
|
|
76
|
+
"- artifactType: \"web-app\" (for web frontends) or \"api-service\" (for backend APIs)",
|
|
77
|
+
"- previewCommand: the exact shell command to start the server, using {PORT} as a",
|
|
78
|
+
" placeholder for the port number. You are the expert who wrote the code — provide",
|
|
79
|
+
" the real command you would use to run it (e.g. \"npm run dev -- --port {PORT}\",",
|
|
80
|
+
" \"python3 app.py\", \"PORT={PORT} go run .\", \"npx next dev -p {PORT}\").",
|
|
81
|
+
"- previewCwd: the working directory relative to the workspace root",
|
|
82
|
+
" (e.g. \"my-app\", \"flask-api\", \".\")",
|
|
83
|
+
"- previewReadyPath: the URL path to poll for health checks (default \"/\")",
|
|
84
|
+
"",
|
|
85
|
+
"For static sites (HTML/CSS/JS without a build step), set artifactType to \"web-app\"",
|
|
86
|
+
"and leave previewCommand empty — the controller will serve static files automatically.",
|
|
87
|
+
"",
|
|
88
|
+
"For non-runnable deliverables (documents, scripts, configs, data files),",
|
|
89
|
+
"use kind \"file\" or \"note\" and do not set artifactType.",
|
|
90
|
+
"",
|
|
91
|
+
"The preview command will be executed in a sandboxed subprocess. It MUST bind to",
|
|
92
|
+
"0.0.0.0:{PORT} (or accept HOST and PORT environment variables) so the controller",
|
|
93
|
+
"can proxy requests to it. Do NOT use sed -i or any in-place file modification in",
|
|
94
|
+
"your preview command — it would dirty the git workspace.",
|
|
95
|
+
].join("\n"),
|
|
96
|
+
suggestedNextRoles: ["qa", "developer"],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: "qa",
|
|
100
|
+
label: "QA Engineer",
|
|
101
|
+
icon: "\uD83D\uDD0D",
|
|
102
|
+
description: "Testing, quality assurance, bug reporting",
|
|
103
|
+
capabilities: [
|
|
104
|
+
"test-planning", "test-case-writing", "bug-reporting",
|
|
105
|
+
"regression-testing", "quality-assurance",
|
|
106
|
+
],
|
|
107
|
+
recommendedSkills: ["find-skills"],
|
|
108
|
+
systemPrompt: [
|
|
109
|
+
"You are a QA Engineer in a virtual software team.",
|
|
110
|
+
"Your responsibilities include test planning, writing test cases, reporting bugs,",
|
|
111
|
+
"and ensuring quality standards.",
|
|
112
|
+
"When reviewing work, check for edge cases, error handling, and adherence to specifications.",
|
|
113
|
+
"Provide detailed, reproducible bug reports.",
|
|
114
|
+
"Prioritize a fast, evidence-based verdict over extra automation.",
|
|
115
|
+
"If you find a clear bug with solid reproduction steps, report it and conclude instead of continuing to expand optional coverage.",
|
|
116
|
+
"Only create auxiliary artifacts such as smoke scripts when they are explicitly requested or can be finished quickly without delaying your final QA result.",
|
|
117
|
+
].join("\n"),
|
|
118
|
+
suggestedNextRoles: ["developer", "release-engineer"],
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: "release-engineer",
|
|
122
|
+
label: "Release Engineer",
|
|
123
|
+
icon: "\uD83D\uDE82",
|
|
124
|
+
description: "Release management, deployment, version control",
|
|
125
|
+
capabilities: [
|
|
126
|
+
"release-management", "deployment", "version-control",
|
|
127
|
+
"ci-cd-pipeline", "release-notes",
|
|
128
|
+
],
|
|
129
|
+
recommendedSkills: ["find-skills"],
|
|
130
|
+
systemPrompt: [
|
|
131
|
+
"You are a Release Engineer in a virtual software team.",
|
|
132
|
+
"Your responsibilities include managing releases, deployment pipelines,",
|
|
133
|
+
"version control, and writing release notes.",
|
|
134
|
+
"Ensure smooth and reliable deployments with proper rollback strategies.",
|
|
135
|
+
].join("\n"),
|
|
136
|
+
suggestedNextRoles: ["devops", "developer"],
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "infra-engineer",
|
|
140
|
+
label: "Infrastructure Engineer",
|
|
141
|
+
icon: "\uD83D\uDEE2\uFE0F",
|
|
142
|
+
description: "Cloud infrastructure, networking, storage, compute resources",
|
|
143
|
+
capabilities: [
|
|
144
|
+
"cloud-infrastructure", "networking", "load-balancing",
|
|
145
|
+
"storage-design", "compute-provisioning", "cost-optimization",
|
|
146
|
+
"disaster-recovery", "capacity-planning", "iac-terraform",
|
|
147
|
+
],
|
|
148
|
+
recommendedSkills: ["find-skills"],
|
|
149
|
+
systemPrompt: [
|
|
150
|
+
"You are an Infrastructure Engineer in a virtual software team.",
|
|
151
|
+
"Your core responsibilities include designing, provisioning, and maintaining cloud infrastructure.",
|
|
152
|
+
"",
|
|
153
|
+
"Scope of expertise:",
|
|
154
|
+
"- Cloud platforms: AWS, Azure, GCP, and hybrid/multi-cloud architectures",
|
|
155
|
+
"- Networking: VPC/VNet design, DNS, CDN, VPN, firewall rules, subnets, NAT gateways",
|
|
156
|
+
"- Compute: VMs, containers, serverless (Lambda/Cloud Functions), auto-scaling groups",
|
|
157
|
+
"- Storage: block storage, object storage (S3/Blob), databases, caching layers (Redis/Memcached)",
|
|
158
|
+
"- Infrastructure as Code: Terraform, CloudFormation, Pulumi for reproducible environments",
|
|
159
|
+
"- High availability: multi-AZ, multi-region, failover strategies, RPO/RTO targets",
|
|
160
|
+
"- Cost management: right-sizing resources, reserved instances, spot/preemptible instances, tagging policies",
|
|
161
|
+
"",
|
|
162
|
+
"When receiving tasks:",
|
|
163
|
+
"1. Always produce concrete, actionable infrastructure specifications (not vague guidance).",
|
|
164
|
+
"2. Include resource estimates, topology diagrams (in ASCII/mermaid if helpful), and configuration snippets.",
|
|
165
|
+
"3. Consider cost implications and recommend the most cost-effective approach that meets requirements.",
|
|
166
|
+
"4. Design for failure: assume any component can fail at any time.",
|
|
167
|
+
"5. Follow the principle of least privilege for all IAM roles and access policies.",
|
|
168
|
+
"6. Ensure infrastructure is reproducible and version-controlled via IaC.",
|
|
169
|
+
"7. Collaborate closely with DevOps on CI/CD integration and with Security on compliance requirements.",
|
|
170
|
+
"8. Prefer open-source/free infrastructure building blocks first when they satisfy the requirement.",
|
|
171
|
+
"9. If the required infrastructure, credentials, or provisioning path are unavailable in the current environment, explicitly report the blocker and request clarification instead of inventing a nonexistent system.",
|
|
172
|
+
"",
|
|
173
|
+
"Output format: Provide structured specifications with clear sections for architecture, resources, networking, security boundaries, and cost estimates.",
|
|
174
|
+
].join("\n"),
|
|
175
|
+
suggestedNextRoles: ["devops", "security-engineer", "architect"],
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
id: "devops",
|
|
179
|
+
label: "DevOps Engineer",
|
|
180
|
+
icon: "\u2699\uFE0F",
|
|
181
|
+
description: "Infrastructure, CI/CD, monitoring, deployment",
|
|
182
|
+
capabilities: [
|
|
183
|
+
"infrastructure", "ci-cd", "monitoring",
|
|
184
|
+
"docker-kubernetes", "automation",
|
|
185
|
+
],
|
|
186
|
+
recommendedSkills: ["find-skills"],
|
|
187
|
+
systemPrompt: [
|
|
188
|
+
"You are a DevOps Engineer in a virtual software team.",
|
|
189
|
+
"Your responsibilities include infrastructure management, CI/CD pipelines,",
|
|
190
|
+
"monitoring, and automation.",
|
|
191
|
+
"Ensure reliable and scalable infrastructure with proper monitoring.",
|
|
192
|
+
"Prefer open-source/free tooling first when it can satisfy the task.",
|
|
193
|
+
"If the environment does not expose the required provisioning access, credentials, or runtime tools, stop and request clarification instead of pretending the deployment exists.",
|
|
194
|
+
].join("\n"),
|
|
195
|
+
suggestedNextRoles: ["developer", "release-engineer"],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
id: "security-engineer",
|
|
199
|
+
label: "Security Engineer",
|
|
200
|
+
icon: "\uD83D\uDD12",
|
|
201
|
+
description: "Application security, threat modeling, compliance, vulnerability assessment",
|
|
202
|
+
capabilities: [
|
|
203
|
+
"threat-modeling", "vulnerability-assessment", "security-architecture",
|
|
204
|
+
"penetration-testing", "compliance-audit", "incident-response",
|
|
205
|
+
"code-security-review", "secrets-management", "auth-design",
|
|
206
|
+
"data-protection",
|
|
207
|
+
],
|
|
208
|
+
recommendedSkills: ["find-skills"],
|
|
209
|
+
systemPrompt: [
|
|
210
|
+
"You are a Security Engineer in a virtual software team.",
|
|
211
|
+
"Your core responsibility is ensuring the security posture of all software, infrastructure, and data.",
|
|
212
|
+
"",
|
|
213
|
+
"Scope of expertise:",
|
|
214
|
+
"- Application Security: OWASP Top 10 prevention, input validation, output encoding, authentication/authorization flaws, injection attacks (SQLi, XSS, SSRF, deserialization)",
|
|
215
|
+
"- Authentication & Authorization: JWT/OAuth2/OIDC design, RBAC/ABAC models, session management, MFA, password policies, token lifecycle",
|
|
216
|
+
"- API Security: rate limiting, input sanitization, CORS policies, API key management, request signing, response filtering",
|
|
217
|
+
"- Infrastructure Security: network segmentation, WAF rules, TLS configuration, container security, secrets rotation, least-privilege IAM",
|
|
218
|
+
"- Data Protection: encryption at rest and in transit, PII handling, data classification, GDPR/PCI-D959/SoX compliance, key management",
|
|
219
|
+
"- Threat Modeling: STRIDE/DREAD analysis, attack tree construction, risk assessment matrices, trust boundary definition",
|
|
220
|
+
"- Incident Response: detection strategies, containment procedures, forensic analysis, post-mortem reporting, vulnerability disclosure",
|
|
221
|
+
"",
|
|
222
|
+
"When receiving tasks:",
|
|
223
|
+
"1. Always think like an attacker first. Identify the threat surface before proposing mitigations.",
|
|
224
|
+
"2. Provide specific, actionable recommendations with code examples or configuration snippets.",
|
|
225
|
+
"3. Classify findings by severity (Critical / High / Medium / Low / Informational) using CVSS or a similar framework.",
|
|
226
|
+
"4. Consider the full attack chain, not just individual vulnerabilities in isolation.",
|
|
227
|
+
"5. Balance security with usability — reject only when risk genuinely outweighs convenience.",
|
|
228
|
+
"6. Reference established standards: OWASP ASVS, NIST CSF, CIS Benchmarks, ISO 27001.",
|
|
229
|
+
"7. For code reviews, check for: injection, broken authentication, sensitive data exposure, XML external entities, broken access control, security misconfiguration, XSS, insecure deserialization, using components with known vulnerabilities, insufficient logging.",
|
|
230
|
+
"",
|
|
231
|
+
"Output format: Provide structured findings with severity, description, impact analysis, remediation steps, and verification methods.",
|
|
232
|
+
].join("\n"),
|
|
233
|
+
suggestedNextRoles: ["developer", "architect", "infra-engineer"],
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
id: "designer",
|
|
237
|
+
label: "UI/UX Designer",
|
|
238
|
+
icon: "\uD83C\uDFA8",
|
|
239
|
+
description: "User interface design, UX research, wireframing",
|
|
240
|
+
capabilities: [
|
|
241
|
+
"ui-design", "ux-research", "wireframing",
|
|
242
|
+
"prototyping", "design-systems",
|
|
243
|
+
],
|
|
244
|
+
recommendedSkills: ["ui-ux-pro-max", "find-skills"],
|
|
245
|
+
systemPrompt: [
|
|
246
|
+
"You are a UI/UX Designer in a virtual software team.",
|
|
247
|
+
"Your responsibilities include user interface design, UX research,",
|
|
248
|
+
"wireframing, and maintaining design systems.",
|
|
249
|
+
"Focus on user experience, accessibility, and visual consistency.",
|
|
250
|
+
].join("\n"),
|
|
251
|
+
suggestedNextRoles: ["developer", "pm"],
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
id: "marketing",
|
|
255
|
+
label: "Marketing Specialist",
|
|
256
|
+
icon: "\uD83D\uDCE3\uFE0F",
|
|
257
|
+
description: "Product marketing, content, launch strategy",
|
|
258
|
+
capabilities: [
|
|
259
|
+
"product-marketing", "content-creation",
|
|
260
|
+
"launch-strategy", "user-acquisition", "analytics",
|
|
261
|
+
],
|
|
262
|
+
recommendedSkills: ["find-skills"],
|
|
263
|
+
systemPrompt: [
|
|
264
|
+
"You are a Marketing Specialist in a virtual software team.",
|
|
265
|
+
"Your responsibilities include product marketing, content creation,",
|
|
266
|
+
"launch strategy, and user analytics.",
|
|
267
|
+
"Focus on user acquisition, engagement, and product positioning.",
|
|
268
|
+
].join("\n"),
|
|
269
|
+
suggestedNextRoles: ["pm", "designer"],
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
id: "data-engineer",
|
|
273
|
+
label: "Data Engineer",
|
|
274
|
+
icon: "\uD83D\uDCCA",
|
|
275
|
+
description: "Data pipeline design, ETL, data modeling",
|
|
276
|
+
capabilities: [
|
|
277
|
+
"data-modeling", "etl-pipeline", "data-quality", "sql-optimization",
|
|
278
|
+
],
|
|
279
|
+
recommendedSkills: ["find-skills"],
|
|
280
|
+
systemPrompt: [
|
|
281
|
+
"You are a Data Engineer in a virtual software team.",
|
|
282
|
+
"Your core responsibilities include designing, building, and maintaining data pipelines,",
|
|
283
|
+
"ETL processes, data models, and ensuring data quality across systems.",
|
|
284
|
+
"",
|
|
285
|
+
"Scope of expertise:",
|
|
286
|
+
"- Data Pipeline Design: batch and streaming pipelines (Apache Spark, Airflow, dbt, Flink, Kafka)",
|
|
287
|
+
"- ETL/ELT Processes: extraction, transformation, loading patterns; incremental vs. full refresh strategies",
|
|
288
|
+
"- Data Modeling: dimensional modeling (star/snowflake schemas), Data Vault, event-sourced modeling, normalization vs. denormalization trade-offs",
|
|
289
|
+
"- Data Quality: validation frameworks, anomaly detection, data profiling, SLA monitoring, lineage tracking",
|
|
290
|
+
"- SQL Optimization: query performance tuning, indexing strategies, execution plan analysis, partitioning",
|
|
291
|
+
"- Data Storage: relational databases (PostgreSQL, MySQL), data warehouses (Snowflake, BigQuery, Redshift), data lakes (Delta Lake, Iceberg, Hudi)",
|
|
292
|
+
"- Orchestration: workflow scheduling, dependency management, idempotent pipeline design, backfill strategies",
|
|
293
|
+
"- Data Integration: API ingestion, CDC (Change Data Capture), schema evolution, data contracts",
|
|
294
|
+
"",
|
|
295
|
+
"When receiving tasks:",
|
|
296
|
+
"1. Always produce concrete, actionable data specifications (not vague guidance).",
|
|
297
|
+
"2. Include schema definitions (DDL), pipeline DAGs or flow diagrams (in ASCII/mermaid if helpful), and configuration snippets.",
|
|
298
|
+
"3. Consider data freshness, latency, and throughput requirements when choosing pipeline architectures.",
|
|
299
|
+
"4. Design for data quality from the start: include validation checks, monitoring, and alerting in every pipeline.",
|
|
300
|
+
"5. Prefer idempotent and reversible transformations to simplify recovery and debugging.",
|
|
301
|
+
"6. Document data lineage and ownership so downstream consumers can trace data origins.",
|
|
302
|
+
"7. Collaborate closely with Developers on data API contracts and with Architects on storage infrastructure.",
|
|
303
|
+
"8. If the required data sources, credentials, or infrastructure are unavailable in the current environment, explicitly report the blocker and request clarification instead of inventing a nonexistent system.",
|
|
304
|
+
"",
|
|
305
|
+
"Output format: Provide structured specifications with clear sections for pipeline architecture, data models (schema DDL), quality rules, and operational runbooks.",
|
|
306
|
+
].join("\n"),
|
|
307
|
+
suggestedNextRoles: ["developer", "infra-engineer"],
|
|
308
|
+
},
|
|
309
|
+
];
|
|
310
|
+
for (const role of ROLES) {
|
|
311
|
+
role.systemPrompt = composePrompt(role.systemPrompt, buildRoleOperatingRules({
|
|
312
|
+
suggestedRoles: role.suggestedNextRoles,
|
|
313
|
+
recommendedSkills: role.recommendedSkills,
|
|
314
|
+
}), buildWorkerMemoryContractRules());
|
|
315
|
+
}
|
|
316
|
+
const ROLE_MAP = new Map(ROLES.map((r) => [r.id, r]));
|
|
317
|
+
const ROLE_IDS = ROLES.map((r) => r.id);
|
|
318
|
+
function getRole(id) {
|
|
319
|
+
return ROLE_MAP.get(id);
|
|
320
|
+
}
|
|
321
|
+
function normalizeRecommendedSkills(skills = []) {
|
|
322
|
+
const seen = new Set();
|
|
323
|
+
const normalized = [];
|
|
324
|
+
for (const entry of skills) {
|
|
325
|
+
const value = String(entry || "").trim();
|
|
326
|
+
if (!value) {
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
const key = value.toLowerCase();
|
|
330
|
+
if (seen.has(key)) {
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
seen.add(key);
|
|
334
|
+
normalized.push(value);
|
|
335
|
+
}
|
|
336
|
+
return normalized;
|
|
337
|
+
}
|
|
338
|
+
function resolveRecommendedSkillsForRole(roleId, taskSkills = []) {
|
|
339
|
+
const roleSkills = roleId ? (getRole(roleId)?.recommendedSkills ?? []) : [];
|
|
340
|
+
return normalizeRecommendedSkills([...roleSkills, ...taskSkills]);
|
|
341
|
+
}
|
|
342
|
+
function buildRolePrompt(role, teamContext) {
|
|
343
|
+
const parts = [role.systemPrompt];
|
|
344
|
+
if (teamContext) {
|
|
345
|
+
parts.push(`\nTeam Context:\n${teamContext}`);
|
|
346
|
+
}
|
|
347
|
+
return composePrompt(...parts);
|
|
348
|
+
}
|
|
349
|
+
export { ROLES, ROLE_IDS, getRole, buildRolePrompt, normalizeRecommendedSkills, resolveRecommendedSkillsForRole };
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
const STATE_VERSION = 2;
|
|
5
|
+
function migrateState(raw) {
|
|
6
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const state = raw;
|
|
10
|
+
// Basic structural guard — same checks as the old loadTeamState
|
|
11
|
+
if (typeof state.teamName !== "string" ||
|
|
12
|
+
typeof state.createdAt !== "number" ||
|
|
13
|
+
typeof state.updatedAt !== "number" ||
|
|
14
|
+
!state.workers ||
|
|
15
|
+
!state.tasks) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
// Ensure required nested objects exist (defensive, same as before)
|
|
19
|
+
if (!state.controllerRuns || typeof state.controllerRuns !== "object") {
|
|
20
|
+
state.controllerRuns = {};
|
|
21
|
+
}
|
|
22
|
+
if (!state.projects || typeof state.projects !== "object") {
|
|
23
|
+
state.projects = {};
|
|
24
|
+
}
|
|
25
|
+
if (!Array.isArray(state.messages)) {
|
|
26
|
+
state.messages = [];
|
|
27
|
+
}
|
|
28
|
+
if (!state.clarifications || typeof state.clarifications !== "object") {
|
|
29
|
+
state.clarifications = {};
|
|
30
|
+
}
|
|
31
|
+
if (state.repo && typeof state.repo !== "object") {
|
|
32
|
+
delete state.repo;
|
|
33
|
+
}
|
|
34
|
+
if (!state.provisioning || typeof state.provisioning !== "object") {
|
|
35
|
+
state.provisioning = createEmptyProvisioningState();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const prov = state.provisioning;
|
|
39
|
+
if (!prov.workers || typeof prov.workers !== "object") {
|
|
40
|
+
prov.workers = {};
|
|
41
|
+
}
|
|
42
|
+
prov.startupReadiness = normalizeStartupReadiness(prov.startupReadiness);
|
|
43
|
+
}
|
|
44
|
+
const version = typeof state.version === "number" ? state.version : 1;
|
|
45
|
+
if (version > STATE_VERSION) {
|
|
46
|
+
throw new Error(`Saved team state is version ${version}, but this software only supports up to version ${STATE_VERSION}. ` +
|
|
47
|
+
"Please update TeamClaw to a newer version that supports this state format.");
|
|
48
|
+
}
|
|
49
|
+
// Version 1 → 2: no new required fields beyond `version` itself.
|
|
50
|
+
// startupReadiness was already optional and handled by normalizeStartupReadiness above.
|
|
51
|
+
state.version = STATE_VERSION;
|
|
52
|
+
return state;
|
|
53
|
+
}
|
|
54
|
+
function resolvePluginStateDir() {
|
|
55
|
+
const explicitStateDir = process.env.OPENCLAW_STATE_DIR?.trim();
|
|
56
|
+
if (explicitStateDir) {
|
|
57
|
+
return path.join(explicitStateDir, "plugins", "teamclaw");
|
|
58
|
+
}
|
|
59
|
+
const explicitHome = process.env.OPENCLAW_HOME?.trim() || process.env.HOME?.trim();
|
|
60
|
+
const homeDir = explicitHome ? path.resolve(explicitHome) : os.homedir();
|
|
61
|
+
return path.join(homeDir, ".openclaw", "plugins", "teamclaw");
|
|
62
|
+
}
|
|
63
|
+
const STATE_DIR = resolvePluginStateDir();
|
|
64
|
+
const writeQueues = new Map();
|
|
65
|
+
function createEmptyProvisioningState() {
|
|
66
|
+
return {
|
|
67
|
+
workers: {},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function normalizeStartupReadiness(value) {
|
|
71
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
const record = value;
|
|
75
|
+
const status = record.status === "checking" || record.status === "ready" || record.status === "degraded"
|
|
76
|
+
? record.status
|
|
77
|
+
: undefined;
|
|
78
|
+
const startedAt = typeof record.startedAt === "number" ? record.startedAt : undefined;
|
|
79
|
+
const checkedAt = typeof record.checkedAt === "number" ? record.checkedAt : undefined;
|
|
80
|
+
const attempts = typeof record.attempts === "number" && record.attempts >= 0 ? Math.floor(record.attempts) : 0;
|
|
81
|
+
const requiredRoles = Array.isArray(record.requiredRoles)
|
|
82
|
+
? record.requiredRoles.filter((entry) => typeof entry === "string")
|
|
83
|
+
: [];
|
|
84
|
+
const readyWorkerIds = Array.isArray(record.readyWorkerIds)
|
|
85
|
+
? record.readyWorkerIds.filter((entry) => typeof entry === "string")
|
|
86
|
+
: [];
|
|
87
|
+
const message = typeof record.message === "string" && record.message.trim() ? record.message : undefined;
|
|
88
|
+
if (!status || startedAt === undefined || checkedAt === undefined) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
status,
|
|
93
|
+
startedAt,
|
|
94
|
+
checkedAt,
|
|
95
|
+
attempts,
|
|
96
|
+
requiredRoles: requiredRoles,
|
|
97
|
+
readyWorkerIds,
|
|
98
|
+
message,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async function ensureDir(dir) {
|
|
102
|
+
await fs.mkdir(dir, { recursive: true });
|
|
103
|
+
}
|
|
104
|
+
async function writeFileAtomically(filePath, contents) {
|
|
105
|
+
const tmpPath = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
106
|
+
await fs.writeFile(tmpPath, contents, "utf8");
|
|
107
|
+
await fs.rename(tmpPath, filePath);
|
|
108
|
+
}
|
|
109
|
+
function enqueueAtomicWrite(filePath, contents) {
|
|
110
|
+
const previous = writeQueues.get(filePath) ?? Promise.resolve();
|
|
111
|
+
const next = previous
|
|
112
|
+
.catch(() => { })
|
|
113
|
+
.then(() => writeFileAtomically(filePath, contents));
|
|
114
|
+
writeQueues.set(filePath, next);
|
|
115
|
+
return next.finally(() => {
|
|
116
|
+
if (writeQueues.get(filePath) === next) {
|
|
117
|
+
writeQueues.delete(filePath);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async function loadTeamState(teamName) {
|
|
122
|
+
const filePath = path.join(STATE_DIR, `${teamName}-team-state.json`);
|
|
123
|
+
try {
|
|
124
|
+
const raw = await fs.readFile(filePath, "utf8");
|
|
125
|
+
const parsed = JSON.parse(raw);
|
|
126
|
+
return migrateState(parsed);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function saveTeamState(state) {
|
|
133
|
+
await ensureDir(STATE_DIR);
|
|
134
|
+
const filePath = path.join(STATE_DIR, `${state.teamName}-team-state.json`);
|
|
135
|
+
state.version = STATE_VERSION;
|
|
136
|
+
state.updatedAt = Date.now();
|
|
137
|
+
state.provisioning = state.provisioning && typeof state.provisioning === "object"
|
|
138
|
+
? state.provisioning
|
|
139
|
+
: createEmptyProvisioningState();
|
|
140
|
+
state.provisioning.workers = state.provisioning.workers && typeof state.provisioning.workers === "object"
|
|
141
|
+
? state.provisioning.workers
|
|
142
|
+
: {};
|
|
143
|
+
state.provisioning.startupReadiness = normalizeStartupReadiness(state.provisioning.startupReadiness);
|
|
144
|
+
state.controllerRuns = state.controllerRuns && typeof state.controllerRuns === "object"
|
|
145
|
+
? state.controllerRuns
|
|
146
|
+
: {};
|
|
147
|
+
state.projects = state.projects && typeof state.projects === "object"
|
|
148
|
+
? state.projects
|
|
149
|
+
: {};
|
|
150
|
+
await enqueueAtomicWrite(filePath, `${JSON.stringify(state, null, 2)}\n`);
|
|
151
|
+
}
|
|
152
|
+
async function loadWorkerIdentity() {
|
|
153
|
+
const filePath = path.join(STATE_DIR, "worker-identity.json");
|
|
154
|
+
try {
|
|
155
|
+
const raw = await fs.readFile(filePath, "utf8");
|
|
156
|
+
const parsed = JSON.parse(raw);
|
|
157
|
+
if (typeof parsed.workerId !== "string" ||
|
|
158
|
+
typeof parsed.role !== "string" ||
|
|
159
|
+
typeof parsed.controllerUrl !== "string" ||
|
|
160
|
+
typeof parsed.registeredAt !== "number") {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
return parsed;
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function saveWorkerIdentity(identity) {
|
|
170
|
+
await ensureDir(STATE_DIR);
|
|
171
|
+
const filePath = path.join(STATE_DIR, "worker-identity.json");
|
|
172
|
+
await enqueueAtomicWrite(filePath, `${JSON.stringify(identity, null, 2)}\n`);
|
|
173
|
+
}
|
|
174
|
+
async function clearWorkerIdentity() {
|
|
175
|
+
const filePath = path.join(STATE_DIR, "worker-identity.json");
|
|
176
|
+
try {
|
|
177
|
+
await fs.unlink(filePath);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// ignore
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
export { STATE_DIR, loadTeamState, saveTeamState, loadWorkerIdentity, saveWorkerIdentity, clearWorkerIdentity, };
|