@teamclaws/teamclaw 2026.11.0 → 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 +272 -2
- package/dist/index.js +54 -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/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 +67 -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/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/types.js +15 -1
- package/dist/src/ui/app.js +846 -62
- package/dist/src/ui/github-login.html +1 -0
- package/dist/src/ui/index.html +102 -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 +61 -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/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 +133 -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 +19 -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/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/scheduler.ts +2 -1
- package/src/types.ts +130 -1
- package/src/ui/app.js +846 -62
- package/src/ui/github-login.html +1 -0
- package/src/ui/index.html +102 -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
package/index.ts
CHANGED
|
@@ -16,6 +16,9 @@ import { createControllerTools } from "./src/controller/controller-tools.js";
|
|
|
16
16
|
import { publishWorkerRepo, syncWorkerRepo } from "./src/git-collaboration.js";
|
|
17
17
|
import { resolveTeamClawProjectsDir } from "./src/openclaw-workspace.js";
|
|
18
18
|
import { installRecommendedSkills } from "./src/worker/skill-installer.js";
|
|
19
|
+
// W6 of issue #226: local swallowing pathExists copy replaced by the shared
|
|
20
|
+
// one (identical semantics; alias keeps the call site byte-identical).
|
|
21
|
+
import { pathExistsTolerant as pathExists } from "./src/shared/utils.js";
|
|
19
22
|
|
|
20
23
|
export default definePluginEntry({
|
|
21
24
|
id: "teamclaw",
|
|
@@ -84,34 +87,42 @@ function registerController(api: OpenClawPluginApi, config: ReturnType<typeof pa
|
|
|
84
87
|
});
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
role: config.role,
|
|
98
|
-
controllerUrl: currentControllerUrl,
|
|
99
|
-
registeredAt: Date.now(),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
90
|
+
/**
|
|
91
|
+
* Issue #23 (client wave): headers for worker -> controller calls, same
|
|
92
|
+
* pattern as identity.ts / worker-service.ts / worker/tools.ts. A configured
|
|
93
|
+
* device token rides X-TeamClaw-Token; without one the headers are unchanged
|
|
94
|
+
* (L0). The token value is never logged.
|
|
95
|
+
*/
|
|
96
|
+
function withDeviceToken(config: ReturnType<typeof parsePluginConfig>, headers: Record<string, string>): Record<string, string> {
|
|
97
|
+
const token = config.securityToken?.trim();
|
|
98
|
+
return token ? { ...headers, "X-TeamClaw-Token": token } : headers;
|
|
99
|
+
}
|
|
102
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Execution-event + checkpoint reporters (issue #23 review follow-up: the
|
|
103
|
+
* execution stream and resume checkpoints MUST survive device protection, so
|
|
104
|
+
* both POSTs carry the paired device token). Extracted from registerWorker
|
|
105
|
+
* as an exported factory so the dist-level client tests can exercise the
|
|
106
|
+
* real header behavior against a stub controller.
|
|
107
|
+
*/
|
|
108
|
+
export function createWorkerEventReporters(
|
|
109
|
+
config: ReturnType<typeof parsePluginConfig>,
|
|
110
|
+
logger: { warn(entry: string): void },
|
|
111
|
+
state: { getControllerUrl: () => string | null; getWorkerId: () => string | null },
|
|
112
|
+
) {
|
|
103
113
|
async function reportExecutionEvent(taskId: string, event: TaskExecutionEventInput): Promise<void> {
|
|
104
|
-
|
|
114
|
+
const controllerUrl = state.getControllerUrl();
|
|
115
|
+
if (!controllerUrl) {
|
|
105
116
|
return;
|
|
106
117
|
}
|
|
107
118
|
|
|
108
119
|
try {
|
|
109
|
-
const res = await fetch(`${
|
|
120
|
+
const res = await fetch(`${controllerUrl}/api/v1/tasks/${taskId}/execution`, {
|
|
110
121
|
method: "POST",
|
|
111
|
-
headers: { "Content-Type": "application/json" },
|
|
122
|
+
headers: withDeviceToken(config, { "Content-Type": "application/json" }),
|
|
112
123
|
body: JSON.stringify({
|
|
113
124
|
...event,
|
|
114
|
-
workerId:
|
|
125
|
+
workerId: state.getWorkerId() ?? undefined,
|
|
115
126
|
role: config.role,
|
|
116
127
|
}),
|
|
117
128
|
});
|
|
@@ -124,20 +135,47 @@ function registerWorker(api: OpenClawPluginApi, config: ReturnType<typeof parseP
|
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
async function reportCheckpoint(taskId: string, checkpoint: { lastAssistantMessage: string; progressNote?: string; sessionKey: string }): Promise<void> {
|
|
127
|
-
|
|
138
|
+
const controllerUrl = state.getControllerUrl();
|
|
139
|
+
if (!controllerUrl) {
|
|
128
140
|
return;
|
|
129
141
|
}
|
|
130
142
|
try {
|
|
131
|
-
await fetch(`${
|
|
143
|
+
await fetch(`${controllerUrl}/api/v1/tasks/${taskId}/checkpoint`, {
|
|
132
144
|
method: "POST",
|
|
133
|
-
headers: { "Content-Type": "application/json" },
|
|
134
|
-
body: JSON.stringify({ ...checkpoint, workerId:
|
|
145
|
+
headers: withDeviceToken(config, { "Content-Type": "application/json" }),
|
|
146
|
+
body: JSON.stringify({ ...checkpoint, workerId: state.getWorkerId() ?? undefined }),
|
|
135
147
|
});
|
|
136
148
|
} catch {
|
|
137
149
|
// Checkpointing is best-effort; a lost heartbeat only costs resume freshness.
|
|
138
150
|
}
|
|
139
151
|
}
|
|
140
152
|
|
|
153
|
+
return { reportExecutionEvent, reportCheckpoint };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function registerWorker(api: OpenClawPluginApi, config: ReturnType<typeof parsePluginConfig>) {
|
|
157
|
+
const logger = api.logger;
|
|
158
|
+
const messageQueue = new MessageQueue();
|
|
159
|
+
let currentControllerUrl: string | null = null;
|
|
160
|
+
let currentWorkerId: string | null = null;
|
|
161
|
+
|
|
162
|
+
function getIdentity(): WorkerIdentity | null {
|
|
163
|
+
if (!currentWorkerId || !currentControllerUrl) return null;
|
|
164
|
+
return {
|
|
165
|
+
workerId: currentWorkerId,
|
|
166
|
+
role: config.role,
|
|
167
|
+
controllerUrl: currentControllerUrl,
|
|
168
|
+
registeredAt: Date.now(),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const { reportExecutionEvent, reportCheckpoint } = createWorkerEventReporters(config, logger, {
|
|
173
|
+
// Read through getters so the reporters always see the identity the
|
|
174
|
+
// worker service has established by the time an event fires.
|
|
175
|
+
getControllerUrl: () => currentControllerUrl,
|
|
176
|
+
getWorkerId: () => currentWorkerId,
|
|
177
|
+
});
|
|
178
|
+
|
|
141
179
|
const getWorkerSessionKey = (assignment: TaskAssignmentPayload) =>
|
|
142
180
|
assignment.executionSessionKey?.trim() || `teamclaw-task-${assignment.taskId}`;
|
|
143
181
|
|
|
@@ -171,15 +209,6 @@ function registerWorker(api: OpenClawPluginApi, config: ReturnType<typeof parseP
|
|
|
171
209
|
return { sharedProjectDir, localProjectDir };
|
|
172
210
|
}
|
|
173
211
|
|
|
174
|
-
async function pathExists(targetPath: string): Promise<boolean> {
|
|
175
|
-
try {
|
|
176
|
-
await fs.access(targetPath);
|
|
177
|
-
return true;
|
|
178
|
-
} catch {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
212
|
async function syncProjectDir(sourceDir: string, destinationDir: string): Promise<boolean> {
|
|
184
213
|
if (!await pathExists(sourceDir)) {
|
|
185
214
|
return false;
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "teamclaw",
|
|
3
3
|
"name": "TeamClaw",
|
|
4
4
|
"description": "Virtual team collaboration - multiple OpenClaw instances form a virtual software company with role-based task routing.",
|
|
5
|
-
"version": "2026.11.
|
|
5
|
+
"version": "2026.11.1",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true
|
|
8
8
|
},
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"maxConcurrentTasks": {
|
|
76
76
|
"label": "Max Concurrent Tasks",
|
|
77
77
|
"hint": "number",
|
|
78
|
-
"help": "Maximum number of tasks that can be in 'in_progress' status at the same time (1
|
|
78
|
+
"help": "Maximum number of tasks that can be in 'in_progress' status at the same time (1–50)"
|
|
79
79
|
},
|
|
80
80
|
"gitEnabled": {
|
|
81
81
|
"label": "Git Collaboration",
|
|
@@ -106,6 +106,10 @@
|
|
|
106
106
|
"hint": "optional - prefer the TEAMCLAW_GITHUB_CLIENT_SECRET env var",
|
|
107
107
|
"help": "GitHub App OAuth client secret; the TEAMCLAW_GITHUB_CLIENT_SECRET environment variable takes precedence"
|
|
108
108
|
},
|
|
109
|
+
"security": {
|
|
110
|
+
"label": "Device Pairing Security",
|
|
111
|
+
"help": "Controller device-pairing options; autoPair allows LAN devices to pair with zero input (POST /api/v1/security/pair-auto), disable it to require a pairing code for every new device"
|
|
112
|
+
},
|
|
109
113
|
"agentIsolationMode": {
|
|
110
114
|
"label": "Agent Isolation Mode",
|
|
111
115
|
"help": "Use a dedicated TeamClaw agent/workspace by default, or the legacy shared main-agent mode"
|
|
@@ -302,6 +306,23 @@
|
|
|
302
306
|
"default": "",
|
|
303
307
|
"description": "GitHub App OAuth client secret; the TEAMCLAW_GITHUB_CLIENT_SECRET environment variable takes precedence"
|
|
304
308
|
},
|
|
309
|
+
"security": {
|
|
310
|
+
"type": "object",
|
|
311
|
+
"default": {},
|
|
312
|
+
"description": "Controller device-pairing security (issue #23); protection itself is enabled per-team via POST /api/v1/security/enable",
|
|
313
|
+
"properties": {
|
|
314
|
+
"autoPair": {
|
|
315
|
+
"type": "boolean",
|
|
316
|
+
"default": true,
|
|
317
|
+
"description": "Allow zero-input pairing from LAN peers (POST /api/v1/security/pair-auto); disable to require a pairing code for every new device"
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
"securityToken": {
|
|
322
|
+
"type": "string",
|
|
323
|
+
"default": "",
|
|
324
|
+
"description": "Device pairing token for a protected controller (issue #23); written by `teamclaw pair`, sent as X-TeamClaw-Token on API calls. Leave empty for unpaired local mode"
|
|
325
|
+
},
|
|
305
326
|
"agentIsolationMode": {
|
|
306
327
|
"type": "string",
|
|
307
328
|
"enum": [
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -105,6 +105,26 @@ function buildConfigSchema() {
|
|
|
105
105
|
default: "",
|
|
106
106
|
description: "GitHub App OAuth client secret; the TEAMCLAW_GITHUB_CLIENT_SECRET environment variable takes precedence",
|
|
107
107
|
},
|
|
108
|
+
security: {
|
|
109
|
+
type: "object" as const,
|
|
110
|
+
default: {},
|
|
111
|
+
description: "Controller device-pairing security (issue #23); protection itself is enabled per-team via POST /api/v1/security/enable",
|
|
112
|
+
properties: {
|
|
113
|
+
autoPair: {
|
|
114
|
+
type: "boolean" as const,
|
|
115
|
+
default: true,
|
|
116
|
+
description: "Allow zero-input pairing from LAN peers (POST /api/v1/security/pair-auto); disable to require a pairing code for every new device",
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
securityToken: {
|
|
121
|
+
type: "string" as const,
|
|
122
|
+
default: "",
|
|
123
|
+
// Deliberately NO uiHints entry: the token is a secret written by
|
|
124
|
+
// `teamclaw pair` / the desktop pairing flow and must never be
|
|
125
|
+
// echoed back through config surfaces or logs.
|
|
126
|
+
description: "Device pairing token for a protected controller (issue #23); written by `teamclaw pair`, sent as X-TeamClaw-Token on API calls. Leave empty for unpaired local mode",
|
|
127
|
+
},
|
|
108
128
|
agentIsolationMode: {
|
|
109
129
|
type: "string" as const,
|
|
110
130
|
enum: ["independent", "main"],
|
|
@@ -309,6 +329,10 @@ function buildConfigSchema() {
|
|
|
309
329
|
hint: "optional - prefer the TEAMCLAW_GITHUB_CLIENT_SECRET env var",
|
|
310
330
|
help: "GitHub App OAuth client secret; the TEAMCLAW_GITHUB_CLIENT_SECRET environment variable takes precedence",
|
|
311
331
|
},
|
|
332
|
+
security: {
|
|
333
|
+
label: "Device Pairing Security",
|
|
334
|
+
help: "Controller device-pairing options; autoPair allows LAN devices to pair with zero input (POST /api/v1/security/pair-auto), disable it to require a pairing code for every new device",
|
|
335
|
+
},
|
|
312
336
|
agentIsolationMode: {
|
|
313
337
|
label: "Agent Isolation Mode",
|
|
314
338
|
help: "Use a dedicated TeamClaw agent/workspace by default, or the legacy shared main-agent mode",
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Issue #226 W2 (route-table carve-up): the GitHub login/logout route
|
|
2
|
+
// handlers (plus their private HTML-rendering helpers) moved verbatim from
|
|
3
|
+
// route-table.ts (PR-D had moved them verbatim from http-server.ts before
|
|
4
|
+
// that) - bodies byte-identical, only the module home changed. route-table.ts
|
|
5
|
+
// keeps the table entries that bind these handlers. Like security.ts, this
|
|
6
|
+
// module imports route-table.js as TYPE ONLY (RouteContext), so the module
|
|
7
|
+
// graph stays acyclic.
|
|
8
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
9
|
+
import type { PluginConfig } from "../types.js";
|
|
10
|
+
import { parseJsonBody, sendJson, sendError } from "../protocol.js";
|
|
11
|
+
import { getGithubAuthManager } from "./github-auth.js";
|
|
12
|
+
import type { RouteContext } from "./route-table.js";
|
|
13
|
+
|
|
14
|
+
function resolveRequestOrigin(req: IncomingMessage, config: PluginConfig): string {
|
|
15
|
+
const host = req.headers.host;
|
|
16
|
+
if (typeof host === "string" && host.trim()) {
|
|
17
|
+
return `http://${host.trim()}`;
|
|
18
|
+
}
|
|
19
|
+
return `http://127.0.0.1:${config.port}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function escapeHtmlText(value: string): string {
|
|
23
|
+
return value
|
|
24
|
+
.replace(/&/g, "&")
|
|
25
|
+
.replace(/</g, "<")
|
|
26
|
+
.replace(/>/g, ">")
|
|
27
|
+
.replace(/"/g, """)
|
|
28
|
+
.replace(/'/g, "'");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function sendGithubCallbackHtml(res: ServerResponse, statusCode: number, title: string, message: string): void {
|
|
32
|
+
const html = [
|
|
33
|
+
"<!DOCTYPE html><html><head><meta charset=\"utf-8\">",
|
|
34
|
+
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">",
|
|
35
|
+
`<title>${escapeHtmlText(title)}</title>`,
|
|
36
|
+
"<style>body{font-family:-apple-system,system-ui,sans-serif;display:flex;min-height:100vh;align-items:center;justify-content:center;margin:0;background:#0f1117;color:#e6e8ee}main{max-width:520px;padding:32px 40px;border:1px solid #2a2f3a;border-radius:14px;background:#161923;text-align:center}h1{font-size:20px;margin:0 0 10px}p{margin:6px 0;color:#a8b0c0;line-height:1.6}</style>",
|
|
37
|
+
"</head><body><main>",
|
|
38
|
+
`<h1>${escapeHtmlText(title)}</h1>`,
|
|
39
|
+
`<p>${escapeHtmlText(message)}</p>`,
|
|
40
|
+
"</main></body></html>",
|
|
41
|
+
].join("");
|
|
42
|
+
res.writeHead(statusCode, {
|
|
43
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
44
|
+
"Content-Length": Buffer.byteLength(html),
|
|
45
|
+
});
|
|
46
|
+
res.end(html);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function githubAuthStatusRoute(ctx: RouteContext): Promise<void> {
|
|
50
|
+
const { req, res, deps } = ctx;
|
|
51
|
+
const { config, logger } = deps;
|
|
52
|
+
try {
|
|
53
|
+
const status = await getGithubAuthManager(config, logger).getStatus(resolveRequestOrigin(req, config));
|
|
54
|
+
sendJson(res, 200, status);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
sendError(res, 500, err instanceof Error ? err.message : "failed to read GitHub login status");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function githubAuthLoginRoute(ctx: RouteContext): Promise<void> {
|
|
61
|
+
const { req, res, deps } = ctx;
|
|
62
|
+
const { config, logger } = deps;
|
|
63
|
+
let flow: string | undefined;
|
|
64
|
+
try {
|
|
65
|
+
const body = await parseJsonBody(req) as { flow?: unknown };
|
|
66
|
+
if (typeof body?.flow === "string") {
|
|
67
|
+
flow = body.flow.trim();
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
// No body or invalid body: fall through to the default (device) flow.
|
|
71
|
+
}
|
|
72
|
+
const manager = getGithubAuthManager(config, logger);
|
|
73
|
+
try {
|
|
74
|
+
const loginPageUrl = resolveRequestOrigin(req, config).replace(/\/+$/, "") + "/ui/auth/github";
|
|
75
|
+
if (flow === "web") {
|
|
76
|
+
// Web flow needs a client secret for the code exchange; the device
|
|
77
|
+
// flow (default) is fully secretless.
|
|
78
|
+
const start = manager.beginLogin(resolveRequestOrigin(req, config));
|
|
79
|
+
sendJson(res, 200, { mode: "web", loginPageUrl, ...start });
|
|
80
|
+
} else {
|
|
81
|
+
const start = await manager.beginDeviceLogin();
|
|
82
|
+
// authorizeUrl intentionally points at our standalone login page so
|
|
83
|
+
// older UI clients that just open response.authorizeUrl land on the
|
|
84
|
+
// device-code page instead of a dead web-flow URL.
|
|
85
|
+
sendJson(res, 200, { mode: "device", loginPageUrl, authorizeUrl: loginPageUrl, ...start });
|
|
86
|
+
}
|
|
87
|
+
logger.info(`Controller: GitHub login flow started (${flow === "web" ? "web" : "device"})`);
|
|
88
|
+
} catch (err) {
|
|
89
|
+
sendError(res, 400, err instanceof Error ? err.message : "failed to start GitHub login");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function githubAuthCallbackRoute(ctx: RouteContext): Promise<void> {
|
|
94
|
+
const { req, res, requestUrl, deps } = ctx;
|
|
95
|
+
const { config, logger } = deps;
|
|
96
|
+
const callbackError = requestUrl.searchParams.get("error");
|
|
97
|
+
if (callbackError) {
|
|
98
|
+
const description = requestUrl.searchParams.get("error_description") ?? "";
|
|
99
|
+
logger.warn(`Controller: GitHub login was denied (${callbackError})`);
|
|
100
|
+
sendGithubCallbackHtml(
|
|
101
|
+
res,
|
|
102
|
+
400,
|
|
103
|
+
"GitHub login failed",
|
|
104
|
+
`Authorization was denied: ${callbackError}${description ? ` (${description})` : ""}`,
|
|
105
|
+
);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const code = requestUrl.searchParams.get("code") ?? "";
|
|
109
|
+
const state = requestUrl.searchParams.get("state") ?? "";
|
|
110
|
+
try {
|
|
111
|
+
const account = await getGithubAuthManager(config, logger).completeLogin({
|
|
112
|
+
code: code || undefined,
|
|
113
|
+
state: state || undefined,
|
|
114
|
+
});
|
|
115
|
+
logger.info(`Controller: GitHub login completed for @${account.login}`);
|
|
116
|
+
sendGithubCallbackHtml(
|
|
117
|
+
res,
|
|
118
|
+
200,
|
|
119
|
+
"GitHub login successful",
|
|
120
|
+
`Signed in as @${account.login}(GitHub 登录成功,可关闭本页返回 TeamClaw)。`,
|
|
121
|
+
);
|
|
122
|
+
} catch (err) {
|
|
123
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
124
|
+
logger.warn(`Controller: GitHub login callback failed: ${message}`);
|
|
125
|
+
sendGithubCallbackHtml(res, 400, "GitHub login failed", `${message}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function githubAuthLogoutRoute(ctx: RouteContext): Promise<void> {
|
|
130
|
+
const { res, deps } = ctx;
|
|
131
|
+
const { config, logger } = deps;
|
|
132
|
+
try {
|
|
133
|
+
await getGithubAuthManager(config, logger).logout();
|
|
134
|
+
sendJson(res, 200, { ok: true });
|
|
135
|
+
} catch (err) {
|
|
136
|
+
sendError(res, 500, err instanceof Error ? err.message : "failed to sign out of GitHub");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function githubAuthRefreshRoute(ctx: RouteContext): Promise<void> {
|
|
141
|
+
const { res, deps } = ctx;
|
|
142
|
+
const { config, logger } = deps;
|
|
143
|
+
try {
|
|
144
|
+
const store = await getGithubAuthManager(config, logger).forceRefresh();
|
|
145
|
+
sendJson(res, 200, { ok: true, account: store.account, expiresAt: store.expiresAt });
|
|
146
|
+
} catch (err) {
|
|
147
|
+
sendError(res, 400, err instanceof Error ? err.message : "failed to refresh the GitHub token");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export {
|
|
152
|
+
githubAuthStatusRoute,
|
|
153
|
+
githubAuthLoginRoute,
|
|
154
|
+
githubAuthCallbackRoute,
|
|
155
|
+
githubAuthLogoutRoute,
|
|
156
|
+
githubAuthRefreshRoute,
|
|
157
|
+
};
|
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
import { generateId, parseJsonBody, sendError, sendJson } from "../protocol.js";
|
|
17
17
|
import { ensureTeamMessageContract } from "../interaction-contracts.js";
|
|
18
18
|
import { validateActiveRoleId } from "../profile-loader.js";
|
|
19
|
-
import { normalizeClarificationQuestionSchema } from "
|
|
19
|
+
import { normalizeClarificationQuestionSchema } from "../shared/clarification-schema.js";
|
|
20
20
|
import {
|
|
21
21
|
cancelTaskExecution,
|
|
22
22
|
recordTaskExecutionEvent,
|
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
RoleId,
|
|
16
16
|
TaskInfo,
|
|
17
17
|
TaskPriority,
|
|
18
|
+
TaskWorkflowContext,
|
|
18
19
|
TeamMessage,
|
|
19
20
|
TeamState,
|
|
20
21
|
WorkerTaskResultContract,
|
|
@@ -576,6 +577,12 @@ export async function createControllerManagedTask(
|
|
|
576
577
|
controllerSessionKey?: string;
|
|
577
578
|
projectName?: string;
|
|
578
579
|
recommendedSkills?: string[];
|
|
580
|
+
/**
|
|
581
|
+
* Design 2.4 workflow-chain context: when present the task is a workflow
|
|
582
|
+
* step task (createdBy "workflow") and the completion hook routes the
|
|
583
|
+
* chain from it. Untouched for controller/other creators.
|
|
584
|
+
*/
|
|
585
|
+
workflow?: TaskWorkflowContext;
|
|
579
586
|
},
|
|
580
587
|
deps: ControllerTaskDomainDeps,
|
|
581
588
|
): Promise<TaskInfo | undefined> {
|
|
@@ -605,6 +612,7 @@ export async function createControllerManagedTask(
|
|
|
605
612
|
recommendedSkills: normalizedRecommendedSkills.length > 0 ? normalizedRecommendedSkills : undefined,
|
|
606
613
|
controllerRunId: input.createdBy === "controller" ? input.controllerRunId : undefined,
|
|
607
614
|
controllerSessionKey: normalizedSessionKey,
|
|
615
|
+
workflow: input.workflow,
|
|
608
616
|
projectId,
|
|
609
617
|
projectDir,
|
|
610
618
|
createdAt: now,
|
|
@@ -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
|
+
};
|