@teamclaws/teamclaw 2026.11.0 → 2026.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/cli.mjs +368 -13
  2. package/dist/index.js +61 -32
  3. package/dist/src/config.js +24 -0
  4. package/dist/src/controller/auth-routes.js +129 -0
  5. package/dist/src/controller/clarification-routes.js +1 -1
  6. package/dist/src/controller/config-routes.js +138 -0
  7. package/dist/src/controller/controller-planning.js +1 -0
  8. package/dist/src/controller/controller-routes.js +195 -0
  9. package/dist/src/controller/controller-service.js +67 -10
  10. package/dist/src/controller/controller-tools.js +3 -1
  11. package/dist/src/controller/github-auth.js +2 -1
  12. package/dist/src/controller/http-server.js +51 -16
  13. package/dist/src/controller/kickoff-orchestrator.js +3 -39
  14. package/dist/src/controller/message-delivery.js +4 -1
  15. package/dist/src/controller/orchestration-manifest.js +5 -65
  16. package/dist/src/controller/preview-manager.js +51 -3
  17. package/dist/src/controller/profile-switch.js +42 -22
  18. package/dist/src/controller/provisioning/backend-contract.js +9 -0
  19. package/dist/src/controller/provisioning/container-shared.js +64 -0
  20. package/dist/src/controller/provisioning/docker.js +214 -0
  21. package/dist/src/controller/provisioning/kubernetes.js +244 -0
  22. package/dist/src/controller/provisioning/plugin-root.js +41 -0
  23. package/dist/src/controller/provisioning/process-supervisor.js +190 -0
  24. package/dist/src/controller/provisioning-config.js +239 -0
  25. package/dist/src/controller/repo-routes.js +70 -4
  26. package/dist/src/controller/report-routes.js +56 -0
  27. package/dist/src/controller/route-table.js +73 -1045
  28. package/dist/src/controller/security.js +775 -0
  29. package/dist/src/controller/status-routes.js +287 -0
  30. package/dist/src/controller/task-assignment.js +5 -2
  31. package/dist/src/controller/task-execution.js +31 -0
  32. package/dist/src/controller/task-results.js +10 -0
  33. package/dist/src/controller/tunnel-manager.js +41 -8
  34. package/dist/src/controller/tunnel-routes.js +225 -0
  35. package/dist/src/controller/websocket.js +6 -2
  36. package/dist/src/controller/webui-routes.js +49 -0
  37. package/dist/src/controller/worker-provisioning.js +39 -949
  38. package/dist/src/controller/workflow-routes.js +407 -0
  39. package/dist/src/controller/workspace-routes.js +200 -0
  40. package/dist/src/git-collaboration.js +4 -9
  41. package/dist/src/identity.js +12 -1
  42. package/dist/src/openclaw-workspace.js +36 -0
  43. package/dist/src/profile-loader.js +119 -1
  44. package/dist/src/profiles/banking.json +26 -2
  45. package/dist/src/profiles/schema.json +82 -2
  46. package/dist/src/prompt-policy.js +18 -6
  47. package/dist/src/protocol.js +66 -3
  48. package/dist/src/shared/clarification-schema.js +65 -0
  49. package/dist/src/shared/github-auth.js +15 -0
  50. package/dist/src/shared/kickoff-prompt.js +37 -0
  51. package/dist/src/shared/utils.js +47 -0
  52. package/dist/src/state.js +89 -3
  53. package/dist/src/teamauto/scanner.js +21 -2
  54. package/dist/src/teamauto/scheduler.js +9 -2
  55. package/dist/src/types.js +15 -1
  56. package/dist/src/ui/app.js +990 -73
  57. package/dist/src/ui/github-login.html +1 -0
  58. package/dist/src/ui/index.html +125 -36
  59. package/dist/src/worker/http-handler.js +59 -0
  60. package/dist/src/worker/skill-installer.js +3 -9
  61. package/dist/src/worker/tools.js +20 -10
  62. package/dist/src/worker/worker-service.js +17 -4
  63. package/index.ts +69 -32
  64. package/openclaw.plugin.json +23 -2
  65. package/package.json +1 -1
  66. package/src/config.ts +24 -0
  67. package/src/controller/auth-routes.ts +157 -0
  68. package/src/controller/clarification-routes.ts +1 -1
  69. package/src/controller/config-routes.ts +152 -0
  70. package/src/controller/controller-planning.ts +8 -0
  71. package/src/controller/controller-routes.ts +237 -0
  72. package/src/controller/controller-service.ts +128 -10
  73. package/src/controller/controller-tools.ts +5 -2
  74. package/src/controller/github-auth.ts +28 -63
  75. package/src/controller/http-server.ts +66 -17
  76. package/src/controller/kickoff-orchestrator.ts +3 -42
  77. package/src/controller/message-delivery.ts +4 -1
  78. package/src/controller/orchestration-manifest.ts +8 -71
  79. package/src/controller/preview-manager.ts +53 -3
  80. package/src/controller/profile-switch.ts +53 -23
  81. package/src/controller/provisioning/backend-contract.ts +51 -0
  82. package/src/controller/provisioning/container-shared.ts +84 -0
  83. package/src/controller/provisioning/docker.ts +260 -0
  84. package/src/controller/provisioning/kubernetes.ts +263 -0
  85. package/src/controller/provisioning/plugin-root.ts +42 -0
  86. package/src/controller/provisioning/process-supervisor.ts +214 -0
  87. package/src/controller/provisioning-config.ts +289 -0
  88. package/src/controller/repo-routes.ts +84 -12
  89. package/src/controller/report-routes.ts +64 -0
  90. package/src/controller/route-table.ts +139 -1152
  91. package/src/controller/security.ts +899 -0
  92. package/src/controller/status-routes.ts +354 -0
  93. package/src/controller/task-assignment.ts +5 -1
  94. package/src/controller/task-execution.ts +43 -0
  95. package/src/controller/task-results.ts +12 -0
  96. package/src/controller/tunnel-manager.ts +45 -8
  97. package/src/controller/tunnel-routes.ts +231 -0
  98. package/src/controller/websocket.ts +20 -3
  99. package/src/controller/webui-routes.ts +55 -0
  100. package/src/controller/worker-provisioning.ts +51 -1117
  101. package/src/controller/workflow-routes.ts +498 -0
  102. package/src/controller/workspace-routes.ts +222 -0
  103. package/src/git-collaboration.ts +4 -9
  104. package/src/identity.ts +13 -1
  105. package/src/openclaw-workspace.ts +47 -0
  106. package/src/profile-loader.ts +167 -1
  107. package/src/profiles/banking.json +26 -2
  108. package/src/profiles/schema.json +82 -2
  109. package/src/prompt-policy.ts +19 -6
  110. package/src/protocol.ts +72 -2
  111. package/src/shared/clarification-schema.ts +81 -0
  112. package/src/shared/github-auth.ts +92 -0
  113. package/src/shared/kickoff-prompt.ts +47 -0
  114. package/src/shared/utils.ts +51 -0
  115. package/src/state.ts +92 -3
  116. package/src/teamauto/github-client.ts +2 -1
  117. package/src/teamauto/repo-sync.ts +2 -1
  118. package/src/teamauto/scanner.ts +22 -3
  119. package/src/teamauto/scheduler.ts +11 -3
  120. package/src/teamauto/store.ts +5 -0
  121. package/src/types.ts +130 -1
  122. package/src/ui/app.js +990 -73
  123. package/src/ui/github-login.html +1 -0
  124. package/src/ui/index.html +125 -36
  125. package/src/worker/http-handler.ts +64 -1
  126. package/src/worker/skill-installer.ts +3 -9
  127. package/src/worker/tools.ts +21 -10
  128. package/src/worker/worker-service.ts +18 -4
package/cli.mjs CHANGED
@@ -20,6 +20,7 @@ const PACKAGE_INSTALL_SPEC = `${PACKAGE_NAME}@${PACKAGE_VERSION}`;
20
20
  const PLUGIN_ID = "teamclaw";
21
21
  const DANGEROUS_INSTALL_FLAG = "--dangerously-force-unsafe-install";
22
22
  const CAPABILITY_CONSENT_FLAG = "--accept-capabilities";
23
+ const FORCE_INSTALL_FLAG = "--force";
23
24
 
24
25
  /**
25
26
  * OpenClaw 2026.10+ replaced the legacy break-glass install flag (now a
@@ -32,6 +33,19 @@ const CAPABILITY_CONSENT_FLAG = "--accept-capabilities";
32
33
  function isCapabilityConsentRequired(output) {
33
34
  return /accept-capabilities|capability[\s-]?consent|CapabilityConsentRequired/i.test(String(output || ""));
34
35
  }
36
+
37
+ /**
38
+ * openclaw 2026.10+ retired the legacy break-glass install flag (now a
39
+ * deprecated no-op) and cancels any install from a source outside ClawHub
40
+ * review/trust metadata — local package directories and npm-registry packages
41
+ * alike — asking the operator to rerun with --force after reviewing the
42
+ * source. This source gate cancels before the capability-consent check, so
43
+ * the capability error never surfaces on its own and both consents must be
44
+ * appended on the retry (issue #261).
45
+ */
46
+ function isSourceTrustGateCancel(output) {
47
+ return /rerun with --force|outside ClawHub review/i.test(String(output || ""));
48
+ }
35
49
  const DEFAULT_TEAMCLAW_IMAGE = "ghcr.io/topcheer/teamclaw-openclaw:latest";
36
50
  const DEFAULT_CONTROLLER_PORT = 9527;
37
51
  const DEFAULT_WORKER_PORT = 9528;
@@ -44,6 +58,16 @@ const TEAMCLAW_AGENT_ID = "teamclaw";
44
58
  const TEAMCLAW_RECOMMENDED_EXEC_SECURITY = "full";
45
59
  const TEAMCLAW_RECOMMENDED_EXEC_ASK = "off";
46
60
  const TEAMCLAW_RECOMMENDED_COMMAND_MODE = "auto";
61
+ /**
62
+ * The installer historically wrote commands.ownerDisplay="raw" as a host
63
+ * default. openclaw 2026.11 renders owner ids raw when the key is absent and
64
+ * its doctor now removes the key outright, while openclaw 2026.10.x config
65
+ * validation rejects the key as unrecognized — poisoning every later host CLI
66
+ * invocation after an install (issue #261). This value is what the installer
67
+ * used to write and what it now prunes; explicit non-default user choices are
68
+ * preserved.
69
+ */
70
+ const TEAMCLAW_RETIRED_OWNER_DISPLAY_DEFAULT = "raw";
47
71
  const AGENT_MODE_OPTIONS = [
48
72
  {
49
73
  value: "independent",
@@ -67,8 +91,27 @@ let ROLE_OPTIONS = [];
67
91
  let DEFAULT_WORKER_ROLE = "";
68
92
 
69
93
  async function loadRoleOptions() {
94
+ // #253 layout-adaptive loading via VARIABLE specifiers: bundlers and the
95
+ // image's dist-import checker treat a LITERAL dynamic import whose target
96
+ // does not exist in the current layout (./dist/src/roles.js is a phantom
97
+ // under the image's flat bundle; ./index.js does not exist in the npm
98
+ // tarball) as an unresolved edge and fail the build. A runtime variable
99
+ // defeats static resolution on purpose: whichever layout this file ships
100
+ // in resolves exactly one of the candidates.
101
+ const ROLE_MODULE_CANDIDATES = ["./dist/src/roles.js", "./index.js"];
102
+ let rolesModule = null;
103
+ for (const candidate of ROLE_MODULE_CANDIDATES) {
104
+ try {
105
+ rolesModule = await import(candidate);
106
+ break;
107
+ } catch {
108
+ // try the next layout
109
+ }
110
+ }
70
111
  try {
71
- const rolesModule = await import("./dist/src/roles.js");
112
+ if (!rolesModule) {
113
+ throw new Error("no role registry module found in any known layout");
114
+ }
72
115
  const roles = Array.isArray(rolesModule.ROLES) ? rolesModule.ROLES : [];
73
116
  ROLE_OPTIONS = roles
74
117
  .filter((role) => role && typeof role.id === "string" && role.id.trim())
@@ -81,9 +124,9 @@ async function loadRoleOptions() {
81
124
  ? registryDefault
82
125
  : "";
83
126
  } 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.
127
+ // Neither layout resolvable (pre-build dev checkout). Keep the registry
128
+ // empty so callers fail with the actionable guidance in
129
+ // ensureRoleOptionsLoaded instead of presenting a stale role list.
87
130
  ROLE_OPTIONS = [];
88
131
  DEFAULT_WORKER_ROLE = "";
89
132
  }
@@ -92,7 +135,7 @@ async function loadRoleOptions() {
92
135
  function ensureRoleOptionsLoaded() {
93
136
  if (ROLE_OPTIONS.length === 0) {
94
137
  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.",
138
+ "TeamClaw role registry unavailable (tried ./dist/src/roles.js and ./index.js). Run `npm --prefix src run build` in the repository, or reinstall the @teamclaws/teamclaw package, then retry.",
96
139
  );
97
140
  }
98
141
  }
@@ -135,7 +178,20 @@ Usage:
135
178
 
136
179
  Commands:
137
180
  install Install/configure TeamClaw for OpenClaw
138
- help Show this help
181
+ pair <controller-url> Pair this instance with a controller that has device
182
+ protection enabled (issue #23). Without --code it
183
+ first tries zero-input LAN auto-pairing.
184
+ --code <code> One-shot pairing code from the controller owner
185
+ (web UI: Device security -> New pairing code)
186
+ --name <name> Device name shown in the controller device list
187
+ --kind <kind> Device kind: worker, desktop or cli (default cli)
188
+ --config <path> OpenClaw config path to store the token in
189
+ token reset <controller-url>
190
+ Revoke ALL paired devices and return the controller
191
+ to unpaired local mode (loopback host, or --token)
192
+ --token <token> Device token (required from a non-loopback host)
193
+ --config <path> OpenClaw config path to clear the stored token from
194
+ help Show this help
139
195
 
140
196
  Options:
141
197
  --config <path> Override the OpenClaw config path
@@ -249,6 +305,242 @@ function parseArgs(argv) {
249
305
  return { command: command || "help", options };
250
306
  }
251
307
 
308
+ // ===========================================================================
309
+ // Device pairing commands (issue #23, client wave).
310
+ //
311
+ // pair <controller-url> [--code] [--name] [--kind] - exchange a one-shot
312
+ // code (or a LAN auto-pair attempt) for a device token, then store it as
313
+ // plugins.entries.teamclaw.config.securityToken in the OpenClaw config so
314
+ // every later worker/controller API call from this instance carries the
315
+ // X-TeamClaw-Token header automatically.
316
+ // token reset <controller-url> [--token] - revoke all devices (loopback
317
+ // host needs no token) and clear any locally stored token.
318
+ // ===========================================================================
319
+
320
+ const PAIR_DEVICE_KINDS = new Set(["worker", "desktop", "cli"]);
321
+ const SECURITY_REQUEST_TIMEOUT_MS = 15_000;
322
+
323
+ function normalizeControllerUrlArg(raw) {
324
+ let value = String(raw || "").trim();
325
+ if (!value) {
326
+ throw new Error("A controller URL is required (e.g. http://192.168.1.10:9527).");
327
+ }
328
+ if (!value.startsWith("http://") && !value.startsWith("https://")) {
329
+ value = `http://${value}`;
330
+ }
331
+ try {
332
+ const parsed = new URL(value);
333
+ if (!parsed.hostname) {
334
+ throw new Error("empty host");
335
+ }
336
+ // Strip any trailing path/slash so endpoint joining stays predictable.
337
+ return `${parsed.protocol}//${parsed.host}`;
338
+ } catch (error) {
339
+ throw new Error(`Invalid controller URL: ${raw}`);
340
+ }
341
+ }
342
+
343
+ function readFlagValue(argv, index, flag) {
344
+ const value = argv[index + 1];
345
+ if (!value) {
346
+ throw new Error(`${flag} requires a value`);
347
+ }
348
+ return value;
349
+ }
350
+
351
+ function parsePairArgs(argv) {
352
+ const options = { controllerUrl: "", code: "", name: "", kind: "cli", configPath: "" };
353
+ const positional = [];
354
+ for (let index = 0; index < argv.length; index += 1) {
355
+ const arg = argv[index];
356
+ if (arg === "--help" || arg === "-h") {
357
+ return { help: true, options };
358
+ }
359
+ if (arg.startsWith("--")) {
360
+ if (arg === "--code") {
361
+ options.code = readFlagValue(argv, index, arg).trim();
362
+ index += 1;
363
+ } else if (arg === "--name") {
364
+ options.name = readFlagValue(argv, index, arg).trim();
365
+ index += 1;
366
+ } else if (arg === "--kind") {
367
+ const kind = readFlagValue(argv, index, arg).trim();
368
+ if (!PAIR_DEVICE_KINDS.has(kind)) {
369
+ throw new Error(`--kind requires one of: ${[...PAIR_DEVICE_KINDS].join(", ")}`);
370
+ }
371
+ options.kind = kind;
372
+ index += 1;
373
+ } else if (arg === "--config") {
374
+ options.configPath = readFlagValue(argv, index, arg);
375
+ index += 1;
376
+ } else {
377
+ throw new Error(`Unknown argument: ${arg}`);
378
+ }
379
+ continue;
380
+ }
381
+ positional.push(arg);
382
+ }
383
+ if (positional.length !== 1) {
384
+ throw new Error('Usage: teamclaw pair <controller-url> [--code <code>] [--name <name>] [--kind worker|desktop|cli]');
385
+ }
386
+ options.controllerUrl = positional[0];
387
+ return { help: false, options };
388
+ }
389
+
390
+ function parseTokenArgs(argv) {
391
+ const options = { controllerUrl: "", token: "", configPath: "" };
392
+ const positional = [];
393
+ for (let index = 0; index < argv.length; index += 1) {
394
+ const arg = argv[index];
395
+ if (arg === "--help" || arg === "-h") {
396
+ return { help: true, options };
397
+ }
398
+ if (arg.startsWith("--")) {
399
+ if (arg === "--token") {
400
+ options.token = readFlagValue(argv, index, arg).trim();
401
+ index += 1;
402
+ } else if (arg === "--config") {
403
+ options.configPath = readFlagValue(argv, index, arg);
404
+ index += 1;
405
+ } else {
406
+ throw new Error(`Unknown argument: ${arg}`);
407
+ }
408
+ continue;
409
+ }
410
+ positional.push(arg);
411
+ }
412
+ if (positional.length === 0 || positional[0] !== "reset") {
413
+ throw new Error('Usage: teamclaw token reset <controller-url> [--token <token>]');
414
+ }
415
+ if (positional.length !== 2) {
416
+ throw new Error('Usage: teamclaw token reset <controller-url> [--token <token>]');
417
+ }
418
+ options.controllerUrl = positional[1];
419
+ return { help: false, options };
420
+ }
421
+
422
+ async function securityFetch(controllerUrl, pathname, { method = "POST", body, token } = {}) {
423
+ const headers = {};
424
+ if (body !== undefined) {
425
+ headers["Content-Type"] = "application/json";
426
+ }
427
+ if (token) {
428
+ headers["X-TeamClaw-Token"] = token;
429
+ }
430
+ let response;
431
+ try {
432
+ response = await fetch(`${controllerUrl}/api/v1${pathname}`, {
433
+ method,
434
+ headers,
435
+ body: body !== undefined ? JSON.stringify(body) : undefined,
436
+ signal: AbortSignal.timeout(SECURITY_REQUEST_TIMEOUT_MS),
437
+ });
438
+ } catch (error) {
439
+ throw new Error(`Could not reach the controller at ${controllerUrl}: ${error instanceof Error ? error.message : String(error)}`);
440
+ }
441
+ let payload = null;
442
+ try {
443
+ payload = await response.json();
444
+ } catch {
445
+ payload = null;
446
+ }
447
+ return { status: response.status, ok: response.ok, payload };
448
+ }
449
+
450
+ function describeSecurityError(result, fallback) {
451
+ if (result.payload && typeof result.payload === "object") {
452
+ const parts = [result.payload.error, result.payload.hint].filter((part) => typeof part === "string" && part.trim());
453
+ if (parts.length > 0) {
454
+ return parts.join(" - ");
455
+ }
456
+ }
457
+ return `${fallback} (HTTP ${result.status})`;
458
+ }
459
+
460
+ async function upsertTeamClawConfig(configPath, update) {
461
+ const config = await readOpenClawConfig(configPath);
462
+ const plugins = ensureRecord(config, "plugins");
463
+ const entries = ensureRecord(plugins, "entries");
464
+ const teamclawEntry = ensureRecord(entries, PLUGIN_ID);
465
+ const teamclawConfig = ensureRecord(teamclawEntry, "config");
466
+ update(teamclawConfig);
467
+ await writeConfig(configPath, config);
468
+ }
469
+
470
+ async function runPair(options) {
471
+ const controllerUrl = normalizeControllerUrlArg(options.controllerUrl);
472
+ const kind = options.kind;
473
+ const name = options.name || `${os.hostname()} ${kind}`;
474
+ let result;
475
+ if (options.code) {
476
+ result = await securityFetch(controllerUrl, "/security/pair", {
477
+ body: { code: options.code.toUpperCase(), kind, name },
478
+ });
479
+ } else {
480
+ // Zero-input LAN path first (mDNS scenario): a LAN peer pairs without a
481
+ // code while the controller allows auto-pairing.
482
+ result = await securityFetch(controllerUrl, "/security/pair-auto", { body: { kind, name } });
483
+ if (result.status === 403) {
484
+ throw new Error(
485
+ "This controller did not accept zero-input pairing (not a LAN peer, or auto-pairing is disabled). " +
486
+ "Ask the controller owner for a one-shot pairing code (web UI: Device security -> New pairing code) and rerun with --code <code>.",
487
+ );
488
+ }
489
+ }
490
+ if (!result.ok || !result.payload || typeof result.payload.token !== "string") {
491
+ if (result.status === 409) {
492
+ throw new Error(describeSecurityError(result, "Device protection is not enabled on this controller; there is nothing to pair with yet"));
493
+ }
494
+ throw new Error(describeSecurityError(result, "Pairing failed"));
495
+ }
496
+ const configPath = expandUserPath(options.configPath || resolveDefaultOpenClawConfigPath());
497
+ await upsertTeamClawConfig(configPath, (teamclawConfig) => {
498
+ // Same layer as teamName: the worker/controller pipeline reads this and
499
+ // sends X-TeamClaw-Token on every API call automatically.
500
+ teamclawConfig.securityToken = result.payload.token;
501
+ if (!teamclawConfig.controllerUrl) {
502
+ teamclawConfig.controllerUrl = controllerUrl;
503
+ }
504
+ });
505
+ console.log(`Paired with ${controllerUrl}`);
506
+ console.log(` Device: "${result.payload.device?.name || name}" (kind ${kind}, id ${result.payload.deviceId || result.payload.device?.id || "?"})`);
507
+ console.log(` Token stored at plugins.entries.teamclaw.config.securityToken in ${configPath}`);
508
+ 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.");
509
+ console.log("Next step: restart this instance (or run `openclaw gateway restart`) so its API calls pick up the token.");
510
+ }
511
+
512
+ async function runTokenReset(options) {
513
+ const controllerUrl = normalizeControllerUrlArg(options.controllerUrl);
514
+ const result = await securityFetch(controllerUrl, "/security/reset", { body: {}, token: options.token });
515
+ if (!result.ok) {
516
+ if (result.status === 401) {
517
+ throw new Error(
518
+ "Reset refused: only the controller host itself (loopback) or an authenticated device may reset. " +
519
+ "Run this on the controller machine, or pass --token <device-token>.",
520
+ );
521
+ }
522
+ throw new Error(describeSecurityError(result, "Token reset failed"));
523
+ }
524
+ // Best effort: drop the now-invalid local token so the next pair starts clean.
525
+ const configPath = expandUserPath(options.configPath || resolveDefaultOpenClawConfigPath());
526
+ try {
527
+ const config = await readOpenClawConfig(configPath);
528
+ const teamclawConfig = getExistingTeamClawConfig(config);
529
+ if (typeof teamclawConfig.securityToken === "string" && teamclawConfig.securityToken) {
530
+ delete teamclawConfig.securityToken;
531
+ const plugins = ensureRecord(config, "plugins");
532
+ const entries = ensureRecord(plugins, "entries");
533
+ const teamclawEntry = ensureRecord(entries, PLUGIN_ID);
534
+ teamclawEntry.config = teamclawConfig;
535
+ await writeConfig(configPath, config);
536
+ console.log(`Cleared the stored device token from ${configPath}`);
537
+ }
538
+ } catch {
539
+ // No local config/token to clear - resetting a remote controller only.
540
+ }
541
+ console.log(`All paired devices on ${controllerUrl} were revoked; the controller is back to unpaired local mode (L0).`);
542
+ }
543
+
252
544
  function isRecord(value) {
253
545
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
254
546
  }
@@ -406,6 +698,36 @@ async function writeConfig(configPath, config) {
406
698
  await fs.writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
407
699
  }
408
700
 
701
+ /**
702
+ * openclaw 2026.10.x config validation rejects the retired commands.ownerDisplay
703
+ * key ("Unrecognized key"), so a config still carrying the value written by an
704
+ * earlier installer deadlocks every host CLI invocation — including the plugin
705
+ * install this run is about to attempt (issue #261). Prune the
706
+ * installer-written "raw" default before any host command runs: the value is
707
+ * openclaw 2026.11's built-in default, and explicit non-default user choices
708
+ * are left untouched.
709
+ */
710
+ async function pruneInstallerWrittenOwnerDisplay(configPath) {
711
+ let config;
712
+ try {
713
+ config = await readOpenClawConfig(configPath);
714
+ } catch {
715
+ // Unparseable config: leave it alone; the host CLI and the existing
716
+ // config-parse error path will surface the problem.
717
+ return false;
718
+ }
719
+ const commands = isRecord(config.commands) ? config.commands : null;
720
+ if (!commands || commands.ownerDisplay !== TEAMCLAW_RETIRED_OWNER_DISPLAY_DEFAULT) {
721
+ return false;
722
+ }
723
+ delete commands.ownerDisplay;
724
+ await writeConfig(configPath, config);
725
+ console.log(
726
+ `Removed commands.ownerDisplay from ${configPath}: the key is retired, openclaw 2026.10.x rejects it as unrecognized (which blocks every OpenClaw command), and openclaw renders owner ids raw by default.`,
727
+ );
728
+ return true;
729
+ }
730
+
409
731
  function getExistingTeamClawConfig(config) {
410
732
  if (!isRecord(config)) {
411
733
  return {};
@@ -1085,7 +1407,7 @@ function attemptPluginInstall({ configPath }) {
1085
1407
  }
1086
1408
  }
1087
1409
  console.log(
1088
- `\nTeamClaw uses host-level orchestration capabilities, so OpenClaw requires an install consent flag during plugin installation (legacy: ${DANGEROUS_INSTALL_FLAG}; OpenClaw 2026.10+: ${CAPABILITY_CONSENT_FLAG}).`,
1410
+ `\nTeamClaw uses host-level orchestration capabilities, so OpenClaw requires install consent flags during plugin installation (legacy: ${DANGEROUS_INSTALL_FLAG}; OpenClaw 2026.10+: ${FORCE_INSTALL_FLAG} ${CAPABILITY_CONSENT_FLAG}).`,
1089
1411
  );
1090
1412
  const candidates = [
1091
1413
  {
@@ -1140,12 +1462,14 @@ function attemptPluginInstall({ configPath }) {
1140
1462
  if (
1141
1463
  result.status !== 0 &&
1142
1464
  !candidate.args.includes(CAPABILITY_CONSENT_FLAG) &&
1143
- isCapabilityConsentRequired(result.output)
1465
+ (isCapabilityConsentRequired(result.output) || isSourceTrustGateCancel(result.output))
1144
1466
  ) {
1145
- console.log("OpenClaw requires capability consent; retrying with --accept-capabilities...");
1467
+ console.log(
1468
+ `OpenClaw requires install consent; retrying with ${FORCE_INSTALL_FLAG} and ${CAPABILITY_CONSENT_FLAG}...`,
1469
+ );
1146
1470
  result = installPluginWithCommand(
1147
1471
  candidate.command,
1148
- [...candidate.args, CAPABILITY_CONSENT_FLAG],
1472
+ [...candidate.args, FORCE_INSTALL_FLAG, CAPABILITY_CONSENT_FLAG],
1149
1473
  env,
1150
1474
  );
1151
1475
  }
@@ -1630,8 +1954,12 @@ function applyTeamClawHostRuntimeDefaults(next) {
1630
1954
  if (typeof commands.restart !== "boolean") {
1631
1955
  commands.restart = true;
1632
1956
  }
1633
- if (typeof commands.ownerDisplay !== "string" || !commands.ownerDisplay.trim()) {
1634
- commands.ownerDisplay = "raw";
1957
+ if (commands.ownerDisplay === TEAMCLAW_RETIRED_OWNER_DISPLAY_DEFAULT) {
1958
+ // openclaw 2026.10.x rejects this retired key ("Unrecognized key"), which
1959
+ // deadlocks every later host CLI invocation; openclaw 2026.11 renders
1960
+ // owner ids raw by default anyway. Prune the installer-written default
1961
+ // and keep explicit non-default user choices (issue #261).
1962
+ delete commands.ownerDisplay;
1635
1963
  }
1636
1964
 
1637
1965
  const tools = ensureRecord(next, "tools");
@@ -2005,6 +2333,12 @@ async function runInstall(options) {
2005
2333
  : `Created ${configPath}`);
2006
2334
  }
2007
2335
 
2336
+ if (!options.dryRun) {
2337
+ // Heal configs poisoned by earlier installers before any host OpenClaw
2338
+ // command runs (issue #261).
2339
+ await pruneInstallerWrittenOwnerDisplay(configPath);
2340
+ }
2341
+
2008
2342
  let pluginInstallStatus = "skipped";
2009
2343
  let pluginInstallMethod = "";
2010
2344
  let pluginInstallError = "";
@@ -2103,8 +2437,29 @@ async function runInstall(options) {
2103
2437
  }
2104
2438
 
2105
2439
  async function main() {
2440
+ const argv = process.argv.slice(2);
2441
+ // Issue #23 pairing commands dispatch before the installer parser (their
2442
+ // positional <controller-url> argument is not an installer flag).
2443
+ if (argv[0] === "pair") {
2444
+ const { help, options } = parsePairArgs(argv.slice(1));
2445
+ if (help) {
2446
+ printHelp();
2447
+ return;
2448
+ }
2449
+ await runPair(options);
2450
+ return;
2451
+ }
2452
+ if (argv[0] === "token") {
2453
+ const { help, options } = parseTokenArgs(argv.slice(1));
2454
+ if (help) {
2455
+ printHelp();
2456
+ return;
2457
+ }
2458
+ await runTokenReset(options);
2459
+ return;
2460
+ }
2106
2461
  await loadRoleOptions();
2107
- const { command, options } = parseArgs(process.argv.slice(2));
2462
+ const { command, options } = parseArgs(argv);
2108
2463
  if (command === "help") {
2109
2464
  printHelp();
2110
2465
  return;
package/dist/index.js CHANGED
@@ -15,6 +15,16 @@ 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";
21
+ // #253: the image build compiles this plugin into a flat rolldown bundle
22
+ // (dist/extensions/teamclaw/index.js) with NO nested dist/src tree, while the
23
+ // npm tarball layout ships dist/src/roles.js and no top-level index.js. The
24
+ // installer CLI (cli.mjs) reads the role registry through whichever layout it
25
+ // lands in, so the registry must be reachable from this entry as a named
26
+ // export for the bundled layout to resolve it.
27
+ export { ROLES, DEFAULT_ROLE } from "./src/roles.js";
18
28
  export default definePluginEntry({
19
29
  id: "teamclaw",
20
30
  name: "TeamClaw",
@@ -76,32 +86,36 @@ function registerController(api, config) {
76
86
  });
77
87
  });
78
88
  }
79
- function registerWorker(api, config) {
80
- const logger = api.logger;
81
- const messageQueue = new MessageQueue();
82
- let currentControllerUrl = null;
83
- let currentWorkerId = null;
84
- function getIdentity() {
85
- if (!currentWorkerId || !currentControllerUrl)
86
- return null;
87
- return {
88
- workerId: currentWorkerId,
89
- role: config.role,
90
- controllerUrl: currentControllerUrl,
91
- registeredAt: Date.now(),
92
- };
93
- }
89
+ /**
90
+ * Issue #23 (client wave): headers for worker -> controller calls, same
91
+ * pattern as identity.ts / worker-service.ts / worker/tools.ts. A configured
92
+ * device token rides X-TeamClaw-Token; without one the headers are unchanged
93
+ * (L0). The token value is never logged.
94
+ */
95
+ function withDeviceToken(config, headers) {
96
+ const token = config.securityToken?.trim();
97
+ return token ? { ...headers, "X-TeamClaw-Token": token } : headers;
98
+ }
99
+ /**
100
+ * Execution-event + checkpoint reporters (issue #23 review follow-up: the
101
+ * execution stream and resume checkpoints MUST survive device protection, so
102
+ * both POSTs carry the paired device token). Extracted from registerWorker
103
+ * as an exported factory so the dist-level client tests can exercise the
104
+ * real header behavior against a stub controller.
105
+ */
106
+ export function createWorkerEventReporters(config, logger, state) {
94
107
  async function reportExecutionEvent(taskId, event) {
95
- if (!currentControllerUrl) {
108
+ const controllerUrl = state.getControllerUrl();
109
+ if (!controllerUrl) {
96
110
  return;
97
111
  }
98
112
  try {
99
- const res = await fetch(`${currentControllerUrl}/api/v1/tasks/${taskId}/execution`, {
113
+ const res = await fetch(`${controllerUrl}/api/v1/tasks/${taskId}/execution`, {
100
114
  method: "POST",
101
- headers: { "Content-Type": "application/json" },
115
+ headers: withDeviceToken(config, { "Content-Type": "application/json" }),
102
116
  body: JSON.stringify({
103
117
  ...event,
104
- workerId: currentWorkerId ?? undefined,
118
+ workerId: state.getWorkerId() ?? undefined,
105
119
  role: config.role,
106
120
  }),
107
121
  });
@@ -114,20 +128,44 @@ function registerWorker(api, config) {
114
128
  }
115
129
  }
116
130
  async function reportCheckpoint(taskId, checkpoint) {
117
- if (!currentControllerUrl) {
131
+ const controllerUrl = state.getControllerUrl();
132
+ if (!controllerUrl) {
118
133
  return;
119
134
  }
120
135
  try {
121
- await fetch(`${currentControllerUrl}/api/v1/tasks/${taskId}/checkpoint`, {
136
+ await fetch(`${controllerUrl}/api/v1/tasks/${taskId}/checkpoint`, {
122
137
  method: "POST",
123
- headers: { "Content-Type": "application/json" },
124
- body: JSON.stringify({ ...checkpoint, workerId: currentWorkerId ?? undefined }),
138
+ headers: withDeviceToken(config, { "Content-Type": "application/json" }),
139
+ body: JSON.stringify({ ...checkpoint, workerId: state.getWorkerId() ?? undefined }),
125
140
  });
126
141
  }
127
142
  catch {
128
143
  // Checkpointing is best-effort; a lost heartbeat only costs resume freshness.
129
144
  }
130
145
  }
146
+ return { reportExecutionEvent, reportCheckpoint };
147
+ }
148
+ function registerWorker(api, config) {
149
+ const logger = api.logger;
150
+ const messageQueue = new MessageQueue();
151
+ let currentControllerUrl = null;
152
+ let currentWorkerId = null;
153
+ function getIdentity() {
154
+ if (!currentWorkerId || !currentControllerUrl)
155
+ return null;
156
+ return {
157
+ workerId: currentWorkerId,
158
+ role: config.role,
159
+ controllerUrl: currentControllerUrl,
160
+ registeredAt: Date.now(),
161
+ };
162
+ }
163
+ const { reportExecutionEvent, reportCheckpoint } = createWorkerEventReporters(config, logger, {
164
+ // Read through getters so the reporters always see the identity the
165
+ // worker service has established by the time an event fires.
166
+ getControllerUrl: () => currentControllerUrl,
167
+ getWorkerId: () => currentWorkerId,
168
+ });
131
169
  const getWorkerSessionKey = (assignment) => assignment.executionSessionKey?.trim() || `teamclaw-task-${assignment.taskId}`;
132
170
  const taskExecutor = createRoleTaskExecutor({
133
171
  runtime: api.runtime,
@@ -155,15 +193,6 @@ function registerWorker(api, config) {
155
193
  }
156
194
  return { sharedProjectDir, localProjectDir };
157
195
  }
158
- async function pathExists(targetPath) {
159
- try {
160
- await fs.access(targetPath);
161
- return true;
162
- }
163
- catch {
164
- return false;
165
- }
166
- }
167
196
  async function syncProjectDir(sourceDir, destinationDir) {
168
197
  if (!await pathExists(sourceDir)) {
169
198
  return false;
@@ -103,6 +103,26 @@ function buildConfigSchema() {
103
103
  default: "",
104
104
  description: "GitHub App OAuth client secret; the TEAMCLAW_GITHUB_CLIENT_SECRET environment variable takes precedence",
105
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
+ },
106
126
  agentIsolationMode: {
107
127
  type: "string",
108
128
  enum: ["independent", "main"],
@@ -307,6 +327,10 @@ function buildConfigSchema() {
307
327
  hint: "optional - prefer the TEAMCLAW_GITHUB_CLIENT_SECRET env var",
308
328
  help: "GitHub App OAuth client secret; the TEAMCLAW_GITHUB_CLIENT_SECRET environment variable takes precedence",
309
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
+ },
310
334
  agentIsolationMode: {
311
335
  label: "Agent Isolation Mode",
312
336
  help: "Use a dedicated TeamClaw agent/workspace by default, or the legacy shared main-agent mode",