@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.
- package/cli.mjs +318 -17
- package/dist/index.js +54 -32
- package/dist/src/config.js +57 -2
- package/dist/src/controller/auth-routes.js +129 -0
- package/dist/src/controller/clarification-routes.js +315 -0
- package/dist/src/controller/controller-intake.js +895 -0
- package/dist/src/controller/controller-planning.js +814 -0
- package/dist/src/controller/controller-routes.js +195 -0
- package/dist/src/controller/controller-runs.js +175 -0
- package/dist/src/controller/controller-service.js +338 -50
- package/dist/src/controller/controller-tools.js +14 -7
- package/dist/src/controller/github-auth.js +2 -1
- package/dist/src/controller/http-server.js +290 -6003
- package/dist/src/controller/kickoff-orchestrator.js +33 -43
- package/dist/src/controller/message-delivery.js +31 -0
- package/dist/src/controller/message-routes.js +114 -0
- package/dist/src/controller/orchestration-manifest.js +11 -93
- package/dist/src/controller/preview-manager.js +51 -3
- package/dist/src/controller/preview-proxy.js +98 -0
- package/dist/src/controller/profile-switch.js +309 -0
- package/dist/src/controller/project-registry.js +294 -0
- package/dist/src/controller/prompt-injector.js +19 -9
- package/dist/src/controller/provisioning/backend-contract.js +9 -0
- package/dist/src/controller/provisioning/container-shared.js +64 -0
- package/dist/src/controller/provisioning/docker.js +214 -0
- package/dist/src/controller/provisioning/kubernetes.js +244 -0
- package/dist/src/controller/provisioning/plugin-root.js +41 -0
- package/dist/src/controller/provisioning/process-supervisor.js +190 -0
- package/dist/src/controller/provisioning-config.js +239 -0
- package/dist/src/controller/repo-routes.js +129 -0
- package/dist/src/controller/report-routes.js +56 -0
- package/dist/src/controller/role-inference.js +231 -20
- package/dist/src/controller/route-table.js +375 -0
- package/dist/src/controller/security.js +775 -0
- package/dist/src/controller/status-routes.js +287 -0
- package/dist/src/controller/task-assignment.js +511 -0
- package/dist/src/controller/task-cleanup.js +258 -0
- package/dist/src/controller/task-execution.js +271 -0
- package/dist/src/controller/task-results.js +471 -0
- package/dist/src/controller/task-router.js +74 -4
- package/dist/src/controller/task-routes.js +703 -0
- package/dist/src/controller/teamauto-routes.js +124 -0
- package/dist/src/controller/tunnel-manager.js +41 -8
- package/dist/src/controller/tunnel-routes.js +225 -0
- package/dist/src/controller/ui-assets.js +68 -0
- package/dist/src/controller/websocket.js +6 -2
- package/dist/src/controller/webui-routes.js +49 -0
- package/dist/src/controller/worker-provisioning.js +69 -953
- package/dist/src/controller/worker-routes.js +188 -0
- package/dist/src/controller/workflow-routes.js +407 -0
- package/dist/src/controller/workspace-routes.js +200 -0
- package/dist/src/git-collaboration.js +4 -9
- package/dist/src/identity.js +15 -3
- package/dist/src/interaction-contracts.js +7 -7
- package/dist/src/openclaw-workspace.js +40 -18
- package/dist/src/profile-loader.js +604 -0
- package/dist/src/profiles/banking.json +202 -0
- package/dist/src/profiles/crossborder-ecom.json +253 -0
- package/dist/src/profiles/insurance.json +157 -0
- package/dist/src/profiles/knowledge/hs-structure.md +97 -0
- package/dist/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/dist/src/profiles/knowledge/vat-principles.md +85 -0
- package/dist/src/profiles/schema.json +281 -0
- package/dist/src/profiles/securities.json +137 -0
- package/dist/src/profiles/software-rd.json +264 -0
- package/dist/src/profiles/trading-co.json +200 -0
- package/dist/src/prompt-policy.js +42 -17
- package/dist/src/protocol.js +66 -3
- package/dist/src/role-ids.js +29 -0
- package/dist/src/roles.js +54 -13
- package/dist/src/session-roles.js +14 -0
- package/dist/src/shared/clarification-schema.js +65 -0
- package/dist/src/shared/github-auth.js +15 -0
- package/dist/src/shared/kickoff-prompt.js +37 -0
- package/dist/src/shared/utils.js +47 -0
- package/dist/src/state.js +275 -11
- package/dist/src/task-executor.js +7 -17
- package/dist/src/teamauto/github-client.js +18 -0
- package/dist/src/teamauto/repo-sync.js +228 -6
- package/dist/src/teamauto/scanner.js +40 -12
- package/dist/src/teamauto/scheduler.js +231 -12
- package/dist/src/types.js +77 -16
- package/dist/src/ui/app.js +1434 -82
- package/dist/src/ui/github-login.html +1 -0
- package/dist/src/ui/index.html +144 -45
- package/dist/src/ui/style.css +194 -0
- package/dist/src/worker/http-handler.js +59 -0
- package/dist/src/worker/prompt-injector.js +44 -8
- package/dist/src/worker/skill-installer.js +6 -10
- package/dist/src/worker/tools.js +20 -10
- package/dist/src/worker/worker-service.js +93 -7
- package/index.ts +61 -32
- package/openclaw.plugin.json +50 -2
- package/package.json +3 -2
- package/src/config.ts +57 -2
- package/src/controller/auth-routes.ts +157 -0
- package/src/controller/clarification-routes.ts +404 -0
- package/src/controller/controller-intake.ts +1113 -0
- package/src/controller/controller-planning.ts +1037 -0
- package/src/controller/controller-routes.ts +237 -0
- package/src/controller/controller-runs.ts +239 -0
- package/src/controller/controller-service.ts +422 -50
- package/src/controller/controller-tools.ts +16 -9
- package/src/controller/github-auth.ts +28 -63
- package/src/controller/http-server.ts +336 -6964
- package/src/controller/kickoff-orchestrator.ts +69 -45
- package/src/controller/message-delivery.ts +52 -0
- package/src/controller/message-routes.ts +137 -0
- package/src/controller/orchestration-manifest.ts +14 -100
- package/src/controller/preview-manager.ts +53 -3
- package/src/controller/preview-proxy.ts +127 -0
- package/src/controller/profile-switch.ts +396 -0
- package/src/controller/project-registry.ts +361 -0
- package/src/controller/prompt-injector.ts +23 -8
- package/src/controller/provisioning/backend-contract.ts +51 -0
- package/src/controller/provisioning/container-shared.ts +84 -0
- package/src/controller/provisioning/docker.ts +260 -0
- package/src/controller/provisioning/kubernetes.ts +263 -0
- package/src/controller/provisioning/plugin-root.ts +42 -0
- package/src/controller/provisioning/process-supervisor.ts +214 -0
- package/src/controller/provisioning-config.ts +289 -0
- package/src/controller/repo-routes.ts +163 -0
- package/src/controller/report-routes.ts +64 -0
- package/src/controller/role-inference.ts +260 -22
- package/src/controller/route-table.ts +597 -0
- package/src/controller/security.ts +899 -0
- package/src/controller/status-routes.ts +354 -0
- package/src/controller/task-assignment.ts +622 -0
- package/src/controller/task-cleanup.ts +344 -0
- package/src/controller/task-execution.ts +399 -0
- package/src/controller/task-results.ts +556 -0
- package/src/controller/task-router.ts +98 -6
- package/src/controller/task-routes.ts +812 -0
- package/src/controller/teamauto-routes.ts +121 -0
- package/src/controller/tunnel-manager.ts +45 -8
- package/src/controller/tunnel-routes.ts +231 -0
- package/src/controller/ui-assets.ts +70 -0
- package/src/controller/websocket.ts +32 -4
- package/src/controller/webui-routes.ts +55 -0
- package/src/controller/worker-provisioning.ts +83 -1121
- package/src/controller/worker-routes.ts +241 -0
- package/src/controller/workflow-routes.ts +498 -0
- package/src/controller/workspace-routes.ts +222 -0
- package/src/git-collaboration.ts +4 -9
- package/src/identity.ts +16 -3
- package/src/interaction-contracts.ts +7 -7
- package/src/openclaw-workspace.ts +44 -18
- package/src/profile-loader.ts +816 -0
- package/src/profiles/banking.json +202 -0
- package/src/profiles/crossborder-ecom.json +253 -0
- package/src/profiles/insurance.json +157 -0
- package/src/profiles/knowledge/hs-structure.md +97 -0
- package/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/src/profiles/knowledge/vat-principles.md +85 -0
- package/src/profiles/schema.json +281 -0
- package/src/profiles/securities.json +137 -0
- package/src/profiles/software-rd.json +264 -0
- package/src/profiles/trading-co.json +200 -0
- package/src/prompt-policy.ts +44 -17
- package/src/protocol.ts +72 -2
- package/src/role-ids.ts +31 -0
- package/src/roles.ts +60 -14
- package/src/session-roles.ts +14 -0
- package/src/shared/clarification-schema.ts +81 -0
- package/src/shared/github-auth.ts +92 -0
- package/src/shared/kickoff-prompt.ts +47 -0
- package/src/shared/utils.ts +51 -0
- package/src/state.ts +326 -10
- package/src/task-executor.ts +7 -18
- package/src/teamauto/github-client.ts +23 -1
- package/src/teamauto/repo-sync.ts +248 -7
- package/src/teamauto/scanner.ts +47 -13
- package/src/teamauto/scheduler.ts +261 -17
- package/src/teamauto/store.ts +12 -0
- package/src/types.ts +263 -17
- package/src/ui/app.js +1434 -82
- package/src/ui/github-login.html +1 -0
- package/src/ui/index.html +144 -45
- package/src/ui/style.css +194 -0
- package/src/worker/http-handler.ts +64 -1
- package/src/worker/prompt-injector.ts +48 -8
- package/src/worker/skill-installer.ts +6 -10
- package/src/worker/tools.ts +21 -10
- package/src/worker/worker-service.ts +101 -7
|
@@ -16,8 +16,14 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import type { PluginLogger } from "../../api.js";
|
|
19
|
-
import type { KickoffAssessment, KickoffPlan, RoleId, TeamState, WorkerInfo } from "../types.js";
|
|
20
|
-
|
|
19
|
+
import type { KickoffAssessment, KickoffPlan, RoleId, TaskInfo, TeamState, WorkerInfo } from "../types.js";
|
|
20
|
+
// Phase 1.3: role data comes from the active TeamProfile loader.
|
|
21
|
+
import { getActiveDefaultRole, getActiveRole, getActiveRoleIds, validateActiveRoleId } from "../profile-loader.js";
|
|
22
|
+
// W6 of issue #226: the local sleep copy (byte-identical to the shared one)
|
|
23
|
+
// was removed in favor of shared/utils.js.
|
|
24
|
+
import { sleep } from "../shared/utils.js";
|
|
25
|
+
import { inferTaskRoleWithConfidence } from "./role-inference.js";
|
|
26
|
+
import type { RoleInferenceVerdict } from "./role-inference.js";
|
|
21
27
|
|
|
22
28
|
// ── Constants ────────────────────────────────────────────────────────────────
|
|
23
29
|
|
|
@@ -30,7 +36,7 @@ const ASSESSMENT_TIMEOUT_MS = 120_000;
|
|
|
30
36
|
/** Poll interval when waiting for workers to appear in state. */
|
|
31
37
|
const WORKER_POLL_INTERVAL_MS = 2_000;
|
|
32
38
|
|
|
33
|
-
|
|
39
|
+
|
|
34
40
|
|
|
35
41
|
// ── Types ────────────────────────────────────────────────────────────────────
|
|
36
42
|
|
|
@@ -65,7 +71,8 @@ export async function runKickoffMeeting(
|
|
|
65
71
|
const { requirement, candidateRoles, complexity } = request;
|
|
66
72
|
|
|
67
73
|
// Validate roles
|
|
68
|
-
|
|
74
|
+
// Resolved per call so the set always reflects the active profile.
|
|
75
|
+
const validRoles = candidateRoles.filter((r) => getActiveRoleIds().includes(r));
|
|
69
76
|
if (validRoles.length === 0) {
|
|
70
77
|
return buildEmptyResult(complexity, "No valid candidate roles provided.");
|
|
71
78
|
}
|
|
@@ -184,7 +191,7 @@ function buildKickoffSummary(plan: KickoffPlan, _requirement: string): string {
|
|
|
184
191
|
if (needed.length > 0) {
|
|
185
192
|
parts.push("### Roles Confirmed Needed");
|
|
186
193
|
for (const a of needed) {
|
|
187
|
-
const roleDef =
|
|
194
|
+
const roleDef = getActiveRole(a.role);
|
|
188
195
|
const icon = roleDef?.icon ?? "•";
|
|
189
196
|
parts.push(`\n**${icon} ${roleDef?.label ?? a.role}**`);
|
|
190
197
|
parts.push(`- Scope: ${a.scope}`);
|
|
@@ -207,7 +214,7 @@ function buildKickoffSummary(plan: KickoffPlan, _requirement: string): string {
|
|
|
207
214
|
parts.push("");
|
|
208
215
|
parts.push("### Roles Not Needed");
|
|
209
216
|
for (const a of notNeeded) {
|
|
210
|
-
const roleDef =
|
|
217
|
+
const roleDef = getActiveRole(a.role);
|
|
211
218
|
parts.push(`- ${roleDef?.icon ?? "•"} ${roleDef?.label ?? a.role}: ${a.scope}`);
|
|
212
219
|
}
|
|
213
220
|
}
|
|
@@ -247,46 +254,63 @@ function buildKickoffSummary(plan: KickoffPlan, _requirement: string): string {
|
|
|
247
254
|
return parts.join("\n");
|
|
248
255
|
}
|
|
249
256
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
`- Return ONLY the JSON object, no markdown fencing, no explanation.`,
|
|
285
|
-
].join("\n");
|
|
286
|
-
}
|
|
257
|
+
// ── Phase 2.5: LLM fallback for unconfident role inference (design 2.3) ─────
|
|
258
|
+
//
|
|
259
|
+
// The tiered token scoring in role-inference.ts is the FAST PATH only. When
|
|
260
|
+
// it refuses to decide (all-zero, or the top two roles tie), the role
|
|
261
|
+
// decision escalates to the controller LLM pass - the same LLM-driven intake
|
|
262
|
+
// flow that drives this orchestrator (manifest requiredRoles, kickoff
|
|
263
|
+
// candidateRoles, worker assessments). role-inference stays a pure module,
|
|
264
|
+
// so the escalation lives here behind an injected callback: production
|
|
265
|
+
// callers wire the callback to their controller-LLM session; tests inject a
|
|
266
|
+
// fake. Without a callback the resolver degrades to the profile defaultRole
|
|
267
|
+
// (the Phase 0.1 configurable fallback).
|
|
268
|
+
|
|
269
|
+
export type TaskRoleResolutionDeps = {
|
|
270
|
+
/** Pure token fast path. Injectable so tests can pin the escalation wiring. */
|
|
271
|
+
inferWithConfidence?: typeof inferTaskRoleWithConfidence;
|
|
272
|
+
/**
|
|
273
|
+
* LLM fallback: ask the controller LLM pass to judge the role for the
|
|
274
|
+
* task. Returns a role id (validated against the active profile; invalid
|
|
275
|
+
* or null results fall back to the profile defaultRole).
|
|
276
|
+
* "id" is part of the payload (P2.5 wiring) so production judges can key
|
|
277
|
+
* one-shot sessions and logs by task id.
|
|
278
|
+
*/
|
|
279
|
+
llmRoleJudge?: (input: { task: Pick<TaskInfo, "id" | "assignedRole" | "title" | "description">; verdict: RoleInferenceVerdict }) => Promise<RoleId | string | null>;
|
|
280
|
+
logger?: Pick<PluginLogger, "info" | "warn">;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
export async function resolveTaskRoleWithLlmFallback(
|
|
284
|
+
task: Pick<TaskInfo, "id" | "assignedRole" | "title" | "description">,
|
|
285
|
+
deps: TaskRoleResolutionDeps = {},
|
|
286
|
+
): Promise<RoleId> {
|
|
287
|
+
const verdict = (deps.inferWithConfidence ?? inferTaskRoleWithConfidence)(task);
|
|
288
|
+
if (!verdict.needsLlmFallback) {
|
|
289
|
+
return verdict.role!;
|
|
290
|
+
}
|
|
287
291
|
|
|
288
|
-
|
|
289
|
-
|
|
292
|
+
if (deps.llmRoleJudge) {
|
|
293
|
+
try {
|
|
294
|
+
const judged = await deps.llmRoleJudge({ task, verdict });
|
|
295
|
+
const validated = validateActiveRoleId(judged);
|
|
296
|
+
if (validated) {
|
|
297
|
+
deps.logger?.info(
|
|
298
|
+
`RoleInference: LLM fallback judged role ${validated} (token fast path refused: ${verdict.reason})`,
|
|
299
|
+
);
|
|
300
|
+
return validated;
|
|
301
|
+
}
|
|
302
|
+
deps.logger?.warn(
|
|
303
|
+
`RoleInference: LLM fallback returned ${JSON.stringify(judged)} which is not a role of the active profile; using defaultRole`,
|
|
304
|
+
);
|
|
305
|
+
} catch (err) {
|
|
306
|
+
deps.logger?.warn(`RoleInference: LLM fallback failed (${err instanceof Error ? err.message : String(err)}); using defaultRole`);
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
deps.logger?.info(
|
|
310
|
+
`RoleInference: token fast path refused to decide (${verdict.reason}) and no LLM fallback is wired; using defaultRole`,
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
return getActiveDefaultRole();
|
|
290
314
|
}
|
|
291
315
|
|
|
292
316
|
export { ASSESSMENT_TIMEOUT_MS };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// PR-C of issue #204 (http-server monolith split): the worker message
|
|
2
|
+
// delivery helpers extracted verbatim from controller/http-server.ts. Zero
|
|
3
|
+
// behavior change. This module must NEVER import http-server (the reverse
|
|
4
|
+
// edge exists: http-server -> message-delivery); the router and state getter
|
|
5
|
+
// arrive through the deps slice below. Kept separate from the higher-level
|
|
6
|
+
// message ROUTES because the controller-planning intake glue also delivers
|
|
7
|
+
// messages and must stay below the route layer.
|
|
8
|
+
import type { TeamMessage, WorkerInfo } from "../types.js";
|
|
9
|
+
import { withWorkerDispatchToken } from "./task-execution.js";
|
|
10
|
+
import type { ControllerTaskDomainDeps } from "./task-execution.js";
|
|
11
|
+
|
|
12
|
+
export async function deliverMessageToWorker(
|
|
13
|
+
worker: WorkerInfo,
|
|
14
|
+
message: TeamMessage,
|
|
15
|
+
deps: ControllerTaskDomainDeps,
|
|
16
|
+
): Promise<void> {
|
|
17
|
+
// Issue #222: carry the worker's dispatch token so a token-paired worker
|
|
18
|
+
// accepts the injection; L0 sends the historical header set unchanged.
|
|
19
|
+
const res = await fetch(`${worker.url}/api/v1/messages`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: withWorkerDispatchToken({ "Content-Type": "application/json" }, worker.id, deps.config, deps.getTeamState()),
|
|
22
|
+
body: JSON.stringify(message),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
throw new Error(`worker ${worker.id} responded with ${res.status}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function routeDirectMessage(
|
|
31
|
+
message: TeamMessage,
|
|
32
|
+
deps: ControllerTaskDomainDeps,
|
|
33
|
+
): Promise<boolean> {
|
|
34
|
+
const { getTeamState, logger, messageRouter } = deps;
|
|
35
|
+
const state = getTeamState();
|
|
36
|
+
if (!state) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const routed = messageRouter.routeDirectMessage(message, state.workers);
|
|
41
|
+
if (!routed) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
await deliverMessageToWorker(routed.worker, routed.message, deps);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
logger.warn(`Controller: failed to deliver message to ${routed.worker.id}: ${String(err)}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// PR-C of issue #204 (http-server monolith split): the team message routes
|
|
2
|
+
// (direct/broadcast/review-request send + list) lifted verbatim from the
|
|
3
|
+
// inline dispatch blocks in controller/http-server.ts. Zero behavior change -
|
|
4
|
+
// the route shells in http-server keep the method+pathname matches and call
|
|
5
|
+
// these handlers with the same deps object as before. This module must NEVER
|
|
6
|
+
// import http-server (the reverse edge exists: http-server -> message-routes).
|
|
7
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
8
|
+
import type { TeamMessage } from "../types.js";
|
|
9
|
+
import { generateId, parseJsonBody, sendJson } from "../protocol.js";
|
|
10
|
+
import { ensureTeamMessageContract } from "../interaction-contracts.js";
|
|
11
|
+
import { validateActiveRoleId } from "../profile-loader.js";
|
|
12
|
+
import {
|
|
13
|
+
deliverMessageToWorker,
|
|
14
|
+
routeDirectMessage,
|
|
15
|
+
} from "./message-delivery.js";
|
|
16
|
+
import type { ControllerTaskDomainDeps } from "./task-execution.js";
|
|
17
|
+
|
|
18
|
+
// POST /api/v1/messages/direct
|
|
19
|
+
export async function handleDirectMessageRequest(deps: ControllerTaskDomainDeps, req: IncomingMessage, res: ServerResponse): Promise<void> {
|
|
20
|
+
const { updateTeamState, wsServer } = deps;
|
|
21
|
+
const body = await parseJsonBody(req);
|
|
22
|
+
const fromRole = validateActiveRoleId(body.fromRole);
|
|
23
|
+
const toRole = validateActiveRoleId(body.toRole);
|
|
24
|
+
const message: TeamMessage = {
|
|
25
|
+
id: generateId(),
|
|
26
|
+
from: typeof body.from === "string" ? body.from : "",
|
|
27
|
+
fromRole,
|
|
28
|
+
toRole,
|
|
29
|
+
type: "direct",
|
|
30
|
+
content: typeof body.content === "string" ? body.content : "",
|
|
31
|
+
contract: ensureTeamMessageContract(body.contract, {
|
|
32
|
+
type: "direct",
|
|
33
|
+
content: typeof body.content === "string" ? body.content : "",
|
|
34
|
+
toRole,
|
|
35
|
+
taskId: typeof body.taskId === "string" ? body.taskId : undefined,
|
|
36
|
+
}),
|
|
37
|
+
taskId: typeof body.taskId === "string" ? body.taskId : undefined,
|
|
38
|
+
createdAt: Date.now(),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
updateTeamState((s) => { s.messages.push(message); });
|
|
42
|
+
|
|
43
|
+
const routed = await routeDirectMessage(message, deps);
|
|
44
|
+
|
|
45
|
+
wsServer.broadcastUpdate({ type: "message:new", data: message });
|
|
46
|
+
sendJson(res, 201, { status: routed ? "delivered" : "no-target", message });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// POST /api/v1/messages/broadcast
|
|
50
|
+
export async function handleBroadcastMessageRequest(deps: ControllerTaskDomainDeps, req: IncomingMessage, res: ServerResponse): Promise<void> {
|
|
51
|
+
const { logger, getTeamState, updateTeamState, messageRouter, wsServer } = deps;
|
|
52
|
+
const body = await parseJsonBody(req);
|
|
53
|
+
const fromRole = validateActiveRoleId(body.fromRole);
|
|
54
|
+
const message: TeamMessage = {
|
|
55
|
+
id: generateId(),
|
|
56
|
+
from: typeof body.from === "string" ? body.from : "",
|
|
57
|
+
fromRole,
|
|
58
|
+
type: "broadcast",
|
|
59
|
+
content: typeof body.content === "string" ? body.content : "",
|
|
60
|
+
contract: ensureTeamMessageContract(body.contract, {
|
|
61
|
+
type: "broadcast",
|
|
62
|
+
content: typeof body.content === "string" ? body.content : "",
|
|
63
|
+
taskId: typeof body.taskId === "string" ? body.taskId : undefined,
|
|
64
|
+
}),
|
|
65
|
+
taskId: typeof body.taskId === "string" ? body.taskId : undefined,
|
|
66
|
+
createdAt: Date.now(),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
updateTeamState((s) => { s.messages.push(message); });
|
|
70
|
+
|
|
71
|
+
const state = getTeamState()!;
|
|
72
|
+
const routed = messageRouter.routeBroadcast(message, state.workers);
|
|
73
|
+
for (const { worker, message: routedMsg } of routed) {
|
|
74
|
+
try {
|
|
75
|
+
await deliverMessageToWorker(worker, routedMsg, deps);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
logger.warn(`Controller: failed to broadcast to ${worker.id}: ${String(err)}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
wsServer.broadcastUpdate({ type: "message:new", data: message });
|
|
82
|
+
sendJson(res, 201, { status: "broadcast", recipients: routed.length });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// POST /api/v1/messages/review-request
|
|
86
|
+
export async function handleReviewRequestMessageRequest(deps: ControllerTaskDomainDeps, req: IncomingMessage, res: ServerResponse): Promise<void> {
|
|
87
|
+
const { logger, getTeamState, updateTeamState, messageRouter, wsServer } = deps;
|
|
88
|
+
const body = await parseJsonBody(req);
|
|
89
|
+
const fromRole = validateActiveRoleId(body.fromRole);
|
|
90
|
+
const toRole = validateActiveRoleId(body.toRole);
|
|
91
|
+
const message: TeamMessage = {
|
|
92
|
+
id: generateId(),
|
|
93
|
+
from: typeof body.from === "string" ? body.from : "",
|
|
94
|
+
fromRole,
|
|
95
|
+
toRole,
|
|
96
|
+
type: "review-request",
|
|
97
|
+
content: typeof body.content === "string" ? body.content : "",
|
|
98
|
+
contract: ensureTeamMessageContract(body.contract, {
|
|
99
|
+
type: "review-request",
|
|
100
|
+
content: typeof body.content === "string" ? body.content : "",
|
|
101
|
+
toRole,
|
|
102
|
+
taskId: typeof body.taskId === "string" ? body.taskId : undefined,
|
|
103
|
+
intent: "review-request",
|
|
104
|
+
needsResponse: true,
|
|
105
|
+
}),
|
|
106
|
+
taskId: typeof body.taskId === "string" ? body.taskId : undefined,
|
|
107
|
+
createdAt: Date.now(),
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
updateTeamState((s) => { s.messages.push(message); });
|
|
111
|
+
|
|
112
|
+
const state = getTeamState()!;
|
|
113
|
+
const routed = messageRouter.routeReviewRequest(message, state.workers);
|
|
114
|
+
if (routed) {
|
|
115
|
+
try {
|
|
116
|
+
await deliverMessageToWorker(routed.worker, routed.message, deps);
|
|
117
|
+
} catch (err) {
|
|
118
|
+
logger.warn(`Controller: failed to deliver review request: ${String(err)}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
wsServer.broadcastUpdate({ type: "message:new", data: message });
|
|
123
|
+
sendJson(res, 201, { status: routed ? "delivered" : "no-target", message });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// GET /api/v1/messages
|
|
127
|
+
export async function handleMessageListRequest(deps: ControllerTaskDomainDeps, res: ServerResponse, requestUrl: URL): Promise<void> {
|
|
128
|
+
const { getTeamState } = deps;
|
|
129
|
+
const state = getTeamState();
|
|
130
|
+
const messages = state?.messages ?? [];
|
|
131
|
+
const limit = parseInt(requestUrl.searchParams.get("limit") ?? "50", 10);
|
|
132
|
+
const offset = parseInt(requestUrl.searchParams.get("offset") ?? "0", 10);
|
|
133
|
+
sendJson(res, 200, {
|
|
134
|
+
messages: messages.slice(offset, offset + limit),
|
|
135
|
+
total: messages.length,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
@@ -1,44 +1,27 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
ClarificationQuestionOption,
|
|
3
|
-
ClarificationQuestionSchema,
|
|
4
2
|
ControllerManifestCompletionOpportunity,
|
|
5
3
|
ControllerManifestCreatedTask,
|
|
6
4
|
ControllerManifestDeferredTask,
|
|
7
5
|
ControllerOrchestrationManifest,
|
|
8
6
|
RoleId,
|
|
9
7
|
} from "../types.js";
|
|
8
|
+
import { validateRoleIdList } from "../roles.js";
|
|
10
9
|
import { deriveStableProjectKey } from "../openclaw-workspace.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"devops",
|
|
20
|
-
"security-engineer",
|
|
21
|
-
"designer",
|
|
22
|
-
"marketing",
|
|
23
|
-
"data-engineer",
|
|
24
|
-
]);
|
|
10
|
+
// Issue #226 W3: the clarification-schema normalization family moved to the
|
|
11
|
+
// shared layer (worker/tools.ts consumes it; the worker must not import the
|
|
12
|
+
// controller tree). This module keeps the manifest-specific normalizers and
|
|
13
|
+
// imports the shared contract — controller -> shared direction only.
|
|
14
|
+
import {
|
|
15
|
+
normalizeClarificationQuestionSchemas,
|
|
16
|
+
normalizeOptionalManifestText,
|
|
17
|
+
} from "../shared/clarification-schema.js";
|
|
25
18
|
|
|
26
19
|
export function normalizeManifestRoleList(raw: unknown): RoleId[] {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (typeof entry !== "string") {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
const normalized = entry.trim() as RoleId;
|
|
36
|
-
if (!normalized || !TEAMCLAW_ROLE_IDS.has(normalized) || roleIds.includes(normalized)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
roleIds.push(normalized);
|
|
40
|
-
}
|
|
41
|
-
return roleIds;
|
|
20
|
+
// Phase 0.3: delegates to the shared validateRoleIdList guard in roles.ts.
|
|
21
|
+
// The hand-written TEAMCLAW_ROLE_IDS copy this function used to keep was
|
|
22
|
+
// removed by Phase 1.2 (single-source-of-truth convergence); the role set
|
|
23
|
+
// now lives only in role-ids.ts / roles.ts.
|
|
24
|
+
return validateRoleIdList(raw);
|
|
42
25
|
}
|
|
43
26
|
|
|
44
27
|
export function normalizeManifestStringList(raw: unknown): string[] {
|
|
@@ -50,75 +33,6 @@ export function normalizeManifestStringList(raw: unknown): string[] {
|
|
|
50
33
|
.filter(Boolean);
|
|
51
34
|
}
|
|
52
35
|
|
|
53
|
-
export function normalizeOptionalManifestText(raw: unknown): string | undefined {
|
|
54
|
-
if (typeof raw !== "string") {
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
const normalized = raw.trim();
|
|
58
|
-
return normalized || undefined;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function normalizeClarificationOptions(raw: unknown): ClarificationQuestionOption[] {
|
|
62
|
-
if (!Array.isArray(raw)) {
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
return raw
|
|
66
|
-
.filter((entry): entry is Record<string, unknown> => !!entry && typeof entry === "object")
|
|
67
|
-
.map((entry) => ({
|
|
68
|
-
value: typeof entry.value === "string" ? entry.value.trim() : "",
|
|
69
|
-
label: typeof entry.label === "string" ? entry.label.trim() : "",
|
|
70
|
-
hint: typeof entry.hint === "string" && entry.hint.trim() ? entry.hint.trim() : undefined,
|
|
71
|
-
}))
|
|
72
|
-
.filter((entry) => entry.value && entry.label);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function normalizeClarificationQuestionSchema(raw: unknown): ClarificationQuestionSchema | undefined {
|
|
76
|
-
if (!raw || typeof raw !== "object") {
|
|
77
|
-
return undefined;
|
|
78
|
-
}
|
|
79
|
-
const input = raw as Record<string, unknown>;
|
|
80
|
-
const kind = typeof input.kind === "string" ? input.kind.trim() : "";
|
|
81
|
-
const title = typeof input.title === "string" ? input.title.trim() : "";
|
|
82
|
-
if (!title || !["single-select", "multi-select", "number", "text"].includes(kind)) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
const options = normalizeClarificationOptions(input.options);
|
|
86
|
-
const schema: ClarificationQuestionSchema = {
|
|
87
|
-
kind: kind as ClarificationQuestionSchema["kind"],
|
|
88
|
-
title,
|
|
89
|
-
description: normalizeOptionalManifestText(input.description),
|
|
90
|
-
required: input.required == null ? true : Boolean(input.required),
|
|
91
|
-
allowOther: Boolean(input.allowOther),
|
|
92
|
-
placeholder: normalizeOptionalManifestText(input.placeholder),
|
|
93
|
-
unit: normalizeOptionalManifestText(input.unit),
|
|
94
|
-
};
|
|
95
|
-
if (options.length > 0) {
|
|
96
|
-
schema.options = options;
|
|
97
|
-
}
|
|
98
|
-
if (typeof input.min === "number" && Number.isFinite(input.min)) {
|
|
99
|
-
schema.min = input.min;
|
|
100
|
-
}
|
|
101
|
-
if (typeof input.max === "number" && Number.isFinite(input.max)) {
|
|
102
|
-
schema.max = input.max;
|
|
103
|
-
}
|
|
104
|
-
if (typeof input.step === "number" && Number.isFinite(input.step)) {
|
|
105
|
-
schema.step = input.step;
|
|
106
|
-
}
|
|
107
|
-
if ((schema.kind === "single-select" || schema.kind === "multi-select") && (!schema.options || schema.options.length === 0)) {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
return schema;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function normalizeClarificationQuestionSchemas(raw: unknown): ClarificationQuestionSchema[] {
|
|
114
|
-
if (!Array.isArray(raw)) {
|
|
115
|
-
return [];
|
|
116
|
-
}
|
|
117
|
-
return raw
|
|
118
|
-
.map((entry) => normalizeClarificationQuestionSchema(entry))
|
|
119
|
-
.filter((entry): entry is ClarificationQuestionSchema => Boolean(entry));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
36
|
export function normalizeManifestCreatedTasks(raw: unknown): ControllerManifestCreatedTask[] {
|
|
123
37
|
if (!Array.isArray(raw)) {
|
|
124
38
|
return [];
|
|
@@ -13,6 +13,48 @@ const PREVIEW_STOP_TIMEOUT_MS = 5_000;
|
|
|
13
13
|
|
|
14
14
|
const GENERIC_SERVE_COMMAND = "npx -y serve -l {PORT}";
|
|
15
15
|
|
|
16
|
+
// Issue #237 W1: preview commands are LLM-authored (result contracts) and
|
|
17
|
+
// run through a shell - they must NOT inherit the controller's environment,
|
|
18
|
+
// or a prompt-injected previewCommand could exfiltrate every controller
|
|
19
|
+
// credential (GH_TOKEN, provider API keys, tunnel tokens). Policy: minimal
|
|
20
|
+
// allowlist of toolchain basics, matched case-insensitively so Windows
|
|
21
|
+
// (Path/SystemRoot/...) survives, plus the explicit preview vars set at the
|
|
22
|
+
// spawn site. Repos that genuinely need more can pass names through
|
|
23
|
+
// TEAMCLAW_PREVIEW_EXTRA_ENV (comma-separated list of env var names whose
|
|
24
|
+
// controller values are forwarded verbatim); anything else is absent.
|
|
25
|
+
const PREVIEW_ENV_ALLOWLIST = new Set([
|
|
26
|
+
"PATH", "HOME", "LANG", "LC_ALL", "LC_CTYPE", "TMPDIR", "TZ", "TERM", "SHELL",
|
|
27
|
+
// Windows toolchain basics (no-ops elsewhere, harmless to match).
|
|
28
|
+
// PROCESSOR_ARCHITECTURE/PROCESSOR_IDENTIFIER are read by node-gyp-style
|
|
29
|
+
// native builds (review follow-up to #237 W1) - plain toolchain
|
|
30
|
+
// descriptors, no credential material.
|
|
31
|
+
"SYSTEMROOT", "SYSTEMDRIVE", "COMSPEC", "PATHEXT", "WINDIR", "USERPROFILE",
|
|
32
|
+
"APPDATA", "LOCALAPPDATA", "PROGRAMFILES", "PROGRAMDATA", "NUMBER_OF_PROCESSORS", "OS",
|
|
33
|
+
"PROCESSOR_ARCHITECTURE", "PROCESSOR_IDENTIFIER",
|
|
34
|
+
]);
|
|
35
|
+
const PREVIEW_EXTRA_ENV_VAR = "TEAMCLAW_PREVIEW_EXTRA_ENV";
|
|
36
|
+
|
|
37
|
+
/** Builds the restricted environment for preview subprocesses (#237 W1):
|
|
38
|
+
* allowlisted controller vars + extraEnv (venv PATH/VIRTUAL_ENV) + whatever
|
|
39
|
+
* the operator declared via TEAMCLAW_PREVIEW_EXTRA_ENV. Never returns the
|
|
40
|
+
* full process.env. Exported for the #237 regression test. */
|
|
41
|
+
export function buildPreviewEnv(extraEnv: Record<string, string>): NodeJS.ProcessEnv {
|
|
42
|
+
const allow = new Set(PREVIEW_ENV_ALLOWLIST);
|
|
43
|
+
for (const name of (process.env[PREVIEW_EXTRA_ENV_VAR] ?? "").split(",")) {
|
|
44
|
+
const normalized = name.trim().toUpperCase();
|
|
45
|
+
if (normalized) {
|
|
46
|
+
allow.add(normalized);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const env: Record<string, string> = {};
|
|
50
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
51
|
+
if (value !== undefined && allow.has(key.toUpperCase())) {
|
|
52
|
+
env[key] = value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { ...env, ...extraEnv };
|
|
56
|
+
}
|
|
57
|
+
|
|
16
58
|
/**
|
|
17
59
|
* Detect the tech stack from files in `cwd` and return a suitable preview command.
|
|
18
60
|
* Only overrides `existingCommand` when it is the generic static file server
|
|
@@ -456,7 +498,10 @@ export class PreviewManager {
|
|
|
456
498
|
const pipInstall = spawnManagedCommandProcess({
|
|
457
499
|
command: `${pipBin} install -q -r requirements.txt`,
|
|
458
500
|
cwd,
|
|
459
|
-
|
|
501
|
+
// #237 W1: requirements.txt is worker-influenced and pip executes
|
|
502
|
+
// setup.py at install time, so this subprocess gets the same
|
|
503
|
+
// restricted env as the preview command itself.
|
|
504
|
+
env: buildPreviewEnv(extraEnv),
|
|
460
505
|
});
|
|
461
506
|
await new Promise<void>((resolve) => {
|
|
462
507
|
pipInstall.on("exit", () => resolve());
|
|
@@ -470,10 +515,15 @@ export class PreviewManager {
|
|
|
470
515
|
|
|
471
516
|
const child = spawnManagedCommandProcess({
|
|
472
517
|
command: resolvedCommand,
|
|
518
|
+
// cwd is already forced inside the workspace (resolveWorkspaceDirectory
|
|
519
|
+
// confinement above), so the shell cannot escape the deliverable dir.
|
|
473
520
|
cwd,
|
|
521
|
+
// #237 W1: restricted allowlist env - never the controller's full
|
|
522
|
+
// process.env (credential exfiltration via prompt-injected
|
|
523
|
+
// previewCommand). HOST/PORT/TEAMCLAW_PREVIEW_* are the explicit
|
|
524
|
+
// preview contract vars.
|
|
474
525
|
env: {
|
|
475
|
-
...
|
|
476
|
-
...extraEnv,
|
|
526
|
+
...buildPreviewEnv(extraEnv),
|
|
477
527
|
HOST: "0.0.0.0",
|
|
478
528
|
PORT: String(record.targetPort),
|
|
479
529
|
TEAMCLAW_PREVIEW_BASE_PATH: record.liveUrl.replace(/\/$/u, ""),
|