@teamclaws/teamclaw 2026.8.0 → 2026.11.0
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 +46 -15
- package/dist/api.js +1 -0
- package/dist/index.js +325 -0
- package/dist/src/config.js +412 -0
- package/dist/src/controller/clarification-routes.js +315 -0
- package/dist/src/controller/controller-capacity.js +14 -0
- package/dist/src/controller/controller-intake.js +895 -0
- package/dist/src/controller/controller-planning.js +813 -0
- package/dist/src/controller/controller-runs.js +175 -0
- package/dist/src/controller/controller-service.js +624 -0
- package/dist/src/controller/controller-tools.js +587 -0
- package/dist/src/controller/delivery-report.js +458 -0
- package/dist/src/controller/github-auth.js +564 -0
- package/dist/src/controller/http-server.js +284 -0
- package/dist/src/controller/kickoff-orchestrator.js +246 -0
- package/dist/src/controller/managed-gateway-process.js +286 -0
- package/dist/src/controller/message-delivery.js +28 -0
- package/dist/src/controller/message-router.js +38 -0
- package/dist/src/controller/message-routes.js +114 -0
- package/dist/src/controller/orchestration-manifest.js +151 -0
- package/dist/src/controller/preview-manager.js +586 -0
- package/dist/src/controller/preview-proxy.js +98 -0
- package/dist/src/controller/profile-switch.js +289 -0
- package/dist/src/controller/project-registry.js +294 -0
- package/dist/src/controller/prompt-injector.js +197 -0
- package/dist/src/controller/repo-routes.js +63 -0
- package/dist/src/controller/role-inference.js +246 -0
- package/dist/src/controller/route-table.js +1353 -0
- package/dist/src/controller/task-assignment.js +508 -0
- package/dist/src/controller/task-cleanup.js +258 -0
- package/dist/src/controller/task-execution.js +240 -0
- package/dist/src/controller/task-results.js +461 -0
- package/dist/src/controller/task-router.js +137 -0
- 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 +548 -0
- package/dist/src/controller/ui-assets.js +68 -0
- package/dist/src/controller/websocket.js +42 -0
- package/dist/src/controller/worker-provisioning.js +1674 -0
- package/dist/src/controller/worker-routes.js +188 -0
- package/dist/src/discovery.js +86 -0
- package/dist/src/git-collaboration.js +694 -0
- package/dist/src/identity.js +132 -0
- package/dist/src/install-defaults.js +1 -0
- package/dist/src/interaction-contracts.js +531 -0
- package/dist/src/networking.js +91 -0
- package/dist/src/openclaw-workspace.js +925 -0
- package/dist/src/profile-loader.js +486 -0
- package/dist/src/profiles/banking.json +178 -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 +201 -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 +386 -0
- package/dist/src/protocol.js +58 -0
- package/dist/src/role-ids.js +29 -0
- package/dist/src/roles.js +390 -0
- package/dist/src/session-roles.js +14 -0
- package/dist/src/state.js +361 -0
- package/dist/src/task-executor.js +1023 -0
- package/dist/src/teamauto/github-client.js +210 -0
- package/dist/src/teamauto/norms.js +85 -0
- package/dist/src/teamauto/repo-sync.js +423 -0
- package/dist/src/teamauto/scanner.js +207 -0
- package/dist/src/teamauto/schedule.js +123 -0
- package/dist/src/teamauto/scheduler.js +907 -0
- package/dist/src/teamauto/store.js +133 -0
- package/dist/src/types.js +290 -0
- package/dist/src/ui/app.js +4860 -0
- package/dist/src/ui/assets/teamclaw-app-icon.png +0 -0
- package/dist/src/ui/github-login.html +296 -0
- package/dist/src/ui/index.html +447 -0
- package/dist/src/ui/style.css +2805 -0
- package/dist/src/worker/http-handler.js +146 -0
- package/dist/src/worker/message-queue.js +24 -0
- package/dist/src/worker/prompt-injector.js +78 -0
- package/dist/src/worker/skill-installer.js +255 -0
- package/dist/src/worker/tools.js +541 -0
- package/dist/src/worker/worker-service.js +307 -0
- package/dist/src/workspace-browser.js +269 -0
- package/openclaw.plugin.json +28 -1
- package/package.json +3 -2
- package/src/config.ts +33 -2
- package/src/controller/clarification-routes.ts +404 -0
- package/src/controller/controller-intake.ts +1113 -0
- package/src/controller/controller-planning.ts +1029 -0
- package/src/controller/controller-runs.ts +239 -0
- package/src/controller/controller-service.ts +295 -41
- package/src/controller/controller-tools.ts +11 -7
- package/src/controller/http-server.ts +294 -6971
- package/src/controller/kickoff-orchestrator.ts +70 -7
- package/src/controller/message-delivery.ts +49 -0
- package/src/controller/message-routes.ts +137 -0
- package/src/controller/orchestration-manifest.ts +6 -29
- package/src/controller/preview-proxy.ts +127 -0
- package/src/controller/profile-switch.ts +366 -0
- package/src/controller/project-registry.ts +361 -0
- package/src/controller/prompt-injector.ts +23 -8
- package/src/controller/repo-routes.ts +91 -0
- package/src/controller/role-inference.ts +260 -22
- package/src/controller/route-table.ts +1616 -0
- package/src/controller/task-assignment.ts +618 -0
- package/src/controller/task-cleanup.ts +344 -0
- package/src/controller/task-execution.ts +356 -0
- package/src/controller/task-results.ts +544 -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/ui-assets.ts +70 -0
- package/src/controller/websocket.ts +13 -1
- package/src/controller/worker-provisioning.ts +32 -4
- package/src/controller/worker-routes.ts +241 -0
- package/src/identity.ts +3 -2
- package/src/interaction-contracts.ts +7 -7
- package/src/openclaw-workspace.ts +44 -18
- package/src/profile-loader.ts +650 -0
- package/src/profiles/banking.json +178 -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 +201 -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 +27 -13
- package/src/role-ids.ts +31 -0
- package/src/roles.ts +60 -14
- package/src/session-roles.ts +14 -0
- package/src/state.ts +236 -9
- package/src/task-executor.ts +7 -18
- package/src/teamauto/github-client.ts +21 -0
- package/src/teamauto/repo-sync.ts +246 -6
- package/src/teamauto/scanner.ts +47 -13
- package/src/teamauto/scheduler.ts +259 -16
- package/src/teamauto/store.ts +12 -0
- package/src/types.ts +133 -16
- package/src/ui/app.js +592 -24
- package/src/ui/index.html +44 -11
- package/src/ui/style.css +194 -0
- package/src/worker/prompt-injector.ts +48 -8
- package/src/worker/skill-installer.ts +3 -1
- package/src/worker/worker-service.ts +83 -3
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
|
{
|
|
@@ -185,6 +213,7 @@ function parseArgs(argv) {
|
|
|
185
213
|
}
|
|
186
214
|
if (arg === "--worker-role") {
|
|
187
215
|
const value = argv[index + 1];
|
|
216
|
+
ensureRoleOptionsLoaded();
|
|
188
217
|
const validRoles = new Set(ROLE_OPTIONS.map((option) => option.value));
|
|
189
218
|
if (!value || !validRoles.has(value)) {
|
|
190
219
|
throw new Error(`--worker-role requires one of: ${ROLE_OPTIONS.map((option) => option.value).join(", ")}`);
|
|
@@ -1318,7 +1347,7 @@ async function collectInstallChoices(configPath, config, prompter, options) {
|
|
|
1318
1347
|
defaultValue: options.workerRole || (
|
|
1319
1348
|
typeof existingTeamClaw.role === "string" && existingTeamClaw.role.trim()
|
|
1320
1349
|
? existingTeamClaw.role.trim()
|
|
1321
|
-
:
|
|
1350
|
+
: DEFAULT_WORKER_ROLE || ROLE_OPTIONS[0].value
|
|
1322
1351
|
),
|
|
1323
1352
|
});
|
|
1324
1353
|
const workerPort = await prompter.number({
|
|
@@ -1410,7 +1439,7 @@ async function collectInstallChoices(configPath, config, prompter, options) {
|
|
|
1410
1439
|
|
|
1411
1440
|
const provisioningRoles = await promptOptionalRoleList(
|
|
1412
1441
|
prompter,
|
|
1413
|
-
|
|
1442
|
+
`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
1443
|
resolveDefaultProvisioningRoles(existingTeamClaw),
|
|
1415
1444
|
);
|
|
1416
1445
|
const maxPerRole = await prompter.number({
|
|
@@ -1950,6 +1979,7 @@ async function runInstall(options) {
|
|
|
1950
1979
|
if (!options.yes && (!process.stdin.isTTY || !process.stdout.isTTY)) {
|
|
1951
1980
|
throw new Error("Interactive install requires a TTY. Re-run with --yes or in a terminal.");
|
|
1952
1981
|
}
|
|
1982
|
+
ensureRoleOptionsLoaded();
|
|
1953
1983
|
|
|
1954
1984
|
const prompter = new Prompter({ yes: options.yes });
|
|
1955
1985
|
try {
|
|
@@ -2073,6 +2103,7 @@ async function runInstall(options) {
|
|
|
2073
2103
|
}
|
|
2074
2104
|
|
|
2075
2105
|
async function main() {
|
|
2106
|
+
await loadRoleOptions();
|
|
2076
2107
|
const { command, options } = parseArgs(process.argv.slice(2));
|
|
2077
2108
|
if (command === "help") {
|
|
2078
2109
|
printHelp();
|
package/dist/api.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { definePluginEntry, emptyPluginConfigSchema } from "openclaw/plugin-sdk/plugin-entry";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { definePluginEntry } from "./api.js";
|
|
4
|
+
import { parsePluginConfig } from "./src/types.js";
|
|
5
|
+
import { buildConfigSchema } from "./src/config.js";
|
|
6
|
+
import { loadTeamState } from "./src/state.js";
|
|
7
|
+
import { createRoleTaskExecutor } from "./src/task-executor.js";
|
|
8
|
+
import { createWorkerService } from "./src/worker/worker-service.js";
|
|
9
|
+
import { createWorkerPromptInjector } from "./src/worker/prompt-injector.js";
|
|
10
|
+
import { createWorkerTools } from "./src/worker/tools.js";
|
|
11
|
+
import { MessageQueue } from "./src/worker/message-queue.js";
|
|
12
|
+
import { createControllerService } from "./src/controller/controller-service.js";
|
|
13
|
+
import { createControllerPromptInjector } from "./src/controller/prompt-injector.js";
|
|
14
|
+
import { createControllerTools } from "./src/controller/controller-tools.js";
|
|
15
|
+
import { publishWorkerRepo, syncWorkerRepo } from "./src/git-collaboration.js";
|
|
16
|
+
import { resolveTeamClawProjectsDir } from "./src/openclaw-workspace.js";
|
|
17
|
+
import { installRecommendedSkills } from "./src/worker/skill-installer.js";
|
|
18
|
+
export default definePluginEntry({
|
|
19
|
+
id: "teamclaw",
|
|
20
|
+
name: "TeamClaw",
|
|
21
|
+
description: "Virtual team collaboration - multiple OpenClaw instances form a virtual software company with role-based task routing.",
|
|
22
|
+
configSchema: buildConfigSchema,
|
|
23
|
+
register(api) {
|
|
24
|
+
const config = parsePluginConfig(api.pluginConfig);
|
|
25
|
+
if (config.mode === "controller") {
|
|
26
|
+
registerController(api, config);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
registerWorker(api, config);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
function registerController(api, config) {
|
|
34
|
+
const logger = api.logger;
|
|
35
|
+
let getControllerTeamState = () => null;
|
|
36
|
+
let controllerUrl = `http://127.0.0.1:${config.port}`;
|
|
37
|
+
let kickoffHandler;
|
|
38
|
+
let getTeamAutoScheduler = () => null;
|
|
39
|
+
// Service (starts HTTP server + mDNS + WebSocket)
|
|
40
|
+
api.registerService(createControllerService({
|
|
41
|
+
config,
|
|
42
|
+
logger,
|
|
43
|
+
runtime: api.runtime,
|
|
44
|
+
onTeamStateAvailable: (getter) => {
|
|
45
|
+
getControllerTeamState = getter;
|
|
46
|
+
},
|
|
47
|
+
onActualPort: (port) => {
|
|
48
|
+
controllerUrl = `http://127.0.0.1:${port}`;
|
|
49
|
+
},
|
|
50
|
+
onKickoffHandlerAvailable: (handler) => {
|
|
51
|
+
kickoffHandler = handler;
|
|
52
|
+
logger.info("TeamClaw: kickoff handler registered successfully");
|
|
53
|
+
},
|
|
54
|
+
onTeamAutoSchedulerAvailable: (getter) => {
|
|
55
|
+
getTeamAutoScheduler = getter;
|
|
56
|
+
},
|
|
57
|
+
}));
|
|
58
|
+
// Prompt injection
|
|
59
|
+
api.on("before_prompt_build", async (_event, ctx) => {
|
|
60
|
+
const state = getControllerTeamState() ?? await loadTeamState(config.teamName);
|
|
61
|
+
const injector = createControllerPromptInjector({
|
|
62
|
+
config,
|
|
63
|
+
getTeamState: () => state,
|
|
64
|
+
});
|
|
65
|
+
return injector() ?? {};
|
|
66
|
+
});
|
|
67
|
+
// Tools - register all controller tools via factory returning an array
|
|
68
|
+
api.registerTool((ctx) => {
|
|
69
|
+
return createControllerTools({
|
|
70
|
+
config,
|
|
71
|
+
controllerUrl,
|
|
72
|
+
getTeamState: getControllerTeamState,
|
|
73
|
+
sessionKey: ctx.sessionKey ?? null,
|
|
74
|
+
getKickoffHandler: () => kickoffHandler,
|
|
75
|
+
getTeamAutoScheduler: () => getTeamAutoScheduler(),
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
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
|
+
}
|
|
94
|
+
async function reportExecutionEvent(taskId, event) {
|
|
95
|
+
if (!currentControllerUrl) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const res = await fetch(`${currentControllerUrl}/api/v1/tasks/${taskId}/execution`, {
|
|
100
|
+
method: "POST",
|
|
101
|
+
headers: { "Content-Type": "application/json" },
|
|
102
|
+
body: JSON.stringify({
|
|
103
|
+
...event,
|
|
104
|
+
workerId: currentWorkerId ?? undefined,
|
|
105
|
+
role: config.role,
|
|
106
|
+
}),
|
|
107
|
+
});
|
|
108
|
+
if (!res.ok) {
|
|
109
|
+
logger.warn(`Worker: failed to record execution event for ${taskId} (${res.status})`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
logger.warn(`Worker: failed to POST execution event for ${taskId}: ${String(err)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function reportCheckpoint(taskId, checkpoint) {
|
|
117
|
+
if (!currentControllerUrl) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
await fetch(`${currentControllerUrl}/api/v1/tasks/${taskId}/checkpoint`, {
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers: { "Content-Type": "application/json" },
|
|
124
|
+
body: JSON.stringify({ ...checkpoint, workerId: currentWorkerId ?? undefined }),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// Checkpointing is best-effort; a lost heartbeat only costs resume freshness.
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const getWorkerSessionKey = (assignment) => assignment.executionSessionKey?.trim() || `teamclaw-task-${assignment.taskId}`;
|
|
132
|
+
const taskExecutor = createRoleTaskExecutor({
|
|
133
|
+
runtime: api.runtime,
|
|
134
|
+
logger,
|
|
135
|
+
role: config.role,
|
|
136
|
+
taskTimeoutMs: config.taskTimeoutMs,
|
|
137
|
+
config,
|
|
138
|
+
getSessionKey: getWorkerSessionKey,
|
|
139
|
+
getIdempotencyKey: (assignment) => assignment.executionIdempotencyKey?.trim() || `teamclaw-${assignment.taskId}`,
|
|
140
|
+
reportExecutionEvent,
|
|
141
|
+
reportCheckpoint,
|
|
142
|
+
});
|
|
143
|
+
function resolveProjectSyncPaths(projectDir) {
|
|
144
|
+
const normalizedProjectDir = projectDir?.trim();
|
|
145
|
+
const sharedWorkspaceOverride = process.env.TEAMCLAW_WORKSPACE_DIR?.trim();
|
|
146
|
+
if (!normalizedProjectDir || !sharedWorkspaceOverride) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
const sharedProjectDir = path.join(resolveTeamClawProjectsDir(), normalizedProjectDir);
|
|
150
|
+
const localEnv = { ...process.env };
|
|
151
|
+
delete localEnv.TEAMCLAW_WORKSPACE_DIR;
|
|
152
|
+
const localProjectDir = path.join(resolveTeamClawProjectsDir(localEnv), normalizedProjectDir);
|
|
153
|
+
if (sharedProjectDir === localProjectDir) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
return { sharedProjectDir, localProjectDir };
|
|
157
|
+
}
|
|
158
|
+
async function pathExists(targetPath) {
|
|
159
|
+
try {
|
|
160
|
+
await fs.access(targetPath);
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function syncProjectDir(sourceDir, destinationDir) {
|
|
168
|
+
if (!await pathExists(sourceDir)) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
await fs.mkdir(path.dirname(destinationDir), { recursive: true });
|
|
172
|
+
await fs.cp(sourceDir, destinationDir, { recursive: true, force: true });
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
// Service
|
|
176
|
+
api.registerService(createWorkerService({
|
|
177
|
+
config,
|
|
178
|
+
logger,
|
|
179
|
+
onIdentityEstablished: (identity) => {
|
|
180
|
+
currentControllerUrl = identity.controllerUrl;
|
|
181
|
+
currentWorkerId = identity.workerId;
|
|
182
|
+
},
|
|
183
|
+
prepareTaskAssignment: async (assignment) => {
|
|
184
|
+
const controllerUrl = currentControllerUrl || config.controllerUrl.trim();
|
|
185
|
+
if (assignment.recommendedSkills?.length) {
|
|
186
|
+
try {
|
|
187
|
+
const skillInstall = await installRecommendedSkills(assignment, logger);
|
|
188
|
+
for (const event of skillInstall.events) {
|
|
189
|
+
await reportExecutionEvent(assignment.taskId, event);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
194
|
+
await reportExecutionEvent(assignment.taskId, {
|
|
195
|
+
type: "error",
|
|
196
|
+
phase: "skills_preflight_failed",
|
|
197
|
+
source: "worker",
|
|
198
|
+
status: "running",
|
|
199
|
+
message,
|
|
200
|
+
});
|
|
201
|
+
logger.warn(`Worker: skill preflight failed for ${assignment.taskId}: ${message}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const syncPaths = resolveProjectSyncPaths(assignment.projectDir);
|
|
205
|
+
if (syncPaths) {
|
|
206
|
+
const restored = await syncProjectDir(syncPaths.sharedProjectDir, syncPaths.localProjectDir);
|
|
207
|
+
if (restored) {
|
|
208
|
+
await reportExecutionEvent(assignment.taskId, {
|
|
209
|
+
type: "lifecycle",
|
|
210
|
+
phase: "project_sync_restored",
|
|
211
|
+
source: "worker",
|
|
212
|
+
status: "running",
|
|
213
|
+
message: `Restored shared project files into the worker runtime from ${syncPaths.sharedProjectDir}.`,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (!assignment.repo?.enabled || !controllerUrl) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
await reportExecutionEvent(assignment.taskId, {
|
|
221
|
+
type: "lifecycle",
|
|
222
|
+
phase: "repo_sync_started",
|
|
223
|
+
source: "worker",
|
|
224
|
+
status: "running",
|
|
225
|
+
message: `Preparing ${assignment.repo.mode} git workspace sync before task execution.`,
|
|
226
|
+
});
|
|
227
|
+
try {
|
|
228
|
+
const syncResult = await syncWorkerRepo(config, logger, controllerUrl, assignment.repo);
|
|
229
|
+
await reportExecutionEvent(assignment.taskId, {
|
|
230
|
+
type: "lifecycle",
|
|
231
|
+
phase: "repo_sync_completed",
|
|
232
|
+
source: "worker",
|
|
233
|
+
status: "running",
|
|
234
|
+
message: syncResult.message,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
239
|
+
await reportExecutionEvent(assignment.taskId, {
|
|
240
|
+
type: "error",
|
|
241
|
+
phase: "repo_sync_failed",
|
|
242
|
+
source: "worker",
|
|
243
|
+
status: "running",
|
|
244
|
+
message,
|
|
245
|
+
});
|
|
246
|
+
throw err;
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
publishTaskAssignment: async (assignment) => {
|
|
250
|
+
const syncPaths = resolveProjectSyncPaths(assignment.projectDir);
|
|
251
|
+
if (syncPaths) {
|
|
252
|
+
const published = await syncProjectDir(syncPaths.localProjectDir, syncPaths.sharedProjectDir);
|
|
253
|
+
if (published) {
|
|
254
|
+
await reportExecutionEvent(assignment.taskId, {
|
|
255
|
+
type: "lifecycle",
|
|
256
|
+
phase: "project_sync_published",
|
|
257
|
+
source: "worker",
|
|
258
|
+
status: "running",
|
|
259
|
+
message: `Published worker runtime project files back to the shared workspace at ${syncPaths.sharedProjectDir}.`,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const controllerUrl = currentControllerUrl || config.controllerUrl.trim();
|
|
264
|
+
if (!assignment.repo?.enabled || !controllerUrl) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const workerId = currentWorkerId || "unknown-worker";
|
|
268
|
+
await reportExecutionEvent(assignment.taskId, {
|
|
269
|
+
type: "lifecycle",
|
|
270
|
+
phase: "repo_publish_started",
|
|
271
|
+
source: "worker",
|
|
272
|
+
status: "running",
|
|
273
|
+
message: `Publishing task changes through ${assignment.repo.mode} git collaboration.`,
|
|
274
|
+
});
|
|
275
|
+
try {
|
|
276
|
+
const publishResult = await publishWorkerRepo(config, logger, controllerUrl, assignment.repo, {
|
|
277
|
+
taskId: assignment.taskId,
|
|
278
|
+
workerId,
|
|
279
|
+
role: config.role,
|
|
280
|
+
});
|
|
281
|
+
await reportExecutionEvent(assignment.taskId, {
|
|
282
|
+
type: "lifecycle",
|
|
283
|
+
phase: publishResult.published ? "repo_publish_completed" : "repo_publish_skipped",
|
|
284
|
+
source: "worker",
|
|
285
|
+
status: "running",
|
|
286
|
+
message: publishResult.message,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
291
|
+
await reportExecutionEvent(assignment.taskId, {
|
|
292
|
+
type: "error",
|
|
293
|
+
phase: "repo_publish_failed",
|
|
294
|
+
source: "worker",
|
|
295
|
+
status: "running",
|
|
296
|
+
message,
|
|
297
|
+
});
|
|
298
|
+
throw err;
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
taskExecutor,
|
|
302
|
+
cancelTaskExecution: async (taskId, sessionKey) => {
|
|
303
|
+
const resolvedSessionKey = sessionKey || `teamclaw-task-${taskId}`;
|
|
304
|
+
try {
|
|
305
|
+
await api.runtime.subagent.deleteSession({ sessionKey: resolvedSessionKey });
|
|
306
|
+
logger.info(`Worker: cancelled subagent session ${resolvedSessionKey} for task ${taskId}`);
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
catch (err) {
|
|
310
|
+
logger.warn(`Worker: failed to cancel session ${resolvedSessionKey} for task ${taskId}: ${String(err)}`);
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
messageQueue,
|
|
315
|
+
}));
|
|
316
|
+
// Prompt injection
|
|
317
|
+
api.on("before_prompt_build", async () => {
|
|
318
|
+
const injector = createWorkerPromptInjector(config, getIdentity, messageQueue);
|
|
319
|
+
return injector() ?? {};
|
|
320
|
+
});
|
|
321
|
+
// Tools - register all worker tools via factory returning an array
|
|
322
|
+
api.registerTool(() => {
|
|
323
|
+
return createWorkerTools({ config, getIdentity });
|
|
324
|
+
});
|
|
325
|
+
}
|