@teamclaws/teamclaw 2026.11.6 → 2026.11.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +17 -11
  2. package/dist/src/config.js +3 -3
  3. package/dist/src/controller/http-server.js +18 -6
  4. package/dist/src/controller/managed-gateway-process.js +17 -1
  5. package/dist/src/controller/preview-proxy.js +55 -8
  6. package/dist/src/controller/provisioning/process-supervisor.js +11 -0
  7. package/dist/src/controller/route-table.js +2 -2
  8. package/dist/src/controller/security.js +85 -17
  9. package/dist/src/controller/task-assignment.js +62 -1
  10. package/dist/src/controller/task-routes.js +39 -2
  11. package/dist/src/controller/tunnel-manager.js +11 -0
  12. package/dist/src/controller/tunnel-routes.js +11 -0
  13. package/dist/src/controller/workspace-routes.js +16 -2
  14. package/dist/src/teamauto/github-client.js +19 -0
  15. package/dist/src/teamauto/repo-sync.js +96 -22
  16. package/dist/src/teamauto/scheduler.js +458 -36
  17. package/dist/src/teamauto/store.js +125 -3
  18. package/dist/src/types.js +5 -3
  19. package/dist/src/ui/app.js +2 -2
  20. package/dist/src/worker/worker-service.js +13 -1
  21. package/dist/src/workspace-browser.js +14 -0
  22. package/openclaw.plugin.json +5 -5
  23. package/package.json +4 -2
  24. package/src/config.ts +3 -3
  25. package/src/controller/http-server.ts +19 -5
  26. package/src/controller/managed-gateway-process.ts +17 -1
  27. package/src/controller/preview-proxy.ts +54 -8
  28. package/src/controller/provisioning/process-supervisor.ts +11 -0
  29. package/src/controller/route-table.ts +2 -2
  30. package/src/controller/security.ts +90 -17
  31. package/src/controller/task-assignment.ts +58 -1
  32. package/src/controller/task-routes.ts +39 -1
  33. package/src/controller/tunnel-manager.ts +12 -1
  34. package/src/controller/tunnel-routes.ts +11 -0
  35. package/src/controller/workspace-routes.ts +17 -2
  36. package/src/teamauto/github-client.ts +21 -1
  37. package/src/teamauto/repo-sync.ts +85 -21
  38. package/src/teamauto/scheduler.ts +434 -33
  39. package/src/teamauto/store.ts +133 -3
  40. package/src/types.ts +9 -7
  41. package/src/ui/app.js +2 -2
  42. package/src/worker/worker-service.ts +15 -1
  43. package/src/workspace-browser.ts +15 -0
@@ -19,6 +19,8 @@ function workspaceRequestErrorStatus(err) {
19
19
  function workspaceRequestErrorMessage(err) {
20
20
  return err instanceof Error ? err.message : "Workspace request failed";
21
21
  }
22
+ // Active content the raw route must sandbox on direct navigation (finding 6).
23
+ const ACTIVE_CONTENT_TYPES = new Set(["text/html; charset=utf-8", "image/svg+xml"]);
22
24
  function workspaceStatusRoute(ctx) {
23
25
  const { res } = ctx;
24
26
  sendJson(res, 200, {
@@ -181,7 +183,15 @@ async function workspaceRawFileRoute(ctx) {
181
183
  try {
182
184
  const relativePath = decodeURIComponent(rawPathname);
183
185
  const file = await readWorkspaceRawFile(relativePath);
184
- res.writeHead(200, {
186
+ // ClawHub security review 2026.11.6 (finding 6): HTML/SVG served with
187
+ // their active MIME type under the controller origin execute with the
188
+ // owner's session on DIRECT navigation (the preview iframe's sandbox
189
+ // attribute does not travel with the "Open Raw" link). A response-level
190
+ // CSP sandbox without allow-same-origin gives the document an opaque
191
+ // origin even on top-level navigation: scripts may run (the preview
192
+ // already allows that) but cannot read controller cookies or call
193
+ // /api/v1/* same-origin. Mirrors the iframe flags byte for byte.
194
+ const headers = {
185
195
  "Content-Type": file.contentType,
186
196
  "Cache-Control": "no-store",
187
197
  // Issue #23 security review follow-up: honor a CORS origin the
@@ -190,7 +200,11 @@ async function workspaceRawFileRoute(ctx) {
190
200
  // historical "*" byte for byte (shared helper, see protocol.ts).
191
201
  "Access-Control-Allow-Origin": pinnedCorsAllowOrigin(res),
192
202
  "X-Content-Type-Options": "nosniff",
193
- });
203
+ };
204
+ if (ACTIVE_CONTENT_TYPES.has(file.contentType)) {
205
+ headers["Content-Security-Policy"] = "sandbox allow-scripts allow-forms";
206
+ }
207
+ res.writeHead(200, headers);
194
208
  res.end(file.content);
195
209
  }
196
210
  catch (err) {
@@ -160,6 +160,24 @@ export function createGithubClient(auth) {
160
160
  };
161
161
  });
162
162
  },
163
+ /** #5785: PRs (any state) whose head is exactly this branch - the
164
+ * PR-face evidence surface. The settle audit asks "did this WRITE task's
165
+ * PR ever come into existence", which no comment surface can answer (an
166
+ * issue direct-post masks the missing PR). Mirrors the sentinel's
167
+ * pulls?head= REST probe. */
168
+ async listPullsByHead(owner, repo, branch) {
169
+ const { data } = await request("GET", `/repos/${owner}/${repo}/pulls?head=${encodeURIComponent(`${owner}:${branch}`)}&state=all&per_page=10`);
170
+ if (!Array.isArray(data)) {
171
+ return [];
172
+ }
173
+ return data
174
+ .map((raw) => ({
175
+ number: Number(raw.number ?? 0),
176
+ state: String(raw.state ?? ""),
177
+ htmlUrl: String(raw.html_url ?? ""),
178
+ }))
179
+ .filter((p) => p.number > 0);
180
+ },
163
181
  async listCommits(owner, repo, sinceSha) {
164
182
  const suffix = sinceSha ? `?sha=${encodeURIComponent(sinceSha)}` : "?per_page=20";
165
183
  void suffix;
@@ -246,6 +264,7 @@ export function createGithubClient(auth) {
246
264
  return data.map((c) => ({
247
265
  user: String(c.user?.login ?? ""),
248
266
  createdAt: String(c.created_at ?? ""),
267
+ body: String(c.body ?? ""),
249
268
  })).filter((c) => c.user);
250
269
  }
251
270
  catch {
@@ -118,16 +118,51 @@ export function createRepoSync(auth, logger) {
118
118
  async function createWorkBranch(dir, name) {
119
119
  await run(["checkout", "-B", name], dir);
120
120
  }
121
+ /** #5815: deliverable must mean commits beyond the REMOTE base tip. A
122
+ * stale local baseline makes a zero-commit branch look deliverable; the
123
+ * PR then 422s (zero diff) deterministically six times. */
124
+ async function branchHasCommits(dir, defaultBranch, cloneUrl) {
125
+ if (!defaultBranch)
126
+ return false;
127
+ try {
128
+ if (cloneUrl) {
129
+ const authed = await tokenizedUrl(cloneUrl);
130
+ await run(["fetch", authed, defaultBranch], dir).catch(() => { });
131
+ }
132
+ else {
133
+ await run(["fetch", "origin", defaultBranch], dir).catch(() => { });
134
+ }
135
+ const out = await run(["rev-list", "--count", `origin/${defaultBranch}..HEAD`], dir);
136
+ return Number(out.trim()) > 0;
137
+ }
138
+ catch {
139
+ return false;
140
+ }
141
+ }
142
+ /** #5815: is the branch an ancestor of the remote base (zero-diff shape)? */
143
+ async function branchIsAncestorOfRemoteBase(dir, branch, defaultBranch) {
144
+ await run(["fetch", "origin", defaultBranch], dir).catch(() => { });
145
+ const head = (await run(["rev-parse", `origin/${branch}`], dir).catch(() => "")).trim();
146
+ const base = (await run(["rev-parse", `origin/${defaultBranch}`], dir).catch(() => "")).trim();
147
+ if (!head || !base)
148
+ return false;
149
+ return run(["merge-base", "--is-ancestor", head, base], dir).then(() => true, () => false);
150
+ }
151
+ /** #5788: does the branch exist on the remote? (422 disambiguation probe) */
152
+ async function branchExistsRemotely(dir, branch) {
153
+ const out = await run(["ls-remote", "origin", `refs/heads/${branch}`], dir).catch(() => "");
154
+ return out.trim().length > 0;
155
+ }
121
156
  async function commitAll(dir, message, authorName, authorEmail) {
122
157
  const status = await run(["status", "--porcelain"], dir);
123
158
  if (!status.trim()) {
124
159
  return false;
125
160
  }
126
161
  await run(["add", "-A"], dir);
127
- await run(["-c", `user.name=${authorName}`, "-c", `user.email=${authorEmail}`, "commit", "-m", message], dir);
162
+ await run(["-c", `user.name=${authorName}`, "-c", `user.email=${authorEmail}`, "-c", "core.hooksPath=", "commit", "-m", message], dir);
128
163
  return true;
129
164
  }
130
- async function pushBranch(repoId, dir, cloneUrl, branch) {
165
+ async function pushBranch(repoId, dir, cloneUrl, branch, onPushError) {
131
166
  const authed = await tokenizedUrl(cloneUrl);
132
167
  // #stale-base follow-up: the remote task branch may ALREADY carry the
133
168
  // delivery (previous incarnation pushed it; the PR got merged). Blindly
@@ -150,11 +185,32 @@ export function createRepoSync(auth, logger) {
150
185
  catch { /* branch absent remotely or fetch failed - plain push below */ }
151
186
  try {
152
187
  await run(["push", authed, `HEAD:refs/heads/${branch}`], dir);
188
+ // #5788: verify the push LANDED - a "successful" push whose ref is
189
+ // missing remotely (auth edge, proxy quirk) strands the branch exactly
190
+ // like a failed one, and createPR would 422 on the missing head.
191
+ const ls = await run(["ls-remote", authed, `refs/heads/${branch}`], dir).catch(() => "");
192
+ const localHead = (await run(["rev-parse", "HEAD"], dir)).trim();
193
+ if (ls && localHead && !ls.includes(localHead)) {
194
+ const msg = `post-push ref verification failed: remote refs/heads/${branch} does not contain local HEAD ${localHead.slice(0, 8)}`;
195
+ logger.warn(`TeamAuto: ${msg}`);
196
+ try {
197
+ onPushError?.(msg);
198
+ }
199
+ catch { /* observability only */ }
200
+ throw new Error(msg);
201
+ }
153
202
  return { alreadyDelivered: false };
154
203
  }
155
204
  catch (err) {
156
205
  const msg = err instanceof Error ? err.message : String(err);
157
206
  logger.warn(`TeamAuto: push failed for ${repoId}#${branch}: ${msg}`);
207
+ // #5788: the push leg was the ONLY delivery step with zero activity
208
+ // surface - its failure only ever showed as downstream createPR 422
209
+ // noise (two stranded self-fix legs). Surface it via the callback.
210
+ try {
211
+ onPushError?.(msg);
212
+ }
213
+ catch { /* observability only */ }
158
214
  // #5651 (ggcode, 2026-11-15): a NON-FAST-FORWARD rejection is
159
215
  // deterministic - the generic retry ladder burned 6 attempts / ~25min
160
216
  // on it twice (#5268 family). The task branch is exclusively ours, so
@@ -258,13 +314,14 @@ export function createRepoSync(auth, logger) {
258
314
  // wtName carries the teamauto/ level for the REL path; the physical dir is
259
315
  // a SIBLING of the base checkout (path.join would nest teamauto/ twice).
260
316
  const wtPath = path.join(path.dirname(base), path.basename(wtName));
261
- if (!(await fs.access(path.join(wtPath, ".git")).then(() => true, () => false))) {
317
+ const wtExists = await fs.access(path.join(wtPath, ".git")).then(() => true, () => false);
318
+ if (!wtExists) {
262
319
  // #stale-base (user report 2026-11-14): ensureCloned (fetch + reset to
263
320
  // the default-branch tip) only ran at BIND time (learnNorms), so the
264
321
  // base checkout's HEAD drifted days behind origin/main and EVERY new
265
322
  // task worktree branched from stale code. Refresh the base right
266
323
  // before creating a new branch off it - same fetch+reset as
267
- // ensureCloned. Existing worktrees (resume path) are left untouched.
324
+ // ensureCloned.
268
325
  if (defaultBranch && cloneUrl) {
269
326
  try {
270
327
  const authed = await tokenizedUrl(cloneUrl);
@@ -278,6 +335,40 @@ export function createRepoSync(auth, logger) {
278
335
  await run(["worktree", "add", "-b", taskBranchName(taskId), wtPath, "HEAD"], base);
279
336
  logger.warn(`TeamAuto: worktree ${wtName} (branch ${taskBranchName(taskId)}) for ${taskId}`);
280
337
  }
338
+ else {
339
+ // #resume-sync (user 2026-11-18): a RESUMED task (retry / review
340
+ // follow-up) used to continue on the ORIGINAL base untouched - the
341
+ // comment above explicitly left resume paths stale. On repos that
342
+ // move fast, a worktree alive for hours is guaranteed behind, all
343
+ // retried work lands on a superseded base, and the divergence only
344
+ // surfaces at push (single-shot #5651 rebase self-heal or dead
345
+ // letter). Sync BEFORE resuming: fetch the main tree, count how far
346
+ // behind this branch is, rebase when behind (dirty trees via
347
+ // autostash). Best-effort: on any failure we continue on the current
348
+ // base exactly as before - delivery-time self-heal still applies.
349
+ try {
350
+ await run(["fetch", "origin", "+refs/heads/main:refs/remotes/origin/main"], base).catch(async () => {
351
+ const db = defaultBranch || (await run(["symbolic-ref", "--short", "refs/remotes/origin/HEAD"], base).then((o) => o.trim(), () => ""));
352
+ if (db)
353
+ await run(["fetch", "origin", `+refs/heads/${db}:refs/remotes/origin/${db}`], base);
354
+ });
355
+ const behindOut = await run(["rev-list", "--count", "HEAD..origin/main"], wtPath).catch(() => "");
356
+ const behind = Number(behindOut.trim()) || 0;
357
+ if (behind > 0) {
358
+ logger.warn(`TeamAuto: resume-sync ${repoId}#${taskId}: branch is ${behind} commit(s) behind main - rebasing before work continues`);
359
+ try {
360
+ await run(["rebase", "--autostash", "origin/main"], wtPath);
361
+ }
362
+ catch (rebaseErr) {
363
+ await run(["rebase", "--abort"], wtPath).catch(() => { });
364
+ logger.warn(`TeamAuto: resume-sync rebase failed for ${repoId}#${taskId} (continuing on current base; delivery-time self-heal applies): ${rebaseErr instanceof Error ? rebaseErr.message : String(rebaseErr)}`);
365
+ }
366
+ }
367
+ }
368
+ catch (err) {
369
+ logger.warn(`TeamAuto: resume-sync skipped for ${repoId}#${taskId}: ${err instanceof Error ? err.message : String(err)}`);
370
+ }
371
+ }
281
372
  // Refresh the in-use sentinel on create AND resume (#173 follow-up 2).
282
373
  await writeTaskLock(wtPath);
283
374
  return wtPath;
@@ -487,22 +578,5 @@ export function createRepoSync(auth, logger) {
487
578
  function taskWorktreeRelDir(repoId, taskId) {
488
579
  return taskWorktreeDirName(repoId, taskId);
489
580
  }
490
- /** True when HEAD has commits beyond the base branch (worktree delivery). */
491
- async function branchHasCommits(dir, baseBranch) {
492
- try {
493
- const out = await run(["rev-list", "--count", "HEAD", "--not", baseBranch], dir);
494
- return Number(out.trim()) > 0;
495
- }
496
- catch {
497
- // Base branch name unknown/unfetched - fall back to diff against first parent chain
498
- try {
499
- const root = await run(["rev-list", "--max-parents=0", "HEAD"], dir);
500
- return root.trim().length > 0;
501
- }
502
- catch {
503
- return false;
504
- }
505
- }
506
- }
507
- return { ensureCloned, currentSha, recentCommitMessages, readFileIfPresent, safeRepoPath, createWorkBranch, commitAll, pushBranch, ensureTaskWorktree, removeTaskWorktree, safeRemoveTaskWorktree, gcTaskWorktrees, taskWorktreeRelDir, taskBranchName, branchHasCommits, repoDir };
581
+ return { ensureCloned, currentSha, recentCommitMessages, readFileIfPresent, safeRepoPath, createWorkBranch, commitAll, pushBranch, branchExistsRemotely, branchIsAncestorOfRemoteBase, ensureTaskWorktree, removeTaskWorktree, safeRemoveTaskWorktree, gcTaskWorktrees, taskWorktreeRelDir, taskBranchName, branchHasCommits, repoDir };
508
582
  }