@teamclaws/teamclaw 2026.8.1 → 2026.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.mjs +46 -15
- package/dist/src/config.js +33 -2
- 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 +813 -0
- package/dist/src/controller/controller-runs.js +175 -0
- package/dist/src/controller/controller-service.js +271 -40
- package/dist/src/controller/controller-tools.js +11 -6
- package/dist/src/controller/http-server.js +256 -6004
- package/dist/src/controller/kickoff-orchestrator.js +32 -6
- package/dist/src/controller/message-delivery.js +28 -0
- package/dist/src/controller/message-routes.js +114 -0
- package/dist/src/controller/orchestration-manifest.js +6 -28
- package/dist/src/controller/preview-proxy.js +98 -0
- package/dist/src/controller/profile-switch.js +289 -0
- package/dist/src/controller/project-registry.js +294 -0
- package/dist/src/controller/prompt-injector.js +19 -9
- package/dist/src/controller/repo-routes.js +63 -0
- package/dist/src/controller/role-inference.js +231 -20
- package/dist/src/controller/route-table.js +1353 -0
- package/dist/src/controller/task-assignment.js +508 -0
- package/dist/src/controller/task-cleanup.js +258 -0
- package/dist/src/controller/task-execution.js +240 -0
- package/dist/src/controller/task-results.js +461 -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/ui-assets.js +68 -0
- package/dist/src/controller/worker-provisioning.js +30 -4
- package/dist/src/controller/worker-routes.js +188 -0
- package/dist/src/identity.js +3 -2
- package/dist/src/interaction-contracts.js +7 -7
- package/dist/src/openclaw-workspace.js +40 -18
- package/dist/src/profile-loader.js +486 -0
- package/dist/src/profiles/banking.json +178 -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 +201 -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 +26 -13
- 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/state.js +188 -10
- 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 +62 -15
- package/dist/src/ui/app.js +592 -24
- package/dist/src/ui/index.html +44 -11
- package/dist/src/ui/style.css +194 -0
- package/dist/src/worker/prompt-injector.js +44 -8
- package/dist/src/worker/skill-installer.js +3 -1
- package/dist/src/worker/worker-service.js +76 -3
- package/openclaw.plugin.json +28 -1
- package/package.json +3 -2
- package/src/config.ts +33 -2
- package/src/controller/clarification-routes.ts +404 -0
- package/src/controller/controller-intake.ts +1113 -0
- package/src/controller/controller-planning.ts +1029 -0
- package/src/controller/controller-runs.ts +239 -0
- package/src/controller/controller-service.ts +295 -41
- package/src/controller/controller-tools.ts +11 -7
- package/src/controller/http-server.ts +294 -6971
- package/src/controller/kickoff-orchestrator.ts +70 -7
- package/src/controller/message-delivery.ts +49 -0
- package/src/controller/message-routes.ts +137 -0
- package/src/controller/orchestration-manifest.ts +6 -29
- package/src/controller/preview-proxy.ts +127 -0
- package/src/controller/profile-switch.ts +366 -0
- package/src/controller/project-registry.ts +361 -0
- package/src/controller/prompt-injector.ts +23 -8
- package/src/controller/repo-routes.ts +91 -0
- package/src/controller/role-inference.ts +260 -22
- package/src/controller/route-table.ts +1616 -0
- package/src/controller/task-assignment.ts +618 -0
- package/src/controller/task-cleanup.ts +344 -0
- package/src/controller/task-execution.ts +356 -0
- package/src/controller/task-results.ts +544 -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/ui-assets.ts +70 -0
- package/src/controller/websocket.ts +13 -1
- package/src/controller/worker-provisioning.ts +32 -4
- package/src/controller/worker-routes.ts +241 -0
- package/src/identity.ts +3 -2
- package/src/interaction-contracts.ts +7 -7
- package/src/openclaw-workspace.ts +44 -18
- package/src/profile-loader.ts +650 -0
- package/src/profiles/banking.json +178 -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 +201 -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 +27 -13
- package/src/role-ids.ts +31 -0
- package/src/roles.ts +60 -14
- package/src/session-roles.ts +14 -0
- package/src/state.ts +236 -9
- package/src/task-executor.ts +7 -18
- package/src/teamauto/github-client.ts +21 -0
- package/src/teamauto/repo-sync.ts +246 -6
- package/src/teamauto/scanner.ts +47 -13
- package/src/teamauto/scheduler.ts +259 -16
- package/src/teamauto/store.ts +12 -0
- package/src/types.ts +133 -16
- package/src/ui/app.js +592 -24
- package/src/ui/index.html +44 -11
- package/src/ui/style.css +194 -0
- package/src/worker/prompt-injector.ts +48 -8
- package/src/worker/skill-installer.ts +3 -1
- package/src/worker/worker-service.ts +83 -3
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { generateId } from "../protocol.js";
|
|
2
|
+
import { deriveProjectSlug } from "../openclaw-workspace.js";
|
|
3
|
+
import { buildTaskExecutionSummary, MAX_TASK_EXECUTION_EVENTS } from "./task-execution.js";
|
|
4
|
+
import { extractExplicitProjectNameHint, resolveExistingProjectIdentityFromMessage, resolveProjectIdentityForSession, resolveProjectIdentityForTaskId, syncProjectRegistryEntry, } from "./project-registry.js";
|
|
5
|
+
const MAX_CONTROLLER_RUNS = 40;
|
|
6
|
+
export function ensureControllerRunExecution(run) {
|
|
7
|
+
if (!run.execution) {
|
|
8
|
+
run.execution = {
|
|
9
|
+
status: run.status,
|
|
10
|
+
runId: run.runId,
|
|
11
|
+
startedAt: run.startedAt,
|
|
12
|
+
endedAt: run.completedAt,
|
|
13
|
+
lastUpdatedAt: run.updatedAt,
|
|
14
|
+
events: [],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (!Array.isArray(run.execution.events)) {
|
|
18
|
+
run.execution.events = [];
|
|
19
|
+
}
|
|
20
|
+
run.execution.status = run.status;
|
|
21
|
+
run.execution.runId = run.runId ?? run.execution.runId;
|
|
22
|
+
run.execution.startedAt = run.startedAt ?? run.execution.startedAt;
|
|
23
|
+
run.execution.endedAt = run.completedAt ?? run.execution.endedAt;
|
|
24
|
+
run.execution.lastUpdatedAt = run.updatedAt ?? run.execution.lastUpdatedAt;
|
|
25
|
+
return run.execution;
|
|
26
|
+
}
|
|
27
|
+
export function appendControllerRunEvent(run, input) {
|
|
28
|
+
const now = input.createdAt ?? Date.now();
|
|
29
|
+
const execution = ensureControllerRunExecution(run);
|
|
30
|
+
if (input.runId) {
|
|
31
|
+
run.runId = input.runId;
|
|
32
|
+
execution.runId = input.runId;
|
|
33
|
+
}
|
|
34
|
+
if (input.sessionKey) {
|
|
35
|
+
execution.sessionKey = input.sessionKey;
|
|
36
|
+
}
|
|
37
|
+
if (input.status) {
|
|
38
|
+
run.status = input.status;
|
|
39
|
+
execution.status = input.status;
|
|
40
|
+
}
|
|
41
|
+
if ((input.status === "running" || input.phase === "run_started") && !run.startedAt) {
|
|
42
|
+
run.startedAt = now;
|
|
43
|
+
execution.startedAt = now;
|
|
44
|
+
}
|
|
45
|
+
if (run.status === "completed" || run.status === "failed") {
|
|
46
|
+
run.completedAt = run.completedAt ?? now;
|
|
47
|
+
execution.endedAt = execution.endedAt ?? now;
|
|
48
|
+
}
|
|
49
|
+
run.updatedAt = now;
|
|
50
|
+
execution.lastUpdatedAt = now;
|
|
51
|
+
const event = {
|
|
52
|
+
id: generateId(),
|
|
53
|
+
type: input.type,
|
|
54
|
+
createdAt: now,
|
|
55
|
+
message: input.message,
|
|
56
|
+
phase: input.phase,
|
|
57
|
+
source: input.source,
|
|
58
|
+
stream: input.stream,
|
|
59
|
+
};
|
|
60
|
+
execution.events.push(event);
|
|
61
|
+
if (execution.events.length > MAX_TASK_EXECUTION_EVENTS) {
|
|
62
|
+
execution.events = execution.events.slice(-MAX_TASK_EXECUTION_EVENTS);
|
|
63
|
+
}
|
|
64
|
+
return event;
|
|
65
|
+
}
|
|
66
|
+
export function trimControllerRuns(state) {
|
|
67
|
+
const runs = Object.values(state.controllerRuns)
|
|
68
|
+
.sort((left, right) => left.updatedAt - right.updatedAt);
|
|
69
|
+
if (runs.length <= MAX_CONTROLLER_RUNS) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
for (const run of runs.slice(0, runs.length - MAX_CONTROLLER_RUNS)) {
|
|
73
|
+
delete state.controllerRuns[run.id];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export function serializeControllerRun(run, includeExecutionEvents = true) {
|
|
77
|
+
if (!run) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
const payload = { ...run };
|
|
81
|
+
if (!run.execution) {
|
|
82
|
+
return payload;
|
|
83
|
+
}
|
|
84
|
+
payload.execution = includeExecutionEvents
|
|
85
|
+
? {
|
|
86
|
+
status: run.execution.status,
|
|
87
|
+
runId: run.execution.runId,
|
|
88
|
+
startedAt: run.execution.startedAt,
|
|
89
|
+
endedAt: run.execution.endedAt,
|
|
90
|
+
lastUpdatedAt: run.execution.lastUpdatedAt,
|
|
91
|
+
events: run.execution.events.map((event) => ({ ...event })),
|
|
92
|
+
}
|
|
93
|
+
: buildTaskExecutionSummary(run.execution);
|
|
94
|
+
return payload;
|
|
95
|
+
}
|
|
96
|
+
export function buildControllerRunTitle(message, source, sourceTaskTitle) {
|
|
97
|
+
if (source === "task_follow_up") {
|
|
98
|
+
const normalizedSourceTitle = String(sourceTaskTitle || "").replace(/\s+/g, " ").trim();
|
|
99
|
+
if (normalizedSourceTitle) {
|
|
100
|
+
const compactSourceTitle = normalizedSourceTitle.length <= 72
|
|
101
|
+
? normalizedSourceTitle
|
|
102
|
+
: `${normalizedSourceTitle.slice(0, 72).trimEnd()}…`;
|
|
103
|
+
return `Controller follow-up after ${compactSourceTitle}`;
|
|
104
|
+
}
|
|
105
|
+
return "Controller workflow follow-up";
|
|
106
|
+
}
|
|
107
|
+
const normalized = message.replace(/\s+/g, " ").trim();
|
|
108
|
+
if (!normalized) {
|
|
109
|
+
return "Controller intake";
|
|
110
|
+
}
|
|
111
|
+
if (normalized.length <= 100) {
|
|
112
|
+
return normalized;
|
|
113
|
+
}
|
|
114
|
+
return `${normalized.slice(0, 100).trimEnd()}…`;
|
|
115
|
+
}
|
|
116
|
+
export function createControllerRun(message, sessionKey, deps, options) {
|
|
117
|
+
const now = Date.now();
|
|
118
|
+
const existingState = deps.getTeamState();
|
|
119
|
+
const inheritedProject = options?.sourceTaskId
|
|
120
|
+
? resolveProjectIdentityForTaskId(options.sourceTaskId, existingState)
|
|
121
|
+
: resolveProjectIdentityForSession(sessionKey, existingState)
|
|
122
|
+
?? resolveExistingProjectIdentityFromMessage(message, existingState);
|
|
123
|
+
const explicitProjectId = extractExplicitProjectNameHint(message);
|
|
124
|
+
const projectId = inheritedProject?.projectId ?? explicitProjectId;
|
|
125
|
+
const projectDir = inheritedProject?.projectDir ?? projectId ?? deriveProjectSlug(message);
|
|
126
|
+
const run = {
|
|
127
|
+
id: generateId(),
|
|
128
|
+
title: buildControllerRunTitle(message, options?.source ?? "human", options?.sourceTaskTitle),
|
|
129
|
+
sessionKey,
|
|
130
|
+
projectId: projectId || undefined,
|
|
131
|
+
projectDir,
|
|
132
|
+
source: options?.source ?? "human",
|
|
133
|
+
sourceTaskId: options?.sourceTaskId,
|
|
134
|
+
sourceTaskTitle: options?.sourceTaskTitle,
|
|
135
|
+
request: message,
|
|
136
|
+
createdTaskIds: [],
|
|
137
|
+
status: "pending",
|
|
138
|
+
createdAt: now,
|
|
139
|
+
updatedAt: now,
|
|
140
|
+
};
|
|
141
|
+
const state = deps.updateTeamState((teamState) => {
|
|
142
|
+
syncProjectRegistryEntry(teamState, {
|
|
143
|
+
projectId: run.projectId,
|
|
144
|
+
projectDir: run.projectDir,
|
|
145
|
+
aliases: [run.projectId, extractExplicitProjectNameHint(message)],
|
|
146
|
+
summary: run.title,
|
|
147
|
+
updatedAt: now,
|
|
148
|
+
});
|
|
149
|
+
teamState.controllerRuns[run.id] = run;
|
|
150
|
+
trimControllerRuns(teamState);
|
|
151
|
+
});
|
|
152
|
+
const createdRun = state.controllerRuns[run.id] ?? run;
|
|
153
|
+
deps.wsServer.broadcastUpdate({ type: "controller:run", data: serializeControllerRun(createdRun) });
|
|
154
|
+
return createdRun;
|
|
155
|
+
}
|
|
156
|
+
export function updateControllerRun(runId, deps, updater) {
|
|
157
|
+
const state = deps.updateTeamState((teamState) => {
|
|
158
|
+
const run = teamState.controllerRuns[runId];
|
|
159
|
+
if (!run) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
updater(run);
|
|
163
|
+
trimControllerRuns(teamState);
|
|
164
|
+
});
|
|
165
|
+
const updatedRun = state.controllerRuns[runId];
|
|
166
|
+
if (updatedRun) {
|
|
167
|
+
deps.wsServer.broadcastUpdate({ type: "controller:run", data: serializeControllerRun(updatedRun) });
|
|
168
|
+
}
|
|
169
|
+
return updatedRun;
|
|
170
|
+
}
|
|
171
|
+
export function recordControllerRunEvent(runId, input, deps) {
|
|
172
|
+
return updateControllerRun(runId, deps, (run) => {
|
|
173
|
+
appendControllerRunEvent(run, input);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
@@ -3,11 +3,17 @@ import { exec } from "node:child_process";
|
|
|
3
3
|
import { loadTeamState, saveTeamState } from "../state.js";
|
|
4
4
|
import { MDnsAdvertiser } from "../discovery.js";
|
|
5
5
|
import { WORKER_TIMEOUT_MS } from "../protocol.js";
|
|
6
|
-
import { createControllerHttpServer
|
|
6
|
+
import { createControllerHttpServer } from "./http-server.js";
|
|
7
|
+
// PR-C of issue #204: the assignment pipeline incl. the gated auto-assign
|
|
8
|
+
// loop lives in ./task-assignment.js, not http-server.ts.
|
|
9
|
+
import { autoAssignPendingTasks } from "./task-assignment.js";
|
|
10
|
+
// PR-A of issue #204: the profile switch state machine (incl. crash resume)
|
|
11
|
+
// lives in ./profile-switch.ts, not http-server.ts.
|
|
12
|
+
import { resumeTeamProfileSwitch } from "./profile-switch.js";
|
|
7
13
|
import { TaskRouter } from "./task-router.js";
|
|
8
14
|
import { MessageRouter } from "./message-router.js";
|
|
9
15
|
import { TeamWebSocketServer } from "./websocket.js";
|
|
10
|
-
import { ensureOpenClawWorkspaceMemoryDir } from "../openclaw-workspace.js";
|
|
16
|
+
import { ensureOpenClawWorkspaceMemoryDir, buildTeamClawAgentSessionKey } from "../openclaw-workspace.js";
|
|
11
17
|
import { ensureControllerGitRepo } from "../git-collaboration.js";
|
|
12
18
|
import { WorkerProvisioningManager } from "./worker-provisioning.js";
|
|
13
19
|
import { PreviewManager } from "./preview-manager.js";
|
|
@@ -15,6 +21,9 @@ import { runKickoffMeeting, buildKickoffAssessmentPrompt, ASSESSMENT_TIMEOUT_MS
|
|
|
15
21
|
import { resolvePreferredLanAddress } from "../networking.js";
|
|
16
22
|
import { createTeamAutoScheduler } from "../teamauto/scheduler.js";
|
|
17
23
|
import { getGithubAuthManager } from "./github-auth.js";
|
|
24
|
+
// Phase 1.6 (design 2.3): TeamState.profileId is the single runtime truth for
|
|
25
|
+
// the active TeamProfile; config teamProfile only seeds first initialization.
|
|
26
|
+
import { getActiveProfile, getActiveRoleIds, hasProfile, setActiveProfileId, validateActiveRoleId, SOFTWARE_RD_PROFILE_ID } from "../profile-loader.js";
|
|
18
27
|
function getPreferredLanUiUrl(port) {
|
|
19
28
|
const preferredLanAddress = resolvePreferredLanAddress();
|
|
20
29
|
if (!preferredLanAddress) {
|
|
@@ -38,15 +47,53 @@ export function createControllerService(deps) {
|
|
|
38
47
|
async start(_ctx) {
|
|
39
48
|
const serviceStartedAt = Date.now();
|
|
40
49
|
await ensureOpenClawWorkspaceMemoryDir(logger);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// Load or create team state
|
|
50
|
+
// Load or create team state. The active profile is resolved FIRST (from
|
|
51
|
+
// the restored TeamState.profileId, or the config bootstrap value on
|
|
52
|
+
// first initialization) so that capability-dependent startup wiring
|
|
53
|
+
// below knows which profile it is initializing (Phase 2.3 preview).
|
|
46
54
|
teamState = await loadTeamState(config.teamName);
|
|
55
|
+
let seededProfileId;
|
|
56
|
+
if (!teamState) {
|
|
57
|
+
// Phase 1.6: first initialization seeds the active profile from the
|
|
58
|
+
// config bootstrap value. An unknown id is the one sanctioned
|
|
59
|
+
// fallback (design 2.2): warn and run the software-rd baseline.
|
|
60
|
+
const requestedProfileId = config.teamProfile;
|
|
61
|
+
seededProfileId = requestedProfileId;
|
|
62
|
+
if (!hasProfile(requestedProfileId)) {
|
|
63
|
+
seededProfileId = SOFTWARE_RD_PROFILE_ID;
|
|
64
|
+
logger.warn(`Controller: configured teamProfile "${requestedProfileId}" is not a built-in profile; falling back to "${SOFTWARE_RD_PROFILE_ID}"`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// Restored state: TeamState.profileId is the runtime truth (config
|
|
69
|
+
// changes do not re-seed it). A dangling reference means the profile
|
|
70
|
+
// package this team ran on is not available in this installation.
|
|
71
|
+
// Design 2.2 red line: FATAL, never silently run another profile -
|
|
72
|
+
// that is exactly how a banking team would degrade into the software
|
|
73
|
+
// baseline unnoticed. (The config-miss fallback above stays a warn:
|
|
74
|
+
// it only seeds first initialization, where no team exists yet.)
|
|
75
|
+
if (!hasProfile(teamState.profileId)) {
|
|
76
|
+
throw new Error(`Controller: team state references team profile "${teamState.profileId}", which is not available in this installation. `
|
|
77
|
+
+ "Check the teamProfile config value and the persisted state profileId, or reinstall a TeamClaw version that ships this profile.");
|
|
78
|
+
}
|
|
79
|
+
seededProfileId = teamState.profileId;
|
|
80
|
+
}
|
|
81
|
+
setActiveProfileId(seededProfileId);
|
|
82
|
+
const activeCapabilities = getActiveProfile().capabilities;
|
|
83
|
+
// Phase 2.3 preview (minimal capability wiring, design 2.1): the git
|
|
84
|
+
// collaboration repo is only prepared for profiles with git enabled -
|
|
85
|
+
// a document-delivery team has no repo concept. On the software-rd
|
|
86
|
+
// baseline (git: true) behavior is unchanged.
|
|
87
|
+
const repoState = activeCapabilities.git
|
|
88
|
+
? await ensureControllerGitRepo(config, logger).catch((err) => {
|
|
89
|
+
logger.warn(`Controller: failed to prepare git collaboration repo: ${err instanceof Error ? err.message : String(err)}`);
|
|
90
|
+
return null;
|
|
91
|
+
})
|
|
92
|
+
: null;
|
|
47
93
|
let repoStateChanged = false;
|
|
48
94
|
if (!teamState) {
|
|
49
95
|
teamState = {
|
|
96
|
+
profileId: seededProfileId,
|
|
50
97
|
teamName: config.teamName,
|
|
51
98
|
workers: {},
|
|
52
99
|
tasks: {},
|
|
@@ -59,11 +106,11 @@ export function createControllerService(deps) {
|
|
|
59
106
|
updatedAt: Date.now(),
|
|
60
107
|
};
|
|
61
108
|
await saveTeamState(teamState);
|
|
62
|
-
logger.info(`Controller: created new team "${config.teamName}"`);
|
|
109
|
+
logger.info(`Controller: created new team "${config.teamName}" (profile: ${seededProfileId})`);
|
|
63
110
|
}
|
|
64
111
|
else {
|
|
65
112
|
const previousRepoState = JSON.stringify(teamState.repo ?? null);
|
|
66
|
-
teamState.repo = repoState ?? teamState.repo;
|
|
113
|
+
teamState.repo = repoState ?? (activeCapabilities.git ? teamState.repo : undefined);
|
|
67
114
|
repoStateChanged = JSON.stringify(teamState.repo ?? null) !== previousRepoState;
|
|
68
115
|
logger.info(`Controller: restored team "${config.teamName}" with ${Object.keys(teamState.workers).length} workers`);
|
|
69
116
|
}
|
|
@@ -148,7 +195,18 @@ export function createControllerService(deps) {
|
|
|
148
195
|
}
|
|
149
196
|
}
|
|
150
197
|
mdnsAdvertiser = new MDnsAdvertiser(logger);
|
|
151
|
-
|
|
198
|
+
// Phase 2.5 wiring (design 2.3 "LLM 兜底", P2.5 follow-up): the
|
|
199
|
+
// controller LLM session is the production role judge for tasks the
|
|
200
|
+
// bilingual token fast path refuses to decide (tie / all-zero). The
|
|
201
|
+
// judge runs on a dedicated one-shot subagent session - NOT the intake
|
|
202
|
+
// conversation - so verdicts never pollute intake semantics. Missing
|
|
203
|
+
// runtime subagent => no judge, and the TaskRouter keeps its exact
|
|
204
|
+
// pre-wiring behavior.
|
|
205
|
+
const llmRoleJudge = createControllerLlmRoleJudge(deps);
|
|
206
|
+
if (llmRoleJudge) {
|
|
207
|
+
logger.info("Controller: LLM role judge wired into task dispatch (unconfident role inference escalates to the controller LLM)");
|
|
208
|
+
}
|
|
209
|
+
taskRouter = new TaskRouter(logger, llmRoleJudge ? { llmRoleJudge } : undefined);
|
|
152
210
|
messageRouter = new MessageRouter(logger);
|
|
153
211
|
wsServer = new TeamWebSocketServer(logger);
|
|
154
212
|
// When running inside a container (Docker or K8s), bind to 0.0.0.0
|
|
@@ -160,7 +218,7 @@ export function createControllerService(deps) {
|
|
|
160
218
|
const listenPort = config.port;
|
|
161
219
|
const listenHost = isContainer ? "0.0.0.0" : "127.0.0.1";
|
|
162
220
|
let serviceKickoffHandler;
|
|
163
|
-
const
|
|
221
|
+
const httpDeps = {
|
|
164
222
|
config,
|
|
165
223
|
logger,
|
|
166
224
|
runtime: deps.runtime,
|
|
@@ -173,7 +231,8 @@ export function createControllerService(deps) {
|
|
|
173
231
|
previewManager,
|
|
174
232
|
getKickoffHandler: () => serviceKickoffHandler,
|
|
175
233
|
getTeamAutoScheduler: () => teamAutoSchedulerRef,
|
|
176
|
-
}
|
|
234
|
+
};
|
|
235
|
+
const server = createControllerHttpServer(httpDeps);
|
|
177
236
|
const PORT_RETRY_STEP = 10;
|
|
178
237
|
const PORT_MAX_RETRIES = 10;
|
|
179
238
|
let actualPort = 0;
|
|
@@ -215,30 +274,55 @@ export function createControllerService(deps) {
|
|
|
215
274
|
if (workerProvisioningManager.isEnabled()) {
|
|
216
275
|
workerProvisioningManager.setActualPort(actualPort);
|
|
217
276
|
}
|
|
277
|
+
// Phase 2.1 (design 2.3 crash semantics): resume an interrupted team
|
|
278
|
+
// profile switch before TeamAuto/preview restoration/provisioning kick
|
|
279
|
+
// in, so no subsystem fights the resume. Runs after the port is known
|
|
280
|
+
// (switch warmup launches need the actual controller URL). Requests
|
|
281
|
+
// arriving mid-resume hit the transition concurrency matrix (409/503),
|
|
282
|
+
// which is exactly what it exists for. An unavailable target profile is
|
|
283
|
+
// fatal here - same red line as restoring an unknown profileId.
|
|
284
|
+
await resumeTeamProfileSwitch(httpDeps);
|
|
218
285
|
// TeamAuto: autonomous repo collaboration (bind repos via /api/v1/teamauto/*).
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
logger
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
286
|
+
// Phase 2.3 preview (minimal capability wiring): a profile with
|
|
287
|
+
// teamauto disabled never starts the scheduler at all.
|
|
288
|
+
if (getActiveProfile().capabilities.teamauto) {
|
|
289
|
+
try {
|
|
290
|
+
const auth = getGithubAuthManager(config, logger);
|
|
291
|
+
teamAutoSchedulerRef = createTeamAutoScheduler({
|
|
292
|
+
logger,
|
|
293
|
+
auth,
|
|
294
|
+
getTeamState: () => teamState,
|
|
295
|
+
updateTeamState: updateState,
|
|
296
|
+
onTasksCreated: async () => {
|
|
297
|
+
// Same deps object as every HTTP call site (issue #191 gate
|
|
298
|
+
// review): the autoAssign re-entrancy gate is keyed per deps
|
|
299
|
+
// object, so an ad-hoc object here would open a SECOND gate -
|
|
300
|
+
// a TeamAuto round and an HTTP round could then run concurrently
|
|
301
|
+
// with separate attemptedPairs sets (double dispatch attempts,
|
|
302
|
+
// same-task double LLM-judge window). The ad-hoc object also
|
|
303
|
+
// silently dropped workerProvisioningManager/getTeamAutoScheduler
|
|
304
|
+
// for these rounds (no reconcile nudge; teamauto write tasks
|
|
305
|
+
// dispatched from this path fell back to the shared checkout
|
|
306
|
+
// instead of a task-scoped worktree). It was a leftover from
|
|
307
|
+
// before the shared httpDeps existed, not a deliberate split.
|
|
308
|
+
await autoAssignPendingTasks(httpDeps);
|
|
309
|
+
},
|
|
310
|
+
onActivity: (entry) => {
|
|
311
|
+
wsServer.broadcastUpdate({
|
|
312
|
+
type: "teamauto:activity",
|
|
313
|
+
data: { at: entry.at, repoId: entry.repoId, kind: entry.kind, text: entry.text },
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
await teamAutoSchedulerRef.start();
|
|
318
|
+
deps.onTeamAutoSchedulerAvailable?.(() => teamAutoSchedulerRef);
|
|
319
|
+
}
|
|
320
|
+
catch (err) {
|
|
321
|
+
logger.warn(`Controller: TeamAuto scheduler failed to start: ${err instanceof Error ? err.message : String(err)}`);
|
|
322
|
+
}
|
|
239
323
|
}
|
|
240
|
-
|
|
241
|
-
logger.
|
|
324
|
+
else {
|
|
325
|
+
logger.info("Controller: TeamAuto scheduler skipped (capability disabled by the active team profile)");
|
|
242
326
|
}
|
|
243
327
|
// Start mDNS advertising with the actual port
|
|
244
328
|
await mdnsAdvertiser.start(actualPort, config.teamName);
|
|
@@ -263,12 +347,16 @@ export function createControllerService(deps) {
|
|
|
263
347
|
};
|
|
264
348
|
serviceKickoffHandler = kickoffHandler;
|
|
265
349
|
deps.onKickoffHandlerAvailable?.(kickoffHandler);
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
350
|
+
// Phase 2.3 preview (minimal capability wiring): only profiles with
|
|
351
|
+
// runnablePreview enabled restore dynamic previews on startup.
|
|
352
|
+
if (getActiveProfile().capabilities.runnablePreview) {
|
|
353
|
+
logger.info(`Controller: starting preview restoration...`);
|
|
354
|
+
void previewManager.restorePreviewsOnStartup().then(() => {
|
|
355
|
+
logger.info(`Controller: preview restoration completed`);
|
|
356
|
+
}).catch((err) => {
|
|
357
|
+
logger.warn(`Controller: failed to restore previews on startup: ${String(err)}`);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
272
360
|
// Start timeout monitoring
|
|
273
361
|
timeoutTimer = setInterval(() => {
|
|
274
362
|
if (!teamState)
|
|
@@ -318,6 +406,46 @@ export function createControllerService(deps) {
|
|
|
318
406
|
if (changed) {
|
|
319
407
|
saveTeamState(teamState);
|
|
320
408
|
}
|
|
409
|
+
// Runtime orphan-task reconciliation (user-found: one live worker but
|
|
410
|
+
// two active tasks - the second task was pinned to a worker whose
|
|
411
|
+
// registry entry was already gone). The startup sweep handles this
|
|
412
|
+
// once at boot; tasks whose worker disappears AFTER claiming sat in
|
|
413
|
+
// in_progress forever. Mirror the startup semantics: reset to pending
|
|
414
|
+
// (bounded resume attempts), re-dispatch happens via the reconcile
|
|
415
|
+
// call below. Skip workers the sweep above just released - their
|
|
416
|
+
// tasks were already handled with a broadcast.
|
|
417
|
+
{
|
|
418
|
+
let orphaned = false;
|
|
419
|
+
for (const task of Object.values(teamState.tasks)) {
|
|
420
|
+
if (task.assignedWorkerId &&
|
|
421
|
+
(task.status === "assigned" || task.status === "in_progress") &&
|
|
422
|
+
!teamState.workers[task.assignedWorkerId]) {
|
|
423
|
+
const attempt = (task.resumeAttempt ?? 0) + 1;
|
|
424
|
+
const MAX_RESUME_ATTEMPTS = 3;
|
|
425
|
+
if (attempt > MAX_RESUME_ATTEMPTS) {
|
|
426
|
+
logger.warn(`Controller: task ${task.id} exceeded ${MAX_RESUME_ATTEMPTS} resume attempts (worker gone) - failing`);
|
|
427
|
+
task.status = "failed";
|
|
428
|
+
task.error = `worker disappeared without completing (resumed ${MAX_RESUME_ATTEMPTS} times)`;
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
logger.info(`Controller: resetting orphaned task ${task.id} for resume attempt ${attempt} (worker ${task.assignedWorkerId} missing)`);
|
|
432
|
+
task.status = "pending";
|
|
433
|
+
task.resumeAttempt = attempt;
|
|
434
|
+
if (task.checkpoint) {
|
|
435
|
+
task.checkpoint.attempt = attempt;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
task.assignedWorkerId = undefined;
|
|
439
|
+
task.updatedAt = now;
|
|
440
|
+
wsServer.broadcastUpdate({ type: "task:updated", data: { ...task } });
|
|
441
|
+
orphaned = true;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (orphaned) {
|
|
445
|
+
saveTeamState(teamState);
|
|
446
|
+
changed = true;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
321
449
|
if (workerProvisioningManager?.isEnabled()) {
|
|
322
450
|
void workerProvisioningManager.requestReconcile("periodic controller sync");
|
|
323
451
|
}
|
|
@@ -391,3 +519,106 @@ async function requestKickoffAssessment(worker, requirement) {
|
|
|
391
519
|
clearTimeout(timeout);
|
|
392
520
|
}
|
|
393
521
|
}
|
|
522
|
+
// ── Phase 2.5 wiring: controller LLM as the role judge ───────────────────────
|
|
523
|
+
//
|
|
524
|
+
// resolveTaskRoleWithLlmFallback (kickoff-orchestrator) defined the seam in
|
|
525
|
+
// P2.5 with fake-driven tests but no production caller. This factory builds
|
|
526
|
+
// the production llmRoleJudge: a ONE-SHOT subagent session on the controller
|
|
527
|
+
// runtime (never the long-lived intake conversation, so verdicts cannot
|
|
528
|
+
// pollute intake semantics) that answers with a single role id of the ACTIVE
|
|
529
|
+
// profile. The resolver validates the answer (validateActiveRoleId) and
|
|
530
|
+
// degrades to the profile defaultRole when the judge is unavailable, times
|
|
531
|
+
// out, errors, or names a role outside the active profile - the TaskRouter
|
|
532
|
+
// then treats the outcome as a routing hint, so dispatch never blocks on a
|
|
533
|
+
// strand.
|
|
534
|
+
/** Budget for a one-id LLM verdict; past it the resolver degrades to defaultRole. */
|
|
535
|
+
const ROLE_JUDGE_TIMEOUT_MS = 30_000;
|
|
536
|
+
const ROLE_JUDGE_SESSION_PREFIX = "teamclaw-role-judge:";
|
|
537
|
+
const ROLE_JUDGE_SYSTEM_PROMPT = [
|
|
538
|
+
"You are the role router of a TeamClaw controller.",
|
|
539
|
+
"Given one task, pick the single team role that should own it.",
|
|
540
|
+
"Reply with EXACTLY one role id from the provided list - no prose, no markdown, no explanation.",
|
|
541
|
+
].join(" ");
|
|
542
|
+
function createControllerLlmRoleJudge(deps) {
|
|
543
|
+
const subagent = deps.runtime?.subagent;
|
|
544
|
+
if (!subagent
|
|
545
|
+
|| typeof subagent.run !== "function"
|
|
546
|
+
|| typeof subagent.waitForRun !== "function"
|
|
547
|
+
|| typeof subagent.getSessionMessages !== "function") {
|
|
548
|
+
// Runtime without an LLM subagent (e.g. minimal test doubles): leave the
|
|
549
|
+
// seam unwired; the TaskRouter keeps its pre-wiring behavior.
|
|
550
|
+
return undefined;
|
|
551
|
+
}
|
|
552
|
+
const logger = deps.logger;
|
|
553
|
+
return async ({ task, verdict }) => {
|
|
554
|
+
const roleIds = getActiveRoleIds();
|
|
555
|
+
const message = [
|
|
556
|
+
`Task title: ${task.title}`,
|
|
557
|
+
`Task description: ${task.description?.trim() || "(none)"}`,
|
|
558
|
+
"",
|
|
559
|
+
`Token-based role scoring refused to decide (${verdict.reason}).`,
|
|
560
|
+
`Pick the single role that should own this task. Answer with EXACTLY one role id from: ${roleIds.join(", ")}`,
|
|
561
|
+
].join("\n");
|
|
562
|
+
// Fresh one-shot session per verdict: the judge must stay stateless and
|
|
563
|
+
// separate from any intake/worker conversation.
|
|
564
|
+
const sessionKey = buildTeamClawAgentSessionKey(`${ROLE_JUDGE_SESSION_PREFIX}${task.id}-${Date.now()}`);
|
|
565
|
+
const run = await subagent.run({
|
|
566
|
+
sessionKey,
|
|
567
|
+
message,
|
|
568
|
+
extraSystemPrompt: ROLE_JUDGE_SYSTEM_PROMPT,
|
|
569
|
+
idempotencyKey: `role-judge-${task.id}-${Date.now()}`,
|
|
570
|
+
});
|
|
571
|
+
const waited = await subagent.waitForRun({
|
|
572
|
+
runId: run.runId,
|
|
573
|
+
timeoutMs: ROLE_JUDGE_TIMEOUT_MS,
|
|
574
|
+
});
|
|
575
|
+
if (waited.status !== "ok") {
|
|
576
|
+
logger.warn(`Controller: LLM role judge did not complete for task ${task.id} (${waited.status}${"error" in waited && waited.error ? `: ${waited.error}` : ""}); using the profile defaultRole`);
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
const session = await subagent.getSessionMessages({ sessionKey, limit: 5 });
|
|
580
|
+
const reply = extractLastAssistantText(session.messages);
|
|
581
|
+
const direct = validateActiveRoleId(reply.trim());
|
|
582
|
+
if (direct) {
|
|
583
|
+
return direct;
|
|
584
|
+
}
|
|
585
|
+
// Tolerate light prose wrapping ("The role is: qa."): first ACTIVE role
|
|
586
|
+
// id that appears as a whole word in the reply.
|
|
587
|
+
for (const roleId of roleIds) {
|
|
588
|
+
const pattern = new RegExp(`(^|[^a-z0-9-])${roleId.replace(/[-]/g, "\\-")}([^a-z0-9-]|$)`);
|
|
589
|
+
if (pattern.test(reply)) {
|
|
590
|
+
return roleId;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
logger.warn(`Controller: LLM role judge reply for task ${task.id} named no active role (${reply.slice(0, 120) || "empty reply"}); using the profile defaultRole`);
|
|
594
|
+
return null;
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
/** Last assistant message text (string or text blocks), mirroring the http-server intake helper semantics. */
|
|
598
|
+
function extractLastAssistantText(messages) {
|
|
599
|
+
const assistantMessages = messages.filter((message) => {
|
|
600
|
+
if (!message || typeof message !== "object") {
|
|
601
|
+
return false;
|
|
602
|
+
}
|
|
603
|
+
return message.role === "assistant";
|
|
604
|
+
});
|
|
605
|
+
const lastAssistant = assistantMessages[assistantMessages.length - 1];
|
|
606
|
+
if (!lastAssistant) {
|
|
607
|
+
return "";
|
|
608
|
+
}
|
|
609
|
+
if (typeof lastAssistant.content === "string") {
|
|
610
|
+
return lastAssistant.content;
|
|
611
|
+
}
|
|
612
|
+
if (Array.isArray(lastAssistant.content)) {
|
|
613
|
+
const textBlocks = lastAssistant.content
|
|
614
|
+
.filter((block) => {
|
|
615
|
+
return !!block && typeof block === "object" && block.type === "text";
|
|
616
|
+
})
|
|
617
|
+
.map((block) => (typeof block.text === "string" ? block.text : ""))
|
|
618
|
+
.filter(Boolean);
|
|
619
|
+
if (textBlocks.length > 0) {
|
|
620
|
+
return textBlocks.join("\n");
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return "";
|
|
624
|
+
}
|
|
@@ -2,6 +2,12 @@ import { Type } from "@sinclair/typebox";
|
|
|
2
2
|
import { buildControllerNoWorkersMessage, hasOnDemandWorkerProvisioning, shouldBlockControllerWithoutWorkers } from "./controller-capacity.js";
|
|
3
3
|
import { normalizeClarificationQuestionSchemas, normalizeManifestCompletionOpportunities, normalizeManifestCreatedTasks, normalizeManifestDeferredTasks, normalizeManifestRoleList, normalizeManifestStringList, normalizeOptionalManifestText, } from "./orchestration-manifest.js";
|
|
4
4
|
import { ensureTeamMessageContract, normalizeContractRole, normalizeContractStringList, } from "../interaction-contracts.js";
|
|
5
|
+
// Phase 2.1 debt item 1 (P1 closeout handover): tool input validation checks
|
|
6
|
+
// the ACTIVE TeamProfile's role set via the profile loader. The previous
|
|
7
|
+
// registry-set check would silently kill every non-software role once a team
|
|
8
|
+
// switches profiles; behavior on the software-rd baseline is unchanged
|
|
9
|
+
// (active set == registry set).
|
|
10
|
+
import { validateActiveRoleId } from "../profile-loader.js";
|
|
5
11
|
const EXECUTION_READY_BLOCKERS = [
|
|
6
12
|
{ pattern: /\bdepends?\s+on\b/i, reason: "it explicitly depends on other unfinished work" },
|
|
7
13
|
{ pattern: /\bprerequisite\b/i, reason: "it references a prerequisite that may not be satisfied yet" },
|
|
@@ -12,10 +18,6 @@ const EXECUTION_READY_BLOCKERS = [
|
|
|
12
18
|
{ pattern: /blocked\s*-\s*by/i, reason: "it explicitly says the task is blocked by another item" },
|
|
13
19
|
{ pattern: /需要.*先完成/u, reason: "it states another piece of work must complete first" },
|
|
14
20
|
];
|
|
15
|
-
const VALID_ROLE_IDS = new Set([
|
|
16
|
-
"pm", "architect", "developer", "qa", "release-engineer",
|
|
17
|
-
"infra-engineer", "devops", "security-engineer", "designer", "marketing",
|
|
18
|
-
]);
|
|
19
21
|
const ENGLISH_LATER_PHASE_CLAUSE_RE = /\b(?:after|once)\b(.+?)\b(complete|completed|ready|available|exists?)\b/i;
|
|
20
22
|
const ENGLISH_LATER_PHASE_DEPENDENCY_RE = /\b(?:task|tasks|service|services|module|modules|phase|phases|api|apis|interface|interfaces|review|qa|design|developer|architect|skeleton|backend|frontend|deliverable|artifact|handoff)\b/i;
|
|
21
23
|
const CHINESE_LATER_PHASE_CLAUSE_RE = /(.+?)(完成后|就绪后)/u;
|
|
@@ -58,9 +60,12 @@ export function createControllerTools(deps) {
|
|
|
58
60
|
return { details: {}, content: [{ type: "text", text: "requirement is required." }] };
|
|
59
61
|
}
|
|
60
62
|
const rawRoles = Array.isArray(params.candidateRoles) ? params.candidateRoles : [];
|
|
63
|
+
// Phase 2.1 debt item 1: validate against the ACTIVE profile's role
|
|
64
|
+
// set (validateActiveRoleId) so kickoff candidate roles of a switched
|
|
65
|
+
// team (e.g. banking) pass instead of being silently filtered out.
|
|
61
66
|
const candidateRoles = rawRoles
|
|
62
|
-
.map((r) => String(r ?? "").trim().toLowerCase())
|
|
63
|
-
.filter((r) =>
|
|
67
|
+
.map((r) => validateActiveRoleId(String(r ?? "").trim().toLowerCase()))
|
|
68
|
+
.filter((r) => r !== undefined);
|
|
64
69
|
if (candidateRoles.length === 0) {
|
|
65
70
|
return { details: {}, content: [{ type: "text", text: "At least one valid candidate role is required." }] };
|
|
66
71
|
}
|