@teamclaws/teamclaw 2026.7.1 → 2026.8.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/README.md +8 -0
- package/dist/api.js +1 -0
- package/dist/index.js +325 -0
- package/dist/src/config.js +381 -0
- package/dist/src/controller/controller-capacity.js +14 -0
- package/dist/src/controller/controller-service.js +393 -0
- package/dist/src/controller/controller-tools.js +582 -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 +6032 -0
- package/dist/src/controller/kickoff-orchestrator.js +220 -0
- package/dist/src/controller/managed-gateway-process.js +286 -0
- package/dist/src/controller/message-router.js +38 -0
- package/dist/src/controller/orchestration-manifest.js +173 -0
- package/dist/src/controller/preview-manager.js +586 -0
- package/dist/src/controller/prompt-injector.js +187 -0
- package/dist/src/controller/role-inference.js +35 -0
- package/dist/src/controller/task-router.js +67 -0
- package/dist/src/controller/tunnel-manager.js +548 -0
- package/dist/src/controller/websocket.js +42 -0
- package/dist/src/controller/worker-provisioning.js +1648 -0
- package/dist/src/discovery.js +86 -0
- package/dist/src/git-collaboration.js +694 -0
- package/dist/src/identity.js +131 -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 +903 -0
- package/dist/src/prompt-policy.js +373 -0
- package/dist/src/protocol.js +58 -0
- package/dist/src/roles.js +349 -0
- package/dist/src/state.js +183 -0
- package/dist/src/task-executor.js +1033 -0
- package/dist/src/teamauto/github-client.js +192 -0
- package/dist/src/teamauto/norms.js +85 -0
- package/dist/src/teamauto/repo-sync.js +201 -0
- package/dist/src/teamauto/scanner.js +179 -0
- package/dist/src/teamauto/schedule.js +123 -0
- package/dist/src/teamauto/scheduler.js +688 -0
- package/dist/src/teamauto/store.js +133 -0
- package/dist/src/types.js +243 -0
- package/dist/src/ui/app.js +4292 -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 +414 -0
- package/dist/src/ui/style.css +2611 -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 +42 -0
- package/dist/src/worker/skill-installer.js +253 -0
- package/dist/src/worker/tools.js +541 -0
- package/dist/src/worker/worker-service.js +234 -0
- package/dist/src/workspace-browser.js +269 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +9 -7
- package/src/controller/http-server.ts +26 -1
- package/src/controller/tunnel-manager.ts +139 -15
- package/src/ui/app.js +97 -20
- package/src/ui/index.html +16 -4
- package/src/ui/style.css +49 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
import { createHeartbeatPayload } from "../protocol.js";
|
|
3
|
+
import { IdentityManager } from "../identity.js";
|
|
4
|
+
import { MessageQueue } from "./message-queue.js";
|
|
5
|
+
import { createWorkerHttpHandler } from "./http-handler.js";
|
|
6
|
+
import { buildTeamClawAgentSessionKey, ensureOpenClawWorkspaceMemoryDir } from "../openclaw-workspace.js";
|
|
7
|
+
export function createWorkerService(deps) {
|
|
8
|
+
const { config, logger, onIdentityEstablished, taskExecutor: externalTaskExecutor } = deps;
|
|
9
|
+
let identityManager;
|
|
10
|
+
let messageQueue;
|
|
11
|
+
let server = null;
|
|
12
|
+
let heartbeatTimer = null;
|
|
13
|
+
let controllerUrl = null;
|
|
14
|
+
let workerId = null;
|
|
15
|
+
let activeTaskId;
|
|
16
|
+
const activeTaskSessionKeys = new Map();
|
|
17
|
+
const cancelledTaskIds = new Set();
|
|
18
|
+
let consecutiveHeartbeatFailures = 0;
|
|
19
|
+
const taskExecutor = externalTaskExecutor
|
|
20
|
+
? async (assignment) => {
|
|
21
|
+
const taskId = assignment.taskId;
|
|
22
|
+
cancelledTaskIds.delete(taskId);
|
|
23
|
+
activeTaskId = taskId;
|
|
24
|
+
activeTaskSessionKeys.set(taskId, assignment.executionSessionKey || buildTeamClawAgentSessionKey(`teamclaw-task-${taskId}`));
|
|
25
|
+
try {
|
|
26
|
+
await deps.prepareTaskAssignment?.(assignment);
|
|
27
|
+
let taskPrompt = [assignment.title.trim(), assignment.description.trim()].filter(Boolean).join("\n\n");
|
|
28
|
+
if (assignment.checkpoint) {
|
|
29
|
+
const cp = assignment.checkpoint;
|
|
30
|
+
const resumeLines = [
|
|
31
|
+
"## RESUMED EXECUTION",
|
|
32
|
+
`This task was interrupted mid-execution (resume attempt ${assignment.resumeAttempt ?? cp.attempt}). You are CONTINUING previous work, not starting over. The OpenClaw session you are running in already contains the full prior conversation - review it before acting.`,
|
|
33
|
+
"Do NOT redo steps that are already done. Re-verify state on disk/git instead of redoing work.",
|
|
34
|
+
"",
|
|
35
|
+
"Last assistant activity before interruption:",
|
|
36
|
+
(cp.lastAssistantMessage || "(none recorded)").slice(0, 4000),
|
|
37
|
+
];
|
|
38
|
+
if (cp.progressNotes?.length) {
|
|
39
|
+
resumeLines.push("", "Progress notes from prior attempts:", ...cp.progressNotes.map((n) => `- ${n}`));
|
|
40
|
+
}
|
|
41
|
+
taskPrompt = `${taskPrompt}\n\n${resumeLines.join("\n")}`;
|
|
42
|
+
}
|
|
43
|
+
const raw = await externalTaskExecutor(taskPrompt, assignment);
|
|
44
|
+
if (cancelledTaskIds.has(taskId)) {
|
|
45
|
+
throw new Error("Task execution cancelled by controller");
|
|
46
|
+
}
|
|
47
|
+
const result = typeof raw === "string" ? { text: raw } : raw;
|
|
48
|
+
await deps.publishTaskAssignment?.(assignment, result.text);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
activeTaskId = undefined;
|
|
53
|
+
activeTaskSessionKeys.delete(taskId);
|
|
54
|
+
if (!cancelledTaskIds.has(taskId)) {
|
|
55
|
+
cancelledTaskIds.delete(taskId);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
: undefined;
|
|
60
|
+
function reportTaskResult(taskId, result, error, contract) {
|
|
61
|
+
if (cancelledTaskIds.has(taskId)) {
|
|
62
|
+
logger.info(`Worker: suppressing result report for cancelled task ${taskId}`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!controllerUrl)
|
|
66
|
+
return;
|
|
67
|
+
const body = { result, error, workerId };
|
|
68
|
+
if (contract) {
|
|
69
|
+
body.resultContract = contract;
|
|
70
|
+
}
|
|
71
|
+
fetch(`${controllerUrl}/api/v1/tasks/${taskId}/result`, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: { "Content-Type": "application/json" },
|
|
74
|
+
body: JSON.stringify(body),
|
|
75
|
+
}).catch((err) => {
|
|
76
|
+
logger.error(`Worker: failed to report task result: ${String(err)}`);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async function cancelAssignedTask(taskId) {
|
|
80
|
+
if (activeTaskId !== taskId) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
cancelledTaskIds.add(taskId);
|
|
84
|
+
try {
|
|
85
|
+
const cancelled = await deps.cancelTaskExecution?.(taskId, activeTaskSessionKeys.get(taskId));
|
|
86
|
+
return cancelled ?? true;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
logger.warn(`Worker: failed to cancel task ${taskId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function isTaskCancelled(taskId) {
|
|
94
|
+
return cancelledTaskIds.has(taskId);
|
|
95
|
+
}
|
|
96
|
+
async function startServer() {
|
|
97
|
+
// Kickoff assessor — uses the worker's subagent runtime for lightweight assessment
|
|
98
|
+
const kickoffAssessor = externalTaskExecutor
|
|
99
|
+
? async (requirement, role) => {
|
|
100
|
+
const { buildKickoffAssessmentPrompt } = await import("../controller/kickoff-orchestrator.js");
|
|
101
|
+
const prompt = buildKickoffAssessmentPrompt(role, requirement);
|
|
102
|
+
const sessionKey = buildTeamClawAgentSessionKey(`teamclaw-kickoff-${role}-${Date.now()}`);
|
|
103
|
+
const raw = await externalTaskExecutor(prompt, {
|
|
104
|
+
taskId: `kickoff-${role}`,
|
|
105
|
+
title: `Kickoff Assessment (${role})`,
|
|
106
|
+
description: prompt,
|
|
107
|
+
executionSessionKey: sessionKey,
|
|
108
|
+
});
|
|
109
|
+
const text = typeof raw === "string" ? raw : raw.text;
|
|
110
|
+
// Parse the JSON response
|
|
111
|
+
const jsonMatch = text.match(/```(?:json)?\s*([\s\S]*?)```/) || text.match(/(\{[\s\S]*\})/);
|
|
112
|
+
const jsonStr = jsonMatch?.[1]?.trim() ?? text.trim();
|
|
113
|
+
try {
|
|
114
|
+
const parsed = JSON.parse(jsonStr);
|
|
115
|
+
return {
|
|
116
|
+
role,
|
|
117
|
+
needed: Boolean(parsed.needed),
|
|
118
|
+
scope: String(parsed.scope ?? ""),
|
|
119
|
+
suggestedTasks: Array.isArray(parsed.suggestedTasks) ? parsed.suggestedTasks : [],
|
|
120
|
+
dependencies: Array.isArray(parsed.dependencies) ? parsed.dependencies : [],
|
|
121
|
+
risks: Array.isArray(parsed.risks) ? parsed.risks : [],
|
|
122
|
+
questions: Array.isArray(parsed.questions) ? parsed.questions : [],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return { role, needed: false, scope: `Could not parse: ${text.slice(0, 200)}`, suggestedTasks: [], dependencies: [], risks: [], questions: [] };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
: undefined;
|
|
130
|
+
const handler = createWorkerHttpHandler({ role: config.role, port: config.port }, logger, messageQueue, workerId ?? "", taskExecutor, reportTaskResult, cancelAssignedTask, isTaskCancelled, kickoffAssessor);
|
|
131
|
+
if (server) {
|
|
132
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
133
|
+
}
|
|
134
|
+
server = http.createServer(handler);
|
|
135
|
+
await new Promise((resolve, reject) => {
|
|
136
|
+
server.listen(config.port, () => {
|
|
137
|
+
logger.info(`Worker: HTTP server listening on port ${config.port}`);
|
|
138
|
+
resolve();
|
|
139
|
+
});
|
|
140
|
+
server.on("error", reject);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
id: "teamclaw-worker",
|
|
145
|
+
async start(_ctx) {
|
|
146
|
+
await ensureOpenClawWorkspaceMemoryDir(logger);
|
|
147
|
+
messageQueue = deps.messageQueue ?? new MessageQueue();
|
|
148
|
+
identityManager = new IdentityManager(config, logger);
|
|
149
|
+
// Start HTTP server initially (without identity)
|
|
150
|
+
await startServer();
|
|
151
|
+
// Register with controller
|
|
152
|
+
const identity = await identityManager.register();
|
|
153
|
+
if (!identity) {
|
|
154
|
+
logger.warn("Worker: could not register with controller, will retry on next heartbeat");
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
controllerUrl = identity.controllerUrl;
|
|
158
|
+
workerId = identity.workerId;
|
|
159
|
+
onIdentityEstablished(identity);
|
|
160
|
+
// Restart server with worker ID and task executor
|
|
161
|
+
await startServer();
|
|
162
|
+
}
|
|
163
|
+
// Start heartbeat
|
|
164
|
+
heartbeatTimer = setInterval(async () => {
|
|
165
|
+
if (!identityManager.hasIdentity()) {
|
|
166
|
+
const newIdentity = await identityManager.register();
|
|
167
|
+
if (newIdentity && !controllerUrl) {
|
|
168
|
+
controllerUrl = newIdentity.controllerUrl;
|
|
169
|
+
workerId = newIdentity.workerId;
|
|
170
|
+
onIdentityEstablished(newIdentity);
|
|
171
|
+
await startServer();
|
|
172
|
+
}
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const id = identityManager.getIdentity();
|
|
176
|
+
if (!id || !controllerUrl)
|
|
177
|
+
return;
|
|
178
|
+
try {
|
|
179
|
+
const heartbeat = createHeartbeatPayload(id.workerId, activeTaskId ? "busy" : "idle", activeTaskId);
|
|
180
|
+
const res = await fetch(`${controllerUrl}/api/v1/workers/${id.workerId}/heartbeat`, {
|
|
181
|
+
method: "POST",
|
|
182
|
+
headers: { "Content-Type": "application/json" },
|
|
183
|
+
body: JSON.stringify(heartbeat),
|
|
184
|
+
});
|
|
185
|
+
if (!res.ok) {
|
|
186
|
+
consecutiveHeartbeatFailures += 1;
|
|
187
|
+
logger.warn(`Worker: heartbeat failed (${res.status})`);
|
|
188
|
+
if (consecutiveHeartbeatFailures >= 3) {
|
|
189
|
+
logger.warn("Worker: controller heartbeat failed repeatedly; clearing identity and forcing re-registration");
|
|
190
|
+
await identityManager.clear();
|
|
191
|
+
controllerUrl = null;
|
|
192
|
+
workerId = null;
|
|
193
|
+
consecutiveHeartbeatFailures = 0;
|
|
194
|
+
await startServer();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
consecutiveHeartbeatFailures = 0;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
consecutiveHeartbeatFailures += 1;
|
|
203
|
+
logger.warn(`Worker: heartbeat error: ${err instanceof Error ? err.message : String(err)}`);
|
|
204
|
+
if (consecutiveHeartbeatFailures >= 3) {
|
|
205
|
+
logger.warn("Worker: controller heartbeat errored repeatedly; clearing identity and forcing re-registration");
|
|
206
|
+
await identityManager.clear();
|
|
207
|
+
controllerUrl = null;
|
|
208
|
+
workerId = null;
|
|
209
|
+
consecutiveHeartbeatFailures = 0;
|
|
210
|
+
await startServer();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}, config.heartbeatIntervalMs);
|
|
214
|
+
if (heartbeatTimer) {
|
|
215
|
+
const timer = heartbeatTimer;
|
|
216
|
+
timer.unref?.();
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
async stop() {
|
|
220
|
+
if (heartbeatTimer) {
|
|
221
|
+
clearInterval(heartbeatTimer);
|
|
222
|
+
heartbeatTimer = null;
|
|
223
|
+
}
|
|
224
|
+
if (server) {
|
|
225
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
226
|
+
server = null;
|
|
227
|
+
}
|
|
228
|
+
if (identityManager) {
|
|
229
|
+
await identityManager.clear();
|
|
230
|
+
}
|
|
231
|
+
logger.info("Worker: stopped");
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveTeamClawWorkspaceDir } from "./openclaw-workspace.js";
|
|
4
|
+
const MAX_PREVIEW_BYTES = 256 * 1024;
|
|
5
|
+
const MAX_TREE_DEPTH = 8;
|
|
6
|
+
const HIDDEN_WORKSPACE_NAMES = new Set([
|
|
7
|
+
".git",
|
|
8
|
+
".openclaw",
|
|
9
|
+
"node_modules",
|
|
10
|
+
"memory",
|
|
11
|
+
"AGENTS.md",
|
|
12
|
+
"BOOTSTRAP.md",
|
|
13
|
+
"HEARTBEAT.md",
|
|
14
|
+
"IDENTITY.md",
|
|
15
|
+
"SOUL.md",
|
|
16
|
+
"TOOLS.md",
|
|
17
|
+
"USER.md",
|
|
18
|
+
]);
|
|
19
|
+
const MARKDOWN_EXTENSIONS = new Set([".md", ".markdown", ".mdown"]);
|
|
20
|
+
const HTML_EXTENSIONS = new Set([".html", ".htm"]);
|
|
21
|
+
const TEXT_EXTENSIONS = new Set([
|
|
22
|
+
".txt",
|
|
23
|
+
".js",
|
|
24
|
+
".mjs",
|
|
25
|
+
".cjs",
|
|
26
|
+
".jsx",
|
|
27
|
+
".ts",
|
|
28
|
+
".tsx",
|
|
29
|
+
".css",
|
|
30
|
+
".scss",
|
|
31
|
+
".sass",
|
|
32
|
+
".less",
|
|
33
|
+
".json",
|
|
34
|
+
".yml",
|
|
35
|
+
".yaml",
|
|
36
|
+
".xml",
|
|
37
|
+
".svg",
|
|
38
|
+
".sh",
|
|
39
|
+
".bash",
|
|
40
|
+
".zsh",
|
|
41
|
+
".py",
|
|
42
|
+
".go",
|
|
43
|
+
".rs",
|
|
44
|
+
".java",
|
|
45
|
+
".kt",
|
|
46
|
+
".swift",
|
|
47
|
+
".rb",
|
|
48
|
+
".php",
|
|
49
|
+
".sql",
|
|
50
|
+
".env",
|
|
51
|
+
".gitignore",
|
|
52
|
+
".gitattributes",
|
|
53
|
+
".npmrc",
|
|
54
|
+
".editorconfig",
|
|
55
|
+
]);
|
|
56
|
+
export async function listWorkspaceTree(maxDepth) {
|
|
57
|
+
const workspaceDir = await ensureWorkspaceDir();
|
|
58
|
+
const entries = await readTree(workspaceDir, "", 0, maxDepth);
|
|
59
|
+
return {
|
|
60
|
+
root: "/",
|
|
61
|
+
entries,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Load children of a single directory (one level). Used for lazy-loading. */
|
|
65
|
+
export async function listWorkspaceSubtree(relativePath) {
|
|
66
|
+
const { absolutePath, normalizedPath } = await resolveWorkspacePath(relativePath);
|
|
67
|
+
const stat = await fs.stat(absolutePath);
|
|
68
|
+
if (!stat.isDirectory()) {
|
|
69
|
+
throw new Error("Path is not a directory");
|
|
70
|
+
}
|
|
71
|
+
return readTree(absolutePath, normalizedPath, 0, 1);
|
|
72
|
+
}
|
|
73
|
+
export async function readWorkspaceFile(relativePath) {
|
|
74
|
+
const { normalizedPath, absolutePath } = await resolveWorkspacePath(relativePath);
|
|
75
|
+
const stat = await fs.stat(absolutePath);
|
|
76
|
+
if (!stat.isFile()) {
|
|
77
|
+
throw new Error("Workspace path is not a file");
|
|
78
|
+
}
|
|
79
|
+
const extension = path.extname(normalizedPath).toLowerCase();
|
|
80
|
+
const contentType = getContentType(normalizedPath);
|
|
81
|
+
const handle = await fs.open(absolutePath, "r");
|
|
82
|
+
try {
|
|
83
|
+
const length = Math.min(stat.size, MAX_PREVIEW_BYTES + 1);
|
|
84
|
+
const buffer = Buffer.alloc(length);
|
|
85
|
+
const { bytesRead } = await handle.read(buffer, 0, length, 0);
|
|
86
|
+
const slice = buffer.subarray(0, bytesRead);
|
|
87
|
+
const truncated = stat.size > MAX_PREVIEW_BYTES;
|
|
88
|
+
const previewType = detectPreviewType(normalizedPath, slice);
|
|
89
|
+
return {
|
|
90
|
+
name: path.basename(normalizedPath),
|
|
91
|
+
path: normalizedPath,
|
|
92
|
+
size: stat.size,
|
|
93
|
+
extension,
|
|
94
|
+
previewType,
|
|
95
|
+
truncated,
|
|
96
|
+
content: previewType === "binary" ? undefined : slice.subarray(0, Math.min(slice.length, MAX_PREVIEW_BYTES)).toString("utf8"),
|
|
97
|
+
rawUrl: buildWorkspaceRawUrl(normalizedPath),
|
|
98
|
+
contentType,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
await handle.close();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export async function readWorkspaceRawFile(relativePath) {
|
|
106
|
+
const { absolutePath } = await resolveWorkspacePath(relativePath);
|
|
107
|
+
const stat = await fs.stat(absolutePath);
|
|
108
|
+
if (!stat.isFile()) {
|
|
109
|
+
throw new Error("Workspace path is not a file");
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
content: await fs.readFile(absolutePath),
|
|
113
|
+
contentType: getContentType(absolutePath),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export function buildWorkspaceRawUrl(relativePath) {
|
|
117
|
+
const normalizedPath = normalizeWorkspacePath(relativePath);
|
|
118
|
+
const encodedPath = normalizedPath.split("/").map((segment) => encodeURIComponent(segment)).join("/");
|
|
119
|
+
return `/api/v1/workspace/raw/${encodedPath}`;
|
|
120
|
+
}
|
|
121
|
+
async function ensureWorkspaceDir() {
|
|
122
|
+
const workspaceDir = resolveTeamClawWorkspaceDir();
|
|
123
|
+
await fs.mkdir(workspaceDir, { recursive: true });
|
|
124
|
+
return workspaceDir;
|
|
125
|
+
}
|
|
126
|
+
async function resolveWorkspacePath(relativePath) {
|
|
127
|
+
const workspaceDir = await ensureWorkspaceDir();
|
|
128
|
+
const normalizedPath = normalizeWorkspacePath(relativePath);
|
|
129
|
+
if (!normalizedPath) {
|
|
130
|
+
throw new Error("workspace path is required");
|
|
131
|
+
}
|
|
132
|
+
const absolutePath = path.resolve(workspaceDir, normalizedPath);
|
|
133
|
+
const relativeFromWorkspace = path.relative(workspaceDir, absolutePath).replace(/\\/g, "/");
|
|
134
|
+
if (!relativeFromWorkspace || relativeFromWorkspace.startsWith("..") || path.isAbsolute(relativeFromWorkspace)) {
|
|
135
|
+
throw new Error("workspace path must stay inside the workspace");
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
workspaceDir,
|
|
139
|
+
normalizedPath: relativeFromWorkspace,
|
|
140
|
+
absolutePath,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function normalizeWorkspacePath(relativePath) {
|
|
144
|
+
const value = String(relativePath || "").trim().replace(/\\/g, "/").replace(/^\/+/, "");
|
|
145
|
+
if (!value) {
|
|
146
|
+
return "";
|
|
147
|
+
}
|
|
148
|
+
const normalized = path.posix.normalize(value);
|
|
149
|
+
if (normalized === "." || normalized === ".." || normalized.startsWith("../")) {
|
|
150
|
+
throw new Error("Invalid workspace path");
|
|
151
|
+
}
|
|
152
|
+
return normalized;
|
|
153
|
+
}
|
|
154
|
+
async function readTree(dirPath, relativeDir, depth, maxDepth) {
|
|
155
|
+
const effectiveMaxDepth = maxDepth ?? MAX_TREE_DEPTH;
|
|
156
|
+
if (depth > effectiveMaxDepth) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
const dirents = await fs.readdir(dirPath, { withFileTypes: true });
|
|
160
|
+
const visibleDirents = dirents
|
|
161
|
+
.filter((dirent) => !HIDDEN_WORKSPACE_NAMES.has(dirent.name))
|
|
162
|
+
.sort((left, right) => {
|
|
163
|
+
if (left.isDirectory() && !right.isDirectory())
|
|
164
|
+
return -1;
|
|
165
|
+
if (!left.isDirectory() && right.isDirectory())
|
|
166
|
+
return 1;
|
|
167
|
+
return left.name.localeCompare(right.name);
|
|
168
|
+
});
|
|
169
|
+
const nodes = [];
|
|
170
|
+
for (const dirent of visibleDirents) {
|
|
171
|
+
const childRelativePath = relativeDir ? `${relativeDir}/${dirent.name}` : dirent.name;
|
|
172
|
+
const childAbsolutePath = path.join(dirPath, dirent.name);
|
|
173
|
+
if (dirent.isDirectory()) {
|
|
174
|
+
// At max depth, mark directory as lazy-loadable (no children yet)
|
|
175
|
+
const atLimit = depth + 1 > effectiveMaxDepth;
|
|
176
|
+
nodes.push({
|
|
177
|
+
name: dirent.name,
|
|
178
|
+
path: childRelativePath,
|
|
179
|
+
type: "directory",
|
|
180
|
+
children: atLimit ? undefined : await readTree(childAbsolutePath, childRelativePath, depth + 1, effectiveMaxDepth),
|
|
181
|
+
});
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (!dirent.isFile()) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const stat = await fs.stat(childAbsolutePath);
|
|
188
|
+
nodes.push({
|
|
189
|
+
name: dirent.name,
|
|
190
|
+
path: childRelativePath,
|
|
191
|
+
type: "file",
|
|
192
|
+
size: stat.size,
|
|
193
|
+
previewType: classifyPreviewType(childRelativePath),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return nodes;
|
|
197
|
+
}
|
|
198
|
+
function classifyPreviewType(filePath) {
|
|
199
|
+
const extension = path.extname(filePath).toLowerCase();
|
|
200
|
+
if (MARKDOWN_EXTENSIONS.has(extension)) {
|
|
201
|
+
return "markdown";
|
|
202
|
+
}
|
|
203
|
+
if (HTML_EXTENSIONS.has(extension)) {
|
|
204
|
+
return "html";
|
|
205
|
+
}
|
|
206
|
+
return TEXT_EXTENSIONS.has(extension) ? "source" : "binary";
|
|
207
|
+
}
|
|
208
|
+
function detectPreviewType(filePath, content) {
|
|
209
|
+
const classified = classifyPreviewType(filePath);
|
|
210
|
+
if (classified === "markdown" || classified === "html") {
|
|
211
|
+
return classified;
|
|
212
|
+
}
|
|
213
|
+
if (classified === "source") {
|
|
214
|
+
return "source";
|
|
215
|
+
}
|
|
216
|
+
return isLikelyBinary(content) ? "binary" : "source";
|
|
217
|
+
}
|
|
218
|
+
function isLikelyBinary(content) {
|
|
219
|
+
const sample = content.subarray(0, Math.min(content.length, 4096));
|
|
220
|
+
for (const byte of sample) {
|
|
221
|
+
if (byte === 0) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
function getContentType(filePath) {
|
|
228
|
+
const extension = path.extname(filePath).toLowerCase();
|
|
229
|
+
switch (extension) {
|
|
230
|
+
case ".html":
|
|
231
|
+
case ".htm":
|
|
232
|
+
return "text/html; charset=utf-8";
|
|
233
|
+
case ".md":
|
|
234
|
+
case ".markdown":
|
|
235
|
+
case ".mdown":
|
|
236
|
+
return "text/markdown; charset=utf-8";
|
|
237
|
+
case ".css":
|
|
238
|
+
return "text/css; charset=utf-8";
|
|
239
|
+
case ".js":
|
|
240
|
+
case ".mjs":
|
|
241
|
+
case ".cjs":
|
|
242
|
+
return "application/javascript; charset=utf-8";
|
|
243
|
+
case ".json":
|
|
244
|
+
return "application/json; charset=utf-8";
|
|
245
|
+
case ".svg":
|
|
246
|
+
return "image/svg+xml";
|
|
247
|
+
case ".txt":
|
|
248
|
+
case ".sh":
|
|
249
|
+
case ".bash":
|
|
250
|
+
case ".zsh":
|
|
251
|
+
case ".yml":
|
|
252
|
+
case ".yaml":
|
|
253
|
+
case ".ts":
|
|
254
|
+
case ".tsx":
|
|
255
|
+
case ".jsx":
|
|
256
|
+
case ".py":
|
|
257
|
+
case ".go":
|
|
258
|
+
case ".rs":
|
|
259
|
+
case ".java":
|
|
260
|
+
case ".kt":
|
|
261
|
+
case ".swift":
|
|
262
|
+
case ".rb":
|
|
263
|
+
case ".php":
|
|
264
|
+
case ".sql":
|
|
265
|
+
return "text/plain; charset=utf-8";
|
|
266
|
+
default:
|
|
267
|
+
return "application/octet-stream";
|
|
268
|
+
}
|
|
269
|
+
}
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "teamclaw",
|
|
3
3
|
"name": "TeamClaw",
|
|
4
4
|
"description": "Virtual team collaboration - multiple OpenClaw instances form a virtual software company with role-based task routing.",
|
|
5
|
-
"version": "2026.
|
|
5
|
+
"version": "2026.8.1",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true
|
|
8
8
|
},
|
package/package.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamclaws/teamclaw",
|
|
3
|
-
"version": "2026.
|
|
4
|
-
"description": "OpenClaw virtual software team orchestration plugin",
|
|
3
|
+
"version": "2026.8.1",
|
|
4
|
+
"description": "OpenClaw virtual software team orchestration plugin - controller, role-based workers, Web UI with internet tunnel sharing",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
7
|
-
"
|
|
8
|
-
"plugin",
|
|
9
|
-
"teamclaw",
|
|
7
|
+
"cloudflared",
|
|
10
8
|
"multi-agent",
|
|
9
|
+
"multi-role",
|
|
10
|
+
"openclaw",
|
|
11
11
|
"orchestration",
|
|
12
|
-
"
|
|
12
|
+
"plugin",
|
|
13
13
|
"sdlc",
|
|
14
|
-
"
|
|
14
|
+
"teamclaw",
|
|
15
|
+
"tunnel",
|
|
16
|
+
"virtual-team"
|
|
15
17
|
],
|
|
16
18
|
"author": "Junjun Zhang <topcheer@me.com>",
|
|
17
19
|
"homepage": "https://github.com/topcheer/teamclaw/tree/main/src#readme",
|
|
@@ -54,7 +54,7 @@ import type { WorkerProvisioningManager } from "./worker-provisioning.js";
|
|
|
54
54
|
import type { PreviewManager } from "./preview-manager.js";
|
|
55
55
|
import { createControllerPromptInjector } from "./prompt-injector.js";
|
|
56
56
|
import { getGithubAuthManager } from "./github-auth.js";
|
|
57
|
-
import { createTunnelManager, gatePageHtml, computeGateCookie, GATE_COOKIE_NAME, type TunnelManager } from "./tunnel-manager.js";
|
|
57
|
+
import { createTunnelManager, gatePageHtml, computeGateCookie, GATE_COOKIE_NAME, selfHostedTokenFromEnv, type TunnelManager } from "./tunnel-manager.js";
|
|
58
58
|
import { createGithubClient } from "../teamauto/github-client.js";
|
|
59
59
|
import type { TeamAutoScheduler } from "../teamauto/scheduler.js";
|
|
60
60
|
import { buildControllerNoWorkersMessage, shouldBlockControllerWithoutWorkers } from "./controller-capacity.js";
|
|
@@ -4786,6 +4786,31 @@ export function createControllerHttpServer(deps: ControllerHttpDeps): http.Serve
|
|
|
4786
4786
|
sendJson(res, 202, { launched, status: tunnelManager.status() });
|
|
4787
4787
|
return;
|
|
4788
4788
|
}
|
|
4789
|
+
// Self-hosted: user-owned Cloudflare tunnel via connector token (no
|
|
4790
|
+
// GitHub login, no platform tunnel server). Token from the request
|
|
4791
|
+
// body, or the TEAMCLAW_TUNNEL_TOKEN env injection when body is empty.
|
|
4792
|
+
if (req.method === "POST" && pathname === "/api/v1/tunnel/start-self-hosted") {
|
|
4793
|
+
let token = "";
|
|
4794
|
+
try {
|
|
4795
|
+
const body = await readFormBody(req) as { token?: unknown };
|
|
4796
|
+
token = String(body.token ?? "");
|
|
4797
|
+
} catch { /* fall through to env */ }
|
|
4798
|
+
if (!token.trim()) {
|
|
4799
|
+
const envToken = selfHostedTokenFromEnv();
|
|
4800
|
+
if (!envToken) { sendError(res, 400, "connector token required (or set TEAMCLAW_TUNNEL_TOKEN)"); return; }
|
|
4801
|
+
token = envToken;
|
|
4802
|
+
}
|
|
4803
|
+
const r = tunnelManager.startSelfHosted(token);
|
|
4804
|
+
if (!r.launched) { sendError(res, 400, r.error ?? "failed to start self-hosted tunnel"); return; }
|
|
4805
|
+
sendJson(res, 202, { launched: true, status: tunnelManager.status() });
|
|
4806
|
+
return;
|
|
4807
|
+
}
|
|
4808
|
+
if (req.method === "POST" && pathname === "/api/v1/tunnel/start-quick") {
|
|
4809
|
+
const r = tunnelManager.startQuick();
|
|
4810
|
+
if (!r.launched) { sendError(res, 400, r.error ?? "failed to start quick tunnel"); return; }
|
|
4811
|
+
sendJson(res, 202, { launched: true, status: tunnelManager.status() });
|
|
4812
|
+
return;
|
|
4813
|
+
}
|
|
4789
4814
|
if (req.method === "POST" && pathname === "/api/v1/tunnel/stop") {
|
|
4790
4815
|
await tunnelManager.stop();
|
|
4791
4816
|
sendJson(res, 200, tunnelManager.status());
|