@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
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// W1 of issue #226 (worker-provisioning god-file split): worker config
|
|
2
|
+
// synthesis, controller auth-profile copy and the no-proxy env builder,
|
|
3
|
+
// extracted VERBATIM from controller/worker-provisioning.ts (zero behavior
|
|
4
|
+
// change; only the functions consumed by the facade / process backend gained
|
|
5
|
+
// an `export`). This module never imports worker-provisioning.ts or the
|
|
6
|
+
// provisioning backends - dependency direction is one-way into it.
|
|
7
|
+
import fs from "node:fs/promises";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import JSON5 from "json5";
|
|
10
|
+
import { resolveDefaultOpenClawConfigPath, resolveDefaultOpenClawStateDir, resolveDefaultAgentDir, resolveTeamClawAgentDir, resolveTeamClawAgentWorkspaceRootDir, TEAMCLAW_AGENT_ID, } from "../openclaw-workspace.js";
|
|
11
|
+
import { cloneJson, pathExists, sanitizePathSegment } from "../shared/utils.js";
|
|
12
|
+
export function buildProvisionedWorkerConfig(baseConfig, controllerConfig, spec) {
|
|
13
|
+
const config = cloneJson(baseConfig);
|
|
14
|
+
delete config.channels;
|
|
15
|
+
const agents = ensureRecord(config.agents);
|
|
16
|
+
const agentDefaults = ensureRecord(agents.defaults);
|
|
17
|
+
delete agentDefaults.repoRoot;
|
|
18
|
+
if (spec.workspaceDir) {
|
|
19
|
+
agentDefaults.workspace = spec.workspaceDir;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
delete agentDefaults.workspace;
|
|
23
|
+
}
|
|
24
|
+
// The host controller may run a newer openclaw that persists the keyed
|
|
25
|
+
// agents.entries schema (e.g. agents.entries.teamclaw.model written by the
|
|
26
|
+
// model-configuration feature). Provisioned workers can run an older
|
|
27
|
+
// openclaw that rejects unknown agents keys ("Unrecognized key: entries"),
|
|
28
|
+
// so fold the teamclaw entry's model back into the legacy
|
|
29
|
+
// agents.defaults.model and drop the entries map. New-schema workers also
|
|
30
|
+
// accept agents.defaults, keeping the folded config compatible both ways.
|
|
31
|
+
const agentsRecord = agents;
|
|
32
|
+
if (agentsRecord.entries && typeof agentsRecord.entries === "object") {
|
|
33
|
+
const entryModel = agentsRecord.entries[TEAMCLAW_AGENT_ID]?.model;
|
|
34
|
+
if (entryModel && !agentDefaults.model) {
|
|
35
|
+
agentDefaults.model = entryModel;
|
|
36
|
+
}
|
|
37
|
+
// Container backends may run older openclaw runtimes that reject the
|
|
38
|
+
// keyed agents schema ("Unrecognized key: entries") - fold down to
|
|
39
|
+
// legacy defaults there. Process workers share the controller's own
|
|
40
|
+
// runtime, which REQUIRES at least one entry ("agents.entries must
|
|
41
|
+
// contain at least one configured agent" crash-loop, exit 78, observed
|
|
42
|
+
// 2026-11-03 when entries was deleted unconditionally) - keep only the
|
|
43
|
+
// teamclaw worker entry for them.
|
|
44
|
+
const containerized = controllerConfig.workerProvisioningType === "docker" ||
|
|
45
|
+
controllerConfig.workerProvisioningType === "kubernetes";
|
|
46
|
+
if (containerized) {
|
|
47
|
+
delete agentsRecord.entries;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
agentsRecord.entries = {
|
|
51
|
+
[TEAMCLAW_AGENT_ID]: agentsRecord.entries[TEAMCLAW_AGENT_ID] ?? {},
|
|
52
|
+
};
|
|
53
|
+
// Pruning entries can dangle defaults.heartbeat.agentId /
|
|
54
|
+
// defaults.systemAgent.agentId ("main" no longer exists in the worker
|
|
55
|
+
// config) - remap any dangling agentId reference to the surviving
|
|
56
|
+
// teamclaw entry.
|
|
57
|
+
for (const sectionKey of Object.keys(agentDefaults)) {
|
|
58
|
+
const section = agentDefaults[sectionKey];
|
|
59
|
+
if (section &&
|
|
60
|
+
typeof section === "object" &&
|
|
61
|
+
typeof section.agentId === "string" &&
|
|
62
|
+
!agentsRecord.entries[section.agentId]) {
|
|
63
|
+
section.agentId = TEAMCLAW_AGENT_ID;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
agents.defaults = agentDefaults;
|
|
69
|
+
config.agents = agents;
|
|
70
|
+
const gateway = ensureRecord(config.gateway);
|
|
71
|
+
gateway.mode = "local";
|
|
72
|
+
// Workers running inside Docker/K8s containers must bind on all
|
|
73
|
+
// interfaces so the controller (in a sibling container) can reach them.
|
|
74
|
+
gateway.bind =
|
|
75
|
+
controllerConfig.workerProvisioningType === "docker" ||
|
|
76
|
+
controllerConfig.workerProvisioningType === "kubernetes"
|
|
77
|
+
? "lan"
|
|
78
|
+
: "loopback";
|
|
79
|
+
gateway.port = spec.gatewayPort;
|
|
80
|
+
delete gateway.remote;
|
|
81
|
+
config.gateway = gateway;
|
|
82
|
+
const plugins = ensureRecord(config.plugins);
|
|
83
|
+
plugins.enabled = true;
|
|
84
|
+
if (controllerConfig.workerProvisioningType === "docker" || controllerConfig.workerProvisioningType === "kubernetes") {
|
|
85
|
+
delete plugins.load;
|
|
86
|
+
}
|
|
87
|
+
const entries = ensureRecord(plugins.entries);
|
|
88
|
+
const teamclawEntry = ensureRecord(entries.teamclaw);
|
|
89
|
+
teamclawEntry.enabled = true;
|
|
90
|
+
const teamclawConfig = ensureRecord(teamclawEntry.config);
|
|
91
|
+
teamclawConfig.mode = "worker";
|
|
92
|
+
teamclawConfig.processModel = "multi";
|
|
93
|
+
teamclawConfig.role = spec.role;
|
|
94
|
+
teamclawConfig.port = spec.workerPort;
|
|
95
|
+
teamclawConfig.controllerUrl = spec.controllerUrl;
|
|
96
|
+
teamclawConfig.teamName = controllerConfig.teamName;
|
|
97
|
+
teamclawConfig.heartbeatIntervalMs = controllerConfig.heartbeatIntervalMs;
|
|
98
|
+
teamclawConfig.taskTimeoutMs = controllerConfig.taskTimeoutMs;
|
|
99
|
+
teamclawConfig.gitEnabled = controllerConfig.gitEnabled;
|
|
100
|
+
teamclawConfig.gitRemoteUrl = controllerConfig.gitRemoteUrl;
|
|
101
|
+
teamclawConfig.gitDefaultBranch = controllerConfig.gitDefaultBranch;
|
|
102
|
+
teamclawConfig.gitAuthorName = controllerConfig.gitAuthorName;
|
|
103
|
+
teamclawConfig.gitAuthorEmail = controllerConfig.gitAuthorEmail;
|
|
104
|
+
teamclawConfig.workerProvisioningType = "none";
|
|
105
|
+
teamclawConfig.workerProvisioningControllerUrl = "";
|
|
106
|
+
teamclawConfig.workerProvisioningRoles = [];
|
|
107
|
+
teamclawConfig.workerProvisioningMinPerRole = 0;
|
|
108
|
+
teamclawConfig.workerProvisioningMaxPerRole = 10;
|
|
109
|
+
teamclawConfig.workerProvisioningIdleTtlMs = controllerConfig.workerProvisioningIdleTtlMs;
|
|
110
|
+
teamclawConfig.workerProvisioningStartupTimeoutMs = controllerConfig.workerProvisioningStartupTimeoutMs;
|
|
111
|
+
teamclawConfig.workerProvisioningImage = "";
|
|
112
|
+
teamclawConfig.workerProvisioningPassEnv = [];
|
|
113
|
+
teamclawConfig.workerProvisioningExtraEnv = {};
|
|
114
|
+
teamclawConfig.workerProvisioningDockerNetwork = "";
|
|
115
|
+
teamclawConfig.workerProvisioningDockerMounts = [];
|
|
116
|
+
teamclawConfig.workerProvisioningWorkspaceRoot = "";
|
|
117
|
+
teamclawConfig.workerProvisioningDockerWorkspaceVolume = "";
|
|
118
|
+
teamclawConfig.workerProvisioningKubernetesNamespace = "default";
|
|
119
|
+
teamclawConfig.workerProvisioningKubernetesContext = "";
|
|
120
|
+
teamclawConfig.workerProvisioningKubernetesServiceAccount = "";
|
|
121
|
+
teamclawConfig.workerProvisioningKubernetesImagePullSecrets = [];
|
|
122
|
+
teamclawConfig.workerProvisioningKubernetesWorkspacePersistentVolumeClaim = "";
|
|
123
|
+
teamclawConfig.workerProvisioningKubernetesLabels = {};
|
|
124
|
+
teamclawConfig.workerProvisioningKubernetesAnnotations = {};
|
|
125
|
+
teamclawEntry.config = teamclawConfig;
|
|
126
|
+
entries.teamclaw = teamclawEntry;
|
|
127
|
+
plugins.entries = entries;
|
|
128
|
+
config.plugins = plugins;
|
|
129
|
+
return config;
|
|
130
|
+
}
|
|
131
|
+
export async function loadOpenClawConfig(configPath) {
|
|
132
|
+
const raw = await fs.readFile(configPath, "utf8");
|
|
133
|
+
return parseLooseJsonObject(raw, configPath);
|
|
134
|
+
}
|
|
135
|
+
export async function copyControllerAuthProfiles(stateDir) {
|
|
136
|
+
const candidateControllerStateDirs = [
|
|
137
|
+
path.dirname(resolveDefaultOpenClawConfigPath()),
|
|
138
|
+
resolveDefaultOpenClawStateDir(),
|
|
139
|
+
];
|
|
140
|
+
const candidateAuthProfilePaths = [
|
|
141
|
+
path.join(resolveTeamClawAgentDir(), "auth-profiles.json"),
|
|
142
|
+
path.join(resolveDefaultAgentDir(), "auth-profiles.json"),
|
|
143
|
+
...candidateControllerStateDirs.flatMap((controllerStateDir) => [
|
|
144
|
+
path.join(controllerStateDir, "agents", TEAMCLAW_AGENT_ID, "agent", "auth-profiles.json"),
|
|
145
|
+
path.join(controllerStateDir, "agents", "main", "agent", "auth-profiles.json"),
|
|
146
|
+
]),
|
|
147
|
+
].filter((value, index, values) => values.indexOf(value) === index);
|
|
148
|
+
let controllerAuthProfilesPath;
|
|
149
|
+
for (const candidatePath of candidateAuthProfilePaths) {
|
|
150
|
+
if (await pathExists(candidatePath)) {
|
|
151
|
+
controllerAuthProfilesPath = candidatePath;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (!controllerAuthProfilesPath) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const runtimeAuthProfilePaths = [
|
|
159
|
+
path.join(stateDir, "agents", TEAMCLAW_AGENT_ID, "agent", "auth-profiles.json"),
|
|
160
|
+
path.join(stateDir, "agents", "main", "agent", "auth-profiles.json"),
|
|
161
|
+
];
|
|
162
|
+
for (const runtimeAuthProfilesPath of runtimeAuthProfilePaths) {
|
|
163
|
+
await fs.mkdir(path.dirname(runtimeAuthProfilesPath), { recursive: true });
|
|
164
|
+
await fs.copyFile(controllerAuthProfilesPath, runtimeAuthProfilesPath);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export function appendNoProxyEntries(env, controllerUrl) {
|
|
168
|
+
const requiredEntries = resolveRequiredNoProxyEntries(controllerUrl);
|
|
169
|
+
if (requiredEntries.length === 0) {
|
|
170
|
+
return env;
|
|
171
|
+
}
|
|
172
|
+
const upperBase = env.NO_PROXY ?? process.env.NO_PROXY ?? process.env.no_proxy ?? "";
|
|
173
|
+
const lowerBase = env.no_proxy ?? process.env.no_proxy ?? env.NO_PROXY ?? process.env.NO_PROXY ?? "";
|
|
174
|
+
env.NO_PROXY = mergeNoProxyEntries(upperBase, requiredEntries);
|
|
175
|
+
env.no_proxy = mergeNoProxyEntries(lowerBase, requiredEntries);
|
|
176
|
+
return env;
|
|
177
|
+
}
|
|
178
|
+
function resolveRequiredNoProxyEntries(controllerUrl) {
|
|
179
|
+
const required = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
180
|
+
try {
|
|
181
|
+
const host = new URL(controllerUrl).hostname.trim();
|
|
182
|
+
if (host) {
|
|
183
|
+
required.add(host);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// Ignore malformed controller URLs; worker registration will fail separately.
|
|
188
|
+
}
|
|
189
|
+
return Array.from(required);
|
|
190
|
+
}
|
|
191
|
+
function mergeNoProxyEntries(existing, requiredEntries) {
|
|
192
|
+
const tokens = new Map();
|
|
193
|
+
for (const entry of existing.split(",")) {
|
|
194
|
+
const trimmed = entry.trim();
|
|
195
|
+
if (!trimmed) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
tokens.set(trimmed.toLowerCase(), trimmed);
|
|
199
|
+
}
|
|
200
|
+
for (const entry of requiredEntries) {
|
|
201
|
+
const trimmed = entry.trim();
|
|
202
|
+
if (!trimmed) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
tokens.set(trimmed.toLowerCase(), trimmed);
|
|
206
|
+
}
|
|
207
|
+
return Array.from(tokens.values()).join(",");
|
|
208
|
+
}
|
|
209
|
+
function ensureRecord(value) {
|
|
210
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
211
|
+
? { ...value }
|
|
212
|
+
: {};
|
|
213
|
+
}
|
|
214
|
+
function parseLooseJsonObject(raw, configPath) {
|
|
215
|
+
try {
|
|
216
|
+
return JSON5.parse(raw);
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
throw new Error(`Failed to parse OpenClaw config at ${configPath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
export function buildProvisionedWorkspaceDir(provider, config, role, workerId) {
|
|
223
|
+
// Process-type workers run on the same host — share the controller's workspace
|
|
224
|
+
// so that file artifacts (previews, deliverables) are immediately visible to
|
|
225
|
+
// the controller without requiring git sync or file transfer.
|
|
226
|
+
if (provider === "process") {
|
|
227
|
+
return resolveTeamClawAgentWorkspaceRootDir();
|
|
228
|
+
}
|
|
229
|
+
if ((provider !== "docker" && provider !== "kubernetes") ||
|
|
230
|
+
!config.workerProvisioningWorkspaceRoot) {
|
|
231
|
+
return "";
|
|
232
|
+
}
|
|
233
|
+
return path.posix.join(config.workerProvisioningWorkspaceRoot, sanitizePathSegment(config.teamName), sanitizePathSegment(role), sanitizePathSegment(workerId));
|
|
234
|
+
}
|
|
235
|
+
export function getConfiguredWorkerWorkspaceDir(config) {
|
|
236
|
+
const agents = ensureRecord(config.agents);
|
|
237
|
+
const defaults = ensureRecord(agents.defaults);
|
|
238
|
+
return typeof defaults.workspace === "string" ? defaults.workspace : "";
|
|
239
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { sendJson, sendError } from "../protocol.js";
|
|
2
|
-
import { getActiveProfile } from "../profile-loader.js";
|
|
3
|
-
import { ensureControllerGitRepo, exportControllerGitBundle } from "../git-collaboration.js";
|
|
1
|
+
import { sendJson, sendError, pinnedCorsAllowOrigin, readRequestBody } from "../protocol.js";
|
|
2
|
+
import { getActiveProfile, validateActiveRoleId } from "../profile-loader.js";
|
|
3
|
+
import { ensureControllerGitRepo, exportControllerGitBundle, importControllerGitBundle } from "../git-collaboration.js";
|
|
4
|
+
import { recordTaskExecutionEvent } from "./task-execution.js";
|
|
4
5
|
export async function refreshControllerRepoState(deps) {
|
|
5
6
|
// Phase 2.3: the ACTIVE PROFILE's git switch outranks the legacy config
|
|
6
7
|
// knob here - refreshing (or stamping) repo state for a profile that
|
|
@@ -51,7 +52,12 @@ export async function handleRepoBundleRequest(deps, res) {
|
|
|
51
52
|
"Content-Type": "application/octet-stream",
|
|
52
53
|
"Content-Length": exported.data.byteLength,
|
|
53
54
|
"Content-Disposition": `attachment; filename="${exported.filename}"`,
|
|
54
|
-
|
|
55
|
+
// Issue #23 security review follow-up: this response used to hardcode
|
|
56
|
+
// the L0 wildcard, which silently WIDENED a CORS origin the security
|
|
57
|
+
// gate had pinned while device protection is on. Honor the pinned
|
|
58
|
+
// header via the shared protocol helper; unpinned (protection off /
|
|
59
|
+
// non-browser) keeps the historical "*" byte for byte.
|
|
60
|
+
"Access-Control-Allow-Origin": pinnedCorsAllowOrigin(res),
|
|
55
61
|
"Access-Control-Allow-Methods": "GET, POST, PATCH, DELETE, OPTIONS",
|
|
56
62
|
"Access-Control-Allow-Headers": "Content-Type",
|
|
57
63
|
});
|
|
@@ -61,3 +67,63 @@ export async function handleRepoBundleRequest(deps, res) {
|
|
|
61
67
|
sendError(res, 503, err instanceof Error ? err.message : String(err));
|
|
62
68
|
}
|
|
63
69
|
}
|
|
70
|
+
// POST /api/v1/repo/import - issue #226 W2: moved verbatim from route-table.ts
|
|
71
|
+
// (which had moved it verbatim from http-server.ts with PR-D). Keeps the
|
|
72
|
+
// RouteContext shape; route-table's table entry binds it directly.
|
|
73
|
+
export async function repoImportRoute(ctx) {
|
|
74
|
+
const { req, res, requestUrl, deps } = ctx;
|
|
75
|
+
const { config, logger, updateTeamState } = deps;
|
|
76
|
+
const body = await readRequestBody(req);
|
|
77
|
+
if (!body.length) {
|
|
78
|
+
sendError(res, 400, "bundle body is required");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const taskId = typeof requestUrl.searchParams.get("taskId") === "string" && requestUrl.searchParams.get("taskId")
|
|
82
|
+
? requestUrl.searchParams.get("taskId")
|
|
83
|
+
: undefined;
|
|
84
|
+
const workerId = typeof requestUrl.searchParams.get("workerId") === "string" && requestUrl.searchParams.get("workerId")
|
|
85
|
+
? requestUrl.searchParams.get("workerId")
|
|
86
|
+
: undefined;
|
|
87
|
+
const role = validateActiveRoleId(requestUrl.searchParams.get("role"));
|
|
88
|
+
try {
|
|
89
|
+
const imported = await importControllerGitBundle(config, logger, body, { taskId, workerId });
|
|
90
|
+
updateTeamState((s) => {
|
|
91
|
+
s.repo = imported.repo;
|
|
92
|
+
});
|
|
93
|
+
if (taskId) {
|
|
94
|
+
recordTaskExecutionEvent(taskId, {
|
|
95
|
+
type: imported.merged || imported.alreadyUpToDate ? "lifecycle" : "error",
|
|
96
|
+
phase: imported.merged
|
|
97
|
+
? "repo_imported"
|
|
98
|
+
: imported.alreadyUpToDate
|
|
99
|
+
? "repo_import_skipped"
|
|
100
|
+
: "repo_import_failed",
|
|
101
|
+
source: "controller",
|
|
102
|
+
message: imported.message,
|
|
103
|
+
workerId,
|
|
104
|
+
role,
|
|
105
|
+
}, deps);
|
|
106
|
+
}
|
|
107
|
+
sendJson(res, imported.merged || imported.alreadyUpToDate ? 200 : 409, {
|
|
108
|
+
repo: imported.repo,
|
|
109
|
+
merged: imported.merged,
|
|
110
|
+
fastForwarded: imported.fastForwarded,
|
|
111
|
+
alreadyUpToDate: imported.alreadyUpToDate,
|
|
112
|
+
message: imported.message,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
117
|
+
if (taskId) {
|
|
118
|
+
recordTaskExecutionEvent(taskId, {
|
|
119
|
+
type: "error",
|
|
120
|
+
phase: "repo_import_failed",
|
|
121
|
+
source: "controller",
|
|
122
|
+
message,
|
|
123
|
+
workerId,
|
|
124
|
+
role,
|
|
125
|
+
}, deps);
|
|
126
|
+
}
|
|
127
|
+
sendError(res, 500, message);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Issue #226 W2 (route-table carve-up): the delivery-report / health route
|
|
2
|
+
// handlers moved verbatim from route-table.ts (PR-D had moved them verbatim
|
|
3
|
+
// from http-server.ts before that) - bodies byte-identical, only the module
|
|
4
|
+
// home changed. route-table.ts keeps the table entries that bind these
|
|
5
|
+
// handlers. Like security.ts, this module imports route-table.js as TYPE
|
|
6
|
+
// ONLY (RouteContext), so the module graph stays acyclic.
|
|
7
|
+
import { sendJson, sendError } from "../protocol.js";
|
|
8
|
+
import { getTeamClawModelReadiness } from "../openclaw-workspace.js";
|
|
9
|
+
import { generateDeliveryReport, renderReportHtml } from "./delivery-report.js";
|
|
10
|
+
import { normalizeControllerIntakeSessionKey } from "./task-execution.js";
|
|
11
|
+
import { getEffectiveStartupReadiness } from "./worker-routes.js";
|
|
12
|
+
// GET /api/v1/reports — list all delivery reports
|
|
13
|
+
function reportsListRoute(ctx) {
|
|
14
|
+
const { res, deps } = ctx;
|
|
15
|
+
const state = deps.getTeamState();
|
|
16
|
+
const reports = Object.values(state?.reports ?? {}).sort((a, b) => b.generatedAt - a.generatedAt);
|
|
17
|
+
sendJson(res, 200, { reports });
|
|
18
|
+
}
|
|
19
|
+
// GET /api/v1/reports/:sessionKey — serve delivery report page
|
|
20
|
+
async function reportsSessionRoute(ctx) {
|
|
21
|
+
const { req, res, pathname, deps } = ctx;
|
|
22
|
+
const sessionKey = decodeURIComponent(pathname.slice("/api/v1/reports/".length));
|
|
23
|
+
const state = deps.getTeamState();
|
|
24
|
+
if (!state) {
|
|
25
|
+
sendError(res, 503, "Team state not loaded");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const report = generateDeliveryReport(sessionKey, state, normalizeControllerIntakeSessionKey);
|
|
29
|
+
if (!report) {
|
|
30
|
+
sendError(res, 404, "No report found for this session");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const accept = (req.headers["accept"] ?? "").toLowerCase();
|
|
34
|
+
if (accept.includes("application/json")) {
|
|
35
|
+
sendJson(res, 200, { report });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const html = renderReportHtml(report);
|
|
39
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Content-Length": Buffer.byteLength(html, "utf-8") });
|
|
40
|
+
res.end(html);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function healthRoute(ctx) {
|
|
44
|
+
const { res, deps, currentState } = ctx;
|
|
45
|
+
const readiness = getEffectiveStartupReadiness(deps, currentState);
|
|
46
|
+
const modelReadiness = getTeamClawModelReadiness();
|
|
47
|
+
const statusCode = readiness && readiness.status !== "ready" ? 503 : 200;
|
|
48
|
+
sendJson(res, statusCode, {
|
|
49
|
+
status: readiness?.status === "degraded" ? "degraded" : readiness?.status === "checking" ? "starting" : "ok",
|
|
50
|
+
mode: "controller",
|
|
51
|
+
timestamp: Date.now(),
|
|
52
|
+
provisioningReadiness: readiness,
|
|
53
|
+
modelReadiness,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
export { reportsListRoute, reportsSessionRoute, healthRoute, };
|