@saadnvd1/agent-os 0.3.662 → 0.3.671

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 (122) hide show
  1. package/app/api/audits/[kind]/[id]/route.test.ts +2 -2
  2. package/app/api/mcp-auth/callback/route.test.ts +42 -0
  3. package/app/api/mcp-auth/callback/route.ts +56 -0
  4. package/app/api/projects/init/route.test.ts +2 -4
  5. package/app/api/sessions/[id]/mcp-auth/route.test.ts +86 -0
  6. package/app/api/sessions/[id]/mcp-auth/route.ts +58 -0
  7. package/app/api/sessions/[id]/route.ts +3 -3
  8. package/app/api/shares/route.test.ts +3 -4
  9. package/app/api/workspaces/[id]/route.ts +9 -1
  10. package/app/api/worktree-sweep/route.test.ts +40 -1
  11. package/app/api/worktree-sweep/route.ts +45 -6
  12. package/components/Chat/ChatPanel.tsx +6 -3
  13. package/components/Chat/McpServers.tsx +61 -24
  14. package/components/Chat/McpSignIn.tsx +122 -0
  15. package/components/Chat/session.ts +8 -0
  16. package/components/Health/SweepRuns.tsx +77 -1
  17. package/components/Workspaces/WorkspaceSettings.tsx +6 -0
  18. package/data/chat/mcpAuth.ts +42 -0
  19. package/data/workspaces/index.ts +6 -0
  20. package/data/worktree-sweep/index.ts +15 -0
  21. package/lib/agentos-home.ts +11 -0
  22. package/lib/agents/launch.ts +3 -7
  23. package/lib/artifacts/store.ts +2 -5
  24. package/lib/chat/driver.ts +24 -2
  25. package/lib/chat/drivers/claude-approvals.ts +7 -0
  26. package/lib/chat/drivers/claude-mcp-auth.ts +82 -0
  27. package/lib/chat/drivers/claude.ts +7 -0
  28. package/lib/chat/drivers/pi-approvals.ts +2 -2
  29. package/lib/chat/events.ts +12 -0
  30. package/lib/chat/mcp-auth.ts +193 -0
  31. package/lib/chat/registry.ts +2 -0
  32. package/lib/chat/runner.ts +18 -0
  33. package/lib/chat/worker/client.ts +35 -1
  34. package/lib/chat/worker/host.ts +9 -0
  35. package/lib/chat/worker/main.ts +1 -1
  36. package/lib/chat/worker/mcp-auth.ts +119 -0
  37. package/lib/chat/worker/protocol.ts +21 -2
  38. package/lib/connect/config.ts +2 -3
  39. package/lib/db/backup.ts +2 -2
  40. package/lib/db/migrations/20261018T1600_health_boot_deploys.ts +13 -0
  41. package/lib/db/migrations/20261018T1730_mcp_sign_ins.ts +22 -0
  42. package/lib/db/migrations/20261018T2100_orch_full_access.ts +16 -0
  43. package/lib/db/types.ts +3 -0
  44. package/lib/dev-instance/processInfo.ts +48 -27
  45. package/lib/dev-instance/startDevServer.ts +1 -1
  46. package/lib/dev-instance/stopDevServer.ts +20 -17
  47. package/lib/dev-servers.ts +2 -1
  48. package/lib/done/index.ts +2 -2
  49. package/lib/done/testing.ts +2 -2
  50. package/lib/env-setup.ts +8 -1
  51. package/lib/health/boots.ts +31 -0
  52. package/lib/health/ci.ts +23 -2
  53. package/lib/health/detectors.ts +2 -1
  54. package/lib/health/evidence.ts +1 -1
  55. package/lib/health/facts.ts +3 -3
  56. package/lib/health/fixtures.ts +1 -0
  57. package/lib/health/tick.ts +6 -1
  58. package/lib/health/types.ts +2 -0
  59. package/lib/orchestrator/armed.test-helpers.ts +3 -2
  60. package/lib/orchestrator/brief.ts +14 -9
  61. package/lib/orchestrator/external-gates.ts +62 -1
  62. package/lib/orchestrator/full-access.ts +21 -0
  63. package/lib/orchestrator/home.ts +2 -5
  64. package/lib/orchestrator/quick.ts +47 -4
  65. package/lib/orchestrator/serve.ts +11 -2
  66. package/lib/orchestrator/shell-guard.ts +24 -0
  67. package/lib/orchestrator/signoff.test-helpers.ts +3 -2
  68. package/lib/orchestrator/sweep-arm.ts +180 -0
  69. package/lib/orchestrator/tool-names.ts +4 -1
  70. package/lib/orchestrator/tool-schemas.ts +33 -1
  71. package/lib/orchestrator/tools.ts +6 -2
  72. package/lib/orchestrator/write-guard.ts +37 -9
  73. package/lib/plans/features.ts +2 -2
  74. package/lib/program-status/claude-hooks.ts +2 -2
  75. package/lib/program-status/tap.ts +2 -2
  76. package/lib/project-config/brief.ts +3 -1
  77. package/lib/project-config/database.ts +77 -16
  78. package/lib/project-config/index.ts +108 -21
  79. package/lib/project-config/schema.ts +10 -4
  80. package/lib/project-config/session.ts +27 -6
  81. package/lib/security/net.ts +7 -4
  82. package/lib/security/tailnet-https.ts +2 -2
  83. package/lib/session-artifacts/collect.ts +18 -1
  84. package/lib/session-artifacts/keep.ts +2 -4
  85. package/lib/session-audit/store.ts +2 -5
  86. package/lib/session-logs/folder.ts +2 -3
  87. package/lib/sessions/launch.ts +2 -2
  88. package/lib/sessions/leftovers.ts +61 -0
  89. package/lib/simulator/agent-device.ts +2 -2
  90. package/lib/tasks/finish.ts +2 -2
  91. package/lib/tasks/import.ts +3 -5
  92. package/lib/tasks/move-testing.ts +2 -2
  93. package/lib/tasks/move.ts +2 -2
  94. package/lib/tasks/moved-away.ts +2 -0
  95. package/lib/tasks/state.ts +7 -3
  96. package/lib/tasks/ui-brief.ts +2 -2
  97. package/lib/test-temp.ts +30 -0
  98. package/lib/workspaces.ts +6 -2
  99. package/lib/worktree-deps/fastcopy.ts +2 -2
  100. package/lib/worktree-deps/spare.ts +2 -2
  101. package/lib/worktree-sweep/caches.ts +129 -0
  102. package/lib/worktree-sweep/databases.ts +222 -0
  103. package/lib/worktree-sweep/du.ts +13 -0
  104. package/lib/worktree-sweep/extras.ts +196 -0
  105. package/lib/worktree-sweep/findOrphans.ts +19 -8
  106. package/lib/worktree-sweep/report.ts +86 -0
  107. package/lib/worktree-sweep/runSweep.ts +46 -13
  108. package/lib/worktree-sweep/settings.ts +24 -0
  109. package/lib/worktree-sweep/state.ts +5 -0
  110. package/lib/worktree-sweep/store.ts +11 -0
  111. package/lib/worktree-sweep/testTemp.ts +113 -0
  112. package/lib/worktree-sweep/types.ts +46 -1
  113. package/lib/worktrees.ts +3 -0
  114. package/package.json +2 -1
  115. package/scripts/autodeploy.test.ts +2 -2
  116. package/scripts/check-bundle.test.ts +2 -2
  117. package/scripts/disk-dry-run.ts +57 -0
  118. package/scripts/hooks/banned-terms.test.ts +3 -2
  119. package/scripts/hooks/staged-secrets.test.ts +2 -2
  120. package/scripts/lib/build-swap.test.ts +2 -3
  121. package/scripts/lib/wsl.test.ts +2 -3
  122. package/scripts/update-run.test.ts +2 -2
@@ -14,6 +14,7 @@ import { git } from "../git-exec";
14
14
  import { PLAN_FILE } from "../models/plan-step";
15
15
  import { listArtifacts } from "../artifacts/store";
16
16
  import { allowedRoots, within } from "./access";
17
+ import { SCREENSHOT_DIR } from "../tasks/ui-brief";
17
18
  import {
18
19
  fromItems,
19
20
  fromPr,
@@ -293,6 +294,20 @@ export async function collectArtifacts(
293
294
 
294
295
  export const cachedCount = () => cache.size;
295
296
 
297
+ // What the UI brief has a terminal session save, whether or not a chat tool
298
+ // call named it: the PR names these files and the worktree is about to go.
299
+ export function screenshotsIn(worktree: string): string[] {
300
+ const dir = path.join(worktree, SCREENSHOT_DIR);
301
+ try {
302
+ return fs
303
+ .readdirSync(dir)
304
+ .filter((f) => /\.(png|jpe?g|webp)$/i.test(f))
305
+ .map((f) => path.join(dir, f));
306
+ } catch {
307
+ return [];
308
+ }
309
+ }
310
+
296
311
  /**
297
312
  * Before a session's worktree is removed: copy what it made there that git
298
313
  * doesn't hold. Never throws, and never holds up the removal for long.
@@ -309,7 +324,9 @@ export async function keepSessionFiles(sessionId: string): Promise<void> {
309
324
  const files = entries
310
325
  .map((e) => e.read)
311
326
  .filter((f): f is string => !!f && !!relInside(worktree, f));
312
- await keepFiles(sessionId, worktree, files);
327
+ await keepFiles(sessionId, worktree, [
328
+ ...new Set([...files, ...screenshotsIn(worktree)]),
329
+ ]);
313
330
  } catch (error) {
314
331
  console.error(`[session-artifacts] keeping ${sessionId}:`, error);
315
332
  } finally {
@@ -5,8 +5,8 @@
5
5
  * copy; the manifest records them so the view can say "in the PR".
6
6
  */
7
7
 
8
+ import { agentosHome } from "../agentos-home";
8
9
  import fs from "fs";
9
- import os from "os";
10
10
  import path from "path";
11
11
  import { git } from "../git-exec";
12
12
  import { isSecretPath } from "../secret-paths";
@@ -23,9 +23,7 @@ export interface Manifest {
23
23
  }
24
24
 
25
25
  export function keptDir(): string {
26
- return (
27
- process.env.AGENTOS_KEPT_DIR || path.join(os.homedir(), ".agent-os", "kept")
28
- );
26
+ return process.env.AGENTOS_KEPT_DIR || agentosHome("kept");
29
27
  }
30
28
 
31
29
  const safeId = (sessionId: string) => sessionId.replace(/[^\w-]/g, "_");
@@ -8,8 +8,8 @@
8
8
  * one before.
9
9
  */
10
10
 
11
+ import { agentosHome } from "../agentos-home";
11
12
  import fs from "fs";
12
- import os from "os";
13
13
  import path from "path";
14
14
  import type { Summary } from "./aggregate";
15
15
 
@@ -19,10 +19,7 @@ export const AUDIT_NAME = /^[a-z0-9][a-z0-9-]{0,80}$/;
19
19
  export const SESSIONS_KIND = "sessions";
20
20
 
21
21
  export function auditsRoot(): string {
22
- return (
23
- process.env.AGENTOS_AUDITS_DIR ||
24
- path.join(os.homedir(), ".agent-os", "audits")
25
- );
22
+ return process.env.AGENTOS_AUDITS_DIR || agentosHome("audits");
26
23
  }
27
24
 
28
25
  export function auditsDir(): string {
@@ -6,8 +6,8 @@
6
6
  * can be public, and a log holds briefs and reviews.
7
7
  */
8
8
 
9
+ import { agentosHome } from "../agentos-home";
9
10
  import fs from "fs";
10
- import os from "os";
11
11
  import path from "path";
12
12
  import { db } from "../db";
13
13
  import { slugify } from "../git";
@@ -17,8 +17,7 @@ import { expand, repoPaths, resolved, within } from "./paths";
17
17
 
18
18
  // AGENTOS_SESSION_LOGS_DIR moves the default (tests keep it off the real one).
19
19
  export const DEFAULT_ROOT = () =>
20
- process.env.AGENTOS_SESSION_LOGS_DIR ||
21
- path.join(os.homedir(), ".agent-os", "session-logs");
20
+ process.env.AGENTOS_SESSION_LOGS_DIR || agentosHome("session-logs");
22
21
 
23
22
  const key = (projectId: string) => `session-logs.folder.${projectId}`;
24
23
 
@@ -3,10 +3,10 @@
3
3
  * then (for a worktree) the setup in the background, then the first message.
4
4
  */
5
5
 
6
+ import { agentosHome } from "../agentos-home";
6
7
  import type { StartVia } from "../tasks/starter";
7
8
  import fs from "fs";
8
9
  import os from "os";
9
- import path from "path";
10
10
  import { randomUUID } from "crypto";
11
11
  import { db, queries, type Session } from "../db";
12
12
  import type { AgentType } from "../providers";
@@ -45,7 +45,7 @@ export const DEFAULT_START_VIEW: StartView = "chat";
45
45
  export const startView = (v: unknown): StartView | undefined =>
46
46
  v === "chat" || v === "terminal" ? v : undefined;
47
47
 
48
- export const SCRATCH_DIR = path.join(os.homedir(), ".agent-os", "scratch");
48
+ export const SCRATCH_DIR = agentosHome("scratch");
49
49
 
50
50
  export interface LaunchInput {
51
51
  // The client's key for this start (a draft's id): it becomes the
@@ -0,0 +1,61 @@
1
+ /**
2
+ * What a task leaves outside its checkout, released when it ends (merge,
3
+ * drop, done, move, delete): its dev server, its private database and what
4
+ * the project derived from it, and its temp folder. The worktree itself is
5
+ * removed by the caller, which knows whether anything in it would be lost.
6
+ */
7
+
8
+ import fs from "fs";
9
+ import os from "os";
10
+ import path from "path";
11
+ import { stopDevServer } from "../dev-instance/stopDevServer";
12
+ import { dropSessionDatabase } from "../project-config/database";
13
+
14
+ export const SESSION_TMP_PREFIX = "agentos-s-";
15
+
16
+ // The whole id: a shortened one could name two sessions' folders alike.
17
+ export const tmpName = (sessionId: string) => sessionId.replace(/[^\w-]/g, "");
18
+
19
+ export const sessionTmpDir = (sessionId: string) =>
20
+ path.join(os.tmpdir(), `${SESSION_TMP_PREFIX}${tmpName(sessionId)}`);
21
+
22
+ export interface LeftoverDeps {
23
+ stopDev: (worktree: string) => Promise<unknown>;
24
+ dropDatabase: (sessionId: string) => Promise<void>;
25
+ removeDir: (dir: string) => Promise<void>;
26
+ }
27
+
28
+ const realDeps: LeftoverDeps = {
29
+ stopDev: (worktree) => stopDevServer(worktree),
30
+ dropDatabase: dropSessionDatabase,
31
+ removeDir: (dir) => fs.promises.rm(dir, { recursive: true, force: true }),
32
+ };
33
+
34
+ /**
35
+ * Never throws and never waits on a step that can't be reached: each is
36
+ * tried on its own. Callers read the session row first and don't await this.
37
+ */
38
+ export async function releaseSessionLeftovers(
39
+ session: { id: string; worktree_path?: string | null },
40
+ deps: Partial<LeftoverDeps> = {}
41
+ ): Promise<void> {
42
+ const d = { ...realDeps, ...deps };
43
+ const steps: Array<[string, () => Promise<unknown>]> = [
44
+ // First: its row is read before the caller deletes it.
45
+ ["database", () => d.dropDatabase(session.id)],
46
+ [
47
+ "dev server",
48
+ async () => {
49
+ if (session.worktree_path) await d.stopDev(session.worktree_path);
50
+ },
51
+ ],
52
+ ["temp folder", () => d.removeDir(sessionTmpDir(session.id))],
53
+ ];
54
+ for (const [what, step] of steps) {
55
+ try {
56
+ await step();
57
+ } catch (error) {
58
+ console.error(`[leftovers] ${what} for ${session.id}:`, error);
59
+ }
60
+ }
61
+ }
@@ -5,9 +5,9 @@
5
5
  * here, so it can only drive its own simulator.
6
6
  */
7
7
 
8
+ import { agentosHome } from "../agentos-home";
8
9
  import { execFile } from "child_process";
9
10
  import fs from "fs";
10
- import os from "os";
11
11
  import path from "path";
12
12
  import { promisify } from "util";
13
13
 
@@ -15,7 +15,7 @@ const execFileAsync = promisify(execFile);
15
15
 
16
16
  export const AGENT_DEVICE_VERSION = "0.21.27";
17
17
 
18
- const root = () => path.join(os.homedir(), ".agent-os");
18
+ const root = () => agentosHome();
19
19
  export const toolDir = () =>
20
20
  path.join(root(), "tools", `agent-device-${AGENT_DEVICE_VERSION}`);
21
21
  export const toolBin = () =>
@@ -34,7 +34,7 @@ import {
34
34
  prFor,
35
35
  projectPathFor,
36
36
  } from "./session";
37
- import { dropSessionDatabase } from "../project-config/database";
37
+ import { releaseSessionLeftovers } from "../sessions/leftovers";
38
38
  import { captureMergedTask } from "../session-logs";
39
39
  import { sessionEnded } from "../experiments/hooks";
40
40
  import { snapshotWorktree } from "../resurrect/snapshot";
@@ -62,7 +62,7 @@ async function cleanup(
62
62
  const keepRemoteBranch = opts.keepRemoteBranch ?? false;
63
63
  await endSessionAgent(session);
64
64
  // Never waited on: the row is read now, and Postgres can't hold this up.
65
- void dropSessionDatabase(session.id);
65
+ void releaseSessionLeftovers(session);
66
66
  if (session.worktree_path && opts.merged) {
67
67
  const fate = await settleWorktree(session, opts.merged).catch(() => null);
68
68
  if (fate?.action === "kept")
@@ -5,6 +5,7 @@
5
5
  * again returns the task it made the first time.
6
6
  */
7
7
 
8
+ import { releaseSessionLeftovers } from "../sessions/leftovers";
8
9
  import fs from "fs";
9
10
  import os from "os";
10
11
  import path from "path";
@@ -13,10 +14,7 @@ import { db, queries, type Session } from "../db";
13
14
  import { setupWorktree } from "../env-setup";
14
15
  import { allocatePorts } from "../ports";
15
16
  import { loadProjectConfig, portBases } from "../project-config";
16
- import {
17
- dropSessionDatabase,
18
- ensureSessionDatabase,
19
- } from "../project-config/database";
17
+ import { ensureSessionDatabase } from "../project-config/database";
20
18
  import { runInBackground } from "../async-operations";
21
19
  import { launchClaude } from "../agents/launch";
22
20
  import { resolveModelForAgent } from "../model-catalog";
@@ -238,7 +236,7 @@ async function arrive(
238
236
  } catch (err) {
239
237
  // Nothing runs here, so the source may resume it: leave no row behind,
240
238
  // and no database (the drop reads the row before it goes).
241
- void dropSessionDatabase(id);
239
+ void releaseSessionLeftovers({ id });
242
240
  if (bundle.chat) {
243
241
  stopChat(id);
244
242
  dropChat(id);
@@ -3,13 +3,13 @@
3
3
  // Tests mock ../worktrees (WORKTREES_DIR), ../env-setup and ../agents/launch.
4
4
 
5
5
  import fs from "fs";
6
- import os from "os";
7
6
  import path from "path";
8
7
  import { randomUUID } from "crypto";
9
8
  import { db, insertSessionRow, type Session } from "../db";
10
9
  import { createProject } from "../projects";
11
10
  import { writeTranscript } from "./transcript";
12
11
  import { gitSync } from "../git-exec";
12
+ import { tempDir } from "@/lib/test-temp";
13
13
 
14
14
  export const CLAUDE_ID = "11111111-2222-3333-4444-555555555555";
15
15
 
@@ -30,7 +30,7 @@ export interface MoveFixture {
30
30
  /** HOME, Claude's folder and git identity all point into a temp dir. */
31
31
  export function setupMoveRepo(): MoveFixture {
32
32
  const saved = { HOME: process.env.HOME };
33
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "aos-move-"));
33
+ const tmp = tempDir("aos-move-");
34
34
  process.env.HOME = tmp;
35
35
  process.env.CLAUDE_CONFIG_DIR = path.join(tmp, ".claude");
36
36
  for (const who of ["AUTHOR", "COMMITTER"]) {
package/lib/tasks/move.ts CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  } from "./move-bundle";
27
27
  import { stepProgress } from "./move-progress";
28
28
  import { PLAN_FILE } from "../models/plan-step";
29
- import { dropSessionDatabase } from "../project-config/database";
29
+ import { releaseSessionLeftovers } from "../sessions/leftovers";
30
30
  import { releaseChat } from "../chat/runner";
31
31
  import { collectWhileMoving } from "../chat/hold";
32
32
  import { packChat, stopChatForMove } from "./move-chat";
@@ -258,7 +258,7 @@ export function markMoved(id: string, to: string): void {
258
258
  { task_status: ["running", "moving"] }
259
259
  );
260
260
  // It goes on there with a copy of its own.
261
- if (moved) void dropSessionDatabase(id);
261
+ if (moved) void releaseSessionLeftovers({ id });
262
262
  }
263
263
 
264
264
  /**
@@ -5,6 +5,7 @@
5
5
  * no commit a remote lacks). The row stays, archived, as history.
6
6
  */
7
7
 
8
+ import { releaseSessionLeftovers } from "../sessions/leftovers";
8
9
  import { db, type Session } from "../db";
9
10
  import { endSessionAgent } from "../sessions/end";
10
11
  import { releasePorts } from "../ports";
@@ -28,6 +29,7 @@ export async function cleanUpMovedAway(id: string): Promise<WorktreeFate> {
28
29
  path: s.worktree_path ?? "",
29
30
  })
30
31
  );
32
+ void releaseSessionLeftovers(s);
31
33
  archiveSession(id);
32
34
  if (fate.action === "kept")
33
35
  console.warn(
@@ -137,6 +137,10 @@ const UNFINISHED = [
137
137
  const outcome = (c: RollupEntry) =>
138
138
  (c.conclusion || c.state || c.status || "").toUpperCase();
139
139
 
140
+ // A skipped or neutral run is settled and says nothing about a rerun, so it
141
+ // never makes a check look unsettled.
142
+ const counts = (c: RollupEntry) => !["SKIPPED", "NEUTRAL"].includes(outcome(c));
143
+
140
144
  // Job names repeat across workflows, and a status context can share a check
141
145
  // run's name, so a check is its kind, workflow and name together.
142
146
  const checkKey = (c: RollupEntry) => {
@@ -198,7 +202,7 @@ const groupByCheck = <T extends RollupEntry>(rollup: T[]) => {
198
202
  // rollup can't tell one attempt from the next.
199
203
  function shownAttempts(rollup: RollupEntry[]): Map<string, number | null> {
200
204
  const shown = new Map<string, number | null>();
201
- for (const c of rollup) {
205
+ for (const c of rollup.filter(counts)) {
202
206
  const run = actionsRunOf(c);
203
207
  if (!run) continue;
204
208
  const key = `${run.repo}#${run.id}`;
@@ -226,7 +230,7 @@ export function rerunsToLookUp(
226
230
  string,
227
231
  { repo: string; id: string; attempt: string | null }
228
232
  >();
229
- for (const group of groupByCheck(rollup).values()) {
233
+ for (const group of groupByCheck(rollup.filter(counts)).values()) {
230
234
  if (group.length < 2) continue;
231
235
  for (const c of group) {
232
236
  const run = actionsRunOf(c);
@@ -259,7 +263,7 @@ export function settleReruns<T extends RollupEntry>(
259
263
  const shown = shownAttempts(rollup);
260
264
  const drop = new Set<RollupEntry>();
261
265
  const unsettled: RollupEntry[] = [];
262
- for (const group of groupByCheck(rollup).values()) {
266
+ for (const group of groupByCheck(rollup.filter(counts)).values()) {
263
267
  if (group.length < 2) continue;
264
268
  const located = group.map((c) => ({ c, run: actionsRunOf(c) }));
265
269
  // Not all GitHub Actions: nothing says which run is stale, so all count.
@@ -80,6 +80,6 @@ If your diff changes what a user sees, run the app and look at every changed scr
80
80
  - Log in and go to pages by URL, from the login, pages and map under "Running this project" when they are there. Exploring the UI to find a page is the most expensive thing a session does.
81
81
  - One snapshot to find a uid, then act. Verify with a screenshot of the one element or a small \`evaluate_script\` returning the one value you need, not another full snapshot.
82
82
  - Verify the thing that would be wrong, not the thing that is easy to see: a page that rendered proves it rendered. Fix anything visibly off (gaps, clipping, overlap, horizontal scroll, stray bands, misalignment; measure rects with \`evaluate_script\` and report numbers) and read the console for errors.
83
- - Save screenshots of the final changed screens with \`filePath\` under \`${SCREENSHOT_DIR}/\`, after \`mkdir -p ${SCREENSHOT_DIR} && printf '*\\n' > .agentos/.gitignore\`. That folder is inside the browser's allowed root and git ignores it; a path in /tmp is refused.
84
- - Add a **Browser check** section to the PR body: the pages and widths you checked, what you fixed, and the screenshot file names. If you didn't check (no visible change, or no browser), say why in one line.`;
83
+ - Save screenshots of the final changed screens with \`filePath\` under \`${SCREENSHOT_DIR}/\`, after \`mkdir -p ${SCREENSHOT_DIR} && printf '*\\n' > .agentos/.gitignore\`. That folder is inside the browser's allowed root and git ignores it; a path in /tmp is refused. AgentOS keeps these files after the worktree is removed.
84
+ - Add a **Browser check** section to the PR body: the pages and widths you checked, what you fixed, and the screenshot file names (names only, never a worktree path: the worktree is removed when the task ends). If you didn't check (no visible change, or no browser), say why in one line.`;
85
85
  }
@@ -0,0 +1,30 @@
1
+ import { mkdtempSync, rmSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+
5
+ // Folders made by tempDir, removed when the test file ends (vitest.setup.ts
6
+ // calls removeTempDirs). Kept on globalThis: vi.resetModules() would
7
+ // otherwise lose the list.
8
+ const KEY = Symbol.for("agentos.testTempDirs");
9
+ const made = (): Set<string> => {
10
+ const g = globalThis as unknown as Record<symbol, Set<string> | undefined>;
11
+ return (g[KEY] ??= new Set<string>());
12
+ };
13
+
14
+ /** A fresh temp folder that is removed when the test file ends. */
15
+ export function tempDir(prefix: string): string {
16
+ const dir = mkdtempSync(join(tmpdir(), prefix));
17
+ made().add(dir);
18
+ return dir;
19
+ }
20
+
21
+ export function removeTempDirs(): void {
22
+ for (const dir of made()) {
23
+ try {
24
+ rmSync(dir, { recursive: true, force: true, maxRetries: 5 });
25
+ } catch {
26
+ // the run root's removal is the backstop
27
+ }
28
+ }
29
+ made().clear();
30
+ }
package/lib/workspaces.ts CHANGED
@@ -8,10 +8,11 @@ import { db, type Workspace } from "./db";
8
8
 
9
9
  type WorkspaceRow = Omit<
10
10
  Workspace,
11
- "collapsed" | "wake_tasks_on_pr" | "orch_mcp_servers"
11
+ "collapsed" | "wake_tasks_on_pr" | "orch_mcp_servers" | "orch_full_access"
12
12
  > & {
13
13
  collapsed: number;
14
14
  wake_tasks_on_pr: number;
15
+ orch_full_access: number;
15
16
  orch_mcp_servers: string;
16
17
  };
17
18
 
@@ -38,6 +39,7 @@ const toWorkspace = (row: WorkspaceRow): Workspace => ({
38
39
  ...row,
39
40
  collapsed: !!row.collapsed,
40
41
  wake_tasks_on_pr: !!row.wake_tasks_on_pr,
42
+ orch_full_access: !!row.orch_full_access,
41
43
  orch_mcp_servers: parseServers(row.orch_mcp_servers),
42
44
  });
43
45
 
@@ -86,6 +88,7 @@ export function updateWorkspace(
86
88
  sortOrder?: number;
87
89
  maxRunningTasks?: number | null;
88
90
  wakeTasksOnPR?: boolean;
91
+ orchFullAccess?: boolean;
89
92
  mcpServers?: string[];
90
93
  }
91
94
  ): Workspace | null {
@@ -93,13 +96,14 @@ export function updateWorkspace(
93
96
  if (!existing) return null;
94
97
  const name = updates.name?.trim() || existing.name;
95
98
  db.prepare(
96
- `UPDATE workspaces SET name = ?, collapsed = ?, sort_order = ?, max_running_tasks = ?, wake_tasks_on_pr = ?, orch_mcp_servers = ? WHERE id = ?`
99
+ `UPDATE workspaces SET name = ?, collapsed = ?, sort_order = ?, max_running_tasks = ?, wake_tasks_on_pr = ?, orch_full_access = ?, orch_mcp_servers = ? WHERE id = ?`
97
100
  ).run(
98
101
  name,
99
102
  (updates.collapsed ?? existing.collapsed) ? 1 : 0,
100
103
  updates.sortOrder ?? existing.sort_order,
101
104
  taskLimit(updates.maxRunningTasks, existing.max_running_tasks),
102
105
  (updates.wakeTasksOnPR ?? existing.wake_tasks_on_pr) ? 1 : 0,
106
+ (updates.orchFullAccess ?? existing.orch_full_access) ? 1 : 0,
103
107
  JSON.stringify(serverNames(updates.mcpServers, existing.orch_mcp_servers)),
104
108
  id
105
109
  );
@@ -5,9 +5,9 @@
5
5
  * none works, and the caller installs or copies plainly instead.
6
6
  */
7
7
 
8
+ import { agentosHome } from "../agentos-home";
8
9
  import { execFile } from "child_process";
9
10
  import * as fs from "fs";
10
- import * as os from "os";
11
11
  import * as path from "path";
12
12
  import { promisify } from "util";
13
13
  import type { CopyMode } from "./spare";
@@ -18,7 +18,7 @@ export type FastMode = Exclude<CopyMode, "copy">;
18
18
 
19
19
  // Where hardlinked dependencies are kept: one real copy per lockfile, so a
20
20
  // write through a link can only ever reach this, never the main checkout.
21
- export const STORE_ROOT = path.join(os.homedir(), ".agent-os", "deps-store");
21
+ export const STORE_ROOT = agentosHome("deps-store");
22
22
 
23
23
  // Files tools rewrite in place. A hardlink would carry the write back into
24
24
  // the store, so these are real copies in every worktree.
@@ -8,13 +8,13 @@
8
8
  * one made before the dependencies changed is never taken, and is pruned.
9
9
  */
10
10
 
11
+ import { agentosHome } from "../agentos-home";
11
12
  import { createHash } from "crypto";
12
13
  import { spawn } from "child_process";
13
14
  import * as fs from "fs";
14
- import * as os from "os";
15
15
  import * as path from "path";
16
16
 
17
- export const SPARE_ROOT = path.join(os.homedir(), ".agent-os", "spare");
17
+ export const SPARE_ROOT = agentosHome("spare");
18
18
 
19
19
  // A half-built spare left by a restart is removed after this long.
20
20
  const BUILDING_TTL_MS = 30 * 60 * 1000;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * What a task leaves outside its checkout and the database: dependency
3
+ * spares nobody took, its temp folder, a crashed preview browser's profile,
4
+ * and Xcode's build folder for a worktree that no longer exists. Each is
5
+ * rebuilt or recreated on demand, so the only rule is "old enough, and not
6
+ * in use".
7
+ */
8
+
9
+ import fs from "fs";
10
+ import path from "path";
11
+ import { execFile } from "child_process";
12
+ import { SESSION_TMP_PREFIX, tmpName } from "../sessions/leftovers";
13
+ import { isTestTempName } from "./testTemp";
14
+ import type { Candidate, SweepSkipped } from "./types";
15
+
16
+ const DAY_MS = 24 * 3600_000;
17
+ const SPARE_MIN_AGE_MS = 7 * DAY_MS;
18
+ const BUILDING_MIN_AGE_MS = 3600_000;
19
+
20
+ export interface CacheDeps {
21
+ now: number;
22
+ spareRoot: string;
23
+ tmpRoot: string;
24
+ derivedRoot: string;
25
+ worktreesRoot: string;
26
+ // Ids of the sessions still running on this machine.
27
+ liveIds: Set<string>;
28
+ workspaceOf: (derivedDir: string) => Promise<string | null>;
29
+ size: (dir: string) => Promise<number>;
30
+ }
31
+
32
+ export const workspaceFromPlist = (dir: string): Promise<string | null> =>
33
+ new Promise((resolve) =>
34
+ execFile(
35
+ "plutil",
36
+ [
37
+ "-extract",
38
+ "WorkspacePath",
39
+ "raw",
40
+ "-o",
41
+ "-",
42
+ path.join(dir, "info.plist"),
43
+ ],
44
+ { timeout: 10_000 },
45
+ (error, stdout) => resolve(error ? null : String(stdout).trim() || null)
46
+ )
47
+ );
48
+
49
+ const subdirs = (root: string): string[] => {
50
+ try {
51
+ return fs
52
+ .readdirSync(root, { withFileTypes: true })
53
+ .filter((e) => e.isDirectory())
54
+ .map((e) => path.join(root, e.name));
55
+ } catch {
56
+ return [];
57
+ }
58
+ };
59
+
60
+ const mtime = (p: string) => {
61
+ try {
62
+ return fs.statSync(p).mtimeMs;
63
+ } catch {
64
+ return 0;
65
+ }
66
+ };
67
+
68
+ const inside = (root: string, p: string) => {
69
+ const rel = path.relative(path.resolve(root), path.resolve(p));
70
+ return !!rel && !rel.startsWith("..") && !path.isAbsolute(rel);
71
+ };
72
+
73
+ export async function findCacheLeftovers(deps: CacheDeps): Promise<{
74
+ candidates: Candidate[];
75
+ skipped: SweepSkipped[];
76
+ }> {
77
+ const candidates: Candidate[] = [];
78
+ const skipped: SweepSkipped[] = [];
79
+ const add = async (dir: string, kind: Candidate["kind"], why: string) =>
80
+ candidates.push({ path: dir, kind, why, bytes: await deps.size(dir) });
81
+
82
+ for (const dir of subdirs(deps.spareRoot)) {
83
+ const building = path.basename(dir).includes(".");
84
+ const min = building ? BUILDING_MIN_AGE_MS : SPARE_MIN_AGE_MS;
85
+ if (deps.now - mtime(dir) >= min)
86
+ await add(
87
+ dir,
88
+ "spare",
89
+ building ? "an abandoned build" : "unused for a week"
90
+ );
91
+ }
92
+
93
+ const livePrefixes = [...deps.liveIds].map(tmpName);
94
+ for (const dir of subdirs(deps.tmpRoot)) {
95
+ const name = path.basename(dir);
96
+ if (isTestTempName(name)) {
97
+ if (deps.now - mtime(dir) >= DAY_MS)
98
+ await add(dir, "test-temp", "left behind by a test run");
99
+ continue;
100
+ }
101
+ const isSession = name.startsWith(SESSION_TMP_PREFIX);
102
+ if (!isSession && !name.startsWith("agentos-preview-")) continue;
103
+ if (deps.now - mtime(dir) < DAY_MS) continue;
104
+ if (
105
+ isSession &&
106
+ livePrefixes.includes(name.slice(SESSION_TMP_PREFIX.length))
107
+ ) {
108
+ skipped.push({
109
+ path: dir,
110
+ kind: "temp",
111
+ reason: "its session is running",
112
+ });
113
+ continue;
114
+ }
115
+ await add(
116
+ dir,
117
+ "temp",
118
+ isSession ? "its task is over" : "a preview browser's profile"
119
+ );
120
+ }
121
+
122
+ for (const dir of subdirs(deps.derivedRoot)) {
123
+ const workspace = await deps.workspaceOf(dir);
124
+ if (!workspace || !inside(deps.worktreesRoot, workspace)) continue;
125
+ if (fs.existsSync(workspace)) continue;
126
+ await add(dir, "derived-data", "its worktree is gone");
127
+ }
128
+ return { candidates, skipped };
129
+ }