@orgsdk/cli 2.0.1 → 2.2.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.
Files changed (71) hide show
  1. package/README.md +1 -1
  2. package/dist/runtime/client.js +19 -0
  3. package/dist/runtime/contract.js +1 -0
  4. package/dist/runtime/plugins.js +16 -4
  5. package/dist/runtime/runner.js +16 -13
  6. package/dist/runtime/shell-policy.js +31 -0
  7. package/dist/server/{bun-driver-DTZUUCI3.js → bun-driver-UOZIWBHK.js} +1 -1
  8. package/dist/server/{chunk-S5SFX3JM.js → chunk-EXZNZYIJ.js} +13 -0
  9. package/dist/server/index.js +1123 -842
  10. package/dist/server/migrations/0004_shell_executable_policy.sql +9 -0
  11. package/dist/server/migrations/meta/0004_snapshot.json +3455 -0
  12. package/dist/server/migrations/meta/_journal.json +7 -0
  13. package/dist/server/{node-driver-HDJKKWXQ.js → node-driver-75PFAG2L.js} +1 -1
  14. package/dist/server/out/_next/static/chunks/0tlox6w8yf345.css +1 -0
  15. package/dist/server/out/accounts/2fa/__next._full.txt +2 -2
  16. package/dist/server/out/accounts/2fa/__next._tree.txt +2 -2
  17. package/dist/server/out/accounts/2fa/__next.accounts.2fa.__PAGE__.txt +2 -2
  18. package/dist/server/out/accounts/2fa/index.html +1 -1
  19. package/dist/server/out/accounts/2fa/index.txt +2 -2
  20. package/dist/server/out/accounts/email/__next._full.txt +2 -2
  21. package/dist/server/out/accounts/email/__next._tree.txt +2 -2
  22. package/dist/server/out/accounts/email/__next.accounts.email.__PAGE__.txt +2 -2
  23. package/dist/server/out/accounts/email/index.html +1 -1
  24. package/dist/server/out/accounts/email/index.txt +2 -2
  25. package/dist/server/out/accounts/login/__next._full.txt +2 -2
  26. package/dist/server/out/accounts/login/__next._tree.txt +2 -2
  27. package/dist/server/out/accounts/login/__next.accounts.login.__PAGE__.txt +2 -2
  28. package/dist/server/out/accounts/login/index.html +1 -1
  29. package/dist/server/out/accounts/login/index.txt +2 -2
  30. package/dist/server/out/accounts/logout/__next._full.txt +2 -2
  31. package/dist/server/out/accounts/logout/__next._tree.txt +2 -2
  32. package/dist/server/out/accounts/logout/__next.accounts.logout.__PAGE__.txt +2 -2
  33. package/dist/server/out/accounts/logout/index.html +1 -1
  34. package/dist/server/out/accounts/logout/index.txt +2 -2
  35. package/dist/server/out/accounts/password/change/__next._full.txt +2 -2
  36. package/dist/server/out/accounts/password/change/__next._tree.txt +2 -2
  37. package/dist/server/out/accounts/password/change/__next.accounts.password.change.__PAGE__.txt +2 -2
  38. package/dist/server/out/accounts/password/change/index.html +1 -1
  39. package/dist/server/out/accounts/password/change/index.txt +2 -2
  40. package/dist/server/out/accounts/password/reset/__next._full.txt +2 -2
  41. package/dist/server/out/accounts/password/reset/__next._tree.txt +2 -2
  42. package/dist/server/out/accounts/password/reset/__next.accounts.password.reset.__PAGE__.txt +2 -2
  43. package/dist/server/out/accounts/password/reset/index.html +1 -1
  44. package/dist/server/out/accounts/password/reset/index.txt +2 -2
  45. package/dist/server/out/accounts/signup/__next._full.txt +2 -2
  46. package/dist/server/out/accounts/signup/__next._tree.txt +2 -2
  47. package/dist/server/out/accounts/signup/__next.accounts.signup.__PAGE__.txt +2 -2
  48. package/dist/server/out/accounts/signup/index.html +1 -1
  49. package/dist/server/out/accounts/signup/index.txt +2 -2
  50. package/dist/server/out/setup/__next._full.txt +2 -2
  51. package/dist/server/out/setup/__next._tree.txt +2 -2
  52. package/dist/server/out/setup/__next.setup.__PAGE__.txt +2 -2
  53. package/dist/server/out/setup/index.html +1 -1
  54. package/dist/server/out/setup/index.txt +2 -2
  55. package/dist/server/out/studio/approve/__next._full.txt +2 -2
  56. package/dist/server/out/studio/approve/__next._tree.txt +2 -2
  57. package/dist/server/out/studio/approve/__next.studio.approve.__PAGE__.txt +2 -2
  58. package/dist/server/out/studio/approve/index.html +1 -1
  59. package/dist/server/out/studio/approve/index.txt +2 -2
  60. package/dist/server/out/workspaces/invite/__next._full.txt +2 -2
  61. package/dist/server/out/workspaces/invite/__next._tree.txt +2 -2
  62. package/dist/server/out/workspaces/invite/__next.workspaces.invite.__PAGE__.txt +2 -2
  63. package/dist/server/out/workspaces/invite/index.html +1 -1
  64. package/dist/server/out/workspaces/invite/index.txt +2 -2
  65. package/docs/browser-sessions.md +1 -1
  66. package/docs/studio.md +12 -4
  67. package/package.json +1 -1
  68. package/dist/server/out/_next/static/chunks/22w_ipn94al45.css +0 -1
  69. /package/dist/server/out/_next/static/{j2chhlp57Phx_pC8UJ95w → m1cOvyKRNnDjsWBMfcCJt}/_buildManifest.js +0 -0
  70. /package/dist/server/out/_next/static/{j2chhlp57Phx_pC8UJ95w → m1cOvyKRNnDjsWBMfcCJt}/_clientMiddlewareManifest.js +0 -0
  71. /package/dist/server/out/_next/static/{j2chhlp57Phx_pC8UJ95w → m1cOvyKRNnDjsWBMfcCJt}/_ssgManifest.js +0 -0
@@ -22,6 +22,7 @@ import {
22
22
  runs,
23
23
  schedules,
24
24
  sessions,
25
+ shellRules,
25
26
  tableRows,
26
27
  users,
27
28
  webhookDeliveries,
@@ -29,7 +30,7 @@ import {
29
30
  workspaceSettings,
30
31
  workspaceTables,
31
32
  workspaces
32
- } from "./chunk-S5SFX3JM.js";
33
+ } from "./chunk-EXZNZYIJ.js";
33
34
 
34
35
  // server/platform/health.ts
35
36
  import { get } from "node:http";
@@ -362,9 +363,17 @@ var serviceErrorStatus = {
362
363
 
363
364
  // server/auth/studio.ts
364
365
  var installations = /* @__PURE__ */ new WeakMap();
366
+ function isLoopbackInstallation(endpoint) {
367
+ return ["127.0.0.1", "localhost", "[::1]"].includes(
368
+ new URL(endpoint).hostname
369
+ );
370
+ }
371
+ function studioLoginSessionId(endpoint, audience, secret) {
372
+ return "studio:" + digest(JSON.stringify([endpoint, audience, secret]));
373
+ }
365
374
  function studioAudience(endpoint) {
366
375
  const url = new URL(endpoint);
367
- const loopback2 = ["127.0.0.1", "localhost", "[::1]"].includes(url.hostname);
376
+ const loopback2 = isLoopbackInstallation(endpoint);
368
377
  const configured = process.env.ORGSDK_STUDIO_ORIGIN ?? (loopback2 ? "https://studio.orgsdk.ai" : void 0);
369
378
  if (!configured || !URL.canParse(configured)) {
370
379
  return;
@@ -724,6 +733,8 @@ var agentsSchema = z4.array(
724
733
  resources: z4.object({ tables: resourceGrant, documents: resourceGrant }).optional(),
725
734
  plugins: z4.array(
726
735
  z4.object({
736
+ shell_policy_id: z4.uuid().optional(),
737
+ digest: z4.string().optional(),
727
738
  credential_id: z4.string().nullable().optional(),
728
739
  distribution: z4.string().optional(),
729
740
  mcp: z4.object({ id: z4.uuid() }).optional()
@@ -1168,7 +1179,7 @@ import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
1168
1179
  import { ZodError as ZodError2 } from "zod";
1169
1180
 
1170
1181
  // server/api/mcp-dispatch.ts
1171
- import { z as z43 } from "zod";
1182
+ import { z as z46 } from "zod";
1172
1183
 
1173
1184
  // server/actions/schemas.ts
1174
1185
  import { z as z8 } from "zod";
@@ -1357,12 +1368,8 @@ function createContext(request, store) {
1357
1368
  const workspace2 = identities.workspaceForHost(hostname2) ?? null;
1358
1369
  const origin = request.headers.get("origin");
1359
1370
  const studioOrigin = origin && url.pathname.startsWith("/trpc/") && origin === studioAudience(url.origin) ? origin : void 0;
1360
- const grant = studioOrigin ? studioSession(
1361
- store.db,
1362
- url.origin,
1363
- studioOrigin,
1364
- request.headers.get("x-orgsdk-studio-session")
1365
- ) : void 0;
1371
+ const studioToken = request.headers.get("x-orgsdk-studio-session");
1372
+ const grant = studioOrigin ? studioSession(store.db, url.origin, studioOrigin, studioToken) : void 0;
1366
1373
  if (studioOrigin && (request.headers.has("cookie") || request.headers.has("authorization"))) {
1367
1374
  throw new ServiceError(
1368
1375
  "FORBIDDEN",
@@ -1371,7 +1378,8 @@ function createContext(request, store) {
1371
1378
  }
1372
1379
  const values2 = cookies(request);
1373
1380
  const secret = values2.get("sessionid");
1374
- const sessionId = grant?.sessionId ?? (secret ? digest(secret) : void 0);
1381
+ const localStudioId = studioOrigin && studioToken && isLoopbackInstallation(url.origin) ? studioLoginSessionId(url.origin, studioOrigin, studioToken) : void 0;
1382
+ const sessionId = grant?.sessionId ?? localStudioId ?? (secret ? digest(secret) : void 0);
1375
1383
  const session = sessionId ? identities.session(sessionId) : void 0;
1376
1384
  const validSession = session && session.expiresAt > Date.now() ? session : void 0;
1377
1385
  const authorization = request.headers.get("authorization");
@@ -1399,7 +1407,7 @@ function createContext(request, store) {
1399
1407
  clientTokenError,
1400
1408
  responseHeaders,
1401
1409
  studioOrigin,
1402
- studioExpiresAt: grant?.expiresAt,
1410
+ studioExpiresAt: grant?.expiresAt ?? (localStudioId ? validSession?.expiresAt : void 0),
1403
1411
  sessionId: validSession?.id ?? null
1404
1412
  };
1405
1413
  if (!studioOrigin && !values2.get("csrftoken")) {
@@ -1429,10 +1437,17 @@ function checkClientRequest(ctx, operationType = ctx.operationType) {
1429
1437
  import { eq as eq8 } from "drizzle-orm";
1430
1438
  function rotateSession(ctx, userId, pendingUserId = null, guard, mutation) {
1431
1439
  const secret = randomSecret();
1432
- const id = digest(secret);
1440
+ const id = ctx.studioOrigin ? studioLoginSessionId(ctx.origin, ctx.studioOrigin, secret) : digest(secret);
1433
1441
  const time = Date.now();
1442
+ const expiresAt = time + (pendingUserId ? 5 * 6e4 : 14 * 864e5);
1434
1443
  inTransaction(ctx, (ctx2) => {
1435
1444
  guard?.(ctx2);
1445
+ if (ctx2.studioOrigin && userId && (!ctx2.workspace || !identityRepository(ctx2.db).membership(ctx2.workspace.id, userId))) {
1446
+ throw new ServiceError(
1447
+ "FORBIDDEN",
1448
+ "You are not a member of this workspace."
1449
+ );
1450
+ }
1436
1451
  mutation?.(ctx2);
1437
1452
  if (ctx2.sessionId) {
1438
1453
  ctx2.db.delete(sessions).where(eq8(sessions.id, ctx2.sessionId)).run();
@@ -1442,12 +1457,16 @@ function rotateSession(ctx, userId, pendingUserId = null, guard, mutation) {
1442
1457
  userId,
1443
1458
  pendingUserId,
1444
1459
  workspaceId: ctx2.workspace?.id ?? null,
1445
- expiresAt: time + (pendingUserId ? 5 * 6e4 : 14 * 864e5),
1460
+ expiresAt,
1446
1461
  reauthenticatedAt: userId ? time : null
1447
1462
  }).run();
1448
1463
  });
1449
1464
  ctx.sessionId = id;
1450
1465
  ctx.sessionChanged(secret);
1466
+ if (ctx.studioOrigin) {
1467
+ return { token: secret, expiresAt };
1468
+ }
1469
+ return null;
1451
1470
  }
1452
1471
  function requireFresh(ctx) {
1453
1472
  requireUser(ctx);
@@ -1555,14 +1574,20 @@ var publicProcedure = rpc.procedure.use(
1555
1574
  async ({ ctx, type, path, next }) => {
1556
1575
  try {
1557
1576
  if (ctx.studioOrigin) {
1558
- const bootstrap2 = path === "studio.discover" || path === "studio.exchange";
1577
+ const localSignIn = isLoopbackInstallation(ctx.origin) && [
1578
+ "auth.setup",
1579
+ "auth.setupStatus",
1580
+ "auth.login",
1581
+ "auth.mfaAuthenticate"
1582
+ ].includes(path);
1583
+ const bootstrap2 = localSignIn || path === "studio.discover" || path === "studio.exchange";
1559
1584
  if (!bootstrap2 && (!ctx.studioExpiresAt || !ctx.sessionId || !ctx.user)) {
1560
1585
  throw new ServiceError(
1561
1586
  "UNAUTHORIZED",
1562
1587
  "Reconnect to your OrgSDK installation."
1563
1588
  );
1564
1589
  }
1565
- if (path.startsWith("auth.") && !["auth.session", "auth.browserSession", "auth.logout"].includes(path)) {
1590
+ if (!localSignIn && path.startsWith("auth.") && !["auth.session", "auth.browserSession", "auth.logout"].includes(path)) {
1566
1591
  throw new ServiceError(
1567
1592
  "FORBIDDEN",
1568
1593
  "Manage your account on the installation."
@@ -2317,7 +2342,81 @@ function findIdempotentRun(ctx, namespace, key) {
2317
2342
  }
2318
2343
 
2319
2344
  // server/runs/create.ts
2345
+ import { z as z16 } from "zod";
2346
+
2347
+ // server/plugins/shell-policy.ts
2348
+ import { and as and19, eq as eq20, gt as gt2, inArray as inArray5, sql } from "drizzle-orm";
2349
+
2350
+ // server/runs/resume-after-approval.ts
2351
+ import { and as and18, eq as eq19, notExists } from "drizzle-orm";
2352
+ function resumeAfterApproval(ctx, runId) {
2353
+ const pending = ctx.db.select({ id: approvals.id }).from(approvals).where(and18(eq19(approvals.runId, runId), eq19(approvals.status, "pending")));
2354
+ ctx.db.update(runs).set({ status: "running", updatedAt: now() }).where(
2355
+ and18(
2356
+ eq19(runs.id, runId),
2357
+ eq19(runs.status, "waiting_approval"),
2358
+ eq19(runs.cancelRequested, false),
2359
+ notExists(pending)
2360
+ )
2361
+ ).run();
2362
+ }
2363
+
2364
+ // server/plugins/shell-policy.ts
2320
2365
  import { z as z15 } from "zod";
2366
+ var executableName = z15.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.+-]{0,127}$/);
2367
+ var ruleDecision = z15.enum(["allow", "block", "ask"]);
2368
+ function supportsShellPolicy(plugin) {
2369
+ const tools2 = plugin.releaseMetadata.tools;
2370
+ return plugin.slug === "shell" && plugin.distribution === "external" && Array.isArray(tools2) && tools2.some(
2371
+ (tool) => object(tool) && tool.name === "run" && object(tool.metadata) && tool.metadata.approval === "shell-executable"
2372
+ );
2373
+ }
2374
+ function writeShellRule(ctx, plugin, executable, decision) {
2375
+ const pluginId = plugin.id;
2376
+ if (decision === "ask") {
2377
+ ctx.db.delete(shellRules).where(
2378
+ and19(
2379
+ eq20(shellRules.pluginId, pluginId),
2380
+ eq20(shellRules.executable, executable)
2381
+ )
2382
+ ).run();
2383
+ } else {
2384
+ ctx.db.insert(shellRules).values({ pluginId, executable, decision }).onConflictDoUpdate({
2385
+ target: [shellRules.pluginId, shellRules.executable],
2386
+ set: { decision }
2387
+ }).run();
2388
+ }
2389
+ if (decision !== "ask") {
2390
+ const currentTime = now();
2391
+ const liveRunIds = ctx.db.select({ id: runs.id }).from(runs).where(
2392
+ and19(
2393
+ eq20(runs.projectId, plugin.projectId),
2394
+ eq20(runs.workspaceId, plugin.workspaceId),
2395
+ eq20(runs.cancelRequested, false),
2396
+ eq20(runs.status, "waiting_approval"),
2397
+ gt2(runs.leaseExpiresAt, currentTime),
2398
+ gt2(runs.deadline, currentTime)
2399
+ )
2400
+ );
2401
+ const changed = ctx.db.update(approvals).set({
2402
+ status: decision === "allow" ? "approved" : "denied",
2403
+ decidedBy: ctx.user?.id,
2404
+ updatedAt: currentTime
2405
+ }).where(
2406
+ and19(
2407
+ eq20(approvals.workspaceId, plugin.workspaceId),
2408
+ eq20(approvals.status, "pending"),
2409
+ inArray5(approvals.runId, liveRunIds),
2410
+ sql`json_extract(${approvals.shell}, '$.pluginId') = ${plugin.id} and json_extract(${approvals.shell}, '$.digest') = ${plugin.digest} and json_extract(${approvals.shell}, '$.executable') = ${executable}`
2411
+ )
2412
+ ).returning({ id: approvals.id, runId: approvals.runId }).all();
2413
+ for (const row of changed) {
2414
+ recordAudit(ctx, "approval", row.id, "updated");
2415
+ resumeAfterApproval(ctx, row.runId);
2416
+ }
2417
+ }
2418
+ recordAudit(ctx, "shell_rule", pluginId + "/" + executable, decision);
2419
+ }
2321
2420
 
2322
2421
  // server/projects/plugin-namespace.ts
2323
2422
  function pluginNamespace(slug2) {
@@ -2407,6 +2506,7 @@ function projectConfiguration(ctx, projectId) {
2407
2506
  configuration: plugin.configuration,
2408
2507
  package_url: plugin.packageUrl,
2409
2508
  contract_version: 1,
2509
+ ...supportsShellPolicy(plugin) ? { shell_policy_id: plugin.id } : {},
2410
2510
  ...plugin.distribution === "mcp" ? { mcp: mcpSnapshot(ctx, plugin.id) } : {}
2411
2511
  }));
2412
2512
  const revision3 = digest(
@@ -2543,11 +2643,11 @@ function projectSnapshot(ctx, projectId, operation = "code") {
2543
2643
  }
2544
2644
 
2545
2645
  // server/repositories/runs.ts
2546
- import { and as and18, eq as eq19 } from "drizzle-orm";
2646
+ import { and as and20, eq as eq21 } from "drizzle-orm";
2547
2647
  function runsRepository(context) {
2548
2648
  const workspaceId = requireWorkspace(context).id;
2549
2649
  const database = context.db;
2550
- const scoped = (id) => and18(eq19(runs.workspaceId, workspaceId), eq19(runs.id, id));
2650
+ const scoped = (id) => and20(eq21(runs.workspaceId, workspaceId), eq21(runs.id, id));
2551
2651
  return {
2552
2652
  find(id) {
2553
2653
  const row = database.select().from(runs).where(scoped(id)).get();
@@ -2579,22 +2679,22 @@ function runsRepository(context) {
2579
2679
  }
2580
2680
 
2581
2681
  // server/repositories/workspace-settings.ts
2582
- import { eq as eq20 } from "drizzle-orm";
2682
+ import { eq as eq22 } from "drizzle-orm";
2583
2683
  function workspaceSettingsForWorkspace(database, workspaceId) {
2584
- return database.select().from(workspaceSettings).where(eq20(workspaceSettings.workspaceId, workspaceId)).get();
2684
+ return database.select().from(workspaceSettings).where(eq22(workspaceSettings.workspaceId, workspaceId)).get();
2585
2685
  }
2586
2686
 
2587
2687
  // server/runs/sessions.ts
2588
- import { eq as eq22 } from "drizzle-orm";
2688
+ import { eq as eq24 } from "drizzle-orm";
2589
2689
 
2590
2690
  // server/repositories/executors.ts
2591
- import { and as and19, eq as eq21 } from "drizzle-orm";
2691
+ import { and as and21, eq as eq23 } from "drizzle-orm";
2592
2692
  function executorsRepository(context) {
2593
2693
  const workspaceId = requireWorkspace(context).id;
2594
2694
  const database = context.db;
2595
- const scoped = (id, filter) => and19(
2596
- eq21(executors.workspaceId, workspaceId),
2597
- id === void 0 ? void 0 : eq21(executors.id, id),
2695
+ const scoped = (id, filter) => and21(
2696
+ eq23(executors.workspaceId, workspaceId),
2697
+ id === void 0 ? void 0 : eq23(executors.id, id),
2598
2698
  filter
2599
2699
  );
2600
2700
  return {
@@ -2629,7 +2729,7 @@ function sessionSource(command2, input2) {
2629
2729
  }
2630
2730
  function requireSessionRunner(ctx, project, executionPool) {
2631
2731
  const [runner] = executorsRepository(ctx).list(
2632
- eq22(executors.projectId, project)
2732
+ eq24(executors.projectId, project)
2633
2733
  );
2634
2734
  if (!runner?.enabled || executionPool !== void 0 && runner.pool !== executionPool || !runner.lastSeenAt || Date.parse(runner.lastSeenAt) < Date.now() - 6e4 || runner.protocolVersion < 4 || !runner.capabilities.includes("session")) {
2635
2735
  throw new ServiceError(
@@ -2720,7 +2820,7 @@ function createRunInTransaction(ctx, body) {
2720
2820
  "Schemas are only accepted for validation jobs."
2721
2821
  );
2722
2822
  }
2723
- const snapshot = z15.record(z15.string(), z15.json()).parse(projectSnapshot(ctx, project.id, operation));
2823
+ const snapshot = z16.record(z16.string(), z16.json()).parse(projectSnapshot(ctx, project.id, operation));
2724
2824
  const source = version?.source ?? (session ? sessionSource(session, body) : sourceText(body.source));
2725
2825
  if (session) {
2726
2826
  Object.assign(snapshot, {
@@ -2871,20 +2971,21 @@ var actionsRouter = router({
2871
2971
  });
2872
2972
 
2873
2973
  // server/router/approvals/list.ts
2874
- import { eq as eq23 } from "drizzle-orm";
2974
+ import { eq as eq25 } from "drizzle-orm";
2875
2975
 
2876
2976
  // server/runs/approvals.ts
2877
- import { z as z16 } from "zod";
2878
- var approvalIdSchema = z16.strictObject({ id: z16.uuid() });
2879
- var decideApprovalSchema = z16.strictObject({
2880
- id: z16.uuid(),
2881
- decision: z16.enum(["approved", "denied"])
2977
+ import { z as z17 } from "zod";
2978
+ var approvalIdSchema = z17.strictObject({ id: z17.uuid() });
2979
+ var decideApprovalSchema = z17.strictObject({
2980
+ id: z17.uuid(),
2981
+ decision: z17.enum(["approved", "denied", "always_allow", "block"])
2882
2982
  });
2883
2983
  function approvalView(row) {
2884
2984
  return {
2885
2985
  id: row.id,
2886
2986
  run: row.runId,
2887
2987
  prompt: row.prompt,
2988
+ shell: row.shell ? { executable: row.shell.executable, project: row.shell.projectId } : null,
2888
2989
  status: row.status,
2889
2990
  decided_by: row.decidedBy
2890
2991
  };
@@ -2892,16 +2993,16 @@ function approvalView(row) {
2892
2993
 
2893
2994
  // server/router/approvals/list.ts
2894
2995
  var listProcedure2 = browserWorkspaceProcedure.query(({ ctx }) => {
2895
- const workspaceApprovals = ctx.db.select().from(approvals).where(eq23(approvals.workspaceId, ctx.workspace.id)).all();
2996
+ const workspaceApprovals = ctx.db.select().from(approvals).where(eq25(approvals.workspaceId, ctx.workspace.id)).all();
2896
2997
  return page(workspaceApprovals.map(approvalView));
2897
2998
  });
2898
2999
 
2899
3000
  // server/repositories/approvals.ts
2900
- import { and as and20, eq as eq24 } from "drizzle-orm";
3001
+ import { and as and22, eq as eq26 } from "drizzle-orm";
2901
3002
  function approvalsRepository(context) {
2902
3003
  const workspaceId = requireWorkspace(context).id;
2903
3004
  const database = context.db;
2904
- const scoped = (id) => and20(eq24(approvals.workspaceId, workspaceId), eq24(approvals.id, id));
3005
+ const scoped = (id) => and22(eq26(approvals.workspaceId, workspaceId), eq26(approvals.id, id));
2905
3006
  return {
2906
3007
  find(id) {
2907
3008
  const row = database.select().from(approvals).where(scoped(id)).get();
@@ -2930,26 +3031,74 @@ var getProcedure2 = browserWorkspaceProcedure.input(approvalIdSchema).query(({ c
2930
3031
  return approvalView(approvalsRepository(ctx).find(id));
2931
3032
  });
2932
3033
 
3034
+ // server/repositories/plugins.ts
3035
+ import { and as and23, eq as eq27 } from "drizzle-orm";
3036
+ function pluginsRepository(context) {
3037
+ const workspaceId = requireWorkspace(context).id;
3038
+ const database = context.db;
3039
+ const scoped = (id, filter) => and23(
3040
+ eq27(plugins.workspaceId, workspaceId),
3041
+ id === void 0 ? void 0 : eq27(plugins.id, id),
3042
+ filter
3043
+ );
3044
+ return {
3045
+ find(id) {
3046
+ const row = database.select().from(plugins).where(scoped(id)).get();
3047
+ if (!row) {
3048
+ throw new ServiceError("NOT_FOUND", "Not found.");
3049
+ }
3050
+ return row;
3051
+ },
3052
+ list(filter) {
3053
+ return database.select().from(plugins).where(scoped(void 0, filter)).all();
3054
+ }
3055
+ };
3056
+ }
3057
+
2933
3058
  // server/router/approvals/decide.ts
2934
- var decideProcedure = browserManagerProcedure.input(decideApprovalSchema).mutation(({ ctx, input: input2 }) => {
2935
- return approvalView(
2936
- inTransaction(ctx, (ctx2) => {
2937
- const approval = approvalsRepository(ctx2).find(input2.id);
2938
- if (approval.status !== "pending" || ["succeeded", "failed", "cancelled", "interrupted"].includes(
2939
- runsRepository(ctx2).find(approval.runId).status
2940
- )) {
3059
+ var decideProcedure = browserManagerProcedure.input(decideApprovalSchema).mutation(
3060
+ ({ ctx, input: input2 }) => inTransaction(ctx, (ctx2) => {
3061
+ assertCurrentPluginManager(ctx2);
3062
+ const approval = approvalsRepository(ctx2).find(input2.id);
3063
+ const run = runsRepository(ctx2).find(approval.runId);
3064
+ const currentTime = now();
3065
+ if (approval.status !== "pending" || run.cancelRequested || !["running", "waiting_approval"].includes(run.status) || run.deadline && run.deadline <= currentTime || run.leaseExpiresAt && run.leaseExpiresAt <= currentTime) {
3066
+ throw new ServiceError("CONFLICT", "Approval is no longer actionable.");
3067
+ }
3068
+ const persistent = input2.decision === "always_allow" || input2.decision === "block";
3069
+ if (persistent && !approval.shell) {
3070
+ throw new ServiceError(
3071
+ "BAD_REQUEST",
3072
+ "Persistent decisions require a Shell executable request."
3073
+ );
3074
+ }
3075
+ if (approval.shell) {
3076
+ const plugin = pluginsRepository(ctx2).find(approval.shell.pluginId);
3077
+ if (!plugin.enabled || !supportsShellPolicy(plugin) || plugin.projectId !== run.projectId || plugin.digest !== approval.shell.digest) {
2941
3078
  throw new ServiceError(
2942
3079
  "CONFLICT",
2943
- "Approval is no longer actionable."
3080
+ "The Shell installation changed since this request."
2944
3081
  );
2945
3082
  }
2946
- return approvalsRepository(ctx2).update(input2.id, {
2947
- status: input2.decision,
2948
- decidedBy: ctx2.user.id
2949
- });
2950
- })
2951
- );
2952
- });
3083
+ if (persistent) {
3084
+ writeShellRule(
3085
+ ctx2,
3086
+ plugin,
3087
+ approval.shell.executable,
3088
+ input2.decision === "block" ? "block" : "allow"
3089
+ );
3090
+ return approvalView(approvalsRepository(ctx2).find(input2.id));
3091
+ }
3092
+ }
3093
+ const status = input2.decision === "denied" || input2.decision === "block" ? "denied" : "approved";
3094
+ const updated = approvalsRepository(ctx2).update(input2.id, {
3095
+ status,
3096
+ decidedBy: ctx2.user.id
3097
+ });
3098
+ resumeAfterApproval(ctx2, run.id);
3099
+ return approvalView(updated);
3100
+ })
3101
+ );
2953
3102
 
2954
3103
  // server/router/approvals/index.ts
2955
3104
  var approvalsRouter = router({
@@ -2959,11 +3108,11 @@ var approvalsRouter = router({
2959
3108
  });
2960
3109
 
2961
3110
  // server/router/artifacts/list.ts
2962
- import { eq as eq25 } from "drizzle-orm";
3111
+ import { eq as eq28 } from "drizzle-orm";
2963
3112
 
2964
3113
  // server/runs/artifacts.ts
2965
- import { z as z17 } from "zod";
2966
- var artifactIdSchema = z17.strictObject({ id: z17.uuid() });
3114
+ import { z as z18 } from "zod";
3115
+ var artifactIdSchema = z18.strictObject({ id: z18.uuid() });
2967
3116
  function artifactView(row) {
2968
3117
  return {
2969
3118
  id: row.id,
@@ -2976,17 +3125,17 @@ function artifactView(row) {
2976
3125
 
2977
3126
  // server/router/artifacts/list.ts
2978
3127
  var listProcedure3 = browserWorkspaceProcedure.query(({ ctx }) => {
2979
- const workspaceArtifacts = ctx.db.select().from(artifacts).where(eq25(artifacts.workspaceId, ctx.workspace.id)).all();
3128
+ const workspaceArtifacts = ctx.db.select().from(artifacts).where(eq28(artifacts.workspaceId, ctx.workspace.id)).all();
2980
3129
  return page(workspaceArtifacts.map(artifactView));
2981
3130
  });
2982
3131
 
2983
3132
  // server/router/artifacts/get.ts
2984
- import { and as and21, eq as eq26 } from "drizzle-orm";
3133
+ import { and as and24, eq as eq29 } from "drizzle-orm";
2985
3134
  var getProcedure3 = browserWorkspaceProcedure.input(artifactIdSchema).query(({ ctx, input: input2 }) => {
2986
3135
  const artifact = ctx.db.select().from(artifacts).where(
2987
- and21(
2988
- eq26(artifacts.workspaceId, ctx.workspace.id),
2989
- eq26(artifacts.id, input2.id)
3136
+ and24(
3137
+ eq29(artifacts.workspaceId, ctx.workspace.id),
3138
+ eq29(artifacts.id, input2.id)
2990
3139
  )
2991
3140
  ).get();
2992
3141
  if (!artifact) {
@@ -3002,10 +3151,10 @@ var artifactsRouter = router({
3002
3151
  });
3003
3152
 
3004
3153
  // server/router/audit/list.ts
3005
- import { and as and23, desc as desc3, eq as eq28, gte, lt } from "drizzle-orm";
3154
+ import { and as and26, desc as desc3, eq as eq31, gte, lt } from "drizzle-orm";
3006
3155
 
3007
3156
  // server/audit/queries.ts
3008
- import { and as and22, eq as eq27 } from "drizzle-orm";
3157
+ import { and as and25, eq as eq30 } from "drizzle-orm";
3009
3158
  function auditQueries(database, workspaceId) {
3010
3159
  return {
3011
3160
  actor(userId) {
@@ -3017,10 +3166,10 @@ function auditQueries(database, workspaceId) {
3017
3166
  firstName: users.firstName,
3018
3167
  lastName: users.lastName,
3019
3168
  username: users.username
3020
- }).from(memberships).innerJoin(users, eq27(users.id, memberships.userId)).where(
3021
- and22(
3022
- eq27(memberships.workspaceId, workspaceId),
3023
- eq27(memberships.userId, userId)
3169
+ }).from(memberships).innerJoin(users, eq30(users.id, memberships.userId)).where(
3170
+ and25(
3171
+ eq30(memberships.workspaceId, workspaceId),
3172
+ eq30(memberships.userId, userId)
3024
3173
  )
3025
3174
  ).get();
3026
3175
  }
@@ -3028,13 +3177,13 @@ function auditQueries(database, workspaceId) {
3028
3177
  }
3029
3178
 
3030
3179
  // server/audit/schemas.ts
3031
- import { z as z18 } from "zod";
3032
- var auditFiltersSchema = z18.object({
3033
- actor: z18.number().int().positive().optional(),
3034
- kind: z18.string().optional(),
3035
- object_id: z18.string().optional(),
3036
- since: z18.iso.datetime().optional(),
3037
- before: z18.iso.datetime().optional()
3180
+ import { z as z19 } from "zod";
3181
+ var auditFiltersSchema = z19.object({
3182
+ actor: z19.number().int().positive().optional(),
3183
+ kind: z19.string().optional(),
3184
+ object_id: z19.string().optional(),
3185
+ since: z19.iso.datetime().optional(),
3186
+ before: z19.iso.datetime().optional()
3038
3187
  }).strict().refine(
3039
3188
  (input2) => !input2.since || !input2.before || Date.parse(input2.since) < Date.parse(input2.before),
3040
3189
  "Invalid date range."
@@ -3056,11 +3205,11 @@ function auditView(record, actor) {
3056
3205
  var listProcedure4 = browserManagerProcedure.input(auditFiltersSchema.optional().default({})).query(({ ctx, input: input2 }) => {
3057
3206
  const queries = auditQueries(ctx.db, ctx.workspace.id);
3058
3207
  const records = ctx.db.select().from(auditRecords).where(
3059
- and23(
3060
- eq28(auditRecords.workspaceId, ctx.workspace.id),
3061
- input2.actor === void 0 ? void 0 : eq28(auditRecords.actorId, input2.actor),
3062
- input2.kind === void 0 ? void 0 : eq28(auditRecords.action, input2.kind),
3063
- input2.object_id === void 0 ? void 0 : eq28(auditRecords.resource, input2.object_id),
3208
+ and26(
3209
+ eq31(auditRecords.workspaceId, ctx.workspace.id),
3210
+ input2.actor === void 0 ? void 0 : eq31(auditRecords.actorId, input2.actor),
3211
+ input2.kind === void 0 ? void 0 : eq31(auditRecords.action, input2.kind),
3212
+ input2.object_id === void 0 ? void 0 : eq31(auditRecords.resource, input2.object_id),
3064
3213
  input2.since === void 0 ? void 0 : gte(auditRecords.createdAt, input2.since),
3065
3214
  input2.before === void 0 ? void 0 : lt(auditRecords.createdAt, input2.before)
3066
3215
  )
@@ -3071,13 +3220,13 @@ var listProcedure4 = browserManagerProcedure.input(auditFiltersSchema.optional()
3071
3220
  });
3072
3221
 
3073
3222
  // server/router/audit/get.ts
3074
- import { and as and24, eq as eq29 } from "drizzle-orm";
3075
- import { z as z19 } from "zod";
3076
- var getProcedure4 = browserManagerProcedure.input(z19.strictObject({ id: z19.uuid() })).query(({ ctx, input: input2 }) => {
3223
+ import { and as and27, eq as eq32 } from "drizzle-orm";
3224
+ import { z as z20 } from "zod";
3225
+ var getProcedure4 = browserManagerProcedure.input(z20.strictObject({ id: z20.uuid() })).query(({ ctx, input: input2 }) => {
3077
3226
  const record = ctx.db.select().from(auditRecords).where(
3078
- and24(
3079
- eq29(auditRecords.workspaceId, ctx.workspace.id),
3080
- eq29(auditRecords.id, input2.id)
3227
+ and27(
3228
+ eq32(auditRecords.workspaceId, ctx.workspace.id),
3229
+ eq32(auditRecords.id, input2.id)
3081
3230
  )
3082
3231
  ).get();
3083
3232
  if (!record) {
@@ -3126,16 +3275,16 @@ var password = {
3126
3275
  import { randomUUID as randomUUID2 } from "node:crypto";
3127
3276
 
3128
3277
  // server/auth/queries.ts
3129
- import { eq as eq30 } from "drizzle-orm";
3278
+ import { eq as eq33 } from "drizzle-orm";
3130
3279
  function createAccount(database, values2) {
3131
3280
  return database.insert(users).values(values2).returning().get();
3132
3281
  }
3133
3282
  function updateAccount(database, userId, changes) {
3134
- return database.update(users).set(changes).where(eq30(users.id, userId)).returning().get();
3283
+ return database.update(users).set(changes).where(eq33(users.id, userId)).returning().get();
3135
3284
  }
3136
3285
 
3137
3286
  // server/workspaces/queries.ts
3138
- import { and as and25, eq as eq31 } from "drizzle-orm";
3287
+ import { and as and28, eq as eq34 } from "drizzle-orm";
3139
3288
  function memberQuery(database, workspaceId, id) {
3140
3289
  return database.select({
3141
3290
  id: memberships.id,
@@ -3143,24 +3292,24 @@ function memberQuery(database, workspaceId, id) {
3143
3292
  email: users.email,
3144
3293
  username: users.username,
3145
3294
  role: memberships.role
3146
- }).from(memberships).innerJoin(users, eq31(users.id, memberships.userId)).where(
3147
- and25(
3148
- eq31(memberships.workspaceId, workspaceId),
3149
- id === void 0 ? void 0 : eq31(memberships.id, id)
3295
+ }).from(memberships).innerJoin(users, eq34(users.id, memberships.userId)).where(
3296
+ and28(
3297
+ eq34(memberships.workspaceId, workspaceId),
3298
+ id === void 0 ? void 0 : eq34(memberships.id, id)
3150
3299
  )
3151
3300
  );
3152
3301
  }
3153
3302
  function membershipForUser(database, workspaceId, userId) {
3154
3303
  return database.select().from(memberships).where(
3155
- and25(
3156
- eq31(memberships.workspaceId, workspaceId),
3157
- eq31(memberships.userId, userId)
3304
+ and28(
3305
+ eq34(memberships.workspaceId, workspaceId),
3306
+ eq34(memberships.userId, userId)
3158
3307
  )
3159
3308
  ).get();
3160
3309
  }
3161
3310
  function membershipById(database, workspaceId, id) {
3162
3311
  return database.select().from(memberships).where(
3163
- and25(eq31(memberships.workspaceId, workspaceId), eq31(memberships.id, id))
3312
+ and28(eq34(memberships.workspaceId, workspaceId), eq34(memberships.id, id))
3164
3313
  ).get();
3165
3314
  }
3166
3315
  function createMembership(database, values2) {
@@ -3168,17 +3317,17 @@ function createMembership(database, values2) {
3168
3317
  }
3169
3318
  function setMembershipRole(database, workspaceId, id, role) {
3170
3319
  database.update(memberships).set({ role }).where(
3171
- and25(eq31(memberships.workspaceId, workspaceId), eq31(memberships.id, id))
3320
+ and28(eq34(memberships.workspaceId, workspaceId), eq34(memberships.id, id))
3172
3321
  ).run();
3173
3322
  }
3174
3323
  function updateInvitation(database, workspaceId, id, changes) {
3175
3324
  database.update(invitations).set(changes).where(
3176
- and25(eq31(invitations.workspaceId, workspaceId), eq31(invitations.id, id))
3325
+ and28(eq34(invitations.workspaceId, workspaceId), eq34(invitations.id, id))
3177
3326
  ).run();
3178
3327
  }
3179
3328
 
3180
3329
  // server/auth/schemas.ts
3181
- import { z as z20 } from "zod";
3330
+ import { z as z21 } from "zod";
3182
3331
 
3183
3332
  // server/auth/validation.ts
3184
3333
  function strongPassword(value) {
@@ -3189,38 +3338,38 @@ function validEmail(value) {
3189
3338
  }
3190
3339
 
3191
3340
  // server/auth/schemas.ts
3192
- var emailSchema = z20.string().refine(validEmail, "Enter a valid email address.");
3193
- var passwordSchema = z20.string().refine(strongPassword, "Choose a stronger password.");
3194
- var loginSchema = z20.strictObject({
3195
- email: z20.string(),
3196
- password: z20.string().max(1024)
3197
- });
3198
- var codeSchema = z20.strictObject({ code: z20.string() });
3199
- var signupSchema = z20.strictObject({
3341
+ var emailSchema = z21.string().refine(validEmail, "Enter a valid email address.");
3342
+ var passwordSchema = z21.string().refine(strongPassword, "Choose a stronger password.");
3343
+ var loginSchema = z21.strictObject({
3344
+ email: z21.string(),
3345
+ password: z21.string().max(1024)
3346
+ });
3347
+ var codeSchema = z21.strictObject({ code: z21.string() });
3348
+ var signupSchema = z21.strictObject({
3200
3349
  email: emailSchema,
3201
- username: z20.string().trim().min(1).max(150),
3350
+ username: z21.string().trim().min(1).max(150),
3202
3351
  password: passwordSchema
3203
3352
  });
3204
- var setupSchema = z20.strictObject({
3205
- domain: z20.string(),
3206
- workspace_name: z20.string().trim().min(1),
3207
- username: z20.string().trim().min(1),
3353
+ var setupSchema = z21.strictObject({
3354
+ domain: z21.string(),
3355
+ workspace_name: z21.string().trim().min(1),
3356
+ username: z21.string().trim().min(1),
3208
3357
  email: emailSchema,
3209
3358
  password1: passwordSchema,
3210
- password2: z20.string(),
3211
- project_name: z20.string().optional()
3359
+ password2: z21.string(),
3360
+ project_name: z21.string().optional()
3212
3361
  }).refine((body) => body.password1 === body.password2, "Passwords must match.");
3213
- var passwordChangeSchema = z20.strictObject({
3214
- current_password: z20.string().max(1024),
3362
+ var passwordChangeSchema = z21.strictObject({
3363
+ current_password: z21.string().max(1024),
3215
3364
  new_password: passwordSchema
3216
3365
  });
3217
- var emailChangeSchema = z20.strictObject({ email: emailSchema });
3218
- var reauthenticationSchema = z20.strictObject({
3219
- password: z20.string().max(1024)
3366
+ var emailChangeSchema = z21.strictObject({ email: emailSchema });
3367
+ var reauthenticationSchema = z21.strictObject({
3368
+ password: z21.string().max(1024)
3220
3369
  });
3221
- var profileSchema = z20.strictObject({
3222
- first_name: z20.string().optional(),
3223
- last_name: z20.string().optional()
3370
+ var profileSchema = z21.strictObject({
3371
+ first_name: z21.string().optional(),
3372
+ last_name: z21.string().optional()
3224
3373
  });
3225
3374
 
3226
3375
  // server/router/auth/setup.ts
@@ -3327,6 +3476,7 @@ var browserSessionProcedure = browserProcedure.query(({ ctx }) => {
3327
3476
  function identityContext(ctx) {
3328
3477
  return {
3329
3478
  db: ctx.db,
3479
+ studioOrigin: ctx.studioOrigin,
3330
3480
  secrets: ctx.secrets,
3331
3481
  workspace: ctx.workspace,
3332
3482
  role: ctx.role,
@@ -3363,10 +3513,10 @@ function identityContext(ctx) {
3363
3513
  }
3364
3514
 
3365
3515
  // server/repositories/auth-attempts.ts
3366
- import { eq as eq32, sql } from "drizzle-orm";
3516
+ import { eq as eq35, sql as sql2 } from "drizzle-orm";
3367
3517
  function recordAuthAttempt(store, key, time) {
3368
3518
  inTransaction(store, (store2) => {
3369
- const current = store2.db.select().from(authAttempts).where(eq32(authAttempts.key, key)).get();
3519
+ const current = store2.db.select().from(authAttempts).where(eq35(authAttempts.key, key)).get();
3370
3520
  if (current && current.expiresAt > time && current.count >= 10) {
3371
3521
  throw new ServiceError(
3372
3522
  "TOO_MANY_REQUESTS",
@@ -3380,7 +3530,7 @@ function recordAuthAttempt(store, key, time) {
3380
3530
  }).run();
3381
3531
  return;
3382
3532
  }
3383
- store2.db.update(authAttempts).set({ count: sql`${authAttempts.count} + 1` }).where(eq32(authAttempts.key, key)).run();
3533
+ store2.db.update(authAttempts).set({ count: sql2`${authAttempts.count} + 1` }).where(eq35(authAttempts.key, key)).run();
3384
3534
  });
3385
3535
  }
3386
3536
 
@@ -3405,32 +3555,32 @@ var loginProcedure = browserProcedure.input(loginSchema).mutation(async ({ ctx:
3405
3555
  throw new ServiceError("BAD_REQUEST", "Invalid email or password.");
3406
3556
  }
3407
3557
  if (user.totpSecret) {
3408
- rotateSession(
3558
+ const studioGrant2 = rotateSession(
3409
3559
  ctx,
3410
3560
  null,
3411
3561
  user.id,
3412
3562
  (ctx2) => assertCurrentUser(ctx2, user, false)
3413
3563
  );
3414
3564
  ctx.user = null;
3415
- return authState(ctx, ["mfa_authenticate"]);
3565
+ return { ...authState(ctx, ["mfa_authenticate"]), studioGrant: studioGrant2 };
3416
3566
  }
3417
- rotateSession(
3567
+ const studioGrant = rotateSession(
3418
3568
  ctx,
3419
3569
  user.id,
3420
3570
  null,
3421
3571
  (ctx2) => assertCurrentUser(ctx2, user, false)
3422
3572
  );
3423
3573
  ctx.user = user;
3424
- return authState(ctx);
3574
+ return { ...authState(ctx), studioGrant };
3425
3575
  });
3426
3576
 
3427
3577
  // server/router/auth/logout.ts
3428
- import { eq as eq33 } from "drizzle-orm";
3578
+ import { eq as eq36 } from "drizzle-orm";
3429
3579
  var logoutProcedure = browserProcedure.mutation(
3430
3580
  ({ ctx: requestContext }) => {
3431
3581
  const ctx = identityContext(requestContext);
3432
3582
  if (ctx.sessionId) {
3433
- ctx.db.delete(sessions).where(eq33(sessions.id, ctx.sessionId)).run();
3583
+ ctx.db.delete(sessions).where(eq36(sessions.id, ctx.sessionId)).run();
3434
3584
  }
3435
3585
  ctx.sessionId = null;
3436
3586
  ctx.user = null;
@@ -3472,8 +3622,8 @@ var signupProcedure = browserProcedure.input(signupSchema).mutation(async ({ ctx
3472
3622
  });
3473
3623
 
3474
3624
  // server/auth/totp.ts
3475
- import { z as z21 } from "zod";
3476
- import { eq as eq34 } from "drizzle-orm";
3625
+ import { z as z22 } from "zod";
3626
+ import { eq as eq37 } from "drizzle-orm";
3477
3627
  import { createHmac, timingSafeEqual } from "node:crypto";
3478
3628
  var base32Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
3479
3629
  function base32(bytes) {
@@ -3532,16 +3682,16 @@ function consumeCode(ctx, user, code) {
3532
3682
  }
3533
3683
  const step = totpCounter(decrypt(ctx2, current.totpSecret), code);
3534
3684
  if (step !== null && (current.totpLastCounter === null || step > current.totpLastCounter)) {
3535
- ctx2.db.update(users).set({ totpLastCounter: step }).where(eq34(users.id, current.id)).run();
3685
+ ctx2.db.update(users).set({ totpLastCounter: step }).where(eq37(users.id, current.id)).run();
3536
3686
  return true;
3537
3687
  }
3538
- const hashes = z21.array(z21.string()).parse(JSON.parse(current.recoveryCodes));
3688
+ const hashes = z22.array(z22.string()).parse(JSON.parse(current.recoveryCodes));
3539
3689
  const index = hashes.indexOf(digest(code));
3540
3690
  if (index < 0) {
3541
3691
  return false;
3542
3692
  }
3543
3693
  hashes.splice(index, 1);
3544
- ctx2.db.update(users).set({ recoveryCodes: JSON.stringify(hashes) }).where(eq34(users.id, current.id)).run();
3694
+ ctx2.db.update(users).set({ recoveryCodes: JSON.stringify(hashes) }).where(eq37(users.id, current.id)).run();
3545
3695
  return true;
3546
3696
  });
3547
3697
  }
@@ -3565,7 +3715,7 @@ var mfaAuthenticateProcedure = browserProcedure.input(codeSchema).mutation(({ ct
3565
3715
  if (!user || !consumeCode(ctx, user, code) || !ctx.workspace) {
3566
3716
  throw new ServiceError("BAD_REQUEST", "Invalid authentication code.");
3567
3717
  }
3568
- rotateSession(ctx, user.id, null, (ctx2) => {
3718
+ const studioGrant = rotateSession(ctx, user.id, null, (ctx2) => {
3569
3719
  const current = ctx2.sessionId ? identityRepository(ctx2.db).session(ctx2.sessionId) : void 0;
3570
3720
  if (!current || current.pendingUserId !== user.id || current.expiresAt <= Date.now()) {
3571
3721
  throw new ServiceError(
@@ -3576,7 +3726,7 @@ var mfaAuthenticateProcedure = browserProcedure.input(codeSchema).mutation(({ ct
3576
3726
  assertCurrentUser(ctx2, user, false);
3577
3727
  });
3578
3728
  ctx.user = user;
3579
- return authState(ctx);
3729
+ return { ...authState(ctx), studioGrant };
3580
3730
  });
3581
3731
 
3582
3732
  // server/router/auth/reauthenticate.ts
@@ -3610,7 +3760,7 @@ var mfaReauthenticateProcedure = authenticatedBrowserProcedure.input(codeSchema)
3610
3760
  });
3611
3761
 
3612
3762
  // server/router/auth/change-password.ts
3613
- import { eq as eq35, or as or2 } from "drizzle-orm";
3763
+ import { eq as eq38, or as or2 } from "drizzle-orm";
3614
3764
  var changePasswordProcedure = freshBrowserProcedure.input(passwordChangeSchema).mutation(async ({ ctx: requestContext, input: input2 }) => {
3615
3765
  const ctx = identityContext(requestContext);
3616
3766
  const user = requestContext.user;
@@ -3631,8 +3781,8 @@ var changePasswordProcedure = freshBrowserProcedure.input(passwordChangeSchema).
3631
3781
  updateAccount(ctx2.db, user.id, { passwordHash });
3632
3782
  ctx2.db.delete(sessions).where(
3633
3783
  or2(
3634
- eq35(sessions.userId, user.id),
3635
- eq35(sessions.pendingUserId, user.id)
3784
+ eq38(sessions.userId, user.id),
3785
+ eq38(sessions.pendingUserId, user.id)
3636
3786
  )
3637
3787
  ).run();
3638
3788
  }
@@ -3782,7 +3932,7 @@ var authRouter = router({
3782
3932
  });
3783
3933
 
3784
3934
  // server/router/conversations/list.ts
3785
- import { eq as eq36 } from "drizzle-orm";
3935
+ import { eq as eq39 } from "drizzle-orm";
3786
3936
 
3787
3937
  // server/projects/conversations.ts
3788
3938
  var conversationView = (conversation) => {
@@ -3797,35 +3947,35 @@ var conversationView = (conversation) => {
3797
3947
 
3798
3948
  // server/router/conversations/list.ts
3799
3949
  var listProcedure5 = browserWorkspaceProcedure.query(({ ctx }) => {
3800
- const records = ctx.db.select().from(conversations).where(eq36(conversations.workspaceId, ctx.workspace.id)).all();
3950
+ const records = ctx.db.select().from(conversations).where(eq39(conversations.workspaceId, ctx.workspace.id)).all();
3801
3951
  return page(records.map((record) => conversationView(record)));
3802
3952
  });
3803
3953
 
3804
3954
  // server/router/conversations/get.ts
3805
- import { and as and26, eq as eq37 } from "drizzle-orm";
3955
+ import { and as and29, eq as eq40 } from "drizzle-orm";
3806
3956
 
3807
3957
  // server/projects/schemas.ts
3808
- import { z as z22 } from "zod";
3809
- var projectIdSchema = z22.strictObject({ id: z22.uuid() });
3810
- var projectCreateSchema = z22.strictObject({
3811
- name: z22.string().min(1).max(100),
3812
- enabled: z22.boolean().optional(),
3813
- readable_tables: z22.array(z22.uuid()).optional(),
3814
- writable_tables: z22.array(z22.uuid()).optional(),
3815
- readable_documents: z22.array(z22.uuid()).optional(),
3816
- writable_documents: z22.array(z22.uuid()).optional()
3817
- });
3818
- var projectChangesSchema = projectCreateSchema.partial().extend({ id: z22.uuid() });
3958
+ import { z as z23 } from "zod";
3959
+ var projectIdSchema = z23.strictObject({ id: z23.uuid() });
3960
+ var projectCreateSchema = z23.strictObject({
3961
+ name: z23.string().min(1).max(100),
3962
+ enabled: z23.boolean().optional(),
3963
+ readable_tables: z23.array(z23.uuid()).optional(),
3964
+ writable_tables: z23.array(z23.uuid()).optional(),
3965
+ readable_documents: z23.array(z23.uuid()).optional(),
3966
+ writable_documents: z23.array(z23.uuid()).optional()
3967
+ });
3968
+ var projectChangesSchema = projectCreateSchema.partial().extend({ id: z23.uuid() });
3819
3969
  var projectExecutorSchema = projectIdSchema.extend({
3820
- locally_managed: z22.boolean().default(false)
3970
+ locally_managed: z23.boolean().default(false)
3821
3971
  });
3822
3972
 
3823
3973
  // server/router/conversations/get.ts
3824
3974
  var getProcedure5 = browserWorkspaceProcedure.input(projectIdSchema).query(({ ctx, input: input2 }) => {
3825
3975
  const conversation = ctx.db.select().from(conversations).where(
3826
- and26(
3827
- eq37(conversations.workspaceId, ctx.workspace.id),
3828
- eq37(conversations.id, input2.id)
3976
+ and29(
3977
+ eq40(conversations.workspaceId, ctx.workspace.id),
3978
+ eq40(conversations.id, input2.id)
3829
3979
  )
3830
3980
  ).get();
3831
3981
  if (!conversation) {
@@ -3841,25 +3991,25 @@ var conversationsRouter = router({
3841
3991
  });
3842
3992
 
3843
3993
  // server/router/credentials/begin-oauth.ts
3844
- import { and as and28, eq as eq39, lt as lt2 } from "drizzle-orm";
3994
+ import { and as and31, eq as eq42, lt as lt2 } from "drizzle-orm";
3845
3995
  import { createHash as createHash2 } from "node:crypto";
3846
3996
 
3847
3997
  // server/oauth/schemas.ts
3848
- import { z as z23 } from "zod";
3849
- var oauthConnectSchema = z23.strictObject({
3850
- plugin: z23.uuid(),
3851
- name: z23.string().trim().min(1).max(100),
3852
- client_id: z23.string().trim().min(1).max(500),
3853
- client_secret: z23.string().trim().min(1).max(2e3)
3998
+ import { z as z24 } from "zod";
3999
+ var oauthConnectSchema = z24.strictObject({
4000
+ plugin: z24.uuid(),
4001
+ name: z24.string().trim().min(1).max(100),
4002
+ client_id: z24.string().trim().min(1).max(500),
4003
+ client_secret: z24.string().trim().min(1).max(2e3)
3854
4004
  });
3855
- var oauthCallbackSchema = z23.object({
3856
- state: z23.string().optional(),
3857
- code: z23.string().optional(),
3858
- error: z23.string().optional()
4005
+ var oauthCallbackSchema = z24.object({
4006
+ state: z24.string().optional(),
4007
+ code: z24.string().optional(),
4008
+ error: z24.string().optional()
3859
4009
  });
3860
4010
 
3861
4011
  // server/oauth/providers.ts
3862
- import { and as and27, eq as eq38 } from "drizzle-orm";
4012
+ import { and as and30, eq as eq41 } from "drizzle-orm";
3863
4013
  var providers = {
3864
4014
  "xero-oauth": {
3865
4015
  authorization: "https://login.xero.com/identity/connect/authorize",
@@ -3949,9 +4099,9 @@ function checkedMetadata(plugin) {
3949
4099
  }
3950
4100
  function isCurrentManager(ctx, workspaceId, userId) {
3951
4101
  const member = ctx.db.select().from(memberships).where(
3952
- and27(
3953
- eq38(memberships.workspaceId, workspaceId),
3954
- eq38(memberships.userId, userId)
4102
+ and30(
4103
+ eq41(memberships.workspaceId, workspaceId),
4104
+ eq41(memberships.userId, userId)
3955
4105
  )
3956
4106
  ).get();
3957
4107
  return member && ["owner", "admin"].includes(member.role);
@@ -3966,7 +4116,7 @@ var beginOAuthProcedure = browserSessionManagerProcedure.input(oauthConnectSchem
3966
4116
  const clientId = field(input2.client_id, 500);
3967
4117
  const clientSecret = field(input2.client_secret, 2e3);
3968
4118
  const plugin = ctx.db.select().from(plugins).where(
3969
- and28(eq39(plugins.id, pluginId), eq39(plugins.workspaceId, workspace2.id))
4119
+ and31(eq42(plugins.id, pluginId), eq42(plugins.workspaceId, workspace2.id))
3970
4120
  ).get();
3971
4121
  if (!plugin) {
3972
4122
  throw new ServiceError(
@@ -3998,8 +4148,8 @@ var beginOAuthProcedure = browserSessionManagerProcedure.input(oauthConnectSchem
3998
4148
  );
3999
4149
  }
4000
4150
  ctx2.db.delete(oauthAttempts).where(
4001
- and28(
4002
- eq39(oauthAttempts.workspaceId, workspace2.id),
4151
+ and31(
4152
+ eq42(oauthAttempts.workspaceId, workspace2.id),
4003
4153
  lt2(oauthAttempts.expiresAt, Date.now())
4004
4154
  )
4005
4155
  ).run();
@@ -4035,33 +4185,33 @@ var beginOAuthProcedure = browserSessionManagerProcedure.input(oauthConnectSchem
4035
4185
  });
4036
4186
 
4037
4187
  // server/router/credentials/list.ts
4038
- import { asc as asc2, eq as eq40 } from "drizzle-orm";
4188
+ import { asc as asc2, eq as eq43 } from "drizzle-orm";
4039
4189
  var listProcedure6 = browserWorkspaceProcedure.query(({ ctx }) => {
4040
- const records = ctx.db.select(credentialPublicFields).from(credentials).where(eq40(credentials.workspaceId, ctx.workspace.id)).orderBy(asc2(credentials.name), asc2(credentials.id)).all();
4190
+ const records = ctx.db.select(credentialPublicFields).from(credentials).where(eq43(credentials.workspaceId, ctx.workspace.id)).orderBy(asc2(credentials.name), asc2(credentials.id)).all();
4041
4191
  return page(records);
4042
4192
  });
4043
4193
 
4044
4194
  // server/credentials/schemas.ts
4045
- import { z as z24 } from "zod";
4046
- var credentialName = z24.string().trim().min(1).max(100).refine((value) => !value.includes("\0"));
4047
- var credentialSecret = z24.record(z24.string(), z24.json()).refine(
4195
+ import { z as z25 } from "zod";
4196
+ var credentialName = z25.string().trim().min(1).max(100).refine((value) => !value.includes("\0"));
4197
+ var credentialSecret = z25.record(z25.string(), z25.json()).refine(
4048
4198
  (secret) => Object.keys(secret).length > 0 && Buffer.byteLength(JSON.stringify(secret)) <= 32e3,
4049
4199
  "Supply a nonempty secret object under 32KB."
4050
4200
  );
4051
- var credentialSchema = z24.object({
4052
- id: z24.uuid(),
4053
- name: z24.string(),
4054
- provider: z24.string()
4201
+ var credentialSchema = z25.object({
4202
+ id: z25.uuid(),
4203
+ name: z25.string(),
4204
+ provider: z25.string()
4055
4205
  });
4056
- var credentialCreateSchema = z24.strictObject({
4206
+ var credentialCreateSchema = z25.strictObject({
4057
4207
  name: credentialName,
4058
4208
  provider: credentialName,
4059
4209
  secret: credentialSecret
4060
4210
  });
4061
4211
  var updateCredentialSchema = credentialCreateSchema.partial();
4062
- var credentialIdSchema = z24.strictObject({ id: z24.uuid() });
4212
+ var credentialIdSchema = z25.strictObject({ id: z25.uuid() });
4063
4213
  var credentialChangesSchema = updateCredentialSchema.extend({
4064
- id: z24.uuid()
4214
+ id: z25.uuid()
4065
4215
  });
4066
4216
 
4067
4217
  // server/router/credentials/get.ts
@@ -4095,7 +4245,7 @@ var createProcedure2 = browserManagerProcedure.input(credentialCreateSchema).mut
4095
4245
  });
4096
4246
 
4097
4247
  // server/router/credentials/update.ts
4098
- import { and as and29, eq as eq41 } from "drizzle-orm";
4248
+ import { and as and32, eq as eq44 } from "drizzle-orm";
4099
4249
  var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mutation(({ ctx, input: input2 }) => {
4100
4250
  const changes = {
4101
4251
  ...input2.name === void 0 ? {} : { name: input2.name },
@@ -4106,9 +4256,9 @@ var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mu
4106
4256
  };
4107
4257
  return inTransaction(ctx, (transaction) => {
4108
4258
  const existing = transaction.db.select({ provider: credentials.provider }).from(credentials).where(
4109
- and29(
4110
- eq41(credentials.workspaceId, ctx.workspace.id),
4111
- eq41(credentials.id, input2.id)
4259
+ and32(
4260
+ eq44(credentials.workspaceId, ctx.workspace.id),
4261
+ eq44(credentials.id, input2.id)
4112
4262
  )
4113
4263
  ).get();
4114
4264
  if (input2.provider?.startsWith("mcp-") || existing?.provider.startsWith("mcp-") && (input2.provider !== void 0 || input2.secret !== void 0)) {
@@ -4118,9 +4268,9 @@ var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mu
4118
4268
  );
4119
4269
  }
4120
4270
  const credential = transaction.db.update(credentials).set({ ...changes, updatedAt: now() }).where(
4121
- and29(
4122
- eq41(credentials.workspaceId, ctx.workspace.id),
4123
- eq41(credentials.id, input2.id)
4271
+ and32(
4272
+ eq44(credentials.workspaceId, ctx.workspace.id),
4273
+ eq44(credentials.id, input2.id)
4124
4274
  )
4125
4275
  ).returning(credentialPublicFields).get();
4126
4276
  if (!credential) {
@@ -4132,25 +4282,25 @@ var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mu
4132
4282
  });
4133
4283
 
4134
4284
  // server/router/credentials/delete.ts
4135
- import { and as and30, eq as eq42 } from "drizzle-orm";
4285
+ import { and as and33, eq as eq45 } from "drizzle-orm";
4136
4286
  var deleteProcedure = browserManagerProcedure.input(credentialIdSchema).mutation(({ ctx, input: input2 }) => {
4137
4287
  inTransaction(ctx, (transaction) => {
4138
4288
  if (!findCredential(transaction.db, ctx.workspace.id, input2.id)) {
4139
4289
  throw new ServiceError("NOT_FOUND", "Credential not found.");
4140
4290
  }
4141
4291
  const dependentPlugin = transaction.db.select({ id: plugins.id }).from(plugins).where(
4142
- and30(
4143
- eq42(plugins.workspaceId, ctx.workspace.id),
4144
- eq42(plugins.credentialId, input2.id)
4292
+ and33(
4293
+ eq45(plugins.workspaceId, ctx.workspace.id),
4294
+ eq45(plugins.credentialId, input2.id)
4145
4295
  )
4146
4296
  ).limit(1).get();
4147
4297
  if (dependentPlugin) {
4148
4298
  throw new ServiceError("CONFLICT", "Credential is used by a plugin.");
4149
4299
  }
4150
4300
  transaction.db.delete(credentials).where(
4151
- and30(
4152
- eq42(credentials.workspaceId, ctx.workspace.id),
4153
- eq42(credentials.id, input2.id)
4301
+ and33(
4302
+ eq45(credentials.workspaceId, ctx.workspace.id),
4303
+ eq45(credentials.id, input2.id)
4154
4304
  )
4155
4305
  ).run();
4156
4306
  recordAudit(transaction, "credential", input2.id, "deleted");
@@ -4168,7 +4318,7 @@ var credentialsRouter = router({
4168
4318
  });
4169
4319
 
4170
4320
  // server/router/documents/list.ts
4171
- import { eq as eq43 } from "drizzle-orm";
4321
+ import { eq as eq46 } from "drizzle-orm";
4172
4322
 
4173
4323
  // server/documents/views.ts
4174
4324
  function documentView(row) {
@@ -4177,14 +4327,14 @@ function documentView(row) {
4177
4327
 
4178
4328
  // server/router/documents/list.ts
4179
4329
  var listProcedure7 = browserWorkspaceProcedure.query(({ ctx }) => {
4180
- const records = ctx.db.select().from(documents).where(eq43(documents.workspaceId, ctx.workspace.id)).all();
4330
+ const records = ctx.db.select().from(documents).where(eq46(documents.workspaceId, ctx.workspace.id)).all();
4181
4331
  return page(records.map((record) => documentView(record)));
4182
4332
  });
4183
4333
 
4184
4334
  // server/repositories/documents.ts
4185
- import { and as and31, eq as eq44 } from "drizzle-orm";
4335
+ import { and as and34, eq as eq47 } from "drizzle-orm";
4186
4336
  function findDocument(database, workspaceId, id) {
4187
- const record = database.select().from(documents).where(and31(eq44(documents.workspaceId, workspaceId), eq44(documents.id, id))).get();
4337
+ const record = database.select().from(documents).where(and34(eq47(documents.workspaceId, workspaceId), eq47(documents.id, id))).get();
4188
4338
  if (!record) {
4189
4339
  throw new ServiceError("NOT_FOUND", "Not found.");
4190
4340
  }
@@ -4192,18 +4342,18 @@ function findDocument(database, workspaceId, id) {
4192
4342
  }
4193
4343
 
4194
4344
  // server/documents/schemas.ts
4195
- import { z as z25 } from "zod";
4196
- var identifier3 = z25.uuid();
4345
+ import { z as z26 } from "zod";
4346
+ var identifier3 = z26.uuid();
4197
4347
  var documentFields = {
4198
- kind: z25.enum(["memory", "document"]),
4199
- title: z25.string(),
4200
- content: z25.string().max(2e5).refine((value) => !value.includes("\0"), "Invalid document.")
4348
+ kind: z26.enum(["memory", "document"]),
4349
+ title: z26.string(),
4350
+ content: z26.string().max(2e5).refine((value) => !value.includes("\0"), "Invalid document.")
4201
4351
  };
4202
- var documentIdSchema = z25.strictObject({ id: identifier3 });
4203
- var createDocumentSchema = z25.strictObject(documentFields);
4204
- var updateDocumentSchema = z25.strictObject({
4352
+ var documentIdSchema = z26.strictObject({ id: identifier3 });
4353
+ var createDocumentSchema = z26.strictObject(documentFields);
4354
+ var updateDocumentSchema = z26.strictObject({
4205
4355
  id: identifier3,
4206
- ...z25.object(documentFields).partial().shape
4356
+ ...z26.object(documentFields).partial().shape
4207
4357
  });
4208
4358
 
4209
4359
  // server/router/documents/get.ts
@@ -4225,7 +4375,7 @@ var createProcedure3 = browserWorkspaceProcedure.input(createDocumentSchema).mut
4225
4375
  );
4226
4376
 
4227
4377
  // server/router/documents/update.ts
4228
- import { and as and32, eq as eq45 } from "drizzle-orm";
4378
+ import { and as and35, eq as eq48 } from "drizzle-orm";
4229
4379
  var updateProcedure3 = browserWorkspaceProcedure.input(updateDocumentSchema).mutation(({ ctx, input: input2 }) => {
4230
4380
  return inTransaction(ctx, (ctx2) => {
4231
4381
  const current = findDocument(ctx2.db, ctx2.workspace.id, input2.id);
@@ -4235,9 +4385,9 @@ var updateProcedure3 = browserWorkspaceProcedure.input(updateDocumentSchema).mut
4235
4385
  content: input2.content ?? current.content,
4236
4386
  updatedAt: now()
4237
4387
  }).where(
4238
- and32(
4239
- eq45(documents.workspaceId, ctx2.workspace.id),
4240
- eq45(documents.id, input2.id)
4388
+ and35(
4389
+ eq48(documents.workspaceId, ctx2.workspace.id),
4390
+ eq48(documents.id, input2.id)
4241
4391
  )
4242
4392
  ).returning().get();
4243
4393
  if (!document) {
@@ -4249,7 +4399,7 @@ var updateProcedure3 = browserWorkspaceProcedure.input(updateDocumentSchema).mut
4249
4399
  });
4250
4400
 
4251
4401
  // server/router/documents/delete.ts
4252
- import { and as and33, eq as eq46 } from "drizzle-orm";
4402
+ import { and as and36, eq as eq49 } from "drizzle-orm";
4253
4403
  var deleteProcedure2 = browserWorkspaceProcedure.input(documentIdSchema).mutation(({ ctx, input: input2 }) => {
4254
4404
  return inTransaction(ctx, (ctx2) => {
4255
4405
  findDocument(ctx2.db, ctx2.workspace.id, input2.id);
@@ -4264,9 +4414,9 @@ var deleteProcedure2 = browserWorkspaceProcedure.input(documentIdSchema).mutatio
4264
4414
  });
4265
4415
  }
4266
4416
  const deleted = ctx2.db.delete(documents).where(
4267
- and33(
4268
- eq46(documents.workspaceId, ctx2.workspace.id),
4269
- eq46(documents.id, input2.id)
4417
+ and36(
4418
+ eq49(documents.workspaceId, ctx2.workspace.id),
4419
+ eq49(documents.id, input2.id)
4270
4420
  )
4271
4421
  ).returning({ id: documents.id }).get();
4272
4422
  if (deleted) {
@@ -4285,36 +4435,76 @@ var documentsRouter = router({
4285
4435
  delete: deleteProcedure2
4286
4436
  });
4287
4437
 
4438
+ // server/router/plugins/shell-rules.ts
4439
+ import { asc as asc3, eq as eq50 } from "drizzle-orm";
4440
+ import { z as z27 } from "zod";
4441
+ var shellRulesProcedure = browserWorkspaceProcedure.input(z27.strictObject({ id: z27.uuid() })).query(({ ctx, input: input2 }) => {
4442
+ const plugin = pluginsRepository(ctx).find(input2.id);
4443
+ if (!supportsShellPolicy(plugin)) {
4444
+ throw new ServiceError(
4445
+ "BAD_REQUEST",
4446
+ "This plugin version does not support executable policies."
4447
+ );
4448
+ }
4449
+ return ctx.db.select({
4450
+ executable: shellRules.executable,
4451
+ decision: shellRules.decision
4452
+ }).from(shellRules).where(eq50(shellRules.pluginId, plugin.id)).orderBy(asc3(shellRules.executable)).all();
4453
+ });
4454
+
4455
+ // server/router/plugins/set-shell-rule.ts
4456
+ import { z as z28 } from "zod";
4457
+ var setShellRuleProcedure = browserManagerProcedure.input(
4458
+ z28.strictObject({
4459
+ id: z28.uuid(),
4460
+ executable: executableName,
4461
+ decision: ruleDecision
4462
+ })
4463
+ ).mutation(
4464
+ ({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
4465
+ assertCurrentPluginManager(transaction);
4466
+ const plugin = pluginsRepository(transaction).find(input2.id);
4467
+ if (!supportsShellPolicy(plugin)) {
4468
+ throw new ServiceError(
4469
+ "BAD_REQUEST",
4470
+ "This plugin version does not support executable policies."
4471
+ );
4472
+ }
4473
+ writeShellRule(transaction, plugin, input2.executable, input2.decision);
4474
+ return { saved: true };
4475
+ })
4476
+ );
4477
+
4288
4478
  // server/router/plugins/mcp/begin-oauth.ts
4289
4479
  import { auth as auth2, discoverOAuthServerInfo } from "@modelcontextprotocol/client";
4290
4480
 
4291
4481
  // server/mcp/schemas.ts
4292
- import { z as z26 } from "zod";
4293
- var connectionInputSchema = z26.strictObject({
4294
- project: z26.uuid(),
4295
- slug: z26.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/).max(50),
4482
+ import { z as z29 } from "zod";
4483
+ var connectionInputSchema = z29.strictObject({
4484
+ project: z29.uuid(),
4485
+ slug: z29.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/).max(50),
4296
4486
  endpoint: endpointSchema,
4297
4487
  transport: transportSchema.default("auto"),
4298
- auth_mode: z26.enum(["none", "headers", "oauth"]).default("none"),
4488
+ auth_mode: z29.enum(["none", "headers", "oauth"]).default("none"),
4299
4489
  headers: headerSchema.optional()
4300
4490
  });
4301
- var connectionUpdateSchema = z26.strictObject({
4302
- id: z26.uuid(),
4491
+ var connectionUpdateSchema = z29.strictObject({
4492
+ id: z29.uuid(),
4303
4493
  endpoint: endpointSchema.optional(),
4304
4494
  transport: transportSchema.optional(),
4305
- auth_mode: z26.enum(["none", "headers", "oauth"]).optional(),
4495
+ auth_mode: z29.enum(["none", "headers", "oauth"]).optional(),
4306
4496
  headers: headerSchema.optional()
4307
4497
  });
4308
- var catalogueAcceptSchema = z26.strictObject({
4309
- id: z26.uuid(),
4310
- run: z26.uuid(),
4311
- tools: z26.array(z26.string()).max(1e3)
4498
+ var catalogueAcceptSchema = z29.strictObject({
4499
+ id: z29.uuid(),
4500
+ run: z29.uuid(),
4501
+ tools: z29.array(z29.string()).max(1e3)
4312
4502
  });
4313
- var oauthBeginSchema = z26.strictObject({
4314
- id: z26.uuid(),
4315
- client_id: z26.string().max(2e3).optional(),
4316
- client_secret: z26.string().max(4e3).optional(),
4317
- client_metadata_url: z26.string().url().optional()
4503
+ var oauthBeginSchema = z29.strictObject({
4504
+ id: z29.uuid(),
4505
+ client_id: z29.string().max(2e3).optional(),
4506
+ client_secret: z29.string().max(4e3).optional(),
4507
+ client_metadata_url: z29.string().url().optional()
4318
4508
  });
4319
4509
 
4320
4510
  // server/router/plugins/mcp/begin-oauth.ts
@@ -4400,30 +4590,6 @@ function createHeaderCredential(ctx, name, headers) {
4400
4590
  }).returning().get().id;
4401
4591
  }
4402
4592
 
4403
- // server/repositories/plugins.ts
4404
- import { and as and34, eq as eq47 } from "drizzle-orm";
4405
- function pluginsRepository(context) {
4406
- const workspaceId = requireWorkspace(context).id;
4407
- const database = context.db;
4408
- const scoped = (id, filter) => and34(
4409
- eq47(plugins.workspaceId, workspaceId),
4410
- id === void 0 ? void 0 : eq47(plugins.id, id),
4411
- filter
4412
- );
4413
- return {
4414
- find(id) {
4415
- const row = database.select().from(plugins).where(scoped(id)).get();
4416
- if (!row) {
4417
- throw new ServiceError("NOT_FOUND", "Not found.");
4418
- }
4419
- return row;
4420
- },
4421
- list(filter) {
4422
- return database.select().from(plugins).where(scoped(void 0, filter)).all();
4423
- }
4424
- };
4425
- }
4426
-
4427
4593
  // server/router/plugins/mcp/create.ts
4428
4594
  var createProcedure4 = browserManagerProcedure.input(connectionInputSchema).mutation(
4429
4595
  ({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
@@ -4462,7 +4628,7 @@ var createProcedure4 = browserManagerProcedure.input(connectionInputSchema).muta
4462
4628
  );
4463
4629
 
4464
4630
  // server/router/plugins/mcp/update.ts
4465
- import { eq as eq48 } from "drizzle-orm";
4631
+ import { eq as eq51 } from "drizzle-orm";
4466
4632
  var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mutation(
4467
4633
  ({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
4468
4634
  assertCurrentPluginManager(transaction);
@@ -4490,12 +4656,12 @@ var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mut
4490
4656
  discoveryRunId: null,
4491
4657
  catalogue: [],
4492
4658
  enabledTools: []
4493
- }).where(eq48(mcpConnections.pluginId, input2.id)).run();
4659
+ }).where(eq51(mcpConnections.pluginId, input2.id)).run();
4494
4660
  transaction.db.update(plugins).set({
4495
4661
  enabled: false,
4496
4662
  ...credentialId ? { credentialId } : resetAuth ? { credentialId: null } : {},
4497
4663
  updatedAt: now()
4498
- }).where(eq48(plugins.id, input2.id)).run();
4664
+ }).where(eq51(plugins.id, input2.id)).run();
4499
4665
  discardMcpCredential(transaction, replacedCredential);
4500
4666
  recordAudit(transaction, "plugin", input2.id, "connection.updated");
4501
4667
  return { id: input2.id };
@@ -4503,41 +4669,41 @@ var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mut
4503
4669
  );
4504
4670
 
4505
4671
  // server/plugins/schemas.ts
4506
- import { z as z27 } from "zod";
4507
- var pluginIdSchema = z27.strictObject({ id: z27.uuid() });
4508
- var pluginCreateSchema = z27.strictObject({
4509
- project: z27.uuid(),
4510
- slug: z27.string(),
4511
- version: z27.string(),
4512
- description: z27.string().optional(),
4513
- source: z27.string().optional(),
4514
- distribution: z27.enum(["inline", "external"]).optional(),
4515
- credential: z27.uuid().nullable().optional(),
4516
- configuration: z27.json().optional(),
4517
- enabled: z27.boolean().optional()
4518
- });
4519
- var pluginChangesSchema = pluginCreateSchema.omit({ slug: true }).partial().extend({ id: z27.uuid(), refresh_bundle: z27.boolean().optional() });
4672
+ import { z as z30 } from "zod";
4673
+ var pluginIdSchema = z30.strictObject({ id: z30.uuid() });
4674
+ var pluginCreateSchema = z30.strictObject({
4675
+ project: z30.uuid(),
4676
+ slug: z30.string(),
4677
+ version: z30.string(),
4678
+ description: z30.string().optional(),
4679
+ source: z30.string().optional(),
4680
+ distribution: z30.enum(["inline", "external"]).optional(),
4681
+ credential: z30.uuid().nullable().optional(),
4682
+ configuration: z30.json().optional(),
4683
+ enabled: z30.boolean().optional()
4684
+ });
4685
+ var pluginChangesSchema = pluginCreateSchema.omit({ slug: true }).partial().extend({ id: z30.uuid(), refresh_bundle: z30.boolean().optional() });
4520
4686
 
4521
4687
  // server/router/plugins/mcp/get.ts
4522
- import { and as and35, eq as eq49, gt as gt2 } from "drizzle-orm";
4688
+ import { and as and37, eq as eq52, gt as gt3 } from "drizzle-orm";
4523
4689
  var getProcedure8 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx, input: input2 }) => {
4524
4690
  const connection = mcpConnection(ctx, input2.id);
4525
- const plugin = ctx.db.select().from(plugins).where(eq49(plugins.id, connection.pluginId)).get();
4691
+ const plugin = ctx.db.select().from(plugins).where(eq52(plugins.id, connection.pluginId)).get();
4526
4692
  const runner = plugin ? ctx.db.select({ protocolVersion: executors.protocolVersion }).from(executors).where(
4527
- and35(
4528
- eq49(executors.workspaceId, ctx.workspace.id),
4529
- eq49(executors.projectId, plugin.projectId),
4530
- eq49(executors.enabled, true),
4531
- gt2(
4693
+ and37(
4694
+ eq52(executors.workspaceId, ctx.workspace.id),
4695
+ eq52(executors.projectId, plugin.projectId),
4696
+ eq52(executors.enabled, true),
4697
+ gt3(
4532
4698
  executors.lastSeenAt,
4533
4699
  new Date(Date.now() - 6e4).toISOString()
4534
4700
  )
4535
4701
  )
4536
4702
  ).all() : [];
4537
4703
  const run = connection.discoveryRunId ? ctx.db.select({ status: runs.status, error: runs.error }).from(runs).where(
4538
- and35(
4539
- eq49(runs.id, connection.discoveryRunId),
4540
- eq49(runs.workspaceId, ctx.workspace.id)
4704
+ and37(
4705
+ eq52(runs.id, connection.discoveryRunId),
4706
+ eq52(runs.workspaceId, ctx.workspace.id)
4541
4707
  )
4542
4708
  ).get() : void 0;
4543
4709
  return {
@@ -4550,18 +4716,18 @@ var getProcedure8 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx
4550
4716
  });
4551
4717
 
4552
4718
  // server/router/plugins/mcp/discover.ts
4553
- import { and as and36, eq as eq50, gt as gt3 } from "drizzle-orm";
4719
+ import { and as and38, eq as eq53, gt as gt4 } from "drizzle-orm";
4554
4720
  var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
4555
4721
  ({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
4556
4722
  assertCurrentPluginManager(transaction);
4557
4723
  const plugin = pluginsRepository(transaction).find(input2.id);
4558
4724
  const connection = mcpConnection(transaction, input2.id);
4559
4725
  const workers = transaction.db.select().from(executors).where(
4560
- and36(
4561
- eq50(executors.workspaceId, ctx.workspace.id),
4562
- eq50(executors.projectId, plugin.projectId),
4563
- eq50(executors.enabled, true),
4564
- gt3(
4726
+ and38(
4727
+ eq53(executors.workspaceId, ctx.workspace.id),
4728
+ eq53(executors.projectId, plugin.projectId),
4729
+ eq53(executors.enabled, true),
4730
+ gt4(
4565
4731
  executors.lastSeenAt,
4566
4732
  new Date(Date.now() - 6e4).toISOString()
4567
4733
  )
@@ -4583,16 +4749,16 @@ var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
4583
4749
  }
4584
4750
  if (connection.discoveryRunId) {
4585
4751
  const previous = transaction.db.select().from(runs).where(
4586
- and36(
4587
- eq50(runs.id, connection.discoveryRunId),
4588
- eq50(runs.workspaceId, ctx.workspace.id)
4752
+ and38(
4753
+ eq53(runs.id, connection.discoveryRunId),
4754
+ eq53(runs.workspaceId, ctx.workspace.id)
4589
4755
  )
4590
4756
  ).get();
4591
4757
  if (previous && ["queued", "running"].includes(previous.status)) {
4592
4758
  transaction.db.update(runs).set({
4593
4759
  cancelRequested: true,
4594
4760
  ...previous.status === "queued" ? { status: "cancelled" } : {}
4595
- }).where(eq50(runs.id, previous.id)).run();
4761
+ }).where(eq53(runs.id, previous.id)).run();
4596
4762
  }
4597
4763
  }
4598
4764
  const target = { ...mcpSnapshot(transaction, input2.id), tools: [] };
@@ -4624,14 +4790,14 @@ var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
4624
4790
  ]
4625
4791
  }
4626
4792
  }).returning().get();
4627
- transaction.db.update(mcpConnections).set({ discoveryRunId: run.id, status: "checking", candidate: null }).where(eq50(mcpConnections.pluginId, input2.id)).run();
4793
+ transaction.db.update(mcpConnections).set({ discoveryRunId: run.id, status: "checking", candidate: null }).where(eq53(mcpConnections.pluginId, input2.id)).run();
4628
4794
  recordAudit(transaction, "plugin", input2.id, "discovery.requested");
4629
4795
  return { run: run.id };
4630
4796
  })
4631
4797
  );
4632
4798
 
4633
4799
  // server/router/plugins/mcp/accept.ts
4634
- import { eq as eq51 } from "drizzle-orm";
4800
+ import { eq as eq54 } from "drizzle-orm";
4635
4801
 
4636
4802
  // runtime/src/mcp/aliases.ts
4637
4803
  import { createHash as createHash3 } from "node:crypto";
@@ -4714,13 +4880,13 @@ var acceptProcedure = browserManagerProcedure.input(catalogueAcceptSchema).mutat
4714
4880
  candidate: null,
4715
4881
  revision: revision3,
4716
4882
  status: "ready"
4717
- }).where(eq51(mcpConnections.pluginId, input2.id)).run();
4883
+ }).where(eq54(mcpConnections.pluginId, input2.id)).run();
4718
4884
  transaction.db.update(plugins).set({
4719
4885
  version: String(revision3),
4720
4886
  digest: digest(JSON.stringify(catalogue)),
4721
4887
  enabled: selected.size > 0,
4722
4888
  updatedAt: now()
4723
- }).where(eq51(plugins.id, input2.id)).run();
4889
+ }).where(eq54(plugins.id, input2.id)).run();
4724
4890
  recordAudit(transaction, "plugin", input2.id, "catalogue.accepted");
4725
4891
  return { id: input2.id, revision: revision3 };
4726
4892
  })
@@ -4749,6 +4915,7 @@ var pluginView = (plugin) => {
4749
4915
  enabled: plugin.enabled,
4750
4916
  credential: plugin.credentialId,
4751
4917
  distribution: plugin.distribution,
4918
+ shell_policy: supportsShellPolicy(plugin),
4752
4919
  configuration: plugin.configuration,
4753
4920
  package_url: plugin.packageUrl,
4754
4921
  tools: plugin.releaseMetadata?.tools ?? null,
@@ -4772,54 +4939,54 @@ var getProcedure9 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx
4772
4939
  });
4773
4940
 
4774
4941
  // server/router/plugins/create.ts
4775
- import { and as and37, eq as eq52 } from "drizzle-orm";
4942
+ import { and as and39, eq as eq55 } from "drizzle-orm";
4776
4943
 
4777
4944
  // server/plugins/catalog.ts
4778
- import { z as z29 } from "zod";
4945
+ import { z as z32 } from "zod";
4779
4946
 
4780
4947
  // server/plugins/catalog-schemas.ts
4781
- import { z as z28 } from "zod";
4782
- var jsonObject4 = z28.record(z28.string(), z28.json());
4783
- var slug = z28.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/);
4784
- var releaseSchema = z28.object({
4948
+ import { z as z31 } from "zod";
4949
+ var jsonObject4 = z31.record(z31.string(), z31.json());
4950
+ var slug = z31.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/);
4951
+ var releaseSchema = z31.object({
4785
4952
  slug,
4786
- version: z28.string().min(1).max(100),
4787
- digest: z28.string().regex(/^[a-f0-9]{64}$/),
4788
- package_url: z28.string(),
4789
- display_name: z28.string(),
4790
- description: z28.string(),
4791
- category: z28.string(),
4792
- documentation: z28.string(),
4793
- distribution: z28.literal("external"),
4794
- contract_version: z28.literal(1),
4795
- auth: z28.object({
4796
- type: z28.string().optional(),
4797
- provider: z28.string().optional(),
4798
- label: z28.string().optional(),
4799
- hint: z28.string().optional(),
4800
- scopes: z28.array(z28.string()).optional()
4801
- }).catchall(z28.json()),
4953
+ version: z31.string().min(1).max(100),
4954
+ digest: z31.string().regex(/^[a-f0-9]{64}$/),
4955
+ package_url: z31.string(),
4956
+ display_name: z31.string(),
4957
+ description: z31.string(),
4958
+ category: z31.string(),
4959
+ documentation: z31.string(),
4960
+ distribution: z31.literal("external"),
4961
+ contract_version: z31.literal(1),
4962
+ auth: z31.object({
4963
+ type: z31.string().optional(),
4964
+ provider: z31.string().optional(),
4965
+ label: z31.string().optional(),
4966
+ hint: z31.string().optional(),
4967
+ scopes: z31.array(z31.string()).optional()
4968
+ }).catchall(z31.json()),
4802
4969
  marketplace: jsonObject4,
4803
4970
  configuration_schema: jsonObject4,
4804
- tools: z28.array(jsonObject4)
4805
- }).catchall(z28.json());
4806
- var marketplaceSchema = z28.object({
4807
- schema_version: z28.literal(1),
4808
- plugins: z28.array(
4809
- z28.object({
4971
+ tools: z31.array(jsonObject4)
4972
+ }).catchall(z31.json());
4973
+ var marketplaceSchema = z31.object({
4974
+ schema_version: z31.literal(1),
4975
+ plugins: z31.array(
4976
+ z31.object({
4810
4977
  slug,
4811
- display_name: z28.string(),
4812
- description: z28.string(),
4813
- category: z28.string(),
4814
- permissions: z28.string(),
4815
- source_version: z28.string(),
4816
- source_url: z28.string(),
4817
- url: z28.string(),
4818
- release_status: z28.enum(["unreleased", "available"]),
4819
- auth_type: z28.enum(["none", "token", "oauth2"]),
4820
- tags: z28.array(z28.string()),
4821
- use_cases: z28.array(z28.string())
4822
- }).catchall(z28.json())
4978
+ display_name: z31.string(),
4979
+ description: z31.string(),
4980
+ category: z31.string(),
4981
+ permissions: z31.string(),
4982
+ source_version: z31.string(),
4983
+ source_url: z31.string(),
4984
+ url: z31.string(),
4985
+ release_status: z31.enum(["unreleased", "available"]),
4986
+ auth_type: z31.enum(["none", "token", "oauth2"]),
4987
+ tags: z31.array(z31.string()),
4988
+ use_cases: z31.array(z31.string())
4989
+ }).catchall(z31.json())
4823
4990
  )
4824
4991
  });
4825
4992
 
@@ -4885,7 +5052,7 @@ async function catalogEntries() {
4885
5052
  "Cannot read the configured plugin catalog."
4886
5053
  );
4887
5054
  }
4888
- const result = z29.array(releaseSchema).safeParse(entries);
5055
+ const result = z32.array(releaseSchema).safeParse(entries);
4889
5056
  if (!result.success) {
4890
5057
  throw new ServiceError(
4891
5058
  "PRECONDITION_FAILED",
@@ -4979,10 +5146,10 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
4979
5146
  metadata2
4980
5147
  );
4981
5148
  const installedPlugin = transaction.db.select({ id: plugins.id }).from(plugins).where(
4982
- and37(
4983
- eq52(plugins.workspaceId, context.workspace.id),
4984
- eq52(plugins.projectId, projectId),
4985
- eq52(plugins.slug, slug2)
5149
+ and39(
5150
+ eq55(plugins.workspaceId, context.workspace.id),
5151
+ eq55(plugins.projectId, projectId),
5152
+ eq55(plugins.slug, slug2)
4986
5153
  )
4987
5154
  ).limit(1).get();
4988
5155
  if (installedPlugin) {
@@ -4999,7 +5166,7 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
4999
5166
 
5000
5167
  // server/router/plugins/update.ts
5001
5168
  import { isDeepStrictEqual } from "node:util";
5002
- import { and as and38, eq as eq53 } from "drizzle-orm";
5169
+ import { and as and40, eq as eq56 } from "drizzle-orm";
5003
5170
  var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutation(async ({ ctx: context, input: input2 }) => {
5004
5171
  const { id, ...changes } = input2;
5005
5172
  const originalPlugin = pluginsRepository(context).find(id);
@@ -5087,9 +5254,9 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
5087
5254
  releaseMetadata: metadata2,
5088
5255
  updatedAt: now()
5089
5256
  }).where(
5090
- and38(
5091
- eq53(plugins.workspaceId, context.workspace.id),
5092
- eq53(plugins.id, id)
5257
+ and40(
5258
+ eq56(plugins.workspaceId, context.workspace.id),
5259
+ eq56(plugins.id, id)
5093
5260
  )
5094
5261
  ).returning().get();
5095
5262
  if (!updatedPlugin) {
@@ -5101,15 +5268,15 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
5101
5268
  });
5102
5269
 
5103
5270
  // server/router/plugins/delete.ts
5104
- import { and as and39, eq as eq54 } from "drizzle-orm";
5271
+ import { and as and41, eq as eq57 } from "drizzle-orm";
5105
5272
  var deleteProcedure3 = browserManagerProcedure.input(pluginIdSchema).mutation(({ ctx, input: input2 }) => {
5106
5273
  inTransaction(ctx, (transaction) => {
5107
5274
  assertCurrentPluginManager(transaction);
5108
5275
  cancelConnectionRuns(transaction, input2.id);
5109
5276
  const deletedPlugin = transaction.db.delete(plugins).where(
5110
- and39(
5111
- eq54(plugins.workspaceId, ctx.workspace.id),
5112
- eq54(plugins.id, input2.id)
5277
+ and41(
5278
+ eq57(plugins.workspaceId, ctx.workspace.id),
5279
+ eq57(plugins.id, input2.id)
5113
5280
  )
5114
5281
  ).returning({ id: plugins.id, credentialId: plugins.credentialId }).get();
5115
5282
  if (!deletedPlugin) {
@@ -5156,6 +5323,8 @@ var marketplaceProcedure = browserWorkspaceProcedure.query(
5156
5323
  // server/router/plugins/index.ts
5157
5324
  var pluginsRouter = router({
5158
5325
  mcp: mcpRouter,
5326
+ shellRules: shellRulesProcedure,
5327
+ setShellRule: setShellRuleProcedure,
5159
5328
  list: listProcedure8,
5160
5329
  get: getProcedure9,
5161
5330
  create: createProcedure5,
@@ -5166,39 +5335,39 @@ var pluginsRouter = router({
5166
5335
  });
5167
5336
 
5168
5337
  // server/router/projects/list.ts
5169
- import { and as and41, eq as eq57 } from "drizzle-orm";
5338
+ import { and as and43, eq as eq60 } from "drizzle-orm";
5170
5339
 
5171
5340
  // server/projects/queries.ts
5172
- import { and as and40, eq as eq55, inArray as inArray5, or as or3 } from "drizzle-orm";
5341
+ import { and as and42, eq as eq58, inArray as inArray6, or as or3 } from "drizzle-orm";
5173
5342
  function projectVisibility(database, workspaceId, grants2) {
5174
5343
  if (!grants2) {
5175
5344
  return void 0;
5176
5345
  }
5177
5346
  const grantedActionProjects = database.select({ projectId: actions.projectId }).from(actions).innerJoin(
5178
5347
  actionVersions,
5179
- and40(
5180
- eq55(actionVersions.actionId, actions.id),
5181
- eq55(actionVersions.workspaceId, workspaceId)
5348
+ and42(
5349
+ eq58(actionVersions.actionId, actions.id),
5350
+ eq58(actionVersions.workspaceId, workspaceId)
5182
5351
  )
5183
5352
  ).where(
5184
- and40(
5185
- eq55(actions.workspaceId, workspaceId),
5186
- inArray5(actionVersions.id, grants2.actionVersions)
5353
+ and42(
5354
+ eq58(actions.workspaceId, workspaceId),
5355
+ inArray6(actionVersions.id, grants2.actionVersions)
5187
5356
  )
5188
5357
  );
5189
5358
  return or3(
5190
- inArray5(projects.id, grants2.projects),
5191
- inArray5(projects.id, grantedActionProjects)
5359
+ inArray6(projects.id, grants2.projects),
5360
+ inArray6(projects.id, grantedActionProjects)
5192
5361
  );
5193
5362
  }
5194
5363
 
5195
5364
  // server/projects/views.ts
5196
- import { eq as eq56 } from "drizzle-orm";
5365
+ import { eq as eq59 } from "drizzle-orm";
5197
5366
  function serializeProject(ctx, row) {
5198
5367
  const executor2 = executorsRepository(ctx).list(
5199
- eq56(executors.projectId, row.id)
5368
+ eq59(executors.projectId, row.id)
5200
5369
  )[0];
5201
- const pluginIds = pluginsRepository(ctx).list(eq56(plugins.projectId, row.id)).map((plugin) => plugin.id);
5370
+ const pluginIds = pluginsRepository(ctx).list(eq59(plugins.projectId, row.id)).map((plugin) => plugin.id);
5202
5371
  const minimal = {
5203
5372
  id: row.id,
5204
5373
  name: row.name,
@@ -5229,8 +5398,8 @@ function serializeProject(ctx, row) {
5229
5398
  var listProcedure9 = scopedProcedure("catalog:read").query(
5230
5399
  ({ ctx }) => {
5231
5400
  const projects2 = ctx.db.select().from(projects).where(
5232
- and41(
5233
- eq57(projects.workspaceId, ctx.workspace.id),
5401
+ and43(
5402
+ eq60(projects.workspaceId, ctx.workspace.id),
5234
5403
  projectVisibility(ctx.db, ctx.workspace.id, ctx.token)
5235
5404
  )
5236
5405
  ).all();
@@ -5239,12 +5408,12 @@ var listProcedure9 = scopedProcedure("catalog:read").query(
5239
5408
  );
5240
5409
 
5241
5410
  // server/router/projects/get.ts
5242
- import { and as and42, eq as eq58 } from "drizzle-orm";
5411
+ import { and as and44, eq as eq61 } from "drizzle-orm";
5243
5412
  var getProcedure10 = scopedProcedure("catalog:read").input(projectIdSchema).query(({ ctx, input: input2 }) => {
5244
5413
  const project = ctx.db.select().from(projects).where(
5245
- and42(
5246
- eq58(projects.workspaceId, ctx.workspace.id),
5247
- eq58(projects.id, input2.id),
5414
+ and44(
5415
+ eq61(projects.workspaceId, ctx.workspace.id),
5416
+ eq61(projects.id, input2.id),
5248
5417
  projectVisibility(ctx.db, ctx.workspace.id, ctx.token)
5249
5418
  )
5250
5419
  ).get();
@@ -5255,12 +5424,12 @@ var getProcedure10 = scopedProcedure("catalog:read").input(projectIdSchema).quer
5255
5424
  });
5256
5425
 
5257
5426
  // server/repositories/workspace-tables.ts
5258
- import { and as and43, eq as eq59 } from "drizzle-orm";
5427
+ import { and as and45, eq as eq62 } from "drizzle-orm";
5259
5428
  function findWorkspaceTable(database, workspaceId, id) {
5260
5429
  const record = database.select().from(workspaceTables).where(
5261
- and43(
5262
- eq59(workspaceTables.workspaceId, workspaceId),
5263
- eq59(workspaceTables.id, id)
5430
+ and45(
5431
+ eq62(workspaceTables.workspaceId, workspaceId),
5432
+ eq62(workspaceTables.id, id)
5264
5433
  )
5265
5434
  ).get();
5266
5435
  if (!record) {
@@ -5332,21 +5501,21 @@ var updateProcedure6 = browserManagerProcedure.input(projectChangesSchema).mutat
5332
5501
  });
5333
5502
 
5334
5503
  // server/router/projects/delete.ts
5335
- import { and as and44, eq as eq60 } from "drizzle-orm";
5504
+ import { and as and46, eq as eq63 } from "drizzle-orm";
5336
5505
  var deleteProcedure4 = browserManagerProcedure.input(projectIdSchema).mutation(({ ctx, input: input2 }) => {
5337
5506
  inTransaction(ctx, (transaction) => {
5338
5507
  const projects2 = projectsRepository(transaction);
5339
5508
  projects2.find(input2.id);
5340
5509
  const retainedRun = transaction.db.select({ id: runs.id }).from(runs).where(
5341
- and44(
5342
- eq60(runs.workspaceId, ctx.workspace.id),
5343
- eq60(runs.projectId, input2.id)
5510
+ and46(
5511
+ eq63(runs.workspaceId, ctx.workspace.id),
5512
+ eq63(runs.projectId, input2.id)
5344
5513
  )
5345
5514
  ).limit(1).get();
5346
5515
  const retainedAction = transaction.db.select({ id: actions.id }).from(actions).where(
5347
- and44(
5348
- eq60(actions.workspaceId, ctx.workspace.id),
5349
- eq60(actions.projectId, input2.id)
5516
+ and46(
5517
+ eq63(actions.workspaceId, ctx.workspace.id),
5518
+ eq63(actions.projectId, input2.id)
5350
5519
  )
5351
5520
  ).limit(1).get();
5352
5521
  if (retainedRun || retainedAction) {
@@ -5356,9 +5525,9 @@ var deleteProcedure4 = browserManagerProcedure.input(projectIdSchema).mutation((
5356
5525
  );
5357
5526
  }
5358
5527
  const deleted = transaction.db.delete(projects).where(
5359
- and44(
5360
- eq60(projects.workspaceId, ctx.workspace.id),
5361
- eq60(projects.id, input2.id)
5528
+ and46(
5529
+ eq63(projects.workspaceId, ctx.workspace.id),
5530
+ eq63(projects.id, input2.id)
5362
5531
  )
5363
5532
  ).returning({ id: projects.id }).get();
5364
5533
  if (deleted) {
@@ -5378,20 +5547,20 @@ import { createHmac as createHmac2, randomUUID as randomUUID4 } from "node:crypt
5378
5547
 
5379
5548
  // server/projects/executor.ts
5380
5549
  import { randomUUID as randomUUID3 } from "node:crypto";
5381
- import { and as and45, eq as eq61, inArray as inArray6 } from "drizzle-orm";
5550
+ import { and as and47, eq as eq64, inArray as inArray7 } from "drizzle-orm";
5382
5551
  function revokeExecutor(ctx, id) {
5383
5552
  const workspaceId = requireWorkspace(ctx).id;
5384
5553
  const worker = ctx.db.select().from(executors).where(
5385
- and45(eq61(executors.workspaceId, workspaceId), eq61(executors.projectId, id))
5554
+ and47(eq64(executors.workspaceId, workspaceId), eq64(executors.projectId, id))
5386
5555
  ).get();
5387
5556
  if (!worker) {
5388
5557
  return;
5389
5558
  }
5390
5559
  const activeRuns = ctx.db.select().from(runs).where(
5391
- and45(
5392
- eq61(runs.workspaceId, workspaceId),
5393
- eq61(runs.executorId, worker.id),
5394
- inArray6(runs.status, ["running", "waiting_approval"])
5560
+ and47(
5561
+ eq64(runs.workspaceId, workspaceId),
5562
+ eq64(runs.executorId, worker.id),
5563
+ inArray7(runs.status, ["running", "waiting_approval"])
5395
5564
  )
5396
5565
  ).all();
5397
5566
  for (const run of activeRuns) {
@@ -5403,10 +5572,10 @@ function revokeExecutor(ctx, id) {
5403
5572
  leaseExpiresAt: null
5404
5573
  });
5405
5574
  const pendingApprovals = ctx.db.select().from(approvals).where(
5406
- and45(
5407
- eq61(approvals.workspaceId, workspaceId),
5408
- eq61(approvals.runId, run.id),
5409
- eq61(approvals.status, "pending")
5575
+ and47(
5576
+ eq64(approvals.workspaceId, workspaceId),
5577
+ eq64(approvals.runId, run.id),
5578
+ eq64(approvals.status, "pending")
5410
5579
  )
5411
5580
  ).all();
5412
5581
  for (const approval of pendingApprovals) {
@@ -5495,17 +5664,17 @@ var projectsRouter = router({
5495
5664
  });
5496
5665
 
5497
5666
  // server/router/runs/list.ts
5498
- import { and as and46, desc as desc4, eq as eq62, inArray as inArray7, or as or4 } from "drizzle-orm";
5667
+ import { and as and48, desc as desc4, eq as eq65, inArray as inArray8, or as or4 } from "drizzle-orm";
5499
5668
  var listProcedure10 = scopedProcedure("runs:read").query(({ ctx }) => {
5500
5669
  const token = ctx.token;
5501
- const grant = token ? and46(
5502
- eq62(runs.tokenId, token.id),
5670
+ const grant = token ? and48(
5671
+ eq65(runs.tokenId, token.id),
5503
5672
  or4(
5504
- inArray7(runs.projectId, token.projects),
5505
- inArray7(runs.actionVersionId, token.actionVersions)
5673
+ inArray8(runs.projectId, token.projects),
5674
+ inArray8(runs.actionVersionId, token.actionVersions)
5506
5675
  )
5507
5676
  ) : void 0;
5508
- const visibleRuns = ctx.db.select().from(runs).where(and46(eq62(runs.workspaceId, ctx.workspace.id), grant)).orderBy(desc4(runs.createdAt)).all();
5677
+ const visibleRuns = ctx.db.select().from(runs).where(and48(eq65(runs.workspaceId, ctx.workspace.id), grant)).orderBy(desc4(runs.createdAt)).all();
5509
5678
  return page(visibleRuns.map(serializeRun));
5510
5679
  });
5511
5680
 
@@ -5523,16 +5692,16 @@ var createProcedure7 = protectedProcedure.input(createRunSchema).mutation(({ ctx
5523
5692
  });
5524
5693
 
5525
5694
  // server/router/runs/events.ts
5526
- import { and as and47, asc as asc3, eq as eq63 } from "drizzle-orm";
5695
+ import { and as and49, asc as asc4, eq as eq66 } from "drizzle-orm";
5527
5696
  var eventsProcedure = scopedProcedure("runs:read").input(runIdSchema).query(({ ctx, input: input2 }) => {
5528
5697
  const run = runsRepository(ctx).find(input2.id);
5529
5698
  authorizeRunRead(ctx, run, null);
5530
5699
  const events = ctx.db.select().from(runEvents).where(
5531
- and47(
5532
- eq63(runEvents.workspaceId, ctx.workspace.id),
5533
- eq63(runEvents.runId, input2.id)
5700
+ and49(
5701
+ eq66(runEvents.workspaceId, ctx.workspace.id),
5702
+ eq66(runEvents.runId, input2.id)
5534
5703
  )
5535
- ).orderBy(asc3(runEvents.sequence)).all();
5704
+ ).orderBy(asc4(runEvents.sequence)).all();
5536
5705
  return events.map((event) => ({
5537
5706
  sequence: event.sequence,
5538
5707
  kind: event.kind,
@@ -5615,7 +5784,7 @@ var retryProcedure = protectedProcedure.input(retryRunSchema).mutation(
5615
5784
  );
5616
5785
 
5617
5786
  // server/router/runs/cancel.ts
5618
- import { and as and48, eq as eq64 } from "drizzle-orm";
5787
+ import { and as and50, eq as eq67 } from "drizzle-orm";
5619
5788
  var cancelProcedure = scopedProcedure("runs:cancel").input(runIdSchema).mutation(({ ctx, input: input2 }) => {
5620
5789
  const id = input2.id;
5621
5790
  const updated = inTransaction(ctx, (ctx2) => {
@@ -5629,10 +5798,10 @@ var cancelProcedure = scopedProcedure("runs:cancel").input(runIdSchema).mutation
5629
5798
  cancelRequested: true
5630
5799
  });
5631
5800
  const pendingApprovals = ctx2.db.select().from(approvals).where(
5632
- and48(
5633
- eq64(approvals.workspaceId, ctx2.workspace.id),
5634
- eq64(approvals.runId, id),
5635
- eq64(approvals.status, "pending")
5801
+ and50(
5802
+ eq67(approvals.workspaceId, ctx2.workspace.id),
5803
+ eq67(approvals.runId, id),
5804
+ eq67(approvals.status, "pending")
5636
5805
  )
5637
5806
  ).all();
5638
5807
  for (const approval of pendingApprovals) {
@@ -5688,7 +5857,7 @@ var promoteProcedure = scopedProcedure(["runs:read", "actions:write"]).input(pro
5688
5857
 
5689
5858
  // server/router/runs/stream.ts
5690
5859
  import { setTimeout } from "node:timers/promises";
5691
- import { and as and49, asc as asc4, eq as eq65, gt as gt4 } from "drizzle-orm";
5860
+ import { and as and51, asc as asc5, eq as eq68, gt as gt5 } from "drizzle-orm";
5692
5861
  var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscription(async function* ({ ctx, input: input2, signal }) {
5693
5862
  const run = runsRepository(ctx).find(input2.id);
5694
5863
  authorizeRunRead(ctx, run, null);
@@ -5698,9 +5867,9 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
5698
5867
  return;
5699
5868
  }
5700
5869
  const membership = ctx.db.select().from(memberships).where(
5701
- and49(
5702
- eq65(memberships.workspaceId, ctx.workspace.id),
5703
- eq65(memberships.userId, ctx.userId)
5870
+ and51(
5871
+ eq68(memberships.workspaceId, ctx.workspace.id),
5872
+ eq68(memberships.userId, ctx.userId)
5704
5873
  )
5705
5874
  ).get();
5706
5875
  if (!membership) {
@@ -5709,9 +5878,9 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
5709
5878
  let currentContext = ctx;
5710
5879
  if (ctx.token) {
5711
5880
  const token = ctx.db.select().from(accessTokens).where(
5712
- and49(
5713
- eq65(accessTokens.id, ctx.token.id),
5714
- eq65(accessTokens.workspaceId, ctx.workspace.id)
5881
+ and51(
5882
+ eq68(accessTokens.id, ctx.token.id),
5883
+ eq68(accessTokens.workspaceId, ctx.workspace.id)
5715
5884
  )
5716
5885
  ).get();
5717
5886
  if (!token || token.revoked) {
@@ -5731,12 +5900,12 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
5731
5900
  }
5732
5901
  const current = runsRepository(currentContext).find(input2.id);
5733
5902
  const batch = currentContext.db.select().from(runEvents).where(
5734
- and49(
5735
- eq65(runEvents.workspaceId, ctx.workspace.id),
5736
- eq65(runEvents.runId, input2.id),
5737
- gt4(runEvents.sequence, after)
5903
+ and51(
5904
+ eq68(runEvents.workspaceId, ctx.workspace.id),
5905
+ eq68(runEvents.runId, input2.id),
5906
+ gt5(runEvents.sequence, after)
5738
5907
  )
5739
- ).orderBy(asc4(runEvents.sequence)).limit(100).all();
5908
+ ).orderBy(asc5(runEvents.sequence)).limit(100).all();
5740
5909
  for (const event of batch) {
5741
5910
  after = event.sequence;
5742
5911
  yield {
@@ -5774,7 +5943,7 @@ var runsRouter = router({
5774
5943
  });
5775
5944
 
5776
5945
  // server/router/schedules/list.ts
5777
- import { eq as eq66 } from "drizzle-orm";
5946
+ import { eq as eq69 } from "drizzle-orm";
5778
5947
 
5779
5948
  // server/automations/schedule-view.ts
5780
5949
  function scheduleView(schedule) {
@@ -5790,21 +5959,21 @@ function scheduleView(schedule) {
5790
5959
 
5791
5960
  // server/router/schedules/list.ts
5792
5961
  var listProcedure11 = browserWorkspaceProcedure.query(({ ctx }) => {
5793
- const records = ctx.db.select().from(schedules).where(eq66(schedules.workspaceId, ctx.workspace.id)).all();
5962
+ const records = ctx.db.select().from(schedules).where(eq69(schedules.workspaceId, ctx.workspace.id)).all();
5794
5963
  return page(records.map((record) => scheduleView(record)));
5795
5964
  });
5796
5965
 
5797
5966
  // server/router/schedules/get.ts
5798
- import { z as z30 } from "zod";
5967
+ import { z as z33 } from "zod";
5799
5968
 
5800
5969
  // server/repositories/schedules.ts
5801
- import { and as and50, eq as eq67 } from "drizzle-orm";
5970
+ import { and as and52, eq as eq70 } from "drizzle-orm";
5802
5971
  function schedulesRepository(context) {
5803
5972
  const workspaceId = requireWorkspace(context).id;
5804
5973
  return {
5805
5974
  find(id) {
5806
5975
  const record = context.db.select().from(schedules).where(
5807
- and50(eq67(schedules.workspaceId, workspaceId), eq67(schedules.id, id))
5976
+ and52(eq70(schedules.workspaceId, workspaceId), eq70(schedules.id, id))
5808
5977
  ).get();
5809
5978
  if (!record) {
5810
5979
  throw new ServiceError("NOT_FOUND", "Not found.");
@@ -5815,21 +5984,21 @@ function schedulesRepository(context) {
5815
5984
  }
5816
5985
 
5817
5986
  // server/router/schedules/get.ts
5818
- var getProcedure12 = browserWorkspaceProcedure.input(z30.object({ id: z30.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
5987
+ var getProcedure12 = browserWorkspaceProcedure.input(z33.object({ id: z33.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
5819
5988
  const id = input2.id;
5820
5989
  return scheduleView(schedulesRepository(context).find(id));
5821
5990
  });
5822
5991
 
5823
5992
  // server/automations/schedule-schemas.ts
5824
- import { z as z31 } from "zod";
5825
- var scheduleFields = z31.object({
5826
- action: z31.uuid(),
5827
- cron: z31.string().trim().min(1).max(100),
5828
- inputs: z31.json().optional(),
5829
- enabled: z31.boolean().optional()
5993
+ import { z as z34 } from "zod";
5994
+ var scheduleFields = z34.object({
5995
+ action: z34.uuid(),
5996
+ cron: z34.string().trim().min(1).max(100),
5997
+ inputs: z34.json().optional(),
5998
+ enabled: z34.boolean().optional()
5830
5999
  });
5831
6000
  var scheduleCreateSchema = scheduleFields.strict();
5832
- var scheduleUpdateSchema = scheduleFields.partial().extend({ id: z31.uuid() }).strict();
6001
+ var scheduleUpdateSchema = scheduleFields.partial().extend({ id: z34.uuid() }).strict();
5833
6002
 
5834
6003
  // server/automations/cron.ts
5835
6004
  import { CronExpressionParser } from "cron-parser";
@@ -5880,7 +6049,7 @@ var createProcedure8 = browserWorkspaceProcedure.input(scheduleCreateSchema).mut
5880
6049
  });
5881
6050
 
5882
6051
  // server/router/schedules/update.ts
5883
- import { and as and51, eq as eq68 } from "drizzle-orm";
6052
+ import { and as and53, eq as eq71 } from "drizzle-orm";
5884
6053
  var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mutation(({ ctx: context, input: input2 }) => {
5885
6054
  return inTransaction(context, (context2) => {
5886
6055
  const previous = schedulesRepository(context2).find(input2.id);
@@ -5903,9 +6072,9 @@ var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mut
5903
6072
  nextRunAt,
5904
6073
  updatedAt: now()
5905
6074
  }).where(
5906
- and51(
5907
- eq68(schedules.workspaceId, context2.workspace.id),
5908
- eq68(schedules.id, input2.id)
6075
+ and53(
6076
+ eq71(schedules.workspaceId, context2.workspace.id),
6077
+ eq71(schedules.id, input2.id)
5909
6078
  )
5910
6079
  ).returning().get();
5911
6080
  if (!schedule) {
@@ -5917,15 +6086,15 @@ var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mut
5917
6086
  });
5918
6087
 
5919
6088
  // server/router/schedules/delete.ts
5920
- import { and as and52, eq as eq69 } from "drizzle-orm";
5921
- import { z as z32 } from "zod";
5922
- var deleteProcedure5 = browserWorkspaceProcedure.input(z32.object({ id: z32.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
6089
+ import { and as and54, eq as eq72 } from "drizzle-orm";
6090
+ import { z as z35 } from "zod";
6091
+ var deleteProcedure5 = browserWorkspaceProcedure.input(z35.object({ id: z35.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
5923
6092
  const id = input2.id;
5924
6093
  return inTransaction(context, (context2) => {
5925
6094
  const deleted = context2.db.delete(schedules).where(
5926
- and52(
5927
- eq69(schedules.workspaceId, context2.workspace.id),
5928
- eq69(schedules.id, id)
6095
+ and54(
6096
+ eq72(schedules.workspaceId, context2.workspace.id),
6097
+ eq72(schedules.id, id)
5929
6098
  )
5930
6099
  ).returning({ id: schedules.id }).get();
5931
6100
  if (!deleted) {
@@ -5945,8 +6114,8 @@ var schedulesRouter = router({
5945
6114
  });
5946
6115
 
5947
6116
  // server/router/studio/approve.ts
5948
- import { z as z33 } from "zod";
5949
- var approve = browserWorkspaceProcedure.input(z33.object({ challenge: z33.string().regex(/^[0-9a-f]{64}$/) }).strict()).mutation(({ ctx, input: input2 }) => {
6117
+ import { z as z36 } from "zod";
6118
+ var approve = browserWorkspaceProcedure.input(z36.object({ challenge: z36.string().regex(/^[0-9a-f]{64}$/) }).strict()).mutation(({ ctx, input: input2 }) => {
5950
6119
  if (ctx.studioOrigin || !ctx.sessionId || ctx.request.headers.get("origin") !== ctx.origin) {
5951
6120
  throw new ServiceError(
5952
6121
  "FORBIDDEN",
@@ -5965,13 +6134,18 @@ var discover = publicProcedure.query(({ ctx }) => {
5965
6134
  "Studio is disabled for this installation."
5966
6135
  );
5967
6136
  }
5968
- return { product: "orgsdk", protocol: 1, audience };
6137
+ return {
6138
+ product: "orgsdk",
6139
+ protocol: 1,
6140
+ audience,
6141
+ localSignIn: isLoopbackInstallation(ctx.origin)
6142
+ };
5969
6143
  });
5970
6144
 
5971
6145
  // server/router/studio/exchange.ts
5972
- import { z as z34 } from "zod";
6146
+ import { z as z37 } from "zod";
5973
6147
  var exchange = publicProcedure.input(
5974
- z34.object({ code: z34.string().length(43), verifier: z34.string().length(64) }).strict()
6148
+ z37.object({ code: z37.string().length(43), verifier: z37.string().length(64) }).strict()
5975
6149
  ).mutation(({ ctx, input: input2 }) => {
5976
6150
  if (!ctx.studioOrigin) {
5977
6151
  throw new ServiceError("FORBIDDEN", "Open the configured dashboard.");
@@ -6001,7 +6175,7 @@ var systemRouter = router({
6001
6175
  });
6002
6176
 
6003
6177
  // server/router/tables/list.ts
6004
- import { eq as eq70 } from "drizzle-orm";
6178
+ import { eq as eq73 } from "drizzle-orm";
6005
6179
 
6006
6180
  // server/tables/views.ts
6007
6181
  function standard(row) {
@@ -6026,48 +6200,48 @@ function rowView(row) {
6026
6200
 
6027
6201
  // server/router/tables/list.ts
6028
6202
  var listProcedure12 = browserWorkspaceProcedure.query(({ ctx }) => {
6029
- const records = ctx.db.select().from(workspaceTables).where(eq70(workspaceTables.workspaceId, ctx.workspace.id)).all();
6203
+ const records = ctx.db.select().from(workspaceTables).where(eq73(workspaceTables.workspaceId, ctx.workspace.id)).all();
6030
6204
  return page(records.map((record) => standard(record)));
6031
6205
  });
6032
6206
 
6033
6207
  // server/tables/schemas.ts
6034
- import { z as z35 } from "zod";
6035
- var identifier4 = z35.uuid();
6036
- var revision = z35.number().int().positive();
6037
- var columns = z35.array(
6038
- z35.strictObject({
6039
- key: z35.string(),
6040
- type: z35.enum(["text", "number", "boolean", "date"]),
6041
- required: z35.boolean()
6208
+ import { z as z38 } from "zod";
6209
+ var identifier4 = z38.uuid();
6210
+ var revision = z38.number().int().positive();
6211
+ var columns = z38.array(
6212
+ z38.strictObject({
6213
+ key: z38.string(),
6214
+ type: z38.enum(["text", "number", "boolean", "date"]),
6215
+ required: z38.boolean()
6042
6216
  })
6043
6217
  );
6044
- var values = z35.record(z35.string(), z35.json());
6045
- var tableIdSchema = z35.strictObject({ id: identifier4 });
6046
- var createTableSchema = z35.strictObject({ name: z35.string(), columns });
6047
- var updateTableSchema = z35.strictObject({
6218
+ var values = z38.record(z38.string(), z38.json());
6219
+ var tableIdSchema = z38.strictObject({ id: identifier4 });
6220
+ var createTableSchema = z38.strictObject({ name: z38.string(), columns });
6221
+ var updateTableSchema = z38.strictObject({
6048
6222
  id: identifier4,
6049
6223
  revision,
6050
- name: z35.string().optional(),
6224
+ name: z38.string().optional(),
6051
6225
  columns: columns.optional()
6052
6226
  });
6053
- var deleteTableSchema = z35.strictObject({ id: identifier4, revision });
6054
- var tableRowSchema = z35.strictObject({
6227
+ var deleteTableSchema = z38.strictObject({ id: identifier4, revision });
6228
+ var tableRowSchema = z38.strictObject({
6055
6229
  id: identifier4,
6056
6230
  rowId: identifier4
6057
6231
  });
6058
- var createRowSchema = z35.strictObject({
6232
+ var createRowSchema = z38.strictObject({
6059
6233
  id: identifier4,
6060
6234
  table_revision: revision,
6061
6235
  values
6062
6236
  });
6063
- var updateRowSchema = z35.strictObject({
6237
+ var updateRowSchema = z38.strictObject({
6064
6238
  id: identifier4,
6065
6239
  rowId: identifier4,
6066
6240
  table_revision: revision,
6067
6241
  revision,
6068
6242
  values
6069
6243
  });
6070
- var deleteRowSchema = z35.strictObject({
6244
+ var deleteRowSchema = z38.strictObject({
6071
6245
  id: identifier4,
6072
6246
  rowId: identifier4,
6073
6247
  revision
@@ -6093,15 +6267,15 @@ var createProcedure9 = browserManagerProcedure.input(createTableSchema).mutation
6093
6267
  );
6094
6268
 
6095
6269
  // server/router/tables/update.ts
6096
- import { and as and54, eq as eq72 } from "drizzle-orm";
6270
+ import { and as and56, eq as eq75 } from "drizzle-orm";
6097
6271
 
6098
6272
  // server/tables/queries.ts
6099
- import { and as and53, eq as eq71 } from "drizzle-orm";
6273
+ import { and as and55, eq as eq74 } from "drizzle-orm";
6100
6274
  function rowsForTable(database, workspaceId, tableId2) {
6101
6275
  return database.select().from(tableRows).where(
6102
- and53(
6103
- eq71(tableRows.workspaceId, workspaceId),
6104
- eq71(tableRows.tableId, tableId2)
6276
+ and55(
6277
+ eq74(tableRows.workspaceId, workspaceId),
6278
+ eq74(tableRows.tableId, tableId2)
6105
6279
  )
6106
6280
  ).all();
6107
6281
  }
@@ -6122,9 +6296,9 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
6122
6296
  revision: current.revision + 1,
6123
6297
  updatedAt: now()
6124
6298
  }).where(
6125
- and54(
6126
- eq72(workspaceTables.workspaceId, ctx2.workspace.id),
6127
- eq72(workspaceTables.id, input2.id)
6299
+ and56(
6300
+ eq75(workspaceTables.workspaceId, ctx2.workspace.id),
6301
+ eq75(workspaceTables.id, input2.id)
6128
6302
  )
6129
6303
  ).returning().get();
6130
6304
  if (!table) {
@@ -6137,14 +6311,14 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
6137
6311
  });
6138
6312
 
6139
6313
  // server/router/tables/delete.ts
6140
- import { and as and56, eq as eq74 } from "drizzle-orm";
6314
+ import { and as and58, eq as eq77 } from "drizzle-orm";
6141
6315
 
6142
6316
  // server/repositories/table-rows.ts
6143
- import { and as and55, eq as eq73 } from "drizzle-orm";
6317
+ import { and as and57, eq as eq76 } from "drizzle-orm";
6144
6318
  function removeTableRow(context, id) {
6145
6319
  const workspaceId = requireWorkspace(context).id;
6146
6320
  inTransaction(context, (transaction) => {
6147
- const deleted = transaction.db.delete(tableRows).where(and55(eq73(tableRows.workspaceId, workspaceId), eq73(tableRows.id, id))).returning({ id: tableRows.id }).get();
6321
+ const deleted = transaction.db.delete(tableRows).where(and57(eq76(tableRows.workspaceId, workspaceId), eq76(tableRows.id, id))).returning({ id: tableRows.id }).get();
6148
6322
  if (deleted) {
6149
6323
  recordAudit(transaction, "row", id, "deleted");
6150
6324
  }
@@ -6172,9 +6346,9 @@ var deleteProcedure6 = browserManagerProcedure.input(deleteTableSchema).mutation
6172
6346
  });
6173
6347
  }
6174
6348
  const deleted = ctx2.db.delete(workspaceTables).where(
6175
- and56(
6176
- eq74(workspaceTables.workspaceId, ctx2.workspace.id),
6177
- eq74(workspaceTables.id, input2.id)
6349
+ and58(
6350
+ eq77(workspaceTables.workspaceId, ctx2.workspace.id),
6351
+ eq77(workspaceTables.id, input2.id)
6178
6352
  )
6179
6353
  ).returning({ id: workspaceTables.id }).get();
6180
6354
  if (deleted) {
@@ -6191,13 +6365,13 @@ var listRowsProcedure = browserWorkspaceProcedure.input(tableIdSchema).query(({
6191
6365
  });
6192
6366
 
6193
6367
  // server/tables/access.ts
6194
- import { and as and57, eq as eq75 } from "drizzle-orm";
6368
+ import { and as and59, eq as eq78 } from "drizzle-orm";
6195
6369
  function rowInTable(database, workspaceId, tableId2, rowId) {
6196
6370
  const row = database.select().from(tableRows).where(
6197
- and57(
6198
- eq75(tableRows.workspaceId, workspaceId),
6199
- eq75(tableRows.tableId, tableId2),
6200
- eq75(tableRows.id, rowId)
6371
+ and59(
6372
+ eq78(tableRows.workspaceId, workspaceId),
6373
+ eq78(tableRows.tableId, tableId2),
6374
+ eq78(tableRows.id, rowId)
6201
6375
  )
6202
6376
  ).get();
6203
6377
  if (!row) {
@@ -6232,7 +6406,7 @@ var createRowProcedure = browserWorkspaceProcedure.input(createRowSchema).mutati
6232
6406
  });
6233
6407
 
6234
6408
  // server/router/tables/update-row.ts
6235
- import { and as and58, eq as eq76 } from "drizzle-orm";
6409
+ import { and as and60, eq as eq79 } from "drizzle-orm";
6236
6410
  var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutation(({ ctx, input: input2 }) => {
6237
6411
  return rowView(
6238
6412
  inTransaction(ctx, (ctx2) => {
@@ -6246,9 +6420,9 @@ var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutati
6246
6420
  revision: row.revision + 1,
6247
6421
  updatedAt: now()
6248
6422
  }).where(
6249
- and58(
6250
- eq76(tableRows.workspaceId, ctx2.workspace.id),
6251
- eq76(tableRows.id, input2.rowId)
6423
+ and60(
6424
+ eq79(tableRows.workspaceId, ctx2.workspace.id),
6425
+ eq79(tableRows.id, input2.rowId)
6252
6426
  )
6253
6427
  ).returning().get();
6254
6428
  if (!updatedRow) {
@@ -6288,7 +6462,7 @@ var tablesRouter = router({
6288
6462
  });
6289
6463
 
6290
6464
  // server/router/tokens/list.ts
6291
- import { eq as eq77 } from "drizzle-orm";
6465
+ import { eq as eq80 } from "drizzle-orm";
6292
6466
 
6293
6467
  // server/tokens/views.ts
6294
6468
  function tokenView(row) {
@@ -6316,18 +6490,18 @@ function tokenView(row) {
6316
6490
 
6317
6491
  // server/router/tokens/list.ts
6318
6492
  var listProcedure13 = browserManagerProcedure.query(({ ctx }) => {
6319
- const records = ctx.db.select().from(accessTokens).where(eq77(accessTokens.workspaceId, ctx.workspace.id)).all();
6493
+ const records = ctx.db.select().from(accessTokens).where(eq80(accessTokens.workspaceId, ctx.workspace.id)).all();
6320
6494
  return page(records.map((record) => tokenView(record)));
6321
6495
  });
6322
6496
 
6323
6497
  // server/router/tokens/get.ts
6324
- import { and as and59, eq as eq78 } from "drizzle-orm";
6325
- import { z as z36 } from "zod";
6326
- var getProcedure14 = browserManagerProcedure.input(z36.strictObject({ id: z36.uuid() })).query(({ ctx, input: input2 }) => {
6498
+ import { and as and61, eq as eq81 } from "drizzle-orm";
6499
+ import { z as z39 } from "zod";
6500
+ var getProcedure14 = browserManagerProcedure.input(z39.strictObject({ id: z39.uuid() })).query(({ ctx, input: input2 }) => {
6327
6501
  const token = ctx.db.select().from(accessTokens).where(
6328
- and59(
6329
- eq78(accessTokens.workspaceId, ctx.workspace.id),
6330
- eq78(accessTokens.id, input2.id)
6502
+ and61(
6503
+ eq81(accessTokens.workspaceId, ctx.workspace.id),
6504
+ eq81(accessTokens.id, input2.id)
6331
6505
  )
6332
6506
  ).get();
6333
6507
  if (!token) {
@@ -6337,8 +6511,8 @@ var getProcedure14 = browserManagerProcedure.input(z36.strictObject({ id: z36.uu
6337
6511
  });
6338
6512
 
6339
6513
  // server/tokens/schemas.ts
6340
- import { z as z37 } from "zod";
6341
- var clientScopes = z37.enum([
6514
+ import { z as z40 } from "zod";
6515
+ var clientScopes = z40.enum([
6342
6516
  "catalog:read",
6343
6517
  "code:execute",
6344
6518
  "actions:write",
@@ -6347,11 +6521,11 @@ var clientScopes = z37.enum([
6347
6521
  "runs:read",
6348
6522
  "runs:cancel"
6349
6523
  ]);
6350
- var tokenCreateSchema = z37.object({
6351
- name: z37.string().trim().min(1).max(100),
6352
- scopes: z37.array(clientScopes).min(1),
6353
- projects: z37.array(z37.uuid()).default([]),
6354
- action_versions: z37.array(z37.uuid()).default([])
6524
+ var tokenCreateSchema = z40.object({
6525
+ name: z40.string().trim().min(1).max(100),
6526
+ scopes: z40.array(clientScopes).min(1),
6527
+ projects: z40.array(z40.uuid()).default([]),
6528
+ action_versions: z40.array(z40.uuid()).default([])
6355
6529
  }).strict();
6356
6530
 
6357
6531
  // server/router/tokens/create.ts
@@ -6390,14 +6564,14 @@ var createProcedure10 = browserManagerProcedure.input(tokenCreateSchema).output(
6390
6564
  });
6391
6565
 
6392
6566
  // server/router/tokens/revoke.ts
6393
- import { and as and60, eq as eq79 } from "drizzle-orm";
6394
- import { z as z38 } from "zod";
6395
- var revokeProcedure = browserManagerProcedure.input(z38.strictObject({ id: z38.uuid() })).mutation(({ ctx, input: input2 }) => {
6567
+ import { and as and62, eq as eq82 } from "drizzle-orm";
6568
+ import { z as z41 } from "zod";
6569
+ var revokeProcedure = browserManagerProcedure.input(z41.strictObject({ id: z41.uuid() })).mutation(({ ctx, input: input2 }) => {
6396
6570
  return inTransaction(ctx, (ctx2) => {
6397
6571
  const token = ctx2.db.update(accessTokens).set({ revoked: true, updatedAt: now() }).where(
6398
- and60(
6399
- eq79(accessTokens.workspaceId, ctx2.workspace.id),
6400
- eq79(accessTokens.id, input2.id)
6572
+ and62(
6573
+ eq82(accessTokens.workspaceId, ctx2.workspace.id),
6574
+ eq82(accessTokens.id, input2.id)
6401
6575
  )
6402
6576
  ).returning().get();
6403
6577
  if (!token) {
@@ -6440,20 +6614,20 @@ var usersRouter = router({
6440
6614
  });
6441
6615
 
6442
6616
  // server/router/webhooks/list.ts
6443
- import { eq as eq81 } from "drizzle-orm";
6617
+ import { eq as eq84 } from "drizzle-orm";
6444
6618
 
6445
6619
  // server/automations/webhook-view.ts
6446
- import { desc as desc5, eq as eq80 } from "drizzle-orm";
6447
- import { and as and61 } from "drizzle-orm";
6620
+ import { desc as desc5, eq as eq83 } from "drizzle-orm";
6621
+ import { and as and63 } from "drizzle-orm";
6448
6622
  function webhookView(context, webhook) {
6449
6623
  const version = actionVersionsRepository(context).find(
6450
6624
  webhook.actionVersionId
6451
6625
  );
6452
6626
  const action = actionsRepository(context).find(version.actionId);
6453
6627
  const deliveries = context.db.select().from(webhookDeliveries).where(
6454
- and61(
6455
- eq80(webhookDeliveries.workspaceId, workspace(context)),
6456
- eq80(webhookDeliveries.webhookId, webhook.id)
6628
+ and63(
6629
+ eq83(webhookDeliveries.workspaceId, workspace(context)),
6630
+ eq83(webhookDeliveries.webhookId, webhook.id)
6457
6631
  )
6458
6632
  ).orderBy(desc5(webhookDeliveries.createdAt)).limit(20).all();
6459
6633
  return {
@@ -6482,19 +6656,19 @@ function webhookView(context, webhook) {
6482
6656
 
6483
6657
  // server/router/webhooks/list.ts
6484
6658
  var listProcedure14 = browserWorkspaceProcedure.query(({ ctx }) => {
6485
- const records = ctx.db.select().from(webhooks).where(eq81(webhooks.workspaceId, ctx.workspace.id)).all();
6659
+ const records = ctx.db.select().from(webhooks).where(eq84(webhooks.workspaceId, ctx.workspace.id)).all();
6486
6660
  return page(records.map((record) => webhookView(ctx, record)));
6487
6661
  });
6488
6662
 
6489
6663
  // server/router/webhooks/get.ts
6490
- import { z as z39 } from "zod";
6664
+ import { z as z42 } from "zod";
6491
6665
 
6492
6666
  // server/repositories/webhooks.ts
6493
- import { and as and62, eq as eq82 } from "drizzle-orm";
6667
+ import { and as and64, eq as eq85 } from "drizzle-orm";
6494
6668
  function webhooksRepository(context) {
6495
6669
  const workspaceId = requireWorkspace(context).id;
6496
6670
  const database = context.db;
6497
- const scoped = (id) => and62(eq82(webhooks.workspaceId, workspaceId), eq82(webhooks.id, id));
6671
+ const scoped = (id) => and64(eq85(webhooks.workspaceId, workspaceId), eq85(webhooks.id, id));
6498
6672
  return {
6499
6673
  find(id) {
6500
6674
  const row = database.select().from(webhooks).where(scoped(id)).get();
@@ -6518,22 +6692,22 @@ function webhooksRepository(context) {
6518
6692
  }
6519
6693
 
6520
6694
  // server/router/webhooks/get.ts
6521
- var getProcedure15 = browserWorkspaceProcedure.input(z39.object({ id: z39.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
6695
+ var getProcedure15 = browserWorkspaceProcedure.input(z42.object({ id: z42.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
6522
6696
  const id = input2.id;
6523
6697
  return webhookView(context, webhooksRepository(context).find(id));
6524
6698
  });
6525
6699
 
6526
6700
  // server/automations/webhook-schemas.ts
6527
- import { z as z40 } from "zod";
6528
- var webhookCreateSchema = z40.object({
6529
- name: z40.string().trim().min(1).max(100),
6530
- action: z40.uuid(),
6531
- enabled: z40.boolean().optional()
6701
+ import { z as z43 } from "zod";
6702
+ var webhookCreateSchema = z43.object({
6703
+ name: z43.string().trim().min(1).max(100),
6704
+ action: z43.uuid(),
6705
+ enabled: z43.boolean().optional()
6532
6706
  }).strict();
6533
- var webhookUpdateSchema = z40.object({
6534
- id: z40.uuid(),
6535
- name: z40.string().trim().min(1).max(100).optional(),
6536
- enabled: z40.boolean().optional()
6707
+ var webhookUpdateSchema = z43.object({
6708
+ id: z43.uuid(),
6709
+ name: z43.string().trim().min(1).max(100).optional(),
6710
+ enabled: z43.boolean().optional()
6537
6711
  }).strict();
6538
6712
 
6539
6713
  // server/router/webhooks/create.ts
@@ -6578,8 +6752,8 @@ var updateProcedure9 = browserManagerProcedure.input(webhookUpdateSchema).mutati
6578
6752
  });
6579
6753
 
6580
6754
  // server/router/webhooks/rotate.ts
6581
- import { z as z41 } from "zod";
6582
- var rotateProcedure = browserManagerProcedure.input(z41.object({ id: z41.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
6755
+ import { z as z44 } from "zod";
6756
+ var rotateProcedure = browserManagerProcedure.input(z44.object({ id: z44.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
6583
6757
  const id = input2.id;
6584
6758
  return inTransaction(context, (context2) => {
6585
6759
  const secret = randomSecret();
@@ -6609,7 +6783,7 @@ var listProcedure15 = browserWorkspaceProcedure.query(({ ctx }) => {
6609
6783
  });
6610
6784
 
6611
6785
  // server/router/workspace/current.ts
6612
- import { eq as eq83 } from "drizzle-orm";
6786
+ import { eq as eq86 } from "drizzle-orm";
6613
6787
 
6614
6788
  // server/workspaces/views.ts
6615
6789
  var serializeInvite = (invitation) => ({
@@ -6628,34 +6802,34 @@ var currentProcedure = browserWorkspaceProcedure.query(({ ctx }) => {
6628
6802
  workspace: { id: workspace2.id, name: workspace2.name },
6629
6803
  role: ctx.role,
6630
6804
  members: memberQuery(ctx.db, workspace2.id).all(),
6631
- invitations: ctx.role && ["owner", "admin"].includes(ctx.role) ? ctx.db.select().from(invitations).where(eq83(invitations.workspaceId, workspace2.id)).all().map(serializeInvite) : []
6805
+ invitations: ctx.role && ["owner", "admin"].includes(ctx.role) ? ctx.db.select().from(invitations).where(eq86(invitations.workspaceId, workspace2.id)).all().map(serializeInvite) : []
6632
6806
  };
6633
6807
  });
6634
6808
 
6635
6809
  // server/router/workspace/update.ts
6636
- import { eq as eq84 } from "drizzle-orm";
6810
+ import { eq as eq87 } from "drizzle-orm";
6637
6811
 
6638
6812
  // server/workspaces/schemas.ts
6639
- import { z as z42 } from "zod";
6640
- var membershipIdSchema = z42.strictObject({
6641
- id: z42.number().int().positive()
6813
+ import { z as z45 } from "zod";
6814
+ var membershipIdSchema = z45.strictObject({
6815
+ id: z45.number().int().positive()
6642
6816
  });
6643
- var workspaceNameSchema = z42.strictObject({
6644
- name: z42.string().trim().min(1).max(100)
6817
+ var workspaceNameSchema = z45.strictObject({
6818
+ name: z45.string().trim().min(1).max(100)
6645
6819
  });
6646
- var roleSchema = z42.enum(["admin", "member"]);
6820
+ var roleSchema = z45.enum(["admin", "member"]);
6647
6821
  var memberUpdateSchema = membershipIdSchema.extend({
6648
6822
  role: roleSchema
6649
6823
  });
6650
- var ownershipSchema = z42.strictObject({
6651
- membership_id: z42.number().int().positive()
6824
+ var ownershipSchema = z45.strictObject({
6825
+ membership_id: z45.number().int().positive()
6652
6826
  });
6653
- var invitationSchema = z42.strictObject({
6827
+ var invitationSchema = z45.strictObject({
6654
6828
  email: emailSchema,
6655
6829
  role: roleSchema
6656
6830
  });
6657
- var invitationTokenSchema = z42.strictObject({
6658
- token: z42.string().min(1)
6831
+ var invitationTokenSchema = z45.strictObject({
6832
+ token: z45.string().min(1)
6659
6833
  });
6660
6834
 
6661
6835
  // server/router/workspace/update.ts
@@ -6672,7 +6846,7 @@ var updateProcedure10 = browserManagerProcedure.input(workspaceNameSchema).mutat
6672
6846
  "Only workspace owners and admins can manage this workspace."
6673
6847
  );
6674
6848
  }
6675
- const updated = ctx2.db.update(workspaces).set({ name: name.trim() }).where(eq84(workspaces.id, workspace2.id)).returning().get();
6849
+ const updated = ctx2.db.update(workspaces).set({ name: name.trim() }).where(eq87(workspaces.id, workspace2.id)).returning().get();
6676
6850
  return { id: updated.id, name: updated.name };
6677
6851
  });
6678
6852
  });
@@ -6700,13 +6874,13 @@ import { randomUUID as randomUUID5 } from "node:crypto";
6700
6874
  import nodemailer from "nodemailer";
6701
6875
 
6702
6876
  // server/repositories/mail-outbox.ts
6703
- import { and as and63, asc as asc5, eq as eq85, isNull, lt as lt3, lte, or as or5 } from "drizzle-orm";
6877
+ import { and as and65, asc as asc6, eq as eq88, isNull, lt as lt3, lte, or as or5 } from "drizzle-orm";
6704
6878
  function enqueueMail(store, message) {
6705
6879
  store.db.insert(mailOutbox).values({ ...message, nextAttempt: Date.now() }).run();
6706
6880
  }
6707
6881
  function revokeUnsentMail(store, id) {
6708
- const unsent = and63(
6709
- eq85(mailOutbox.id, id),
6882
+ const unsent = and65(
6883
+ eq88(mailOutbox.id, id),
6710
6884
  isNull(mailOutbox.sentAt),
6711
6885
  isNull(mailOutbox.leaseUntil)
6712
6886
  );
@@ -6718,29 +6892,29 @@ function claimMail(store, time) {
6718
6892
  isNull(mailOutbox.leaseUntil),
6719
6893
  lt3(mailOutbox.leaseUntil, time)
6720
6894
  );
6721
- const due = and63(
6895
+ const due = and65(
6722
6896
  isNull(mailOutbox.sentAt),
6723
6897
  lte(mailOutbox.nextAttempt, time),
6724
6898
  availableLease
6725
6899
  );
6726
- const row = store2.db.select().from(mailOutbox).where(due).orderBy(asc5(mailOutbox.nextAttempt)).limit(1).get();
6900
+ const row = store2.db.select().from(mailOutbox).where(due).orderBy(asc6(mailOutbox.nextAttempt)).limit(1).get();
6727
6901
  if (!row) {
6728
6902
  return;
6729
6903
  }
6730
6904
  if (row.id.startsWith("invitation:")) {
6731
6905
  const id = Number(row.id.slice("invitation:".length));
6732
- const invitation = store2.db.select().from(invitations).where(eq85(invitations.id, id)).get();
6906
+ const invitation = store2.db.select().from(invitations).where(eq88(invitations.id, id)).get();
6733
6907
  if (!invitation || invitation.acceptedAt || invitation.revokedAt || invitation.expiresAt <= new Date(time).toISOString()) {
6734
- store2.db.delete(mailOutbox).where(eq85(mailOutbox.id, row.id)).run();
6908
+ store2.db.delete(mailOutbox).where(eq88(mailOutbox.id, row.id)).run();
6735
6909
  return;
6736
6910
  }
6737
6911
  }
6738
- store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(eq85(mailOutbox.id, row.id)).run();
6912
+ store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(eq88(mailOutbox.id, row.id)).run();
6739
6913
  return row;
6740
6914
  });
6741
6915
  }
6742
6916
  function markMailSent(store, id) {
6743
- store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(eq85(mailOutbox.id, id)).run();
6917
+ store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(eq88(mailOutbox.id, id)).run();
6744
6918
  }
6745
6919
  function retryMail(store, job) {
6746
6920
  const attempts = job.attempts + 1;
@@ -6750,7 +6924,7 @@ function retryMail(store, job) {
6750
6924
  nextAttempt: Date.now() + delay,
6751
6925
  leaseUntil: null,
6752
6926
  lastError: "Delivery failed"
6753
- }).where(eq85(mailOutbox.id, job.id)).run();
6927
+ }).where(eq88(mailOutbox.id, job.id)).run();
6754
6928
  }
6755
6929
 
6756
6930
  // server/mail/outbox.ts
@@ -6804,7 +6978,7 @@ async function flushOutbox(store, send) {
6804
6978
  }
6805
6979
 
6806
6980
  // server/router/workspace/invite.ts
6807
- import { and as and64, eq as eq86, isNull as isNull2, sql as sql2 } from "drizzle-orm";
6981
+ import { and as and66, eq as eq89, isNull as isNull2, sql as sql3 } from "drizzle-orm";
6808
6982
  var inviteProcedure = browserManagerProcedure.input(invitationSchema).mutation(({ ctx, input: input2 }) => {
6809
6983
  const user = ctx.user;
6810
6984
  const workspace2 = ctx.workspace;
@@ -6842,10 +7016,10 @@ This invitation expires in seven days.`
6842
7016
  "Only the owner can invite admins."
6843
7017
  );
6844
7018
  }
6845
- const existingMember = db.select({ id: memberships.id }).from(memberships).innerJoin(users, eq86(users.id, memberships.userId)).where(
6846
- and64(
6847
- eq86(memberships.workspaceId, workspace2.id),
6848
- sql2`lower(${users.email}) = ${email}`
7019
+ const existingMember = db.select({ id: memberships.id }).from(memberships).innerJoin(users, eq89(users.id, memberships.userId)).where(
7020
+ and66(
7021
+ eq89(memberships.workspaceId, workspace2.id),
7022
+ sql3`lower(${users.email}) = ${email}`
6849
7023
  )
6850
7024
  ).get();
6851
7025
  if (existingMember) {
@@ -6855,9 +7029,9 @@ This invitation expires in seven days.`
6855
7029
  );
6856
7030
  }
6857
7031
  const prior = db.select({ id: invitations.id, expiresAt: invitations.expiresAt }).from(invitations).where(
6858
- and64(
6859
- eq86(invitations.workspaceId, workspace2.id),
6860
- sql2`lower(${invitations.email}) = ${email}`,
7032
+ and66(
7033
+ eq89(invitations.workspaceId, workspace2.id),
7034
+ sql3`lower(${invitations.email}) = ${email}`,
6861
7035
  isNull2(invitations.acceptedAt),
6862
7036
  isNull2(invitations.revokedAt)
6863
7037
  )
@@ -6891,7 +7065,7 @@ This invitation expires in seven days.`
6891
7065
  });
6892
7066
 
6893
7067
  // server/router/workspace/revoke-invitation.ts
6894
- import { and as and65, eq as eq87 } from "drizzle-orm";
7068
+ import { and as and67, eq as eq90 } from "drizzle-orm";
6895
7069
  var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
6896
7070
  const id = input2.id;
6897
7071
  const user = ctx.user;
@@ -6906,9 +7080,9 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
6906
7080
  );
6907
7081
  }
6908
7082
  const invitation = ctx2.db.select().from(invitations).where(
6909
- and65(
6910
- eq87(invitations.workspaceId, workspace2.id),
6911
- eq87(invitations.id, id)
7083
+ and67(
7084
+ eq90(invitations.workspaceId, workspace2.id),
7085
+ eq90(invitations.id, id)
6912
7086
  )
6913
7087
  ).get();
6914
7088
  if (!invitation) {
@@ -6929,7 +7103,7 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
6929
7103
  });
6930
7104
 
6931
7105
  // server/router/workspace/accept-invitation.ts
6932
- import { and as and66, eq as eq88 } from "drizzle-orm";
7106
+ import { and as and68, eq as eq91 } from "drizzle-orm";
6933
7107
  var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTokenSchema).mutation(({ ctx, input: input2 }) => {
6934
7108
  const token = input2.token;
6935
7109
  const user = ctx.user;
@@ -6941,9 +7115,9 @@ var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTo
6941
7115
  throw new ServiceError("NOT_FOUND", "Invitation not found.");
6942
7116
  }
6943
7117
  const invite = db.select().from(invitations).where(
6944
- and66(
6945
- eq88(invitations.workspaceId, workspace2.id),
6946
- eq88(invitations.tokenDigest, digest(token))
7118
+ and68(
7119
+ eq91(invitations.workspaceId, workspace2.id),
7120
+ eq91(invitations.tokenDigest, digest(token))
6947
7121
  )
6948
7122
  ).get();
6949
7123
  if (!invite) {
@@ -7024,7 +7198,7 @@ var updateMemberProcedure = browserOwnerProcedure.input(memberUpdateSchema).muta
7024
7198
  });
7025
7199
 
7026
7200
  // server/router/workspace/remove-member.ts
7027
- import { and as and67, eq as eq89 } from "drizzle-orm";
7201
+ import { and as and69, eq as eq92 } from "drizzle-orm";
7028
7202
  var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
7029
7203
  const id = input2.id;
7030
7204
  inTransaction(ctx, (ctx2) => {
@@ -7037,9 +7211,9 @@ var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).
7037
7211
  );
7038
7212
  }
7039
7213
  ctx2.db.delete(memberships).where(
7040
- and67(
7041
- eq89(memberships.workspaceId, target.workspaceId),
7042
- eq89(memberships.id, id)
7214
+ and69(
7215
+ eq92(memberships.workspaceId, target.workspaceId),
7216
+ eq92(memberships.id, id)
7043
7217
  )
7044
7218
  ).run();
7045
7219
  });
@@ -7110,8 +7284,8 @@ var appRouter = router({
7110
7284
  // server/api/mcp-dispatch.ts
7111
7285
  async function dispatchTool(context, name, toolInput) {
7112
7286
  const caller = appRouter.createCaller(context);
7113
- const id = () => z43.string().parse(toolInput.id);
7114
- const actionId = () => z43.string().parse(toolInput.action);
7287
+ const id = () => z46.string().parse(toolInput.id);
7288
+ const actionId = () => z46.string().parse(toolInput.action);
7115
7289
  const queueSession = (session) => caller.runs.session(
7116
7290
  sessionRunSchema.parse({
7117
7291
  project: toolInput.project,
@@ -7132,7 +7306,7 @@ async function dispatchTool(context, name, toolInput) {
7132
7306
  };
7133
7307
  }
7134
7308
  case "get_project_sdk":
7135
- return caller.projects.sdk({ id: z43.string().parse(toolInput.project) });
7309
+ return caller.projects.sdk({ id: z46.string().parse(toolInput.project) });
7136
7310
  case "execute_code":
7137
7311
  return caller.runs.create(
7138
7312
  createRunSchema.strip().parse({ ...toolInput, operation: "code" })
@@ -7142,23 +7316,23 @@ async function dispatchTool(context, name, toolInput) {
7142
7316
  case "execute_cell":
7143
7317
  return queueSession({
7144
7318
  operation: "execute",
7145
- id: z43.uuid().parse(toolInput.session_id),
7146
- cellId: z43.uuid().parse(toolInput.cell_id),
7147
- generation: z43.number().parse(toolInput.generation),
7148
- expectedSequence: z43.number().parse(toolInput.expected_sequence),
7319
+ id: z46.uuid().parse(toolInput.session_id),
7320
+ cellId: z46.uuid().parse(toolInput.cell_id),
7321
+ generation: z46.number().parse(toolInput.generation),
7322
+ expectedSequence: z46.number().parse(toolInput.expected_sequence),
7149
7323
  after: toolInput.after
7150
7324
  });
7151
7325
  case "read_session":
7152
7326
  return queueSession({
7153
7327
  operation: "read",
7154
- id: z43.uuid().parse(toolInput.session_id),
7328
+ id: z46.uuid().parse(toolInput.session_id),
7155
7329
  after: toolInput.after,
7156
7330
  limit: toolInput.limit
7157
7331
  });
7158
7332
  case "close_session":
7159
7333
  return queueSession({
7160
7334
  operation: "close",
7161
- id: z43.uuid().parse(toolInput.session_id)
7335
+ id: z46.uuid().parse(toolInput.session_id)
7162
7336
  });
7163
7337
  case "get_run_events": {
7164
7338
  const all = await caller.runs.events({ id: id() });
@@ -7235,17 +7409,17 @@ async function dispatchTool(context, name, toolInput) {
7235
7409
  }
7236
7410
 
7237
7411
  // server/api/mcp-schemas.ts
7238
- import { z as z44 } from "zod";
7239
- var mcpArgumentsSchema = z44.object({
7240
- action: z44.string().optional(),
7241
- project: z44.string().optional(),
7242
- id: z44.string().optional(),
7243
- version: z44.number().optional(),
7244
- suite_revision: z44.number().optional(),
7245
- after: z44.number().optional(),
7246
- offset: z44.number().optional(),
7247
- limit: z44.number().optional()
7248
- }).catchall(z44.json());
7412
+ import { z as z47 } from "zod";
7413
+ var mcpArgumentsSchema = z47.object({
7414
+ action: z47.string().optional(),
7415
+ project: z47.string().optional(),
7416
+ id: z47.string().optional(),
7417
+ version: z47.number().optional(),
7418
+ suite_revision: z47.number().optional(),
7419
+ after: z47.number().optional(),
7420
+ offset: z47.number().optional(),
7421
+ limit: z47.number().optional()
7422
+ }).catchall(z47.json());
7249
7423
 
7250
7424
  // server/api/mcp.ts
7251
7425
  import Ajv2 from "ajv";
@@ -7996,18 +8170,18 @@ async function handleMcp(ctx) {
7996
8170
  }
7997
8171
 
7998
8172
  // server/automations/ingress.ts
7999
- import { z as z45 } from "zod";
8000
- import { and as and69, eq as eq91 } from "drizzle-orm";
8173
+ import { z as z48 } from "zod";
8174
+ import { and as and71, eq as eq94 } from "drizzle-orm";
8001
8175
  import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
8002
8176
 
8003
8177
  // server/repositories/webhook-deliveries.ts
8004
- import { and as and68, eq as eq90 } from "drizzle-orm";
8178
+ import { and as and70, eq as eq93 } from "drizzle-orm";
8005
8179
  function webhookDeliveriesRepository(context) {
8006
8180
  const workspaceId = requireWorkspace(context).id;
8007
8181
  const database = context.db;
8008
- const scoped = (id, filter) => and68(
8009
- eq90(webhookDeliveries.workspaceId, workspaceId),
8010
- id === void 0 ? void 0 : eq90(webhookDeliveries.id, id),
8182
+ const scoped = (id, filter) => and70(
8183
+ eq93(webhookDeliveries.workspaceId, workspaceId),
8184
+ id === void 0 ? void 0 : eq93(webhookDeliveries.id, id),
8011
8185
  filter
8012
8186
  );
8013
8187
  return {
@@ -8035,7 +8209,7 @@ async function handleWebhookIngress(ctx) {
8035
8209
  if (ctx.request.method !== "POST") {
8036
8210
  throw new HttpError(405, "Method not allowed.");
8037
8211
  }
8038
- const hook = ctx.db.select().from(webhooks).where(eq91(webhooks.id, match[1])).get();
8212
+ const hook = ctx.db.select().from(webhooks).where(eq94(webhooks.id, match[1])).get();
8039
8213
  if (!hook || !ctx.workspace || hook.workspaceId !== ctx.workspace.id) {
8040
8214
  throw new HttpError(404, "Webhook not found.");
8041
8215
  }
@@ -8070,9 +8244,9 @@ async function handleWebhookIngress(ctx) {
8070
8244
  jsonValue(payload.inputs, "Inputs");
8071
8245
  const actor = identityRepository(ctx.db).user(hook.actorId);
8072
8246
  const member = ctx.db.select().from(memberships).where(
8073
- and69(
8074
- eq91(memberships.userId, hook.actorId),
8075
- eq91(memberships.workspaceId, hook.workspaceId)
8247
+ and71(
8248
+ eq94(memberships.userId, hook.actorId),
8249
+ eq94(memberships.workspaceId, hook.workspaceId)
8076
8250
  )
8077
8251
  ).get();
8078
8252
  if (!hook.enabled || !actor || !member) {
@@ -8093,9 +8267,9 @@ async function handleWebhookIngress(ctx) {
8093
8267
  throw new HttpError(403, "Webhook is unavailable.");
8094
8268
  }
8095
8269
  const old = webhookDeliveriesRepository(actorCtx2).list(
8096
- and69(
8097
- eq91(webhookDeliveries.webhookId, hook.id),
8098
- eq91(webhookDeliveries.deliveryId, delivery)
8270
+ and71(
8271
+ eq94(webhookDeliveries.webhookId, hook.id),
8272
+ eq94(webhookDeliveries.deliveryId, delivery)
8099
8273
  )
8100
8274
  )[0];
8101
8275
  if (old) {
@@ -8115,7 +8289,7 @@ async function handleWebhookIngress(ctx) {
8115
8289
  operation: "action",
8116
8290
  action: action.id,
8117
8291
  version: version.number,
8118
- inputs: z45.record(z45.string(), z45.json()).parse(payload.inputs),
8292
+ inputs: z48.record(z48.string(), z48.json()).parse(payload.inputs),
8119
8293
  idempotency_key: `webhook:${hook.id}:${delivery}`
8120
8294
  });
8121
8295
  runsRepository(actorCtx2).update(run.id, {
@@ -8138,7 +8312,7 @@ async function handleWebhookIngress(ctx) {
8138
8312
  }
8139
8313
 
8140
8314
  // server/execution/authority.ts
8141
- import { and as and70, eq as eq92 } from "drizzle-orm";
8315
+ import { and as and72, eq as eq95 } from "drizzle-orm";
8142
8316
  import { timingSafeEqual as timingSafeEqual3 } from "node:crypto";
8143
8317
  var terminal = /* @__PURE__ */ new Set([
8144
8318
  "succeeded",
@@ -8156,15 +8330,15 @@ function bearer(ctx) {
8156
8330
  }
8157
8331
  function executor(ctx) {
8158
8332
  const row = ctx.db.select().from(executors).where(
8159
- and70(
8160
- eq92(executors.tokenHash, digest(bearer(ctx))),
8161
- eq92(executors.enabled, true)
8333
+ and72(
8334
+ eq95(executors.tokenHash, digest(bearer(ctx))),
8335
+ eq95(executors.enabled, true)
8162
8336
  )
8163
8337
  ).get();
8164
8338
  const project = row && ctx.db.select().from(projects).where(
8165
- and70(
8166
- eq92(projects.id, row.projectId),
8167
- eq92(projects.workspaceId, row.workspaceId)
8339
+ and72(
8340
+ eq95(projects.id, row.projectId),
8341
+ eq95(projects.workspaceId, row.workspaceId)
8168
8342
  )
8169
8343
  ).get();
8170
8344
  if (!row || !project?.enabled) {
@@ -8173,17 +8347,17 @@ function executor(ctx) {
8173
8347
  return row;
8174
8348
  }
8175
8349
  function runCapability(ctx, expectedId) {
8176
- const run = ctx.db.select().from(runs).where(eq92(runs.capabilityHash, digest(bearer(ctx)))).get();
8350
+ const run = ctx.db.select().from(runs).where(eq95(runs.capabilityHash, digest(bearer(ctx)))).get();
8177
8351
  const currentTime = now();
8178
8352
  if (!run || expectedId && run.id !== expectedId || !run.deadline || run.deadline <= currentTime || !run.leaseExpiresAt || run.leaseExpiresAt <= currentTime) {
8179
8353
  throw new HttpError(401, "Invalid or expired run capability.");
8180
8354
  }
8181
- const worker = run.executorId && ctx.db.select().from(executors).where(eq92(executors.id, run.executorId)).get();
8182
- const project = ctx.db.select().from(projects).where(eq92(projects.id, run.projectId)).get();
8355
+ const worker = run.executorId && ctx.db.select().from(executors).where(eq95(executors.id, run.executorId)).get();
8356
+ const project = ctx.db.select().from(projects).where(eq95(projects.id, run.projectId)).get();
8183
8357
  const member = ctx.db.select().from(memberships).where(
8184
- and70(
8185
- eq92(memberships.workspaceId, run.workspaceId),
8186
- eq92(memberships.userId, run.actorId)
8358
+ and72(
8359
+ eq95(memberships.workspaceId, run.workspaceId),
8360
+ eq95(memberships.userId, run.actorId)
8187
8361
  )
8188
8362
  ).get();
8189
8363
  if (!worker || !worker.enabled || worker.projectId !== run.projectId || !project?.enabled || !member) {
@@ -8203,9 +8377,9 @@ function runCapability(ctx, expectedId) {
8203
8377
  if (!terminal.has(run.status) && !run.cancelRequested) {
8204
8378
  const operation = object(command2) ? command2.operation : void 0;
8205
8379
  const token = run.tokenId ? ctx.db.select().from(accessTokens).where(
8206
- and70(
8207
- eq92(accessTokens.workspaceId, run.workspaceId),
8208
- eq92(accessTokens.id, run.tokenId)
8380
+ and72(
8381
+ eq95(accessTokens.workspaceId, run.workspaceId),
8382
+ eq95(accessTokens.id, run.tokenId)
8209
8383
  )
8210
8384
  ).get() : void 0;
8211
8385
  const tokenRevoked = run.tokenId && (!token || token.revoked || !token.projects.includes(run.projectId) || !token.scopes.includes("code:execute") || operation === "read" && !token.scopes.includes("runs:read"));
@@ -8246,11 +8420,11 @@ function live(run) {
8246
8420
  }
8247
8421
  function actorContext(ctx, run) {
8248
8422
  const user = identityRepository(ctx.db).user(run.actorId) ?? null;
8249
- const workspace2 = ctx.db.select().from(workspaces).where(eq92(workspaces.id, run.workspaceId)).get() ?? null;
8423
+ const workspace2 = ctx.db.select().from(workspaces).where(eq95(workspaces.id, run.workspaceId)).get() ?? null;
8250
8424
  const membership = ctx.db.select().from(memberships).where(
8251
- and70(
8252
- eq92(memberships.workspaceId, run.workspaceId),
8253
- eq92(memberships.userId, run.actorId)
8425
+ and72(
8426
+ eq95(memberships.workspaceId, run.workspaceId),
8427
+ eq95(memberships.userId, run.actorId)
8254
8428
  )
8255
8429
  ).get();
8256
8430
  if (!user || !workspace2 || !membership) {
@@ -8267,7 +8441,7 @@ function actorContext(ctx, run) {
8267
8441
  }
8268
8442
 
8269
8443
  // server/execution/bootstrap.ts
8270
- import { eq as eq93 } from "drizzle-orm";
8444
+ import { eq as eq96 } from "drizzle-orm";
8271
8445
  import { createHmac as createHmac3, randomUUID as randomUUID6 } from "node:crypto";
8272
8446
  function bootstrap(ctx) {
8273
8447
  const configured = process.env.LOCAL_EXECUTOR_BOOTSTRAP_TOKEN;
@@ -8275,8 +8449,8 @@ function bootstrap(ctx) {
8275
8449
  throw new HttpError(403, "Invalid local bootstrap credential.");
8276
8450
  }
8277
8451
  const registrations = [];
8278
- for (const project of ctx.db.select().from(projects).where(eq93(projects.enabled, true)).all()) {
8279
- let worker = ctx.db.select().from(executors).where(eq93(executors.projectId, project.id)).get();
8452
+ for (const project of ctx.db.select().from(projects).where(eq96(projects.enabled, true)).all()) {
8453
+ let worker = ctx.db.select().from(executors).where(eq96(executors.projectId, project.id)).get();
8280
8454
  if (worker && (!worker.locallyManaged || !worker.enabled)) {
8281
8455
  continue;
8282
8456
  }
@@ -8296,7 +8470,7 @@ function bootstrap(ctx) {
8296
8470
  }).returning().get();
8297
8471
  }
8298
8472
  const token = createHmac3("sha256", configured).update(`${worker.id}:${worker.registrationNonce}`).digest("hex");
8299
- ctx.db.update(executors).set({ tokenHash: digest(token) }).where(eq93(executors.id, worker.id)).run();
8473
+ ctx.db.update(executors).set({ tokenHash: digest(token) }).where(eq96(executors.id, worker.id)).run();
8300
8474
  registrations.push({
8301
8475
  agent_id: project.id,
8302
8476
  executor_id: worker.id,
@@ -8307,34 +8481,34 @@ function bootstrap(ctx) {
8307
8481
  }
8308
8482
 
8309
8483
  // server/execution/claim.ts
8310
- import { and as and71, asc as asc6, eq as eq94, inArray as inArray8 } from "drizzle-orm";
8484
+ import { and as and73, asc as asc7, eq as eq97, inArray as inArray9 } from "drizzle-orm";
8311
8485
  function claim(ctx, worker) {
8312
8486
  ctx.db.update(executors).set({ lastSeenAt: now() }).where(
8313
- and71(
8314
- eq94(executors.id, worker.id),
8315
- eq94(executors.workspaceId, worker.workspaceId)
8487
+ and73(
8488
+ eq97(executors.id, worker.id),
8489
+ eq97(executors.workspaceId, worker.workspaceId)
8316
8490
  )
8317
8491
  ).run();
8318
- const setting = ctx.db.select().from(workspaceSettings).where(eq94(workspaceSettings.workspaceId, worker.workspaceId)).get();
8492
+ const setting = ctx.db.select().from(workspaceSettings).where(eq97(workspaceSettings.workspaceId, worker.workspaceId)).get();
8319
8493
  if (setting && (!setting.enabled || setting.executionPool !== worker.pool)) {
8320
8494
  return new Response(null, { status: 204 });
8321
8495
  }
8322
8496
  const active = ctx.db.select().from(runs).where(
8323
- and71(
8324
- eq94(runs.workspaceId, worker.workspaceId),
8325
- inArray8(runs.status, ["running", "waiting_approval"])
8497
+ and73(
8498
+ eq97(runs.workspaceId, worker.workspaceId),
8499
+ inArray9(runs.status, ["running", "waiting_approval"])
8326
8500
  )
8327
8501
  ).all();
8328
8502
  if (active.some((run) => run.projectId === worker.projectId) || active.length >= (setting?.maxConcurrentRuns ?? 4)) {
8329
8503
  return new Response(null, { status: 204 });
8330
8504
  }
8331
8505
  const candidates = ctx.db.select().from(runs).where(
8332
- and71(
8333
- eq94(runs.projectId, worker.projectId),
8334
- eq94(runs.workspaceId, worker.workspaceId),
8335
- eq94(runs.status, "queued")
8506
+ and73(
8507
+ eq97(runs.projectId, worker.projectId),
8508
+ eq97(runs.workspaceId, worker.workspaceId),
8509
+ eq97(runs.status, "queued")
8336
8510
  )
8337
- ).orderBy(asc6(runs.createdAt)).all();
8511
+ ).orderBy(asc7(runs.createdAt)).all();
8338
8512
  for (const run of candidates) {
8339
8513
  if (!worker.capabilities.includes(run.operation)) {
8340
8514
  continue;
@@ -8344,18 +8518,18 @@ function claim(ctx, worker) {
8344
8518
  continue;
8345
8519
  }
8346
8520
  const member = ctx.db.select().from(memberships).where(
8347
- and71(
8348
- eq94(memberships.userId, run.actorId),
8349
- eq94(memberships.workspaceId, run.workspaceId)
8521
+ and73(
8522
+ eq97(memberships.userId, run.actorId),
8523
+ eq97(memberships.workspaceId, run.workspaceId)
8350
8524
  )
8351
8525
  ).get();
8352
- const token = run.tokenId ? ctx.db.select().from(accessTokens).where(eq94(accessTokens.id, run.tokenId)).get() : null;
8526
+ const token = run.tokenId ? ctx.db.select().from(accessTokens).where(eq97(accessTokens.id, run.tokenId)).get() : null;
8353
8527
  if (!member || run.cancelRequested || run.tokenId && (!token || token.revoked)) {
8354
8528
  ctx.db.update(runs).set({
8355
8529
  status: "cancelled",
8356
8530
  cancelRequested: true,
8357
8531
  updatedAt: now()
8358
- }).where(eq94(runs.id, run.id)).run();
8532
+ }).where(eq97(runs.id, run.id)).run();
8359
8533
  continue;
8360
8534
  }
8361
8535
  const capability = randomSecret();
@@ -8367,7 +8541,7 @@ function claim(ctx, worker) {
8367
8541
  deadline,
8368
8542
  leaseExpiresAt: new Date(Date.now() + 6e4).toISOString(),
8369
8543
  updatedAt: now()
8370
- }).where(eq94(runs.id, run.id)).run();
8544
+ }).where(eq97(runs.id, run.id)).run();
8371
8545
  return json({
8372
8546
  protocol_version: protocol,
8373
8547
  run_id: run.id,
@@ -8385,13 +8559,13 @@ function claim(ctx, worker) {
8385
8559
  }
8386
8560
 
8387
8561
  // server/execution/configuration.ts
8388
- import { and as and72, eq as eq95 } from "drizzle-orm";
8562
+ import { and as and74, eq as eq98 } from "drizzle-orm";
8389
8563
  function pluginsFor(ctx, worker) {
8390
8564
  return ctx.db.select().from(plugins).where(
8391
- and72(
8392
- eq95(plugins.workspaceId, worker.workspaceId),
8393
- eq95(plugins.projectId, worker.projectId),
8394
- eq95(plugins.enabled, true)
8565
+ and74(
8566
+ eq98(plugins.workspaceId, worker.workspaceId),
8567
+ eq98(plugins.projectId, worker.projectId),
8568
+ eq98(plugins.enabled, true)
8395
8569
  )
8396
8570
  ).all().filter(
8397
8571
  (plugin) => plugin.distribution !== "mcp" || worker.protocolVersion >= 4
@@ -8419,11 +8593,11 @@ function configuration(ctx, worker) {
8419
8593
  }
8420
8594
 
8421
8595
  // server/execution/credentials.ts
8422
- import { and as and75, eq as eq98 } from "drizzle-orm";
8596
+ import { and as and77, eq as eq101 } from "drizzle-orm";
8423
8597
 
8424
8598
  // server/mcp/oauth-refresh.ts
8425
8599
  import { auth as auth3 } from "@modelcontextprotocol/client";
8426
- import { and as and73, eq as eq96 } from "drizzle-orm";
8600
+ import { and as and75, eq as eq99 } from "drizzle-orm";
8427
8601
  var refreshes = /* @__PURE__ */ new WeakMap();
8428
8602
  async function mcpExecutionSecret(ctx, credential) {
8429
8603
  let pending = refreshes.get(ctx.db);
@@ -8445,9 +8619,9 @@ async function mcpExecutionSecret(ctx, credential) {
8445
8619
  }
8446
8620
  async function refresh(ctx, initial) {
8447
8621
  const credential = ctx.db.select().from(credentials).where(
8448
- and73(
8449
- eq96(credentials.id, initial.id),
8450
- eq96(credentials.workspaceId, initial.workspaceId)
8622
+ and75(
8623
+ eq99(credentials.id, initial.id),
8624
+ eq99(credentials.workspaceId, initial.workspaceId)
8451
8625
  )
8452
8626
  ).get();
8453
8627
  if (!credential) {
@@ -8478,9 +8652,9 @@ async function refresh(ctx, initial) {
8478
8652
  encryptedSecret: encrypt(ctx, JSON.stringify(state)),
8479
8653
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
8480
8654
  }).where(
8481
- and73(
8482
- eq96(credentials.id, credential.id),
8483
- eq96(credentials.encryptedSecret, credential.encryptedSecret)
8655
+ and75(
8656
+ eq99(credentials.id, credential.id),
8657
+ eq99(credentials.encryptedSecret, credential.encryptedSecret)
8484
8658
  )
8485
8659
  ).returning().get();
8486
8660
  if (!updated) {
@@ -8504,11 +8678,11 @@ async function refresh(ctx, initial) {
8504
8678
  }
8505
8679
 
8506
8680
  // server/oauth/refresh.ts
8507
- import { z as z47 } from "zod";
8508
- import { and as and74, eq as eq97 } from "drizzle-orm";
8681
+ import { z as z50 } from "zod";
8682
+ import { and as and76, eq as eq100 } from "drizzle-orm";
8509
8683
 
8510
8684
  // server/oauth/tokens.ts
8511
- import { z as z46 } from "zod";
8685
+ import { z as z49 } from "zod";
8512
8686
  async function tokenExchange(providerName, clientId, clientSecret, params, fetcher) {
8513
8687
  const fields = new URLSearchParams({ ...params, client_id: clientId });
8514
8688
  const headers = new Headers({
@@ -8549,7 +8723,7 @@ async function tokenExchange(providerName, clientId, clientSecret, params, fetch
8549
8723
  }
8550
8724
  chunks.push(item.value);
8551
8725
  }
8552
- const value = z46.record(z46.string(), z46.unknown()).parse(JSON.parse(Buffer.concat(chunks).toString("utf8")));
8726
+ const value = z49.record(z49.string(), z49.unknown()).parse(JSON.parse(Buffer.concat(chunks).toString("utf8")));
8553
8727
  if (typeof value.access_token !== "string" || !value.access_token || value.access_token.length > 32e3 || value.refresh_token !== void 0 && (typeof value.refresh_token !== "string" || value.refresh_token.length > 32e3) || value.scope !== void 0 && (typeof value.scope !== "string" || value.scope.length > 1e4)) {
8554
8728
  throw new Error();
8555
8729
  }
@@ -8597,9 +8771,9 @@ function recordSecretVersion(secret, credential) {
8597
8771
  function assertExecutionSecretCurrent(store, credential, secret) {
8598
8772
  const version = secretVersions.get(secret);
8599
8773
  const current = store.db.select().from(credentials).where(
8600
- and74(
8601
- eq97(credentials.id, credential.id),
8602
- eq97(credentials.workspaceId, credential.workspaceId)
8774
+ and76(
8775
+ eq100(credentials.id, credential.id),
8776
+ eq100(credentials.workspaceId, credential.workspaceId)
8603
8777
  )
8604
8778
  ).get();
8605
8779
  if (!version || !current || version.id !== current.id || version.workspaceId !== current.workspaceId || version.provider !== current.provider || version.encryptedSecret !== current.encryptedSecret) {
@@ -8615,7 +8789,7 @@ async function executionSecret(store, credential, fetcher = fetch) {
8615
8789
  }
8616
8790
  if (!provider(credential.provider)) {
8617
8791
  return recordSecretVersion(
8618
- z47.record(z47.string(), z47.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret))),
8792
+ z50.record(z50.string(), z50.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret))),
8619
8793
  credential
8620
8794
  );
8621
8795
  }
@@ -8641,15 +8815,15 @@ async function executionSecret(store, credential, fetcher = fetch) {
8641
8815
  }
8642
8816
  async function resolveExecutionSecret(store, initial, fetcher) {
8643
8817
  const credential = store.db.select().from(credentials).where(
8644
- and74(
8645
- eq97(credentials.id, initial.id),
8646
- eq97(credentials.workspaceId, initial.workspaceId)
8818
+ and76(
8819
+ eq100(credentials.id, initial.id),
8820
+ eq100(credentials.workspaceId, initial.workspaceId)
8647
8821
  )
8648
8822
  ).get();
8649
8823
  if (!credential || !provider(credential.provider)) {
8650
8824
  throw new ServiceError("BAD_REQUEST", "Reconnect this credential.");
8651
8825
  }
8652
- const payload = z47.record(z47.string(), z47.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret)));
8826
+ const payload = z50.record(z50.string(), z50.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret)));
8653
8827
  if (credential.provider === "xero-oauth" && Object.keys(payload).length === 1 && typeof payload.secret_accessToken === "string" && payload.secret_accessToken) {
8654
8828
  return recordSecretVersion(
8655
8829
  { secret_accessToken: payload.secret_accessToken },
@@ -8685,9 +8859,9 @@ async function resolveExecutionSecret(store, initial, fetcher) {
8685
8859
  JSON.stringify(applyTokens(payload, tokens2))
8686
8860
  );
8687
8861
  const result = store.db.update(credentials).set({ encryptedSecret: updated, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(
8688
- and74(
8689
- eq97(credentials.id, credential.id),
8690
- eq97(credentials.encryptedSecret, credential.encryptedSecret)
8862
+ and76(
8863
+ eq100(credentials.id, credential.id),
8864
+ eq100(credentials.encryptedSecret, credential.encryptedSecret)
8691
8865
  )
8692
8866
  ).returning().get();
8693
8867
  if (!result) {
@@ -8719,9 +8893,9 @@ async function serveCredential(ctx, credentialId) {
8719
8893
  throw new HttpError(403, "Credential is outside this run capability.");
8720
8894
  }
8721
8895
  const credential2 = ctx.db.select().from(credentials).where(
8722
- and75(
8723
- eq98(credentials.id, credentialId),
8724
- eq98(credentials.workspaceId, run.workspaceId)
8896
+ and77(
8897
+ eq101(credentials.id, credentialId),
8898
+ eq101(credentials.workspaceId, run.workspaceId)
8725
8899
  )
8726
8900
  ).get();
8727
8901
  if (!credential2) {
@@ -8748,11 +8922,164 @@ async function serveCredential(ctx, credentialId) {
8748
8922
  });
8749
8923
  }
8750
8924
 
8925
+ // server/execution/shell-policy.ts
8926
+ import { and as and78, asc as asc8, eq as eq103 } from "drizzle-orm";
8927
+ import { z as z52 } from "zod";
8928
+
8929
+ // server/execution/redaction.ts
8930
+ import { z as z51 } from "zod";
8931
+ import { eq as eq102 } from "drizzle-orm";
8932
+ function redact(ctx, workspaceId, value) {
8933
+ const secrets = [];
8934
+ const collect = (entry) => {
8935
+ if (typeof entry === "string" && entry) {
8936
+ secrets.push(entry);
8937
+ } else if (Array.isArray(entry)) {
8938
+ entry.forEach(collect);
8939
+ } else if (entry && typeof entry === "object") {
8940
+ Object.values(entry).forEach(collect);
8941
+ }
8942
+ };
8943
+ for (const credential of ctx.db.select().from(credentials).where(eq102(credentials.workspaceId, workspaceId)).all()) {
8944
+ collect(JSON.parse(decrypt(ctx, credential.encryptedSecret)));
8945
+ }
8946
+ secrets.sort((a, b) => b.length - a.length);
8947
+ const mask = (entry) => {
8948
+ if (typeof entry === "string") {
8949
+ return secrets.reduce(
8950
+ (text3, secret) => text3.replaceAll(secret, "[REDACTED]"),
8951
+ entry
8952
+ );
8953
+ }
8954
+ if (Array.isArray(entry)) {
8955
+ return entry.map(mask);
8956
+ }
8957
+ if (entry && typeof entry === "object") {
8958
+ return Object.fromEntries(
8959
+ Object.entries(entry).map(([key, child]) => [
8960
+ typeof key === "string" ? secrets.reduce(
8961
+ (text3, secret) => text3.replaceAll(secret, "[REDACTED]"),
8962
+ key
8963
+ ) : key,
8964
+ mask(child)
8965
+ ])
8966
+ );
8967
+ }
8968
+ return entry;
8969
+ };
8970
+ return mask(z51.json().parse(value));
8971
+ }
8972
+ function bounded(value, limit = 2e5) {
8973
+ if (Buffer.byteLength(JSON.stringify(value)) > limit) {
8974
+ throw new HttpError(400, "Data exceeds the response limit.");
8975
+ }
8976
+ return value;
8977
+ }
8978
+
8979
+ // server/execution/shell-policy.ts
8980
+ var invocation = z52.strictObject({
8981
+ executable: executableName,
8982
+ args: z52.array(
8983
+ z52.string().max(4096).refine((arg) => !arg.includes("\0"))
8984
+ ).max(64)
8985
+ });
8986
+ function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
8987
+ const plugin = ctx.db.select().from(plugins).where(
8988
+ and78(
8989
+ eq103(plugins.id, pluginId),
8990
+ eq103(plugins.projectId, run.projectId),
8991
+ eq103(plugins.workspaceId, run.workspaceId),
8992
+ eq103(plugins.enabled, true)
8993
+ )
8994
+ ).get();
8995
+ const agent = snapshotAgents(run.snapshot).find(
8996
+ (agent2) => agent2.id === run.projectId
8997
+ );
8998
+ if (!plugin || !supportsShellPolicy(plugin) || !agent?.plugins.some(
8999
+ (slot) => slot.shell_policy_id === plugin.id && slot.digest === plugin.digest
9000
+ )) {
9001
+ throw new HttpError(
9002
+ 403,
9003
+ "Shell is outside this run's active plugin grants."
9004
+ );
9005
+ }
9006
+ if (!approvalId && method === "GET") {
9007
+ return json(
9008
+ ctx.db.select({ name: shellRules.executable }).from(shellRules).where(
9009
+ and78(
9010
+ eq103(shellRules.pluginId, pluginId),
9011
+ eq103(shellRules.decision, "allow")
9012
+ )
9013
+ ).orderBy(asc8(shellRules.executable)).all().map((rule2) => rule2.name)
9014
+ );
9015
+ }
9016
+ if (approvalId && method === "GET") {
9017
+ const row2 = ctx.db.select().from(approvals).where(
9018
+ and78(
9019
+ eq103(approvals.id, approvalId),
9020
+ eq103(approvals.workspaceId, run.workspaceId),
9021
+ eq103(approvals.runId, run.id)
9022
+ )
9023
+ ).get();
9024
+ if (row2?.shell?.pluginId !== plugin.id || row2.shell.digest !== plugin.digest) {
9025
+ throw new HttpError(404, "Shell approval not found.");
9026
+ }
9027
+ const blocked = ctx.db.select().from(shellRules).where(
9028
+ and78(
9029
+ eq103(shellRules.pluginId, pluginId),
9030
+ eq103(shellRules.executable, row2.shell.executable),
9031
+ eq103(shellRules.decision, "block")
9032
+ )
9033
+ ).get();
9034
+ return json({
9035
+ id: row2.id,
9036
+ status: blocked && row2.status === "approved" ? "denied" : row2.status
9037
+ });
9038
+ }
9039
+ if (approvalId || method !== "POST") {
9040
+ throw new HttpError(405, "Method not allowed.");
9041
+ }
9042
+ const parsed = invocation.safeParse(body);
9043
+ if (!parsed.success) {
9044
+ throw new HttpError(400, "Invalid Shell executable or arguments.");
9045
+ }
9046
+ const { executable, args } = parsed.data;
9047
+ const rule = ctx.db.select().from(shellRules).where(
9048
+ and78(
9049
+ eq103(shellRules.pluginId, pluginId),
9050
+ eq103(shellRules.executable, executable)
9051
+ )
9052
+ ).get();
9053
+ if (rule) {
9054
+ return json({ status: rule.decision === "allow" ? "approved" : "denied" });
9055
+ }
9056
+ const argv = JSON.stringify(
9057
+ redact(ctx, run.workspaceId, [executable, ...args])
9058
+ ).replace(
9059
+ /[\u200b-\u200f\u2028-\u202e\u2060-\u206f]/gu,
9060
+ (character) => "\\u" + character.charCodeAt(0).toString(16).padStart(4, "0")
9061
+ );
9062
+ const row = ctx.db.insert(approvals).values({
9063
+ ...base(run.workspaceId),
9064
+ runId: run.id,
9065
+ prompt: argv,
9066
+ shell: {
9067
+ pluginId,
9068
+ projectId: run.projectId,
9069
+ digest: plugin.digest,
9070
+ executable
9071
+ },
9072
+ status: "pending"
9073
+ }).returning().get();
9074
+ ctx.db.update(runs).set({ status: "waiting_approval", updatedAt: now() }).where(eq103(runs.id, run.id)).run();
9075
+ return json({ id: row.id, status: row.status }, 201);
9076
+ }
9077
+
8751
9078
  // server/execution/product.ts
8752
- import { and as and78, eq as eq102 } from "drizzle-orm";
9079
+ import { and as and81, eq as eq106 } from "drizzle-orm";
8753
9080
 
8754
9081
  // server/execution/project-data.ts
8755
- import { and as and77, asc as asc7, eq as eq101, inArray as inArray9 } from "drizzle-orm";
9082
+ import { and as and80, asc as asc9, eq as eq105, inArray as inArray10 } from "drizzle-orm";
8756
9083
 
8757
9084
  // server/execution/data-pagination.ts
8758
9085
  function paginateData(items, offset, limit) {
@@ -8779,106 +9106,56 @@ function paginateData(items, offset, limit) {
8779
9106
  }
8780
9107
 
8781
9108
  // server/execution/data-schemas.ts
8782
- import { z as z48 } from "zod";
9109
+ import { z as z53 } from "zod";
8783
9110
  var pagination = {
8784
- offset: z48.number().int().min(0).max(1e6).default(0),
8785
- limit: z48.number().int().min(1).max(100).default(100)
9111
+ offset: z53.number().int().min(0).max(1e6).default(0),
9112
+ limit: z53.number().int().min(1).max(100).default(100)
8786
9113
  };
8787
- var tableId = { table_id: z48.string().uuid() };
8788
- var revision2 = z48.number().int().positive();
8789
- var content = z48.string().refine(
9114
+ var tableId = { table_id: z53.string().uuid() };
9115
+ var revision2 = z53.number().int().positive();
9116
+ var content = z53.string().refine(
8790
9117
  (value) => !value.includes("\0") && Buffer.byteLength(value) <= 2e5
8791
9118
  );
8792
- var dataOperationSchema = z48.discriminatedUnion("operation", [
8793
- z48.strictObject({ operation: z48.literal("list_tables"), ...pagination }),
8794
- z48.strictObject({ operation: z48.literal("get_table"), ...tableId }),
8795
- z48.strictObject({
8796
- operation: z48.literal("list_rows"),
9119
+ var dataOperationSchema = z53.discriminatedUnion("operation", [
9120
+ z53.strictObject({ operation: z53.literal("list_tables"), ...pagination }),
9121
+ z53.strictObject({ operation: z53.literal("get_table"), ...tableId }),
9122
+ z53.strictObject({
9123
+ operation: z53.literal("list_rows"),
8797
9124
  ...tableId,
8798
9125
  ...pagination
8799
9126
  }),
8800
- z48.strictObject({
8801
- operation: z48.literal("write_row"),
9127
+ z53.strictObject({
9128
+ operation: z53.literal("write_row"),
8802
9129
  ...tableId,
8803
9130
  table_revision: revision2,
8804
- values: z48.record(z48.string(), z48.json()),
8805
- row_id: z48.string().uuid().optional(),
9131
+ values: z53.record(z53.string(), z53.json()),
9132
+ row_id: z53.string().uuid().optional(),
8806
9133
  revision: revision2.optional()
8807
9134
  }).refine(
8808
9135
  (input2) => input2.row_id === void 0 === (input2.revision === void 0),
8809
9136
  "Row updates require both row ID and revision."
8810
9137
  ),
8811
- z48.strictObject({
8812
- operation: z48.literal("delete_row"),
9138
+ z53.strictObject({
9139
+ operation: z53.literal("delete_row"),
8813
9140
  ...tableId,
8814
- row_id: z48.string().uuid(),
9141
+ row_id: z53.string().uuid(),
8815
9142
  revision: revision2
8816
9143
  }),
8817
- z48.strictObject({ operation: z48.literal("list_documents"), ...pagination }),
8818
- z48.strictObject({
8819
- operation: z48.literal("get_document"),
8820
- document_id: z48.string().uuid()
9144
+ z53.strictObject({ operation: z53.literal("list_documents"), ...pagination }),
9145
+ z53.strictObject({
9146
+ operation: z53.literal("get_document"),
9147
+ document_id: z53.string().uuid()
8821
9148
  }),
8822
- z48.strictObject({
8823
- operation: z48.literal("write_document"),
8824
- document_id: z48.string().uuid(),
8825
- title: z48.string().trim().min(1).max(200).refine((value) => !value.includes("\0")).optional(),
9149
+ z53.strictObject({
9150
+ operation: z53.literal("write_document"),
9151
+ document_id: z53.string().uuid(),
9152
+ title: z53.string().trim().min(1).max(200).refine((value) => !value.includes("\0")).optional(),
8826
9153
  content: content.optional()
8827
9154
  })
8828
9155
  ]);
8829
9156
 
8830
- // server/execution/redaction.ts
8831
- import { z as z49 } from "zod";
8832
- import { eq as eq99 } from "drizzle-orm";
8833
- function redact(ctx, workspaceId, value) {
8834
- const secrets = [];
8835
- const collect = (entry) => {
8836
- if (typeof entry === "string" && entry) {
8837
- secrets.push(entry);
8838
- } else if (Array.isArray(entry)) {
8839
- entry.forEach(collect);
8840
- } else if (entry && typeof entry === "object") {
8841
- Object.values(entry).forEach(collect);
8842
- }
8843
- };
8844
- for (const credential of ctx.db.select().from(credentials).where(eq99(credentials.workspaceId, workspaceId)).all()) {
8845
- collect(JSON.parse(decrypt(ctx, credential.encryptedSecret)));
8846
- }
8847
- secrets.sort((a, b) => b.length - a.length);
8848
- const mask = (entry) => {
8849
- if (typeof entry === "string") {
8850
- return secrets.reduce(
8851
- (text3, secret) => text3.replaceAll(secret, "[REDACTED]"),
8852
- entry
8853
- );
8854
- }
8855
- if (Array.isArray(entry)) {
8856
- return entry.map(mask);
8857
- }
8858
- if (entry && typeof entry === "object") {
8859
- return Object.fromEntries(
8860
- Object.entries(entry).map(([key, child]) => [
8861
- typeof key === "string" ? secrets.reduce(
8862
- (text3, secret) => text3.replaceAll(secret, "[REDACTED]"),
8863
- key
8864
- ) : key,
8865
- mask(child)
8866
- ])
8867
- );
8868
- }
8869
- return entry;
8870
- };
8871
- return mask(z49.json().parse(value));
8872
- }
8873
- function bounded(value, limit = 2e5) {
8874
- if (Buffer.byteLength(JSON.stringify(value)) > limit) {
8875
- throw new HttpError(400, "Data exceeds the response limit.");
8876
- }
8877
- return value;
8878
- }
8879
-
8880
9157
  // server/execution/run-grants.ts
8881
- import { and as and76, eq as eq100 } from "drizzle-orm";
9158
+ import { and as and79, eq as eq104 } from "drizzle-orm";
8882
9159
  function grantIds(context, run, kind, write = false) {
8883
9160
  const root2 = snapshotAgents(run.snapshot).find(
8884
9161
  (agent) => agent.id === run.projectId
@@ -8889,9 +9166,9 @@ function grantIds(context, run, kind, write = false) {
8889
9166
  ...write ? [] : grants2?.read ?? []
8890
9167
  ];
8891
9168
  const project = context.db.select().from(projects).where(
8892
- and76(
8893
- eq100(projects.id, run.projectId),
8894
- eq100(projects.workspaceId, run.workspaceId)
9169
+ and79(
9170
+ eq104(projects.id, run.projectId),
9171
+ eq104(projects.workspaceId, run.workspaceId)
8895
9172
  )
8896
9173
  ).get();
8897
9174
  if (!project) {
@@ -8917,11 +9194,11 @@ function projectData(context, run, body) {
8917
9194
  const documentOperation = input2.operation === "list_documents" || input2.operation === "get_document" || input2.operation === "write_document";
8918
9195
  if (documentOperation) {
8919
9196
  const accessibleDocuments = context.db.select().from(documents).where(
8920
- and77(
8921
- eq101(documents.workspaceId, run.workspaceId),
8922
- inArray9(documents.id, grantIds(context, run, "documents"))
9197
+ and80(
9198
+ eq105(documents.workspaceId, run.workspaceId),
9199
+ inArray10(documents.id, grantIds(context, run, "documents"))
8923
9200
  )
8924
- ).orderBy(asc7(documents.id)).all();
9201
+ ).orderBy(asc9(documents.id)).all();
8925
9202
  if (input2.operation === "list_documents") {
8926
9203
  return paginateData(
8927
9204
  accessibleDocuments.map(documentView2),
@@ -8946,9 +9223,9 @@ function projectData(context, run, body) {
8946
9223
  content: input2.content ?? document.content,
8947
9224
  updatedAt: now()
8948
9225
  }).where(
8949
- and77(
8950
- eq101(documents.id, document.id),
8951
- eq101(documents.workspaceId, run.workspaceId)
9226
+ and80(
9227
+ eq105(documents.id, document.id),
9228
+ eq105(documents.workspaceId, run.workspaceId)
8952
9229
  )
8953
9230
  ).returning().get();
8954
9231
  if (!updated) {
@@ -8957,11 +9234,11 @@ function projectData(context, run, body) {
8957
9234
  return bounded(documentView2(updated));
8958
9235
  }
8959
9236
  const tables = context.db.select().from(workspaceTables).where(
8960
- and77(
8961
- eq101(workspaceTables.workspaceId, run.workspaceId),
8962
- inArray9(workspaceTables.id, grantIds(context, run, "tables"))
9237
+ and80(
9238
+ eq105(workspaceTables.workspaceId, run.workspaceId),
9239
+ inArray10(workspaceTables.id, grantIds(context, run, "tables"))
8963
9240
  )
8964
- ).orderBy(asc7(workspaceTables.id)).all();
9241
+ ).orderBy(asc9(workspaceTables.id)).all();
8965
9242
  if (input2.operation === "list_tables") {
8966
9243
  return paginateData(tables.map(standard), input2.offset, input2.limit);
8967
9244
  }
@@ -8975,15 +9252,15 @@ function projectData(context, run, body) {
8975
9252
  if (input2.operation !== "list_rows" && !grantIds(context, run, "tables", true).includes(table.id)) {
8976
9253
  throw new HttpError(403, "Resource is read only.");
8977
9254
  }
8978
- const matchesTable = and77(
8979
- eq101(tableRows.workspaceId, run.workspaceId),
8980
- eq101(tableRows.tableId, table.id)
9255
+ const matchesTable = and80(
9256
+ eq105(tableRows.workspaceId, run.workspaceId),
9257
+ eq105(tableRows.tableId, table.id)
8981
9258
  );
8982
9259
  if (input2.operation === "list_rows") {
8983
- const rows = context.db.select().from(tableRows).where(matchesTable).orderBy(asc7(tableRows.id)).all();
9260
+ const rows = context.db.select().from(tableRows).where(matchesTable).orderBy(asc9(tableRows.id)).all();
8984
9261
  return paginateData(rows.map(rowView), input2.offset, input2.limit);
8985
9262
  }
8986
- const row = input2.row_id === void 0 ? void 0 : context.db.select().from(tableRows).where(and77(matchesTable, eq101(tableRows.id, input2.row_id))).get();
9263
+ const row = input2.row_id === void 0 ? void 0 : context.db.select().from(tableRows).where(and80(matchesTable, eq105(tableRows.id, input2.row_id))).get();
8987
9264
  if (input2.row_id !== void 0 && !row) {
8988
9265
  throw new HttpError(404, "Row not found.");
8989
9266
  }
@@ -8991,7 +9268,7 @@ function projectData(context, run, body) {
8991
9268
  throw new HttpError(409, "Row changed. Reload before saving.");
8992
9269
  }
8993
9270
  if (input2.operation === "delete_row") {
8994
- context.db.delete(tableRows).where(and77(matchesTable, eq101(tableRows.id, input2.row_id))).run();
9271
+ context.db.delete(tableRows).where(and80(matchesTable, eq105(tableRows.id, input2.row_id))).run();
8995
9272
  return { deleted: true };
8996
9273
  }
8997
9274
  if (table.revision !== input2.table_revision) {
@@ -9003,7 +9280,7 @@ function projectData(context, run, body) {
9003
9280
  values: input2.values,
9004
9281
  revision: row.revision + 1,
9005
9282
  updatedAt: now()
9006
- }).where(and77(matchesTable, eq101(tableRows.id, row.id))).returning().get();
9283
+ }).where(and80(matchesTable, eq105(tableRows.id, row.id))).returning().get();
9007
9284
  if (!updated) {
9008
9285
  throw new HttpError(404, "Row not found.");
9009
9286
  }
@@ -9020,6 +9297,10 @@ function projectData(context, run, body) {
9020
9297
 
9021
9298
  // server/execution/product.ts
9022
9299
  function handleProduct(ctx, run, route, method, body) {
9300
+ const shell = route.match(/^product\/shell\/([^/]+)\/(?:([^/]+)\/)?$/);
9301
+ if (shell?.[1]) {
9302
+ return shellPolicyRequest(ctx, run, shell[1], shell[2], method, body);
9303
+ }
9023
9304
  if (route === "product/project-data/" && method === "POST") {
9024
9305
  return json(projectData(ctx, run, body));
9025
9306
  }
@@ -9043,7 +9324,7 @@ function handleProduct(ctx, run, route, method, body) {
9043
9324
  }
9044
9325
  if (method === "GET") {
9045
9326
  const items = ctx.db.select().from(table).where(
9046
- and78(eq102(table.workspaceId, run.workspaceId), eq102(table.runId, run.id))
9327
+ and81(eq106(table.workspaceId, run.workspaceId), eq106(table.runId, run.id))
9047
9328
  ).all();
9048
9329
  const view = (entry) => "prompt" in entry ? {
9049
9330
  id: entry.id,
@@ -9082,7 +9363,7 @@ function handleProduct(ctx, run, route, method, body) {
9082
9363
  status: "pending",
9083
9364
  decidedBy: null
9084
9365
  }).returning().get();
9085
- ctx.db.update(runs).set({ status: "waiting_approval" }).where(eq102(runs.id, run.id)).run();
9366
+ ctx.db.update(runs).set({ status: "waiting_approval" }).where(eq106(runs.id, run.id)).run();
9086
9367
  return json(
9087
9368
  {
9088
9369
  id: approval.id,
@@ -9120,7 +9401,7 @@ function handleProduct(ctx, run, route, method, body) {
9120
9401
  }
9121
9402
 
9122
9403
  // server/execution/register.ts
9123
- import { eq as eq103 } from "drizzle-orm";
9404
+ import { eq as eq107 } from "drizzle-orm";
9124
9405
  function register(ctx, worker, body) {
9125
9406
  const version = body.protocol_version;
9126
9407
  const capabilities = body.capabilities;
@@ -9144,20 +9425,20 @@ function register(ctx, worker, body) {
9144
9425
  capabilities: validatedCapabilities,
9145
9426
  lastSeenAt: now(),
9146
9427
  updatedAt: now()
9147
- }).where(eq103(executors.id, worker.id)).returning().get();
9428
+ }).where(eq107(executors.id, worker.id)).returning().get();
9148
9429
  return json(configuration(ctx, registered));
9149
9430
  }
9150
9431
 
9151
9432
  // server/execution/run-update.ts
9152
- import { and as and79, eq as eq104 } from "drizzle-orm";
9433
+ import { and as and82, eq as eq108 } from "drizzle-orm";
9153
9434
  function handleRunUpdate(ctx, run, action, body) {
9154
9435
  if (action === "heartbeat") {
9155
9436
  if (!terminal.has(run.status)) {
9156
9437
  if (run.executorId) {
9157
9438
  ctx.db.update(executors).set({ lastSeenAt: now() }).where(
9158
- and79(
9159
- eq104(executors.id, run.executorId),
9160
- eq104(executors.workspaceId, run.workspaceId)
9439
+ and82(
9440
+ eq108(executors.id, run.executorId),
9441
+ eq108(executors.workspaceId, run.workspaceId)
9161
9442
  )
9162
9443
  ).run();
9163
9444
  }
@@ -9166,7 +9447,7 @@ function handleRunUpdate(ctx, run, action, body) {
9166
9447
  leaseExpiresAt: new Date(
9167
9448
  Math.min(Date.now() + 6e4, Date.parse(run.deadline))
9168
9449
  ).toISOString()
9169
- }).where(eq104(runs.id, run.id)).run();
9450
+ }).where(eq108(runs.id, run.id)).run();
9170
9451
  }
9171
9452
  return json({
9172
9453
  status: run.status,
@@ -9184,9 +9465,9 @@ function handleRunUpdate(ctx, run, action, body) {
9184
9465
  "Event data"
9185
9466
  );
9186
9467
  const existing = ctx.db.select().from(runEvents).where(
9187
- and79(
9188
- eq104(runEvents.runId, run.id),
9189
- eq104(runEvents.sequence, body.sequence)
9468
+ and82(
9469
+ eq108(runEvents.runId, run.id),
9470
+ eq108(runEvents.sequence, body.sequence)
9190
9471
  )
9191
9472
  ).get();
9192
9473
  if (existing && (existing.kind !== body.kind || JSON.stringify(existing.data) !== JSON.stringify(data))) {
@@ -9240,13 +9521,13 @@ function handleRunUpdate(ctx, run, action, body) {
9240
9521
  );
9241
9522
  }
9242
9523
  const pending = ctx.db.select().from(approvals).where(
9243
- and79(eq104(approvals.runId, run.id), eq104(approvals.status, "pending"))
9524
+ and82(eq108(approvals.runId, run.id), eq108(approvals.status, "pending"))
9244
9525
  ).all();
9245
9526
  if (pending.length && status === "succeeded") {
9246
9527
  throw new HttpError(400, "Resolve pending approvals before completing.");
9247
9528
  }
9248
9529
  ctx.db.update(approvals).set({ status: "interrupted" }).where(
9249
- and79(eq104(approvals.runId, run.id), eq104(approvals.status, "pending"))
9530
+ and82(eq108(approvals.runId, run.id), eq108(approvals.status, "pending"))
9250
9531
  ).run();
9251
9532
  ctx.db.update(runs).set({
9252
9533
  status,
@@ -9254,7 +9535,7 @@ function handleRunUpdate(ctx, run, action, body) {
9254
9535
  error,
9255
9536
  cancelRequested: run.cancelRequested,
9256
9537
  updatedAt: now()
9257
- }).where(eq104(runs.id, run.id)).run();
9538
+ }).where(eq108(runs.id, run.id)).run();
9258
9539
  return new Response(null, { status: 204 });
9259
9540
  }
9260
9541
 
@@ -9304,7 +9585,7 @@ function handleWorker(ctx, route, method, body) {
9304
9585
  }
9305
9586
 
9306
9587
  // server/oauth/callback.ts
9307
- import { and as and80, eq as eq105 } from "drizzle-orm";
9588
+ import { and as and83, eq as eq109 } from "drizzle-orm";
9308
9589
  import { randomUUID as randomUUID7 } from "node:crypto";
9309
9590
  async function finishOAuth(ctx, input2, fetcher = fetch) {
9310
9591
  const workspace2 = authorize(ctx);
@@ -9318,14 +9599,14 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
9318
9599
  const state = field(input2.state, 500);
9319
9600
  const code = field(input2.code, 4e3);
9320
9601
  const attempt = inTransaction(ctx, (ctx2) => {
9321
- const record = ctx2.db.select().from(oauthAttempts).where(eq105(oauthAttempts.stateDigest, digest(state))).get();
9602
+ const record = ctx2.db.select().from(oauthAttempts).where(eq109(oauthAttempts.stateDigest, digest(state))).get();
9322
9603
  if (!record || record.userId !== user.id || record.workspaceId !== workspace2.id || record.sessionId !== ctx2.sessionId || record.expiresAt <= Date.now() || !isCurrentManager(ctx2, workspace2.id, user.id)) {
9323
9604
  throw new ServiceError(
9324
9605
  "BAD_REQUEST",
9325
9606
  "This connection request has expired or belongs to another session."
9326
9607
  );
9327
9608
  }
9328
- ctx2.db.delete(oauthAttempts).where(eq105(oauthAttempts.stateDigest, record.stateDigest)).run();
9609
+ ctx2.db.delete(oauthAttempts).where(eq109(oauthAttempts.stateDigest, record.stateDigest)).run();
9329
9610
  return record;
9330
9611
  });
9331
9612
  const payload = JSON.parse(decrypt(ctx, attempt.encryptedPayload));
@@ -9350,9 +9631,9 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
9350
9631
  inTransaction(ctx, (ctx2) => {
9351
9632
  const session = identityRepository(ctx2.db).session(ctx2.sessionId);
9352
9633
  const plugin = ctx2.db.select().from(plugins).where(
9353
- and80(
9354
- eq105(plugins.id, attempt.pluginId),
9355
- eq105(plugins.workspaceId, workspace2.id)
9634
+ and83(
9635
+ eq109(plugins.id, attempt.pluginId),
9636
+ eq109(plugins.workspaceId, workspace2.id)
9356
9637
  )
9357
9638
  ).get();
9358
9639
  if (!session || session.userId !== user.id || session.expiresAt <= Date.now() || !isCurrentManager(ctx2, workspace2.id, user.id)) {
@@ -9394,7 +9675,7 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
9394
9675
  createdAt: timestamp,
9395
9676
  updatedAt: timestamp
9396
9677
  }).run();
9397
- ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(eq105(plugins.id, plugin.id)).run();
9678
+ ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(eq109(plugins.id, plugin.id)).run();
9398
9679
  ctx2.db.insert(auditRecords).values({
9399
9680
  id: randomUUID7(),
9400
9681
  workspaceId: workspace2.id,
@@ -9452,22 +9733,22 @@ function publicRequest(request) {
9452
9733
  }
9453
9734
 
9454
9735
  // server/repositories/token-activity.ts
9455
- import { and as and81, eq as eq106, sql as sql3 } from "drizzle-orm";
9736
+ import { and as and84, eq as eq110, sql as sql4 } from "drizzle-orm";
9456
9737
  function recordTokenActivity(store, token, status, isMcp, hasFailed) {
9457
9738
  const time = (/* @__PURE__ */ new Date()).toISOString();
9458
9739
  store.db.update(accessTokens).set({
9459
9740
  firstUsedAt: token.firstUsedAt ?? time,
9460
9741
  lastUsedAt: time,
9461
- requestCount: sql3`${accessTokens.requestCount} + 1`,
9462
- ...hasFailed ? { errorCount: sql3`${accessTokens.errorCount} + 1` } : { successCount: sql3`${accessTokens.successCount} + 1` },
9463
- ...isMcp ? { mcpRequestCount: sql3`${accessTokens.mcpRequestCount} + 1` } : { trpcRequestCount: sql3`${accessTokens.trpcRequestCount} + 1` },
9742
+ requestCount: sql4`${accessTokens.requestCount} + 1`,
9743
+ ...hasFailed ? { errorCount: sql4`${accessTokens.errorCount} + 1` } : { successCount: sql4`${accessTokens.successCount} + 1` },
9744
+ ...isMcp ? { mcpRequestCount: sql4`${accessTokens.mcpRequestCount} + 1` } : { trpcRequestCount: sql4`${accessTokens.trpcRequestCount} + 1` },
9464
9745
  lastTransport: isMcp ? "mcp" : "trpc",
9465
9746
  lastOutcome: hasFailed ? "error" : "success",
9466
9747
  lastStatusCode: status
9467
9748
  }).where(
9468
- and81(
9469
- eq106(accessTokens.id, token.id),
9470
- eq106(accessTokens.workspaceId, token.workspaceId)
9749
+ and84(
9750
+ eq110(accessTokens.id, token.id),
9751
+ eq110(accessTokens.workspaceId, token.workspaceId)
9471
9752
  )
9472
9753
  ).run();
9473
9754
  }
@@ -9742,7 +10023,7 @@ function createApp(dependencies) {
9742
10023
  }
9743
10024
 
9744
10025
  // server/cli/accounts.ts
9745
- import { eq as eq107, or as or6 } from "drizzle-orm";
10026
+ import { eq as eq111, or as or6 } from "drizzle-orm";
9746
10027
  import { createInterface } from "node:readline/promises";
9747
10028
  import { Writable } from "node:stream";
9748
10029
  async function resetPassword(store, email) {
@@ -9783,9 +10064,9 @@ async function resetPassword(store, email) {
9783
10064
  }
9784
10065
  const passwordHash = await password.hash(password2);
9785
10066
  inTransaction(store, (store2) => {
9786
- store2.db.update(users).set({ passwordHash }).where(eq107(users.id, user.id)).run();
10067
+ store2.db.update(users).set({ passwordHash }).where(eq111(users.id, user.id)).run();
9787
10068
  store2.db.delete(sessions).where(
9788
- or6(eq107(sessions.userId, user.id), eq107(sessions.pendingUserId, user.id))
10069
+ or6(eq111(sessions.userId, user.id), eq111(sessions.pendingUserId, user.id))
9789
10070
  ).run();
9790
10071
  });
9791
10072
  console.log("Password changed. Existing sign-in sessions were revoked.");
@@ -9795,17 +10076,17 @@ async function resetPassword(store, email) {
9795
10076
  }
9796
10077
 
9797
10078
  // server/cli/database.ts
9798
- import { z as z50 } from "zod";
10079
+ import { z as z54 } from "zod";
9799
10080
 
9800
10081
  // server/db/connection.ts
9801
- var driver = typeof Bun === "undefined" ? await import("./node-driver-HDJKKWXQ.js") : await import("./bun-driver-DTZUUCI3.js");
10082
+ var driver = typeof Bun === "undefined" ? await import("./node-driver-75PFAG2L.js") : await import("./bun-driver-UOZIWBHK.js");
9802
10083
  var openDatabase = driver.openDatabase;
9803
10084
 
9804
10085
  // server/cli/database.ts
9805
10086
  import { chmodSync, constants, copyFileSync, existsSync as existsSync3 } from "node:fs";
9806
10087
  import { join as join3 } from "node:path";
9807
10088
  function verifySnapshot(sqlite) {
9808
- const integrity = z50.array(z50.object({ integrity_check: z50.string() })).parse(sqlite.query("PRAGMA integrity_check").all());
10089
+ const integrity = z54.array(z54.object({ integrity_check: z54.string() })).parse(sqlite.query("PRAGMA integrity_check").all());
9809
10090
  if (integrity.length !== 1 || integrity[0]?.integrity_check !== "ok") {
9810
10091
  throw new Error("Backup integrity check failed.");
9811
10092
  }
@@ -9953,13 +10234,13 @@ function openStore(dataDir2) {
9953
10234
  }
9954
10235
 
9955
10236
  // server/execution/maintenance.ts
9956
- import { z as z51 } from "zod";
10237
+ import { z as z55 } from "zod";
9957
10238
  import { CronExpressionParser as CronExpressionParser2 } from "cron-parser";
9958
- import { and as and82, eq as eq108, inArray as inArray10 } from "drizzle-orm";
10239
+ import { and as and85, eq as eq112, inArray as inArray11 } from "drizzle-orm";
9959
10240
  function maintenance(store) {
9960
10241
  const currentTime = now();
9961
10242
  inTransaction(store, (store2) => {
9962
- const active = store2.db.select().from(runs).where(inArray10(runs.status, ["running", "waiting_approval"])).all();
10243
+ const active = store2.db.select().from(runs).where(inArray11(runs.status, ["running", "waiting_approval"])).all();
9963
10244
  for (const run of active) {
9964
10245
  if (run.leaseExpiresAt && run.leaseExpiresAt <= currentTime || run.deadline && run.deadline <= currentTime) {
9965
10246
  store2.db.update(runs).set({
@@ -9967,22 +10248,22 @@ function maintenance(store) {
9967
10248
  error: "Execution stopped responding. Review side effects before retrying.",
9968
10249
  capabilityHash: "",
9969
10250
  updatedAt: currentTime
9970
- }).where(eq108(runs.id, run.id)).run();
10251
+ }).where(eq112(runs.id, run.id)).run();
9971
10252
  store2.db.update(approvals).set({ status: "interrupted" }).where(
9972
- and82(
9973
- eq108(approvals.runId, run.id),
9974
- eq108(approvals.status, "pending")
10253
+ and85(
10254
+ eq112(approvals.runId, run.id),
10255
+ eq112(approvals.status, "pending")
9975
10256
  )
9976
10257
  ).run();
9977
10258
  }
9978
10259
  }
9979
- for (const schedule of store2.db.select().from(schedules).where(eq108(schedules.enabled, true)).all()) {
10260
+ for (const schedule of store2.db.select().from(schedules).where(eq112(schedules.enabled, true)).all()) {
9980
10261
  if (schedule.nextRunAt > currentTime) {
9981
10262
  continue;
9982
10263
  }
9983
- const action = store2.db.select().from(actions).where(eq108(actions.id, schedule.actionId)).get();
10264
+ const action = store2.db.select().from(actions).where(eq112(actions.id, schedule.actionId)).get();
9984
10265
  if (!action) {
9985
- store2.db.update(schedules).set({ enabled: false }).where(eq108(schedules.id, schedule.id)).run();
10266
+ store2.db.update(schedules).set({ enabled: false }).where(eq112(schedules.id, schedule.id)).run();
9986
10267
  continue;
9987
10268
  }
9988
10269
  const nextRunAt = CronExpressionParser2.parse(schedule.cron, {
@@ -10013,16 +10294,16 @@ function maintenance(store) {
10013
10294
  project: action.projectId,
10014
10295
  operation: "action",
10015
10296
  action: action.id,
10016
- inputs: z51.record(z51.string(), z51.json()).parse(schedule.inputs),
10297
+ inputs: z55.record(z55.string(), z55.json()).parse(schedule.inputs),
10017
10298
  idempotency_key: `schedule:${schedule.id}:${schedule.nextRunAt}`
10018
10299
  });
10019
- store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(eq108(runs.id, run.id)).run();
10300
+ store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(eq112(runs.id, run.id)).run();
10020
10301
  } catch (error) {
10021
10302
  if (!(error instanceof ServiceError)) {
10022
10303
  throw error;
10023
10304
  }
10024
10305
  }
10025
- store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(eq108(schedules.id, schedule.id)).run();
10306
+ store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(eq112(schedules.id, schedule.id)).run();
10026
10307
  }
10027
10308
  });
10028
10309
  }