@teamclaws/teamclaw 2026.4.4 → 2026.6.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/README.md +2 -0
- package/index.ts +16 -0
- package/openclaw.plugin.json +20 -1
- package/package.json +2 -2
- package/src/config.ts +19 -0
- package/src/controller/controller-service.ts +50 -2
- package/src/controller/github-auth.ts +699 -0
- package/src/controller/http-server.ts +482 -6
- package/src/controller/orchestration-manifest.ts +1 -0
- package/src/controller/tunnel-manager.ts +386 -0
- package/src/controller/websocket.ts +2 -1
- package/src/controller/worker-provisioning.ts +15 -0
- package/src/task-executor.ts +17 -1
- package/src/teamauto/github-client.ts +254 -0
- package/src/teamauto/norms.ts +103 -0
- package/src/teamauto/repo-sync.ts +218 -0
- package/src/teamauto/scanner.ts +221 -0
- package/src/teamauto/scheduler.ts +595 -0
- package/src/teamauto/store.ts +242 -0
- package/src/types.ts +39 -0
- package/src/ui/app.js +892 -10
- package/src/ui/github-login.html +296 -0
- package/src/ui/index.html +52 -1
- package/src/ui/style.css +208 -58
- package/src/worker/worker-service.ts +16 -1
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { resolveTeamClawProjectsDir } from "../openclaw-workspace.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TeamAuto persistence: bound repos, schedules, policies, cursors, norms,
|
|
9
|
+
* and write-back bookkeeping. Mirrors the plugin state-dir resolution used by
|
|
10
|
+
* state.ts / github-auth.ts. See TEAMAUTO_DESIGN.md for the design contract.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const TEAMAUTO_STORE_VERSION = 1;
|
|
14
|
+
|
|
15
|
+
export type TeamAutoActionPolicy = {
|
|
16
|
+
issueReview: boolean;
|
|
17
|
+
takeOwnership: boolean;
|
|
18
|
+
prReview: boolean;
|
|
19
|
+
createPR: boolean;
|
|
20
|
+
fullReview: "off" | "weekly" | "daily";
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type TeamAutoKeywordFilter = {
|
|
24
|
+
include: string[];
|
|
25
|
+
exclude: string[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type TeamAutoRepoPolicy = {
|
|
29
|
+
maxTasksPerSweep: number;
|
|
30
|
+
actions: TeamAutoActionPolicy;
|
|
31
|
+
skipAssignedToHumans: boolean;
|
|
32
|
+
labelFilter: TeamAutoKeywordFilter;
|
|
33
|
+
keywordFilter: TeamAutoKeywordFilter;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type TeamAutoCursors = {
|
|
37
|
+
lastIssueSince: number;
|
|
38
|
+
lastPrSince: number;
|
|
39
|
+
lastCommitSha: string;
|
|
40
|
+
lastFullReviewAt: number;
|
|
41
|
+
seen: Record<string, number>;
|
|
42
|
+
etags: Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type TeamAutoRepoNorms = {
|
|
46
|
+
commitStyle: string;
|
|
47
|
+
issueTemplate: string | null;
|
|
48
|
+
prTemplate: string | null;
|
|
49
|
+
contributing: string | null;
|
|
50
|
+
learnedAt: number;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type TeamAutoRepoProvision = {
|
|
54
|
+
status: "provisioning" | "ready" | "failed";
|
|
55
|
+
/** Current stage label for UI display, e.g. "cloning repo". */
|
|
56
|
+
message: string;
|
|
57
|
+
startedAt: number;
|
|
58
|
+
updatedAt: number;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type TeamAutoRepo = {
|
|
62
|
+
id: string; // "owner/repo"
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
schedule: string; // cron, default "*/30 * * * *"
|
|
65
|
+
addedAt: number;
|
|
66
|
+
lastSweepAt: number;
|
|
67
|
+
lastSweepSummary: string | null;
|
|
68
|
+
pausedReason: string | null;
|
|
69
|
+
dryRunDone: boolean;
|
|
70
|
+
/** Bind-time provisioning state; ready/undefined means sweepable. */
|
|
71
|
+
provision?: TeamAutoRepoProvision;
|
|
72
|
+
policy: TeamAutoRepoPolicy;
|
|
73
|
+
cursors: TeamAutoCursors;
|
|
74
|
+
norms: TeamAutoRepoNorms | null;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type TeamAutoWriteBack = {
|
|
78
|
+
taskId: string;
|
|
79
|
+
action: "issueComment" | "prComment" | "createIssue" | "createPR";
|
|
80
|
+
repoId: string;
|
|
81
|
+
targetId: number | null;
|
|
82
|
+
doneAt: number | null;
|
|
83
|
+
prUrl: string | null;
|
|
84
|
+
error: string | null;
|
|
85
|
+
/** Joint full-review cycle id: same-cycle sections share one umbrella issue. */
|
|
86
|
+
cycleKey?: string;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type TeamAutoActivityKind = "bind" | "provision" | "sweep" | "task" | "writeback";
|
|
90
|
+
|
|
91
|
+
export type TeamAutoActivityEntry = {
|
|
92
|
+
at: number;
|
|
93
|
+
repoId: string;
|
|
94
|
+
kind: TeamAutoActivityKind;
|
|
95
|
+
text: string;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const TEAMAUTO_ACTIVITY_LIMIT = 100;
|
|
99
|
+
|
|
100
|
+
export function pushTeamAutoActivity(store: TeamAutoStore, entry: TeamAutoActivityEntry): void {
|
|
101
|
+
store.activity = store.activity ?? [];
|
|
102
|
+
store.activity.push(entry);
|
|
103
|
+
if (store.activity.length > TEAMAUTO_ACTIVITY_LIMIT) {
|
|
104
|
+
store.activity = store.activity.slice(store.activity.length - TEAMAUTO_ACTIVITY_LIMIT);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type TeamAutoStore = {
|
|
109
|
+
version: number;
|
|
110
|
+
repos: TeamAutoRepo[];
|
|
111
|
+
writebacks: TeamAutoWriteBack[];
|
|
112
|
+
/** Bounded activity log for the UI feed (persists across restarts). */
|
|
113
|
+
activity?: TeamAutoActivityEntry[];
|
|
114
|
+
budget: {
|
|
115
|
+
maxTasksPerDay: number;
|
|
116
|
+
firstSweepDryRun: boolean;
|
|
117
|
+
tasksToday: number;
|
|
118
|
+
dayStamp: string;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export function defaultPolicy(): TeamAutoRepoPolicy {
|
|
123
|
+
return {
|
|
124
|
+
maxTasksPerSweep: 5,
|
|
125
|
+
actions: { issueReview: true, takeOwnership: true, prReview: true, createPR: true, fullReview: "weekly" },
|
|
126
|
+
skipAssignedToHumans: true,
|
|
127
|
+
labelFilter: { include: [], exclude: ["wontfix", "teamclaw-skip", "do-not-automate"] },
|
|
128
|
+
keywordFilter: { include: [], exclude: [] },
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function defaultCursors(): TeamAutoCursors {
|
|
133
|
+
return { lastIssueSince: 0, lastPrSince: 0, lastCommitSha: "", lastFullReviewAt: 0, seen: {}, etags: {} };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function emptyStore(): TeamAutoStore {
|
|
137
|
+
const now = new Date();
|
|
138
|
+
return {
|
|
139
|
+
version: TEAMAUTO_STORE_VERSION,
|
|
140
|
+
repos: [],
|
|
141
|
+
writebacks: [],
|
|
142
|
+
activity: [],
|
|
143
|
+
budget: {
|
|
144
|
+
maxTasksPerDay: 50,
|
|
145
|
+
firstSweepDryRun: true,
|
|
146
|
+
tasksToday: 0,
|
|
147
|
+
dayStamp: now.toISOString().slice(0, 10),
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function resolveTeamAutoPaths(): { storeFile: string; reposRoot: string; legacyReposRoot: string } {
|
|
153
|
+
const explicitStateDir = process.env.OPENCLAW_STATE_DIR?.trim();
|
|
154
|
+
let base: string;
|
|
155
|
+
if (explicitStateDir) {
|
|
156
|
+
base = path.join(path.resolve(explicitStateDir), "plugins", "teamclaw");
|
|
157
|
+
} else {
|
|
158
|
+
const explicitHome = process.env.OPENCLAW_HOME?.trim() || process.env.HOME?.trim();
|
|
159
|
+
const homeDir = explicitHome ? path.resolve(explicitHome) : os.homedir();
|
|
160
|
+
base = path.join(homeDir, ".openclaw", "plugins", "teamclaw");
|
|
161
|
+
}
|
|
162
|
+
// Repos live inside the TeamClaw workspace projects tree so workers and
|
|
163
|
+
// the workspace browser can actually operate on them (TEAMAUTO_DESIGN.md).
|
|
164
|
+
// The pre-workspace location is kept only to migrate existing clones.
|
|
165
|
+
let reposRoot: string;
|
|
166
|
+
try {
|
|
167
|
+
reposRoot = path.join(resolveTeamClawProjectsDir(), "teamauto");
|
|
168
|
+
} catch {
|
|
169
|
+
reposRoot = path.join(base, "teamauto", "repos");
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
storeFile: path.join(base, "teamauto.json"),
|
|
173
|
+
reposRoot,
|
|
174
|
+
legacyReposRoot: path.join(base, "teamauto", "repos"),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const writeQueue: Promise<void>[] = [];
|
|
179
|
+
|
|
180
|
+
export async function loadTeamAutoStore(): Promise<TeamAutoStore> {
|
|
181
|
+
const { storeFile } = resolveTeamAutoPaths();
|
|
182
|
+
try {
|
|
183
|
+
const raw = await fs.readFile(storeFile, "utf8");
|
|
184
|
+
const parsed = JSON.parse(raw) as Partial<TeamAutoStore>;
|
|
185
|
+
const store = emptyStore();
|
|
186
|
+
if (Array.isArray(parsed.repos)) {
|
|
187
|
+
store.repos = parsed.repos
|
|
188
|
+
.filter((r): r is TeamAutoRepo => Boolean(r && typeof r.id === "string"))
|
|
189
|
+
.map((r) => ({
|
|
190
|
+
...r,
|
|
191
|
+
policy: { ...defaultPolicy(), ...(r.policy ?? {}), actions: { ...defaultPolicy().actions, ...(r.policy?.actions ?? {}) } },
|
|
192
|
+
cursors: { ...defaultCursors(), ...(r.cursors ?? {}) },
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
if (Array.isArray(parsed.writebacks)) {
|
|
196
|
+
store.writebacks = parsed.writebacks as TeamAutoWriteBack[];
|
|
197
|
+
}
|
|
198
|
+
if (Array.isArray(parsed.activity)) {
|
|
199
|
+
store.activity = parsed.activity.slice(-TEAMAUTO_ACTIVITY_LIMIT);
|
|
200
|
+
}
|
|
201
|
+
store.budget = { ...store.budget, ...(parsed.budget ?? {}) };
|
|
202
|
+
return store;
|
|
203
|
+
} catch {
|
|
204
|
+
return emptyStore();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export async function saveTeamAutoStore(store: TeamAutoStore): Promise<void> {
|
|
209
|
+
const { storeFile } = resolveTeamAutoPaths();
|
|
210
|
+
await fs.mkdir(path.dirname(storeFile), { recursive: true });
|
|
211
|
+
const tmp = `${storeFile}.tmp-${process.pid}-${Date.now()}`;
|
|
212
|
+
const next = writeQueue.length ? writeQueue[writeQueue.length - 1].catch(() => {}) : Promise.resolve();
|
|
213
|
+
const job = next.then(async () => {
|
|
214
|
+
await fs.writeFile(tmp, JSON.stringify(store, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
|
|
215
|
+
await fs.rename(tmp, storeFile);
|
|
216
|
+
});
|
|
217
|
+
writeQueue.push(job);
|
|
218
|
+
writeQueue.splice(0, Math.max(0, writeQueue.length - 20));
|
|
219
|
+
await job;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function repoSlugToDirName(repoId: string): string {
|
|
223
|
+
return repoId.replace(/[/\\]/g, "__");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function todayStamp(now = new Date()): string {
|
|
227
|
+
return now.toISOString().slice(0, 10);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Budget accounting: resets the daily counter on date rollover. */
|
|
231
|
+
export function consumeDailyBudget(store: TeamAutoStore, count: number, now = new Date()): boolean {
|
|
232
|
+
const stamp = todayStamp(now);
|
|
233
|
+
if (store.budget.dayStamp !== stamp) {
|
|
234
|
+
store.budget.dayStamp = stamp;
|
|
235
|
+
store.budget.tasksToday = 0;
|
|
236
|
+
}
|
|
237
|
+
if (store.budget.tasksToday + count > store.budget.maxTasksPerDay) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
store.budget.tasksToday += count;
|
|
241
|
+
return true;
|
|
242
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TEAMCLAW_PUBLISHED_RUNTIME_IMAGE } from "./install-defaults.js";
|
|
2
|
+
import { DEFAULT_GITHUB_CLIENT_ID } from "./controller/github-auth.js";
|
|
2
3
|
|
|
3
4
|
export type TeamClawMode = "controller" | "worker";
|
|
4
5
|
|
|
@@ -126,6 +127,11 @@ export type TaskInfo = {
|
|
|
126
127
|
lastHandoff?: TaskHandoffContract;
|
|
127
128
|
clarificationRequestId?: string;
|
|
128
129
|
execution?: TaskExecution;
|
|
130
|
+
/** Collaboration contract: read-only tasks never mutate the checkout; write tasks run in a dedicated git worktree and deliver via PR. */
|
|
131
|
+
writeMode?: "read-only" | "write";
|
|
132
|
+
/** Surviving progress snapshot for interrupted executions (resume support). */
|
|
133
|
+
checkpoint?: TaskCheckpoint;
|
|
134
|
+
resumeAttempt?: number;
|
|
129
135
|
};
|
|
130
136
|
|
|
131
137
|
export type TaskExecutionEvent = {
|
|
@@ -140,6 +146,19 @@ export type TaskExecutionEvent = {
|
|
|
140
146
|
workerId?: string;
|
|
141
147
|
};
|
|
142
148
|
|
|
149
|
+
export type TaskCheckpoint = {
|
|
150
|
+
/** Epoch ms of the last checkpoint update. */
|
|
151
|
+
updatedAt: number;
|
|
152
|
+
/** Monotonic resume counter; controller increments on each orphan reset. */
|
|
153
|
+
attempt: number;
|
|
154
|
+
/** OpenClaw session key hosting the persisted conversation for this task. */
|
|
155
|
+
sessionKey: string;
|
|
156
|
+
/** Last assistant message observed before the interruption. */
|
|
157
|
+
lastAssistantMessage: string;
|
|
158
|
+
/** Human-readable notes of verified work already done (latest last). */
|
|
159
|
+
progressNotes: string[];
|
|
160
|
+
};
|
|
161
|
+
|
|
143
162
|
export type TaskAssignmentPayload = {
|
|
144
163
|
taskId: string;
|
|
145
164
|
title: string;
|
|
@@ -149,6 +168,9 @@ export type TaskAssignmentPayload = {
|
|
|
149
168
|
projectDir?: string;
|
|
150
169
|
executionSessionKey?: string;
|
|
151
170
|
executionIdempotencyKey?: string;
|
|
171
|
+
/** Present when this assignment resumes an interrupted execution. */
|
|
172
|
+
checkpoint?: TaskCheckpoint;
|
|
173
|
+
resumeAttempt?: number;
|
|
152
174
|
repo?: RepoSyncInfo;
|
|
153
175
|
teamContext?: {
|
|
154
176
|
requirementSummary?: string;
|
|
@@ -489,6 +511,13 @@ export type PluginConfig = {
|
|
|
489
511
|
gitDefaultBranch: string;
|
|
490
512
|
gitAuthorName: string;
|
|
491
513
|
gitAuthorEmail: string;
|
|
514
|
+
/** GitHub App OAuth client ID used by the GitHub login feature. */
|
|
515
|
+
githubClientId: string;
|
|
516
|
+
/**
|
|
517
|
+
* GitHub App OAuth client secret. The TEAMCLAW_GITHUB_CLIENT_SECRET
|
|
518
|
+
* environment variable takes precedence when set.
|
|
519
|
+
*/
|
|
520
|
+
githubClientSecret: string;
|
|
492
521
|
agentIsolationMode: AgentIsolationMode;
|
|
493
522
|
workerProvisioningType: WorkerProvisioningType;
|
|
494
523
|
workerProvisioningDisabled: boolean;
|
|
@@ -649,6 +678,14 @@ export function parsePluginConfig(raw: Record<string, unknown> = {}): PluginConf
|
|
|
649
678
|
? raw.gitAuthorEmail.trim()
|
|
650
679
|
: "teamclaw@local";
|
|
651
680
|
|
|
681
|
+
const githubClientId = typeof raw.githubClientId === "string" && raw.githubClientId.trim()
|
|
682
|
+
? raw.githubClientId.trim()
|
|
683
|
+
: DEFAULT_GITHUB_CLIENT_ID;
|
|
684
|
+
|
|
685
|
+
const githubClientSecret = typeof raw.githubClientSecret === "string"
|
|
686
|
+
? raw.githubClientSecret.trim()
|
|
687
|
+
: "";
|
|
688
|
+
|
|
652
689
|
const agentIsolationMode: AgentIsolationMode =
|
|
653
690
|
typeof raw.agentIsolationMode === "string" && (raw.agentIsolationMode === "independent" || raw.agentIsolationMode === "main")
|
|
654
691
|
? raw.agentIsolationMode
|
|
@@ -755,6 +792,8 @@ export function parsePluginConfig(raw: Record<string, unknown> = {}): PluginConf
|
|
|
755
792
|
gitDefaultBranch,
|
|
756
793
|
gitAuthorName,
|
|
757
794
|
gitAuthorEmail,
|
|
795
|
+
githubClientId,
|
|
796
|
+
githubClientSecret,
|
|
758
797
|
agentIsolationMode,
|
|
759
798
|
workerProvisioningType,
|
|
760
799
|
workerProvisioningDisabled,
|