@teamclaws/teamclaw 2026.8.1 → 2026.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.mjs +318 -17
- package/dist/index.js +54 -32
- package/dist/src/config.js +57 -2
- package/dist/src/controller/auth-routes.js +129 -0
- package/dist/src/controller/clarification-routes.js +315 -0
- package/dist/src/controller/controller-intake.js +895 -0
- package/dist/src/controller/controller-planning.js +814 -0
- package/dist/src/controller/controller-routes.js +195 -0
- package/dist/src/controller/controller-runs.js +175 -0
- package/dist/src/controller/controller-service.js +338 -50
- package/dist/src/controller/controller-tools.js +14 -7
- package/dist/src/controller/github-auth.js +2 -1
- package/dist/src/controller/http-server.js +290 -6003
- package/dist/src/controller/kickoff-orchestrator.js +33 -43
- package/dist/src/controller/message-delivery.js +31 -0
- package/dist/src/controller/message-routes.js +114 -0
- package/dist/src/controller/orchestration-manifest.js +11 -93
- package/dist/src/controller/preview-manager.js +51 -3
- package/dist/src/controller/preview-proxy.js +98 -0
- package/dist/src/controller/profile-switch.js +309 -0
- package/dist/src/controller/project-registry.js +294 -0
- package/dist/src/controller/prompt-injector.js +19 -9
- package/dist/src/controller/provisioning/backend-contract.js +9 -0
- package/dist/src/controller/provisioning/container-shared.js +64 -0
- package/dist/src/controller/provisioning/docker.js +214 -0
- package/dist/src/controller/provisioning/kubernetes.js +244 -0
- package/dist/src/controller/provisioning/plugin-root.js +41 -0
- package/dist/src/controller/provisioning/process-supervisor.js +190 -0
- package/dist/src/controller/provisioning-config.js +239 -0
- package/dist/src/controller/repo-routes.js +129 -0
- package/dist/src/controller/report-routes.js +56 -0
- package/dist/src/controller/role-inference.js +231 -20
- package/dist/src/controller/route-table.js +375 -0
- package/dist/src/controller/security.js +775 -0
- package/dist/src/controller/status-routes.js +287 -0
- package/dist/src/controller/task-assignment.js +511 -0
- package/dist/src/controller/task-cleanup.js +258 -0
- package/dist/src/controller/task-execution.js +271 -0
- package/dist/src/controller/task-results.js +471 -0
- package/dist/src/controller/task-router.js +74 -4
- package/dist/src/controller/task-routes.js +703 -0
- package/dist/src/controller/teamauto-routes.js +124 -0
- package/dist/src/controller/tunnel-manager.js +41 -8
- package/dist/src/controller/tunnel-routes.js +225 -0
- package/dist/src/controller/ui-assets.js +68 -0
- package/dist/src/controller/websocket.js +6 -2
- package/dist/src/controller/webui-routes.js +49 -0
- package/dist/src/controller/worker-provisioning.js +69 -953
- package/dist/src/controller/worker-routes.js +188 -0
- package/dist/src/controller/workflow-routes.js +407 -0
- package/dist/src/controller/workspace-routes.js +200 -0
- package/dist/src/git-collaboration.js +4 -9
- package/dist/src/identity.js +15 -3
- package/dist/src/interaction-contracts.js +7 -7
- package/dist/src/openclaw-workspace.js +40 -18
- package/dist/src/profile-loader.js +604 -0
- package/dist/src/profiles/banking.json +202 -0
- package/dist/src/profiles/crossborder-ecom.json +253 -0
- package/dist/src/profiles/insurance.json +157 -0
- package/dist/src/profiles/knowledge/hs-structure.md +97 -0
- package/dist/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/dist/src/profiles/knowledge/vat-principles.md +85 -0
- package/dist/src/profiles/schema.json +281 -0
- package/dist/src/profiles/securities.json +137 -0
- package/dist/src/profiles/software-rd.json +264 -0
- package/dist/src/profiles/trading-co.json +200 -0
- package/dist/src/prompt-policy.js +42 -17
- package/dist/src/protocol.js +66 -3
- package/dist/src/role-ids.js +29 -0
- package/dist/src/roles.js +54 -13
- package/dist/src/session-roles.js +14 -0
- package/dist/src/shared/clarification-schema.js +65 -0
- package/dist/src/shared/github-auth.js +15 -0
- package/dist/src/shared/kickoff-prompt.js +37 -0
- package/dist/src/shared/utils.js +47 -0
- package/dist/src/state.js +275 -11
- package/dist/src/task-executor.js +7 -17
- package/dist/src/teamauto/github-client.js +18 -0
- package/dist/src/teamauto/repo-sync.js +228 -6
- package/dist/src/teamauto/scanner.js +40 -12
- package/dist/src/teamauto/scheduler.js +231 -12
- package/dist/src/types.js +77 -16
- package/dist/src/ui/app.js +1434 -82
- package/dist/src/ui/github-login.html +1 -0
- package/dist/src/ui/index.html +144 -45
- package/dist/src/ui/style.css +194 -0
- package/dist/src/worker/http-handler.js +59 -0
- package/dist/src/worker/prompt-injector.js +44 -8
- package/dist/src/worker/skill-installer.js +6 -10
- package/dist/src/worker/tools.js +20 -10
- package/dist/src/worker/worker-service.js +93 -7
- package/index.ts +61 -32
- package/openclaw.plugin.json +50 -2
- package/package.json +3 -2
- package/src/config.ts +57 -2
- package/src/controller/auth-routes.ts +157 -0
- package/src/controller/clarification-routes.ts +404 -0
- package/src/controller/controller-intake.ts +1113 -0
- package/src/controller/controller-planning.ts +1037 -0
- package/src/controller/controller-routes.ts +237 -0
- package/src/controller/controller-runs.ts +239 -0
- package/src/controller/controller-service.ts +422 -50
- package/src/controller/controller-tools.ts +16 -9
- package/src/controller/github-auth.ts +28 -63
- package/src/controller/http-server.ts +336 -6964
- package/src/controller/kickoff-orchestrator.ts +69 -45
- package/src/controller/message-delivery.ts +52 -0
- package/src/controller/message-routes.ts +137 -0
- package/src/controller/orchestration-manifest.ts +14 -100
- package/src/controller/preview-manager.ts +53 -3
- package/src/controller/preview-proxy.ts +127 -0
- package/src/controller/profile-switch.ts +396 -0
- package/src/controller/project-registry.ts +361 -0
- package/src/controller/prompt-injector.ts +23 -8
- package/src/controller/provisioning/backend-contract.ts +51 -0
- package/src/controller/provisioning/container-shared.ts +84 -0
- package/src/controller/provisioning/docker.ts +260 -0
- package/src/controller/provisioning/kubernetes.ts +263 -0
- package/src/controller/provisioning/plugin-root.ts +42 -0
- package/src/controller/provisioning/process-supervisor.ts +214 -0
- package/src/controller/provisioning-config.ts +289 -0
- package/src/controller/repo-routes.ts +163 -0
- package/src/controller/report-routes.ts +64 -0
- package/src/controller/role-inference.ts +260 -22
- package/src/controller/route-table.ts +597 -0
- package/src/controller/security.ts +899 -0
- package/src/controller/status-routes.ts +354 -0
- package/src/controller/task-assignment.ts +622 -0
- package/src/controller/task-cleanup.ts +344 -0
- package/src/controller/task-execution.ts +399 -0
- package/src/controller/task-results.ts +556 -0
- package/src/controller/task-router.ts +98 -6
- package/src/controller/task-routes.ts +812 -0
- package/src/controller/teamauto-routes.ts +121 -0
- package/src/controller/tunnel-manager.ts +45 -8
- package/src/controller/tunnel-routes.ts +231 -0
- package/src/controller/ui-assets.ts +70 -0
- package/src/controller/websocket.ts +32 -4
- package/src/controller/webui-routes.ts +55 -0
- package/src/controller/worker-provisioning.ts +83 -1121
- package/src/controller/worker-routes.ts +241 -0
- package/src/controller/workflow-routes.ts +498 -0
- package/src/controller/workspace-routes.ts +222 -0
- package/src/git-collaboration.ts +4 -9
- package/src/identity.ts +16 -3
- package/src/interaction-contracts.ts +7 -7
- package/src/openclaw-workspace.ts +44 -18
- package/src/profile-loader.ts +816 -0
- package/src/profiles/banking.json +202 -0
- package/src/profiles/crossborder-ecom.json +253 -0
- package/src/profiles/insurance.json +157 -0
- package/src/profiles/knowledge/hs-structure.md +97 -0
- package/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/src/profiles/knowledge/vat-principles.md +85 -0
- package/src/profiles/schema.json +281 -0
- package/src/profiles/securities.json +137 -0
- package/src/profiles/software-rd.json +264 -0
- package/src/profiles/trading-co.json +200 -0
- package/src/prompt-policy.ts +44 -17
- package/src/protocol.ts +72 -2
- package/src/role-ids.ts +31 -0
- package/src/roles.ts +60 -14
- package/src/session-roles.ts +14 -0
- package/src/shared/clarification-schema.ts +81 -0
- package/src/shared/github-auth.ts +92 -0
- package/src/shared/kickoff-prompt.ts +47 -0
- package/src/shared/utils.ts +51 -0
- package/src/state.ts +326 -10
- package/src/task-executor.ts +7 -18
- package/src/teamauto/github-client.ts +23 -1
- package/src/teamauto/repo-sync.ts +248 -7
- package/src/teamauto/scanner.ts +47 -13
- package/src/teamauto/scheduler.ts +261 -17
- package/src/teamauto/store.ts +12 -0
- package/src/types.ts +263 -17
- package/src/ui/app.js +1434 -82
- package/src/ui/github-login.html +1 -0
- package/src/ui/index.html +144 -45
- package/src/ui/style.css +194 -0
- package/src/worker/http-handler.ts +64 -1
- package/src/worker/prompt-injector.ts +48 -8
- package/src/worker/skill-installer.ts +6 -10
- package/src/worker/tools.ts +21 -10
- package/src/worker/worker-service.ts +101 -7
|
@@ -3,13 +3,29 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// Issue #226 W5: cross-subsystem contract lives in the shared layer now.
|
|
7
|
+
import type { GithubAuthManager } from "../shared/github-auth.js";
|
|
7
8
|
import { repoSlugToDirName, resolveTeamAutoPaths } from "./store.js";
|
|
8
9
|
|
|
9
10
|
const exec = promisify(execFile);
|
|
10
11
|
|
|
11
12
|
export const TEAMCLAW_BRANCH_PREFIX = "teamclaw/";
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Delivery oracle for worktree GC (#173 follow-up 5): after a squash merge +
|
|
16
|
+
* branch deletion the task branch's commits never become reachable from
|
|
17
|
+
* origin/<default> (different shas, same content), so ls-remote is empty and
|
|
18
|
+
* the local rev-list own-count never drains. The scheduler supplies an oracle
|
|
19
|
+
* that asks GitHub whether a PR carrying EXACTLY this head tip was merged.
|
|
20
|
+
* Returns true only on positive proof; any error must resolve false (fail
|
|
21
|
+
* toward keep).
|
|
22
|
+
*/
|
|
23
|
+
export type TaskDeliveryOracle = (
|
|
24
|
+
repoId: string,
|
|
25
|
+
taskId: string,
|
|
26
|
+
headTip: string,
|
|
27
|
+
) => Promise<boolean>;
|
|
28
|
+
|
|
13
29
|
/** TaskInfo.projectDir slug for a bound repo (relative to the projects dir). */
|
|
14
30
|
export function teamAutoProjectDir(repoId: string): string {
|
|
15
31
|
return `teamauto/${repoSlugToDirName(repoId)}`;
|
|
@@ -158,6 +174,65 @@ export function createRepoSync(auth: GithubAuthManager, logger: { warn: (m: stri
|
|
|
158
174
|
return `teamclaw/task-${taskId.replace(/[^\w-]/g, "")}`;
|
|
159
175
|
}
|
|
160
176
|
|
|
177
|
+
// ---------- in-use sentinel (#173 follow-up 2) ----------
|
|
178
|
+
|
|
179
|
+
// The lock lives in the per-worktree git ADMIN dir, never inside the worktree
|
|
180
|
+
// tree: a file in the tree would dirty `git status --porcelain` and wedge the
|
|
181
|
+
// GC dirty guard. The admin dir is removed together with the worktree.
|
|
182
|
+
const TASK_LOCK_NAME = "teamclaw-task-lock.json";
|
|
183
|
+
|
|
184
|
+
async function taskLockPath(wtPath: string): Promise<string | null> {
|
|
185
|
+
try {
|
|
186
|
+
const out = (await run(["rev-parse", "--git-dir"], wtPath)).trim();
|
|
187
|
+
return path.join(path.resolve(wtPath, out), TASK_LOCK_NAME);
|
|
188
|
+
} catch {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function processAlive(pid: number): boolean {
|
|
194
|
+
try {
|
|
195
|
+
process.kill(pid, 0);
|
|
196
|
+
return true;
|
|
197
|
+
} catch (err) {
|
|
198
|
+
// EPERM: alive but owned by another user - treat as in use.
|
|
199
|
+
return (err as NodeJS.ErrnoException).code === "EPERM";
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function writeTaskLock(wtPath: string): Promise<void> {
|
|
204
|
+
const lockPath = await taskLockPath(wtPath);
|
|
205
|
+
if (!lockPath) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
await fs.writeFile(lockPath, JSON.stringify({ pid: process.pid, at: Date.now() })).catch(() => undefined);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Live foreign controller holding this worktree, or null. Covers two
|
|
213
|
+
* controllers sharing one projects/ tree: whoever created/resumed the
|
|
214
|
+
* worktree last recorded its pid; GC (a different live pid) must not rip the
|
|
215
|
+
* tree out from under it. Our OWN pid never blocks (we are the GC). An
|
|
216
|
+
* orphaned worker process is not visible from the controller - the dirty
|
|
217
|
+
* guard remains that case's backstop (fails toward keep).
|
|
218
|
+
*/
|
|
219
|
+
async function worktreeInUseBy(wtPath: string): Promise<number | null> {
|
|
220
|
+
const lockPath = await taskLockPath(wtPath);
|
|
221
|
+
if (!lockPath) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
const lock = JSON.parse(await fs.readFile(lockPath, "utf8")) as { pid?: number };
|
|
226
|
+
const pid = Number(lock.pid);
|
|
227
|
+
if (Number.isInteger(pid) && pid > 0 && pid !== process.pid && processAlive(pid)) {
|
|
228
|
+
return pid;
|
|
229
|
+
}
|
|
230
|
+
} catch {
|
|
231
|
+
// missing/corrupt lock - cannot prove in-use; proceed.
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
|
|
161
236
|
/**
|
|
162
237
|
* Collaboration contract: write tasks execute in a dedicated git worktree
|
|
163
238
|
* branched from HEAD. Reuses an existing worktree (resume-safe) so the
|
|
@@ -169,11 +244,12 @@ export function createRepoSync(auth: GithubAuthManager, logger: { warn: (m: stri
|
|
|
169
244
|
// wtName carries the teamauto/ level for the REL path; the physical dir is
|
|
170
245
|
// a SIBLING of the base checkout (path.join would nest teamauto/ twice).
|
|
171
246
|
const wtPath = path.join(path.dirname(base), path.basename(wtName));
|
|
172
|
-
if (await fs.access(path.join(wtPath, ".git")).then(() => true, () => false)) {
|
|
173
|
-
|
|
247
|
+
if (!(await fs.access(path.join(wtPath, ".git")).then(() => true, () => false))) {
|
|
248
|
+
await run(["worktree", "add", "-b", taskBranchName(taskId), wtPath, "HEAD"], base);
|
|
249
|
+
logger.warn(`TeamAuto: worktree ${wtName} (branch ${taskBranchName(taskId)}) for ${taskId}`);
|
|
174
250
|
}
|
|
175
|
-
|
|
176
|
-
|
|
251
|
+
// Refresh the in-use sentinel on create AND resume (#173 follow-up 2).
|
|
252
|
+
await writeTaskLock(wtPath);
|
|
177
253
|
return wtPath;
|
|
178
254
|
}
|
|
179
255
|
|
|
@@ -184,7 +260,12 @@ export function createRepoSync(auth: GithubAuthManager, logger: { warn: (m: stri
|
|
|
184
260
|
const wtPath = path.join(path.dirname(base), path.basename(wtName));
|
|
185
261
|
try {
|
|
186
262
|
if (await fs.access(wtPath).then(() => true, () => false)) {
|
|
187
|
-
await run(["worktree", "remove", "--force", wtPath], base)
|
|
263
|
+
await run(["worktree", "remove", "--force", wtPath], base).catch(async () => {
|
|
264
|
+
// Not a registered worktree anymore (stale admin dir / manual mv):
|
|
265
|
+
// prune registrations and delete the directory directly.
|
|
266
|
+
await run(["worktree", "prune"], base).catch(() => undefined);
|
|
267
|
+
await fs.rm(wtPath, { recursive: true, force: true });
|
|
268
|
+
});
|
|
188
269
|
}
|
|
189
270
|
await run(["branch", "-D", taskBranchName(taskId)], base).catch(() => undefined);
|
|
190
271
|
} catch (err) {
|
|
@@ -192,6 +273,166 @@ export function createRepoSync(auth: GithubAuthManager, logger: { warn: (m: stri
|
|
|
192
273
|
}
|
|
193
274
|
}
|
|
194
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Terminal-state removal with a delivery-safety check: delete the task
|
|
278
|
+
* worktree only when its work is either already on the remote (branch tip
|
|
279
|
+
* matches) or nonexistent (no commits of its own). Undelivered local work
|
|
280
|
+
* is retained and reported - never silently destroyed.
|
|
281
|
+
*/
|
|
282
|
+
async function safeRemoveTaskWorktree(
|
|
283
|
+
repoId: string,
|
|
284
|
+
taskId: string,
|
|
285
|
+
deliveryOracle?: TaskDeliveryOracle,
|
|
286
|
+
): Promise<{ removed: boolean; reason: string }> {
|
|
287
|
+
const base = await repoDir(repoId);
|
|
288
|
+
const wtName = taskWorktreeDirName(repoId, taskId);
|
|
289
|
+
const wtPath = path.join(path.dirname(base), path.basename(wtName));
|
|
290
|
+
const branch = taskBranchName(taskId);
|
|
291
|
+
if (!(await fs.access(wtPath).then(() => true, () => false))) {
|
|
292
|
+
// Review F4: the dir is gone but a stale local branch can survive an
|
|
293
|
+
// earlier removal whose branch -D failed. Reap it when the remote tip
|
|
294
|
+
// still matches (work provably on the remote); otherwise leave it.
|
|
295
|
+
try {
|
|
296
|
+
const refs = await run(["ls-remote", "origin", `refs/heads/${branch}`], base);
|
|
297
|
+
const remoteTip = refs.split("\t")[0]?.trim() ?? "";
|
|
298
|
+
const localTip = remoteTip ? (await run(["rev-parse", branch], base).catch(() => "")).trim() : "";
|
|
299
|
+
if (remoteTip && localTip === remoteTip) {
|
|
300
|
+
await run(["branch", "-D", branch], base);
|
|
301
|
+
return { removed: true, reason: "worktree already gone; reaped stale branch (tip matches remote)" };
|
|
302
|
+
}
|
|
303
|
+
} catch { /* conservative: leave the branch */ }
|
|
304
|
+
return { removed: false, reason: "already gone" };
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
// #173 follow-up 2: in-use sentinel - a live foreign controller recorded
|
|
308
|
+
// in the task lock owns this tree; never remove under it.
|
|
309
|
+
const inUsePid = await worktreeInUseBy(wtPath);
|
|
310
|
+
if (inUsePid !== null) {
|
|
311
|
+
return { removed: false, reason: `retained: in use by live process (pid ${inUsePid})` };
|
|
312
|
+
}
|
|
313
|
+
// #173 follow-up 1: the dirty guard must cover BOTH removal paths. The
|
|
314
|
+
// tip-match branch used to remove without any dirty check, silently
|
|
315
|
+
// destroying post-delivery worker edits (small window, but real).
|
|
316
|
+
const dirty = await run(["status", "--porcelain"], wtPath).catch(() => "x");
|
|
317
|
+
if (dirty.trim()) {
|
|
318
|
+
return { removed: false, reason: "retained: dirty worktree (uncommitted changes)" };
|
|
319
|
+
}
|
|
320
|
+
const remoteRefs = await run(["ls-remote", "origin", `refs/heads/${branch}`], base);
|
|
321
|
+
const remoteTip = remoteRefs.split("\t")[0]?.trim() ?? "";
|
|
322
|
+
if (remoteTip) {
|
|
323
|
+
const localTip = (await run(["rev-parse", branch], base).catch(() => "")).trim();
|
|
324
|
+
if (localTip && localTip === remoteTip) {
|
|
325
|
+
await removeTaskWorktree(repoId, taskId);
|
|
326
|
+
return { removed: true, reason: "delivered (branch tip on remote)" };
|
|
327
|
+
}
|
|
328
|
+
return { removed: false, reason: "retained: local branch ahead of pushed tip (unpushed work)" };
|
|
329
|
+
}
|
|
330
|
+
// Branch never pushed (or deleted post-merge): the worktree is the only
|
|
331
|
+
// copy. Keep it when it carries its own commits; drop it when the worker
|
|
332
|
+
// never committed anything at all.
|
|
333
|
+
const info = await run(["symbolic-ref", "--short", "refs/remotes/origin/HEAD"], base).catch(() => "");
|
|
334
|
+
const defaultBranch = info.trim().replace(/^origin\//, "") || "main";
|
|
335
|
+
const own = await run(["rev-list", "--count", `HEAD`, "--not", `origin/${defaultBranch}`], wtPath).catch(() => null);
|
|
336
|
+
if (own === null) {
|
|
337
|
+
// Cannot prove emptiness (fetch state unknown) - conservative keep.
|
|
338
|
+
return { removed: false, reason: "retained: could not verify emptiness" };
|
|
339
|
+
}
|
|
340
|
+
if (Number(own.trim()) === 0) {
|
|
341
|
+
await removeTaskWorktree(repoId, taskId);
|
|
342
|
+
return { removed: true, reason: "no own commits, branch never pushed" };
|
|
343
|
+
}
|
|
344
|
+
// #173 follow-up 5: squash-merge + branch deletion re-leak. own > 0 with
|
|
345
|
+
// an empty ls-remote is ALSO the shape of a delivered-via-squash PR whose
|
|
346
|
+
// branch was auto-deleted (shas unreachable, content merged). Ask the
|
|
347
|
+
// oracle for positive proof (merged PR with exactly this head tip);
|
|
348
|
+
// anything less retains the worktree.
|
|
349
|
+
if (deliveryOracle) {
|
|
350
|
+
const headTip = (await run(["rev-parse", "HEAD"], wtPath).catch(() => "")).trim();
|
|
351
|
+
if (headTip && (await deliveryOracle(repoId, taskId, headTip).catch(() => false))) {
|
|
352
|
+
await removeTaskWorktree(repoId, taskId);
|
|
353
|
+
return { removed: true, reason: "delivered via merged PR (squash-merge, head tip matches)" };
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return { removed: false, reason: `retained: ${own.trim()} unpushed own commit(s)` };
|
|
357
|
+
} catch (err) {
|
|
358
|
+
return { removed: false, reason: `retained: gc check failed (${err instanceof Error ? err.message : String(err)})` };
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Reconcile leftover task worktrees on disk: for every `<slug>__task-*`
|
|
364
|
+
* sibling whose task is terminal (or unknown), apply the delivery-safety
|
|
365
|
+
* removal. Heals the historical backlog that pre-dates terminal cleanup.
|
|
366
|
+
*/
|
|
367
|
+
async function gcTaskWorktrees(
|
|
368
|
+
repoId: string,
|
|
369
|
+
isTerminal: (taskId: string) => boolean,
|
|
370
|
+
deliveryOracle?: TaskDeliveryOracle,
|
|
371
|
+
): Promise<{ removed: string[]; retained: { taskId: string; reason: string }[]; stale: number }> {
|
|
372
|
+
const base = await repoDir(repoId);
|
|
373
|
+
const siblings = path.dirname(base);
|
|
374
|
+
// taskWorktreeDirName(repoId, "x") = "teamauto/<slug>__task-x"; the
|
|
375
|
+
// physical dir is its basename, so the scan prefix is basename minus "x".
|
|
376
|
+
const withSentinel = path.basename(taskWorktreeDirName(repoId, "x"));
|
|
377
|
+
const prefix = withSentinel.slice(0, withSentinel.length - 1);
|
|
378
|
+
const removed: string[] = [];
|
|
379
|
+
const retained: { taskId: string; reason: string }[] = [];
|
|
380
|
+
let stale = 0;
|
|
381
|
+
const apply = async (taskId: string): Promise<void> => {
|
|
382
|
+
const r = await safeRemoveTaskWorktree(repoId, taskId, deliveryOracle);
|
|
383
|
+
if (r.removed) {
|
|
384
|
+
removed.push(taskId);
|
|
385
|
+
logger.warn(`TeamAuto: worktree GC removed ${taskId} (${r.reason})`);
|
|
386
|
+
} else if (r.reason.includes("already gone")) {
|
|
387
|
+
// #173 QA finding: dir already gone but a stale local branch survives
|
|
388
|
+
// (squash-merge leak face) - previously invisible in both the log and
|
|
389
|
+
// the activity line. Counted + logged now.
|
|
390
|
+
stale += 1;
|
|
391
|
+
logger.warn(`TeamAuto: worktree GC ${taskId}: worktree already gone (stale branch may remain)`);
|
|
392
|
+
} else {
|
|
393
|
+
retained.push({ taskId, reason: r.reason });
|
|
394
|
+
logger.warn(`TeamAuto: worktree GC kept ${taskId}: ${r.reason}`);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
let entries: string[] = [];
|
|
398
|
+
try {
|
|
399
|
+
entries = (await fs.readdir(siblings)).filter((e) => e.startsWith(prefix));
|
|
400
|
+
} catch {
|
|
401
|
+
entries = [];
|
|
402
|
+
}
|
|
403
|
+
const dirTaskIds: string[] = [];
|
|
404
|
+
for (const entry of entries) {
|
|
405
|
+
const taskId = entry.slice(prefix.length);
|
|
406
|
+
if (!taskId) continue;
|
|
407
|
+
dirTaskIds.push(taskId);
|
|
408
|
+
if (!isTerminal(taskId)) continue; // active/resumable task - worktree is resume state
|
|
409
|
+
await apply(taskId);
|
|
410
|
+
}
|
|
411
|
+
// #173 QA finding: BRANCH-ONLY leaks - the worktree dir is already gone
|
|
412
|
+
// but the local teamclaw/task-* branch survives (e.g. an earlier removal
|
|
413
|
+
// whose branch -D failed, or the squash-merge stale-branch face). The
|
|
414
|
+
// directory enumeration above never sees them; enumerate the branches too
|
|
415
|
+
// so safeRemoveTaskWorktree can reap (tip on remote) or at least surface
|
|
416
|
+
// them in the stale count instead of leaking silently forever.
|
|
417
|
+
const branchPrefix = `${TEAMCLAW_BRANCH_PREFIX}task-`;
|
|
418
|
+
let branchRefs: string[] = [];
|
|
419
|
+
try {
|
|
420
|
+
branchRefs = (await run(["for-each-ref", "--format=%(refname:short)", `refs/heads/${branchPrefix}*`], base))
|
|
421
|
+
.split("\n")
|
|
422
|
+
.filter(Boolean);
|
|
423
|
+
} catch {
|
|
424
|
+
branchRefs = [];
|
|
425
|
+
}
|
|
426
|
+
const seen = new Set(dirTaskIds);
|
|
427
|
+
for (const ref of branchRefs) {
|
|
428
|
+
const taskId = ref.slice(branchPrefix.length);
|
|
429
|
+
if (!taskId || seen.has(taskId)) continue;
|
|
430
|
+
if (!isTerminal(taskId)) continue;
|
|
431
|
+
await apply(taskId);
|
|
432
|
+
}
|
|
433
|
+
return { removed, retained, stale };
|
|
434
|
+
}
|
|
435
|
+
|
|
195
436
|
function taskWorktreeRelDir(repoId: string, taskId: string): string {
|
|
196
437
|
return taskWorktreeDirName(repoId, taskId);
|
|
197
438
|
}
|
|
@@ -212,7 +453,7 @@ export function createRepoSync(auth: GithubAuthManager, logger: { warn: (m: stri
|
|
|
212
453
|
}
|
|
213
454
|
}
|
|
214
455
|
|
|
215
|
-
return { ensureCloned, currentSha, recentCommitMessages, readFileIfPresent, safeRepoPath, createWorkBranch, commitAll, pushBranch, ensureTaskWorktree, removeTaskWorktree, taskWorktreeRelDir, taskBranchName, branchHasCommits, repoDir };
|
|
456
|
+
return { ensureCloned, currentSha, recentCommitMessages, readFileIfPresent, safeRepoPath, createWorkBranch, commitAll, pushBranch, ensureTaskWorktree, removeTaskWorktree, safeRemoveTaskWorktree, gcTaskWorktrees, taskWorktreeRelDir, taskBranchName, branchHasCommits, repoDir };
|
|
216
457
|
}
|
|
217
458
|
|
|
218
459
|
export type TeamAutoRepoSync = ReturnType<typeof createRepoSync>;
|
package/src/teamauto/scanner.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getActiveProfile } from "../profile-loader.js";
|
|
2
|
+
import type { RoleId } from "../types.js";
|
|
1
3
|
import type { SweepableIssue, SweepablePull, TeamAutoGithubClient } from "./github-client.js";
|
|
2
4
|
import type { TeamAutoRepo } from "./store.js";
|
|
3
5
|
|
|
@@ -9,14 +11,39 @@ import type { TeamAutoRepo } from "./store.js";
|
|
|
9
11
|
|
|
10
12
|
export type CandidateKind = "issueReview" | "takeOwnership" | "prReview" | "fullReview";
|
|
11
13
|
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Joint full-review section definitions: which review sections exist and
|
|
16
|
+
* what each section focuses on. The ROLE SET is derived from the ACTIVE team
|
|
17
|
+
* profile at sweep time (Phase 2.3, P1 handover debt item 4): only sections
|
|
18
|
+
* whose role id is a role of the active profile are scheduled, replacing the
|
|
19
|
+
* old hardcoded role-id literal list + closed role union. software-rd keeps
|
|
20
|
+
* all three sections, so its sweeps are unchanged; a profile that carries
|
|
21
|
+
* none of the section roles simply produces no joint full-review candidates.
|
|
22
|
+
*/
|
|
23
|
+
const JOINT_REVIEW_SECTIONS: ReadonlyArray<{ id: RoleId; focus: string }> = [
|
|
24
|
+
{
|
|
25
|
+
id: "architect",
|
|
26
|
+
focus: "architecture and structure: module boundaries, layering, README/docs accuracy, maintainability hotspots, dead or duplicated code paths",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "qa",
|
|
30
|
+
focus: "quality and tests: test coverage gaps, flaky-test hotspots, error-handling weaknesses, missing failure-path tests, CI blind spots",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "security-engineer",
|
|
34
|
+
focus: "security surface: dependency risks, secret handling, injection/validation gaps, auth-sensitive paths, unsafe defaults",
|
|
35
|
+
},
|
|
36
|
+
];
|
|
14
37
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Joint-review sections whose roles exist in the ACTIVE profile, in section
|
|
40
|
+
* order (one candidate per role, one shared cycle). Derived per call so a
|
|
41
|
+
* profile switch flips the joint fan-out on the next sweep.
|
|
42
|
+
*/
|
|
43
|
+
export function resolveJointReviewSections(): ReadonlyArray<{ id: RoleId; focus: string }> {
|
|
44
|
+
const activeRoleIds = new Set(getActiveProfile().roles.map((role) => role.id));
|
|
45
|
+
return JOINT_REVIEW_SECTIONS.filter((section) => activeRoleIds.has(section.id));
|
|
46
|
+
}
|
|
20
47
|
|
|
21
48
|
export type Candidate = {
|
|
22
49
|
kind: CandidateKind;
|
|
@@ -24,7 +51,12 @@ export type Candidate = {
|
|
|
24
51
|
key: string; // idempotency key, e.g. "owner/repo#issue-42"
|
|
25
52
|
number: number;
|
|
26
53
|
title: string;
|
|
27
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Role the candidate is routed to. RoleId (not a software-only literal
|
|
56
|
+
* union) since Phase 2.3 debt item 4: candidates may name any role of the
|
|
57
|
+
* active profile.
|
|
58
|
+
*/
|
|
59
|
+
role: RoleId;
|
|
28
60
|
/** Collaboration contract: reviews are read-only, ownership work writes. */
|
|
29
61
|
writeMode: "read-only" | "write";
|
|
30
62
|
/** Shared full-review cycle id: write-backs group on it (umbrella issue). */
|
|
@@ -161,10 +193,12 @@ export async function sweepRepo(
|
|
|
161
193
|
// repo whose first sweep observed nothing - see the deadlock note above).
|
|
162
194
|
if (now - repo.cursors.lastFullReviewAt >= intervalMs) {
|
|
163
195
|
const cycle = Math.floor(now / intervalMs);
|
|
164
|
-
// Joint review: one candidate per role
|
|
165
|
-
// reply becomes a labeled section of a
|
|
166
|
-
// (the write-back reconciler groups by
|
|
167
|
-
|
|
196
|
+
// Joint review: one candidate per section role of the ACTIVE profile,
|
|
197
|
+
// one shared cycle. Each role's reply becomes a labeled section of a
|
|
198
|
+
// single umbrella review issue (the write-back reconciler groups by
|
|
199
|
+
// the cycle key).
|
|
200
|
+
for (const section of resolveJointReviewSections()) {
|
|
201
|
+
const role = section.id;
|
|
168
202
|
candidates.push({
|
|
169
203
|
repoId: repo.id,
|
|
170
204
|
key: `${repo.id}#fullreview-${cycle}-${role}`,
|
|
@@ -177,7 +211,7 @@ export async function sweepRepo(
|
|
|
177
211
|
reason: `scheduled ${repo.policy.actions.fullReview} full review (joint, ${role} section)`,
|
|
178
212
|
context: [
|
|
179
213
|
`Perform the ${role} section of a joint full-repository review of ${repo.id}.`,
|
|
180
|
-
`Your focus: ${
|
|
214
|
+
`Your focus: ${section.focus}.`,
|
|
181
215
|
"Other roles cover complementary areas in parallel - do NOT duplicate their scope; go deep on yours.",
|
|
182
216
|
"Your reply becomes the " + role + " section of the joint review issue on GitHub. Do not change code.",
|
|
183
217
|
].join("\n"),
|