@teamclaws/teamclaw 2026.11.0 → 2026.11.2
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 +368 -13
- package/dist/index.js +61 -32
- package/dist/src/config.js +24 -0
- package/dist/src/controller/auth-routes.js +129 -0
- package/dist/src/controller/clarification-routes.js +1 -1
- package/dist/src/controller/config-routes.js +138 -0
- package/dist/src/controller/controller-planning.js +1 -0
- package/dist/src/controller/controller-routes.js +195 -0
- package/dist/src/controller/controller-service.js +67 -10
- package/dist/src/controller/controller-tools.js +3 -1
- package/dist/src/controller/github-auth.js +2 -1
- package/dist/src/controller/http-server.js +51 -16
- package/dist/src/controller/kickoff-orchestrator.js +3 -39
- package/dist/src/controller/message-delivery.js +4 -1
- package/dist/src/controller/orchestration-manifest.js +5 -65
- package/dist/src/controller/preview-manager.js +51 -3
- package/dist/src/controller/profile-switch.js +42 -22
- 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 +70 -4
- package/dist/src/controller/report-routes.js +56 -0
- package/dist/src/controller/route-table.js +73 -1045
- package/dist/src/controller/security.js +775 -0
- package/dist/src/controller/status-routes.js +287 -0
- package/dist/src/controller/task-assignment.js +5 -2
- package/dist/src/controller/task-execution.js +31 -0
- package/dist/src/controller/task-results.js +10 -0
- package/dist/src/controller/tunnel-manager.js +41 -8
- package/dist/src/controller/tunnel-routes.js +225 -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 +39 -949
- 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 +12 -1
- package/dist/src/openclaw-workspace.js +36 -0
- package/dist/src/profile-loader.js +119 -1
- package/dist/src/profiles/banking.json +26 -2
- package/dist/src/profiles/schema.json +82 -2
- package/dist/src/prompt-policy.js +18 -6
- package/dist/src/protocol.js +66 -3
- 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 +89 -3
- package/dist/src/teamauto/scanner.js +21 -2
- package/dist/src/teamauto/scheduler.js +9 -2
- package/dist/src/types.js +15 -1
- package/dist/src/ui/app.js +990 -73
- package/dist/src/ui/github-login.html +1 -0
- package/dist/src/ui/index.html +125 -36
- package/dist/src/worker/http-handler.js +59 -0
- package/dist/src/worker/skill-installer.js +3 -9
- package/dist/src/worker/tools.js +20 -10
- package/dist/src/worker/worker-service.js +17 -4
- package/index.ts +69 -32
- package/openclaw.plugin.json +23 -2
- package/package.json +1 -1
- package/src/config.ts +24 -0
- package/src/controller/auth-routes.ts +157 -0
- package/src/controller/clarification-routes.ts +1 -1
- package/src/controller/config-routes.ts +152 -0
- package/src/controller/controller-planning.ts +8 -0
- package/src/controller/controller-routes.ts +237 -0
- package/src/controller/controller-service.ts +128 -10
- package/src/controller/controller-tools.ts +5 -2
- package/src/controller/github-auth.ts +28 -63
- package/src/controller/http-server.ts +66 -17
- package/src/controller/kickoff-orchestrator.ts +3 -42
- package/src/controller/message-delivery.ts +4 -1
- package/src/controller/orchestration-manifest.ts +8 -71
- package/src/controller/preview-manager.ts +53 -3
- package/src/controller/profile-switch.ts +53 -23
- 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 +84 -12
- package/src/controller/report-routes.ts +64 -0
- package/src/controller/route-table.ts +139 -1152
- package/src/controller/security.ts +899 -0
- package/src/controller/status-routes.ts +354 -0
- package/src/controller/task-assignment.ts +5 -1
- package/src/controller/task-execution.ts +43 -0
- package/src/controller/task-results.ts +12 -0
- package/src/controller/tunnel-manager.ts +45 -8
- package/src/controller/tunnel-routes.ts +231 -0
- package/src/controller/websocket.ts +20 -3
- package/src/controller/webui-routes.ts +55 -0
- package/src/controller/worker-provisioning.ts +51 -1117
- 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 +13 -1
- package/src/openclaw-workspace.ts +47 -0
- package/src/profile-loader.ts +167 -1
- package/src/profiles/banking.json +26 -2
- package/src/profiles/schema.json +82 -2
- package/src/prompt-policy.ts +19 -6
- package/src/protocol.ts +72 -2
- 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 +92 -3
- package/src/teamauto/github-client.ts +2 -1
- package/src/teamauto/repo-sync.ts +2 -1
- package/src/teamauto/scanner.ts +22 -3
- package/src/teamauto/scheduler.ts +11 -3
- package/src/teamauto/store.ts +5 -0
- package/src/types.ts +130 -1
- package/src/ui/app.js +990 -73
- package/src/ui/github-login.html +1 -0
- package/src/ui/index.html +125 -36
- package/src/worker/http-handler.ts +64 -1
- package/src/worker/skill-installer.ts +3 -9
- package/src/worker/tools.ts +21 -10
- package/src/worker/worker-service.ts +18 -4
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// Issue #226 W2 (route-table carve-up): the controller runs / projects /
|
|
2
|
+
// intake route handlers moved verbatim from route-table.ts (PR-D had moved
|
|
3
|
+
// them verbatim from http-server.ts before that) - bodies byte-identical,
|
|
4
|
+
// only the module home changed. route-table.ts keeps the table entries that
|
|
5
|
+
// bind these handlers and re-exports the retry-hint constant for
|
|
6
|
+
// http-server.ts's dispatch gates. Like security.ts, this module imports
|
|
7
|
+
// route-table.js as TYPE ONLY (RouteContext), so the module graph stays
|
|
8
|
+
// acyclic.
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import { parseJsonBody, sendJson, sendError } from "../protocol.js";
|
|
11
|
+
import { normalizeControllerManifest } from "./orchestration-manifest.js";
|
|
12
|
+
import {
|
|
13
|
+
normalizeControllerIntakeSessionKey,
|
|
14
|
+
} from "./task-execution.js";
|
|
15
|
+
import {
|
|
16
|
+
findLatestControllerRunIdForSession,
|
|
17
|
+
syncProjectRegistryEntry,
|
|
18
|
+
} from "./project-registry.js";
|
|
19
|
+
import {
|
|
20
|
+
appendControllerRunEvent,
|
|
21
|
+
serializeControllerRun,
|
|
22
|
+
updateControllerRun,
|
|
23
|
+
} from "./controller-runs.js";
|
|
24
|
+
import {
|
|
25
|
+
deleteControllerRunCascade,
|
|
26
|
+
deleteProjectCascade,
|
|
27
|
+
resolveSafeProjectDirectory,
|
|
28
|
+
} from "./task-cleanup.js";
|
|
29
|
+
import {
|
|
30
|
+
ControllerIntakeSwitchInProgressError,
|
|
31
|
+
reconcileControllerClarifications,
|
|
32
|
+
runControllerIntake,
|
|
33
|
+
} from "./controller-intake.js";
|
|
34
|
+
import { buildControllerManifestEventMessage } from "./controller-planning.js";
|
|
35
|
+
import {
|
|
36
|
+
buildStartupReadinessMessage,
|
|
37
|
+
shouldBlockControllerUntilProvisioningReady,
|
|
38
|
+
} from "./worker-routes.js";
|
|
39
|
+
import type { RouteContext } from "./route-table.js";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Retry hint shared by the transition-matrix gate (http-server.ts, task
|
|
43
|
+
* submission / repo import) and the intake handler in this module. Lived in
|
|
44
|
+
* route-table.ts since PR-D (the intake handler body carried it in 503
|
|
45
|
+
* bodies); W2 moved it here with its consumer - route-table re-exports it so
|
|
46
|
+
* http-server.ts's gate import is unchanged.
|
|
47
|
+
*/
|
|
48
|
+
export const SWITCH_TASK_SUBMISSION_RETRY_AFTER_SECONDS = 5;
|
|
49
|
+
|
|
50
|
+
async function controllerManifestRoute(ctx: RouteContext): Promise<void> {
|
|
51
|
+
const { req, res, deps } = ctx;
|
|
52
|
+
const { logger, getTeamState, updateTeamState, wsServer } = deps;
|
|
53
|
+
const body = await parseJsonBody(req);
|
|
54
|
+
const sessionKey = normalizeControllerIntakeSessionKey(body.sessionKey);
|
|
55
|
+
const manifest = normalizeControllerManifest(body.manifest);
|
|
56
|
+
if (!manifest) {
|
|
57
|
+
sendError(res, 400, "manifest is required and must include requirementSummary");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const runId = findLatestControllerRunIdForSession(sessionKey, deps.getTeamState(), {
|
|
62
|
+
preferActive: true,
|
|
63
|
+
});
|
|
64
|
+
if (!runId) {
|
|
65
|
+
sendError(res, 404, "Controller run not found for session");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const updatedRun = updateControllerRun(runId, deps, (run) => {
|
|
70
|
+
run.manifest = manifest;
|
|
71
|
+
const state = deps.getTeamState();
|
|
72
|
+
if (state) {
|
|
73
|
+
const project = syncProjectRegistryEntry(state, {
|
|
74
|
+
projectId: manifest.projectName ?? run.projectId,
|
|
75
|
+
projectDir: run.projectDir ?? manifest.projectName,
|
|
76
|
+
aliases: [manifest.projectName, run.projectId],
|
|
77
|
+
summary: manifest.requirementSummary,
|
|
78
|
+
updatedAt: Date.now(),
|
|
79
|
+
});
|
|
80
|
+
run.projectId = project.projectId;
|
|
81
|
+
run.projectDir = project.projectDir;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (run.projectDir) {
|
|
85
|
+
const state = deps.getTeamState();
|
|
86
|
+
if (state) {
|
|
87
|
+
for (const taskId of run.createdTaskIds) {
|
|
88
|
+
const task = state.tasks[taskId];
|
|
89
|
+
if (task) {
|
|
90
|
+
if (!task.projectDir) {
|
|
91
|
+
task.projectDir = run.projectDir;
|
|
92
|
+
}
|
|
93
|
+
if (!task.projectId) {
|
|
94
|
+
task.projectId = run.projectId;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
appendControllerRunEvent(run, {
|
|
102
|
+
type: "output",
|
|
103
|
+
phase: "manifest_recorded",
|
|
104
|
+
source: "controller",
|
|
105
|
+
status: "running",
|
|
106
|
+
sessionKey,
|
|
107
|
+
message: buildControllerManifestEventMessage(manifest),
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (!updatedRun) {
|
|
112
|
+
sendError(res, 404, "Controller run not found");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (manifest.requirementFullyComplete) {
|
|
117
|
+
logger.info(`Controller: requirement fully complete for session ${sessionKey} (run ${runId})`);
|
|
118
|
+
wsServer.broadcastUpdate({
|
|
119
|
+
type: "requirement:complete",
|
|
120
|
+
data: {
|
|
121
|
+
runId,
|
|
122
|
+
sessionKey,
|
|
123
|
+
requirementSummary: manifest.requirementSummary,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
sendJson(res, 201, {
|
|
129
|
+
controllerRun: serializeControllerRun(updatedRun),
|
|
130
|
+
manifest,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function controllerRunsListRoute(ctx: RouteContext): Promise<void> {
|
|
135
|
+
const { res, deps } = ctx;
|
|
136
|
+
const state = reconcileControllerClarifications(deps);
|
|
137
|
+
const controllerRuns = state
|
|
138
|
+
? Object.values(state.controllerRuns)
|
|
139
|
+
.sort((left, right) => right.updatedAt - left.updatedAt)
|
|
140
|
+
.map((run) => serializeControllerRun(run))
|
|
141
|
+
: [];
|
|
142
|
+
sendJson(res, 200, { controllerRuns });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function projectDeleteRoute(ctx: RouteContext): Promise<void> {
|
|
146
|
+
const { res, pathname, deps } = ctx;
|
|
147
|
+
const projectDir = decodeURIComponent(pathname.split("/").pop()!);
|
|
148
|
+
const result = await deleteProjectCascade(projectDir, deps);
|
|
149
|
+
if (!result.deleted) {
|
|
150
|
+
sendError(res, 404, "Project not found or project cleanup could not be confirmed");
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const safeProjectPath = resolveSafeProjectDirectory(projectDir);
|
|
154
|
+
const stillExists = safeProjectPath ? fs.existsSync(safeProjectPath) : true;
|
|
155
|
+
if (stillExists) {
|
|
156
|
+
sendError(res, 409, "Project cleanup could not be confirmed");
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
sendJson(res, 200, {
|
|
160
|
+
status: "deleted",
|
|
161
|
+
confirmed: true,
|
|
162
|
+
projectDir,
|
|
163
|
+
cleanup: result.summary,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function controllerRunDeleteRoute(ctx: RouteContext): Promise<void> {
|
|
168
|
+
const { res, pathname, deps } = ctx;
|
|
169
|
+
const { getTeamState } = deps;
|
|
170
|
+
const runId = pathname.split("/").pop()!;
|
|
171
|
+
const result = await deleteControllerRunCascade(runId, deps);
|
|
172
|
+
if (!result.deleted) {
|
|
173
|
+
sendError(res, 404, "Controller run not found");
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const stillExists = !!getTeamState()?.controllerRuns[runId];
|
|
177
|
+
if (stillExists) {
|
|
178
|
+
sendError(res, 409, "Planning run cleanup could not be confirmed");
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
sendJson(res, 200, {
|
|
182
|
+
status: "deleted",
|
|
183
|
+
confirmed: true,
|
|
184
|
+
runId,
|
|
185
|
+
cleanup: result.summary,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function controllerIntakeRoute(ctx: RouteContext): Promise<void> {
|
|
190
|
+
const { req, res, deps, currentState } = ctx;
|
|
191
|
+
const { logger } = deps;
|
|
192
|
+
const readinessGate = shouldBlockControllerUntilProvisioningReady(deps, currentState);
|
|
193
|
+
if (readinessGate.blocked && readinessGate.readiness) {
|
|
194
|
+
sendError(res, 503, buildStartupReadinessMessage(readinessGate.readiness));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const body = await parseJsonBody(req);
|
|
198
|
+
const message = typeof body.message === "string" ? body.message.trim() : "";
|
|
199
|
+
if (!message) {
|
|
200
|
+
sendError(res, 400, "message is required");
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const sessionKey = normalizeControllerIntakeSessionKey(body.sessionKey);
|
|
205
|
+
|
|
206
|
+
try {
|
|
207
|
+
const result = await runControllerIntake(message, sessionKey, deps);
|
|
208
|
+
sendJson(res, 200, result);
|
|
209
|
+
} catch (err) {
|
|
210
|
+
if (err instanceof ControllerIntakeSwitchInProgressError) {
|
|
211
|
+
// Same response shape as the URL-level transition gate (503 +
|
|
212
|
+
// Retry-After); reachable here when a switch starts between the gate
|
|
213
|
+
// and the intake entry (the gate reads the state once per request).
|
|
214
|
+
res.setHeader("Retry-After", String(SWITCH_TASK_SUBMISSION_RETRY_AFTER_SECONDS));
|
|
215
|
+
sendJson(res, 503, {
|
|
216
|
+
error: err.message,
|
|
217
|
+
retryAfterSeconds: SWITCH_TASK_SUBMISSION_RETRY_AFTER_SECONDS,
|
|
218
|
+
transition: {
|
|
219
|
+
phase: err.transition.phase,
|
|
220
|
+
targetProfileId: err.transition.targetProfileId,
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
226
|
+
logger.warn(`Controller: intake failed for ${sessionKey}: ${errorMessage}`);
|
|
227
|
+
sendError(res, errorMessage.includes("timed out") ? 504 : 500, errorMessage);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export {
|
|
232
|
+
controllerManifestRoute,
|
|
233
|
+
controllerRunsListRoute,
|
|
234
|
+
projectDeleteRoute,
|
|
235
|
+
controllerRunDeleteRoute,
|
|
236
|
+
controllerIntakeRoute,
|
|
237
|
+
};
|
|
@@ -9,17 +9,21 @@ import { createControllerHttpServer, type ControllerHttpDeps } from "./http-serv
|
|
|
9
9
|
// PR-C of issue #204: the assignment pipeline incl. the gated auto-assign
|
|
10
10
|
// loop lives in ./task-assignment.js, not http-server.ts.
|
|
11
11
|
import { autoAssignPendingTasks } from "./task-assignment.js";
|
|
12
|
+
// Issue #222: worker dispatch-token header helper for controller -> worker calls.
|
|
13
|
+
import { withWorkerDispatchToken } from "./task-execution.js";
|
|
12
14
|
// PR-A of issue #204: the profile switch state machine (incl. crash resume)
|
|
13
15
|
// lives in ./profile-switch.ts, not http-server.ts.
|
|
14
16
|
import { resumeTeamProfileSwitch } from "./profile-switch.js";
|
|
15
17
|
import { TaskRouter } from "./task-router.js";
|
|
16
18
|
import { MessageRouter } from "./message-router.js";
|
|
17
|
-
import { TeamWebSocketServer } from "./websocket.js";
|
|
19
|
+
import { TeamWebSocketServer, type WsEvent } from "./websocket.js";
|
|
18
20
|
import { ensureOpenClawWorkspaceMemoryDir, buildTeamClawAgentSessionKey } from "../openclaw-workspace.js";
|
|
19
21
|
import { ensureControllerGitRepo } from "../git-collaboration.js";
|
|
20
22
|
import { WorkerProvisioningManager } from "./worker-provisioning.js";
|
|
21
23
|
import { PreviewManager } from "./preview-manager.js";
|
|
22
|
-
import { runKickoffMeeting,
|
|
24
|
+
import { runKickoffMeeting, ASSESSMENT_TIMEOUT_MS, type TaskRoleResolutionDeps } from "./kickoff-orchestrator.js";
|
|
25
|
+
// Issue #226 W3: the kickoff prompt contract lives in the shared layer now.
|
|
26
|
+
import { buildKickoffAssessmentPrompt } from "../shared/kickoff-prompt.js";
|
|
23
27
|
import { resolvePreferredLanAddress } from "../networking.js";
|
|
24
28
|
import { createTeamAutoScheduler, type TeamAutoScheduler } from "../teamauto/scheduler.js";
|
|
25
29
|
import { getGithubAuthManager } from "./github-auth.js";
|
|
@@ -33,6 +37,66 @@ export type KickoffHandler = (
|
|
|
33
37
|
requirement: string,
|
|
34
38
|
) => Promise<{ assessments: KickoffAssessment[]; summary: string }>;
|
|
35
39
|
|
|
40
|
+
// ===========================================================================
|
|
41
|
+
// Issue #226 W4: the single TeamState write-entry contract.
|
|
42
|
+
//
|
|
43
|
+
// `updateState` below is the ONLY sanctioned way to mutate the shared
|
|
44
|
+
// TeamState and persist it: the updater closure runs synchronously on the
|
|
45
|
+
// shared object, then the entry owns persistence (and, when asked, the WS
|
|
46
|
+
// broadcast). Before W4 there were three parallel write tracks - this
|
|
47
|
+
// controlled channel, direct mutation + saveTeamState in route-table's
|
|
48
|
+
// inline handlers, and profile-switch's independent saves - with
|
|
49
|
+
// lost-update / missed-broadcast risk across await interleavings. The
|
|
50
|
+
// route-handler and profile-switch tracks were migrated onto this entry;
|
|
51
|
+
// the remaining direct saveTeamState call sites are startup-early writes
|
|
52
|
+
// registered as explicit exemptions (search "W4 write-face exemption") and
|
|
53
|
+
// machine-pinned by tests/test-teamstate-writes.mjs, so a new unregistered
|
|
54
|
+
// direct save turns the suite red.
|
|
55
|
+
// ===========================================================================
|
|
56
|
+
|
|
57
|
+
/** A WS event the entry broadcasts on the caller's behalf (see below). */
|
|
58
|
+
export type TeamStateUpdateEvent = WsEvent;
|
|
59
|
+
|
|
60
|
+
export type TeamStateUpdateOptions = {
|
|
61
|
+
/**
|
|
62
|
+
* WS events to broadcast after the updater returned. With the default
|
|
63
|
+
* background persistence they fire synchronously right after the save was
|
|
64
|
+
* enqueued (the historical shape of callers broadcasting manually right
|
|
65
|
+
* after updateTeamState); with `persist: "awaited"` they fire only once
|
|
66
|
+
* the state-file write has fulfilled - the durability-before-broadcast
|
|
67
|
+
* contract the profile switch steps 1/6 rely on - and never fire when the
|
|
68
|
+
* write fails.
|
|
69
|
+
*/
|
|
70
|
+
broadcast?: ReadonlyArray<TeamStateUpdateEvent>;
|
|
71
|
+
/**
|
|
72
|
+
* "background" (default): fire-and-forget save, the exact semantics every
|
|
73
|
+
* pre-W4 caller of updateTeamState relies on (an un-caught promise, same
|
|
74
|
+
* as the historical `void saveTeamState(...)`).
|
|
75
|
+
* "awaited": durability barrier - the update returns a handle carrying
|
|
76
|
+
* the save promise so the caller can enforce persisted-before-broadcast
|
|
77
|
+
* (profile switch transition step 1) and roll the in-memory mutation back
|
|
78
|
+
* when the write fails.
|
|
79
|
+
*/
|
|
80
|
+
persist?: "background" | "awaited";
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Return shape of the `persist: "awaited"` variant (see UpdateTeamStateFn). */
|
|
84
|
+
export type TeamStateUpdateHandle = {
|
|
85
|
+
state: TeamState;
|
|
86
|
+
/** Resolves when the state-file write settled; rejects on write failure. */
|
|
87
|
+
persisted: Promise<void>;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The deps-facing signature of the single write entry. Callers that pass no
|
|
92
|
+
* options keep the historical `(updater) => TeamState` behavior; the second
|
|
93
|
+
* overload is the awaited-durability variant used by the profile switch.
|
|
94
|
+
*/
|
|
95
|
+
export type UpdateTeamStateFn = {
|
|
96
|
+
(updater: (state: TeamState) => void, options?: TeamStateUpdateOptions & { persist?: "background" }): TeamState;
|
|
97
|
+
(updater: (state: TeamState) => void, options: TeamStateUpdateOptions & { persist: "awaited" }): TeamStateUpdateHandle;
|
|
98
|
+
};
|
|
99
|
+
|
|
36
100
|
export type ControllerServiceDeps = {
|
|
37
101
|
config: PluginConfig;
|
|
38
102
|
logger: PluginLogger;
|
|
@@ -133,6 +197,10 @@ export function createControllerService(deps: ControllerServiceDeps): OpenClawPl
|
|
|
133
197
|
createdAt: Date.now(),
|
|
134
198
|
updatedAt: Date.now(),
|
|
135
199
|
};
|
|
200
|
+
// W4 write-face exemption (#226): first-boot TeamState creation.
|
|
201
|
+
// This is initialization, not an update - the updateState entry is
|
|
202
|
+
// only defined below and presupposes an existing shared object. No
|
|
203
|
+
// WS server exists yet, so there is nothing to broadcast to.
|
|
136
204
|
await saveTeamState(teamState);
|
|
137
205
|
logger.info(`Controller: created new team "${config.teamName}" (profile: ${seededProfileId})`);
|
|
138
206
|
} else {
|
|
@@ -143,11 +211,38 @@ export function createControllerService(deps: ControllerServiceDeps): OpenClawPl
|
|
|
143
211
|
}
|
|
144
212
|
deps.onTeamStateAvailable?.(() => teamState);
|
|
145
213
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
214
|
+
// Issue #226 W4: the single TeamState write entry (see the contract
|
|
215
|
+
// block above). The updater stays a synchronous closure over the
|
|
216
|
+
// shared object; persistence - and, when requested, the WS broadcast -
|
|
217
|
+
// happen strictly after the updater returned. Existing one-argument
|
|
218
|
+
// callers keep the exact pre-W4 fire-and-forget semantics.
|
|
219
|
+
const updateState = ((updater: (state: TeamState) => void, options: TeamStateUpdateOptions = {}) => {
|
|
220
|
+
const state = teamState!;
|
|
221
|
+
updater(state);
|
|
222
|
+
if (options.persist === "awaited") {
|
|
223
|
+
// Durability variant (profile switch): the caller owns the save
|
|
224
|
+
// promise - broadcast events ride its fulfillment and never fire
|
|
225
|
+
// on failure; rejections surface to the caller's rollback. A
|
|
226
|
+
// dropped handle rejects unhandled, exactly like the historical
|
|
227
|
+
// floating void save.
|
|
228
|
+
let persisted = saveTeamState(state);
|
|
229
|
+
if (options.broadcast?.length) {
|
|
230
|
+
persisted = persisted.then(() => {
|
|
231
|
+
for (const event of options.broadcast!) {
|
|
232
|
+
wsServer.broadcastUpdate(event);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
return { state, persisted };
|
|
237
|
+
}
|
|
238
|
+
void saveTeamState(state);
|
|
239
|
+
if (options.broadcast?.length) {
|
|
240
|
+
for (const event of options.broadcast) {
|
|
241
|
+
wsServer.broadcastUpdate(event);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return state;
|
|
245
|
+
}) as UpdateTeamStateFn;
|
|
151
246
|
|
|
152
247
|
// Provisioned workers die with the previous gateway process. Their
|
|
153
248
|
// persisted entries flip to offline once heartbeats stop but were
|
|
@@ -189,6 +284,11 @@ export function createControllerService(deps: ControllerServiceDeps): OpenClawPl
|
|
|
189
284
|
// Run ALL syncState calls (avoid || short-circuit skipping some).
|
|
190
285
|
const syncC = workerProvisioningManager.syncState(teamState);
|
|
191
286
|
if (repoStateChanged || syncC) {
|
|
287
|
+
// W4 write-face exemption (#226): startup durability barrier for the
|
|
288
|
+
// startup state assembly above (repo stamp + provisioning syncState's
|
|
289
|
+
// in-place mutations, which belong to the provisioning module). Runs
|
|
290
|
+
// before the WS server exists; there is no updater closure to run
|
|
291
|
+
// here - the mutations already happened on the shared object.
|
|
192
292
|
await saveTeamState(teamState);
|
|
193
293
|
}
|
|
194
294
|
|
|
@@ -228,6 +328,12 @@ export function createControllerService(deps: ControllerServiceDeps): OpenClawPl
|
|
|
228
328
|
}
|
|
229
329
|
}
|
|
230
330
|
if (orphanCleaned) {
|
|
331
|
+
// W4 write-face exemption (#226): startup orphan-task sweep. The
|
|
332
|
+
// loop above mutates in place interleaved with per-task startup
|
|
333
|
+
// logging; this awaited save is the pre-HTTP durability barrier -
|
|
334
|
+
// folding the sweep into an updater closure would reshuffle the
|
|
335
|
+
// startup crash-window ordering for zero convergence gain (the WS
|
|
336
|
+
// server does not exist yet, nothing to broadcast).
|
|
231
337
|
await saveTeamState(teamState);
|
|
232
338
|
}
|
|
233
339
|
}
|
|
@@ -389,7 +495,8 @@ export function createControllerService(deps: ControllerServiceDeps): OpenClawPl
|
|
|
389
495
|
}
|
|
390
496
|
},
|
|
391
497
|
requestWorkerAssessment: async (worker, req) => {
|
|
392
|
-
|
|
498
|
+
// Issue #222: carry the worker's dispatch token on the assess call.
|
|
499
|
+
return await requestKickoffAssessment(worker, req, withWorkerDispatchToken({}, worker.id, config, teamState));
|
|
393
500
|
},
|
|
394
501
|
},
|
|
395
502
|
);
|
|
@@ -462,6 +569,12 @@ export function createControllerService(deps: ControllerServiceDeps): OpenClawPl
|
|
|
462
569
|
}
|
|
463
570
|
|
|
464
571
|
if (changed) {
|
|
572
|
+
// W4 write-face exemption (#226): heartbeat-timeout sweep. The
|
|
573
|
+
// mutations interleave with per-worker WS broadcasts inside the
|
|
574
|
+
// synchronous loop above; this floating save is byte-for-byte the
|
|
575
|
+
// entry's own background semantics (void saveTeamState), so
|
|
576
|
+
// routing it through updateState with a no-op updater would add
|
|
577
|
+
// ceremony without moving any save or broadcast.
|
|
465
578
|
saveTeamState(teamState);
|
|
466
579
|
}
|
|
467
580
|
|
|
@@ -502,6 +615,9 @@ export function createControllerService(deps: ControllerServiceDeps): OpenClawPl
|
|
|
502
615
|
}
|
|
503
616
|
}
|
|
504
617
|
if (orphaned) {
|
|
618
|
+
// W4 write-face exemption (#226): runtime orphan-task
|
|
619
|
+
// reconciliation, same sweep-interleaved-broadcast shape as the
|
|
620
|
+
// worker loop above (see that exemption note).
|
|
505
621
|
saveTeamState(teamState);
|
|
506
622
|
changed = true;
|
|
507
623
|
}
|
|
@@ -554,11 +670,13 @@ function openBrowser(url: string, logger: PluginLogger): void {
|
|
|
554
670
|
/**
|
|
555
671
|
* Request a kickoff assessment from a worker.
|
|
556
672
|
*
|
|
557
|
-
* Request kickoff assessment from a worker over HTTP.
|
|
673
|
+
* Request kickoff assessment from a worker over HTTP. `authHeaders` carries
|
|
674
|
+
* the worker's dispatch token (issue #222) when the controller knows one.
|
|
558
675
|
*/
|
|
559
676
|
async function requestKickoffAssessment(
|
|
560
677
|
worker: import("../types.js").WorkerInfo,
|
|
561
678
|
requirement: string,
|
|
679
|
+
authHeaders: Record<string, string> = {},
|
|
562
680
|
): Promise<import("../types.js").KickoffAssessment> {
|
|
563
681
|
const role = worker.role;
|
|
564
682
|
const prompt = buildKickoffAssessmentPrompt(role, requirement);
|
|
@@ -574,7 +692,7 @@ async function requestKickoffAssessment(
|
|
|
574
692
|
try {
|
|
575
693
|
const res = await fetch(`${worker.url}/api/v1/kickoff/assess`, {
|
|
576
694
|
method: "POST",
|
|
577
|
-
headers: { "Content-Type": "application/json" },
|
|
695
|
+
headers: { "Content-Type": "application/json", ...authHeaders },
|
|
578
696
|
body: JSON.stringify({ requirement, role }),
|
|
579
697
|
signal: controller.signal,
|
|
580
698
|
});
|
|
@@ -9,14 +9,17 @@ import type {
|
|
|
9
9
|
} from "../types.js";
|
|
10
10
|
import { buildControllerNoWorkersMessage, hasOnDemandWorkerProvisioning, shouldBlockControllerWithoutWorkers } from "./controller-capacity.js";
|
|
11
11
|
import {
|
|
12
|
-
normalizeClarificationQuestionSchemas,
|
|
13
12
|
normalizeManifestCompletionOpportunities,
|
|
14
13
|
normalizeManifestCreatedTasks,
|
|
15
14
|
normalizeManifestDeferredTasks,
|
|
16
15
|
normalizeManifestRoleList,
|
|
17
16
|
normalizeManifestStringList,
|
|
18
|
-
normalizeOptionalManifestText,
|
|
19
17
|
} from "./orchestration-manifest.js";
|
|
18
|
+
// Issue #226 W3: the clarification-schema family lives in the shared layer now.
|
|
19
|
+
import {
|
|
20
|
+
normalizeClarificationQuestionSchemas,
|
|
21
|
+
normalizeOptionalManifestText,
|
|
22
|
+
} from "../shared/clarification-schema.js";
|
|
20
23
|
import {
|
|
21
24
|
ensureTeamMessageContract,
|
|
22
25
|
normalizeContractRole,
|
|
@@ -2,6 +2,31 @@ import crypto from "node:crypto";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
// Issue #226 W5: the GithubAuthManager contract (and the pure types it
|
|
6
|
+
// references) moved to the shared layer — teamauto consumes the type and must
|
|
7
|
+
// not import the controller tree. The factory below is annotated with the
|
|
8
|
+
// shared return type, so TypeScript keeps the structural contract in lockstep
|
|
9
|
+
// with the returned closures; the re-export keeps this module's historical
|
|
10
|
+
// public surface stable for existing importers.
|
|
11
|
+
import type {
|
|
12
|
+
GithubAccountInfo,
|
|
13
|
+
GithubAuthManager,
|
|
14
|
+
GithubAuthStatus,
|
|
15
|
+
GithubAuthStore,
|
|
16
|
+
GithubDeviceFlowInfo,
|
|
17
|
+
GithubLoginCallbackParams,
|
|
18
|
+
GithubLoginStart,
|
|
19
|
+
} from "../shared/github-auth.js";
|
|
20
|
+
|
|
21
|
+
export type {
|
|
22
|
+
GithubAccountInfo,
|
|
23
|
+
GithubAuthManager,
|
|
24
|
+
GithubAuthStatus,
|
|
25
|
+
GithubAuthStore,
|
|
26
|
+
GithubDeviceFlowInfo,
|
|
27
|
+
GithubLoginCallbackParams,
|
|
28
|
+
GithubLoginStart,
|
|
29
|
+
} from "../shared/github-auth.js";
|
|
5
30
|
|
|
6
31
|
/**
|
|
7
32
|
* GitHub (GitHub App) user login for the TeamClaw controller.
|
|
@@ -14,7 +39,8 @@ import path from "node:path";
|
|
|
14
39
|
* (`auth/github.json`, mode 0600, atomic tmp+rename writes).
|
|
15
40
|
*/
|
|
16
41
|
|
|
17
|
-
|
|
42
|
+
import { DEFAULT_GITHUB_CLIENT_ID } from "../shared/github-auth.js";
|
|
43
|
+
export { DEFAULT_GITHUB_CLIENT_ID };
|
|
18
44
|
export const GITHUB_AUTH_CALLBACK_PATH = "/api/v1/auth/github/callback";
|
|
19
45
|
export const GITHUB_CLIENT_SECRET_ENV = "TEAMCLAW_GITHUB_CLIENT_SECRET";
|
|
20
46
|
|
|
@@ -43,65 +69,6 @@ export class GithubAuthError extends Error {
|
|
|
43
69
|
}
|
|
44
70
|
}
|
|
45
71
|
|
|
46
|
-
export type GithubAccountInfo = {
|
|
47
|
-
id: number;
|
|
48
|
-
login: string;
|
|
49
|
-
name: string | null;
|
|
50
|
-
avatarUrl: string | null;
|
|
51
|
-
htmlUrl: string | null;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export type GithubAuthStore = {
|
|
55
|
-
version: number;
|
|
56
|
-
clientId: string;
|
|
57
|
-
/** Which OAuth flow produced this token; device-flow tokens refresh without a client secret. */
|
|
58
|
-
flowOrigin: "device" | "web";
|
|
59
|
-
account: GithubAccountInfo | null;
|
|
60
|
-
accessToken: string;
|
|
61
|
-
refreshToken: string | null;
|
|
62
|
-
obtainedAt: number;
|
|
63
|
-
/** Epoch ms when the access token expires; null when it does not expire. */
|
|
64
|
-
expiresAt: number | null;
|
|
65
|
-
/** Epoch ms when the refresh token expires; null when unknown. */
|
|
66
|
-
refreshExpiresAt: number | null;
|
|
67
|
-
updatedAt: number;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export type GithubAuthStatus = {
|
|
71
|
-
authenticated: boolean;
|
|
72
|
-
account: GithubAccountInfo | null;
|
|
73
|
-
clientId: string;
|
|
74
|
-
clientSecretConfigured: boolean;
|
|
75
|
-
expiresAt: number | null;
|
|
76
|
-
refreshExpiresAt: number | null;
|
|
77
|
-
callbackPath: string;
|
|
78
|
-
callbackUrl: string | null;
|
|
79
|
-
/** Absolute URL of the standalone device-login page, when origin is known. */
|
|
80
|
-
loginPageUrl: string | null;
|
|
81
|
-
/** Active device-flow login (user code to enter at github.com/login/device), if any. */
|
|
82
|
-
device: GithubDeviceFlowInfo | null;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export type GithubDeviceFlowInfo = {
|
|
86
|
-
userCode: string;
|
|
87
|
-
verificationUri: string;
|
|
88
|
-
expiresAt: number;
|
|
89
|
-
intervalMs: number;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export type GithubLoginStart = {
|
|
93
|
-
authorizeUrl: string;
|
|
94
|
-
state: string;
|
|
95
|
-
callbackUrl: string;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export type GithubLoginCallbackParams = {
|
|
99
|
-
code?: string;
|
|
100
|
-
state?: string;
|
|
101
|
-
error?: string;
|
|
102
|
-
errorDescription?: string;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
72
|
export type GithubAuthLogger = {
|
|
106
73
|
info: (message: string) => void;
|
|
107
74
|
warn: (message: string) => void;
|
|
@@ -203,7 +170,7 @@ export function createGithubAuthManager(options: {
|
|
|
203
170
|
logger?: GithubAuthLogger;
|
|
204
171
|
fetchImpl?: GithubFetch;
|
|
205
172
|
now?: () => number;
|
|
206
|
-
} = {}) {
|
|
173
|
+
} = {}): GithubAuthManager {
|
|
207
174
|
const clientId = options.clientId?.trim() || DEFAULT_GITHUB_CLIENT_ID;
|
|
208
175
|
// The environment variable wins so operators can keep the secret out of the
|
|
209
176
|
// plugin config file.
|
|
@@ -670,8 +637,6 @@ export function createGithubAuthManager(options: {
|
|
|
670
637
|
};
|
|
671
638
|
}
|
|
672
639
|
|
|
673
|
-
export type GithubAuthManager = ReturnType<typeof createGithubAuthManager>;
|
|
674
|
-
|
|
675
640
|
const managerCache = new Map<string, GithubAuthManager>();
|
|
676
641
|
|
|
677
642
|
/**
|