@teamclaws/teamclaw 2026.8.1 → 2026.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.mjs +318 -17
- package/dist/index.js +54 -32
- package/dist/src/config.js +57 -2
- package/dist/src/controller/auth-routes.js +129 -0
- package/dist/src/controller/clarification-routes.js +315 -0
- package/dist/src/controller/controller-intake.js +895 -0
- package/dist/src/controller/controller-planning.js +814 -0
- package/dist/src/controller/controller-routes.js +195 -0
- package/dist/src/controller/controller-runs.js +175 -0
- package/dist/src/controller/controller-service.js +338 -50
- package/dist/src/controller/controller-tools.js +14 -7
- package/dist/src/controller/github-auth.js +2 -1
- package/dist/src/controller/http-server.js +290 -6003
- package/dist/src/controller/kickoff-orchestrator.js +33 -43
- package/dist/src/controller/message-delivery.js +31 -0
- package/dist/src/controller/message-routes.js +114 -0
- package/dist/src/controller/orchestration-manifest.js +11 -93
- package/dist/src/controller/preview-manager.js +51 -3
- package/dist/src/controller/preview-proxy.js +98 -0
- package/dist/src/controller/profile-switch.js +309 -0
- package/dist/src/controller/project-registry.js +294 -0
- package/dist/src/controller/prompt-injector.js +19 -9
- package/dist/src/controller/provisioning/backend-contract.js +9 -0
- package/dist/src/controller/provisioning/container-shared.js +64 -0
- package/dist/src/controller/provisioning/docker.js +214 -0
- package/dist/src/controller/provisioning/kubernetes.js +244 -0
- package/dist/src/controller/provisioning/plugin-root.js +41 -0
- package/dist/src/controller/provisioning/process-supervisor.js +190 -0
- package/dist/src/controller/provisioning-config.js +239 -0
- package/dist/src/controller/repo-routes.js +129 -0
- package/dist/src/controller/report-routes.js +56 -0
- package/dist/src/controller/role-inference.js +231 -20
- package/dist/src/controller/route-table.js +375 -0
- package/dist/src/controller/security.js +775 -0
- package/dist/src/controller/status-routes.js +287 -0
- package/dist/src/controller/task-assignment.js +511 -0
- package/dist/src/controller/task-cleanup.js +258 -0
- package/dist/src/controller/task-execution.js +271 -0
- package/dist/src/controller/task-results.js +471 -0
- package/dist/src/controller/task-router.js +74 -4
- package/dist/src/controller/task-routes.js +703 -0
- package/dist/src/controller/teamauto-routes.js +124 -0
- package/dist/src/controller/tunnel-manager.js +41 -8
- package/dist/src/controller/tunnel-routes.js +225 -0
- package/dist/src/controller/ui-assets.js +68 -0
- package/dist/src/controller/websocket.js +6 -2
- package/dist/src/controller/webui-routes.js +49 -0
- package/dist/src/controller/worker-provisioning.js +69 -953
- package/dist/src/controller/worker-routes.js +188 -0
- package/dist/src/controller/workflow-routes.js +407 -0
- package/dist/src/controller/workspace-routes.js +200 -0
- package/dist/src/git-collaboration.js +4 -9
- package/dist/src/identity.js +15 -3
- package/dist/src/interaction-contracts.js +7 -7
- package/dist/src/openclaw-workspace.js +40 -18
- package/dist/src/profile-loader.js +604 -0
- package/dist/src/profiles/banking.json +202 -0
- package/dist/src/profiles/crossborder-ecom.json +253 -0
- package/dist/src/profiles/insurance.json +157 -0
- package/dist/src/profiles/knowledge/hs-structure.md +97 -0
- package/dist/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/dist/src/profiles/knowledge/vat-principles.md +85 -0
- package/dist/src/profiles/schema.json +281 -0
- package/dist/src/profiles/securities.json +137 -0
- package/dist/src/profiles/software-rd.json +264 -0
- package/dist/src/profiles/trading-co.json +200 -0
- package/dist/src/prompt-policy.js +42 -17
- package/dist/src/protocol.js +66 -3
- package/dist/src/role-ids.js +29 -0
- package/dist/src/roles.js +54 -13
- package/dist/src/session-roles.js +14 -0
- package/dist/src/shared/clarification-schema.js +65 -0
- package/dist/src/shared/github-auth.js +15 -0
- package/dist/src/shared/kickoff-prompt.js +37 -0
- package/dist/src/shared/utils.js +47 -0
- package/dist/src/state.js +275 -11
- package/dist/src/task-executor.js +7 -17
- package/dist/src/teamauto/github-client.js +18 -0
- package/dist/src/teamauto/repo-sync.js +228 -6
- package/dist/src/teamauto/scanner.js +40 -12
- package/dist/src/teamauto/scheduler.js +231 -12
- package/dist/src/types.js +77 -16
- package/dist/src/ui/app.js +1434 -82
- package/dist/src/ui/github-login.html +1 -0
- package/dist/src/ui/index.html +144 -45
- package/dist/src/ui/style.css +194 -0
- package/dist/src/worker/http-handler.js +59 -0
- package/dist/src/worker/prompt-injector.js +44 -8
- package/dist/src/worker/skill-installer.js +6 -10
- package/dist/src/worker/tools.js +20 -10
- package/dist/src/worker/worker-service.js +93 -7
- package/index.ts +61 -32
- package/openclaw.plugin.json +50 -2
- package/package.json +3 -2
- package/src/config.ts +57 -2
- package/src/controller/auth-routes.ts +157 -0
- package/src/controller/clarification-routes.ts +404 -0
- package/src/controller/controller-intake.ts +1113 -0
- package/src/controller/controller-planning.ts +1037 -0
- package/src/controller/controller-routes.ts +237 -0
- package/src/controller/controller-runs.ts +239 -0
- package/src/controller/controller-service.ts +422 -50
- package/src/controller/controller-tools.ts +16 -9
- package/src/controller/github-auth.ts +28 -63
- package/src/controller/http-server.ts +336 -6964
- package/src/controller/kickoff-orchestrator.ts +69 -45
- package/src/controller/message-delivery.ts +52 -0
- package/src/controller/message-routes.ts +137 -0
- package/src/controller/orchestration-manifest.ts +14 -100
- package/src/controller/preview-manager.ts +53 -3
- package/src/controller/preview-proxy.ts +127 -0
- package/src/controller/profile-switch.ts +396 -0
- package/src/controller/project-registry.ts +361 -0
- package/src/controller/prompt-injector.ts +23 -8
- package/src/controller/provisioning/backend-contract.ts +51 -0
- package/src/controller/provisioning/container-shared.ts +84 -0
- package/src/controller/provisioning/docker.ts +260 -0
- package/src/controller/provisioning/kubernetes.ts +263 -0
- package/src/controller/provisioning/plugin-root.ts +42 -0
- package/src/controller/provisioning/process-supervisor.ts +214 -0
- package/src/controller/provisioning-config.ts +289 -0
- package/src/controller/repo-routes.ts +163 -0
- package/src/controller/report-routes.ts +64 -0
- package/src/controller/role-inference.ts +260 -22
- package/src/controller/route-table.ts +597 -0
- package/src/controller/security.ts +899 -0
- package/src/controller/status-routes.ts +354 -0
- package/src/controller/task-assignment.ts +622 -0
- package/src/controller/task-cleanup.ts +344 -0
- package/src/controller/task-execution.ts +399 -0
- package/src/controller/task-results.ts +556 -0
- package/src/controller/task-router.ts +98 -6
- package/src/controller/task-routes.ts +812 -0
- package/src/controller/teamauto-routes.ts +121 -0
- package/src/controller/tunnel-manager.ts +45 -8
- package/src/controller/tunnel-routes.ts +231 -0
- package/src/controller/ui-assets.ts +70 -0
- package/src/controller/websocket.ts +32 -4
- package/src/controller/webui-routes.ts +55 -0
- package/src/controller/worker-provisioning.ts +83 -1121
- package/src/controller/worker-routes.ts +241 -0
- package/src/controller/workflow-routes.ts +498 -0
- package/src/controller/workspace-routes.ts +222 -0
- package/src/git-collaboration.ts +4 -9
- package/src/identity.ts +16 -3
- package/src/interaction-contracts.ts +7 -7
- package/src/openclaw-workspace.ts +44 -18
- package/src/profile-loader.ts +816 -0
- package/src/profiles/banking.json +202 -0
- package/src/profiles/crossborder-ecom.json +253 -0
- package/src/profiles/insurance.json +157 -0
- package/src/profiles/knowledge/hs-structure.md +97 -0
- package/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/src/profiles/knowledge/vat-principles.md +85 -0
- package/src/profiles/schema.json +281 -0
- package/src/profiles/securities.json +137 -0
- package/src/profiles/software-rd.json +264 -0
- package/src/profiles/trading-co.json +200 -0
- package/src/prompt-policy.ts +44 -17
- package/src/protocol.ts +72 -2
- package/src/role-ids.ts +31 -0
- package/src/roles.ts +60 -14
- package/src/session-roles.ts +14 -0
- package/src/shared/clarification-schema.ts +81 -0
- package/src/shared/github-auth.ts +92 -0
- package/src/shared/kickoff-prompt.ts +47 -0
- package/src/shared/utils.ts +51 -0
- package/src/state.ts +326 -10
- package/src/task-executor.ts +7 -18
- package/src/teamauto/github-client.ts +23 -1
- package/src/teamauto/repo-sync.ts +248 -7
- package/src/teamauto/scanner.ts +47 -13
- package/src/teamauto/scheduler.ts +261 -17
- package/src/teamauto/store.ts +12 -0
- package/src/types.ts +263 -17
- package/src/ui/app.js +1434 -82
- package/src/ui/github-login.html +1 -0
- package/src/ui/index.html +144 -45
- package/src/ui/style.css +194 -0
- package/src/worker/http-handler.ts +64 -1
- package/src/worker/prompt-injector.ts +48 -8
- package/src/worker/skill-installer.ts +6 -10
- package/src/worker/tools.ts +21 -10
- package/src/worker/worker-service.ts +101 -7
package/cli.mjs
CHANGED
|
@@ -55,19 +55,47 @@ const AGENT_MODE_OPTIONS = [
|
|
|
55
55
|
},
|
|
56
56
|
];
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
// Installer role options are derived from the packaged role registry
|
|
59
|
+
// (dist/src/roles.js, compiled from src/src/roles.ts) instead of a
|
|
60
|
+
// hand-maintained copy, so profile-driven role sets flow into the wizard
|
|
61
|
+
// without editing this file. dist/ always ships inside the npm package; in a
|
|
62
|
+
// dev checkout it appears after `npm --prefix src run build`. The dynamic
|
|
63
|
+
// import keeps pre-build tooling (lint, source-level tests) working: this
|
|
64
|
+
// file parses without dist present and only the interactive/install paths
|
|
65
|
+
// require it.
|
|
66
|
+
let ROLE_OPTIONS = [];
|
|
67
|
+
let DEFAULT_WORKER_ROLE = "";
|
|
68
|
+
|
|
69
|
+
async function loadRoleOptions() {
|
|
70
|
+
try {
|
|
71
|
+
const rolesModule = await import("./dist/src/roles.js");
|
|
72
|
+
const roles = Array.isArray(rolesModule.ROLES) ? rolesModule.ROLES : [];
|
|
73
|
+
ROLE_OPTIONS = roles
|
|
74
|
+
.filter((role) => role && typeof role.id === "string" && role.id.trim())
|
|
75
|
+
.map((role) => ({
|
|
76
|
+
value: role.id,
|
|
77
|
+
label: typeof role.label === "string" && role.label.trim() ? role.label : role.id,
|
|
78
|
+
}));
|
|
79
|
+
const registryDefault = rolesModule.DEFAULT_ROLE;
|
|
80
|
+
DEFAULT_WORKER_ROLE = typeof registryDefault === "string" && ROLE_OPTIONS.some((option) => option.value === registryDefault)
|
|
81
|
+
? registryDefault
|
|
82
|
+
: "";
|
|
83
|
+
} catch {
|
|
84
|
+
// dist not built yet (dev checkout). Keep the registry empty so callers
|
|
85
|
+
// fail with the actionable guidance in ensureRoleOptionsLoaded instead
|
|
86
|
+
// of presenting a stale role list.
|
|
87
|
+
ROLE_OPTIONS = [];
|
|
88
|
+
DEFAULT_WORKER_ROLE = "";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function ensureRoleOptionsLoaded() {
|
|
93
|
+
if (ROLE_OPTIONS.length === 0) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
"TeamClaw role registry unavailable (./dist/src/roles.js). Run `npm --prefix src run build` in the repository, or reinstall the @teamclaws/teamclaw package, then retry.",
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
71
99
|
|
|
72
100
|
const INSTALL_MODE_OPTIONS = [
|
|
73
101
|
{
|
|
@@ -107,7 +135,20 @@ Usage:
|
|
|
107
135
|
|
|
108
136
|
Commands:
|
|
109
137
|
install Install/configure TeamClaw for OpenClaw
|
|
110
|
-
|
|
138
|
+
pair <controller-url> Pair this instance with a controller that has device
|
|
139
|
+
protection enabled (issue #23). Without --code it
|
|
140
|
+
first tries zero-input LAN auto-pairing.
|
|
141
|
+
--code <code> One-shot pairing code from the controller owner
|
|
142
|
+
(web UI: Device security -> New pairing code)
|
|
143
|
+
--name <name> Device name shown in the controller device list
|
|
144
|
+
--kind <kind> Device kind: worker, desktop or cli (default cli)
|
|
145
|
+
--config <path> OpenClaw config path to store the token in
|
|
146
|
+
token reset <controller-url>
|
|
147
|
+
Revoke ALL paired devices and return the controller
|
|
148
|
+
to unpaired local mode (loopback host, or --token)
|
|
149
|
+
--token <token> Device token (required from a non-loopback host)
|
|
150
|
+
--config <path> OpenClaw config path to clear the stored token from
|
|
151
|
+
help Show this help
|
|
111
152
|
|
|
112
153
|
Options:
|
|
113
154
|
--config <path> Override the OpenClaw config path
|
|
@@ -185,6 +226,7 @@ function parseArgs(argv) {
|
|
|
185
226
|
}
|
|
186
227
|
if (arg === "--worker-role") {
|
|
187
228
|
const value = argv[index + 1];
|
|
229
|
+
ensureRoleOptionsLoaded();
|
|
188
230
|
const validRoles = new Set(ROLE_OPTIONS.map((option) => option.value));
|
|
189
231
|
if (!value || !validRoles.has(value)) {
|
|
190
232
|
throw new Error(`--worker-role requires one of: ${ROLE_OPTIONS.map((option) => option.value).join(", ")}`);
|
|
@@ -220,6 +262,242 @@ function parseArgs(argv) {
|
|
|
220
262
|
return { command: command || "help", options };
|
|
221
263
|
}
|
|
222
264
|
|
|
265
|
+
// ===========================================================================
|
|
266
|
+
// Device pairing commands (issue #23, client wave).
|
|
267
|
+
//
|
|
268
|
+
// pair <controller-url> [--code] [--name] [--kind] - exchange a one-shot
|
|
269
|
+
// code (or a LAN auto-pair attempt) for a device token, then store it as
|
|
270
|
+
// plugins.entries.teamclaw.config.securityToken in the OpenClaw config so
|
|
271
|
+
// every later worker/controller API call from this instance carries the
|
|
272
|
+
// X-TeamClaw-Token header automatically.
|
|
273
|
+
// token reset <controller-url> [--token] - revoke all devices (loopback
|
|
274
|
+
// host needs no token) and clear any locally stored token.
|
|
275
|
+
// ===========================================================================
|
|
276
|
+
|
|
277
|
+
const PAIR_DEVICE_KINDS = new Set(["worker", "desktop", "cli"]);
|
|
278
|
+
const SECURITY_REQUEST_TIMEOUT_MS = 15_000;
|
|
279
|
+
|
|
280
|
+
function normalizeControllerUrlArg(raw) {
|
|
281
|
+
let value = String(raw || "").trim();
|
|
282
|
+
if (!value) {
|
|
283
|
+
throw new Error("A controller URL is required (e.g. http://192.168.1.10:9527).");
|
|
284
|
+
}
|
|
285
|
+
if (!value.startsWith("http://") && !value.startsWith("https://")) {
|
|
286
|
+
value = `http://${value}`;
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
const parsed = new URL(value);
|
|
290
|
+
if (!parsed.hostname) {
|
|
291
|
+
throw new Error("empty host");
|
|
292
|
+
}
|
|
293
|
+
// Strip any trailing path/slash so endpoint joining stays predictable.
|
|
294
|
+
return `${parsed.protocol}//${parsed.host}`;
|
|
295
|
+
} catch (error) {
|
|
296
|
+
throw new Error(`Invalid controller URL: ${raw}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function readFlagValue(argv, index, flag) {
|
|
301
|
+
const value = argv[index + 1];
|
|
302
|
+
if (!value) {
|
|
303
|
+
throw new Error(`${flag} requires a value`);
|
|
304
|
+
}
|
|
305
|
+
return value;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function parsePairArgs(argv) {
|
|
309
|
+
const options = { controllerUrl: "", code: "", name: "", kind: "cli", configPath: "" };
|
|
310
|
+
const positional = [];
|
|
311
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
312
|
+
const arg = argv[index];
|
|
313
|
+
if (arg === "--help" || arg === "-h") {
|
|
314
|
+
return { help: true, options };
|
|
315
|
+
}
|
|
316
|
+
if (arg.startsWith("--")) {
|
|
317
|
+
if (arg === "--code") {
|
|
318
|
+
options.code = readFlagValue(argv, index, arg).trim();
|
|
319
|
+
index += 1;
|
|
320
|
+
} else if (arg === "--name") {
|
|
321
|
+
options.name = readFlagValue(argv, index, arg).trim();
|
|
322
|
+
index += 1;
|
|
323
|
+
} else if (arg === "--kind") {
|
|
324
|
+
const kind = readFlagValue(argv, index, arg).trim();
|
|
325
|
+
if (!PAIR_DEVICE_KINDS.has(kind)) {
|
|
326
|
+
throw new Error(`--kind requires one of: ${[...PAIR_DEVICE_KINDS].join(", ")}`);
|
|
327
|
+
}
|
|
328
|
+
options.kind = kind;
|
|
329
|
+
index += 1;
|
|
330
|
+
} else if (arg === "--config") {
|
|
331
|
+
options.configPath = readFlagValue(argv, index, arg);
|
|
332
|
+
index += 1;
|
|
333
|
+
} else {
|
|
334
|
+
throw new Error(`Unknown argument: ${arg}`);
|
|
335
|
+
}
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
positional.push(arg);
|
|
339
|
+
}
|
|
340
|
+
if (positional.length !== 1) {
|
|
341
|
+
throw new Error('Usage: teamclaw pair <controller-url> [--code <code>] [--name <name>] [--kind worker|desktop|cli]');
|
|
342
|
+
}
|
|
343
|
+
options.controllerUrl = positional[0];
|
|
344
|
+
return { help: false, options };
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function parseTokenArgs(argv) {
|
|
348
|
+
const options = { controllerUrl: "", token: "", configPath: "" };
|
|
349
|
+
const positional = [];
|
|
350
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
351
|
+
const arg = argv[index];
|
|
352
|
+
if (arg === "--help" || arg === "-h") {
|
|
353
|
+
return { help: true, options };
|
|
354
|
+
}
|
|
355
|
+
if (arg.startsWith("--")) {
|
|
356
|
+
if (arg === "--token") {
|
|
357
|
+
options.token = readFlagValue(argv, index, arg).trim();
|
|
358
|
+
index += 1;
|
|
359
|
+
} else if (arg === "--config") {
|
|
360
|
+
options.configPath = readFlagValue(argv, index, arg);
|
|
361
|
+
index += 1;
|
|
362
|
+
} else {
|
|
363
|
+
throw new Error(`Unknown argument: ${arg}`);
|
|
364
|
+
}
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
positional.push(arg);
|
|
368
|
+
}
|
|
369
|
+
if (positional.length === 0 || positional[0] !== "reset") {
|
|
370
|
+
throw new Error('Usage: teamclaw token reset <controller-url> [--token <token>]');
|
|
371
|
+
}
|
|
372
|
+
if (positional.length !== 2) {
|
|
373
|
+
throw new Error('Usage: teamclaw token reset <controller-url> [--token <token>]');
|
|
374
|
+
}
|
|
375
|
+
options.controllerUrl = positional[1];
|
|
376
|
+
return { help: false, options };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async function securityFetch(controllerUrl, pathname, { method = "POST", body, token } = {}) {
|
|
380
|
+
const headers = {};
|
|
381
|
+
if (body !== undefined) {
|
|
382
|
+
headers["Content-Type"] = "application/json";
|
|
383
|
+
}
|
|
384
|
+
if (token) {
|
|
385
|
+
headers["X-TeamClaw-Token"] = token;
|
|
386
|
+
}
|
|
387
|
+
let response;
|
|
388
|
+
try {
|
|
389
|
+
response = await fetch(`${controllerUrl}/api/v1${pathname}`, {
|
|
390
|
+
method,
|
|
391
|
+
headers,
|
|
392
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
393
|
+
signal: AbortSignal.timeout(SECURITY_REQUEST_TIMEOUT_MS),
|
|
394
|
+
});
|
|
395
|
+
} catch (error) {
|
|
396
|
+
throw new Error(`Could not reach the controller at ${controllerUrl}: ${error instanceof Error ? error.message : String(error)}`);
|
|
397
|
+
}
|
|
398
|
+
let payload = null;
|
|
399
|
+
try {
|
|
400
|
+
payload = await response.json();
|
|
401
|
+
} catch {
|
|
402
|
+
payload = null;
|
|
403
|
+
}
|
|
404
|
+
return { status: response.status, ok: response.ok, payload };
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function describeSecurityError(result, fallback) {
|
|
408
|
+
if (result.payload && typeof result.payload === "object") {
|
|
409
|
+
const parts = [result.payload.error, result.payload.hint].filter((part) => typeof part === "string" && part.trim());
|
|
410
|
+
if (parts.length > 0) {
|
|
411
|
+
return parts.join(" - ");
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return `${fallback} (HTTP ${result.status})`;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
async function upsertTeamClawConfig(configPath, update) {
|
|
418
|
+
const config = await readOpenClawConfig(configPath);
|
|
419
|
+
const plugins = ensureRecord(config, "plugins");
|
|
420
|
+
const entries = ensureRecord(plugins, "entries");
|
|
421
|
+
const teamclawEntry = ensureRecord(entries, PLUGIN_ID);
|
|
422
|
+
const teamclawConfig = ensureRecord(teamclawEntry, "config");
|
|
423
|
+
update(teamclawConfig);
|
|
424
|
+
await writeConfig(configPath, config);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
async function runPair(options) {
|
|
428
|
+
const controllerUrl = normalizeControllerUrlArg(options.controllerUrl);
|
|
429
|
+
const kind = options.kind;
|
|
430
|
+
const name = options.name || `${os.hostname()} ${kind}`;
|
|
431
|
+
let result;
|
|
432
|
+
if (options.code) {
|
|
433
|
+
result = await securityFetch(controllerUrl, "/security/pair", {
|
|
434
|
+
body: { code: options.code.toUpperCase(), kind, name },
|
|
435
|
+
});
|
|
436
|
+
} else {
|
|
437
|
+
// Zero-input LAN path first (mDNS scenario): a LAN peer pairs without a
|
|
438
|
+
// code while the controller allows auto-pairing.
|
|
439
|
+
result = await securityFetch(controllerUrl, "/security/pair-auto", { body: { kind, name } });
|
|
440
|
+
if (result.status === 403) {
|
|
441
|
+
throw new Error(
|
|
442
|
+
"This controller did not accept zero-input pairing (not a LAN peer, or auto-pairing is disabled). " +
|
|
443
|
+
"Ask the controller owner for a one-shot pairing code (web UI: Device security -> New pairing code) and rerun with --code <code>.",
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (!result.ok || !result.payload || typeof result.payload.token !== "string") {
|
|
448
|
+
if (result.status === 409) {
|
|
449
|
+
throw new Error(describeSecurityError(result, "Device protection is not enabled on this controller; there is nothing to pair with yet"));
|
|
450
|
+
}
|
|
451
|
+
throw new Error(describeSecurityError(result, "Pairing failed"));
|
|
452
|
+
}
|
|
453
|
+
const configPath = expandUserPath(options.configPath || resolveDefaultOpenClawConfigPath());
|
|
454
|
+
await upsertTeamClawConfig(configPath, (teamclawConfig) => {
|
|
455
|
+
// Same layer as teamName: the worker/controller pipeline reads this and
|
|
456
|
+
// sends X-TeamClaw-Token on every API call automatically.
|
|
457
|
+
teamclawConfig.securityToken = result.payload.token;
|
|
458
|
+
if (!teamclawConfig.controllerUrl) {
|
|
459
|
+
teamclawConfig.controllerUrl = controllerUrl;
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
console.log(`Paired with ${controllerUrl}`);
|
|
463
|
+
console.log(` Device: "${result.payload.device?.name || name}" (kind ${kind}, id ${result.payload.deviceId || result.payload.device?.id || "?"})`);
|
|
464
|
+
console.log(` Token stored at plugins.entries.teamclaw.config.securityToken in ${configPath}`);
|
|
465
|
+
console.log(" This instance now authenticates automatically. Keep that config file private; the token is shown only once by the controller and cannot be recovered.");
|
|
466
|
+
console.log("Next step: restart this instance (or run `openclaw gateway restart`) so its API calls pick up the token.");
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
async function runTokenReset(options) {
|
|
470
|
+
const controllerUrl = normalizeControllerUrlArg(options.controllerUrl);
|
|
471
|
+
const result = await securityFetch(controllerUrl, "/security/reset", { body: {}, token: options.token });
|
|
472
|
+
if (!result.ok) {
|
|
473
|
+
if (result.status === 401) {
|
|
474
|
+
throw new Error(
|
|
475
|
+
"Reset refused: only the controller host itself (loopback) or an authenticated device may reset. " +
|
|
476
|
+
"Run this on the controller machine, or pass --token <device-token>.",
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
throw new Error(describeSecurityError(result, "Token reset failed"));
|
|
480
|
+
}
|
|
481
|
+
// Best effort: drop the now-invalid local token so the next pair starts clean.
|
|
482
|
+
const configPath = expandUserPath(options.configPath || resolveDefaultOpenClawConfigPath());
|
|
483
|
+
try {
|
|
484
|
+
const config = await readOpenClawConfig(configPath);
|
|
485
|
+
const teamclawConfig = getExistingTeamClawConfig(config);
|
|
486
|
+
if (typeof teamclawConfig.securityToken === "string" && teamclawConfig.securityToken) {
|
|
487
|
+
delete teamclawConfig.securityToken;
|
|
488
|
+
const plugins = ensureRecord(config, "plugins");
|
|
489
|
+
const entries = ensureRecord(plugins, "entries");
|
|
490
|
+
const teamclawEntry = ensureRecord(entries, PLUGIN_ID);
|
|
491
|
+
teamclawEntry.config = teamclawConfig;
|
|
492
|
+
await writeConfig(configPath, config);
|
|
493
|
+
console.log(`Cleared the stored device token from ${configPath}`);
|
|
494
|
+
}
|
|
495
|
+
} catch {
|
|
496
|
+
// No local config/token to clear - resetting a remote controller only.
|
|
497
|
+
}
|
|
498
|
+
console.log(`All paired devices on ${controllerUrl} were revoked; the controller is back to unpaired local mode (L0).`);
|
|
499
|
+
}
|
|
500
|
+
|
|
223
501
|
function isRecord(value) {
|
|
224
502
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
225
503
|
}
|
|
@@ -1318,7 +1596,7 @@ async function collectInstallChoices(configPath, config, prompter, options) {
|
|
|
1318
1596
|
defaultValue: options.workerRole || (
|
|
1319
1597
|
typeof existingTeamClaw.role === "string" && existingTeamClaw.role.trim()
|
|
1320
1598
|
? existingTeamClaw.role.trim()
|
|
1321
|
-
:
|
|
1599
|
+
: DEFAULT_WORKER_ROLE || ROLE_OPTIONS[0].value
|
|
1322
1600
|
),
|
|
1323
1601
|
});
|
|
1324
1602
|
const workerPort = await prompter.number({
|
|
@@ -1410,7 +1688,7 @@ async function collectInstallChoices(configPath, config, prompter, options) {
|
|
|
1410
1688
|
|
|
1411
1689
|
const provisioningRoles = await promptOptionalRoleList(
|
|
1412
1690
|
prompter,
|
|
1413
|
-
|
|
1691
|
+
`Preferred on-demand roles (comma-separated, leave empty to keep workerProvisioningRoles empty and let startup readiness default to a warm ${DEFAULT_WORKER_ROLE} worker)`,
|
|
1414
1692
|
resolveDefaultProvisioningRoles(existingTeamClaw),
|
|
1415
1693
|
);
|
|
1416
1694
|
const maxPerRole = await prompter.number({
|
|
@@ -1950,6 +2228,7 @@ async function runInstall(options) {
|
|
|
1950
2228
|
if (!options.yes && (!process.stdin.isTTY || !process.stdout.isTTY)) {
|
|
1951
2229
|
throw new Error("Interactive install requires a TTY. Re-run with --yes or in a terminal.");
|
|
1952
2230
|
}
|
|
2231
|
+
ensureRoleOptionsLoaded();
|
|
1953
2232
|
|
|
1954
2233
|
const prompter = new Prompter({ yes: options.yes });
|
|
1955
2234
|
try {
|
|
@@ -2073,7 +2352,29 @@ async function runInstall(options) {
|
|
|
2073
2352
|
}
|
|
2074
2353
|
|
|
2075
2354
|
async function main() {
|
|
2076
|
-
const
|
|
2355
|
+
const argv = process.argv.slice(2);
|
|
2356
|
+
// Issue #23 pairing commands dispatch before the installer parser (their
|
|
2357
|
+
// positional <controller-url> argument is not an installer flag).
|
|
2358
|
+
if (argv[0] === "pair") {
|
|
2359
|
+
const { help, options } = parsePairArgs(argv.slice(1));
|
|
2360
|
+
if (help) {
|
|
2361
|
+
printHelp();
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2364
|
+
await runPair(options);
|
|
2365
|
+
return;
|
|
2366
|
+
}
|
|
2367
|
+
if (argv[0] === "token") {
|
|
2368
|
+
const { help, options } = parseTokenArgs(argv.slice(1));
|
|
2369
|
+
if (help) {
|
|
2370
|
+
printHelp();
|
|
2371
|
+
return;
|
|
2372
|
+
}
|
|
2373
|
+
await runTokenReset(options);
|
|
2374
|
+
return;
|
|
2375
|
+
}
|
|
2376
|
+
await loadRoleOptions();
|
|
2377
|
+
const { command, options } = parseArgs(argv);
|
|
2077
2378
|
if (command === "help") {
|
|
2078
2379
|
printHelp();
|
|
2079
2380
|
return;
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,9 @@ import { createControllerTools } from "./src/controller/controller-tools.js";
|
|
|
15
15
|
import { publishWorkerRepo, syncWorkerRepo } from "./src/git-collaboration.js";
|
|
16
16
|
import { resolveTeamClawProjectsDir } from "./src/openclaw-workspace.js";
|
|
17
17
|
import { installRecommendedSkills } from "./src/worker/skill-installer.js";
|
|
18
|
+
// W6 of issue #226: local swallowing pathExists copy replaced by the shared
|
|
19
|
+
// one (identical semantics; alias keeps the call site byte-identical).
|
|
20
|
+
import { pathExistsTolerant as pathExists } from "./src/shared/utils.js";
|
|
18
21
|
export default definePluginEntry({
|
|
19
22
|
id: "teamclaw",
|
|
20
23
|
name: "TeamClaw",
|
|
@@ -76,32 +79,36 @@ function registerController(api, config) {
|
|
|
76
79
|
});
|
|
77
80
|
});
|
|
78
81
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Issue #23 (client wave): headers for worker -> controller calls, same
|
|
84
|
+
* pattern as identity.ts / worker-service.ts / worker/tools.ts. A configured
|
|
85
|
+
* device token rides X-TeamClaw-Token; without one the headers are unchanged
|
|
86
|
+
* (L0). The token value is never logged.
|
|
87
|
+
*/
|
|
88
|
+
function withDeviceToken(config, headers) {
|
|
89
|
+
const token = config.securityToken?.trim();
|
|
90
|
+
return token ? { ...headers, "X-TeamClaw-Token": token } : headers;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Execution-event + checkpoint reporters (issue #23 review follow-up: the
|
|
94
|
+
* execution stream and resume checkpoints MUST survive device protection, so
|
|
95
|
+
* both POSTs carry the paired device token). Extracted from registerWorker
|
|
96
|
+
* as an exported factory so the dist-level client tests can exercise the
|
|
97
|
+
* real header behavior against a stub controller.
|
|
98
|
+
*/
|
|
99
|
+
export function createWorkerEventReporters(config, logger, state) {
|
|
94
100
|
async function reportExecutionEvent(taskId, event) {
|
|
95
|
-
|
|
101
|
+
const controllerUrl = state.getControllerUrl();
|
|
102
|
+
if (!controllerUrl) {
|
|
96
103
|
return;
|
|
97
104
|
}
|
|
98
105
|
try {
|
|
99
|
-
const res = await fetch(`${
|
|
106
|
+
const res = await fetch(`${controllerUrl}/api/v1/tasks/${taskId}/execution`, {
|
|
100
107
|
method: "POST",
|
|
101
|
-
headers: { "Content-Type": "application/json" },
|
|
108
|
+
headers: withDeviceToken(config, { "Content-Type": "application/json" }),
|
|
102
109
|
body: JSON.stringify({
|
|
103
110
|
...event,
|
|
104
|
-
workerId:
|
|
111
|
+
workerId: state.getWorkerId() ?? undefined,
|
|
105
112
|
role: config.role,
|
|
106
113
|
}),
|
|
107
114
|
});
|
|
@@ -114,20 +121,44 @@ function registerWorker(api, config) {
|
|
|
114
121
|
}
|
|
115
122
|
}
|
|
116
123
|
async function reportCheckpoint(taskId, checkpoint) {
|
|
117
|
-
|
|
124
|
+
const controllerUrl = state.getControllerUrl();
|
|
125
|
+
if (!controllerUrl) {
|
|
118
126
|
return;
|
|
119
127
|
}
|
|
120
128
|
try {
|
|
121
|
-
await fetch(`${
|
|
129
|
+
await fetch(`${controllerUrl}/api/v1/tasks/${taskId}/checkpoint`, {
|
|
122
130
|
method: "POST",
|
|
123
|
-
headers: { "Content-Type": "application/json" },
|
|
124
|
-
body: JSON.stringify({ ...checkpoint, workerId:
|
|
131
|
+
headers: withDeviceToken(config, { "Content-Type": "application/json" }),
|
|
132
|
+
body: JSON.stringify({ ...checkpoint, workerId: state.getWorkerId() ?? undefined }),
|
|
125
133
|
});
|
|
126
134
|
}
|
|
127
135
|
catch {
|
|
128
136
|
// Checkpointing is best-effort; a lost heartbeat only costs resume freshness.
|
|
129
137
|
}
|
|
130
138
|
}
|
|
139
|
+
return { reportExecutionEvent, reportCheckpoint };
|
|
140
|
+
}
|
|
141
|
+
function registerWorker(api, config) {
|
|
142
|
+
const logger = api.logger;
|
|
143
|
+
const messageQueue = new MessageQueue();
|
|
144
|
+
let currentControllerUrl = null;
|
|
145
|
+
let currentWorkerId = null;
|
|
146
|
+
function getIdentity() {
|
|
147
|
+
if (!currentWorkerId || !currentControllerUrl)
|
|
148
|
+
return null;
|
|
149
|
+
return {
|
|
150
|
+
workerId: currentWorkerId,
|
|
151
|
+
role: config.role,
|
|
152
|
+
controllerUrl: currentControllerUrl,
|
|
153
|
+
registeredAt: Date.now(),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const { reportExecutionEvent, reportCheckpoint } = createWorkerEventReporters(config, logger, {
|
|
157
|
+
// Read through getters so the reporters always see the identity the
|
|
158
|
+
// worker service has established by the time an event fires.
|
|
159
|
+
getControllerUrl: () => currentControllerUrl,
|
|
160
|
+
getWorkerId: () => currentWorkerId,
|
|
161
|
+
});
|
|
131
162
|
const getWorkerSessionKey = (assignment) => assignment.executionSessionKey?.trim() || `teamclaw-task-${assignment.taskId}`;
|
|
132
163
|
const taskExecutor = createRoleTaskExecutor({
|
|
133
164
|
runtime: api.runtime,
|
|
@@ -155,15 +186,6 @@ function registerWorker(api, config) {
|
|
|
155
186
|
}
|
|
156
187
|
return { sharedProjectDir, localProjectDir };
|
|
157
188
|
}
|
|
158
|
-
async function pathExists(targetPath) {
|
|
159
|
-
try {
|
|
160
|
-
await fs.access(targetPath);
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
189
|
async function syncProjectDir(sourceDir, destinationDir) {
|
|
168
190
|
if (!await pathExists(sourceDir)) {
|
|
169
191
|
return false;
|
package/dist/src/config.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { parsePluginConfig } from "./types.js";
|
|
2
|
-
|
|
2
|
+
// Phase 1.3: the enum is driven by the active TeamProfile (software-rd
|
|
3
|
+
// baseline) instead of importing the roles.ts registry directly. The
|
|
4
|
+
// manifest generator evaluates this file without imports and injects
|
|
5
|
+
// equivalent getActiveRoleIds/SOFTWARE_RD_PROFILE_ID bindings.
|
|
6
|
+
import { getActiveRoleIds, SOFTWARE_RD_PROFILE_ID } from "./profile-loader.js";
|
|
3
7
|
import { TEAMCLAW_PUBLISHED_RUNTIME_IMAGE } from "./install-defaults.js";
|
|
4
8
|
function buildConfigSchema() {
|
|
5
9
|
return {
|
|
@@ -17,6 +21,11 @@ function buildConfigSchema() {
|
|
|
17
21
|
default: 9527,
|
|
18
22
|
description: "HTTP server port for this instance",
|
|
19
23
|
},
|
|
24
|
+
listenHost: {
|
|
25
|
+
type: "string",
|
|
26
|
+
default: "",
|
|
27
|
+
description: "HTTP listen host override (empty = 127.0.0.1 on hosts, 0.0.0.0 in containers); set 0.0.0.0 for external workers reachable by a remote controller",
|
|
28
|
+
},
|
|
20
29
|
role: {
|
|
21
30
|
type: "string",
|
|
22
31
|
default: "developer",
|
|
@@ -32,6 +41,11 @@ function buildConfigSchema() {
|
|
|
32
41
|
default: "TeamClaw",
|
|
33
42
|
description: "Team name for mDNS identification",
|
|
34
43
|
},
|
|
44
|
+
teamProfile: {
|
|
45
|
+
type: "string",
|
|
46
|
+
default: SOFTWARE_RD_PROFILE_ID,
|
|
47
|
+
description: "Team profile package id (software-rd baseline); seeds first initialization only - the persisted team state profile is the runtime truth",
|
|
48
|
+
},
|
|
35
49
|
heartbeatIntervalMs: {
|
|
36
50
|
type: "number",
|
|
37
51
|
default: 10000,
|
|
@@ -42,6 +56,11 @@ function buildConfigSchema() {
|
|
|
42
56
|
default: 600000,
|
|
43
57
|
description: "Inactivity threshold in milliseconds before TeamClaw probes a stalled role task instead of failing it",
|
|
44
58
|
},
|
|
59
|
+
teamSwitchDrainTimeoutMs: {
|
|
60
|
+
type: "number",
|
|
61
|
+
default: 30000,
|
|
62
|
+
description: "How long a team profile switch waits for in-flight tasks to finish before force-collecting them (design 2.3 graceful drain)",
|
|
63
|
+
},
|
|
45
64
|
maxConcurrentTasks: {
|
|
46
65
|
type: "integer",
|
|
47
66
|
default: 5,
|
|
@@ -84,6 +103,26 @@ function buildConfigSchema() {
|
|
|
84
103
|
default: "",
|
|
85
104
|
description: "GitHub App OAuth client secret; the TEAMCLAW_GITHUB_CLIENT_SECRET environment variable takes precedence",
|
|
86
105
|
},
|
|
106
|
+
security: {
|
|
107
|
+
type: "object",
|
|
108
|
+
default: {},
|
|
109
|
+
description: "Controller device-pairing security (issue #23); protection itself is enabled per-team via POST /api/v1/security/enable",
|
|
110
|
+
properties: {
|
|
111
|
+
autoPair: {
|
|
112
|
+
type: "boolean",
|
|
113
|
+
default: true,
|
|
114
|
+
description: "Allow zero-input pairing from LAN peers (POST /api/v1/security/pair-auto); disable to require a pairing code for every new device",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
securityToken: {
|
|
119
|
+
type: "string",
|
|
120
|
+
default: "",
|
|
121
|
+
// Deliberately NO uiHints entry: the token is a secret written by
|
|
122
|
+
// `teamclaw pair` / the desktop pairing flow and must never be
|
|
123
|
+
// echoed back through config surfaces or logs.
|
|
124
|
+
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",
|
|
125
|
+
},
|
|
87
126
|
agentIsolationMode: {
|
|
88
127
|
type: "string",
|
|
89
128
|
enum: ["independent", "main"],
|
|
@@ -118,7 +157,7 @@ function buildConfigSchema() {
|
|
|
118
157
|
description: "Preferred on-demand roles; task-required roles can still launch automatically. Empty means no preferred startup role list, so startup readiness falls back to a warm developer worker",
|
|
119
158
|
items: {
|
|
120
159
|
type: "string",
|
|
121
|
-
enum:
|
|
160
|
+
enum: getActiveRoleIds(),
|
|
122
161
|
},
|
|
123
162
|
},
|
|
124
163
|
workerProvisioningMinPerRole: {
|
|
@@ -234,14 +273,26 @@ function buildConfigSchema() {
|
|
|
234
273
|
uiHints: {
|
|
235
274
|
mode: { label: "Mode", help: "controller manages the team, worker executes tasks" },
|
|
236
275
|
port: { label: "Port", help: "HTTP server port for this instance" },
|
|
276
|
+
listenHost: {
|
|
277
|
+
label: "Listen Host",
|
|
278
|
+
help: "HTTP bind address override; empty defaults to 127.0.0.1 on hosts and 0.0.0.0 in containers. Use 0.0.0.0 when a remote controller must reach this worker",
|
|
279
|
+
},
|
|
237
280
|
role: { label: "Role", help: "Worker role (worker mode only)" },
|
|
238
281
|
controllerUrl: { label: "Controller URL", help: "Manual fallback if mDNS discovery fails" },
|
|
239
282
|
teamName: { label: "Team Name", help: "Team identifier for mDNS" },
|
|
283
|
+
teamProfile: {
|
|
284
|
+
label: "Team Profile",
|
|
285
|
+
help: "Team profile package id; applies to the first team initialization only (Phase 2 adds profile switching)",
|
|
286
|
+
},
|
|
240
287
|
heartbeatIntervalMs: { label: "Heartbeat Interval", help: "In milliseconds, minimum 1000" },
|
|
241
288
|
taskTimeoutMs: {
|
|
242
289
|
label: "Task Stall Threshold",
|
|
243
290
|
help: "In milliseconds, how long TeamClaw waits without visible progress before probing the task instead of failing it",
|
|
244
291
|
},
|
|
292
|
+
teamSwitchDrainTimeoutMs: {
|
|
293
|
+
label: "Profile Switch Drain Timeout",
|
|
294
|
+
help: "In milliseconds, how long a team profile switch waits for in-flight tasks to finish before force-collecting them",
|
|
295
|
+
},
|
|
245
296
|
maxConcurrentTasks: {
|
|
246
297
|
label: "Max Concurrent Tasks",
|
|
247
298
|
hint: "number",
|
|
@@ -276,6 +327,10 @@ function buildConfigSchema() {
|
|
|
276
327
|
hint: "optional - prefer the TEAMCLAW_GITHUB_CLIENT_SECRET env var",
|
|
277
328
|
help: "GitHub App OAuth client secret; the TEAMCLAW_GITHUB_CLIENT_SECRET environment variable takes precedence",
|
|
278
329
|
},
|
|
330
|
+
security: {
|
|
331
|
+
label: "Device Pairing Security",
|
|
332
|
+
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",
|
|
333
|
+
},
|
|
279
334
|
agentIsolationMode: {
|
|
280
335
|
label: "Agent Isolation Mode",
|
|
281
336
|
help: "Use a dedicated TeamClaw agent/workspace by default, or the legacy shared main-agent mode",
|